refclock: require new samples to have newer timestamp
If all or most SHM/SOCK samples collected in a polling interval had the same local timestamp, the dispersion could end up as nan, which could trigger an assert failure later in the code. Before accumulating a refclock sample, check if the timestamp is newer than the previous one.
This commit is contained in:
parent
b443ec5ea5
commit
0a848e2528
1 changed files with 11 additions and 5 deletions
16
refclock.c
16
refclock.c
|
@ -505,16 +505,22 @@ RCL_AddPulse(RCL_Instance instance, struct timeval *pulse_time, double second)
|
||||||
static int
|
static int
|
||||||
valid_sample_time(RCL_Instance instance, struct timeval *tv)
|
valid_sample_time(RCL_Instance instance, struct timeval *tv)
|
||||||
{
|
{
|
||||||
struct timeval raw_time;
|
struct timeval raw_time, last_sample_time;
|
||||||
double diff;
|
double diff, last_offset, last_dispersion;
|
||||||
|
|
||||||
LCL_ReadRawTime(&raw_time);
|
LCL_ReadRawTime(&raw_time);
|
||||||
UTI_DiffTimevalsToDouble(&diff, &raw_time, tv);
|
UTI_DiffTimevalsToDouble(&diff, &raw_time, tv);
|
||||||
if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1)) {
|
|
||||||
DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f tv=%s",
|
if (diff < 0.0 || diff > UTI_Log2ToDouble(instance->poll + 1) ||
|
||||||
UTI_RefidToString(instance->ref_id), diff, UTI_TimevalToString(tv));
|
(filter_get_last_sample(&instance->filter, &last_sample_time,
|
||||||
|
&last_offset, &last_dispersion) &&
|
||||||
|
UTI_CompareTimevals(&last_sample_time, tv) >= 0)) {
|
||||||
|
DEBUG_LOG(LOGF_Refclock, "%s refclock sample not valid age=%.6f ts=%s lastts=%s",
|
||||||
|
UTI_RefidToString(instance->ref_id), diff,
|
||||||
|
UTI_TimevalToString(tv), UTI_TimevalToString(&last_sample_time));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue