Skip to content

Commit

Permalink
Merge pull request #5 from DLR-FT/dev/update_a653rs
Browse files Browse the repository at this point in the history
Dev/update a653rs
  • Loading branch information
dadada authored Jan 30, 2024
2 parents 51187ad + 0b353d9 commit 6bf1c90
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "a653rs-postcard"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
authors = ["Sven Friedrich <[email protected]>"]
license = "MIT OR Apache-2.0"
Expand All @@ -12,4 +12,4 @@ serde = { version = "1.0", features = ["derive"], default-features = false }
postcard = { version = "1.0", default-features = false }
arrayvec = { version = "0.7", default-features = false }

a653rs = "0.4"
a653rs = "0.5"
82 changes: 60 additions & 22 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let
pkgs = import nixpkgs {
inherit system;
overlays = [ devshell.overlay ];
overlays = [ devshell.overlays.default ];
};
rust-toolchain = with fenix.packages.${system};
combine [
Expand Down
14 changes: 10 additions & 4 deletions src/queuing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ pub trait QueuingPortSenderExt {
}

pub trait QueuingPortReceiverExt<const MSG_SIZE: MessageSize> {
fn recv_type<T>(&self, timeout: SystemTime) -> Result<T, QueuingRecvError<MSG_SIZE>>
fn recv_type<T>(
&self,
timeout: SystemTime,
) -> Result<(T, QueueOverflow), QueuingRecvError<MSG_SIZE>>
where
T: for<'a> Deserialize<'a>,
[u8; MSG_SIZE as usize]:;
Expand All @@ -40,16 +43,19 @@ impl<const MSG_SIZE: MessageSize, const NB_MSGS: MessageRange, Q: ApexQueuingPor
where
[u8; MSG_SIZE as usize]:,
{
fn recv_type<T>(&self, timeout: SystemTime) -> Result<T, QueuingRecvError<MSG_SIZE>>
fn recv_type<T>(
&self,
timeout: SystemTime,
) -> Result<(T, QueueOverflow), QueuingRecvError<MSG_SIZE>>
where
T: for<'a> Deserialize<'a>,
{
let mut msg_buf = [0u8; MSG_SIZE as usize];
let msg = self.receive(&mut msg_buf, timeout)?;
let (msg, overflow) = self.receive(&mut msg_buf, timeout)?;
let msg_slice = DeSlice::new(msg);
let mut deserializer = postcard::Deserializer::from_flavor(msg_slice);
match T::deserialize(&mut deserializer) {
Ok(t) => Ok(t),
Ok(t) => Ok((t, overflow)),
Err(e) => {
let mut msg = ArrayVec::from(msg_buf);
msg.truncate(msg.len());
Expand Down

0 comments on commit 6bf1c90

Please sign in to comment.