Add corrupted CAN message detection

This commit is contained in:
Daniel Öster 2025-08-14 15:56:51 +03:00
parent 2dff7c62af
commit 0dad293d96
2 changed files with 14 additions and 0 deletions

View file

@ -30,6 +30,11 @@ uint8_t RenaultZoeGen2Battery::calculate_crc_zoe(CAN_frame& rx_frame, uint8_t cr
return crc ^ crc_xor;
}
bool RenaultZoeGen2Battery::is_message_corrupt(CAN_frame rx_frame, uint8_t crc_xor) {
uint8_t crc = calculate_crc_zoe(rx_frame, crc_xor);
return crc != rx_frame.data.u8[7];
}
void RenaultZoeGen2Battery::update_values() {
datalayer_battery->status.soh_pptt = battery_soh;
@ -149,6 +154,12 @@ void RenaultZoeGen2Battery::handle_incoming_can_frame(CAN_frame rx_frame) {
case 0x3EF:
datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE;
break;
case 0x36C:
datalayer_battery->status.CAN_battery_still_alive = CAN_STILL_ALIVE;
if (is_message_corrupt(rx_frame, 0x01)) {
datalayer_battery->status.CAN_error_counter++;
}
break;
case 0x4AE:
case 0x4AF:
case 0x4DB:
@ -744,6 +755,7 @@ void RenaultZoeGen2Battery::transmit_can(unsigned long currentMillis) {
ZOE_0EE.data.u8[7] = calculate_crc_zoe(ZOE_0EE, 0xAC);
transmit_can_frame(&ZOE_0EE); //Pedal position
//transmit_can_frame(&ZOE_133); //Vehicle speed (CRC is frame3 B1A670 55 0006FFFF)
}
// Send 100ms CAN Message

View file

@ -50,6 +50,8 @@ class RenaultZoeGen2Battery : public CanBattery {
// If not null, this battery decides when the contactor can be closed and writes the value here.
bool* allows_contactor_closing;
bool is_message_corrupt(CAN_frame rx_frame, uint8_t crc_xor);
static const int MAX_PACK_VOLTAGE_DV = 4100; //5000 = 500.0V
static const int MIN_PACK_VOLTAGE_DV = 3000;
static const int MAX_CELL_DEVIATION_MV = 150;