Make Pylon/Solxpow/Ferroamp inverters use the new settings in COMMON_IMAGE mode

This commit is contained in:
Jonny 2025-08-16 12:19:30 +01:00
parent 2f1ff9950c
commit efd6ca1349
8 changed files with 122 additions and 11 deletions

View file

@ -1,6 +1,7 @@
#include "FERROAMP-CAN.h"
#include "../communication/can/comm_can.h"
#include "../datalayer/datalayer.h"
#include "../inverter/INVERTERS.h"
//#define SEND_0 //If defined, the messages will have ID ending with 0 (useful for some inverters)
#define SEND_1 //If defined, the messages will have ID ending with 1 (useful for some inverters)
@ -364,3 +365,38 @@ void FerroampCanInverter::send_system_data() { //System equipment information
transmit_can_frame(&PYLON_4291);
#endif
}
bool FerroampCanInverter::setup() {
if (user_selected_inverter_cells > 0) {
PYLON_7320.data.u8[0] = user_selected_inverter_cells & 0xff;
PYLON_7320.data.u8[1] = (uint8_t)(user_selected_inverter_cells >> 8);
PYLON_7321.data.u8[0] = user_selected_inverter_cells & 0xff;
PYLON_7321.data.u8[1] = (uint8_t)(user_selected_inverter_cells >> 8);
}
if (user_selected_inverter_modules > 0) {
PYLON_7320.data.u8[2] = user_selected_inverter_modules;
PYLON_7321.data.u8[2] = user_selected_inverter_modules;
}
if (user_selected_inverter_cells_per_module > 0) {
PYLON_7320.data.u8[3] = user_selected_inverter_cells_per_module;
PYLON_7321.data.u8[3] = user_selected_inverter_cells_per_module;
}
if (user_selected_inverter_voltage_level > 0) {
PYLON_7320.data.u8[4] = user_selected_inverter_voltage_level & 0xff;
PYLON_7320.data.u8[5] = (uint8_t)(user_selected_inverter_voltage_level >> 8);
PYLON_7321.data.u8[4] = user_selected_inverter_voltage_level & 0xff;
PYLON_7321.data.u8[5] = (uint8_t)(user_selected_inverter_voltage_level >> 8);
}
if (user_selected_inverter_ah_capacity > 0) {
PYLON_7320.data.u8[6] = user_selected_inverter_ah_capacity & 0xff;
PYLON_7320.data.u8[7] = (uint8_t)(user_selected_inverter_ah_capacity >> 8);
PYLON_7321.data.u8[6] = user_selected_inverter_ah_capacity & 0xff;
PYLON_7321.data.u8[7] = (uint8_t)(user_selected_inverter_ah_capacity >> 8);
}
return true;
}

View file

