Skip to content

Commit

Permalink
lstab: Add LSTAB_EXPIRED result
Browse files Browse the repository at this point in the history
LSTAB_UNKNOWN is too generic, add LSTAB_EXPIRED result to return the latest
lstab correction and indicate that the tab used to resolve it is expired.

This is useful for more precise reporting of lstab file state and will enable an
override of expired table.

Signed-off-by: Maciek Machnikowski <[email protected]>
Reviewed-by: Jacob Keller <[email protected]>
Signed-off-by: Maciek Machnikowski <[email protected]>
  • Loading branch information
MaciekMachni authored and richardcochran committed Feb 12, 2023
1 parent b2ef98f commit 30d1db5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
9 changes: 5 additions & 4 deletions lstab.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,10 +182,6 @@ enum lstab_result lstab_utc2tai(struct lstab *lstab, uint64_t utctime,
{
int epoch = -1, index, next;

if (utctime > lstab->expiration_utc) {
return LSTAB_UNKNOWN;
}

for (index = lstab->length - 1; index > -1; index--) {
if (utctime >= lstab->lstab[index].utc) {
epoch = index;
Expand All @@ -203,5 +199,10 @@ enum lstab_result lstab_utc2tai(struct lstab *lstab, uint64_t utctime,
if (next < lstab->length && utctime == lstab->lstab[next].utc - 1) {
return LSTAB_AMBIGUOUS;
}

if (utctime > lstab->expiration_utc) {
return LSTAB_EXPIRED;
}

return LSTAB_OK;
}
6 changes: 6 additions & 0 deletions lstab.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ enum lstab_result {
*/
LSTAB_UNKNOWN,

/**
* The given lstab is past its expiry date and the tai_offset return
* value may not be correct.
*/
LSTAB_EXPIRED,

/**
* The given UTC value is ambiguous. The corresponding TAI time is either
*
Expand Down
7 changes: 4 additions & 3 deletions ts2phc_nmea_pps_source.c
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
struct ts2phc_nmea_pps_source *m =
container_of(src, struct ts2phc_nmea_pps_source, pps_source);
tmv_t delay_t1, delay_t2, duration_since_rmc, local_t1, local_t2, rmc;
int lstab_error = 0, tai_offset = 0;
int lstab_error = -1, tai_offset = 0;
enum lstab_result result;
struct timespec now;
int64_t utc_time;
Expand Down Expand Up @@ -237,11 +237,12 @@ static int ts2phc_nmea_pps_source_getppstime(struct ts2phc_pps_source *src,
break;
case LSTAB_UNKNOWN:
pr_err("nmea: unable to find utc time in leap second table");
lstab_error = -1;
break;
case LSTAB_EXPIRED:
pr_err("nmea: utc time is past leap second table expiry date");
break;
case LSTAB_AMBIGUOUS:
pr_err("nmea: utc time stamp is ambiguous");
lstab_error = -1;
break;
}
ts->tv_sec += tai_offset;
Expand Down

0 comments on commit 30d1db5

Please sign in to comment.