Skip to main content

CanBus

Trait CanBus 

Source
pub trait CanBus: Send {
    // Required methods
    fn name(&self) -> &str;
    fn capabilities(&self) -> BusCapabilities;
    fn send(&mut self, frame: &CanFrame) -> Result<(), TransportError>;
    fn drain_inbound_nonblocking(
        &mut self,
    ) -> Result<Vec<CanFrame>, TransportError>;
    fn raw_fd(&self) -> Option<RawFd>;
}
Expand description

The contract every CAN transport must satisfy.

The trait is intentionally object-safe so that Box<dyn CanBus> is a valid field type in crate::Bus / Robot. Implementations must be Send because they may move between threads (background IO thread, future async adapter).

Required Methods§

Source

fn name(&self) -> &str

Human-readable interface name ("vcan0", "can0", "mock-0").

Source

fn capabilities(&self) -> BusCapabilities

Runtime capabilities of this bus (FD support, max payload length).

Source

fn send(&mut self, frame: &CanFrame) -> Result<(), TransportError>

Send a single frame. Must not call read or poll internally.

Source

fn drain_inbound_nonblocking(&mut self) -> Result<Vec<CanFrame>, TransportError>

Drain every frame currently in the receive queue and return them in arrival order. Returns Ok(vec![]) immediately if the queue is empty.

Source

fn raw_fd(&self) -> Option<RawFd>

Pollable file descriptor for poll(2)-based multiplexing. Returns None for transports that have no single pollable fd. The robot drains those transports from memory on every crate::Robot::tick call.

Implementors§