Fix odometer encoding in main.cpp to use bytes 0-2 and update calculation factor. Comment out debug print statements for RPM and speed to reduce output noise.

This commit is contained in:
2026-03-01 14:37:10 +01:00
parent 78056f97ac
commit dd8b90cdac

View File

@@ -53,7 +53,7 @@ void loop() {
#define ID_ENGINE_RPM 0x1F9 // bytes 2-3 BE, raw/8 = RPM #define ID_ENGINE_RPM 0x1F9 // bytes 2-3 BE, raw/8 = RPM
#define ID_VEHICLE_SPEED 0x354 // bytes 0-1 BE, raw*0.01 = km/h #define ID_VEHICLE_SPEED 0x354 // bytes 0-1 BE, raw*0.01 = km/h
#define ID_SPEED_2 0x645 // bytes 3-4 BE, raw*0.01 = km/h (dashboard backlight msg) #define ID_SPEED_2 0x645 // bytes 3-4 BE, raw*0.01 = km/h (dashboard backlight msg)
#define ID_ODOMETER 0x5FD // bytes 2-4 BE, raw/13.0856 = km (cal: 114513) #define ID_ODOMETER 0x5FD // bytes 0-2 BE, raw/16 = km (fixed encoding)
static uint16_t lastRpm = 0xFFFF; static uint16_t lastRpm = 0xFFFF;
static uint16_t lastSpeed = 0xFFFF; static uint16_t lastSpeed = 0xFFFF;
@@ -75,7 +75,7 @@ void decode_renault(const CanFrame& frame) {
if (rpm >= 100 && rpm <= 7000 && (rpm != lastRpm || now - lastPrintMs > DEBOUNCE_MS)) { if (rpm >= 100 && rpm <= 7000 && (rpm != lastRpm || now - lastPrintMs > DEBOUNCE_MS)) {
lastRpm = rpm; lastRpm = rpm;
lastPrintMs = now; lastPrintMs = now;
Serial.printf("RPM: %u\n", rpm); // Serial.printf("RPM: %u\n", rpm);
} }
} }
break; break;
@@ -87,7 +87,7 @@ void decode_renault(const CanFrame& frame) {
if (kmh < 250 && (raw != lastSpeed || now - lastPrintMs > DEBOUNCE_MS)) { if (kmh < 250 && (raw != lastSpeed || now - lastPrintMs > DEBOUNCE_MS)) {
lastSpeed = raw; lastSpeed = raw;
lastPrintMs = now; lastPrintMs = now;
Serial.printf("Speed: %.1f km/h\n", kmh); // Serial.printf("Speed: %.1f km/h\n", kmh);
} }
} }
break; break;
@@ -99,15 +99,15 @@ void decode_renault(const CanFrame& frame) {
if (kmh < 250 && (raw != lastSpeed || now - lastPrintMs > DEBOUNCE_MS)) { if (kmh < 250 && (raw != lastSpeed || now - lastPrintMs > DEBOUNCE_MS)) {
lastSpeed = raw; lastSpeed = raw;
lastPrintMs = now; lastPrintMs = now;
Serial.printf("Speed: %.1f km/h\n", kmh); // Serial.printf("Speed: %.1f km/h\n", kmh);
} }
} }
break; break;
case ID_ODOMETER: // 0x5FD x0r: bytes 0-2 = km. This car uses bytes 2-4. case ID_ODOMETER: // 0x5FD bytes 0-2 BE: raw = km*16 (fixed factor, stable)
if (len >= 5) { if (len >= 3) {
uint32_t raw = (uint32_t)d[2] << 16 | (uint32_t)d[3] << 8 | d[4]; uint32_t raw02 = (uint32_t)d[0] << 16 | (uint32_t)d[1] << 8 | d[2];
uint32_t km = (uint32_t)(raw / 13.0834f); // cal: 114513 uint32_t km = raw02 / 16; // encoding: raw = km * 16 (constant)
if (km < 999999 && (km != lastOdo || now - lastPrintMs > DEBOUNCE_MS)) { if (km < 999999 && (km != lastOdo || now - lastPrintMs > DEBOUNCE_MS)) {
lastOdo = km; lastOdo = km;
lastPrintMs = now; lastPrintMs = now;