refclock: improve TAI-UTC conversion
Instead of using the TAI-UTC offset which corresponds to the current system time, get the offset for the reference time. This allows the clock to be accurately stepped from a time with different TAI-UTC offset.
This commit is contained in:
parent
a349b2803c
commit
f35c81c871
1 changed files with 25 additions and 9 deletions
30
refclock.c
30
refclock.c
|
@ -357,6 +357,28 @@ RCL_GetDriverOption(RCL_Instance instance, char *name)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int
|
||||||
|
convert_tai_offset(struct timespec *sample_time, double *offset)
|
||||||
|
{
|
||||||
|
struct timespec tai_ts, utc_ts;
|
||||||
|
int tai_offset;
|
||||||
|
|
||||||
|
/* Get approximate TAI-UTC offset for the reference time in TAI */
|
||||||
|
UTI_AddDoubleToTimespec(sample_time, *offset, &tai_ts);
|
||||||
|
tai_offset = REF_GetTaiOffset(&tai_ts);
|
||||||
|
|
||||||
|
/* Get TAI-UTC offset for the reference time in UTC +/- 1 second */
|
||||||
|
UTI_AddDoubleToTimespec(&tai_ts, -tai_offset, &utc_ts);
|
||||||
|
tai_offset = REF_GetTaiOffset(&utc_ts);
|
||||||
|
|
||||||
|
if (!tai_offset)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*offset -= tai_offset;
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset, int leap)
|
RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset, int leap)
|
||||||
{
|
{
|
||||||
|
@ -386,17 +408,11 @@ RCL_AddSample(RCL_Instance instance, struct timespec *sample_time, double offset
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (instance->tai) {
|
if (instance->tai && !convert_tai_offset(sample_time, &offset)) {
|
||||||
int tai_offset = REF_GetTaiOffset(sample_time);
|
|
||||||
|
|
||||||
if (!tai_offset) {
|
|
||||||
DEBUG_LOG("refclock sample ignored unknown TAI offset");
|
DEBUG_LOG("refclock sample ignored unknown TAI offset");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset -= tai_offset;
|
|
||||||
}
|
|
||||||
|
|
||||||
filter_add_sample(&instance->filter, &cooked_time, offset - correction + instance->offset, dispersion);
|
filter_add_sample(&instance->filter, &cooked_time, offset - correction + instance->offset, dispersion);
|
||||||
instance->pps_active = 0;
|
instance->pps_active = 0;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue