#automotive #uds #obd #kwp2000

no-std automotive_diag

Unified Diagnostic Services/UDS (ISO-14229-1), KWP2000 (ISO-142330) and OBD-II (ISO-9141) definitions to communicate with the road vehicle ECUs in Rust

12 releases

new 0.1.11 Feb 11, 2025
0.1.10 Jan 10, 2025
0.1.9 Jul 24, 2024
0.1.7 Jun 20, 2024
0.1.3 Apr 15, 2023

#76 in Embedded development

Download history 1162/week @ 2024-10-21 667/week @ 2024-10-28 1087/week @ 2024-11-04 1139/week @ 2024-11-11 1104/week @ 2024-11-18 1116/week @ 2024-11-25 830/week @ 2024-12-02 1142/week @ 2024-12-09 831/week @ 2024-12-16 1061/week @ 2024-12-23 471/week @ 2024-12-30 1104/week @ 2025-01-06 740/week @ 2025-01-13 667/week @ 2025-01-20 85/week @ 2025-01-27 822/week @ 2025-02-03

2,332 downloads per month
Used in ecu_diagnostics

MIT/Apache

73KB
1K SLoC

Automotive diagnostics in Rust

GitHub crates.io version docs.rs crates.io license CI build

This crate provides low-level no_std structs and enums of the Unified Diagnostic Services (ISO-14229-1), KWP2000 (ISO-142330) and OBD-II (ISO-9141) specifications for the road vehicles in Rust.

Most features have been implemented and documented to handle the most common diagnostic commands and responses. If you find a missing command or response, please open an issue or better yet, a pull request.

Usage

All values are presented as Rust enum, and can be converted to/from their underlying numeric values using the T::from_repr(u8) and u8::from(value). Most enums also have a corresponding ...Byte enums as ByteWrapper<T> to handle the non-standard Extended(u8) values in addition to the defined Standand(T) ones.

use automotive_diag::ByteWrapper::{Extended, Standard};
use automotive_diag::uds::UdsCommand::{DiagnosticSessionControl, ECUReset};
use automotive_diag::uds::UdsCommandByte;

/// Handle a single command byte on the ECU side
fn handle_cmd_byte(cmd: u8) {
    match UdsCommandByte::from(cmd) {
        Standard(DiagnosticSessionControl) => {
            // handle_diag_session()
        }
        Standard(ECUReset) => {
            // handle_ecu_reset()
        }
        Extended(0x42) => {
            // handle_custom_cmd_42()
        }
        _ => {
            // handle all other commands
        }
    }
}

Development

  • This project is easier to develop with just, a modern alternative to make. Install it with cargo install just.
  • To get a list of available commands, run just.
  • To run tests, use just test.
  • On git push, it will run a few validations, including cargo fmt, cargo clippy, and cargo test. Use git push --no-verify to skip these checks.

Credits

The code was forked from the amazing rnd-ash/ecu_diagnostics project. The code was forked from the last MIT-versioned code before the MIT to GPL license migration. Initially, this code was developed as a deprecated auto_uds crate.

License

Licensed under either of

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~260–780KB
~18K SLoC