From 0957e01b6047cc31bffec64f1a6426158e6f4d8d Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Tue, 24 Feb 2015 13:39:12 -0500 Subject: In gpsmon, refactor so PPS field updates are done by common code. --- gpsmon.c | 33 ++++++++++++++++++++++++++++++--- gpsmon.h | 4 +++- monitor_nmea0183.c | 23 +---------------------- monitor_sirf.c | 23 +---------------------- monitor_ubx.c | 23 +---------------------- 5 files changed, 36 insertions(+), 70 deletions(-) diff --git a/gpsmon.c b/gpsmon.c index 5c19f4c6..dfa1d490 100644 --- a/gpsmon.c +++ b/gpsmon.c @@ -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 diff --git a/gpsmon.h b/gpsmon.h index f05e6012..95820272 100644 --- a/gpsmon.h +++ b/gpsmon.h @@ -36,9 +36,11 @@ extern WINDOW *devicewin; extern struct gps_device_t session; extern bool serial; /* True - direct mode, False - daemon mode */ #ifdef NTP_ENABLE -extern struct timedelta_t time_offset; void toff_update(WINDOW *, int, int); #endif /* NTP_ENABLE */ +#ifdef PPS_ENABLE +void pps_update(WINDOW *, int, int); +#endif /* PPS_ENABLE */ #endif /* _GPSD_GPSMON_H_ */ /* gpsmon.h ends here */ diff --git a/monitor_nmea0183.c b/monitor_nmea0183.c index 8ba58882..06acfa66 100644 --- a/monitor_nmea0183.c +++ b/monitor_nmea0183.c @@ -215,9 +215,6 @@ static void monitor_satlist(WINDOW *win, int y, int x) static void nmea_update(void) { char **fields; -#ifdef PPS_ENABLE - struct timedelta_t ppstimes; -#endif /* PPS_ENABLE */ assert(cookedwin != NULL); assert(nmeawin != NULL); @@ -348,25 +345,7 @@ static void nmea_update(void) } #ifdef PPS_ENABLE - /*@-compdef@*/ - /*@-type -noeffect@*/ /* splint is confused about struct timespec */ - 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(gpgsawin, PPS_LINE, 6, "> 1 day"); - } else { - char buf[TIMESPEC_LEN]; - timespec_str( &timedelta, buf, sizeof(buf) ); - (void)mvwprintw(gpgsawin, PPS_LINE, 6, "%s", buf); - } - (void)wnoutrefresh(gpgsawin); - } - /*@+type +noeffect@*/ - /*@+compdef@*/ + pps_update(gpgsawin, PPS_LINE, 6); #endif /* PPS_ENABLE */ } diff --git a/monitor_sirf.c b/monitor_sirf.c index 42fbb189..5efbcc65 100644 --- a/monitor_sirf.c +++ b/monitor_sirf.c @@ -282,9 +282,6 @@ static void sirf_update(void) size_t len; uint8_t dgps; char tbuf[JSON_DATE_MAX+1]; -#ifdef PPS_ENABLE - struct timedelta_t ppstimes; -#endif /* PPS_ENABLE */ /* splint pacification */ assert(mid2win!=NULL && mid27win != NULL); @@ -588,25 +585,7 @@ static void sirf_update(void) /*@ +nullpass -nullderef @*/ #ifdef PPS_ENABLE - /*@-compdef@*/ - /*@-type -noeffect@*/ /* splint is confused about struct timespec */ - if (pps_thread_lastpps(&session, &ppstimes) > 0) { - /* NOTE: cannot 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(mid7win, 2, 28, "> 1 day"); - } else { - char buf2[TIMESPEC_LEN]; - timespec_str( &timedelta, buf2, sizeof(buf2) ); - (void)mvwprintw(mid7win, 2, 32, "%s", buf2); - } - (void)wnoutrefresh(mid7win); - } - /*@+type +noeffect@*/ - /*@+compdef@*/ + pps_update(mid7win, 2, 32); #endif /* PPS_ENABLE */ } diff --git a/monitor_ubx.c b/monitor_ubx.c index 9ad21286..6766524f 100644 --- a/monitor_ubx.c +++ b/monitor_ubx.c @@ -233,9 +233,6 @@ static void ubx_update(void) unsigned char *buf; size_t data_len; unsigned short msgid; -#ifdef PPS_ENABLE - struct timedelta_t ppstimes; -#endif /* PPS_ENABLE */ buf = session.lexer.outbuffer; msgid = (unsigned short)((buf[2] << 8) | buf[3]); @@ -255,25 +252,7 @@ static void ubx_update(void) } #ifdef PPS_ENABLE - /*@-compdef@*/ - /*@-type -noeffect@*/ /* splint is confused about struct timespec */ - 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(ppswin, 1, 6, "> 1 day"); - } else { - char buf2[TIMESPEC_LEN]; - timespec_str( &timedelta, buf2, sizeof(buf2) ); - (void)mvwprintw(ppswin, 1, 6, "%s", buf2); - } - (void)wnoutrefresh(ppswin); - } - /*@+type +noeffect@*/ - /*@+compdef@*/ + pps_update(ppswin, 1, 6); #endif /* PPS_ENABLE */ } -- cgit v1.2.1