Merge pull request #1094 from dalathegreat/feature/SMA-enable-event

SMA: Add Event for missing enable line
This commit is contained in:
Daniel Öster 2025-05-03 10:44:18 +03:00 committed by GitHub
commit 948e6d8c1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 46 additions and 0 deletions

View file

@ -81,6 +81,7 @@ void init_events(void) {
events.entries[EVENT_INVERTER_OPEN_CONTACTOR].level = EVENT_LEVEL_INFO; events.entries[EVENT_INVERTER_OPEN_CONTACTOR].level = EVENT_LEVEL_INFO;
events.entries[EVENT_INTERFACE_MISSING].level = EVENT_LEVEL_INFO; events.entries[EVENT_INTERFACE_MISSING].level = EVENT_LEVEL_INFO;
events.entries[EVENT_MODBUS_INVERTER_MISSING].level = EVENT_LEVEL_INFO; events.entries[EVENT_MODBUS_INVERTER_MISSING].level = EVENT_LEVEL_INFO;
events.entries[EVENT_NO_ENABLE_DETECTED].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_CRITICAL_UNDER_VOLTAGE].level = EVENT_LEVEL_ERROR; events.entries[EVENT_CELL_CRITICAL_UNDER_VOLTAGE].level = EVENT_LEVEL_ERROR;
events.entries[EVENT_CELL_CRITICAL_OVER_VOLTAGE].level = EVENT_LEVEL_ERROR; events.entries[EVENT_CELL_CRITICAL_OVER_VOLTAGE].level = EVENT_LEVEL_ERROR;
@ -269,6 +270,8 @@ const char* get_event_message_string(EVENTS_ENUM_TYPE event) {
"Check other error code for reason!"; "Check other error code for reason!";
case EVENT_MODBUS_INVERTER_MISSING: case EVENT_MODBUS_INVERTER_MISSING:
return "Modbus inverter has not sent any data. Inspect communication wiring!"; return "Modbus inverter has not sent any data. Inspect communication wiring!";
case EVENT_NO_ENABLE_DETECTED:
return "Inverter Enable line has not been active for a long time. Check Wiring!";
case EVENT_CELL_CRITICAL_UNDER_VOLTAGE: case EVENT_CELL_CRITICAL_UNDER_VOLTAGE:
return "CELL VOLTAGE CRITICALLY LOW! Not possible to continue. Inspect battery!"; return "CELL VOLTAGE CRITICALLY LOW! Not possible to continue. Inspect battery!";
case EVENT_CELL_UNDER_VOLTAGE: case EVENT_CELL_UNDER_VOLTAGE:

View file

@ -55,6 +55,7 @@
XX(EVENT_INVERTER_OPEN_CONTACTOR) \ XX(EVENT_INVERTER_OPEN_CONTACTOR) \
XX(EVENT_INTERFACE_MISSING) \ XX(EVENT_INTERFACE_MISSING) \
XX(EVENT_MODBUS_INVERTER_MISSING) \ XX(EVENT_MODBUS_INVERTER_MISSING) \
XX(EVENT_NO_ENABLE_DETECTED) \
XX(EVENT_ERROR_OPEN_CONTACTOR) \ XX(EVENT_ERROR_OPEN_CONTACTOR) \
XX(EVENT_CELL_CRITICAL_UNDER_VOLTAGE) \ XX(EVENT_CELL_CRITICAL_UNDER_VOLTAGE) \
XX(EVENT_CELL_CRITICAL_OVER_VOLTAGE) \ XX(EVENT_CELL_CRITICAL_OVER_VOLTAGE) \

View file

@ -1,6 +1,7 @@
#include "../include.h" #include "../include.h"
#ifdef SMA_BYD_H_CAN #ifdef SMA_BYD_H_CAN
#include "../datalayer/datalayer.h" #include "../datalayer/datalayer.h"
#include "../devboard/utils/events.h"
#include "SMA-BYD-H-CAN.h" #include "SMA-BYD-H-CAN.h"
/* TODO: Map error bits in 0x158 */ /* TODO: Map error bits in 0x158 */
@ -11,6 +12,8 @@ static unsigned long previousMillis100ms = 0;
static uint32_t inverter_time = 0; static uint32_t inverter_time = 0;
static uint16_t inverter_voltage = 0; static uint16_t inverter_voltage = 0;
static int16_t inverter_current = 0; static int16_t inverter_current = 0;
static uint16_t timeWithoutInverterAllowsContactorClosing = 0;
#define THIRTY_MINUTES 1200
//Actual content messages //Actual content messages
CAN_frame SMA_158 = {.FD = false, CAN_frame SMA_158 = {.FD = false,
@ -145,6 +148,17 @@ void update_values_can_inverter() { //This function maps all the values fetched
#endif // INVERTER_CONTACTOR_ENABLE_LED_PIN #endif // INVERTER_CONTACTOR_ENABLE_LED_PIN
} }
// Check if Enable line is working. If we go too long without any input, raise an event
if (!datalayer.system.status.inverter_allows_contactor_closing) {
timeWithoutInverterAllowsContactorClosing++;
if (timeWithoutInverterAllowsContactorClosing > THIRTY_MINUTES) {
set_event(EVENT_NO_ENABLE_DETECTED, 0);
}
} else {
timeWithoutInverterAllowsContactorClosing = 0;
}
/* /*
//SMA_158.data.u8[0] = //bit12 Fault high temperature, bit34Battery cellundervoltage, bit56 Battery cell overvoltage, bit78 batterysystemdefect //SMA_158.data.u8[0] = //bit12 Fault high temperature, bit34Battery cellundervoltage, bit56 Battery cell overvoltage, bit78 batterysystemdefect
//TODO: add all error bits. Sending message with all 0xAA until that. //TODO: add all error bits. Sending message with all 0xAA until that.

View file

@ -1,6 +1,7 @@
#include "../include.h" #include "../include.h"
#ifdef SMA_BYD_HVS_CAN #ifdef SMA_BYD_HVS_CAN
#include "../datalayer/datalayer.h" #include "../datalayer/datalayer.h"
#include "../devboard/utils/events.h"
#include "SMA-BYD-HVS-CAN.h" #include "SMA-BYD-HVS-CAN.h"
/* TODO: Map error bits in 0x158 */ /* TODO: Map error bits in 0x158 */
@ -11,6 +12,8 @@ static unsigned long previousMillis100ms = 0;
static uint32_t inverter_time = 0; static uint32_t inverter_time = 0;
static uint16_t inverter_voltage = 0; static uint16_t inverter_voltage = 0;
static int16_t inverter_current = 0; static int16_t inverter_current = 0;
static uint16_t timeWithoutInverterAllowsContactorClosing = 0;
#define THIRTY_MINUTES 1200
//Actual content messages //Actual content messages
CAN_frame SMA_158 = {.FD = false, CAN_frame SMA_158 = {.FD = false,
@ -149,6 +152,17 @@ void update_values_can_inverter() { //This function maps all the values fetched
#endif // INVERTER_CONTACTOR_ENABLE_LED_PIN #endif // INVERTER_CONTACTOR_ENABLE_LED_PIN
} }
// Check if Enable line is working. If we go too long without any input, raise an event
if (!datalayer.system.status.inverter_allows_contactor_closing) {
timeWithoutInverterAllowsContactorClosing++;
if (timeWithoutInverterAllowsContactorClosing > THIRTY_MINUTES) {
set_event(EVENT_NO_ENABLE_DETECTED, 0);
}
} else {
timeWithoutInverterAllowsContactorClosing = 0;
}
/* /*
//SMA_158.data.u8[0] = //bit12 Fault high temperature, bit34Battery cellundervoltage, bit56 Battery cell overvoltage, bit78 batterysystemdefect //SMA_158.data.u8[0] = //bit12 Fault high temperature, bit34Battery cellundervoltage, bit56 Battery cell overvoltage, bit78 batterysystemdefect
//TODO: add all error bits. Sending message with all 0xAA until that. //TODO: add all error bits. Sending message with all 0xAA until that.

View file

@ -1,6 +1,7 @@
#include "../include.h" #include "../include.h"
#ifdef SMA_TRIPOWER_CAN #ifdef SMA_TRIPOWER_CAN
#include "../datalayer/datalayer.h" #include "../datalayer/datalayer.h"
#include "../devboard/utils/events.h"
#include "SMA-TRIPOWER-CAN.h" #include "SMA-TRIPOWER-CAN.h"
/* TODO: /* TODO:
@ -32,6 +33,8 @@ static int16_t inverter_current = 0;
static bool pairing_completed = false; static bool pairing_completed = false;
static int16_t temperature_average = 0; static int16_t temperature_average = 0;
static uint16_t ampere_hours_remaining = 0; static uint16_t ampere_hours_remaining = 0;
static uint16_t timeWithoutInverterAllowsContactorClosing = 0;
#define THIRTY_MINUTES 1200
//Actual content messages //Actual content messages
CAN_frame SMA_358 = {.FD = false, CAN_frame SMA_358 = {.FD = false,
@ -146,6 +149,17 @@ void update_values_can_inverter() { //This function maps all the values fetched
} else { } else {
SMA_4D8.data.u8[6] = READY_STATE; SMA_4D8.data.u8[6] = READY_STATE;
} }
// Check if Enable line is working. If we go too long without any input, raise an event
if (!datalayer.system.status.inverter_allows_contactor_closing) {
timeWithoutInverterAllowsContactorClosing++;
if (timeWithoutInverterAllowsContactorClosing > THIRTY_MINUTES) {
set_event(EVENT_NO_ENABLE_DETECTED, 0);
}
} else {
timeWithoutInverterAllowsContactorClosing = 0;
}
} }
void map_can_frame_to_variable_inverter(CAN_frame rx_frame) { void map_can_frame_to_variable_inverter(CAN_frame rx_frame) {