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 printMicroinverters();
|
||||
|
||||
~Dtu();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -29,6 +29,8 @@ class Microinverter {
|
|||
void updatePort(int i);
|
||||
|
||||
Port getPort(int i);
|
||||
|
||||
void printPorts();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -19,14 +19,16 @@ class Port {
|
|||
|
||||
uint16_t portStartAddress;
|
||||
|
||||
std::vector<std::shared_ptr<PortParameter>> parameters;
|
||||
|
||||
void populateParameters();
|
||||
|
||||
public:
|
||||
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 printParameters();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -84,7 +84,17 @@ void Dtu::updateMicroinverters() {
|
|||
|
||||
std::vector<std::thread>::iterator updateThreadsIterator = updateThreads.begin();
|
||||
while(updateThreadsIterator != updateThreads.end()) {
|
||||
updateThreadsIterator->join();
|
||||
updateThreadsIterator++;
|
||||
updateThreadsIterator->join(); 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 <iostream>
|
||||
#include <memory>
|
||||
|
||||
#include "modbus.h"
|
||||
|
||||
|
|
@ -26,4 +28,15 @@ void Microinverter::updatePorts() {
|
|||
updateThreadsIterator->join();
|
||||
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()) {
|
||||
parametersIterator->get()->updateValue(this->modbus_context, this->modbus_context_mutex, this->portStartAddress);
|
||||
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) {
|
||||
if (registerCount > 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() {
|
||||
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) {
|
||||
|
|
@ -81,5 +82,6 @@ void PortParameterInt::setValueFromRegisters(uint16_t *readArray, int registerCo
|
|||
}
|
||||
|
||||
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();
|
||||
Dtu dtu {ip_address.c_str(), port};
|
||||
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) {
|
||||
auto startTime = std::chrono::high_resolution_clock::now();
|
||||
dtu.updateMicroinverters();
|
||||
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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue