Add diag console probe (OBD-II mode 01/09 on 0x7DF); wiki: diagnostic polling, two sources

Firmware:
- CANDriver::transmit(): the single sanctioned transmit path (single-shot,
  echoed as CANTX lines, TX_FAILED alert counted); CAN-task warnings now take
  the serial lock
- DiagProbe module: `diag pids` supported-PID bitmap scan, `diag pid <hex>`,
  `diag vin`, `diag ecu`, `diag status`; ISO-TP reassembly with flow control;
  one request in flight, refused for 3 s after any foreign tester frame
- Console dispatch chained via Tunables::setExtraCommandHandler()
- CLAUDE.md and docs/UART_PROTOCOL.md updated

Wiki:
- New page obd-diagnostic-polling (broadcast vs polled, 0x6F1->0x612 addressing,
  Route A generic OBD PID table, Route B, test-day procedure, firmware probe)
- New sources: google-ai-dde7m57-pids (clipping, unverified, 0x612 direction
  contradicted), dwr-335d-torque-pids (thread + raw/BMW 335d.csv decoded)
- Clippings/ folder added to the schema (Obsidian Web Clipper, treated as raw/)
- bmw-m57n-engine, can-bus-integration, open-questions, index, log updated
This commit is contained in:
2026-09-21 19:51:49 +02:00
parent f60bdac268
commit 974082cb3e
21 changed files with 1357 additions and 24 deletions
+47 -4
View File
@@ -10,6 +10,7 @@
#include "modules/settings_manager.h"
#include "modules/serial_lock.h"
#include "modules/tunables.h"
#include "modules/diag_probe.h"
#include "esp_log.h"
// Import shared data from UARTManager namespace
@@ -339,9 +340,10 @@ static bool parseCANMessage(const twai_message_t& message) {
*
* @param message Received TWAI message
*/
static void emitRawFrame(const twai_message_t& message) {
static void emitFrameLine(const char* prefix, const twai_message_t& message) {
char buf[72];
int n = snprintf(buf, sizeof(buf), "CANRAW,%lu,%03lX,%u,%u,",
int n = snprintf(buf, sizeof(buf), "%s,%lu,%03lX,%u,%u,",
prefix,
(unsigned long)millis(),
(unsigned long)message.identifier,
(unsigned)(message.extd ? 1 : 0),
@@ -370,9 +372,12 @@ static void handleRxMessage(twai_message_t& message) {
// Raw capture FIRST, before parse — logs every frame including unknown IDs
if (g_raw_logging) {
emitRawFrame(message);
emitFrameLine("CANRAW", message);
}
// Diagnostic replies (0x7E8..) and foreign-tester detection
DiagProbe::onFrame(message);
// Auto-restart UART if it was stopped due to CAN timeout
if (g_uart_auto_stopped) {
ESP_LOGI("CANDrv", "✓ CAN messages resumed, auto-restarting UART");
@@ -453,7 +458,8 @@ static bool initTWAI() {
uint32_t alerts_to_enable = TWAI_ALERT_RX_DATA |
TWAI_ALERT_ERR_PASS |
TWAI_ALERT_BUS_ERROR |
TWAI_ALERT_RX_QUEUE_FULL;
TWAI_ALERT_RX_QUEUE_FULL |
TWAI_ALERT_TX_FAILED;
if (twai_reconfigure_alerts(alerts_to_enable, NULL) != ESP_OK) {
ESP_LOGE("CANDrv", "Failed to reconfigure alerts");
@@ -537,14 +543,27 @@ static void canTask(void* parameter) {
// Handle error alerts
if (alerts_triggered & TWAI_ALERT_ERR_PASS) {
SerialLock::lock();
ESP_LOGW("CANTask", "TWAI controller has become error passive");
SerialLock::unlock();
}
if (alerts_triggered & TWAI_ALERT_BUS_ERROR) {
twai_status_info_t status;
twai_get_status_info(&status);
SerialLock::lock();
ESP_LOGW("CANTask", "Bus error detected (count: %d)", status.bus_error_count);
SerialLock::unlock();
g_can_stats.parse_errors++;
}
if (alerts_triggered & TWAI_ALERT_TX_FAILED) {
// Single-shot frame got no ACK or hit a bus error: nobody is
// listening on that ID, or the bus is unhappy. Not retried.
g_can_stats.tx_failures++;
SerialLock::lock();
ESP_LOGW("CANTask", "TX failed (no ACK / bus error) - %lu so far",
(unsigned long)g_can_stats.tx_failures);
SerialLock::unlock();
}
if (alerts_triggered & TWAI_ALERT_RX_QUEUE_FULL) {
twai_status_info_t status;
twai_get_status_info(&status);
@@ -661,6 +680,30 @@ bool isActive() {
return g_can_active;
}
bool transmit(uint32_t id, const uint8_t* data, uint8_t len) {
if (!g_can_active || data == NULL || len > 8 || id > 0x7FF) {
g_can_stats.tx_failures++;
return false;
}
twai_message_t m;
memset(&m, 0, sizeof(m));
m.identifier = id;
m.extd = 0;
m.ss = 1; // single shot: never retransmit on error
m.data_length_code = len;
memcpy(m.data, data, len);
esp_err_t r = twai_transmit(&m, pdMS_TO_TICKS(20));
if (r != ESP_OK) {
g_can_stats.tx_failures++;
ESP_LOGW("CANDrv", "twai_transmit(0x%03lX) failed: %s", (unsigned long)id, esp_err_to_name(r));
return false;
}
g_can_stats.messages_transmitted++;
emitFrameLine("CANTX", m);
return true;
}
void setRawLogging(bool enabled) {
g_raw_logging = enabled;
ESP_LOGI("CANDrv", "Raw frame logging %s", enabled ? "ENABLED" : "disabled");