CuBridge

Trait CuBridge 

Source
pub trait CuBridge: Freezable {
    type Tx: BridgeChannelSet;
    type Rx: BridgeChannelSet;

    // Required methods
    fn new(
        config: Option<&ComponentConfig>,
        tx_channels: &[BridgeChannelConfig<<Self::Tx as BridgeChannelSet>::Id>],
        rx_channels: &[BridgeChannelConfig<<Self::Rx as BridgeChannelSet>::Id>],
    ) -> Result<Self, CuError>
       where Self: Sized;
    fn send<'a, Payload>(
        &mut self,
        clock: &RobotClock,
        channel: &'static BridgeChannel<<Self::Tx as BridgeChannelSet>::Id, Payload>,
        msg: &CuStampedData<Payload, CuMsgMetadata>,
    ) -> Result<(), CuError>
       where Payload: CuMsgPayload + 'a;
    fn receive<'a, Payload>(
        &mut self,
        clock: &RobotClock,
        channel: &'static BridgeChannel<<Self::Rx as BridgeChannelSet>::Id, Payload>,
        msg: &mut CuStampedData<Payload, CuMsgMetadata>,
    ) -> Result<(), CuError>
       where Payload: CuMsgPayload + 'a;

    // Provided methods
    fn start(&mut self, _clock: &RobotClock) -> Result<(), CuError> { ... }
    fn preprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError> { ... }
    fn postprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError> { ... }
    fn stop(&mut self, _clock: &RobotClock) -> Result<(), CuError> { ... }
}
Expand description

Public trait implemented by every copper bridge.

A bridge behaves similarly to set of crate::cutask::CuSrcTask / crate::cutask::CuSinkTask, but it owns the shared transport state and knows how to multiplex multiple channels on a single backend (serial, CAN, middleware, …).

Required Associated Types§

Source

type Tx: BridgeChannelSet

Outgoing channels (Copper -> external world).

Source

type Rx: BridgeChannelSet

Incoming channels (external world -> Copper).

Required Methods§

Source

fn new( config: Option<&ComponentConfig>, tx_channels: &[BridgeChannelConfig<<Self::Tx as BridgeChannelSet>::Id>], rx_channels: &[BridgeChannelConfig<<Self::Rx as BridgeChannelSet>::Id>], ) -> Result<Self, CuError>
where Self: Sized,

Constructs a new bridge.

The runtime passes the bridge-level configuration plus the per-channel descriptors so the implementation can cache settings such as QoS, IDs, baud rates, etc.

Source

fn send<'a, Payload>( &mut self, clock: &RobotClock, channel: &'static BridgeChannel<<Self::Tx as BridgeChannelSet>::Id, Payload>, msg: &CuStampedData<Payload, CuMsgMetadata>, ) -> Result<(), CuError>
where Payload: CuMsgPayload + 'a,

Sends a message on the selected outbound channel.

Source

fn receive<'a, Payload>( &mut self, clock: &RobotClock, channel: &'static BridgeChannel<<Self::Rx as BridgeChannelSet>::Id, Payload>, msg: &mut CuStampedData<Payload, CuMsgMetadata>, ) -> Result<(), CuError>
where Payload: CuMsgPayload + 'a,

Receives a message from the selected inbound channel.

Implementations should write into msg when data is available.

Provided Methods§

Source

fn start(&mut self, _clock: &RobotClock) -> Result<(), CuError>

Called before the first send/receive cycle.

Source

fn preprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError>

Gives the bridge a chance to prepare buffers before I/O.

Source

fn postprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError>

Called once the send/receive pair completed.

Source

fn stop(&mut self, _clock: &RobotClock) -> Result<(), CuError>

Notifies the bridge that no more I/O will happen until a subsequent [start].

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§