diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-02-24 13:39:12 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-02-24 13:39:12 -0500 |
commit | 0957e01b6047cc31bffec64f1a6426158e6f4d8d (patch) | |
tree | 1324f57dbd2c436312af16d0e529fef158e0e6c0 /gpsmon.c | |
parent | e0beddef34daa0690acd468ac6480c5df3bd9d0f (diff) | |
download | gpsd-0957e01b6047cc31bffec64f1a6426158e6f4d8d.tar.gz |
In gpsmon, refactor so PPS field updates are done by common code.
Diffstat (limited to 'gpsmon.c')
-rw-r--r-- | gpsmon.c | 33 |
1 files changed, 30 insertions, 3 deletions
@@ -47,9 +47,6 @@ extern const struct gps_type_t driver_nmea0183; /* These are public */ struct gps_device_t session; WINDOW *devicewin; -#ifdef NTP_ENABLE -struct timedelta_t time_offset; -#endif /* NTP_ENABLE */ bool serial; /* These are private */ @@ -62,6 +59,9 @@ static char *type_name; static size_t promptlen = 0; struct termios cooked, rare; struct fixsource_t source; +#ifdef NTP_ENABLE +struct timedelta_t time_offset; +#endif /* NTP_ENABLE */ #ifdef PASSTHROUGH_ENABLE /* no methods, it's all device window */ @@ -237,6 +237,33 @@ void toff_update(WINDOW *win, int y, int x) /*@+compdef@*/ #endif /* NTP_ENABLE */ +#ifdef PPS_ENABLE +void pps_update(WINDOW *win, int y, int x) +{ + /*@-compdef@*/ + /*@-type -noeffect@*/ /* splint is confused about struct timespec */ + struct timedelta_t ppstimes; + + if (pps_thread_lastpps(&session, &ppstimes) > 0) { + /* NOTE: can not use double here due to precision requirements */ + struct timespec timedelta; + TS_SUB( &timedelta, &ppstimes.clock, &ppstimes.real); + if ( 86400 < (long)labs(timedelta.tv_sec) ) { + /* more than one day off, overflow */ + /* need a bigger field to show it */ + (void)mvwprintw(win, y, x, "> 1 day"); + } else { + char buf[TIMESPEC_LEN]; + timespec_str( &timedelta, buf, sizeof(buf) ); + (void)mvwprintw(win, y, x, "%s", buf); + } + (void)wnoutrefresh(win); + } + /*@+type +noeffect@*/ + /*@+compdef@*/ +} +#endif /* PPS_ENABLE */ + /****************************************************************************** * * Curses I/O |