Files
obd_emulator/docs/UDS_PROTOCOL.md
Alexander Poletaev 2ec05d2e9d Add UDS protocol support (ISO 14229) for ECU emulator
Implement UDS Service 0x22 (Read Data By Identifier) with support for:
- Engine ECU (0x7E0): boost pressure, fuel rail pressure, lambda, torque,
  wastegate position, ignition timing, knock correction per cylinder
- DSG Transmission (0x7E1): current gear, selector position, oil temp
- Instrument Cluster (0x714): RPM, ambient light sensor

Also adds ECU_EMULATOR_SPEC.md with full protocol documentation.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-30 16:28:55 +03:00

3.9 KiB

UDS Protocol Support

Эмулятор поддерживает UDS (Unified Diagnostic Services) протокол согласно ISO 14229.

Поддерживаемые ECU

ECU Request ID Response ID Описание
Engine ECU 0x7E0 0x7E8 Блок управления двигателем
DSG Transmission 0x7E1 0x7E9 Коробка передач DSG
Instrument Cluster 0x714 0x77E Приборная панель

Формат запроса

CAN ID: Request ID ECU
Data:   [03, 22, PID_H, PID_L, 55, 55, 55, 55]
         │   │   └───┴── Data Identifier (DID)
         │   └────────── Service 0x22 (Read Data By ID)
         └────────────── Length: 3 bytes

Формат ответа

Положительный ответ

CAN ID: Response ID ECU
Data:   [Length, 62, PID_H, PID_L, DataA, DataB, ...]
              │   └───┴── Data Identifier
              └────────── Service 0x62 (positive response)

Отрицательный ответ

CAN ID: Response ID ECU
Data:   [03, 7F, 22, ErrorCode, 00, 00, 00, 00]
              │   │   └── Error code (0x31 = Request Out of Range)
              │   └────── Service that failed
              └────────── Negative Response Indicator

Поддерживаемые DIDs

Engine ECU (0x7E0 → 0x7E8)

DID Название Формула Единицы Диапазон
0x202A Boost Pressure Actual (A*256+B) * 0.1 kPa 0-400
0x2029 Boost Pressure Target (A*256+B) * 0.1 kPa 0-400
0xF423 Fuel Rail Pressure (A*256+B) * 10 kPa 0-25000
0x10C0 Lambda Actual (A*256+B) * 0.000977 λ 0.5-2.0
0x1456 Lambda Target (A*256+B) * 0.000977 λ 0.5-2.0
0x437C Torque Actual (A*256+B) * 0.1 Nm 0-500
0x39A2 Wastegate Actual (A*256+B) * 0.01 % 0-100
0x39A3 Wastegate Target (A*256+B) * 0.01 % 0-100
0x2004 Ignition Timing signed(A*256+B) * 0.01 ° -10 to 50
0x200A Timing Correction Cyl1 signed(A*256+B) * 0.01 ° -15 to 5
0x200B Timing Correction Cyl2 signed(A*256+B) * 0.01 ° -15 to 5
0x200C Timing Correction Cyl3 signed(A*256+B) * 0.01 ° -15 to 5
0x200D Timing Correction Cyl4 signed(A*256+B) * 0.01 ° -15 to 5

DSG Transmission (0x7E1 → 0x7E9)

DID Название Формула Значения
0x3816 Current Gear Lookup 0x00=N, 0x0C=R, 0x02=1, 0x04=2, 0x06=3, 0x08=4, 0x0A=5, 0x0E=6, 0x10=7
0x3815 Gear Selector Lookup 0=P, 1=R, 2=N, 3=D, 4=S, 5=M
0x1940 Trans Oil Temp A - 40 °C (-40 to 150)

Instrument Cluster (0x714 → 0x77E)

DID Название Формула Единицы
0x22D1 RPM (A*256+B) / 4 RPM
0x224D Ambient Light A 0-255 (0=dark, 255=bright)

Примеры

Запрос Boost Pressure

TX: 7E0 [03 22 20 2A 55 55 55 55]
RX: 7E8 [05 62 20 2A 07 D0 00 00]  → 0x07D0 = 2000 → 200.0 kPa

Запрос Current Gear (3rd)

TX: 7E1 [03 22 38 16 55 55 55 55]
RX: 7E9 [04 62 38 16 06 00 00 00]  → 0x06 = 3rd gear

Запрос неподдерживаемого DID

TX: 7E0 [03 22 FF FF 55 55 55 55]
RX: 7E8 [03 7F 22 31 00 00 00 00]  → Negative response: Request Out of Range

Тестирование

Используйте скрипт scripts/test_uds.py:

python scripts/test_uds.py --interface vcan0

Опции:

  • --engine - тестировать только Engine ECU
  • --dsg - тестировать только DSG
  • --cluster - тестировать только Instrument Cluster