mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-05 02:39:57 +02:00
Merge pull request #276 from dalathegreat/refactor/inverter-can-send
Refactor: Inverter handling
This commit is contained in:
commit
a58c570dc5
20 changed files with 81 additions and 182 deletions
|
@ -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!
|
||||
|
|
|
@ -114,7 +114,7 @@ static uint16_t inverter_SOC = 0;
|
|||
static long inverter_timestamp = 0;
|
||||
static bool initialDataSent = 0;
|
||||
|
||||
void update_values_can_byd() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
void update_values_can_inverter() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
//Calculate values
|
||||
charge_current =
|
||||
((datalayer.battery.status.max_charge_power_W * 10) /
|
||||
|
@ -199,7 +199,7 @@ void update_values_can_byd() { //This function maps all the values fetched from
|
|||
#endif
|
||||
}
|
||||
|
||||
void receive_can_byd(CAN_frame_t rx_frame) {
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
case 0x151: //Message originating from BYD HVS compatible inverter. Reply with CAN identifier!
|
||||
if (rx_frame.data.u8[0] & 0x01) { //Battery requests identification
|
||||
|
@ -229,7 +229,7 @@ void receive_can_byd(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
|
||||
void send_can_byd() {
|
||||
void send_can_inverter() {
|
||||
unsigned long currentMillis = millis();
|
||||
// Send initial CAN data once on bootup
|
||||
if (!initialDataSent) {
|
||||
|
|
|
@ -1,14 +1,10 @@
|
|||
#ifndef BYD_CAN_H
|
||||
#define BYD_CAN_H
|
||||
#include <Arduino.h>
|
||||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
void update_values_can_byd();
|
||||
void send_can_byd();
|
||||
void receive_can_byd(CAN_frame_t rx_frame);
|
||||
void send_intial_data();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -39,4 +39,15 @@
|
|||
#include "SERIAL-LINK-TRANSMITTER-INVERTER.h"
|
||||
#endif
|
||||
|
||||
#ifdef CAN_INVERTER_SELECTED
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h" // This include is annoying, consider defining a frame type in types.h
|
||||
void update_values_can_inverter();
|
||||
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
|
||||
|
|
|
@ -170,7 +170,7 @@ CAN_frame_t PYLON_4291 = {.FIR = {.B =
|
|||
.MsgID = 0x4291,
|
||||
.data = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}};
|
||||
|
||||
void update_values_can_pylon() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
void update_values_can_inverter() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
//There are more mappings that could be added, but this should be enough to use as a starting point
|
||||
// Note we map both 0 and 1 messages
|
||||
|
||||
|
@ -243,7 +243,7 @@ void update_values_can_pylon() { //This function maps all the values fetched fr
|
|||
}
|
||||
}
|
||||
|
||||
void receive_can_pylon(CAN_frame_t rx_frame) {
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
case 0x4200: //Message originating from inverter. Depending on which data is required, act accordingly
|
||||
if (rx_frame.data.u8[0] == 0x02) {
|
||||
|
@ -258,6 +258,10 @@ void receive_can_pylon(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
|
||||
void send_can_inverter() {
|
||||
// No periodic sending, we only react on received can messages
|
||||
}
|
||||
|
||||
void send_setup_info() { //Ensemble information
|
||||
#ifdef SEND_0
|
||||
ESP32Can.CANWriteFrame(&PYLON_7310);
|
||||
|
|
|
@ -3,10 +3,8 @@
|
|||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
void update_values_can_pylon();
|
||||
void receive_can_pylon(CAN_frame_t rx_frame);
|
||||
void send_system_data();
|
||||
void send_setup_info();
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@
|
|||
#include "../include.h"
|
||||
#include "../lib/mackelec-SerialDataLink/SerialDataLink.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
|
||||
void manageSerialLinkTransmitter();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -103,7 +103,7 @@ static int16_t charge_current = 0;
|
|||
static int16_t temperature_average = 0;
|
||||
static uint16_t ampere_hours_remaining = 0;
|
||||
|
||||
void update_values_can_sma() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
void update_values_can_inverter() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
//Calculate values
|
||||
charge_current =
|
||||
((datalayer.battery.status.max_charge_power_W * 10) /
|
||||
|
@ -226,7 +226,7 @@ void update_values_can_sma() { //This function maps all the values fetched from
|
|||
*/
|
||||
}
|
||||
|
||||
void receive_can_sma(CAN_frame_t rx_frame) {
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
case 0x360: //Message originating from SMA inverter - Voltage and current
|
||||
//Frame0-1 Voltage
|
||||
|
@ -246,7 +246,7 @@ void receive_can_sma(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
|
||||
void send_can_sma() {
|
||||
void send_can_inverter() {
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
// Send CAN Message every 100ms
|
||||
|
|
|
@ -3,13 +3,9 @@
|
|||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
#define READY_STATE 0x03
|
||||
#define STOP_STATE 0x02
|
||||
|
||||
void update_values_can_sma();
|
||||
void send_can_sma();
|
||||
void receive_can_sma(CAN_frame_t rx_frame);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -161,7 +161,7 @@ Command2Battery command2Battery = RUN;
|
|||
enum InvInitState { SYSTEM_FREQUENCY, XPHASE_SYSTEM, BLACKSTART_OPERATION };
|
||||
InvInitState invInitState = SYSTEM_FREQUENCY;
|
||||
|
||||
void update_values_can_sma_tripower() { //This function maps all the values fetched from battery CAN to the inverter CAN
|
||||
void update_values_can_inverter() { //This function maps all the values fetched from battery CAN to the inverter CAN
|
||||
//Calculate values
|
||||
charge_current =
|
||||
((datalayer.battery.status.max_charge_power_W * 10) /
|
||||
|
@ -328,7 +328,7 @@ void update_values_can_sma_tripower() { //This function maps all the values fet
|
|||
//SMA_018.data.u8[7] = BatteryName;
|
||||
}
|
||||
|
||||
void receive_can_sma_tripower(CAN_frame_t rx_frame) {
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) {
|
||||
case 0x00D: //Inverter Measurements
|
||||
break;
|
||||
|
@ -347,7 +347,7 @@ void receive_can_sma_tripower(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
|
||||
void send_can_sma_tripower() {
|
||||
void send_can_inverter() {
|
||||
unsigned long currentMillis = millis();
|
||||
|
||||
// Send CAN Message every 500ms
|
||||
|
|
|
@ -3,11 +3,8 @@
|
|||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
void update_values_can_sma_tripower();
|
||||
void send_can_sma_tripower();
|
||||
void receive_can_sma_tripower(CAN_frame_t rx_frame);
|
||||
void send_tripower_init();
|
||||
|
||||
#endif
|
||||
|
|
|
@ -280,7 +280,7 @@ CAN_frame_t SOFAR_7C0 = {.FIR = {.B =
|
|||
.MsgID = 0x7C0,
|
||||
.data = {0x00, 0x00, 0x00, 0x04, 0x00, 0x04, 0x80, 0x00}};
|
||||
|
||||
void update_values_can_sofar() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
void update_values_can_inverter() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
|
||||
//Maxvoltage (eg 400.0V = 4000 , 16bits long) Charge Cutoff Voltage
|
||||
SOFAR_351.data.u8[0] = (datalayer.battery.info.max_design_voltage_dV >> 8);
|
||||
|
@ -308,7 +308,7 @@ void update_values_can_sofar() { //This function maps all the values fetched fr
|
|||
SOFAR_356.data.u8[3] = (datalayer.battery.status.temperature_max_dC & 0x00FF);
|
||||
}
|
||||
|
||||
void receive_can_sofar(CAN_frame_t rx_frame) {
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
switch (rx_frame.MsgID) { //In here we need to respond to the inverter. TODO: make logic
|
||||
case 0x605:
|
||||
//frame1_605 = rx_frame.data.u8[1];
|
||||
|
@ -323,7 +323,7 @@ void receive_can_sofar(CAN_frame_t rx_frame) {
|
|||
}
|
||||
}
|
||||
|
||||
void send_can_sofar() {
|
||||
void send_can_inverter() {
|
||||
unsigned long currentMillis = millis();
|
||||
// Send 100ms CAN Message
|
||||
if (currentMillis - previousMillis100 >= INTERVAL_100_MS) {
|
||||
|
|
|
@ -3,10 +3,6 @@
|
|||
#include "../include.h"
|
||||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
|
||||
void update_values_can_sofar();
|
||||
void send_can_sofar();
|
||||
void receive_can_sofar(CAN_frame_t rx_frame);
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
#endif
|
||||
|
|
|
@ -121,7 +121,7 @@ void CAN_WriteFrame(CAN_frame_t* tx_frame) {
|
|||
#endif
|
||||
}
|
||||
|
||||
void update_values_can_solax() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
void update_values_can_inverter() { //This function maps all the values fetched from battery CAN to the correct CAN messages
|
||||
// If not receiveing any communication from the inverter, open contactors and return to battery announce state
|
||||
if (millis() - LastFrameTime >= SolaxTimeout) {
|
||||
datalayer.system.status.inverter_allows_contactor_closing = false;
|
||||
|
@ -237,7 +237,11 @@ void update_values_can_solax() { //This function maps all the values fetched fr
|
|||
SOLAX_1801.data.u8[4] = 1;
|
||||
}
|
||||
|
||||
void receive_can_solax(CAN_frame_t rx_frame) {
|
||||
void send_can_inverter() {
|
||||
// No periodic sending used on this protocol, we react only on incoming CAN messages!
|
||||
}
|
||||
|
||||
void receive_can_inverter(CAN_frame_t rx_frame) {
|
||||
if (rx_frame.MsgID == 0x1871 && rx_frame.data.u8[0] == (0x01) ||
|
||||
rx_frame.MsgID == 0x1871 && rx_frame.data.u8[0] == (0x02)) {
|
||||
LastFrameTime = millis();
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "../lib/miwagner-ESP32-Arduino-CAN/ESP32CAN.h"
|
||||
#include "../lib/pierremolinaro-acan2515/ACAN2515.h"
|
||||
|
||||
#define INVERTER_SELECTED
|
||||
#define CAN_INVERTER_SELECTED
|
||||
|
||||
extern ACAN2515 can;
|
||||
|
||||
|
@ -18,6 +18,5 @@ extern ACAN2515 can;
|
|||
#define FAULT_SOLAX 3
|
||||
#define UPDATING_FW 4
|
||||
|
||||
void update_values_can_solax();
|
||||
void receive_can_solax(CAN_frame_t rx_frame);
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue