Skip to main content

CanSimBus

Struct CanSimBus 

Source
pub struct CanSimBus<const MAX_DATA: usize, const MAX_QUEUED: 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 MAX_DATA: usize, const MAX_QUEUED: usize> CanSimBus<MAX_DATA, MAX_QUEUED>

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

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

Trait Implementations§

Source§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> Debug for CanSimBus<MAX_DATA, MAX_QUEUED>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> Freeze for CanSimBus<MAX_DATA, MAX_QUEUED>

§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> RefUnwindSafe for CanSimBus<MAX_DATA, MAX_QUEUED>

§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> Send for CanSimBus<MAX_DATA, MAX_QUEUED>

§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> Sync for CanSimBus<MAX_DATA, MAX_QUEUED>

§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> Unpin for CanSimBus<MAX_DATA, MAX_QUEUED>

§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> UnsafeUnpin for CanSimBus<MAX_DATA, MAX_QUEUED>

§

impl<const MAX_DATA: usize, const MAX_QUEUED: usize> UnwindSafe for CanSimBus<MAX_DATA, MAX_QUEUED>

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.