blob: e18220f84995f453035f4dace364fb7d46522c3d (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#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);
}
|