Struct statime::PtpInstance
source · pub struct PtpInstance<F, S = RefCell<PtpInstanceState>> { /* private fields */ }
Expand description
A PTP node.
This object handles the complete running of the PTP protocol once created. It provides all the logic for both ordinary and boundary clock mode.
§Example
use statime::PtpInstance;
use statime::config::{AcceptAnyMaster, ClockIdentity, InstanceConfig, TimePropertiesDS, TimeSource};
use statime::filters::BasicFilter;
let instance_config = InstanceConfig {
clock_identity: ClockIdentity::from_mac_address(system::get_mac()),
priority_1: 128,
priority_2: 128,
domain_number: 0,
slave_only: false,
sdo_id: Default::default(),
path_trace: false,
};
let time_properties_ds = TimePropertiesDS::new_arbitrary_time(false, false, TimeSource::InternalOscillator);
let mut instance = PtpInstance::<BasicFilter>::new(
instance_config,
time_properties_ds,
);
let mut port = instance.add_port(port_config, filter_config, clock, rng);
// Send of port to its own thread/task to do its work
loop {
instance.bmca(&mut [&mut port]);
system::sleep(instance.bmca_interval());
}
Implementations§
source§impl<F, S: PtpInstanceStateMutex> PtpInstance<F, S>
impl<F, S: PtpInstanceStateMutex> PtpInstance<F, S>
sourcepub fn new(config: InstanceConfig, time_properties_ds: TimePropertiesDS) -> Self
pub fn new(config: InstanceConfig, time_properties_ds: TimePropertiesDS) -> Self
Construct a new PtpInstance
with the given config and time
properties
sourcepub fn default_ds(&self) -> DefaultDS
pub fn default_ds(&self) -> DefaultDS
Return IEEE-1588 defaultDS for introspection
sourcepub fn current_ds(&self) -> CurrentDS
pub fn current_ds(&self) -> CurrentDS
Return IEEE-1588 currentDS for introspection
sourcepub fn time_properties_ds(&self) -> TimePropertiesDS
pub fn time_properties_ds(&self) -> TimePropertiesDS
Return IEEE-1588 timePropertiesDS for introspection
sourcepub fn path_trace_ds(&self) -> PathTraceDS
pub fn path_trace_ds(&self) -> PathTraceDS
Return IEEE-1588 pathTraceDS for introspection
source§impl<F: Filter, S: PtpInstanceStateMutex> PtpInstance<F, S>
impl<F: Filter, S: PtpInstanceStateMutex> PtpInstance<F, S>
sourcepub fn add_port<A, C, R: Rng>(
&self,
config: PortConfig<A>,
filter_config: F::Config,
clock: C,
rng: R,
) -> Port<'_, InBmca, A, R, C, F, S>
pub fn add_port<A, C, R: Rng>( &self, config: PortConfig<A>, filter_config: F::Config, clock: C, rng: R, ) -> Port<'_, InBmca, A, R, C, F, S>
Add and initialize this port
We start in the BMCA state because that is convenient
When providing the port with a different clock than the instance clock, the caller is responsible for propagating any property changes to this clock, and for synchronizing this clock with the instance clock as appropriate based on the ports state.
sourcepub fn bmca<A: AcceptableMasterList, C: Clock, R: Rng>(
&self,
ports: &mut [&mut Port<'_, InBmca, A, R, C, F, S>],
)
pub fn bmca<A: AcceptableMasterList, C: Clock, R: Rng>( &self, ports: &mut [&mut Port<'_, InBmca, A, R, C, F, S>], )
Run the best master clock algorithm (BMCA)
The caller must pass all the ports that were created on this instance in the slice!
sourcepub fn bmca_interval(&self) -> Duration
pub fn bmca_interval(&self) -> Duration
Time to wait between calls to PtpInstance::bmca