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§
Sourcetype Tx: BridgeChannelSet
type Tx: BridgeChannelSet
Outgoing channels (Copper -> external world).
Sourcetype Rx: BridgeChannelSet
type Rx: BridgeChannelSet
Incoming channels (external world -> Copper).
Required Methods§
Sourcefn 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 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.
Sourcefn 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 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.
Sourcefn 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,
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§
Sourcefn new(
config: Option<&ComponentConfig>,
tx_channels: &[BridgeChannelConfig<<Self::Tx as BridgeChannelSet>::Id>],
rx_channels: &[BridgeChannelConfig<<Self::Rx as BridgeChannelSet>::Id>],
) -> CuResult<Self>
fn new( config: Option<&ComponentConfig>, tx_channels: &[BridgeChannelConfig<<Self::Tx as BridgeChannelSet>::Id>], rx_channels: &[BridgeChannelConfig<<Self::Rx as BridgeChannelSet>::Id>], ) -> CuResult<Self>
Backward-compatible constructor for bridges that do not require resources.
Sourcefn start(&mut self, _clock: &RobotClock) -> CuResult<()>
fn start(&mut self, _clock: &RobotClock) -> CuResult<()>
Called before the first send/receive cycle.
Sourcefn preprocess(&mut self, _clock: &RobotClock) -> CuResult<()>
fn preprocess(&mut self, _clock: &RobotClock) -> CuResult<()>
Gives the bridge a chance to prepare buffers before I/O.
Sourcefn postprocess(&mut self, _clock: &RobotClock) -> CuResult<()>
fn postprocess(&mut self, _clock: &RobotClock) -> CuResult<()>
Called once the send/receive pair completed.
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.