mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 10:49:42 +02:00
Event cleanup
This commit is contained in:
parent
32378df03e
commit
b528c8917f
25 changed files with 45 additions and 138 deletions
|
@ -555,7 +555,7 @@ void handle_LED_state() {
|
||||||
} else if (!rampUp && brightness == 0) {
|
} else if (!rampUp && brightness == 0) {
|
||||||
rampUp = true;
|
rampUp = true;
|
||||||
}
|
}
|
||||||
switch (LEDcolor) {
|
switch (get_event_ledcolor()) {
|
||||||
case GREEN:
|
case GREEN:
|
||||||
pixels.setPixelColor(0, pixels.Color(0, brightness, 0)); // Green pulsing LED
|
pixels.setPixelColor(0, pixels.Color(0, brightness, 0)); // Green pulsing LED
|
||||||
break;
|
break;
|
||||||
|
@ -575,12 +575,6 @@ void handle_LED_state() {
|
||||||
break;
|
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.
|
pixels.show(); // This sends the updated pixel color to the hardware.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
CANstillAlive--;
|
||||||
|
|
|
@ -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*/
|
/* Check if the Vehicle is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
errorCode = 7;
|
errorCode = 7;
|
||||||
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
CANstillAlive--;
|
||||||
|
|
|
@ -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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
CANstillAlive--;
|
||||||
|
|
|
@ -28,7 +28,6 @@ extern uint16_t cell_max_voltage;
|
||||||
extern uint16_t cell_min_voltage;
|
extern uint16_t cell_min_voltage;
|
||||||
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern uint8_t LEDcolor;
|
|
||||||
|
|
||||||
void update_values_imiev_battery();
|
void update_values_imiev_battery();
|
||||||
void receive_can_imiev_battery(CAN_frame_t rx_frame);
|
void receive_can_imiev_battery(CAN_frame_t rx_frame);
|
||||||
|
|
|
@ -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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
CANstillAlive--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waterleakageSensor == 0) {
|
if (waterleakageSensor == 0) {
|
||||||
Serial.println("Water leakage inside battery detected. Operation halted. Inspect battery!");
|
|
||||||
bms_status = FAULT;
|
|
||||||
set_event(EVENT_WATER_INGRESS, 0);
|
set_event(EVENT_WATER_INGRESS, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (leadAcidBatteryVoltage < 110) {
|
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);
|
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);
|
cell_deviation_mV = (cell_max_voltage - cell_min_voltage);
|
||||||
|
|
||||||
if (cell_max_voltage >= MAX_CELL_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);
|
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_min_voltage <= MIN_CELL_VOLTAGE) {
|
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);
|
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_deviation_mV > MAX_CELL_DEVIATION) {
|
if (cell_deviation_mV > MAX_CELL_DEVIATION) {
|
||||||
LEDcolor = YELLOW;
|
|
||||||
Serial.println("ERROR: HIGH CELL DEVIATION!!! Inspect battery!");
|
|
||||||
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
|
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -20,14 +20,12 @@ extern uint16_t capacity_Wh; //Wh, 0-60000
|
||||||
extern uint16_t remaining_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_discharge_power; //W, 0-60000
|
||||||
extern uint16_t max_target_charge_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 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 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_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 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_max_voltage; //mV, 0-4350
|
||||||
extern uint16_t cell_min_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 batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
|
||||||
|
|
|
@ -259,10 +259,6 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
|
||||||
if (battery_voltage >
|
if (battery_voltage >
|
||||||
(ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
|
(ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
|
||||||
if (LB_SOC < 650) {
|
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);
|
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;
|
break;
|
||||||
case (5):
|
case (5):
|
||||||
//Caution Lamp Request & Normal Stop Request
|
//Caution Lamp Request & Normal Stop Request
|
||||||
bms_status = FAULT;
|
|
||||||
errorCode = 2;
|
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);
|
set_event(EVENT_BATTERY_DISCHG_STOP_REQ, 0);
|
||||||
break;
|
break;
|
||||||
case (6):
|
case (6):
|
||||||
//Caution Lamp Request & Charging Mode Stop Request
|
//Caution Lamp Request & Charging Mode Stop Request
|
||||||
bms_status = FAULT;
|
|
||||||
errorCode = 3;
|
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);
|
set_event(EVENT_BATTERY_CHG_STOP_REQ, 0);
|
||||||
break;
|
break;
|
||||||
case (7):
|
case (7):
|
||||||
//Caution Lamp Request & Charging Mode Stop Request & Normal Stop Request
|
//Caution Lamp Request & Charging Mode Stop Request & Normal Stop Request
|
||||||
bms_status = FAULT;
|
|
||||||
errorCode = 4;
|
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);
|
set_event(EVENT_BATTERY_CHG_DISCHG_STOP_REQ, 0);
|
||||||
break;
|
break;
|
||||||
default:
|
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 < 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
|
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;
|
errorCode = 5;
|
||||||
set_event(EVENT_LOW_SOH, LB_StateOfHealth);
|
set_event(EVENT_LOW_SOH, LB_StateOfHealth);
|
||||||
max_target_discharge_power = 0;
|
max_target_discharge_power = 0;
|
||||||
|
@ -355,12 +333,6 @@ void update_values_leaf_battery() { /* This function maps all the values fetched
|
||||||
|
|
||||||
#ifdef INTERLOCK_REQUIRED
|
#ifdef INTERLOCK_REQUIRED
|
||||||
if (!LB_Interlock) {
|
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);
|
set_event(EVENT_HVIL_FAILURE, 0);
|
||||||
errorCode = 6;
|
errorCode = 6;
|
||||||
SOC = 0;
|
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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
errorCode = 7;
|
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);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
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
|
MAX_CAN_FAILURES) //Also check if we have recieved too many malformed CAN messages. If so, signal via LED
|
||||||
{
|
{
|
||||||
errorCode = 10;
|
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);
|
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];
|
cell_min_voltage = min_max_voltage[0];
|
||||||
|
|
||||||
if (cell_deviation_mV > MAX_CELL_DEVIATION) {
|
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);
|
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (min_max_voltage[1] >= MAX_CELL_VOLTAGE) {
|
if (min_max_voltage[1] >= MAX_CELL_VOLTAGE) {
|
||||||
bms_status = FAULT;
|
|
||||||
errorCode = 8;
|
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);
|
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (min_max_voltage[0] <= MIN_CELL_VOLTAGE) {
|
if (min_max_voltage[0] <= MIN_CELL_VOLTAGE) {
|
||||||
bms_status = FAULT;
|
|
||||||
errorCode = 9;
|
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);
|
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -18,14 +18,12 @@ extern uint16_t capacity_Wh; //Wh, 0-60000
|
||||||
extern uint16_t remaining_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_discharge_power; //W, 0-60000
|
||||||
extern uint16_t max_target_charge_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 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 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_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 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_max_voltage; //mV, 0-4350
|
||||||
extern uint16_t cell_min_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 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 nof_cellvoltages; // Total number of cell voltages, set by each battery.
|
||||||
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
|
|
@ -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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
CANstillAlive--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) {
|
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);
|
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (LB_Cell_Min_Voltage <= ABSOLUTE_CELL_MIN_VOLTAGE) {
|
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);
|
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) {
|
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);
|
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ extern uint16_t capacity_Wh; //Wh, 0-60000
|
||||||
extern uint16_t remaining_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_discharge_power; //W, 0-60000
|
||||||
extern uint16_t max_target_charge_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 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 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_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_max_voltage; //mV, 0-4350
|
||||||
extern uint16_t cell_min_voltage; //mV, 0-4350
|
extern uint16_t cell_min_voltage; //mV, 0-4350
|
||||||
extern uint16_t CANerror;
|
extern uint16_t CANerror;
|
||||||
extern uint8_t LEDcolor; //Enum, 0-10
|
|
||||||
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
|
||||||
|
|
|
@ -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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
CANstillAlive--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LB_Cell_Max_Voltage >= ABSOLUTE_CELL_MAX_VOLTAGE) {
|
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);
|
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (LB_Cell_Min_Voltage <= ABSOLUTE_CELL_MIN_VOLTAGE) {
|
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);
|
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_deviation_mV > MAX_CELL_DEVIATION_MV) {
|
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);
|
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,7 +23,6 @@ extern uint16_t capacity_Wh; //Wh, 0-60000
|
||||||
extern uint16_t remaining_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_discharge_power; //W, 0-60000
|
||||||
extern uint16_t max_target_charge_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 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 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_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_max_voltage; //mV, 0-4350
|
||||||
extern uint16_t cell_min_voltage; //mV, 0-4350
|
extern uint16_t cell_min_voltage; //mV, 0-4350
|
||||||
extern uint16_t CANerror;
|
extern uint16_t CANerror;
|
||||||
extern uint8_t LEDcolor; //Enum, 0-10
|
|
||||||
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
|
|
||||||
|
|
|
@ -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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!CANstillAlive) {
|
if (!CANstillAlive) {
|
||||||
bms_status = FAULT;
|
|
||||||
Serial.println("No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
CANstillAlive--;
|
CANstillAlive--;
|
||||||
|
|
|
@ -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*/
|
/* Check if the BMS is still sending CAN messages. If we go 60s without messages we raise an error*/
|
||||||
if (!stillAliveCAN) {
|
if (!stillAliveCAN) {
|
||||||
bms_status = FAULT;
|
|
||||||
Serial.println("ERROR: No CAN communication detected for 60s. Shutting down battery control.");
|
|
||||||
set_event(EVENT_CAN_FAILURE, 0);
|
set_event(EVENT_CAN_FAILURE, 0);
|
||||||
} else {
|
} else {
|
||||||
stillAliveCAN--;
|
stillAliveCAN--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hvil_status == 3) { //INTERNAL_OPEN_FAULT - Someone disconnected a high voltage cable while battery was in use
|
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);
|
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 >
|
if (battery_voltage >
|
||||||
(ABSOLUTE_MAX_VOLTAGE - 100)) { // When pack voltage is close to max, and SOC% is still low, raise FAULT
|
(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
|
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);
|
set_event(EVENT_SOC_PLAUSIBILITY_ERROR, SOC / 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check if BMS is in need of recalibration
|
//Check if BMS is in need of recalibration
|
||||||
if (nominal_full_pack_energy < REASONABLE_ENERGYAMOUNT) {
|
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);
|
set_event(EVENT_KWH_PLAUSIBILITY_ERROR, nominal_full_pack_energy);
|
||||||
LEDcolor = YELLOW;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LFP_Chemistry) { //LFP limits used for voltage safeties
|
if (LFP_Chemistry) { //LFP limits used for voltage safeties
|
||||||
if (cell_max_v >= MAX_CELL_VOLTAGE_LFP) {
|
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);
|
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_min_v <= MIN_CELL_VOLTAGE_LFP) {
|
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);
|
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_deviation_mV > MAX_CELL_DEVIATION_LFP) {
|
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);
|
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
|
||||||
}
|
}
|
||||||
} else { //NCA/NCM limits used
|
} else { //NCA/NCM limits used
|
||||||
if (cell_max_v >= MAX_CELL_VOLTAGE_NCA_NCM) {
|
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);
|
set_event(EVENT_CELL_OVER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_min_v <= MIN_CELL_VOLTAGE_NCA_NCM) {
|
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);
|
set_event(EVENT_CELL_UNDER_VOLTAGE, 0);
|
||||||
}
|
}
|
||||||
if (cell_deviation_mV > MAX_CELL_DEVIATION_NCA_NCM) {
|
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);
|
set_event(EVENT_CELL_DEVIATION_HIGH, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,6 @@ extern uint16_t capacity_Wh; //Wh, 0-60000
|
||||||
extern uint16_t remaining_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_discharge_power; //W, 0-60000
|
||||||
extern uint16_t max_target_charge_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 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 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_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 cell_min_voltage; //mV, 0-4350
|
||||||
extern uint16_t cellvoltages[120]; //mV 0-4350 per cell
|
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 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 batteryAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
extern bool inverterAllowsContactorClosing; //Bool, 1=true, 0=false
|
||||||
extern bool LFP_Chemistry;
|
extern bool LFP_Chemistry;
|
||||||
|
|
|
@ -32,11 +32,11 @@
|
||||||
#define SD_CS_PIN 13
|
#define SD_CS_PIN 13
|
||||||
#define WS2812_PIN 4
|
#define WS2812_PIN 4
|
||||||
|
|
||||||
// LED definitions for the board
|
// LED definitions for the board, in order of "priority", DONT CHANGE!
|
||||||
#define GREEN 0
|
#define GREEN 0
|
||||||
#define YELLOW 1
|
#define YELLOW 1
|
||||||
#define RED 2
|
#define BLUE 2
|
||||||
#define BLUE 3
|
#define RED 3
|
||||||
#define TEST_ALL_COLORS 10
|
#define TEST_ALL_COLORS 10
|
||||||
|
|
||||||
// Inverter definitions
|
// Inverter definitions
|
||||||
|
|
|
@ -39,6 +39,9 @@ void init_events(void) {
|
||||||
entries[EVENT_CAN_WARNING].led_color = YELLOW;
|
entries[EVENT_CAN_WARNING].led_color = YELLOW;
|
||||||
entries[EVENT_CELL_DEVIATION_HIGH].led_color = YELLOW;
|
entries[EVENT_CELL_DEVIATION_HIGH].led_color = YELLOW;
|
||||||
entries[EVENT_KWH_PLAUSIBILITY_ERROR].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) {
|
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].timestamp = time_seconds;
|
||||||
entries[event].data = data;
|
entries[event].data = data;
|
||||||
entries[event].occurences++;
|
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);
|
set_event_message(event);
|
||||||
#ifdef DEBUG_VIA_USB
|
#ifdef DEBUG_VIA_USB
|
||||||
Serial.println(event_message);
|
Serial.println(event_message);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t get_event_ledcolor(void) {
|
||||||
|
return total_led_color;
|
||||||
|
}
|
||||||
|
|
||||||
/* Local functions */
|
/* Local functions */
|
||||||
static void update_event_time(void) {
|
static void update_event_time(void) {
|
||||||
unsigned long new_millis = millis();
|
unsigned long new_millis = millis();
|
||||||
|
@ -64,7 +80,7 @@ static void update_event_time(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static void update_led_color(EVENTS_ENUM_TYPE event) {
|
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) {
|
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:
|
case EVENT_UNKNOWN_EVENT_SET:
|
||||||
snprintf(event_message, sizeof(event_message), "An unknown event was set! Review your code!");
|
snprintf(event_message, sizeof(event_message), "An unknown event was set! Review your code!");
|
||||||
break;
|
break;
|
||||||
|
case EVENT_OTA_UPDATE:
|
||||||
|
snprintf(event_message, sizeof(event_message), "OTA update started!");
|
||||||
|
break;
|
||||||
case EVENT_DUMMY:
|
case EVENT_DUMMY:
|
||||||
snprintf(event_message, sizeof(event_message), "The dummy event was set!"); // Don't change this event message!
|
snprintf(event_message, sizeof(event_message), "The dummy event was set!"); // Don't change this event message!
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -24,6 +24,7 @@ typedef enum {
|
||||||
EVENT_CELL_OVER_VOLTAGE,
|
EVENT_CELL_OVER_VOLTAGE,
|
||||||
EVENT_CELL_DEVIATION_HIGH,
|
EVENT_CELL_DEVIATION_HIGH,
|
||||||
EVENT_UNKNOWN_EVENT_SET,
|
EVENT_UNKNOWN_EVENT_SET,
|
||||||
|
EVENT_OTA_UPDATE,
|
||||||
EVENT_DUMMY,
|
EVENT_DUMMY,
|
||||||
EVENT_NOF_EVENTS
|
EVENT_NOF_EVENTS
|
||||||
} EVENTS_ENUM_TYPE;
|
} EVENTS_ENUM_TYPE;
|
||||||
|
@ -31,5 +32,8 @@ typedef enum {
|
||||||
void init_events(void);
|
void init_events(void);
|
||||||
void set_event(EVENTS_ENUM_TYPE event, uint8_t data);
|
void set_event(EVENTS_ENUM_TYPE event, uint8_t data);
|
||||||
void run_event_handling(void);
|
void run_event_handling(void);
|
||||||
|
uint8_t get_event_ledcolor(void);
|
||||||
|
|
||||||
|
extern uint8_t bms_status; //Enum, 0-5
|
||||||
|
|
||||||
#endif // __MYTIMER_H__
|
#endif // __MYTIMER_H__
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "webserver.h"
|
#include "webserver.h"
|
||||||
#include <Preferences.h>
|
#include <Preferences.h>
|
||||||
|
#include "../utils/events.h"
|
||||||
|
|
||||||
Preferences preferences3;
|
Preferences preferences3;
|
||||||
|
|
||||||
|
@ -927,15 +928,11 @@ String cellmonitor_processor(const String& var) {
|
||||||
|
|
||||||
void onOTAStart() {
|
void onOTAStart() {
|
||||||
// Log when OTA has started
|
// Log when OTA has started
|
||||||
Serial.println("OTA update started!");
|
|
||||||
ESP32Can.CANStop();
|
ESP32Can.CANStop();
|
||||||
bms_status = UPDATING; //Inform inverter that we are updating
|
set_event(EVENT_OTA_UPDATE, 0);
|
||||||
LEDcolor = BLUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void onOTAProgress(size_t current, size_t final) {
|
void onOTAProgress(size_t current, size_t final) {
|
||||||
bms_status = UPDATING; //Inform inverter that we are updating
|
|
||||||
LEDcolor = BLUE;
|
|
||||||
// Log every 1 second
|
// Log every 1 second
|
||||||
if (millis() - ota_progress_millis > 1000) {
|
if (millis() - ota_progress_millis > 1000) {
|
||||||
ota_progress_millis = millis();
|
ota_progress_millis = millis();
|
||||||
|
@ -950,8 +947,6 @@ void onOTAEnd(bool success) {
|
||||||
} else {
|
} else {
|
||||||
Serial.println("There was an error during OTA update!");
|
Serial.println("There was an error during OTA update!");
|
||||||
}
|
}
|
||||||
bms_status = UPDATING; //Inform inverter that we are updating
|
|
||||||
LEDcolor = BLUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T> // This function makes power values appear as W when under 1000, and kW when over
|
template <typename T> // This function makes power values appear as W when under 1000, and kW when over
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
# Include the directory with your source files
|
# 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
|
# Create a variable to store the list of test files
|
||||||
file(GLOB TEST_SOURCES utils/*.cpp)
|
file(GLOB TEST_SOURCES utils/*.cpp)
|
||||||
|
|
|
@ -201,7 +201,7 @@ class Runtime {
|
||||||
return 0; \
|
return 0; \
|
||||||
} else { \
|
} else { \
|
||||||
double percentage = 100.0 * num_failed / mt::TestsManager::tests().size(); \
|
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; \
|
return -1; \
|
||||||
} \
|
} \
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,11 @@
|
||||||
#include "test_lib.h"
|
#include "test_lib.h"
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
MySerial Serial;
|
MySerial Serial;
|
||||||
|
|
||||||
unsigned long testlib_millis = 0;
|
unsigned long testlib_millis = 0;
|
||||||
|
|
||||||
|
uint8_t bms_status = ACTIVE;
|
||||||
|
|
|
@ -2,14 +2,20 @@
|
||||||
#define __TEST_LIB_H__
|
#define __TEST_LIB_H__
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
#include <algorithm>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
#include "microtest.h"
|
#include "microtest.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
class MySerial;
|
class MySerial;
|
||||||
|
|
||||||
extern unsigned long testlib_millis;
|
extern unsigned long testlib_millis;
|
||||||
|
extern MySerial Serial;
|
||||||
|
extern uint8_t bms_status;
|
||||||
|
|
||||||
/* Mock millis() */
|
/* Mock millis() */
|
||||||
static inline unsigned long millis(void) {
|
static inline unsigned long millis(void) {
|
||||||
|
@ -38,6 +44,4 @@ class MySerial {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
extern MySerial Serial;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -58,13 +58,14 @@ TEST(set_event_test) {
|
||||||
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].data, 0);
|
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].occurences, 0);
|
||||||
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 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;
|
time_seconds = 345;
|
||||||
set_event(EVENT_CELL_OVER_VOLTAGE, 123);
|
set_event(EVENT_CELL_OVER_VOLTAGE, 123);
|
||||||
// Ensure proper event data
|
// Ensure proper event data
|
||||||
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].data, 123);
|
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].occurences, 1);
|
||||||
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 345);
|
ASSERT_EQ(entries[EVENT_CELL_OVER_VOLTAGE].timestamp, 345);
|
||||||
|
ASSERT_EQ(bms_status, FAULT);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(event_message_test) {
|
TEST(event_message_test) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue