From 4342064ee35d4facf1ad4cbde8f6f84460df02a0 Mon Sep 17 00:00:00 2001 From: root Date: Sat, 20 Mar 2021 12:08:14 +0000 Subject: add webserver content --- app/Makefile | 15 +++++++++--- app/fs.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ app/gps.c | 38 ++++++++++++++++++++++------- app/lwip/lwipopts.h | 39 ++++++++++++++++++------------ app/lwip_glue.c | 1 + app/project.h | 6 +++++ app/prototypes.h | 16 ++++++++++--- app/ptp.c | 7 ++++++ app/ref.c | 5 ++++ app/time_fn.c | 10 ++++---- 10 files changed, 172 insertions(+), 34 deletions(-) create mode 100644 app/fs.c diff --git a/app/Makefile b/app/Makefile index ab88c83..126baa1 100644 --- a/app/Makefile +++ b/app/Makefile @@ -29,7 +29,7 @@ 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 + ptp.c display.c fs.c HSRCS= events.h gps.h project.h ring.h steth.h time_fn.h ubx.h @@ -42,7 +42,16 @@ LWIP_PATH=.. VPATH=${LWIP_PATH} -LWIP_API=${LWIP}/src/api/err.c +LWIP_API= \ + ${LWIPDIR}/api/err.c + +LWIP_APPS= \ + $(LWIPDIR)/apps/http/fs.c \ + $(LWIPDIR)/apps/http/httpd.c + + +# $(LWIPDIR)/apps/http/http_client.c \ +# # ${LWIP}/src/api/err.c ${LWIP}/src/api/netdb.c ${LWIP}/src/api/api_msg.c \ ${LWIP}/src/api/tcpip.c ${LWIP}/src/api/sockets.c ${LWIP}/src/api/api_lib.c \ ${LWIP}/src/api/netbuf.c ${LWIP}/src/api/netifapi.c @@ -59,7 +68,7 @@ LWIP_INC=${LWIP_PATH}/${LWIP} LWIP_LOCAL=${LWIP_PATH}/lwip/lwip-local -LWIP_CSRCS=${LWIP_API} ${LWIP_CORE} +LWIP_CSRCS=${LWIP_API} ${LWIP_CORE} ${LWIP_APPS} EXTRA_CLEAN=${LWIP} diff --git a/app/fs.c b/app/fs.c new file mode 100644 index 0000000..7b041fb --- /dev/null +++ b/app/fs.c @@ -0,0 +1,69 @@ +#include "project.h" + +#if 0 +#define FS_FILE_FLAGS_HEADER_INCLUDED 0x01 +#define FS_FILE_FLAGS_HEADER_PERSISTENT 0x02 +#define FS_FILE_FLAGS_HEADER_HTTPVER_1_1 0x04 +#define FS_FILE_FLAGS_SSI 0x08 +#endif + + +static char index_html[8192]; + +static uint32_t make_index (void) +{ + uint64_t abs = ref_get(); + EPOCH e; + UTC u; + ST l; + char buf[128]; + + PTB_INIT (index_html); + + e = ref_decompose (abs); + u = time_epoch_to_utc (e); + l = time_utc_to_lst (u, gps_lon); + + utc_to_str (buf, &u); + + PTB_ADD ("
\n");
+  PTB_ADD ("UTC: %s\n", buf);
+  PTB_ADD ("LST:                 %02d:%02d:%02d.%09d\n", l.hour, l.minute, l.second, l.nanosecond);
+  PTB_ADD("\n");
+
+  PTB_ADD ("GPS:\n");
+  PTB_ADD ("%s\n", gps_info);
+  PTB_ADD (" %s\n", gps_pos);
+  PTB_ADD (" %s\n", gps_svin_info);
+  PTB_ADD("\n");
+
+  PTB_ADD ("%s", gps_svinfo);
+  PTB_ADD ("
\n"); + + return PTB_LEN; +} + +int fs_open_custom (struct fs_file *file, const char *name) +{ + int len; + + if (strcmp (name, "/index.html")) return 0; + + len = make_index(); + + file->data = (const char *)index_html; + file->len = len; + file->index = file->len; + file->pextension = NULL; + file->flags = 0; + + + return 1; +} + + + + +void fs_close_custom (struct fs_file *file) +{ +} diff --git a/app/gps.c b/app/gps.c index 7ccefd7..7327435 100644 --- a/app/gps.c +++ b/app/gps.c @@ -39,7 +39,7 @@ static int32_t freq = 0; static Event_ring gps_ring; -static char gps_info[60]; +char gps_info[60]; static int ubx_cfg_tmode (uint32_t time_mode, int32_t x, int32_t y, int32_t z, uint32_t var, uint32_t min_dur, uint32_t max_var); @@ -113,6 +113,8 @@ static int ubx_recv_almanac (uint8_t *ptr, unsigned len) double gps_lat, gps_lon; +char gps_pos[128]; + static int ubx_recv_nav_posllh (uint8_t *ptr, unsigned len) { @@ -137,6 +139,8 @@ ubx_recv_nav_posllh (uint8_t *ptr, unsigned len) printf ("POS: %.4f %.4f\r\n", gps_lat, gps_lon); + snprintf (gps_pos, sizeof (gps_pos) - 1, "location: %.4f %.4f", gps_lat, gps_lon); + return 0; } @@ -404,6 +408,8 @@ static int ubx_recv_nav_sbas (uint8_t *ptr, unsigned len) return 0; } +char gps_svinfo[4096]; + static int ubx_recv_nav_svinfo (uint8_t *ptr, unsigned len) { uint32_t d4; @@ -412,7 +418,8 @@ static int ubx_recv_nav_svinfo (uint8_t *ptr, unsigned len) uint8_t n, flags, cflags; const char *st; - if (!chatty_gps) return 0; + PTB_INIT (gps_svinfo); + ptr += ubx_get_u32 (ptr, &d4); ptr += ubx_get_u8 (ptr, &n); @@ -475,12 +482,22 @@ static int ubx_recv_nav_svinfo (uint8_t *ptr, unsigned len) } - printf ("GPS SVID:%3d C/N:%3d %c%c%c %s\r\n", - svid, cno, - (cflags & 0x01) ? 'U' : '-', - (cflags & 0x02) ? 'D' : '-', - (cflags & 0x04) ? 'E' : '-', - st); + if (chatty_gps) + printf ("GPS SVID:%3d C/N:%3d %c%c%c %s\r\n", + svid, cno, + (cflags & 0x01) ? 'U' : '-', + (cflags & 0x02) ? 'D' : '-', + (cflags & 0x04) ? 'E' : '-', + st); + + + PTB_ADD ("GPS SVID:%3d C/N:%3d %c%c%c %s\n", + svid, cno, + (cflags & 0x01) ? 'U' : '-', + (cflags & 0x02) ? 'D' : '-', + (cflags & 0x04) ? 'E' : '-', + st); + } @@ -495,6 +512,8 @@ static int ubx_recv_rinex (uint8_t *payload, unsigned len) return 0; } +char gps_svin_info[128]; + static int ubx_recv_tim_svin (uint8_t *ptr, unsigned len) { uint8_t valid, active; @@ -513,6 +532,9 @@ static int ubx_recv_tim_svin (uint8_t *ptr, unsigned len) printf ("TIM-SVIN dur %u var %u obs %u valid %02x active %02x\r\n", (unsigned) dur, (unsigned) var, (unsigned) obs, valid, active); + snprintf (gps_svin_info, sizeof (gps_svin_info) - 1, "TIM-SVIN dur %u var %u obs %u valid %02x active %02x", + (unsigned) dur, (unsigned) var, (unsigned) obs, valid, active); + display_report_svin (valid, active); return 0; diff --git a/app/lwip/lwipopts.h b/app/lwip/lwipopts.h index 7d208a3..ee49f7c 100644 --- a/app/lwip/lwipopts.h +++ b/app/lwip/lwipopts.h @@ -44,6 +44,7 @@ #define UDP_DEBUG LWIP_DBG_ON #define IP_DEBUG LWIP_DBG_ON #define ETHARP_DEBUG LWIP_DBG_ON +#define HTTPD_DEBUG LWIP_DBG_ON #define TIMERS_DEBUG LWIP_DBG_ON #define LWIP_DBG_TYPES_ON (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT) #define LWIP_DEBUG 1 @@ -97,7 +98,7 @@ a lot of data that needs to be copied, this should be set high. */ #define MEMP_NUM_TCP_SEG 12 /* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. */ -#define MEMP_NUM_SYS_TIMEOUT 4 +#define MEMP_NUM_SYS_TIMEOUT 6 #define PBUF_POOL_FREE_OOSEQ 0 @@ -111,26 +112,29 @@ a lot of data that needs to be copied, this should be set high. */ /* ---------- TCP options ---------- */ -#define LWIP_TCP 0 +#define LWIP_TCP 1 #define TCP_TTL 255 -/* Controls if TCP should queue segments that arrive out of - order. Define to 0 if your device is low on memory. */ -#define TCP_QUEUE_OOSEQ 0 +#define TCP_WND (4 * TCP_MSS) +#define TCP_MAXRTX 12 +#define TCP_SYNMAXRTX 6 +#define TCP_QUEUE_OOSEQ LWIP_TCP +#define LWIP_TCP_SACK_OUT 0 +#define LWIP_TCP_MAX_SACK_NUM 4 +#define TCP_MSS 536 +#define TCP_CALCULATE_EFF_SEND_MSS 1 +#define TCP_SND_BUF (2 * TCP_MSS) +#define TCP_SND_QUEUELEN ((4 * (TCP_SND_BUF) + (TCP_MSS - 1))/(TCP_MSS)) +#define TCP_SNDLOWAT LWIP_MIN(LWIP_MAX(((TCP_SND_BUF)/2), (2 * TCP_MSS) + 1), (TCP_SND_BUF) - 1) +#define TCP_SNDQUEUELOWAT LWIP_MAX(((TCP_SND_QUEUELEN)/2), 5) +#define TCP_OOSEQ_BYTES_LIMIT(pcb) TCP_OOSEQ_MAX_BYTES +#define TCP_OOSEQ_MAX_PBUFS 0 +#define TCP_OOSEQ_PBUFS_LIMIT(pcb) TCP_OOSEQ_MAX_PBUFS +#define TCP_LISTEN_BACKLOG 0 -/* TCP Maximum segment size. */ -#define TCP_MSS (MTU - 40) /* TCP_MSS = (Ethernet MTU - IP header size - TCP header size) */ -/* TCP sender buffer space (bytes). */ -#define TCP_SND_BUF (2*TCP_MSS) -/* TCP_SND_QUEUELEN: TCP sender buffer space (pbufs). This must be at least - as much as (2 * TCP_SND_BUF/TCP_MSS) for things to work. */ -#define TCP_SND_QUEUELEN (2* TCP_SND_BUF/TCP_MSS) - -/* TCP receive window. */ -#define TCP_WND (2*TCP_MSS) /* ---------- ICMP options ---------- */ @@ -207,6 +211,11 @@ The STM32F4x7 allows computing and verifying the IP, UDP, TCP and ICMP checksums #define LWIP_SOCKET 0 +#define LWIP_HTTPD_CUSTOM_FILES 1 +#define LWIP_HTTPD_FILE_STATE 0 + + + /* ---------------------------------------- ---------- Lwip Debug options ---------- diff --git a/app/lwip_glue.c b/app/lwip_glue.c index 7f63ada..72428ba 100644 --- a/app/lwip_glue.c +++ b/app/lwip_glue.c @@ -31,6 +31,7 @@ void start_lwip (void) dhcp_start (&if0); + httpd_init(); } static sys_prot_t ethernet_irq_enabled = 1; diff --git a/app/project.h b/app/project.h index d66122b..c2f9a56 100644 --- a/app/project.h +++ b/app/project.h @@ -51,8 +51,12 @@ #include #include #include + #include +#include +#include + #include "time_fn.h" #include "pins.h" @@ -62,6 +66,8 @@ #include "ubx.h" #include "gps.h" +#include "ptb.h" + #include "prototypes.h" //#define HZ 10000000 diff --git a/app/prototypes.h b/app/prototypes.h index b96a453..e763d3d 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -49,10 +49,11 @@ extern struct netif if0; extern uint32_t sys_now(void); extern void dispatch_lwip(void); extern void start_lwip(void); +extern sys_prot_t sys_arch_protect(void); +extern void sys_arch_unprotect(sys_prot_t lev); /* steth.c */ extern void steth_calculate_mac(void); extern void eth_isr(void); -extern void steth_isr(void); extern err_t steth_lwip_init(struct netif *netif); extern void steth_init(void); extern void steth_slow_tick(void); @@ -73,8 +74,8 @@ extern int main(void); /* time_fn.c */ extern UTC time_epoch_to_utc(EPOCH epoch); extern EPOCH time_utc_to_epoch(UTC u); -extern void utc_to_str(char *dst, UTC u); -extern void time_print_utc(const char *p, UTC u, const char *t); +extern void utc_to_str(char *dst, UTC *u); +extern void time_print_utc(const char *p, UTC *u, const char *t); extern void time_print_epoch(const char *p, EPOCH e, const char *t); extern double time_utc_to_tjd(UTC u); extern double time_utc_to_ra(UTC u); @@ -99,11 +100,15 @@ extern unsigned gps_sats_locked; extern unsigned gps_sats_with_e; extern int gps_initting; extern uint64_t gps_last_happy; +extern char gps_info[60]; extern void exti9_5_isr(void); extern double gps_lat; extern double gps_lon; +extern char gps_pos[128]; extern int gps_utc_diff; extern int gps_wday; +extern char gps_svinfo[4096]; +extern char gps_svin_info[128]; extern void gps_dispatch(void); extern int gps_init(void); extern int gps_almanac(void); @@ -167,6 +172,7 @@ extern uint64_t ref_get_irq(void); extern uint64_t ref_get(void); extern void ref_slow_tick(void); extern uint64_t make_happy(uint64_t abs, int64_t shift); +extern char ref_info[128]; extern void ref_dispatch(uint64_t edge, const char *src); extern void ref_set_offset(EPOCH epoch, uint64_t abs); extern EPOCH ref_decompose_diff(int64_t diff); @@ -175,6 +181,7 @@ extern EPOCH ref_decompose(uint64_t abs); extern int ptp_offset_known; extern uint64_t ptp_to_u64(uint32_t l, uint32_t h); extern uint64_t ptp_get(void); +extern char ptp_info[128]; extern void ptp_dispatch(uint64_t edge, const char *src); extern void ptp_set_offset(EPOCH epoch, uint64_t abs); extern EPOCH ptp_decompose_diff(int64_t diff); @@ -184,3 +191,6 @@ extern void ptp_slow_tick(void); extern void display_report_fix(char fix, char fix2); extern void display_report_svin(int valid, int active); extern void display_dispatch(void); +/* fs.c */ +extern int fs_open_custom(struct fs_file *file, const char *name); +extern void fs_close_custom(struct fs_file *file); diff --git a/app/ptp.c b/app/ptp.c index 026e6ec..6113d45 100644 --- a/app/ptp.c +++ b/app/ptp.c @@ -155,6 +155,8 @@ static uint64_t pll (int64_t obs_phase) } +char ptp_info[128]; + void ptp_dispatch (uint64_t edge, const char *src) @@ -167,6 +169,11 @@ void ptp_dispatch (uint64_t edge, const char *src) last_edge = edge; obs_phase = edge_to_phase (edge); + snprintf (ptp_info, sizeof (ptp_info) - 1, "PTP PLL: obs_f=%9d delta_phi=%5d f=%9d %s\n", + (int) obs_freq, + (int) obs_phase, + (int) ptp_freq, src); + #ifdef CHATTY_PLLS printf ("PTP PLL: obs_f=%9d delta_phi=%5d f=%9d %s\r\n", (int) obs_freq, diff --git a/app/ref.c b/app/ref.c index 6d335ce..ecd8018 100644 --- a/app/ref.c +++ b/app/ref.c @@ -351,6 +351,7 @@ static uint64_t pll (int64_t obs_phase) return pd; } +char ref_info[128]; void ref_dispatch (uint64_t edge, const char *src) @@ -374,6 +375,10 @@ void ref_dispatch (uint64_t edge, const char *src) // delta_f = obs_freq - ref_freq; + snprintf (ref_info, sizeof (ref_info) - 1, "REF PLL: obs_f=%9d delta_phi=%5d f=%9d %s\n", + (int) obs_freq, + (int) obs_phase, + (int) ref_freq, src); #ifdef CHATTY_PLLS printf ("REF PLL: obs_f=%9d delta_phi=%5d f=%9d %s\r\n", diff --git a/app/time_fn.c b/app/time_fn.c index 3e58854..fc3f829 100644 --- a/app/time_fn.c +++ b/app/time_fn.c @@ -207,25 +207,25 @@ EPOCH time_utc_to_epoch (UTC u) return ret; } -void utc_to_str (char *dst, UTC u) +void utc_to_str (char *dst, UTC *u) { const char *dname[] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat", "Sun"}; const char *mname[] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - sprintf (dst, "%s %04d-%s-%02d %02d:%02d:%02d.%09d", dname[u.wday], u.year, mname[u.month], u.mday, u.hour, u.minute, u.second, u.nanosecond); + sprintf (dst, "%s %04d-%s-%02d %02d:%02d:%02d.%09d", dname[u->wday], u->year, mname[u->month], u->mday, u->hour, u->minute, u->second, u->nanosecond); } -void time_print_utc (const char *p, UTC u, const char *t) +void time_print_utc (const char *p, UTC *u, const char *t) { const char *dname[] = {"Sun", "Mon", "Tue", "Wed", "Thr", "Fri", "Sat", "Sun"}; const char *mname[] = {"", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; - printf ("%s%s %04d-%s-%02d %02d:%02d:%02d.%09d %s\r\n", p ? p : "", dname[u.wday], u.year, mname[u.month], u.mday, u.hour, u.minute, u.second, u.nanosecond, t ? t : ""); + printf ("%s%s %04d-%s-%02d %02d:%02d:%02d.%09d %s\r\n", p ? p : "", dname[u->wday], u->year, mname[u->month], u->mday, u->hour, u->minute, u->second, u->nanosecond, t ? t : ""); } void time_print_epoch (const char *p, EPOCH e, const char *t) { UTC u = time_epoch_to_utc (e); - time_print_utc (p, u, t); + time_print_utc (p, &u, t); } -- cgit v1.2.3