mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 10:19:29 +02:00
Added a TX error for CAN comms
This commit is contained in:
parent
091334789a
commit
09db1513f1
12 changed files with 33 additions and 22 deletions
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ 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--;
|
||||
}
|
||||
|
@ -352,7 +352,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
|
|||
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*/
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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--;
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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:
|
||||
|
@ -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 "";
|
||||
}
|
||||
|
|
|
@ -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) \
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue