Refactor modbus inverter handling

This commit is contained in:
Daniel 2024-04-29 21:22:54 +03:00
parent 3aa5704d74
commit a6ec991f26
7 changed files with 14 additions and 18 deletions

View file

@ -55,7 +55,7 @@ ACAN2517FD canfd(MCP2517_CS, SPI, MCP2517_INT);
#endif #endif
// ModbusRTU parameters // ModbusRTU parameters
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS) #ifdef MODBUS_INVERTER_SELECTED
#define MB_RTU_NUM_VALUES 30000 #define MB_RTU_NUM_VALUES 30000
uint16_t mbPV[MB_RTU_NUM_VALUES]; // Process variable memory uint16_t mbPV[MB_RTU_NUM_VALUES]; // Process variable memory
// Create a ModbusRTU server instance listening on Serial2 with 2000ms timeout // Create a ModbusRTU server instance listening on Serial2 with 2000ms timeout
@ -416,7 +416,7 @@ void init_contactors() {
} }
void init_modbus() { void init_modbus() {
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS) #ifdef MODBUS_INVERTER_SELECTED
// Set up Modbus RTU Server // Set up Modbus RTU Server
pinMode(RS485_EN_PIN, OUTPUT); pinMode(RS485_EN_PIN, OUTPUT);
digitalWrite(RS485_EN_PIN, HIGH); digitalWrite(RS485_EN_PIN, HIGH);
@ -444,7 +444,6 @@ void init_modbus() {
} }
void init_inverter() { void init_inverter() {
#ifdef SOLAX_CAN #ifdef SOLAX_CAN
datalayer.system.status.inverter_allows_contactor_closing = false; // The inverter needs to allow first datalayer.system.status.inverter_allows_contactor_closing = false; // The inverter needs to allow first
intervalUpdateValues = 800; // This protocol also requires the values to be updated faster intervalUpdateValues = 800; // This protocol also requires the values to be updated faster
@ -655,16 +654,13 @@ void update_SOC() {
void update_values() { void update_values() {
// Battery // Battery
update_values_battery(); // Map the fake values to the correct registers update_values_battery();
// Inverter // Inverter
#ifdef CAN_INVERTER_SELECTED #ifdef CAN_INVERTER_SELECTED
update_values_can_inverter(); update_values_can_inverter();
#endif #endif
#ifdef BYD_MODBUS #ifdef MODBUS_INVERTER_SELECTED
update_modbus_registers_byd(); update_modbus_registers_inverter();
#endif
#ifdef LUNA2000_MODBUS
update_modbus_registers_luna2000();
#endif #endif
} }

View file

@ -26,7 +26,7 @@
#error CAN-FD AND DUAL-CAN CANNOT BE USED SIMULTANEOUSLY #error CAN-FD AND DUAL-CAN CANNOT BE USED SIMULTANEOUSLY
#endif #endif
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS) #ifdef MODBUS_INVERTER_SELECTED
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER) #if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
// Check that Dual LilyGo via RS485 option isn't enabled, this collides with Modbus! // Check that Dual LilyGo via RS485 option isn't enabled, this collides with Modbus!
#error MODBUS CANNOT BE USED IN DOUBLE LILYGO SETUPS! CHECK USER SETTINGS! #error MODBUS CANNOT BE USED IN DOUBLE LILYGO SETUPS! CHECK USER SETTINGS!

View file

@ -3,8 +3,7 @@
#include "../datalayer/datalayer.h" #include "../datalayer/datalayer.h"
#include "BYD-MODBUS.h" #include "BYD-MODBUS.h"
void update_modbus_registers_byd() { void update_modbus_registers_inverter() {
//Updata for ModbusRTU Server for BYD
verify_temperature_modbus(); verify_temperature_modbus();
handle_update_data_modbusp201_byd(); handle_update_data_modbusp201_byd();
handle_update_data_modbusp301_byd(); handle_update_data_modbusp301_byd();

View file

@ -2,7 +2,7 @@
#define BYD_MODBUS_H #define BYD_MODBUS_H
#include "../include.h" #include "../include.h"
#define INVERTER_SELECTED #define MODBUS_INVERTER_SELECTED
#define MB_RTU_NUM_VALUES 30000 #define MB_RTU_NUM_VALUES 30000
#define MAX_POWER 40960 //BYD Modbus specific value #define MAX_POWER 40960 //BYD Modbus specific value
@ -13,5 +13,4 @@ void handle_static_data_modbus_byd();
void verify_temperature_modbus(); void verify_temperature_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();
void update_modbus_registers_byd();
#endif #endif

View file

@ -46,4 +46,8 @@ void receive_can_inverter(CAN_frame_t rx_frame);
void send_can_inverter(); void send_can_inverter();
#endif #endif
#ifdef MODBUS_INVERTER_SELECTED
void update_modbus_registers_inverter();
#endif
#endif #endif

View file

@ -3,8 +3,7 @@
#include "../datalayer/datalayer.h" #include "../datalayer/datalayer.h"
#include "LUNA2000-MODBUS.h" #include "LUNA2000-MODBUS.h"
void update_modbus_registers_luna2000() { void update_modbus_registers_inverter() {
//Updata for ModbusRTU Server for Luna2000
handle_update_data_modbus32051(); handle_update_data_modbus32051();
handle_update_data_modbus39500(); handle_update_data_modbus39500();
} }

View file

@ -2,13 +2,12 @@
#define LUNA2000_MODBUS_H #define LUNA2000_MODBUS_H
#include "../include.h" #include "../include.h"
#define INVERTER_SELECTED #define MODBUS_INVERTER_SELECTED
#define MB_RTU_NUM_VALUES 30000 #define MB_RTU_NUM_VALUES 30000
extern uint16_t mbPV[MB_RTU_NUM_VALUES]; extern uint16_t mbPV[MB_RTU_NUM_VALUES];
void update_modbus_registers_luna2000();
void handle_update_data_modbus32051(); void handle_update_data_modbus32051();
void handle_update_data_modbus39500(); void handle_update_data_modbus39500();
#endif #endif