12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- #pragma once
- #include "ModbusRegister.h"
- #include <optional>
- #include <vector>
- #include <memory>
- class ModbusInterface;
-
- enum class Access {
- //Access Permission of a given MODBUS Parameter
- R,
- W,
- RW,
- CMD
- };
-
- struct ParameterSpecification {
- ModbusRegister description;
- Category cat;
- uint16_t address;
- uint8_t length;
- Access access;
- std::vector<uint16_t> readedBytes;
- bool error = true;
- std::unique_ptr<ModbusInterface>& connection;
-
- ParameterSpecification(ModbusRegister d, Category c, uint16_t ad, uint8_t l, std::unique_ptr<ModbusInterface>& i, Access ac) :
- description(d), cat(c), address(ad), length(l), access(ac), connection(i) {}
-
- bool isReadable(){ return access == Access::R || access == Access::RW;}
- bool isWritable(){ return access == Access::W || access == Access::RW || access == Access::CMD;}
- };
-
-
- template<typename S>
- class ParameterInterface
- {
- protected:
- S currentParam{};
-
- const ModbusRegister valueDescription;
- const uint16_t modbusAddress;
- const Access access;
- const Category cat = Category::NONE;
-
- public:
- ParameterInterface(const ModbusRegister description, const unsigned short address, const Access access) : valueDescription(description), modbusAddress(address), access(access) {};
- ParameterInterface(const ModbusRegister description, const unsigned short address, const Access access, const Category _cat) : valueDescription(description), modbusAddress(address), access(access), cat(_cat) {};
- virtual ~ParameterInterface(){}
-
- bool isReadable() { return (access == Access::R || access == Access::RW); }
- S getParam()const { return currentParam; };
- uint16_t getModbusAddress() { return modbusAddress; }
- ModbusRegister getValueDescription() { return valueDescription; };
- Category getCategory()const {return cat;}
- virtual uint8_t getSize() const = 0;
-
- ParameterSpecification getSpecification(std::unique_ptr<ModbusInterface>& connection) const { return ParameterSpecification(valueDescription, cat, modbusAddress, getSize(), connection, access); }
- };
|