summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-02-24 13:39:12 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-02-24 13:39:12 -0500
commit0957e01b6047cc31bffec64f1a6426158e6f4d8d (patch)
tree1324f57dbd2c436312af16d0e529fef158e0e6c0
parente0beddef34daa0690acd468ac6480c5df3bd9d0f (diff)
downloadgpsd-0957e01b6047cc31bffec64f1a6426158e6f4d8d.tar.gz
In gpsmon, refactor so PPS field updates are done by common code.
-rw-r--r--gpsmon.c33
-rw-r--r--gpsmon.h4
-rw-r--r--monitor_nmea0183.c23
-rw-r--r--monitor_sirf.c23
-rw-r--r--monitor_ubx.c23
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 */
}