Made basic output of values, slow but starting to be actually functional
This commit is contained in:
parent
6cfdcc13ce
commit
30a39aff3e
9 changed files with 56 additions and 9 deletions
|
|
@ -26,6 +26,8 @@ class Dtu {
|
||||||
|
|
||||||
void updateMicroinverters();
|
void updateMicroinverters();
|
||||||
|
|
||||||
|
void printMicroinverters();
|
||||||
|
|
||||||
~Dtu();
|
~Dtu();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,8 @@ class Microinverter {
|
||||||
void updatePort(int i);
|
void updatePort(int i);
|
||||||
|
|
||||||
Port getPort(int i);
|
Port getPort(int i);
|
||||||
|
|
||||||
|
void printPorts();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -19,14 +19,16 @@ class Port {
|
||||||
|
|
||||||
uint16_t portStartAddress;
|
uint16_t portStartAddress;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<PortParameter>> parameters;
|
|
||||||
|
|
||||||
void populateParameters();
|
void populateParameters();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Port(std::shared_ptr<modbus_t*> modbus_context, std::mutex *modbus_context_mutex, uint16_t portStartAddress);
|
Port(std::shared_ptr<modbus_t*> modbus_context, std::mutex *modbus_context_mutex, uint16_t portStartAddress);
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<PortParameter>> parameters;
|
||||||
|
|
||||||
void updateParameters();
|
void updateParameters();
|
||||||
|
|
||||||
|
void printParameters();
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -84,7 +84,17 @@ void Dtu::updateMicroinverters() {
|
||||||
|
|
||||||
std::vector<std::thread>::iterator updateThreadsIterator = updateThreads.begin();
|
std::vector<std::thread>::iterator updateThreadsIterator = updateThreads.begin();
|
||||||
while(updateThreadsIterator != updateThreads.end()) {
|
while(updateThreadsIterator != updateThreads.end()) {
|
||||||
updateThreadsIterator->join();
|
updateThreadsIterator->join(); updateThreadsIterator++;
|
||||||
updateThreadsIterator++;
|
}
|
||||||
|
std::cout << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Dtu::printMicroinverters() {
|
||||||
|
std::cout << "DTU:" << std::endl;
|
||||||
|
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||||
|
while(microinvertersIterator != this->microinverters.end()) {
|
||||||
|
microinvertersIterator->printPorts();
|
||||||
|
std::cout << std::endl;
|
||||||
|
microinvertersIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
#include <thread>
|
#include <thread>
|
||||||
|
#include <iostream>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
||||||
|
|
@ -27,3 +29,14 @@ void Microinverter::updatePorts() {
|
||||||
updateThreadsIterator++;
|
updateThreadsIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Microinverter::printPorts() {
|
||||||
|
std::cout << "Microinverter: " << this->serialNumber << std::endl;
|
||||||
|
|
||||||
|
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||||
|
while(portsIterator != this->ports.end()) {
|
||||||
|
portsIterator->printParameters();
|
||||||
|
std::cout << std::endl;
|
||||||
|
portsIterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -55,6 +55,18 @@ void Port::updateParameters() {
|
||||||
while (parametersIterator != this->parameters.end()) {
|
while (parametersIterator != this->parameters.end()) {
|
||||||
parametersIterator->get()->updateValue(this->modbus_context, this->modbus_context_mutex, this->portStartAddress);
|
parametersIterator->get()->updateValue(this->modbus_context, this->modbus_context_mutex, this->portStartAddress);
|
||||||
parametersIterator++;
|
parametersIterator++;
|
||||||
break;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Port::printParameters() {
|
||||||
|
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||||
|
|
||||||
|
if(parametersIterator != this->parameters.end()) {
|
||||||
|
std::cout << "|";
|
||||||
|
}
|
||||||
|
|
||||||
|
while(parametersIterator != this->parameters.end()) {
|
||||||
|
std::cout << " " << parametersIterator->get()->name << ": " << parametersIterator->get()->getOutputValue() << " |";
|
||||||
|
parametersIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -25,6 +25,9 @@ PortParameterPortNumber::PortParameterPortNumber() : PortParameterInt("portNumbe
|
||||||
void PortParameterPortNumber::setValueFromRegisters(uint16_t *readArray, int registerCount) {
|
void PortParameterPortNumber::setValueFromRegisters(uint16_t *readArray, int registerCount) {
|
||||||
if (registerCount > 0) {
|
if (registerCount > 0) {
|
||||||
this->value.i = readArray[0];
|
this->value.i = readArray[0];
|
||||||
|
std::stringstream valueStringStream;
|
||||||
|
valueStringStream << std::hex << this->value.i;
|
||||||
|
this->value.i = valueStringStream.str().at(0) - '0';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,8 @@ void PortParameterFloat::setValueFromRegisters(uint16_t *readArray, int register
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PortParameterFloat::getOutputValue() {
|
std::string PortParameterFloat::getOutputValue() {
|
||||||
return std::to_string(this->value.f);
|
std::string separator{"_age"};
|
||||||
|
return std::to_string(this->value.f).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, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, parameterAddressOffset, registerSize) {
|
||||||
|
|
@ -81,5 +82,6 @@ void PortParameterInt::setValueFromRegisters(uint16_t *readArray, int registerCo
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string PortParameterInt::getOutputValue() {
|
std::string PortParameterInt::getOutputValue() {
|
||||||
return std::to_string(this->value.i);
|
std::string separator{"_age"};
|
||||||
|
return std::to_string(this->value.i).append(separator.append(std::to_string(this->age)));
|
||||||
}
|
}
|
||||||
|
|
@ -14,13 +14,14 @@ int main(){
|
||||||
auto startTime = std::chrono::high_resolution_clock::now();
|
auto startTime = std::chrono::high_resolution_clock::now();
|
||||||
Dtu dtu {ip_address.c_str(), port};
|
Dtu dtu {ip_address.c_str(), port};
|
||||||
auto endTime = std::chrono::high_resolution_clock::now();
|
auto endTime = std::chrono::high_resolution_clock::now();
|
||||||
std::cout << "Construction time: " << std::chrono::duration_cast<std::chrono::seconds>(endTime - startTime).count() << "s" << std::endl;
|
std::cout << "Construction time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
auto startTime = std::chrono::high_resolution_clock::now();
|
auto startTime = std::chrono::high_resolution_clock::now();
|
||||||
dtu.updateMicroinverters();
|
dtu.updateMicroinverters();
|
||||||
auto endTime = std::chrono::high_resolution_clock::now();
|
auto endTime = std::chrono::high_resolution_clock::now();
|
||||||
std::cout << "Update time: " << std::chrono::duration_cast<std::chrono::seconds>(endTime - startTime).count() << "s" << std::endl;
|
std::cout << "Update time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
||||||
|
dtu.printMicroinverters();
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue