mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 02:39:57 +02:00
Refactor modbus inverter handling
This commit is contained in:
parent
3aa5704d74
commit
a6ec991f26
7 changed files with 14 additions and 18 deletions
|
@ -55,7 +55,7 @@ ACAN2517FD canfd(MCP2517_CS, SPI, MCP2517_INT);
|
|||
#endif
|
||||
|
||||
// ModbusRTU parameters
|
||||
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS)
|
||||
#ifdef MODBUS_INVERTER_SELECTED
|
||||
#define MB_RTU_NUM_VALUES 30000
|
||||
uint16_t mbPV[MB_RTU_NUM_VALUES]; // Process variable memory
|
||||
// Create a ModbusRTU server instance listening on Serial2 with 2000ms timeout
|
||||
|
@ -416,7 +416,7 @@ void init_contactors() {
|
|||
}
|
||||
|
||||
void init_modbus() {
|
||||
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS)
|
||||
#ifdef MODBUS_INVERTER_SELECTED
|
||||
// Set up Modbus RTU Server
|
||||
pinMode(RS485_EN_PIN, OUTPUT);
|
||||
digitalWrite(RS485_EN_PIN, HIGH);
|
||||
|
@ -444,7 +444,6 @@ void init_modbus() {
|
|||
}
|
||||
|
||||
void init_inverter() {
|
||||
|
||||
#ifdef SOLAX_CAN
|
||||
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
|
||||
|
@ -655,16 +654,13 @@ void update_SOC() {
|
|||
|
||||
void update_values() {
|
||||
// Battery
|
||||
update_values_battery(); // Map the fake values to the correct registers
|
||||
update_values_battery();
|
||||
// Inverter
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
update_values_can_inverter();
|
||||
#endif
|
||||
#ifdef BYD_MODBUS
|
||||
update_modbus_registers_byd();
|
||||
#endif
|
||||
#ifdef LUNA2000_MODBUS
|
||||
update_modbus_registers_luna2000();
|
||||
#ifdef MODBUS_INVERTER_SELECTED
|
||||
update_modbus_registers_inverter();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
#error CAN-FD AND DUAL-CAN CANNOT BE USED SIMULTANEOUSLY
|
||||
#endif
|
||||
|
||||
#if defined(BYD_MODBUS) || defined(LUNA2000_MODBUS)
|
||||
#ifdef MODBUS_INVERTER_SELECTED
|
||||
#if defined(SERIAL_LINK_RECEIVER) || defined(SERIAL_LINK_TRANSMITTER)
|
||||
// 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!
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "BYD-MODBUS.h"
|
||||
|
||||
void update_modbus_registers_byd() {
|
||||
//Updata for ModbusRTU Server for BYD
|
||||
void update_modbus_registers_inverter() {
|
||||
verify_temperature_modbus();
|
||||
handle_update_data_modbusp201_byd();
|
||||
handle_update_data_modbusp301_byd();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define BYD_MODBUS_H
|
||||
#include "../include.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
#define MODBUS_INVERTER_SELECTED
|
||||
|
||||
#define MB_RTU_NUM_VALUES 30000
|
||||
#define MAX_POWER 40960 //BYD Modbus specific value
|
||||
|
@ -13,5 +13,4 @@ void handle_static_data_modbus_byd();
|
|||
void verify_temperature_modbus();
|
||||
void handle_update_data_modbusp201_byd();
|
||||
void handle_update_data_modbusp301_byd();
|
||||
void update_modbus_registers_byd();
|
||||
#endif
|
||||
|
|
|
@ -46,4 +46,8 @@ void receive_can_inverter(CAN_frame_t rx_frame);
|
|||
void send_can_inverter();
|
||||
#endif
|
||||
|
||||
#ifdef MODBUS_INVERTER_SELECTED
|
||||
void update_modbus_registers_inverter();
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
|
|
@ -3,8 +3,7 @@
|
|||
#include "../datalayer/datalayer.h"
|
||||
#include "LUNA2000-MODBUS.h"
|
||||
|
||||
void update_modbus_registers_luna2000() {
|
||||
//Updata for ModbusRTU Server for Luna2000
|
||||
void update_modbus_registers_inverter() {
|
||||
handle_update_data_modbus32051();
|
||||
handle_update_data_modbus39500();
|
||||
}
|
||||
|
|
|
@ -2,13 +2,12 @@
|
|||
#define LUNA2000_MODBUS_H
|
||||
#include "../include.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
#define MODBUS_INVERTER_SELECTED
|
||||
|
||||
#define MB_RTU_NUM_VALUES 30000
|
||||
|
||||
extern uint16_t mbPV[MB_RTU_NUM_VALUES];
|
||||
|
||||
void update_modbus_registers_luna2000();
|
||||
void handle_update_data_modbus32051();
|
||||
void handle_update_data_modbus39500();
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue