diff --git a/Software/src/devboard/utils/events.cpp b/Software/src/devboard/utils/events.cpp index e40fb218..8f9eb299 100644 --- a/Software/src/devboard/utils/events.cpp +++ b/Software/src/devboard/utils/events.cpp @@ -153,6 +153,7 @@ void init_events(void) { events.entries[EVENT_PRECHARGE_FAILURE].level = EVENT_LEVEL_INFO; events.entries[EVENT_INTERNAL_OPEN_FAULT].level = EVENT_LEVEL_ERROR; events.entries[EVENT_INVERTER_OPEN_CONTACTOR].level = EVENT_LEVEL_INFO; + events.entries[EVENT_MODBUS_INVERTER_MISSING].level = EVENT_LEVEL_INFO; events.entries[EVENT_ERROR_OPEN_CONTACTOR].level = EVENT_LEVEL_INFO; events.entries[EVENT_CELL_UNDER_VOLTAGE].level = EVENT_LEVEL_ERROR; events.entries[EVENT_CELL_OVER_VOLTAGE].level = EVENT_LEVEL_ERROR; @@ -247,6 +248,8 @@ const char* get_event_message_string(EVENTS_ENUM_TYPE event) { case EVENT_ERROR_OPEN_CONTACTOR: return "Info: Too much time spent in error state. Opening contactors, not safe to continue charging. " "Check other error code for reason!"; + case EVENT_MODBUS_INVERTER_MISSING: + return "Info: Modbus inverter has not sent any data. Inspect communication wiring!"; case EVENT_CELL_UNDER_VOLTAGE: return "ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!"; case EVENT_CELL_OVER_VOLTAGE: diff --git a/Software/src/devboard/utils/events.h b/Software/src/devboard/utils/events.h index ae2ff9e9..16e66365 100644 --- a/Software/src/devboard/utils/events.h +++ b/Software/src/devboard/utils/events.h @@ -6,7 +6,7 @@ // #define INCLUDE_EVENTS_TEST // Enable to run an event test loop, see events_test_on_target.cpp -#define EE_MAGIC_HEADER_VALUE 0x0004 // 0x0000 to 0xFFFF +#define EE_MAGIC_HEADER_VALUE 0x0005 // 0x0000 to 0xFFFF #define GENERATE_ENUM(ENUM) ENUM, #define GENERATE_STRING(STRING) #STRING, @@ -49,6 +49,7 @@ XX(EVENT_PRECHARGE_FAILURE) \ XX(EVENT_INTERNAL_OPEN_FAULT) \ XX(EVENT_INVERTER_OPEN_CONTACTOR) \ + XX(EVENT_MODBUS_INVERTER_MISSING) \ XX(EVENT_ERROR_OPEN_CONTACTOR) \ XX(EVENT_CELL_UNDER_VOLTAGE) \ XX(EVENT_CELL_OVER_VOLTAGE) \ diff --git a/Software/src/inverter/BYD-MODBUS.cpp b/Software/src/inverter/BYD-MODBUS.cpp index b92b6254..44338782 100644 --- a/Software/src/inverter/BYD-MODBUS.cpp +++ b/Software/src/inverter/BYD-MODBUS.cpp @@ -1,18 +1,23 @@ #include "../include.h" #ifdef BYD_MODBUS #include "../datalayer/datalayer.h" +#include "../devboard/utils/events.h" #include "BYD-MODBUS.h" // For modbus register definitions, see https://gitlab.com/pelle8/inverter_resources/-/blob/main/byd_registers_modbus_rtu.md -static uint8_t bms_char_dis_status = STANDBY; +static unsigned long previousMillis60s = 0; // will store last time a 60s event occured +static uint32_t previous_value_register_401 = 0x0F0F; +static uint32_t current_value_register_401 = 0xF0F0; static uint32_t user_configured_max_discharge_W = 0; static uint32_t user_configured_max_charge_W = 0; static uint32_t max_discharge_W = 0; static uint32_t max_charge_W = 0; +static uint8_t bms_char_dis_status = STANDBY; void update_modbus_registers_inverter() { verify_temperature_modbus(); + verify_inverter_modbus(); handle_update_data_modbusp201_byd(); handle_update_data_modbusp301_byd(); } @@ -107,4 +112,24 @@ void verify_temperature_modbus() { } } } + +void verify_inverter_modbus() { + // Every 60 seconds, the Gen24 writes to this 401 register, alternating between 00FF and FF00. + // We use this info to see if inverter is still alive, incase not, raise an event + unsigned long currentMillis = millis(); + + if (currentMillis - previousMillis60s >= INTERVAL_60_S) { + previousMillis60s = currentMillis; + + current_value_register_401 = mbPV[401]; + + if (current_value_register_401 == previous_value_register_401) { + set_event(EVENT_MODBUS_INVERTER_MISSING, 0); + } else { + clear_event(EVENT_MODBUS_INVERTER_MISSING); + } + + previous_value_register_401 = current_value_register_401; + } +} #endif diff --git a/Software/src/inverter/BYD-MODBUS.h b/Software/src/inverter/BYD-MODBUS.h index 34a97c01..3d014daa 100644 --- a/Software/src/inverter/BYD-MODBUS.h +++ b/Software/src/inverter/BYD-MODBUS.h @@ -11,6 +11,7 @@ extern uint16_t mbPV[MB_RTU_NUM_VALUES]; void handle_static_data_modbus_byd(); void verify_temperature_modbus(); +void verify_inverter_modbus(); void handle_update_data_modbusp201_byd(); void handle_update_data_modbusp301_byd(); #endif