Introduce CanReceiver and Rs485Receiver

This commit is contained in:
Jaakko Haakana 2025-06-06 16:48:10 +03:00
parent 30b4b4b54d
commit 2fe64690cd
42 changed files with 129 additions and 177 deletions

View file

@ -224,10 +224,9 @@ void core_loop(void*) {
#endif #endif
// Input, Runs as fast as possible // Input, Runs as fast as possible
receive_can(); // Receive CAN messages receive_can(); // Receive CAN messages
#if defined(RS485_INVERTER_SELECTED) || defined(RS485_BATTERY_SELECTED) receive_rs485(); // Process serial2 RS485 interface
receive_RS485(); // Process serial2 RS485 interface
#endif // RS485_INVERTER_SELECTED
END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us); END_TIME_MEASUREMENT_MAX(comm, datalayer.system.status.time_comm_us);
#ifdef WEBSERVER #ifdef WEBSERVER
START_TIME_MEASUREMENT(ota); START_TIME_MEASUREMENT(ota);

View file

@ -41,21 +41,4 @@ void setup_battery() {
#endif #endif
} }
// transmit_can_battery is called once and we need to
// call both batteries.
void handle_incoming_can_frame_battery(CAN_frame rx_frame) {
((CanBattery*)battery)->handle_incoming_can_frame(rx_frame);
}
void handle_incoming_can_frame_battery2(CAN_frame rx_frame) {
((CanBattery*)battery2)->handle_incoming_can_frame(rx_frame);
}
#ifdef RS485_BATTERY_SELECTED
void receive_RS485() {
((RS485Battery*)battery)->receive_RS485();
}
#endif
#endif #endif

View file

@ -13,7 +13,6 @@ void setup_can_shunt();
#ifdef BMW_SBOX #ifdef BMW_SBOX
#include "BMW-SBOX.h" #include "BMW-SBOX.h"
void handle_incoming_can_frame_shunt(CAN_frame rx_frame);
#endif #endif
#ifdef BMW_I3_BATTERY #ifdef BMW_I3_BATTERY
@ -160,14 +159,4 @@ void handle_incoming_can_frame_shunt(CAN_frame rx_frame);
void setup_battery(void); void setup_battery(void);
#ifdef RS485_BATTERY_SELECTED
void transmit_rs485(unsigned long currentMillis);
void receive_RS485();
#else
void handle_incoming_can_frame_battery(CAN_frame rx_frame);
void transmit_can_battery(unsigned long currentMillis);
#endif
void handle_incoming_can_frame_battery2(CAN_frame rx_frame);
#endif #endif

View file

@ -341,6 +341,8 @@ void ChademoBattery::handle_incoming_can_frame(CAN_frame rx_frame) {
} }
handle_chademo_sequence(); handle_chademo_sequence();
ISA_handleFrame(&rx_frame);
} }
/* (re)initialize evse structures to pre-charge/discharge states */ /* (re)initialize evse structures to pre-charge/discharge states */

View file

