knx
ETS configurable knx-stack
address_table_object.cpp
Go to the documentation of this file.
1 #include <cstring>
2 
3 #include "address_table_object.h"
4 #include "bits.h"
5 #include "data_property.h"
6 
7 using namespace std;
8 
10  : TableObject(memory)
11 {
12  Property* properties[] =
13  {
15  };
16 
17  TableObject::initializeProperties(sizeof(properties), properties);
18 }
19 
21 {
22  // after programming without GA the module hangs
23  if (loadState() != LS_LOADED || _groupAddresses[0] == 0xFFFF)
24  return 0;
25 
26  return ntohs(_groupAddresses[0]);
27 }
28 
29 uint16_t AddressTableObject::getGroupAddress(uint16_t tsap)
30 {
31  if (loadState() != LS_LOADED || tsap > entryCount() )
32  return 0;
33 
34  return ntohs(_groupAddresses[tsap]);
35 }
36 
37 uint16_t AddressTableObject::getTsap(uint16_t addr)
38 {
39  uint16_t size = entryCount();
40 #ifdef USE_BINSEARCH
41 
42  uint16_t low, high, i;
43  low = 1;
44  high = size;
45 
46  while (low <= high)
47  {
48  i = (low + high) / 2;
49  uint16_t ga = ntohs(_groupAddresses[i]);
50 
51  if (ga == addr)
52  return i;
53 
54  if (addr < ga)
55  high = i - 1;
56  else
57  low = i + 1 ;
58  }
59 
60 #else
61 
62  for (uint16_t i = 1; i <= size; i++)
63  if (ntohs(_groupAddresses[i]) == addr)
64  return i;
65 
66 #endif
67  return 0;
68 }
69 
70 #pragma region SaveRestore
71 
72 const uint8_t* AddressTableObject::restore(const uint8_t* buffer)
73 {
74  buffer = TableObject::restore(buffer);
75 
76  _groupAddresses = (uint16_t*)data();
77 
78  return buffer;
79 }
80 
81 #pragma endregion
82 
83 bool AddressTableObject::contains(uint16_t addr)
84 {
85  return (getTsap(addr) > 0);
86 }
87 
89 {
91 
92  if (newState != LS_LOADED)
93  return;
94 
95  _groupAddresses = (uint16_t*)data();
96 }
uint16_t getGroupAddress(uint16_t tsap)
Get the group address mapped to a TSAP.
bool contains(uint16_t groupAddress)
Check if the address table contains a group address.
uint16_t getTsap(uint16_t groupAddress)
Get the TSAP mapped to a group address.
AddressTableObject(Memory &memory)
The constructor.
void beforeStateChange(LoadState &newState) override
This method is called before the interface object enters a new LoadState.
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
uint16_t entryCount()
returns the number of group addresses of the object.
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.
const uint8_t * restore(const uint8_t *buffer) override
This method is called when the object should restore its state from the buffer.
@ OT_ADDR_TABLE
Address table object.
@ PID_OBJECT_TYPE
Interface Object Type independent Properties.
Definition: property.h:72
@ 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