Compare commits
No commits in common. "c24e6c7d066c06be2b9115919f044350eb5d9276" and "582b1bcc93dabf6249785ce3b2e919eea0167c91" have entirely different histories.
c24e6c7d06
...
582b1bcc93
6 changed files with 14 additions and 149 deletions
|
|
@ -14,10 +14,6 @@ class Dtu {
|
|||
|
||||
std::vector<Microinverter> microinverters;
|
||||
|
||||
Port dtuPort;
|
||||
|
||||
int rtuId;
|
||||
|
||||
bool connected;
|
||||
|
||||
void populateMicroinverters();
|
||||
|
|
@ -25,8 +21,6 @@ class Dtu {
|
|||
public:
|
||||
Dtu(const char *address, int id, bool rtu, bool tcp);
|
||||
|
||||
Dtu(modbus_t *modbus, int id);
|
||||
|
||||
std::pair<Microinverter *, bool> getMicroinverterBySerialNumber(long long serialNumber);
|
||||
|
||||
bool isConnected();
|
||||
|
|
@ -41,15 +35,6 @@ class Dtu {
|
|||
|
||||
void listOfMicroinverters();
|
||||
|
||||
float getCurrentPower();
|
||||
|
||||
int getCurrentOnOff();
|
||||
|
||||
void turnOffMicroinverters();
|
||||
void turnOnMicroinverters();
|
||||
|
||||
void limitMicroinverters(uint16_t limit);
|
||||
|
||||
~Dtu();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ class Microinverter {
|
|||
private:
|
||||
modbus_t *modbus;
|
||||
|
||||
// Sunspec sunspec;
|
||||
Sunspec sunspec;
|
||||
|
||||
int startAddress;
|
||||
|
||||
|
|
@ -43,10 +43,6 @@ class Microinverter {
|
|||
void setStatus(std::vector<std::pair<int, uint16_t>> portsToSet, std::string statusName);
|
||||
|
||||
void setStatusWholeMicroinverter(uint16_t value, std::string statusName);
|
||||
|
||||
float getCurrentPower();
|
||||
|
||||
int getCurrentOnOff();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
@ -11,8 +11,7 @@
|
|||
|
||||
#include "portParameters.h"
|
||||
|
||||
Dtu::Dtu(const char *address, int id, bool rtu, bool tcp) : dtuPort(0) {
|
||||
dtuPort.statusPortStartAddress = 0xd000;
|
||||
Dtu::Dtu(const char *address, int id, bool rtu, bool tcp) {
|
||||
if (tcp) {
|
||||
this->modbus = modbus_new_tcp(address, id);
|
||||
}
|
||||
|
|
@ -23,7 +22,7 @@ Dtu::Dtu(const char *address, int id, bool rtu, bool tcp) : dtuPort(0) {
|
|||
|
||||
this->connected = false;
|
||||
if (modbus_connect(this->modbus) == -1) {
|
||||
std::cerr << "[" << id << "] NOT_CONNECTED" << std::endl;
|
||||
std::cerr << "NOT CONNECTED" << std::endl;
|
||||
} else {
|
||||
this->connected = true;
|
||||
if (rtu) {
|
||||
|
|
@ -33,24 +32,6 @@ Dtu::Dtu(const char *address, int id, bool rtu, bool tcp) : dtuPort(0) {
|
|||
}
|
||||
}
|
||||
|
||||
Dtu::Dtu(modbus_t *modbus, int id = -1) : dtuPort(0) {
|
||||
dtuPort.statusPortStartAddress = 0xd000;
|
||||
|
||||
this->modbus = modbus;
|
||||
this->rtuId = id;
|
||||
|
||||
this->connected = false;
|
||||
if (modbus_connect(this->modbus) == -1) {
|
||||
std::cerr << "[" << id << "] NOT_CONNECTED" << std::endl;
|
||||
} else {
|
||||
this->connected = true;
|
||||
if (id != -1) {
|
||||
modbus_set_slave(this->modbus, rtuId);
|
||||
}
|
||||
this->populateMicroinverters();
|
||||
}
|
||||
}
|
||||
|
||||
bool Dtu::isConnected() { return this->connected; }
|
||||
|
||||
Dtu::~Dtu() {
|
||||
|
|
@ -59,32 +40,14 @@ Dtu::~Dtu() {
|
|||
}
|
||||
|
||||
void Dtu::populateMicroinverters() {
|
||||
if(this->rtuId != -1) {
|
||||
modbus_set_slave(this->modbus, this->rtuId);
|
||||
}
|
||||
|
||||
int portStartAddress = 0x4000;
|
||||
int registersToRead{19};
|
||||
uint16_t registers[registersToRead];
|
||||
|
||||
bool lastSuccesful{true};
|
||||
|
||||
int addressToSkip{-1};
|
||||
uint16_t registers[19];
|
||||
|
||||
while (portStartAddress <= (0x4000 + (0x0019 * 99))) {
|
||||
int registerCount{-1};
|
||||
int timesTried{0};
|
||||
while (((timesTried < 3) && (lastSuccesful && registerCount == -1) && portStartAddress != addressToSkip)) {
|
||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, registersToRead, registers);
|
||||
timesTried++;
|
||||
}
|
||||
int registerCount;
|
||||
registerCount = modbus_read_registers(this->modbus, portStartAddress, 19, registers);
|
||||
portStartAddress += 0x0019;
|
||||
if ((registers[0] == 12 && registerCount != -1) && portStartAddress != addressToSkip) {
|
||||
if (!lastSuccesful) {
|
||||
addressToSkip = portStartAddress;
|
||||
portStartAddress -= 2 * 0x0019;
|
||||
}
|
||||
lastSuccesful = true;
|
||||
if (registers[0] == 12) {
|
||||
Port port{portStartAddress};
|
||||
port.setParametersFromMicroinverterArray(registers, 0);
|
||||
|
||||
|
|
@ -93,23 +56,10 @@ void Dtu::populateMicroinverters() {
|
|||
this->microinverters.push_back(microinverter);
|
||||
}
|
||||
|
||||
Microinverter *microinverter = this->getMicroinverterBySerialNumber(port.getParameterByName("microinverterSerialNumber").first.get()->getValue().first.i).first;
|
||||
std::vector<Port>::iterator portsIterator = microinverter->ports.begin();
|
||||
bool valueExists{false};
|
||||
while (portsIterator != microinverter->ports.end() && !valueExists) {
|
||||
if (portsIterator->getParameterByName("portNumber").first.get()->getValue().first.i == port.getParameterByName("portNumber").first.get()->getValue().first.i) {
|
||||
valueExists = true;
|
||||
}
|
||||
portsIterator++;
|
||||
}
|
||||
if (!valueExists) {
|
||||
microinverter->ports.push_back(port);
|
||||
}
|
||||
} else {
|
||||
lastSuccesful = false;
|
||||
this->getMicroinverterBySerialNumber(port.getParameterByName("microinverterSerialNumber").first.get()->getValue().first.i).first->ports.push_back(port);
|
||||
}
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(20));
|
||||
std::this_thread::sleep_for(std::chrono::milliseconds(10));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -126,9 +76,6 @@ std::pair<Microinverter *, bool> Dtu::getMicroinverterBySerialNumber(long long s
|
|||
}
|
||||
|
||||
void Dtu::updateMicroinverters(std::vector<std::string> ¶metersToGet, bool allParameters, std::vector<long long> µinvertersToGet) {
|
||||
if(this->rtuId != -1) {
|
||||
modbus_set_slave(this->modbus, this->rtuId);
|
||||
}
|
||||
if (microinvertersToGet.empty()) {
|
||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||
while (microinvertersIterator != this->microinverters.end()) {
|
||||
|
|
@ -209,38 +156,3 @@ void Dtu::listOfMicroinverters() {
|
|||
microinvertersIterator++;
|
||||
}
|
||||
}
|
||||
|
||||
float Dtu::getCurrentPower() {
|
||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||
float currentPower{0};
|
||||
while (microinvertersIterator != this->microinverters.end()) {
|
||||
currentPower += microinvertersIterator->getCurrentPower();
|
||||
microinvertersIterator++;
|
||||
}
|
||||
return currentPower;
|
||||
}
|
||||
|
||||
int Dtu::getCurrentOnOff() {
|
||||
if(this->microinverters.size() == 0) {
|
||||
return 0;
|
||||
}
|
||||
std::vector<Microinverter>::iterator microinvertersIterator = this->microinverters.begin();
|
||||
int currentOn{0};
|
||||
while(microinvertersIterator != this->microinverters.end()) {
|
||||
currentOn += microinvertersIterator->getCurrentOnOff();
|
||||
microinvertersIterator++;
|
||||
}
|
||||
float balance = currentOn / this->microinverters.size();
|
||||
if(balance >= 0.5) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Dtu::turnOffMicroinverters() { this->dtuPort.getStatusByName("onOff").first.get()->writeValue(0, this->modbus, this->dtuPort.statusPortStartAddress); }
|
||||
|
||||
void Dtu::turnOnMicroinverters() { this->dtuPort.getStatusByName("onOff").first.get()->writeValue(1, this->modbus, this->dtuPort.statusPortStartAddress); }
|
||||
|
||||
void Dtu::limitMicroinverters(uint16_t limit) { this->dtuPort.getStatusByName("limitActivePower").first.get()->writeValue(limit, this->modbus, this->dtuPort.statusPortStartAddress); }
|
||||
|
|
@ -8,7 +8,7 @@
|
|||
#include "port.h"
|
||||
#include "sunspec.h"
|
||||
|
||||
Microinverter::Microinverter(modbus_t *modbus, int startAddress, long long serialNumber) {
|
||||
Microinverter::Microinverter(modbus_t *modbus, int startAddress, long long serialNumber) : sunspec(40000, modbus) {
|
||||
this->modbus = modbus;
|
||||
this->startAddress = startAddress;
|
||||
this->serialNumber = serialNumber;
|
||||
|
|
@ -137,29 +137,3 @@ void Microinverter::setStatusWholeMicroinverter(uint16_t value, std::string stat
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
float Microinverter::getCurrentPower() {
|
||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||
float currentPower{0};
|
||||
while(portsIterator != this->ports.end()) {
|
||||
currentPower += portsIterator->getParameterByName("pvPower").first.get()->getValue().first.f;
|
||||
portsIterator++;
|
||||
}
|
||||
return currentPower;
|
||||
}
|
||||
|
||||
int Microinverter::getCurrentOnOff() {
|
||||
std::vector<Port>::iterator portsIterator = this->ports.begin();
|
||||
int currentOn{0};
|
||||
while(portsIterator != this->ports.end()) {
|
||||
currentOn += portsIterator->getStatusByName("onOff").first.get()->getValue().first.i;
|
||||
portsIterator++;
|
||||
}
|
||||
float balance = currentOn / this->ports.size();
|
||||
if(balance >= 0.5) {
|
||||
return 1;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
@ -16,10 +16,10 @@ Sunspec::Sunspec(int address, modbus_t *modbus) {
|
|||
}
|
||||
|
||||
void Sunspec::setValues() {
|
||||
uint16_t registers[2];
|
||||
uint16_t registers[70];
|
||||
|
||||
int registerCount;
|
||||
registerCount = modbus_read_registers(this->modbus, this->sunspecAddress, 2, registers);
|
||||
registerCount = modbus_read_registers(this->modbus, this->sunspecAddress, 70, registers);
|
||||
|
||||
std::vector<std::shared_ptr<SunspecParameter>>::iterator parametersIterator = this->parameters.begin();
|
||||
while(parametersIterator != this->parameters.end()) {
|
||||
|
|
|
|||
|
|
@ -10,9 +10,7 @@ SunspecParameter::SunspecParameter(std::string name, int registerAddressOffset,
|
|||
|
||||
void SunspecParameter::getValueFromRegisters(uint16_t *registers, int addressOffset) {}
|
||||
|
||||
std::pair<SunspecParameter::SunspecValue, SunspecParameter::SunspecValueType> SunspecParameter::getValue() {
|
||||
return {this->value, this->valueType};
|
||||
}
|
||||
std::pair<SunspecParameter::SunspecValue, SunspecParameter::SunspecValueType> SunspecParameter::getValue() {}
|
||||
|
||||
SunspecParameterString32::SunspecParameterString32(std::string name, int registerAddressOffset, int registerSize) : SunspecParameter(name, registerAddressOffset, registerSize) {}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue