mirror of
https://github.com/dalathegreat/Battery-Emulator.git
synced 2025-10-04 02:09:30 +02:00
Eliminate some preprocessor define usage
This commit is contained in:
parent
24fff70984
commit
c58d7a2b67
8 changed files with 14 additions and 22 deletions
|
@ -102,10 +102,7 @@ void setup() {
|
||||||
#endif // PRECHARGE_CONTROL
|
#endif // PRECHARGE_CONTROL
|
||||||
|
|
||||||
setup_charger();
|
setup_charger();
|
||||||
|
|
||||||
#if defined(CAN_INVERTER_SELECTED) || defined(MODBUS_INVERTER_SELECTED) || defined(RS485_INVERTER_SELECTED)
|
|
||||||
setup_inverter();
|
setup_inverter();
|
||||||
#endif
|
|
||||||
setup_battery();
|
setup_battery();
|
||||||
|
|
||||||
init_rs485();
|
init_rs485();
|
||||||
|
@ -512,15 +509,9 @@ void update_calculated_values() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_values_inverter() {
|
void update_values_inverter() {
|
||||||
#ifdef SELECTED_INVERTER_CLASS
|
|
||||||
if (inverter) {
|
if (inverter) {
|
||||||
inverter->update_values();
|
inverter->update_values();
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
#ifdef CAN_INVERTER_SELECTED
|
|
||||||
update_values_can_inverter();
|
|
||||||
#endif // CAN_INVERTER_SELECTED
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void check_reset_reason() {
|
void check_reset_reason() {
|
||||||
|
|
|
@ -39,13 +39,10 @@ String settings_processor(const String& var) {
|
||||||
String(getCANInterfaceName(can_config.battery_double)) + "</span></h4>";
|
String(getCANInterfaceName(can_config.battery_double)) + "</span></h4>";
|
||||||
#endif // DOUBLE_BATTERY
|
#endif // DOUBLE_BATTERY
|
||||||
|
|
||||||
#ifdef CAN_INVERTER_SELECTED
|
if (inverter) {
|
||||||
content += "<h4 style='color: white;'>Inverter interface: <span id='Inverter'>" +
|
content += "<h4 style='color: white;'>Inverter interface: <span id='Inverter'>" +
|
||||||
String(getCANInterfaceName(can_config.inverter)) + "</span></h4>";
|
String(inverter->interface_name()) + "</span></h4>";
|
||||||
#endif //CAN_INVERTER_SELECTED
|
}
|
||||||
#ifdef MODBUS_INVERTER_SELECTED
|
|
||||||
content += "<h4 style='color: white;'>Inverter interface: RS485<span id='Inverter'></span></h4>";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef CAN_SHUNT_SELECTED
|
#ifdef CAN_SHUNT_SELECTED
|
||||||
content += "<h4 style='color: white;'>Shunt Interface: <span id='Shunt'>" +
|
content += "<h4 style='color: white;'>Shunt Interface: <span id='Shunt'>" +
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
class CanInverterProtocol : public InverterProtocol {
|
class CanInverterProtocol : public InverterProtocol {
|
||||||
public:
|
public:
|
||||||
|
virtual const char* interface_name() { return getCANInterfaceName(can_config.inverter); }
|
||||||
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;
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,9 +3,7 @@
|
||||||
// These functions adapt the old C-style global functions inverter-API to the
|
// These functions adapt the old C-style global functions inverter-API to the
|
||||||
// object-oriented inverter protocol API.
|
// object-oriented inverter protocol API.
|
||||||
|
|
||||||
#ifdef SELECTED_INVERTER_CLASS
|
InverterProtocol* inverter = nullptr;
|
||||||
|
|
||||||
InverterProtocol* inverter;
|
|
||||||
|
|
||||||
#ifdef CAN_INVERTER_SELECTED
|
#ifdef CAN_INVERTER_SELECTED
|
||||||
CanInverterProtocol* can_inverter;
|
CanInverterProtocol* can_inverter;
|
||||||
|
@ -30,7 +28,9 @@ void setup_inverter() {
|
||||||
inverter = new SELECTED_INVERTER_CLASS();
|
inverter = new SELECTED_INVERTER_CLASS();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
if (inverter) {
|
||||||
inverter->setup();
|
inverter->setup();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CAN_INVERTER_SELECTED
|
#ifdef CAN_INVERTER_SELECTED
|
||||||
|
@ -52,5 +52,3 @@ void receive_RS485() {
|
||||||
((Rs485InverterProtocol*)inverter)->receive_RS485();
|
((Rs485InverterProtocol*)inverter)->receive_RS485();
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ extern InverterProtocol* inverter;
|
||||||
#include "SOLAX-CAN.h"
|
#include "SOLAX-CAN.h"
|
||||||
#include "SUNGROW-CAN.h"
|
#include "SUNGROW-CAN.h"
|
||||||
|
|
||||||
|
// 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
|
#ifdef CAN_INVERTER_SELECTED
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
class InverterProtocol {
|
class InverterProtocol {
|
||||||
public:
|
public:
|
||||||
virtual void setup() = 0;
|
virtual void setup() = 0;
|
||||||
|
virtual const char* interface_name() = 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;
|
||||||
|
|
|
@ -10,6 +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"; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Create a ModbusRTU server instance with 2000ms timeout
|
// Create a ModbusRTU server instance with 2000ms timeout
|
||||||
ModbusInverterProtocol() : MBserver(2000) { mbPV = ::mbPV; }
|
ModbusInverterProtocol() : MBserver(2000) { mbPV = ::mbPV; }
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
|
|
||||||
class Rs485InverterProtocol : public InverterProtocol {
|
class Rs485InverterProtocol : public InverterProtocol {
|
||||||
public:
|
public:
|
||||||
|
virtual const char* interface_name() { return "RS485"; }
|
||||||
virtual void receive_RS485() = 0;
|
virtual void receive_RS485() = 0;
|
||||||
virtual int baud_rate() = 0;
|
virtual int baud_rate() = 0;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue