Restore previous SMA TRIPOWER behaviour to fix regression and potential issues

This commit is contained in:
Jonny 2025-09-14 20:55:27 +01:00
parent 00a820f007
commit 50d794d0de
2 changed files with 52 additions and 17 deletions

View file

@ -137,6 +137,17 @@ void SmaTripowerInverter::map_can_frame_to_variable(CAN_frame rx_frame) {
} }
} }
void SmaTripowerInverter::pushFrame(CAN_frame* frame, std::function<void(void)> callback) {
if (listLength >= 20) {
return; //TODO: scream.
}
framesToSend[listLength] = {
.frame = frame,
.callback = callback,
};
listLength++;
}
void SmaTripowerInverter::transmit_can(unsigned long currentMillis) { void SmaTripowerInverter::transmit_can(unsigned long currentMillis) {
// Send CAN Message only if we're enabled by inverter // Send CAN Message only if we're enabled by inverter
@ -144,6 +155,18 @@ void SmaTripowerInverter::transmit_can(unsigned long currentMillis) {
return; return;
} }
if (listLength > 0 && currentMillis - previousMillis250ms >= INTERVAL_250_MS) {
previousMillis250ms = currentMillis;
// Send next frame.
Frame frame = framesToSend[0];
transmit_can_frame(frame.frame);
frame.callback();
for (int i = 0; i < listLength - 1; i++) {
framesToSend[i] = framesToSend[i + 1];
}
listLength--;
}
if (!pairing_completed) { if (!pairing_completed) {
return; return;
} }
@ -151,19 +174,19 @@ void SmaTripowerInverter::transmit_can(unsigned long currentMillis) {
// Send CAN Message every 2s // Send CAN Message every 2s
if (currentMillis - previousMillis2s >= INTERVAL_2_S) { if (currentMillis - previousMillis2s >= INTERVAL_2_S) {
previousMillis2s = currentMillis; previousMillis2s = currentMillis;
transmit_can_frame(&SMA_358); pushFrame(&SMA_358);
} }
// Send CAN Message every 10s // Send CAN Message every 10s
if (currentMillis - previousMillis10s >= INTERVAL_10_S) { if (currentMillis - previousMillis10s >= INTERVAL_10_S) {
previousMillis10s = currentMillis; previousMillis10s = currentMillis;
transmit_can_frame(&SMA_518); pushFrame(&SMA_518);
transmit_can_frame(&SMA_4D8); pushFrame(&SMA_4D8);
transmit_can_frame(&SMA_3D8); pushFrame(&SMA_3D8);
} }
// Send CAN Message every 60s (potentially SMA_458 is not required for stable operation) // Send CAN Message every 60s (potentially SMA_458 is not required for stable operation)
if (currentMillis - previousMillis60s >= INTERVAL_60_S) { if (currentMillis - previousMillis60s >= INTERVAL_60_S) {
previousMillis60s = currentMillis; previousMillis60s = currentMillis;
transmit_can_frame(&SMA_458); pushFrame(&SMA_458);
} }
} }
@ -172,17 +195,18 @@ void SmaTripowerInverter::completePairing() {
} }
void SmaTripowerInverter::transmit_can_init() { void SmaTripowerInverter::transmit_can_init() {
listLength = 0; // clear all frames
transmit_can_frame(&SMA_558); //Pairing start - Vendor pushFrame(&SMA_558); //Pairing start - Vendor
transmit_can_frame(&SMA_598); //Serial pushFrame(&SMA_598); //Serial
transmit_can_frame(&SMA_5D8); //BYD pushFrame(&SMA_5D8); //BYD
transmit_can_frame(&SMA_618_0); //BATTERY pushFrame(&SMA_618_0); //BATTERY
transmit_can_frame(&SMA_618_1); //-Box Pr pushFrame(&SMA_618_1); //-Box Pr
transmit_can_frame(&SMA_618_2); //emium H pushFrame(&SMA_618_2); //emium H
transmit_can_frame(&SMA_618_3); //VS pushFrame(&SMA_618_3); //VS
transmit_can_frame(&SMA_358); pushFrame(&SMA_358);
transmit_can_frame(&SMA_3D8); pushFrame(&SMA_3D8);
transmit_can_frame(&SMA_458); pushFrame(&SMA_458);
transmit_can_frame(&SMA_4D8); pushFrame(&SMA_4D8);
transmit_can_frame(&SMA_518); pushFrame(&SMA_518, [this]() { this->completePairing(); });
} }

View file

@ -4,6 +4,8 @@
#include "../devboard/hal/hal.h" #include "../devboard/hal/hal.h"
#include "SmaInverterBase.h" #include "SmaInverterBase.h"
#include <functional>
class SmaTripowerInverter : public SmaInverterBase { class SmaTripowerInverter : public SmaInverterBase {
public: public:
const char* name() override { return Name; } const char* name() override { return Name; }
@ -20,6 +22,7 @@ class SmaTripowerInverter : public SmaInverterBase {
const int THIRTY_MINUTES = 1200; const int THIRTY_MINUTES = 1200;
void transmit_can_init(); void transmit_can_init();
void pushFrame(CAN_frame* frame, std::function<void(void)> callback = []() {});
void completePairing(); void completePairing();
unsigned long previousMillis250ms = 0; // will store last time a 250ms CAN Message was send unsigned long previousMillis250ms = 0; // will store last time a 250ms CAN Message was send
@ -28,6 +31,14 @@ class SmaTripowerInverter : public SmaInverterBase {
unsigned long previousMillis10s = 0; // will store last time a 10s CAN Message was send unsigned long previousMillis10s = 0; // will store last time a 10s CAN Message was send
unsigned long previousMillis60s = 0; // will store last time a 60s CAN Message was send unsigned long previousMillis60s = 0; // will store last time a 60s CAN Message was send
typedef struct {
CAN_frame* frame;
std::function<void(void)> callback;
} Frame;
unsigned short listLength = 0;
Frame framesToSend[20];
uint32_t inverter_time = 0; uint32_t inverter_time = 0;
uint16_t inverter_voltage = 0; uint16_t inverter_voltage = 0;
int16_t inverter_current = 0; int16_t inverter_current = 0;