Skip to content

Commit

Permalink
ts2phc: Fix timestamp conversion for leap seconds.
Browse files Browse the repository at this point in the history
The UTC timestamp parsed from the RMC message needs to be converted to
TAI in order to calculate the PHC offset. This conversion was done after
adjusting the timestamp for the measured delay between the reception of
the message and the following pulse, which caused the offset measured by
ts2phc to have a one-second error if the message expected during or
after a leap second was missed.

Apply the TAI-UTC offset to the timestamp parsed from the RMC message
before any adjustments are made to avoid the error.

Signed-off-by: Miroslav Lichvar <mlichvar@redhat.com>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
  • Loading branch information
mlichvar authored and richardcochran committed Jul 30, 2024
1 parent 66fcd01 commit 59e6f2e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions ts2phc_nmea_pps_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,9 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
pr_err("nmea: rmc time stamp stale");
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);

result = lstab_utc2tai(m->lstab, utc_time, &tai_offset);
switch (result) {
Expand All @@ -208,6 +206,10 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
pr_err("nmea: utc time stamp is ambiguous");
break;
}

rmc = tmv_add(rmc, duration_since_rmc);
rmc = tmv_add(rmc, m->delay_correction);
*ts = tmv_to_timespec(rmc);
ts->tv_sec += tai_offset;

return lstab_error;
Expand Down

0 comments on commit 59e6f2e

Please sign in to comment.