Release with more helpful help message
This commit is contained in:
parent
3b79dc94f4
commit
a0d06edf7b
8 changed files with 105 additions and 110 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "modbus.h"
|
||||
|
||||
|
|
@ -9,31 +9,27 @@
|
|||
|
||||
#include "portParameters.h"
|
||||
|
||||
|
||||
Dtu::Dtu(const char *ip_address, int port) {
|
||||
class modbus modbus{ip_address, (uint16_t) port};
|
||||
class modbus modbus {
|
||||
ip_address, (uint16_t)port
|
||||
};
|
||||
this->modbus = std::make_shared<class modbus>(modbus);
|
||||
|
||||
if (!this->modbus.get()->modbus_connect()) {
|
||||
std::cerr << "conn_error" << std::endl;
|
||||
this->connected = false;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this->connected = true;
|
||||
}
|
||||
|
||||
if(this->connected) {
|
||||
if (this->connected) {
|
||||
this->populateMicroinverters();
|
||||
}
|
||||
}
|
||||
|
||||
bool Dtu::isConnected() {
|
||||
return this->connected;
|
||||
}
|
||||
bool Dtu::isConnected() { return this->connected; }
|
||||
|
||||
Dtu::~Dtu() {
|
||||
this->modbus.get()->modbus_close();
|
||||
}
|
||||
Dtu::~Dtu() { this->modbus.get()->modbus_close(); }
|
||||
|
||||
void Dtu::populateMicroinverters() {
|
||||
uint16_t portStartAddress = 0x1000;
|
||||
|
|
@ -41,19 +37,18 @@ void Dtu::populateMicroinverters() {
|
|||
|
||||
int registerCount;
|
||||
registerCount = this->modbus.get()->modbus_read_holding_registers(portStartAddress + 0x0021, 1, readArray);
|
||||
while(registerCount != -1 && readArray[0] == 0x700) {
|
||||
Port port{ this->modbus, portStartAddress };
|
||||
while (registerCount != -1 && readArray[0] == 0x700) {
|
||||
Port port{this->modbus, portStartAddress};
|
||||
|
||||
PortParameterMicroinverterSerialNumber portParameterMicroinverterSerialNumber{};
|
||||
portParameterMicroinverterSerialNumber.updateValue(this->modbus, portStartAddress);
|
||||
long long serialNumber = portParameterMicroinverterSerialNumber.getValue().first.i;
|
||||
|
||||
std::pair<bool, Microinverter*> getMicroinverterBySerialNumber = this->getMicroinverterBySerialNumber(serialNumber);
|
||||
if(getMicroinverterBySerialNumber.first) {
|
||||
std::pair<bool, Microinverter *> getMicroinverterBySerialNumber = this->getMicroinverterBySerialNumber(serialNumber);
|
||||
if (getMicroinverterBySerialNumber.first) {
|
||||
getMicroinverterBySerialNumber.second->ports.push_back(port);
|
||||
}
|
||||
else {
|
||||
Microinverter microinverter{ this->modbus, serialNumber };
|
||||
} else {
|
||||
Microinverter microinverter{this->modbus, serialNumber};
|
||||
this->microinverters.push_back(microinverter);
|
||||
this->microinverters.back().ports.push_back(port);
|
||||
}
|
||||
|
|
@ -64,32 +59,31 @@ void Dtu::populateMicroinverters() {
|
|||
}
|
||||
}
|
||||
|
||||
std::pair<bool, Microinverter*> Dtu::getMicroinverterBySerialNumber(long long serialNumber) {
|
||||
std::pair<bool, Microinverter *> Dtu::getMicroinverterBySerialNumber(long long serialNumber) {
|
||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||
while(microinvertersIterator != this->microinverters.end()) {
|
||||
if(microinvertersIterator->serialNumber == serialNumber) {
|
||||
return std::pair<bool, Microinverter*>(true, &*microinvertersIterator);
|
||||
}
|
||||
else{
|
||||
while (microinvertersIterator != this->microinverters.end()) {
|
||||
if (microinvertersIterator->serialNumber == serialNumber) {
|
||||
return std::pair<bool, Microinverter *>(true, &*microinvertersIterator);
|
||||
} else {
|
||||
microinvertersIterator++;
|
||||
}
|
||||
}
|
||||
return std::pair<bool, Microinverter*>(false, &*microinvertersIterator);
|
||||
return std::pair<bool, Microinverter *>(false, &*microinvertersIterator);
|
||||
}
|
||||
|
||||
void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet) {
|
||||
if(microinvertersToGet.empty()) {
|
||||
if (microinvertersToGet.empty()) {
|
||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||
while(microinvertersIterator != this->microinverters.end()) {
|
||||
while (microinvertersIterator != this->microinverters.end()) {
|
||||
microinvertersToGet.push_back(microinvertersIterator->serialNumber);
|
||||
microinvertersIterator++;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<long long>::iterator microinvertersToGetIterator = microinvertersToGet.begin();
|
||||
while(microinvertersToGetIterator != microinvertersToGet.end()) {
|
||||
std::pair<bool, Microinverter*> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||
if(microinverterPair.first) {
|
||||
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
||||
std::pair<bool, Microinverter *> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||
if (microinverterPair.first) {
|
||||
microinverterPair.second->updatePorts(parametersToGet, allParameters);
|
||||
}
|
||||
microinvertersToGetIterator++;
|
||||
|
|
@ -97,18 +91,18 @@ void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool a
|
|||
}
|
||||
|
||||
void Dtu::printMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet) {
|
||||
if(microinvertersToGet.empty()) {
|
||||
if (microinvertersToGet.empty()) {
|
||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||
while(microinvertersIterator != this->microinverters.end()) {
|
||||
while (microinvertersIterator != this->microinverters.end()) {
|
||||
microinvertersToGet.push_back(microinvertersIterator->serialNumber);
|
||||
microinvertersIterator++;
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<long long>::iterator microinvertersToGetIterator = microinvertersToGet.begin();
|
||||
while(microinvertersToGetIterator != microinvertersToGet.end()) {
|
||||
std::pair<bool, Microinverter*> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||
if(microinverterPair.first) {
|
||||
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
||||
std::pair<bool, Microinverter *> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||
if (microinverterPair.first) {
|
||||
microinverterPair.second->printPorts(parametersToGet, allParameters);
|
||||
}
|
||||
microinvertersToGetIterator++;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
// #include <thread>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
|
@ -10,14 +9,12 @@
|
|||
|
||||
Microinverter::Microinverter(std::shared_ptr<class modbus> modbus, long long serialNumber) {
|
||||
this->modbus = modbus;
|
||||
// this->modbus_context_mutex = modbus_context_mutex;
|
||||
|
||||
this->serialNumber = serialNumber;
|
||||
}
|
||||
|
||||
void Microinverter::updatePorts(std::vector<std::string> ¶metersToGet, bool allParameters) {
|
||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||
while(portsIterator != this->ports.end()) {
|
||||
while (portsIterator != this->ports.end()) {
|
||||
portsIterator->updateParameters(parametersToGet, allParameters);
|
||||
portsIterator++;
|
||||
}
|
||||
|
|
@ -27,9 +24,33 @@ void Microinverter::printPorts(std::vector<std::string> ¶metersToGet, bool a
|
|||
std::cout << "Microinverter: " << this->serialNumber << std::endl;
|
||||
|
||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||
while(portsIterator != this->ports.end()) {
|
||||
while (portsIterator != this->ports.end()) {
|
||||
portsIterator->printParameters(parametersToGet, allParameters);
|
||||
std::cout << std::endl;
|
||||
portsIterator++;
|
||||
}
|
||||
}
|
||||
|
||||
long long Microinverter::getTodayProduction() {
|
||||
long long result{0};
|
||||
|
||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||
while(portsIterator != this->ports.end()) {
|
||||
result += portsIterator->getParameterByName("todayProduction").first->getValue().first.i;
|
||||
portsIterator++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
long long Microinverter::getTotalProduction() {
|
||||
long long result{0};
|
||||
|
||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||
while(portsIterator != this->ports.end()) {
|
||||
result += portsIterator->getParameterByName("totalProduction").first->getValue().first.i;
|
||||
portsIterator++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -77,15 +77,14 @@ void Port::fixCurrent() {
|
|||
|
||||
if (this->getParameterByName("pvVoltage").second && this->getParameterByName("pvPower").second) {
|
||||
if (this->getParameterByName("pvCurrentMI").second && this->getParameterByName("pvCurrentHM").second) {
|
||||
if(this->getParameterByName("pvPower").first->getValue().first.f > this->getParameterByName("pvVoltage").first->getValue().first.f * this->getParameterByName("pvCurrentMI").first->getValue().first.f) {
|
||||
if (this->getParameterByName("pvPower").first->getValue().first.f > this->getParameterByName("pvVoltage").first->getValue().first.f * this->getParameterByName("pvCurrentMI").first->getValue().first.f) {
|
||||
this->parameters.erase(std::find(this->parameters.begin(), this->parameters.end(), this->getParameterByName("pvCurrentHM").first));
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
this->parameters.erase(std::find(this->parameters.begin(), this->parameters.end(), this->getParameterByName("pvCurrentM").first));
|
||||
}
|
||||
this->currentFixed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Port::updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters) {
|
||||
|
|
@ -109,7 +108,7 @@ void Port::updateParameters(std::vector<std::string> ¶metersToGet, bool allP
|
|||
}
|
||||
|
||||
this->fixCurrent();
|
||||
|
||||
|
||||
parametersToGetIterator++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue