No invented data: shared structure starts with nothing valid, cleared on CAN stop and bus silence; DEFAULT_* removed from the shared header
Firmware / build (push) Successful in 7m19s
Firmware / build (push) Successful in 7m19s
This commit is contained in:
@@ -772,16 +772,8 @@ static inline char* format_voltage(uint16_t voltage_x100, char* buffer) {
|
||||
return buffer;
|
||||
}
|
||||
|
||||
// ============================================================================
|
||||
// DEFAULT/TEST VALUES
|
||||
// ============================================================================
|
||||
|
||||
// Default values for testing (before CAN data is available)
|
||||
#define DEFAULT_GEAR_LEVER LEVER_PARK
|
||||
#define DEFAULT_GEARBOX_TEMP 850 // 85.0°C
|
||||
#define DEFAULT_ENGINE_OIL_TEMP 920 // 92.0°C
|
||||
#define DEFAULT_COOLANT_TEMP 890 // 89.0°C
|
||||
#define DEFAULT_BATTERY_VOLTAGE 1245 // 12.45V
|
||||
#define DEFAULT_ALERTS 0x0000 // No alerts
|
||||
// No default / test values: a field is only ever filled from a CAN frame, and
|
||||
// its VALID_FLAG_* bit says so. Removed 2026-09-28 - the bench defaults
|
||||
// (89 / 85 degC, 12.45 V) looked like real readings on Controller B.
|
||||
|
||||
#endif // _AUTOMOTIVE_DATA_H
|
||||
@@ -42,6 +42,7 @@ static QueueHandle_t g_can_event_queue = NULL;
|
||||
static can_stats_t g_can_stats = {0};
|
||||
static bool g_uart_auto_stopped = false; // Track if UART was auto-stopped due to CAN timeout
|
||||
|
||||
|
||||
// Raw frame logging: capture EVERY frame (candump-style) for offline CAN ID
|
||||
// discovery. Default ON since discovery is the current priority.
|
||||
static bool g_raw_logging = true;
|
||||
@@ -53,6 +54,22 @@ static bool g_verbose_decode = false;
|
||||
// Guarded by g_data_mutex along with g_automotive_data.
|
||||
static driveline_t g_driveline = {0};
|
||||
|
||||
/**
|
||||
* Forget every CAN-derived value: nothing may be shown or sent that the bus
|
||||
* did not say recently. Called when CAN stops and when the bus goes silent.
|
||||
*/
|
||||
static void clearSharedData() {
|
||||
if (xSemaphoreTake(UARTManager::g_data_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
|
||||
uint8_t dbg = UARTManager::g_automotive_data.debug_enabled;
|
||||
memset(&UARTManager::g_automotive_data, 0, sizeof(UARTManager::g_automotive_data));
|
||||
UARTManager::g_automotive_data.gear_lever = LEVER_UNKNOWN;
|
||||
UARTManager::g_automotive_data.debug_enabled = dbg;
|
||||
xSemaphoreGive(UARTManager::g_data_mutex);
|
||||
}
|
||||
memset(&g_driveline, 0, sizeof(g_driveline));
|
||||
g_driveline.lever = GEAR_UNKNOWN;
|
||||
}
|
||||
|
||||
// Last gear LEVER code seen on 0x1D2, for the lever-vs-gearbox cross-check.
|
||||
static gear_position_t g_last_lever = GEAR_UNKNOWN;
|
||||
// When the current disagreement started (0 = currently in agreement).
|
||||
@@ -523,6 +540,7 @@ static void canTask(void* parameter) {
|
||||
deinitTWAI();
|
||||
g_can_active = false;
|
||||
g_uart_auto_stopped = false; // Reset auto-stop flag
|
||||
clearSharedData();
|
||||
|
||||
// Auto-stop UART transmission (CAN drives UART)
|
||||
UARTManager::linkToCANState(false);
|
||||
@@ -595,6 +613,7 @@ static void canTask(void* parameter) {
|
||||
// CAN data is stale - auto-stop UART to prevent transmitting stale data
|
||||
ESP_LOGW("CANTask", "⚠ CAN timeout (%dms since last message), auto-stopping UART", time_since_last_rx);
|
||||
UARTManager::linkToCANState(false);
|
||||
clearSharedData(); // stale values must not come back as "valid" later
|
||||
g_uart_auto_stopped = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,30 +50,17 @@ static volatile bool g_port_ready = false; // Serial1.begin() done (in the tas
|
||||
// ============================================================================
|
||||
|
||||
/**
|
||||
* @brief Seed the shared structure until CAN data arrives.
|
||||
* @note The temperatures/voltage are marked valid so a bench without CAN still
|
||||
* exercises B's display. RPM and gear nibbles are NOT marked valid: the
|
||||
* tach output must never run on invented data.
|
||||
* @brief Start from NOTHING valid. Until a CAN frame fills a field, its valid
|
||||
* flag stays clear and B shows no value for it (user decision
|
||||
* 2026-09-28: no invented numbers, ever - the old bench defaults of
|
||||
* 89 / 85 degC and 12.45 V looked like real readings).
|
||||
*/
|
||||
static void initializeDefaultData() {
|
||||
if (xSemaphoreTake(g_data_mutex, pdMS_TO_TICKS(100)) == pdTRUE) {
|
||||
g_automotive_data.gear_lever = DEFAULT_GEAR_LEVER;
|
||||
g_automotive_data.gear_nibbles = 0;
|
||||
g_automotive_data.engine_rpm = 0;
|
||||
g_automotive_data.gearbox_oil_temp = DEFAULT_GEARBOX_TEMP;
|
||||
g_automotive_data.engine_oil_temp = DEFAULT_ENGINE_OIL_TEMP;
|
||||
g_automotive_data.coolant_temp = DEFAULT_COOLANT_TEMP;
|
||||
g_automotive_data.battery_voltage = DEFAULT_BATTERY_VOLTAGE;
|
||||
g_automotive_data.alerts = DEFAULT_ALERTS;
|
||||
|
||||
g_automotive_data.valid_flags = VALID_FLAG_GEAR_POS |
|
||||
VALID_FLAG_GEARBOX_TEMP |
|
||||
VALID_FLAG_ENGINE_TEMP |
|
||||
VALID_FLAG_COOLANT_TEMP |
|
||||
VALID_FLAG_BATTERY_VOLT |
|
||||
VALID_FLAG_ALERTS;
|
||||
|
||||
g_automotive_data.debug_enabled = 0;
|
||||
uint8_t dbg = g_automotive_data.debug_enabled;
|
||||
memset(&g_automotive_data, 0, sizeof(g_automotive_data));
|
||||
g_automotive_data.gear_lever = LEVER_UNKNOWN;
|
||||
g_automotive_data.debug_enabled = dbg;
|
||||
xSemaphoreGive(g_data_mutex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,3 +206,7 @@ With the wire connected: pairing, credential push, check and install of B's firs
|
||||
## [2026-09-27] update | Wi-Fi chip and blinking alert banner on every screen; Driveline reds
|
||||
|
||||
User: show Wi-Fi on every screen (top-right) and give a sense of urgency when a threshold is crossed. New `status_overlay.cpp` on `lv_layer_top()`: Wi-Fi chip (fixed 150 px, LONG_DOT) top-right on all three screens - the shared header's back button moved 160 px left to make room; alert banner top-centre, red blinking at 2 Hz (colour toggle from tick, no lv_anim) naming the value (`COOLANT 104 °C HOT`, `GEARBOX OIL ...`, `GEAR MISMATCH`, `BATTERY 11.20 V LOW`), steady amber for `GEARBOX COOLING`; hidden with CAN off / ignition off. Driveline: chips row moved to y 60, crossed values and their titles go red (amber for cooling), gear mismatch turns the hero ring and gear letter red and the separate mismatch label is gone. Built and flashed COM14. Untested visually and untestable on the bench (alerts need CAN frames) - user to look at the car.
|
||||
|
||||
## [2026-09-28] update | No invented data: A starts with nothing valid and forgets everything when the bus stops
|
||||
|
||||
User: "if there is no info from CAN bus, no values should be shown". Until now `UARTManager::initializeDefaultData()` seeded 89.0 / 85.0 degC and 12.45 V with their valid flags SET, so a bench B (and a car with CAN off) showed plausible fake readings. Now the shared structure starts zeroed with `valid_flags = 0` and lever UNKNOWN; every field is valid only after a CAN frame filled it. `can_driver.cpp` gained `clearSharedData()`, called on CAN stop and on the bus-silence timeout (which already stopped the link) so stale values never come back marked valid. The `DEFAULT_*` block left the shared header (copied to B, `cmp`-identical). Driveline and B already key everything off the valid flags, so they show `--` / hidden needles. Flashed COM14; B's RX log now shows `Valid:0x00`. Released as v0.1.9 (v0.1.8, tagged minutes earlier, still carries the defaults - do not install it).
|
||||
|
||||
Reference in New Issue
Block a user