Files
ESP32-S3-Touch-LCD-5B/src/modules/tunables.h
T
julian 974082cb3e 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
2026-09-21 19:51:49 +02:00

68 lines
1.8 KiB
C++

/*
* Tunables Module
*
* Owns the link_config_t that Controller A pushes to Controller B: Patrol gauge
* calibration (tach pulses/rev, coolant PWM law) and the alert thresholds A
* evaluates. Persisted in NVS. Editable at runtime over the USB serial console
* ("cfg help") until a settings-screen UI exists.
*/
#pragma once
#include <Arduino.h>
#include "protocol/automotive_data.h"
namespace Tunables {
/**
* Load from NVS (or defaults if absent / size mismatch). Call after Serial.begin().
*/
void init();
/**
* Snapshot of the current configuration (thread-safe copy).
*/
link_config_t get();
/**
* Current cfg_version. Increments on every change; the UART manager re-sends
* a CONFIG frame when it sees a new value.
*/
uint8_t version();
/**
* Replace the whole configuration (bumps cfg_version, saves to NVS).
*/
void set(const link_config_t& cfg);
/**
* Reset to link_config_defaults() and save.
*/
void resetDefaults();
/**
* Set the bench override (bumps cfg_version so it is pushed to B, but NEVER
* saved to NVS - a reboot must not leave the gauges pinned to a test value).
*/
void setOverride(uint8_t mode, uint16_t rpm, uint8_t duty);
/**
* Execute one console command line ("cfg show", "cfg set tach_ppr 4", ...).
* @return true if the line was a recognised command
*/
bool handleCommand(const char* line);
/**
* Non-blocking: read pending bytes from Serial, dispatch complete lines to
* handleCommand(), then to the extra handler (if registered). Call from loop().
*/
void pollSerial();
/**
* Register a second console command handler (e.g. DiagProbe::handleCommand)
* that gets lines `cfg` does not recognise. Returns true if it consumed the line.
*/
void setExtraCommandHandler(bool (*handler)(const char* line));
} // namespace Tunables