hoymilesClient/src/hoymiles/port.cpp

59 lines
1.9 KiB
C++
Raw Normal View History

2024-03-16 21:15:15 +01:00
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <memory>
#include "modbus.h"
#include "port.h"
#include "portParameters.h"
2024-03-16 21:15:15 +01:00
Port::Port(std::shared_ptr<modbus_t*> modbus_context, std::mutex *modbus_context_mutex, uint16_t portStartAddress) {
2024-03-16 21:15:15 +01:00
this->modbus_context = modbus_context;
this->modbus_context_mutex = modbus_context_mutex;
2024-03-16 21:15:15 +01:00
this->portStartAddress = portStartAddress;
this->populateParameters();
}
void Port::populateParameters() {
this->parameters.push_back(std::make_shared<PortParameterMicroinverterSerialNumber>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterPortNumber>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterPvVoltage>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterPvCurrentMi>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterPvCurrentHm>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterGridVoltage>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterGridFrequency>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterPvPower>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterTodayProduction>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterTotalProduction>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterTemperature>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterOperatingStatus>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterAlarmCode>());
2024-03-16 21:15:15 +01:00
this->parameters.push_back(std::make_shared<PortParameterAlarmCount>());
this->parameters.push_back(std::make_shared<PortParameterLinkStatus>());
2024-03-16 21:15:15 +01:00
}
void Port::updateParameters() {
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator{this->parameters.begin()};
while (parametersIterator != this->parameters.end()) {
parametersIterator->get()->updateValue(this->modbus_context, this->modbus_context_mutex, this->portStartAddress);
parametersIterator++;
}
2024-03-16 21:15:15 +01:00
}