sgnes / ecu-simulator

Tool that simulates some vehicle diagnostic services. It can be used to test OBD-II dongles or tester tools that support the UDS (ISO 14229) and ISO-TP (ISO 15765-2) protocols.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

⚠️ This project is not maintained anymore :( It is kept here only for reference. Thanks for the feedbacks :)

ECU Simulator

This Python tool simulates some vehicle diagnostic services. It can be used to test OBD-II dongles or tester tools that support the UDS (ISO 14229) and ISO-TP (ISO 15765-2) protocols.

This tool does NOT implement the ISO-TP protocol. It just simulates a couple of OBD and UDS services. The simulation consists in receiving a diagnostic request (e.g., Request DTCs (0x03)), and responding to it according to the protocol specifications. The data of some responses (e.g., VIN) must be defined in the ecu_config.json file.

I created this project to learn more about the OBD and UDS protocols. I did my best to understand the specifications, however, if you suspect that something is implemented wrongly, please let me know. Any feedback will be very appreciated.

Supported Services

OBD-II

Service PID Description
0x01 0x00 List of supported PIDs in service 0x01
0x01 0x05 Engine coolant temperature
0x01 0x0D Vehicle speed
0x01 0x2F Fuel tank level input
0x01 0x51 Fuel type
0x03 - Request DTCs
0x09 0x00 List of supported PIDs in service 0x09
0x09 0x02 Vehicle Identification Number (VIN)
0x09 0x0A ECU name

UDS (ISO 14229)

Service ID Name Supported sub-functions Default parameters (response)
0x10 DiagnosticSessionControl session types

0x01 default
0x02 programming
0x03 extended
0x04 safety
0x11 ECUReset reset types

0x01 hardReset
0x02 keyOffOnReset
0x03 softReset
0x04 enableRapidPowerShutDown
0x05 disableRapidPowerShutDown
0x0F powerDownTime
0x19 ReadDTCInformation report types

0x02 reportDTCByStatusMask

0xFF DTCStatusAvailabilityMask
0x2F statusOfDTC

Addressing

OBD: Functional and physical. See options obd_broadcast_address and obd_ecu_address in ecu_config.json.

UDS: Physical. See option uds_ecu_address in ecu_config.json.

In both cases, only ISO-TP normal addressing (only CAN arbitration ID is used) is supported.

Requirements

  • Python3
  • SocketCAN Implementation of the CAN protocol. This kernel module is part of Linux.
  • ISO-TP kernel module It is NOT part of linux. It needs to be loaded before running the ecu-simulator. See isotp_ko_file_path in ecu_config.json.
  • isotp The ecu-simulator only uses isotp.socket, which is a wrapper for the ISO-TP kernel module.
  • python-can The ecu-simulator uses this library to log CAN messages (see loggers\logger_can.py). Note: The bus type socketcan_native is used.

Usage

The ecu-simulator sets up the CAN interface and loads the ISO-TP linux kernel module (you need to configure can_interface, can_interface_type, can_bitrate, and isotp_ko_file_path in ecu_config.json). To perform this task, the tool must be started with root privileges:

sudo python3 ecu-simulator.py

If you do not want to start the tool with root privileges, you can do the following:

# set up CAN hardware interface
sudo sh setup_can.sh <CAN interface e.g., can0> <CAN bitrate e.g., 500000> <can-isotp.ko file pyth e.g., /lib/modules/4.19.75-v7+/kernel/net/can/can-isotp.ko>

# or set up CAN virtual interface 
sudo sh setup_vcan.sh <virtual CAN interface e.g., vcan0> <can-isotp.ko file pyth e.g., /lib/modules/4.19.75-v7+/kernel/net/can/can-isotp.ko>

# and then start the tool without sudo
python3 ecu_simulator.py

Logging

The ecu-simulator provides 3 levels of logging: CAN, ISO-TP, and application level. For example, when the VIN is requested, the following is logged:

  • In can_[Timestamp].log
2020-02-05T13:08:39.188 can0 0x7df 0x0209020000000000
2020-02-05T13:08:39.192 can0 0x7e8 0x1014490200544553
2020-02-05T13:08:39.192 can0 0x7e0 0x3000050000000000
2020-02-05T13:08:39.198 can0 0x7e8 0x215456494e303132
2020-02-05T13:08:39.203 can0 0x7e8 0x2233343536373839
  • In isotp_[Timestamp].log
2020-02-05T13:08:39.498 can0 0x7df 0x0902
2020-02-05T13:08:39.499 can0 0x7e8 0x4902005445535456494e30313233343536373839
  • In ecu_simulator.log
2020-02-05T13:08:39.189 - ecu_simulator - INFO - Receiving on OBD address 0x7df from 0x7e8 Request: 0x0902
2020-02-05T13:08:39.190 - ecu_simulator - INFO - Requested OBD SID 0x9: Request vehicle information
2020-02-05T13:08:39.191 - ecu_simulator - INFO - Requested PID 0x2: Vehicle Identification Number(VIN)
2020-02-05T13:08:39.191 - ecu_simulator - INFO - Sending to 0x7e8 Response: 0x4902005445535456494e30313233343536373839

The log files have a max size of 1.5 M. A new log file is generated when this size is reached.

Test Environment

The ecu-simulator was tested on a Raspberry Pi (Raspbian, Linux Kernel 4.19) with PiCAN and SBC-CAN01 (see pic below) as CAN-Bus board.

OBD-II

The OBD-II services were tested using a real OBD-II scanner.

OBD-II test - SBC-CAN01

OBD-II test env

OBD-II test env

OBD-II test env

UDS

To test the UDS services, the Caring Caribou tool was used.

UDS test env

UDS test env

License

MIT License

Copyright (c) 2020 Luis Alberto Benthin Sanguino

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

Tool that simulates some vehicle diagnostic services. It can be used to test OBD-II dongles or tester tools that support the UDS (ISO 14229) and ISO-TP (ISO 15765-2) protocols.

License:MIT License


Languages

Language:Python 99.3%Language:Shell 0.7%