@ -4,10 +4,11 @@
#include "Battery.h" #include "Battery.h"
#include "src/communication/Transmitter.h" #include "src/communication/Transmitter.h"
#include "src/communication/can/CanReceiver.h"
#include "src/devboard/utils/types.h" #include "src/devboard/utils/types.h"
// Abstract base class for batteries using the CAN bus // Abstract base class for batteries using the CAN bus
class CanBattery : public Battery, Transmitter { class CanBattery : public Battery, Transmitter, CanReceiver {
public: public:
virtual void handle_incoming_can_frame(CAN_frame rx_frame) = 0; virtual void handle_incoming_can_frame(CAN_frame rx_frame) = 0;
virtual void transmit_can(unsigned long currentMillis) = 0; virtual void transmit_can(unsigned long currentMillis) = 0;
@ -16,17 +17,21 @@ class CanBattery : public Battery, Transmitter {
void transmit(unsigned long currentMillis) { transmit_can(currentMillis); } void transmit(unsigned long currentMillis) { transmit_can(currentMillis); }
void receive_can_frame(CAN_frame* frame) { handle_incoming_can_frame(*frame); }
protected: protected:
CAN_Interface can_interface; CAN_Interface can_interface;
CanBattery() { CanBattery() {
can_interface = can_config.battery; can_interface = can_config.battery;
register_transmitter(this); register_transmitter(this);
register_can_receiver(this, can_interface);
} }
CanBattery(CAN_Interface interface) { CanBattery(CAN_Interface interface) {
can_interface = interface; can_interface = interface;
register_transmitter(this); register_transmitter(this);
register_can_receiver(this, can_interface);
} }
}; };

View file

@ -178,7 +178,7 @@ void DalyBms::transmit_rs485(unsigned long currentMillis) {
} }
} }
void DalyBms::receive_RS485() { void DalyBms::receive() {
static uint8_t recv_buff[13] = {0}; static uint8_t recv_buff[13] = {0};
static uint8_t recv_len = 0; static uint8_t recv_len = 0;

View file

@ -23,7 +23,7 @@ class DalyBms : public RS485Battery {
void setup(); void setup();
void update_values(); void update_values();
void transmit_rs485(unsigned long currentMillis); void transmit_rs485(unsigned long currentMillis);
void receive_RS485(); void receive();
private: private:
int baud_rate() { return 9600; } int baud_rate() { return 9600; }

View file

@ -6,17 +6,21 @@
#include "src/communication/Transmitter.h" #include "src/communication/Transmitter.h"
#include "src/devboard/utils/types.h" #include "src/devboard/utils/types.h"
#include "src/communication/rs485/comm_rs485.h"
// Abstract base class for batteries using the RS485 interface // Abstract base class for batteries using the RS485 interface
class RS485Battery : public Battery, Transmitter { class RS485Battery : public Battery, Transmitter, Rs485Receiver {
public: public:
virtual void receive_RS485() = 0;
virtual void transmit_rs485(unsigned long currentMillis) = 0; virtual void transmit_rs485(unsigned long currentMillis) = 0;
String interface_name() { return "RS485"; } String interface_name() { return "RS485"; }
void transmit(unsigned long currentMillis) { transmit_rs485(currentMillis); } void transmit(unsigned long currentMillis) { transmit_rs485(currentMillis); }
RS485Battery() { register_transmitter(this); } RS485Battery() {
register_transmitter(this);
register_receiver(this);
}
}; };
#endif #endif

View file

@ -1,11 +1,11 @@
#ifndef _SHUNT_H #ifndef _SHUNT_H
#define _SHUNT_H #define _SHUNT_H
#include "../communication/can/comm_can.h"
#include "src/communication/Transmitter.h" #include "src/communication/Transmitter.h"
#include "src/communication/can/CanReceiver.h"
#include "src/devboard/utils/types.h" #include "src/devboard/utils/types.h"
class CanShunt : public Transmitter { class CanShunt : public Transmitter, CanReceiver {
public: public:
virtual void setup() = 0; virtual void setup() = 0;
virtual void transmit_can(unsigned long currentMillis) = 0; virtual void transmit_can(unsigned long currentMillis) = 0;
@ -17,12 +17,15 @@ class CanShunt : public Transmitter {
} }
} }
void receive_can_frame(CAN_frame* frame) { handle_incoming_can_frame(*frame); }
protected: protected:
CAN_Interface can_interface; CAN_Interface can_interface;
CanShunt() { CanShunt() {
can_interface = can_config.battery; can_interface = can_config.battery;
register_transmitter(this); register_transmitter(this);
register_can_receiver(this, can_interface);
} }
}; };

View file

@ -4,13 +4,7 @@
CanShunt* shunt = nullptr; CanShunt* shunt = nullptr;
void setup_can_shunt() { void setup_can_shunt() {
#if defined(CAN_SHUNT_SELECTED) && defined(SELECTED_SHUNT_CLASS) #if defined(SELECTED_SHUNT_CLASS)
shunt = new SELECTED_SHUNT_CLASS(); shunt = new SELECTED_SHUNT_CLASS();
#endif #endif
} }
void handle_incoming_can_frame_shunt(CAN_frame rx_frame) {
if (shunt) {
shunt->handle_incoming_can_frame(rx_frame);
}
}

