Compare commits
4 commits
ee2c9c3352
...
0381c3c334
| Author | SHA1 | Date | |
|---|---|---|---|
| 0381c3c334 | |||
| 582b1bcc93 | |||
| dc4e40924d | |||
| 6d1bd77f19 |
3 changed files with 37 additions and 44 deletions
|
|
@ -1,8 +1,8 @@
|
||||||
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
|
||||||
#include <chrono>
|
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
||||||
|
|
@ -23,8 +23,7 @@ Dtu::Dtu(const char *address, int id, bool rtu, bool tcp) {
|
||||||
this->connected = false;
|
this->connected = false;
|
||||||
if (modbus_connect(this->modbus) == -1) {
|
if (modbus_connect(this->modbus) == -1) {
|
||||||
std::cerr << "NOT CONNECTED" << std::endl;
|
std::cerr << "NOT CONNECTED" << std::endl;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
this->connected = true;
|
this->connected = true;
|
||||||
if (rtu) {
|
if (rtu) {
|
||||||
modbus_set_slave(this->modbus, id);
|
modbus_set_slave(this->modbus, id);
|
||||||
|
|
@ -44,18 +43,11 @@ void Dtu::populateMicroinverters() {
|
||||||
int portStartAddress = 0x4000;
|
int portStartAddress = 0x4000;
|
||||||
uint16_t registers[19];
|
uint16_t registers[19];
|
||||||
|
|
||||||
|
while (portStartAddress <= (0x4000 + (0x0019 * 99))) {
|
||||||
int registerCount;
|
int registerCount;
|
||||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers);
|
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers);
|
||||||
|
portStartAddress += 0x0019;
|
||||||
if (registerCount == -1) {
|
if (registers[0] == 12) {
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
while (registerCount != -1) {
|
|
||||||
if(registers[0] != 12) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Port port{portStartAddress};
|
Port port{portStartAddress};
|
||||||
port.setParametersFromMicroinverterArray(registers, 0);
|
port.setParametersFromMicroinverterArray(registers, 0);
|
||||||
|
|
||||||
|
|
@ -65,11 +57,9 @@ void Dtu::populateMicroinverters() {
|
||||||
}
|
}
|
||||||
|
|
||||||
this->getMicroinverterBySerialNumber(port.getParameterByName("microinverterSerialNumber").first.get()->getValue().first.i).first->ports.push_back(port);
|
this->getMicroinverterBySerialNumber(port.getParameterByName("microinverterSerialNumber").first.get()->getValue().first.i).first->ports.push_back(port);
|
||||||
|
}
|
||||||
portStartAddress += 0x0019;
|
|
||||||
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -118,13 +108,17 @@ void Dtu::printMicroinverters(std::vector<std::string> ¶metersToGet, bool al
|
||||||
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
while (microinvertersToGetIterator != microinvertersToGet.end()) {
|
||||||
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||||
if (microinverterPair.second) {
|
if (microinverterPair.second) {
|
||||||
std::cout << " " << "Microinverter: " << microinverterPair.first->serialNumber << std::endl;
|
std::cout << " "
|
||||||
std::cout << " " << "Microinverter Data Age: " << microinverterPair.first->age << std::endl;
|
<< "Microinverter: " << microinverterPair.first->serialNumber << std::endl;
|
||||||
|
std::cout << " "
|
||||||
|
<< "Microinverter Data Age: " << microinverterPair.first->age << std::endl;
|
||||||
if (printTodayProduction) {
|
if (printTodayProduction) {
|
||||||
std::cout << " " << "TodayProduction: " << microinverterPair.first->getTodayProduction() << "Wh" << std::endl;
|
std::cout << " "
|
||||||
|
<< "TodayProduction: " << microinverterPair.first->getTodayProduction() << "Wh" << std::endl;
|
||||||
}
|
}
|
||||||
if (printTotalProduction) {
|
if (printTotalProduction) {
|
||||||
std::cout << " " << "TotalProduction: " << microinverterPair.first->getTotalProduction() << "Wh" << std::endl;
|
std::cout << " "
|
||||||
|
<< "TotalProduction: " << microinverterPair.first->getTotalProduction() << "Wh" << std::endl;
|
||||||
}
|
}
|
||||||
microinverterPair.first->printPorts(parametersToGet, allParameters, shortNames);
|
microinverterPair.first->printPorts(parametersToGet, allParameters, shortNames);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
@ -152,9 +146,7 @@ void Dtu::setStatusMicroinverters(uint16_t value, std::string statusName, std::v
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Dtu::empty() {
|
bool Dtu::empty() { return this->microinverters.empty(); }
|
||||||
return this->microinverters.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Dtu::listOfMicroinverters() {
|
void Dtu::listOfMicroinverters() {
|
||||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,9 @@ void PortParameterMicroinverterSerialNumber::getValueFromRegisters(uint16_t *reg
|
||||||
std::string readValueString = "";
|
std::string readValueString = "";
|
||||||
for (int i{0}; i < this->registerSize; i++) {
|
for (int i{0}; i < this->registerSize; i++) {
|
||||||
std::stringstream readValueStringStream;
|
std::stringstream readValueStringStream;
|
||||||
readValueStringStream << std::hex << (int) ((registers[addressOffset + this->parameterAddressOffset + i] & 0xff00) >> 8);
|
readValueStringStream.fill('0');
|
||||||
readValueStringStream << std::hex << (int) (registers[addressOffset + this->parameterAddressOffset + i] & 0x00ff);
|
readValueStringStream << std::setw(2) << std::hex << (int) ((registers[addressOffset + this->parameterAddressOffset + i] & 0xff00) >> 8);
|
||||||
|
readValueStringStream << std::setw(2) << std::hex << (int) (registers[addressOffset + this->parameterAddressOffset + i] & 0x00ff);
|
||||||
readValueString.append(readValueStringStream.str());
|
readValueString.append(readValueStringStream.str());
|
||||||
}
|
}
|
||||||
this->value.i = std::stoll(readValueString);
|
this->value.i = std::stoll(readValueString);
|
||||||
|
|
|
||||||
|
|
@ -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{"v2.3h"};
|
std::string version{"v2.4h"};
|
||||||
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"};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue