Skip to main content

CanSimBus

Struct CanSimBus 

Source
pub struct CanSimBus<const N: usize, const Q: usize> { /* private fields */ }
Expand description

A CAN-aware simulation bus.

Wraps SimBus for message delivery and adds CAN bus state and CAN-specific fault injection. Connection-less - any node may send to any other node as long as the bus is operational.

N - max frame payload bytes (8 for classic CAN, 64 for CAN FD) Q - max frames in-flight simultaneously

Implementations§

Source§

impl<const N: usize, const Q: usize> CanSimBus<N, Q>

Source

pub fn new(seed: u64, faults: CanFaultConfig) -> Self

Creates a new CanSimBus.

seed - seeds both the message bus RNG and the CAN fault RNG. The CAN RNG uses seed.wrapping_add(2) for independence.

Source

pub fn send(&mut self, src: NodeAddress, dst: NodeAddress, data: &[u8]) -> bool

Enqueues a CAN frame - rejected if the bus is in bus-off state or CAN-level fault injection drops it.

Returns true if the frame was accepted.

Source

pub fn trigger_bus_off(&mut self)

Manually triggers bus-off - useful for DST fault injection.

Source

pub fn reset_bus_off(&mut self)

Resets the bus from bus-off state back to Active.

Source

pub fn bus_state(&self) -> &CanBusState

Source

pub fn tick(&mut self, duration: Duration) -> Vec<Envelope<N>, Q>

Advances simulation time, delivers due frames, and checks bus-off fault injection.

Source

pub fn now(&self) -> Instant

Source

pub fn drain_events(&mut self) -> impl Iterator<Item = CanEvent> + '_

Drains accumulated CAN events.

Source

pub fn set_faults(&mut self, faults: CanFaultConfig)

Source

pub fn inner_mut(&mut self) -> &mut SimBus<N, Q>

Trait Implementations§

Source§

impl<const N: usize, const Q: usize> Debug for CanSimBus<N, Q>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const N: usize, const Q: usize> Freeze for CanSimBus<N, Q>

§

impl<const N: usize, const Q: usize> RefUnwindSafe for CanSimBus<N, Q>

§

impl<const N: usize, const Q: usize> Send for CanSimBus<N, Q>

§

impl<const N: usize, const Q: usize> Sync for CanSimBus<N, Q>

§

impl<const N: usize, const Q: usize> Unpin for CanSimBus<N, Q>

§

impl<const N: usize, const Q: usize> UnsafeUnpin for CanSimBus<N, Q>

§

impl<const N: usize, const Q: usize> UnwindSafe for CanSimBus<N, Q>

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> 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<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<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.