From 1d09dacccb1424edc13fcc54bede3ed869047498 Mon Sep 17 00:00:00 2001 From: Cabooman <81711263+Cabooman@users.noreply.github.com> Date: Mon, 5 Feb 2024 23:36:25 +0100 Subject: [PATCH] Event setting --- Software/src/battery/BMW-I3-BATTERY.cpp | 2 ++ Software/src/battery/CHADEMO-BATTERY.cpp | 2 ++ Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp | 2 ++ Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp | 7 +++++++ Software/src/battery/NISSAN-LEAF-BATTERY.cpp | 12 ++++++++++++ Software/src/battery/RENAULT-KANGOO-BATTERY.cpp | 5 +++++ Software/src/battery/RENAULT-ZOE-BATTERY.cpp | 5 +++++ Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp | 2 ++ Software/src/battery/TESLA-MODEL-3-BATTERY.cpp | 11 +++++++++++ 9 files changed, 48 insertions(+) diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index 935da03e..40acb0e2 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -1,4 +1,5 @@ #include "BMW-I3-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -103,6 +104,7 @@ void update_values_i3_battery() { //This function maps all the values fetched v if (!CANstillAlive) { bms_status = FAULT; Serial.println("No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } diff --git a/Software/src/battery/CHADEMO-BATTERY.cpp b/Software/src/battery/CHADEMO-BATTERY.cpp index 929c0a15..84a3634d 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -1,4 +1,5 @@ #include "CHADEMO-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -107,6 +108,7 @@ void update_values_chademo_battery() { //This function maps all the values fetc bms_status = FAULT; errorCode = 7; Serial.println("No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } diff --git a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp index f9a4d97d..51ebdba9 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -1,4 +1,5 @@ #include "IMIEV-CZERO-ION-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -109,6 +110,7 @@ void update_values_imiev_battery() { //This function maps all the values fetche if (!CANstillAlive) { bms_status = FAULT; Serial.println("No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index 40c948cd..e1b27df7 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -1,4 +1,5 @@ #include "KIA-HYUNDAI-64-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -200,6 +201,7 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value if (!CANstillAlive) { bms_status = FAULT; Serial.println("No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } @@ -207,11 +209,13 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value if (waterleakageSensor == 0) { Serial.println("Water leakage inside battery detected. Operation halted. Inspect battery!"); bms_status = FAULT; + set_event(EVENT_WATER_INGRESS, 0); } if (leadAcidBatteryVoltage < 110) { Serial.println("12V battery source below required voltage to safely close contactors. Inspect the supply/battery!"); LEDcolor = YELLOW; + set_event(EVENT_12V_LOW, leadAcidBatteryVoltage); } // Check if cell voltages are within allowed range @@ -220,14 +224,17 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value if (cell_max_voltage >= MAX_CELL_VOLTAGE) { bms_status = FAULT; Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_OVER_VOLTAGE, 0); } if (cell_min_voltage <= MIN_CELL_VOLTAGE) { bms_status = FAULT; Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_UNDER_VOLTAGE, 0); } if (cell_deviation_mV > MAX_CELL_DEVIATION) { LEDcolor = YELLOW; Serial.println("ERROR: HIGH CELL DEVIATION!!! Inspect battery!"); + set_event(EVENT_CELL_DEVIATION_HIGH, 0); } if (bms_status == FAULT) { //Incase we enter a critical fault state, zero out the allowed limits diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index 17a28679..835487ee 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -2,6 +2,7 @@ #ifdef MQTT #include "../devboard/mqtt/mqtt.h" #endif +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -262,6 +263,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #ifdef DEBUG_VIA_USB Serial.println("ERROR: SOC% reported by battery not plausible. Restart battery!"); #endif + set_event(EVENT_SOC_PLAUSIBILITY_ERROR, LB_SOC / 10); } } @@ -311,6 +313,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #ifdef DEBUG_VIA_USB Serial.println("ERROR: Battery raised caution indicator AND requested discharge stop. Inspect battery status!"); #endif + set_event(EVENT_BATTERY_DISCHG_STOP_REQ, 0); break; case (6): //Caution Lamp Request & Charging Mode Stop Request @@ -319,6 +322,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #ifdef DEBUG_VIA_USB Serial.println("ERROR: Battery raised caution indicator AND requested charge stop. Inspect battery status!"); #endif + set_event(EVENT_BATTERY_CHG_STOP_REQ, 0); break; case (7): //Caution Lamp Request & Charging Mode Stop Request & Normal Stop Request @@ -328,6 +332,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched Serial.println( "ERROR: Battery raised caution indicator AND requested charge/discharge stop. Inspect battery status!"); #endif + set_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ, 0); break; default: break; @@ -342,6 +347,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #endif bms_status = FAULT; errorCode = 5; + set_event(EVENT_LOW_SOH, LB_StateOfHealth); max_target_discharge_power = 0; max_target_charge_power = 0; } @@ -355,6 +361,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched "disabled!"); #endif bms_status = FAULT; + set_event(EVENT_HVIL_FAILURE, 0); errorCode = 6; SOC = 0; max_target_discharge_power = 0; @@ -369,6 +376,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #ifdef DEBUG_VIA_USB Serial.println("ERROR: No CAN communication detected for 60s. Shutting down battery control."); #endif + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } @@ -380,6 +388,7 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #ifdef DEBUG_VIA_USB Serial.println("ERROR: High amount of corrupted CAN messages detected. Check CAN wire shielding!"); #endif + set_event(EVENT_CAN_WARNING, 0); } /*Finally print out values to serial if configured to do so*/ @@ -615,6 +624,7 @@ void receive_can_leaf_battery(CAN_frame_t rx_frame) { #ifdef DEBUG_VIA_USB Serial.println("HIGH CELL DEVIATION!!! Inspect battery!"); #endif + set_event(EVENT_CELL_DEVIATION_HIGH, 0); } if (min_max_voltage[1] >= MAX_CELL_VOLTAGE) { @@ -623,6 +633,7 @@ void receive_can_leaf_battery(CAN_frame_t rx_frame) { #ifdef DEBUG_VIA_USB Serial.println("CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); #endif + set_event(EVENT_CELL_OVER_VOLTAGE, 0); } if (min_max_voltage[0] <= MIN_CELL_VOLTAGE) { bms_status = FAULT; @@ -630,6 +641,7 @@ void receive_can_leaf_battery(CAN_frame_t rx_frame) { #ifdef DEBUG_VIA_USB Serial.println("CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); #endif + set_event(EVENT_CELL_UNDER_VOLTAGE, 0); } break; } diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 4f818878..47ab1f64 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -1,4 +1,5 @@ #include "RENAULT-KANGOO-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -126,6 +127,7 @@ void update_values_kangoo_battery() { //This function maps all the values fetch if (!CANstillAlive) { bms_status = FAULT; Serial.println("No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } @@ -133,14 +135,17 @@ void update_values_kangoo_battery() { //This function maps all the values fetch if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) { bms_status = FAULT; Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_OVER_VOLTAGE, 0); } if (LB_Cell_Min_Voltage <= ABSOLUTE_CELL_MIN_VOLTAGE) { bms_status = FAULT; Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_UNDER_VOLTAGE, 0); } if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) { LEDcolor = YELLOW; Serial.println("ERROR: HIGH CELL mV DEVIATION!!! Inspect battery!"); + set_event(EVENT_CELL_DEVIATION_HIGH, 0); } #ifdef DEBUG_VIA_USB diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp index b65b71ec..d40f09cf 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp @@ -1,4 +1,5 @@ #include "RENAULT-ZOE-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -87,6 +88,7 @@ void update_values_zoe_battery() { //This function maps all the values fetched if (!CANstillAlive) { bms_status = FAULT; Serial.println("No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } @@ -94,14 +96,17 @@ void update_values_zoe_battery() { //This function maps all the values fetched if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) { bms_status = FAULT; Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_OVER_VOLTAGE, 0); } if (LB_Cell_Min_Voltage <= ABSOLUTE_CELL_MIN_VOLTAGE) { bms_status = FAULT; Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_UNDER_VOLTAGE, 0); } if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) { LEDcolor = YELLOW; Serial.println("ERROR: HIGH CELL mV DEVIATION!!! Inspect battery!"); + set_event(EVENT_CELL_DEVIATION_HIGH, 0); } #ifdef DEBUG_VIA_USB diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index 2959a684..e2aaa66f 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -1,4 +1,5 @@ #include "SANTA-FE-PHEV-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -84,6 +85,7 @@ void update_values_santafe_phev_battery() { //This function maps all the values if (!CANstillAlive) { bms_status = FAULT; Serial.println("No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp index 59aa7c18..fb05806a 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -1,4 +1,5 @@ #include "TESLA-MODEL-3-BATTERY.h" +#include "../devboard/utils/events.h" #include "../lib/miwagner-ESP32-Arduino-CAN/CAN_config.h" #include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" @@ -231,6 +232,7 @@ void update_values_tesla_model_3_battery() { //This function maps all the value if (!stillAliveCAN) { bms_status = FAULT; Serial.println("ERROR: No CAN communication detected for 60s. Shutting down battery control."); + set_event(EVENT_CAN_FAILURE, 0); } else { stillAliveCAN--; } @@ -238,6 +240,7 @@ void update_values_tesla_model_3_battery() { //This function maps all the value if (hvil_status == 3) { //INTERNAL_OPEN_FAULT - Someone disconnected a high voltage cable while battery was in use bms_status = FAULT; Serial.println("ERROR: High voltage cable removed while battery running. Opening contactors!"); + set_event(EVENT_INTERNAL_OPEN_FAULT, 0); } cell_deviation_mV = (cell_max_v - cell_min_v); @@ -258,12 +261,14 @@ void update_values_tesla_model_3_battery() { //This function maps all the value if (SOC < 6500) { //When SOC is less than 65.00% when approaching max voltage bms_status = FAULT; Serial.println("ERROR: SOC% reported by battery not plausible. Restart battery!"); + set_event(EVENT_SOC_PLAUSIBILITY_ERROR, SOC / 100); } } //Check if BMS is in need of recalibration if (nominal_full_pack_energy < REASONABLE_ENERGYAMOUNT) { Serial.println("Warning: kWh remaining reported by battery not plausible. Battery needs cycling."); + set_event(EVENT_KWH_PLAUSIBILITY_ERROR, nominal_full_pack_energy); LEDcolor = YELLOW; } @@ -271,27 +276,33 @@ void update_values_tesla_model_3_battery() { //This function maps all the value if (cell_max_v >= MAX_CELL_VOLTAGE_LFP) { bms_status = FAULT; Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_OVER_VOLTAGE, 0); } if (cell_min_v <= MIN_CELL_VOLTAGE_LFP) { bms_status = FAULT; Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_UNDER_VOLTAGE, 0); } if (cell_deviation_mV > MAX_CELL_DEVIATION_LFP) { LEDcolor = YELLOW; Serial.println("ERROR: HIGH CELL DEVIATION!!! Inspect battery!"); + set_event(EVENT_CELL_DEVIATION_HIGH, 0); } } else { //NCA/NCM limits used if (cell_max_v >= MAX_CELL_VOLTAGE_NCA_NCM) { bms_status = FAULT; Serial.println("ERROR: CELL OVERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_OVER_VOLTAGE, 0); } if (cell_min_v <= MIN_CELL_VOLTAGE_NCA_NCM) { bms_status = FAULT; Serial.println("ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"); + set_event(EVENT_CELL_UNDER_VOLTAGE, 0); } if (cell_deviation_mV > MAX_CELL_DEVIATION_NCA_NCM) { LEDcolor = YELLOW; Serial.println("ERROR: HIGH CELL DEVIATION!!! Inspect battery!"); + set_event(EVENT_CELL_DEVIATION_HIGH, 0); } }