statime/datastructures/datasets/time_properties.rs
1use crate::datastructures::common::{LeapIndicator, TimeSource};
2
3/// A concrete implementation of the PTP Time Properties dataset
4///
5/// This dataset describes the timescale currently in use, as well as any
6/// upcoming leap seconds on that timescale.
7///
8/// For more details see *IEEE1588-2019 section 8.2.4*.
9#[derive(Default, Copy, Clone, Debug, Eq, PartialEq)]
10#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
11pub struct TimePropertiesDS {
12 /// The offset off UTC time compared to TAI time in seconds.
13 pub current_utc_offset: Option<i16>,
14 /// Describes upcoming leap seconds.
15 pub leap_indicator: LeapIndicator,
16 /// Wheter the timescale is tracable to a primary reference
17 pub time_traceable: bool,
18 /// Wheter the frequence determining the timescale is tracable to a primary
19 /// reference. True when the timescale is PTP, false when the timescale is
20 /// ARB.
21 pub frequency_traceable: bool,
22 /// Wheter the timescale of the Grandmaster PTP Instance is PTP.
23 pub ptp_timescale: bool,
24 /// The time source used by the Grandmaster PTP instance.
25 pub time_source: TimeSource,
26}
27
28impl TimePropertiesDS {
29 /// Create a Time Properties data set for the PTP timescale.
30 ///
31 /// This creates a dataset for the default PTP timescale, which is UTC
32 /// seconds since the PTP epoch excluding leap seconds. The traceability
33 /// properties indicate whether the current clock time and frequency can be
34 /// traced back to an internationally recognized standard in the metrology
35 /// sense of the word. When in doubt, just set these to false.
36 pub fn new_ptp_time(
37 current_utc_offset: Option<i16>,
38 leap_indicator: LeapIndicator,
39 time_traceable: bool,
40 frequency_traceable: bool,
41 time_source: TimeSource,
42 ) -> Self {
43 TimePropertiesDS {
44 current_utc_offset,
45 leap_indicator,
46 time_traceable,
47 frequency_traceable,
48 ptp_timescale: true,
49 time_source,
50 }
51 }
52
53 /// Create a Time Properties data set for an Arbitrary timescale
54 ///
55 /// The arbitrary timescale can be used when wanting to synchronize multiple
56 /// computers using PTP to a timescale that is unrelated to UTC. The
57 /// traceability properties indicate whether the current clock time and
58 /// frequency can be traced back to an internationally recognized standard
59 /// in the metrology sense of the word. When in doubt, just set these to
60 /// false.
61 pub fn new_arbitrary_time(
62 time_traceable: bool,
63 frequency_traceable: bool,
64 time_source: TimeSource,
65 ) -> Self {
66 TimePropertiesDS {
67 current_utc_offset: None,
68 leap_indicator: LeapIndicator::NoLeap,
69 time_traceable,
70 frequency_traceable,
71 ptp_timescale: false,
72 time_source,
73 }
74 }
75
76 /// Is this timescale a ptp (utc-derived) timescale?
77 pub fn is_ptp(&self) -> bool {
78 self.ptp_timescale
79 }
80
81 /// Information on upcoming leap seconds
82 pub fn leap_indicator(&self) -> LeapIndicator {
83 self.leap_indicator
84 }
85
86 /// Current offset to UTC caused by leap seconds
87 ///
88 /// Returns `None` if this time scale is not referenced to UTC
89 pub fn utc_offset(&self) -> Option<i16> {
90 self.current_utc_offset
91 }
92}