knx
ETS configurable knx-stack
callback_property.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "property.h"
4 
5 class InterfaceObject;
6 
7 template <class T> class CallbackProperty : public Property
8 {
9  public:
10  CallbackProperty(T* io, PropertyID id, bool writeEnable, PropertyDataType type, uint16_t maxElements,
11  uint8_t access, uint8_t (*readCallback)(T*, uint16_t, uint8_t, uint8_t*),
12  uint8_t (*writeCallback)(T*, uint16_t, uint8_t, const uint8_t*))
13  : Property(id, writeEnable, type, maxElements, access),
14  _interfaceObject(io), _readCallback(readCallback), _writeCallback(writeCallback)
15  {}
16  CallbackProperty(T* io, PropertyID id, bool writeEnable, PropertyDataType type, uint16_t maxElements,
17  uint8_t access, uint8_t (*readCallback)(T*, uint16_t, uint8_t, uint8_t*))
18  : Property(id, writeEnable, type, maxElements, access), _interfaceObject(io), _readCallback(readCallback)
19  {}
20 
21  uint8_t read(uint16_t start, uint8_t count, uint8_t* data) const override
22  {
23  if (count == 0 || _readCallback == nullptr || start > _maxElements || start + count > _maxElements + 1)
24  return 0;
25 
26  return _readCallback(_interfaceObject, start, count, data);
27  }
28  uint8_t write(uint16_t start, uint8_t count, const uint8_t* data) override
29  {
30  if (count == 0 || start > _maxElements || start + count > _maxElements + 1 || _writeCallback == nullptr)
31  return 0;
32 
33  return _writeCallback(_interfaceObject, start, count, data);
34  }
35  private:
36  T* _interfaceObject = nullptr;
37  uint8_t (*_readCallback)(T*, uint16_t, uint8_t, uint8_t*) = nullptr;
38  uint8_t (*_writeCallback)(T*, uint16_t, uint8_t, const uint8_t*) = nullptr;
39 };
uint8_t write(uint16_t start, uint8_t count, const uint8_t *data) override
CallbackProperty(T *io, PropertyID id, bool writeEnable, PropertyDataType type, uint16_t maxElements, uint8_t access, uint8_t(*readCallback)(T *, uint16_t, uint8_t, uint8_t *))
uint8_t read(uint16_t start, uint8_t count, uint8_t *data) const override
CallbackProperty(T *io, PropertyID id, bool writeEnable, PropertyDataType type, uint16_t maxElements, uint8_t access, uint8_t(*readCallback)(T *, uint16_t, uint8_t, uint8_t *), uint8_t(*writeCallback)(T *, uint16_t, uint8_t, const uint8_t *))
This class represents and interface object.
uint16_t _maxElements
Definition: property.h:290
PropertyID
Definition: property.h:70
PropertyDataType
The data type of a property.
Definition: property.h:17