Skip to content

Commit

Permalink
ts2phc: Add option to correct for NMEA delay.
Browse files Browse the repository at this point in the history
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. ]

Signed-off-by: Miroslav Lichvar <[email protected]>
Signed-off-by: Richard Cochran <[email protected]>
Reviewed-by: Jacob Keller <[email protected]>
  • Loading branch information
mlichvar authored and richardcochran committed Jul 28, 2024
1 parent c6e5766 commit f722bda
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
1 change: 1 addition & 0 deletions config.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,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"),
Expand Down
30 changes: 20 additions & 10 deletions ts2phc.8
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,6 @@ with the log level of the message as a number. The default is an empty string
(which cannot be set in the configuration file as the option requires an
argument).

.TP
.B ts2phc.holdover
The holdover interval, specified in seconds. When the ToD information stops
working (e.g. GNSS receiver lost its fix), ts2phc is allowed for the specified
interval to continue synchronizing the target clock as long as the servo is in
the SERVO_LOCKED_STABLE state. The servo state needs be enabled by the
\fBservo_num_offset_values\fP option. The holdover is not supported with the
\fB-a\fP option and when \fBts2phc.extts_polarity\fP is set to \fIboth\fP.
The default is 0 (disabled).

.TP
.B sa_file
Specifies the location of the file containing Security Associations used
Expand All @@ -204,6 +194,26 @@ for all messages in accordance to the corresponding security association
sourced via the \fBsa_file\fR directive. Not compatible with one step ports.
Must be in the range of -1 to 255, inclusive. The default is -1 (disabled).

.TP
.B ts2phc.holdover
The holdover interval, specified in seconds. When the ToD information stops
working (e.g. GNSS receiver lost its fix), ts2phc is allowed for the specified
interval to continue synchronizing the target clock as long as the servo is in
the SERVO_LOCKED_STABLE state. The servo state needs be enabled by the
\fBservo_num_offset_values\fP option. The holdover is not supported with the
\fB-a\fP option and when \fBts2phc.extts_polarity\fP is set to \fIboth\fP.
The default is 0 (disabled).

.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
Expand Down
4 changes: 4 additions & 0 deletions ts2phc_nmea_pps_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -187,6 +188,7 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
return -1;
}
rmc = tmv_add(rmc, duration_since_rmc);
rmc = tmv_add(rmc, m->delay_correction);
utc_time = tmv_to_nanoseconds(rmc);
utc_time /= (int64_t) 1000000000;
*ts = tmv_to_timespec(rmc);
Expand Down Expand Up @@ -232,6 +234,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) {
Expand Down

0 comments on commit f722bda

Please sign in to comment.