Added feature flag for single packet messages so we can have an optimized version when we don't need to check data over multiple packets.

This commit is contained in:
Zachary Sunforge
2024-07-02 15:32:20 -07:00
parent 63d97b4b3b
commit 403df6f5f4
3 changed files with 9 additions and 2 deletions

View File

@ -9,7 +9,7 @@ members = [
] ]
[workspace.package] [workspace.package]
version = "0.3.2" version = "0.3.3"
edition = "2021" edition = "2021"
repository = "https://git.bfpower.io/BFPOWER/physical" repository = "https://git.bfpower.io/BFPOWER/physical"
readme = "README.md" readme = "README.md"

View File

@ -9,6 +9,7 @@ license.workspace = true
[features] [features]
comms = [] comms = []
single-packet-msgs = []
usb = ["embassy-usb"] usb = ["embassy-usb"]
stm32 = ["embassy-stm32", "physical/stm32"] stm32 = ["embassy-stm32", "physical/stm32"]

View File

@ -18,11 +18,17 @@ impl comms::Sender for TypedInterIn {
} }
impl comms::Receiver for TypedInterOut { impl comms::Receiver for TypedInterOut {
#[cfg(feature = "single-packet-msgs")]
async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), comms::Reset> { async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), comms::Reset> {
// This should be OK because all our messages are smaller than a single packet. // This is OK when all our messages are smaller than a single packet.
self.read(buffer) self.read(buffer)
.await .await
.map(|_| ()) .map(|_| ())
.map_err(|_| comms::Reset) .map_err(|_| comms::Reset)
} }
#[cfg(not(feature = "single-packet-msgs"))]
async fn receive(&mut self, buffer: &mut [u8]) -> Result<(), comms::Reset> {
todo!("Decide if we want a general purpose multi-packet message receive")
}
} }