Digitalisierte Elektroverteilung zur permanenten Verbraucherüberwachung
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ParameterInterface.h 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #pragma once
  2. #include "ModbusRegister.h"
  3. #include <optional>
  4. #include <vector>
  5. #include <memory>
  6. class ModbusInterface;
  7. enum class Access {
  8. //Access Permission of a given MODBUS Parameter
  9. R,
  10. W,
  11. RW,
  12. CMD
  13. };
  14. struct ParameterSpecification {
  15. ModbusRegister description;
  16. Category cat;
  17. uint16_t address;
  18. uint8_t length;
  19. Access access;
  20. std::vector<uint16_t> readedBytes;
  21. bool error = true;
  22. std::unique_ptr<ModbusInterface>& connection;
  23. ParameterSpecification(ModbusRegister d, Category c, uint16_t ad, uint8_t l, std::unique_ptr<ModbusInterface>& i, Access ac) :
  24. description(d), cat(c), address(ad), length(l), access(ac), connection(i) {}
  25. bool isReadable(){ return access == Access::R || access == Access::RW;}
  26. bool isWritable(){ return access == Access::W || access == Access::RW || access == Access::CMD;}
  27. };
  28. template<typename S>
  29. class ParameterInterface
  30. {
  31. protected:
  32. S currentParam{};
  33. const ModbusRegister valueDescription;
  34. const uint16_t modbusAddress;
  35. const Access access;
  36. const Category cat = Category::NONE;
  37. public:
  38. ParameterInterface(const ModbusRegister description, const unsigned short address, const Access access) : valueDescription(description), modbusAddress(address), access(access) {};
  39. ParameterInterface(const ModbusRegister description, const unsigned short address, const Access access, const Category _cat) : valueDescription(description), modbusAddress(address), access(access), cat(_cat) {};
  40. virtual ~ParameterInterface(){}
  41. bool isReadable() { return (access == Access::R || access == Access::RW); }
  42. S getParam()const { return currentParam; };
  43. uint16_t getModbusAddress() { return modbusAddress; }
  44. ModbusRegister getValueDescription() { return valueDescription; };
  45. Category getCategory()const {return cat;}
  46. virtual uint8_t getSize() const = 0;
  47. ParameterSpecification getSpecification(std::unique_ptr<ModbusInterface>& connection) const { return ParameterSpecification(valueDescription, cat, modbusAddress, getSize(), connection, access); }
  48. };