Release v2.2w #17
16 changed files with 169 additions and 65 deletions
|
|
@ -16,11 +16,11 @@ class Dtu {
|
|||
|
||||
void populateMicroinverters();
|
||||
|
||||
std::pair<Microinverter *, bool> getMicroinverterBySerialNumber(long long serialNumber);
|
||||
|
||||
public:
|
||||
Dtu(const char *ip_address, int port);
|
||||
|
||||
std::pair<Microinverter *, bool> getMicroinverterBySerialNumber(long long serialNumber);
|
||||
|
||||
bool isConnected();
|
||||
|
||||
bool modbusError();
|
||||
|
|
|
|||
|
|
@ -17,6 +17,8 @@ class Microinverter {
|
|||
|
||||
int startAddress;
|
||||
|
||||
int statusStartAddress;
|
||||
|
||||
public:
|
||||
Microinverter(std::shared_ptr<class modbus> modbus, int startAddress, long long serialNumber);
|
||||
|
||||
|
|
@ -30,11 +32,15 @@ class Microinverter {
|
|||
|
||||
void updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters);
|
||||
|
||||
void updateStatusParameters();
|
||||
|
||||
void printPorts(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames);
|
||||
|
||||
long long getTodayProduction();
|
||||
|
||||
long long getTotalProduction();
|
||||
|
||||
void setStatus(std::vector<std::pair<int, uint16_t>> portsToSet, std::string statusName);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -6,6 +6,7 @@
|
|||
#include <vector>
|
||||
|
||||
#include "portParametersGeneric.h"
|
||||
#include "portParameters.h"
|
||||
#include "modbus.h"
|
||||
|
||||
class Port {
|
||||
|
|
@ -22,15 +23,27 @@ class Port {
|
|||
|
||||
int portStartAddress;
|
||||
|
||||
int statusPortStartAddress;
|
||||
|
||||
std::vector<std::shared_ptr<PortParameter>> parameters;
|
||||
|
||||
std::vector<std::shared_ptr<PortParameter>> statusParameters;
|
||||
|
||||
std::pair<std::shared_ptr<PortParameter>, bool> getParameterByName(std::string name);
|
||||
|
||||
std::pair<std::shared_ptr<PortParameter>, bool> getStatusByName(std::string name);
|
||||
|
||||
// void updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters);
|
||||
|
||||
void setParametersFromMicroinverterArray(uint16_t *registers, int addressOffset);
|
||||
|
||||
void setStatusesFromMicroinverterArray(uint16_t *registers, int addressOffset);
|
||||
|
||||
void printParameters(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames);
|
||||
|
||||
void turnOff(class modbus &modbus);
|
||||
|
||||
bool isOff(class modbus &modbus);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
class PortParameterMicroinverterSerialNumber : public PortParameterInt {
|
||||
private:
|
||||
void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
|
||||
public:
|
||||
PortParameterMicroinverterSerialNumber();
|
||||
|
|
@ -81,4 +81,14 @@ class PortParameterLinkStatus : public PortParameterInt {
|
|||
PortParameterLinkStatus();
|
||||
};
|
||||
|
||||
class PortParameterOnOff : public PortParameterInt {
|
||||
public:
|
||||
PortParameterOnOff();
|
||||
};
|
||||
|
||||
class PortParameterLimitActivePower : public PortParameterInt {
|
||||
public:
|
||||
PortParameterLimitActivePower();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -42,9 +42,11 @@ class PortParameter {
|
|||
|
||||
std::pair<PortParameterValue, PortParameterValueType> getValue();
|
||||
|
||||
PortParameter& writeValue(uint16_t value, class modbus& modbus, int portStartAddress);
|
||||
|
||||
virtual std::string getOutputValue();
|
||||
|
||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
|
||||
// void updateValue(std::shared_ptr<class modbus> modubs, uint16_t portStartAddress);
|
||||
};
|
||||
|
|
@ -58,7 +60,7 @@ class PortParameterFloat : public PortParameter {
|
|||
|
||||
std::string getOutputValue();
|
||||
|
||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
};
|
||||
|
||||
class PortParameterInt : public PortParameter {
|
||||
|
|
@ -69,7 +71,7 @@ class PortParameterInt : public PortParameter {
|
|||
|
||||
std::string getOutputValue();
|
||||
|
||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -9,7 +9,7 @@ class SunspecParameterManufacturer : public SunspecParameterString32 {
|
|||
public:
|
||||
SunspecParameterManufacturer();
|
||||
|
||||
void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -33,7 +33,7 @@ class SunspecParameter {
|
|||
|
||||
public:
|
||||
|
||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
|
||||
std::pair<SunspecValue, SunspecValueType> getValue();
|
||||
};
|
||||
|
|
@ -44,7 +44,7 @@ class SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterUint32(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
// class SunspecParameterUint16 : public SunspecParameter {
|
||||
|
|
@ -53,7 +53,7 @@ class SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterUint16(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
class SunspecParameterString32 : public SunspecParameter {
|
||||
|
|
@ -63,7 +63,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
|||
public:
|
||||
SunspecParameterString32(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
};
|
||||
|
||||
// class SunspecParameterString16 : public SunspecParameter {
|
||||
|
|
@ -73,7 +73,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterString16(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
// class SunspecParameterSunssf : public SunspecParameter {
|
||||
|
|
@ -82,7 +82,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterSunssf(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
// class SunspecParameterInt16 : public SunspecParameter {
|
||||
|
|
@ -91,7 +91,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterInt16(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
// class SunspecParameterAcc32 : public SunspecParameter {
|
||||
|
|
@ -100,7 +100,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterAcc32(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
// class SunspecParameterFloat32 : public SunspecParameter {
|
||||
|
|
@ -109,7 +109,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterFloat32(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
// class SunspecParameterEnum16 : public SunspecParameter {
|
||||
|
|
@ -118,7 +118,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
|||
// public:
|
||||
// SunspecParameterEnum16(std::string name, int registerAddressOffset, int registerSize);
|
||||
|
||||
// virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||
// };
|
||||
|
||||
#endif
|
||||
|
|
@ -90,6 +90,7 @@ void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool a
|
|||
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||
if (microinverterPair.second) {
|
||||
microinverterPair.first->updateParameters(parametersToGet, allParameters);
|
||||
microinverterPair.first->updateStatusParameters();
|
||||
}
|
||||
microinvertersToGetIterator++;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ Microinverter::Microinverter(std::shared_ptr<class modbus> modbus, int startAddr
|
|||
this->startAddress = startAddress;
|
||||
this->serialNumber = serialNumber;
|
||||
|
||||
this->statusStartAddress = (((this->startAddress - 0x4000) / 0x0019) * 6) + 0xd006;
|
||||
|
||||
this->age = 0;
|
||||
}
|
||||
|
||||
|
|
@ -50,6 +52,33 @@ void Microinverter::updateParameters(std::vector<std::string> ¶metersToGet,
|
|||
}
|
||||
}
|
||||
|
||||
void Microinverter::updateStatusParameters() {
|
||||
int portsRead = 0;
|
||||
while (portsRead < this->ports.size()) {
|
||||
int portsToRead = 0;
|
||||
while (portsToRead * 6 < (10 - 6) && (portsToRead + portsRead) < this->ports.size()) {
|
||||
portsToRead++;
|
||||
}
|
||||
|
||||
int registersToRead = (portsToRead * 6);
|
||||
uint16_t registers[registersToRead];
|
||||
|
||||
int registerCount;
|
||||
registerCount = this->modbus.get()->modbus_read_holding_registers(this->statusStartAddress + (portsRead * 6), registersToRead, registers);
|
||||
|
||||
if (registerCount != 0) {
|
||||
this->age++;
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i{0}; i < portsToRead; i++) {
|
||||
this->ports.at(i + portsRead).setStatusesFromMicroinverterArray(registers, i * 6);
|
||||
}
|
||||
|
||||
portsRead += portsToRead;
|
||||
}
|
||||
}
|
||||
|
||||
void Microinverter::printPorts(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames) {
|
||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||
while (portsIterator != this->ports.end()) {
|
||||
|
|
@ -82,3 +111,11 @@ long long Microinverter::getTotalProduction() {
|
|||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Microinverter::setStatus(std::vector<std::pair<int, uint16_t>> portsToSet, std::string statusName) {
|
||||
std::vector<std::pair<int, uint16_t>>::iterator portsToSetIterator = portsToSet.begin();
|
||||
while(portsToSetIterator != portsToSet.end()) {
|
||||
this->ports.at(portsToSetIterator->first).getStatusByName(statusName).first.get()->writeValue(portsToSetIterator->second, *this->modbus, this->ports.at(portsToSetIterator->first).statusPortStartAddress);
|
||||
portsToSetIterator++;
|
||||
}
|
||||
}
|
||||
|
|
@ -12,6 +12,8 @@
|
|||
Port::Port(int portStartAddress) {
|
||||
this->portStartAddress = portStartAddress;
|
||||
|
||||
this->statusPortStartAddress = (((this->portStartAddress - 0x4000) / 0x0019) * 6) + 0xd006;
|
||||
|
||||
this->currentFixed = false;
|
||||
|
||||
this->populateParameters();
|
||||
|
|
@ -47,6 +49,11 @@ void Port::populateParameters() {
|
|||
this->parameters.push_back(std::make_shared<PortParameterAlarmCount>());
|
||||
|
||||
this->parameters.push_back(std::make_shared<PortParameterLinkStatus>());
|
||||
|
||||
|
||||
this->statusParameters.push_back(std::make_shared<PortParameterOnOff>());
|
||||
|
||||
this->statusParameters.push_back(std::make_shared<PortParameterLimitActivePower>());
|
||||
}
|
||||
|
||||
std::pair<std::shared_ptr<PortParameter>, bool> Port::getParameterByName(std::string name) {
|
||||
|
|
@ -65,6 +72,22 @@ std::pair<std::shared_ptr<PortParameter>, bool> Port::getParameterByName(std::st
|
|||
return result;
|
||||
}
|
||||
|
||||
std::pair<std::shared_ptr<PortParameter>, bool> Port::getStatusByName(std::string name) {
|
||||
std::pair<std::shared_ptr<PortParameter>, bool> result;
|
||||
result.second = false;
|
||||
|
||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->statusParameters.begin();
|
||||
while (parametersIterator != this->statusParameters.end() && !result.second) {
|
||||
if (parametersIterator->get()->name == name) {
|
||||
result.first = *parametersIterator;
|
||||
result.second = true;
|
||||
}
|
||||
parametersIterator++;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void Port::fixCurrent() {
|
||||
if (this->currentFixed) {
|
||||
return;
|
||||
|
|
@ -126,12 +149,20 @@ void Port::fixCurrent() {
|
|||
void Port::setParametersFromMicroinverterArray(uint16_t *registers, int addressOffset) {
|
||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||
while (parametersIterator != this->parameters.end()) {
|
||||
parametersIterator->get()->setValueFromRegisters(registers, addressOffset);
|
||||
parametersIterator->get()->getValueFromRegisters(registers, addressOffset);
|
||||
parametersIterator++;
|
||||
}
|
||||
this->fixCurrent();
|
||||
}
|
||||
|
||||
void Port::setStatusesFromMicroinverterArray(uint16_t *registers, int addressOffset) {
|
||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->statusParameters.begin();
|
||||
while (parametersIterator != this->statusParameters.end()) {
|
||||
parametersIterator->get()->getValueFromRegisters(registers, addressOffset);
|
||||
parametersIterator++;
|
||||
}
|
||||
}
|
||||
|
||||
void Port::printParameters(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames) {
|
||||
if (allParameters && parametersToGet.size() < this->parameters.size()) {
|
||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||
|
|
@ -161,8 +192,7 @@ void Port::printParameters(std::vector<std::string> ¶metersToGet, bool allPa
|
|||
std::cout << " ";
|
||||
if (shortNames) {
|
||||
std::cout << parameterPair.first->shortName;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
std::cout << parameterPair.first->name;
|
||||
}
|
||||
std::cout << ": " << parameterPair.first->getOutputValue() << " |";
|
||||
|
|
@ -170,3 +200,14 @@ void Port::printParameters(std::vector<std::string> ¶metersToGet, bool allPa
|
|||
parametersToGetIterator++;
|
||||
}
|
||||
}
|
||||
|
||||
void Port::turnOff(class modbus &modbus) { this->getStatusByName("onOff").first.get()->writeValue(0, modbus, this->statusPortStartAddress); }
|
||||
|
||||
bool Port::isOff(class modbus &modbus) {
|
||||
if(this->getStatusByName("onOff").first.get()->getValue().first.i == 1) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
@ -5,9 +5,9 @@
|
|||
|
||||
#include "portParameters.h"
|
||||
|
||||
PortParameterMicroinverterSerialNumber::PortParameterMicroinverterSerialNumber() : PortParameterInt("microinverterSerialNumber", "mSN", "", false, false, 0x0001, 3) {}
|
||||
PortParameterMicroinverterSerialNumber::PortParameterMicroinverterSerialNumber() : PortParameterInt("microinverterSerialNumber", "mSN", "", true, false, 0x0001, 3) {}
|
||||
|
||||
void PortParameterMicroinverterSerialNumber::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
void PortParameterMicroinverterSerialNumber::getValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
std::string readValueString = "";
|
||||
for (int i{0}; i < this->registerSize; i++) {
|
||||
std::stringstream readValueStringStream;
|
||||
|
|
@ -18,30 +18,34 @@ void PortParameterMicroinverterSerialNumber::setValueFromRegisters(uint16_t *reg
|
|||
this->value.i = std::stoll(readValueString);
|
||||
}
|
||||
|
||||
PortParameterPortNumber::PortParameterPortNumber() : PortParameterInt("portNumber", "pN", "", false, false, 0x0004, 1) {}
|
||||
PortParameterPortNumber::PortParameterPortNumber() : PortParameterInt("portNumber", "pN", "", true, false, 0x0004, 1) {}
|
||||
|
||||
PortParameterPvVoltage::PortParameterPvVoltage() : PortParameterFloat("pvVoltage", "pvU", "V", false, false, 1, 0x0005, 1) {}
|
||||
PortParameterPvVoltage::PortParameterPvVoltage() : PortParameterFloat("pvVoltage", "pvU", "V", true, false, 1, 0x0005, 1) {}
|
||||
|
||||
PortParameterPvCurrentMi::PortParameterPvCurrentMi() : PortParameterFloat("pvCurrentMI", "pvIMI", "A", false, false, 1, 0x0006, 1) {}
|
||||
PortParameterPvCurrentMi::PortParameterPvCurrentMi() : PortParameterFloat("pvCurrentMI", "pvIMI", "A", true, false, 1, 0x0006, 1) {}
|
||||
|
||||
PortParameterPvCurrentHm::PortParameterPvCurrentHm() : PortParameterFloat("pvCurrentHM", "pvIHM", "A", false, false, 2, 0x0006, 1) {}
|
||||
PortParameterPvCurrentHm::PortParameterPvCurrentHm() : PortParameterFloat("pvCurrentHM", "pvIHM", "A", true, false, 2, 0x0006, 1) {}
|
||||
|
||||
PortParameterGridVoltage::PortParameterGridVoltage() : PortParameterFloat("gridVoltage", "gU", "V", false, false, 1, 0x0007, 1) {}
|
||||
PortParameterGridVoltage::PortParameterGridVoltage() : PortParameterFloat("gridVoltage", "gU", "V", true, false, 1, 0x0007, 1) {}
|
||||
|
||||
PortParameterGridFrequency::PortParameterGridFrequency() : PortParameterFloat("gridFrequency", "gF", "Hz", false, false, 2, 0x0008, 1) {}
|
||||
PortParameterGridFrequency::PortParameterGridFrequency() : PortParameterFloat("gridFrequency", "gF", "Hz", true, false, 2, 0x0008, 1) {}
|
||||
|
||||
PortParameterPvPower::PortParameterPvPower() : PortParameterFloat("pvPower", "pvP", "W", false, false, 1, 0x0009, 1) {}
|
||||
PortParameterPvPower::PortParameterPvPower() : PortParameterFloat("pvPower", "pvP", "W", true, false, 1, 0x0009, 1) {}
|
||||
|
||||
PortParameterTodayProduction::PortParameterTodayProduction() : PortParameterInt("todayProduction", "tdP", "Wh", false, false, 0x000A, 1) {}
|
||||
PortParameterTodayProduction::PortParameterTodayProduction() : PortParameterInt("todayProduction", "tdP", "Wh", true, false, 0x000A, 1) {}
|
||||
|
||||
PortParameterTotalProduction::PortParameterTotalProduction() : PortParameterInt("totalProduction", "ttP", "Wh", false, false, 0x000B, 2) {}
|
||||
PortParameterTotalProduction::PortParameterTotalProduction() : PortParameterInt("totalProduction", "ttP", "Wh", true, false, 0x000B, 2) {}
|
||||
|
||||
PortParameterTemperature::PortParameterTemperature() : PortParameterFloat("temperature", "t", "C", false, false, 1, 0x000D, 1) {}
|
||||
PortParameterTemperature::PortParameterTemperature() : PortParameterFloat("temperature", "t", "C", true, false, 1, 0x000D, 1) {}
|
||||
|
||||
PortParameterOperatingStatus::PortParameterOperatingStatus() : PortParameterInt("operatingStatus", "oS", "", false, false, 0x000e, 1) {}
|
||||
PortParameterOperatingStatus::PortParameterOperatingStatus() : PortParameterInt("operatingStatus", "oS", "", true, false, 0x000e, 1) {}
|
||||
|
||||
PortParameterAlarmCode::PortParameterAlarmCode() : PortParameterInt("alarmCode", "aC", "", false, false, 0x000f, 1) {}
|
||||
PortParameterAlarmCode::PortParameterAlarmCode() : PortParameterInt("alarmCode", "aC", "", true, false, 0x000f, 1) {}
|
||||
|
||||
PortParameterAlarmCount::PortParameterAlarmCount() : PortParameterInt("alarmCount", "aCnt", "", false, false, 0x0010, 1) {}
|
||||
PortParameterAlarmCount::PortParameterAlarmCount() : PortParameterInt("alarmCount", "aCnt", "", true, false, 0x0010, 1) {}
|
||||
|
||||
PortParameterLinkStatus::PortParameterLinkStatus() : PortParameterInt("linkStatus", "lS", "", false, false, 0x011, 1) {}
|
||||
PortParameterLinkStatus::PortParameterLinkStatus() : PortParameterInt("linkStatus", "lS", "", true, false, 0x011, 1) {}
|
||||
|
||||
PortParameterOnOff::PortParameterOnOff() : PortParameterInt("onOff", "of", "", true, true, 0x0000, 1) {}
|
||||
|
||||
PortParameterLimitActivePower::PortParameterLimitActivePower() : PortParameterInt("limitActivePower", "lAP", "", true, true, 0x0001, 1) {}
|
||||
|
|
@ -18,38 +18,25 @@ PortParameter::PortParameter(std::string name, std::string shortName, std::strin
|
|||
|
||||
this->parameterAddressOffset = parameterAddressOffset;
|
||||
this->registerSize = registerSize;
|
||||
|
||||
// this->age = 0;
|
||||
}
|
||||
|
||||
PortParameter::~PortParameter() {}
|
||||
|
||||
void PortParameter::setValueFromRegisters(uint16_t *readArray, int portOffset) {}
|
||||
void PortParameter::getValueFromRegisters(uint16_t *readArray, int portOffset) {}
|
||||
|
||||
std::pair<PortParameter::PortParameterValue, PortParameter::PortParameterValueType> PortParameter::getValue() {
|
||||
return std::pair<PortParameter::PortParameterValue, PortParameter::PortParameterValueType>(this->value, this->valueType);
|
||||
}
|
||||
|
||||
PortParameter& PortParameter::writeValue(uint16_t value, class modbus& modbus, int portStartAddress) {
|
||||
modbus.modbus_write_register(this->parameterAddressOffset + portStartAddress, value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::string PortParameter::getOutputValue() {
|
||||
return "yeet";
|
||||
}
|
||||
|
||||
// void PortParameter::updateValue(std::shared_ptr<class modbus> modbus, uint16_t portStartAddress) {
|
||||
// uint16_t readArray[this->registerSize];
|
||||
// int registerCount;
|
||||
|
||||
// registerCount = modbus.get()->modbus_read_holding_registers(portStartAddress + this->parameterAddressOffset, this->registerSize, readArray);
|
||||
|
||||
// if(registerCount != 0){
|
||||
// this->age++;
|
||||
// }
|
||||
// else{
|
||||
// registerCount = this->registerSize;
|
||||
// this->setValueFromRegisters(readArray, registerCount);
|
||||
// this->age = 0;
|
||||
// }
|
||||
// }
|
||||
|
||||
PortParameterFloat::PortParameterFloat(std::string name, std::string shortName, std::string unit, bool r, bool w, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, shortName, unit, r, w, parameterAddressOffset, registerSize) {
|
||||
this->decimalPlaces = decimalPlaces;
|
||||
|
||||
|
|
@ -58,7 +45,7 @@ PortParameterFloat::PortParameterFloat(std::string name, std::string shortName,
|
|||
this->value.f = 0;
|
||||
}
|
||||
|
||||
void PortParameterFloat::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
void PortParameterFloat::getValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
std::string readValueString{""};
|
||||
for(int i{0}; i<this->registerSize; i++) {
|
||||
std::stringstream readValueStringStream;
|
||||
|
|
@ -80,7 +67,7 @@ PortParameterInt::PortParameterInt(std::string name, std::string shortName, std:
|
|||
this->value.i = 0;
|
||||
}
|
||||
|
||||
void PortParameterInt::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
void PortParameterInt::getValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
std::string readValueString{""};
|
||||
for (int i{0}; i < this->registerSize; i++) {
|
||||
std::stringstream readValueStringStream;
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ void Sunspec::setValues() {
|
|||
|
||||
std::vector<std::shared_ptr<SunspecParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||
while(parametersIterator != this->parameters.end()) {
|
||||
parametersIterator->get()->setValueFromRegisters(registers, 0);
|
||||
parametersIterator->get()->getValueFromRegisters(registers, 0);
|
||||
parametersIterator++;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ SunspecParameterManufacturer::SunspecParameterManufacturer() : SunspecParameterS
|
|||
this->valueType = string32;
|
||||
}
|
||||
|
||||
void SunspecParameterManufacturer::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
void SunspecParameterManufacturer::getValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||
std::string readValue;
|
||||
|
||||
for(int i{0}; i<this->registerSize; i++) {
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@ SunspecParameter::SunspecParameter(std::string name, int registerAddressOffset,
|
|||
this->registerSize = registerSize;
|
||||
}
|
||||
|
||||
void SunspecParameter::setValueFromRegisters(uint16_t *registers, int addressOffset) {}
|
||||
void SunspecParameter::getValueFromRegisters(uint16_t *registers, int addressOffset) {}
|
||||
|
||||
std::pair<SunspecParameter::SunspecValue, SunspecParameter::SunspecValueType> SunspecParameter::getValue() {}
|
||||
|
||||
SunspecParameterString32::SunspecParameterString32(std::string name, int registerAddressOffset, int registerSize) : SunspecParameter(name, registerAddressOffset, registerSize) {}
|
||||
|
||||
void SunspecParameterString32::setValueFromRegisters(uint16_t *registers, int addressOffset) {}
|
||||
void SunspecParameterString32::getValueFromRegisters(uint16_t *registers, int addressOffset) {}
|
||||
|
|
@ -88,6 +88,9 @@ int main(int argc, char **argv) {
|
|||
|
||||
dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToGet, shortNames, microinvertersGetTodayProduction, microinvertersGetTotalProduction);
|
||||
std::cout << std::endl;
|
||||
|
||||
std::vector<std::pair<int, uint16_t>> portsToLimitActivePower{std::pair<int, uint16_t>(0, 69), std::pair<int, uint16_t>(1, 38), std::pair<int, uint16_t>(3, 3)};
|
||||
dtu.getMicroinverterBySerialNumber(138273312349).first->setStatus(portsToLimitActivePower, "limitActivePower");
|
||||
}
|
||||
// if(dtu.modbusError()) {
|
||||
// std::cerr << dtu.modbusErrorMessage() << std::endl;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue