diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2015-02-24 13:24:42 -0500 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2015-02-24 13:24:42 -0500 |
commit | e0beddef34daa0690acd468ac6480c5df3bd9d0f (patch) | |
tree | 73865c3ab1753a4d76ba19b5313f7c59430a397b | |
parent | 0fdf858fa62cdd419dd31dacdb122f9d7b04b29b (diff) | |
download | gpsd-e0beddef34daa0690acd468ac6480c5df3bd9d0f.tar.gz |
gpsmon: refactoring step, make utility function for TOS display.
-rw-r--r-- | gpsmon.c | 25 | ||||
-rw-r--r-- | gpsmon.h | 1 | ||||
-rw-r--r-- | monitor_nmea0183.c | 20 |
3 files changed, 27 insertions, 19 deletions
@@ -212,6 +212,31 @@ static void cond_hexdump(/*@out@*/char *buf2, size_t len2, } /*@+compdef +mustdefine@*/ +#ifdef NTP_ENABLE +/*@-compdef@*/ +/*@-type -noeffect@*/ /* splint is confused about struct timespec */ +void toff_update(WINDOW *win, int y, int x) +{ + if (time_offset.real.tv_sec != 0) + { + /* NOTE: can not use double here due to precision requirements */ + struct timespec timedelta; + TS_SUB(&timedelta, &time_offset.clock, &time_offset.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); + } + } +} +/*@+type +noeffect@*/ +/*@+compdef@*/ +#endif /* NTP_ENABLE */ + /****************************************************************************** * * Curses I/O @@ -37,6 +37,7 @@ 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 */ #endif /* _GPSD_GPSMON_H_ */ diff --git a/monitor_nmea0183.c b/monitor_nmea0183.c index 39eae9d7..8ba58882 100644 --- a/monitor_nmea0183.c +++ b/monitor_nmea0183.c @@ -320,25 +320,7 @@ static void nmea_update(void) } #ifdef NTP_ENABLE - /*@-compdef@*/ - /*@-type -noeffect@*/ /* splint is confused about struct timespec */ - if (time_offset.real.tv_sec != 0) - { - /* NOTE: can not use double here due to precision requirements */ - struct timespec timedelta; - TS_SUB(&timedelta, &time_offset.clock, &time_offset.real); - if ( 86400 < (long)labs(timedelta.tv_sec) ) { - /* more than one day off, overflow */ - /* need a bigger field to show it */ - (void)mvwprintw(gpgsawin, TOFF_LINE, 7, "> 1 day"); - } else { - char buf[TIMESPEC_LEN]; - timespec_str( &timedelta, buf, sizeof(buf) ); - (void)mvwprintw(gpgsawin, TOFF_LINE, 7, "%s", buf); - } - } - /*@+type +noeffect@*/ - /*@+compdef@*/ + toff_update(gpgsawin, TOFF_LINE, 7); #endif /* NTP_ENABLE */ if (strcmp(fields[0], "GPGGA") == 0 |