View file

@ -5,6 +5,7 @@
#include "../datalayer/datalayer.h" #include "../datalayer/datalayer.h"
#include "src/communication/Transmitter.h" #include "src/communication/Transmitter.h"
#include "src/communication/can/CanReceiver.h"
enum class ChargerType { NissanLeaf, ChevyVolt }; enum class ChargerType { NissanLeaf, ChevyVolt };
@ -37,7 +38,7 @@ class Charger {
}; };
// Base class for chargers on a CAN bus // Base class for chargers on a CAN bus
class CanCharger : public Charger, Transmitter { class CanCharger : public Charger, Transmitter, CanReceiver {
public: public:
virtual void map_can_frame_to_variable(CAN_frame rx_frame) = 0; virtual void map_can_frame_to_variable(CAN_frame rx_frame) = 0;
virtual void transmit_can(unsigned long currentMillis) = 0; virtual void transmit_can(unsigned long currentMillis) = 0;
@ -48,8 +49,13 @@ class CanCharger : public Charger, Transmitter {
} }
} }
void receive_can_frame(CAN_frame* frame) { map_can_frame_to_variable(*frame); }
protected: protected:
CanCharger(ChargerType type) : Charger(type) { register_transmitter(this); } CanCharger(ChargerType type) : Charger(type) {
register_transmitter(this);
register_can_receiver(this, can_config.charger);
}
}; };
#endif #endif

View file

@ -0,0 +1,15 @@
#ifndef _CANRECEIVER_H
#define _CANRECEIVER_H
#include "src/devboard/utils/types.h"
#include "src/include.h"
class CanReceiver {
public:
virtual void receive_can_frame(CAN_frame* rx_frame) = 0;
};
// Register a receiver object for a given CAN interface
void register_can_receiver(CanReceiver* receiver, CAN_Interface interface);
#endif

View file

