diff --git a/Software/Software.ino b/Software/Software.ino index 779b6aed..409c1f76 100644 --- a/Software/Software.ino +++ b/Software/Software.ino @@ -555,7 +555,7 @@ void handle_LED_state() { } else if (!rampUp && brightness == 0) { rampUp = true; } - switch (LEDcolor) { + switch (get_event_ledcolor()) { case GREEN: pixels.setPixelColor(0, pixels.Color(0, brightness, 0)); // Green pulsing LED break; @@ -575,12 +575,6 @@ void handle_LED_state() { break; } - // BMS in fault state overrides everything - if (bms_status == FAULT) { - LEDcolor = RED; - pixels.setPixelColor(0, pixels.Color(255, 0, 0)); // Red LED full brightness - } - pixels.show(); // This sends the updated pixel color to the hardware. } diff --git a/Software/src/battery/BMW-I3-BATTERY.cpp b/Software/src/battery/BMW-I3-BATTERY.cpp index 40acb0e2..3e0ffc95 100644 --- a/Software/src/battery/BMW-I3-BATTERY.cpp +++ b/Software/src/battery/BMW-I3-BATTERY.cpp @@ -102,8 +102,6 @@ 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) { - 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 84a3634d..225dc404 100644 --- a/Software/src/battery/CHADEMO-BATTERY.cpp +++ b/Software/src/battery/CHADEMO-BATTERY.cpp @@ -105,9 +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) { - 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 51ebdba9..585354c5 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.cpp @@ -108,8 +108,6 @@ 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) { - 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/IMIEV-CZERO-ION-BATTERY.h b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h index 0a2af171..39d367d9 100644 --- a/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h +++ b/Software/src/battery/IMIEV-CZERO-ION-BATTERY.h @@ -28,7 +28,6 @@ extern uint16_t cell_max_voltage; extern uint16_t cell_min_voltage; extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false -extern uint8_t LEDcolor; void update_values_imiev_battery(); void receive_can_imiev_battery(CAN_frame_t rx_frame); diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp index e1b27df7..0685131b 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.cpp @@ -199,22 +199,16 @@ 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) { - bms_status = FAULT; - Serial.println("No CAN communication detected for 60s. Shutting down battery control."); set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } 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); } @@ -222,18 +216,12 @@ void update_values_kiaHyundai_64_battery() { //This function maps all the value cell_deviation_mV = (cell_max_voltage - cell_min_voltage); 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); } diff --git a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h index 47d5e2ba..0a55d888 100644 --- a/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h +++ b/Software/src/battery/KIA-HYUNDAI-64-BATTERY.h @@ -20,14 +20,12 @@ extern uint16_t capacity_Wh; //Wh, 0-60000 extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 extern uint16_t max_target_discharge_power; //W, 0-60000 extern uint16_t max_target_charge_power; //W, 0-60000 -extern uint8_t bms_status; //Enum, 0-5 extern uint8_t bms_char_dis_status; //Enum, 0-2 extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 -extern uint8_t LEDcolor; //Enum, 0-10 extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false diff --git a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp index 835487ee..dadbc5b4 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.cpp +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.cpp @@ -259,10 +259,6 @@ void update_values_leaf_battery() { /* This function maps all the values fetched if (battery_voltage > (ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT if (LB_SOC < 650) { - bms_status = FAULT; -#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); } } @@ -308,30 +304,17 @@ void update_values_leaf_battery() { /* This function maps all the values fetched break; case (5): //Caution Lamp Request & Normal Stop Request - bms_status = FAULT; errorCode = 2; -#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 - bms_status = FAULT; errorCode = 3; -#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 - bms_status = FAULT; errorCode = 4; -#ifdef DEBUG_VIA_USB - 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: @@ -341,11 +324,6 @@ void update_values_leaf_battery() { /* This function maps all the values fetched if (LB_StateOfHealth < 25) { //Battery is extremely degraded, not fit for secondlifestorage. Zero it all out. if (LB_StateOfHealth != 0) { //Extra check to see that we actually have a SOH Value available -#ifdef DEBUG_VIA_USB - Serial.println( - "ERROR: State of health critically low. Battery internal resistance too high to continue. Recycle battery."); -#endif - bms_status = FAULT; errorCode = 5; set_event(EVENT_LOW_SOH, LB_StateOfHealth); max_target_discharge_power = 0; @@ -355,12 +333,6 @@ void update_values_leaf_battery() { /* This function maps all the values fetched #ifdef INTERLOCK_REQUIRED if (!LB_Interlock) { -#ifdef DEBUG_VIA_USB - Serial.println( - "ERROR: Battery interlock loop broken. Check that high voltage connectors are seated. Battery will be " - "disabled!"); -#endif - bms_status = FAULT; set_event(EVENT_HVIL_FAILURE, 0); errorCode = 6; SOC = 0; @@ -371,11 +343,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) { - bms_status = FAULT; errorCode = 7; -#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--; @@ -384,10 +352,6 @@ 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; - LEDcolor = YELLOW; -#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); } @@ -620,27 +584,15 @@ void receive_can_leaf_battery(CAN_frame_t rx_frame) { cell_min_voltage = min_max_voltage[0]; if (cell_deviation_mV > MAX_CELL_DEVIATION) { - LEDcolor = YELLOW; -#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) { - bms_status = FAULT; errorCode = 8; -#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; errorCode = 9; -#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/NISSAN-LEAF-BATTERY.h b/Software/src/battery/NISSAN-LEAF-BATTERY.h index fa88a959..34fdf23d 100644 --- a/Software/src/battery/NISSAN-LEAF-BATTERY.h +++ b/Software/src/battery/NISSAN-LEAF-BATTERY.h @@ -18,14 +18,12 @@ extern uint16_t capacity_Wh; //Wh, 0-60000 extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 extern uint16_t max_target_discharge_power; //W, 0-60000 extern uint16_t max_target_charge_power; //W, 0-60000 -extern uint8_t bms_status; //Enum, 0-5 extern uint8_t bms_char_dis_status; //Enum, 0-2 extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 -extern uint8_t LEDcolor; //Enum, 0-10 extern uint16_t cellvoltages[120]; //mV 0-4350 per cell extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp index 47ab1f64..1657e73f 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.cpp @@ -125,26 +125,18 @@ 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) { - bms_status = FAULT; - Serial.println("No CAN communication detected for 60s. Shutting down battery control."); set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } 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); } diff --git a/Software/src/battery/RENAULT-KANGOO-BATTERY.h b/Software/src/battery/RENAULT-KANGOO-BATTERY.h index 973c3df8..105f60a9 100644 --- a/Software/src/battery/RENAULT-KANGOO-BATTERY.h +++ b/Software/src/battery/RENAULT-KANGOO-BATTERY.h @@ -23,7 +23,6 @@ extern uint16_t capacity_Wh; //Wh, 0-60000 extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 extern uint16_t max_target_discharge_power; //W, 0-60000 extern uint16_t max_target_charge_power; //W, 0-60000 -extern uint8_t bms_status; //Enum, 0-5 extern uint8_t bms_char_dis_status; //Enum, 0-2 extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) @@ -31,7 +30,6 @@ extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 funct extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 extern uint16_t CANerror; -extern uint8_t LEDcolor; //Enum, 0-10 extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp index d40f09cf..b69ebbf4 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.cpp +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.cpp @@ -86,26 +86,18 @@ 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) { - bms_status = FAULT; - Serial.println("No CAN communication detected for 60s. Shutting down battery control."); set_event(EVENT_CAN_FAILURE, 0); } else { CANstillAlive--; } 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); } diff --git a/Software/src/battery/RENAULT-ZOE-BATTERY.h b/Software/src/battery/RENAULT-ZOE-BATTERY.h index aa45054f..7a2e46c4 100644 --- a/Software/src/battery/RENAULT-ZOE-BATTERY.h +++ b/Software/src/battery/RENAULT-ZOE-BATTERY.h @@ -23,7 +23,6 @@ extern uint16_t capacity_Wh; //Wh, 0-60000 extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 extern uint16_t max_target_discharge_power; //W, 0-60000 extern uint16_t max_target_charge_power; //W, 0-60000 -extern uint8_t bms_status; //Enum, 0-5 extern uint8_t bms_char_dis_status; //Enum, 0-2 extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) @@ -31,7 +30,6 @@ extern uint16_t temperature_max; //C+1, Goes thru convert2unsignedint16 funct extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 extern uint16_t CANerror; -extern uint8_t LEDcolor; //Enum, 0-10 extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false diff --git a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp index e2aaa66f..ba1417c3 100644 --- a/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp +++ b/Software/src/battery/SANTA-FE-PHEV-BATTERY.cpp @@ -83,8 +83,6 @@ 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) { - 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 fb05806a..0c03307e 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.cpp @@ -230,16 +230,12 @@ 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) { - bms_status = FAULT; - Serial.println("ERROR: No CAN communication detected for 60s. Shutting down battery control."); set_event(EVENT_CAN_FAILURE, 0); } else { stillAliveCAN--; } 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); } @@ -259,49 +255,33 @@ void update_values_tesla_model_3_battery() { //This function maps all the value if (battery_voltage > (ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT 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; } if (LFP_Chemistry) { //LFP limits used for voltage safeties 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); } } diff --git a/Software/src/battery/TESLA-MODEL-3-BATTERY.h b/Software/src/battery/TESLA-MODEL-3-BATTERY.h index a10d6cc7..ed2ba9c1 100644 --- a/Software/src/battery/TESLA-MODEL-3-BATTERY.h +++ b/Software/src/battery/TESLA-MODEL-3-BATTERY.h @@ -21,7 +21,6 @@ extern uint16_t capacity_Wh; //Wh, 0-60000 extern uint16_t remaining_capacity_Wh; //Wh, 0-60000 extern uint16_t max_target_discharge_power; //W, 0-60000 extern uint16_t max_target_charge_power; //W, 0-60000 -extern uint8_t bms_status; //Enum, 0-5 extern uint8_t bms_char_dis_status; //Enum, 0-2 extern uint16_t stat_batt_power; //W, Goes thru convert2unsignedint16 function (5W = 5, -5W = 65530) extern uint16_t temperature_min; //C+1, Goes thru convert2unsignedint16 function (15.0C = 150, -15.0C = 65385) @@ -30,7 +29,6 @@ extern uint16_t cell_max_voltage; //mV, 0-4350 extern uint16_t cell_min_voltage; //mV, 0-4350 extern uint16_t cellvoltages[120]; //mV 0-4350 per cell extern uint8_t nof_cellvoltages; // Total number of cell voltages, set by each battery. -extern uint8_t LEDcolor; //Enum, 0-10 extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false extern bool LFP_Chemistry; diff --git a/Software/src/devboard/config.h b/Software/src/devboard/config.h index 04f12822..ff4b2f7b 100644 --- a/Software/src/devboard/config.h +++ b/Software/src/devboard/config.h @@ -32,11 +32,11 @@ #define SD_CS_PIN 13 #define WS2812_PIN 4 -// LED definitions for the board +// LED definitions for the board, in order of "priority", DONT CHANGE! #define GREEN 0 #define YELLOW 1 -#define RED 2 -#define BLUE 3 +#define BLUE 2 +#define RED 3 #define TEST_ALL_COLORS 10 // Inverter definitions diff --git a/Software/src/devboard/utils/events.cpp b/Software/src/devboard/utils/events.cpp index bbdf51ea..48f3ef96 100644 --- a/Software/src/devboard/utils/events.cpp +++ b/Software/src/devboard/utils/events.cpp @@ -39,6 +39,9 @@ void init_events(void) { entries[EVENT_CAN_WARNING].led_color = YELLOW; entries[EVENT_CELL_DEVIATION_HIGH].led_color = YELLOW; entries[EVENT_KWH_PLAUSIBILITY_ERROR].led_color = YELLOW; + + // BLUE... + entries[EVENT_OTA_UPDATE].led_color = BLUE; } void set_event(EVENTS_ENUM_TYPE event, uint8_t data) { @@ -48,12 +51,25 @@ void set_event(EVENTS_ENUM_TYPE event, uint8_t data) { entries[event].timestamp = time_seconds; entries[event].data = data; entries[event].occurences++; + + update_led_color(event); + + if (total_led_color == RED) { + bms_status = FAULT; + } else if (total_led_color) { + bms_status = UPDATING; + } + set_event_message(event); #ifdef DEBUG_VIA_USB Serial.println(event_message); #endif } +uint8_t get_event_ledcolor(void) { + return total_led_color; +} + /* Local functions */ static void update_event_time(void) { unsigned long new_millis = millis(); @@ -64,7 +80,7 @@ static void update_event_time(void) { } static void update_led_color(EVENTS_ENUM_TYPE event) { - total_led_color = (total_led_color == RED) ? RED : entries[event].led_color; + total_led_color = max(total_led_color, entries[event].led_color); } static void set_event_message(EVENTS_ENUM_TYPE event) { @@ -132,6 +148,9 @@ static void set_event_message(EVENTS_ENUM_TYPE event) { case EVENT_UNKNOWN_EVENT_SET: snprintf(event_message, sizeof(event_message), "An unknown event was set! Review your code!"); break; + case EVENT_OTA_UPDATE: + snprintf(event_message, sizeof(event_message), "OTA update started!"); + break; case EVENT_DUMMY: snprintf(event_message, sizeof(event_message), "The dummy event was set!"); // Don't change this event message! break; diff --git a/Software/src/devboard/utils/events.h b/Software/src/devboard/utils/events.h index 1b2daf5f..8c1345da 100644 --- a/Software/src/devboard/utils/events.h +++ b/Software/src/devboard/utils/events.h @@ -24,6 +24,7 @@ typedef enum { EVENT_CELL_OVER_VOLTAGE, EVENT_CELL_DEVIATION_HIGH, EVENT_UNKNOWN_EVENT_SET, + EVENT_OTA_UPDATE, EVENT_DUMMY, EVENT_NOF_EVENTS } EVENTS_ENUM_TYPE; @@ -31,5 +32,8 @@ typedef enum { void init_events(void); void set_event(EVENTS_ENUM_TYPE event, uint8_t data); void run_event_handling(void); +uint8_t get_event_ledcolor(void); + +extern uint8_t bms_status; //Enum, 0-5 #endif // __MYTIMER_H__ diff --git a/Software/src/devboard/webserver/webserver.cpp b/Software/src/devboard/webserver/webserver.cpp index 039257a6..73324752 100644 --- a/Software/src/devboard/webserver/webserver.cpp +++ b/Software/src/devboard/webserver/webserver.cpp @@ -1,5 +1,6 @@ #include "webserver.h" #include +#include "../utils/events.h" Preferences preferences3; @@ -927,15 +928,11 @@ String cellmonitor_processor(const String& var) { void onOTAStart() { // Log when OTA has started - Serial.println("OTA update started!"); ESP32Can.CANStop(); - bms_status = UPDATING; //Inform inverter that we are updating - LEDcolor = BLUE; + set_event(EVENT_OTA_UPDATE, 0); } void onOTAProgress(size_t current, size_t final) { - bms_status = UPDATING; //Inform inverter that we are updating - LEDcolor = BLUE; // Log every 1 second if (millis() - ota_progress_millis > 1000) { ota_progress_millis = millis(); @@ -950,8 +947,6 @@ void onOTAEnd(bool success) { } else { Serial.println("There was an error during OTA update!"); } - bms_status = UPDATING; //Inform inverter that we are updating - LEDcolor = BLUE; } template // This function makes power values appear as W when under 1000, and kW when over diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6d63e2e3..76cde93f 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,5 +1,5 @@ # Include the directory with your source files -include_directories(${CMAKE_SOURCE_DIR}/Software/src/devboard/utils .) +include_directories(${CMAKE_SOURCE_DIR}/Software/src/devboard ${CMAKE_SOURCE_DIR}/Software/src/devboard/utils . ) # Create a variable to store the list of test files file(GLOB TEST_SOURCES utils/*.cpp) diff --git a/test/microtest.h b/test/microtest.h index 36c73aa1..8814cd18 100644 --- a/test/microtest.h +++ b/test/microtest.h @@ -201,7 +201,7 @@ class Runtime { return 0; \ } else { \ double percentage = 100.0 * num_failed / mt::TestsManager::tests().size(); \ - fprintf(stderr, "%s{ summary} %lu tests failed (%.2f%%)%s\n", mt::red(), num_failed, percentage, mt::def()); \ + fprintf(stderr, "%s{ summary} %zu tests failed (%.2f%%)%s\n", mt::red(), num_failed, percentage, mt::def()); \ return -1; \ } \ } diff --git a/test/test_lib.cpp b/test/test_lib.cpp index 8ed9c2f5..0d28b92e 100644 --- a/test/test_lib.cpp +++ b/test/test_lib.cpp @@ -1,6 +1,11 @@ #include "test_lib.h" + #include +#include "config.h" + MySerial Serial; unsigned long testlib_millis = 0; + +uint8_t bms_status = ACTIVE; diff --git a/test/test_lib.h b/test/test_lib.h index ccca3ca4..b2819503 100644 --- a/test/test_lib.h +++ b/test/test_lib.h @@ -2,14 +2,20 @@ #define __TEST_LIB_H__ #include +#include #include #include +#include "config.h" #include "microtest.h" +using namespace std; + class MySerial; extern unsigned long testlib_millis; +extern MySerial Serial; +extern uint8_t bms_status; /* Mock millis() */ static inline unsigned long millis(void) { @@ -38,6 +44,4 @@ class MySerial { } }; -extern MySerial Serial; - #endif diff --git a/test/utils/events_test.cpp b/test/utils/events_test.cpp index 1afae2ed..bf1413ee 100644 --- a/test/utils/events_test.cpp +++ b/test/utils/events_test.cpp @@ -58,13 +58,14 @@ TEST(set_event_test) { ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].data, 0); ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].occurences, 0); ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 0); - // Set current time and overvoltage event for cell 23 + // Set current time and overvoltage event for cell 23 (RED color, bms_status == FAULT) time_seconds = 345; set_event(EVENT_CELL_OVER_VOLTAGE, 123); // Ensure proper event data ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].data, 123); ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].occurences, 1); ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 345); + ASSERT_EQ(bms_status, FAULT); } TEST(event_message_test) {