• Stars
    star
    161
  • Rank 233,470 (Top 5 %)
  • Language
    Rust
  • License
    GNU General Publi...
  • Created over 3 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Rust crate for ECU diagnostic protocols (UDS / KWP)

ecu_diagnostics

crates.io version docs.rs docs

A cross-platform crate for the diagnostic servers used for ECU diagnostics.

Ensure you are running Rust 1.56.0 (2021 edition) or higher to use this crate!

Features

  • Easy to use (Check the examples folder)
  • Implements UDS, KWP2000 and OBD2
  • Hardware API for accessing common OBD-2 adapter types (Passthru)
  • FFI bindings for use in C/C++ projects! (Check the examples folder)
  • Safe to use (Cannot inadvertently send incorrect requests to the ECU)
  • Parsing support - Where possible, data is returned in data structures, being interpreted from the ECU's response, rather than just bytes which have to be manually interpreted
  • ISO-TP transport layer, LIN, J1850 and DoIP is work in progress at this time
  • Diagnostic servers (For KWP2000 and UDS) automatically handle disconnects from ECU
  • Optional diagnostic server event receiving for logging internal server events

A quick overview of diagnostic servers used by ECUs

On-board diagnostics (OBD2)

ISO9141 - OBD2 is a legal requirement on all vehicles produced from 2002, allowing for reading of sensor data, reading and clearing standard DTCs, and reading basic vehicle information. OBD2 is designed to be safe and simple, and does not write data to the ECU.

Keyword protocol 2000 (KWP2000)

ISO14230 - KWP2000 is a advanced diagnostic protocol utilized by many vehicle manufacturers from 2000-2006 (Superseded by UDS). Unlike OBD2, KWP2000 allows for much more complex operations, which could potentially cause damage to a vehicle if used incorrectly.
A few examples of features allowed by KWP2000 are

  • ECU flashing
  • Clearing and reading of permanent DTCs
  • Manipulation of ECU communication parameters
  • Low level manipulation of ECU's EEPROM or RAM
  • Gateway access in vehicles which have them

The specification implemented in this crate is v2.2, dated 05-08-2002

Unified diagnostic services (UDS)

ISO14429 - UDS is an advanced diagnostic protocol utilized by almost all vehicle manufacturers from 2006 onwards. Like KWP2000, this protocol allows for reading/writing directly to the ECU, and should therefore be used with caution.

The specification implemented in this crate is the second edition, dated 01-12-2006.

NEW (as of v0.91 UNIFIED DIAGNOSTIC SERVER)

The individual diagnostic servers are now merged into 1 diagnostic server that can handle all the different protocols (Diagnostic protocol is specified at the servers creation). This dramatically reduces the crates bloat (Less copy/paste code), and the refactoring has also introduced some new features:

  • It is also possible now to define your own ECU Diagnostic protocol and session modes. Check the examples folder for how to do this!
  • You can now set a hook function for when the ECU has received the request and is processing (Useful for longer running operations)
  • You can now set a hook function for when transmit is completed and the server is waiting for the ECUs reply
  • The diagnostic server can now inform you if the ECU is connected or has been disconnected
  • The diagnostic server can now automtically change the ECUs diagnostic session mode after a reboot to avoid 'ServiceNotSupportedInActiveSession'

Diagnostic server checklist

OBD2

Custom service support: YES

Working specification services:

  • Service 01 - Show current data
  • Service 02 - Show data of freeze frame
  • Service 09 - Request vehicle information

KWP2000

Custom service support: YES

Working specification services:

  • StartDiagnosticSession
  • ECUReset
  • ReadDTCByStatus
  • ReadECUIdentification
  • ReadStatusOfDTC
  • ClearDiagnosticInformation

UDS

Custom service support: YES

Working specification services:

  • DiagnosticSessionControl
  • ECUReset
  • ReadDTCInformation
  • SecurityAccess

Hardware API checklist

The Hardware API contains a common interface for scanning for compatible devices on a system as well as an API for creating Channels for diagnostic servers using the hardware

Passthru (SAE J2534)

  • ISO-TP
  • CAN
  • Read Battery voltage

SocketCAN

  • ISO-TP
  • CAN

D-PDU (ISO 22900-2)

TBA

Notable contributions

  • @LLBlumire
  • @nyurik (Created the automotive_diag crate, which this project now relies on)

More Repositories

1

OpenVehicleDiag

A rust based cross-platform ECU diagnostics and car hacking application, utilizing the passthru protocol
Rust
783
star
2

razer-laptop-control

Project to create driver/software to control performance of razer laptops
Rust
345
star
3

mercedes-hacking-docs

Documents on hacking and reverse engineering Mercedes vehicles
193
star
4

MBUX-Port

Custom Infotainment UI for older Mercedes vehicles (2000-2007), inspired loosely by the 2021 S Class MBUX UI
Kotlin
136
star
5

W203-canbus

Open source project for W211/W219 W203/W209 Mercs - bluetooth audio control and more!
C++
124
star
6

ultimate_nag52

An open source TCM for Daimlers 722.6 gearbox. Resource repository
100
star
7

Macchina-J2534

J2534 drivers for various Macchina hardware
C++
76
star
8

openStar

Opensource diagnostic software for Daimler vehicles, inspired by Xentry and DAS, written in Rust
Rust
49
star
9

ultimate-nag52-fw

Ultimate NAG52 firmware repository
C++
47
star
10

canviewer-rs

A Realtime CAN network viewer with DBC support
Rust
39
star
11

mb-w211-pc

A fully custom infotainment system for my W211 E55 AMG based on a PC with a custom daughter board!
Rust
24
star
12

j2534-arduino-win

Windows code for J2534 Arduino
C++
21
star
13

MacchinaM2-J2534-Rust

Cross platform J2534 API for Macchinas M2 UTD module
C++
20
star
14

rx8-reverse-engineering

Mazda RX8 hacking / reverse engineering notes and example code
20
star
15

m2-utd-passthru

Passthru API (j2534) Driver for Macchina M2 Under the dash
C++
18
star
16

J2534-Rust

Cross platform J2534 definition for Rust
Rust
12
star
17

ultimate-nag52-config-app

Ultimate-NAG52 configuration app
Rust
10
star
18

arduino-xentry-passthru

Xentry passthru with Arduino (Arduino code)
C++
7
star
19

722_6_arduino_mod

Modification to the 722.6xx automatic transmission via CanBus that allows for a more sportier appeal
C++
7
star
20

m2-utd-dpdu

D-PDU API driver for Macchina m2 under the dash
C
6
star
21

arduino-xentry-passthru-driver

Xentry passthru with Arduino (Windows code)
C++
6
star
22

EGS52_emu

Mercedes EGS52 ECU emulator
Rust
4
star
23

msts-rs

Rust based port of Microsoft Train Simulator 2001 (MSTS)
Rust
4
star
24

razerbiosunlock

Unlocks options in Razer AMI BIOS's
Python
4
star
25

ecu_debug_query_spec

An experimental specification for querying an ECU for debugging purposes over KWP or UDS
4
star
26

serial-rs

A cross-platform serial library for Rust based on pyserial
Rust
4
star
27

razer-control-center

Cross platform control center for Razer hardware - Written in Rust
Rust
4
star
28

rnd-ash

3
star
29

dpdu-rust

An implementation of the core D-PDU (ISO 22900-2) library in Rust
Rust
3
star
30

rusty_hex_edit

Hex editor written in Rust, geared torwards ECU tuning
Rust
2
star
31

serialport-rs

Rust
1
star