hoymilesClient/inc/hoymiles/portParameters/portParametersGeneric.h

77 lines
1.8 KiB
C
Raw Normal View History

#ifndef PORTPARAMETERSGENERIC_H
#define PORTPARAMETERSGENERIC_H
2024-03-20 19:55:36 +01:00
#include <memory>
#include <stdint.h>
#include <string>
struct _modbus;
typedef _modbus modbus_t;
class PortParameter {
protected:
uint16_t parameterAddressOffset;
int registerSize;
std::string unit;
bool r;
bool w;
public:
PortParameter(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize);
virtual ~PortParameter();
enum PortParameterValueType { Int, Float };
union PortParameterValue {
2024-03-20 16:39:25 +01:00
long long i;
float f;
};
protected:
2024-03-20 19:55:36 +01:00
PortParameterValueType valueType;
PortParameterValue value;
public:
std::string name;
2024-03-20 20:17:15 +01:00
std::string shortName;
// int age;
std::pair<PortParameterValue, PortParameterValueType> getValue();
2024-04-06 00:32:49 +02:00
PortParameter& writeValue(uint16_t value, class modbus& modbus, int portStartAddress);
virtual std::string getOutputValue();
2024-04-06 00:32:49 +02:00
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
// void updateValue(std::shared_ptr<class modbus> modubs, uint16_t portStartAddress);
};
2024-03-20 20:17:15 +01:00
class PortParameterFloat : public PortParameter {
protected:
2024-03-20 19:55:36 +01:00
int decimalPlaces;
2024-03-20 19:55:36 +01:00
public:
PortParameterFloat(std::string name, std::string shortName, std::string unit, bool r, bool w, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize);
std::string getOutputValue();
2024-04-06 00:32:49 +02:00
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
};
2024-03-20 20:17:15 +01:00
class PortParameterInt : public PortParameter {
2024-03-20 19:55:36 +01:00
protected:
2024-03-20 19:55:36 +01:00
public:
PortParameterInt(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize);
std::string getOutputValue();
2024-04-06 00:32:49 +02:00
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
};
#endif