diff options
author | root <root@ka-ata-killa.ourano.james.local> | 2021-03-21 00:24:14 +0000 |
---|---|---|
committer | root <root@ka-ata-killa.ourano.james.local> | 2021-03-21 00:24:14 +0000 |
commit | ac7e8b2318a0e118d4cb7ced49d109c40908cb85 (patch) | |
tree | 91d8ec03cb9552a47db467b5c0f9c5bea68b6473 | |
parent | 8c8218f878609af4719252d16ac0f42bccd9ba5b (diff) | |
download | clock-ac7e8b2318a0e118d4cb7ced49d109c40908cb85.tar.gz clock-ac7e8b2318a0e118d4cb7ced49d109c40908cb85.tar.bz2 clock-ac7e8b2318a0e118d4cb7ced49d109c40908cb85.zip |
fix content-type headers, and store a day's worth of weather data
-rw-r--r-- | app/Makefile | 6 | ||||
-rw-r--r-- | app/dcf77.c | 2 | ||||
-rw-r--r-- | app/httpd.c | 19 | ||||
-rw-r--r-- | app/lwip/lwipopts.h | 2 | ||||
-rw-r--r-- | app/meteotime.c | 65 | ||||
-rw-r--r-- | app/prototypes.h | 3 |
6 files changed, 88 insertions, 9 deletions
diff --git a/app/Makefile b/app/Makefile index 224f182..fddc03b 100644 --- a/app/Makefile +++ b/app/Makefile @@ -21,15 +21,17 @@ CPROTO=cproto PROG=clockv2 + LDSCRIPT = ${PROG}.ld V=1 default: ${PROG}.elf + CSRCS=led.c ticker.c ring.c usart.c stdio.c lwip_glue.c steth.c msf.c abs.c \ pll.c main.c time_fn.c ntp.c dcf77.c util.c stats.c gps.c hexdump.c bits.c \ max7219.c report.c sysclk.c cdcacm.c usb.c dfu.c adc.c dummy_kb.c ref.c \ - ptp.c display.c httpd.c alarm.c + ptp.c display.c httpd.c alarm.c meteotime.c HSRCS= events.h gps.h project.h ring.h steth.h time_fn.h ubx.h @@ -162,7 +164,7 @@ almanac: wget -O almanac.alp http://alp.u-blox.com/current_7d.alp -EXTRA_CLEAN=${OBJS} ${LWIP_OBJS:%.o=%.d} almanac.c +EXTRA_CLEAN=${OBJS} ${LWIP_OBJS:%.o=%.d} almanac.c *.orig tidy: astyle -A3 -s2 --attach-extern-c -L -c -w -Y -m0 -f -p -H -U -k3 -xj -xd ${CSRCS} ${HSRCS} diff --git a/app/dcf77.c b/app/dcf77.c index 30cfd26..4b69a69 100644 --- a/app/dcf77.c +++ b/app/dcf77.c @@ -104,6 +104,8 @@ static void process_bits (uint64_t abs, uint64_t ptp) printf ("DCF77: Next minute is: %02d-%02d-%02d %02d:%02d\r\n", u.year, u.month, u.mday, u.hour, u.minute); time_print_epoch ("DCF77: ", e, dcf77_info); + meteotime_save(&u,bits); + dump_bits ("dcf77", bits); } diff --git a/app/httpd.c b/app/httpd.c index 3fdea93..b3776c3 100644 --- a/app/httpd.c +++ b/app/httpd.c @@ -257,19 +257,24 @@ static const char *cgi_set_handler (int idx, int num_params, char *params[], cha int fs_open_custom (struct fs_file *file, const char *name) { - int len; - if (!strcmp (name, "/index.html")) - len = make_index(); - else if (!strcmp (name, "/alarm.html")) - len = make_alarm(); + if (!strcmp (name, "/index.html")) { + file->data = (const char *)html_buf; + file->len = make_index(); + } + else if (!strcmp (name, "/alarm.html")) { + file->data = (const char *)html_buf; + file->len = make_alarm(); + } + else if (!strcmp (name, "/meteotime.dat")) { + file->data = (const char *)meteotime_data; + file->len=sizeof(meteotime_data); + } else { printf ("looking for url=%s, found nothing\n", name); return 0; } - file->data = (const char *)html_buf; - file->len = len; file->index = file->len; file->pextension = NULL; file->flags = 0; diff --git a/app/lwip/lwipopts.h b/app/lwip/lwipopts.h index b3e37c7..a44c06c 100644 --- a/app/lwip/lwipopts.h +++ b/app/lwip/lwipopts.h @@ -216,6 +216,8 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums #define LWIP_HTTPD_CUSTOM_FILES 1 #define LWIP_HTTPD_FILE_STATE 0 #define LWIP_HTTPD_CGI 1 +#define LWIP_HTTPD_DYNAMIC_HEADERS 1 +#define HTTPD_ADDITIONAL_CONTENT_TYPES {"dat", HTTP_CONTENT_TYPE("application/octet-stream")} #define LWIP_IGMP 1 #define LWIP_MDNS_RESPONDER 1 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); + +} diff --git a/app/prototypes.h b/app/prototypes.h index e1164bf..e502fd9 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -206,3 +206,6 @@ extern void cgi_init(void); /* alarm.c */ extern EPOCH alarm; extern void alarm_dispatch(void); +/* meteotime.c */ +extern uint32_t meteotime_data[(((((37)*(60)*(24)))+(32 -1))/(32))]; +extern void meteotime_save(UTC *u, uint8_t *bits); |