2024-03-29 21:40:50 +01:00
|
|
|
#include <string>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
#include "sunspec.h"
|
|
|
|
|
#include "modbus.h"
|
|
|
|
|
#include "sunspecParameters.h"
|
|
|
|
|
|
2024-04-09 12:21:21 +02:00
|
|
|
Sunspec::Sunspec(int address, modbus_t *modbus) {
|
2024-03-29 21:40:50 +01:00
|
|
|
this->modbus = modbus;
|
|
|
|
|
this->sunspecAddress = address;
|
|
|
|
|
|
|
|
|
|
this->populateParameters();
|
|
|
|
|
|
|
|
|
|
this->setValues();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Sunspec::setValues() {
|
|
|
|
|
uint16_t registers[70];
|
|
|
|
|
|
|
|
|
|
int registerCount;
|
2024-04-09 12:21:21 +02:00
|
|
|
registerCount = modbus_read_registers(this->modbus, this->sunspecAddress, 70, registers);
|
2024-03-29 21:40:50 +01:00
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<SunspecParameter>>::iterator parametersIterator = this->parameters.begin();
|
|
|
|
|
while(parametersIterator != this->parameters.end()) {
|
2024-04-06 00:32:49 +02:00
|
|
|
parametersIterator->get()->getValueFromRegisters(registers, 0);
|
2024-03-29 21:40:50 +01:00
|
|
|
parametersIterator++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Sunspec::populateParameters() {
|
|
|
|
|
SunspecParameterManufacturer manufacturer{};
|
|
|
|
|
this->parameters.push_back(std::make_shared<SunspecParameterManufacturer>(manufacturer));
|
|
|
|
|
}
|