#include "project.h" #define BITS_PER_MIN 37 #define MINS_PER_HOUR 60 #define HOURS_PER_DAY 24 #define N_BITS ((BITS_PER_MIN)*(MINS_PER_HOUR)*(HOURS_PER_DAY)) #define BITS_PER_WORD 32 #define N_WORDS (((N_BITS)+(BITS_PER_WORD-1))/(BITS_PER_WORD)) #define M1 (~0UL) #define M2 ((1UL << (BITS_PER_MIN - BITS_PER_WORD))-1) uint32_t meteotime_data[N_WORDS]; void meteotime_save (UTC *u, uint8_t *bits) { uint32_t c; uint32_t d1; uint32_t d2; unsigned i; unsigned word; unsigned bit; unsigned ibit; //0-13 for (d1 = 0, c = 1, i = 1; i < 15; ++i, c <<= 1) if (bits[i]) d1 |= c; //14 if (bits[17]) d1 |= c; c <<= 1; //15-31 for (i = 36; i < 53; ++i, c <<= 1) if (bits[i]) d1 |= c; //0-4 for (d2 = 0, c = 1, i = 53; i < 58; ++i, c <<= 1) if (bits[i]) d2 |= c; bit = u->hour; bit *= 60; bit += u->minute; bit *= BITS_PER_MIN; word = bit / BITS_PER_WORD; bit = bit & (BITS_PER_WORD - 1); ibit = BITS_PER_WORD - bit; meteotime_data[word] &= ~ (M1 << bit); meteotime_data[word] |= (d1 << bit); word++; meteotime_data[word] &= ~ ((M1 >> ibit) | (M2 << bit)); meteotime_data[word] |= (d1 >> ibit) | (d2 << bit); }