commit 0d508d8cfb96cc32d3516f1d0d3e80db49f00468 Author: Miroslav Lichvar Date: Mon Jun 3 16:43:54 2024 +0200 ts2phc: Add option to correct for NMEA delay. Add an option to specify the minimum expected delay of NMEA RMC messages to correct timestamps returned by the NMEA PPS time source. This enables operation with receivers that have delays outside of the expected 0-1.0s interval, or 0-pulsewidth if the PPS edge rejection is enabled. [ RPC: Preserve alphabetical ordering in the ts2phc man page. ] (Rebased to 4.2) Signed-off-by: Miroslav Lichvar Signed-off-by: Richard Cochran Reviewed-by: Jacob Keller diff --git a/config.c b/config.c index 58481db..d441d1e 100644 --- a/config.c +++ b/config.c @@ -347,6 +347,7 @@ struct config_item config_tab[] = { PORT_ITEM_INT("ts2phc.holdover", 0, 0, INT_MAX), PORT_ITEM_INT("ts2phc.master", 0, 0, 1), PORT_ITEM_INT("ts2phc.nmea_baudrate", 9600, 300, INT_MAX), + PORT_ITEM_INT("ts2phc.nmea_delay", 0, INT_MIN, INT_MAX), GLOB_ITEM_STR("ts2phc.nmea_remote_host", ""), GLOB_ITEM_STR("ts2phc.nmea_remote_port", ""), GLOB_ITEM_STR("ts2phc.nmea_serialport", "/dev/ttyS0"), diff --git a/ts2phc.8 b/ts2phc.8 index c0b718b..b8383ff 100644 --- a/ts2phc.8 +++ b/ts2phc.8 @@ -262,6 +262,16 @@ by changing the clock frequency instead of stepping the clock. When set to 0.0, the servo will never step the clock except on start. The default is 0.0. +.TP +.B ts2phc.nmea_delay +Specifies the minimum expected delay of NMEA RMC messages in nanoseconds. +If the maximum delay is longer than 1 second, or 'ts2phc.pulsewidth' +if 'ts2phc.extts_polarity' is set to "both", this option needs to be set +accordingly to allow the timestamps from NMEA messages to be correctly +assigned to pulses from the PPS signal and wrong PPS edges to be rejected if +the edge rejection is enabled. +The default is 0 nanoseconds. + .TP .B ts2phc.nmea_remote_host, ts2phc.nmea_remote_port Specifies the remote host providing ToD information when using the diff --git a/ts2phc_nmea_pps_source.c b/ts2phc_nmea_pps_source.c index bdfaf19..e345969 100644 --- a/ts2phc_nmea_pps_source.c +++ b/ts2phc_nmea_pps_source.c @@ -33,6 +33,7 @@ struct ts2phc_nmea_pps_source { pthread_t worker; /* Protects anonymous struct fields, below, from concurrent access. */ pthread_mutex_t mutex; + tmv_t delay_correction; struct { struct timespec local_monotime; struct timespec local_utctime; @@ -207,6 +208,7 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src, } rmc = tmv_add(rmc, duration_since_rmc); + rmc = tmv_add(rmc, m->delay_correction); *ts = tmv_to_timespec(rmc); ts->tv_sec += tai_offset; @@ -234,6 +236,8 @@ struct ts2phc_pps_source *ts2phc_nmea_pps_source_create(struct ts2phc_private *p s->pps_source.destroy = ts2phc_nmea_pps_source_destroy; s->pps_source.getppstime = ts2phc_nmea_pps_source_getppstime; s->config = priv->cfg; + s->delay_correction = nanoseconds_to_tmv( + config_get_int(priv->cfg, NULL, "ts2phc.nmea_delay")); pthread_mutex_init(&s->mutex, NULL); err = pthread_create(&s->worker, NULL, monitor_nmea_status, s); if (err) {