From 970f6a3d647478d0671daf0307a5534c77d4aefa Mon Sep 17 00:00:00 2001 From: MangaValk Date: Wed, 18 Nov 2026 16:18:52 +0100 Subject: [PATCH] 12-OBD-Speed: watch mode for the unknown PCM DIDs - After the DID scan, the log page reads the 327 PCM DIDs of unknown meaning round after round and logs every change ("W did data"), 3 per request if the PCM allows it (reply split with the lengths from the scan) - tools/make_watch_dids.py generates src/watch_dids.h from the scan logs - README/CLAUDE.md: scan results, test-drive plan, git remote Co-Authored-By: Claude Opus 5.5 --- 12-OBD-Speed/README.md | 9 ++++ 12-OBD-Speed/src/obd_link.cpp | 94 +++++++++++++++++++++++++++++++++-- 12-OBD-Speed/src/watch_dids.h | 69 +++++++++++++++++++++++++ CLAUDE.md | 12 +++-- tools/make_watch_dids.py | 42 ++++++++++++++++ 5 files changed, 220 insertions(+), 6 deletions(-) create mode 100644 12-OBD-Speed/src/watch_dids.h create mode 100644 tools/make_watch_dids.py diff --git a/12-OBD-Speed/README.md b/12-OBD-Speed/README.md index 86e6999..433bde2 100644 --- a/12-OBD-Speed/README.md +++ b/12-OBD-Speed/README.md @@ -56,6 +56,15 @@ So the values have to be asked from the modules. While logging is on, the OBD ta supported ones) when the module passes the test `22F1FFF188F1FE`; a hit is re-asked one DID at a time. `E progress` every 512 DIDs (with ms/DID). 4. Every 2 s `ATSH 7DF` / `ATAR` + `010D` (speed, so the display keeps working, a bit laggy) and `ATRV`. +5. **Watch** (once the scan is done): the 327 PCM DIDs of unknown meaning in `src/watch_dids.h` (generated by + `../tools/make_watch_dids.py` from the scan logs; leaves out F1xx identification, F4xx = mode 01 copies, DExx + tables, D01A text, DD00 clock, DD01 odometer) are read round after round; every change is logged as + `W `, each round as `E round N done, s, changes`. 3 DIDs per request if the PCM allows it + (tested with `22D100D134D137`), the reply is split with the lengths from the scan. + +**Scan result (2026-11-12..18, logs `docs/canlog/scan`, `scan2`)**: only the PCM 0x7E0 answers (also with `3E00` and a 1 s +timeout); **389 supported DIDs**, ~175 ms per request, the multi-DID test `22F1FFF188F1FE` timed out (single requests). +Known: F190 VIN, F188 `JB2B-14C204-ADA`, DD01 odometer (0x021676 = 136 822 km), F4xx = mode 01 PIDs. Page: Start/Stop (remembered), Mark, progress (module, DID, %), modules found, DIDs found, last positive reply, **Reset scan** (starts over the next time logging runs). While logging the speed page shows `REC `; a tap on diff --git a/12-OBD-Speed/src/obd_link.cpp b/12-OBD-Speed/src/obd_link.cpp index ede0415..88b4d60 100644 --- a/12-OBD-Speed/src/obd_link.cpp +++ b/12-OBD-Speed/src/obd_link.cpp @@ -5,6 +5,7 @@ #include #include "can_log.h" +#include "watch_dids.h" #define RETRY_DELAY_MS 3000 #define IDLE_RETRY_DELAY_MS 30000 @@ -414,6 +415,7 @@ static uint16_t probe_addr = 0; // 0 = not started on this connection static int probe_new = 0; static int multi_did = 0; // 0 = not tested, 1 = several DIDs per request work, 2 = one at a time static uint16_t multi_module = 0; // module multi_did was tested on +static int watch_multi = 0; // watch mode: 0 = not tested (per connection), 1 = 3 per request, 2 = single static uint32_t progress_ms = 0; static String hex3(uint16_t v) @@ -570,6 +572,7 @@ static void scan_setup() next_scan_obd = 0; probe_addr = 0; multi_module = 0; + watch_multi = 0; progress_ms = millis(); scan_ready = true; } @@ -840,6 +843,92 @@ static void scan_did_step() } } +// ---------- watch (after the scan): read the unknown PCM DIDs over and over, log every change ---------- +// To find the cruise set speed / speed limit: values that only change when the set speed is changed or a +// sign is passed (marks). Up to 3 DIDs per request when the PCM allows it; the reply is split with the +// lengths known from the scan. Log: "W " on every change, "E round ..." per round. +static std::vector watch_last; // last value per WATCH_DIDS entry +static uint32_t watch_index = 0, watch_round = 0, watch_round_start = 0, watch_changes = 0; + +static void watch_record(int i, const String &data) +{ + if (data == watch_last[i]) + return; + watch_last[i] = data; + watch_changes++; + can_log_line("W " + hex4(WATCH_DIDS[i].did) + " " + data); + if (watch_round > 0) + can_log_set_frame(2, "Changed: " + hex4(WATCH_DIDS[i].did) + " = " + data.substring(0, 16)); +} + +// Reads WATCH_DIDS[i..i+n-1] in one request; false if the reply couldn't be split (then ask one by one) +static bool watch_read(int i, int n, bool &answered) +{ + String req = "22"; + for (int k = 0; k < n; k++) + req += hex4(WATCH_DIDS[i + k].did); + String r = scan_request(0x7E0, req); + answered = r != "NODATA" && r.length() && r != "?TIMEOUT"; + if (!r.startsWith("62")) + return n == 1; // single: nothing more to try; several: retry one by one + int pos = 2; + for (int k = 0; k < n; k++) + { + int len = WATCH_DIDS[i + k].len * 2; + if (r.substring(pos, pos + 4) != hex4(WATCH_DIDS[i + k].did) || (int)r.length() < pos + 4 + len) + return false; + watch_record(i + k, r.substring(pos + 4, pos + 4 + len)); + pos += 4 + len; + } + return true; +} + +static void watch_step() +{ + if (watch_last.empty()) + watch_last.resize(WATCH_COUNT); + if (watch_multi == 0) + { + // three 1-byte DIDs: reply "62D10001D13400D13700" if the PCM handles several per request + String r = scan_request(0x7E0, "22D100D134D137"); + watch_multi = (r.startsWith("62D100") && r.indexOf("D137") > 0) ? 1 : 2; + can_log_line("E watch multi-DID: " + String(watch_multi == 1 ? "yes" : "no") + " (" + r.substring(0, 24) + ")"); + watch_round_start = millis(); + } + if (watch_index >= WATCH_COUNT) + { + uint32_t ms = millis() - watch_round_start; + can_log_line("E round " + String(watch_round) + " done, " + String(ms / 1000) + " s, " + String(watch_changes) + + " changes"); + can_log_set_frame(1, "Round " + String(watch_round + 1) + ", last " + String(ms / 1000) + " s"); + watch_round++; + watch_index = 0; + watch_changes = 0; + watch_round_start = millis(); + } + int n = watch_multi == 1 ? std::min(3, WATCH_COUNT - watch_index) : 1; + bool answered; + if (!watch_read(watch_index, n, answered)) + for (int k = 0; k < n; k++) + watch_read(watch_index + k, 1, answered); + if (!answered) + { + if (++scan_silent >= 20) + { + scan_silent = 0; + can_log_line("E 7E0 not answering (watch)"); + vTaskDelay(pdMS_TO_TICKS(5000)); + return; + } + } + else + scan_silent = 0; + watch_index += n; + if ((watch_index & 0x1F) < (uint32_t)n) + can_log_set_phase("Watching PCM: round " + String(watch_round) + ", " + String(watch_index) + "/" + + String(WATCH_COUNT)); +} + // One unit of scan work (one request), with speed + voltage every 2 s static void log_step() { @@ -885,9 +974,8 @@ static void log_step() else scan_did_step(); break; - default: - can_log_set_phase("Scan finished"); - vTaskDelay(pdMS_TO_TICKS(100)); + default: // scan finished: watch the unknown DIDs + watch_step(); break; } } diff --git a/12-OBD-Speed/src/watch_dids.h b/12-OBD-Speed/src/watch_dids.h new file mode 100644 index 0000000..e3cc211 --- /dev/null +++ b/12-OBD-Speed/src/watch_dids.h @@ -0,0 +1,69 @@ +// Generated by tools/make_watch_dids.py from the DID scan logs (docs/canlog) - do not edit. +// PCM (0x7E0) DIDs with unknown meaning that are watched for changes: 327 of 389 supported. +#pragma once +#include + +struct WatchDid +{ + uint16_t did; + uint8_t len; // reply data bytes (from the scan) +}; + +static const WatchDid WATCH_DIDS[] = { + {0x0117, 1}, {0x0118, 2}, {0x0119, 1}, {0x0202, 1}, {0x0300, 4}, {0x0301, 2}, + {0x0302, 4}, {0x0303, 4}, {0x0304, 2}, {0x0307, 2}, {0x0308, 2}, {0x0309, 1}, + {0x030A, 2}, {0x030B, 1}, {0x0310, 1}, {0x0311, 1}, {0x0315, 2}, {0x0316, 2}, + {0x0317, 2}, {0x0318, 2}, {0x0319, 2}, {0x031A, 2}, {0x031B, 2}, {0x031E, 2}, + {0x0320, 1}, {0x0324, 2}, {0x032B, 1}, {0x0334, 2}, {0x0338, 2}, {0x033C, 2}, + {0x033E, 2}, {0x033F, 2}, {0x0345, 4}, {0x0348, 2}, {0x034E, 2}, {0x0353, 2}, + {0x0355, 2}, {0x0356, 2}, {0x0357, 2}, {0x035A, 2}, {0x035D, 4}, {0x035F, 2}, + {0x0371, 4}, {0x0382, 1}, {0x0388, 1}, {0x0389, 4}, {0x038A, 1}, {0x038E, 2}, + {0x038F, 2}, {0x0390, 4}, {0x0391, 4}, {0x0393, 2}, {0x0394, 4}, {0x03A0, 2}, + {0x03A1, 1}, {0x03A7, 1}, {0x03A8, 4}, {0x03A9, 4}, {0x03AA, 4}, {0x03AC, 2}, + {0x03AD, 4}, {0x03AF, 1}, {0x03B1, 2}, {0x03B3, 1}, {0x03B5, 2}, {0x03BA, 2}, + {0x03BB, 2}, {0x03BC, 2}, {0x03BD, 2}, {0x03C0, 1}, {0x03C7, 2}, {0x03C9, 2}, + {0x03CA, 1}, {0x03CD, 1}, {0x03CF, 1}, {0x03D1, 2}, {0x03D3, 2}, {0x03D4, 2}, + {0x03D7, 2}, {0x03D8, 2}, {0x03D9, 2}, {0x03DA, 2}, {0x03DC, 2}, {0x03E8, 2}, + {0x03EC, 2}, {0x03EF, 2}, {0x03FD, 2}, {0x0403, 2}, {0x0409, 1}, {0x0414, 4}, + {0x0416, 4}, {0x0418, 2}, {0x0427, 1}, {0x0429, 2}, {0x045C, 4}, {0x0461, 2}, + {0x0462, 2}, {0x0464, 1}, {0x0465, 1}, {0x0466, 2}, {0x046D, 2}, {0x046F, 1}, + {0x0470, 1}, {0x0474, 1}, {0x04A9, 4}, {0x04F7, 2}, {0x051B, 2}, {0x0546, 4}, + {0x0547, 1}, {0x054B, 1}, {0x054F, 2}, {0x0551, 2}, {0x0552, 2}, {0x0554, 2}, + {0x057D, 1}, {0x057E, 1}, {0x0580, 1}, {0x0590, 4}, {0x0591, 4}, {0x0594, 2}, + {0x0598, 2}, {0x0599, 1}, {0x059A, 1}, {0x05AB, 2}, {0x05AC, 1}, {0x05AD, 1}, + {0x05AE, 1}, {0x05B7, 4}, {0x05B8, 2}, {0x05BB, 4}, {0x05CB, 1}, {0x05E1, 4}, + {0x05E2, 1}, {0x05E3, 1}, {0x05E4, 1}, {0x05E5, 4}, {0x05E6, 4}, {0x05E7, 4}, + {0x05E8, 4}, {0x05E9, 4}, {0x05FB, 4}, {0x05FC, 2}, {0x05FD, 2}, {0x061B, 2}, + {0x0629, 2}, {0x062A, 2}, {0x062E, 2}, {0x062F, 1}, {0x0630, 1}, {0x0639, 2}, + {0x063B, 2}, {0x063C, 2}, {0x063D, 2}, {0x063E, 2}, {0x0651, 1}, {0x0654, 1}, + {0x0655, 2}, {0x0700, 4}, {0x0703, 4}, {0x0707, 1}, {0x0914, 2}, {0x0915, 2}, + {0x0917, 2}, {0x0918, 2}, {0x091A, 2}, {0x091B, 1}, {0x093C, 2}, {0x099B, 2}, + {0x09CD, 1}, {0x1126, 1}, {0x1166, 2}, {0x1167, 2}, {0x116B, 2}, {0x1279, 2}, + {0x1505, 2}, {0x16D3, 2}, {0x16D4, 2}, {0x16D7, 2}, {0x16D8, 1}, {0x16DC, 2}, + {0x1E01, 4}, {0x1E04, 4}, {0x1E09, 2}, {0x1E0A, 2}, {0x1E0C, 1}, {0x1E0D, 1}, + {0x1E0E, 1}, {0x1E0F, 1}, {0x1E10, 1}, {0x1E11, 2}, {0x1E12, 1}, {0x1E13, 2}, + {0x1E14, 2}, {0x1E15, 2}, {0x1E16, 2}, {0x1E17, 1}, {0x1E18, 4}, {0x1E19, 2}, + {0x1E1A, 2}, {0x1E1B, 2}, {0x1E1C, 2}, {0x1E1D, 2}, {0x1E23, 1}, {0x1E28, 1}, + {0x1E29, 2}, {0x1E2A, 2}, {0x1E2B, 2}, {0x1E2D, 2}, {0x1E2E, 1}, {0x1E33, 2}, + {0x1E35, 2}, {0x1E36, 2}, {0x1E37, 2}, {0x1E39, 4}, {0x1E3A, 2}, {0x1E3C, 2}, + {0x1E3D, 2}, {0x1E46, 1}, {0x1E4D, 2}, {0x1E53, 2}, {0x1E54, 2}, {0x1E55, 2}, + {0x1E56, 2}, {0x1E59, 2}, {0x1E5E, 1}, {0x1E60, 1}, {0x1EF8, 2}, {0x1EF9, 2}, + {0x1EFA, 2}, {0x2028, 2}, {0x2029, 2}, {0x2872, 2}, {0x2873, 2}, {0x2874, 1}, + {0x2B00, 4}, {0x3B40, 4}, {0x9800, 2}, {0x9801, 4}, {0x9863, 1}, {0x9864, 2}, + {0x986B, 4}, {0xA45F, 4}, {0xC011, 4}, {0xC012, 4}, {0xC1A3, 4}, {0xD002, 2}, + {0xD003, 4}, {0xD005, 4}, {0xD006, 4}, {0xD014, 4}, {0xD015, 4}, {0xD100, 1}, + {0xD127, 2}, {0xD134, 1}, {0xD137, 1}, {0xD980, 4}, {0xFD00, 2}, {0xFD01, 2}, + {0xFD02, 2}, {0xFD03, 2}, {0xFD04, 2}, {0xFD05, 2}, {0xFD06, 2}, {0xFD07, 2}, + {0xFD08, 2}, {0xFD09, 2}, {0xFD0A, 2}, {0xFD0B, 2}, {0xFD0C, 2}, {0xFD0D, 2}, + {0xFD10, 2}, {0xFD11, 2}, {0xFD12, 2}, {0xFD13, 2}, {0xFD14, 2}, {0xFD15, 2}, + {0xFD16, 2}, {0xFD17, 4}, {0xFD18, 4}, {0xFD19, 2}, {0xFD1A, 2}, {0xFD1B, 2}, + {0xFD1C, 2}, {0xFD1D, 2}, {0xFD1E, 2}, {0xFD1F, 2}, {0xFD20, 2}, {0xFD21, 2}, + {0xFD22, 2}, {0xFD23, 2}, {0xFD24, 2}, {0xFD25, 2}, {0xFD26, 2}, {0xFD27, 2}, + {0xFD28, 2}, {0xFD29, 2}, {0xFD2A, 2}, {0xFD2B, 2}, {0xFD2C, 2}, {0xFD2D, 2}, + {0xFD2E, 2}, {0xFD2F, 1}, {0xFD33, 2}, {0xFD34, 2}, {0xFD35, 2}, {0xFD36, 2}, + {0xFD37, 2}, {0xFD38, 2}, {0xFD39, 4}, {0xFD3A, 4}, {0xFD40, 2}, {0xFD41, 2}, + {0xFD4A, 2}, {0xFD4B, 2}, {0xFD4C, 2}, {0xFD4D, 2}, {0xFD5D, 2}, {0xFD5E, 2}, + {0xFD5F, 2}, {0xFD60, 2}, {0xFD61, 2}, {0xFD62, 1}, {0xFD63, 2}, {0xFD64, 4}, + {0xFD66, 4}, {0xFE24, 2}, {0xFE25, 2}, +}; +static const uint16_t WATCH_COUNT = sizeof(WATCH_DIDS) / sizeof(WATCH_DIDS[0]); diff --git a/CLAUDE.md b/CLAUDE.md index 4cc07c7..1277c2a 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -11,7 +11,7 @@ Goal: write a **new custom program** for this device. smooth. Background work (BLE/OBD polling, scans, logging, SD, a future WiFi/web UI) must never make the display stutter or lag — measure FPS before/after when adding load, and give up features/RAM elsewhere first. (Accepted exception for now: the temporary diagnostic scan slows speed updates to ~2 s; user OK'd 2026-11-08.) -- The folder is a **git repo** (local only, no remote). Commit `9ee85bf` = original kit snapshot before any cleanup. +- The folder is a **git repo**, remote `origin` = `https://mangavalk.com/mangavalk/JC3636W518EN.git` (user's own server). Commit `9ee85bf` = original kit snapshot before any cleanup. ## Hardware summary | Item | Detail | @@ -82,7 +82,7 @@ Display color format is `RGB565_SWAPPED` (ST77916 byte order, set in `lv_conf.h` |---|---| | `1-Instructions` | Spec PDF (duplicate), AIDA64 remote-sensor layout `aida_remote_1.85.rslcd`, MJPEG conversion tool (Windows .NET, converts video to 360×360 MJPEG 25 fps) | | `2-Program Example/Demo_Arduino` | **Vendor only:** `library/` (3 libs), `lv_conf.h` (vendor original), `sd/` (SD listing example; its lv_conf.h has FATFS edits), `docs/` (setup screenshots + compile instructions). The vendor's original LVGL demo sketch no longer exists unmodified. | -| `tools` | `gif_to_360.py` — converts GIFs to 360×360 for the device (Pillow; scale to cover + center crop, keeps frame timing) | +| `tools` | `gif_to_360.py` — converts GIFs to 360×360 for the device (Pillow; scale to cover + center crop, keeps frame timing); `make_watch_dids.py` — builds `12-OBD-Speed/src/watch_dids.h` from the DID scan logs | | `shared` | **Shared code for all JC3636W518 projects:** `jc3636w518.ini` (PlatformIO base config), `include/lv_conf.h` (LVGL 9.6), `lib/JC3636W518` (board library). See its `README.md` | | `12-OBD-Speed` | (+ log page: CAN logger / diagnostic DID scan, 2026-11, see "User's car") **The new program — working in the car (2026-10-23):** speed from the ELM327 over BLE as big number + arc gauge on a GIF background, battery-voltage arc in the bottom gap, idle/screen-off mode (both **verified by the user**); swipe left for the adapter menu (scan, select → remembered in NVS, auto-reconnect every 3 s), again for settings (rotation, idle/screen-off timeout), again for the background (GIF from SD `/gifs` copied into an 11.9 MB raw flash partition, own `partitions.csv`). See its `README.md` | | `13-Dash-Mount` | **3D-printed dashboard holder** (OpenSCAD, 2026-10-23; **base printed 2026-10-24, user: "perfect"**): snap-in cup with lip over the bezel + USB-C opening on the side, detent tilt hinge (36 face teeth = 10° steps, M3×20 bolt + captive nut + printed knob), flat foot for VHB tape. ASA. User's choices: adhesive base, detent hinge, M3, cable exits sideways, only a USB-C opening needed. OpenSCAD is installed (`C:\Program Files\OpenSCAD\openscad.exe`, use from bash for `-D part="..."` quoting). See its `README.md` | @@ -134,7 +134,13 @@ D127 140E, D134 00, D137 00. Scan rate only ~200 ms per DID (BLE + clone), PCM a The PCM is promising anyway: per opendbc it *receives* `IsaVLim_D_Rq` (speed limit) and it runs the cruise control. Firmware after drive 2: probe again with `3E00` + 1 s timeout (once, NVS `probed`), 3 DIDs per request (single CAN frame, hits re-asked one by one; tested per module with `22F1FFF188F1FE`), BLE interval 7.5-15 ms requested, -`E progress` line every 512 DIDs with ms/DID. Flashed, not yet driven. +`E progress` line every 512 DIDs with ms/DID. +**Scan finished (2026-11-18)**: probe found no other module; **PCM has 389 DIDs** (175 ms/DID, multi-DID test timed out). +Known: F190 = VIN (keep logs private), DD01 = odometer (136 822 km), F4xx = mode 01 copies. Single readings can't tell +which DID is the set speed / limit -> **watch mode** (flashed 2026-11-18, not yet driven): 327 unknown DIDs +(`src/watch_dids.h`, generated by `tools/make_watch_dids.py`) read in rounds (~55 s, ~20 s if 3 per request works), +changes logged as `W`. Agreed test drive: ACC at **unusual set speeds** (e.g. 47 then 63, ~2 min each, user reports the +values), marks at speed signs (user remembers the order). ## Future ideas (not started) - **Web UI hosted by the puck** (user's idea, 2026-11-12): WiFi access point / web server on the puck showing all the diff --git a/tools/make_watch_dids.py b/tools/make_watch_dids.py new file mode 100644 index 0000000..b8b6709 --- /dev/null +++ b/tools/make_watch_dids.py @@ -0,0 +1,42 @@ +"""Builds 12-OBD-Speed/src/watch_dids.h from the DID scan logs: every DID the PCM supports, with its reply +length, minus the ones whose meaning is known or that are useless for finding the cruise set speed / speed limit. + + python tools/make_watch_dids.py 12-OBD-Speed/docs/canlog 12-OBD-Speed/src/watch_dids.h +""" +import glob +import os +import re +import sys + +src, out = sys.argv[1], sys.argv[2] +dids = {} +for path in glob.glob(os.path.join(src, "**", "*.txt"), recursive=True): + for line in open(path, encoding="utf-8", errors="replace"): + m = re.match(r"^\d+ S 7E0 ([0-9A-F]{4}) ([0-9A-F]+)\s*$", line) + if m: + dids[int(m.group(1), 16)] = len(m.group(2)) // 2 + + +def skip(did, length): + if 0xF100 <= did <= 0xF1FF: # identification (part numbers, VIN) + return True + if 0xF400 <= did <= 0xF4FF: # copies of the standard mode 01 PIDs + return True + if 0xDE00 <= did <= 0xDEFF: # large tables + return True + if did in (0xD01A, 0xDD00, 0xDD01): # text, clock, odometer + return True + return length > 8 + + +keep = sorted((d, l) for d, l in dids.items() if not skip(d, l)) +with open(out, "w", newline="\n") as f: + f.write("// Generated by tools/make_watch_dids.py from the DID scan logs (docs/canlog) - do not edit.\n") + f.write(f"// PCM (0x7E0) DIDs with unknown meaning that are watched for changes: {len(keep)} of {len(dids)} supported.\n") + f.write("#pragma once\n#include \n\n") + f.write("struct WatchDid\n{\n uint16_t did;\n uint8_t len; // reply data bytes (from the scan)\n};\n\n") + f.write("static const WatchDid WATCH_DIDS[] = {\n") + for i in range(0, len(keep), 6): + f.write(" " + " ".join(f"{{0x{d:04X}, {l}}}," for d, l in keep[i:i + 6]) + "\n") + f.write("};\nstatic const uint16_t WATCH_COUNT = sizeof(WATCH_DIDS) / sizeof(WATCH_DIDS[0]);\n") +print(f"{len(keep)} of {len(dids)} DIDs -> {out}")