diff options
-rw-r--r-- | gpsd.c | 4 | ||||
-rw-r--r-- | gpsd.h-tail | 32 | ||||
-rw-r--r-- | gpsmon.c | 10 | ||||
-rw-r--r-- | libgpsd_core.c | 16 | ||||
-rw-r--r-- | ppsthread.c | 50 | ||||
-rw-r--r-- | timehint.c | 20 |
6 files changed, 65 insertions, 67 deletions
@@ -1519,8 +1519,10 @@ static void all_reports(struct gps_device_t *device, gps_mask_t changed) //gpsd_report(&context.errout, LOG_PROG, "NTP: No time this packet\n"); } else if (isnan(device->newdata.time)) { //gpsd_report(&context.errout, LOG_PROG, "NTP: bad new time\n"); - } else if (device->newdata.time == device->last_fixtime.real) { +#ifdef PPS_ENABLE + } else if (device->newdata.time == device->pps_thread.fixin_real) { //gpsd_report(&context.errout, LOG_PROG, "NTP: Not a new time\n"); +#endif /* PPS_ENABLE */ } else if (!device->ship_to_ntpd) { //gpsd_report(&context.errout, LOG_PROG, "NTP: No precision time report\n"); } else { diff --git a/gpsd.h-tail b/gpsd.h-tail index 0be3877b..5d2ce0f0 100644 --- a/gpsd.h-tail +++ b/gpsd.h-tail @@ -458,6 +458,22 @@ struct ntrip_stream_t int bitrate; }; +#ifdef PPS_ENABLE +struct pps_thread_t { + timestamp_t fixin_real; + struct timespec fixin_clock; /* system clock time when last fix received */ +#if defined(HAVE_SYS_TIMEPPS_H) + pps_handle_t kernelpps_handle; +#endif /* defined(HAVE_SYS_TIMEPPS_H) */ + int chronyfd; /* for talking to chrony */ + /*@null@*/ char *(*report_hook)(struct gps_device_t *, + struct timedelta_t *); + /*@null@*/ void (*wrap_hook)(struct gps_device_t *); + struct timedelta_t ppsout_last; + int ppsout_count; +}; +#endif /* PPS_ENABLE */ + struct gps_device_t { /* session object, encapsulates all global state */ struct gps_data_t gpsdata; @@ -499,22 +515,8 @@ struct gps_device_t { volatile /*@null@*/ struct shmTime *shm_pps; # endif /* PPS_ENABLE */ #endif /* NTP_ENABLE */ - volatile struct { - timestamp_t real; - /* clock must be a timespec as it is in nSec and - * a timestamp_t will lose precision */ - struct timespec clock; /* system clock time when last fix received */ - } last_fixtime; /* so updates happen once */ #ifdef PPS_ENABLE -#if defined(HAVE_SYS_TIMEPPS_H) - pps_handle_t kernelpps_handle; -#endif /* defined(HAVE_SYS_TIMEPPS_H) */ - int chronyfd; /* for talking to chrony */ - /*@null@*/ char *(*thread_report_hook)(struct gps_device_t *, - struct timedelta_t *); - /*@null@*/ void (*thread_wrap_hook)(struct gps_device_t *); - volatile struct timedelta_t ppslast; - volatile int ppscount; + volatile struct pps_thread_t pps_thread; #endif /* PPS_ENABLE */ double mag_var; /* magnetic variation in degrees */ bool back_to_nmea; /* back to NMEA on revert? */ @@ -790,9 +790,9 @@ static void gpsmon_hook(struct gps_device_t *device, gps_mask_t changed UNUSED) "------------------- PPS offset: %.20s ------\n ", timedelta_str); /* coverity[missing_lock] */ - session.ppslast = noclobber.pps; + session.pps_thread.ppsout_last = noclobber.pps; /* coverity[missing_lock] */ - session.ppscount++; + session.pps_thread.ppsout_count++; } } else @@ -847,8 +847,10 @@ static void gpsmon_hook(struct gps_device_t *device, gps_mask_t changed UNUSED) * and it is a new second. */ if ( 0 != isnan(device->newdata.time)) { // "NTP: bad new time - } else if (device->newdata.time == device->last_fixtime.real) { +#ifdef PPS_ENABLE + } else if (device->newdata.time == device->pps_thread.fixin_real) { // "NTP: Not a new time +#endif /* PPS_ENABLE */ } else ntp_latch(device, &time_offset); #endif /* NTP_ENABLE */ @@ -1316,7 +1318,7 @@ int main(int argc, char **argv) /* this guard suppresses a warning on Bluetooth devices */ if (session.sourcetype == source_rs232 || session.sourcetype == source_usb) { - session.thread_report_hook = pps_report; + session.pps_thread.report_hook = pps_report; pps_thread_activate(&session); } #endif /* PPS_ENABLE */ diff --git a/libgpsd_core.c b/libgpsd_core.c index 5dadde02..1c3c91ca 100644 --- a/libgpsd_core.c +++ b/libgpsd_core.c @@ -317,12 +317,8 @@ void gpsd_init(struct gps_device_t *session, struct gps_context_t *context, /* initialize GPS polling */ { /* clear some times */ - session->last_fixtime.real = 0.0; - /*@i2@*/session->last_fixtime.clock.tv_sec = 0; - /*@i2@*/session->last_fixtime.clock.tv_nsec = 0; #ifdef PPS_ENABLE - memset( (void *)&session->ppslast, 0, sizeof(session->ppslast)); - session->ppscount = 0; + memset((void *)&session->pps_thread, '\0', sizeof(session->pps_thread)); #endif /* PPS_ENABLE */ /*@ -mayaliasunique @*/ @@ -389,7 +385,7 @@ void gpsd_deactivate(struct gps_device_t *session) "DEACTIVATE"); #ifdef PPS_ENABLE /*@-mustfreeonly@*/ - session->thread_report_hook = NULL; /* tell any PPS-watcher thread to die */ + session->pps_thread.report_hook = NULL; /* tell any PPS-watcher thread to die */ #endif /* PPS_ENABLE */ /*@-mustfreeonly@*/ /* mark it inactivated */ @@ -415,13 +411,9 @@ void gpsd_clear(struct gps_device_t *session) /* clear the private data union */ memset( (void *)&session->driver, '\0', sizeof(session->driver)); - /* clear some times */ - session->last_fixtime.real = 0.0; - /*@i2@*/session->last_fixtime.clock.tv_sec = 0; - /*@i2@*/session->last_fixtime.clock.tv_nsec = 0; #ifdef PPS_ENABLE - memset( (void *)&session->ppslast, 0, sizeof(session->ppslast)); - session->ppscount = 0; + /* clear some times */ + memset((void *)&session->pps_thread, 0, sizeof(session->pps_thread)); #endif /* PPS_ENABLE */ session->opentime = timestamp(); diff --git a/ppsthread.c b/ppsthread.c index 73d1cfdc..a1b6ade6 100644 --- a/ppsthread.c +++ b/ppsthread.c @@ -114,7 +114,7 @@ static int init_kernel_pps(struct gps_device_t *session) char path[GPS_PATH_MAX] = ""; #endif - session->kernelpps_handle = -1; + session->pps_thread.kernelpps_handle = -1; if ( isatty(session->gpsdata.gps_fd) == 0 ) { gpsd_report(&session->context->errout, LOG_INF, "KPPS gps_fd not a tty\n"); return -1; @@ -218,7 +218,7 @@ static int init_kernel_pps(struct gps_device_t *session) /* RFC 2783 implies the time_pps_setcap() needs priviledges * * keep root a tad longer just in case */ - if ( 0 > time_pps_create(ret, &session->kernelpps_handle )) { + if ( 0 > time_pps_create(ret, (pps_handle_t *)&session->pps_thread.kernelpps_handle )) { char errbuf[BUFSIZ] = "unknown error"; (void)strerror_r(errno, errbuf, (int)sizeof(errbuf)); gpsd_report(&session->context->errout, LOG_INF, @@ -230,7 +230,7 @@ static int init_kernel_pps(struct gps_device_t *session) /* have kernel PPS handle */ int caps; /* get features supported */ - if ( 0 > time_pps_getcap(session->kernelpps_handle, &caps)) { + if ( 0 > time_pps_getcap(session->pps_thread.kernelpps_handle, &caps)) { gpsd_report(&session->context->errout, LOG_ERROR, "KPPS time_pps_getcap() failed\n"); } else { @@ -250,12 +250,12 @@ static int init_kernel_pps(struct gps_device_t *session) #endif #endif /* S_SPLINT_S */ - if ( 0 > time_pps_setparams(session->kernelpps_handle, &pp)) { + if ( 0 > time_pps_setparams(session->pps_thread.kernelpps_handle, &pp)) { char errbuf[BUFSIZ] = "unknown error"; (void)strerror_r(errno, errbuf, (int)sizeof(errbuf)); gpsd_report(&session->context->errout, LOG_ERROR, "KPPS time_pps_setparams() failed: %s\n", errbuf); - time_pps_destroy(session->kernelpps_handle); + time_pps_destroy(session->pps_thread.kernelpps_handle); return -1; } } @@ -313,7 +313,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) * ntpshm and chrony_send */ - while (session->thread_report_hook != NULL + while (session->pps_thread.report_hook != NULL || session->context->pps_hook != NULL) { bool ok = false; #ifndef S_SPLINT_S @@ -350,8 +350,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) "PPS: pthread_mutex_lock() : %s\n", errbuf); } /*@ +unrecog @*/ - last_fixtime_real = session->last_fixtime.real; - last_fixtime_clock = session->last_fixtime.clock; + last_fixtime_real = session->pps_thread.fixin_real; + last_fixtime_clock = session->pps_thread.fixin_clock; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -407,7 +407,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) ok = false; log = NULL; #if defined(HAVE_SYS_TIMEPPS_H) && !defined(S_SPLINT_S) - if ( 0 <= session->kernelpps_handle ) { + if ( 0 <= session->pps_thread.kernelpps_handle ) { struct timespec kernelpps_tv; /* on a quad core 2.4GHz Xeon using KPPS timestamp instead of plain * PPS timestamp removes about 20uS of latency, and about +/-5uS @@ -432,7 +432,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) kernelpps_tv.tv_sec = 1; kernelpps_tv.tv_nsec = 0; #endif - if ( 0 > time_pps_fetch(session->kernelpps_handle, PPS_TSFMT_TSPEC + if ( 0 > time_pps_fetch(session->pps_thread.kernelpps_handle, PPS_TSFMT_TSPEC , &pi, &kernelpps_tv)) { gpsd_report(&session->context->errout, LOG_ERROR, "KPPS kernel PPS failed\n"); @@ -633,7 +633,7 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) "PPS edge accepted %.100s", log); #ifndef S_SPLINT_S #if defined(HAVE_SYS_TIMEPPS_H) - if ( 0 <= session->kernelpps_handle && ok_kpps) { + if ( 0 <= session->pps_thread.kernelpps_handle && ok_kpps) { /* use KPPS time */ gpsd_report(&session->context->errout, LOG_RAW, "KPPS using edge %d", edge_kpps ); @@ -688,8 +688,8 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) } else { /*@-compdef@*/ last_second_used = last_fixtime_real; - if (session->thread_report_hook != NULL) - log1 = session->thread_report_hook(session, &ppstimes); + if (session->pps_thread.report_hook != NULL) + log1 = session->pps_thread.report_hook(session, &ppstimes); else log1 = "no report hook"; if (session->context->pps_hook != NULL) @@ -704,9 +704,9 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) } /*@ +unrecog @*/ /*@-type@*/ /* splint is confused about struct timespec */ - session->ppslast = ppstimes; + session->pps_thread.ppsout_last = ppstimes; /*@+type@*/ - session->ppscount++; + session->pps_thread.ppsout_count++; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -740,14 +740,14 @@ static /*@null@*/ void *gpsd_ppsmonitor(void *arg) } } #if defined(HAVE_SYS_TIMEPPS_H) - if (session->kernelpps_handle > 0) { + if (session->pps_thread.kernelpps_handle > 0) { gpsd_report(&session->context->errout, LOG_PROG, "PPS descriptor cleaned up\n"); - (void)time_pps_destroy(session->kernelpps_handle); + (void)time_pps_destroy(session->pps_thread.kernelpps_handle); } #endif - if (session->thread_wrap_hook != NULL) - session->thread_wrap_hook(session); + if (session->pps_thread.wrap_hook != NULL) + session->pps_thread.wrap_hook(session); gpsd_report(&session->context->errout, LOG_PROG, "PPS gpsd_ppsmonitor exited.\n"); return NULL; @@ -766,7 +766,7 @@ void pps_thread_activate(struct gps_device_t *session) #if defined(HAVE_SYS_TIMEPPS_H) /* some operations in init_kernel_pps() require root privs */ (void)init_kernel_pps( session ); - if ( 0 <= session->kernelpps_handle ) { + if ( 0 <= session->pps_thread.kernelpps_handle ) { gpsd_report(&session->context->errout, LOG_WARN, "KPPS kernel PPS will be used\n"); } @@ -782,7 +782,7 @@ void pps_thread_deactivate(struct gps_device_t *session) /* cleanly terminate PPS thread */ { /*@-nullstate -mustfreeonly@*/ - session->thread_report_hook = NULL; + session->pps_thread.report_hook = NULL; session->context->pps_hook = NULL; /*@+nullstate +mustfreeonly@*/ } @@ -800,8 +800,8 @@ void pps_thread_stash_fixtime(struct gps_device_t *session, "PPS: pthread_mutex_lock() : %s\n", errbuf); } /*@ +unrecog @*/ - session->last_fixtime.real = realtime; - session->last_fixtime.clock = clocktime; + session->pps_thread.fixin_real = realtime; + session->pps_thread.fixin_clock = clocktime; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -829,8 +829,8 @@ int pps_thread_lastpps(struct gps_device_t *session, struct timedelta_t *td) "PPS: pthread_mutex_lock() : %s\n", errbuf); } /*@ +unrecog @*/ - *td = session->ppslast; - ret = session->ppscount; + *td = session->pps_thread.ppsout_last; + ret = session->pps_thread.ppsout_count; /*@ -unrecog (splint has no pthread declarations as yet) @*/ pthread_err = pthread_mutex_unlock(&ppslast_mutex); if ( 0 != pthread_err ) { @@ -278,7 +278,7 @@ static void init_hook(struct gps_device_t *session) /* open the chrony socket */ char chrony_path[GPS_PATH_MAX]; - session->chronyfd = -1; + session->pps_thread.chronyfd = -1; if ( 0 == getuid() ) { /* this case will fire on command-line devices; * they're opened before priv-dropping. Matters because @@ -295,11 +295,11 @@ static void init_hook(struct gps_device_t *session) gpsd_report(&session->context->errout, LOG_PROG, "PPS chrony socket %s doesn't exist\n", chrony_path); } else { - session->chronyfd = netlib_localsocket(chrony_path, SOCK_DGRAM); - if (session->chronyfd < 0) + session->pps_thread.chronyfd = netlib_localsocket(chrony_path, SOCK_DGRAM); + if (session->pps_thread.chronyfd < 0) gpsd_report(&session->context->errout, LOG_PROG, "PPS connect chrony socket failed: %s, error: %d, errno: %d/%s\n", - chrony_path, session->chronyfd, errno, strerror(errno)); + chrony_path, session->pps_thread.chronyfd, errno, strerror(errno)); else gpsd_report(&session->context->errout, LOG_RAW, "PPS using chrony socket: %s\n", chrony_path); @@ -342,13 +342,13 @@ static void chrony_send(struct gps_device_t *session, struct timedelta_t *td) "PPS chrony_send %s @ %s Offset: %0.9f\n", real_str, clock_str, sample.offset); /*@+type@*/ - (void)send(session->chronyfd, &sample, sizeof (sample), 0); + (void)send(session->pps_thread.chronyfd, &sample, sizeof (sample), 0); } static void wrap_hook(struct gps_device_t *session) { - if (session->chronyfd != -1) - (void)close(session->chronyfd); + if (session->pps_thread.chronyfd != -1) + (void)close(session->pps_thread.chronyfd); } static /*@observer@*/ char *report_hook(struct gps_device_t *session, @@ -373,7 +373,7 @@ static /*@observer@*/ char *report_hook(struct gps_device_t *session, return "no fix"; log1 = "accepted"; - if ( 0 <= session->chronyfd ) { + if ( 0 <= session->pps_thread.chronyfd ) { log1 = "accepted chrony sock"; chrony_send(session, td); } @@ -427,8 +427,8 @@ void ntpshm_link_activate(struct gps_device_t *session) "NTPD ntpshm_alloc(1) failed\n"); } else { init_hook(session); - session->thread_report_hook = report_hook; - session->thread_wrap_hook = wrap_hook; + session->pps_thread.report_hook = report_hook; + session->pps_thread.wrap_hook = wrap_hook; pps_thread_activate(session); } #endif /* PPS_ENABLE */ |