summaryrefslogtreecommitdiffstats
path: root/app/gps.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/gps.c')
-rw-r--r--app/gps.c105
1 files changed, 64 insertions, 41 deletions
diff --git a/app/gps.c b/app/gps.c
index 9fc60de..b0bc433 100644
--- a/app/gps.c
+++ b/app/gps.c
@@ -10,12 +10,12 @@
static int ubx_ack = 0;
static int ubx_ack_xfer = 0;
-static int current_ref_hz=1;
+static int current_ref_hz = 1;
int gps_locked;
int gps_happy;
-static char fix,fix2;
+static char fix, fix2;
static int32_t freq = 0;
static const int fish[] = { 1, 2, 3, 4, 5, 6, 7 };
@@ -72,47 +72,47 @@ ubx_recv_nav_status (uint8_t *ptr, unsigned len)
switch (gps_fix) {
case 0:
case 1:
- fix='-';
+ fix = '-';
gps_locked = 0;
break;
case 2:
- fix='2';
+ fix = '2';
gps_locked = 0;
break;
case 3:
- fix='L';
+ fix = 'L';
gps_locked = 1;
break;
case 4:
- fix='R';
+ fix = 'R';
gps_locked = 0;
break;
case 5:
- fix='T';
+ fix = 'T';
gps_locked = 0;
break;
default:
- fix='?';
+ fix = '?';
gps_locked = 0;
}
switch (flags & 3) {
case 0:
case 2:
- fix2='!';
+ fix2 = '!';
break;
case 1:
- fix2='-';
+ fix2 = '-';
break;
case 3:
- fix2='D';
+ fix2 = 'D';
if (gps_locked == 1)
gps_locked = 2;
@@ -120,11 +120,11 @@ ubx_recv_nav_status (uint8_t *ptr, unsigned len)
break;
default:
- fix2='?';
+ fix2 = '?';
}
-// printf ("fix: %c%c\r\n",fix,fix2);
+ // printf ("fix: %c%c\r\n",fix,fix2);
if ((gps_locked) && (gps_happy < 10000))
@@ -152,7 +152,7 @@ ubx_recv_clock_stats (uint8_t *ptr, unsigned len)
ptr += ubx_get_u32 (ptr, &d); //time acc estimate
ptr += ubx_get_i32 (ptr, &freq); //freq acc estimate
-// printf ("TCXO %+8dE-12\r\n", (int) freq);
+ // printf ("TCXO %+8dE-12\r\n", (int) freq);
#if 0
sprintf (buf, "TCXO %+8dE-12", (int) freq);
lcd_erase_line (18, 0);
@@ -185,7 +185,26 @@ ubx_recv_utc (uint8_t *ptr, unsigned len)
ptr += ubx_get_u8 (ptr, &min);
ptr += ubx_get_u8 (ptr, &sec);
-// printf ("gps %02d:%02d:%02d %09d\r\n", (int) hour, (int) min, (int) sec, (int) nano);
+// printf ("gps %02d:%02d:%02d %09d\r\n", (int) hour, (int) min, (int) sec, (int) nano);
+
+{
+ UTC u;
+ EPOCH gps_time;
+
+ u.jday = 0;
+ u.year = year;
+ u.month = month;
+ u.mday = day;
+ u.hour = hour;
+ u.minute = min;
+ u.second = sec;
+ u.nanosecond = 0;
+
+ gps_time = time_utc_to_epoch (u);
+
+ pll_set_offset (gps_time, abs);
+}
+
#if 0
sprintf (buf, "%+6dE-12 %02d%02d%02d", (int) freq,
@@ -266,8 +285,9 @@ ubx_recv (uint8_t class, uint8_t id, uint8_t *payload, unsigned len)
default:
printf ("RX> %02x.%02x (%d bytes)\r\n", class, id, len);
- if (class!=0x03)
- hexdump (payload, len);
+
+ if (class != 0x03)
+ hexdump (payload, len);
}
@@ -401,8 +421,8 @@ ubx_dispatch_search (int s_class, int s_id, unsigned *len_ptr)
static void gps_pps_dispatch (void)
{
char buf[80];
- uint64_t abs;
uint32_t now;
+ uint64_t abs;
int v;
EPOCH e;
UTC u;
@@ -417,22 +437,25 @@ static void gps_pps_dispatch (void)
if (!v) return;
-
-
- abs = abs_extend (now);
- pll_dispatch(abs);
+ abs=abs_extend(now);
+
+
+
+ pll_dispatch (abs);
e = pll_decompose (abs);
- u=time_epoch_to_utc(e);
- printf ("GPS %02d:%02d:%02d.%09d Fix:%c%c TXCO %+8dE-12\r\n",
+ u = time_epoch_to_utc (e);
+
+ printf (" GPS %02d:%02d:%02d.%09d Fix:%c%c TXCO %+8dE-12\r\n",
u.hour,
u.minute,
u.second,
u.nanosecond,
- fix,fix2,(int) freq);
+ fix, fix2, (int) freq);
+ time_print_epoch ("GPS : ", e);
}
@@ -491,7 +514,7 @@ ubx_handshake (uint8_t class, uint8_t id, const void *payload, unsigned len)
if (ticks > timeout) {
printf ("GPS timeout resending packet\r\n");
- usart3_drain();
+ usart3_drain();
ubx_send (class, id, payload, len);
timeout = ticks + TIMEOUT;
}
@@ -512,7 +535,7 @@ ubx_handshake_xfer (uint8_t class, uint8_t id, const void *payload,
uint32_t timeout;
ubx_ack_xfer = 0;
-// usart3_drain();
+ // usart3_drain();
ubx_send (class, id, payload, len);
@@ -523,7 +546,7 @@ ubx_handshake_xfer (uint8_t class, uint8_t id, const void *payload,
if (ticks > timeout) {
printf ("GPS timeout resending packet\r\n");
-// usart3_drain();
+ // usart3_drain();
ubx_send (class, id, payload, len);
timeout = ticks + TIMEOUT;
}
@@ -609,7 +632,7 @@ gps_set_ref (int ref_hz)
ptr += ubx_put_u8 (ptr, 0); //reserved
ptr += ubx_put_u16 (ptr, 0); //reserved
-// ptr += ubx_put_u16 (ptr, 32); //ant cable delay ns
+ // ptr += ubx_put_u16 (ptr, 32); //ant cable delay ns
ptr += ubx_put_u16 (ptr, 0); //ant cable delay ns
ptr += ubx_put_u16 (ptr, 0); //rf group delay ns
ptr += ubx_put_u32 (ptr, 1000000 / ref_hz); //period unlocked/us
@@ -668,9 +691,9 @@ gps_init (void)
printf ("configured GNSS protocol\r\n");
#if 1
-ptr = buf;
- ptr += ubx_put_u16 (ptr, 0x14);
- ptr += ubx_put_u16 (ptr, 0x00);
+ ptr = buf;
+ ptr += ubx_put_u16 (ptr, 0x14);
+ ptr += ubx_put_u16 (ptr, 0x00);
ubx_handshake (0x06, 0x13, buf, (unsigned) (ptr - buf));
printf ("configured antenna pins\r\n");
@@ -738,12 +761,12 @@ ptr = buf;
#endif
#if 1
-ptr = buf;
- ptr += ubx_put_u8 (ptr, 0x1);
- ptr += ubx_put_u8 (ptr, 0x7);
- ptr += ubx_put_u8 (ptr, 0x1);
- ptr += ubx_put_u8 (ptr, 0xf);
- ptr += ubx_put_u32 (ptr, 0xffffffff);
+ ptr = buf;
+ ptr += ubx_put_u8 (ptr, 0x1);
+ ptr += ubx_put_u8 (ptr, 0x7);
+ ptr += ubx_put_u8 (ptr, 0x1);
+ ptr += ubx_put_u8 (ptr, 0xf);
+ ptr += ubx_put_u32 (ptr, 0xffffffff);
ubx_handshake (0x06, 0x16, buf, (unsigned) (ptr - buf));
printf ("configured SBAS\r\n");
@@ -809,10 +832,10 @@ gps_reset (void)
#define RPOS (1UL << 4)
#define RRTC (1UL << 8)
- ubx_cfg_rst (REPHEMERIDIES | RALMANAC | RPOS | RRTC);
+ ubx_cfg_rst (REPHEMERIDIES | RALMANAC | RPOS | RRTC);
-delay_ms(1000);
-usart3_drain();
+ delay_ms (1000);
+ usart3_drain();
printf ("Testing GNSS...\r\n");