knx
ETS configurable knx-stack
group_object.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <stddef.h>
4 #include <stdint.h>
5 #include "knx_types.h"
6 #include "dptconvert.h"
7 
9 
10 enum ComFlag : uint8_t
11 {
12  Updated = 0,
16  Ok = 4,
17  Error = 5,
18  Uninitialized = 6
19 };
20 
21 class GroupObject;
22 
23 #ifndef HAS_FUNCTIONAL
24  #if defined(__linux__) || defined(ARDUINO_ARCH_ESP32) || defined(ESP_PLATFORM) || defined(ARDUINO_ARCH_STM32) || defined (ARDUINO_ARCH_SAMD) || defined (ARDUINO_ARCH_RP2040) || defined(LIBRETINY)
25  #define HAS_FUNCTIONAL 1
26  #else
27  #define HAS_FUNCTIONAL 0
28  #endif
29 #endif
30 
31 #if HAS_FUNCTIONAL
32  #include <functional>
33  typedef std::function<void(GroupObject&)> GroupObjectUpdatedHandler;
34 #else
35  typedef void (*GroupObjectUpdatedHandler)(GroupObject& go);
36 #endif
37 
42 {
43  friend class GroupObjectTableObject;
44  GroupObject(const GroupObject& other) = delete;
45  public:
49  GroupObject();
53  virtual ~GroupObject();
54  // config flags from ETS
58  bool responseUpdateEnable();
62  bool transmitEnable();
66  bool valueReadOnInit();
70  bool writeEnable();
74  bool readEnable();
78  bool communicationEnable();
79 
84 
88  ComFlag commFlag();
93  void commFlag(ComFlag value);
94 
98  bool initialized();
99 
109  void requestObjectRead();
116  void objectWritten();
117 
122  size_t valueSize();
127  size_t sizeInTelegram();
132  size_t sizeInMemory() const;
137  uint8_t* valueRef();
142  uint16_t asap();
143 
144 #ifndef SMALL_GROUPOBJECT
148  void callback(GroupObjectUpdatedHandler handler);
153 #endif
158  KNXValue value(const Dpt& type);
168  bool value(const KNXValue& value, const Dpt& type);
169 
180  bool valueCompare(const KNXValue& value, const Dpt& type);
181 
191  bool valueNoSend(const KNXValue& value, const Dpt& type);
192 
203  bool valueNoSendCompare(const KNXValue& value, const Dpt& type);
204 
214  bool tryValue(KNXValue& value, const Dpt& type);
215 
216 #ifndef SMALL_GROUPOBJECT
221  KNXValue value();
230  bool value(const KNXValue& value);
239  bool valueNoSend(const KNXValue& value);
248  bool tryValue(KNXValue& value);
249 
253  Dpt dataPointType();
257  void dataPointType(Dpt value);
258 #else
265  static void classCallback(GroupObjectUpdatedHandler handler);
266  static void processClassCallback(GroupObject& ko);
267 #endif
268 
269  private:
270  // class members
271  static GroupObjectTableObject* _table;
272 #ifdef SMALL_GROUPOBJECT
273  static GroupObjectUpdatedHandler _updateHandlerStatic;
274 #endif
275 
276  size_t asapValueSize(uint8_t code) const;
277  size_t goSize();
278  uint16_t _asap = 0;
279  bool _uninitialized : 1;
280  ComFlag _commFlag : 7;
281  uint8_t* _data = 0;
282  uint8_t _dataLength = 0;
283 #ifndef SMALL_GROUPOBJECT
284  GroupObjectUpdatedHandler _updateHandler;
285  Dpt _datapointType;
286 #endif
287 };
Definition: dpt.h:364
This class represents a single group object.
Definition: group_object.h:42
bool writeEnable()
Check if the write flag (W) was set.
bool valueCompare(const KNXValue &value, const Dpt &type)
Check if the value (after conversion to dpt) will differ from current value of the group object and c...
GroupObjectUpdatedHandler callback()
returns the registered callback
uint16_t asap()
returns the Application Service Access Point of the group object.
bool responseUpdateEnable()
Check if the update flag (U) was set.
bool initialized()
Check if the group object contains a valid value assigned from bus or from application program.
virtual ~GroupObject()
The destructor.
size_t sizeInTelegram()
returns the size of the group object in Byte as it is in a telegram.
static void processClassCallback(GroupObject &ko)
static GroupObjectUpdatedHandler classCallback()
Alternative callback processing: register one global callback for all group object.
ComFlag commFlag()
Return the current state of the group object.
KNXValue value()
return the current value of the group object.
size_t sizeInMemory() const
returns the size of the group object in the heap memory of the group object.
bool transmitEnable()
Check if the transmit flag (T) was set.
GroupObject()
The constructor.
void objectWritten()
Mark a communication object as written.
uint8_t * valueRef()
returns the pointer to the value of the group object.
bool valueNoSendCompare(const KNXValue &value, const Dpt &type)
Check if the value (after conversion to dpt) will differ from current value of the group object and u...
void requestObjectRead()
Request the read of a communication object.
Priority priority()
Get the priority of the group object.
bool valueReadOnInit()
Check if the initialisation flag (I) was set.
bool communicationEnable()
Check if the communication flag (C) was set.
bool tryValue(KNXValue &value, const Dpt &type)
set the current value of the group object.
bool valueNoSend(const KNXValue &value, const Dpt &type)
set the current value of the group objectand show success.
size_t valueSize()
returns the size of the group object in Byte.
Dpt dataPointType()
returns the currently configured datapoint type.
bool readEnable()
Check if the read flag (R) was set.
ComFlag
Definition: group_object.h:11
@ Ok
read or write request were send successfully
Definition: group_object.h:16
@ ReadRequest
Read was requested but was not processed.
Definition: group_object.h:13
@ Updated
Group object was updated.
Definition: group_object.h:12
@ Uninitialized
uninitialized Group Object, its value is not valid
Definition: group_object.h:18
@ Error
there was an error on processing a request
Definition: group_object.h:17
@ Transmitting
Group Object is processed a the moment (read or write)
Definition: group_object.h:15
@ WriteRequest
Write was requested but was not processed.
Definition: group_object.h:14
std::function< void(GroupObject &)> GroupObjectUpdatedHandler
Definition: group_object.h:33
Priority
Definition: knx_types.h:10