@ -10,6 +10,7 @@
class FerroampCanInverter : public CanInverterProtocol {
public:
const char* name() override { return Name; }
bool setup() override;
void update_values();
void transmit_can(unsigned long currentMillis);
void map_can_frame_to_variable(CAN_frame rx_frame);

View file

@ -4,6 +4,17 @@ InverterProtocol* inverter = nullptr;
InverterProtocolType user_selected_inverter_protocol = InverterProtocolType::BydModbus;
// Some user-configurable settings that can be used by inverters. These
// inverters should use sensible defaults if the corresponding user_selected
// value is zero.
uint16_t user_selected_inverter_cells = 0;
uint16_t user_selected_inverter_modules = 0;
uint16_t user_selected_inverter_cells_per_module = 0;
uint16_t user_selected_inverter_voltage_level = 0;
uint16_t user_selected_inverter_ah_capacity = 0;
uint16_t user_selected_inverter_battery_type = 0;
bool user_selected_inverter_ignore_contactors = false;
std::vector<InverterProtocolType> supported_inverter_protocols() {
std::vector<InverterProtocolType> types;
@ -90,15 +101,6 @@ extern const char* name_for_inverter_type(InverterProtocolType type) {
#error "Compile time SELECTED_INVERTER_CLASS should not be defined with COMMON_IMAGE"
#endif
// Some settings that can be used by inverters
uint16_t user_selected_inverter_cells = 0;
uint16_t user_selected_inverter_modules = 0;
uint16_t user_selected_inverter_cells_per_module = 0;
uint16_t user_selected_inverter_voltage_level = 0;
uint16_t user_selected_inverter_ah_capacity = 0;
uint16_t user_selected_inverter_battery_type = 0;
bool user_selected_inverter_ignore_contactors = false;
bool setup_inverter() {
if (inverter) {
return true;

View file

@ -36,7 +36,6 @@ extern InverterProtocol* inverter;
// Call to initialize the build-time selected inverter. Safe to call even though inverter was not selected.
bool setup_inverter();
#ifdef COMMON_IMAGE
extern uint16_t user_selected_inverter_cells;
extern uint16_t user_selected_inverter_modules;
extern uint16_t user_selected_inverter_cells_per_module;
@ -44,6 +43,5 @@ extern uint16_t user_selected_inverter_voltage_level;
extern uint16_t user_selected_inverter_ah_capacity;
extern uint16_t user_selected_inverter_battery_type;
extern bool user_selected_inverter_ignore_contactors;
#endif
#endif

View file

@ -1,6 +1,7 @@
#include "PYLON-CAN.h"
#include "../communication/can/comm_can.h"
#include "../datalayer/datalayer.h"
#include "../inverter/INVERTERS.h"
#define SEND_0 //If defined, the messages will have ID ending with 0 (useful for some inverters)
//#define SEND_1 //If defined, the messages will have ID ending with 1 (useful for some inverters)
@ -351,3 +352,38 @@ void PylonInverter::send_system_data() { //System equipment information
transmit_can_frame(&PYLON_4291);
#endif
}
bool PylonInverter::setup() {
if (user_selected_inverter_cells > 0) {
PYLON_7320.data.u8[0] = user_selected_inverter_cells & 0xff;
PYLON_7320.data.u8[1] = (uint8_t)(user_selected_inverter_cells >> 8);
PYLON_7321.data.u8[0] = user_selected_inverter_cells & 0xff;
PYLON_7321.data.u8[1] = (uint8_t)(user_selected_inverter_cells >> 8);
}
if (user_selected_inverter_modules > 0) {
PYLON_7320.data.u8[2] = user_selected_inverter_modules;
PYLON_7321.data.u8[2] = user_selected_inverter_modules;
}
if (user_selected_inverter_cells_per_module > 0) {
PYLON_7320.data.u8[3] = user_selected_inverter_cells_per_module;
PYLON_7321.data.u8[3] = user_selected_inverter_cells_per_module;
}
if (user_selected_inverter_voltage_level > 0) {
PYLON_7320.data.u8[4] = user_selected_inverter_voltage_level & 0xff;
PYLON_7320.data.u8[5] = (uint8_t)(user_selected_inverter_voltage_level >> 8);
PYLON_7321.data.u8[4] = user_selected_inverter_voltage_level & 0xff;
PYLON_7321.data.u8[5] = (uint8_t)(user_selected_inverter_voltage_level >> 8);
}
if (user_selected_inverter_ah_capacity > 0) {
PYLON_7320.data.u8[6] = user_selected_inverter_ah_capacity & 0xff;
PYLON_7320.data.u8[7] = (uint8_t)(user_selected_inverter_ah_capacity >> 8);
PYLON_7321.data.u8[6] = user_selected_inverter_ah_capacity & 0xff;
PYLON_7321.data.u8[7] = (uint8_t)(user_selected_inverter_ah_capacity >> 8);
}
return true;
}

View file

@ -10,6 +10,7 @@
class PylonInverter : public CanInverterProtocol {
public:
const char* name() override { return Name; }
bool setup() override;
void update_values();
void transmit_can(unsigned long currentMillis);
void map_can_frame_to_variable(CAN_frame rx_frame);

View file

@ -1,6 +1,7 @@
#include "SOLXPOW-CAN.h"
#include "../communication/can/comm_can.h"
#include "../datalayer/datalayer.h"
#include "../inverter/INVERTERS.h"
#define SEND_0 //If defined, the messages will have ID ending with 0 (useful for some inverters)
//#define SEND_1 //If defined, the messages will have ID ending with 1 (useful for some inverters)
@ -353,3 +354,38 @@ void SolxpowInverter::send_system_data() { //System equipment information
transmit_can_frame(&SOLXPOW_4291);
#endif
}
bool SolxpowInverter::setup() {
if (user_selected_inverter_cells > 0) {
SOLXPOW_7320.data.u8[0] = user_selected_inverter_cells & 0xff;
SOLXPOW_7320.data.u8[1] = (uint8_t)(user_selected_inverter_cells >> 8);
SOLXPOW_7321.data.u8[0] = user_selected_inverter_cells & 0xff;
SOLXPOW_7321.data.u8[1] = (uint8_t)(user_selected_inverter_cells >> 8);
}
if (user_selected_inverter_modules > 0) {
SOLXPOW_7320.data.u8[2] = user_selected_inverter_modules;
SOLXPOW_7321.data.u8[2] = user_selected_inverter_modules;
}
if (user_selected_inverter_cells_per_module > 0) {
SOLXPOW_7320.data.u8[3] = user_selected_inverter_cells_per_module;
SOLXPOW_7321.data.u8[3] = user_selected_inverter_cells_per_module;
}
if (user_selected_inverter_voltage_level > 0) {
SOLXPOW_7320.data.u8[4] = user_selected_inverter_voltage_level & 0xff;
SOLXPOW_7320.data.u8[5] = (uint8_t)(user_selected_inverter_voltage_level >> 8);
SOLXPOW_7321.data.u8[4] = user_selected_inverter_voltage_level & 0xff;
SOLXPOW_7321.data.u8[5] = (uint8_t)(user_selected_inverter_voltage_level >> 8);
}
if (user_selected_inverter_ah_capacity > 0) {
SOLXPOW_7320.data.u8[6] = user_selected_inverter_ah_capacity & 0xff;
SOLXPOW_7320.data.u8[7] = (uint8_t)(user_selected_inverter_ah_capacity >> 8);
SOLXPOW_7321.data.u8[6] = user_selected_inverter_ah_capacity & 0xff;
SOLXPOW_7321.data.u8[7] = (uint8_t)(user_selected_inverter_ah_capacity >> 8);
}
return true;
}

View file

@ -10,6 +10,7 @@
class SolxpowInverter : public CanInverterProtocol {
public:
const char* name() override { return Name; }
bool setup() override;
void update_values();
void transmit_can(unsigned long currentMillis);
void map_can_frame_to_variable(CAN_frame rx_frame);