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 
82  if (newState != LS_LOADED)
83  return;
84 
85  _tableData = (uint16_t*)data();
86 
87  if (!initGroupObjects())
88  {
89  newState = LS_ERROR;
91  }
92 }
93 
94 bool GroupObjectTableObject::initGroupObjects()
95 {
96  if (!_tableData)
97  return false;
98 
99  freeGroupObjects();
100 
101  uint16_t goCount = ntohs(_tableData[0]);
102 
103  _groupObjects = new GroupObject[goCount];
104  _groupObjectCount = goCount;
105 
106  for (uint16_t asap = 1; asap <= goCount; asap++)
107  {
108  GroupObject& go = _groupObjects[asap - 1];
109  go._asap = asap;
110  go._table = this;
111 
112  go._dataLength = go.goSize();
113  size_t sizeInMemory = go.sizeInMemory();
114  go._data = new uint8_t[sizeInMemory];
115  memset(go._data, 0, sizeInMemory);
116 
117  if (go.valueReadOnInit())
118  go.requestObjectRead();
119  }
120 
121  return true;
122 }
123 
124 void GroupObjectTableObject::freeGroupObjects()
125 {
126  if (_groupObjects)
127  delete[] _groupObjects;
128 
129  _groupObjectCount = 0;
130  _groupObjects = 0;
131 }
This class represents a single group object.
Definition: group_object.h:42
ComFlag commFlag()
Return the current state of the group object.
size_t sizeInMemory() const
returns the size of the group object in the heap memory 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:224
@ PDT_UNSIGNED_INT
length: 2
Definition: property.h:22
@ WriteLv0
Definition: property.h:247
@ ReadLv3
Definition: property.h:246
LoadState
Definition: property.h:198
@ LS_LOADED
Definition: property.h:200
@ LS_ERROR
Definition: property.h:202