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(),
};
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>

source

pub fn new(config: InstanceConfig, time_properties_ds: TimePropertiesDS) -> Self

Construct a new PtpInstance with the given config and time properties

source

pub fn default_ds(&self) -> DefaultDS

Return IEEE-1588 defaultDS for introspection

source

pub fn current_ds(&self) -> CurrentDS

Return IEEE-1588 currentDS for introspection

source

pub fn parent_ds(&self) -> ParentDS

Return IEEE-1588 parentDS for introspection

source

pub fn time_properties_ds(&self) -> TimePropertiesDS

Return IEEE-1588 timePropertiesDS for introspection

source§

impl<F: Filter, S: PtpInstanceStateMutex> PtpInstance<F, S>

source

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.

source

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!

source

pub fn bmca_interval(&self) -> Duration

Time to wait between calls to PtpInstance::bmca

Auto Trait Implementations§

§

impl<F, S = RefCell<PtpInstanceState>> !Freeze for PtpInstance<F, S>

§

impl<F, S> RefUnwindSafe for PtpInstance<F, S>

§

impl<F, S> Send for PtpInstance<F, S>
where S: Send, F: Send,

§

impl<F, S> Sync for PtpInstance<F, S>
where S: Sync, F: Sync,

§

impl<F, S> Unpin for PtpInstance<F, S>
where S: Unpin, F: Unpin,

§

impl<F, S> UnwindSafe for PtpInstance<F, S>
where S: UnwindSafe, F: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Az for T

source§

fn az<Dst>(self) -> Dst
where T: Cast<Dst>,

Casts the value.
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<Src, Dst> CastFrom<Src> for Dst
where Src: Cast<Dst>,

source§

fn cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> CheckedAs for T

source§

fn checked_as<Dst>(self) -> Option<Dst>
where T: CheckedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> CheckedCastFrom<Src> for Dst
where Src: CheckedCast<Dst>,

source§

fn checked_cast_from(src: Src) -> Option<Dst>

Casts the value.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<Src, Dst> LosslessTryInto<Dst> for Src
where Dst: LosslessTryFrom<Src>,

source§

fn lossless_try_into(self) -> Option<Dst>

Performs the conversion.
source§

impl<Src, Dst> LossyInto<Dst> for Src
where Dst: LossyFrom<Src>,

source§

fn lossy_into(self) -> Dst

Performs the conversion.
source§

impl<T> OverflowingAs for T

source§

fn overflowing_as<Dst>(self) -> (Dst, bool)
where T: OverflowingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> OverflowingCastFrom<Src> for Dst
where Src: OverflowingCast<Dst>,

source§

fn overflowing_cast_from(src: Src) -> (Dst, bool)

Casts the value.
source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<T> SaturatingAs for T

source§

fn saturating_as<Dst>(self) -> Dst
where T: SaturatingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> SaturatingCastFrom<Src> for Dst
where Src: SaturatingCast<Dst>,

source§

fn saturating_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> UnwrappedAs for T

source§

fn unwrapped_as<Dst>(self) -> Dst
where T: UnwrappedCast<Dst>,

Casts the value.
source§

impl<Src, Dst> UnwrappedCastFrom<Src> for Dst
where Src: UnwrappedCast<Dst>,

source§

fn unwrapped_cast_from(src: Src) -> Dst

Casts the value.
source§

impl<T> WrappingAs for T

source§

fn wrapping_as<Dst>(self) -> Dst
where T: WrappingCast<Dst>,

Casts the value.
source§

impl<Src, Dst> WrappingCastFrom<Src> for Dst
where Src: WrappingCast<Dst>,

source§

fn wrapping_cast_from(src: Src) -> Dst

Casts the value.