diff options
Diffstat (limited to 'src/protocol_17')
-rw-r--r-- | src/protocol_17/defines.cc | 138 | ||||
-rw-r--r-- | src/protocol_17/defines.h | 32 | ||||
-rw-r--r-- | src/protocol_17/input.cc | 117 | ||||
-rw-r--r-- | src/protocol_17/input.h | 21 | ||||
-rw-r--r-- | src/protocol_17/response.h | 462 | ||||
-rw-r--r-- | src/protocol_17/types.h | 103 |
6 files changed, 873 insertions, 0 deletions
diff --git a/src/protocol_17/defines.cc b/src/protocol_17/defines.cc new file mode 100644 index 0000000..2589861 --- /dev/null +++ b/src/protocol_17/defines.cc @@ -0,0 +1,138 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#include <iostream> + +#include "defines.h" +#include "types.h" + +namespace p17 { + +const std::map<CommandType, std::string> raw_commands = { + {CommandType::GetProtocolID, "PI"}, + {CommandType::GetSeriesNumber, "ID"}, + {CommandType::GetCPUVersion, "VFW"}, + {CommandType::GetSecondaryCPUVersion, "VFW2"}, + {CommandType::GetDeviceModel, "MD"}, + {CommandType::GetRatedInformation, "PIRI"}, + {CommandType::GetGeneralStatus, "GS"}, + {CommandType::GetPowerStatus, "PS"}, + {CommandType::GetWorkingMode, "MOD"}, + {CommandType::GetWarningStatus, "WS"}, + {CommandType::GetFlags, "FLAG"}, + {CommandType::GetCurrentTime, "T"}, + {CommandType::GetTotalGenerated, "ET"}, + {CommandType::GetYearGenerated, "EY"}, + {CommandType::GetMonthGenerated, "EM"}, + {CommandType::GetDayGenerated, "ED"}, + {CommandType::GetHourGenerated, "EH"}, + {CommandType::GetACInputVoltageRange, "GOV"}, + {CommandType::GetACInputFrequencyRange, "GOF"}, + {CommandType::GetMaximumOutputPower, "OPMP"}, + {CommandType::GetMaximumGridOutputPower, "GPMP"}, + {CommandType::GetSolarInputMPPTRange, "MPPTV"}, + {CommandType::GetSolarInputVoltageRange, "SV"}, + {CommandType::GetLCDSleepTimeout, "LST"}, + {CommandType::GetDefaults, "DI"}, + {CommandType::GetBatterySettings, "BATS"}, + {CommandType::GetMachineModel, "DM"}, + {CommandType::GetMachineAdjustableRanges, "MAR"}, + {CommandType::GetFaults, "CFS"}, + {CommandType::GetFaultsHistory, "HFS"}, + {CommandType::GetEnergyControlStatus, "HECS"}, + {CommandType::GetACInputLongTimeHighestAvgVoltage, "GLTHV"}, + {CommandType::GetFirstGeneratedEnergySavedTime, "FET"}, + {CommandType::GetFeedWaitTime, "FT"}, + {CommandType::GetACChargingTimeBucket, "ACCT"}, + {CommandType::GetACLoadsSupplyTimeBucket, "ACLT"}, + {CommandType::GetFeedingGridPowerCalibration, "FPADJ"}, + {CommandType::GetFeedInPowerFactor, "FPPF"}, + {CommandType::GetAutoAdjustPFWithPowerInformation, "AAPF"}, + {CommandType::GetAllowOneOfSTPhaseLossStatus, "PLE"}, + {CommandType::SetLoads, "LON"}, + {CommandType::SetFlag, "P"}, + {CommandType::SetDateTime, "DAT"}, + {CommandType::SetACInputHighestVoltageForFeedingPower, "GOHV"}, + {CommandType::SetACInputHighestFrequencyForFeedingPower, "GOHF"}, + {CommandType::SetACInputLowestVoltageForFeedingPower, "GOLV"}, + {CommandType::SetACInputLowestFrequencyForFeedingPower, "GOLF"}, + {CommandType::SetMaxOutputPower, "OPMP"}, + {CommandType::SetMaxFeedingGridPower, "GPMP"}, + {CommandType::SetSolarInputHighestVoltage, "SIHV"}, + {CommandType::SetSolarInputLowestVoltage, "SILV"}, + {CommandType::SetSolarInputHighestMPPTVoltage, "MPPTHV"}, + {CommandType::SetSolarInputLowestMPPTVoltage, "MPPTLV"}, + {CommandType::SetLCDSleepTimeout, "LST"}, + {CommandType::SetBatteryMaxChargingCurrent, "MCHGC"}, + {CommandType::SetBatteryMaxChargingVoltage, "MCHGV"}, + {CommandType::SetACInputLongTimeHighestAverageVoltage, "GLTHV"}, + {CommandType::SetBatteryDischargingVoltage, "BATDV"}, + {CommandType::SetSolarEnergyDistributionOfPriority, "SEP"}, + {CommandType::SetEnergyDistribution, "ED"}, + {CommandType::SetBatteryChargerApplicationInFloatingCharging, "BCA"}, + {CommandType::SetMachineModel, "DM"}, + {CommandType::SetDefaults, "PF"}, + {CommandType::SetACOutputFreq, "F"}, + {CommandType::SetACOutputRatedVoltage, "V"}, + {CommandType::SetFeedWaitTime, "FT"}, + {CommandType::SetACChargingTimeBucket, "ACCT"}, + {CommandType::SetACLoadsSupplyTimeBucket, "ACLT"}, + {CommandType::SetBatteryType, "BT"}, + {CommandType::SetBatteryInstallTime, "BIT"}, + {CommandType::SetLiFeBatterySelfTest, "BST"}, + {CommandType::SetACChargerKeepBatteryVoltageSetting, "ACCB"}, + {CommandType::SetBatteryTempSensorCompensation, "BTS"}, + {CommandType::SetBatteryMaxACChargingCurrent, "MUCHGC"}, + {CommandType::SetFeedingGridPowerCalibration, "FPADJ"}, + {CommandType::SetBatteryMaxDischargingCurrentInHybridMode, "BDCM"}, + {CommandType::SetFeedInPowerFactor, "FPPF"}, + {CommandType::SetParallelOutput, "PALE"}, + {CommandType::SetRPhaseFeedingGridPowerCalibration, "FPRADJ"}, + {CommandType::SetSPhaseFeedingGridPowerCalibration, "FPSADJ"}, + {CommandType::SetTPhaseFeedingGridPowerCalibration, "FPTADJ"}, + {CommandType::SetAutoAdjustPFWithPowerInformation, "AAPF"}, + {CommandType::SetAllowOneOfSTPhaseLoss, "PLE"}, + {CommandType::SetEmergencyPowerSupplyControl, "EPS"} +}; + +const std::map<int, std::string> fault_codes = { + {1, "BUS exceed the upper limit"}, + {2, "BUS dropp to the lower limit"}, + {3, "BUS soft start circuit timeout"}, + {4, "Inverter voltage soft start timeout"}, + {5, "Inverter current exceed the upper limit"}, + {6, "Temperature over"}, + {7, "Inverter relay work abnormal"}, + {8, "Current sample abnormal when inverter doesn't work"}, + {9, "Solar input voltage exceed upper limit"}, + {10, "SPS power voltage abnormal"}, + {11, "Solar input current exceed upper limit"}, + {12, "Leakage current exceed permit range"}, + {13, "Solar insulation resistance too low"}, + {14, "Inverter DC current exceed permit range when feed power"}, + {15, "The AC input voltage or frequency has been detected different between master CPU and slave CPU"}, + {16, "Leakage current detect circuit abnormal when inverter doesn't work"}, + {17, "Communication loss between master CPU and slave CPU"}, + {18, "Communicate data discordant between master CPU and slave CPU"}, + {19, "AC input ground wire loss"}, + {22, "Battery voltage exceed upper limit"}, + {23, "Over load"}, + {24, "Battery disconnected"}, + {26, "AC output short"}, + {27, "Fan lock"}, + {32, "Battery DC-DC current over"}, + {33, "AC output voltage too low"}, + {34, "AC output voltage too high"}, + {35, "Control board wiring error"}, + {36, "AC circuit voltage sample error"}, +}; + +const std::array<Flag, 6> flags = {{ + {"BUZZ", 'A', "Mute buzzer beep"}, + {"BUZS", 'B', "Mute buzzer beep in standby mode"}, + {"BUZB", 'C', "Mute buzzer beep only on battery discharged status"}, + {"GENI", 'D', "Generator as AC input"}, + {"WAIR", 'E', "Wide AC input range"}, + {"NGRF", 'F', "N/G relay function"}, +}}; + +}
\ No newline at end of file diff --git a/src/protocol_17/defines.h b/src/protocol_17/defines.h new file mode 100644 index 0000000..2a50110 --- /dev/null +++ b/src/protocol_17/defines.h @@ -0,0 +1,32 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#ifndef INVERTER_TOOLS_P17_DEFINES_H +#define INVERTER_TOOLS_P17_DEFINES_H + +#include <map> +#include <string> +#include <array> + +#include "types.h" + +namespace p17 { + +extern const std::map<CommandType, std::string> raw_commands; + +//extern const std::array<int, 5> ac_output_rated_voltages; +// +//extern const std::array<float, 8> bat_ac_recharging_voltages_12v; +//extern const std::array<float, 8> bat_ac_recharging_voltages_24v; +//extern const std::array<float, 8> bat_ac_recharging_voltages_48v; +// +//extern const std::array<float, 12> bat_ac_redischarging_voltages_12v; +//extern const std::array<float, 12> bat_ac_redischarging_voltages_24v; +//extern const std::array<float, 12> bat_ac_redischarging_voltages_48v; + +extern const std::map<int, std::string> fault_codes; + +extern const std::array<Flag, 6> flags; + +} + +#endif //INVERTER_TOOLS_P17_DEFINES_H diff --git a/src/protocol_17/input.cc b/src/protocol_17/input.cc new file mode 100644 index 0000000..b35bf20 --- /dev/null +++ b/src/protocol_17/input.cc @@ -0,0 +1,117 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#include "input.h" +#include "defines.h" +//#include "functions.h" +#include "../util.h" + +namespace p17 { + +using namespace protocol; + +const std::map<std::string, CommandType> client_commands = { + {"get-protocol-id", CommandType::GetProtocolID}, + {"get-date-time", CommandType::GetCurrentTime}, + {"get-total-generated", CommandType::GetTotalGenerated}, + {"get-year-generated", CommandType::GetYearGenerated}, + {"get-month-generated", CommandType::GetMonthGenerated}, + {"get-day-generated", CommandType::GetDayGenerated}, + {"get-hour-generated", CommandType::GetHourGenerated}, + {"get-series-number", CommandType::GetSeriesNumber}, + {"get-cpu-version", CommandType::GetCPUVersion}, + {"get-secondary-cpu-version", CommandType::GetSecondaryCPUVersion}, + {"get-device-model", CommandType::GetDeviceModel}, + {"get-rated", CommandType::GetRatedInformation}, + {"get-general-status", CommandType::GetGeneralStatus}, + {"get-power-status", CommandType::GetPowerStatus}, + {"get-working-mode", CommandType::GetWorkingMode}, + {"get-warnings", CommandType::GetWarningStatus}, + {"get-flags", CommandType::GetFlags}, + {"get-ac-input-voltage-range", CommandType::GetACInputVoltageRange}, + {"get-ac-input-frequency-range", CommandType::GetACInputFrequencyRange}, + {"get-max-grid-output-power", CommandType::GetMaximumGridOutputPower}, + {"get-max-output-power", CommandType::GetMaximumOutputPower}, + {"get-solar-input-mppt-range", CommandType::GetSolarInputMPPTRange}, + {"get-solar-input-voltage-range", CommandType::GetSolarInputVoltageRange}, + {"get-lcd-sleep-timeout", CommandType::GetLCDSleepTimeout}, + {"get-defaults", CommandType::GetDefaults}, + {"get-battery-settings", CommandType::GetBatterySettings}, + {"get-machine-model", CommandType::GetMachineModel}, + {"get-machine-adjustable-ranges", CommandType::GetMachineAdjustableRanges}, + {"get-faults", CommandType::GetFaults}, + {"get-faults-history", CommandType::GetFaultsHistory}, + {"get-energy-control-status", CommandType::GetEnergyControlStatus}, + {"get-ac-input-long-time-highest-average-voltage", CommandType::GetACInputLongTimeHighestAvgVoltage}, + {"get-first-generated-energy-saved-time", CommandType::GetFirstGeneratedEnergySavedTime}, + {"get-feed-wait-time", CommandType::GetFeedWaitTime}, + {"get-ac-charging-time", CommandType::GetACChargingTimeBucket}, + {"get-ac-loads-supply-time", CommandType::GetACLoadsSupplyTimeBucket}, + {"get-feeding-grid-power-calibration", CommandType::GetFeedingGridPowerCalibration}, + {"get-feed-in-power-factor", CommandType::GetFeedInPowerFactor}, + {"get-auto-adjust-pf-with-power-info", CommandType::GetAutoAdjustPFWithPowerInformation}, + {"get-allow-one-of-s-t-phase-loss-state", CommandType::GetAllowOneOfSTPhaseLossStatus}, + {"set-loads", CommandType::SetLoads}, + {"set-flag", CommandType::SetFlag}, + {"set-date-time", CommandType::SetDateTime}, + {"set-ac-input-highest-voltage-for-feeding-power", CommandType::SetACInputHighestVoltageForFeedingPower}, + {"set-ac-input-lowest-voltage-for-feeding-power", CommandType::SetACInputLowestVoltageForFeedingPower}, + {"set-ac-input-highest-frequency-for-feeding-power", CommandType::SetACInputHighestFrequencyForFeedingPower}, + {"set-ac-input-lowest-frequency-for-feeding-power", CommandType::SetACInputLowestFrequencyForFeedingPower}, + {"set-max-output-power", CommandType::SetMaxOutputPower}, + {"set-max-feeding-grid-power", CommandType::SetMaxFeedingGridPower}, + {"set-solar-input-highest-voltage", CommandType::SetSolarInputHighestVoltage}, + {"set-solar-input-lowest-voltage", CommandType::SetSolarInputLowestVoltage}, + {"set-solar-input-highest-mppt-voltage", CommandType::SetSolarInputHighestMPPTVoltage}, + {"set-solar-input-lowest-mppt-voltage", CommandType::SetSolarInputLowestMPPTVoltage}, + {"set-lcd-sleep-timeout", CommandType::SetLCDSleepTimeout}, + {"set-battery-max-charging-current", CommandType::SetBatteryMaxChargingCurrent}, + {"set-battery-max-ac-charging-current", CommandType::SetBatteryMaxACChargingCurrent}, + {"set-battery-max-charging-voltage", CommandType::SetBatteryMaxChargingVoltage}, + {"set-ac-input-long-time-highest-average-voltage", CommandType::SetACInputLongTimeHighestAverageVoltage}, + {"set-battery-discharging-voltage", CommandType::SetBatteryDischargingVoltage}, + {"set-solar-energy-distribution-of-priority", CommandType::SetSolarEnergyDistributionOfPriority}, + {"set-energy-distribution", CommandType::SetEnergyDistribution}, + {"set-battery-charger-application-in-floating-charging", CommandType::SetBatteryChargerApplicationInFloatingCharging}, + {"set-machine-model", CommandType::SetMachineModel}, + {"set-defaults", CommandType::SetDefaults}, + {"set-ac-output-freq", CommandType::SetACOutputFreq}, + {"set-ac-output-rated-voltage", CommandType::SetACOutputRatedVoltage}, + {"set-feed-wait-time", CommandType::SetFeedWaitTime}, + {"set-ac-charging-time", CommandType::SetACChargingTimeBucket}, + {"set-ac-loads-supply-time", CommandType::SetACLoadsSupplyTimeBucket}, + {"set-battery-type", CommandType::SetBatteryType}, + {"set-battery-install-time", CommandType::SetBatteryInstallTime}, + {"set-li-fe-battery-self-test", CommandType::SetLiFeBatterySelfTest}, + {"set-ac-charger-keep-battery-voltage-setting", CommandType::SetACChargerKeepBatteryVoltageSetting}, + {"set-battery-temp-sensor-compensation", CommandType::SetBatteryTempSensorCompensation}, + {"set-feeding-grid-power-calibration", CommandType::SetFeedingGridPowerCalibration}, + {"set-battery-max-discharging-current-in-hybrid-mode", CommandType::SetBatteryMaxDischargingCurrentInHybridMode}, + {"set-feed-in-power-factor", CommandType::SetFeedInPowerFactor}, + {"set-parallel-output", CommandType::SetParallelOutput}, + {"set-r-phase-feeding-grid-power-calibration", CommandType::SetRPhaseFeedingGridPowerCalibration}, + {"set-s-phase-feeding-grid-power-calibration", CommandType::SetSPhaseFeedingGridPowerCalibration}, + {"set-t-phase-feeding-grid-power-calibration", CommandType::SetTPhaseFeedingGridPowerCalibration}, + {"set-auto-adjust-pf-with-power-info", CommandType::SetAutoAdjustPFWithPowerInformation}, + {"set-allow-one-of-s-t-phase-loss", CommandType::SetAllowOneOfSTPhaseLoss}, + {"set-emergency-power-supply-control", CommandType::SetEmergencyPowerSupplyControl}, +}; + +CommandType validate_input(std::string& command, + std::vector<std::string>& arguments, + void* input) { + auto it = client_commands.find(command); + if (it == client_commands.end()) + throw std::invalid_argument("invalid command"); + + auto commandType = it->second; + switch (commandType) { + + + default: + break; + } + + return commandType; +} + +}
\ No newline at end of file diff --git a/src/protocol_17/input.h b/src/protocol_17/input.h new file mode 100644 index 0000000..5ac64fe --- /dev/null +++ b/src/protocol_17/input.h @@ -0,0 +1,21 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#ifndef INVERTER_TOOLS_P17_INPUT_H +#define INVERTER_TOOLS_P17_INPUT_H + +#include <map> +#include <string> +#include <vector> + +#include "../protocol/input.h" +#include "types.h" + +namespace p17 { + +extern const std::map<std::string, p17::CommandType> client_commands; + +CommandType validate_input(std::string& command, std::vector<std::string>& arguments, void* input); + +} + +#endif //INVERTER_TOOLS_P17_INPUT_H diff --git a/src/protocol_17/response.h b/src/protocol_17/response.h new file mode 100644 index 0000000..93a4ffe --- /dev/null +++ b/src/protocol_17/response.h @@ -0,0 +1,462 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#ifndef INVERTER_TOOLS_P17_RESPONSE_H +#define INVERTER_TOOLS_P17_RESPONSE_H + +#include <string> +#include <vector> +#include <memory> +#include <variant> +#include <nlohmann/json.hpp> + +#include "types.h" +#include "../formatter/formatter.h" +#include "../protocol/response.h" + +namespace p17::response_type { + +using protocol::BaseResponse; +using nlohmann::json; + +typedef std::shared_ptr<formatter::Formattable> formattable_ptr; + + +/** + * Value holder for the formatter module + */ + +/*typedef std::variant< + unsigned, + unsigned short, + unsigned long, + bool, + double, + std::string, + p18::BatteryType, + p18::BatteryPowerDirection, + p18::ChargerSourcePriority, + p18::DC_AC_PowerDirection, + p18::InputVoltageRange, + p18::LinePowerDirection, + p18::MachineType, + p18::MPPTChargerStatus, + p18::Topology, + p18::OutputSourcePriority, + p18::OutputModelSetting, + p18::ParallelConnectionStatus, + p18::SolarPowerPriority, + p18::WorkingMode, + p18::LoadConnectionStatus, + p18::ConfigurationStatus +> Variant; + +class VariantHolder { +private: + Variant v_; + +public: + VariantHolder(unsigned v) : v_(v) {} + VariantHolder(unsigned short v) : v_(v) {} + VariantHolder(unsigned long v) : v_(v) {} + VariantHolder(bool v) : v_(v) {} + VariantHolder(double v) : v_(v) {} + VariantHolder(std::string v) : v_(v) {} + VariantHolder(p18::BatteryType v) : v_(v) {} + VariantHolder(p18::BatteryPowerDirection v) : v_(v) {} + VariantHolder(p18::ChargerSourcePriority v) : v_(v) {} + VariantHolder(p18::DC_AC_PowerDirection v) : v_(v) {} + VariantHolder(p18::InputVoltageRange v) : v_(v) {} + VariantHolder(p18::LinePowerDirection v) : v_(v) {} + VariantHolder(p18::MachineType v) : v_(v) {} + VariantHolder(p18::MPPTChargerStatus v) : v_(v) {} + VariantHolder(p18::Topology v) : v_(v) {} + VariantHolder(p18::OutputSourcePriority v) : v_(v) {} + VariantHolder(p18::OutputModelSetting v) : v_(v) {} + 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) { + os << elem; + }, ref.v_); + return os; + } + + inline json toJSON() const { + json j; + bool isEnum = + std::holds_alternative<p18::BatteryType>(v_) || + std::holds_alternative<p18::BatteryPowerDirection>(v_) || + std::holds_alternative<p18::ChargerSourcePriority>(v_) || + std::holds_alternative<p18::DC_AC_PowerDirection>(v_) || + std::holds_alternative<p18::InputVoltageRange>(v_) || + std::holds_alternative<p18::LinePowerDirection>(v_) || + std::holds_alternative<p18::MachineType>(v_) || + std::holds_alternative<p18::MPPTChargerStatus>(v_) || + std::holds_alternative<p18::Topology>(v_) || + std::holds_alternative<p18::OutputSourcePriority>(v_) || + 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::LoadConnectionStatus>(v_) || + std::holds_alternative<p18::ConfigurationStatus>(v_); + + std::visit([&j, &isEnum](const auto& elem) { + if (isEnum) + j = formatter::to_str(elem); + else + j = elem; + }, v_); + + return j; + } + + inline json toSimpleJSON() const { + json j; + std::visit([&j](const auto& elem) { + j = elem; + }, v_); + return j; + } +}; + + +class GetResponse : public BaseResponse { +protected: + const char* getData() const; + size_t getDataSize() const; + std::vector<std::string> getList(std::vector<size_t> itemLengths) const; + +public: + using BaseResponse::BaseResponse; + bool validate() override; +}; + +class SetResponse : public BaseResponse { +public: + using BaseResponse::BaseResponse; + void unpack() override; + bool validate() override; + formattable_ptr format(formatter::Format format) override; + bool get(); +};*/ + + +/** + * Actual typed responses + */ + +class ProtocolID : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned id = 0; +}; + +class CurrentTime : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned year = 0; + unsigned short month = 0; + unsigned short day = 0; + unsigned short hour = 0; + unsigned short minute = 0; + unsigned short second = 0; +}; + +class TotalGenerated : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned long wh = 0; +}; + +class YearGenerated : public TotalGenerated { +public: + using TotalGenerated::TotalGenerated; +}; + +class MonthGenerated : public TotalGenerated { +public: + using TotalGenerated::TotalGenerated; +}; + +class DayGenerated : public TotalGenerated { +public: + using TotalGenerated::TotalGenerated; +}; + +class HourGenerated : public TotalGenerated { +public: + using TotalGenerated::TotalGenerated; +}; + +class SeriesNumber : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + std::string id; +}; + +class CPUVersion : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + std::string main_cpu_version; + std::string slave1_cpu_version; + std::string slave2_cpu_version; +}; + +class RatedInformation : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned ac_input_rating_voltage; /* unit: 0.1V */ + unsigned ac_input_rating_current; /* unit: 0.1A */ + unsigned ac_output_rating_voltage; /* unit: 0.1A */ + unsigned ac_output_rating_freq; /* unit: 0.1Hz */ + unsigned ac_output_rating_current; /* unit: 0.1A */ + unsigned ac_output_rating_apparent_power; /* unit: VA */ + unsigned ac_output_rating_active_power; /* unit: W */ + unsigned battery_rating_voltage; /* unit: 0.1V */ + unsigned battery_recharge_voltage; /* unit: 0.1V */ + unsigned battery_redischarge_voltage; /* unit: 0.1V */ + unsigned battery_under_voltage; /* unit: 0.1V */ + unsigned battery_bulk_voltage; /* unit: 0.1V */ + unsigned battery_float_voltage; /* unit: 0.1V */ + p18::BatteryType battery_type; + unsigned max_ac_charging_current; /* unit: A */ + unsigned max_charging_current; /* unit: A */ + p18::InputVoltageRange input_voltage_range; + p18::OutputModelSetting output_source_priority; + p18::ChargerSourcePriority charger_source_priority; + unsigned parallel_max_num; + p18::MachineType machine_type; + p18::Topology topology; + p18::OutputModelSetting output_model_setting; + p18::SolarPowerPriority solar_power_priority; + std::string mppt; +}; + +class GeneralStatus : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned grid_voltage; /* unit: 0.1V */ + unsigned grid_freq; /* unit: 0.1Hz */ + unsigned ac_output_voltage; /* unit: 0.1V */ + unsigned ac_output_freq; /* unit: 0.1Hz */ + unsigned ac_output_apparent_power; /* unit: VA */ + unsigned ac_output_active_power; /* unit: W */ + unsigned output_load_percent; /* unit: % */ + unsigned battery_voltage; /* unit: 0.1V */ + unsigned battery_voltage_scc; /* unit: 0.1V */ + unsigned battery_voltage_scc2; /* unit: 0.1V */ + unsigned battery_discharge_current; /* unit: A */ + unsigned battery_charging_current; /* unit: A */ + unsigned battery_capacity; /* unit: % */ + unsigned inverter_heat_sink_temp; /* unit: C */ + unsigned mppt1_charger_temp; /* unit: C */ + unsigned mppt2_charger_temp; /* unit: C */ + unsigned pv1_input_power; /* unit: W */ + unsigned pv2_input_power; /* unit: W */ + unsigned pv1_input_voltage; /* unit: 0.1V */ + unsigned pv2_input_voltage; /* unit: 0.1V */ + p18::ConfigurationStatus configuration_status; + p18::MPPTChargerStatus mppt1_charger_status; + p18::MPPTChargerStatus mppt2_charger_status; + p18::LoadConnectionStatus load_connected; + p18::BatteryPowerDirection battery_power_direction; + p18::DC_AC_PowerDirection dc_ac_power_direction; + p18::LinePowerDirection line_power_direction; + unsigned local_parallel_id; /* 0 .. (parallel number - 1) */ +}; + +class WorkingMode : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + p18::WorkingMode mode = static_cast<p18::WorkingMode>(0); +}; + +class FaultsAndWarnings : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned fault_code = 0; + bool line_fail = false; + bool output_circuit_short = false; + bool inverter_over_temperature = false; + bool fan_lock = false; + bool battery_voltage_high = false; + bool battery_low = false; + bool battery_under = false; + bool over_load = false; + bool eeprom_fail = false; + bool power_limit = false; + bool pv1_voltage_high = false; + bool pv2_voltage_high = false; + bool mppt1_overload_warning = false; + bool mppt2_overload_warning = false; + bool battery_too_low_to_charge_for_scc1 = false; + bool battery_too_low_to_charge_for_scc2 = false; +}; + +class FlagsAndStatuses : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + bool buzzer = false; + bool overload_bypass = false; + bool lcd_escape_to_default_page_after_1min_timeout = false; + bool overload_restart = false; + bool over_temp_restart = false; + bool backlight_on = false; + bool alarm_on_primary_source_interrupt = false; + bool fault_code_record = false; + char reserved = '0'; +}; + +class Defaults : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned ac_output_voltage = 0; /* unit: 0.1V */ + unsigned ac_output_freq = 0; + p18::InputVoltageRange ac_input_voltage_range = static_cast<InputVoltageRange>(0); + unsigned battery_under_voltage = 0; + unsigned charging_float_voltage = 0; + unsigned charging_bulk_voltage = 0; + unsigned battery_recharge_voltage = 0; + unsigned battery_redischarge_voltage = 0; + unsigned max_charging_current = 0; + unsigned max_ac_charging_current = 0; + p18::BatteryType battery_type = static_cast<BatteryType>(0); + p18::OutputSourcePriority output_source_priority = static_cast<OutputSourcePriority>(0); + p18::ChargerSourcePriority charger_source_priority = static_cast<ChargerSourcePriority>(0); + p18::SolarPowerPriority solar_power_priority = static_cast<SolarPowerPriority>(0); + p18::MachineType machine_type = static_cast<MachineType>(0); + p18::OutputModelSetting output_model_setting = static_cast<OutputModelSetting>(0); + bool flag_buzzer = false; + bool flag_overload_restart = false; + bool flag_over_temp_restart = false; + bool flag_backlight_on = false; + bool flag_alarm_on_primary_source_interrupt = false; + bool flag_fault_code_record = false; + bool flag_overload_bypass = false; + bool flag_lcd_escape_to_default_page_after_1min_timeout = false; +}; + +class AllowedChargingCurrents : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + std::vector<unsigned> amps; +}; + +class AllowedACChargingCurrents : public AllowedChargingCurrents { +public: + using AllowedChargingCurrents::AllowedChargingCurrents; +}; + +class ParallelRatedInformation : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + p18::ParallelConnectionStatus parallel_id_connection_status = static_cast<ParallelConnectionStatus>(0); + unsigned serial_number_valid_length = 0; + std::string serial_number; + p18::ChargerSourcePriority charger_source_priority = static_cast<ChargerSourcePriority>(0); + unsigned max_ac_charging_current = 0; // unit: A + unsigned max_charging_current = 0; // unit: A + p18::OutputModelSetting output_model_setting = static_cast<OutputModelSetting>(0); +}; + +class ParallelGeneralStatus : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + p18::ParallelConnectionStatus parallel_id_connection_status; + p18::WorkingMode work_mode; + unsigned fault_code; + unsigned grid_voltage; /* unit: 0.1V */ + unsigned grid_freq; /* unit: 0.1Hz */ + unsigned ac_output_voltage; /* unit: 0.1V */ + unsigned ac_output_freq; /* unit: 0.1Hz */ + unsigned ac_output_apparent_power; /* unit: VA */ + unsigned ac_output_active_power; /* unit: W */ + unsigned total_ac_output_apparent_power; /* unit: VA */ + unsigned total_ac_output_active_power; /* unit: W */ + unsigned output_load_percent; /* unit: % */ + unsigned total_output_load_percent; /* unit: % */ + unsigned battery_voltage; /* unit: 0.1V */ + unsigned battery_discharge_current; /* unit: A */ + unsigned battery_charging_current; /* unit: A */ + unsigned total_battery_charging_current; /* unit: A */ + unsigned battery_capacity; /* unit: % */ + unsigned pv1_input_power; /* unit: W */ + unsigned pv2_input_power; /* unit: W */ + unsigned pv1_input_voltage; /* unit: 0.1V */ + unsigned pv2_input_voltage; /* unit: 0.1V */ + p18::MPPTChargerStatus mppt1_charger_status; + p18::MPPTChargerStatus mppt2_charger_status; + p18::LoadConnectionStatus load_connected; + p18::BatteryPowerDirection battery_power_direction; + p18::DC_AC_PowerDirection dc_ac_power_direction; + p18::LinePowerDirection line_power_direction; + unsigned max_temp; /* unit: C */ +}; + +class ACChargingTimeBucket : public GetResponse { +public: + using GetResponse::GetResponse; + void unpack() override; + formattable_ptr format(formatter::Format format) override; + + unsigned short start_h = 0; + unsigned short start_m = 0; + unsigned short end_h = 0; + unsigned short end_m = 0; +}; + +class ACLoadsSupplyTimeBucket : public ACChargingTimeBucket { +public: + using ACChargingTimeBucket::ACChargingTimeBucket; +}; + +} // namespace protocol_18 + +#endif //INVERTER_TOOLS_P17_RESPONSE_H diff --git a/src/protocol_17/types.h b/src/protocol_17/types.h new file mode 100644 index 0000000..daec2e1 --- /dev/null +++ b/src/protocol_17/types.h @@ -0,0 +1,103 @@ +// SPDX-License-Identifier: BSD-3-Clause + +#ifndef INVERTER_TOOLS_P17_TYPES_H +#define INVERTER_TOOLS_P17_TYPES_H + +namespace p17 { + +enum class CommandType: int { + GetProtocolID = 0, + GetCurrentTime, + GetTotalGenerated, + GetYearGenerated, + GetMonthGenerated, + GetDayGenerated, + GetHourGenerated, + GetSeriesNumber, + GetCPUVersion, + GetSecondaryCPUVersion, + GetDeviceModel, + GetRatedInformation, + GetGeneralStatus, + GetPowerStatus, + GetWorkingMode, + GetWarningStatus, + GetFlags, + GetACInputVoltageRange, + GetACInputFrequencyRange, + GetMaximumGridOutputPower, + GetMaximumOutputPower, + GetSolarInputMPPTRange, + GetSolarInputVoltageRange, + GetLCDSleepTimeout, + GetDefaults, + GetBatterySettings, + GetMachineModel, + GetMachineAdjustableRanges, + GetFaults, + GetFaultsHistory, + GetEnergyControlStatus, + GetACInputLongTimeHighestAvgVoltage, + GetFirstGeneratedEnergySavedTime, + GetFeedWaitTime, + GetACChargingTimeBucket, + GetACLoadsSupplyTimeBucket, + GetFeedingGridPowerCalibration, + GetFeedInPowerFactor, + GetAutoAdjustPFWithPowerInformation, + GetAllowOneOfSTPhaseLossStatus, + SetLoads = 100, + SetFlag, + SetDateTime, + SetACInputHighestVoltageForFeedingPower, + SetACInputLowestVoltageForFeedingPower, + SetACInputHighestFrequencyForFeedingPower, + SetACInputLowestFrequencyForFeedingPower, + SetMaxOutputPower, + SetMaxFeedingGridPower, + SetSolarInputHighestVoltage, + SetSolarInputLowestVoltage, + SetSolarInputHighestMPPTVoltage, + SetSolarInputLowestMPPTVoltage, + SetLCDSleepTimeout, + SetBatteryMaxChargingCurrent, + SetBatteryMaxACChargingCurrent, + SetBatteryMaxChargingVoltage, + SetACInputLongTimeHighestAverageVoltage, + SetBatteryDischargingVoltage, + SetSolarEnergyDistributionOfPriority, + SetEnergyDistribution, + SetBatteryChargerApplicationInFloatingCharging, + SetMachineModel, + SetDefaults, + SetACOutputFreq, + SetACOutputRatedVoltage, + SetFeedWaitTime, + SetACChargingTimeBucket, + SetACLoadsSupplyTimeBucket, + SetBatteryType, + SetBatteryInstallTime, + SetLiFeBatterySelfTest, + SetACChargerKeepBatteryVoltageSetting, + SetBatteryTempSensorCompensation, + SetFeedingGridPowerCalibration, + SetBatteryMaxDischargingCurrentInHybridMode, + SetFeedInPowerFactor, + SetParallelOutput, + SetRPhaseFeedingGridPowerCalibration, // ??? + SetSPhaseFeedingGridPowerCalibration, // ??? + SetTPhaseFeedingGridPowerCalibration, // ??? + SetAutoAdjustPFWithPowerInformation, + SetAllowOneOfSTPhaseLoss, + SetEmergencyPowerSupplyControl, +}; + +struct Flag { + std::string flag; + char letter; + std::string description; +}; + +} + +#endif //INVERTER_TOOLS_P17_TYPES_H
\ No newline at end of file |