Skip to content

Commit

Permalink
bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Sep 2, 2024
1 parent 23fdcce commit 8bb7e2d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/isotp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions tests/isotp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,17 @@ 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;

// Single frame with some padding to reach next DLC
isotp_test_echo(50, config).await;

// Multiple frames
isotp_test_echo(218, config).await;
isotp_test_echo(256, config).await;

// First frame escape
Expand Down

0 comments on commit 8bb7e2d

Please sign in to comment.