Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper default for clock quality. #321

Merged
merged 1 commit into from
Nov 17, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading