Skip to content

Commit

Permalink
Added a TX error for CAN comms
Browse files Browse the repository at this point in the history
  • Loading branch information
Cabooman committed Feb 12, 2024
1 parent 0913347 commit 09db151
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Software/src/battery/BMW-I3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ void update_values_i3_battery() { //This function maps all the values fetched v

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 1 addition & 1 deletion Software/src/battery/CHADEMO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void update_values_chademo_battery() { //This function maps all the values fetc
/* Check if the Vehicle is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
errorCode = 7;
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 1 addition & 1 deletion Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ void update_values_imiev_battery() { //This function maps all the values fetche

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 1 addition & 1 deletion Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
4 changes: 2 additions & 2 deletions Software/src/battery/NISSAN-LEAF-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,15 +344,15 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
errorCode = 7;
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
if (CANerror >
MAX_CAN_FAILURES) //Also check if we have recieved too many malformed CAN messages. If so, signal via LED
{
errorCode = 10;
set_event(EVENT_CAN_WARNING, 0);
set_event(EVENT_CAN_RX_WARNING, 0);
}

/*Finally print out values to serial if configured to do so*/
Expand Down
2 changes: 1 addition & 1 deletion Software/src/battery/RENAULT-KANGOO-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void update_values_kangoo_battery() { //This function maps all the values fetch

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 1 addition & 1 deletion Software/src/battery/RENAULT-ZOE-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void update_values_zoe_battery() { //This function maps all the values fetched

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 1 addition & 1 deletion Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void update_values_santafe_phev_battery() { //This function maps all the values

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!CANstillAlive) {
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
CANstillAlive--;
}
Expand Down
2 changes: 1 addition & 1 deletion Software/src/battery/TESLA-MODEL-3-BATTERY.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ void update_values_tesla_model_3_battery() { //This function maps all the value

/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
if (!stillAliveCAN) {
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_RX_FAILURE, 0);
} else {
stillAliveCAN--;
}
Expand Down
25 changes: 17 additions & 8 deletions Software/src/devboard/utils/events.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,15 @@ void init_events(void) {
}

for (uint16_t i = 0; i < EVENT_NOF_EVENTS; i++) {
events.entries[EVENT_CAN_FAILURE].data = 0;
events.entries[EVENT_CAN_FAILURE].timestamp = 0;
events.entries[EVENT_CAN_FAILURE].occurences = 0;
events.entries[EVENT_CAN_FAILURE].log = false;
events.entries[i].data = 0;
events.entries[i].timestamp = 0;
events.entries[i].occurences = 0;
events.entries[i].log = false;
}

events.entries[EVENT_CAN_FAILURE].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_CAN_WARNING].level = EVENT_LEVEL_WARNING;
events.entries[EVENT_CAN_RX_FAILURE].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_CAN_RX_WARNING].level = EVENT_LEVEL_WARNING;
events.entries[EVENT_CAN_TX_FAILURE].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_WATER_INGRESS].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_12V_LOW].level = EVENT_LEVEL_WARNING;
events.entries[EVENT_SOC_PLAUSIBILITY_ERROR].level = EVENT_LEVEL_ERROR;
Expand All @@ -126,6 +127,10 @@ void init_events(void) {
events.entries[EVENT_DUMMY_DEBUG].level = EVENT_LEVEL_DEBUG;
events.entries[EVENT_DUMMY_WARNING].level = EVENT_LEVEL_WARNING;
events.entries[EVENT_DUMMY_ERROR].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_SERIAL_RX_WARNING].level = EVENT_LEVEL_WARNING;
events.entries[EVENT_SERIAL_RX_FAILURE].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_SERIAL_TX_FAILURE].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_SERIAL_TRANSMITTER_FAILURE].level = EVENT_LEVEL_ERROR;

events.entries[EVENT_DUMMY_INFO].log = true;
events.entries[EVENT_DUMMY_DEBUG].log = true;
Expand Down Expand Up @@ -154,10 +159,12 @@ void clear_event(EVENTS_ENUM_TYPE event) {

const char* get_event_message_string(EVENTS_ENUM_TYPE event) {
switch (event) {
case EVENT_CAN_FAILURE:
case EVENT_CAN_RX_FAILURE:
return "No CAN communication detected for 60s. Shutting down battery control.";
case EVENT_CAN_WARNING:
case EVENT_CAN_RX_WARNING:
return "ERROR: High amount of corrupted CAN messages detected. Check CAN wire shielding!";
case EVENT_CAN_TX_FAILURE:
return "ERROR: CAN messages failed to transmit, or no one on the bus to ACK the message!";
case EVENT_WATER_INGRESS:
return "Water leakage inside battery detected. Operation halted. Inspect battery!";
case EVENT_12V_LOW:
Expand Down Expand Up @@ -204,6 +211,8 @@ const char* get_event_message_string(EVENTS_ENUM_TYPE event) {
return "Error in serial function: No ACK from receiver!";
case EVENT_SERIAL_TRANSMITTER_FAILURE:
return "Error in serial function: Some ERROR level fault in transmitter, received by receiver";
case EVENT_OTA_UPDATE:
return "OTA update started!";
default:
return "";
}
Expand Down
6 changes: 4 additions & 2 deletions Software/src/devboard/utils/events.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@
*
* After adding an event, assign the proper event level in events.cpp:init_events()
*/

#define EVENTS_ENUM_TYPE(XX) \
XX(EVENT_CAN_FAILURE) \
XX(EVENT_CAN_WARNING) \
XX(EVENT_CAN_RX_FAILURE) \
XX(EVENT_CAN_RX_WARNING) \
XX(EVENT_CAN_TX_FAILURE) \
XX(EVENT_WATER_INGRESS) \
XX(EVENT_12V_LOW) \
XX(EVENT_SOC_PLAUSIBILITY_ERROR) \
Expand Down
4 changes: 2 additions & 2 deletions Software/src/lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ int ESP32CAN::CANWriteFrame(const CAN_frame_t* p_frame) {
tx_ok = (result == 0) ? true : false;
if (tx_ok == false) {
Serial.println("CAN failure! Check wires");
set_event(EVENT_CAN_FAILURE, 0);
set_event(EVENT_CAN_TX_FAILURE, 0);
start_time = millis();
} else {
clear_event(EVENT_CAN_FAILURE);
clear_event(EVENT_CAN_TX_FAILURE);
}
} else {
if ((millis() - start_time) >= 2000) {
Expand Down

0 comments on commit 09db151

Please sign in to comment.