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
202 downloads per month
68KB
1.5K
SLoC
The Automotive Crate
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