knx
ETS configurable knx-stack
bau07B0.cpp
Go to the documentation of this file.
1 #include "config.h"
2 #if MASK_VERSION == 0x07B0
3 
4 #include "bau07B0.h"
5 #include "bits.h"
6 #include <string.h>
7 #include <stdio.h>
8 
9 using namespace std;
10 
13  _dlLayer(_deviceObj, _netLayer.getInterface(), _platform, (ITpUartCallBacks&) * this, (DataLinkLayerCallbacks*) this)
14 #ifdef USE_CEMI_SERVER
15  , _cemiServer(*this)
16 #endif
17 {
19 #ifdef USE_CEMI_SERVER
21  _cemiServer.dataLinkLayer(_dlLayer);
22  _dlLayer.cemiServer(_cemiServer);
23  _memory.addSaveRestore(&_cemiServerObject);
24 #endif
25  // Set Mask Version in Device Object depending on the BAU
26  _deviceObj.maskVersion(0x07B0);
27 
28  // Set which interface objects are available in the device object
29  // This differs from BAU to BAU with different medium types.
30  // See PID_IO_LIST
32  prop->write(1, (uint16_t) OT_DEVICE);
33  prop->write(2, (uint16_t) OT_ADDR_TABLE);
34  prop->write(3, (uint16_t) OT_ASSOC_TABLE);
35  prop->write(4, (uint16_t) OT_GRP_OBJ_TABLE);
36  prop->write(5, (uint16_t) OT_APPLICATION_PROG);
37 #if defined(USE_DATASECURE) && defined(USE_CEMI_SERVER)
38  prop->write(6, (uint16_t) OT_SECURITY);
39  prop->write(7, (uint16_t) OT_CEMI_SERVER);
40 #elif defined(USE_DATASECURE)
41  prop->write(6, (uint16_t) OT_SECURITY);
42 #elif defined(USE_CEMI_SERVER)
43  prop->write(6, (uint16_t) OT_CEMI_SERVER);
44 #endif
45 }
46 
48 {
49  switch (idx)
50  {
51  case 0:
52  return &_deviceObj;
53 
54  case 1:
55  return &_addrTable;
56 
57  case 2:
58  return &_assocTable;
59 
60  case 3:
61  return &_groupObjTable;
62 
63  case 4:
64  return &_appProgram;
65 
66  case 5: // would be app_program 2
67  return nullptr;
68 #if defined(USE_DATASECURE) && defined(USE_CEMI_SERVER)
69 
70  case 6:
71  return &_secIfObj;
72 
73  case 7:
74  return &_cemiServerObject;
75 #elif defined(USE_CEMI_SERVER)
76 
77  case 6:
78  return &_cemiServerObject;
79 #elif defined(USE_DATASECURE)
80 
81  case 6:
82  return &_secIfObj;
83 #endif
84 
85  default:
86  return nullptr;
87  }
88 }
89 
90 InterfaceObject* Bau07B0::getInterfaceObject(ObjectType objectType, uint16_t objectInstance)
91 {
92  // We do not use it right now.
93  // Required for coupler mode as there are multiple router objects for example
94  (void) objectInstance;
95 
96  switch (objectType)
97  {
98  case OT_DEVICE:
99  return &_deviceObj;
100 
101  case OT_ADDR_TABLE:
102  return &_addrTable;
103 
104  case OT_ASSOC_TABLE:
105  return &_assocTable;
106 
107  case OT_GRP_OBJ_TABLE:
108  return &_groupObjTable;
109 
110  case OT_APPLICATION_PROG:
111  return &_appProgram;
112 #ifdef USE_DATASECURE
113 
114  case OT_SECURITY:
115  return &_secIfObj;
116 #endif
117 #ifdef USE_CEMI_SERVER
118 
119  case OT_CEMI_SERVER:
120  return &_cemiServerObject;
121 #endif
122 
123  default:
124  return nullptr;
125  }
126 }
127 
129 {
130  return _dlLayer.enabled();
131 }
132 
133 void Bau07B0::enabled(bool value)
134 {
135  _dlLayer.enabled(value);
136 }
137 
139 {
140  _dlLayer.loop();
142 #ifdef USE_CEMI_SERVER
143  _cemiServer.loop();
144 #endif
145 }
146 
147 TPAckType Bau07B0::isAckRequired(uint16_t address, bool isGrpAddr)
148 {
149  if (isGrpAddr)
150  {
151  // ACK for broadcasts
152  if (address == 0)
153  return TPAckType::AckReqAck;
154 
155  // is group address in group address table? ACK if yes.
156  if (_addrTable.contains(address))
157  return TPAckType::AckReqAck;
158  else
159  return TPAckType::AckReqNone;
160  }
161 
162  // Also ACK for our own individual address
163  if (address == _deviceObj.individualAddress())
164  return TPAckType::AckReqAck;
165 
166  if (address == 0)
167  {
168  println("Invalid broadcast detected: destination address is 0, but address type is \"individual\"");
169  }
170 
171  return TPAckType::AckReqNone;
172 }
173 
175 {
176  return (TpUartDataLinkLayer*)&_dlLayer;
177 }
178 #endif
void println(const char *s)
bool contains(uint16_t groupAddress)
Check if the address table contains a group address.
TPAckType isAckRequired(uint16_t address, bool isGrpAddr) override
Definition: bau07B0.cpp:147
InterfaceObject * getInterfaceObject(uint8_t idx)
TpUartDataLinkLayer * getDataLinkLayer()
Definition: bau07B0.cpp:174
Bau07B0(Platform &platform)
Definition: bau07B0.cpp:11
bool enabled() override
Definition: bau07B0.cpp:128
void loop() override
Definition: bau07B0.cpp:138
void loop() override
AssociationTableObject _assocTable
NetworkLayerDevice _netLayer
AddressTableObject _addrTable
GroupObjectTableObject _groupObjTable
SecurityInterfaceObject _secIfObj
Memory _memory
Definition: bau_systemB.h:123
ApplicationProgramObject _appProgram
Definition: bau_systemB.h:125
DeviceObject _deviceObj
Definition: bau_systemB.h:124
void dataLinkLayer(DataLinkLayer &layer)
void setMediumTypeAsSupported(DptMedium dptMedium)
uint16_t maskVersion()
uint16_t individualAddress()
This class represents and interface object.
Property * property(PropertyID id)
Gets property with PropertyID id if it exists and nullptr otherwise.
void addSaveRestore(SaveRestore *obj)
Definition: memory.cpp:209
NetworkLayerEntity & getInterface()
void dataLinkLayer(DataLinkLayer &layer)
virtual uint8_t write(uint16_t start, uint8_t count, const uint8_t *data)=0
ObjectType
Enum for the type of an interface object.
@ OT_CEMI_SERVER
cEMI Server Object
@ OT_APPLICATION_PROG
Application program object.
@ OT_GRP_OBJ_TABLE
Group Object Table Object.
@ OT_ADDR_TABLE
Address table object.
@ OT_DEVICE
Device object.
@ OT_SECURITY
Security Interface Object.
@ OT_ASSOC_TABLE
Association table object.
@ KNX_TP1
Definition: knx_types.h:257
TPAckType
Definition: knx_types.h:24
@ AckReqNone
Definition: knx_types.h:29
@ AckReqAck
Definition: knx_types.h:28
@ PID_IO_LIST
Definition: property.h:98