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§
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(
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 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.
Sourcefn 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 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.
Sourcefn 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,
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§
Sourcefn start(&mut self, _clock: &RobotClock) -> Result<(), CuError>
fn start(&mut self, _clock: &RobotClock) -> Result<(), CuError>
Called before the first send/receive cycle.
Sourcefn preprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError>
fn preprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError>
Gives the bridge a chance to prepare buffers before I/O.
Sourcefn postprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError>
fn postprocess(&mut self, _clock: &RobotClock) -> Result<(), CuError>
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.