Repository navigation
Diagnostics and OBD
The simulator answers three diagnostic protocols on the same bus:
- OBD-II (SAE J1979), on this page
- UDS over ISO-TP, the real ISO 14229 protocol, see UDS over ISO-TP
- The DBC's own UDS-style protocol, a simplified teaching protocol defined in
vehicle.dbc, on this page
Logic in obd.py; answered by OBDResponderThread (simulator/runner.py). Requests go to the functional ID 0x7DF; the engine answers on 0x7E8. Values come from the simulated vehicle (with any active fault applied), so they agree with the DBC signals and J1939.
| Service | PID | Response |
|---|---|---|
0x01 |
0x00, 0x20, 0x40
|
Supported-PID bitmaps |
0x01 |
0x05 |
Coolant temperature, °C |
0x01 |
0x0C |
Engine RPM |
0x01 |
0x0D |
Vehicle speed, km/h |
0x01 |
0x2F |
Fuel level, % |
0x01 |
0x42 |
Control module (battery) voltage, V |
0x01 |
0x51 |
Fuel type (gasoline) |
0x03 |
Stored DTCs from the active fault (up to 3 in one frame) | |
0x09 |
0x00 |
Supported-PID bitmap |
0x09 |
0x02 |
VIN, a 20-byte multi-frame reply, answered by the ISO-TP engine ECU, see UDS over ISO-TP |
0x09 |
0x0A |
ECU name (truncated to one frame) |
A bus carries a lot of periodic traffic, so send_obd_request / peykan obd-request don't take the next frame as the answer: they wait for a frame from a response ID (0x7E8–0x7EF) whose service byte answers the request (service + 0x40, or a 0x7F negative response). On the simulator, taking the next frame returned the wrong message about 1 time in 30; on a real bus it would be most of the time.
obd.py::encode_dtc / decode_dtc implement the SAE J2012 2-byte format: P0217 ↔ 0x02 0x17. Mode 03 replies are decoded into a dtcs list.
peykan obd-request --service 0x01 --pid 0x0C # RPM
peykan obd-request --service 0x03 # stored DTCsor the send_obd_request tool. Mode 0x04 (clear DTCs) and 0x08 count as write services under the transmit policy.
vehicle.dbc defines a deliberately simple protocol: one request frame, DIAGNOSTIC_REQUEST (ID 1047), and one response frame per ECU (DIAGNOSTIC_RESPONSE_ENGINE/ABS/AIRBAG/BODY, IDs 1048–1051). The request has no target field, so every ECU answers each request. Logic is in diagnostics.py; the responder is DiagnosticResponderThread.
This is a teaching protocol for working with DBC-encoded diagnostics. For real ECUs use UDS over ISO-TP.
| Service | ID | Simulator behaviour | Transmit policy |
|---|---|---|---|
START_DIAGNOSTIC_SESSION |
0x10 |
OK | read |
RESET_ECU |
0x11 |
OK | write |
READ_DATA_BY_ID |
0x22 |
A deterministic value derived from the parameter ID | read |
ROUTINE_CONTROL |
0x2F |
SERVICE_NOT_SUPPORTED |
write |
READ_MEMORY |
0x31 |
SERVICE_NOT_SUPPORTED |
read |
WRITE_MEMORY |
0x32 |
SERVICE_NOT_SUPPORTED |
write |
| anything else | SERVICE_NOT_SUPPORTED |
write |
The numbering is this protocol's own and differs from standard UDS (0x31 is RoutineControl in ISO 14229), so the transmit policy uses the read-only list above and treats everything else, including unknown IDs, as a write.
Response codes: OK (0x00), GENERAL_REJECT (0x01), SERVICE_NOT_SUPPORTED (0x11), INVALID_FORMAT (0x21), CONDITION_NOT_CORRECT (0x22).
peykan diag-request --service-id 0x22 --parameter-id 0x05or the send_diagnostic_request tool; both collect every ECU's reply.
Getting started
Reference
Protocols
Features
Operating it
Contributing