Skip to content

Commit

Permalink
wait between CF
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Mar 15, 2024
1 parent 0d94fb7 commit 88d2852
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 3 additions & 1 deletion examples/isotp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ async fn main() {
tracing_subscriber::fmt::init();

let adapter = automotive::adapter::get_adapter().unwrap();
let config = IsoTPConfig::new(0, Identifier::Standard(0x7a1));
let mut config = IsoTPConfig::new(0, Identifier::Standard(0x7a1));
config.timeout = std::time::Duration::from_secs(1);

let isotp = IsoTPAdapter::new(&adapter, config);

let response = isotp.recv();
Expand Down
14 changes: 7 additions & 7 deletions src/isotp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ use futures_core::stream::Stream;
use tokio_stream::{StreamExt, Timeout};
use tracing::debug;

use self::types::FlowControlConfig;

const DEFAULT_TIMEOUT_MS: u64 = 100;

/// Configuring passed to the IsoTPAdapter.
Expand Down Expand Up @@ -146,7 +148,7 @@ impl<'a> IsoTPAdapter<'a> {
self.adapter.send(&frame).await;
}

fn receive_flow_control(&self, frame: &Frame) -> Result<(), Error> {
fn receive_flow_control(&self, frame: &Frame) -> Result<FlowControlConfig, Error> {
// Check if Flow Control
if FrameType::from_repr(frame.data[0] & FRAME_TYPE_MASK) != Some(FrameType::FlowControl) {
return Err(crate::isotp::error::Error::FlowControl.into());
Expand All @@ -162,10 +164,9 @@ impl<'a> IsoTPAdapter<'a> {

// Parse block size and separation time
let config = types::FlowControlConfig::try_from(frame)?;
println!("{:?}", config);

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

async fn send_multiple(&self, data: &[u8]) -> Result<(), Error> {
Expand All @@ -178,14 +179,15 @@ impl<'a> IsoTPAdapter<'a> {

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

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

let chunks = data[self.config.tx_dl - 2..].chunks(self.config.tx_dl - 1);
for (idx, chunk) in chunks.enumerate() {
self.send_consecutive_frame(chunk, idx).await;
tokio::time::sleep(config.separation_time_min).await;
}

Ok(())
Expand Down Expand Up @@ -306,8 +308,6 @@ impl<'a> IsoTPAdapter<'a> {
}
};

debug!("{} {}", len, buf.len());

if buf.len() >= len {
break;
}
Expand Down

0 comments on commit 88d2852

Please sign in to comment.