mirror of
https://gitlab.com/chrony/chrony.git
synced 2025-12-04 03:45:07 -05:00
samplefilt: add function to correct accumulated offsets
Analogously to SST_CorrectOffset(), add SPF_CorrectOffset() to correct the offsets accumulated in the filter.
This commit is contained in:
46
samplefilt.c
46
samplefilt.c
@@ -410,6 +410,27 @@ SPF_GetFilteredSample(SPF_Instance filter, NTP_Sample *sample)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
|
static int
|
||||||
|
get_first_last(SPF_Instance filter, int *first, int *last)
|
||||||
|
{
|
||||||
|
if (filter->last < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
/* Always slew the last sample as it may be returned even if no new
|
||||||
|
samples were accumulated */
|
||||||
|
if (filter->used > 0) {
|
||||||
|
*first = 0;
|
||||||
|
*last = filter->used - 1;
|
||||||
|
} else {
|
||||||
|
*first = *last = filter->last;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -418,18 +439,9 @@ SPF_SlewSamples(SPF_Instance filter, struct timespec *when, double dfreq, double
|
|||||||
int i, first, last;
|
int i, first, last;
|
||||||
double delta_time;
|
double delta_time;
|
||||||
|
|
||||||
if (filter->last < 0)
|
if (!get_first_last(filter, &first, &last))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* Always slew the last sample as it may be returned even if no new
|
|
||||||
samples were accumulated */
|
|
||||||
if (filter->used > 0) {
|
|
||||||
first = 0;
|
|
||||||
last = filter->used - 1;
|
|
||||||
} else {
|
|
||||||
first = last = filter->last;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = first; i <= last; i++) {
|
for (i = first; i <= last; i++) {
|
||||||
UTI_AdjustTimespec(&filter->samples[i].time, when, &filter->samples[i].time,
|
UTI_AdjustTimespec(&filter->samples[i].time, when, &filter->samples[i].time,
|
||||||
&delta_time, dfreq, doffset);
|
&delta_time, dfreq, doffset);
|
||||||
@@ -439,6 +451,20 @@ SPF_SlewSamples(SPF_Instance filter, struct timespec *when, double dfreq, double
|
|||||||
|
|
||||||
/* ================================================== */
|
/* ================================================== */
|
||||||
|
|
||||||
|
void
|
||||||
|
SPF_CorrectOffset(SPF_Instance filter, double doffset)
|
||||||
|
{
|
||||||
|
int i, first, last;
|
||||||
|
|
||||||
|
if (!get_first_last(filter, &first, &last))
|
||||||
|
return;
|
||||||
|
|
||||||
|
for (i = first; i <= last; i++)
|
||||||
|
filter->samples[i].offset -= doffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* ================================================== */
|
||||||
|
|
||||||
void
|
void
|
||||||
SPF_AddDispersion(SPF_Instance filter, double dispersion)
|
SPF_AddDispersion(SPF_Instance filter, double dispersion)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ extern void SPF_DropSamples(SPF_Instance filter);
|
|||||||
extern int SPF_GetFilteredSample(SPF_Instance filter, NTP_Sample *sample);
|
extern int SPF_GetFilteredSample(SPF_Instance filter, NTP_Sample *sample);
|
||||||
extern void SPF_SlewSamples(SPF_Instance filter, struct timespec *when,
|
extern void SPF_SlewSamples(SPF_Instance filter, struct timespec *when,
|
||||||
double dfreq, double doffset);
|
double dfreq, double doffset);
|
||||||
|
extern void SPF_CorrectOffset(SPF_Instance filter, double doffset);
|
||||||
extern void SPF_AddDispersion(SPF_Instance filter, double dispersion);
|
extern void SPF_AddDispersion(SPF_Instance filter, double dispersion);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -69,6 +69,7 @@ test_unit(void)
|
|||||||
TEST_CHECK(!memcmp(&sample_in, &sample_out, sizeof (sample_in)));
|
TEST_CHECK(!memcmp(&sample_in, &sample_out, sizeof (sample_in)));
|
||||||
|
|
||||||
SPF_SlewSamples(filter, &sample_in.time, 0.0, 0.0);
|
SPF_SlewSamples(filter, &sample_in.time, 0.0, 0.0);
|
||||||
|
SPF_CorrectOffset(filter, 0.0);
|
||||||
SPF_AddDispersion(filter, 0.0);
|
SPF_AddDispersion(filter, 0.0);
|
||||||
|
|
||||||
if (k + 1 < min_samples)
|
if (k + 1 < min_samples)
|
||||||
|
|||||||
Reference in New Issue
Block a user