Files
OBD2-Simulator/README.md

151 lines
3.7 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# OBD-II ECU Simulator für SocketCAN
Dieses Projekt simuliert ein OBD-II Steuergerät (ECU) über SocketCAN auf Linux.
Es eignet sich, um Embedded-Hardware (z. B. den Kettenöler) zu testen, ohne ein echtes Fahrzeug anschließen zu müssen.
## Features
- **OBD-II Responder (11-bit IDs, ISO 15765-4)**
- Unterstützt Mode 01 / PID `0x0D` (Geschwindigkeit)
- Unterstützt Mode 01 / PID `0x0C` (Motordrehzahl)
- **Tkinter-GUI**
- Gangwahl (N/0 6)
- Gasregler (0100 %)
- Anzeige von Geschwindigkeit & Drehzahl (berechnet über einfaches Antriebsmodell)
- CAN-Interface Auswahl, Bitrate, Timeout, RESP-ID
- Link-Up/Down Steuerung direkt in der GUI
- Settings in `settings.json` speicherbar
- **Trace-Fenster**: ähnlich CANalyzer Light
- Stream-Modus (alle Frames)
- Aggregat-Modus (eine Zeile pro ID+Richtung)
- **Robust gegen Interface-Down/Up**
- Erkennt automatisch, wenn `can0` (oder anderes IF) Down geht
- Öffnet Bus neu, sobald wieder Up
## Voraussetzungen
- Linux mit SocketCAN Support
- Python ≥ 3.10
- Pakete:
```bash
pip install -r requirements.txt
````
(enthält `python-can`, `pyroute2`, `typing_extensions`, `wrapt`, `packaging`)
* Ein CAN-Interface (z. B. [CANable](https://canable.io/), `gs_usb`, Peak, vcan)
## Installation & Start
```bash
git clone <repo>
cd Kettenöler-Testsoftware
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
./start.sh
```
Das GUI startet und öffnet automatisch den Responder.
Über die Buttons „Link UP/DOWN“ kann das CAN-Interface hoch-/runtergefahren werden.
## Rechte / Berechtigungen
Um CAN-Links ohne `sudo` hoch/runter zu setzen, benötigt der Python-Interpreter die Capability `CAP_NET_ADMIN`:
```bash
sudo setcap cap_net_admin,cap_net_raw=eip "$(readlink -f .venv/bin/python)"
getcap "$(readlink -f .venv/bin/python)"
```
Alternativ: App mit `sudo ./start.sh` starten.
## Nutzung
1. **Interface vorbereiten**
Klassisches CAN-Interface:
```bash
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000
sudo ip link set can0 up
```
Virtuelles Interface (nur Softwaretests):
```bash
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set vcan0 up
```
2. **Simulator starten**
GUI öffnen (`./start.sh`).
3. **Test mit can-utils**
Terminal 1:
```bash
candump can0
```
Terminal 2: Anfrage nach Geschwindigkeit:
```bash
cansend can0 7DF#02010D0000000000
```
Erwartung:
* Request `7DF`
* Response `7E8` mit `03 41 0D <speed>`
Anfrage nach Drehzahl:
```bash
cansend can0 7DF#02010C0000000000
```
4. **Trace im GUI**
* „Stream“: zeigt alle Frames einzeln
* „Aggregate“: fasst pro CAN-ID zusammen (Count, Last Data)
## Projektstruktur
```
app/
├─ gui.py ← main GUI with Simulator tabs + Save/Load
├─ config.py
├─ can.py
├─ obd2.py
├─ tabs/
│ ├─ __init__.py
│ ├─ basics.py ← vehicle basics tab
│ ├─ engine.py ← engine tab
│ ├─ gearbox.py ← gearbox tab
│ └─ dtc.py ← DTC toggles tab
└─ simulation/
├─ __init__.py
├─ simulator_main.py ← VehicleSimulator wrapper used by GUI
├─ vehicle.py ← core state + module orchestration
└─ modules/
├─ __init__.py
├─ engine.py
├─ gearbox.py
└─ abs_.py
```
## Bekannte Einschränkungen
* Nur wenige PIDs implementiert (0x0C, 0x0D).
* Antwort immer mit fixer DLC=8.
* Einfaches Driveline-Modell (keine realistische Fahrzeugphysik).
* Trace-Fenster ist eine Light-Variante, kein vollwertiger CANalyzer.
## Lizenz
\[MIT] oder \[GPLv3] bitte je nach Projektziel eintragen.