From ae0195ab312388deb8466816375addc155eadad9 Mon Sep 17 00:00:00 2001 From: James McKenzie Date: Sat, 18 Feb 2023 18:44:57 +0000 Subject: add code for fetching epheredies and ublox assit data --- app/Makefile | 8 ++--- app/gps.c | 89 ++++++++++++++++++++++++++++++++++++++++++++++++-------- app/httpd.c | 4 +++ app/main.c | 2 +- app/project.h | 1 + app/prototypes.h | 3 ++ 6 files changed, 90 insertions(+), 17 deletions(-) (limited to 'app') diff --git a/app/Makefile b/app/Makefile index fddc03b..78f0d9b 100644 --- a/app/Makefile +++ b/app/Makefile @@ -31,7 +31,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 httpd.c alarm.c meteotime.c + ptp.c display.c httpd.c alarm.c meteotime.c ephemeris.c HSRCS= events.h gps.h project.h ring.h steth.h time_fn.h ubx.h @@ -100,9 +100,9 @@ LDLIBS+= -lm fish: ${OBJS} echo ${OBJS} -#HOST=clock-lnx +HOST=clock-lnx #HOST=10.32.91.140 -HOST=tick +#HOST=tick reset: @@ -148,7 +148,7 @@ debugfl: ${PROG}.elf protos: ${CSRCS} echo -n > prototypes.h - ${CPROTO} -E "${CPP} $(CPPFLAGS)" -e -v ${CSRCS} > prototypes.h.tmp + ${CPROTO} -E "${CPP} ${CPPFLAGS}" -D_Noreturn= -e -v ${CSRCS} > prototypes.h.tmp mv -f prototypes.h.tmp prototypes.h almanac.txt: diff --git a/app/gps.c b/app/gps.c index 7327435..a8b8099 100644 --- a/app/gps.c +++ b/app/gps.c @@ -111,6 +111,39 @@ static int ubx_recv_almanac (uint8_t *ptr, unsigned len) return 0; } + +static int ubx_recv_aid_eph (uint8_t *ptr, unsigned len) +{ + unsigned i; + uint32_t sv; + + ptr += ubx_get_u32 (ptr, &sv); + len -= 4; + + if ((sv<1) ||( sv>32)) return 0; + + i=sv-1; + + + ptr += ubx_get_u32 (ptr, &ephemeris[i].how); + len -= 4; + + printf("Received %d bytes of ephemeris for SV%d\r\n",len,(int) sv); + + if ((!len) ||( !ephemeris[i].how)) return 0 ; + + memcpy(&ephemeris[i].sf1,ptr,32); + len-=32; + ptr+=32; + memcpy(&ephemeris[i].sf2,ptr,32); + len-=32; + ptr+=32; + memcpy(&ephemeris[i].sf3,ptr,32); + + return 0; +} + + double gps_lat, gps_lon; char gps_pos[128]; @@ -603,7 +636,6 @@ ubx_recv (uint8_t class, uint8_t id, uint8_t *payload, unsigned len) } break; - case 0xd: switch (id) { case 0x4: @@ -637,6 +669,9 @@ ubx_recv (uint8_t class, uint8_t id, uint8_t *payload, unsigned len) case 0x30: ubx_recv_almanac (payload, len); break; + case 0x31: + ubx_recv_aid_eph(payload,len); + break; case 0x50: printf ("xfer ack\r\n"); @@ -815,7 +850,7 @@ static void gps_pps_dispatch (void) if (gps_happy > 30) { - chatty_gps = 0; + //chatty_gps = 0; pll_dispatch (gps_last_happy, abs, ptp, "GPS"); } @@ -830,14 +865,6 @@ static void gps_pps_dispatch (void) } -void -gps_dispatch (void) -{ - ubx_dispatch_search (-1, -1, NULL); - gps_pps_dispatch(); - -} - static void ubx_send (uint8_t class, uint8_t id, const void *_payload, unsigned len) { @@ -869,6 +896,28 @@ ubx_send (uint8_t class, uint8_t id, const void *_payload, unsigned len) } + +void +gps_dispatch (void) +{ +static uint32_t last_eph; +uint32_t t ; + + ubx_dispatch_search (-1, -1, NULL); + gps_pps_dispatch(); + + + +t=ticks-last_eph; +if (t>60000) { + printf("Requesting ephemeris data\r\n"); + gps_dump_eph(); + last_eph=ticks; +} + +} + + static int ubx_handshake (uint8_t class, uint8_t id, const void *payload, unsigned len) { @@ -1025,8 +1074,18 @@ static int ubx_cfg_sbas (uint8_t mode, uint8_t usage, uint8_t channels) ptr += ubx_put_u8 (ptr, mode); ptr += ubx_put_u8 (ptr, usage); ptr += ubx_put_u8 (ptr, channels); - ptr += ubx_put_u8 (ptr, 0x0); +#if 0 + ptr += ubx_put_u8 (ptr, 0x40 /*PRN158*/); + ptr += ubx_put_u32 (ptr, /* 0x1 PRN 120 | */ 0x8 /*PRN 123*/ | /* 0x40 PRN 126 | */ 0x10000 /*PRN136*/); +#else +#if 1 + ptr += ubx_put_u8 (ptr, 0x7f); + ptr += ubx_put_u32 (ptr, 0xffffffffU); +#else + ptr += ubx_put_u8 (ptr, 0x40 /*PRN158*/); ptr += ubx_put_u32 (ptr, /* 0x1 PRN 120 | */ 0x8 /*PRN 123*/ | /* 0x40 PRN 126 | */ 0x10000 /*PRN136*/); +#endif +#endif return ubx_handshake (0x06, 0x16, buf, (unsigned) (ptr - buf)); } @@ -1239,7 +1298,7 @@ gps_init (void) ubx_set_message_rate_port1 (0x0D, 0x04, 10); - ubx_cfg_sbas (1, 0x7, 2); + ubx_cfg_sbas (1, 0x7, 3); ubx_cfg_poll (0x6, 0x16); @@ -1315,6 +1374,12 @@ void gps_dump_almanac (void) } +void gps_dump_eph (void) +{ + ubx_send (0xb, 0x31, NULL, 0); +} + + #if 1 int gps_bs (void) { diff --git a/app/httpd.c b/app/httpd.c index b3776c3..71c62a4 100644 --- a/app/httpd.c +++ b/app/httpd.c @@ -270,6 +270,10 @@ int fs_open_custom (struct fs_file *file, const char *name) file->data = (const char *)meteotime_data; file->len=sizeof(meteotime_data); } + else if (!strcmp (name, "/ephemeris.dat")) { + file->data = (const char *)ephemeris; + file->len=sizeof(ephemeris); + } else { printf ("looking for url=%s, found nothing\n", name); return 0; diff --git a/app/main.c b/app/main.c index 7c36f32..3fe11eb 100644 --- a/app/main.c +++ b/app/main.c @@ -222,7 +222,7 @@ static void timer_setup (void) timer_slave_set_trigger (TIM2, TIM_SMCR_TS_ITR0); /*clock from timer 1*/ timer_enable_counter (TIM2); #else - /* New Scheme 10MHz -> TIM2_ETR */ + /* New Scheme 10MHz -> TIM2_ETR PA8->PA15*/ #define REFCLK_IN (GPIO15) #define REFCLK_IN_PORT GPIOA diff --git a/app/project.h b/app/project.h index 9c1c6f1..04959b0 100644 --- a/app/project.h +++ b/app/project.h @@ -66,6 +66,7 @@ #include "ring.h" #include "ubx.h" #include "gps.h" +#include "ephemeris.h" #include "ptb.h" diff --git a/app/prototypes.h b/app/prototypes.h index e502fd9..2fb6277 100644 --- a/app/prototypes.h +++ b/app/prototypes.h @@ -121,6 +121,7 @@ extern void gps_dispatch(void); extern int gps_init(void); extern int gps_almanac(void); extern void gps_dump_almanac(void); +extern void gps_dump_eph(void); extern int gps_bs(void); extern void gps_reset(void); /* hexdump.c */ @@ -209,3 +210,5 @@ 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); +/* ephemeris.c */ +extern Ephemeris ephemeris[32]; -- cgit v1.2.3