Skip to content

Commit

Permalink
make IsoTPConfig.padding optional
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Mar 15, 2024
1 parent 601062f commit baeeec4
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/isotp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ pub struct IsoTPConfig {
pub rx_id: Identifier,
/// Transmit Data Length
pub tx_dl: usize,
/// Padding byte (0x00, or more efficient 0xAA)
pub padding: u8,
/// Padding byte (0x00, or more efficient 0xAA). Set to None to disable padding.
pub padding: Option<u8>,
/// Max timeout for receiving a frame
pub timeout: std::time::Duration,
}
Expand Down Expand Up @@ -75,7 +75,7 @@ impl IsoTPConfig {
tx_id,
rx_id,
tx_dl: 8,
padding: 0xaa,
padding: Some(0xaa),
timeout: std::time::Duration::from_millis(DEFAULT_TIMEOUT_MS),
}
}
Expand All @@ -100,8 +100,10 @@ impl<'a> IsoTPAdapter<'a> {
}

fn pad(&self, data: &mut Vec<u8>) {
let len = self.config.tx_dl - data.len();
data.extend(std::iter::repeat(self.config.padding).take(len));
if let Some(padding) = self.config.padding {
let len = self.config.tx_dl - data.len();
data.extend(std::iter::repeat(padding).take(len));
}
}

pub async fn send_single_frame(&self, data: &[u8]) {
Expand Down

0 comments on commit baeeec4

Please sign in to comment.