From 8c29930594f11aee13cccf81b2c541bcba920a38 Mon Sep 17 00:00:00 2001 From: trabus322 Date: Wed, 20 Mar 2024 20:19:39 +0100 Subject: [PATCH 1/2] Made README more accurate --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f652676..603419a 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Jenkins Link for jenkins builds with artifacts: - - [jenkins.trabus322.eu#freeBsd](https://jenkins.trabus322.eu/job/hoymilesClient/) - - [Executable](https://jenkins.trabus322.eu/job/hoymilesClient/lastSuccesfulBuild/artifact/build/hoymilesClient_exec) + - [jenkins.trabus322.eu#freeBsd](https://jenkins.trabus322.eu/job/hoymilesClient_freeBsd/) + - [Release executable](https://jenkins.trabus322.eu/job/hoymilesClient_freeBsd_release/lastSuccesfulBuild/artifact/build/hoymilesClient_exec) - [jenkins.trabus322.eu#linux](https://jenkins.trabus322.eu/job/hoymilesClient_linux/) - - [Executable](https://jenkins.trabus322.eu/job/hoymilesClient_linux/lastSuccesfulBuild/artifact/build/hoymilesClient_exec) + - [Release executable](https://jenkins.trabus322.eu/job/hoymilesClient_linux_release/lastSuccesfulBuild/artifact/build/hoymilesClient_exec) - [jenkins.trabus322.eu#windows](https://jenkins.trabus322.eu/job/hoymilesClient_windows/) - - [Executable](https://jenkins.trabus322.eu/job/hoymilesClient_windows/lastSuccessfulBuild/artifact/build/hoymilesClient_exec.exe) \ No newline at end of file + - [Release executable](https://jenkins.trabus322.eu/job/hoymilesClient_windows_release/lastSuccessfulBuild/artifact/build/hoymilesClient_exec.exe) \ No newline at end of file From 5e34b7fe37f4726a99e10623d76a3eed60d1b381 Mon Sep 17 00:00:00 2001 From: trabus322 Date: Wed, 20 Mar 2024 22:48:59 +0100 Subject: [PATCH 2/2] Release for implementing microinverter totals and actually managing the age of parameters --- inc/hoymiles/dtu.h | 6 +++--- inc/hoymiles/port.h | 6 ++++-- src/hoymiles/dtu.cpp | 33 ++++++++++++++++++++------------- src/hoymiles/microinverter.cpp | 9 +++++++-- src/hoymiles/port.cpp | 10 ++++++++++ src/main.cpp | 18 +++++++++++++----- 6 files changed, 57 insertions(+), 25 deletions(-) diff --git a/inc/hoymiles/dtu.h b/inc/hoymiles/dtu.h index bce11dd..bf2875c 100644 --- a/inc/hoymiles/dtu.h +++ b/inc/hoymiles/dtu.h @@ -1,9 +1,9 @@ #ifndef DTU_H #define DTU_H -#include #include #include +#include #include "microinverter.h" #include "modbus.h" @@ -18,7 +18,7 @@ class Dtu { void populateMicroinverters(); - std::pair getMicroinverterBySerialNumber(long long serialNumber); + std::pair getMicroinverterBySerialNumber(long long serialNumber); public: Dtu(const char *ip_address, int port); @@ -31,7 +31,7 @@ class Dtu { // void printMicroinverters(); - void printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet, bool shortNames); + void printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet, bool shortNames, bool printTodayProduction, bool printTotalProduction); ~Dtu(); }; diff --git a/inc/hoymiles/port.h b/inc/hoymiles/port.h index 02cb72f..194ffe7 100644 --- a/inc/hoymiles/port.h +++ b/inc/hoymiles/port.h @@ -12,16 +12,18 @@ class Port { private: std::shared_ptr modbus; - uint16_t portStartAddress; - void populateParameters(); void fixCurrent(); bool currentFixed; + void increaseParametersAge(); + public: Port(std::shared_ptr modbus, uint16_t portStartAddress); + uint16_t portStartAddress; + std::vector> parameters; std::pair, bool> getParameterByName(std::string name); diff --git a/src/hoymiles/dtu.cpp b/src/hoymiles/dtu.cpp index 7c59ac9..c3025db 100644 --- a/src/hoymiles/dtu.cpp +++ b/src/hoymiles/dtu.cpp @@ -44,9 +44,9 @@ void Dtu::populateMicroinverters() { portParameterMicroinverterSerialNumber.updateValue(this->modbus, portStartAddress); long long serialNumber = portParameterMicroinverterSerialNumber.getValue().first.i; - std::pair getMicroinverterBySerialNumber = this->getMicroinverterBySerialNumber(serialNumber); - if (getMicroinverterBySerialNumber.first) { - getMicroinverterBySerialNumber.second->ports.push_back(port); + std::pair getMicroinverterBySerialNumber = this->getMicroinverterBySerialNumber(serialNumber); + if (getMicroinverterBySerialNumber.second) { + getMicroinverterBySerialNumber.first->ports.push_back(port); } else { Microinverter microinverter{this->modbus, serialNumber}; this->microinverters.push_back(microinverter); @@ -59,16 +59,16 @@ void Dtu::populateMicroinverters() { } } -std::pair Dtu::getMicroinverterBySerialNumber(long long serialNumber) { +std::pair Dtu::getMicroinverterBySerialNumber(long long serialNumber) { std::vector::iterator microinvertersIterator = this->microinverters.begin(); while (microinvertersIterator != this->microinverters.end()) { if (microinvertersIterator->serialNumber == serialNumber) { - return std::pair(true, &*microinvertersIterator); + return std::pair(&*microinvertersIterator, true); } else { microinvertersIterator++; } } - return std::pair(false, &*microinvertersIterator); + return std::pair(&*microinvertersIterator, false); } void Dtu::updateMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet) { @@ -82,15 +82,15 @@ void Dtu::updateMicroinverters(std::vector ¶metersToGet, bool a std::vector::iterator microinvertersToGetIterator = microinvertersToGet.begin(); while (microinvertersToGetIterator != microinvertersToGet.end()) { - std::pair microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator); - if (microinverterPair.first) { - microinverterPair.second->updatePorts(parametersToGet, allParameters); + std::pair microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator); + if (microinverterPair.second) { + microinverterPair.first->updatePorts(parametersToGet, allParameters); } microinvertersToGetIterator++; } } -void Dtu::printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet, bool shortNames) { +void Dtu::printMicroinverters(std::vector ¶metersToGet, bool allParameters, std::vector µinvertersToGet, bool shortNames, bool printTodayProduction, bool printTotalProduction) { if (microinvertersToGet.empty()) { std::vector::iterator microinvertersIterator = this->microinverters.begin(); while (microinvertersIterator != this->microinverters.end()) { @@ -101,9 +101,16 @@ void Dtu::printMicroinverters(std::vector ¶metersToGet, bool al std::vector::iterator microinvertersToGetIterator = microinvertersToGet.begin(); while (microinvertersToGetIterator != microinvertersToGet.end()) { - std::pair microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator); - if (microinverterPair.first) { - microinverterPair.second->printPorts(parametersToGet, allParameters, shortNames); + std::pair microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator); + if (microinverterPair.second) { + std::cout << "Microinverter: " << microinverterPair.first->serialNumber << std::endl; + if(printTodayProduction) { + std::cout << "TodayProduction: " << microinverterPair.first->getTodayProduction() << std::endl; + } + if(printTotalProduction) { + std::cout << "TotalProduction: " << microinverterPair.first->getTotalProduction() << std::endl; + } + microinverterPair.first->printPorts(parametersToGet, allParameters, shortNames); } microinvertersToGetIterator++; } diff --git a/src/hoymiles/microinverter.cpp b/src/hoymiles/microinverter.cpp index 101ab29..6ec1eb5 100644 --- a/src/hoymiles/microinverter.cpp +++ b/src/hoymiles/microinverter.cpp @@ -21,8 +21,6 @@ void Microinverter::updatePorts(std::vector ¶metersToGet, bool } 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, shortNames); @@ -36,6 +34,9 @@ long long Microinverter::getTodayProduction() { std::vector::iterator portsIterator = this->ports.begin(); while(portsIterator != this->ports.end()) { + if(portsIterator->getParameterByName("todayProduction").first->age > 0) { + portsIterator->getParameterByName("todayProduction").first->updateValue(this->modbus, portsIterator->portStartAddress); + } result += portsIterator->getParameterByName("todayProduction").first->getValue().first.i; portsIterator++; } @@ -48,8 +49,12 @@ long long Microinverter::getTotalProduction() { std::vector::iterator portsIterator = this->ports.begin(); while(portsIterator != this->ports.end()) { + if(portsIterator->getParameterByName("totalProduction").first->age > 0) { + portsIterator->getParameterByName("totalProduction").first->updateValue(this->modbus, portsIterator->portStartAddress); + } result += portsIterator->getParameterByName("totalProduction").first->getValue().first.i; portsIterator++; + portsIterator++; } return result; diff --git a/src/hoymiles/port.cpp b/src/hoymiles/port.cpp index 7ae5f5c..6a8b8ba 100644 --- a/src/hoymiles/port.cpp +++ b/src/hoymiles/port.cpp @@ -87,7 +87,17 @@ void Port::fixCurrent() { } } +void Port::increaseParametersAge() { + std::vector>::iterator parametersIterator = this->parameters.begin(); + while(parametersIterator != this->parameters.end()) { + parametersIterator->get()->age++; + parametersIterator++; + } +} + void Port::updateParameters(std::vector ¶metersToGet, bool allParameters) { + this->increaseParametersAge(); + if (allParameters && parametersToGet.size() < this->parameters.size()) { std::vector>::iterator parametersIterator = this->parameters.begin(); while (parametersIterator != this->parameters.end()) { diff --git a/src/main.cpp b/src/main.cpp index fee9da8..0383375 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.0sn"}; + std::string version{"v1.0mt"}; std::cout << version << std::endl; CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"}; @@ -40,19 +40,27 @@ int main(int argc, char **argv) { std::string allParametersHelp{"Fetch all parameters"}; hoymilesClient.add_flag("-a,--all_parameters", allParameters, allParametersHelp)->group("Parameters"); + bool shortNames = false; + std::string shortNamesHelp{"Print short parameter names"}; + hoymilesClient.add_flag("-s,--short", shortNames, shortNamesHelp)->group("Parameters"); std::vector microinvertersToGet{}; 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 microinvertersGetTodayProduction; + std::string microinvertersGetTodayProductionHelp{"Show today production for microinverters"}; + hoymilesClient.add_flag("-t,--today_production", microinvertersGetTodayProduction, microinvertersGetTodayProductionHelp)->group("Microinverters"); + + bool microinvertersGetTotalProduction{}; + std::string microinvertersGetTotalProductionHelp{"Show total production for microinverters"}; + hoymilesClient.add_flag("-T,--total_production", microinvertersGetTotalProduction, microinvertersGetTotalProductionHelp)->group("Microinverters"); bool ignoreNotConnected = false; std::string ignoreNotConnectedHelp{"Ignore conn_error"}; hoymilesClient.add_flag("-I,--ignore_conn_error", ignoreNotConnected, ignoreNotConnectedHelp)->group("Debug"); + try { hoymilesClient.parse(argc, argv); } catch (const CLI::ParseError &e) { @@ -71,7 +79,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, shortNames); + dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToGet, shortNames, microinvertersGetTodayProduction, microinvertersGetTotalProduction); std::cout << std::endl; }