Compare commits
No commits in common. "b6e1228fc80cd8c4cefbbe5f43a7f841a667a922" and "8c29930594f11aee13cccf81b2c541bcba920a38" have entirely different histories.
b6e1228fc8
...
8c29930594
6 changed files with 25 additions and 57 deletions
|
|
@ -1,9 +1,9 @@
|
||||||
#ifndef DTU_H
|
#ifndef DTU_H
|
||||||
#define DTU_H
|
#define DTU_H
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
#include "microinverter.h"
|
#include "microinverter.h"
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
@ -18,7 +18,7 @@ class Dtu {
|
||||||
|
|
||||||
void populateMicroinverters();
|
void populateMicroinverters();
|
||||||
|
|
||||||
std::pair<Microinverter *, bool> getMicroinverterBySerialNumber(long long serialNumber);
|
std::pair<bool, Microinverter*> getMicroinverterBySerialNumber(long long serialNumber);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Dtu(const char *ip_address, int port);
|
Dtu(const char *ip_address, int port);
|
||||||
|
|
@ -31,7 +31,7 @@ class Dtu {
|
||||||
|
|
||||||
// void printMicroinverters();
|
// void printMicroinverters();
|
||||||
|
|
||||||
void printMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet, bool shortNames, bool printTodayProduction, bool printTotalProduction);
|
void printMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet, bool shortNames);
|
||||||
|
|
||||||
~Dtu();
|
~Dtu();
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -12,18 +12,16 @@ class Port {
|
||||||
private:
|
private:
|
||||||
std::shared_ptr<class modbus> modbus;
|
std::shared_ptr<class modbus> modbus;
|
||||||
|
|
||||||
|
uint16_t portStartAddress;
|
||||||
|
|
||||||
void populateParameters();
|
void populateParameters();
|
||||||
|
|
||||||
void fixCurrent();
|
void fixCurrent();
|
||||||
bool currentFixed;
|
bool currentFixed;
|
||||||
|
|
||||||
void increaseParametersAge();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Port(std::shared_ptr<class modbus> modbus, uint16_t portStartAddress);
|
Port(std::shared_ptr<class modbus> modbus, uint16_t portStartAddress);
|
||||||
|
|
||||||
uint16_t portStartAddress;
|
|
||||||
|
|
||||||
std::vector<std::shared_ptr<PortParameter>> parameters;
|
std::vector<std::shared_ptr<PortParameter>> parameters;
|
||||||
|
|
||||||
std::pair<std::shared_ptr<PortParameter>, bool> getParameterByName(std::string name);
|
std::pair<std::shared_ptr<PortParameter>, bool> getParameterByName(std::string name);
|
||||||
|
|
|
||||||
|
|
@ -44,9 +44,9 @@ void Dtu::populateMicroinverters() {
|
||||||
portParameterMicroinverterSerialNumber.updateValue(this->modbus, portStartAddress);
|
portParameterMicroinverterSerialNumber.updateValue(this->modbus, portStartAddress);
|
||||||
long long serialNumber = portParameterMicroinverterSerialNumber.getValue().first.i;
|
long long serialNumber = portParameterMicroinverterSerialNumber.getValue().first.i;
|
||||||
|
|
||||||
std::pair<Microinverter *, bool> getMicroinverterBySerialNumber = this->getMicroinverterBySerialNumber(serialNumber);
|
std::pair<bool, Microinverter *> getMicroinverterBySerialNumber = this->getMicroinverterBySerialNumber(serialNumber);
|
||||||
if (getMicroinverterBySerialNumber.second) {
|
if (getMicroinverterBySerialNumber.first) {
|
||||||
getMicroinverterBySerialNumber.first->ports.push_back(port);
|
getMicroinverterBySerialNumber.second->ports.push_back(port);
|
||||||
} else {
|
} else {
|
||||||
Microinverter microinverter{this->modbus, serialNumber};
|
Microinverter microinverter{this->modbus, serialNumber};
|
||||||
this->microinverters.push_back(microinverter);
|
this->microinverters.push_back(microinverter);
|
||||||
|
|
@ -59,16 +59,16 @@ void Dtu::populateMicroinverters() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<Microinverter *, bool> Dtu::getMicroinverterBySerialNumber(long long serialNumber) {
|
std::pair<bool, Microinverter *> Dtu::getMicroinverterBySerialNumber(long long serialNumber) {
|
||||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||||
while (microinvertersIterator != this->microinverters.end()) {
|
while (microinvertersIterator != this->microinverters.end()) {
|
||||||
if (microinvertersIterator->serialNumber == serialNumber) {
|
if (microinvertersIterator->serialNumber == serialNumber) {
|
||||||
return std::pair<Microinverter *, bool>(&*microinvertersIterator, true);
|
return std::pair<bool, Microinverter *>(true, &*microinvertersIterator);
|
||||||
} else {
|
} else {
|
||||||
microinvertersIterator++;
|
microinvertersIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return std::pair<Microinverter *, bool>(&*microinvertersIterator, false);
|
return std::pair<bool, Microinverter *>(false, &*microinvertersIterator);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet) {
|
void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet) {
|
||||||
|
|
@ -82,15 +82,15 @@ void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool a
|
||||||
|
|
||||||
std::vector<long long>::iterator microinvertersToGetIterator = microinvertersToGet.begin();
|
std::vector<long long>::iterator microinvertersToGetIterator = microinvertersToGet.begin();
|
||||||
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
||||||
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
std::pair<bool, Microinverter *> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||||
if (microinverterPair.second) {
|
if (microinverterPair.first) {
|
||||||
microinverterPair.first->updatePorts(parametersToGet, allParameters);
|
microinverterPair.second->updatePorts(parametersToGet, allParameters);
|
||||||
}
|
}
|
||||||
microinvertersToGetIterator++;
|
microinvertersToGetIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dtu::printMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet, bool shortNames, bool printTodayProduction, bool printTotalProduction) {
|
void Dtu::printMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet, bool shortNames) {
|
||||||
if (microinvertersToGet.empty()) {
|
if (microinvertersToGet.empty()) {
|
||||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||||
while (microinvertersIterator != this->microinverters.end()) {
|
while (microinvertersIterator != this->microinverters.end()) {
|
||||||
|
|
@ -101,16 +101,9 @@ void Dtu::printMicroinverters(std::vector<std::string> ¶metersToGet, bool al
|
||||||
|
|
||||||
std::vector<long long>::iterator microinvertersToGetIterator = microinvertersToGet.begin();
|
std::vector<long long>::iterator microinvertersToGetIterator = microinvertersToGet.begin();
|
||||||
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
||||||
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
std::pair<bool, Microinverter *> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||||
if (microinverterPair.second) {
|
if (microinverterPair.first) {
|
||||||
std::cout << "Microinverter: " << microinverterPair.first->serialNumber << std::endl;
|
microinverterPair.second->printPorts(parametersToGet, allParameters, shortNames);
|
||||||
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++;
|
microinvertersToGetIterator++;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -21,6 +21,8 @@ void Microinverter::updatePorts(std::vector<std::string> ¶metersToGet, bool
|
||||||
}
|
}
|
||||||
|
|
||||||
void Microinverter::printPorts(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames) {
|
void Microinverter::printPorts(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames) {
|
||||||
|
std::cout << "Microinverter: " << this->serialNumber << std::endl;
|
||||||
|
|
||||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||||
while (portsIterator != this->ports.end()) {
|
while (portsIterator != this->ports.end()) {
|
||||||
portsIterator->printParameters(parametersToGet, allParameters, shortNames);
|
portsIterator->printParameters(parametersToGet, allParameters, shortNames);
|
||||||
|
|
@ -34,9 +36,6 @@ long long Microinverter::getTodayProduction() {
|
||||||
|
|
||||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||||
while(portsIterator != this->ports.end()) {
|
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;
|
result += portsIterator->getParameterByName("todayProduction").first->getValue().first.i;
|
||||||
portsIterator++;
|
portsIterator++;
|
||||||
}
|
}
|
||||||
|
|
@ -49,12 +48,8 @@ long long Microinverter::getTotalProduction() {
|
||||||
|
|
||||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||||
while(portsIterator != this->ports.end()) {
|
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;
|
result += portsIterator->getParameterByName("totalProduction").first->getValue().first.i;
|
||||||
portsIterator++;
|
portsIterator++;
|
||||||
portsIterator++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
|
|
@ -87,17 +87,7 @@ void Port::fixCurrent() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Port::increaseParametersAge() {
|
|
||||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
|
||||||
while(parametersIterator != this->parameters.end()) {
|
|
||||||
parametersIterator->get()->age++;
|
|
||||||
parametersIterator++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Port::updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters) {
|
void Port::updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters) {
|
||||||
this->increaseParametersAge();
|
|
||||||
|
|
||||||
if (allParameters && parametersToGet.size() < this->parameters.size()) {
|
if (allParameters && parametersToGet.size() < this->parameters.size()) {
|
||||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||||
while (parametersIterator != this->parameters.end()) {
|
while (parametersIterator != this->parameters.end()) {
|
||||||
|
|
|
||||||
18
src/main.cpp
18
src/main.cpp
|
|
@ -19,7 +19,7 @@ int main(int argc, char **argv) {
|
||||||
signal(SIGTERM, sigHandler);
|
signal(SIGTERM, sigHandler);
|
||||||
signal(SIGABRT, sigHandler);
|
signal(SIGABRT, sigHandler);
|
||||||
|
|
||||||
std::string version{"v1.0mt"};
|
std::string version{"v1.0sn"};
|
||||||
std::cout << version << std::endl;
|
std::cout << version << std::endl;
|
||||||
|
|
||||||
CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"};
|
CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"};
|
||||||
|
|
@ -40,27 +40,19 @@ int main(int argc, char **argv) {
|
||||||
std::string allParametersHelp{"Fetch all parameters"};
|
std::string allParametersHelp{"Fetch all parameters"};
|
||||||
hoymilesClient.add_flag<bool>("-a,--all_parameters", allParameters, allParametersHelp)->group("Parameters");
|
hoymilesClient.add_flag<bool>("-a,--all_parameters", allParameters, allParametersHelp)->group("Parameters");
|
||||||
|
|
||||||
bool shortNames = false;
|
|
||||||
std::string shortNamesHelp{"Print short parameter names"};
|
|
||||||
hoymilesClient.add_flag<bool>("-s,--short", shortNames, shortNamesHelp)->group("Parameters");
|
|
||||||
|
|
||||||
std::vector<long long> microinvertersToGet{};
|
std::vector<long long> microinvertersToGet{};
|
||||||
std::string microinvertersToGetHelp{"List of microinverters to fetch, delimited by ','; if omitted, all are fetched"};
|
std::string microinvertersToGetHelp{"List of microinverters to fetch, delimited by ','; if omitted, all are fetched"};
|
||||||
hoymilesClient.add_option<std::vector<long long>>("-m,--microinverters", microinvertersToGet, microinvertersToGetHelp)->delimiter(',')->group("Microinverters");
|
hoymilesClient.add_option<std::vector<long long>>("-m,--microinverters", microinvertersToGet, microinvertersToGetHelp)->delimiter(',')->group("Microinverters");
|
||||||
|
|
||||||
bool microinvertersGetTodayProduction;
|
bool shortNames = false;
|
||||||
std::string microinvertersGetTodayProductionHelp{"Show today production for microinverters"};
|
std::string shortNamesHelp{"Print short parameter names"};
|
||||||
hoymilesClient.add_flag<bool>("-t,--today_production", microinvertersGetTodayProduction, microinvertersGetTodayProductionHelp)->group("Microinverters");
|
hoymilesClient.add_flag<bool>("-s,--short", shortNames, shortNamesHelp)->group("Parameters");
|
||||||
|
|
||||||
bool microinvertersGetTotalProduction{};
|
|
||||||
std::string microinvertersGetTotalProductionHelp{"Show total production for microinverters"};
|
|
||||||
hoymilesClient.add_flag<bool>("-T,--total_production", microinvertersGetTotalProduction, microinvertersGetTotalProductionHelp)->group("Microinverters");
|
|
||||||
|
|
||||||
bool ignoreNotConnected = false;
|
bool ignoreNotConnected = false;
|
||||||
std::string ignoreNotConnectedHelp{"Ignore conn_error"};
|
std::string ignoreNotConnectedHelp{"Ignore conn_error"};
|
||||||
hoymilesClient.add_flag<bool>("-I,--ignore_conn_error", ignoreNotConnected, ignoreNotConnectedHelp)->group("Debug");
|
hoymilesClient.add_flag<bool>("-I,--ignore_conn_error", ignoreNotConnected, ignoreNotConnectedHelp)->group("Debug");
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
hoymilesClient.parse(argc, argv);
|
hoymilesClient.parse(argc, argv);
|
||||||
} catch (const CLI::ParseError &e) {
|
} catch (const CLI::ParseError &e) {
|
||||||
|
|
@ -79,7 +71,7 @@ int main(int argc, char **argv) {
|
||||||
endTime = std::chrono::high_resolution_clock::now();
|
endTime = std::chrono::high_resolution_clock::now();
|
||||||
std::cout << "DTU update time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
std::cout << "DTU update time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
||||||
|
|
||||||
dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToGet, shortNames, microinvertersGetTodayProduction, microinvertersGetTotalProduction);
|
dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToGet, shortNames);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue