max charge/discharge limit failures

This commit is contained in:
amarofarinha 2024-05-29 16:15:57 +01:00 committed by GitHub
parent 85285dcdd4
commit 5df42afbe7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2,6 +2,7 @@
#include "../utils/events.h"
static uint16_t cell_deviation_mV = 0;
static uint16_t charge_discharge_limit_failures = 0;
void update_machineryprotection() {
// Start checking that the battery is within reason. Incase we see any funny business, raise an event!
@ -52,18 +53,28 @@ void update_machineryprotection() {
// Inverter is charging with more power than battery wants!
if (datalayer.battery.status.active_power_W > 0) { // Charging
if (datalayer.battery.status.active_power_W > (datalayer.battery.status.max_charge_power_W + 2000)) {
set_event(EVENT_CHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
if (charge_discharge_limit_failures > MAX_CHARGE_DISCHARGE_LIMIT_FAILURES ) {
set_event(EVENT_CHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
} else {
charge_discharge_limit_failures++;
}
} else {
clear_event(EVENT_CHARGE_LIMIT_EXCEEDED);
charge_discharge_limit_failures = 0;
}
}
// Inverter is pulling too much power from battery!
if (datalayer.battery.status.active_power_W < 0) { // Discharging
if (-datalayer.battery.status.active_power_W > (datalayer.battery.status.max_discharge_power_W + 2000)) {
set_event(EVENT_DISCHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
if (charge_discharge_limit_failures > MAX_CHARGE_DISCHARGE_LIMIT_FAILURES ) {
set_event(EVENT_DISCHARGE_LIMIT_EXCEEDED, 0); // Alert when 2kW over requested max
} else {
charge_discharge_limit_failures++;
}
} else {
clear_event(EVENT_DISCHARGE_LIMIT_EXCEEDED);
charge_discharge_limit_failures = 0;
}
}