Revert "Trying to make less calls to dtu, making it "multithreaded""
This reverts commit ad4ff13be0.
This commit is contained in:
parent
ad4ff13be0
commit
f22aae499d
7 changed files with 33 additions and 38 deletions
|
|
@ -1,21 +1,18 @@
|
|||
#include <cmath>
|
||||
#include <iostream>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <memory>
|
||||
|
||||
#include "modbus.h"
|
||||
|
||||
#include "port.h"
|
||||
#include "portParameters.h"
|
||||
|
||||
Port::Port(std::shared_ptr<modbus_t *> modbus_context, std::mutex *modbus_context_mutex, uint16_t portStartAddress) {
|
||||
Port::Port(std::shared_ptr<modbus_t*> modbus_context, std::mutex *modbus_context_mutex, uint16_t portStartAddress) {
|
||||
this->modbus_context = modbus_context;
|
||||
this->modbus_context_mutex = modbus_context_mutex;
|
||||
|
||||
this->readArraySize = 34;
|
||||
this->readArray = new uint16_t[this->readArraySize];
|
||||
|
||||
this->portStartAddress = portStartAddress;
|
||||
|
||||
this->populateParameters();
|
||||
|
|
@ -54,15 +51,9 @@ void Port::populateParameters() {
|
|||
}
|
||||
|
||||
void Port::updateParameters() {
|
||||
int registerCount;
|
||||
|
||||
modbus_context_mutex->lock();
|
||||
registerCount = modbus_read_registers(*modbus_context.get(), portStartAddress - 1, this->readArraySize, this->readArray);
|
||||
modbus_context_mutex->unlock();
|
||||
|
||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator{this->parameters.begin()};
|
||||
while (parametersIterator != this->parameters.end()) {
|
||||
parametersIterator->get()->updateValue(this->readArray, this->readArraySize, registerCount);
|
||||
parametersIterator->get()->updateValue(this->modbus_context, this->modbus_context_mutex, this->portStartAddress);
|
||||
parametersIterator++;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue