diff options
-rw-r--r-- | gpsmon.c | 7 | ||||
-rw-r--r-- | libgpsd_core.c | 7 | ||||
-rw-r--r-- | ppsthread.c | 16 |
3 files changed, 15 insertions, 15 deletions
@@ -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; |