knx
ETS configurable knx-stack
group_object_table_object.cpp
Go to the documentation of this file.
1 #include <cstring>
2 
4 #include "group_object.h"
5 #include "bits.h"
6 #include "data_property.h"
7 
9  : TableObject(memory)
10 {
11  Property* properties[]
12  {
14  };
15  TableObject::initializeProperties(sizeof(properties), properties);
16 }
17 
19 {
20  freeGroupObjects();
21 }
22 
24 {
25  if (loadState() != LS_LOADED)
26  return 0;
27 
28  return ntohs(_tableData[0]);
29 }
30 
32 {
33  return _groupObjects[asap - 1];
34 }
35 
36 const uint8_t* GroupObjectTableObject::restore(const uint8_t* buffer)
37 {
38  buffer = TableObject::restore(buffer);
39 
40  _tableData = (uint16_t*)data();
41  initGroupObjects();
42 
43  return buffer;
44 }
45 
47 {
48  static uint16_t startIdx = 1;
49 
50  uint16_t objCount = entryCount();
51 
52  for (uint16_t asap = startIdx; asap <= objCount; asap++)
53  {
54  GroupObject& go = get(asap);
55 
56  if (go.commFlag() == Updated)
57  {
58  go.commFlag(Ok);
59  startIdx = asap + 1;
60  valid = true;
61  return go;
62  }
63  }
64 
65  startIdx = 1;
66  valid = false;
67  return get(1);
68 }
69 
71 {
72  freeGroupObjects();
73  _groupObjects = objs;
74  _groupObjectCount = size;
75  initGroupObjects();
76 }
77 
79 {
81  if (newState != LS_LOADED)
82  return;
83 
84  _tableData = (uint16_t*)data();
85 
86  if (!initGroupObjects())
87  {
88  newState = LS_ERROR;
90  }
91 }
92 
93 bool GroupObjectTableObject::initGroupObjects()
94 {
95  if (!_tableData)
96  return false;
97 
98  freeGroupObjects();
99 
100  uint16_t goCount = ntohs(_tableData[0]);
101 
102  _groupObjects = new GroupObject[goCount];
103  _groupObjectCount = goCount;
104 
105  for (uint16_t asap = 1; asap <= goCount; asap++)
106  {
107  GroupObject& go = _groupObjects[asap - 1];
108  go._asap = asap;
109  go._table = this;
110 
111  go._dataLength = go.goSize();
112  go._data = new uint8_t[go._dataLength];
113  memset(go._data, 0, go._dataLength);
114 
115  if (go.valueReadOnInit())
116  go.requestObjectRead();
117  }
118 
119  return true;
120 }
121 
122 void GroupObjectTableObject::freeGroupObjects()
123 {
124  if (_groupObjects)
125  delete[] _groupObjects;
126 
127  _groupObjectCount = 0;
128  _groupObjects = 0;
129 }
This class represents a single group object.
Definition: group_object.h:42
ComFlag commFlag()
Return the current state of the group object.
void requestObjectRead()
Request the read of a communication object.
bool valueReadOnInit()
Check if the initialisation flag (I) was set.
void groupObjects(GroupObject *objs, uint16_t size)
void beforeStateChange(LoadState &newState) override
This method is called before the interface object enters a new LoadState.
GroupObject & nextUpdatedObject(bool &valid)
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
GroupObject & get(uint16_t asap)
Definition: memory.h:37
This class provides common functionality for interface objects that are configured by ETS with MemorW...
Definition: table_object.h:13
void initializeProperties(size_t propertiesSize, Property **properties) override
Intializes the Property-array the the supplied values.
LoadState loadState()
This method returns the LoadState of the interface object.
uint8_t * data()
returns the internal data of the interface object.
virtual void beforeStateChange(LoadState &newState)
This method is called before the interface object enters a new LoadState.
void errorCode(ErrorCode errorCode)
Set the reason for a state change failure.
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
@ Ok
read or write request were send successfully
Definition: group_object.h:16
@ Updated
Group object was updated.
Definition: group_object.h:12
@ OT_GRP_OBJ_TABLE
Group Object Table Object.
@ PID_OBJECT_TYPE
Interface Object Type independent Properties.
Definition: property.h:72
@ E_SOFTWARE_FAULT
Definition: property.h:222
@ PDT_UNSIGNED_INT
length: 2
Definition: property.h:22
@ WriteLv0
Definition: property.h:245
@ ReadLv3
Definition: property.h:244
LoadState
Definition: property.h:196
@ LS_LOADED
Definition: property.h:198
@ LS_ERROR
Definition: property.h:200