Skip to content

Commit

Permalink
clean up examples
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Mar 27, 2024
1 parent 0dda51a commit 620ed1b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 20 deletions.
3 changes: 1 addition & 2 deletions examples/can_printer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ async fn main() {
let mut stream = adapter.recv();

while let Some(frame) = stream.next().await {
let id: u32 = frame.id.into();
println!("[{}]\t0x{:x}\t{}", frame.bus, id, hex::encode(frame.data));
println!("{:?}", frame);
}
}
24 changes: 6 additions & 18 deletions examples/query_fw_versions.rs
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
use automotive::can::AsyncCanAdapter;
use automotive::can::Identifier;
use automotive::isotp::{IsoTPAdapter, IsoTPConfig};
use automotive::Error;
use automotive::isotp::IsoTPAdapter;
use automotive::Result;

use automotive::uds::DataIdentifier;
use automotive::uds::UDSClient;

use bstr::ByteSlice;
use strum::IntoEnumIterator;

static BUS: u8 = 0;
static ADDRS_IN_PARALLEL: usize = 128;

async fn get_version(adapter: &AsyncCanAdapter, identifier: u32) -> Result<(), Error> {
let config = if identifier < 0x800 {
IsoTPConfig::new(BUS, Identifier::Standard(identifier))
} else {
IsoTPConfig::new(BUS, Identifier::Extended(identifier))
};

let isotp = IsoTPAdapter::new(adapter, config);
async fn get_version(adapter: &AsyncCanAdapter, identifier: u32) -> Result<()> {
let isotp = IsoTPAdapter::from_id(adapter, identifier);
let uds = UDSClient::new(&isotp);

uds.tester_present().await?;
Expand Down Expand Up @@ -50,8 +40,6 @@ async fn main() {

let ids: Vec<u32> = standard_ids.chain(extended_ids).collect();

for ids in ids.chunks(ADDRS_IN_PARALLEL) {
let r = ids.iter().map(|id| get_version(&adapter, *id));
futures::future::join_all(r).await;
}
let r = ids.iter().map(|id| get_version(&adapter, *id));
futures::future::join_all(r).await;
}

0 comments on commit 620ed1b

Please sign in to comment.