From 4d24c5936e920668f62d0c606db82c4596131ed3 Mon Sep 17 00:00:00 2001 From: Andri Yngvason Date: Sun, 1 Oct 2023 22:11:44 +0000 Subject: [PATCH] ntp: Add method to get jitter --- include/ntp.h | 2 ++ src/ntp.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/include/ntp.h b/include/ntp.h index caa6295..3b16f3e 100644 --- a/include/ntp.h +++ b/include/ntp.h @@ -57,3 +57,5 @@ bool ntp_client_get_best_sample(const struct ntp_client* self, bool ntp_client_translate_server_time(const struct ntp_client* self, uint32_t* dst, const uint32_t t); + +uint32_t ntp_client_get_jitter(const struct ntp_client* self); diff --git a/src/ntp.c b/src/ntp.c index 7e2566f..81a6267 100644 --- a/src/ntp.c +++ b/src/ntp.c @@ -118,3 +118,15 @@ bool ntp_client_translate_server_time(const struct ntp_client* self, *dst = (int32_t)t - sample.theta; return true; } + +uint32_t ntp_client_get_jitter(const struct ntp_client* self) +{ + uint32_t max_delta = 0; + for (int i = 0; i < self->sample_count; ++i) { + const struct ntp_sample *sample = &self->samples[i]; + if (sample->delta > max_delta) { + max_delta = sample->delta; + } + } + return max_delta; +}