2024-03-16 22:51:32 +01:00
|
|
|
#ifndef PORTPARAMETERSGENERIC_H
|
|
|
|
|
#define PORTPARAMETERSGENERIC_H
|
|
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string>
|
2024-03-17 21:33:21 +01:00
|
|
|
#include <memory>
|
2024-03-19 13:02:41 +01:00
|
|
|
// #include <mutex>
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
struct _modbus;
|
|
|
|
|
typedef _modbus modbus_t;
|
|
|
|
|
|
|
|
|
|
class PortParameter {
|
|
|
|
|
protected:
|
|
|
|
|
uint16_t parameterAddressOffset;
|
|
|
|
|
int registerSize;
|
|
|
|
|
|
2024-03-18 13:44:25 +01:00
|
|
|
virtual void setValueFromRegisters(uint16_t *readArray, int registerCount);
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PortParameter(std::string name, uint16_t parameterAddressOffset, int registerSize);
|
|
|
|
|
|
|
|
|
|
virtual ~PortParameter();
|
|
|
|
|
|
|
|
|
|
enum PortParameterValueType { Int, Float };
|
|
|
|
|
|
|
|
|
|
union PortParameterValue {
|
2024-03-20 16:39:25 +01:00
|
|
|
long long i;
|
2024-03-16 22:51:32 +01:00
|
|
|
float f;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
PortParameterValueType valueType;
|
|
|
|
|
PortParameterValue value;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::string name;
|
|
|
|
|
int age;
|
|
|
|
|
|
|
|
|
|
std::pair<PortParameterValue, PortParameterValueType> getValue();
|
|
|
|
|
|
|
|
|
|
virtual std::string getOutputValue();
|
|
|
|
|
|
2024-03-20 11:28:43 +01:00
|
|
|
void updateValue(std::shared_ptr<class modbus> modubs, uint16_t portStartAddress);
|
2024-03-16 22:51:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PortParameterFloat : virtual public PortParameter {
|
|
|
|
|
protected:
|
|
|
|
|
int decimalPlaces;
|
|
|
|
|
|
2024-03-18 13:44:25 +01:00
|
|
|
virtual void setValueFromRegisters(uint16_t *readArray, int registerCount);
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PortParameterFloat(std::string name, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize);
|
|
|
|
|
|
|
|
|
|
std::string getOutputValue();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class PortParameterInt : virtual public PortParameter {
|
|
|
|
|
protected:
|
2024-03-18 13:44:25 +01:00
|
|
|
virtual void setValueFromRegisters(uint16_t *readArray, int registerCount);
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
PortParameterInt(std::string name, uint16_t parameterAddressOffset, int registerSize);
|
|
|
|
|
|
|
|
|
|
std::string getOutputValue();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|