summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames McKenzie <root@ka-ata-killa.panaceas.james.local>2023-02-18 18:44:57 +0000
committerJames McKenzie <root@ka-ata-killa.panaceas.james.local>2023-02-18 18:44:57 +0000
commitae0195ab312388deb8466816375addc155eadad9 (patch)
tree1638133d5908a0cc977da3f7e08bffa5a521f4a5
parent86d61b9e775d615f210b79e4f69dbc3d62c885ea (diff)
downloadclock-ae0195ab312388deb8466816375addc155eadad9.tar.gz
clock-ae0195ab312388deb8466816375addc155eadad9.tar.bz2
clock-ae0195ab312388deb8466816375addc155eadad9.zip
add code for fetching epheredies and ublox assit data
-rw-r--r--app/Makefile8
-rw-r--r--app/gps.c89
-rw-r--r--app/httpd.c4
-rw-r--r--app/main.c2
-rw-r--r--app/project.h1
-rw-r--r--app/prototypes.h3
-rwxr-xr-xmetotime/decode.pl47
7 files changed, 125 insertions, 29 deletions
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];
diff --git a/metotime/decode.pl b/metotime/decode.pl
index 9962c75..f2e4fd0 100755
--- a/metotime/decode.pl
+++ b/metotime/decode.pl
@@ -674,8 +674,15 @@ my @cycle_4_lut = (
my @cycle_2_lut = ( "Forecast day 1", "Forecast day 2", );
-sub decode($$$) {
- my ( $dt, $mins_since_midnight, $bits ) = @_;
+sub match($$)
+{
+my ($a,$re)=@_;
+return 1 if ($a =~/\Q$re/);
+return 0;
+}
+
+sub decode($$$$$) {
+ my ( $dt, $mins_since_midnight, $bits, $string, $where ) = @_;
$mins_since_midnight = int( ( $mins_since_midnight - 1 ) / 3 );
@@ -683,30 +690,46 @@ sub decode($$$) {
my $region = $mins_since_midnight % 60;
my $day = int( $cycle / 2 );
+ my $region_str=$location_lut[$region];
+
my $w = decode_bits( $bits, $cycle % 2 );
if ( $cycle < 7 ) {
- print "region: ", $location_lut[$region], ", cycle: ",
+
+ if (match($region_str,$where)) {
+ print $string,"\n";
+ print "region: ", $region_str, ", cycle: ",
$cycle_4_lut[$cycle], ", when: ", time_to_string( $dt, $day ), "\n";
print_prognosis($w);
print_rest($w);
+}
}
else {
- print "region: ", $location_lut[$region], ", cycle: ",
+ my $sub_region = $region % 30;
+ $sub_region += 60;
+ my $sub_region_str = $location_lut[$sub_region];
+
+ if (match($region_str,$where) or match($sub_region_str,$where)) {
+ print $string,"\n";
+ }
+
+ if (match($region_str,$where)) {
+ print "region: ", $region_str, ", cycle: ",
$cycle_4_lut[$cycle], ", when: ", time_to_string( $dt, $day ), "\n";
print_rest($w);
+ }
- my $sub_region = $region % 30;
+ if (match($sub_region_str,$where)) {
my $sub_cycle = int( $region / 30 );
my $sub_day = 1 + $sub_cycle;
- $sub_region += 60;
- print "region: ", $location_lut[$sub_region], ", cycle: ",
+ print "region: ", $sub_region_str, ", cycle: ",
$cycle_2_lut[$sub_cycle], ", when: ",
time_to_string( $dt, $sub_day ), "\n";
print_prognosis($w);
+ }
}
@@ -717,7 +740,7 @@ sub decode($$$) {
# Step 1, fetch the squished up data for the last 24 hours from the clock
# and reconstruct the whole data stream
-my $bin = get("http://tock/meteotime.dat");
+my $bin = get("http://clock2k.hamachi.james.internal/meteotime.dat");
my $bs = unpack( 'b*', $bin );
my $d = [];
@@ -775,7 +798,7 @@ for ( my $i = 0 ; $i < ( $sl - 2 ) ; ++$i ) {
unless ( defined $plain ) {
my $msg = sprintf( "Bad data at %02d:%02d", $hour, $min );
- print STDERR "BAD DATA $msg\n";
+# print STDERR "BAD DATA $msg\n";
next;
}
next unless defined $plain;
@@ -786,9 +809,9 @@ for ( my $i = 0 ; $i < ( $sl - 2 ) ; ++$i ) {
day => $day
);
- printf "%04d-%02d-%02d %02d:%02d bits: %s\n", $year, $month, $day,
- $hour, $min, b4($plain);
+ my $bits= sprintf("%04d-%02d-%02d %02d:%02d bits: %s", $year, $month, $day,
+ $hour, $min, b4($plain));
- decode( $dt, $mins_since_midnight, $plain );
+ decode( $dt, $mins_since_midnight, $plain, $bits, $ARGV[0] );
}