From 8bb7e2d40c989475e3245fcc0e6b352a1cd76076 Mon Sep 17 00:00:00 2001 From: Willem Melching Date: Mon, 2 Sep 2024 11:55:41 +0200 Subject: [PATCH] bugfixes --- src/isotp/mod.rs | 8 +++++--- tests/isotp_tests.rs | 4 ++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/isotp/mod.rs b/src/isotp/mod.rs index 88f1701..6b70b75 100644 --- a/src/isotp/mod.rs +++ b/src/isotp/mod.rs @@ -129,8 +129,10 @@ impl<'a> IsoTPAdapter<'a> { // Pad to at least 8 bytes if padding is enabled if let Some(padding) = self.config.padding { - let padding_len = CAN_MAX_DLEN - len; // Offset for extended address is already accounted for - data.extend(std::iter::repeat(padding).take(padding_len)); + if len < CAN_MAX_DLEN { + let padding_len = CAN_MAX_DLEN - len; // Offset for extended address is already accounted for + data.extend(std::iter::repeat(padding).take(padding_len)); + } } // Pad to next valid DLC for CAN-FD @@ -208,7 +210,7 @@ impl<'a> IsoTPAdapter<'a> { pub async fn send_single_frame(&self, data: &[u8]) -> Result<()> { let mut buf; - if data.len() < 0xf { + if data.len() < 0x8 { // Len fits in single nibble buf = vec![FrameType::Single as u8 | data.len() as u8]; } else { diff --git a/tests/isotp_tests.rs b/tests/isotp_tests.rs index 35eefdb..cfea324 100644 --- a/tests/isotp_tests.rs +++ b/tests/isotp_tests.rs @@ -163,6 +163,9 @@ async fn isotp_test_fd() { ..Default::default() }; + // Single frame with some padding to reach next DLC + isotp_test_echo(8, config).await; + // Single frame escape isotp_test_echo(62, config).await; @@ -170,6 +173,7 @@ async fn isotp_test_fd() { isotp_test_echo(50, config).await; // Multiple frames + isotp_test_echo(218, config).await; isotp_test_echo(256, config).await; // First frame escape