CuBridge

Trait CuBridge 

Source
pub trait CuBridge: Freezable {
    type Tx: BridgeChannelSet;
    type Rx: BridgeChannelSet;
    type Resources<'r>;

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

    // Provided methods
    fn new(
        config: Option<&ComponentConfig>,
        tx_channels: &[BridgeChannelConfig<<Self::Tx as BridgeChannelSet>::Id>],
        rx_channels: &[BridgeChannelConfig<<Self::Rx as BridgeChannelSet>::Id>],
    ) -> CuResult<Self>
       where Self: Sized,
             for<'r> Self::Resources<'r>: Default { ... }
    fn start(&mut self, _clock: &RobotClock) -> CuResult<()> { ... }
    fn preprocess(&mut self, _clock: &RobotClock) -> CuResult<()> { ... }
    fn postprocess(&mut self, _clock: &RobotClock) -> CuResult<()> { ... }
    fn stop(&mut self, _clock: &RobotClock) -> CuResult<()> { ... }
}
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).

Source

type Resources<'r>

Resources required by the bridge.

Required Methods§

Source

fn new_with( config: Option<&ComponentConfig>, tx_channels: &[BridgeChannelConfig<<Self::Tx as BridgeChannelSet>::Id>], rx_channels: &[BridgeChannelConfig<<Self::Rx as BridgeChannelSet>::Id>], resources: Self::Resources<'_>, ) -> CuResult<Self>
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: &CuMsg<Payload>, ) -> CuResult<()>
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 CuMsg<Payload>, ) -> CuResult<()>
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 new( config: Option<&ComponentConfig>, tx_channels: &[BridgeChannelConfig<<Self::Tx as BridgeChannelSet>::Id>], rx_channels: &[BridgeChannelConfig<<Self::Rx as BridgeChannelSet>::Id>], ) -> CuResult<Self>
where Self: Sized, for<'r> Self::Resources<'r>: Default,

Backward-compatible constructor for bridges that do not require resources.

Source

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

Called before the first send/receive cycle.

Source

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

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

Source

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

Called once the send/receive pair completed.

Source

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

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§