mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 18:29:48 +02:00
Add event for missing modbus comm
This commit is contained in:
parent
5afdfcb735
commit
ca573d19e3
4 changed files with 32 additions and 2 deletions
|
@ -153,6 +153,7 @@ void init_events(void) {
|
||||||
events.entries[EVENT_PRECHARGE_FAILURE].level = EVENT_LEVEL_INFO;
|
events.entries[EVENT_PRECHARGE_FAILURE].level = EVENT_LEVEL_INFO;
|
||||||
events.entries[EVENT_INTERNAL_OPEN_FAULT].level = EVENT_LEVEL_ERROR;
|
events.entries[EVENT_INTERNAL_OPEN_FAULT].level = EVENT_LEVEL_ERROR;
|
||||||
events.entries[EVENT_INVERTER_OPEN_CONTACTOR].level = EVENT_LEVEL_INFO;
|
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_ERROR_OPEN_CONTACTOR].level = EVENT_LEVEL_INFO;
|
||||||
events.entries[EVENT_CELL_UNDER_VOLTAGE].level = EVENT_LEVEL_ERROR;
|
events.entries[EVENT_CELL_UNDER_VOLTAGE].level = EVENT_LEVEL_ERROR;
|
||||||
events.entries[EVENT_CELL_OVER_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:
|
case EVENT_ERROR_OPEN_CONTACTOR:
|
||||||
return "Info: Too much time spent in error state. Opening contactors, not safe to continue charging. "
|
return "Info: Too much time spent in error state. Opening contactors, not safe to continue charging. "
|
||||||
"Check other error code for reason!";
|
"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:
|
case EVENT_CELL_UNDER_VOLTAGE:
|
||||||
return "ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!";
|
return "ERROR: CELL UNDERVOLTAGE!!! Stopping battery charging and discharging. Inspect battery!";
|
||||||
case EVENT_CELL_OVER_VOLTAGE:
|
case EVENT_CELL_OVER_VOLTAGE:
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
// #define INCLUDE_EVENTS_TEST // Enable to run an event test loop, see events_test_on_target.cpp
|
// #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_ENUM(ENUM) ENUM,
|
||||||
#define GENERATE_STRING(STRING) #STRING,
|
#define GENERATE_STRING(STRING) #STRING,
|
||||||
|
@ -49,6 +49,7 @@
|
||||||
XX(EVENT_PRECHARGE_FAILURE) \
|
XX(EVENT_PRECHARGE_FAILURE) \
|
||||||
XX(EVENT_INTERNAL_OPEN_FAULT) \
|
XX(EVENT_INTERNAL_OPEN_FAULT) \
|
||||||
XX(EVENT_INVERTER_OPEN_CONTACTOR) \
|
XX(EVENT_INVERTER_OPEN_CONTACTOR) \
|
||||||
|
XX(EVENT_MODBUS_INVERTER_MISSING) \
|
||||||
XX(EVENT_ERROR_OPEN_CONTACTOR) \
|
XX(EVENT_ERROR_OPEN_CONTACTOR) \
|
||||||
XX(EVENT_CELL_UNDER_VOLTAGE) \
|
XX(EVENT_CELL_UNDER_VOLTAGE) \
|
||||||
XX(EVENT_CELL_OVER_VOLTAGE) \
|
XX(EVENT_CELL_OVER_VOLTAGE) \
|
||||||
|
|
|
@ -1,18 +1,23 @@
|
||||||
#include "../include.h"
|
#include "../include.h"
|
||||||
#ifdef BYD_MODBUS
|
#ifdef BYD_MODBUS
|
||||||
#include "../datalayer/datalayer.h"
|
#include "../datalayer/datalayer.h"
|
||||||
|
#include "../devboard/utils/events.h"
|
||||||
#include "BYD-MODBUS.h"
|
#include "BYD-MODBUS.h"
|
||||||
|
|
||||||
// For modbus register definitions, see https://gitlab.com/pelle8/inverter_resources/-/blob/main/byd_registers_modbus_rtu.md
|
// 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_discharge_W = 0;
|
||||||
static uint32_t user_configured_max_charge_W = 0;
|
static uint32_t user_configured_max_charge_W = 0;
|
||||||
static uint32_t max_discharge_W = 0;
|
static uint32_t max_discharge_W = 0;
|
||||||
static uint32_t max_charge_W = 0;
|
static uint32_t max_charge_W = 0;
|
||||||
|
static uint8_t bms_char_dis_status = STANDBY;
|
||||||
|
|
||||||
void update_modbus_registers_inverter() {
|
void update_modbus_registers_inverter() {
|
||||||
verify_temperature_modbus();
|
verify_temperature_modbus();
|
||||||
|
verify_inverter_modbus();
|
||||||
handle_update_data_modbusp201_byd();
|
handle_update_data_modbusp201_byd();
|
||||||
handle_update_data_modbusp301_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
|
#endif
|
||||||
|
|
|
@ -11,6 +11,7 @@ extern uint16_t mbPV[MB_RTU_NUM_VALUES];
|
||||||
|
|
||||||
void handle_static_data_modbus_byd();
|
void handle_static_data_modbus_byd();
|
||||||
void verify_temperature_modbus();
|
void verify_temperature_modbus();
|
||||||
|
void verify_inverter_modbus();
|
||||||
void handle_update_data_modbusp201_byd();
|
void handle_update_data_modbusp201_byd();
|
||||||
void handle_update_data_modbusp301_byd();
|
void handle_update_data_modbusp301_byd();
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue