From 907b55b210310ca034730fb11869f4b131fcba08 Mon Sep 17 00:00:00 2001 From: "Eric S. Raymond" Date: Mon, 12 Apr 2010 17:31:30 -0400 Subject: Refactor serial ntpshm_put() calls. These calls move out of scattered places in the drivers into one spot in libgpsd_core.c where they can be guarded with consistent validity checks. Time offset is now computed by a new driver method, ntp_offset(), which has access through the session structure to the baud rate, the tag of the sentence last received, etc. If the ntp_offset() method returns NAN, no notification is shipped. The logic of these methods replicates the sentence and baud-rate specific computations that were embedded in individual sentence methods before. All regression tests pass. --- driver_zodiac.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'driver_zodiac.c') diff --git a/driver_zodiac.c b/driver_zodiac.c index 1b41bd5f..ba7447e3 100644 --- a/driver_zodiac.c +++ b/driver_zodiac.c @@ -161,14 +161,6 @@ static gps_mask_t handle1000(struct gps_device_t *session) session->newdata.time = (double)mkgmtime(&unpacked_date) + subseconds; /*@ +compdef */ -#ifdef NTPSHM_ENABLE - /* Removing/changing the magic number below is likely to disturb - * the handling of the 1pps signal from the gps device. The regression - * tests and simple gps applications do not detect this. A live test - * with the 1pps signal active is required. */ - if (session->context->enable_ntpshm && session->newdata.mode > MODE_NO_FIX) - (void)ntpshm_put(session, session->newdata.time, 1.1); -#endif /*@ -type @*/ session->newdata.latitude = ((long)getzlong(27)) * RAD_2_DEG * 1e-8; session->newdata.longitude = ((long)getzlong(29)) * RAD_2_DEG * 1e-8; @@ -516,6 +508,17 @@ static bool zodiac_speed_switch(struct gps_device_t *session, } #endif /* ALLOW_RECONFIGURE */ +#ifdef NTPSHM_ENABLE +static double zodiac_ntp_offset(struct gps_device_t *session) +{ + /* Removing/changing the magic number below is likely to disturb + * the handling of the 1pps signal from the gps device. The regression + * tests and simple gps applications do not detect this. A live test + * with the 1pps signal active is required. */ + return 1.1; +} +#endif /* NTPSHM_ENABLE */ + /* this is everything we export */ const struct gps_type_t zodiac_binary = { @@ -537,6 +540,9 @@ const struct gps_type_t zodiac_binary = #ifdef ALLOW_CONTROLSEND .control_send = zodiac_control_send, /* for gpsctl and friends */ #endif /* ALLOW_CONTROLSEND */ +#ifdef NTPSHM_ENABLE + .ntp_offset = zodiac_ntp_offset, /* compute NTO fudge factor */ +#endif /* NTPSHM_ENABLE */ }; #endif /* ZODIAC_ENABLE */ -- cgit v1.2.1