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>
impl<const N: usize, const Q: usize> CanSimBus<N, Q>
Sourcepub fn new(seed: u64, faults: CanFaultConfig) -> Self
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.
Sourcepub fn send(&mut self, src: NodeAddress, dst: NodeAddress, data: &[u8]) -> bool
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.
Sourcepub fn trigger_bus_off(&mut self)
pub fn trigger_bus_off(&mut self)
Manually triggers bus-off - useful for DST fault injection.
Sourcepub fn reset_bus_off(&mut self)
pub fn reset_bus_off(&mut self)
Resets the bus from bus-off state back to Active.
pub fn bus_state(&self) -> &CanBusState
Sourcepub fn tick(&mut self, duration: Duration) -> Vec<Envelope<N>, Q>
pub fn tick(&mut self, duration: Duration) -> Vec<Envelope<N>, Q>
Advances simulation time, delivers due frames, and checks bus-off fault injection.
pub fn now(&self) -> Instant
Sourcepub fn drain_events(&mut self) -> impl Iterator<Item = CanEvent> + '_
pub fn drain_events(&mut self) -> impl Iterator<Item = CanEvent> + '_
Drains accumulated CAN events.