Initial release commit

This commit is contained in:
TraYali 2024-03-20 19:08:13 +01:00
commit 0e25af7ef8
15 changed files with 12511 additions and 0 deletions

39
inc/hoymiles/dtu.h Normal file
View file

@ -0,0 +1,39 @@
#ifndef DTU_H
#define DTU_H
#include <vector>
#include <memory>
#include <string>
#include "microinverter.h"
#include "modbus.h"
class Dtu {
private:
std::shared_ptr<class modbus> modbus;
std::vector<Microinverter> microinverters;
bool connected;
void populateMicroinverters();
std::pair<bool, Microinverter*> getMicroinverterBySerialNumber(long long serialNumber);
public:
Dtu(const char *ip_address, int port);
bool isConnected();
// void updateMicroinverters();
void updateMicroinverters(std::vector<std::string> &parametersToGet, bool allParameters, std::vector<long long> &microinvertersToGet);
// void printMicroinverters();
void printMicroinverters(std::vector<std::string> &parametersToGet, bool allParameters, std::vector<long long> &microinvertersToGet);
~Dtu();
};
#endif

View file

@ -0,0 +1,46 @@
#ifndef MICROINVERTER_H
#define MICROINVERTER_H
#include <vector>
#include <memory>
#include <string>
// #include <mutex>
#include "port.h"
#include "modbus.h"
// struct _modbus;
// typedef _modbus modbus_t;
class Microinverter {
private:
// std::shared_ptr<modbus_t*> modbus_context;
std::shared_ptr<class modbus> modbus;
// std::mutex *modbus_context_mutex;
public:
Microinverter(
std::shared_ptr<class modbus> modbus, long long serialNumber);
long long serialNumber;
std::vector<Port> ports;
// void updatePorts();
void updatePorts(std::vector<std::string> &parametersToGet, bool allParameters);
void updatePort(int i);
Port getPort(int i);
// void printPorts();
void printPorts(std::vector<std::string> &parametersToGet, bool allParameters);
};
#endif

38
inc/hoymiles/port.h Normal file
View file

@ -0,0 +1,38 @@
#ifndef PORT_H
#define PORT_H
#include <stdint.h>
#include <string>
#include <vector>
#include "portParametersGeneric.h"
#include "modbus.h"
class Port {
private:
std::shared_ptr<class modbus> modbus;
uint16_t portStartAddress;
void populateParameters();
std::pair<std::shared_ptr<PortParameter>, bool> getParameterByName(std::string name);
void fixCurrent();
bool currentFixed;
public:
Port(std::shared_ptr<class modbus> modbus, uint16_t portStartAddress);
std::vector<std::shared_ptr<PortParameter>> parameters;
// void updateParameters();
void updateParameters(std::vector<std::string> &parametersToGet, bool allParameters);
// void printParameters();
void printParameters(std::vector<std::string> &parametersToGet, bool allParameters);
};
#endif

View file

@ -0,0 +1,87 @@
#ifndef PORTPARAMETERS_H
#define PORTPARAMETERS_H
#include "portParametersGeneric.h"
class PortParameterMicroinverterSerialNumber : public PortParameterInt {
protected:
void setValueFromRegisters(uint16_t *readArray, int registerCount);
public:
PortParameterMicroinverterSerialNumber();
};
class PortParameterPortNumber : public PortParameterInt {
private:
void setValueFromRegisters(uint16_t *readArray, int registerCount);
public:
PortParameterPortNumber();
};
class PortParameterPvVoltage : public PortParameterFloat {
public:
PortParameterPvVoltage();
};
class PortParameterPvCurrentMi : public PortParameterFloat {
public:
PortParameterPvCurrentMi();
};
class PortParameterPvCurrentHm : public PortParameterFloat {
public:
PortParameterPvCurrentHm();
};
class PortParameterGridVoltage : public PortParameterFloat {
public:
PortParameterGridVoltage();
};
class PortParameterGridFrequency : public PortParameterFloat {
public:
PortParameterGridFrequency();
};
class PortParameterPvPower : public PortParameterFloat {
public:
PortParameterPvPower();
};
class PortParameterTodayProduction : public PortParameterInt {
public:
PortParameterTodayProduction();
};
class PortParameterTotalProduction : public PortParameterInt {
public:
PortParameterTotalProduction();
};
class PortParameterTemperature : public PortParameterFloat {
public:
PortParameterTemperature();
};
class PortParameterOperatingStatus : public PortParameterInt {
public:
PortParameterOperatingStatus();
};
class PortParameterAlarmCode : public PortParameterInt {
public:
PortParameterAlarmCode();
};
class PortParameterAlarmCount : public PortParameterInt {
public:
PortParameterAlarmCount();
};
class PortParameterLinkStatus : public PortParameterInt {
public:
PortParameterLinkStatus();
};
#endif

View file

@ -0,0 +1,68 @@
#ifndef PORTPARAMETERSGENERIC_H
#define PORTPARAMETERSGENERIC_H
#include <stdint.h>
#include <string>
#include <memory>
// #include <mutex>
struct _modbus;
typedef _modbus modbus_t;
class PortParameter {
protected:
uint16_t parameterAddressOffset;
int registerSize;
virtual void setValueFromRegisters(uint16_t *readArray, int registerCount);
public:
PortParameter(std::string name, uint16_t parameterAddressOffset, int registerSize);
virtual ~PortParameter();
enum PortParameterValueType { Int, Float };
union PortParameterValue {
long long i;
float f;
};
protected:
PortParameterValueType valueType;
PortParameterValue value;
public:
std::string name;
int age;
std::pair<PortParameterValue, PortParameterValueType> getValue();
virtual std::string getOutputValue();
void updateValue(std::shared_ptr<class modbus> modubs, uint16_t portStartAddress);
};
class PortParameterFloat : public PortParameter {
protected:
int decimalPlaces;
virtual void setValueFromRegisters(uint16_t *readArray, int registerCount);
public:
PortParameterFloat(std::string name, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize);
std::string getOutputValue();
};
class PortParameterInt : public PortParameter {
protected:
virtual void setValueFromRegisters(uint16_t *readArray, int registerCount);
public:
PortParameterInt(std::string name, uint16_t parameterAddressOffset, int registerSize);
std::string getOutputValue();
};
#endif