hoymilesClient/inc/hoymiles.h

132 lines
2.2 KiB
C
Raw Normal View History

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