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 <noreply@anthropic.com>
This commit is contained in:
mangavalkandClaude Opus 5.5 committed 2026-11-18 16:18:52 +01:00
1 parent c9ad39c8ed
commit 970f6a3d64
5 files changed
+220 -6

No files matched your search

+91 -3
View File
@@ -5,6 +5,7 @@
#include <algorithm>
#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 <did> <data>" on every change, "E round ..." per round.
static std::vector<String> 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<int>(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;
}
}