2024-03-13 00:18:10 +01:00
|
|
|
#ifndef HOYMILES_H
|
|
|
|
|
#define HOYMILES_H
|
|
|
|
|
|
2024-03-13 16:54:03 +01:00
|
|
|
#include <stdint.h>
|
2024-03-15 09:26:41 +01:00
|
|
|
#include <string>
|
2024-03-15 11:46:44 +01:00
|
|
|
#include <vector>
|
|
|
|
|
#include <memory>
|
2024-03-13 16:54:03 +01:00
|
|
|
|
2024-03-13 00:18:10 +01:00
|
|
|
struct _modbus;
|
|
|
|
|
typedef _modbus modbus_t;
|
|
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
class PortParameter {
|
|
|
|
|
protected:
|
|
|
|
|
uint16_t addressOffset;
|
2024-03-13 16:54:03 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
int registerSize;
|
2024-03-13 00:18:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
void setValue(uint16_t *readArray, int registerCount);
|
2024-03-13 00:18:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
public:
|
|
|
|
|
PortParameter(std::string name, uint16_t addressOffset, int registerSize);
|
2024-03-13 00:18:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
std::string name;
|
|
|
|
|
int age;
|
|
|
|
|
int value;
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
virtual void updateValue(modbus_t *modbus_context, uint16_t portStartAddress);
|
2024-03-15 09:26:41 +01:00
|
|
|
};
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
class PortParameterSerialNumber : public PortParameter {
|
|
|
|
|
private:
|
|
|
|
|
void setValue(uint16_t *readArray, int registerCount);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PortParameterSerialNumber();
|
|
|
|
|
};
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
class PortParameterFloat : public PortParameter {
|
|
|
|
|
private:
|
|
|
|
|
int decimalPlaces;
|
|
|
|
|
|
|
|
|
|
void setValue(uint16_t *readArray, int registerCount);
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PortParameterFloat(std::string name, uint16_t addressOffset, int registerSize, int decimalPlaces);
|
|
|
|
|
|
|
|
|
|
float value;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class Port {
|
|
|
|
|
private:
|
|
|
|
|
modbus_t *modbus_context;
|
|
|
|
|
uint16_t portStartAddress;
|
|
|
|
|
|
|
|
|
|
std::vector<std::shared_ptr<PortParameter>> parameters;
|
|
|
|
|
|
|
|
|
|
void populateParameters();
|
2024-03-13 16:54:03 +01:00
|
|
|
|
|
|
|
|
public:
|
2024-03-15 11:46:44 +01:00
|
|
|
Port(modbus_t *modbus_context, uint16_t portStartAddress);
|
2024-03-13 16:54:03 +01:00
|
|
|
|
2024-03-15 09:26:41 +01:00
|
|
|
void updateParameters();
|
2024-03-15 11:46:44 +01:00
|
|
|
};
|
2024-03-13 16:54:03 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
class Microinverter {
|
|
|
|
|
private:
|
|
|
|
|
modbus_t *modbus_context;
|
2024-03-13 16:54:03 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
std::vector<Port> ports;
|
2024-03-13 16:54:03 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
void populatePorts();
|
2024-03-13 16:54:03 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
public:
|
|
|
|
|
Microinverter(modbus_t *modbus_t);
|
|
|
|
|
|
|
|
|
|
void updatePorts();
|
|
|
|
|
|
|
|
|
|
void updatePort(int i);
|
|
|
|
|
|
|
|
|
|
Port getPort(int i);
|
2024-03-13 16:54:03 +01:00
|
|
|
};
|
|
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
class Dtu {
|
|
|
|
|
private:
|
|
|
|
|
modbus_t *modbus_context;
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
std::vector<Microinverter> microinverters;
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
void populateMicroinverters();
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
public:
|
|
|
|
|
Dtu(const char *ip_address, int port);
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
void updateMicroinverters();
|
2024-03-13 19:51:10 +01:00
|
|
|
|
2024-03-15 11:46:44 +01:00
|
|
|
~Dtu();
|
2024-03-13 19:51:10 +01:00
|
|
|
};
|
|
|
|
|
|
2024-03-13 00:18:10 +01:00
|
|
|
#endif
|