summaryrefslogtreecommitdiffstats
path: root/app/meteotime.c
diff options
context:
space:
mode:
authorroot <root@ka-ata-killa.ourano.james.local>2021-03-21 00:24:14 +0000
committerroot <root@ka-ata-killa.ourano.james.local>2021-03-21 00:24:14 +0000
commitac7e8b2318a0e118d4cb7ced49d109c40908cb85 (patch)
tree91d8ec03cb9552a47db467b5c0f9c5bea68b6473 /app/meteotime.c
parent8c8218f878609af4719252d16ac0f42bccd9ba5b (diff)
downloadclock-ac7e8b2318a0e118d4cb7ced49d109c40908cb85.tar.gz
clock-ac7e8b2318a0e118d4cb7ced49d109c40908cb85.tar.bz2
clock-ac7e8b2318a0e118d4cb7ced49d109c40908cb85.zip
fix content-type headers, and store a day's worth of weather data
Diffstat (limited to 'app/meteotime.c')
-rw-r--r--app/meteotime.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/app/meteotime.c b/app/meteotime.c
new file mode 100644
index 0000000..5734a0b
--- /dev/null
+++ b/app/meteotime.c
@@ -0,0 +1,65 @@
+#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);
+
+}