Development

Clone the repository before following the development commands below.

Installation and development

Install the package from PyPI in your uv project:

uv add automotive

For development, run the following from the repository root. The Nix shell provides uv, the Rust toolchain, and native build dependencies:

nix develop
cd python
uv sync
uv run python examples/uds.py
uv check
uv format

uv check runs ty; uv format runs Ruff with default settings and a 120-character line length. uv sync installs the project and development tools; the lockfile records their versions. Use uv run maturin develop after changing Rust code when working directly in the installed development environment. For Rust formatting, run cargo fmt --all.

The Python extension always includes every adapter supported on its platform: SocketCAN on Linux, panda and PEAK USB adapters, and Vector and J2534 on Windows. Vendor drivers/DLLs and USB permissions remain necessary. The Rust crate retains feature flags for Rust applications.

DoIP over IPv4 and IPv6

await automotive.transports.doip.discover() triggers identification using IPv4 broadcast and normally collects unique vehicles for two seconds. Vehicles with incomplete VIN/GID synchronization and a valid VIN or GID add a five-second per-vehicle wait, then another identification request and collection window. Duplicate responses do not restart the synchronization timer. Connect to a result with await vehicle.connect(), or connect directly with await DoIP.connect("192.168.0.10", 0x1000). Pass the resulting transport to UDSClient as usual. No CAN adapter or administrator privileges are needed. DoIPConfig and DiscoveryConfig expose optional settings. IPv6 multicast uses DiscoveryConfig.ipv6(interface_index) with a portable numeric adapter index. await Discovery.listen() receives passive announcements without sending.

The matching blocking functions live in automotive.sync.transports.doip. See the DoIP API and async/sync examples. TLS and OEM authentication are not implemented.

For a directly connected ECU on Linux, configure the Ethernet adapter from the repository root, then run any of the four discovery combinations from python/:

sudo scripts/set_up_doip.sh eth0
cd python
uv run examples/doip.py --ipv4 --discovery active --local-address 169.254.0.1/16
uv run examples/doip.py --adapter eth0 --ipv6 --discovery active
uv run examples/doip.py --ipv4 --discovery passive
uv run examples/doip.py --adapter eth0 --ipv6 --discovery passive

The setup script defaults to tester addresses 169.254.0.1/16 and fe80::1/64. Override them with sudo scripts/set_up_doip.sh eth0 169.254.10.1/16 fe80::1234/64; use addresses distinct from the ECU and an IPv4 subnet matching its configuration. It enables IPv6, disables router advertisements/SLAAC, adds the static addresses and brings the adapter up. When NetworkManager is running, it first marks the adapter unmanaged so it retains these settings. Restore normal management after testing with sudo nmcli device set eth0 managed yes. Existing addresses/routes are retained; the static configuration lasts until reboot/reconfiguration. When iptables/ip6tables are available, it also allows incoming UDP ports 13400 and 49152–65535 on that adapter for announcements and discovery replies. These firewall rules last until a firewall reload or reboot. Unicast replies to broadcast/multicast requests may otherwise be dropped by a stateful firewall.

The examples read VIN through UDS DID 0xF190 on each discovered entity, using tester address 0x0E89 (override with --source-address 0x0E89). Active mode normally collects replies for two seconds, with the synchronization wait described above when needed. Passive mode listens until Ctrl+C; start it before powering up the ECU to receive unsolicited announcements. Active IPv4 requires --local-address, e.g. 169.254.0.1/16, to bind the source IP and derive the subnet broadcast. Passive IPv4 needs no local address: it listens on all interfaces, and diagnostic TCP connections follow OS routing. Incoming UDP port 13400 must be allowed on each receiving interface; the setup script opens the firewall only for the adapter passed to it. IPv6 requires --adapter to select the link-local multicast interface and retains link-local scopes. IPv4 needs no adapter name. Replace examples/doip.py with examples/sync/doip.py for the blocking version. The Rust example has the same options: cargo run --example doip -- --adapter eth0 --ipv6 --discovery active from the repository root. Rust resolves IPv6 adapter indices using Linux sysfs; the Python examples and library support all three desktop platforms.

Run uv run pytest tests/test_doip.py tests/test_uds.py tests/test_uds_sync.py -q for Scapy ECU tests on any platform; --run-vcan is not required.

Examples and API documentation

The async Python examples and their counterparts in examples/sync/ mirror every Rust example, including CAN transmission, PEAK bitrate configuration, ISO-TP, UDS, and firmware queries. The synchronous firmware query visits ECUs sequentially; the async version queries them concurrently. Read installed API documentation using uv run python -m pydoc automotive.protocols.uds, or Python’s help().

Run uv run python examples/can_sender.py to send one Classic CAN frame. Use uv run python examples/sync/can_sender.py for the synchronous version.

Run uv run python examples/configure_bitrate.py to configure a PEAK PCAN-USB FD adapter, or use examples/sync/configure_bitrate.py for the synchronous version.

End-to-end regression tests

On Linux, create vcan0 from the repository root:

scripts/set_up_vcan.sh

The setup script requires sudo. Then run:

cd python
uv run pytest --run-vcan -q

The regression suite starts the Scapy ECU scripts, verifies readiness, and closes/reaps them after each scenario. The shared UDS fixtures run the same async and blocking service, transfer, suppression, pending-response, validation, and timing tests over CAN ISO-TP and IPv4/IPv6 DoIP. The answering machines share UDS responses and fault cases in scripts/uds_ecu.py. CAN frame observations, adapter lifecycle, ISO-TP Classic/FD framing and flow control, and DoIP routing/discovery checks stay in their respective transport test files. Tests run serially on vcan0; do not run the Rust and Python virtual-CAN suites concurrently. Without --run-vcan, the CAN cases are skipped and the shared UDS suite still runs over both DoIP address families. Explicit CAN runs fail if prerequisites are unavailable.