This commit is contained in:
TraYali 2024-03-19 09:22:21 +01:00
parent b10fe4880f
commit 089c7a77b5
2 changed files with 22 additions and 0 deletions

View file

@ -21,6 +21,9 @@ class Port {
void populateParameters(); void populateParameters();
void fixCurrent();
bool currentFixed;
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);

View file

@ -15,6 +15,8 @@ Port::Port(std::shared_ptr<modbus_t*> modbus_context, std::mutex *modbus_context
this->portStartAddress = portStartAddress; this->portStartAddress = portStartAddress;
this->currentFixed = false;
this->populateParameters(); this->populateParameters();
} }
@ -50,12 +52,29 @@ void Port::populateParameters() {
this->parameters.push_back(std::make_shared<PortParameterLinkStatus>()); this->parameters.push_back(std::make_shared<PortParameterLinkStatus>());
} }
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() { void Port::updateParameters() {
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator{this->parameters.begin()}; std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator{this->parameters.begin()};
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++;
} }
this->fixCurrent();
} }
void Port::printParameters() { void Port::printParameters() {