Release v2.2w #17
16 changed files with 281 additions and 86 deletions
|
|
@ -16,11 +16,11 @@ class Dtu {
|
||||||
|
|
||||||
void populateMicroinverters();
|
void populateMicroinverters();
|
||||||
|
|
||||||
std::pair<Microinverter *, bool> getMicroinverterBySerialNumber(long long serialNumber);
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Dtu(const char *ip_address, int port);
|
Dtu(const char *ip_address, int port);
|
||||||
|
|
||||||
|
std::pair<Microinverter *, bool> getMicroinverterBySerialNumber(long long serialNumber);
|
||||||
|
|
||||||
bool isConnected();
|
bool isConnected();
|
||||||
|
|
||||||
bool modbusError();
|
bool modbusError();
|
||||||
|
|
@ -31,6 +31,10 @@ class Dtu {
|
||||||
|
|
||||||
void printMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet, bool shortNames, bool printTodayProduction, bool printTotalProduction);
|
void printMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet, bool shortNames, bool printTodayProduction, bool printTotalProduction);
|
||||||
|
|
||||||
|
void setStatusMicroinverters(uint16_t value, std::string statusName, std::vector<long long>& microinvertersToSet);
|
||||||
|
|
||||||
|
bool empty();
|
||||||
|
|
||||||
~Dtu();
|
~Dtu();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,8 @@ class Microinverter {
|
||||||
|
|
||||||
int startAddress;
|
int startAddress;
|
||||||
|
|
||||||
|
int statusStartAddress;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Microinverter(std::shared_ptr<class modbus> modbus, int startAddress, long long serialNumber);
|
Microinverter(std::shared_ptr<class modbus> modbus, int startAddress, long long serialNumber);
|
||||||
|
|
||||||
|
|
@ -30,11 +32,17 @@ class Microinverter {
|
||||||
|
|
||||||
void updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters);
|
void updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters);
|
||||||
|
|
||||||
|
void updateStatusParameters();
|
||||||
|
|
||||||
void printPorts(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames);
|
void printPorts(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames);
|
||||||
|
|
||||||
long long getTodayProduction();
|
long long getTodayProduction();
|
||||||
|
|
||||||
long long getTotalProduction();
|
long long getTotalProduction();
|
||||||
|
|
||||||
|
void setStatus(std::vector<std::pair<int, uint16_t>> portsToSet, std::string statusName);
|
||||||
|
|
||||||
|
void setStatusWholeMicroinverter(uint16_t value, std::string statusName);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "portParametersGeneric.h"
|
#include "portParametersGeneric.h"
|
||||||
|
#include "portParameters.h"
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
||||||
class Port {
|
class Port {
|
||||||
|
|
@ -22,15 +23,27 @@ class Port {
|
||||||
|
|
||||||
int portStartAddress;
|
int portStartAddress;
|
||||||
|
|
||||||
|
int statusPortStartAddress;
|
||||||
|
|
||||||
std::vector<std::shared_ptr<PortParameter>> parameters;
|
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> 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 updateParameters(std::vector<std::string> ¶metersToGet, bool allParameters);
|
||||||
|
|
||||||
void setParametersFromMicroinverterArray(uint16_t *registers, int addressOffset);
|
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 printParameters(std::vector<std::string> ¶metersToGet, bool allParameters, bool shortNames);
|
||||||
|
|
||||||
|
void turnOff(class modbus &modbus);
|
||||||
|
|
||||||
|
bool isOff(class modbus &modbus);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
class PortParameterMicroinverterSerialNumber : public PortParameterInt {
|
class PortParameterMicroinverterSerialNumber : public PortParameterInt {
|
||||||
private:
|
private:
|
||||||
void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PortParameterMicroinverterSerialNumber();
|
PortParameterMicroinverterSerialNumber();
|
||||||
|
|
@ -81,4 +81,14 @@ class PortParameterLinkStatus : public PortParameterInt {
|
||||||
PortParameterLinkStatus();
|
PortParameterLinkStatus();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class PortParameterOnOff : public PortParameterInt {
|
||||||
|
public:
|
||||||
|
PortParameterOnOff();
|
||||||
|
};
|
||||||
|
|
||||||
|
class PortParameterLimitActivePower : public PortParameterInt {
|
||||||
|
public:
|
||||||
|
PortParameterLimitActivePower();
|
||||||
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -15,8 +15,11 @@ class PortParameter {
|
||||||
|
|
||||||
std::string unit;
|
std::string unit;
|
||||||
|
|
||||||
|
bool r;
|
||||||
|
bool w;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PortParameter(std::string name, std::string shortName, std::string unit, uint16_t parameterAddressOffset, int registerSize);
|
PortParameter(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize);
|
||||||
|
|
||||||
virtual ~PortParameter();
|
virtual ~PortParameter();
|
||||||
|
|
||||||
|
|
@ -39,9 +42,11 @@ class PortParameter {
|
||||||
|
|
||||||
std::pair<PortParameterValue, PortParameterValueType> getValue();
|
std::pair<PortParameterValue, PortParameterValueType> getValue();
|
||||||
|
|
||||||
|
PortParameter& writeValue(uint16_t value, class modbus& modbus, int portStartAddress);
|
||||||
|
|
||||||
virtual std::string getOutputValue();
|
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);
|
// void updateValue(std::shared_ptr<class modbus> modubs, uint16_t portStartAddress);
|
||||||
};
|
};
|
||||||
|
|
@ -51,22 +56,22 @@ class PortParameterFloat : public PortParameter {
|
||||||
int decimalPlaces;
|
int decimalPlaces;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PortParameterFloat(std::string name, std::string shortName, std::string unit, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize);
|
PortParameterFloat(std::string name, std::string shortName, std::string unit, bool r, bool w, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize);
|
||||||
|
|
||||||
std::string getOutputValue();
|
std::string getOutputValue();
|
||||||
|
|
||||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
};
|
};
|
||||||
|
|
||||||
class PortParameterInt : public PortParameter {
|
class PortParameterInt : public PortParameter {
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
public:
|
public:
|
||||||
PortParameterInt(std::string name, std::string shortName, std::string unit, uint16_t parameterAddressOffset, int registerSize);
|
PortParameterInt(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize);
|
||||||
|
|
||||||
std::string getOutputValue();
|
std::string getOutputValue();
|
||||||
|
|
||||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -9,7 +9,7 @@ class SunspecParameterManufacturer : public SunspecParameterString32 {
|
||||||
public:
|
public:
|
||||||
SunspecParameterManufacturer();
|
SunspecParameterManufacturer();
|
||||||
|
|
||||||
void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -33,7 +33,7 @@ class SunspecParameter {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
virtual void setValueFromRegisters(uint16_t *registers, int addressOffset);
|
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
||||||
|
|
||||||
std::pair<SunspecValue, SunspecValueType> getValue();
|
std::pair<SunspecValue, SunspecValueType> getValue();
|
||||||
};
|
};
|
||||||
|
|
@ -44,7 +44,7 @@ class SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterUint32(std::string name, int registerAddressOffset, int registerSize);
|
// 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 {
|
// class SunspecParameterUint16 : public SunspecParameter {
|
||||||
|
|
@ -53,7 +53,7 @@ class SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterUint16(std::string name, int registerAddressOffset, int registerSize);
|
// 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 {
|
class SunspecParameterString32 : public SunspecParameter {
|
||||||
|
|
@ -63,7 +63,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
||||||
public:
|
public:
|
||||||
SunspecParameterString32(std::string name, int registerAddressOffset, int registerSize);
|
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 {
|
// class SunspecParameterString16 : public SunspecParameter {
|
||||||
|
|
@ -73,7 +73,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterString16(std::string name, int registerAddressOffset, int registerSize);
|
// 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 {
|
// class SunspecParameterSunssf : public SunspecParameter {
|
||||||
|
|
@ -82,7 +82,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterSunssf(std::string name, int registerAddressOffset, int registerSize);
|
// 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 {
|
// class SunspecParameterInt16 : public SunspecParameter {
|
||||||
|
|
@ -91,7 +91,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterInt16(std::string name, int registerAddressOffset, int registerSize);
|
// 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 {
|
// class SunspecParameterAcc32 : public SunspecParameter {
|
||||||
|
|
@ -100,7 +100,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterAcc32(std::string name, int registerAddressOffset, int registerSize);
|
// 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 {
|
// class SunspecParameterFloat32 : public SunspecParameter {
|
||||||
|
|
@ -109,7 +109,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterFloat32(std::string name, int registerAddressOffset, int registerSize);
|
// 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 {
|
// class SunspecParameterEnum16 : public SunspecParameter {
|
||||||
|
|
@ -118,7 +118,7 @@ class SunspecParameterString32 : public SunspecParameter {
|
||||||
// public:
|
// public:
|
||||||
// SunspecParameterEnum16(std::string name, int registerAddressOffset, int registerSize);
|
// 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
|
#endif
|
||||||
|
|
@ -90,6 +90,7 @@ void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool a
|
||||||
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToGetIterator);
|
||||||
if (microinverterPair.second) {
|
if (microinverterPair.second) {
|
||||||
microinverterPair.first->updateParameters(parametersToGet, allParameters);
|
microinverterPair.first->updateParameters(parametersToGet, allParameters);
|
||||||
|
microinverterPair.first->updateStatusParameters();
|
||||||
}
|
}
|
||||||
microinvertersToGetIterator++;
|
microinvertersToGetIterator++;
|
||||||
}
|
}
|
||||||
|
|
@ -111,10 +112,10 @@ void Dtu::printMicroinverters(std::vector<std::string> ¶metersToGet, bool al
|
||||||
std::cout << " " << "Microinverter: " << microinverterPair.first->serialNumber << std::endl;
|
std::cout << " " << "Microinverter: " << microinverterPair.first->serialNumber << std::endl;
|
||||||
std::cout << " " << "Microinverter Data Age: " << microinverterPair.first->age << std::endl;
|
std::cout << " " << "Microinverter Data Age: " << microinverterPair.first->age << std::endl;
|
||||||
if (printTodayProduction) {
|
if (printTodayProduction) {
|
||||||
std::cout << " " << "TodayProduction: " << microinverterPair.first->getTodayProduction() << std::endl;
|
std::cout << " " << "TodayProduction: " << microinverterPair.first->getTodayProduction() << "Wh" << std::endl;
|
||||||
}
|
}
|
||||||
if (printTotalProduction) {
|
if (printTotalProduction) {
|
||||||
std::cout << " " << "TotalProduction: " << microinverterPair.first->getTotalProduction() << std::endl;
|
std::cout << " " << "TotalProduction: " << microinverterPair.first->getTotalProduction() << "Wh" << std::endl;
|
||||||
}
|
}
|
||||||
microinverterPair.first->printPorts(parametersToGet, allParameters, shortNames);
|
microinverterPair.first->printPorts(parametersToGet, allParameters, shortNames);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
|
|
@ -122,3 +123,26 @@ void Dtu::printMicroinverters(std::vector<std::string> ¶metersToGet, bool al
|
||||||
microinvertersToGetIterator++;
|
microinvertersToGetIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Dtu::setStatusMicroinverters(uint16_t value, std::string statusName, std::vector<long long>& microinvertersToSet) {
|
||||||
|
if (microinvertersToSet.empty()) {
|
||||||
|
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||||
|
while (microinvertersIterator != this->microinverters.end()) {
|
||||||
|
microinvertersToSet.push_back(microinvertersIterator->serialNumber);
|
||||||
|
microinvertersIterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<long long>::iterator microinvertersToSetIterator = microinvertersToSet.begin();
|
||||||
|
while(microinvertersToSetIterator != microinvertersToSet.end()) {
|
||||||
|
std::pair<Microinverter *, bool> microinverterPair = this->getMicroinverterBySerialNumber(*microinvertersToSetIterator);
|
||||||
|
if(microinverterPair.second) {
|
||||||
|
microinverterPair.first->setStatusWholeMicroinverter(value, statusName);
|
||||||
|
}
|
||||||
|
microinvertersToSetIterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Dtu::empty() {
|
||||||
|
return this->microinverters.empty();
|
||||||
|
}
|
||||||
|
|
@ -13,6 +13,8 @@ Microinverter::Microinverter(std::shared_ptr<class modbus> modbus, int startAddr
|
||||||
this->startAddress = startAddress;
|
this->startAddress = startAddress;
|
||||||
this->serialNumber = serialNumber;
|
this->serialNumber = serialNumber;
|
||||||
|
|
||||||
|
this->statusStartAddress = (((this->startAddress - 0x4000) / 0x0019) * 6) + 0xd006;
|
||||||
|
|
||||||
this->age = 0;
|
this->age = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -43,7 +45,37 @@ void Microinverter::updateParameters(std::vector<std::string> ¶metersToGet,
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i{0}; i < portsToRead; i++) {
|
for (int i{0}; i < portsToRead; i++) {
|
||||||
this->ports.at(i).setParametersFromMicroinverterArray(registers, i * 0x0019);
|
this->ports.at(i + portsRead).setParametersFromMicroinverterArray(registers, i * 0x0019);
|
||||||
|
}
|
||||||
|
|
||||||
|
portsRead += portsToRead;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Microinverter::updateStatusParameters() {
|
||||||
|
int portsRead = 0;
|
||||||
|
while (portsRead < this->ports.size()) {
|
||||||
|
int portsToRead = 0;
|
||||||
|
while (portsToRead * 6 < (128 - 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;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this->age = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i{0}; i < portsToRead; i++) {
|
||||||
|
this->ports.at(i + portsRead).setStatusesFromMicroinverterArray(registers, i * 6);
|
||||||
}
|
}
|
||||||
|
|
||||||
portsRead += portsToRead;
|
portsRead += portsToRead;
|
||||||
|
|
@ -82,3 +114,26 @@ long long Microinverter::getTotalProduction() {
|
||||||
|
|
||||||
return result;
|
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()) {
|
||||||
|
try {
|
||||||
|
if(this->ports.at(portsToSetIterator->first).getStatusByName(statusName).second) {
|
||||||
|
this->ports.at(portsToSetIterator->first).getStatusByName(statusName).first->writeValue(portsToSetIterator->second, *this->modbus, this->statusStartAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const std::out_of_range& outOfRange) {
|
||||||
|
std::cerr << outOfRange.what() << std::endl;
|
||||||
|
}
|
||||||
|
portsToSetIterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Microinverter::setStatusWholeMicroinverter(uint16_t value, std::string statusName) {
|
||||||
|
if(this->ports.begin() != this->ports.end()) {
|
||||||
|
if(this->ports.begin()->getStatusByName(statusName).second) {
|
||||||
|
this->ports.begin()->getStatusByName(statusName).first.get()->writeValue(value, *this->modbus, this->ports.begin()->statusPortStartAddress);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -12,6 +12,8 @@
|
||||||
Port::Port(int portStartAddress) {
|
Port::Port(int portStartAddress) {
|
||||||
this->portStartAddress = portStartAddress;
|
this->portStartAddress = portStartAddress;
|
||||||
|
|
||||||
|
this->statusPortStartAddress = (((this->portStartAddress - 0x4000) / 0x0019) * 6) + 0xd006;
|
||||||
|
|
||||||
this->currentFixed = false;
|
this->currentFixed = false;
|
||||||
|
|
||||||
this->populateParameters();
|
this->populateParameters();
|
||||||
|
|
@ -47,6 +49,10 @@ void Port::populateParameters() {
|
||||||
this->parameters.push_back(std::make_shared<PortParameterAlarmCount>());
|
this->parameters.push_back(std::make_shared<PortParameterAlarmCount>());
|
||||||
|
|
||||||
this->parameters.push_back(std::make_shared<PortParameterLinkStatus>());
|
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) {
|
std::pair<std::shared_ptr<PortParameter>, bool> Port::getParameterByName(std::string name) {
|
||||||
|
|
@ -65,6 +71,22 @@ std::pair<std::shared_ptr<PortParameter>, bool> Port::getParameterByName(std::st
|
||||||
return result;
|
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() {
|
void Port::fixCurrent() {
|
||||||
if (this->currentFixed) {
|
if (this->currentFixed) {
|
||||||
return;
|
return;
|
||||||
|
|
@ -80,7 +102,7 @@ void Port::fixCurrent() {
|
||||||
if (this->getParameterByName("pvPower").first->getValue().first.f > this->getParameterByName("pvVoltage").first->getValue().first.f * this->getParameterByName("pvCurrentMI").first->getValue().first.f) {
|
if (this->getParameterByName("pvPower").first->getValue().first.f > this->getParameterByName("pvVoltage").first->getValue().first.f * this->getParameterByName("pvCurrentMI").first->getValue().first.f) {
|
||||||
this->parameters.erase(std::find(this->parameters.begin(), this->parameters.end(), this->getParameterByName("pvCurrentHM").first));
|
this->parameters.erase(std::find(this->parameters.begin(), this->parameters.end(), this->getParameterByName("pvCurrentHM").first));
|
||||||
} else {
|
} else {
|
||||||
this->parameters.erase(std::find(this->parameters.begin(), this->parameters.end(), this->getParameterByName("pvCurrentM").first));
|
this->parameters.erase(std::find(this->parameters.begin(), this->parameters.end(), this->getParameterByName("pvCurrentMI").first));
|
||||||
}
|
}
|
||||||
this->currentFixed = true;
|
this->currentFixed = true;
|
||||||
}
|
}
|
||||||
|
|
@ -125,8 +147,17 @@ void Port::fixCurrent() {
|
||||||
|
|
||||||
void Port::setParametersFromMicroinverterArray(uint16_t *registers, int addressOffset) {
|
void Port::setParametersFromMicroinverterArray(uint16_t *registers, int addressOffset) {
|
||||||
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
std::vector<std::shared_ptr<PortParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||||
while(parametersIterator != this->parameters.end()) {
|
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++;
|
parametersIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -149,7 +180,7 @@ void Port::printParameters(std::vector<std::string> ¶metersToGet, bool allPa
|
||||||
}
|
}
|
||||||
|
|
||||||
while (parametersToGetIterator != parametersToGet.end()) {
|
while (parametersToGetIterator != parametersToGet.end()) {
|
||||||
if(*parametersToGetIterator == "microinverterSerialNumber") {
|
if (*parametersToGetIterator == "microinverterSerialNumber") {
|
||||||
parametersToGetIterator++;
|
parametersToGetIterator++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
@ -158,14 +189,35 @@ void Port::printParameters(std::vector<std::string> ¶metersToGet, bool allPa
|
||||||
parameterPair = this->getParameterByName(*parametersToGetIterator);
|
parameterPair = this->getParameterByName(*parametersToGetIterator);
|
||||||
if (parameterPair.second) {
|
if (parameterPair.second) {
|
||||||
std::cout << " ";
|
std::cout << " ";
|
||||||
if(shortNames) {
|
if (shortNames) {
|
||||||
std::cout << parameterPair.first->shortName;
|
std::cout << parameterPair.first->shortName;
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
std::cout << parameterPair.first->name;
|
std::cout << parameterPair.first->name;
|
||||||
}
|
}
|
||||||
std::cout << ": " << parameterPair.first->getOutputValue() << " |";
|
std::cout << ": " << parameterPair.first->getOutputValue() << " |";
|
||||||
}
|
}
|
||||||
parametersToGetIterator++;
|
parametersToGetIterator++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::shared_ptr<PortParameter>>::iterator statusesToGetIterator = this->statusParameters.begin();
|
||||||
|
while (statusesToGetIterator != this->statusParameters.end()) {
|
||||||
|
std::cout << " ";
|
||||||
|
if (shortNames) {
|
||||||
|
std::cout << statusesToGetIterator->get()->shortName;
|
||||||
|
} else {
|
||||||
|
std::cout << statusesToGetIterator->get()->name;
|
||||||
|
}
|
||||||
|
std::cout << ": " << statusesToGetIterator->get()->getOutputValue() << " |";
|
||||||
|
statusesToGetIterator++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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,43 +5,47 @@
|
||||||
|
|
||||||
#include "portParameters.h"
|
#include "portParameters.h"
|
||||||
|
|
||||||
PortParameterMicroinverterSerialNumber::PortParameterMicroinverterSerialNumber() : PortParameterInt("microinverterSerialNumber", "mSN", "", 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 = "";
|
std::string readValueString = "";
|
||||||
for (int i{0}; i < this->registerSize; i++) {
|
for (int i{0}; i < this->registerSize; i++) {
|
||||||
std::stringstream readValueStringStream;
|
std::stringstream readValueStringStream;
|
||||||
readValueStringStream << std::hex << (int) ((registers[addressOffset + this->parameterAddressOffset + i] & 0xff00) > 8);
|
readValueStringStream << std::hex << (int) ((registers[addressOffset + this->parameterAddressOffset + i] & 0xff00) >> 8);
|
||||||
readValueStringStream << std::hex << (int) (registers[addressOffset + this->parameterAddressOffset + i] & 0x00ff);
|
readValueStringStream << std::hex << (int) (registers[addressOffset + this->parameterAddressOffset + i] & 0x00ff);
|
||||||
readValueString.append(readValueStringStream.str());
|
readValueString.append(readValueStringStream.str());
|
||||||
}
|
}
|
||||||
this->value.i = std::stoll(readValueString);
|
this->value.i = std::stoll(readValueString);
|
||||||
}
|
}
|
||||||
|
|
||||||
PortParameterPortNumber::PortParameterPortNumber() : PortParameterInt("portNumber", "pN", "", 0x0004, 1) {}
|
PortParameterPortNumber::PortParameterPortNumber() : PortParameterInt("portNumber", "pN", "", true, false, 0x0004, 1) {}
|
||||||
|
|
||||||
PortParameterPvVoltage::PortParameterPvVoltage() : PortParameterFloat("pvVoltage", "pvU", "V", 1, 0x0005, 1) {}
|
PortParameterPvVoltage::PortParameterPvVoltage() : PortParameterFloat("pvVoltage", "pvU", "V", true, false, 1, 0x0005, 1) {}
|
||||||
|
|
||||||
PortParameterPvCurrentMi::PortParameterPvCurrentMi() : PortParameterFloat("pvCurrentMI", "pvIMI", "A", 1, 0x0006, 1) {}
|
PortParameterPvCurrentMi::PortParameterPvCurrentMi() : PortParameterFloat("pvCurrentMI", "pvIMI", "A", true, false, 1, 0x0006, 1) {}
|
||||||
|
|
||||||
PortParameterPvCurrentHm::PortParameterPvCurrentHm() : PortParameterFloat("pvCurrentHM", "pvIHM", "A", 2, 0x0006, 1) {}
|
PortParameterPvCurrentHm::PortParameterPvCurrentHm() : PortParameterFloat("pvCurrentHM", "pvIHM", "A", true, false, 2, 0x0006, 1) {}
|
||||||
|
|
||||||
PortParameterGridVoltage::PortParameterGridVoltage() : PortParameterFloat("gridVoltage", "gU", "V", 1, 0x0007, 1) {}
|
PortParameterGridVoltage::PortParameterGridVoltage() : PortParameterFloat("gridVoltage", "gU", "V", true, false, 1, 0x0007, 1) {}
|
||||||
|
|
||||||
PortParameterGridFrequency::PortParameterGridFrequency() : PortParameterFloat("gridFrequency", "gF", "Hz", 2, 0x0008, 1) {}
|
PortParameterGridFrequency::PortParameterGridFrequency() : PortParameterFloat("gridFrequency", "gF", "Hz", true, false, 2, 0x0008, 1) {}
|
||||||
|
|
||||||
PortParameterPvPower::PortParameterPvPower() : PortParameterFloat("pvPower", "pvP", "W", 1, 0x0009, 1) {}
|
PortParameterPvPower::PortParameterPvPower() : PortParameterFloat("pvPower", "pvP", "W", true, false, 1, 0x0009, 1) {}
|
||||||
|
|
||||||
PortParameterTodayProduction::PortParameterTodayProduction() : PortParameterInt("todayProduction", "tdP", "Wh", 0x000A, 1) {}
|
PortParameterTodayProduction::PortParameterTodayProduction() : PortParameterInt("todayProduction", "tdP", "Wh", true, false, 0x000A, 1) {}
|
||||||
|
|
||||||
PortParameterTotalProduction::PortParameterTotalProduction() : PortParameterInt("totalProduction", "ttP", "Wh", 0x000B, 2) {}
|
PortParameterTotalProduction::PortParameterTotalProduction() : PortParameterInt("totalProduction", "ttP", "Wh", true, false, 0x000B, 2) {}
|
||||||
|
|
||||||
PortParameterTemperature::PortParameterTemperature() : PortParameterFloat("temperature", "t", "C", 1, 0x000D, 1) {}
|
PortParameterTemperature::PortParameterTemperature() : PortParameterFloat("temperature", "t", "C", true, false, 1, 0x000D, 1) {}
|
||||||
|
|
||||||
PortParameterOperatingStatus::PortParameterOperatingStatus() : PortParameterInt("operatingStatus", "oS", "", 0x000e, 1) {}
|
PortParameterOperatingStatus::PortParameterOperatingStatus() : PortParameterInt("operatingStatus", "oS", "", true, false, 0x000e, 1) {}
|
||||||
|
|
||||||
PortParameterAlarmCode::PortParameterAlarmCode() : PortParameterInt("alarmCode", "aC", "", 0x000f, 1) {}
|
PortParameterAlarmCode::PortParameterAlarmCode() : PortParameterInt("alarmCode", "aC", "", true, false, 0x000f, 1) {}
|
||||||
|
|
||||||
PortParameterAlarmCount::PortParameterAlarmCount() : PortParameterInt("alarmCount", "aCnt", "", 0x0010, 1) {}
|
PortParameterAlarmCount::PortParameterAlarmCount() : PortParameterInt("alarmCount", "aCnt", "", true, false, 0x0010, 1) {}
|
||||||
|
|
||||||
PortParameterLinkStatus::PortParameterLinkStatus() : PortParameterInt("linkStatus", "lS", "", 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) {}
|
||||||
|
|
@ -8,46 +8,37 @@
|
||||||
|
|
||||||
#include "portParametersGeneric.h"
|
#include "portParametersGeneric.h"
|
||||||
|
|
||||||
PortParameter::PortParameter(std::string name, std::string shortName, std::string unit, uint16_t parameterAddressOffset, int registerSize) {
|
PortParameter::PortParameter(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize) {
|
||||||
this->name = name;
|
this->name = name;
|
||||||
this->shortName = shortName;
|
this->shortName = shortName;
|
||||||
this->unit = unit;
|
this->unit = unit;
|
||||||
|
|
||||||
|
this->r = r;
|
||||||
|
this->w = w;
|
||||||
|
|
||||||
this->parameterAddressOffset = parameterAddressOffset;
|
this->parameterAddressOffset = parameterAddressOffset;
|
||||||
this->registerSize = registerSize;
|
this->registerSize = registerSize;
|
||||||
|
|
||||||
// this->age = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
PortParameter::~PortParameter() {}
|
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() {
|
std::pair<PortParameter::PortParameterValue, PortParameter::PortParameterValueType> PortParameter::getValue() {
|
||||||
return std::pair<PortParameter::PortParameterValue, PortParameter::PortParameterValueType>(this->value, this->valueType);
|
return std::pair<PortParameter::PortParameterValue, PortParameter::PortParameterValueType>(this->value, this->valueType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PortParameter& PortParameter::writeValue(uint16_t value, class modbus& modbus, int portStartAddress) {
|
||||||
|
int writeCount;
|
||||||
|
writeCount = modbus.modbus_write_register(this->parameterAddressOffset + portStartAddress, value);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
std::string PortParameter::getOutputValue() {
|
std::string PortParameter::getOutputValue() {
|
||||||
return "yeet";
|
return "yeet";
|
||||||
}
|
}
|
||||||
|
|
||||||
// void PortParameter::updateValue(std::shared_ptr<class modbus> modbus, uint16_t portStartAddress) {
|
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) {
|
||||||
// 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, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, shortName, unit, parameterAddressOffset, registerSize) {
|
|
||||||
this->decimalPlaces = decimalPlaces;
|
this->decimalPlaces = decimalPlaces;
|
||||||
|
|
||||||
this->valueType = Float;
|
this->valueType = Float;
|
||||||
|
|
@ -55,7 +46,7 @@ PortParameterFloat::PortParameterFloat(std::string name, std::string shortName,
|
||||||
this->value.f = 0;
|
this->value.f = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortParameterFloat::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
void PortParameterFloat::getValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||||
std::string readValueString{""};
|
std::string readValueString{""};
|
||||||
for(int i{0}; i<this->registerSize; i++) {
|
for(int i{0}; i<this->registerSize; i++) {
|
||||||
std::stringstream readValueStringStream;
|
std::stringstream readValueStringStream;
|
||||||
|
|
@ -71,13 +62,13 @@ std::string PortParameterFloat::getOutputValue() {
|
||||||
return valueStringStream.str().append(this->unit.c_str());
|
return valueStringStream.str().append(this->unit.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
PortParameterInt::PortParameterInt(std::string name, std::string shortName, std::string unit, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, shortName, unit, parameterAddressOffset, registerSize) {
|
PortParameterInt::PortParameterInt(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize) : PortParameter(name, shortName, unit, r, w, parameterAddressOffset, registerSize) {
|
||||||
this->valueType = Int;
|
this->valueType = Int;
|
||||||
|
|
||||||
this->value.i = 0;
|
this->value.i = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PortParameterInt::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
void PortParameterInt::getValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||||
std::string readValueString{""};
|
std::string readValueString{""};
|
||||||
for (int i{0}; i < this->registerSize; i++) {
|
for (int i{0}; i < this->registerSize; i++) {
|
||||||
std::stringstream readValueStringStream;
|
std::stringstream readValueStringStream;
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ void Sunspec::setValues() {
|
||||||
|
|
||||||
std::vector<std::shared_ptr<SunspecParameter>>::iterator parametersIterator = this->parameters.begin();
|
std::vector<std::shared_ptr<SunspecParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||||
while(parametersIterator != this->parameters.end()) {
|
while(parametersIterator != this->parameters.end()) {
|
||||||
parametersIterator->get()->setValueFromRegisters(registers, 0);
|
parametersIterator->get()->getValueFromRegisters(registers, 0);
|
||||||
parametersIterator++;
|
parametersIterator++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ SunspecParameterManufacturer::SunspecParameterManufacturer() : SunspecParameterS
|
||||||
this->valueType = string32;
|
this->valueType = string32;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SunspecParameterManufacturer::setValueFromRegisters(uint16_t *registers, int addressOffset) {
|
void SunspecParameterManufacturer::getValueFromRegisters(uint16_t *registers, int addressOffset) {
|
||||||
std::string readValue;
|
std::string readValue;
|
||||||
|
|
||||||
for(int i{0}; i<this->registerSize; i++) {
|
for(int i{0}; i<this->registerSize; i++) {
|
||||||
|
|
|
||||||
|
|
@ -8,10 +8,10 @@ SunspecParameter::SunspecParameter(std::string name, int registerAddressOffset,
|
||||||
this->registerSize = registerSize;
|
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() {}
|
std::pair<SunspecParameter::SunspecValue, SunspecParameter::SunspecValueType> SunspecParameter::getValue() {}
|
||||||
|
|
||||||
SunspecParameterString32::SunspecParameterString32(std::string name, int registerAddressOffset, int registerSize) : SunspecParameter(name, registerAddressOffset, registerSize) {}
|
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) {}
|
||||||
51
src/main.cpp
51
src/main.cpp
|
|
@ -1,11 +1,11 @@
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <signal.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "CLI11.hpp"
|
#include "CLI11.hpp"
|
||||||
#include "modbus.h"
|
#include "modbus.h"
|
||||||
|
|
@ -19,11 +19,13 @@ int main(int argc, char **argv) {
|
||||||
signal(SIGTERM, sigHandler);
|
signal(SIGTERM, sigHandler);
|
||||||
signal(SIGABRT, sigHandler);
|
signal(SIGABRT, sigHandler);
|
||||||
|
|
||||||
std::string version{"v2.1"};
|
std::string version{"v2.2w"};
|
||||||
std::cout << version << std::endl;
|
std::cout << version << std::endl;
|
||||||
|
|
||||||
CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"};
|
CLI::App hoymilesClient{"Client for DTU-Pro/DTU-ProS"};
|
||||||
|
|
||||||
|
hoymilesClient.set_version_flag("-v,--version", version);
|
||||||
|
|
||||||
std::string ipAddress{"127.0.0.1"};
|
std::string ipAddress{"127.0.0.1"};
|
||||||
std::string ipAddressHelp{"ipv4 address of DTU {default: " + ipAddress + "}"};
|
std::string ipAddressHelp{"ipv4 address of DTU {default: " + ipAddress + "}"};
|
||||||
hoymilesClient.add_option<std::string>("-i,--ip_address", ipAddress, ipAddressHelp)->required()->group("Networking");
|
hoymilesClient.add_option<std::string>("-i,--ip_address", ipAddress, ipAddressHelp)->required()->group("Networking");
|
||||||
|
|
@ -33,7 +35,8 @@ int main(int argc, char **argv) {
|
||||||
hoymilesClient.add_option<int>("-p,--port", port, portHelp)->group("Networking");
|
hoymilesClient.add_option<int>("-p,--port", port, portHelp)->group("Networking");
|
||||||
|
|
||||||
std::vector<std::string> parametersToGet{};
|
std::vector<std::string> parametersToGet{};
|
||||||
std::string parametersToGetHelp{"List of parameters to fetch, delimited by ','; possible parameters:\n - pvVoltage [pvU]\n - pvCurrentMI [pvIMI]\n - pvCurrentHM [pvIHM]\n - gridVoltage [gU]\n - gridFrequency [gF]\n - pvPower [gP]\n - todayProduction [tdP]\n - totalProduction [ttP]\n - temperature [t]\n - operatingStatus [oS]\n - alarmCode [aC]\n - alarmCount [aCnt]\n - linkStatus [lS]"};
|
std::string parametersToGetHelp{"List of parameters to fetch, delimited by ','; possible parameters:\n - pvVoltage [pvU]\n - pvCurrentMI [pvIMI]\n - pvCurrentHM [pvIHM]\n - gridVoltage [gU]\n - gridFrequency [gF]\n - pvPower [gP]\n - "
|
||||||
|
"todayProduction [tdP]\n - totalProduction [ttP]\n - temperature [t]\n - operatingStatus [oS]\n - alarmCode [aC]\n - alarmCount [aCnt]\n - linkStatus [lS]"};
|
||||||
hoymilesClient.add_option<std::vector<std::string>>("-P,--parameters", parametersToGet, parametersToGetHelp)->delimiter(',')->group("Parameters");
|
hoymilesClient.add_option<std::vector<std::string>>("-P,--parameters", parametersToGet, parametersToGetHelp)->delimiter(',')->group("Parameters");
|
||||||
|
|
||||||
bool allParameters = false;
|
bool allParameters = false;
|
||||||
|
|
@ -44,9 +47,9 @@ int main(int argc, char **argv) {
|
||||||
std::string shortNamesHelp{"Print short parameter names"};
|
std::string shortNamesHelp{"Print short parameter names"};
|
||||||
hoymilesClient.add_flag<bool>("-s,--short", shortNames, shortNamesHelp)->group("Parameters");
|
hoymilesClient.add_flag<bool>("-s,--short", shortNames, shortNamesHelp)->group("Parameters");
|
||||||
|
|
||||||
std::vector<long long> microinvertersToGet{};
|
std::vector<long long> microinvertersToChoose{};
|
||||||
std::string microinvertersToGetHelp{"List of microinverters to fetch, delimited by ','; if omitted, all are fetched"};
|
std::string microinvertersToChooseHelp{"List of microinverters to work on, delimited by ','; if omitted, all are selected"};
|
||||||
hoymilesClient.add_option<std::vector<long long>>("-m,--microinverters", microinvertersToGet, microinvertersToGetHelp)->delimiter(',')->group("Microinverters");
|
hoymilesClient.add_option<std::vector<long long>>("-m,--microinverters", microinvertersToChoose, microinvertersToChooseHelp)->delimiter(',')->group("Microinverters");
|
||||||
|
|
||||||
bool microinvertersGetTodayProduction{false};
|
bool microinvertersGetTodayProduction{false};
|
||||||
std::string microinvertersGetTodayProductionHelp{"Show today production for microinverters"};
|
std::string microinvertersGetTodayProductionHelp{"Show today production for microinverters"};
|
||||||
|
|
@ -60,6 +63,17 @@ int main(int argc, char **argv) {
|
||||||
std::string ignoreNotConnectedHelp{"Ignore conn_error"};
|
std::string ignoreNotConnectedHelp{"Ignore conn_error"};
|
||||||
hoymilesClient.add_flag<bool>("-I,--ignore_conn_error", ignoreNotConnected, ignoreNotConnectedHelp)->group("Debug");
|
hoymilesClient.add_flag<bool>("-I,--ignore_conn_error", ignoreNotConnected, ignoreNotConnectedHelp)->group("Debug");
|
||||||
|
|
||||||
|
bool writeMode = false;
|
||||||
|
std::string writeModeHelp{"Write instead of read"};
|
||||||
|
hoymilesClient.add_flag<bool>("-w,--write", writeMode, writeModeHelp)->group("Write");
|
||||||
|
|
||||||
|
uint16_t writeValue;
|
||||||
|
std::string writeValueHelp{"Value to write"};
|
||||||
|
hoymilesClient.add_option<uint16_t>("-V,--value", writeValue, writeModeHelp)->group("Write")->needs(hoymilesClient.get_option("-w"));
|
||||||
|
|
||||||
|
std::string writeStatusName{};
|
||||||
|
std::string writeStatusNameHelp{"Status to write"};
|
||||||
|
hoymilesClient.add_option<std::string>("-S,--status", writeStatusName, writeStatusName)->group("Write")->needs(hoymilesClient.get_option("-w"));
|
||||||
|
|
||||||
try {
|
try {
|
||||||
hoymilesClient.parse(argc, argv);
|
hoymilesClient.parse(argc, argv);
|
||||||
|
|
@ -72,20 +86,35 @@ int main(int argc, char **argv) {
|
||||||
Dtu dtu{ipAddress.c_str(), port};
|
Dtu dtu{ipAddress.c_str(), port};
|
||||||
auto endTime = std::chrono::high_resolution_clock::now();
|
auto endTime = std::chrono::high_resolution_clock::now();
|
||||||
std::cout << "DTU construction time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
std::cout << "DTU construction time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
||||||
|
std::cout << std::endl << std::endl;
|
||||||
|
|
||||||
|
while (!writeMode && (!dtu.empty() && ((dtu.isConnected() || ignoreNotConnected) && (!parametersToGet.empty() || allParameters)))) {
|
||||||
|
time_t now = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now());
|
||||||
|
|
||||||
while ((dtu.isConnected() || ignoreNotConnected) && (!parametersToGet.empty() || allParameters)) {
|
|
||||||
startTime = std::chrono::high_resolution_clock::now();
|
startTime = std::chrono::high_resolution_clock::now();
|
||||||
dtu.updateMicroinverters(parametersToGet, allParameters, microinvertersToGet);
|
dtu.updateMicroinverters(parametersToGet, allParameters, microinvertersToChoose);
|
||||||
endTime = std::chrono::high_resolution_clock::now();
|
endTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
std::cout << "Pass time: " << std::put_time(localtime(&now), "%F %T") << std::endl;
|
||||||
std::cout << "DTU update time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
std::cout << "DTU update time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
||||||
|
|
||||||
dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToGet, shortNames, microinvertersGetTodayProduction, microinvertersGetTotalProduction);
|
dtu.printMicroinverters(parametersToGet, allParameters, microinvertersToChoose, shortNames, microinvertersGetTodayProduction, microinvertersGetTotalProduction);
|
||||||
std::cout << std::endl;
|
std::cout << std::endl;
|
||||||
}
|
}
|
||||||
// if(dtu.modbusError()) {
|
// if(dtu.modbusError()) {
|
||||||
// std::cerr << dtu.modbusErrorMessage() << std::endl;
|
// std::cerr << dtu.modbusErrorMessage() << std::endl;
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
if(writeMode) {
|
||||||
|
std::cout << "Starting DTU write" << std::endl;
|
||||||
|
|
||||||
|
startTime = std::chrono::high_resolution_clock::now();
|
||||||
|
dtu.setStatusMicroinverters(writeValue, writeStatusName, microinvertersToChoose);
|
||||||
|
endTime = std::chrono::high_resolution_clock::now();
|
||||||
|
|
||||||
|
std::cout << "DTU write time: " << std::chrono::duration_cast<std::chrono::milliseconds>(endTime - startTime).count() << "ms" << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue