summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvgeny Zinoviev <me@ch1p.io>2021-05-16 17:06:27 +0300
committerEvgeny Zinoviev <me@ch1p.io>2021-05-16 17:06:27 +0300
commitb72a8d9e65e303e1497c60d9afdf1956d15fc5f7 (patch)
treeef8d52ce5d35eadad99d5aaf27f905d36313eb13 /src
parente8ceb3b5d429c0b58d60c68cc0d00582eb0fd25a (diff)
turn some bools in GS response into enums
Diffstat (limited to 'src')
-rw-r--r--src/p18/defines.cc16
-rw-r--r--src/p18/response.cc12
-rw-r--r--src/p18/response.h22
-rw-r--r--src/p18/types.h12
4 files changed, 45 insertions, 17 deletions
diff --git a/src/p18/defines.cc b/src/p18/defines.cc
index 4207bde..999f81a 100644
--- a/src/p18/defines.cc
+++ b/src/p18/defines.cc
@@ -243,4 +243,20 @@ ENUM_STR(ParallelConnectionStatus) {
ENUM_STR_DEFAULT;
}
+ENUM_STR(LoadConnectionStatus) {
+ switch (val) {
+ case LoadConnectionStatus::Disconnected: return os << "Disconnected";
+ case LoadConnectionStatus::Connected: return os << "Connected";
+ }
+ ENUM_STR_DEFAULT;
+}
+
+ENUM_STR(ConfigurationStatus) {
+ switch (val) {
+ case ConfigurationStatus::Default: return os << "Default";
+ case ConfigurationStatus::Changed: return os << "Changed";
+ }
+ ENUM_STR_DEFAULT;
+}
+
} \ No newline at end of file
diff --git a/src/p18/response.cc b/src/p18/response.cc
index 742ce9d..6faf5b7 100644
--- a/src/p18/response.cc
+++ b/src/p18/response.cc
@@ -372,10 +372,10 @@ void GeneralStatus::unpack() {
pv2_input_power = stou(list[17]);
pv1_input_voltage = stou(list[18]);
pv2_input_voltage = stou(list[19]);
- settings_values_changed = list[20] == "1";
+ configuration_status = static_cast<ConfigurationStatus>(stou(list[20]));
mppt1_charger_status = static_cast<MPPTChargerStatus>(stou(list[21]));
mppt2_charger_status = static_cast<MPPTChargerStatus>(stou(list[22]));
- load_connected = list[23] == "1";
+ load_connected = static_cast<LoadConnectionStatus>(stou(list[23]));
battery_power_direction = static_cast<BatteryPowerDirection>(stou(list[24]));
dc_ac_power_direction = static_cast<DC_AC_PowerDirection>(stou(list[25]));
line_power_direction = static_cast<LinePowerDirection>(stou(list[26]));
@@ -404,10 +404,10 @@ formattable_ptr GeneralStatus::format(formatter::Format format) {
LINE("pv2_input_power", "PV2 input power", pv2_input_power, Unit::Wh),
LINE("pv1_input_voltage", "PV1 input voltage", pv1_input_voltage / 10.0, Unit::V),
LINE("pv2_input_voltage", "PV2 input voltage", pv2_input_voltage / 10.0, Unit::V),
- LINE("settings_values_changed", "Configuration state", std::string(settings_values_changed ? "Default" : "Custom")),
+ LINE("configuration_status", "Configuration state", configuration_status),
LINE("mppt1_charger_status", "MPPT1 charger status", mppt1_charger_status),
LINE("mppt2_charger_status", "MPPT2 charger status", mppt2_charger_status),
- LINE("load_connected", "Load connection", std::string(load_connected ? "Connected" : "Disconnected")),
+ LINE("load_connected", "Load connection", load_connected),
LINE("battery_power_direction", "Battery power direction", battery_power_direction),
LINE("dc_ac_power_direction", "DC/AC power direction", dc_ac_power_direction),
LINE("line_power_direction", "LINE power direction", line_power_direction),
@@ -714,7 +714,7 @@ void ParallelGeneralStatus::unpack() {
pv2_input_voltage = stou(list[21]);
mppt1_charger_status = static_cast<MPPTChargerStatus>(stou(list[22]));
mppt2_charger_status = static_cast<MPPTChargerStatus>(stou(list[23]));
- load_connected = stou(list[24]);
+ load_connected = static_cast<LoadConnectionStatus>(stou(list[24]));
battery_power_direction = static_cast<BatteryPowerDirection>(stou(list[25]));
dc_ac_power_direction = static_cast<DC_AC_PowerDirection>(stou(list[26]));
line_power_direction = static_cast<LinePowerDirection>(stou(list[27]));
@@ -745,7 +745,7 @@ formattable_ptr ParallelGeneralStatus::format(formatter::Format format) {
LINE("pv2_input_voltage", "PV2 Input voltage", pv2_input_voltage / 10.0, Unit::V),
LINE("mppt1_charger_status", "MPPT1 charger status", mppt1_charger_status),
LINE("mppt2_charger_status", "MPPT2 charger status", mppt2_charger_status),
- LINE("load_connected", "Load connection", std::string(load_connected ? "Connected" : "Disconnected")),
+ LINE("load_connected", "Load connection", load_connected),
LINE("battery_power_direction", "Battery power direction", battery_power_direction),
LINE("dc_ac_power_direction", "DC/AC power direction", dc_ac_power_direction),
LINE("line_power_direction", "Line power direction", line_power_direction),
diff --git a/src/p18/response.h b/src/p18/response.h
index e10b72f..be6eece 100644
--- a/src/p18/response.h
+++ b/src/p18/response.h
@@ -43,7 +43,9 @@ typedef std::variant<
p18::OutputModelSetting,
p18::ParallelConnectionStatus,
p18::SolarPowerPriority,
- p18::WorkingMode
+ p18::WorkingMode,
+ p18::LoadConnectionStatus,
+ p18::ConfigurationStatus
> Variant;
class VariantHolder {
@@ -72,6 +74,8 @@ public:
VariantHolder(p18::ParallelConnectionStatus v) : v_(v) {}
VariantHolder(p18::SolarPowerPriority v) : v_(v) {}
VariantHolder(p18::WorkingMode v) : v_(v) {}
+ VariantHolder(p18::LoadConnectionStatus v) : v_(v) {}
+ VariantHolder(p18::ConfigurationStatus v) : v_(v) {}
friend std::ostream &operator<<(std::ostream &os, VariantHolder const& ref) {
std::visit([&os](const auto& elem) {
@@ -96,7 +100,9 @@ public:
std::holds_alternative<p18::OutputModelSetting>(v_) ||
std::holds_alternative<p18::ParallelConnectionStatus>(v_) ||
std::holds_alternative<p18::SolarPowerPriority>(v_) ||
- std::holds_alternative<p18::WorkingMode>(v_);
+ std::holds_alternative<p18::WorkingMode>(v_) ||
+ std::holds_alternative<p18::LoadConnectionStatus>(v_) ||
+ std::holds_alternative<p18::ConfigurationStatus>(v_);
std::visit([&j, &isEnum](const auto& elem) {
if (isEnum)
@@ -302,14 +308,10 @@ public:
unsigned pv2_input_power; /* unit: W */
unsigned pv1_input_voltage; /* unit: 0.1V */
unsigned pv2_input_voltage; /* unit: 0.1V */
- bool settings_values_changed; /* inverter returns:
- 0: nothing changed
- 1: something changed */
+ p18::ConfigurationStatus configuration_status;
p18::MPPTChargerStatus mppt1_charger_status;
p18::MPPTChargerStatus mppt2_charger_status;
- bool load_connected; /* inverter returns:
- 0: disconnected
- 1: connected */
+ p18::LoadConnectionStatus load_connected;
p18::BatteryPowerDirection battery_power_direction;
p18::DC_AC_PowerDirection dc_ac_power_direction;
p18::LinePowerDirection line_power_direction;
@@ -458,9 +460,7 @@ public:
unsigned pv2_input_voltage; /* unit: 0.1V */
p18::MPPTChargerStatus mppt1_charger_status;
p18::MPPTChargerStatus mppt2_charger_status;
- bool load_connected; /* inverter returns:
- 0: disconnected
- 1: connected */
+ p18::LoadConnectionStatus load_connected;
p18::BatteryPowerDirection battery_power_direction;
p18::DC_AC_PowerDirection dc_ac_power_direction;
p18::LinePowerDirection line_power_direction;
diff --git a/src/p18/types.h b/src/p18/types.h
index 69e95e5..bcabd7c 100644
--- a/src/p18/types.h
+++ b/src/p18/types.h
@@ -151,6 +151,18 @@ enum class ParallelConnectionStatus {
};
ENUM_STR(ParallelConnectionStatus);
+enum class LoadConnectionStatus {
+ Disconnected = 0,
+ Connected = 1,
+};
+ENUM_STR(LoadConnectionStatus);
+
+enum class ConfigurationStatus {
+ Default = 0,
+ Changed = 1,
+};
+ENUM_STR(ConfigurationStatus);
+
struct Flag {
std::string flag;
char letter;