summaryrefslogtreecommitdiff
path: root/libgpsd_core.c
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2014-08-22 16:14:39 -0400
committerEric S. Raymond <esr@thyrsus.com>2014-08-22 16:15:43 -0400
commite6d622fabf16b0ca90b18c8b30bfcf95bd2bf3af (patch)
treef6df2c5d43d3b0a49c8264fdf965bd05140fc40c /libgpsd_core.c
parentd1a9c349f3b868d52f015361ccf1cb2fad42e282 (diff)
downloadgpsd-e6d622fabf16b0ca90b18c8b30bfcf95bd2bf3af.tar.gz
Re-integrate Miroslav's support for large PPS offsets.
The factoring on this could use some cleanup. All regression tests pass. PPS is live in both gpsd and gpsmon.
Diffstat (limited to 'libgpsd_core.c')
-rw-r--r--libgpsd_core.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/libgpsd_core.c b/libgpsd_core.c
index 1c2c3981..12561dee 100644
--- a/libgpsd_core.c
+++ b/libgpsd_core.c
@@ -1641,3 +1641,34 @@ void gpsd_zero_satellites( /*@out@*/ struct gps_data_t *out)
gps_clear_dop(&out->dop);
#endif
}
+
+void ntpshm_latch(struct gps_device_t *device, struct timedrift_t *td)
+/* latch the fact that we've saved a fix */
+{
+ double fix_time, integral, fractional;
+
+#ifdef HAVE_CLOCK_GETTIME
+ /*@i2@*/(void)clock_gettime(CLOCK_REALTIME, &td->clock);
+#else
+ struct timeval clock_tv;
+ (void)gettimeofday(&clock_tv, NULL);
+ TVTOTS(&td->clock, &clock_tv);
+#endif /* HAVE_CLOCK_GETTIME */
+ fix_time = device->newdata.time;
+ /* assume zero when there's no offset method */
+ if (device->device_type == NULL
+ || device->device_type->time_offset == NULL)
+ fix_time += 0.0;
+ else
+ fix_time += device->device_type->time_offset(device);
+ /* it's ugly but timestamp_t is double */
+ fractional = modf(fix_time, &integral);
+ /*@-type@*/ /* splint is confused about struct timespec */
+ td->real.tv_sec = (time_t)integral;
+ td->real.tv_nsec = (long)(fractional * 1e+9);
+ /*@+type@*/
+ device->last_fixtime.real = device->newdata.time;
+ device->last_fixtime.clock = td->clock.tv_sec + td->clock.tv_nsec / 1e9;
+}
+
+/* end */