From 089c7a77b5a7aac8ee928cffa37551139595e19d Mon Sep 17 00:00:00 2001 From: trabus322 Date: Tue, 19 Mar 2024 09:22:21 +0100 Subject: [PATCH] tetea --- inc/hoymiles/port.h | 3 +++ src/hoymiles/port.cpp | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/inc/hoymiles/port.h b/inc/hoymiles/port.h index 012d5d5..44d6e19 100644 --- a/inc/hoymiles/port.h +++ b/inc/hoymiles/port.h @@ -21,6 +21,9 @@ class Port { void populateParameters(); + void fixCurrent(); + bool currentFixed; + public: Port(std::shared_ptr modbus_context, std::mutex *modbus_context_mutex, uint16_t portStartAddress); diff --git a/src/hoymiles/port.cpp b/src/hoymiles/port.cpp index 2ba8914..7d507b2 100644 --- a/src/hoymiles/port.cpp +++ b/src/hoymiles/port.cpp @@ -15,6 +15,8 @@ Port::Port(std::shared_ptr modbus_context, std::mutex *modbus_context this->portStartAddress = portStartAddress; + this->currentFixed = false; + this->populateParameters(); } @@ -50,12 +52,29 @@ void Port::populateParameters() { this->parameters.push_back(std::make_shared()); } +void Port::fixCurrent() { + if(this->currentFixed) { + return; + } + if(this->parameters.at(7).get()->getValue().first.f == 0) { + return; + } + if(this->parameters.at(2).get()->getValue().first.f * this->parameters.at(4).get()->getValue().first.f < this->parameters.at(7).get()->getValue().first.f) { + this->parameters.erase(this->parameters.begin() + 4); + } + else { + this->parameters.erase(this->parameters.begin() + 3); + } + this->currentFixed = true; +} + void Port::updateParameters() { std::vector>::iterator parametersIterator{this->parameters.begin()}; while (parametersIterator != this->parameters.end()) { parametersIterator->get()->updateValue(this->modbus_context, this->modbus_context_mutex, this->portStartAddress); parametersIterator++; } + this->fixCurrent(); } void Port::printParameters() {