@ -1,4 +1,5 @@
#include "comm_can.h" #include "comm_can.h"
#include <map>
#include "../../include.h" #include "../../include.h"
#include "src/devboard/sdcard/sdcard.h" #include "src/devboard/sdcard/sdcard.h"
@ -10,6 +11,8 @@ volatile bool send_ok_2515 = 0;
volatile bool send_ok_2518 = 0; volatile bool send_ok_2518 = 0;
static unsigned long previousMillis10 = 0; static unsigned long previousMillis10 = 0;
void map_can_frame_to_variable(CAN_frame* rx_frame, CAN_Interface interface);
#ifdef CAN_ADDON #ifdef CAN_ADDON
static const uint32_t QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL; //MHZ configured in USER_SETTINGS.h static const uint32_t QUARTZ_FREQUENCY = CRYSTAL_FREQUENCY_MHZ * 1000000UL; //MHZ configured in USER_SETTINGS.h
SPIClass SPI2515; SPIClass SPI2515;
@ -273,7 +276,13 @@ void print_can_frame(CAN_frame frame, frameDirection msgDir) {
} }
} }
void map_can_frame_to_variable(CAN_frame* rx_frame, int interface) { static std::multimap<CAN_Interface, CanReceiver*> can_receivers;
void register_can_receiver(CanReceiver* receiver, CAN_Interface interface) {
can_receivers.insert({interface, receiver});
}
void map_can_frame_to_variable(CAN_frame* rx_frame, CAN_Interface interface) {
if (interface != if (interface !=
CANFD_NATIVE) { //Avoid printing twice due to receive_frame_canfd_addon sending to both FD interfaces CANFD_NATIVE) { //Avoid printing twice due to receive_frame_canfd_addon sending to both FD interfaces
//TODO: This check can be removed later when refactored to use inline functions for logging //TODO: This check can be removed later when refactored to use inline functions for logging
@ -288,31 +297,15 @@ void map_can_frame_to_variable(CAN_frame* rx_frame, int interface) {
} }
#endif #endif
if (interface == can_config.battery) { // Send the frame to all the receivers registered for this interface.
#ifndef RS485_BATTERY_SELECTED auto receivers = can_receivers.equal_range(interface);
handle_incoming_can_frame_battery(*rx_frame);
#endif for (auto it = receivers.first; it != receivers.second; ++it) {
#ifdef CHADEMO_BATTERY auto& receiver = it->second;
ISA_handleFrame(rx_frame); receiver->receive_can_frame(rx_frame);
#endif
}
if (interface == can_config.inverter) {
#ifdef CAN_INVERTER_SELECTED
map_can_frame_to_variable_inverter(*rx_frame);
#endif
}
if (interface == can_config.battery_double && battery2) {
handle_incoming_can_frame_battery2(*rx_frame);
}
if (interface == can_config.charger && charger) {
charger->map_can_frame_to_variable(*rx_frame);
}
if (interface == can_config.shunt) {
#ifdef CAN_SHUNT_SELECTED
handle_incoming_can_frame_shunt(*rx_frame);
#endif
} }
} }
void dump_can_frame(CAN_frame& frame, frameDirection msgDir) { void dump_can_frame(CAN_frame& frame, frameDirection msgDir) {
char* message_string = datalayer.system.info.logged_can_messages; char* message_string = datalayer.system.info.logged_can_messages;
int offset = datalayer.system.info.logged_can_messages_offset; // Keeps track of the current position in the buffer int offset = datalayer.system.info.logged_can_messages_offset; // Keeps track of the current position in the buffer

View file

@ -27,16 +27,6 @@ void transmit_can_frame(CAN_frame* tx_frame, int interface);
*/ */
void init_CAN(); void init_CAN();
/**
* @brief Transmit one CAN frame
*
* @param[in] CAN_frame* tx_frame
* @param[in] int interface
*
* @return void
*/
void transmit_can_frame();
/** /**
* @brief Receive CAN messages from all interfaces * @brief Receive CAN messages from all interfaces
* *
@ -82,14 +72,4 @@ void receive_frame_canfd_addon();
*/ */
void print_can_frame(CAN_frame frame, frameDirection msgDir); void print_can_frame(CAN_frame frame, frameDirection msgDir);
/**
* @brief Map CAN frame from specified interface to variable
*
* @param[in] CAN_frame* rx_frame
* @param[in] int interface
*
* @return void
*/
void map_can_frame_to_variable(CAN_frame* rx_frame, int interface);
#endif #endif

View file

@ -1,6 +1,8 @@
#include "comm_rs485.h" #include "comm_rs485.h"
#include "../../include.h" #include "../../include.h"
#include <list>
void init_rs485() { void init_rs485() {
#ifdef RS485_EN_PIN #ifdef RS485_EN_PIN
pinMode(RS485_EN_PIN, OUTPUT); pinMode(RS485_EN_PIN, OUTPUT);
@ -18,3 +20,15 @@ void init_rs485() {
// Inverters and batteries are expected to initialize their serial port in their setup-function // Inverters and batteries are expected to initialize their serial port in their setup-function
// for RS485 or Modbus comms. // for RS485 or Modbus comms.
} }
static std::list<Rs485Receiver*> receivers;
void receive_rs485() {
for (auto& receiver : receivers) {
receiver->receive();
}
}
void register_receiver(Rs485Receiver* receiver) {
receivers.push_back(receiver);
}

View file

@ -1,12 +1,6 @@
#ifndef _COMM_RS485_H_ #ifndef _COMM_RS485_H_
#define _COMM_RS485_H_ #define _COMM_RS485_H_
#include "../../include.h"
#include "../../lib/eModbus-eModbus/Logging.h"
#include "../../lib/eModbus-eModbus/ModbusServerRTU.h"
#include "../../lib/eModbus-eModbus/scripts/mbServerFCs.h"
/** /**
* @brief Initialization of RS485 * @brief Initialization of RS485
* *
@ -16,4 +10,17 @@
*/ */
void init_rs485(); void init_rs485();
// Defines an interface for any object that needs to receive a signal to handle RS485 comm.
// Can be extended later for more complex operation.
class Rs485Receiver {
public:
virtual void receive() = 0;
};
// Forwards the call to all registered RS485 receivers
void receive_rs485();
// Registers the given object as a receiver.
void register_receiver(Rs485Receiver* receiver);
#endif #endif

View file

@ -212,17 +212,18 @@ void update_machineryprotection() {
clear_event(EVENT_CAN_CORRUPTED_WARNING); clear_event(EVENT_CAN_CORRUPTED_WARNING);
} }
#ifdef CAN_INVERTER_SELECTED if (inverter && inverter->interface_type() == InverterInterfaceType::Can) {
// Check if the inverter is still sending CAN messages. If we go 60s without messages we raise a warning // Check if the inverter is still sending CAN messages. If we go 60s without messages we raise a warning
if (!datalayer.system.status.CAN_inverter_still_alive) { if (!datalayer.system.status.CAN_inverter_still_alive) {
set_event(EVENT_CAN_INVERTER_MISSING, can_config.inverter); set_event(EVENT_CAN_INVERTER_MISSING, can_config.inverter);
} else { } else {
datalayer.system.status.CAN_inverter_still_alive--; datalayer.system.status.CAN_inverter_still_alive--;
clear_event(EVENT_CAN_INVERTER_MISSING); clear_event(EVENT_CAN_INVERTER_MISSING);
}
} }
#endif //CAN_INVERTER_SELECTED
if (charger) { if (charger) {
// Assuming chargers are all CAN here.
// Check if the charger is still sending CAN messages. If we go 60s without messages we raise a warning // Check if the charger is still sending CAN messages. If we go 60s without messages we raise a warning
if (!datalayer.charger.CAN_charger_still_alive) { if (!datalayer.charger.CAN_charger_still_alive) {
set_event(EVENT_CAN_CHARGER_MISSING, can_config.charger); set_event(EVENT_CAN_CHARGER_MISSING, can_config.charger);

View file

@ -3,7 +3,6 @@
#include "../include.h" #include "../include.h"
#ifdef AFORE_CAN #ifdef AFORE_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS AforeCanInverter #define SELECTED_INVERTER_CLASS AforeCanInverter
#endif #endif

View file

@ -3,7 +3,6 @@
#include "../include.h" #include "../include.h"
#ifdef BYD_CAN #ifdef BYD_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS BydCanInverter #define SELECTED_INVERTER_CLASS BydCanInverter
#endif #endif

View file

@ -3,7 +3,6 @@
#include "../include.h" #include "../include.h"
#ifdef BYD_MODBUS #ifdef BYD_MODBUS
#define MODBUS_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS BydModbusInverter #define SELECTED_INVERTER_CLASS BydModbusInverter
#endif #endif

View file

@ -3,11 +3,14 @@
#include "InverterProtocol.h" #include "InverterProtocol.h"
#include "src/communication/can/CanReceiver.h"
#include "src/devboard/utils/types.h" #include "src/devboard/utils/types.h"
class CanInverterProtocol : public InverterProtocol, Transmitter { class CanInverterProtocol : public InverterProtocol, Transmitter, CanReceiver {
public: public:
virtual const char* interface_name() { return getCANInterfaceName(can_config.inverter); } virtual const char* interface_name() { return getCANInterfaceName(can_config.inverter); }
InverterInterfaceType interface_type() { return InverterInterfaceType::Can; }
virtual void transmit_can(unsigned long currentMillis) = 0; virtual void transmit_can(unsigned long currentMillis) = 0;
virtual void map_can_frame_to_variable(CAN_frame rx_frame) = 0; virtual void map_can_frame_to_variable(CAN_frame rx_frame) = 0;
@ -17,8 +20,13 @@ class CanInverterProtocol : public InverterProtocol, Transmitter {
} }
} }
void receive_can_frame(CAN_frame* frame) { map_can_frame_to_variable(*frame); }
protected: protected:
CanInverterProtocol() { register_transmitter(this); } CanInverterProtocol() {
register_transmitter(this);
register_can_receiver(this, can_config.inverter);
}
}; };
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef FERROAMP_CAN #ifdef FERROAMP_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS FerroampCanInverter #define SELECTED_INVERTER_CLASS FerroampCanInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef FOXESS_CAN #ifdef FOXESS_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS FoxessCanInverter #define SELECTED_INVERTER_CLASS FoxessCanInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef GROWATT_HV_CAN #ifdef GROWATT_HV_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS GrowattHvInverter #define SELECTED_INVERTER_CLASS GrowattHvInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef GROWATT_LV_CAN #ifdef GROWATT_LV_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS GrowattLvInverter #define SELECTED_INVERTER_CLASS GrowattLvInverter
#endif #endif

View file

@ -1,47 +1,16 @@
#include "../include.h" #include "../include.h"
// These functions adapt the old C-style global functions inverter-API to the
// object-oriented inverter protocol API.
InverterProtocol* inverter = nullptr; InverterProtocol* inverter = nullptr;
#ifdef CAN_INVERTER_SELECTED
CanInverterProtocol* can_inverter;
#endif
#ifdef MODBUS_INVERTER_SELECTED
ModbusInverterProtocol* modbus_inverter;
#endif
void setup_inverter() { void setup_inverter() {
#ifdef MODBUS_INVERTER_SELECTED if (inverter) {
modbus_inverter = new SELECTED_INVERTER_CLASS(); // The inverter is setup only once.
inverter = modbus_inverter; return;
#endif }
#ifdef CAN_INVERTER_SELECTED
can_inverter = new SELECTED_INVERTER_CLASS();
inverter = can_inverter;
#endif
#ifdef RS485_INVERTER_SELECTED
inverter = new SELECTED_INVERTER_CLASS(); inverter = new SELECTED_INVERTER_CLASS();
#endif
if (inverter) { if (inverter) {
inverter->setup(); inverter->setup();
} }
} }
#ifdef CAN_INVERTER_SELECTED
void map_can_frame_to_variable_inverter(CAN_frame rx_frame) {
can_inverter->map_can_frame_to_variable(rx_frame);
}
#endif
#ifdef RS485_INVERTER_SELECTED
void receive_RS485() {
((Rs485InverterProtocol*)inverter)->receive_RS485();
}
#endif

View file

@ -33,13 +33,4 @@ extern InverterProtocol* inverter;
// Call to initialize the build-time selected inverter. Safe to call even though inverter was not selected. // Call to initialize the build-time selected inverter. Safe to call even though inverter was not selected.
void setup_inverter(); void setup_inverter();
#ifdef CAN_INVERTER_SELECTED
void map_can_frame_to_variable_inverter(CAN_frame rx_frame);
void transmit_can_inverter(unsigned long currentMillis);
#endif
#ifdef RS485_INVERTER_SELECTED
void receive_RS485();
#endif
#endif #endif

View file

@ -1,11 +1,14 @@
#ifndef INVERTER_PROTOCOL_H #ifndef INVERTER_PROTOCOL_H
#define INVERTER_PROTOCOL_H #define INVERTER_PROTOCOL_H
enum class InverterInterfaceType { Can, Rs485, Modbus };
// The abstract base class for all inverter protocols // The abstract base class for all inverter protocols
class InverterProtocol { class InverterProtocol {
public: public:
virtual void setup() = 0; virtual void setup() = 0;
virtual const char* interface_name() = 0; virtual const char* interface_name() = 0;
virtual InverterInterfaceType interface_type() = 0;
// This function maps all the values fetched from battery to the correct battery emulator data structures // This function maps all the values fetched from battery to the correct battery emulator data structures
virtual void update_values() = 0; virtual void update_values() = 0;

View file

@ -203,7 +203,7 @@ void KostalInverterProtocol::update_values() {
} }
} }
void KostalInverterProtocol::receive_RS485() // Runs as fast as possible to handle the serial stream void KostalInverterProtocol::receive() // Runs as fast as possible to handle the serial stream
{ {
currentMillis = millis(); currentMillis = millis();

View file

@ -20,7 +20,7 @@
class KostalInverterProtocol : public Rs485InverterProtocol { class KostalInverterProtocol : public Rs485InverterProtocol {
public: public:
void setup(); void setup();
void receive_RS485(); void receive();
void update_values(); void update_values();
private: private:

View file

@ -10,7 +10,8 @@ extern uint16_t mbPV[];
// The abstract base class for all Modbus inverter protocols // The abstract base class for all Modbus inverter protocols
class ModbusInverterProtocol : public InverterProtocol { class ModbusInverterProtocol : public InverterProtocol {
virtual const char* interface_name() { return "RS485 / Modbus"; } const char* interface_name() { return "RS485 / Modbus"; }
InverterInterfaceType interface_type() { return InverterInterfaceType::Modbus; }
protected: protected:
// Create a ModbusRTU server instance with 2000ms timeout // Create a ModbusRTU server instance with 2000ms timeout

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef PYLON_CAN #ifdef PYLON_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS PylonInverter #define SELECTED_INVERTER_CLASS PylonInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef PYLON_LV_CAN #ifdef PYLON_LV_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS PylonLvInverter #define SELECTED_INVERTER_CLASS PylonLvInverter
#endif #endif

View file

@ -1,12 +1,14 @@
#ifndef RS485CANINVERTER_PROTOCOL_H #ifndef _RS485INVERTER_PROTOCOL_H
#define RS485INVERTER_PROTOCOL_H #define _RS485INVERTER_PROTOCOL_H
#include "InverterProtocol.h" #include "InverterProtocol.h"
class Rs485InverterProtocol : public InverterProtocol { #include "src/communication/rs485/comm_rs485.h"
class Rs485InverterProtocol : public InverterProtocol, Rs485Receiver {
public: public:
virtual const char* interface_name() { return "RS485"; } virtual const char* interface_name() { return "RS485"; }
virtual void receive_RS485() = 0; InverterInterfaceType interface_type() { return InverterInterfaceType::Rs485; }
virtual int baud_rate() = 0; virtual int baud_rate() = 0;
}; };

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SCHNEIDER_CAN #ifdef SCHNEIDER_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SchneiderInverter #define SELECTED_INVERTER_CLASS SchneiderInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SMA_BYD_H_CAN #ifdef SMA_BYD_H_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SmaBydHInverter #define SELECTED_INVERTER_CLASS SmaBydHInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SMA_BYD_HVS_CAN #ifdef SMA_BYD_HVS_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SmaBydHvsInverter #define SELECTED_INVERTER_CLASS SmaBydHvsInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SMA_LV_CAN #ifdef SMA_LV_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SmaLvInverter #define SELECTED_INVERTER_CLASS SmaLvInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SMA_TRIPOWER_CAN #ifdef SMA_TRIPOWER_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SmaTripowerInverter #define SELECTED_INVERTER_CLASS SmaTripowerInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SOFAR_CAN #ifdef SOFAR_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SofarInverter #define SELECTED_INVERTER_CLASS SofarInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SOLAX_CAN #ifdef SOLAX_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SolaxInverter #define SELECTED_INVERTER_CLASS SolaxInverter
#endif #endif

View file

@ -5,7 +5,6 @@
#include "CanInverterProtocol.h" #include "CanInverterProtocol.h"
#ifdef SUNGROW_CAN #ifdef SUNGROW_CAN
#define CAN_INVERTER_SELECTED
#define SELECTED_INVERTER_CLASS SungrowInverter #define SELECTED_INVERTER_CLASS SungrowInverter
#endif #endif