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§
Sourcefn capabilities(&self) -> BusCapabilities
fn capabilities(&self) -> BusCapabilities
Runtime capabilities of this bus (FD support, max payload length).
Sourcefn send(&mut self, frame: &CanFrame) -> Result<(), TransportError>
fn send(&mut self, frame: &CanFrame) -> Result<(), TransportError>
Send a single frame. Must not call read or poll internally.
Sourcefn drain_inbound_nonblocking(&mut self) -> Result<Vec<CanFrame>, TransportError>
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.
Sourcefn raw_fd(&self) -> Option<RawFd>
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.