Skip to content

Real Hardware and Safety

farzad edited this page Oct 7, 2026 · 1 revision

Real Hardware and Safety

Peykan works with any adapter python-can supports. Because the tools are driven by an AI model, it is read-only on real hardware until you opt in, and every frame it sends is checked and logged.

Adapters

Adapter PEYKAN_CAN_INTERFACE PEYKAN_CAN_CHANNEL Notes
Linux SocketCAN (incl. many USB adapters) socketcan can0 Bring the link up first: sudo ip link set can0 up type can bitrate 500000
PEAK PCAN-USB pcan PCAN_USBBUS1 Needs the PCAN-Basic driver
Kvaser kvaser 0 Needs Kvaser CANlib
Vector vector 0 Needs the Vector XL driver; assign the application channel in Vector Hardware Config
slcan (CANable, USBtin, ...) slcan COM3 or /dev/ttyACM0 pip install "peykan[serial]"

Set the bitrate with PEYKAN_CAN_BITRATE (except SocketCAN, where the link has it). Interface-specific options can go in python-can's own config file. Passenger-car OBD buses are usually 500 kbit/s; J1939 is usually 250 kbit/s.

# Windows (PowerShell): read-only diagnostics through a PCAN adapter
$env:PEYKAN_CAN_INTERFACE="pcan"; $env:PEYKAN_CAN_CHANNEL="PCAN_USBBUS1"
$env:PEYKAN_CAN_BITRATE="500000"; $env:PEYKAN_ALLOW_TRANSMIT="true"
peykan vin
peykan server

Use peykan server (not demo) on real hardware: demo starts the simulator, which refuses to run on a real interface (see below).

The transmit policy

Virtual bus Real hardware, default ALLOW_TRANSMIT=true + ALLOW_WRITE_SERVICES=true
Listening (frames, snapshot, monitor, J1939 DTCs, logs) ✓ ✓ ✓ ✓
Read requests: OBD Mode 01/03/09, VIN, UDS 0x22/0x19, J1939 Request PGN, DBC protocol reads ✓ blocked ✓ ✓
Write services: clear DTCs (UDS 0x14 / OBD 04), ECU reset, UDS writes/routines, DBC protocol writes, fault injection, log replay ✓ blocked blocked ✓
  • PEYKAN_TRANSMIT_ALLOWLIST=["0x7DF","0x7E0"] additionally restricts sending to those IDs. Include the IDs flow control is sent on (for UDS to the engine, 0x7E0).
  • PEYKAN_TRANSMIT_LOG_PATH=transmit.jsonl appends every frame sent or blocked as a JSON line (time, ID, data, purpose, outcome).
  • A refused request returns status "blocked" with the reason (CLI exit code 2), and nothing is sent. The server instructions tell AI clients to explain a block rather than retry.
  • get_transmit_log shows the current policy and recent traffic.

How it's enforced

safety.py::TransmitGuard wraps the bus object itself (guard.wrap(bus, purpose, write=...)) rather than relying on each tool to check before sending. That matters for ISO-TP: can-isotp sends flow-control and consecutive frames on its own, and those pass through the same check and log.

Write classification is default-deny where the service set is open-ended: for the DBC's diagnostic protocol only session start, read-data and read-memory count as reads, and any unknown service ID counts as a write.

The simulator stays off real buses

peykan simulate / demo broadcast fake ECU traffic. On a vehicle network that would confuse real ECUs, so the simulator refuses to start on anything but the virtual bus. For an isolated bench (two adapters wired to each other, no vehicle), set PEYKAN_SIMULATOR_ON_HARDWARE=true.

Network exposure

The server listens on 127.0.0.1 by default and rejects requests with a non-local Host header. Exposing it (--host 0.0.0.0) gives anyone who can reach the port the tools, with no authentication; combine that with real hardware only on a network you trust.

What hasn't been verified

The policy, ISO-TP and UDS are tested against the simulator and with hardware settings, but not yet against physical vehicles across makes. Expect differences on real cars: VIN answered by another module, security access needed for some reads, different padding. Start read-only, with a transmit log.

Clone this wiki locally