Engine data screen: live rail, boost, charge-air temp, battery from the DDE

New screen (Engine data button on Driveline) polls the DDE with the
Launch's KWP `2C 10 <id>` reads: 00DF rail (bar = raw x 0.03, verified),
0091 boost (mbar = raw / 8), 16A8 charge-air temp, 0093 battery - the last
three provisional (one engine-off point each), tagged on screen with the
raw value shown for calibration.

DiagProbe live mode: `2C 10 15 E0` once, then the four reads in turn, one
in flight, ~100 ms apart, quiet on the console, paused by the foreign-tester
guard, stops 1.5 s after the screen stops asking. 2C stays forbidden from
the console. CANDriver::transmit gains an echo flag (live frames echoed only
with CANRAW on). Wiki: the three CANNY captures ingested, identifier table
and the no-password decision recorded.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-07 19:48:00 +02:00
parent 40a21557f0
commit a28cbada59
17 changed files with 40926 additions and 13 deletions
+147 -1
View File
@@ -80,6 +80,23 @@ static uint32_t g_requests = 0, g_replies = 0, g_timeouts = 0, g_negatives = 0;
static uint32_t g_tx_fail_at_send = 0; // CANDriver tx_failures when the request went out
static bool g_last_req_unacked = false;
// live engine data (Engine data screen) - liveStop() is public, declared in the header
static const uint16_t LIVE_IDS[LIVE_COUNT] = {0x00DF, 0x0091, 0x16A8, 0x0093};
static const uint16_t LIVE_DEFINE_ID = 0x15E0; // the Launch sends `2C 10 15 E0` once on connect
static const uint32_t LIVE_GAP_MS = 80; // between requests (plus the loop's 100 ms tick)
static const uint32_t LIVE_KEEPALIVE_MS = 1500; // stop this long after the screen stops asking
static const uint8_t LIVE_NO_ANSWER_AFTER = 4; // consecutive timeouts
static bool g_live = false;
static bool g_live_defined = false;
static uint8_t g_live_next = 0;
static uint32_t g_live_keep_ms = 0, g_live_last_tx = 0;
static live_state_t g_live_state = LIVE_OFF;
static uint8_t g_live_misses = 0;
static bool g_live_req = false; // the request in flight is a live one (quiet)
static int8_t g_live_req_index = -1; // -1 = the define request
static struct { bool valid; uint16_t raw; uint32_t at_ms; uint8_t nrc; } g_live_vals[LIVE_COUNT];
// ============================================================================
// HELPERS
// ============================================================================
@@ -335,6 +352,28 @@ static void finishScanBlockIfPrimary(uint32_t id, const uint8_t* p, size_t n);
/** A complete ISO-TP payload from `id`. Caller holds g_mutex. */
static void handleReply(uint32_t id, const uint8_t* p, size_t n) {
if (g_live_req) {
// quiet: store and finish at once (no linger - only the DDE answers 0x612)
if (n >= 3 && p[0] == 0x7F && p[2] == 0x78) { g_deadline_ms = millis() + PENDING_EXTRA_MS; return; }
g_replies++;
g_replies_this_req++;
g_live_misses = 0;
if (g_live_req_index >= 0) {
auto& v = g_live_vals[g_live_req_index];
if (n >= 4 && p[0] == 0x6C && p[1] == 0x10) {
v.raw = (uint16_t)((p[2] << 8) | p[3]);
v.valid = true;
v.at_ms = millis();
v.nrc = 0;
} else if (n >= 3 && p[0] == 0x7F) {
v.nrc = p[2];
g_negatives++;
}
}
g_state = ST_IDLE;
g_live_req = false;
return;
}
char hex[3 * 48 + 1];
hexdump(hex, sizeof(hex), p, n > 48 ? 48 : n);
g_replies++;
@@ -540,13 +579,78 @@ static void printScanSummary() {
print("[diag] next: `diag pid 0C` (rpm) to prove a data read, `diag vin` for the donor");
}
/** One fixed `2C 10 <id>` request to the DDE for the live poll. Caller checked the guards. */
static void sendLive(int8_t index) {
uint16_t vid = index < 0 ? LIVE_DEFINE_ID : LIVE_IDS[index];
uint8_t f[8];
memset(f, PAD_BYTE, sizeof(f));
f[0] = BMW_ADDR_DDE;
f[1] = 0x04;
f[2] = 0x2C;
f[3] = 0x10;
f[4] = (uint8_t)(vid >> 8);
f[5] = (uint8_t)vid;
armRequest(0x2C, 0x10, true, BMW_ADDR_DDE);
lock();
g_live_req = true;
g_live_req_index = index;
unlock();
if (!CANDriver::transmit(BMW_TESTER_ID, f, sizeof(f), CANDriver::isRawLogging())) {
lock();
g_state = ST_IDLE;
g_live_req = false;
unlock();
}
}
static void liveTick() {
if (!g_live) return;
uint32_t now = millis();
if (now - g_live_keep_ms > LIVE_KEEPALIVE_MS) {
liveStop();
return;
}
if (!CANDriver::isActive()) { g_live_state = LIVE_CAN_OFF; return; }
lock();
bool busy = (g_state != ST_IDLE);
bool tester = (g_last_tester_ms != 0) && (now - g_last_tester_ms < TESTER_GUARD_MS);
unlock();
if (tester) {
g_live_state = LIVE_PAUSED_TESTER;
g_live_defined = false; // redo the define once the other tester is gone
return;
}
if (busy || now - g_live_last_tx < LIVE_GAP_MS) return;
g_live_state = (g_live_misses >= LIVE_NO_ANSWER_AFTER) ? LIVE_NO_ANSWER : LIVE_RUNNING;
g_live_last_tx = now;
if (!g_live_defined) {
g_live_defined = true;
sendLive(-1);
} else {
sendLive((int8_t)g_live_next);
g_live_next = (g_live_next + 1) % LIVE_COUNT;
}
}
void tick() {
if (g_state == ST_IDLE) return;
if (g_state == ST_IDLE) { liveTick(); return; }
uint32_t now = millis();
lock();
if ((int32_t)(now - g_deadline_ms) < 0) { unlock(); return; }
if (g_live_req) { // a live request timed out: count it quietly, carry on
g_state = ST_IDLE;
g_live_req = false;
g_timeouts++;
if (g_live_misses < 255) g_live_misses++;
unlock();
liveTick();
return;
}
// request over
bool got_reply = g_replies_this_req > 0;
bool scan = g_scan_active;
@@ -721,4 +825,46 @@ void init() {
if (!g_mutex) g_mutex = xSemaphoreCreateMutex();
}
// ----------------------------------------------------------------------------
// Live engine data
// ----------------------------------------------------------------------------
void liveKeepAlive() {
g_live_keep_ms = millis();
if (g_live) return;
lock();
memset(g_live_vals, 0, sizeof(g_live_vals));
unlock();
g_live = true;
g_live_defined = false;
g_live_next = 0;
g_live_misses = 0;
g_live_last_tx = 0;
g_live_state = LIVE_RUNNING;
print("[diag] live engine data ON: polling the DDE (2C 10 00DF/0091/16A8/0093)");
}
void liveStop() {
if (!g_live) return;
g_live = false;
g_live_state = LIVE_OFF;
print("[diag] live engine data OFF");
}
live_state_t liveState() {
return g_live ? g_live_state : LIVE_OFF;
}
live_value_t liveValue(live_id_t id) {
live_value_t out = {false, 0, 0, 0};
if (id >= LIVE_COUNT) return out;
lock();
out.valid = g_live_vals[id].valid;
out.raw = g_live_vals[id].raw;
out.nrc = g_live_vals[id].nrc;
out.age_ms = out.valid ? millis() - g_live_vals[id].at_ms : 0;
unlock();
return out;
}
} // namespace DiagProbe
+36
View File
@@ -28,6 +28,14 @@
* services are whitelisted in sendBmwRequest(): 1A (ident), 18 (DTCs),
* 21/22 (read data) — never session control, resets, or writes.
*
* Live engine data (Engine data screen, 2026-10-07): while the screen keeps
* calling liveKeepAlive(), the probe polls four DDE values with the same
* KWP `2C 10 <id>` requests the Launch uses (one-time `2C 10 15 E0`, then
* rail 00DF, boost 0091, charge-air temp 16A8, battery 0093 in turn, one
* request in flight, ~100 ms apart). Quiet on the console, pauses while
* another tester is on the bus, stops 1.5 s after the last keep-alive.
* `2C` is NOT allowed from the console - only these fixed frames.
*
* Every frame we send is echoed on the console as
* CANTX,<ts_ms>,<id_hex>,0,<dlc>,<data_hex>
* — the same shape as CANRAW — so a capture holds both halves of every exchange.
@@ -58,4 +66,32 @@ void tick();
*/
void onFrame(const twai_message_t& m);
// ---- Live engine data ------------------------------------------------------
typedef enum { LIVE_RAIL, LIVE_BOOST, LIVE_AIR_TEMP, LIVE_BATTERY, LIVE_COUNT } live_id_t;
typedef enum {
LIVE_OFF, // not polling
LIVE_RUNNING,
LIVE_PAUSED_TESTER, // another tester (e.g. the Launch) is polling - we stay quiet
LIVE_CAN_OFF, // CAN task stopped
LIVE_NO_ANSWER // requests go out but the DDE does not answer
} live_state_t;
typedef struct {
bool valid; // at least one reply since polling started
uint16_t raw; // last 2-byte value from `6C 10 HH LL`
uint32_t age_ms; // since that reply
uint8_t nrc; // last negative-response code (0 = none)
} live_value_t;
/** Keep the live poll running; starts it if needed. Call from loop() while the screen is shown. */
void liveKeepAlive();
/** Stop at once (leaving the screen). */
void liveStop();
live_state_t liveState();
live_value_t liveValue(live_id_t id);
} // namespace DiagProbe
+14 -1
View File
@@ -8,6 +8,8 @@
#include "drivers/can_driver.h"
#include "tuning_screen.h"
#include "settings_screen.h"
#include "engine_screen.h"
#include "ui_kit.h"
#include "esp_log.h"
namespace DrivelineScreen {
@@ -149,6 +151,11 @@ static void onScreenGesture(lv_event_t* e) {
}
}
static void onEngineData(lv_event_t* e) {
(void)e;
EngineScreen::show();
}
/**
* @brief Build the screen. Idempotent — returns immediately if already built.
*/
@@ -178,7 +185,13 @@ static void build() {
lv_label_set_text(g_mismatch_lbl, LV_SYMBOL_WARNING " GEAR MISMATCH");
lv_obj_set_style_text_font(g_mismatch_lbl, &lv_font_montserrat_14, 0);
lv_obj_set_style_text_color(g_mismatch_lbl, COL_WARN, 0);
lv_obj_align(g_mismatch_lbl, LV_ALIGN_TOP_RIGHT, -24, 24);
lv_obj_align(g_mismatch_lbl, LV_ALIGN_TOP_RIGHT, -240, 24);
// Live DDE values (rail, boost, charge-air temp, battery). A button, not a
// swipe, so polling the engine ECU never starts by accident.
lv_obj_t* eng = UiKit::button(g_screen, LV_SYMBOL_CHARGE " Engine data", 210, 56,
UiKit::BTN_SECONDARY, onEngineData, NULL);
lv_obj_align(eng, LV_ALIGN_TOP_RIGHT, -16, 10);
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
// ---- gear hero -------------------------------------------------------
+169
View File
@@ -0,0 +1,169 @@
/*
* Engine Data Screen Module Implementation - see engine_screen.h
*/
#include "engine_screen.h"
#include "ui_kit.h"
#include "diag_probe.h"
#include "driveline_screen.h"
#include "display/lvgl_v8_port.h"
namespace EngineScreen {
using namespace UiKit;
// ============================================================================
// SCALINGS (raw = the 2-byte value of `6C 10 HH LL`)
// ============================================================================
typedef struct {
DiagProbe::live_id_t id;
const char* title;
const char* unit;
float factor;
float offset;
int decimals;
bool provisional; // fitted to a single Launch reading
} channel_t;
static const channel_t CHANNELS[DiagProbe::LIVE_COUNT] = {
// verified 2026-09-23 against the Launch at two operating points
{DiagProbe::LIVE_RAIL, "Rail pressure", "bar", 0.03f, 0.0f, 1, false},
// 8271 raw <-> ~1028-1034 mbar engine off (2026-10-07): 1/8 mbar per count
{DiagProbe::LIVE_BOOST, "Boost (absolute)", "mbar", 0.125f, 0.0f, 0, true},
// 5295..5301 raw <-> Launch 36-38 C engine off (2026-10-07)
{DiagProbe::LIVE_AIR_TEMP, "Charge-air temp", "\xC2\xB0" "C", 0.01f, -15.0f, 1, true},
// 4998 raw <-> 12.27 V engine off (2026-10-07, from the capture's file name)
{DiagProbe::LIVE_BATTERY, "Battery", "V", 0.002455f, 0.0f, 2, true},
};
static const uint32_t STALE_MS = 3000; // value older than this shows "--"
// ============================================================================
// STATE
// ============================================================================
static lv_obj_t* g_screen = NULL;
static lv_obj_t* g_status = NULL;
static lv_obj_t* g_value[DiagProbe::LIVE_COUNT];
static lv_obj_t* g_raw[DiagProbe::LIVE_COUNT];
static void onBack(lv_event_t* e) {
(void)e;
DiagProbe::liveStop();
DrivelineScreen::show();
}
static void onGesture(lv_event_t* e) {
(void)e;
if (lv_indev_get_gesture_dir(lv_indev_get_act()) == LV_DIR_RIGHT) {
lv_indev_wait_release(lv_indev_get_act());
DiagProbe::liveStop();
DrivelineScreen::show();
}
}
static void makeCard(lv_obj_t* parent, int i) {
const channel_t& ch = CHANNELS[i];
lv_obj_t* c = card(parent);
lv_obj_set_size(c, 476, 200);
lv_obj_set_flex_flow(c, LV_FLEX_FLOW_COLUMN);
lv_obj_set_style_pad_all(c, 20, 0);
lv_obj_set_style_pad_row(c, 8, 0);
lv_obj_t* top = box(c, LV_FLEX_FLOW_ROW);
lv_obj_set_size(top, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_flex_align(top, LV_FLEX_ALIGN_SPACE_BETWEEN, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
label(top, ch.title, &lv_font_montserrat_24, UI_COL_MUTED);
if (ch.provisional) {
lv_obj_t* tag = label(top, "provisional", &lv_font_montserrat_14, UI_COL_AMBER);
lv_obj_set_style_border_color(tag, UI_COL_AMBER, 0);
lv_obj_set_style_border_width(tag, 1, 0);
lv_obj_set_style_radius(tag, 6, 0);
lv_obj_set_style_pad_hor(tag, 8, 0);
lv_obj_set_style_pad_ver(tag, 3, 0);
}
lv_obj_t* row = box(c, LV_FLEX_FLOW_ROW);
lv_obj_set_size(row, LV_PCT(100), LV_SIZE_CONTENT);
lv_obj_set_flex_align(row, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_END, LV_FLEX_ALIGN_END);
lv_obj_set_style_pad_column(row, 12, 0);
g_value[i] = label(row, "--", &lv_font_montserrat_48, UI_COL_TEXT);
lv_obj_t* u = label(row, ch.unit, &lv_font_montserrat_24, UI_COL_MUTED);
lv_obj_set_style_pad_bottom(u, 6, 0);
g_raw[i] = label(c, "raw --", &lv_font_montserrat_20, UI_COL_MUTED);
}
static void build() {
if (g_screen) return;
g_screen = screen();
lv_obj_add_event_cb(g_screen, onGesture, LV_EVENT_GESTURE, NULL);
header(g_screen, "ENGINE DATA", onBack);
g_status = label(g_screen, "", &lv_font_montserrat_20, UI_COL_MUTED);
lv_obj_set_pos(g_status, 24, 84);
lv_obj_t* grid = box(g_screen, LV_FLEX_FLOW_ROW_WRAP);
lv_obj_set_size(grid, 1024 - 48, 200 * 2 + 24);
lv_obj_set_pos(grid, 24, 126);
lv_obj_set_style_pad_column(grid, 24, 0);
lv_obj_set_style_pad_row(grid, 24, 0);
for (int i = 0; i < DiagProbe::LIVE_COUNT; i++) makeCard(grid, i);
}
static void refresh() {
const char* st;
lv_color_t col = UI_COL_MUTED;
switch (DiagProbe::liveState()) {
case DiagProbe::LIVE_RUNNING:
st = LV_SYMBOL_OK " Live from the engine ECU (DDE)"; col = UI_COL_OK; break;
case DiagProbe::LIVE_PAUSED_TESTER:
st = LV_SYMBOL_PAUSE " Paused: another diagnostic tester is connected (e.g. the Launch)"; col = UI_COL_AMBER; break;
case DiagProbe::LIVE_CAN_OFF:
st = LV_SYMBOL_WARNING " CAN bus is off - turn it on in Settings > System"; col = UI_COL_WARN; break;
case DiagProbe::LIVE_NO_ANSWER:
st = LV_SYMBOL_WARNING " No answer from the engine ECU - is the ignition on?"; col = UI_COL_WARN; break;
default:
st = "Starting..."; break;
}
setText(g_status, st);
setTextColor(g_status, col);
char buf[48];
for (int i = 0; i < DiagProbe::LIVE_COUNT; i++) {
const channel_t& ch = CHANNELS[i];
DiagProbe::live_value_t v = DiagProbe::liveValue(ch.id);
if (v.valid && v.age_ms < STALE_MS) {
snprintf(buf, sizeof(buf), "%.*f", ch.decimals, v.raw * ch.factor + ch.offset);
setText(g_value[i], buf);
snprintf(buf, sizeof(buf), "raw %u (0x%04X)", v.raw, v.raw);
} else {
setText(g_value[i], "--");
if (v.nrc) snprintf(buf, sizeof(buf), "refused by the ECU (NRC 0x%02X)", v.nrc);
else if (v.valid) snprintf(buf, sizeof(buf), "raw %u (stale)", v.raw);
else snprintf(buf, sizeof(buf), "raw --");
}
setText(g_raw[i], buf);
}
}
void show() {
build();
DiagProbe::liveKeepAlive();
refresh();
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_NONE, 0, 0, false); // instant: fades stutter at 1024x600
}
void tick() {
if (g_screen == NULL || lv_scr_act() != g_screen) return;
DiagProbe::liveKeepAlive(); // polling stops ~1.5 s after the screen is left
static uint32_t last = 0;
if (millis() - last < 250) return;
last = millis();
lvgl_port_lock(-1);
refresh();
lvgl_port_unlock();
}
} // namespace EngineScreen
+31
View File
@@ -0,0 +1,31 @@
/*
* Engine Data Screen Module
*
* Four live values read from the DDE (engine ECU) with the same KWP `2C 10`
* requests the Launch scanner uses: rail pressure, boost (charge-air pressure,
* actual), charge-air temperature, battery voltage. Polling (DiagProbe's live
* mode) runs only while this screen is shown and pauses while another tester
* is on the bus.
*
* Scalings come from Launch captures (wiki/pages/obd-diagnostic-polling.md);
* the ones resting on a single reading are tagged "provisional" on screen, and
* every value shows its raw number so it can be compared with the Launch.
*
* Opened from the "Engine data" button on the Driveline screen; the Driveline
* button or a right swipe goes back.
*/
#pragma once
#include <Arduino.h>
#include <lvgl.h>
namespace EngineScreen {
/** Build (idempotent) and load. Caller holds the LVGL lock. */
void show();
/** Keep the poll alive and refresh values while shown. Call from loop(); takes its own lock. */
void tick();
} // namespace EngineScreen