From 25fef43d66116c129bf0844a5e17c6da14aae3a9 Mon Sep 17 00:00:00 2001 From: trabus322 Date: Wed, 20 Mar 2024 20:17:15 +0100 Subject: [PATCH] Release for adding short names --- inc/hoymiles/dtu.h | 2 +- inc/hoymiles/microinverter.h | 2 +- inc/hoymiles/port.h | 2 +- .../portParameters/portParametersGeneric.h | 12 ++++---- src/hoymiles/dtu.cpp | 4 +-- src/hoymiles/microinverter.cpp | 4 +-- src/hoymiles/port.cpp | 11 +++++-- .../portParameters/portParameters.cpp | 30 +++++++++---------- .../portParameters/portParametersGeneric.cpp | 9 +++--- src/main.cpp | 10 +++++-- 10 files changed, 49 insertions(+), 37 deletions(-) diff --git a/inc/hoymiles/dtu.h b/inc/hoymiles/dtu.h index fcd136e..bce11dd 100644 --- a/inc/hoymiles/dtu.h +++ b/inc/hoymiles/dtu.h @@ -31,7 +31,7 @@ class Dtu { // void printMicroinverters(); - void printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet); + void printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet, bool shortNames); ~Dtu(); }; diff --git a/inc/hoymiles/microinverter.h b/inc/hoymiles/microinverter.h index 12f10fa..d582cc3 100644 --- a/inc/hoymiles/microinverter.h +++ b/inc/hoymiles/microinverter.h @@ -21,7 +21,7 @@ class Microinverter { void updatePorts(std::vector ¶metersToGet, bool allParameters); - void printPorts(std::vector ¶metersToGet, bool allParameters); + void printPorts(std::vector ¶metersToGet, bool allParameters, bool shortNames); long long getTodayProduction(); diff --git a/inc/hoymiles/port.h b/inc/hoymiles/port.h index dbdb50b..02cb72f 100644 --- a/inc/hoymiles/port.h +++ b/inc/hoymiles/port.h @@ -28,7 +28,7 @@ class Port { void updateParameters(std::vector ¶metersToGet, bool allParameters); - void printParameters(std::vector ¶metersToGet, bool allParameters); + void printParameters(std::vector ¶metersToGet, bool allParameters, bool shortNames); }; #endif \ No newline at end of file diff --git a/inc/hoymiles/portParameters/portParametersGeneric.h b/inc/hoymiles/portParameters/portParametersGeneric.h index beae85a..ebec562 100644 --- a/inc/hoymiles/portParameters/portParametersGeneric.h +++ b/inc/hoymiles/portParameters/portParametersGeneric.h @@ -16,7 +16,7 @@ class PortParameter { virtual void setValueFromRegisters(uint16_t *readArray, int registerCount); public: - PortParameter(std::string name, uint16_t parameterAddressOffset, int registerSize); + PortParameter(std::string name, std::string shortName, uint16_t parameterAddressOffset, int registerSize); virtual ~PortParameter(); @@ -33,6 +33,8 @@ class PortParameter { public: std::string name; + std::string shortName; + int age; std::pair getValue(); @@ -42,24 +44,24 @@ class PortParameter { void updateValue(std::shared_ptr modubs, uint16_t portStartAddress); }; -class PortParameterFloat : virtual public PortParameter { +class PortParameterFloat : public PortParameter { protected: int decimalPlaces; virtual void setValueFromRegisters(uint16_t *readArray, int registerCount); public: - PortParameterFloat(std::string name, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize); + PortParameterFloat(std::string name, std::string shortName, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize); std::string getOutputValue(); }; -class PortParameterInt : virtual public PortParameter { +class PortParameterInt : public PortParameter { protected: virtual void setValueFromRegisters(uint16_t *readArray, int registerCount); public: - PortParameterInt(std::string name, uint16_t parameterAddressOffset, int registerSize); + PortParameterInt(std::string name, std::string shortName, uint16_t parameterAddressOffset, int registerSize); std::string getOutputValue(); }; diff --git a/src/hoymiles/dtu.cpp b/src/hoymiles/dtu.cpp index f980262..7c59ac9 100644 --- a/src/hoymiles/dtu.cpp +++ b/src/hoymiles/dtu.cpp @@ -90,7 +90,7 @@ void Dtu::updateMicroinverters(std::vector ¶metersToGet, bool a } } -void Dtu::printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet) { +void Dtu::printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet, bool shortNames) { if (microinvertersToGet.empty()) { std::vector::iterator microinvertersIterator = this->microinverters.begin(); while (microinvertersIterator != this->microinverters.end()) { @@ -103,7 +103,7 @@ void Dtu::printMicroinverters(std::vector ¶metersToGet, bool al while (microinvertersToGetIterator != microinvertersToGet.end()) { std::pair microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator); if (microinverterPair.first) { - microinverterPair.second->printPorts(parametersToGet, allParameters); + microinverterPair.second->printPorts(parametersToGet, allParameters, shortNames); } microinvertersToGetIterator++; } diff --git a/src/hoymiles/microinverter.cpp b/src/hoymiles/microinverter.cpp index a34cb3b..101ab29 100644 --- a/src/hoymiles/microinverter.cpp +++ b/src/hoymiles/microinverter.cpp @@ -20,12 +20,12 @@ void Microinverter::updatePorts(std::vector ¶metersToGet, bool } } -void Microinverter::printPorts(std::vector ¶metersToGet, bool allParameters) { +void Microinverter::printPorts(std::vector ¶metersToGet, bool allParameters, bool shortNames) { std::cout << "Microinverter: " << this->serialNumber << std::endl; std::vector::iterator portsIterator = this->ports.begin(); while (portsIterator != this->ports.end()) { - portsIterator->printParameters(parametersToGet, allParameters); + portsIterator->printParameters(parametersToGet, allParameters, shortNames); std::cout << std::endl; portsIterator++; } diff --git a/src/hoymiles/port.cpp b/src/hoymiles/port.cpp index 081665e..7ae5f5c 100644 --- a/src/hoymiles/port.cpp +++ b/src/hoymiles/port.cpp @@ -113,7 +113,7 @@ void Port::updateParameters(std::vector ¶metersToGet, bool allP } } -void Port::printParameters(std::vector ¶metersToGet, bool allParameters) { +void Port::printParameters(std::vector ¶metersToGet, bool allParameters, bool shortNames) { if (allParameters && parametersToGet.size() < this->parameters.size()) { std::vector>::iterator parametersIterator = this->parameters.begin(); while (parametersIterator != this->parameters.end()) { @@ -134,7 +134,14 @@ void Port::printParameters(std::vector ¶metersToGet, bool allPa parameterPair = this->getParameterByName(*parametersToGetIterator); if (parameterPair.second) { - std::cout << " " << parameterPair.first->name << ": " << parameterPair.first->getOutputValue() << " |"; + std::cout << " "; + if(shortNames) { + std::cout << parameterPair.first->shortName; + } + else { + std::cout << parameterPair.first->name; + } + std::cout << ": " << parameterPair.first->getOutputValue() << " |"; } parametersToGetIterator++; } diff --git a/src/hoymiles/portParameters/portParameters.cpp b/src/hoymiles/portParameters/portParameters.cpp index 9119df6..4ef3ca3 100644 --- a/src/hoymiles/portParameters/portParameters.cpp +++ b/src/hoymiles/portParameters/portParameters.cpp @@ -5,7 +5,7 @@ #include "portParameters.h" -PortParameterMicroinverterSerialNumber::PortParameterMicroinverterSerialNumber() : PortParameterInt("microinverterSerialNumber", 0x0001, 6), PortParameter("microinverterSerialNumber", 0x0001, 6) {} +PortParameterMicroinverterSerialNumber::PortParameterMicroinverterSerialNumber() : PortParameterInt("microinverterSerialNumber", "mSN", 0x0001, 6) {} void PortParameterMicroinverterSerialNumber::setValueFromRegisters(uint16_t *readArray, int registerCount) { uint16_t readValue; @@ -20,7 +20,7 @@ void PortParameterMicroinverterSerialNumber::setValueFromRegisters(uint16_t *rea this->value.i = std::stoll(readValueString); } -PortParameterPortNumber::PortParameterPortNumber() : PortParameterInt("portNumber", 0x0007, 1), PortParameter("portNumber", 0x0007, 1) {} +PortParameterPortNumber::PortParameterPortNumber() : PortParameterInt("portNumber", "pN", 0x0007, 1) {} void PortParameterPortNumber::setValueFromRegisters(uint16_t *readArray, int registerCount) { if (registerCount > 0) { @@ -31,28 +31,28 @@ void PortParameterPortNumber::setValueFromRegisters(uint16_t *readArray, int reg } } -PortParameterPvVoltage::PortParameterPvVoltage() : PortParameterFloat("pvVoltage", 1, 0x0008, 2), PortParameter("pvVoltage", 0x0008, 2) {} +PortParameterPvVoltage::PortParameterPvVoltage() : PortParameterFloat("pvVoltage", "pvU", 1, 0x0008, 2) {} -PortParameterPvCurrentMi::PortParameterPvCurrentMi() : PortParameterFloat("pvCurrentMI", 1, 0x000a, 2), PortParameter("pvCurrentMI", 0x000a, 2) {} +PortParameterPvCurrentMi::PortParameterPvCurrentMi() : PortParameterFloat("pvCurrentMI", "pvIMI", 1, 0x000a, 2) {} -PortParameterPvCurrentHm::PortParameterPvCurrentHm() : PortParameterFloat("pvCurrentHM", 2, 0x000a, 2), PortParameter("pvCurrentHM", 0x000a, 2) {} +PortParameterPvCurrentHm::PortParameterPvCurrentHm() : PortParameterFloat("pvCurrentHM", "pvIHM", 2, 0x000a, 2) {} -PortParameterGridVoltage::PortParameterGridVoltage() : PortParameterFloat("gridVoltage", 1, 0x000c, 2), PortParameter("gridVoltage", 0x000c, 2) {} +PortParameterGridVoltage::PortParameterGridVoltage() : PortParameterFloat("gridVoltage", "gU", 1, 0x000c, 2) {} -PortParameterGridFrequency::PortParameterGridFrequency() : PortParameterFloat("gridFrequency", 2, 0x000e, 2), PortParameter("gridFrequency", 0x000e, 2) {} +PortParameterGridFrequency::PortParameterGridFrequency() : PortParameterFloat("gridFrequency", "gF", 2, 0x000e, 2) {} -PortParameterPvPower::PortParameterPvPower() : PortParameterFloat("pvPower", 1, 0x0010, 2), PortParameter("pvPower", 0x0010, 2) {} +PortParameterPvPower::PortParameterPvPower() : PortParameterFloat("pvPower", "pvP", 1, 0x0010, 2) {} -PortParameterTodayProduction::PortParameterTodayProduction() : PortParameterInt("todayProduction", 0x0012, 2), PortParameter("todayProduction", 0x0012, 2) {} +PortParameterTodayProduction::PortParameterTodayProduction() : PortParameterInt("todayProduction", "tdP", 0x0012, 2) {} -PortParameterTotalProduction::PortParameterTotalProduction() : PortParameterInt("totalProduction", 0x0014, 4), PortParameter("totalProduction", 0x0014, 4) {} +PortParameterTotalProduction::PortParameterTotalProduction() : PortParameterInt("totalProduction", "ttP", 0x0014, 4) {} -PortParameterTemperature::PortParameterTemperature() : PortParameterFloat("temperature", 1, 0x0018, 2), PortParameter("temperature", 0x0018, 2) {} +PortParameterTemperature::PortParameterTemperature() : PortParameterFloat("temperature", "t", 1, 0x0018, 2) {} -PortParameterOperatingStatus::PortParameterOperatingStatus() : PortParameterInt("operatingStatus", 0x001a, 2), PortParameter("operatingStatus", 0x001a, 2) {} +PortParameterOperatingStatus::PortParameterOperatingStatus() : PortParameterInt("operatingStatus", "oS", 0x001a, 2) {} -PortParameterAlarmCode::PortParameterAlarmCode() : PortParameterInt("alarmCode", 0x001c, 2), PortParameter("alarmCode", 0x001c, 2) {} +PortParameterAlarmCode::PortParameterAlarmCode() : PortParameterInt("alarmCode", "aC", 0x001c, 2) {} -PortParameterAlarmCount::PortParameterAlarmCount() : PortParameterInt("alarmCount", 0x001e, 2), PortParameter("alarmCount", 0x001e, 2) {} +PortParameterAlarmCount::PortParameterAlarmCount() : PortParameterInt("alarmCount", "aCnt", 0x001e, 2) {} -PortParameterLinkStatus::PortParameterLinkStatus() : PortParameterInt("linkStatus", 0x020, 2), PortParameter("linkStatus", 0x020, 2) {} \ No newline at end of file +PortParameterLinkStatus::PortParameterLinkStatus() : PortParameterInt("linkStatus", "lS", 0x020, 2) {} \ No newline at end of file diff --git a/src/hoymiles/portParameters/portParametersGeneric.cpp b/src/hoymiles/portParameters/portParametersGeneric.cpp index 6f03928..96be846 100644 --- a/src/hoymiles/portParameters/portParametersGeneric.cpp +++ b/src/hoymiles/portParameters/portParametersGeneric.cpp @@ -8,8 +8,9 @@ #include "portParametersGeneric.h" -PortParameter::PortParameter(std::string name, uint16_t parameterAddressOffset, int registerSize) { +PortParameter::PortParameter(std::string name, std::string shortName, uint16_t parameterAddressOffset, int registerSize) { this->name = name; + this->shortName = shortName; this->parameterAddressOffset = parameterAddressOffset; this->registerSize = registerSize; @@ -33,9 +34,7 @@ void PortParameter::updateValue(std::shared_ptr modbus, uint16_t p uint16_t readArray[this->registerSize]; int registerCount; - // modbus_context_mutex->lock(); registerCount = modbus.get()->modbus_read_holding_registers(portStartAddress + this->parameterAddressOffset, this->registerSize, readArray); - // modbus_context_mutex->unlock(); if(registerCount != 0){ this->age++; @@ -47,7 +46,7 @@ void PortParameter::updateValue(std::shared_ptr modbus, uint16_t p } } -PortParameterFloat::PortParameterFloat(std::string name, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, parameterAddressOffset, registerSize) { +PortParameterFloat::PortParameterFloat(std::string name, std::string shortName, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, shortName, parameterAddressOffset, registerSize) { this->decimalPlaces = decimalPlaces; this->valueType = Float; @@ -68,7 +67,7 @@ std::string PortParameterFloat::getOutputValue() { return valueStringStream.str().append(separator.append(std::to_string(this->age))); } -PortParameterInt::PortParameterInt(std::string name, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, parameterAddressOffset, registerSize) { +PortParameterInt::PortParameterInt(std::string name, std::string shortName, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, shortName, parameterAddressOffset, registerSize) { this->valueType = Int; this->value.i = 0; diff --git a/src/main.cpp b/src/main.cpp index 08ac74e..fee9da8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ int main(int argc, char **argv) { signal(SIGTERM, sigHandler); signal(SIGABRT, sigHandler); - std::string version{"v1.0h"}; + std::string version{"v1.0sn"}; std::cout << version << std::endl; CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"}; @@ -33,7 +33,7 @@ int main(int argc, char **argv) { hoymilesClient.add_option("-p,--port", port, portHelp)->group("Networking"); std::vector parametersToGet{}; - std::string parametersToGetHelp{"List of parameters to fetch, delimited by ','; possible parameters:\n - pvVoltage\n - pvCurrentMI\n - pvCurrentHM\n - gridVoltage\n - gridFrequency\n - pvPower\n - todayProduction\n - totalProduction\n - temperature\n - operatingStatus\n - alarmCode\n - alarmCount\n - linkStatus"}; + std::string parametersToGetHelp{"List of parameters to fetch, delimited by ','; possible parameters:\n - pvVoltage [pvU]\n - pvCurrentMI [pvIMI]\n - pvCurrentHM [pvIHM]\n - gridVoltage [gU]\n - gridFrequency [gF]\n - pvPower [gP]\n - todayProduction [tdP]\n - totalProduction [ttP]\n - temperature [t]\n - operatingStatus [oS]\n - alarmCode [aC]\n - alarmCount [aCnt]\n - linkStatus [lS]"}; hoymilesClient.add_option>("-P,--parameters", parametersToGet, parametersToGetHelp)->delimiter(',')->group("Parameters"); bool allParameters = false; @@ -45,6 +45,10 @@ int main(int argc, char **argv) { std::string microinvertersToGetHelp{"List of microinverters to fetch, delimited by ','; if omitted, all are fetched"}; hoymilesClient.add_option>("-m,--microinverters", microinvertersToGet, microinvertersToGetHelp)->delimiter(',')->group("Microinverters"); + bool shortNames = false; + std::string shortNamesHelp{"Print short parameter names"}; + hoymilesClient.add_flag("-s,--short", shortNames, shortNamesHelp)->group("Parameters"); + bool ignoreNotConnected = false; std::string ignoreNotConnectedHelp{"Ignore conn_error"}; hoymilesClient.add_flag("-I,--ignore_conn_error", ignoreNotConnected, ignoreNotConnectedHelp)->group("Debug"); @@ -67,7 +71,7 @@ int main(int argc, char **argv) { endTime = std::chrono::high_resolution_clock::now(); std::cout << "DTU update time: " << std::chrono::duration_cast(endTime - startTime).count() << "ms" << std::endl; - dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToGet); + dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToGet, shortNames); std::cout << std::endl; } -- 2.39.5