Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8c9ee2cde2 | |||
| 894178e7f0 | |||
| 037227ba34 | |||
| e10e03eb90 | |||
| 0b31c6f5f7 | |||
| 0bd8f5c14d | |||
| 1f39e5537a | |||
| bb87b3d6da | |||
| 0a58afca9a | |||
| 87801c593c |
@@ -11,6 +11,9 @@ build/
|
|||||||
*.elf
|
*.elf
|
||||||
*.map
|
*.map
|
||||||
|
|
||||||
|
# Serial monitor capture logs (transient; raw CAN dumps worth keeping go in wiki/raw/)
|
||||||
|
logs/
|
||||||
|
|
||||||
# OS files
|
# OS files
|
||||||
.DS_Store
|
.DS_Store
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
@@ -20,3 +23,5 @@ Thumbs.db
|
|||||||
*.swo
|
*.swo
|
||||||
*~
|
*~
|
||||||
ESP32-S3-Touch-LCD-5-Demo/
|
ESP32-S3-Touch-LCD-5-Demo/
|
||||||
|
# Excel lock/temp files (created while a spreadsheet is open)
|
||||||
|
~$*
|
||||||
|
|||||||
@@ -2,10 +2,13 @@
|
|||||||
* can_driver.h
|
* can_driver.h
|
||||||
*
|
*
|
||||||
* CAN Bus driver for ESP32-S3-Touch-LCD-5B using TWAI (Two-Wire Automotive Interface)
|
* CAN Bus driver for ESP32-S3-Touch-LCD-5B using TWAI (Two-Wire Automotive Interface)
|
||||||
* Reads BMW CAN messages at 500 Kbps in LISTEN_ONLY mode
|
* Reads BMW E60/E65 PT-CAN messages at 500 Kbps.
|
||||||
*
|
*
|
||||||
* Hardware: GPIO 15 (TX), GPIO 16 (RX)
|
* Hardware: GPIO 15 (TX), GPIO 16 (RX)
|
||||||
* Mode: LISTEN_ONLY (safe, won't transmit on vehicle bus)
|
* Mode: TWAI_MODE_NORMAL — the board ACKs the bus (LISTEN_ONLY can't ACK, which
|
||||||
|
* makes transmitters flood it with retries). We never call twai_transmit(),
|
||||||
|
* so behaviour is read-only in practice, but note this is a policy, not a
|
||||||
|
* hardware guarantee: nothing but discipline prevents a write.
|
||||||
* Baud: 500 Kbps
|
* Baud: 500 Kbps
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@@ -57,6 +60,47 @@ typedef struct {
|
|||||||
uint32_t last_receive_time;
|
uint32_t last_receive_time;
|
||||||
} can_stats_t;
|
} can_stats_t;
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// DRIVELINE STATE
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decoded driveline speeds. Deliberately NOT part of automotive_data_t: that
|
||||||
|
* struct is the wire format for the UART link to Controller B, and widening it
|
||||||
|
* would break the receiver. These live here until there's a reason to spend a
|
||||||
|
* protocol version bump on them.
|
||||||
|
*
|
||||||
|
* See wiki/pages/driveline-speed-signals.md for the physics and the calibration
|
||||||
|
* that output_shaft_raw still needs.
|
||||||
|
*/
|
||||||
|
typedef struct {
|
||||||
|
uint16_t engine_rpm; // 0x0AA RPM_ENG (verified)
|
||||||
|
int16_t engine_torque_x10; // 0x0A8 TORQ_AVL, available engine torque, 0.1 Nm signed
|
||||||
|
uint16_t turbine_rpm; // 0x1A2 RPM_GRB_TURB (verified). ~engine speed in
|
||||||
|
// P/N; collapses toward 0 when the box engages.
|
||||||
|
uint16_t output_shaft_raw; // 0x0BA bytes 3-4, RAW COUNTS — scaling unknown.
|
||||||
|
// Zero when the output is held, non-zero when the
|
||||||
|
// wheels turn. The only road-speed signal we have.
|
||||||
|
uint8_t pedal_percent; // 0x0AA ANG_ACPD
|
||||||
|
uint8_t engine_run_state; // 0x1D0 ST_ENGINE_RUN (ENGINE_RUN_* constants)
|
||||||
|
uint8_t gearbox_cooling; // 0x0B5 ST_OTMP_GRB (GEARBOX_COOL_* constants)
|
||||||
|
uint8_t converter_clutch; // 0x0BA ST_CCLT (CCLT_* constants). When CLOSED,
|
||||||
|
// turbine_rpm == engine_rpm by design — read this
|
||||||
|
// before interpreting the two as a slip ratio.
|
||||||
|
bool ignition_on; // 0x3B4 byte 2 low nibble. This bus's only
|
||||||
|
// ignition/terminal signal — CAS (0x130) is not
|
||||||
|
// present in the swap.
|
||||||
|
uint8_t lever; // 0x1D2 byte 0 as gear_position_t: the selected
|
||||||
|
// detent (P/R/N/D). GEAR_UNKNOWN before first frame.
|
||||||
|
uint8_t engaged_gear; // 0x1D2 byte 1: gear the box is actually in, 1..6;
|
||||||
|
// 0 = none (P/R/N, and R which is unnumbered here).
|
||||||
|
// Populated in plain D too, not just S/M.
|
||||||
|
uint8_t gear_mode; // 0x1D2 byte 4 raw: GEAR_MODE_DRIVE_AUTO / _SPORT
|
||||||
|
// / _MANUAL. Only meaningful when lever == D.
|
||||||
|
bool gear_mismatch; // lever (0x1D2) vs gearbox (0x0BA) disagree,
|
||||||
|
// sustained past the debounce window
|
||||||
|
} driveline_t;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// PUBLIC API
|
// PUBLIC API
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -84,12 +128,42 @@ namespace CANDriver {
|
|||||||
*/
|
*/
|
||||||
can_stats_t getStats();
|
can_stats_t getStats();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the decoded driveline speeds (engine / turbine / output shaft).
|
||||||
|
* Not carried over the UART link — see driveline_t.
|
||||||
|
* @return Snapshot of the current driveline state
|
||||||
|
*/
|
||||||
|
driveline_t getDriveline();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check if CAN is currently active
|
* Check if CAN is currently active
|
||||||
* @return true if CAN is receiving messages
|
* @return true if CAN is receiving messages
|
||||||
*/
|
*/
|
||||||
bool isActive();
|
bool isActive();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/disable raw frame logging (candump-style capture of EVERY frame).
|
||||||
|
* When enabled, each received frame is printed to Serial as a compact,
|
||||||
|
* greppable, re-parseable line prefixed "CANRAW," (see emitRawFrame()).
|
||||||
|
* Intended for CAN ID discovery: capture a drive, save the serial stream
|
||||||
|
* to a file, and analyze offline.
|
||||||
|
* @param enabled true to log every frame
|
||||||
|
*/
|
||||||
|
void setRawLogging(bool enabled);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return true if raw frame logging is currently enabled
|
||||||
|
*/
|
||||||
|
bool isRawLogging();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable/disable verbose per-frame DECODED logging (human-prose ESP_LOG
|
||||||
|
* lines for known/unknown IDs). Noisy; off by default so it doesn't drown
|
||||||
|
* the raw capture stream. Independent of setRawLogging().
|
||||||
|
* @param enabled true to log decoded values per frame
|
||||||
|
*/
|
||||||
|
void setVerboseDecode(bool enabled);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* UI event handler for CAN toggle switch
|
* UI event handler for CAN toggle switch
|
||||||
* @param e LVGL event
|
* @param e LVGL event
|
||||||
|
|||||||
@@ -86,30 +86,166 @@ typedef struct __attribute__((packed)) {
|
|||||||
#define VALID_FLAG_BATTERY_VOLT (1 << 4)
|
#define VALID_FLAG_BATTERY_VOLT (1 << 4)
|
||||||
#define VALID_FLAG_FAULT_CODES (1 << 5)
|
#define VALID_FLAG_FAULT_CODES (1 << 5)
|
||||||
|
|
||||||
|
// Fault code bitmap (fault_codes field). NOTE: these are OUR derived faults, not
|
||||||
|
// DDE DTCs — real fault codes are not broadcast on this bus and would require
|
||||||
|
// diagnostic request/response (see wiki/pages/can-id-candidates.md).
|
||||||
|
#define FAULT_GEAR_MISMATCH (1 << 0) // lever (0x1D2) and gearbox (0x0BA) disagree
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// CAN BUS ID MAPPINGS (BMW-Specific)
|
// CAN BUS ID MAPPINGS (BMW-Specific)
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
// BMW CAN message IDs and byte positions
|
// BMW E60/E65 PT-CAN, 500 kbps. Every ID below is an 11-bit STANDARD frame and
|
||||||
#define CAN_ID_COOLANT_TEMP 0x4F // Engine coolant temperature
|
// has been seen live on the actual swap bus. Decodes cross-checked against
|
||||||
#define CAN_BYTE_COOLANT_TEMP 0 // Byte 0
|
// HeinrichG-V12/E65_ReverseEngineering (per-ID DBC docs) AND our own captures.
|
||||||
|
// Full evidence + confidence labels: wiki/pages/can-id-candidates.md
|
||||||
|
//
|
||||||
|
// The original map (0x4F/0x55/0x201/0x1001/0x101F) was placeholder junk — those
|
||||||
|
// IDs were verified ABSENT from the bus 2026-07-15. Do not resurrect them.
|
||||||
|
|
||||||
#define CAN_ID_ENGINE_OIL_TEMP 0x55 // Engine oil temperature
|
// --- 0x1D0 "Engine Data" (DME/DDE, DLC 8, 100 ms) --------------------------
|
||||||
#define CAN_BYTE_ENGINE_OIL_TEMP 7 // Byte 7
|
#define CAN_ID_ENGINE_DATA 0x1D0
|
||||||
|
#define CAN_BYTE_COOLANT_TEMP 0 // TEMP_ENG: °C = raw - 48 (verified)
|
||||||
|
#define CAN_BYTE_ENGINE_OIL_TEMP 1 // TEMP_EOI: °C = raw - 48 (reads 0xFF here — sensor not populated on this M57N)
|
||||||
|
#define CAN_BYTE_ENGINE_STATUS 2 // bits 4-5 = ST_ENGINE_RUN
|
||||||
|
#define ENGINE_TEMP_OFFSET 48 // subtract from raw
|
||||||
|
|
||||||
#define CAN_ID_GEARBOX_TEMP 0x201 // Gearbox oil temperature
|
// ST_ENGINE_RUN (byte 2, bits 4-5)
|
||||||
#define CAN_BYTE_GEARBOX_TEMP 3 // Byte 3
|
#define ENGINE_RUN_OFF 0
|
||||||
|
#define ENGINE_RUN_STARTING 1
|
||||||
|
#define ENGINE_RUN_RUNNING 2
|
||||||
|
#define ENGINE_RUN_INVALID 3
|
||||||
|
|
||||||
#define CAN_ID_GEARBOX_DATA 0x1001 // Gearbox position and current gear
|
// --- 0x0B5 "Torque Request EGS" (EGS, DLC 8, 10 ms) ------------------------
|
||||||
#define CAN_BYTE_GEAR_POS 0 // Byte 0 (P/R/N/D/S/M)
|
#define CAN_ID_TORQUE_EGS 0x0B5
|
||||||
#define CAN_BYTE_CURRENT_GEAR 1 // Byte 1 (1-8)
|
#define CAN_BYTE_GEARBOX_TEMP 7 // TEMP_GRB: °C = raw - 40 (verified two ways)
|
||||||
|
#define GEARBOX_TEMP_OFFSET 40 // NOT 0, NOT +40 — see wiki; a 40 °C error either way
|
||||||
|
#define CAN_BYTE_GEARBOX_COOL 4 // bits 38-39 = ST_OTMP_GRB (cooling demand)
|
||||||
|
|
||||||
#define CAN_ID_BATTERY_VOLTAGE 0x101F // Battery voltage (16-bit)
|
// ST_OTMP_GRB — the box's own overheat opinion (better than thresholding temp)
|
||||||
#define CAN_BYTE_BATTERY_VOLT_H 0 // Byte 0 (high byte)
|
#define GEARBOX_COOL_NONE 0
|
||||||
#define CAN_BYTE_BATTERY_VOLT_L 1 // Byte 1 (low byte)
|
#define GEARBOX_COOL_STAGE1 1
|
||||||
|
#define GEARBOX_COOL_STAGE2 2
|
||||||
|
#define GEARBOX_COOL_INVALID 3
|
||||||
|
|
||||||
// CAN ID type: Mix of standard (0x4F, 0x55, 0x201) and extended (0x1001, 0x101F)
|
// --- 0x1D2 "Display Gearbox Data" (EGS, DLC 6, 200 ms) ---------------------
|
||||||
#define USE_EXTENDED_CAN_IDS true // Using 29-bit extended IDs for some messages
|
// Our decode is AHEAD of the published source here: the E65 repo lists this ID
|
||||||
|
// with an empty signal table. Byte 1 and byte 4 are our own work.
|
||||||
|
#define CAN_ID_GEAR_DISPLAY 0x1D2
|
||||||
|
#define CAN_BYTE_GEAR_LEVER 0 // whole-byte lever code
|
||||||
|
#define CAN_BYTE_GEAR_ENGAGED 1 // (raw >> 4) - 4 = gear 1..6; 0x0F = none
|
||||||
|
#define CAN_BYTE_GEAR_MODE 4 // 0xF0 auto / 0xF1 Sport / 0xF2 Manual
|
||||||
|
|
||||||
|
// Byte 0 lever codes (verified — every code matches the documented table)
|
||||||
|
#define GEAR_CODE_PARK 0xE1
|
||||||
|
#define GEAR_CODE_REVERSE 0xD2
|
||||||
|
#define GEAR_CODE_NEUTRAL 0xB4
|
||||||
|
#define GEAR_CODE_DRIVE 0x78 // D *and* S/M — the side-gate is physically the same detent
|
||||||
|
|
||||||
|
// Byte 4 mode codes. NOTE: 0xF2 is a PERSISTENT mode, not a downshift event —
|
||||||
|
// it holds across gears 2..6. The +/- nudges have no distinct code; the first
|
||||||
|
// tap simply promotes Sport -> Manual.
|
||||||
|
#define GEAR_MODE_DRIVE_AUTO 0xF0
|
||||||
|
#define GEAR_MODE_SPORT 0xF1
|
||||||
|
#define GEAR_MODE_MANUAL 0xF2
|
||||||
|
|
||||||
|
#define GEAR_ENGAGED_NONE 0x0F // byte 1 value in P/R/N — and in R even when engaged
|
||||||
|
|
||||||
|
// --- 0x0BA gearbox state (EGS, DLC 8, 20 ms) -------------------------------
|
||||||
|
// The ONLY source of engaged reverse: 0x1D2 byte 1 stays 0x0F in R.
|
||||||
|
#define CAN_ID_GEARBOX_STATE 0x0BA
|
||||||
|
#define CAN_BYTE_GEARBOX_TARGET 0 // low nibble = ST_GR_GRB
|
||||||
|
|
||||||
|
// ST_GR_GRB (byte 0, low nibble). Every value 1/2/3/5..0xA observed live in the
|
||||||
|
// 2026-07-17 drive capture. Value 4 remains unaccounted for.
|
||||||
|
// This nibble alone is a COMPLETE gear source: P/R/N plus 1st..6th, reverse
|
||||||
|
// included. 0x1D2 is still needed for the lever and the D/S/M mode, which this
|
||||||
|
// message does not carry.
|
||||||
|
#define GRB_TARGET_NEUTRAL 1
|
||||||
|
#define GRB_TARGET_REVERSE 2
|
||||||
|
#define GRB_TARGET_PARK 3
|
||||||
|
#define GRB_TARGET_GEAR1 5 // ..0xA = 6th
|
||||||
|
#define GRB_TARGET_GEAR6 0xA
|
||||||
|
#define GRB_TARGET_INVALID 0xF
|
||||||
|
|
||||||
|
// Byte 0 bits 6-7: ST_CCLT, torque converter lockup clutch. Relevant to any
|
||||||
|
// turbine-vs-engine ratio test: a CLOSED clutch makes turbine == engine exactly,
|
||||||
|
// so ratio ~1.0 at road speed means "locked up", not "not engaged".
|
||||||
|
#define CAN_BYTE_CONVERTER_CLUTCH 0
|
||||||
|
#define CCLT_DISENGAGED 0
|
||||||
|
#define CCLT_CONTROLLED 1
|
||||||
|
#define CCLT_CLOSED 2
|
||||||
|
#define CCLT_INVALID 3
|
||||||
|
|
||||||
|
// Bytes 3-4: output shaft speed, 16-bit little-endian. UNDOCUMENTED in every
|
||||||
|
// source. Identification is verified (rises monotonically 1st->6th under drive,
|
||||||
|
// zero whenever the output is held, including engaged-in-D). This is the
|
||||||
|
// project's only road-speed signal — there is no DSC/wheel-speed module on this
|
||||||
|
// bus.
|
||||||
|
//
|
||||||
|
// SCALING IS UNSETTLED. The upshift-schedule test earlier suggested raw * 0.125
|
||||||
|
// = rpm, but a direct Launch reference reading (128 rpm at raw 1192, 2026-07-17)
|
||||||
|
// points to ~0.107 instead and contradicts 0.125. One eyeballed point isn't a
|
||||||
|
// calibration, so this stays RAW COUNTS until a multi-point Launch sweep fixes
|
||||||
|
// the factor. Do not convert to a physical unit here.
|
||||||
|
// See wiki/pages/driveline-speed-signals.md
|
||||||
|
#define CAN_BYTE_OUTPUT_SHAFT_L 3
|
||||||
|
#define CAN_BYTE_OUTPUT_SHAFT_H 4
|
||||||
|
|
||||||
|
// PROVISIONAL output-shaft factor, from a SINGLE Launch reference reading
|
||||||
|
// (128 rpm at raw 1192, 2026-07-17) taken through a known zero. Good enough to
|
||||||
|
// put an approximate rpm on the display (±~10%), NOT good enough to trust for
|
||||||
|
// anything computed. Replace once a multi-point Launch sweep gives a real fit.
|
||||||
|
// rpm ~= raw * 1074 / 10000
|
||||||
|
#define OUTPUT_SHAFT_RPM_NUM 1074
|
||||||
|
#define OUTPUT_SHAFT_RPM_DEN 10000
|
||||||
|
|
||||||
|
static inline uint16_t can_output_shaft_rpm(uint16_t raw) {
|
||||||
|
return (uint16_t)(((uint32_t)raw * OUTPUT_SHAFT_RPM_NUM) / OUTPUT_SHAFT_RPM_DEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
// --- 0x1A2 turbine speed (EGS, DLC 4, 20 ms) -------------------------------
|
||||||
|
// Gearbox INPUT speed. Physically proves engagement: free-spins at ~engine
|
||||||
|
// speed in P/N, collapses to ~0 when the box engages against a held output.
|
||||||
|
#define CAN_ID_TURBINE_SPEED 0x1A2
|
||||||
|
#define CAN_BYTE_TURBINE_L 0
|
||||||
|
#define CAN_BYTE_TURBINE_H 1
|
||||||
|
|
||||||
|
// --- 0x0A8 "Torque 1" (DME/DDE, DLC 8, 10 ms) ------------------------------
|
||||||
|
// TORQ_AVL = torque the engine has AVAILABLE/is delivering. (0x0AA's TORQ_DVCH
|
||||||
|
// is driver DEMAND — same bit layout, so both read ~27 Nm at idle, but they
|
||||||
|
// diverge under load. This is the one to display as "engine torque".)
|
||||||
|
#define CAN_ID_TORQUE_1 0x0A8
|
||||||
|
#define CAN_BYTE_TORQUE_L 1 // TORQ_AVL low (byte 1) — see can_to_torque_x10
|
||||||
|
#define CAN_BYTE_TORQUE_H 2 // TORQ_AVL high (byte 2)
|
||||||
|
|
||||||
|
// --- 0x0AA "Torque 3" (DME/DDE, DLC 8, 10 ms) ------------------------------
|
||||||
|
#define CAN_ID_TORQUE_3 0x0AA
|
||||||
|
#define CAN_BYTE_PEDAL_POS 3 // ANG_ACPD: % = raw * 0.39063
|
||||||
|
#define CAN_BYTE_RPM_L 4 // RPM_ENG: 1/min = raw16 * 0.25
|
||||||
|
#define CAN_BYTE_RPM_H 5
|
||||||
|
#define CAN_BYTE_CRUISE_STATE 6 // low nibble = ST_CLCTR_V
|
||||||
|
|
||||||
|
// --- 0x3B4 "Power Management Battery Voltage" (DLC 8, 5 s) -----------------
|
||||||
|
#define CAN_ID_BATTERY_VOLTAGE 0x3B4
|
||||||
|
#define CAN_BYTE_BATTERY_VOLT_L 0 // U_BT: 12-bit little-endian, V = raw * 0.015
|
||||||
|
#define CAN_BYTE_BATTERY_VOLT_H 1 // low nibble only (high nibble = ST_BTSW)
|
||||||
|
#define BATTERY_RAW_INVALID 0xFFF // U_BT's not-available marker
|
||||||
|
|
||||||
|
// Byte 2 low nibble. The E65 repo calls this ST_ENGINE_RUN and the E60 VFL sheet
|
||||||
|
// calls it an engine-running flag with 0x09=running — BOTH ARE WRONG FOR US.
|
||||||
|
// Verified on this bus 2026-07-17: it tracks IGNITION, inverted, and does not
|
||||||
|
// move when the engine starts. Use 0x1D0 ST_ENGINE_RUN for engine state.
|
||||||
|
// Although 0x3B4 is nominally a 5 s periodic message, it ALSO transmits
|
||||||
|
// on-change: the ignition nibble flips instantly when the key toggles (user-
|
||||||
|
// verified), so an ignition-driven reset is effectively immediate.
|
||||||
|
#define CAN_BYTE_IGNITION 2
|
||||||
|
#define IGNITION_ON 0x00
|
||||||
|
#define IGNITION_OFF 0x09
|
||||||
|
|
||||||
|
// All IDs are 11-bit standard frames — the extended-ID assumption came from the
|
||||||
|
// bogus 0x1001/0x101F placeholders and is dead.
|
||||||
|
#define USE_EXTENDED_CAN_IDS false
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// PACKET STRUCTURE FOR UART TRANSMISSION
|
// PACKET STRUCTURE FOR UART TRANSMISSION
|
||||||
@@ -163,20 +299,169 @@ static inline bool validate_packet(const uart_packet_t* packet) {
|
|||||||
/**
|
/**
|
||||||
* Convert temperature from CAN format to internal format
|
* Convert temperature from CAN format to internal format
|
||||||
* @param can_value Raw CAN bus value
|
* @param can_value Raw CAN bus value
|
||||||
* @param offset Temperature offset (usually -40 for automotive)
|
* @param offset Value to SUBTRACT from raw (48 for 0x1D0 engine temps, 40 for 0x0B5)
|
||||||
* @return Temperature in 0.1°C units
|
* @return Temperature in 0.1°C units
|
||||||
*/
|
*/
|
||||||
static inline int16_t can_to_temperature(uint8_t can_value, int16_t offset = -40) {
|
static inline int16_t can_to_temperature(uint8_t can_value, int16_t offset) {
|
||||||
return (int16_t)((can_value + offset) * 10); // Convert to 0.1°C units
|
return (int16_t)(((int16_t)can_value - offset) * 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert voltage from CAN format to internal format
|
* Extract the raw 12-bit U_BT field from a 0x3B4 frame.
|
||||||
* @param can_value Raw CAN bus value (typically in 0.1V)
|
* The high nibble of byte 1 is ST_BTSW, NOT voltage — mask it off or you'll read
|
||||||
|
* ~4x too high.
|
||||||
|
* @param d Payload of a 0x3B4 frame (needs DLC >= 2)
|
||||||
|
* @return Raw 12-bit value; BATTERY_RAW_INVALID (0xFFF) means "not available"
|
||||||
|
*/
|
||||||
|
static inline uint16_t can_battery_raw(const uint8_t* d) {
|
||||||
|
return (uint16_t)(((d[CAN_BYTE_BATTERY_VOLT_H] & 0x0F) << 8) | d[CAN_BYTE_BATTERY_VOLT_L]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode battery voltage from a 0x3B4 frame.
|
||||||
|
* U_BT is 12-bit little-endian, factor 0.015 V — i.e. 0.01 V units = raw * 1.5.
|
||||||
|
* (Source example: raw 0x3D9 = 985 -> 14.775 V.)
|
||||||
|
*
|
||||||
|
* CAVEAT: on this bus the field reads BATTERY_RAW_INVALID almost always — the
|
||||||
|
* Power Module appears not to be retained in the swap. Check can_battery_raw()
|
||||||
|
* against BATTERY_RAW_INVALID before calling this; 0xFFF would otherwise decode
|
||||||
|
* to a confident-looking 61 V. The factor itself is also unconfirmed against a
|
||||||
|
* meter (0.015 here vs ~0.0147 implied by the E60 VFL sheet).
|
||||||
|
* See wiki/pages/can-id-candidates.md.
|
||||||
|
*
|
||||||
|
* @param d Payload of a 0x3B4 frame (needs DLC >= 2)
|
||||||
* @return Voltage in 0.01V units
|
* @return Voltage in 0.01V units
|
||||||
*/
|
*/
|
||||||
static inline uint16_t can_to_voltage(uint16_t can_value) {
|
static inline uint16_t can_to_voltage(const uint8_t* d) {
|
||||||
return can_value * 10; // Convert 0.1V to 0.01V units
|
return (uint16_t)((can_battery_raw(d) * 3) / 2); // raw * 0.015 V -> 0.01 V units
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode engine RPM from a 0x0AA frame. RPM_ENG = raw16 (Intel) * 0.25.
|
||||||
|
* @param d Payload of a 0x0AA frame (needs DLC >= 6)
|
||||||
|
*/
|
||||||
|
static inline uint16_t can_to_rpm(const uint8_t* d) {
|
||||||
|
uint16_t raw = (uint16_t)((d[CAN_BYTE_RPM_H] << 8) | d[CAN_BYTE_RPM_L]);
|
||||||
|
return (uint16_t)(raw / 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode available engine torque (TORQ_AVL) from a 0x0A8 frame.
|
||||||
|
*
|
||||||
|
* The field is a SIGNED 12-bit value at bits 12-23, factor 0.5 Nm. The user's
|
||||||
|
* spreadsheet formula (D2*256 + D1)/32 lands on the same number — algebraically
|
||||||
|
* (D2<<8|D1)/32 == ((D2<<4)|(D1>>4)) * 0.5 — but it sweeps D1's low nibble into
|
||||||
|
* the result, and those four bits are ALIV_TORQ_1_DME (the alive counter), not
|
||||||
|
* torque. That adds up to ~0.5 Nm of jitter. We mask it off and sign-extend so
|
||||||
|
* overrun/braking (negative torque) reads correctly. Verified against the repo's
|
||||||
|
* 0x0A8 worked example: C7 08 03 00 ... -> 24 Nm, with ALIV=8 in D1's low nibble.
|
||||||
|
*
|
||||||
|
* @param d Payload of a 0x0A8 frame (needs DLC >= 3)
|
||||||
|
* @return Torque in 0.1 Nm units, signed
|
||||||
|
*/
|
||||||
|
static inline int16_t can_to_torque_x10(const uint8_t* d) {
|
||||||
|
uint16_t raw12 = (uint16_t)((d[CAN_BYTE_TORQUE_H] << 4) | (d[CAN_BYTE_TORQUE_L] >> 4));
|
||||||
|
int16_t s = (raw12 & 0x800) ? (int16_t)(raw12 | 0xF000) // sign-extend 12->16 bit
|
||||||
|
: (int16_t)raw12;
|
||||||
|
return (int16_t)(s * 5); // * 0.5 Nm, expressed in 0.1 Nm units
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode gearbox turbine (input) speed from a 0x1A2 frame.
|
||||||
|
* RPM_GRB_TURB = raw16 (Intel) * 0.125 + 6.
|
||||||
|
* @param d Payload of a 0x1A2 frame (needs DLC >= 2)
|
||||||
|
*/
|
||||||
|
static inline uint16_t can_to_turbine_rpm(const uint8_t* d) {
|
||||||
|
uint16_t raw = (uint16_t)((d[CAN_BYTE_TURBINE_H] << 8) | d[CAN_BYTE_TURBINE_L]);
|
||||||
|
return (uint16_t)(raw / 8 + 6);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a raw 0x1D2 byte-0 lever code to a gear_position_t.
|
||||||
|
* D and S/M share code 0x78 — use decode_gear() to resolve them.
|
||||||
|
* @param d0 Byte 0 of a 0x1D2 frame
|
||||||
|
* @return Lever position, or GEAR_UNKNOWN if the code isn't recognized
|
||||||
|
*/
|
||||||
|
static inline gear_position_t can_to_gear_lever(uint8_t d0) {
|
||||||
|
switch (d0) {
|
||||||
|
case GEAR_CODE_PARK: return GEAR_PARK;
|
||||||
|
case GEAR_CODE_REVERSE: return GEAR_REVERSE;
|
||||||
|
case GEAR_CODE_NEUTRAL: return GEAR_NEUTRAL;
|
||||||
|
case GEAR_CODE_DRIVE: return GEAR_DRIVE; // D or S/M — see decode_gear()
|
||||||
|
default: return GEAR_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the engaged gear number from 0x1D2 byte 1.
|
||||||
|
* High nibble is a +16 ladder: 0x5F=1st .. 0xAF=6th. 0x0F = no numbered gear.
|
||||||
|
* @param d1 Byte 1 of a 0x1D2 frame
|
||||||
|
* @return 1..6, or 0 if no gear is engaged / value out of range.
|
||||||
|
* Always 0 in REVERSE — reverse is unnumbered here; use 0x0BA instead.
|
||||||
|
*/
|
||||||
|
static inline uint8_t can_to_engaged_gear(uint8_t d1) {
|
||||||
|
if (d1 == GEAR_ENGAGED_NONE) return 0;
|
||||||
|
uint8_t n = (uint8_t)((d1 >> 4) - 4);
|
||||||
|
return (n >= 1 && n <= 6) ? n : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the full 0x1D2 frame into a single displayable gear_position_t.
|
||||||
|
*
|
||||||
|
* P/R/N come straight from the lever. In the D detent, byte 4 splits plain Drive
|
||||||
|
* from the Sport/Manual side-gate; when in S/M we surface the engaged gear number
|
||||||
|
* (GEAR_MANUAL_1..6) because that's what a driver in the side-gate wants to read.
|
||||||
|
*
|
||||||
|
* @param d Payload of a 0x1D2 frame
|
||||||
|
* @param dlc Frame DLC (must be >= 5 to reach the mode byte)
|
||||||
|
* @return Gear to display, or GEAR_UNKNOWN if the lever code isn't recognized
|
||||||
|
*/
|
||||||
|
static inline gear_position_t decode_gear(const uint8_t* d, uint8_t dlc) {
|
||||||
|
if (dlc <= CAN_BYTE_GEAR_LEVER) return GEAR_UNKNOWN;
|
||||||
|
|
||||||
|
gear_position_t lever = can_to_gear_lever(d[CAN_BYTE_GEAR_LEVER]);
|
||||||
|
if (lever != GEAR_DRIVE) return lever; // P/R/N (or UNKNOWN) need no further work
|
||||||
|
|
||||||
|
// In the D detent. Without the mode byte we can't tell D from S/M — report D.
|
||||||
|
if (dlc <= CAN_BYTE_GEAR_MODE) return GEAR_DRIVE;
|
||||||
|
if (d[CAN_BYTE_GEAR_MODE] == GEAR_MODE_DRIVE_AUTO) return GEAR_DRIVE;
|
||||||
|
|
||||||
|
// Sport or Manual: show the engaged gear if the box has told us one.
|
||||||
|
if (dlc > CAN_BYTE_GEAR_ENGAGED) {
|
||||||
|
uint8_t n = can_to_engaged_gear(d[CAN_BYTE_GEAR_ENGAGED]);
|
||||||
|
if (n >= 1 && n <= 6) return (gear_position_t)(GEAR_MANUAL_1 + (n - 1));
|
||||||
|
}
|
||||||
|
return GEAR_DRIVE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Map a 0x0BA ST_GR_GRB nibble (the gearbox's own target gear) to a
|
||||||
|
* gear_position_t, for cross-checking against the lever.
|
||||||
|
* @param nibble Low nibble of 0x0BA byte 0
|
||||||
|
* @return Target gear, or GEAR_UNKNOWN if invalid/unrecognized
|
||||||
|
*/
|
||||||
|
static inline gear_position_t can_to_target_gear(uint8_t nibble) {
|
||||||
|
switch (nibble) {
|
||||||
|
case GRB_TARGET_PARK: return GEAR_PARK;
|
||||||
|
case GRB_TARGET_REVERSE: return GEAR_REVERSE;
|
||||||
|
case GRB_TARGET_NEUTRAL: return GEAR_NEUTRAL;
|
||||||
|
default: break;
|
||||||
|
}
|
||||||
|
// 5..0xA = forward gears 1..6 (same ladder as 0x1D2 byte 1)
|
||||||
|
if (nibble >= GRB_TARGET_GEAR1 && nibble <= GRB_TARGET_GEAR6) return GEAR_DRIVE;
|
||||||
|
return GEAR_UNKNOWN;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extract the engaged gear number from a 0x0BA ST_GR_GRB nibble.
|
||||||
|
* Unlike 0x1D2 byte 1, this ladder is the whole picture — but it numbers only
|
||||||
|
* the forward gears, so P/R/N still return 0.
|
||||||
|
* @param nibble Low nibble of 0x0BA byte 0
|
||||||
|
* @return 1..6, or 0 if not in a numbered forward gear
|
||||||
|
*/
|
||||||
|
static inline uint8_t can_to_target_gear_num(uint8_t nibble) {
|
||||||
|
if (nibble < GRB_TARGET_GEAR1 || nibble > GRB_TARGET_GEAR6) return 0;
|
||||||
|
return (uint8_t)(nibble - GRB_TARGET_GEAR1 + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -98,6 +98,15 @@ void ui_event_Toggle_Wifi_Switch(lv_event_t * e)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ui_event_Toggle_CAN_Bus_Switch(lv_event_t * e)
|
||||||
|
{
|
||||||
|
lv_event_code_t event_code = lv_event_get_code(e);
|
||||||
|
|
||||||
|
if(event_code == LV_EVENT_RELEASED) {
|
||||||
|
onCANBusToggle(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void ui_event_Toggle_Debug_Switch(lv_event_t * e)
|
void ui_event_Toggle_Debug_Switch(lv_event_t * e)
|
||||||
{
|
{
|
||||||
lv_event_code_t event_code = lv_event_get_code(e);
|
lv_event_code_t event_code = lv_event_get_code(e);
|
||||||
@@ -428,6 +437,7 @@ void ui_Settings_Screen_screen_init(void)
|
|||||||
|
|
||||||
lv_obj_add_event_cb(ui_Toggle_UART_Switch, ui_event_Toggle_UART_Switch, LV_EVENT_ALL, NULL);
|
lv_obj_add_event_cb(ui_Toggle_UART_Switch, ui_event_Toggle_UART_Switch, LV_EVENT_ALL, NULL);
|
||||||
lv_obj_add_event_cb(ui_Toggle_Wifi_Switch, ui_event_Toggle_Wifi_Switch, LV_EVENT_ALL, NULL);
|
lv_obj_add_event_cb(ui_Toggle_Wifi_Switch, ui_event_Toggle_Wifi_Switch, LV_EVENT_ALL, NULL);
|
||||||
|
lv_obj_add_event_cb(ui_Toggle_CAN_Bus_Switch, ui_event_Toggle_CAN_Bus_Switch, LV_EVENT_ALL, NULL);
|
||||||
lv_obj_add_event_cb(ui_Toggle_Debug_Switch, ui_event_Toggle_Debug_Switch, LV_EVENT_ALL, NULL);
|
lv_obj_add_event_cb(ui_Toggle_Debug_Switch, ui_event_Toggle_Debug_Switch, LV_EVENT_ALL, NULL);
|
||||||
lv_obj_add_event_cb(ui_Select_SSID_BTN, ui_event_Select_SSID_BTN, LV_EVENT_ALL, NULL);
|
lv_obj_add_event_cb(ui_Select_SSID_BTN, ui_event_Select_SSID_BTN, LV_EVENT_ALL, NULL);
|
||||||
lv_obj_add_event_cb(ui_Settings_Screen, ui_event_Settings_Screen, LV_EVENT_ALL, NULL);
|
lv_obj_add_event_cb(ui_Settings_Screen, ui_event_Settings_Screen, LV_EVENT_ALL, NULL);
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ extern "C" {
|
|||||||
|
|
||||||
void onUARTToggle(lv_event_t * e);
|
void onUARTToggle(lv_event_t * e);
|
||||||
void onWifiToggle(lv_event_t * e);
|
void onWifiToggle(lv_event_t * e);
|
||||||
|
void onCANBusToggle(lv_event_t * e);
|
||||||
void onDebugToggle(lv_event_t * e);
|
void onDebugToggle(lv_event_t * e);
|
||||||
void onSelectSSID(lv_event_t * e);
|
void onSelectSSID(lv_event_t * e);
|
||||||
|
|
||||||
|
|||||||
+16
-2
@@ -31,7 +31,9 @@ board = esp32-s3-wroom-1-n16r8
|
|||||||
; Upload & Monitor Settings
|
; Upload & Monitor Settings
|
||||||
; ----------------------------------------------------------------------------
|
; ----------------------------------------------------------------------------
|
||||||
upload_speed = 921600
|
upload_speed = 921600
|
||||||
monitor_speed = 115200
|
; 921600 for the fallback-UART case; ignored (nominal) when Serial = native USB
|
||||||
|
; CDC, where throughput is USB Full-Speed (~1 MB/s) and gates nothing.
|
||||||
|
monitor_speed = 921600
|
||||||
monitor_filters = esp32_exception_decoder
|
monitor_filters = esp32_exception_decoder
|
||||||
|
|
||||||
; ----------------------------------------------------------------------------
|
; ----------------------------------------------------------------------------
|
||||||
@@ -57,6 +59,16 @@ build_flags =
|
|||||||
; Arduino Core debug level (0=None, 1=Error, 3=Info, 5=Verbose)
|
; Arduino Core debug level (0=None, 1=Error, 3=Info, 5=Verbose)
|
||||||
-DCORE_DEBUG_LEVEL=3
|
-DCORE_DEBUG_LEVEL=3
|
||||||
|
|
||||||
|
; USB / Serial routing (deterministic — do not rely on core defaults)
|
||||||
|
; USB_MODE=1 -> Hardware CDC + JTAG (built-in USB-Serial-JTAG, the
|
||||||
|
; 303A:1001 port this board enumerates as)
|
||||||
|
; CDC_ON_BOOT=1 -> `Serial` maps to that native USB CDC, NOT UART0 pins.
|
||||||
|
; Gives ~1 MB/s throughput so the CANRAW frame dump
|
||||||
|
; keeps up with a busy bus (UART0 @115200 would drop
|
||||||
|
; frames), and keeps GPIO43/44 free for the RS485 UART1.
|
||||||
|
-DARDUINO_USB_MODE=1
|
||||||
|
-DARDUINO_USB_CDC_ON_BOOT=1
|
||||||
|
|
||||||
; LVGL configuration
|
; LVGL configuration
|
||||||
-DLV_CONF_INCLUDE_SIMPLE
|
-DLV_CONF_INCLUDE_SIMPLE
|
||||||
-DLV_LVGL_H_INCLUDE_SIMPLE
|
-DLV_LVGL_H_INCLUDE_SIMPLE
|
||||||
@@ -88,6 +100,8 @@ build_flags =
|
|||||||
build_unflags =
|
build_unflags =
|
||||||
-std=gnu++11
|
-std=gnu++11
|
||||||
|
|
||||||
extra_scripts =
|
; Pre-build workaround: put the nested Xtensa toolchain bin on PATH.
|
||||||
|
; See tools/fix_toolchain_path.py for the full explanation.
|
||||||
|
extra_scripts = pre:tools/fix_toolchain_path.py
|
||||||
|
|
||||||
build_type = release
|
build_type = release
|
||||||
|
|||||||
+261
-42
@@ -8,6 +8,7 @@
|
|||||||
#include "drivers/can_driver.h"
|
#include "drivers/can_driver.h"
|
||||||
#include "modules/uart_manager.h"
|
#include "modules/uart_manager.h"
|
||||||
#include "modules/settings_manager.h"
|
#include "modules/settings_manager.h"
|
||||||
|
#include "modules/serial_lock.h"
|
||||||
#include "esp_log.h"
|
#include "esp_log.h"
|
||||||
|
|
||||||
// Import shared data from UARTManager namespace
|
// Import shared data from UARTManager namespace
|
||||||
@@ -23,6 +24,12 @@ namespace CANDriver {
|
|||||||
// CAN timeout threshold - stop UART if no messages received for this duration
|
// CAN timeout threshold - stop UART if no messages received for this duration
|
||||||
#define CAN_TIMEOUT_MS 2000 // 2 seconds (for 5Hz expected rate, this is 10 missed messages)
|
#define CAN_TIMEOUT_MS 2000 // 2 seconds (for 5Hz expected rate, this is 10 missed messages)
|
||||||
|
|
||||||
|
// How long the lever (0x1D2) and the gearbox (0x0BA) must disagree before we call
|
||||||
|
// it a fault. They legitimately differ for a moment during every shift — 0x1D2 is
|
||||||
|
// a 200ms message and 0x0BA a 20ms one, so they are never perfectly in step.
|
||||||
|
// Without this window the flag would strobe on every gear change.
|
||||||
|
#define GEAR_MISMATCH_DEBOUNCE_MS 500
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// MODULE STATE
|
// MODULE STATE
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
@@ -33,10 +40,67 @@ static QueueHandle_t g_can_event_queue = NULL;
|
|||||||
static can_stats_t g_can_stats = {0};
|
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
|
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;
|
||||||
|
// Verbose per-frame DECODED prose logging. Default OFF: it's redundant with
|
||||||
|
// (and would drown) the raw capture stream. Enable only for quick eyeballing.
|
||||||
|
static bool g_verbose_decode = false;
|
||||||
|
|
||||||
|
// Driveline speeds — decoded but NOT sent over UART (see driveline_t in the header).
|
||||||
|
// Guarded by g_data_mutex along with g_automotive_data.
|
||||||
|
static driveline_t g_driveline = {0};
|
||||||
|
|
||||||
|
// 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).
|
||||||
|
static uint32_t g_mismatch_since = 0;
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// PRIVATE FUNCTIONS
|
// PRIVATE FUNCTIONS
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Cross-check the driver's lever selection against the gearbox's own
|
||||||
|
* target gear and raise a fault if they disagree for long enough.
|
||||||
|
*
|
||||||
|
* This is the "lever says R but the car isn't moving" detector: if the box never
|
||||||
|
* took the request, 0x0BA reports a different gear than the lever shows.
|
||||||
|
*
|
||||||
|
* Note this compares INTENT, not mechanical engagement — 0x0BA is a target gear.
|
||||||
|
* Proving the box physically caught requires the turbine/engine speed ratio, which
|
||||||
|
* needs output-shaft calibration to gate correctly (it reads "not engaged" whenever
|
||||||
|
* the wheels are free, e.g. on a lift). Not attempted here on purpose.
|
||||||
|
* See wiki/pages/driveline-speed-signals.md
|
||||||
|
*
|
||||||
|
* Caller must hold g_data_mutex.
|
||||||
|
* @param target Gear the gearbox reports as its target
|
||||||
|
*/
|
||||||
|
static void updateGearMismatch(gear_position_t target) {
|
||||||
|
// Ignore frames we can't interpret rather than guessing a mismatch from them.
|
||||||
|
if (target == GEAR_UNKNOWN || g_last_lever == GEAR_UNKNOWN) return;
|
||||||
|
|
||||||
|
// The lever's D detent covers D/S/M; can_to_target_gear() maps every forward
|
||||||
|
// gear to GEAR_DRIVE, so both sides are directly comparable.
|
||||||
|
bool disagrees = (target != g_last_lever);
|
||||||
|
|
||||||
|
if (!disagrees) {
|
||||||
|
g_mismatch_since = 0;
|
||||||
|
g_driveline.gear_mismatch = false;
|
||||||
|
g_automotive_data.fault_codes &= ~FAULT_GEAR_MISMATCH;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t now = millis();
|
||||||
|
if (g_mismatch_since == 0) {
|
||||||
|
g_mismatch_since = now; // start the clock, don't fault yet
|
||||||
|
} else if ((now - g_mismatch_since) >= GEAR_MISMATCH_DEBOUNCE_MS) {
|
||||||
|
g_driveline.gear_mismatch = true;
|
||||||
|
g_automotive_data.fault_codes |= FAULT_GEAR_MISMATCH;
|
||||||
|
g_automotive_data.valid_flags |= VALID_FLAG_FAULT_CODES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Parse BMW-specific CAN message and update automotive data
|
* @brief Parse BMW-specific CAN message and update automotive data
|
||||||
* @param message Received TWAI message
|
* @param message Received TWAI message
|
||||||
@@ -53,59 +117,134 @@ static bool parseCANMessage(const twai_message_t& message) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t dlc = message.data_length_code;
|
||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case CAN_ID_COOLANT_TEMP:
|
case CAN_ID_ENGINE_DATA:
|
||||||
// Engine coolant temperature (byte 0)
|
// 0x1D0: coolant (byte 0), engine oil (byte 1), engine run state (byte 2).
|
||||||
if (message.data_length_code > CAN_BYTE_COOLANT_TEMP) {
|
if (dlc > CAN_BYTE_COOLANT_TEMP) {
|
||||||
g_automotive_data.coolant_temp = can_to_temperature(data[CAN_BYTE_COOLANT_TEMP]);
|
g_automotive_data.coolant_temp =
|
||||||
|
can_to_temperature(data[CAN_BYTE_COOLANT_TEMP], ENGINE_TEMP_OFFSET);
|
||||||
g_automotive_data.valid_flags |= VALID_FLAG_COOLANT_TEMP;
|
g_automotive_data.valid_flags |= VALID_FLAG_COOLANT_TEMP;
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
break;
|
// Oil temp reads 0xFF on this M57N — the sensor isn't populated. Leave
|
||||||
|
// the valid flag clear rather than publishing -207 C as if it were real.
|
||||||
case CAN_ID_ENGINE_OIL_TEMP:
|
if (dlc > CAN_BYTE_ENGINE_OIL_TEMP && data[CAN_BYTE_ENGINE_OIL_TEMP] != 0xFF) {
|
||||||
// Engine oil temperature (byte 7)
|
g_automotive_data.engine_oil_temp =
|
||||||
if (message.data_length_code > CAN_BYTE_ENGINE_OIL_TEMP) {
|
can_to_temperature(data[CAN_BYTE_ENGINE_OIL_TEMP], ENGINE_TEMP_OFFSET);
|
||||||
g_automotive_data.engine_oil_temp = can_to_temperature(data[CAN_BYTE_ENGINE_OIL_TEMP]);
|
|
||||||
g_automotive_data.valid_flags |= VALID_FLAG_ENGINE_TEMP;
|
g_automotive_data.valid_flags |= VALID_FLAG_ENGINE_TEMP;
|
||||||
parsed = true;
|
}
|
||||||
|
if (dlc > CAN_BYTE_ENGINE_STATUS) {
|
||||||
|
g_driveline.engine_run_state = (data[CAN_BYTE_ENGINE_STATUS] >> 4) & 0x03;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CAN_ID_GEARBOX_TEMP:
|
case CAN_ID_TORQUE_EGS:
|
||||||
// Gearbox oil temperature (byte 3)
|
// 0x0B5: gearbox oil temp (byte 7) + the box's own cooling demand.
|
||||||
if (message.data_length_code > CAN_BYTE_GEARBOX_TEMP) {
|
if (dlc > CAN_BYTE_GEARBOX_TEMP) {
|
||||||
g_automotive_data.gearbox_oil_temp = can_to_temperature(data[CAN_BYTE_GEARBOX_TEMP]);
|
g_automotive_data.gearbox_oil_temp =
|
||||||
|
can_to_temperature(data[CAN_BYTE_GEARBOX_TEMP], GEARBOX_TEMP_OFFSET);
|
||||||
g_automotive_data.valid_flags |= VALID_FLAG_GEARBOX_TEMP;
|
g_automotive_data.valid_flags |= VALID_FLAG_GEARBOX_TEMP;
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
|
if (dlc > CAN_BYTE_GEARBOX_COOL) {
|
||||||
|
// ST_OTMP_GRB = bits 38-39 = byte 4, bits 6-7
|
||||||
|
g_driveline.gearbox_cooling = (data[CAN_BYTE_GEARBOX_COOL] >> 6) & 0x03;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CAN_ID_GEARBOX_DATA:
|
case CAN_ID_GEAR_DISPLAY: {
|
||||||
// Gearbox position and current gear (bytes 0 and 1)
|
// 0x1D2: the EGS publishing its whole state — byte 0 is what the driver
|
||||||
if (message.data_length_code > CAN_BYTE_CURRENT_GEAR) {
|
// selected, byte 1 is what's actually engaged, byte 4 is the mode.
|
||||||
// Byte 0: Gear position (P/R/N/D/S/M)
|
gear_position_t g = decode_gear(data, dlc);
|
||||||
g_automotive_data.gear_position = data[CAN_BYTE_GEAR_POS];
|
if (g != GEAR_UNKNOWN) {
|
||||||
|
g_automotive_data.gear_position = (uint8_t)g;
|
||||||
// Byte 1: Current gear number (1-8) - stored for future use
|
|
||||||
// Could be displayed alongside position for manual modes
|
|
||||||
|
|
||||||
g_automotive_data.valid_flags |= VALID_FLAG_GEAR_POS;
|
g_automotive_data.valid_flags |= VALID_FLAG_GEAR_POS;
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
|
// Break the frame into its pieces for the driveline screen, which
|
||||||
|
// composes its own richer label (e.g. "D3"). Keep the bare lever for
|
||||||
|
// the cross-check below: 0x0BA reports a gear, never a mode.
|
||||||
|
if (dlc > CAN_BYTE_GEAR_LEVER) {
|
||||||
|
g_last_lever = can_to_gear_lever(data[CAN_BYTE_GEAR_LEVER]);
|
||||||
|
g_driveline.lever = (uint8_t)g_last_lever;
|
||||||
|
}
|
||||||
|
if (dlc > CAN_BYTE_GEAR_ENGAGED) {
|
||||||
|
g_driveline.engaged_gear = can_to_engaged_gear(data[CAN_BYTE_GEAR_ENGAGED]);
|
||||||
|
}
|
||||||
|
if (dlc > CAN_BYTE_GEAR_MODE) {
|
||||||
|
g_driveline.gear_mode = data[CAN_BYTE_GEAR_MODE];
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CAN_ID_GEARBOX_STATE: {
|
||||||
|
// 0x0BA: the gearbox's own target gear — the ONLY source of engaged
|
||||||
|
// reverse (0x1D2 byte 1 stays 0x0F in R) — plus the output shaft.
|
||||||
|
if (dlc > CAN_BYTE_GEARBOX_TARGET) {
|
||||||
|
gear_position_t target =
|
||||||
|
can_to_target_gear(data[CAN_BYTE_GEARBOX_TARGET] & 0x0F);
|
||||||
|
updateGearMismatch(target);
|
||||||
|
// ST_CCLT lives in the top two bits of the same byte.
|
||||||
|
g_driveline.converter_clutch =
|
||||||
|
(data[CAN_BYTE_CONVERTER_CLUTCH] >> 6) & 0x03;
|
||||||
|
parsed = true;
|
||||||
|
}
|
||||||
|
if (dlc > CAN_BYTE_OUTPUT_SHAFT_H) {
|
||||||
|
// Raw counts only — scaling uncalibrated, so no physical unit.
|
||||||
|
g_driveline.output_shaft_raw =
|
||||||
|
(uint16_t)((data[CAN_BYTE_OUTPUT_SHAFT_H] << 8) | data[CAN_BYTE_OUTPUT_SHAFT_L]);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case CAN_ID_TURBINE_SPEED:
|
||||||
|
// 0x1A2: gearbox input speed — the physical engagement signal.
|
||||||
|
if (dlc > CAN_BYTE_TURBINE_H) {
|
||||||
|
g_driveline.turbine_rpm = can_to_turbine_rpm(data);
|
||||||
|
parsed = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAN_ID_TORQUE_1:
|
||||||
|
// 0x0A8: TORQ_AVL — available/delivered engine torque.
|
||||||
|
if (dlc > CAN_BYTE_TORQUE_H) {
|
||||||
|
g_driveline.engine_torque_x10 = can_to_torque_x10(data);
|
||||||
|
parsed = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case CAN_ID_TORQUE_3:
|
||||||
|
// 0x0AA: engine RPM + accelerator pedal.
|
||||||
|
if (dlc > CAN_BYTE_RPM_H) {
|
||||||
|
g_driveline.engine_rpm = can_to_rpm(data);
|
||||||
|
parsed = true;
|
||||||
|
}
|
||||||
|
if (dlc > CAN_BYTE_PEDAL_POS) {
|
||||||
|
// ANG_ACPD: % = raw * 0.39063 (i.e. raw * 100 / 256)
|
||||||
|
g_driveline.pedal_percent = (uint8_t)((data[CAN_BYTE_PEDAL_POS] * 100) / 256);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CAN_ID_BATTERY_VOLTAGE:
|
case CAN_ID_BATTERY_VOLTAGE:
|
||||||
// Battery voltage (bytes 0-1, 16-bit value)
|
// 0x3B4: U_BT (12-bit LE x 0.015 V) + ignition state.
|
||||||
if (message.data_length_code > CAN_BYTE_BATTERY_VOLT_L) {
|
if (dlc > CAN_BYTE_BATTERY_VOLT_H) {
|
||||||
// Combine high and low bytes (assuming big-endian)
|
// The field reads 0xFFF (not-available) on nearly every frame of
|
||||||
uint16_t raw_voltage = (data[CAN_BYTE_BATTERY_VOLT_H] << 8) | data[CAN_BYTE_BATTERY_VOLT_L];
|
// this bus. Publishing that would put a confident 61 V on the
|
||||||
|
// display, so only accept real readings and leave the valid flag
|
||||||
// Convert to internal format (0.01V units)
|
// clear otherwise.
|
||||||
// Assuming CAN sends in 0.1V units, multiply by 10
|
if (can_battery_raw(data) != BATTERY_RAW_INVALID) {
|
||||||
g_automotive_data.battery_voltage = raw_voltage * 10;
|
g_automotive_data.battery_voltage = can_to_voltage(data);
|
||||||
|
|
||||||
g_automotive_data.valid_flags |= VALID_FLAG_BATTERY_VOLT;
|
g_automotive_data.valid_flags |= VALID_FLAG_BATTERY_VOLT;
|
||||||
|
}
|
||||||
|
parsed = true;
|
||||||
|
}
|
||||||
|
if (dlc > CAN_BYTE_IGNITION) {
|
||||||
|
// Byte 2's low nibble tracks ignition (inverted), NOT engine run
|
||||||
|
// — verified on this bus against both published claims.
|
||||||
|
g_driveline.ignition_on =
|
||||||
|
((data[CAN_BYTE_IGNITION] & 0x0F) == IGNITION_ON);
|
||||||
parsed = true;
|
parsed = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -120,6 +259,44 @@ static bool parseCANMessage(const twai_message_t& message) {
|
|||||||
return parsed;
|
return parsed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Emit one raw CAN frame as a compact, greppable, re-parseable line.
|
||||||
|
*
|
||||||
|
* Format (CSV, one frame per line):
|
||||||
|
* CANRAW,<ts_ms>,<id_hex>,<extd>,<dlc>,<data_hex>
|
||||||
|
* where:
|
||||||
|
* ts_ms = millis() timestamp (relative to boot)
|
||||||
|
* id_hex = arbitration ID in hex, no 0x prefix (3 digits min for 11-bit)
|
||||||
|
* extd = 1 if 29-bit extended ID, 0 if 11-bit standard
|
||||||
|
* dlc = data length code (0..8)
|
||||||
|
* data_hex = payload bytes, uppercase hex, no separators (e.g. 1122AABB)
|
||||||
|
*
|
||||||
|
* The "CANRAW," prefix lets you filter these out of the mixed ESP_LOG serial
|
||||||
|
* stream: pio device monitor > drive.log then grep CANRAW, drive.log
|
||||||
|
*
|
||||||
|
* @param message Received TWAI message
|
||||||
|
*/
|
||||||
|
static void emitRawFrame(const twai_message_t& message) {
|
||||||
|
char buf[72];
|
||||||
|
int n = snprintf(buf, sizeof(buf), "CANRAW,%lu,%03lX,%u,%u,",
|
||||||
|
(unsigned long)millis(),
|
||||||
|
(unsigned long)message.identifier,
|
||||||
|
(unsigned)(message.extd ? 1 : 0),
|
||||||
|
(unsigned)message.data_length_code);
|
||||||
|
for (int i = 0; i < message.data_length_code && n < (int)sizeof(buf) - 4; i++) {
|
||||||
|
n += snprintf(buf + n, sizeof(buf) - n, "%02X", message.data[i]);
|
||||||
|
}
|
||||||
|
// Append the line terminator into the SAME buffer so the whole frame goes
|
||||||
|
// out in one Serial.write() — no other task can splice into the middle.
|
||||||
|
buf[n++] = '\r';
|
||||||
|
buf[n++] = '\n';
|
||||||
|
|
||||||
|
// Serialize against all other serial writers so lines never interleave.
|
||||||
|
SerialLock::lock();
|
||||||
|
Serial.write((const uint8_t*)buf, n);
|
||||||
|
SerialLock::unlock();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Handle received CAN message
|
* @brief Handle received CAN message
|
||||||
* @param message TWAI message structure
|
* @param message TWAI message structure
|
||||||
@@ -128,6 +305,11 @@ static void handleRxMessage(twai_message_t& message) {
|
|||||||
g_can_stats.messages_received++;
|
g_can_stats.messages_received++;
|
||||||
g_can_stats.last_receive_time = millis();
|
g_can_stats.last_receive_time = millis();
|
||||||
|
|
||||||
|
// Raw capture FIRST, before parse — logs every frame including unknown IDs
|
||||||
|
if (g_raw_logging) {
|
||||||
|
emitRawFrame(message);
|
||||||
|
}
|
||||||
|
|
||||||
// Auto-restart UART if it was stopped due to CAN timeout
|
// Auto-restart UART if it was stopped due to CAN timeout
|
||||||
if (g_uart_auto_stopped) {
|
if (g_uart_auto_stopped) {
|
||||||
ESP_LOGI("CANDrv", "✓ CAN messages resumed, auto-restarting UART");
|
ESP_LOGI("CANDrv", "✓ CAN messages resumed, auto-restarting UART");
|
||||||
@@ -139,22 +321,24 @@ static void handleRxMessage(twai_message_t& message) {
|
|||||||
if (parseCANMessage(message)) {
|
if (parseCANMessage(message)) {
|
||||||
g_can_stats.messages_parsed++;
|
g_can_stats.messages_parsed++;
|
||||||
|
|
||||||
// DETAILED LOGGING (TEMPORARY FOR DEBUGGING)
|
// Per-frame decoded prose — off by default (redundant with raw capture)
|
||||||
// Log EVERY parsed message with actual values
|
if (g_verbose_decode && xSemaphoreTake(g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||||
if (xSemaphoreTake(g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
|
ESP_LOGI("CANDrv", "✓ RX 0x%X → Gear:%s%s Coolant:%d.%d°C Gearbox:%d.%d°C Batt:%d.%02dV | RPM:%u Turb:%u Shaft:%u [%d/%d]",
|
||||||
ESP_LOGI("CANDrv", "✓ RX CAN ID=0x%X → Coolant:%d.%d°C, Oil:%d.%d°C, Gearbox:%d.%d°C, Batt:%d.%02dV, Gear:%d [%d/%d]",
|
|
||||||
message.identifier,
|
message.identifier,
|
||||||
|
gear_to_string((gear_position_t)g_automotive_data.gear_position),
|
||||||
|
g_driveline.gear_mismatch ? " !MISMATCH" : "",
|
||||||
g_automotive_data.coolant_temp / 10, abs(g_automotive_data.coolant_temp % 10),
|
g_automotive_data.coolant_temp / 10, abs(g_automotive_data.coolant_temp % 10),
|
||||||
g_automotive_data.engine_oil_temp / 10, abs(g_automotive_data.engine_oil_temp % 10),
|
|
||||||
g_automotive_data.gearbox_oil_temp / 10, abs(g_automotive_data.gearbox_oil_temp % 10),
|
g_automotive_data.gearbox_oil_temp / 10, abs(g_automotive_data.gearbox_oil_temp % 10),
|
||||||
g_automotive_data.battery_voltage / 100, g_automotive_data.battery_voltage % 100,
|
g_automotive_data.battery_voltage / 100, g_automotive_data.battery_voltage % 100,
|
||||||
g_automotive_data.gear_position,
|
g_driveline.engine_rpm,
|
||||||
|
g_driveline.turbine_rpm,
|
||||||
|
g_driveline.output_shaft_raw,
|
||||||
g_can_stats.messages_parsed,
|
g_can_stats.messages_parsed,
|
||||||
g_can_stats.messages_received);
|
g_can_stats.messages_received);
|
||||||
xSemaphoreGive(g_data_mutex);
|
xSemaphoreGive(g_data_mutex);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (g_verbose_decode) {
|
||||||
// Unknown message ID - log ALL unknown messages for debugging
|
// Unknown message ID (raw capture already logged it; this is just prose)
|
||||||
ESP_LOGW("CANDrv", "⚠ Unknown CAN ID=0x%X (DLC=%d) [%d total]",
|
ESP_LOGW("CANDrv", "⚠ Unknown CAN ID=0x%X (DLC=%d) [%d total]",
|
||||||
message.identifier,
|
message.identifier,
|
||||||
message.data_length_code,
|
message.data_length_code,
|
||||||
@@ -190,7 +374,7 @@ static bool initTWAI() {
|
|||||||
ESP_LOGE("CANDrv", "Failed to install TWAI driver");
|
ESP_LOGE("CANDrv", "Failed to install TWAI driver");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
ESP_LOGI("CANDrv", "TWAI driver installed (GPIO%d/GPIO%d, 500Kbps, LISTEN_ONLY)",
|
ESP_LOGI("CANDrv", "TWAI driver installed (GPIO%d/GPIO%d, 500Kbps, NORMAL/ACK)",
|
||||||
CAN_TX_PIN, CAN_RX_PIN);
|
CAN_TX_PIN, CAN_RX_PIN);
|
||||||
|
|
||||||
// Start TWAI driver
|
// Start TWAI driver
|
||||||
@@ -244,6 +428,13 @@ static void canTask(void* parameter) {
|
|||||||
if (initTWAI()) {
|
if (initTWAI()) {
|
||||||
g_can_active = true;
|
g_can_active = true;
|
||||||
memset(&g_can_stats, 0, sizeof(g_can_stats));
|
memset(&g_can_stats, 0, sizeof(g_can_stats));
|
||||||
|
// Drop stale driveline/gear state from a previous session
|
||||||
|
memset(&g_driveline, 0, sizeof(g_driveline));
|
||||||
|
// GEAR_PARK is 0, so a zeroed lever would read as "P"
|
||||||
|
// before the first 0x1D2 frame — force UNKNOWN instead.
|
||||||
|
g_driveline.lever = (uint8_t)GEAR_UNKNOWN;
|
||||||
|
g_last_lever = GEAR_UNKNOWN;
|
||||||
|
g_mismatch_since = 0;
|
||||||
ESP_LOGI("CANTask", "CAN reception active");
|
ESP_LOGI("CANTask", "CAN reception active");
|
||||||
|
|
||||||
// Auto-start UART transmission (CAN drives UART)
|
// Auto-start UART transmission (CAN drives UART)
|
||||||
@@ -386,10 +577,38 @@ can_stats_t getStats() {
|
|||||||
return g_can_stats;
|
return g_can_stats;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
driveline_t getDriveline() {
|
||||||
|
driveline_t snapshot;
|
||||||
|
if (xSemaphoreTake(g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||||
|
snapshot = g_driveline;
|
||||||
|
xSemaphoreGive(g_data_mutex);
|
||||||
|
} else {
|
||||||
|
// Never hand back a torn read; an all-zero snapshot is honest about
|
||||||
|
// having no fresh data (engine_run_state 0 == ENGINE_RUN_OFF).
|
||||||
|
memset(&snapshot, 0, sizeof(snapshot));
|
||||||
|
snapshot.lever = (uint8_t)GEAR_UNKNOWN; // 0 would mean GEAR_PARK
|
||||||
|
}
|
||||||
|
return snapshot;
|
||||||
|
}
|
||||||
|
|
||||||
bool isActive() {
|
bool isActive() {
|
||||||
return g_can_active;
|
return g_can_active;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setRawLogging(bool enabled) {
|
||||||
|
g_raw_logging = enabled;
|
||||||
|
ESP_LOGI("CANDrv", "Raw frame logging %s", enabled ? "ENABLED" : "disabled");
|
||||||
|
}
|
||||||
|
|
||||||
|
bool isRawLogging() {
|
||||||
|
return g_raw_logging;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVerboseDecode(bool enabled) {
|
||||||
|
g_verbose_decode = enabled;
|
||||||
|
ESP_LOGI("CANDrv", "Verbose decode logging %s", enabled ? "ENABLED" : "disabled");
|
||||||
|
}
|
||||||
|
|
||||||
void onCANToggle(lv_event_t *e) {
|
void onCANToggle(lv_event_t *e) {
|
||||||
lv_obj_t *target = lv_event_get_target(e);
|
lv_obj_t *target = lv_event_get_target(e);
|
||||||
if (target == NULL) {
|
if (target == NULL) {
|
||||||
|
|||||||
+37
-2
@@ -8,6 +8,8 @@
|
|||||||
#include "modules/settings_manager.h" // Settings manager module
|
#include "modules/settings_manager.h" // Settings manager module
|
||||||
#include "modules/ui_state_manager.h" // UI state manager module
|
#include "modules/ui_state_manager.h" // UI state manager module
|
||||||
#include "modules/meters_manager.h" // Meters display manager module
|
#include "modules/meters_manager.h" // Meters display manager module
|
||||||
|
#include "modules/driveline_screen.h" // Hand-coded driveline screen (swipe right from Home)
|
||||||
|
#include "modules/serial_lock.h" // Global serial write mutex
|
||||||
|
|
||||||
// ============================================================================
|
// ============================================================================
|
||||||
// MINIMAL LVGL + UI SETTINGS + WIFI + UART
|
// MINIMAL LVGL + UI SETTINGS + WIFI + UART
|
||||||
@@ -166,9 +168,17 @@ void initializeHomeScreenMeters() {
|
|||||||
// ============================================================================
|
// ============================================================================
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
// Baud is ignored under native USB CDC (Serial = HWCDC); kept high so the
|
||||||
|
// CANRAW dump isn't throttled if Serial ever falls back to UART0.
|
||||||
|
// NOTE: do NOT add `while(!Serial)` — the board must boot headless in-car
|
||||||
|
// with no host attached.
|
||||||
|
Serial.begin(921600);
|
||||||
delay(2000); // Longer delay for serial to stabilize
|
delay(2000); // Longer delay for serial to stabilize
|
||||||
|
|
||||||
|
// Create the global serial write mutex before any task starts, so CAN raw
|
||||||
|
// frames and other tasks' log lines never interleave on the shared port.
|
||||||
|
SerialLock::init();
|
||||||
|
|
||||||
// Use ESP_LOG instead of Serial.println to match library output
|
// Use ESP_LOG instead of Serial.println to match library output
|
||||||
ESP_LOGI("MAIN", "=== ESP32-S3-LCD-5B Minimal Setup ===");
|
ESP_LOGI("MAIN", "=== ESP32-S3-LCD-5B Minimal Setup ===");
|
||||||
ESP_LOGI("MAIN", "Firmware compiled: %s %s", __DATE__, __TIME__);
|
ESP_LOGI("MAIN", "Firmware compiled: %s %s", __DATE__, __TIME__);
|
||||||
@@ -229,7 +239,9 @@ void loop()
|
|||||||
|
|
||||||
// Debug: Print heartbeat every 5 seconds
|
// Debug: Print heartbeat every 5 seconds
|
||||||
if (millis() - last_print > 5000) {
|
if (millis() - last_print > 5000) {
|
||||||
|
SerialLock::lock();
|
||||||
ESP_LOGI("LOOP", "Heartbeat - system running");
|
ESP_LOGI("LOOP", "Heartbeat - system running");
|
||||||
|
SerialLock::unlock();
|
||||||
last_print = millis();
|
last_print = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -244,6 +256,12 @@ void loop()
|
|||||||
// (This survives SquareLine Studio regeneration)
|
// (This survives SquareLine Studio regeneration)
|
||||||
initializeHomeScreenMeters();
|
initializeHomeScreenMeters();
|
||||||
|
|
||||||
|
// Bolt the right-swipe -> Driveline screen onto Home at runtime. Same reason
|
||||||
|
// as the meters above: doing it here rather than in ui_Home_Screen.c means a
|
||||||
|
// SquareLine re-export can't silently remove it.
|
||||||
|
DrivelineScreen::attachHomeGesture();
|
||||||
|
DrivelineScreen::tick();
|
||||||
|
|
||||||
// Update meter values from CAN data every 200ms (5Hz)
|
// Update meter values from CAN data every 200ms (5Hz)
|
||||||
if (millis() - last_meter_update >= 200) {
|
if (millis() - last_meter_update >= 200) {
|
||||||
last_meter_update = millis();
|
last_meter_update = millis();
|
||||||
@@ -254,21 +272,38 @@ void loop()
|
|||||||
int16_t engine_oil_temp = UARTManager::g_automotive_data.engine_oil_temp;
|
int16_t engine_oil_temp = UARTManager::g_automotive_data.engine_oil_temp;
|
||||||
int16_t gearbox_oil_temp = UARTManager::g_automotive_data.gearbox_oil_temp;
|
int16_t gearbox_oil_temp = UARTManager::g_automotive_data.gearbox_oil_temp;
|
||||||
uint16_t battery_voltage = UARTManager::g_automotive_data.battery_voltage;
|
uint16_t battery_voltage = UARTManager::g_automotive_data.battery_voltage;
|
||||||
|
uint8_t valid = UARTManager::g_automotive_data.valid_flags;
|
||||||
xSemaphoreGive(UARTManager::g_data_mutex);
|
xSemaphoreGive(UARTManager::g_data_mutex);
|
||||||
|
|
||||||
// Update meters and labels (LVGL port lock required for thread safety)
|
// Update meters and labels (LVGL port lock required for thread safety)
|
||||||
lvgl_port_lock(-1);
|
lvgl_port_lock(-1);
|
||||||
|
|
||||||
// Update temperature meters
|
// Only show a value once its signal has actually been received. These
|
||||||
|
// fields are pre-seeded with DEFAULT_* constants, so updating them
|
||||||
|
// unconditionally displayed a plausible 92.0degC engine oil temp and a
|
||||||
|
// 12.45V battery that were never measured — inventions, not readings.
|
||||||
|
// Two of these have no source on this bus at all: engine oil temp has
|
||||||
|
// no sensor (0x1D0 byte 1 is permanently 0xFF) and 0x3B4 publishes the
|
||||||
|
// battery's not-available marker on nearly every frame.
|
||||||
|
if (valid & VALID_FLAG_COOLANT_TEMP) {
|
||||||
meters_manager_update_coolant_temp(coolant_temp);
|
meters_manager_update_coolant_temp(coolant_temp);
|
||||||
|
}
|
||||||
|
if (valid & VALID_FLAG_ENGINE_TEMP) {
|
||||||
meters_manager_update_engine_oil_temp(engine_oil_temp);
|
meters_manager_update_engine_oil_temp(engine_oil_temp);
|
||||||
|
}
|
||||||
|
if (valid & VALID_FLAG_GEARBOX_TEMP) {
|
||||||
meters_manager_update_gearbox_oil_temp(gearbox_oil_temp);
|
meters_manager_update_gearbox_oil_temp(gearbox_oil_temp);
|
||||||
|
}
|
||||||
|
|
||||||
// Update battery voltage label (format: "12.45V")
|
// Update battery voltage label (format: "12.45V")
|
||||||
if (uic_Batery_Values_LBL != NULL) {
|
if (uic_Batery_Values_LBL != NULL) {
|
||||||
char battery_buf[16];
|
char battery_buf[16];
|
||||||
|
if (valid & VALID_FLAG_BATTERY_VOLT) {
|
||||||
snprintf(battery_buf, sizeof(battery_buf), "%d.%02d",
|
snprintf(battery_buf, sizeof(battery_buf), "%d.%02d",
|
||||||
battery_voltage / 100, battery_voltage % 100);
|
battery_voltage / 100, battery_voltage % 100);
|
||||||
|
} else {
|
||||||
|
snprintf(battery_buf, sizeof(battery_buf), "--.--");
|
||||||
|
}
|
||||||
lv_label_set_text(uic_Batery_Values_LBL, battery_buf);
|
lv_label_set_text(uic_Batery_Values_LBL, battery_buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "display_init.h"
|
#include "display_init.h"
|
||||||
#include "display/lvgl_v8_port.h"
|
#include "display/lvgl_v8_port.h"
|
||||||
#include "ui/ui.h"
|
#include "ui/ui.h"
|
||||||
|
#include "driveline_screen.h"
|
||||||
|
|
||||||
namespace DisplayInit {
|
namespace DisplayInit {
|
||||||
|
|
||||||
@@ -71,6 +72,11 @@ DisplayObjects init() {
|
|||||||
lvgl_port_lock(-1);
|
lvgl_port_lock(-1);
|
||||||
ui_init(); // Initialize the SquareLine Studio generated UI
|
ui_init(); // Initialize the SquareLine Studio generated UI
|
||||||
// Note: onSelectSSID event handler is registered in ui_Settings_Screen.c
|
// Note: onSelectSSID event handler is registered in ui_Settings_Screen.c
|
||||||
|
// Override the boot screen: land on the Driveline data screen, not the
|
||||||
|
// gauges Home screen. ui_init() loaded Home; swap to Driveline while the
|
||||||
|
// backlight is still off so there's no visible flash of the wrong screen.
|
||||||
|
// Home stays reachable by swiping off the Driveline screen.
|
||||||
|
DrivelineScreen::show();
|
||||||
lvgl_port_unlock();
|
lvgl_port_unlock();
|
||||||
Serial.println("[DisplayInit] Step 13: SquareLine UI loaded successfully!");
|
Serial.println("[DisplayInit] Step 13: SquareLine UI loaded successfully!");
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,419 @@
|
|||||||
|
/*
|
||||||
|
* Driveline Screen Module Implementation
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "driveline_screen.h"
|
||||||
|
#include "uart_manager.h"
|
||||||
|
#include "display/lvgl_v8_port.h"
|
||||||
|
#include "drivers/can_driver.h"
|
||||||
|
#include "esp_log.h"
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "ui.h"
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace DrivelineScreen {
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// LAYOUT / THEME CONSTANTS
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
#define COL_BG lv_color_hex(0x101418)
|
||||||
|
#define COL_PANEL lv_color_hex(0x1B2128)
|
||||||
|
#define COL_TEXT lv_color_hex(0xE8EDF2)
|
||||||
|
#define COL_MUTED lv_color_hex(0x6E7B88)
|
||||||
|
#define COL_ACCENT lv_color_hex(0x3DA9FC)
|
||||||
|
#define COL_OK lv_color_hex(0x3DD68C)
|
||||||
|
#define COL_WARN lv_color_hex(0xE5484D)
|
||||||
|
|
||||||
|
#define RPM_MAX 5000 // M57N redline is ~4500; a little headroom
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// MODULE STATE
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
static lv_obj_t* g_screen = NULL;
|
||||||
|
static lv_obj_t* g_gear_lbl = NULL;
|
||||||
|
static lv_obj_t* g_gear_ring = NULL;
|
||||||
|
static lv_obj_t* g_coolant_lbl = NULL;
|
||||||
|
static lv_obj_t* g_gearbox_lbl = NULL;
|
||||||
|
static lv_obj_t* g_rpm_bar = NULL;
|
||||||
|
static lv_obj_t* g_rpm_lbl = NULL;
|
||||||
|
static lv_obj_t* g_torque_lbl = NULL;
|
||||||
|
static lv_obj_t* g_pedal_lbl = NULL;
|
||||||
|
static lv_obj_t* g_shaft_lbl = NULL;
|
||||||
|
static lv_obj_t* g_ign_chip = NULL;
|
||||||
|
static lv_obj_t* g_eng_chip = NULL;
|
||||||
|
static lv_obj_t* g_clutch_chip = NULL;
|
||||||
|
static lv_obj_t* g_cool_chip = NULL;
|
||||||
|
static lv_obj_t* g_mismatch_lbl = NULL;
|
||||||
|
|
||||||
|
// Home screen instance we've already hooked the right-swipe onto.
|
||||||
|
static lv_obj_t* g_hooked_home = NULL;
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// PRIVATE HELPERS
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a small status chip (rounded pill with text).
|
||||||
|
*/
|
||||||
|
static lv_obj_t* makeChip(lv_obj_t* parent, const char* text) {
|
||||||
|
lv_obj_t* chip = lv_label_create(parent);
|
||||||
|
lv_label_set_text(chip, text);
|
||||||
|
lv_obj_set_style_text_font(chip, &lv_font_montserrat_14, 0);
|
||||||
|
lv_obj_set_style_text_color(chip, COL_MUTED, 0);
|
||||||
|
lv_obj_set_style_bg_color(chip, COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_bg_opa(chip, LV_OPA_COVER, 0);
|
||||||
|
lv_obj_set_style_radius(chip, 10, 0);
|
||||||
|
lv_obj_set_style_pad_hor(chip, 10, 0);
|
||||||
|
lv_obj_set_style_pad_ver(chip, 5, 0);
|
||||||
|
return chip;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Set a chip's text and colour in one go.
|
||||||
|
*/
|
||||||
|
static void setChip(lv_obj_t* chip, const char* text, lv_color_t colour) {
|
||||||
|
if (chip == NULL) return;
|
||||||
|
lv_label_set_text(chip, text);
|
||||||
|
lv_obj_set_style_text_color(chip, colour, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Compose the hero gear label from the 0x1D2 pieces.
|
||||||
|
*
|
||||||
|
* P/R/N are shown as the bare letter. In the Drive detent we prefix the engaged
|
||||||
|
* gear number with the mode: D3 (auto), S3 (sport gate), M3 (manual). If the box
|
||||||
|
* hasn't reported a number yet (or is in R, which is unnumbered here) the mode
|
||||||
|
* letter stands alone.
|
||||||
|
*
|
||||||
|
* @param dl Driveline snapshot
|
||||||
|
* @param out Output buffer (>= 4 bytes)
|
||||||
|
*/
|
||||||
|
static void composeGear(const driveline_t& dl, char* out, size_t n) {
|
||||||
|
switch ((gear_position_t)dl.lever) {
|
||||||
|
case GEAR_PARK: snprintf(out, n, "P"); return;
|
||||||
|
case GEAR_REVERSE: snprintf(out, n, "R"); return;
|
||||||
|
case GEAR_NEUTRAL: snprintf(out, n, "N"); return;
|
||||||
|
case GEAR_DRIVE: break; // fall through to compose D/S/M + number
|
||||||
|
default: snprintf(out, n, "--"); return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char mode = 'D';
|
||||||
|
if (dl.gear_mode == GEAR_MODE_SPORT) mode = 'S';
|
||||||
|
if (dl.gear_mode == GEAR_MODE_MANUAL) mode = 'M';
|
||||||
|
|
||||||
|
if (dl.engaged_gear >= 1 && dl.engaged_gear <= 6) {
|
||||||
|
snprintf(out, n, "%c%u", mode, dl.engaged_gear);
|
||||||
|
} else {
|
||||||
|
snprintf(out, n, "%c", mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Create a title + value stack. Returns the value label.
|
||||||
|
*/
|
||||||
|
static lv_obj_t* makeStat(lv_obj_t* parent, const char* title,
|
||||||
|
const lv_font_t* value_font,
|
||||||
|
lv_align_t align, lv_coord_t x, lv_coord_t y) {
|
||||||
|
lv_obj_t* box = lv_obj_create(parent);
|
||||||
|
lv_obj_remove_style_all(box);
|
||||||
|
lv_obj_set_size(box, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_flow(box, LV_FLEX_FLOW_COLUMN);
|
||||||
|
lv_obj_set_flex_align(box, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||||
|
lv_obj_align(box, align, x, y);
|
||||||
|
lv_obj_clear_flag(box, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
lv_obj_t* t = lv_label_create(box);
|
||||||
|
lv_label_set_text(t, title);
|
||||||
|
lv_obj_set_style_text_font(t, &lv_font_montserrat_14, 0);
|
||||||
|
lv_obj_set_style_text_color(t, COL_MUTED, 0);
|
||||||
|
lv_obj_set_style_pad_bottom(t, 4, 0);
|
||||||
|
|
||||||
|
lv_obj_t* v = lv_label_create(box);
|
||||||
|
lv_label_set_text(v, "--");
|
||||||
|
lv_obj_set_style_text_font(v, value_font, 0);
|
||||||
|
lv_obj_set_style_text_color(v, COL_TEXT, 0);
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gesture handler on OUR screen: swipe right/left goes back to Home.
|
||||||
|
*/
|
||||||
|
static void onScreenGesture(lv_event_t* e) {
|
||||||
|
if (lv_event_get_code(e) != LV_EVENT_GESTURE) return;
|
||||||
|
lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
|
||||||
|
if (dir == LV_DIR_LEFT || dir == LV_DIR_RIGHT) {
|
||||||
|
lv_indev_wait_release(lv_indev_get_act());
|
||||||
|
_ui_screen_change(&ui_Home_Screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0,
|
||||||
|
&ui_Home_Screen_screen_init);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gesture handler we bolt onto the Home screen at runtime.
|
||||||
|
*
|
||||||
|
* The generated ui_event_Home_Screen() already claims LEFT (-> Settings). LVGL
|
||||||
|
* dispatches to every registered callback, so this one coexists with it rather
|
||||||
|
* than replacing it — which is the whole point: we never edit the generated file.
|
||||||
|
*/
|
||||||
|
static void onHomeGesture(lv_event_t* e) {
|
||||||
|
if (lv_event_get_code(e) != LV_EVENT_GESTURE) return;
|
||||||
|
if (lv_indev_get_gesture_dir(lv_indev_get_act()) != LV_DIR_RIGHT) return;
|
||||||
|
lv_indev_wait_release(lv_indev_get_act());
|
||||||
|
show();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Build the screen. Idempotent — returns immediately if already built.
|
||||||
|
*/
|
||||||
|
static void build() {
|
||||||
|
if (g_screen != NULL) return;
|
||||||
|
|
||||||
|
g_screen = lv_obj_create(NULL);
|
||||||
|
lv_obj_set_style_bg_color(g_screen, COL_BG, 0);
|
||||||
|
lv_obj_clear_flag(g_screen, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
lv_obj_add_event_cb(g_screen, onScreenGesture, LV_EVENT_GESTURE, NULL);
|
||||||
|
|
||||||
|
// ---- top status bar --------------------------------------------------
|
||||||
|
lv_obj_t* bar = lv_obj_create(g_screen);
|
||||||
|
lv_obj_remove_style_all(bar);
|
||||||
|
lv_obj_set_size(bar, LV_SIZE_CONTENT, LV_SIZE_CONTENT);
|
||||||
|
lv_obj_set_flex_flow(bar, LV_FLEX_FLOW_ROW);
|
||||||
|
lv_obj_set_style_pad_column(bar, 8, 0);
|
||||||
|
lv_obj_align(bar, LV_ALIGN_TOP_LEFT, 24, 18);
|
||||||
|
lv_obj_clear_flag(bar, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
g_ign_chip = makeChip(bar, "IGN --");
|
||||||
|
g_eng_chip = makeChip(bar, "ENG --");
|
||||||
|
g_clutch_chip = makeChip(bar, "CLUTCH --");
|
||||||
|
g_cool_chip = makeChip(bar, "COOLING --");
|
||||||
|
|
||||||
|
g_mismatch_lbl = lv_label_create(g_screen);
|
||||||
|
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_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
|
||||||
|
// ---- gear hero -------------------------------------------------------
|
||||||
|
g_gear_ring = lv_obj_create(g_screen);
|
||||||
|
lv_obj_set_size(g_gear_ring, 220, 220);
|
||||||
|
lv_obj_align(g_gear_ring, LV_ALIGN_CENTER, 0, -40);
|
||||||
|
lv_obj_set_style_radius(g_gear_ring, LV_RADIUS_CIRCLE, 0);
|
||||||
|
lv_obj_set_style_bg_color(g_gear_ring, COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_border_color(g_gear_ring, COL_ACCENT, 0);
|
||||||
|
lv_obj_set_style_border_width(g_gear_ring, 3, 0);
|
||||||
|
lv_obj_clear_flag(g_gear_ring, LV_OBJ_FLAG_SCROLLABLE);
|
||||||
|
|
||||||
|
g_gear_lbl = lv_label_create(g_gear_ring);
|
||||||
|
lv_label_set_text(g_gear_lbl, "--");
|
||||||
|
lv_obj_set_style_text_font(g_gear_lbl, &lv_font_montserrat_48, 0);
|
||||||
|
lv_obj_set_style_text_color(g_gear_lbl, COL_TEXT, 0);
|
||||||
|
lv_obj_center(g_gear_lbl);
|
||||||
|
|
||||||
|
// ---- flanking temperatures ------------------------------------------
|
||||||
|
g_coolant_lbl = makeStat(g_screen, "COOLANT", &lv_font_montserrat_40,
|
||||||
|
LV_ALIGN_LEFT_MID, 110, -40);
|
||||||
|
g_gearbox_lbl = makeStat(g_screen, "GEARBOX OIL", &lv_font_montserrat_40,
|
||||||
|
LV_ALIGN_RIGHT_MID, -110, -40);
|
||||||
|
|
||||||
|
// ---- RPM bar ---------------------------------------------------------
|
||||||
|
lv_obj_t* rpm_title = lv_label_create(g_screen);
|
||||||
|
lv_label_set_text(rpm_title, "RPM");
|
||||||
|
lv_obj_set_style_text_font(rpm_title, &lv_font_montserrat_14, 0);
|
||||||
|
lv_obj_set_style_text_color(rpm_title, COL_MUTED, 0);
|
||||||
|
lv_obj_align(rpm_title, LV_ALIGN_CENTER, -330, 108);
|
||||||
|
|
||||||
|
g_rpm_bar = lv_bar_create(g_screen);
|
||||||
|
lv_obj_set_size(g_rpm_bar, 560, 16);
|
||||||
|
lv_obj_align(g_rpm_bar, LV_ALIGN_CENTER, -30, 108);
|
||||||
|
lv_bar_set_range(g_rpm_bar, 0, RPM_MAX);
|
||||||
|
lv_bar_set_value(g_rpm_bar, 0, LV_ANIM_OFF);
|
||||||
|
lv_obj_set_style_bg_color(g_rpm_bar, COL_PANEL, 0);
|
||||||
|
lv_obj_set_style_bg_color(g_rpm_bar, COL_ACCENT, LV_PART_INDICATOR);
|
||||||
|
lv_obj_set_style_radius(g_rpm_bar, 8, 0);
|
||||||
|
lv_obj_set_style_radius(g_rpm_bar, 8, LV_PART_INDICATOR);
|
||||||
|
|
||||||
|
g_rpm_lbl = lv_label_create(g_screen);
|
||||||
|
lv_label_set_text(g_rpm_lbl, "----");
|
||||||
|
lv_obj_set_style_text_font(g_rpm_lbl, &lv_font_montserrat_30, 0);
|
||||||
|
lv_obj_set_style_text_color(g_rpm_lbl, COL_TEXT, 0);
|
||||||
|
lv_obj_align(g_rpm_lbl, LV_ALIGN_CENTER, 330, 108);
|
||||||
|
|
||||||
|
// ---- bottom row: torque | pedal | output shaft -----------------------
|
||||||
|
// Turbine speed is intentionally NOT shown: it's a diagnostic (engagement
|
||||||
|
// proof), not a driver number. Still decoded in the driver.
|
||||||
|
g_torque_lbl = makeStat(g_screen, "TORQUE (Nm)", &lv_font_montserrat_30,
|
||||||
|
LV_ALIGN_BOTTOM_MID, -340, -34);
|
||||||
|
g_pedal_lbl = makeStat(g_screen, "PEDAL (%)", &lv_font_montserrat_30,
|
||||||
|
LV_ALIGN_BOTTOM_MID, 0, -34);
|
||||||
|
// Output shaft in rpm via a PROVISIONAL factor (one Launch point). The label
|
||||||
|
// carries "~" so the screen doesn't present an unlocked scaling as exact.
|
||||||
|
g_shaft_lbl = makeStat(g_screen, "OUTPUT (~rpm)", &lv_font_montserrat_30,
|
||||||
|
LV_ALIGN_BOTTOM_MID, 340, -34);
|
||||||
|
|
||||||
|
lv_obj_t* hint = lv_label_create(g_screen);
|
||||||
|
lv_label_set_text(hint, LV_SYMBOL_LEFT " swipe back to Home");
|
||||||
|
lv_obj_set_style_text_font(hint, &lv_font_montserrat_14, 0);
|
||||||
|
lv_obj_set_style_text_color(hint, COL_MUTED, 0);
|
||||||
|
lv_obj_align(hint, LV_ALIGN_BOTTOM_LEFT, 24, -14);
|
||||||
|
|
||||||
|
ESP_LOGI("Driveline", "Driveline screen built");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ============================================================================
|
||||||
|
// PUBLIC API
|
||||||
|
// ============================================================================
|
||||||
|
|
||||||
|
void show() {
|
||||||
|
build();
|
||||||
|
lv_scr_load_anim(g_screen, LV_SCR_LOAD_ANIM_FADE_ON, 100, 0, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void attachHomeGesture() {
|
||||||
|
if (ui_Home_Screen == NULL) {
|
||||||
|
g_hooked_home = NULL; // screen gone; re-hook when it returns
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (g_hooked_home == ui_Home_Screen) return;
|
||||||
|
|
||||||
|
lvgl_port_lock(-1);
|
||||||
|
lv_obj_add_event_cb(ui_Home_Screen, onHomeGesture, LV_EVENT_GESTURE, NULL);
|
||||||
|
lvgl_port_unlock();
|
||||||
|
|
||||||
|
g_hooked_home = ui_Home_Screen;
|
||||||
|
ESP_LOGI("Driveline", "Right-swipe hooked onto Home screen");
|
||||||
|
}
|
||||||
|
|
||||||
|
void tick() {
|
||||||
|
// Nothing to do unless we're built AND actually the screen being shown.
|
||||||
|
if (g_screen == NULL || lv_scr_act() != g_screen) return;
|
||||||
|
|
||||||
|
// loop() spins fast and Core 1 is already ~80% busy rendering. Refreshing at
|
||||||
|
// 10Hz is well past what the eye resolves and keeps us off the LVGL lock.
|
||||||
|
static uint32_t last_refresh = 0;
|
||||||
|
if (millis() - last_refresh < 100) return;
|
||||||
|
last_refresh = millis();
|
||||||
|
|
||||||
|
bool can_up = CANDriver::isActive();
|
||||||
|
driveline_t dl = CANDriver::getDriveline();
|
||||||
|
|
||||||
|
// Snapshot the shared struct under its own mutex, briefly.
|
||||||
|
uint8_t gear = GEAR_UNKNOWN;
|
||||||
|
int16_t coolant = 0, gearbox = 0;
|
||||||
|
uint8_t flags = 0;
|
||||||
|
if (xSemaphoreTake(UARTManager::g_data_mutex, pdMS_TO_TICKS(10)) == pdTRUE) {
|
||||||
|
gear = UARTManager::g_automotive_data.gear_position;
|
||||||
|
coolant = UARTManager::g_automotive_data.coolant_temp;
|
||||||
|
gearbox = UARTManager::g_automotive_data.gearbox_oil_temp;
|
||||||
|
flags = UARTManager::g_automotive_data.valid_flags;
|
||||||
|
xSemaphoreGive(UARTManager::g_data_mutex);
|
||||||
|
} else {
|
||||||
|
return; // couldn't read; leave the last frame on screen
|
||||||
|
}
|
||||||
|
|
||||||
|
char buf[24];
|
||||||
|
(void)gear; // gear now comes from the driveline pieces, not the UART enum
|
||||||
|
lvgl_port_lock(-1);
|
||||||
|
|
||||||
|
// Blank every readout when there's nothing live to show: CAN off, or the key
|
||||||
|
// is off. The user asked for a full reset on ignition-off so the screen goes
|
||||||
|
// quiet with the car rather than freezing the last frame. 0x3B4 sends its
|
||||||
|
// ignition nibble on-change, so this reset is effectively instant.
|
||||||
|
if (!can_up || !dl.ignition_on) {
|
||||||
|
lv_label_set_text(g_gear_lbl, "--");
|
||||||
|
lv_label_set_text(g_coolant_lbl, "--");
|
||||||
|
lv_label_set_text(g_gearbox_lbl, "--");
|
||||||
|
lv_label_set_text(g_rpm_lbl, "----");
|
||||||
|
lv_label_set_text(g_torque_lbl, "--");
|
||||||
|
lv_label_set_text(g_pedal_lbl, "--");
|
||||||
|
lv_label_set_text(g_shaft_lbl, "--");
|
||||||
|
lv_bar_set_value(g_rpm_bar, 0, LV_ANIM_OFF);
|
||||||
|
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
// Leave the ignition chip telling the truth; mute the rest, since their
|
||||||
|
// values are meaningless with the key out (or absent with CAN off).
|
||||||
|
if (!can_up) {
|
||||||
|
setChip(g_ign_chip, "IGN --", COL_MUTED);
|
||||||
|
setChip(g_cool_chip, "CAN OFF", COL_WARN);
|
||||||
|
} else {
|
||||||
|
setChip(g_ign_chip, "IGN OFF", COL_MUTED);
|
||||||
|
setChip(g_cool_chip, "COOLING --", COL_MUTED);
|
||||||
|
}
|
||||||
|
setChip(g_eng_chip, "ENG --", COL_MUTED);
|
||||||
|
setChip(g_clutch_chip, "CLUTCH --", COL_MUTED);
|
||||||
|
lvgl_port_unlock();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- gear (composed: P/R/N, or D/S/M + engaged number) ---------------
|
||||||
|
if ((gear_position_t)dl.lever != GEAR_UNKNOWN) {
|
||||||
|
composeGear(dl, buf, sizeof(buf));
|
||||||
|
lv_label_set_text(g_gear_lbl, buf);
|
||||||
|
} else {
|
||||||
|
lv_label_set_text(g_gear_lbl, "--");
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- temperatures (only when the signal is real) ---------------------
|
||||||
|
if (flags & VALID_FLAG_COOLANT_TEMP) {
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d°C", coolant / 10, abs(coolant % 10));
|
||||||
|
lv_label_set_text(g_coolant_lbl, buf);
|
||||||
|
}
|
||||||
|
if (flags & VALID_FLAG_GEARBOX_TEMP) {
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d°C", gearbox / 10, abs(gearbox % 10));
|
||||||
|
lv_label_set_text(g_gearbox_lbl, buf);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ---- speeds ----------------------------------------------------------
|
||||||
|
snprintf(buf, sizeof(buf), "%u", dl.engine_rpm);
|
||||||
|
lv_label_set_text(g_rpm_lbl, buf);
|
||||||
|
lv_bar_set_value(g_rpm_bar, dl.engine_rpm > RPM_MAX ? RPM_MAX : dl.engine_rpm, LV_ANIM_OFF);
|
||||||
|
|
||||||
|
// Torque is signed (negative under overrun/braking); one decimal, matching
|
||||||
|
// the 0.5 Nm resolution of the field.
|
||||||
|
snprintf(buf, sizeof(buf), "%d.%d", dl.engine_torque_x10 / 10, abs(dl.engine_torque_x10 % 10));
|
||||||
|
lv_label_set_text(g_torque_lbl, buf);
|
||||||
|
|
||||||
|
snprintf(buf, sizeof(buf), "%u", dl.pedal_percent);
|
||||||
|
lv_label_set_text(g_pedal_lbl, buf);
|
||||||
|
|
||||||
|
// Provisional rpm from the single-point Launch factor (see automotive_data.h).
|
||||||
|
snprintf(buf, sizeof(buf), "%u", can_output_shaft_rpm(dl.output_shaft_raw));
|
||||||
|
lv_label_set_text(g_shaft_lbl, buf);
|
||||||
|
|
||||||
|
// ---- status chips ----------------------------------------------------
|
||||||
|
setChip(g_ign_chip, dl.ignition_on ? "IGN ON" : "IGN OFF",
|
||||||
|
dl.ignition_on ? COL_OK : COL_MUTED);
|
||||||
|
|
||||||
|
switch (dl.engine_run_state) {
|
||||||
|
case ENGINE_RUN_RUNNING: setChip(g_eng_chip, "ENG RUN", COL_OK); break;
|
||||||
|
case ENGINE_RUN_STARTING: setChip(g_eng_chip, "ENG START", COL_ACCENT); break;
|
||||||
|
case ENGINE_RUN_OFF: setChip(g_eng_chip, "ENG OFF", COL_MUTED); break;
|
||||||
|
default: setChip(g_eng_chip, "ENG ?", COL_MUTED); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (dl.converter_clutch) {
|
||||||
|
case CCLT_DISENGAGED: setChip(g_clutch_chip, "CLUTCH OPEN", COL_MUTED); break;
|
||||||
|
case CCLT_CONTROLLED: setChip(g_clutch_chip, "CLUTCH SLIP", COL_ACCENT); break;
|
||||||
|
case CCLT_CLOSED: setChip(g_clutch_chip, "CLUTCH LOCK", COL_OK); break;
|
||||||
|
default: setChip(g_clutch_chip, "CLUTCH ?", COL_MUTED); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (dl.gearbox_cooling) {
|
||||||
|
case GEARBOX_COOL_NONE: setChip(g_cool_chip, "COOLING OK", COL_MUTED); break;
|
||||||
|
case GEARBOX_COOL_STAGE1: setChip(g_cool_chip, "COOLING 1", COL_ACCENT); break;
|
||||||
|
case GEARBOX_COOL_STAGE2: setChip(g_cool_chip, "COOLING 2", COL_WARN); break;
|
||||||
|
default: setChip(g_cool_chip, "COOLING ?", COL_MUTED); break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dl.gear_mismatch) {
|
||||||
|
lv_obj_clear_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
} else {
|
||||||
|
lv_obj_add_flag(g_mismatch_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||||
|
}
|
||||||
|
|
||||||
|
lvgl_port_unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace DrivelineScreen
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Driveline Screen Module
|
||||||
|
*
|
||||||
|
* A hand-coded LVGL screen showing the CAN signals we have actually verified on
|
||||||
|
* the swap's bus: gear (hero), coolant, gearbox oil temp, engine RPM, turbine
|
||||||
|
* speed and output shaft, plus ignition / engine / clutch / mismatch status.
|
||||||
|
*
|
||||||
|
* WHY THIS IS NOT A SQUARELINE SCREEN
|
||||||
|
* SquareLine Studio owns include/ui/ and overwrites it on every export. Editing
|
||||||
|
* generated files loses the edit — that is exactly how the CAN toggle's event
|
||||||
|
* handler went missing. This screen lives entirely in src/, which SquareLine
|
||||||
|
* never touches, so it cannot be clobbered. It is reached by a right-swipe
|
||||||
|
* gesture attached to the Home screen AT RUNTIME (see attachHomeGesture) rather
|
||||||
|
* than by editing ui_Home_Screen.c, for the same reason.
|
||||||
|
*
|
||||||
|
* Signals deliberately NOT shown: engine oil temp (no sensor on this M57N —
|
||||||
|
* 0x1D0 byte 1 is permanently 0xFF) and battery voltage (0x3B4 publishes the
|
||||||
|
* invalid marker almost always). See wiki/pages/can-id-candidates.md.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include <lvgl.h>
|
||||||
|
|
||||||
|
namespace DrivelineScreen {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Build the screen (idempotent) and load it.
|
||||||
|
* @note Caller must hold the LVGL lock.
|
||||||
|
*/
|
||||||
|
void show();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Refresh all values from the CAN driver / shared automotive data.
|
||||||
|
* Cheap no-op unless the screen exists and is currently on display.
|
||||||
|
* Call from loop(); takes its own locks.
|
||||||
|
*/
|
||||||
|
void tick();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Attach a right-swipe handler to the Home screen so this screen is
|
||||||
|
* reachable, without touching the SquareLine-generated Home screen code.
|
||||||
|
* Safe to call every loop — re-attaches only when the Home screen
|
||||||
|
* instance changes. Takes its own LVGL lock.
|
||||||
|
*/
|
||||||
|
void attachHomeGesture();
|
||||||
|
|
||||||
|
} // namespace DrivelineScreen
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
/**
|
||||||
|
* serial_lock.cpp
|
||||||
|
*
|
||||||
|
* Implementation of the global serial write mutex. See serial_lock.h.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "modules/serial_lock.h"
|
||||||
|
|
||||||
|
namespace SerialLock {
|
||||||
|
|
||||||
|
static SemaphoreHandle_t g_serial_mutex = NULL;
|
||||||
|
|
||||||
|
void init() {
|
||||||
|
if (g_serial_mutex == NULL) {
|
||||||
|
g_serial_mutex = xSemaphoreCreateMutex();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool lock(TickType_t timeout) {
|
||||||
|
// Not initialized yet (early boot): don't block, just proceed.
|
||||||
|
if (g_serial_mutex == NULL) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return xSemaphoreTake(g_serial_mutex, timeout) == pdTRUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
void unlock() {
|
||||||
|
if (g_serial_mutex != NULL) {
|
||||||
|
xSemaphoreGive(g_serial_mutex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace SerialLock
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
/**
|
||||||
|
* serial_lock.h
|
||||||
|
*
|
||||||
|
* A single global mutex that serializes writes to the USB-CDC `Serial` port.
|
||||||
|
*
|
||||||
|
* Multiple FreeRTOS tasks (CAN raw logger, UART task, main loop heartbeat, ...)
|
||||||
|
* write to the same serial output. Without coordination their writes interleave
|
||||||
|
* and splice mid-line, corrupting the CANRAW capture stream. Every frequent
|
||||||
|
* writer takes this lock around its full line so lines never interleave.
|
||||||
|
*
|
||||||
|
* Usage:
|
||||||
|
* SerialLock::lock();
|
||||||
|
* Serial.write(...); // or ESP_LOGx(...)
|
||||||
|
* SerialLock::unlock();
|
||||||
|
*
|
||||||
|
* Call SerialLock::init() once early in setup(), before any task starts. Before
|
||||||
|
* init (or if creation fails) lock()/unlock() are safe no-ops.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef _SERIAL_LOCK_H
|
||||||
|
#define _SERIAL_LOCK_H
|
||||||
|
|
||||||
|
#include <Arduino.h>
|
||||||
|
#include "freertos/FreeRTOS.h"
|
||||||
|
#include "freertos/semphr.h"
|
||||||
|
|
||||||
|
namespace SerialLock {
|
||||||
|
/** Create the mutex. Idempotent; call once in setup() before tasks start. */
|
||||||
|
void init();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Acquire the serial lock.
|
||||||
|
* @param timeout ticks to wait (default: wait forever)
|
||||||
|
* @return true if acquired (also true if the lock isn't initialized yet)
|
||||||
|
*/
|
||||||
|
bool lock(TickType_t timeout = portMAX_DELAY);
|
||||||
|
|
||||||
|
/** Release the serial lock (no-op if not held / not initialized). */
|
||||||
|
void unlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // _SERIAL_LOCK_H
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "uart_manager.h"
|
#include "uart_manager.h"
|
||||||
#include "settings_manager.h"
|
#include "settings_manager.h"
|
||||||
|
#include "serial_lock.h"
|
||||||
|
|
||||||
namespace UARTManager {
|
namespace UARTManager {
|
||||||
|
|
||||||
@@ -115,6 +116,8 @@ static bool sendUARTPacket() {
|
|||||||
|
|
||||||
// Debug output - first 5 packets, then every 10
|
// Debug output - first 5 packets, then every 10
|
||||||
if (g_uart_stats.packets_sent <= 5 || g_uart_stats.packets_sent % 10 == 0) {
|
if (g_uart_stats.packets_sent <= 5 || g_uart_stats.packets_sent % 10 == 0) {
|
||||||
|
// Hold the serial lock so this line can't splice into a CANRAW frame
|
||||||
|
SerialLock::lock();
|
||||||
ESP_LOGI("UARTTask", "✓ TX Packet #%d (Gear:%s, Temps:%d.%d/%d.%d/%d.%d°C, Batt:%d.%02dV, Debug:%s) [%d bytes on GPIO%d]",
|
ESP_LOGI("UARTTask", "✓ TX Packet #%d (Gear:%s, Temps:%d.%d/%d.%d/%d.%d°C, Batt:%d.%02dV, Debug:%s) [%d bytes on GPIO%d]",
|
||||||
packet.data.packet_id,
|
packet.data.packet_id,
|
||||||
gear_to_string((gear_position_t)packet.data.gear_position),
|
gear_to_string((gear_position_t)packet.data.gear_position),
|
||||||
@@ -124,6 +127,7 @@ static bool sendUARTPacket() {
|
|||||||
packet.data.battery_voltage / 100, packet.data.battery_voltage % 100,
|
packet.data.battery_voltage / 100, packet.data.battery_voltage % 100,
|
||||||
packet.data.debug_enabled ? "ON" : "OFF",
|
packet.data.debug_enabled ? "ON" : "OFF",
|
||||||
bytes_written, UART_TX_PIN);
|
bytes_written, UART_TX_PIN);
|
||||||
|
SerialLock::unlock();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,35 @@
|
|||||||
|
# fix_toolchain_path.py (PlatformIO pre-build extra script)
|
||||||
|
#
|
||||||
|
# WORKAROUND for a pioarduino first-install issue on this machine.
|
||||||
|
#
|
||||||
|
# The Xtensa toolchain (toolchain-xtensa-esp-elf) extracts its binaries to a
|
||||||
|
# NESTED folder:
|
||||||
|
# <pkg>/xtensa-esp-elf/bin/xtensa-esp32s3-elf-gcc.exe (and g++, ar, ld, ...)
|
||||||
|
# but pioarduino's export_paths PATH-injection did not reach the SCons build
|
||||||
|
# environment, so the compiler was invoked by bare name and the shell reported
|
||||||
|
# "'xtensa-esp32s3-elf-gcc' is not recognized as an internal or external command".
|
||||||
|
#
|
||||||
|
# This script finds the toolchain package dir dynamically and prepends its real
|
||||||
|
# bin/ folder to the build PATH. It is a no-op if the bin folder isn't nested
|
||||||
|
# (e.g. after a future clean reinstall that flattens the layout), so it's safe
|
||||||
|
# to leave in place.
|
||||||
|
#
|
||||||
|
# Proper long-term fix (optional): remove ~/.platformio/packages/toolchain-xtensa-esp-elf
|
||||||
|
# and ~/.espressif, then rebuild so pioarduino re-runs idf_tools install cleanly.
|
||||||
|
|
||||||
|
Import("env") # noqa: F821 (injected by PlatformIO/SCons)
|
||||||
|
|
||||||
|
from os.path import isdir, join
|
||||||
|
|
||||||
|
platform = env.PioPlatform()
|
||||||
|
|
||||||
|
toolchain_pkg = platform.get_package_dir("toolchain-xtensa-esp-elf")
|
||||||
|
if toolchain_pkg:
|
||||||
|
nested_bin = join(toolchain_pkg, "xtensa-esp-elf", "bin")
|
||||||
|
if isdir(nested_bin):
|
||||||
|
env.PrependENVPath("PATH", nested_bin)
|
||||||
|
print("[fix_toolchain_path] Prepended toolchain bin to PATH: %s" % nested_bin)
|
||||||
|
else:
|
||||||
|
print("[fix_toolchain_path] Nested bin not found (layout OK?): %s" % nested_bin)
|
||||||
|
else:
|
||||||
|
print("[fix_toolchain_path] toolchain-xtensa-esp-elf package dir not found")
|
||||||
+7
-2
@@ -1,6 +1,6 @@
|
|||||||
---
|
---
|
||||||
type: index
|
type: index
|
||||||
updated: 2026-07-15
|
updated: 2026-07-17
|
||||||
---
|
---
|
||||||
|
|
||||||
# Index
|
# Index
|
||||||
@@ -16,11 +16,12 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
|
|||||||
## Concepts
|
## Concepts
|
||||||
|
|
||||||
- [[can-bus-integration]] — the core challenge; current firmware ID map flagged as placeholder, verification plan
|
- [[can-bus-integration]] — the core challenge; current firmware ID map flagged as placeholder, verification plan
|
||||||
|
- [[driveline-speed-signals]] — **engine / turbine / output-shaft speeds**: turbine speed as physical proof of gear engagement, and the output-shaft field that is our **only road-speed source** (no DSC on this bus) — the feedback variable for a future cruise-control PoC, with the safety envelope that would require
|
||||||
- [[dual-controller-architecture]] — Controller A → UART 5Hz → Controller B (1.3" display); packet format
|
- [[dual-controller-architecture]] — Controller A → UART 5Hz → Controller B (1.3" display); packet format
|
||||||
|
|
||||||
## Synthesis
|
## Synthesis
|
||||||
|
|
||||||
- [[can-id-candidates]] — **the E60/E65 CAN ID map from web research**: 0x1D0/0x1D2/0x0B5/0x3B4 with confidence ratings, layout disputes, sources; fault codes not passively broadcast
|
- [[can-id-candidates]] — **the E60/E65 CAN ID map — now decoded end-to-end**: gear (lever + engaged + mode), coolant, gearbox temp (raw−40), battery (12-bit ×0.015), RPM, turbine speed, engine state all verified; placeholder IDs verified absent; fault codes and boost not passively broadcast
|
||||||
- [[open-questions]] — the research frontier: bench-verify the candidate IDs, operating temp, transient protection, fault-code design decision
|
- [[open-questions]] — the research frontier: bench-verify the candidate IDs, operating temp, transient protection, fault-code design decision
|
||||||
|
|
||||||
## Sources
|
## Sources
|
||||||
@@ -28,3 +29,7 @@ Catalog of every page in the wiki. Read this first when answering questions. Kee
|
|||||||
- [[esp32-s3-touch-lcd-5b-waveshare-wiki]] — official Waveshare product wiki (ingested 2026-07-15); answered CAN-transceiver and power questions, raised the 0–65 °C operating-temp concern
|
- [[esp32-s3-touch-lcd-5b-waveshare-wiki]] — official Waveshare product wiki (ingested 2026-07-15); answered CAN-transceiver and power questions, raised the 0–65 °C operating-temp concern
|
||||||
- [[e60-vfl-can-codes-xlsx]] — community E60 pre-facelift CAN table (ingested 2026-07-15); E60-specific confirmation of 0x1D0/0x3B4, new 0x304 gear-lever candidate
|
- [[e60-vfl-can-codes-xlsx]] — community E60 pre-facelift CAN table (ingested 2026-07-15); E60-specific confirmation of 0x1D0/0x3B4, new 0x304 gear-lever candidate
|
||||||
- [[listen-and-send-pid-arduino]] — Arduino ELM327→E46-cluster sketch (ingested 2026-07-15); technique reference for a diagnostic-request fallback, not ID evidence
|
- [[listen-and-send-pid-arduino]] — Arduino ELM327→E46-cluster sketch (ingested 2026-07-15); technique reference for a diagnostic-request fallback, not ID evidence
|
||||||
|
- [[can-capture-2026-07-15]] — **first live CAN dump off the real swap bus** (captured with the board's own logger); confirms 15 IDs incl. all four signal IDs, resolves the 0x1D2 gear encoding, verifies placeholder IDs absent; raw at `raw/can-capture-2026-07-15-gearshift.csv`
|
||||||
|
- [[gear-box-can-revealings]] — **gear fully decoded & VERIFIED** (2026-07-16/17): `0x1D2` byte0 = lever, **byte1 = engaged gear 1–6**, byte4 = Drive/Sport/Manual mode; `0x0BA` = the box's own target gear incl. **reverse**; raw at `raw/gear_box_can_revealings.csv` + `raw/gearbox_engaged_gear.csv`
|
||||||
|
- [[can-capture-2026-07-17-drive]] — **first capture with the vehicle moving** (2026-07-17): verifies `0x0BA` gears 2nd–6th directly (making it a complete gear source), catches the lockup clutch live, and produces the ×0.125 output-shaft scaling evidence; raw at `raw/log_20260717_145930.txt`
|
||||||
|
- [[e65-reverse-engineering-repo]] — **E65 per-ID DBC-style docs (ingested 2026-07-17)** — the highest-value source yet: settled the gearbox-temp offset (raw−40) and battery layout (12-bit ×0.015), proved the engine was running in our capture, and revealed turbine speed, output shaft, pedal position and cruise state
|
||||||
|
|||||||
+20
@@ -21,3 +21,23 @@ Deep-research workflow ran (interrupted twice by session task-loss on Windows; ~
|
|||||||
## [2026-07-15] update | Donor and target vehicle confirmed by user
|
## [2026-07-15] update | Donor and target vehicle confirmed by user
|
||||||
|
|
||||||
User confirmed: donor chassis is **E60/E65 (2003+)**, transmission is a **BMW auto with EGS on the CAN bus**, target vehicle is a **Nissan Patrol**. Created [[nissan-patrol-swap]]; updated [[bmw-m57n-engine]] (E46-era candidate IDs flagged as probably wrong generation) and [[open-questions]] (three questions moved to Answered). Next: web research for E60-generation PT-CAN broadcast IDs.
|
User confirmed: donor chassis is **E60/E65 (2003+)**, transmission is a **BMW auto with EGS on the CAN bus**, target vehicle is a **Nissan Patrol**. Created [[nissan-patrol-swap]]; updated [[bmw-m57n-engine]] (E46-era candidate IDs flagged as probably wrong generation) and [[open-questions]] (three questions moved to Answered). Next: web research for E60-generation PT-CAN broadcast IDs.
|
||||||
|
|
||||||
|
## [2026-07-16] ingest | Gear lever fully decoded & VERIFIED (0x1D2)
|
||||||
|
|
||||||
|
User captured steady byte values per lever detent (`raw/gear_box_can_revealings.csv`) → [[gear-box-can-revealings]]. **0x1D2 verified as the gear source**: byte0 = P `0xE1` / R `0xD2` / N `0xB4` / D `0x78` (all match documented codes exactly); byte0 can't split D from S/M (shared `0x78`) so byte4 does it (`0xF0` auto / `0xF1` Sport-Manual / `0xF2` downshift −); byte1 is a drive-gate flag (`0x0F`→`0x5F`); byte3 = rolling counter (confirms prediction). 0x0BA also tracks the lever but is messier (D/S-M collide) — don't use. Promoted 0x1D2 gear row to VERIFIED and rewrote the encoding-dispute section in [[can-id-candidates]]; updated index. Still open: actual engaged gear number (needs a drive capture) and the manual up-shift (+) value. Next: rewrite firmware gear map to 0x1D2 byte0 (+byte4).
|
||||||
|
|
||||||
|
## [2026-07-17] update | Driveline screen live; torque decoded; output-shaft scaling revised
|
||||||
|
|
||||||
|
Firmware flashed and running on the car. Built a hand-coded Driveline screen (src/, boot screen, swipe to reach Home) showing gear + coolant + gearbox temp + RPM + torque + turbine + output-shaft + status chips. Three findings from the user testing it: (1) **Torque decoded & verified** — on **0x0A8 TORQ_AVL** (available engine torque; user-identified the ID). User's Excel `(D2*256+D1)/32` is algebraically bits12-23 ×0.5; confirmed against the repo's 0x0A8 worked example (24 Nm, ALIV=8 in D1 low nibble), ~27-28 Nm at idle. Firmware masks D1's low nibble (alive counter, not torque) and sign-extends. Note 0x0AA TORQ_DVCH is the same layout but driver *demand* — identical at idle, diverges under load. → [[can-id-candidates]], [[driveline-speed-signals]]. (2) **Output-shaft scaling revised**: a direct Launch reference (output speed 128 rpm at our raw 1192) **contradicts the earlier ×0.125** (would predict 149) and points to ~0.107. One eyeballed cross-tool point, so not adopted — but 0.125 is downgraded, and the Launch now gives a direct rpm reference so calibration is just a multi-point sweep + linear fit. Firmware keeps raw counts. (3) Fixed a latent display bug: main.cpp showed DEFAULT_* placeholder temps/voltage as if measured; now gated on valid_flags. Ignition decoded from 0x3B4 byte2 (user: 0x00=on/0x09=off, tracks ignition not engine — both published sources wrong here).
|
||||||
|
|
||||||
|
## [2026-07-17] ingest | First drive capture — 0x0BA gear ladder verified, output-shaft scaling narrowed
|
||||||
|
|
||||||
|
`raw/log_20260717_145930.txt` (CANNY 5.3 Pico, 1,857 frames / ~34 s, filtered to 0x0BA + 0x1D2) → [[can-capture-2026-07-17-drive]]. **First capture with the vehicle actually moving.** Closes the inference left open yesterday: **`ST_GR_GRB` values 6/7/8/9/A observed directly** (238/77/93/127/94 frames) = 2nd–6th, so **`0x0BA` D0's low nibble is a complete gear source on its own** — P/R/N + 1st–6th, reverse included; `0x1D2` is now needed only for lever + mode. Also caught `ST_CCLT` (converter lockup) live — 422 frames "controlling" in the higher gears, which matters because a locked clutch makes turbine = engine exactly, so the engagement-ratio test needs to read it before trusting a ratio ≈ 1.0 at road speed. **Output shaft identification VERIFIED** (rises monotonically 1139→16702 across gears 1→6, zero whenever the output is held). **Scaling narrowed to ×0.125** `(unverified)`: implies a coherent 901→1872 rpm upshift schedule across five independent ratios, vs 7,200–15,000 rpm for raw-as-rpm against a ~4,500 redline. User confirmed the box is a **ZF 6HP26X** — same gearset as 6HP26 so the ratio table holds, and the xDrive output variant **dates the donor to E60/E61, not E65** (partly answers open Q#2). New question #11: was the transfer case retained? The X box measures output **upstream** of it, so a Patrol transfer case in the path would make road speed high/low-range dependent. Remaining assumption on the scaling: max-output-per-gear = upshift point — **one capture including `0x1A2` closes it** (turbine ÷ output = ratio directly). Updated [[driveline-speed-signals]], [[gear-box-can-revealings]], [[can-id-candidates]], [[nissan-patrol-swap]], [[open-questions]], index.
|
||||||
|
|
||||||
|
## [2026-07-17] ingest | E65_ReverseEngineering repo — both disputes resolved, driveline speeds discovered
|
||||||
|
|
||||||
|
User pointed at `HeinrichG-V12/E65_ReverseEngineering` (per-ID DBC-style docs, worked example on every page) → [[e65-reverse-engineering-repo]]. Highest-value source to date; combined with re-analysis of our own `raw/can-capture-2026-07-15-gearshift.csv` it closed most of the frontier. **Resolved**: gearbox oil temp = **raw − 40** (source example + our own gearbox-31 °C-vs-coolant-37 °C warm-up cross-check; my earlier "leaning offset 0" was wrong); battery = **12-bit LE × 0.015**; engine **was running** in the 2026-07-15 capture (`ST_ENGINE_RUN`=2 in 397/397) — **cold-start capture no longer needed**; RPM = `0x0AA` ×0.25 (679–684 idle). **Discovered**: `0x1A2` `RPM_GRB_TURB` turbine speed — a *physical* engagement proof (P/N ≈634/628 free-spinning vs D ≈70, R ≈0 stalled — textbook converter behaviour), plus `0x0BA` bits 20–39 output shaft (undocumented anywhere; zero in every stationary frame incl. engaged-in-D, non-zero once wheels turn), plus `ANG_ACPD` pedal % and `ST_CLCTR_V` cruise state. New page [[driveline-speed-signals]] — emphasized per user: **no DSC on this bus ⇒ output shaft is our only road-speed source**, hence the feedback variable for a future cruise-control PoC (safety envelope documented; actuation = transmitting torque requests, a different risk class from everything read-only so far). **Corrected three of my own 2026-07-16 claims**: `0x1D2` D1 is the *engaged gear* (not a "drive-gate flag" — it read 1 because the car was stationary); D4 `0xF2` is a persistent *Manual mode* (not a "downshift event" — it holds across gears 2–6); `0x0BA` is **not** to be dismissed (I'd read D7, an alive counter, instead of D0's `ST_GR_GRB` — which is the only source of engaged **reverse**, `0x1D2` D1 staying `0x0F` in R). Also: boost is **not** broadcast (`AIP_ENG` caps at 1108 hPa = barometric) — confirms the Launch must poll. Updated [[can-id-candidates]], [[gear-box-can-revealings]], [[open-questions]], index. Next: firmware pass over the whole verified map.
|
||||||
|
|
||||||
|
## [2026-07-16] ingest | First live CAN capture — research map CONFIRMED
|
||||||
|
|
||||||
|
First real dump off the swap's bus, taken with the board's **own new raw-frame logger** (`(repo)`; USB-CDC stream, serial mutex, ~486 frame/s, ~1.4% line loss). Raw filed at `raw/can-capture-2026-07-15-gearshift.csv` (20,596 frames) → [[can-capture-2026-07-15]]. Findings: 15 IDs live incl. **all four researched signal IDs** (0x1D0, 0x1D2, 0x0B5, 0x3B4) + bonus 0x0AA/0x0BA; firmware's placeholder IDs (0x4F/0x55/0x201/0x1001/0x101F) **verified absent**; researched-but-absent: 0x130/0x304/0x192. **0x1D0 b0** drifts 0x55→0x58 (coolant −48, ~37→40 °C); **0x1D0 b1 = 0xFF** (oil temp unpopulated). **0x1D2 gear encoding resolved**: DLC 6, byte0 whole-byte codes (0xE1=P, 0xB4=N, 0x78=D seen live). **0x3B4** at ~5 s rate but payload dormant (0xFF) — engine state unconfirmed. Updated [[can-id-candidates]], [[can-bus-integration]], [[esp32-s3-touch-lcd-5b]], [[open-questions]], index. Also corrected a firmware fact across pages: driver runs **`TWAI_MODE_NORMAL` (ACKs the bus), not LISTEN_ONLY**; TJA1051 is non-isolated → must share vehicle ground. Next: cold-start + confirmed-engine-running capture to lock coolant/battery scaling; use differential (per-position) captures for gear.
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: concept
|
type: concept
|
||||||
tags: [can-bus, reverse-engineering]
|
tags: [can-bus, reverse-engineering]
|
||||||
updated: 2026-07-15
|
updated: 2026-07-16
|
||||||
---
|
---
|
||||||
|
|
||||||
# CAN Bus Integration
|
# CAN Bus Integration
|
||||||
@@ -10,10 +10,14 @@ The core technical challenge of the project: reading real data from the [[bmw-m5
|
|||||||
|
|
||||||
## Current firmware state (repo)
|
## Current firmware state (repo)
|
||||||
|
|
||||||
- ESP32-S3 TWAI peripheral, 500 kbps, **LISTEN_ONLY** mode (cannot disturb the bus — good).
|
- ESP32-S3 TWAI peripheral, 500 kbps.
|
||||||
- Falls back to dummy simulated data when CAN is off or failing.
|
- Falls back to dummy simulated data when CAN is off or failing.
|
||||||
|
- **Raw frame logger (repo, added 2026-07-15):** every received frame is streamed over USB-CDC as `CANRAW,<ts_ms>,<id>,<extd>,<dlc>,<hex>`, serialized by a mutex so lines don't interleave. This is how [[can-capture-2026-07-15]] was taken — the board is now its own CAN sniffer. Logs are tethered-only (no onboard SD recording yet; the board has a microSD slot for a future "black box").
|
||||||
- Configured message map:
|
- Configured message map:
|
||||||
|
|
||||||
|
> [!warning] The firmware is NOT in LISTEN_ONLY mode — it ACKs the bus
|
||||||
|
> Despite older comments/docs saying "LISTEN_ONLY", the TWAI driver is installed in **`TWAI_MODE_NORMAL`** `(repo)` — a deliberate choice so it sends ACK bits and stops transmitters from flooding retries. Consequences: (1) the board is an **active bus participant**, not a passive sniffer — correct on a live multi-ECU bus, but do NOT power it in ACK mode on a bench with a single other node and no termination. (2) The onboard **TJA1051T/3 transceiver is non-isolated**, so its ground MUST be common with the vehicle (simplest: power the board from vehicle 12 V, whose negative *is* the reference). A flaky ground on an actively-ACKing node causes intermittent bus errors that look like data problems. → [[esp32-s3-touch-lcd-5b]]
|
||||||
|
|
||||||
| ID | Byte(s) | Mapped to |
|
| ID | Byte(s) | Mapped to |
|
||||||
|--------|---------|-----------|
|
|--------|---------|-----------|
|
||||||
| 0x4F | 0 | Coolant temp |
|
| 0x4F | 0 | Coolant temp |
|
||||||
@@ -25,14 +29,14 @@ The core technical challenge of the project: reading real data from the [[bmw-m5
|
|||||||
> [!warning] These IDs are almost certainly placeholders, not real BMW IDs.
|
> [!warning] These IDs are almost certainly placeholders, not real BMW IDs.
|
||||||
> Two red flags: (1) `0x1001` and `0x101F` exceed `0x7FF`, the maximum for standard 11-bit CAN identifiers — BMW E-series PT-CAN of the M57N era uses 11-bit frames `(unverified)`, so these would never match. (2) None of the five IDs appear in community BMW reverse-engineering documentation. The map needs to be rebuilt from real bus captures or a trustworthy source before any of the displayed data can be believed.
|
> Two red flags: (1) `0x1001` and `0x101F` exceed `0x7FF`, the maximum for standard 11-bit CAN identifiers — BMW E-series PT-CAN of the M57N era uses 11-bit frames `(unverified)`, so these would never match. (2) None of the five IDs appear in community BMW reverse-engineering documentation. The map needs to be rebuilt from real bus captures or a trustworthy source before any of the displayed data can be believed.
|
||||||
|
|
||||||
> [!info] Research done 2026-07-15
|
> [!info] Research done 2026-07-15, then CONFIRMED live
|
||||||
> Web research produced a replacement candidate map — **0x1D0** (coolant + oil temp), **0x1D2** (gear), **0x0B5** (gearbox temp), **0x3B4** (battery voltage) — with confidence ratings and two layout disputes to settle on the bench. Full table and sources: [[can-id-candidates]]. Fault codes are NOT passively broadcast (diagnostic requests required) — the `fault_codes` field needs a design decision.
|
> Web research produced a replacement candidate map — **0x1D0** (coolant + oil temp), **0x1D2** (gear), **0x0B5** (gearbox temp), **0x3B4** (battery voltage) — with confidence ratings and two layout disputes to settle on the bench. Full table and sources: [[can-id-candidates]]. The first live capture ([[can-capture-2026-07-15]]) confirmed all four IDs are present and resolved the 0x1D2 gear encoding. Fault codes are NOT passively broadcast (diagnostic requests required) — the `fault_codes` field needs a design decision.
|
||||||
|
|
||||||
## Verification plan
|
## Verification plan
|
||||||
|
|
||||||
1. Get a raw capture of the actual bus (candump / Savvy CAN / cheap USB-CAN dongle) with the engine running. File the log into `raw/`.
|
1. ~~Get a raw capture of the actual bus. File the log into `raw/`.~~ ✅ **Done** 2026-07-15 with the board's own logger → `raw/can-capture-2026-07-15-gearshift.csv`, summarized in [[can-capture-2026-07-15]]. **Still needed: a cold-start + confirmed-engine-running capture** to lock coolant/battery scaling (the first capture's engine state was unconfirmed and the battery/oil-temp bytes were dormant).
|
||||||
2. Identify candidate IDs by watching which bytes track known physical behavior (rev the engine, warm it up, shift gears).
|
2. Identify candidate IDs by watching which bytes track known physical behavior (rev the engine, warm it up, shift gears). *In progress:* gear (0x1D2) done; coolant drift seen; RPM/battery pending. Use a **differential capture** for gear (hold each position, diff steady states) rather than a continuous sweep.
|
||||||
3. Cross-check against community DBC files / reverse-engineering wikis for the donor vehicle.
|
3. Cross-check against community DBC files / reverse-engineering wikis for the donor vehicle. ✅ done → [[can-id-candidates]].
|
||||||
4. Update `automotive_data.h` `(repo)` and mark each mapping `(verified)` here only after it matches reality on the live bus.
|
4. Update `automotive_data.h` `(repo)` and mark each mapping `(verified)` here only after it matches reality on the live bus.
|
||||||
|
|
||||||
## Signal-source caveat
|
## Signal-source caveat
|
||||||
|
|||||||
@@ -1,48 +1,91 @@
|
|||||||
---
|
---
|
||||||
type: synthesis
|
type: synthesis
|
||||||
tags: [can-bus, reverse-engineering, e60, research]
|
tags: [can-bus, reverse-engineering, e60, research]
|
||||||
updated: 2026-07-15
|
updated: 2026-07-17
|
||||||
---
|
---
|
||||||
|
|
||||||
# E60/E65 CAN ID Candidates (Research Results)
|
# E60/E65 CAN ID Candidates (Research Results)
|
||||||
|
|
||||||
Findings from the 2026-07-15 deep-research run (95 claims extracted from ~15 sources, 30 adversarially verified against primary repos before the run was interrupted; synthesis done manually from the journal). These are the IDs to program into the firmware **for bench testing against a live capture** — none are `(verified)` until seen on the actual swap's bus.
|
Findings from the 2026-07-15 deep-research run (95 claims extracted from ~15 sources, 30 adversarially verified against primary repos before the run was interrupted; synthesis done manually from the journal). These are the IDs to program into the firmware **for bench testing against a live capture** — none are `(verified)` until seen on the actual swap's bus.
|
||||||
|
|
||||||
|
> [!success] Live capture 2026-07-15 — the map is CONFIRMED on the real bus
|
||||||
|
> First dump off the actual swap's bus ([[can-capture-2026-07-15]]) validates the research:
|
||||||
|
> - **All four signal IDs are live**: `0x1D0`, `0x1D2`, `0x0B5`, `0x3B4` (+ bonus `0x0AA`, `0x0BA`). (verified: present)
|
||||||
|
> - The firmware's placeholder IDs are **absent** — confirmed junk. (verified: absent)
|
||||||
|
> - `0x1D0` byte0 drifts up `0x55→0x58` = coolant warming (−48 scaling holds). **Oil temp `0x1D0` byte1 = `0xFF`** (not populated here).
|
||||||
|
> - `0x1D2` **gear fully VERIFIED** (2026-07-16, [[gear-box-can-revealings]]): byte0 `0xE1`=P/`0xD2`=R/`0xB4`=N/`0x78`=D — all codes match; byte4 splits D vs S/M and carries manual +/− shifts.
|
||||||
|
> - Absent despite being researched: `0x130`, `0x304`, `0x192`.
|
||||||
|
|
||||||
|
> [!success] 2026-07-17 — [[e65-reverse-engineering-repo]] ingested: both disputes resolved, engine state closed
|
||||||
|
> A per-ID DBC-style source with worked examples on every page. Combined with re-analysis of our own capture:
|
||||||
|
> - **Gearbox oil temp offset RESOLVED → `raw − 40`** (not offset 0, not +40). Cross-checked against our coolant trace.
|
||||||
|
> - **Battery layout RESOLVED → 12-bit LE × 0.015** (the E65 reading; the E90 24-bit BE reading is wrong for us).
|
||||||
|
> - **Engine-run state CLOSED** — `0x1D0` bits 20–21 read "running" in 397/397 frames of the 2026-07-15 capture. That dump *was* a genuine warm-up trace, so **no cold-start capture is needed to trust the coolant scaling**.
|
||||||
|
> - **Engaged gear number RESOLVED** without a drive capture → `0x1D2` D1 high nibble ([[gear-box-can-revealings]]).
|
||||||
|
> - **New signals**: turbine speed (`0x1A2`), output shaft speed (`0x0BA` D3/D4), pedal position + cruise state (`0x0AA`) → [[driveline-speed-signals]].
|
||||||
|
|
||||||
## The map (replaces the firmware's placeholder IDs)
|
## The map (replaces the firmware's placeholder IDs)
|
||||||
|
|
||||||
| Signal | CAN ID | Bytes | Scaling | Sender | Rate | Confidence |
|
| Signal | CAN ID | Bytes | Scaling | Sender | Rate | Confidence |
|
||||||
|--------|--------|-------|---------|--------|------|------------|
|
|--------|--------|-------|---------|--------|------|------------|
|
||||||
| Coolant temp | **0x1D0** | byte 0 | °C = raw − 48 | DME/DDE | 100 ms | **Very high** — verified verbatim in E65 docs, present in E90-gen DBC, confirmed live on a real E60 545i, E60 tool32 table lists 0x1D0 "Motordaten" from DDE1 (diesel!), and the [[e60-vfl-can-codes-xlsx]] sheet shows 0x7A→74 °C on a real E60 VFL (raw−48 checks out) |
|
| Coolant temp | **0x1D0** | byte 0 | °C = raw − 48 | DME/DDE | 100 ms | **Very high** — verified verbatim in E65 docs, present in E90-gen DBC, confirmed live on a real E60 545i, E60 tool32 table lists 0x1D0 "Motordaten" from DDE1 (diesel!), and the [[e60-vfl-can-codes-xlsx]] sheet shows 0x7A→74 °C on a real E60 VFL (raw−48 checks out) |
|
||||||
| Engine oil temp | **0x1D0** | byte 1 | °C = raw − 48 | DME/DDE | 100 ms | **High** — same sources as coolant |
|
| Engine oil temp | **0x1D0** | byte 1 | °C = raw − 48 | DME/DDE | 100 ms | **High** — same sources as coolant |
|
||||||
| Gearbox oil temp | **0x0B5** ("Torque_request_EGS") | byte 7 | ⚠ disputed: raw + 0 vs raw + 40 | EGS | ? | **Medium** — in the E9x community DBC; absent from the E65 repo's decoded EGS messages. Offset must be settled on the bench (a ~40 °C error is dangerous — resolve before trusting) |
|
| Gearbox oil temp | **0x0B5** (`TEMP_GRB`) | byte 7 | **°C = raw − 40** | EGS | 10 ms | **✅ RESOLVED 2026-07-17** — [[e65-reverse-engineering-repo]] worked example (raw `0x43`=67 → 27 °C), plus our own cross-check: D7 `0x47`(71)→**31 °C** while coolant read 37 °C and climbing. Offset-0 would have the box at 71 °C with the engine at 37 °C — impossible for a warm-up |
|
||||||
| Gear lever position | **0x1D2** ("TransmissionDataDisplay") | byte 0 | ⚠ two encodings, see below | EGS | 200 ms | **High that the ID is right**, medium on layout |
|
| Gear lever position | **0x1D2** ("TransmissionDataDisplay") | **byte 0** | `0xE1`=P `0xD2`=R `0xB4`=N `0x78`=D/(S/M) | EGS | 200 ms | **✅ VERIFIED on the swap bus 2026-07-16** — every code matches. Full decode: [[gear-box-can-revealings]] |
|
||||||
| Current gear number | **0x1D2** byte 1 upper nibble (GearAct, −4 offset) or **0x0BA** bits 0–3 (E65: values P/R/N…6th) | | | EGS | 20–200 ms | **Medium** — two candidate messages; also **0x304** "Gear lever" — the E60 VFL sheet shows a 2-byte lever message: P=0xE3, R=0xC2, N=0xD1, M=0xC9 (its D=0xC2 duplicates R — likely a sheet typo) |
|
| Gearbox mode | **0x1D2** | **byte 4** | `0xF0`=Drive(auto) `0xF1`=Sport `0xF2`=Manual | EGS | 200 ms | **✅ VERIFIED 2026-07-17** — `0xF2` is a *persistent mode*, not a downshift event (earlier claim corrected) |
|
||||||
| Battery voltage | **0x3B4** ("Powermanagement Batteriespannung") | ⚠ disputed layout | 12-bit LE × 0.015 V (E65, verified: 0x3D9→14.775 V) vs 24-bit BE × 0.001 V (E90 DBC) | Power module / DDE | 5 s (E65) | **High on ID** (E60 tool32 table + E60 VFL sheet: `64 F3`→12.76 V, consistent with the 12-bit LE layout though implying factor ≈0.0147 vs 0.015). Bonus from the sheet: byte 3 = engine running flag (0x09 on / 0x00 off) |
|
| Engaged gear number | **0x1D2** | **byte 1** | `gear = (D1 >> 4) − 4`; `0x0F` = none (P/R/N) | EGS | 200 ms | **✅ VERIFIED 2026-07-17** — clean +16 ladder across gears 1–6, identical in D and M/S ([[gear-box-can-revealings]]). **Never set for R** |
|
||||||
| Engine RPM (bonus) | **0x0AA** | bytes 4–5 | RPM = raw / 4 | DME/DDE | 10 ms | High — cross-generation (E65 + E90 comment) |
|
| Engaged gear **incl. reverse** | **0x0BA** (`ST_GR_GRB`) | byte 0 low nibble | `1`=N `2`=**R** `3`=P `5`–`A`=1st–6th `0xF`=invalid | EGS | 20 ms | **✅ FULLY VERIFIED 2026-07-17** — all of 1/2/3/5/6/7/8/9/A observed live in the drive capture ([[can-capture-2026-07-17-drive]]). **A complete gear source on its own**, and the only source of engaged reverse (`0x1D2` D1 is blind to it). Value `4` unobserved |
|
||||||
| Ignition/terminal status (bonus) | **0x130** | byte 0 bitmasks | 0xD5/0xC5/0xC1 | CAS | 100 ms | Medium — used by an M57 project as its only passive decode |
|
| Converter lockup clutch | **0x0BA** (`ST_CCLT`) | byte 0 bits 6–7 | `0`=disengaged `1`=controlled `2`=closed `3`=invalid | EGS | 20 ms | **✅ VERIFIED 2026-07-17** — 422 frames "controlling", clustered in higher gears. Matters for the turbine-ratio test: when locked, turbine = engine exactly → [[driveline-speed-signals]] |
|
||||||
|
| Battery voltage | **0x3B4** (`U_BT`) | bits 0–11 | **`((D1 & 0x0F) << 8 \| D0) × 0.015` V** | Power module | 5 s | **✅ RESOLVED 2026-07-17** — 12-bit LE × 0.015 confirmed by [[e65-reverse-engineering-repo]] worked example (`0x3D9`→14.775 V). The E90 24-bit BE × 0.001 reading is **wrong for us**. Bonus: `ENG_ST` bits 16–19 |
|
||||||
|
| Engine RPM | **0x0AA** (`RPM_ENG`) | bits 32–47 | **`(D4 + D5×256) × 0.25`** 1/min | DME/DDE | 10 ms | **✅ VERIFIED 2026-07-17** — 679–684 rpm at idle on our capture, matching `RPM_IDLE_TARGET`=700 from `0x1D0` |
|
||||||
|
| **Turbine speed** | **0x1A2** (`RPM_GRB_TURB`) | bits 0–15 | **`(D0 + D1×256) × 0.125 + 6`** 1/min | EGS | 20 ms | **✅ VERIFIED 2026-07-17** — physical proof of gear engagement; collapses ~630→~0 when the box engages. → [[driveline-speed-signals]] |
|
||||||
|
| **Output shaft speed** | **0x0BA** | bits 20–39 (D3/D4) | 🔬 raw × ~**0.107** rpm (was 0.125) | EGS | 20 ms | **ID ✅ verified 2026-07-17** — rises monotonically 1st→6th, zero whenever the output is held. **Scaling 🔬 and revised**: a direct Launch reference (128 rpm @ raw 1192) **contradicts ×0.125** (would predict 149) and points to ~0.107. Needs a multi-point Launch sweep to fix. **Our only road-speed signal** (no DSC on this bus) → [[driveline-speed-signals]] |
|
||||||
|
| Engine run state | **0x1D0** (`ST_ENGINE_RUN`) | bits 20–21 | `0`=off `1`=starting `2`=running `3`=invalid | DME/DDE | 100 ms | **✅ VERIFIED 2026-07-17** — read 2 ("running") in 397/397 frames of the 2026-07-15 capture |
|
||||||
|
| Engine torque (available) | **0x0A8** (`TORQ_AVL`) | bits 12–23 | signed × **0.5 Nm** (`(D2<<8\|D1)/32` after masking D1's alive-counter nibble) | DME/DDE | 10 ms | **✅ VERIFIED 2026-07-17** — user-identified ID; formula matches the repo's 0x0A8 worked example (24 Nm, ALIV=8 in D1 low nibble); ~27–28 Nm at warm idle. On the driveline screen → [[driveline-speed-signals]]. NB **0x0AA `TORQ_DVCH`** is the same layout but is driver *demand* — diverges under load |
|
||||||
|
| Pedal position / cruise state | **0x0AA** | `ANG_ACPD` bits 24–31 (×0.39063 %); `ST_CLCTR_V` bits 52–55 | see [[driveline-speed-signals]] | DME/DDE | 10 ms | (source: [[e65-reverse-engineering-repo]]) — relevant to a cruise-control PoC |
|
||||||
|
| Gearbox cooling demand | **0x0B5** (`ST_OTMP_GRB`) | bits 38–39 | `0`=none `1`=stage 1 `2`=stage 2 `3`=invalid | EGS | 10 ms | (source: [[e65-reverse-engineering-repo]]) — the box's own overheat opinion; better display warning than a raw threshold |
|
||||||
|
| Ignition/terminal status | **0x130** | byte 0 bitmasks | 0xD5/0xC5/0xC1 | CAS | 100 ms | **Absent from our bus** (verified 2026-07-15) — CAS not retained in the swap |
|
||||||
|
|
||||||
### The 0x1D2 encoding dispute (must resolve on bench)
|
### The 0x1D2 encoding dispute — ✅ RESOLVED on the swap bus (2026-07-16)
|
||||||
|
|
||||||
- **E90-generation DBC**: low nibble of byte 0 = 1=P, 2=R, 4=N, 8=D (bitmask style, XOR-inverted copy in high nibble); 2-bit ShiftLeverMode at bit 32 (0=Normal, 1=Sport, 2=Manual). DLC 6.
|
The live lever capture ([[gear-box-can-revealings]]) settles it — **DLC 6**, whole-byte codes in byte 0, matching the documented table exactly:
|
||||||
- **E65 live capture** (damienmaguire, verified against code): whole byte 0 = 0xE1=P, 0xD2=R, 0xB4=N, 0x78=D; byte 3 is a rolling counter 0x0D→0xED in steps of 0x10. DLC **5**.
|
|
||||||
- Same ID, different generation dialects — the E60 could speak either. Note the E65 byte-0 values are consistent with the E90 nibble scheme (0xE1 low nibble = 1 = P, 0xD2 → 2 = R, 0xB4 → 4 = N, 0x78 → 8 = D, high nibble = XOR-inverted copy!) — so the two sources may actually agree and the "dispute" is notation. Bench capture decides.
|
| Byte | Meaning | Values |
|
||||||
|
|------|---------|--------|
|
||||||
|
| **0** | **Lever position** | `0xE1`=P, `0xD2`=R, `0xB4`=N, `0x78`=D **and** S/M |
|
||||||
|
| **1** | **Engaged gear** | `gear = (D1 >> 4) − 4`; `0x0F` = none (P/R/N). Never set for R |
|
||||||
|
| 2 | unused | `0xFF` |
|
||||||
|
| 3 | Rolling counter | fluctuates — ignore (matches the predicted byte-3 counter) |
|
||||||
|
| **4** | **Mode** | `0xF0`=Drive(auto), `0xF1`=Sport, `0xF2`=Manual |
|
||||||
|
| 5 | unused | `0xFF` |
|
||||||
|
|
||||||
|
Byte 0 alone gives P/R/N/D; byte 4 splits **D vs S vs M**; byte 1 gives the engaged gear 1–6. The old "dispute" was just notation — the E65 whole-byte values and the E90 low-nibble scheme agree (`0xE1` low nibble = 1 = P, etc.), and this bus speaks the whole-byte/DLC-6 dialect.
|
||||||
|
|
||||||
|
> [!warning] Two 2026-07-16 labels on this page were wrong — corrected 2026-07-17
|
||||||
|
> - **D1 was called a "drive-gate flag"**. It is the **engaged gear number**; it only ever showed two values because the vehicle was stationary in 1st. This also means the "engaged gear needs a drive capture" task was never real — a per-detent capture sufficed.
|
||||||
|
> - **D4 `0xF2` was called "downshift (−)"**, a transient event. It is a **persistent Manual-mode flag** — it holds across gears 2–6. The `+`/`−` nudges have no distinct code; they merely promote Sport → Manual. The old "up-shift (+) value unconfirmed" question therefore dissolves rather than being answered.
|
||||||
|
>
|
||||||
|
> Both errors came from over-reading a two-value field as a boolean. Full evidence: [[gear-box-can-revealings]].
|
||||||
|
|
||||||
|
> Note `0x1D2` is where **our decode is ahead of the published source**: [[e65-reverse-engineering-repo]] lists `0x1D2` as "Display Gearbox Data" with an **empty signal table** — it never decoded it. Its sample frame (`E1 0C 8F 7C F0 FF`) does independently confirm `0xE1`=P.
|
||||||
|
|
||||||
|
> The firmware's `automotive_data.h` gear map should be rewritten to `0x1D2` byte 0 + byte 1 + byte 4, with `0x0BA` for engaged reverse. → [[can-bus-integration]]
|
||||||
|
|
||||||
## Field checklist for the live capture session
|
## Field checklist for the live capture session
|
||||||
|
|
||||||
Setup: 500 kbps, listen-only, board's 120 Ω termination switch **OFF**, tap CAN-H/CAN-L on the PT-CAN. **Log everything raw for the whole session** and save the dump into `wiki/raw/` — even IDs we don't care about yet.
|
Setup: 500 kbps, board's 120 Ω termination switch **OFF**, common ground with the vehicle, tap CAN-H/CAN-L on the PT-CAN. (Note: the firmware runs `TWAI_MODE_NORMAL` and ACKs the bus — not listen-only — see [[can-bus-integration]].) **Log everything raw for the whole session** and save the dump into `wiki/raw/` — even IDs we don't care about yet.
|
||||||
|
|
||||||
|
Setup notes still apply. **Most of the original checklist is now done** — gear (lever, engaged, mode), coolant, gearbox temp, battery, RPM, engine state are all resolved. What remains:
|
||||||
|
|
||||||
| Test | Watch | Confirms |
|
| Test | Watch | Confirms |
|
||||||
|------|-------|----------|
|
|------|-------|----------|
|
||||||
| Ignition on, engine off | `0x130` byte 0 changes per key position; `0x3B4` appears (~every 5 s) | Terminal status; battery message alive |
|
| **Wheels lifted, steady speed in D; step 1st→6th** | `0x0BA` D3/D4 vs `0x1A2` turbine vs `0x0AA` RPM, logged together | **Output-shaft scaling.** Turbine ÷ output at each gear should reproduce the 6HP26 ratios — a built-in self-check. → [[driveline-speed-signals]] |
|
||||||
| Compare `0x3B4` to a multimeter at the battery | Try 12-bit LE ×0.015 and ×0.0147 vs meter (engine off ≈12.4 V, running ≈14+ V); check byte 3 flips 0x00→0x09 on start | Battery layout + factor; engine-running flag |
|
| Compare `0x3B4` to a multimeter at the battery | `((D1 & 0x0F) << 8 \| D0) × 0.015` vs meter (engine off ≈12.4 V, running ≈14+ V) | Battery factor — layout is settled, this is a sanity pass only |
|
||||||
| Cold start, note ambient temp | `0x1D0` byte 0 ≈ ambient+48 raw, then climbs steadily to ~90 °C (raw ~0x8A) | Coolant ID + −48 scaling |
|
| Cross-check `0x0B5` D7 − 40 against the Launch's gearbox oil temp readout | Expect agreement within a degree | Confirmatory only — offset already settled two ways |
|
||||||
| Same, byte 1 | Should ALSO start near ambient but climb **slower** than byte 0 and lag behind | Oil temp really is byte 1 (weakest engine signal) |
|
| Lever to R **on the ground**, brake released | `0x1A2` turbine ÷ `0x0AA` RPM ratio | The engagement test for the "lever says R but nothing happens" fault → [[driveline-speed-signals]] |
|
||||||
| Cold start | `0x0B5` byte 7: if raw ≈ ambient → offset 0; if raw ≈ ambient+40… i.e. reads 40 under ambient with offset 0 assumed → offset +40 | Gearbox temp offset dispute (cold start makes the two hypotheses ~40 apart — unmistakable) |
|
| Engage cruise (if the donor's stalk is wired) | `0x0AA` `ST_CLCTR_V` bits 52–55 → `0x4`–`0x7` | Whether the DME's CC regulator is live on this swap |
|
||||||
| Hold brake, shift P→R→N→D→(S/M) slowly | `0x1D2` byte 0 (note DLC: 5 vs 6!); `0x304` bytes; `0x0BA` bits 0–3 | Gear lever encoding + which message to use; settles the D=R typo in the E60 sheet |
|
|
||||||
| Drive: let the box shift 1→2→3… | `0x1D2` byte 1 upper nibble, `0x0BA` low nibble increments per shift | Current gear number source |
|
|
||||||
| Blip throttle | `0x0AA` bytes 4–5 = RPM×4 | RPM sanity check (fast cross-check that you're on the right bus) |
|
|
||||||
|
|
||||||
If an expected ID is absent entirely, note it — it means the swap harness dropped that module's traffic, which is itself an answer ([[open-questions]] #3).
|
Absent IDs are themselves answers — `0x130`/`0x304`/`0x192` and the whole DSC group (`0x0CE`/`0x19E`/`0x1A0`) never appear, meaning CAS and DSC aren't on the swap bus ([[open-questions]] #3).
|
||||||
|
|
||||||
## Fault codes: passive reading is NOT possible ⚠
|
## Fault codes: passive reading is NOT possible ⚠
|
||||||
|
|
||||||
@@ -59,9 +102,9 @@ Also useful: an E60 forum claim `(unverified)` that arbitration IDs are identica
|
|||||||
|
|
||||||
## Sources
|
## Sources
|
||||||
|
|
||||||
|
- [[e65-reverse-engineering-repo]] — **E65/E66 per-ID DBC-style docs (ingested 2026-07-17)** — the highest-value source found so far: resolved the gearbox-temp offset and battery layout, closed the engine-state question, and supplied turbine speed, output shaft, pedal position and cruise state. Caveat: petrol MED 9.2.1 donor, not M57N diesel
|
||||||
- [[e60-vfl-can-codes-xlsx]] — **E60 VFL community spreadsheet (ingested)**: E60-specific confirmation of 0x1D0 (−48 scaling), 0x3B4, 0x1D2 DLC 6; adds 0x304 gear lever; contains NO oil-temp or gearbox-temp rows
|
- [[e60-vfl-can-codes-xlsx]] — **E60 VFL community spreadsheet (ingested)**: E60-specific confirmation of 0x1D0 (−48 scaling), 0x3B4, 0x1D2 DLC 6; adds 0x304 gear lever; contains NO oil-temp or gearbox-temp rows
|
||||||
- [[listen-and-send-pid-arduino]] — technique reference (ingested): ELM327 PID-request pattern for the fault-code fallback; E46 cluster frames, not E60 evidence
|
- [[listen-and-send-pid-arduino]] — technique reference (ingested): ELM327 PID-request pattern for the fault-code fallback; E46 cluster frames, not E60 evidence
|
||||||
- `HeinrichG-V12/E65_ReverseEngineering` (GitHub) — E65 760Li PT-CAN, docs verified verbatim by the adversarial pass (0x1D0, 0x3B4, 0x192, 0x1D2, 0x0BA, 0x1A2)
|
|
||||||
- `damienmaguire/BMW-E65-CANBUS` (GitHub) — live E65 735i captures + working EGS emulator code (0x1D2 encoding, 0x192, 0x0AA)
|
- `damienmaguire/BMW-E65-CANBUS` (GitHub) — live E65 735i captures + working EGS emulator code (0x1D2 encoding, 0x192, 0x0AA)
|
||||||
- `TimesNewRomanZ/e60-canbus` (GitHub, community `bmw_e9x_e8x.dbc`) — author runs a real E60 545i; 0x1D0 confirmed live on E60
|
- `TimesNewRomanZ/e60-canbus` (GitHub, community `bmw_e9x_e8x.dbc`) — author runs a real E60 545i; 0x1D0 confirmed live on E60
|
||||||
- `kmalinich/dieslg8` (GitHub) — M57 diesel (E90 335d, EDC17): diagnostic-request-only coolant/DTC evidence
|
- `kmalinich/dieslg8` (GitHub) — M57 diesel (E90 335d, EDC17): diagnostic-request-only coolant/DTC evidence
|
||||||
@@ -71,11 +114,13 @@ Also useful: an E60 forum claim `(unverified)` that arbitration IDs are identica
|
|||||||
|
|
||||||
## Caveats
|
## Caveats
|
||||||
|
|
||||||
- No source used an actual **E60 M57N diesel** end-to-end; the closest anchors are the E60 tool32 table (lists DDE1 as sender for 0x1D0/0x3B4), the E60 VFL spreadsheet (real pre-facelift E60, engine variant unknown), and the M57 dieslg8 project (different chassis generation). Engine-side layouts are inferred from petrol DME captures of the same bus generation.
|
- No source used an actual **E60 M57N diesel** end-to-end; the closest anchors are the E60 tool32 table (lists DDE1 as sender for 0x1D0/0x3B4), the E60 VFL spreadsheet, and the M57 dieslg8 project. Engine-side layouts are inferred from petrol DME captures of the same bus generation. **Mitigating evidence (2026-07-17)**: every signal from the petrol-donor [[e65-reverse-engineering-repo]] that we checked against our own bus decoded to physically sensible values first try — coolant, gearbox temp, RPM, turbine speed, engine state, gear. The layouts evidently carry.
|
||||||
- **Oil temp and gearbox oil temp remain the weakest signals** — absent from both E60-specific sources; only the E9x DBC and E65 docs place oil temp at 0x1D0 byte 1, and only the E9x DBC has gearbox temp (0x0B5 byte 7, offset disputed).
|
- **Engine oil temp is now the only dead signal**: `0x1D0` byte 1 reads `0xFF` on our bus — the sensor isn't populated on this M57N. Not a decode error; there is nothing to read. The UART packet's `engine_oil_temp` field has no source.
|
||||||
- Firmware's current IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F`) are contradicted by every source — confirmed placeholders. → [[can-bus-integration]]
|
- **`AIP_ENG` (`0x1D0` byte 3) is barometric, not boost** — 8 bits ×2 +598 caps at 1108 hPa; a boosting M57N reaches ~2500 hPa absolute. Manifold boost is **not broadcast**; the Launch polls for it. → [[obd-diagnostic-polling]]
|
||||||
- Promotion to `(verified)` requires a live capture from the swap's bus: warm the engine and watch 0x1D0 byte 0 climb, shift through P/R/N/D and watch 0x1D2.
|
- Firmware's original IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F`) are contradicted by every source AND **confirmed absent from the live bus** (verified, 2026-07-15) — definitively placeholders. → [[can-bus-integration]]
|
||||||
|
- **The cold-start capture is no longer needed.** It was on the list only because the 2026-07-15 engine state was unknown; `ST_ENGINE_RUN` = running in 397/397 frames settles that, making the coolant trace a genuine warm-up and its −48 scaling trustworthy.
|
||||||
|
- Remaining `(unverified)`: `0x0BA` `ST_GR_GRB` values 6–A (2nd–6th, inferred from the parallel `0x1D2` ladder), and the `0x0BA` D3/D4 output-shaft **scaling**. → [[driveline-speed-signals]]
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
[[can-bus-integration]] · [[bmw-m57n-engine]] · [[nissan-patrol-swap]] · [[open-questions]]
|
[[can-bus-integration]] · [[driveline-speed-signals]] · [[e65-reverse-engineering-repo]] · [[gear-box-can-revealings]] · [[bmw-m57n-engine]] · [[nissan-patrol-swap]] · [[open-questions]]
|
||||||
|
|||||||
@@ -0,0 +1,196 @@
|
|||||||
|
---
|
||||||
|
type: concept
|
||||||
|
tags: [can-bus, egs, dde, speed, gear, cruise-control, verified]
|
||||||
|
updated: 2026-07-17
|
||||||
|
---
|
||||||
|
|
||||||
|
# Driveline Speed Signals
|
||||||
|
|
||||||
|
The three rotating speeds our bus exposes — **engine**, **turbine (gearbox input)**, and **output shaft** — and why they matter well beyond the gear display. Together they give (a) a physical proof of gear engagement that no status byte can provide, and (b) the feedback variable a **cruise-control proof of concept** would be built on.
|
||||||
|
|
||||||
|
> [!important] Why this page exists
|
||||||
|
> The swap bus carries **no DSC module** — the 2026-07-15 capture found 15 IDs and *none* of the chassis/stability IDs (`0x0CE`, `0x19E`, `0x1A0`) the [[e65-reverse-engineering-repo]] documents. **There is no wheel-speed message on this bus.** So the gearbox's own shaft speeds are not a nice-to-have — they are the *only* road-speed information available to us. Anything speed-dependent this project ever does, including cruise control, has to come from here.
|
||||||
|
|
||||||
|
## The three speeds
|
||||||
|
|
||||||
|
| What | ID | Bytes | Decode | Status |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| **Engine RPM** | `0x0AA` `RPM_ENG` | bits 32–47 | `(D4 + D5×256) × 0.25` 1/min | ✅ **verified** — 679–684 at idle |
|
||||||
|
| **Turbine (input)** | `0x1A2` `RPM_GRB_TURB` | bits 0–15 | `(D0 + D1×256) × 0.125 + 6` 1/min | ✅ **verified** — see below |
|
||||||
|
| **Output shaft** | `0x0BA` bits 20–39 | D3/D4 | ⚠ **uncalibrated** | 🔬 **hypothesis** — see below |
|
||||||
|
|
||||||
|
`0x1A2` is DLC 4 @ 20 ms; `0x0AA` is DLC 8 @ 10 ms; `0x0BA` is DLC 8 @ 20 ms. All three are fast — good for a control loop.
|
||||||
|
|
||||||
|
> [!note] Do not use `GRDT_REIN` (`0x0BA` bits 8–19)
|
||||||
|
> The repo documents it as a gearbox speed (×0.125 1/min), but on **our** bus it reads `0xFFE`/`0xFFF` — the invalid marker — across every frame of both captures. Not populated here. `0x1A2` is the turbine source that works. (verified, 2026-07-17)
|
||||||
|
|
||||||
|
## Turbine speed = physical proof of engagement ✅
|
||||||
|
|
||||||
|
The single most useful thing this ingest produced. Correlating `0x1A2` against lever position across the 2026-07-15 capture (engine idling ~680 rpm, vehicle stationary on its brakes):
|
||||||
|
|
||||||
|
| Lever | Frames | Turbine min | **avg** | max |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| P | 1370 | 6 | **634** | 652 |
|
||||||
|
| N | 95 | 6 | **628** | 649 |
|
||||||
|
| **D** | 458 | 6 | **70** | 652 |
|
||||||
|
| **R** | 2 | 6 | **~0** | 6 |
|
||||||
|
|
||||||
|
(verified, 2026-07-17 — derived from `raw/can-capture-2026-07-15-gearshift.csv`)
|
||||||
|
|
||||||
|
This is textbook torque-converter behaviour and it is unambiguous:
|
||||||
|
|
||||||
|
- **P/N** — nothing is engaged, so the turbine free-spins at roughly engine speed (~630 vs ~680; the gap is normal converter slip).
|
||||||
|
- **D/R** — the box engages, the output shaft is held by the brakes, and the turbine **stalls to near zero**.
|
||||||
|
|
||||||
|
The D column's `max` of 652 and the wide min/max spread are just the transition frames as the lever passed through — the *average* tells the story.
|
||||||
|
|
||||||
|
### Why this beats every status byte
|
||||||
|
|
||||||
|
`ST_GR_GRB` (`0x0BA`) tells you what the gearbox **intends**. `0x1D2` D0 tells you what the driver **selected**. Neither is proof that anything mechanically happened. **Turbine speed is a physical measurement of load** — the box can't fake it.
|
||||||
|
|
||||||
|
**The engagement test** is the *ratio* of turbine to engine speed, not the absolute value:
|
||||||
|
|
||||||
|
```
|
||||||
|
ratio = RPM_GRB_TURB (0x1A2) / RPM_ENG (0x0AA)
|
||||||
|
|
||||||
|
ratio ≈ 1.0 → turbine free-spinning → NOT engaged (normal in P/N)
|
||||||
|
ratio ≈ 0 → turbine stalled/loaded → engaged, output held
|
||||||
|
0 < ratio < 1 → engaged and moving (converter slip under load)
|
||||||
|
```
|
||||||
|
|
||||||
|
This directly answers the UX problem that motivated the search — *"lever says R but the car isn't moving."* With the vehicle on the ground and the brake released:
|
||||||
|
|
||||||
|
- lever = R, **ratio ≈ 0 or climbing from 0** → box engaged, it's working
|
||||||
|
- lever = R, **ratio ≈ 1.0** → **the box never took the request** ⚠ this is the fault to surface
|
||||||
|
|
||||||
|
> [!warning] The ratio is only meaningful under known output conditions
|
||||||
|
> On a **lift with the wheels free**, an engaged box spins the wheels up until the turbine approaches engine speed again — so `ratio ≈ 1.0` is normal there and does **not** indicate a fault. The test is only valid when the output is loaded (on the ground). Any firmware use of this must gate on output-shaft speed ≈ 0, or the display will cry wolf every time the car is jacked up.
|
||||||
|
>
|
||||||
|
> **Second exception: the lockup clutch.** `ST_CCLT` (`0x0BA` D0 bits 6–7) mechanically bolts the turbine to the impeller at cruise to eliminate slip — when it's closed, turbine = engine speed *exactly*. So at road speed, ratio ≈ 1.0 means "locked up", not "not engaged". Seen live in the higher gears of the 2026-07-17 capture (422 frames reading "controlling"). Any moving-vehicle use of the ratio must read `ST_CCLT` first. The standstill test is unaffected — the clutch is open at rest.
|
||||||
|
|
||||||
|
## Output shaft speed — the cruise-control variable 🔬
|
||||||
|
|
||||||
|
`0x0BA` bits **20–39** (D2 high nibble, D3, D4) are a **gap in the published source** — the [[e65-reverse-engineering-repo]] table jumps from `GRDT_REIN` at bit 19 straight to the checksum at bit 40. Its own E65 example leaves those bytes zero. **Our bus populates them.**
|
||||||
|
|
||||||
|
Evidence that they are an output-shaft/road-speed field (verified, 2026-07-17):
|
||||||
|
|
||||||
|
| Condition | D3 | D4 | Turbine | Interpretation |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| P — stationary | `00` | `00` | ~634 | output stopped |
|
||||||
|
| N — stationary | `00` | `00` | ~628 | output stopped |
|
||||||
|
| **D — stationary, brakes on** | `00` | `00` | **~70** | engaged but **output held** → zero |
|
||||||
|
| **R — wheels lifted & turning** | `A8` | `01` | — | **output turning → non-zero** |
|
||||||
|
|
||||||
|
The field is zero in *every* stationary frame **including engaged-in-D**, and non-zero the moment the wheels actually rotate. That decouples it from engine, turbine, and gear state — it tracks the **output shaft** and nothing else. Which is exactly the definition of road speed, minus a diff ratio and a tyre circumference.
|
||||||
|
|
||||||
|
### The drive capture — identification settled, scaling narrowed
|
||||||
|
|
||||||
|
The 2026-07-17 drive capture ([[can-capture-2026-07-17-drive]]) put the vehicle in motion through all six gears. Output vs `ST_GR_GRB` gear:
|
||||||
|
|
||||||
|
| Gear | Frames | Min | Avg | Max |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| 1 | 189 | 0 | 1139 | 1728 |
|
||||||
|
| 2 | 238 | 40 | 2911 | 4832 |
|
||||||
|
| 3 | 77 | 1640 | 6133 | 7888 |
|
||||||
|
| 4 | 93 | 2192 | 9152 | 11464 |
|
||||||
|
| 5 | 127 | 5160 | 12991 | 17272 |
|
||||||
|
| 6 | 94 | 13640 | 16702 | 18312 |
|
||||||
|
|
||||||
|
Monotonic with gear, overlapping at shift points, starting at zero. **The identification as output shaft speed is settled.** (verified, 2026-07-17)
|
||||||
|
|
||||||
|
### 🔬 Scaling: ×0.125 — strong hypothesis, not measured
|
||||||
|
|
||||||
|
Taking each gear's max output as its upshift instant and multiplying by the 6HP26 ratio recovers the engine speed at that shift:
|
||||||
|
|
||||||
|
| Gear | ×0.125 → rpm | ratio | **implied engine rpm** |
|
||||||
|
|---|---|---|---|
|
||||||
|
| 1 | 216 | 4.171 | **901** |
|
||||||
|
| 2 | 604 | 2.340 | **1413** |
|
||||||
|
| 3 | 986 | 1.521 | **1500** |
|
||||||
|
| 4 | 1433 | 1.143 | **1638** |
|
||||||
|
| 5 | 2159 | 0.867 | **1872** |
|
||||||
|
|
||||||
|
A smooth, gently-rising upshift schedule — textbook M57N at light throttle. Five independent ratios landing on a coherent curve is hard to get by chance. The alternative (raw = rpm) implies upshifts at **7,200–15,000 rpm** against a ~4,500 redline — ruled out.
|
||||||
|
|
||||||
|
The gearbox is a confirmed **6HP26X** (user, 2026-07-17), so the ratio table is right. The one assumption left standing is **max-output-per-gear = upshift point**.
|
||||||
|
|
||||||
|
### ⚠ Direct reference reading contradicts ×0.125
|
||||||
|
|
||||||
|
The Launch diagnostic tool reads the EGS output speed directly in rpm (it polls the box, so this is the EGS's own value in engineering units). First simultaneous-ish reading (user, 2026-07-17):
|
||||||
|
|
||||||
|
| Launch output speed | our raw `0x0BA` D3/D4 | implied factor |
|
||||||
|
|---|---|---|
|
||||||
|
| **128 rpm** | **1192** | **0.107** |
|
||||||
|
|
||||||
|
`0x125` would predict 1192 × 0.125 = **149 rpm**; the Launch showed **128**. That's 16 % off — too far to be rounding. **So ×0.125 is probably wrong**, and the true factor is nearer **0.107**. This is exactly the failure mode flagged above: the upshift-schedule test couldn't distinguish 0.107 from 0.125 (both produce a plausible-looking curve), so it never really pinned the factor — it only ruled out raw-as-rpm.
|
||||||
|
|
||||||
|
> [!warning] One eyeballed point, not a calibration
|
||||||
|
> Reading 128 on one tool and 1192 on another at the same instant, on a spinning driveline, is hard to do precisely — the two may be a second apart at slightly different speed. So this **downgrades ×0.125** but doesn't yet promote 0.107. It also can't see an offset (both go through zero, which we know, so a pure factor should hold).
|
||||||
|
>
|
||||||
|
> **The driveline screen now shows this as "OUTPUT (~rpm)"** using the provisional 0.107 factor — the `~` and the wiki caveat are how we keep an unlocked scaling from reading as exact. Firmware: `can_output_shaft_rpm()` in `automotive_data.h`. **Turbine speed (`0x1A2`) was removed from the display** — it's a diagnostic (engagement proof), not a driver number — but is still decoded.
|
||||||
|
|
||||||
|
### Finishing it (now easier — the Launch IS the reference)
|
||||||
|
|
||||||
|
The Launch gives road/output speed directly in rpm, so we no longer need the turbine-ratio inference at all — just **several simultaneous `(raw, Launch-rpm)` pairs across a speed sweep**, then a linear fit. Slope = the factor, intercept should be ~0. Three or four points settle it far better than one.
|
||||||
|
|
||||||
|
Still worth logging **`0x1A2` alongside `0x0BA`** in the same capture: turbine ÷ output cross-checks the box identity against the 6HP26 table independently, and `0x0AA` gives engine rpm. The 2026-07-17 drive capture was filtered to `0x0BA`/`0x1D2` only, which is why the ratio method couldn't run.
|
||||||
|
|
||||||
|
`docs/6HP26.pdf` in the source repo would confirm the ratios from a document rather than recollection. → [[open-questions]] wishlist.
|
||||||
|
|
||||||
|
### Raw counts → km/h
|
||||||
|
|
||||||
|
Still needs numbers nobody has written down. The 6HP26**X** measures its output shaft **upstream of the transfer case**, so the conversion depends on the swap's driveline:
|
||||||
|
|
||||||
|
- BMW transfer case retained → rear output ~1:1, math unaffected
|
||||||
|
- Transfer case deleted, straight to the Patrol driveline → also fine
|
||||||
|
- A Patrol transfer case in the path → its ratio enters the calculation **and changes with high/low range**, making road speed range-dependent
|
||||||
|
|
||||||
|
Plus the Patrol's final drive ratio and tyre size. → [[nissan-patrol-swap]], [[open-questions]] #10
|
||||||
|
|
||||||
|
## Cruise control: what the bus already gives us
|
||||||
|
|
||||||
|
The DME publishes its own cruise/ACC regulation state. `0x0AA` `ST_CLCTR_V` (bits 52–55):
|
||||||
|
|
||||||
|
| Value | Meaning |
|
||||||
|
|---|---|
|
||||||
|
| `0x0` | ACC regulation, pedal not pressed |
|
||||||
|
| `0x1` | ACC regulation, pedal pressed |
|
||||||
|
| `0x4` | **CC regulation, retard** |
|
||||||
|
| `0x5` | **CC regulation, constant speed** |
|
||||||
|
| `0x6` | **CC regulation, recall** |
|
||||||
|
| `0x7` | **CC regulation, speed up** |
|
||||||
|
| `0x8` | Pedal not pressed |
|
||||||
|
| `0x9` | Pedal pressed |
|
||||||
|
| `0xA` | Pedal transgress |
|
||||||
|
| `0xB` | Pedal kickdown |
|
||||||
|
|
||||||
|
(source: [[e65-reverse-engineering-repo]]. Our capture reads `0x0` on all 3835 frames — pedal untouched, consistent with a stationary idling test. (verified, 2026-07-17))
|
||||||
|
|
||||||
|
Also available: **`ANG_ACPD`** (`0x0AA` bits 24–31, ×0.39063 %) — accelerator pedal position, `0x00` unpressed → `0xFF` floored.
|
||||||
|
|
||||||
|
> [!note] Torque decode — user's spreadsheet formula confirmed
|
||||||
|
> **Engine torque is on `0x0A8` (`TORQ_AVL`, available/delivered torque)**, bits 12–23, signed ×0.5 Nm — user-identified. `0x0AA` carries `TORQ_DVCH` (driver *demand*) in the same bit layout, so both read ~27 Nm at idle and are indistinguishable there, but they diverge under load; the delivered value (`0x0A8`) is the one to display.
|
||||||
|
> The user's Excel formula `(D2*256 + D1)/32` is algebraically identical to `bits12-23 × 0.5` — `(D2<<8|D1)/32 == ((D2<<4)|(D1>>4))×0.5`. Verified against the repo's `0x0A8` worked example (`C7 08 03 …` → 24 Nm). **One caveat**: the low nibble of D1 is `ALIV_TORQ_1_DME` (the alive counter) — the repo example literally shows `ALIV`=8 there — not torque, so the full-16-bit read sweeps in ~±0.5 Nm of jitter. The firmware masks it and sign-extends the 12-bit field (so overrun/braking reads negative). ~27–28 Nm at warm idle on our capture. (verified, 2026-07-17)
|
||||||
|
|
||||||
|
### Why a PoC is architecturally plausible
|
||||||
|
|
||||||
|
The E65 powertrain is built around **external modules requesting torque from the DME** — that is precisely what `0x0B5` ("Torque Request EGS") is, and what `0x0BA`'s repo title ("Torque Request ACC") points at. The DME arbitrates requests from the EGS, from ACC, and from itself; `ST_CLCTR_V` is it *reporting which regulator currently has the ball*. So the plumbing for "another module asks the engine for torque" is native to this bus, not something we'd have to invent.
|
||||||
|
|
||||||
|
A PoC would then need:
|
||||||
|
|
||||||
|
- **Feedback**: output shaft speed (`0x0BA` D3/D4) — *the only road-speed source we have* ⬅ the reason this page exists
|
||||||
|
- **Actual/limits**: `RPM_ENG`, `ANG_ACPD` (driver override — pedal press must instantly disengage)
|
||||||
|
- **Engagement sanity**: turbine ratio, so it can't regulate against a box in N
|
||||||
|
- **Actuation**: a torque-request frame the DME accepts
|
||||||
|
|
||||||
|
> [!danger] Actuation is a different category of risk from everything so far
|
||||||
|
> Every capability in this project to date is **read-only**. A cruise-control PoC **transmits frames that command engine torque**. Getting the ID, scaling, checksum, or alive counter wrong doesn't produce a bad reading — it produces **unintended acceleration**. Additional hazards specific to our situation:
|
||||||
|
> - The board already runs `TWAI_MODE_NORMAL` and ACKs the bus, so transmit is one function call away — there is **no accidental-write safety margin** left. → [[can-bus-integration]]
|
||||||
|
> - `0x0B5`/`0x0BA` carry **checksums and alive counters**; the DME rejects (and may fault on) malformed requests. Both algorithms are unknown to us.
|
||||||
|
> - The swap has **no DSC and no brake-pedal switch on the bus** we've found — so the usual "brake cancels cruise" interlock has no source. A PoC would have no independent way to know the driver is braking.
|
||||||
|
>
|
||||||
|
> Treat this as a **bench/lifted-wheels-only** exercise until every one of those is resolved. Nothing here should be enabled on a moving vehicle on the strength of a wiki page.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[e65-reverse-engineering-repo]] · [[can-id-candidates]] · [[gear-box-can-revealings]] · [[can-bus-integration]] · [[nissan-patrol-swap]] · [[open-questions]]
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: entity
|
type: entity
|
||||||
tags: [hardware, waveshare, display]
|
tags: [hardware, waveshare, display]
|
||||||
updated: 2026-07-15
|
updated: 2026-07-16
|
||||||
---
|
---
|
||||||
|
|
||||||
# Waveshare ESP32-S3-Touch-LCD-5B
|
# Waveshare ESP32-S3-Touch-LCD-5B
|
||||||
@@ -28,8 +28,10 @@ Controller A of the [[dual-controller-architecture]] — the main in-cabin displ
|
|||||||
## CAN interface (source: waveshare-wiki)
|
## CAN interface (source: waveshare-wiki)
|
||||||
|
|
||||||
- **Onboard TJA1051T/3/1J transceiver**, CAN 2.0, on a 3.5 mm terminal block — wire CAN-H/L straight in. ✅ resolves the transceiver question
|
- **Onboard TJA1051T/3/1J transceiver**, CAN 2.0, on a 3.5 mm terminal block — wire CAN-H/L straight in. ✅ resolves the transceiver question
|
||||||
|
- **Non-isolated** — its ground must be common with the vehicle. Simplest: power the board from vehicle 12 V (the 7–36 V input's negative *is* the CAN reference). Grounding-only + USB power also works, but keep the logging laptop **on battery** to avoid a mains-earth ↔ chassis ground loop.
|
||||||
- **120 Ω termination switch, OFF by default — leave it off** when tapping an existing vehicle bus (the bus is already terminated at both ends).
|
- **120 Ω termination switch, OFF by default — leave it off** when tapping an existing vehicle bus (the bus is already terminated at both ends).
|
||||||
- Firmware drives it via TWAI on GPIO 15 TX / 16 RX, 500 kbps, LISTEN_ONLY `(repo)`.
|
- Firmware drives it via TWAI on GPIO 15 TX / 16 RX, 500 kbps, **`TWAI_MODE_NORMAL`** `(repo)` — it **ACKs the bus** (active participant), *not* LISTEN_ONLY as older docs claimed. Deliberate, to stop transmitters retry-flooding. → [[can-bus-integration]]
|
||||||
|
- **Raw CAN logger** `(repo, 2026-07-15)`: streams every frame as `CANRAW,...` over native USB-CDC (`Serial` remapped to USB-CDC, ~1 MB/s, so it keeps up with the ~486 frame/s bus). First capture: [[can-capture-2026-07-15]].
|
||||||
|
|
||||||
## Other interfaces
|
## Other interfaces
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +1,32 @@
|
|||||||
---
|
---
|
||||||
type: entity
|
type: entity
|
||||||
tags: [vehicle, swap, project-context]
|
tags: [vehicle, swap, project-context]
|
||||||
updated: 2026-07-15
|
updated: 2026-07-17
|
||||||
---
|
---
|
||||||
|
|
||||||
# Nissan Patrol M57N Swap
|
# Nissan Patrol M57N Swap
|
||||||
|
|
||||||
The target vehicle (verified — user, 2026-07-15): a **Nissan Patrol** receiving the [[bmw-m57n-engine]] from an E60/E65 donor, with the BMW automatic + EGS wired into the CAN bus. The display system ([[dual-controller-architecture]]) replaces/augments instrumentation for the swapped drivetrain.
|
The target vehicle (verified — user, 2026-07-15): a **Nissan Patrol** receiving the [[bmw-m57n-engine]] from an **E60/E61** donor, with the BMW automatic + EGS wired into the CAN bus. The display system ([[dual-controller-architecture]]) replaces/augments instrumentation for the swapped drivetrain.
|
||||||
|
|
||||||
|
## Drivetrain
|
||||||
|
|
||||||
|
- Gearbox: **ZF 6HP26X** (verified — user, 2026-07-17). The "X" is the xDrive output variant — same internal gearset as the 6HP26, different output housing/shaft to drive a transfer case. Ratios: 4.171 / 2.340 / 1.521 / 1.143 / 0.867 / 0.691.
|
||||||
|
- **This dates the donor**: M57N + xDrive means **E60/E61, not E65** — the 7-series never took that combination. → [[open-questions]] #2
|
||||||
|
|
||||||
|
> [!question] Was the BMW transfer case retained?
|
||||||
|
> Open, and it blocks road-speed display. The EGS measures the gearbox output shaft **upstream of the transfer case**, so the raw→km/h conversion depends on what sits downstream:
|
||||||
|
> - **BMW case retained** → its rear output is ~1:1, math unaffected
|
||||||
|
> - **Deleted, coupled straight to the Patrol driveline** → also fine
|
||||||
|
> - **A Patrol transfer case in the path** → its ratio enters the calculation, **and changes with high/low range** — road speed would become range-dependent, which the firmware would have to know about
|
||||||
|
>
|
||||||
|
> Also still needed for km/h: the Patrol's **final drive ratio** and **tyre size**. → [[driveline-speed-signals]], [[open-questions]] #10/#11
|
||||||
|
|
||||||
## Why this matters for research
|
## Why this matters for research
|
||||||
|
|
||||||
- The M57-into-Patrol swap is popular (especially in Australia and the Middle East), so swap-community forums likely contain solved CAN-ID lists and gauge projects for exactly this drivetrain. `(unverified)` → [[can-bus-integration]]
|
- The M57-into-Patrol swap is popular (especially in Australia and the Middle East), so swap-community forums likely contain solved CAN-ID lists and gauge projects for exactly this drivetrain. `(unverified)` → [[can-bus-integration]]
|
||||||
- The bus the display taps is essentially a **BMW island in a Nissan vehicle**: only the modules the swap harness retains (DDE, EGS, possibly others) are broadcasting. Nissan-side electronics are not on this bus.
|
- The bus the display taps is essentially a **BMW island in a Nissan vehicle**: only the modules the swap harness retains (DDE, EGS, possibly others) are broadcasting. Nissan-side electronics are not on this bus. **Confirmed by absence**: no DSC/CAS traffic appears, which is why there is no wheel-speed message and why the gearbox output shaft is our only road-speed source. → [[driveline-speed-signals]]
|
||||||
- Patrol generation, swap-harness maker (or DIY), and which BMW modules were retained are still unknown → [[open-questions]].
|
- Patrol generation, swap-harness maker (or DIY), and which BMW modules were retained are still unknown → [[open-questions]].
|
||||||
|
|
||||||
## Related
|
## Related
|
||||||
|
|
||||||
[[bmw-m57n-engine]] · [[can-bus-integration]] · [[open-questions]]
|
[[bmw-m57n-engine]] · [[driveline-speed-signals]] · [[can-capture-2026-07-17-drive]] · [[can-bus-integration]] · [[open-questions]]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
---
|
---
|
||||||
type: synthesis
|
type: synthesis
|
||||||
tags: [meta, todo]
|
tags: [meta, todo]
|
||||||
updated: 2026-07-15
|
updated: 2026-07-17
|
||||||
---
|
---
|
||||||
|
|
||||||
# Open Questions
|
# Open Questions
|
||||||
@@ -10,11 +10,21 @@ The research frontier. Answering any of these should trigger updates across the
|
|||||||
|
|
||||||
## Blocking
|
## Blocking
|
||||||
|
|
||||||
1. **What are the real CAN IDs for the E60/E65-generation M57N data we want?** The firmware's current map is placeholder-quality — two IDs aren't even valid 11-bit identifiers. Needs web research (in progress 2026-07-15) + a live bus capture to verify. → [[can-bus-integration]]
|
*(Nothing is blocking as of 2026-07-17 — the CAN map is decoded end-to-end. See #8 for the one live calibration left.)*
|
||||||
|
|
||||||
|
## Active
|
||||||
|
|
||||||
|
8. **What is the scaling of `0x0BA` D3/D4 (output shaft speed)?** *Identification verified; factor still open and revised 2026-07-17.* The field is confirmed output shaft speed (rises monotonically 1st→6th, zero whenever the output is held). The factor is **not** settled: the upshift-schedule test suggested ×0.125, but a **direct Launch reference (128 rpm @ raw 1192) contradicts it** — that implies **~0.107** (0.125 would predict 149 rpm). One eyeballed cross-tool point isn't a calibration, so nothing is adopted yet. **Closing it is now easy**: the Launch reads output speed directly in rpm, so log several simultaneous `(raw, Launch-rpm)` pairs across a speed sweep and fit a line (slope = factor, intercept ≈ 0). Log `0x1A2` too for an independent box-identity cross-check. Still the project's only road-speed signal (no DSC on this bus). → [[driveline-speed-signals]]
|
||||||
|
|
||||||
|
11. **Was the BMW transfer case retained, and what's downstream?** The 6HP26**X** measures its output shaft *upstream* of the transfer case, so raw counts → km/h depends on the path: BMW case retained (rear output ~1:1, math unaffected) / deleted and coupled straight to the Patrol driveline (also fine) / a Patrol transfer case in the path (its ratio enters the calculation **and changes with high/low range**, making road speed range-dependent). → [[nissan-patrol-swap]]
|
||||||
|
|
||||||
|
9. **Is a cruise-control PoC worth pursuing, and under what safety envelope?** The bus architecture supports it natively (the DME arbitrates torque requests from the EGS and ACC; `ST_CLCTR_V` reports which regulator has control). But actuation means **transmitting frames that command engine torque**, with unknown checksum/alive-counter algorithms and **no brake-pedal signal on this bus** to build the standard cancel interlock from. Design decision, not a research question. → [[driveline-speed-signals]]
|
||||||
|
|
||||||
|
10. **What are the Patrol's final drive ratio and tyre size?** Needed to turn output-shaft rpm into road speed. Swap-specific — not in any donor documentation. → [[nissan-patrol-swap]]
|
||||||
|
|
||||||
## Project context
|
## Project context
|
||||||
|
|
||||||
2. **Exact donor model year / DDE version and EGS variant?** Chassis generation is known (E60/E65); the precise ECU versions would narrow the matrix further. → [[bmw-m57n-engine]]
|
2. **Exact donor model year / DDE version and EGS variant?** *Partly answered 2026-07-17.* The gearbox is a **ZF 6HP26X** (user-confirmed) — the X is the xDrive output variant, which means the donor is an **E60/E61, not an E65**: the 7-series never took M57N + xDrive. Remaining: model year and DDE version. → [[bmw-m57n-engine]]
|
||||||
3. **Standalone harness or full donor loom? Which BMW modules were retained?** Affects which modules broadcast on the swap's bus. → [[nissan-patrol-swap]]
|
3. **Standalone harness or full donor loom? Which BMW modules were retained?** Affects which modules broadcast on the swap's bus. → [[nissan-patrol-swap]]
|
||||||
4. **Which Patrol generation, and how is the display being mounted/powered?** → [[nissan-patrol-swap]]
|
4. **Which Patrol generation, and how is the display being mounted/powered?** → [[nissan-patrol-swap]]
|
||||||
|
|
||||||
@@ -22,19 +32,33 @@ The research frontier. Answering any of these should trigger updates across the
|
|||||||
|
|
||||||
5. **Operating temperature 0–65 °C** (source: waveshare-wiki) — outside automotive norms at both ends (sub-zero winter cabins, sun-baked dashboards). Is the mounting location temperature-controlled enough? Any mitigation (mounting away from vents/sun, accepting reduced lifespan)?
|
5. **Operating temperature 0–65 °C** (source: waveshare-wiki) — outside automotive norms at both ends (sub-zero winter cabins, sun-baked dashboards). Is the mounting location temperature-controlled enough? Any mitigation (mounting away from vents/sun, accepting reduced lifespan)?
|
||||||
6. **Transient protection on the 7–36 V input**: the board takes vehicle 12 V directly, but ISO 7637 load-dump spikes can exceed 36 V `(unverified)`. Consider an upstream TVS diode / automotive-rated buck. Also: ignition-switched vs constant power (the isolated digital input could sense ignition).
|
6. **Transient protection on the 7–36 V input**: the board takes vehicle 12 V directly, but ISO 7637 load-dump spikes can exceed 36 V `(unverified)`. Consider an upstream TVS diode / automotive-rated buck. Also: ignition-switched vs constant power (the isolated digital input could sense ignition).
|
||||||
7. **Fault codes**: the UART packet reserves a field for fault codes — DDE fault codes are read via diagnostic protocols (KWP2000/UDS over K-line or CAN), not passively broadcast. Is passive reading even possible? `(unverified)`
|
7. **Fault codes**: the UART packet reserves a field for fault codes — DDE fault codes are read via diagnostic protocols (KWP2000/UDS over K-line or CAN), not passively broadcast. Is passive reading even possible? `(unverified)` — **update 2026-07-17**: the same barrier explains why the Launch scanner shows boost/gearbox data our dump lacks (it polls; nothing broadcasts them). A capture *while the Launch is connected* would record both request and reply frames, handing us the exact bytes to replay. → [[obd-diagnostic-polling]]
|
||||||
|
|
||||||
## Answered
|
## Answered
|
||||||
|
|
||||||
|
- ~~Was the engine actually running during the 2026-07-15 capture?~~ → **Yes** — `0x1D0` `ST_ENGINE_RUN` = 2 ("running") in **397/397 frames** (verified, 2026-07-17). The coolant trace is genuine warm-up data; **the cold-start capture that was blocking #1 is no longer needed.** → [[e65-reverse-engineering-repo]]
|
||||||
|
- ~~Gearbox oil temp offset: 0 or +40?~~ → **Neither — `raw − 40`** (verified two ways, 2026-07-17): the source's worked example, plus our own gearbox-at-31 °C vs coolant-at-37 °C warm-up cross-check. → [[e65-reverse-engineering-repo]]
|
||||||
|
- ~~Battery voltage layout: 12-bit LE ×0.015 or 24-bit BE ×0.001?~~ → **12-bit LE × 0.015** (source: E65 repo worked example `0x3D9`→14.775 V, 2026-07-17).
|
||||||
|
- ~~What is the actual engaged gear number, and does it need a drive capture?~~ → **`0x1D2` D1**, `gear = (D1>>4)−4`. **No drive capture needed** — a per-detent capture sufficed. (verified, 2026-07-17) → [[gear-box-can-revealings]]
|
||||||
|
- ~~What is the manual up-shift (+) value on `0x1D2` D4?~~ → **The question was malformed.** D4 is a persistent *mode* (`0xF0` auto / `0xF1` Sport / `0xF2` Manual), not a shift-event field; `+` and `−` have no distinct codes. (verified, 2026-07-17)
|
||||||
|
- ~~Is engaged **reverse** observable?~~ → **Yes, but not on `0x1D2`** (D1 stays `0x0F` in R, moving or stationary). Use **`0x0BA` `ST_GR_GRB` = 2**. For physical proof of engagement, use turbine speed. (verified, 2026-07-17) → [[driveline-speed-signals]]
|
||||||
|
- ~~Are `0x0BA` `ST_GR_GRB` values 6–A really 2nd–6th?~~ → **Yes, all observed directly** in the drive capture. `0x0BA` D0's low nibble is a **complete gear source on its own** (P/R/N + 1st–6th, reverse included). (verified, 2026-07-17) → [[can-capture-2026-07-17-drive]]
|
||||||
|
- ~~Is boost passively broadcast?~~ → **No.** `0x1D0` `AIP_ENG` is barometric (caps at 1108 hPa vs ~2500 needed). Diagnostic polling only. (2026-07-17)
|
||||||
|
|
||||||
- ~~Which donor vehicle?~~ → **E60/E65 (2003+)** (verified — user, 2026-07-15) → [[bmw-m57n-engine]]
|
- ~~Which donor vehicle?~~ → **E60/E65 (2003+)** (verified — user, 2026-07-15) → [[bmw-m57n-engine]]
|
||||||
- ~~Is the EGS on the bus?~~ → **Yes — BMW auto with EGS wired in**; gearbox temp and gear position have a real source. (verified — user, 2026-07-15)
|
- ~~Is the EGS on the bus?~~ → **Yes — BMW auto with EGS wired in**; gearbox temp and gear position have a real source. (verified — user, 2026-07-15)
|
||||||
- ~~Is the target a Nissan Patrol?~~ → **Yes.** (verified — user, 2026-07-15) → [[nissan-patrol-swap]]
|
- ~~Is the target a Nissan Patrol?~~ → **Yes.** (verified — user, 2026-07-15) → [[nissan-patrol-swap]]
|
||||||
- ~~CAN transceiver?~~ → **Onboard TJA1051T/3/1J** on a terminal block; leave the 120 Ω termination switch OFF when tapping the vehicle bus. (source: waveshare-wiki, 2026-07-15) → [[esp32-s3-touch-lcd-5b]]
|
- ~~CAN transceiver?~~ → **Onboard TJA1051T/3/1J** on a terminal block; leave the 120 Ω termination switch OFF when tapping the vehicle bus. (source: waveshare-wiki, 2026-07-15) → [[esp32-s3-touch-lcd-5b]]
|
||||||
|
- ~~Does passive-ish listening actually work on this bus?~~ → **Yes** — first live capture pulled 15 IDs cleanly at ~486 frame/s (verified, 2026-07-15). Note the firmware runs `TWAI_MODE_NORMAL` (ACKs), not LISTEN_ONLY. → [[can-capture-2026-07-15]]
|
||||||
|
- ~~How to ground the board to the vehicle?~~ → TJA1051 is **non-isolated**; share ground with the vehicle (power from 12 V, or ground-wire + laptop on battery to avoid a ground loop). (verified, 2026-07-15) → [[esp32-s3-touch-lcd-5b]]
|
||||||
- ~~12 V → 5 V power conversion?~~ → **Not needed**: board has a 7–36 V DC wide input. Residual transient concern moved to #6. (source: waveshare-wiki, 2026-07-15)
|
- ~~12 V → 5 V power conversion?~~ → **Not needed**: board has a 7–36 V DC wide input. Residual transient concern moved to #6. (source: waveshare-wiki, 2026-07-15)
|
||||||
|
|
||||||
## Sourcing wishlist
|
## Sourcing wishlist
|
||||||
|
|
||||||
- ~~Waveshare product page~~ ✅ ingested → [[esp32-s3-touch-lcd-5b-waveshare-wiki]]
|
- ~~Waveshare product page~~ ✅ ingested → [[esp32-s3-touch-lcd-5b-waveshare-wiki]]
|
||||||
- Waveshare **schematic PDF** (linked from the product page: `ESP32-S3-Touch-LCD-5-Sch.pdf`) — would confirm CAN GPIO routing and power path
|
- Waveshare **schematic PDF** (linked from the product page: `ESP32-S3-Touch-LCD-5-Sch.pdf`) — would confirm CAN GPIO routing and power path
|
||||||
- A community DBC / CAN-ID list for the donor platform
|
- ~~A community DBC / CAN-ID list for the donor platform~~ ✅ ingested → [[e65-reverse-engineering-repo]]
|
||||||
- A real candump log from the engine running
|
- ~~A real candump log from the engine running~~ ✅ → [[can-capture-2026-07-15]] (engine confirmed running, 2026-07-17)
|
||||||
|
- **`6HP26.pdf`** — sitting in the E65 repo's `docs/`. The ZF 6HP26 manual, very likely our exact gearbox: gear ratios would let us convert output-shaft rpm → road speed and self-check the D3/D4 scaling. → [[driveline-speed-signals]]
|
||||||
|
- **`can_message_list.txt`** (same repo) — full ID → name → sending-module map, 0x00–0xFFF. Not yet mined; useful if the project ever wants non-powertrain data
|
||||||
|
- A capture taken **while the Launch scanner is polling** — would reveal the request/response byte sequences for boost, gearbox temp and DTCs → [[obd-diagnostic-polling]]
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,11 @@
|
|||||||
|
ADDR,LEN,D0,D1,D2,D3,D4,D5,D6,D7,Position
|
||||||
|
0BA,8,3,255,15,0,0,,,239,P
|
||||||
|
0BA,8,2,132,1,0,0,,,207,R
|
||||||
|
0BA,8,1,255,15,0,0,,,223,N
|
||||||
|
0BA,8,5,220,1,0,0,,,207,D
|
||||||
|
0BA,8,5,220,1,0,0,,,207,M/S
|
||||||
|
1D2,6,225,15,255,,240,255,,,P
|
||||||
|
1D2,6,210,15,255,,240,255,,,R
|
||||||
|
1D2,6,180,15,255,,240,255,,,N
|
||||||
|
1D2,6,120,95,255,,240,255,,,D
|
||||||
|
1D2,6,120,95,255,,241,255,,,M/S
|
||||||
|
@@ -0,0 +1,13 @@
|
|||||||
|
PID,LEN,D0,D1,D2,D3,D4,D5,Actual Gear
|
||||||
|
1D2,6,120,95,255,Fluctuation,240,255,Drive 1
|
||||||
|
1D2,6,120,111,255,Fluctuation,240,255,Drive 2
|
||||||
|
1D2,6,120,127,255,Fluctuation,240,255,Drive 3
|
||||||
|
1D2,6,120,143,255,Fluctuation,240,255,Drive 4
|
||||||
|
1D2,6,120,159,255,Fluctuation,240,255,Drive 5
|
||||||
|
1D2,6,120,175,255,Fluctuation,240,255,Drive 6
|
||||||
|
1D2,6,120,95,255,Fluctuation,241,255,M/S 1
|
||||||
|
1D2,6,120,111,255,Fluctuation,242,255,M/S 2
|
||||||
|
1D2,6,120,127,255,Fluctuation,242,255,M/S 3
|
||||||
|
1D2,6,120,143,255,Fluctuation,242,255,M/S 4
|
||||||
|
1D2,6,120,159,255,Fluctuation,242,255,M/S 5
|
||||||
|
1D2,6,120,175,255,Fluctuation,242,255,M/S 6
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,9 @@
|
|||||||
|
3B4 CAN 8 A5 F3 89 FC FF FF FF FF ........ 15473596 RX0
|
||||||
|
3B4 CAN 8 FF FF 09 FC FF FF FF FF ........ 15473820 RX0
|
||||||
|
3B4 CAN 8 FF FF 09 FC FF FF FF FF ........ 15474335 RX0
|
||||||
|
3B4 CAN 8 FF FF 00 FC FF FF FF FF ........ 15474696 RX0
|
||||||
|
3B4 CAN 8 FF FF 00 FC FF FF FF FF ........ 15479337 RX0
|
||||||
|
3B4 CAN 8 FF FF 00 FC FF FF FF FF ........ 15484332 RX0
|
||||||
|
3B4 CAN 8 FF FF 09 FC FF FF FF FF ........ 15487289 RX0
|
||||||
|
3B4 CAN 8 FF FF 09 FC FF FF FF FF ........ 15489333 RX0
|
||||||
|
3B4 CAN 8 FF FF 09 FC FF FF FF FF ........ 15494327 RX0
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
---
|
||||||
|
type: source
|
||||||
|
tags: [can-bus, capture, verified, e60]
|
||||||
|
updated: 2026-07-16
|
||||||
|
---
|
||||||
|
|
||||||
|
# Live CAN Capture — 2026-07-15 (FIRST REAL BUS DATA)
|
||||||
|
|
||||||
|
First capture off the **actual swap's bus**, taken with the ESP32-S3-Touch-LCD-5B itself (new raw-frame logger, `(repo)`). Two dumps: a ~20 s idle capture and a ~40 s gear-shift capture (`P→R→N→D→S/M→P`, ~5 s per position). Raw dump filed at `raw/can-capture-2026-07-15-gearshift.csv` (20,596 well-formed frames, `CANRAW,<ts_ms>,<id>,<extd>,<dlc>,<hex>` format).
|
||||||
|
|
||||||
|
Bus: 500 kbps, ~486 frames/s. Capture was clean (~1.4 % line-splice loss, filtered out).
|
||||||
|
|
||||||
|
## Headline: the research map is broadly CONFIRMED
|
||||||
|
|
||||||
|
**15 IDs seen live:** `0A8 0A9 0AA 0B5 0BA 1A2 1B6 1D0 1D2 200 332 3B3 3B4 492 498`
|
||||||
|
|
||||||
|
- All four researched signal IDs are **present and live**: `0x1D0`, `0x1D2`, `0x0B5`, `0x3B4` — plus bonus candidates `0x0AA` and `0x0BA`. (verified: present on bus)
|
||||||
|
- The firmware's placeholder IDs (`0x4F`, `0x55`, `0x201`, `0x1001`, `0x101F`) are **completely absent** — confirmed placeholders. (verified: absent)
|
||||||
|
- Researched candidates **NOT seen**: `0x130` (terminal status), `0x304` (gear lever), `0x192`. Either not broadcast by the retained modules, or need a different bus state (ignition/engine). Note for follow-up.
|
||||||
|
|
||||||
|
## Signal-level findings
|
||||||
|
|
||||||
|
| Signal | ID | What the capture shows | Status |
|
||||||
|
|--------|----|------------------------|--------|
|
||||||
|
| Coolant temp | `0x1D0` byte0 | Drifts up `0x55→0x56→0x57→0x58` (−48 → ~37→40 °C). Consistent with a warming coolant sensor. | **Partly verified** — ID + byte + upward drift confirmed; scaling still inferred; needs a cold-start ramp to lock in |
|
||||||
|
| Oil temp | `0x1D0` byte1 | Constant **`0xFF`** the whole capture — reads invalid/unpopulated | ⚠ oil temp NOT present here — the weakest research signal stays unconfirmed |
|
||||||
|
| Gear lever | `0x1D2` byte0 | Took values **`0xB4`, `0x78`, `0xE1`** — these ARE the documented BMW gear codes (N, D, P). Resting value `0xE1` = **P**. **DLC = 6** → E90 dialect. | **Verified: ID + byte0 + encoding.** Not all positions cleanly walked (R `0xD2` and S/M not captured as distinct plateaus) |
|
||||||
|
| Battery volt | `0x3B4` | Present at **~5 s rate** (matches E65 prediction) but payload mostly `0xFF` (`FF FF 00 FC FF FF FF FF`); byte3 = `0xFC`, not the predicted 0x00/0x09 engine flag | ID + rate confirmed; **payload dormant** — needs a powered/engine-running capture |
|
||||||
|
| RPM | `0x0AA` | Present at **~10 ms rate** (matches predicted RPM cadence) | ID + rate consistent; decode unverified (needs a throttle blip) |
|
||||||
|
|
||||||
|
## The 0x1D2 encoding dispute — RESOLVED (mostly)
|
||||||
|
|
||||||
|
The capture settles it: **DLC = 6** (E90-dialect length, not E65's DLC 5), and byte0 carries **whole-byte gear codes matching the documented table** (`0xE1`=P, `0xB4`=N, `0x78`=D seen live). The two sources were the same scheme in different notation, as suspected in [[can-id-candidates]].
|
||||||
|
|
||||||
|
## Open contradiction to resolve
|
||||||
|
|
||||||
|
Coolant (`0x1D0` b0) drifting upward *suggests engine running/warm, but the battery message (`0x3B4`) and oil temp (`0x1D0` b1) are dormant/`0xFF`, which suggests it wasn't. Engine state during this capture was **unconfirmed** (question not answered). A clean **cold-start + idle** capture with confirmed engine state is the next step to promote coolant + battery to fully `(verified)`.
|
||||||
|
|
||||||
|
## Method note
|
||||||
|
|
||||||
|
Gear discovery via a continuous P→R→N→D→S→P sweep was **ambiguous** — timing alignment between the physical shift and the capture window was poor, and slow IDs (`0x1D2` ~4/s) undersample the plateaus. The whole-byte gear-code match is what saved it. **Next time use a differential capture**: hold P (capture ~6 s), hold R (~6 s), diff the steady-state bytes — zero timing ambiguity.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[can-id-candidates]] · [[can-bus-integration]] · [[bmw-m57n-engine]] · [[open-questions]]
|
||||||
@@ -0,0 +1,112 @@
|
|||||||
|
---
|
||||||
|
type: source
|
||||||
|
tags: [can-bus, capture, verified, gear, egs, speed, drive]
|
||||||
|
updated: 2026-07-17
|
||||||
|
---
|
||||||
|
|
||||||
|
# Drive Capture — 2026-07-17 (VERIFIED)
|
||||||
|
|
||||||
|
Raw at `raw/log_20260717_145930.txt` — 1,857 frames over ~34 s, captured with the CANNY 5.3 Pico (tab-separated: ID, "CAN", DLC, data bytes, ASCII, timestamp ms, RX0). Filtered to **`0x0BA` (1,681 frames) and `0x1D2` (176)** only.
|
||||||
|
|
||||||
|
**The first capture with the vehicle actually moving and the box shifting.** It closes the `0x0BA` gear-ladder question outright and produces the first real evidence for the output-shaft scaling.
|
||||||
|
|
||||||
|
## ✅ `ST_GR_GRB` values 6–A — VERIFIED
|
||||||
|
|
||||||
|
The 2026-07-16/17 pages carried `0x0BA` gears 2nd–6th as `(unverified)`, inferred from the parallel `0x1D2` D1 ladder. **All five values now observed directly:**
|
||||||
|
|
||||||
|
| Nibble | Gear | Frames |
|
||||||
|
|---|---|---|
|
||||||
|
| `1` | N | 248 |
|
||||||
|
| `2` | R | 408 |
|
||||||
|
| `3` | P | 207 |
|
||||||
|
| `5` | 1st | 189 |
|
||||||
|
| **`6`** | **2nd** | **238** |
|
||||||
|
| **`7`** | **3rd** | **77** |
|
||||||
|
| **`8`** | **4th** | **93** |
|
||||||
|
| **`9`** | **5th** | **127** |
|
||||||
|
| **`A`** | **6th** | **94** |
|
||||||
|
|
||||||
|
(verified, 2026-07-17)
|
||||||
|
|
||||||
|
**Consequence: `0x0BA` D0's low nibble is a complete gear source on its own** — P, R, N and 1st–6th from one nibble, including the reverse that `0x1D2` D1 cannot express. `0x1D2` remains necessary only for the **lever** (what the driver selected) and the **mode** (`0xF0`/`0xF1`/`0xF2`), which `0x0BA` does not carry.
|
||||||
|
|
||||||
|
Value `4` still never observed. The `0xF`=invalid marker never appeared either.
|
||||||
|
|
||||||
|
## `ST_CCLT` — torque converter lockup clutch, caught live
|
||||||
|
|
||||||
|
`0x0BA` D0 bits 6–7. Across this capture: **1,259 frames = `0` (disengaged), 422 frames = `1` (controlled/slipping)**, the latter clustered in the higher gears — which is exactly when the clutch is supposed to start locking up to kill converter slip at cruise.
|
||||||
|
|
||||||
|
Relevant to the turbine-speed engagement test: **when the clutch is locked, turbine speed = engine speed exactly**, so a ratio ≈ 1.0 at road speed means "locked up", not "not engaged". → [[driveline-speed-signals]]
|
||||||
|
|
||||||
|
## Output shaft (`0x0BA` D3/D4) — behaves as road speed
|
||||||
|
|
||||||
|
Grouped by `ST_GR_GRB`, read as 16-bit Intel:
|
||||||
|
|
||||||
|
| Gear | Frames | Min | Avg | Max |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| 1 | 189 | 0 | 1139 | 1728 |
|
||||||
|
| 2 | 238 | 40 | 2911 | 4832 |
|
||||||
|
| 3 | 77 | 1640 | 6133 | 7888 |
|
||||||
|
| 4 | 93 | 2192 | 9152 | 11464 |
|
||||||
|
| 5 | 127 | 5160 | 12991 | 17272 |
|
||||||
|
| 6 | 94 | 13640 | 16702 | 18312 |
|
||||||
|
|
||||||
|
Monotonic with gear, overlapping across shift points, starting at zero. A vehicle accelerating through the box. Combined with the earlier finding that the field is **zero in every stationary frame including engaged-in-D**, the identification as output shaft speed is settled; only the *scaling* remains open.
|
||||||
|
|
||||||
|
## 🔬 Scaling evidence: ×0.125 (strong hypothesis, not verified)
|
||||||
|
|
||||||
|
Assuming each gear's **max** output is the instant it upshifted, multiplying by the 6HP26 ratio should recover engine speed at that shift:
|
||||||
|
|
||||||
|
| Gear | raw max | ×0.125 → output rpm | 6HP26 ratio | **implied engine rpm** |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| 1 | 1728 | 216 | 4.171 | **901** |
|
||||||
|
| 2 | 4832 | 604 | 2.340 | **1413** |
|
||||||
|
| 3 | 7888 | 986 | 1.521 | **1500** |
|
||||||
|
| 4 | 11464 | 1433 | 1.143 | **1638** |
|
||||||
|
| 5 | 17272 | 2159 | 0.867 | **1872** |
|
||||||
|
| 6 | 18312 | 2289 | 0.691 | *1582 (not an upshift — 6th is top)* |
|
||||||
|
|
||||||
|
A smooth, gently-rising upshift schedule — textbook M57N under light throttle. Five independent gear ratios landing on a coherent curve is not an easy coincidence.
|
||||||
|
|
||||||
|
The alternative (raw = rpm directly) implies upshifts at **7,200 → 15,000 rpm**. The M57N redlines around 4,500. Ruled out.
|
||||||
|
|
||||||
|
> [!warning] Why this is still `(unverified)`
|
||||||
|
> One assumption remains unchecked: **max-output-per-gear = the upshift point**. Plausible while accelerating, but not proven from this log. (The 6HP26 ratio assumption is now **confirmed** — see below.)
|
||||||
|
>
|
||||||
|
> **`0x1A2` was not in this capture.** Turbine ÷ output gives each gear ratio *directly*, with no assumption about shift points, and simultaneously cross-checks the box identity against the ratio table. One capture including `0x1A2` (and `0x0AA`) converts this from inference to measurement. → [[open-questions]] #8
|
||||||
|
|
||||||
|
## ✅ Gearbox identified: ZF **6HP26X**
|
||||||
|
|
||||||
|
User-confirmed 2026-07-17. Two consequences:
|
||||||
|
|
||||||
|
1. **The ratio assumption above holds.** The 6HP26X shares the 6HP26 internal gearset; the "X" is the output end — a different housing and output shaft to drive a transfer case. `(unverified — from LLM prior knowledge; the repo's `docs/6HP26.pdf` would confirm from a document)`
|
||||||
|
2. **The donor is an xDrive chassis** — so **E60/E61, not E65**: the 7-series never took M57N + xDrive. Partly answers [[open-questions]] #2. → [[bmw-m57n-engine]]
|
||||||
|
|
||||||
|
### New question this raises
|
||||||
|
|
||||||
|
The EGS measures the **gearbox output shaft**, which on an X box sits **upstream of the transfer case**. So `0x0BA` D3/D4 is propshaft-*input* speed, and the raw→km/h conversion depends on what's downstream:
|
||||||
|
|
||||||
|
- BMW transfer case retained → its rear output is ~1:1, math unaffected
|
||||||
|
- Transfer case deleted, coupled straight to the Patrol driveline → also fine
|
||||||
|
- A Patrol transfer case in the path → its ratio enters the calculation, **and changes with high/low range**, making road speed range-dependent
|
||||||
|
|
||||||
|
→ [[nissan-patrol-swap]], [[open-questions]] #10
|
||||||
|
|
||||||
|
## `0x1D2` — consistent, plus auto-mode gears
|
||||||
|
|
||||||
|
| D0 | D1 | D4 | Frames | Reading |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| `D2` | `0F` | `F0` | 43 | R — no gear number, as established |
|
||||||
|
| `78` | `5F` | `F0` | 28 | D, 1st |
|
||||||
|
| `E1` | `0F` | `F0` | 23 | P |
|
||||||
|
| `B4` | `0F` | `F0` | 23 | N |
|
||||||
|
| `78` | `6F` | `F0` | 22 | D, 2nd |
|
||||||
|
| `78` | `7F`/`8F`/`9F`/`AF` | `F0` | 11/10/10/6 | D, 3rd–6th |
|
||||||
|
|
||||||
|
Two useful confirmations: the D1 ladder holds **in automatic Drive** (`D4=F0`), where the earlier evidence came only from the manual gate; and R again shows `D1=0F` while moving, so reverse is unnumbered under all conditions, not just at rest.
|
||||||
|
|
||||||
|
Note `0x1D2` D0 = `0xF0` — the unrecognized lever code seen in an earlier discarded log — **does not appear here**. Consistent with it being a transient EGS-not-initialised state rather than a real lever position.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[gear-box-can-revealings]] · [[driveline-speed-signals]] · [[can-id-candidates]] · [[e65-reverse-engineering-repo]] · [[nissan-patrol-swap]] · [[bmw-m57n-engine]]
|
||||||
@@ -0,0 +1,165 @@
|
|||||||
|
---
|
||||||
|
type: source
|
||||||
|
tags: [can-bus, e65, reverse-engineering, dbc, egs, dde, verified]
|
||||||
|
updated: 2026-07-17
|
||||||
|
---
|
||||||
|
|
||||||
|
# HeinrichG-V12/E65_ReverseEngineering (GitHub)
|
||||||
|
|
||||||
|
<https://github.com/HeinrichG-V12/E65_ReverseEngineering>
|
||||||
|
|
||||||
|
Per-ID CAN documentation for the **BMW E65/E66** PT-CAN, written DBC-style (signal name, start bit, length, byte order, factor, offset, unit) with a **worked decode example on every page**. Ingested 2026-07-17. This is the single highest-value source the project has found: it resolved two long-standing disputes, closed an open question, and handed us three signals we didn't know existed.
|
||||||
|
|
||||||
|
Structure: `docs/` holds 39 markdown files named by ID (`0x1D0.md`, `0x0B5.md`, …) plus `can_message_list.txt`/`.xlsx` (full ID → name → sending-module table), `can_error_list.txt`, and **`6HP26.pdf`** — the ZF 6HP26 transmission document, i.e. very likely *our* gearbox. Also `Log1.blf`/`Log2.blf` raw captures.
|
||||||
|
|
||||||
|
> [!warning] Generation/engine caveat
|
||||||
|
> The donor for this repo is an **E65 with a petrol MED 9.2.1 DME** (N73-era V12), not an M57N diesel. Engine-side layouts are therefore cross-engine inferences. **However**: every signal we checked against our own live capture decoded to physically sensible values on the first try (see below), so the EGS/DME message layouts evidently carry across the generation. Treat gearbox/power-management signals as strong, engine-internal ones as good-but-confirm.
|
||||||
|
|
||||||
|
## What it resolved
|
||||||
|
|
||||||
|
### ✅ Gearbox oil temp offset — the dispute is over
|
||||||
|
|
||||||
|
`0x0B5` = **Torque Request EGS**, DLC 8, 10 ms. `TEMP_GRB` at **start bit 56 (byte 7)**, length 8, factor 1, offset 40 — and the repo's own worked example decodes raw `0x43` (67) → **27 °C**. So the physical value is **raw − 40**.
|
||||||
|
|
||||||
|
> [!note] Sign-convention wrinkle
|
||||||
|
> The table literally prints `Offset | 40`, which in strict DBC convention (`phys = raw × factor + offset`) would mean raw **+** 40. The page's worked example computes raw **−** 40. The example wins — and our own data independently confirms it (below). Flagging so nobody "corrects" this back later.
|
||||||
|
|
||||||
|
**Independently confirmed on our bus** (verified, 2026-07-17): during the 2026-07-15 capture, `0x0B5` D7 read `0x47`/`0x48` (71–72) while `0x1D0` D0 showed coolant at 37–40 °C and climbing. raw−40 → gearbox at **31–32 °C**, sitting just behind a warming coolant. That's a correct cold-start picture. The offset-0 reading would put the gearbox at **71 °C while the engine was still at 37 °C** — the transmission warming faster than the engine it's bolted to, which is not a thing.
|
||||||
|
|
||||||
|
Other useful signals on `0x0B5`: `ST_OTMP_GRB` (bits 38–39) = gearbox cooling demand — `0x0`=none, `0x1`=stage 1, `0x2`=stage 2, `0x3`=invalid. **The box's own overheat opinion — a better display warning than thresholding raw temperature.** Also `TORQ_TAR_EGS` (bits 12–23, signed, ×0.5 Nm) and `TORQ_DRAW_GRB` (bits 48–55, Nm).
|
||||||
|
|
||||||
|
### ✅ Battery voltage layout — 12-bit wins
|
||||||
|
|
||||||
|
`0x3B4` = **Power Management Battery Voltage**, DLC 8, 5 s cycle.
|
||||||
|
|
||||||
|
| Signal | Start bit | Len | Factor | Meaning |
|
||||||
|
|---|---|---|---|---|
|
||||||
|
| `U_BT` | 0 | 12 | 0.015 V | Battery voltage (Intel/LE) |
|
||||||
|
| `ST_BTSW` | 12 | 2 | 1 | Battery main switch: `0`=closed, `1`=opening within 5 s, `2`=invalid |
|
||||||
|
| `ENG_ST` | 16 | 4 | 1 | Engine state |
|
||||||
|
| `ST_SWO_KL_30` | 30 | 2 | 1 | `1`=no PM shutdown, `2`=PM shutdown executed, `3`=invalid |
|
||||||
|
| `SDWN_COU_BTSW` | 32 | 8 | 1 | Shutdown counter (s) |
|
||||||
|
|
||||||
|
Worked example: `D9 03 00 53 FE 18 32 08` → `0x3D9` = 985 × 0.015 = **14.775 V**. This settles the [[can-id-candidates]] dispute in favour of **12-bit LE × 0.015**, against the 24-bit BE × 0.001 reading from the E90 DBC. Decode: `((D1 & 0x0F) << 8 | D0) × 0.015`.
|
||||||
|
|
||||||
|
### ✅ Engine-run state — open question closed
|
||||||
|
|
||||||
|
> [!note] Ignition state, found on `0x3B4` byte 2 (2026-07-17)
|
||||||
|
> Separately from engine-run: `0x3B4` byte 2 low nibble tracks **ignition** — `0x00`=on, `0x09`=off (inverted, and unmoved by the engine starting). Both this repo (`ST_ENGINE_RUN`) and the E60 VFL sheet (engine flag, `0x09`=running) mislabel it — wrong signal *and* wrong polarity for our bus. It restores ignition sensing that was thought lost with CAS/`0x130` absent from the swap. Despite `0x3B4`'s nominal 5 s cycle, it transmits this nibble **on-change** — the flip is instant when the key toggles (user-verified). Drives the driveline screen's ignition-off reset. → [[driveline-speed-signals]]
|
||||||
|
|
||||||
|
`0x1D0` carries `ST_ENGINE_RUN` at **bits 20–21** (byte 2): `0x0`=off, `0x1`=starting, `0x2`=**running**, `0x3`=invalid.
|
||||||
|
|
||||||
|
Checked across our capture: **`ST_ENGINE_RUN` = 2 in 397 of 397 frames** (verified, 2026-07-17). The engine was definitively running during the 2026-07-15 session, so its coolant trace is genuine warm-up data. This retires the "engine state unconfirmed" caveat that was blocking [[open-questions]] #1.
|
||||||
|
|
||||||
|
## `0x1D0` Engine Data (DLC 8, 100 ms) — full table
|
||||||
|
|
||||||
|
| Signal | Start bit | Len | Factor | Offset | Unit |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| `TEMP_ENG` | 0 | 8 | 1 | −48 | °C |
|
||||||
|
| `TEMP_EOI` | 8 | 8 | 1 | −48 | °C |
|
||||||
|
| `ALIV_COUNT_DME` | 16 | 4 | 1 | 0 | — |
|
||||||
|
| `ST_ENGINE_RUN` | 20 | 2 | 1 | 0 | — |
|
||||||
|
| `ST_SW_WAUP` | 22 | 2 | 1 | 0 | — |
|
||||||
|
| `AIP_ENG` | 24 | 8 | 2 | 598 | hPa |
|
||||||
|
| `IJV_FU` | 32 | 16 | 1 | 0 | µl |
|
||||||
|
| `CTL_SLCK` | 48 | 2 | 1 | 0 | — |
|
||||||
|
| `RPM_IDLE_TARGET` | 56 | 8 | 5 | 0 | 1/min |
|
||||||
|
|
||||||
|
`ST_SW_WAUP`: `0`=warming up, `1`=engine warm, `2`=EGS forced switching active, `3`=invalid.
|
||||||
|
`CTL_SLCK`: `0`=not allowed, `1`=no shiftlock requirement, `2`=shiftlock required, `3`=invalid.
|
||||||
|
|
||||||
|
Worked example `5D 3C 66 B7 CE 3A 8D 8C`: coolant 93−48=**45 °C**; oil 60−48=**12 °C**; air 183×2+598=**964 hPa**; fuel injection `0x3ACE`=**15054 µl**; idle target 140×5=**700 rpm**.
|
||||||
|
|
||||||
|
- **Coolant `−48` confirmed** — this is now the third independent source, plus our own live trace.
|
||||||
|
- **Oil temp = D1, also −48.** Ours reads `0xFF` → the sensor is genuinely unpopulated on this M57N, not a decode error. (verified, 2026-07-15)
|
||||||
|
- **`AIP_ENG` is NOT boost.** 8 bits × 2 + 598 caps at **1108 hPa**; a boosting M57N reaches ~2500 hPa absolute. The range 598–1108 hPa is barometric/altitude. Manifold boost is **not** broadcast — consistent with the finding that the Launch scanner must poll for it. → [[obd-diagnostic-polling]]
|
||||||
|
- `IJV_FU` (fuel injection quantity, µl) is a bonus the project never asked for but could display.
|
||||||
|
|
||||||
|
## `0x0AA` Torque 3 (DLC 8, 10 ms) — DME
|
||||||
|
|
||||||
|
| Signal | Start bit | Len | Factor | Unit | Meaning |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| `CHKSM_TORQ_3_DME` | 0 | 8 | 1 | — | Checksum |
|
||||||
|
| `ALIV_TORQ_3_DME` | 8 | 4 | 1 | — | Alive counter |
|
||||||
|
| `TORQ_DVCH` | 12 | 12 | 0.5 | Nm | Driver-demand torque (signed) |
|
||||||
|
| `ANG_ACPD` | 24 | 8 | 0.39063 | % | **Accelerator pedal position** (`0x00`=unpressed, `0xFF`=floored) |
|
||||||
|
| `RPM_ENG` | 32 | 16 | 0.25 | 1/min | **Engine RPM** |
|
||||||
|
| `RPM_ENG_ERR` | 48 | 2 | 1 | — | `0`=clear, `1`=speed sensor defective, `3`=invalid |
|
||||||
|
| `ST_IDLG_ENG` | 50 | 2 | 1 | — | `0`=idle, `1`=not idle, `3`=invalid |
|
||||||
|
| `ST_CLCTR_V` | 52 | 4 | 1 | — | **Cruise/pedal state** — see [[driveline-speed-signals]] |
|
||||||
|
| `RQAM_FU` | 56 | 8 | 1 | l/h | Fuel rate |
|
||||||
|
|
||||||
|
**RPM factor is 0.25, not the ÷4-on-bytes-4-5 guess in [[can-id-candidates]]** — same arithmetic, now with a named field and exact bit positions. Verified on our capture: **679–684 rpm at idle** (verified, 2026-07-17), matching `RPM_IDLE_TARGET` = 700 from `0x1D0`.
|
||||||
|
|
||||||
|
`ST_CLCTR_V` is the headline find here — a **cruise-control state field the DME already publishes**. Full encoding and why it matters: [[driveline-speed-signals]].
|
||||||
|
|
||||||
|
## `0x1A2` (DLC 4, 20 ms) — turbine speed
|
||||||
|
|
||||||
|
| Signal | Start bit | Len | Factor | Offset | Unit |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| `RPM_GRB_TURB` | 0 | 16 | 0.125 | 6 | 1/min |
|
||||||
|
|
||||||
|
Worked example `68 14 00 FF` → `0x1468` = 5224 × 0.125 + 6 = **659 rpm**.
|
||||||
|
|
||||||
|
**The most valuable single discovery in this ingest.** This is the gearbox *input* (turbine) speed, and it turns out to be a direct, physical **engagement** signal. Verified against our capture and written up in full: [[driveline-speed-signals]].
|
||||||
|
|
||||||
|
## `0x0BA` (DLC 8, 20 ms) — gearbox state ⚠ our earlier reading was wrong
|
||||||
|
|
||||||
|
Titled "Torque Request ACC" in the repo, but every signal is suffixed `_GRB` (*Getriebe*) — this is **gearbox-sourced**, and the title looks like a copy-paste artifact.
|
||||||
|
|
||||||
|
| Signal | Start bit | Len | Factor | Unit | Meaning |
|
||||||
|
|---|---|---|---|---|---|
|
||||||
|
| `ST_GR_GRB` | 0 | 4 | 1 | — | **Target gear** (N, R, 1st–6th; `0xF`=invalid) |
|
||||||
|
| `ST_GRLV_ACV` | 4 | 2 | 1 | — | Gear lever active |
|
||||||
|
| `ST_CCLT` | 6 | 2 | 1 | — | Torque converter lockup clutch: disengaged / controlled / closed / invalid |
|
||||||
|
| `GRDT_REIN` | 8 | 12 | 0.125 | 1/min | Gearbox speed |
|
||||||
|
| **(bits 20–39)** | — | — | — | — | **UNDOCUMENTED — populated on our bus** → [[driveline-speed-signals]] |
|
||||||
|
| `CHKSM_GRB` | 40 | 8 | 1 | — | Checksum |
|
||||||
|
| `ALIV_GRB` | 48 | 4 | 1 | — | Alive counter |
|
||||||
|
| `ST_MOD_GRB` | 52 | 3 | 1 | — | Gearbox mode |
|
||||||
|
| `ST_HYPP_ACV` | 56 | 2 | 1 | — | — |
|
||||||
|
|
||||||
|
Worked example `03 FF 0F 00 00 48 8B EF` → gear = **P**, clutch disengaged.
|
||||||
|
|
||||||
|
**`ST_GR_GRB` (D0 low nibble) verified against our capture** (verified, 2026-07-17) — frame counts from the 2026-07-15 dump:
|
||||||
|
|
||||||
|
| Value | Meaning | Frames | Status |
|
||||||
|
|---|---|---|---|
|
||||||
|
| `1` | N | 102 | verified |
|
||||||
|
| `2` | **R** | 2 | verified — see the R snapshot below |
|
||||||
|
| `3` | P | 1378 | verified |
|
||||||
|
| `5` | 1st gear | 453 | verified |
|
||||||
|
| `6`–`A` | 2nd–6th | — | `(unverified)` — inferred from the identical ladder in `0x1D2` D1 |
|
||||||
|
| `4` | ? | — | unaccounted for |
|
||||||
|
| `0xF` | invalid | — | (source) |
|
||||||
|
|
||||||
|
Note `5` = 1st gear here, **the same ladder as `0x1D2` D1's high nibble** — two independent messages sharing one encoding, which is good mutual corroboration.
|
||||||
|
|
||||||
|
> [!warning] Correcting the 2026-07-16 wiki claim
|
||||||
|
> [[gear-box-can-revealings]] recorded "`0x0BA` — secondary, do NOT use … D7 collides R=D=`0xCF`". **That dismissal was wrong**: D7 is `ST_HYPP_ACV`/alive-counter territory, not a gear field. The gear lives in **D0's low nibble**, which does not collide, and which carries a **distinct R code that `0x1D2` D1 lacks entirely**. `0x0BA` is not redundant — it is the only source for engaged reverse. Corrected in [[can-id-candidates]].
|
||||||
|
>
|
||||||
|
> Likewise, the same page's note that "`0x0BA` D5/D6 fluctuate so there are no values" is now explained rather than dismissed: **D5 = `CHKSM_GRB` (checksum), D6 = `ALIV_GRB` (alive counter)**. They fluctuate by design.
|
||||||
|
|
||||||
|
## Reverse-engaged snapshot (user-reported, 2026-07-17, verified)
|
||||||
|
|
||||||
|
Values with the lever held in **R** and the box engaged:
|
||||||
|
|
||||||
|
```
|
||||||
|
0BA DLC 8: 02 FE 0F A8 01 CF 8B CF
|
||||||
|
1D2 DLC 6: D2 0F FF DC F0 FF
|
||||||
|
```
|
||||||
|
|
||||||
|
- `0x0BA` D0 = `0x02` → `ST_GR_GRB` = **R**. ✅
|
||||||
|
- `0x1D2` D0 = `0xD2` → lever R; **D1 = `0x0F` → no gear number**. Confirms `0x1D2` D1 is blind to reverse — reverse is unnumbered there.
|
||||||
|
- `0x0BA` D3/D4 = `A8 01` — **non-zero**, where the repo's E65 example and every stationary frame of our own capture show `00 00`. → [[driveline-speed-signals]]
|
||||||
|
- `GRDT_REIN` = `0xFFE` ≈ invalid marker; this field reads `0xFFE`/`0xFFF` across both our captures and appears **not to be populated** on our bus. Use `0x1A2` for turbine speed instead.
|
||||||
|
|
||||||
|
## Cross-references worth chasing
|
||||||
|
|
||||||
|
- **`6HP26.pdf`** in `docs/` — the ZF 6HP26 manual. If our box is a 6HP26 (likely for an E60/E65 M57N), this is a primary source for gear ratios, which would let us convert output-shaft speed → road speed. Added to the [[open-questions]] sourcing wishlist.
|
||||||
|
- **`can_message_list.txt`** — full ID → name → sending-module map spanning 0x00–0xFFF, including K-CAN comfort/lighting. Not yet mined; worth a pass if the project ever wants non-powertrain data.
|
||||||
|
- `Log1.blf` / `Log2.blf` — real E65 captures for offline cross-checking.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[can-id-candidates]] · [[driveline-speed-signals]] · [[gear-box-can-revealings]] · [[can-capture-2026-07-15]] · [[can-bus-integration]] · [[bmw-m57n-engine]]
|
||||||
@@ -0,0 +1,105 @@
|
|||||||
|
---
|
||||||
|
type: source
|
||||||
|
tags: [can-bus, capture, verified, gear, egs, e60]
|
||||||
|
updated: 2026-07-17
|
||||||
|
---
|
||||||
|
|
||||||
|
# Gearbox Lever & Gear Decode — 2026-07-16/17 (VERIFIED)
|
||||||
|
|
||||||
|
User-recorded per-detent captures of the Steptronic selector: `raw/gear_box_can_revealings.csv` (lever positions, 2026-07-16) and `raw/gearbox_engaged_gear.csv` (engaged gear 1–6 in both D and M/S, 2026-07-17). Together these **verify `0x1D2` as the gear source** and decode the lever, the engaged gear number, and the D/S/M mode.
|
||||||
|
|
||||||
|
Two IDs react to the gearbox: **`0x1D2`** (lever + engaged gear) and **`0x0BA`** (the gearbox's own target gear). **Both are needed** — see the correction notice below.
|
||||||
|
|
||||||
|
## `0x1D2` (DLC 6) — lever + engaged gear ✅ VERIFIED
|
||||||
|
|
||||||
|
| Byte | Meaning | Values |
|
||||||
|
|---|---|---|
|
||||||
|
| **0** | **Lever position** | `0xE1`=P · `0xD2`=R · `0xB4`=N · `0x78`=D **and** S/M |
|
||||||
|
| **1** | **Engaged gear** | high nibble − 4 = gear; `0x0F` = no numbered gear |
|
||||||
|
| 2 | unused | `0xFF` |
|
||||||
|
| 3 | rolling counter | fluctuates — ignore |
|
||||||
|
| **4** | **Mode** | `0xF0`=Drive(auto) · `0xF1`=Sport · `0xF2`=Manual |
|
||||||
|
| 5 | unused | `0xFF` |
|
||||||
|
|
||||||
|
### Byte 0 — lever position
|
||||||
|
|
||||||
|
Whole-byte codes, **matching the documented E65/E90 values exactly**, every one. (verified, 2026-07-16)
|
||||||
|
|
||||||
|
Byte 0 **cannot** split D from S/M (both `0x78`) — Steptronic's S/M is a side-gate off D, so the fore/aft position is physically identical. Byte 4 does that job.
|
||||||
|
|
||||||
|
### Byte 1 — engaged gear ✅ (2026-07-17)
|
||||||
|
|
||||||
|
The `raw/gearbox_engaged_gear.csv` capture resolves this. D1 is a clean arithmetic ladder, **+16 per gear** — the high nibble counts, the low nibble is a constant `0xF`:
|
||||||
|
|
||||||
|
| D1 | hex | Engaged gear |
|
||||||
|
|---|---|---|
|
||||||
|
| 15 | `0x0F` | none (P / R / N) |
|
||||||
|
| 95 | `0x5F` | 1 |
|
||||||
|
| 111 | `0x6F` | 2 |
|
||||||
|
| 127 | `0x7F` | 3 |
|
||||||
|
| 143 | `0x8F` | 4 |
|
||||||
|
| 159 | `0x9F` | 5 |
|
||||||
|
| 175 | `0xAF` | 6 |
|
||||||
|
|
||||||
|
`gear = (D1 >> 4) − 4`
|
||||||
|
|
||||||
|
**The D and M/S halves of the capture show identical D1 values for the same gear** — which is the proof that this is *engaged* gear and not a lever field: the box is in 3rd whether it chose 3rd or the driver asked for it.
|
||||||
|
|
||||||
|
Corroborated by the earlier dump: `E10F` (P), `D20F` (R), `B40F` (N), `785F` (D) — D at standstill = gear 1. And `0x0BA` `ST_GR_GRB` uses **the same ladder** (`5` = 1st), independently. (verified, 2026-07-17)
|
||||||
|
|
||||||
|
> [!warning] Corrects the 2026-07-16 claim "D1 = drive-gate flag"
|
||||||
|
> This page previously called D1 a boolean gate (`0x0F` in P/R/N → `0x5F` in D+S/M). **Wrong** — it was the gear number all along, reading 1 because the vehicle was stationary. Only two values were ever observed, so a flag looked like a reasonable fit. This also **closes the "actual engaged gear needs a drive capture"** item that this page previously listed as open — it didn't need a drive capture, it needed the lever held per-gear.
|
||||||
|
|
||||||
|
> [!note] Reverse is not numbered
|
||||||
|
> D1 stays `0x0F` with the lever in R and the box **engaged** (verified 2026-07-17: `1D2 = D2 0F FF DC F0 FF`). `0x1D2` D1 is blind to reverse. **The engaged-R signal is `0x0BA` `ST_GR_GRB` = 2.**
|
||||||
|
|
||||||
|
### Byte 4 — mode ✅ (2026-07-17)
|
||||||
|
|
||||||
|
| D4 | Mode |
|
||||||
|
|---|---|
|
||||||
|
| `0xF0` | Drive — automatic |
|
||||||
|
| `0xF1` | **Sport** — side gate, no manual input yet |
|
||||||
|
| `0xF2` | **Manual** — driver has taken control via +/− |
|
||||||
|
|
||||||
|
From `gearbox_engaged_gear.csv`: M/S 1st = `0xF1`, M/S 2nd–6th = `0xF2`. Read with the user's note — *"when I switch the lever to M/S the D4 has 241; I have not yet pulled the lever +; when I do it becomes 242"* — this maps onto Steptronic behaviour: the **side gate puts you in S**, and the **first +/− tap promotes you to M**, where it stays.
|
||||||
|
|
||||||
|
> [!warning] Corrects the 2026-07-16 claim "0xF2 = downshift (−)"
|
||||||
|
> This page previously called `0xF2` a transient downshift **event**. **Wrong** — it *persists* across M/S gears 2 through 6, and events don't hold steady. It's a **mode flag**, not a shift pulse. The original observation (pushing the lever forward → `0xF2`) is still true but was misread: the downshift didn't *signal* `0xF2`, it *promoted the box into Manual*, which is what `0xF2` reports. This also dissolves the old "manual up-shift (+) value unconfirmed" question — `+` and `−` don't have distinct D4 codes; both simply mean *Manual*.
|
||||||
|
|
||||||
|
### Recommended decode
|
||||||
|
|
||||||
|
```
|
||||||
|
lever = D0: 0xE1→P 0xD2→R 0xB4→N 0x78→D/S/M
|
||||||
|
mode = D4: 0xF0→auto Drive 0xF1→Sport 0xF2→Manual
|
||||||
|
gear = D1: 0x0F→none, else (D1>>4)−4 (1..6; never set for R)
|
||||||
|
engaged R → 0x0BA D0 low nibble == 2
|
||||||
|
```
|
||||||
|
|
||||||
|
## `0x0BA` (DLC 8) — the gearbox's own target gear ⚠ previously dismissed in error
|
||||||
|
|
||||||
|
> [!warning] Corrects the 2026-07-16 claim "`0x0BA` — secondary, do NOT use"
|
||||||
|
> The 2026-07-16 dismissal rested on **D7 colliding R=D=`0xCF`**. D7 is not a gear field — per [[e65-reverse-engineering-repo]] it's `ST_HYPP_ACV`/alive-counter territory. **The gear is in D0's low nibble** (`ST_GR_GRB`), which does not collide and which carries a **distinct R code that `0x1D2` has nowhere**. `0x0BA` is not redundant — it is the *only* source of engaged reverse and the only source of output-shaft motion. Do use it.
|
||||||
|
>
|
||||||
|
> Similarly "D5/D6 fluctuate so there are no values" — **D5 = `CHKSM_GRB` (checksum), D6 = `ALIV_GRB` (alive counter)**. The observation was correct; the fluctuation is by design, not noise.
|
||||||
|
|
||||||
|
`ST_GR_GRB` = D0 low nibble: `1`=N, `2`=**R**, `3`=P, `5`–`A`=gears 1–6, `0xF`=invalid. **All of 1/2/3/5/6/7/8/9/A verified** — 5–A confirmed directly by the 2026-07-17 drive capture ([[can-capture-2026-07-17-drive]]), retiring the earlier inference. Value `4` still unobserved.
|
||||||
|
|
||||||
|
**This makes `0x0BA` D0 a complete gear source on its own** — P/R/N and 1st–6th from one nibble, reverse included. `0x1D2` is still required for the **lever** (what the driver selected) and the **mode** (D/S/M), neither of which `0x0BA` carries.
|
||||||
|
|
||||||
|
D0 bits 6–7 = `ST_CCLT`, the torque converter lockup clutch (`0`=disengaged, `1`=controlled, `2`=closed) — seen live in the higher gears.
|
||||||
|
|
||||||
|
`0x0BA` **D3/D4** carry what is almost certainly **output shaft speed** — undocumented in the source repo, zero in every stationary frame, non-zero the moment the wheels turn. This is the project's only road-speed signal. → [[driveline-speed-signals]]
|
||||||
|
|
||||||
|
## Lever vs box: the UX cross-check
|
||||||
|
|
||||||
|
`0x1D2` D0 = what the driver **selected**; `0x0BA` `ST_GR_GRB` = what the box **intends**. Disagreement means the box refused the request — a real fault worth surfacing on the display. Neither, however, is proof of mechanical engagement; for that, use **turbine speed** (`0x1A2`), which physically collapses when the box loads up. Full treatment: [[driveline-speed-signals]].
|
||||||
|
|
||||||
|
## Still open
|
||||||
|
|
||||||
|
- Value `4` in the `ST_GR_GRB` ladder unaccounted for.
|
||||||
|
- `0x0BA` D3/D4 **scaling** — ×0.125 is now a strong hypothesis but not measured → [[driveline-speed-signals]].
|
||||||
|
- `0x1D2` D0 = `0xF0`, an unrecognized lever code seen once in a discarded log; absent from the drive capture. Probably an EGS-not-initialised transient. The firmware rejects it as `GEAR_UNKNOWN`, which is the right conservative behaviour either way.
|
||||||
|
|
||||||
|
## Related
|
||||||
|
|
||||||
|
[[can-id-candidates]] · [[driveline-speed-signals]] · [[e65-reverse-engineering-repo]] · [[can-capture-2026-07-15]] · [[can-bus-integration]]
|
||||||
Reference in New Issue
Block a user