#uds #diagnostics #adapter #can #async #multiple #communicating

automotive

Rust crate providing a variety of automotive related libraries, such as communicating with CAN interfaces and diagnostic APIs

5 releases

0.1.4 Feb 24, 2024
0.1.3 Feb 22, 2024
0.1.2 Feb 22, 2024
0.1.1 Feb 15, 2024
0.1.0 Feb 15, 2024

#6 in #can

Download history 176/week @ 2024-02-13 277/week @ 2024-02-20 39/week @ 2024-02-27 12/week @ 2024-03-05 8/week @ 2024-03-12

202 downloads per month

MIT license

68KB
1.5K SLoC

The Automotive Crate

crates.io docs.rs

Welcome to the automotive crate documentation. The purpose of this crate is to help you with all things automotive related. Most importantly, it provides a fully async CAN interface supporting multiple adapters.

Async CAN Example

The following adapter opens the first available adapter on the system, and then receives all frames.

let adapter = automotive::adapter::get_adapter().unwrap();
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));
}

UDS Example

The automotive crate also supplies interfaces for various diagnostic protocols such as UDS. The adapter is first wrapped to support the ISO Transport Layer, then a UDS Client is created. All methods are fully async, making it easy to communicate with multiple ECUs in parallel. See https://github.com/I-CAN-hack/automotive/issues/21 for progress on the supported SIDs.

let adapter = automotive::adapter::get_adapter().unwrap();
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();

println!("Application Software Identification: {}", hex::encode(response));

Suported adapters

  • SocketCAN (Linux only, supported using socketcan-rs)
  • comma.ai panda (all platforms)

Dependencies

~7–15MB
~162K SLoC