Skip to content

Commit

Permalink
bump version, added logs
Browse files Browse the repository at this point in the history
Signed-off-by: gabrik <[email protected]>
  • Loading branch information
gabrik committed Sep 15, 2022
1 parent 623ec36 commit 3049a06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

[package]
name = "z-serial"
version = "0.1.0"
version = "0.2.0"
edition = "2021"
repository = "https://github.com/ZettaScaleLabs/z-serial"
homepage = "http://zenoh.io"
Expand Down
11 changes: 10 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,11 @@ impl WireFormat {

let total_len = LEN_FIELD_LEN + CRC32_LEN + src.len();

log::trace!(
"Frame before COBS encoding {:02X?}",
&self.buff[0..total_len]
);

// COBS encode
let mut written = cobs::encode_with_sentinel(&self.buff[0..total_len], dest, SENTINEL);

Expand All @@ -143,13 +148,15 @@ impl WireFormat {
src: &mut [u8],
dst: &mut [u8],
) -> tokio_serial::Result<usize> {
let _size = cobs::decode_in_place_with_sentinel(src, SENTINEL).map_err(|e| {
let decoded_size = cobs::decode_in_place_with_sentinel(src, SENTINEL).map_err(|e| {
tokio_serial::Error::new(
tokio_serial::ErrorKind::InvalidInput,
format!("Unable COBS decode: {e:?}"),
)
})?;

log::trace!("Frame after COBS encoding {:02X?}", &src[0..decoded_size]);

// Decoding message size
let wire_size = ((src[1] as u16) << 8 | src[0] as u16) as usize;

Expand All @@ -168,6 +175,8 @@ impl WireFormat {
// Compute CRC locally
let computed_crc = self.crc.compute_crc32(&data[0..wire_size]);

log::trace!("Received CRC {recv_crc:02X?} Computed CRC {computed_crc:02X?}");

// Check CRC
if recv_crc != computed_crc {
return Err(tokio_serial::Error::new(
Expand Down

0 comments on commit 3049a06

Please sign in to comment.