Crate uds_client

Source
Expand description

§UDS Client for Rust (uds-client-rs)

This crate provides a Unified Diagnostic Services (UDS) client for communication with automotive ECUs (Electronic Control Units). It supports sending and receiving UDS messages over CAN using SocketCAN (Linux) and USB CAN adapters (Windows).

§Features

  • Support for UDS over CAN (ISO 14229).
  • Asynchronous API using tokio.
  • Works with both Linux (socketcan) and Windows (UsbCanSocket).

§Running an Example

To get started, you can run the provided example to test communication with an ECU.

  1. Choose the correct CAN interface:

    • Linux: Use a canX interface (e.g., can0, vcan0).
    • Windows: Uses a supported USB-CAN adapter (Peak CAN).
  2. Run the example:

cd examples/uds_client_ui
cargo run --release

§Usage

Add uds-client-rs to your Cargo.toml:

[dependencies]
uds-client-rs = "0.1"

Example usage:

use uds_client_rs::UdsClient;

#[tokio::main]
async fn main() {
    let mut client = UdsClient::new("can0", 0x784);
    if let Err(e) = client.uds_reset_118().await {
        eprintln!("Failed to request session: {:?}", e);
    }
}

§License

This project is licensed under the MIT License.

Structs§

PciByte
Represents a PCI byte, which consists of a PCI type and an associated value.
ResponseSlot
The response slot for each UDS request This struct holds the response data and a notification object to signal when the response is ready
UdsClient
UdsConsecutiveFrame
Represents a UDS Consecutive Frame. This frame is used for multi-frame transmissions after the First Frame.
UdsFirstFrame
Represents a UDS First Frame. This frame is sent when the payload is too large for a single frame. It contains the total size of the payload and the initial data.
UdsFlowControlFrame
Represents a UDS Flow Control Frame. This frame is sent by the receiver to control the flow of multi-frame transmissions.
UdsNegativeResponse
Represents a UDS Negative Response frame. This frame is sent by the ECU when a UDS request fails.
UdsSingleFrame
Represents a UDS Single Frame. This frame is used when the total payload fits within a single CAN frame.
UdsSocket
UdsSocketRx
UdsSocketTx

Enums§

DiagError
Diagnostic server error
FrameError
Represents errors that can occur while processing UDS frames.
PciType
The definition for the Protocol Control Information (PCI) byte type used in ISO 15765-2 (CAN TP).
RealTimeType
Reset ECU subcommand
Response
UdsFrame
UDS frame types: - Single Frame (SF) - First Frame (FF) - Consecutive Frame (CF) - Flow Control Frame (FC) - Negative Response Frame (NRC)

Traits§

CanSocketRx
CanSocketTx