summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2015-02-10 13:42:29 -0500
committerEric S. Raymond <esr@thyrsus.com>2015-02-10 13:42:29 -0500
commit0231f6359065ba49230051474f977369d5a58e95 (patch)
treeb0bb0f41a5176eed0ea7937d73417b27e86ab363
parent029b5e46b08810d0dcf65456edec877c1bda1105 (diff)
downloadgpsd-0231f6359065ba49230051474f977369d5a58e95.tar.gz
Fix the gpsmon display-trashing problem; add some documentation and asserts.
All regression tests pass.
-rw-r--r--gpsmon.c7
-rw-r--r--libgpsd_core.c7
-rw-r--r--ppsthread.c16
3 files changed, 15 insertions, 15 deletions
diff --git a/gpsmon.c b/gpsmon.c
index f01d16f6..de29f005 100644
--- a/gpsmon.c
+++ b/gpsmon.c
@@ -15,6 +15,7 @@
#include <signal.h>
#include <stdarg.h>
#include <time.h>
+#include <math.h>
#include <sys/time.h> /* expected to declare select(2) a la SuS */
#include <sys/types.h>
#include <sys/stat.h>
@@ -744,9 +745,9 @@ static void gpsmon_hook(struct gps_device_t *device, gps_mask_t changed UNUSED)
report_unlock();
#ifdef NTPSHM_ENABLE
- /* Update the last fix time seen for PPS. */
- /* FIXME! ntpshm_latch() need device->newdata.time to be set */
- ntpshm_latch(device, &td);
+ /* Update the last fix time seen for PPS if we've actually seen one. */
+ if (!isnan(device->newdata.time))
+ ntpshm_latch(device, &td);
#endif /* NTPSHM_ENABLE */
}
/*@+observertrans +nullpass +globstate +compdef +uniondef@*/
diff --git a/libgpsd_core.c b/libgpsd_core.c
index e0d605a0..b7316282 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -1650,6 +1650,9 @@ void ntpshm_latch(struct gps_device_t *device, struct timedrift_t /*@out@*/*td)
{
double fix_time, integral, fractional;
+ /* this should be an invariant of the way this function is called */
+ assert(!isnan(device->newdata.time));
+
#ifdef HAVE_CLOCK_GETTIME
/*@i2@*/(void)clock_gettime(CLOCK_REALTIME, &td->clock);
#else
@@ -1658,10 +1661,6 @@ void ntpshm_latch(struct gps_device_t *device, struct timedrift_t /*@out@*/*td)
TVTOTS(&td->clock, &clock_tv);
#endif /* HAVE_CLOCK_GETTIME */
fix_time = device->newdata.time;
- if ( isnan( device->newdata.time ) ) {
- /* this should not happen, but it does */
- fix_time = 0.0;
- }
/* assume zero when there's no offset method */
if (device->device_type == NULL
|| device->device_type->time_offset == NULL)
diff --git a/ppsthread.c b/ppsthread.c
index 7a441573..ee05d3a1 100644
--- a/ppsthread.c
+++ b/ppsthread.c
@@ -370,14 +370,14 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg)
/*@ -ignoresigns */
/* end of time critical section */
- if ( isnan( last_fixtime_real ) ) {
- gpsd_report(&session->context->errout, LOG_ERROR,
- "PPS last_fixtime_real is NAN\n");
- /* this should never happen, but it does. */
- last_fixtime_real = 0.0;
- session->last_fixtime.real = 0.0;
- }
-
+ /*
+ * If there was no valid time from the GPS when the PPS event was
+ * asserted, we can do nothing further. It will be strange if
+ * this ever actually happens, since we expect PPS to be asserted
+ * only after a valid fix - which should yield time.
+ */
+ if (isnan(last_fixtime_real))
+ continue;
/* mask for monitored lines */
state &= PPS_LINE_TIOC;