2024-03-16 22:51:32 +01:00
|
|
|
#ifndef PORTPARAMETERSGENERIC_H
|
|
|
|
|
#define PORTPARAMETERSGENERIC_H
|
|
|
|
|
|
2024-03-20 19:55:36 +01:00
|
|
|
#include <memory>
|
2024-03-16 22:51:32 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
|
|
struct _modbus;
|
|
|
|
|
typedef _modbus modbus_t;
|
|
|
|
|
|
|
|
|
|
class PortParameter {
|
|
|
|
|
protected:
|
|
|
|
|
uint16_t parameterAddressOffset;
|
|
|
|
|
int registerSize;
|
|
|
|
|
|
2024-04-05 15:54:36 +02:00
|
|
|
std::string unit;
|
|
|
|
|
|
2024-04-05 16:48:06 +02:00
|
|
|
bool r;
|
|
|
|
|
bool w;
|
|
|
|
|
|
2024-03-16 22:51:32 +01:00
|
|
|
public:
|
2024-04-05 16:48:06 +02:00
|
|
|
PortParameter(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize);
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
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:
|
2024-03-20 19:55:36 +01:00
|
|
|
PortParameterValueType valueType;
|
2024-03-16 22:51:32 +01:00
|
|
|
PortParameterValue value;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
std::string name;
|
2024-03-20 20:17:15 +01:00
|
|
|
std::string shortName;
|
|
|
|
|
|
2024-03-28 19:44:54 +01:00
|
|
|
// int age;
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
std::pair<PortParameterValue, PortParameterValueType> getValue();
|
|
|
|
|
|
2024-04-06 00:32:49 +02:00
|
|
|
PortParameter& writeValue(uint16_t value, class modbus& modbus, int portStartAddress);
|
|
|
|
|
|
2024-03-16 22:51:32 +01:00
|
|
|
virtual std::string getOutputValue();
|
|
|
|
|
|
2024-04-06 00:32:49 +02:00
|
|
|
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
2024-03-28 19:44:54 +01:00
|
|
|
|
|
|
|
|
// void updateValue(std::shared_ptr<class modbus> modubs, uint16_t portStartAddress);
|
2024-03-16 22:51:32 +01:00
|
|
|
};
|
|
|
|
|
|
2024-03-20 20:17:15 +01:00
|
|
|
class PortParameterFloat : public PortParameter {
|
2024-03-16 22:51:32 +01:00
|
|
|
protected:
|
2024-03-20 19:55:36 +01:00
|
|
|
int decimalPlaces;
|
2024-03-16 22:51:32 +01:00
|
|
|
|
2024-03-20 19:55:36 +01:00
|
|
|
public:
|
2024-04-05 16:48:06 +02:00
|
|
|
PortParameterFloat(std::string name, std::string shortName, std::string unit, bool r, bool w, int decimalPlaces, uint16_t parameterAddressOffset, int registerSize);
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
std::string getOutputValue();
|
2024-03-28 19:44:54 +01:00
|
|
|
|
2024-04-06 00:32:49 +02:00
|
|
|
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
2024-03-16 22:51:32 +01:00
|
|
|
};
|
|
|
|
|
|
2024-03-20 20:17:15 +01:00
|
|
|
class PortParameterInt : public PortParameter {
|
2024-03-20 19:55:36 +01:00
|
|
|
protected:
|
2024-03-16 22:51:32 +01:00
|
|
|
|
2024-03-20 19:55:36 +01:00
|
|
|
public:
|
2024-04-05 16:48:06 +02:00
|
|
|
PortParameterInt(std::string name, std::string shortName, std::string unit, bool r, bool w, uint16_t parameterAddressOffset, int registerSize);
|
2024-03-16 22:51:32 +01:00
|
|
|
|
|
|
|
|
std::string getOutputValue();
|
2024-03-28 19:44:54 +01:00
|
|
|
|
2024-04-06 00:32:49 +02:00
|
|
|
virtual void getValueFromRegisters(uint16_t *registers, int addressOffset);
|
2024-03-16 22:51:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|