Skip to content

Commit

Permalink
clean up uds example
Browse files Browse the repository at this point in the history
  • Loading branch information
pd0wm committed Feb 24, 2024
1 parent 051cb35 commit 033c8dd
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions examples/uds.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
use automotive::uds::constants::DataIdentifier;
use automotive::uds::constants::{DataIdentifier, SessionType};
use bstr::ByteSlice;

#[tokio::main]
async fn main() {
async fn main() -> Result<(), Box<dyn std::error::Error>> {
tracing_subscriber::fmt::init();

let adapter = automotive::adapter::get_adapter().unwrap();
let adapter = automotive::adapter::get_adapter()?;
let isotp = automotive::isotp::IsoTPAdapter::from_id(&adapter, 0x7a1);
let uds = automotive::uds::UDSClient::new(&isotp);

uds.tester_present().await.unwrap();
let response = uds
.read_data_by_identifier(DataIdentifier::ApplicationSoftwareIdentification as u16)
.await
.unwrap();
uds.tester_present().await?;
uds.diagnostic_session_control(SessionType::ExtendedDiagnostic as u8).await?;

println!(
"Application Software Identification: {}",
hex::encode(response)
);
let did = DataIdentifier::ApplicationSoftwareIdentification;
let resp = uds.read_data_by_identifier(did as u16).await?;

// ApplicationSoftwareIdentification: "\x018965B4209000\0\0\0\0"
println!("{:?}: {:?}", did, resp.as_bstr());

Ok(())
}

0 comments on commit 033c8dd

Please sign in to comment.