altos: Add ao_gps_utc_tick
authorKeith Packard <keithp@keithp.com>
Sun, 13 Nov 2022 07:34:34 +0000 (23:34 -0800)
committerKeith Packard <keithp@keithp.com>
Sun, 13 Nov 2022 08:17:32 +0000 (00:17 -0800)
This indicates which tick is associated with the UTC time found
in the current ao gps data

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_gps_skytraq.c
src/drivers/ao_gps_ublox.c
src/kernel/ao.h

index 3a253eea69559fb19731824c46866995e5b75baa..00c6932fc646e954d4f65c5263501632c5f4fd47 100644 (file)
@@ -40,6 +40,7 @@ static uint8_t ao_gps_cksum;
 static uint8_t ao_gps_error;
 
 AO_TICK_TYPE ao_gps_tick;
+AO_TICK_TYPE ao_gps_utc_tick;
 struct ao_telemetry_location   ao_gps_data;
 struct ao_telemetry_satellite  ao_gps_tracking_data;
 
@@ -296,7 +297,7 @@ ao_nmea_gga(void)
        if (!ao_gps_error) {
                ao_mutex_get(&ao_gps_mutex);
                ao_gps_new |= AO_GPS_NEW_DATA;
-               ao_gps_tick = ao_gps_next_tick;
+               ao_gps_tick = ao_gps_utc_tick = ao_gps_next_tick;
                memcpy(&ao_gps_data, &ao_gps_next, sizeof (ao_gps_data));
                ao_mutex_put(&ao_gps_mutex);
                ao_wakeup(&ao_gps_new);
index 607e9ea9402fcc4bd5f6da92246edbe76bce8fa2..3d615e9c933f14b260f3cd0fb75faeec68073a3c 100644 (file)
@@ -29,6 +29,7 @@
 uint8_t ao_gps_new;
 uint8_t ao_gps_mutex;
 AO_TICK_TYPE ao_gps_tick;
+AO_TICK_TYPE ao_gps_utc_tick;
 struct ao_telemetry_location   ao_gps_data;
 struct ao_telemetry_satellite  ao_gps_tracking_data;
 
@@ -398,6 +399,7 @@ ao_ublox_parse_nav_svinfo(void)
  * NAV-TIMEUTC message parsing
  */
 static struct nav_timeutc {
+       int32_t         nano;
        uint16_t        year;
        uint8_t         month;
        uint8_t         day;
@@ -412,7 +414,8 @@ static struct nav_timeutc {
 #define NAV_TIMEUTC_VALID_UTC  2
 
 static const struct ublox_packet_parse nav_timeutc_packet[] = {
-       { UBLOX_DISCARD, 12 },                                          /* 0 iTOW, tAcc, nano */
+       { UBLOX_DISCARD, 8 },                                           /* 0 iTOW, tAcc */
+       { UBLOX_U32, offsetof(struct nav_timeutc, nano) },              /* 8 nano */
        { UBLOX_U16, offsetof(struct nav_timeutc, year) },              /* 12 year */
        { UBLOX_U8, offsetof(struct nav_timeutc, month) },              /* 14 month */
        { UBLOX_U8, offsetof(struct nav_timeutc, day) },                /* 15 day */
@@ -722,7 +725,7 @@ ao_gps(void)
                        case UBLOX_NAV_TIMEUTC:
                                ao_mutex_get(&ao_gps_mutex);
                                ao_gps_tick = solution_tick;
-
+                               ao_gps_utc_tick = packet_start_tick + (AO_TICK_TYPE) AO_NS_TO_TICKS(nav_timeutc.nano);
                                ao_gps_data.flags = 0;
                                ao_gps_data.flags |= AO_GPS_RUNNING;
                                if (nav_sol.gps_fix & (1 << NAV_SOL_FLAGS_GPSFIXOK)) {
index 9ca2c60eac711c94734d199eca9603ac98ec5169..d714cecbd15e508c3705c0e6751ecae5db2bb475 100644 (file)
@@ -113,6 +113,7 @@ extern volatile AO_TICK_TYPE ao_tick_count;
 #endif
 #define AO_MS_TO_TICKS(ms)     ((ms) / (1000 / AO_HERTZ))
 #define AO_SEC_TO_TICKS(s)     ((AO_TICK_TYPE) (s) * AO_HERTZ)
+#define AO_NS_TO_TICKS(ns)     ((ns) / (1000000000L / AO_HERTZ))
 
 /* Returns the current time in ticks */
 AO_TICK_TYPE
@@ -390,6 +391,7 @@ ao_spi_slave(void);
 
 extern uint8_t ao_gps_new;
 extern AO_TICK_TYPE ao_gps_tick;
+extern AO_TICK_TYPE ao_gps_utc_tick;
 extern uint8_t ao_gps_mutex;
 extern struct ao_telemetry_location ao_gps_data;
 extern struct ao_telemetry_satellite ao_gps_tracking_data;