/* * Diagnostic Probe Module * * The ONLY place this firmware transmits on the PT-CAN. Sends single OBD-II * (SAE J1979 / ISO 15031-5) requests on the functional address 0x7DF and * reassembles the ISO 15765-2 replies from 0x7E8..0x7EF, to find out whether * the DDE answers generic OBD on this bus and which PIDs it offers — the first * step of wiki/pages/obd-diagnostic-polling.md ("Route A"). * * Strictly on demand: nothing is sent unless a `diag ...` console command asks * for it, one request is in flight at a time, frames go out single-shot (no * retransmit storms if nobody ACKs), and requests are refused while another * tester (a scan tool on 0x7DF / 0x7E0..7 / 0x6F1) has been seen recently. * * Console (USB serial, same line reader as `cfg`): * diag pids scan the mode-01 supported-PID bitmaps (00, 20, 40, ...) * diag pid one mode-01 request, e.g. `diag pid 0C` (rpm) * diag dtc mode 03 — stored generic DTCs * diag vin mode 09 PID 02 — VIN (identifies the donor) * diag ecu mode 09 PID 0A — ECU name string * diag ident [addr] BMW KWP `1A 80` ECU identification on 0x6F1 (default 12 = DDE) * diag bmw raw BMW-addressed request; read-only services only * diag status counters, responders seen, tester-guard timer * diag help * * BMW requests use ISO 15765 extended addressing: TX on 0x6F1 with byte 0 = * target ECU address, reply on 0x600+address with byte 0 = 0xF1. Allowed * services are whitelisted in sendBmwRequest(): 1A (ident), 18 (DTCs), * 21/22 (read data) — never session control, resets, or writes. * * Every frame we send is echoed on the console as * CANTX,,,0,, * — the same shape as CANRAW — so a capture holds both halves of every exchange. */ #pragma once #include #include "driver/twai.h" namespace DiagProbe { /** Create the state mutex. Call once in setup(), before the CAN task starts. */ void init(); /** * Execute one console line beginning with "diag". * @return true if the line was a diag command (even if it was rejected) */ bool handleCommand(const char* line); /** Timeouts and scan sequencing. Call from loop(). */ void tick(); /** * Feed every received CAN frame here (called from the CAN task). Cheap for * IDs outside the diagnostic range. */ void onFrame(const twai_message_t& m); } // namespace DiagProbe