Gear decode VERIFIED: real 0x1D2 map in firmware + wiki
The gear lever is fully decoded and confirmed on the actual swap bus (raw/gear_box_can_revealings.csv): 0x1D2 byte0 = P 0xE1 / R 0xD2 / N 0xB4 / D 0x78, matching the documented BMW codes exactly. Byte4 splits D vs S/M (0xF0 auto) and carries manual +/- shifts. Firmware: - automotive_data.h: replace placeholder gear map (0x1001) with CAN_ID_GEAR_LEVER 0x1D2, verified byte-0 codes, byte-4 mode define, and can_to_gear_lever(). - can_driver.cpp: decode 0x1D2 byte0 into gear_position via the enum; reject unrecognized codes instead of copying the raw byte. - Scope: P/R/N/D only (verified). S/M shows as D for now (no enum slot; engaged gear number needs a drive capture) — TODO'd, not faked. Coolant/oil/battery left as flagged placeholders pending a cold-start capture. Wiki: - New source page gear-box-can-revealings + raw CSV filed. - can-id-candidates: 0x1D2 gear row -> VERIFIED; encoding "dispute" section rewritten with the full lever+mode decode table. - Updated index + log. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -100,9 +100,18 @@ typedef struct __attribute__((packed)) {
|
||||
#define CAN_ID_GEARBOX_TEMP 0x201 // Gearbox oil temperature
|
||||
#define CAN_BYTE_GEARBOX_TEMP 3 // Byte 3
|
||||
|
||||
#define CAN_ID_GEARBOX_DATA 0x1001 // Gearbox position and current gear
|
||||
#define CAN_BYTE_GEAR_POS 0 // Byte 0 (P/R/N/D/S/M)
|
||||
#define CAN_BYTE_CURRENT_GEAR 1 // Byte 1 (1-8)
|
||||
// Gear lever position — EGS "TransmissionDataDisplay", DLC 6.
|
||||
// VERIFIED on the swap bus 2026-07-16 (see wiki/sources/gear-box-can-revealings.md).
|
||||
#define CAN_ID_GEAR_LEVER 0x1D2 // Gear lever position message
|
||||
#define CAN_BYTE_GEAR_LEVER 0 // Byte 0: lever code (see can_to_gear_lever)
|
||||
#define CAN_BYTE_GEAR_MODE 4 // Byte 4: 0xF0=Drive(auto), 0xF1=Sport/Manual, 0xF2=downshift(-)
|
||||
|
||||
// Raw byte-0 lever codes (whole-byte encoding, all verified against the live bus)
|
||||
#define GEAR_CODE_PARK 0xE1
|
||||
#define GEAR_CODE_REVERSE 0xD2
|
||||
#define GEAR_CODE_NEUTRAL 0xB4
|
||||
#define GEAR_CODE_DRIVE 0x78 // also S/M side-gate — split via CAN_BYTE_GEAR_MODE
|
||||
#define GEAR_MODE_DRIVE_AUTO 0xF0 // byte 4 value when in plain Drive (else Sport/Manual)
|
||||
|
||||
#define CAN_ID_BATTERY_VOLTAGE 0x101F // Battery voltage (16-bit)
|
||||
#define CAN_BYTE_BATTERY_VOLT_H 0 // Byte 0 (high byte)
|
||||
@@ -179,6 +188,24 @@ static inline uint16_t can_to_voltage(uint16_t can_value) {
|
||||
return can_value * 10; // Convert 0.1V to 0.01V units
|
||||
}
|
||||
|
||||
/**
|
||||
* Map a raw 0x1D2 byte-0 lever code to a gear_position_t.
|
||||
* D and S/M share code 0x78 — they're distinguished by byte 4 (CAN_BYTE_GEAR_MODE),
|
||||
* not surfaced here yet (no enum slot; the engaged manual gear number needs a drive
|
||||
* capture — see wiki/pages/open-questions.md).
|
||||
* @param d0 Byte 0 of a 0x1D2 frame
|
||||
* @return Gear 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
|
||||
default: return GEAR_UNKNOWN;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get human-readable gear position string
|
||||
* @param gear Gear position enum value
|
||||
|
||||
Reference in New Issue
Block a user