It's asking but need to tweek setting values from registers

This commit is contained in:
TraYali 2024-03-16 22:51:32 +01:00
parent d0f8e5b885
commit f3f1aa3903
8 changed files with 309 additions and 109 deletions

View file

@ -7,6 +7,7 @@
#include "modbus.h"
#include "port.h"
#include "portParameters.h"
Port::Port(modbus_t *modbus_context, uint16_t portStartAddress) {
this->modbus_context = modbus_context;
@ -16,8 +17,35 @@ Port::Port(modbus_t *modbus_context, uint16_t portStartAddress) {
}
void Port::populateParameters() {
PortParameterFloat portParameterFloat{"gridVoltage", 1, 0x001a, 2};
this->parameters.push_back(std::make_shared<PortParameterFloat>(portParameterFloat));
this->parameters.push_back(std::make_shared<PortParameterMicroinverterSerialNumber>());
this->parameters.push_back(std::make_shared<PortParameterPortNumber>());
this->parameters.push_back(std::make_shared<PortParameterPvVoltage>());
this->parameters.push_back(std::make_shared<PortParameterPvCurrentMi>());
this->parameters.push_back(std::make_shared<PortParameterPvCurrentHm>());
this->parameters.push_back(std::make_shared<PortParameterGridVoltage>());
this->parameters.push_back(std::make_shared<PortParameterGridFrequency>());
this->parameters.push_back(std::make_shared<PortParameterPvPower>());
this->parameters.push_back(std::make_shared<PortParameterTodayProduction>());
this->parameters.push_back(std::make_shared<PortParameterTotalProduction>());
this->parameters.push_back(std::make_shared<PortParameterTemperature>());
this->parameters.push_back(std::make_shared<PortParameterOperatingStatus>());
this->parameters.push_back(std::make_shared<PortParameterAlarmCode>());
this->parameters.push_back(std::make_shared<PortParameterAlarmCount>());
this->parameters.push_back(std::make_shared<PortParameterLinkStatus>());
}
void Port::updateParameters() {
@ -26,53 +54,4 @@ void Port::updateParameters() {
parametersIterator->get()->updateValue(this->modbus_context, this->portStartAddress);
parametersIterator++;
}
}
PortParameter::PortParameter(std::string name, uint16_t parameterAddressOffset, int registerSize) {
this->name = name;
this->parameterAddressOffset = parameterAddressOffset;
this->registerSize = registerSize;
}
PortParameter::~PortParameter() {}
void PortParameter::setValueFromRegisters(uint16_t *readArray, int registerCount) {}
std::pair<PortParameter::PortParameterValue, PortParameter::PortParameterValueType> PortParameter::getValue() {
return std::pair<PortParameter::PortParameterValue, PortParameter::PortParameterValueType>(this->value, this->valueType);
}
std::string PortParameter::getOutputValue() {}
void PortParameter::updateValue(modbus_t *modbus_context, uint16_t portStartAddress) {
uint16_t readArray[this->registerSize];
int registerCount;
registerCount = modbus_read_registers(modbus_context, portStartAddress + this->parameterAddressOffset, this->registerSize, readArray);
registerCount = 2;
readArray[0] = 2312;
readArray[1] = 5432;
if(registerCount == -1){
std::cerr << "read_error";
return;
}
else{
this->setValueFromRegisters(readArray, registerCount);
}
}
PortParameterFloat::PortParameterFloat(std::string name, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, parameterAddressOffset, registerSize) {
this->decimalPlaces = decimalPlaces;
this->valueType = Float;
}
void PortParameterFloat::setValueFromRegisters(uint16_t *readArray, int registerCount) {
this->value.f = readArray[0] / std::pow(10, this->decimalPlaces);
}
std::string PortParameterFloat::getOutputValue() {
return std::to_string(this->value.f);
}