Skip to content

Commit

Permalink
Add proper default for clock quality.
Browse files Browse the repository at this point in the history
  • Loading branch information
davidv1992 committed Nov 17, 2023
1 parent b286296 commit 047aa36
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion statime/src/datastructures/common/clock_quality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand All @@ -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
Expand Down

0 comments on commit 047aa36

Please sign in to comment.