From 3049a061b738656f736e85681bdbb822bbc99026 Mon Sep 17 00:00:00 2001 From: gabrik Date: Thu, 15 Sep 2022 17:40:13 +0200 Subject: [PATCH] bump version, added logs Signed-off-by: gabrik --- Cargo.toml | 2 +- src/lib.rs | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 095c86d..874f87e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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" diff --git a/src/lib.rs b/src/lib.rs index 9291195..64e0d38 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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); @@ -143,13 +148,15 @@ impl WireFormat { src: &mut [u8], dst: &mut [u8], ) -> tokio_serial::Result { - 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; @@ -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(