Skip to content

Commit

Permalink
[ISO-TP] wait for flow control every block_size frames (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm authored Mar 19, 2024
1 parent e8e0161 commit dc24ce4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
18 changes: 13 additions & 5 deletions src/isotp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ impl<'a> IsoTPAdapter<'a> {

self.send_first_frame(data).await;
let frame = stream.next().await.unwrap()?;
let fc_config = self.receive_flow_control(&frame)?;
let mut fc_config = self.receive_flow_control(&frame)?;

debug!("RX FC, data {}", hex::encode(&frame.data));

Expand All @@ -199,11 +199,19 @@ impl<'a> IsoTPAdapter<'a> {
while let Some((idx, chunk)) = it.next() {
self.send_consecutive_frame(chunk, idx).await;

// Sleep for separation time between frames
let last = it.peek().is_none();
if !last {
tokio::time::sleep(st_min).await;
// Wait for flow control every `block_size` frames, except for the first frame
if fc_config.block_size != 0 && idx > 0 && idx % fc_config.block_size as usize == 0 {
// Wait for next flow control
let frame = stream.next().await.unwrap()?;
fc_config = self.receive_flow_control(&frame)?;
} else {
// Sleep for separation time between frames
let last = it.peek().is_none();
if !last {
tokio::time::sleep(st_min).await;
}
}

}

Ok(())
Expand Down
19 changes: 11 additions & 8 deletions tests/isotp_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,12 +118,15 @@ async fn isotp_test_stmin() {
#[tokio::test]
#[serial_test::serial]
async fn isotp_test_bs() {
let config = VECUConfig {
bs: 4,
..Default::default()
};

// TODO: can we ensure that we actually wait for the
// flow control between blocks?
isotp_test_echo(64, config).await;
for bs in 1..=8 {
let config = VECUConfig {
bs,
..Default::default()
};
isotp_test_echo(64, config).await;

// TODO: can we ensure that we actually wait for the
// flow control between blocks?
isotp_test_echo(64, config).await;
}
}

0 comments on commit dc24ce4

Please sign in to comment.