From: Mike Brady <4265913+mikebrady@users.noreply.github.com> Date: Fri, 19 Mar 2021 08:29:45 +0000 (+0000) Subject: Fix a bug resetting the samples buffer. Calculate differences each time and store... X-Git-Tag: 1.1-dev~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a94d56b24022396f36b3e8b62c3312cb2cc6e965;p=thirdparty%2Fnqptp.git Fix a bug resetting the samples buffer. Calculate differences each time and store them. --- diff --git a/nqptp.c b/nqptp.c index 8e7db34..982860e 100644 --- a/nqptp.c +++ b/nqptp.c @@ -941,6 +941,7 @@ int main(void) { the_clock->vacant_samples = MAX_TIMING_SAMPLES; // invalidate all the previous samples used for // averaging, etc. + the_clock->next_sample_goes_here = 0; } // now, store the remote and local times in the array @@ -948,6 +949,8 @@ int main(void) { the_clock->t2; the_clock->samples[the_clock->next_sample_goes_here].remote = the_clock->t1; + uint64_t diff = the_clock->t1 - the_clock->t2; + the_clock->samples[the_clock->next_sample_goes_here].local_to_remote_offset = diff; the_clock->next_sample_goes_here++; if (the_clock->next_sample_goes_here == MAX_TIMING_SAMPLES) the_clock->next_sample_goes_here = 0; @@ -1026,12 +1029,11 @@ int main(void) { int e; long double offsets = 0; int sample_count = MAX_TIMING_SAMPLES - the_clock->vacant_samples; - for (e = 0; e < MAX_TIMING_SAMPLES - the_clock->vacant_samples; e++) { - offsets = offsets + 1.0 * (the_clock->samples[e].remote - - the_clock->samples[e].local); + for (e = 0; e < sample_count; e++) { + offsets = offsets + 1.0 * (the_clock->samples[e].local_to_remote_offset); } - offsets = offsets / (MAX_TIMING_SAMPLES - the_clock->vacant_samples); + offsets = offsets / sample_count; // uint64_t offset = (uint64_t)offsets;