From 047aa36c153e4eac9571d03fae2864c812517b56 Mon Sep 17 00:00:00 2001 From: David Venhoek Date: Fri, 17 Nov 2023 10:05:30 +0100 Subject: [PATCH] Add proper default for clock quality. --- .../src/datastructures/common/clock_quality.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/statime/src/datastructures/common/clock_quality.rs b/statime/src/datastructures/common/clock_quality.rs index 083eeaeb2..c6bed6b6e 100644 --- a/statime/src/datastructures/common/clock_quality.rs +++ b/statime/src/datastructures/common/clock_quality.rs @@ -2,7 +2,7 @@ use super::clock_accuracy::ClockAccuracy; use crate::datastructures::{WireFormat, WireFormatError}; /// A description of the accuracy and type of a clock. -#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)] +#[derive(Debug, Clone, Copy, PartialEq, Eq)] pub struct ClockQuality { /// The PTP clock class. /// @@ -22,6 +22,19 @@ pub struct ClockQuality { pub offset_scaled_log_variance: u16, } +impl Default for ClockQuality { + fn default() -> Self { + Self { + clock_class: 248, + clock_accuracy: Default::default(), + // See 7.6.3.3 for the description of the calculation procedure. + // We estimate clock variance of desktop to be no worse than + // 2^-23 seconds^2, based on experience from ntpd-rs + offset_scaled_log_variance: 0x8000 - (23 * 256), + } + } +} + impl WireFormat for ClockQuality { fn wire_size(&self) -> usize { 4