knx
ETS configurable knx-stack
bau2920.cpp
Go to the documentation of this file.
1 #include "config.h"
2 #if MASK_VERSION == 0x2920
3 
4 #include "bau2920.h"
5 #include "bits.h"
6 #include <string.h>
7 #include <stdio.h>
8 
9 using namespace std;
10 
11 // Mask 0x2920 uses coupler model 2.0
13  : BauSystemBCoupler(platform),
14  _rtObjPrimary(memory()),
15  _rtObjSecondary(memory()),
16  _rfMediumObject(),
17  _dlLayerPrimary(_deviceObj, _netLayer.getPrimaryInterface(), _platform, (ITpUartCallBacks&) * this),
18  _dlLayerSecondary(_deviceObj, _rfMediumObject, _netLayer.getSecondaryInterface(), platform)
19 #ifdef USE_CEMI_SERVER
20  ,
21  _cemiServer(*this)
22 #endif
23 {
24  // Before accessing anything of the two router objects they have to be initialized according to the used media combination
25  // Coupler model 2.0
28 
29  _netLayer.rtObjPrimary(_rtObjPrimary);
30  _netLayer.rtObjSecondary(_rtObjSecondary);
31  _netLayer.getPrimaryInterface().dataLinkLayer(_dlLayerPrimary);
32  _netLayer.getSecondaryInterface().dataLinkLayer(_dlLayerSecondary);
33 
34 #ifdef USE_CEMI_SERVER
37  _cemiServer.dataLinkLayer(_dlLayerSecondary); // Secondary I/F is the important one!
38  _dlLayerSecondary.cemiServer(_cemiServer);
39  _memory.addSaveRestore(&_cemiServerObject);
40 #endif
41 
42  _memory.addSaveRestore(&_rtObjPrimary);
43  _memory.addSaveRestore(&_rtObjSecondary);
44 
45  _memory.addSaveRestore(&_rfMediumObject);
46 
47  // Set Mask Version in Device Object depending on the BAU
48  _deviceObj.maskVersion(0x2920);
49 
50  // Set which interface objects are available in the device object
51  // This differs from BAU to BAU with different medium types.
52  // See PID_IO_LIST
54  prop->write(1, (uint16_t) OT_DEVICE);
55  prop->write(2, (uint16_t) OT_ROUTER);
56  prop->write(3, (uint16_t) OT_ROUTER);
57  prop->write(4, (uint16_t) OT_APPLICATION_PROG);
58  prop->write(5, (uint16_t) OT_RF_MEDIUM);
59 #if defined(USE_DATASECURE) && defined(USE_CEMI_SERVER)
60  prop->write(6, (uint16_t) OT_SECURITY);
61  prop->write(7, (uint16_t) OT_CEMI_SERVER);
62 #elif defined(USE_DATASECURE)
63  prop->write(6, (uint16_t) OT_SECURITY);
64 #elif defined(USE_CEMI_SERVER)
65  prop->write(6, (uint16_t) OT_CEMI_SERVER);
66 #endif
67 }
68 
70 {
71  switch (idx)
72  {
73  case 0:
74  return &_deviceObj;
75 
76  case 1:
77  return &_rtObjPrimary;
78 
79  case 2:
80  return &_rtObjSecondary;
81 
82  case 3:
83  return &_appProgram;
84 
85  case 4:
86  return &_rfMediumObject;
87 #if defined(USE_DATASECURE) && defined(USE_CEMI_SERVER)
88 
89  case 5:
90  return &_secIfObj;
91 
92  case 6:
93  return &_cemiServerObject;
94 #elif defined(USE_CEMI_SERVER)
95 
96  case 5:
97  return &_cemiServerObject;
98 #elif defined(USE_DATASECURE)
99 
100  case 5:
101  return &_secIfObj;
102 #endif
103 
104  default:
105  return nullptr;
106  }
107 }
108 
109 InterfaceObject* Bau2920::getInterfaceObject(ObjectType objectType, uint16_t objectInstance)
110 {
111  // We do not use it right now.
112  // Required for coupler mode as there are multiple router objects for example
113  (void) objectInstance;
114 
115  switch (objectType)
116  {
117  case OT_DEVICE:
118  return &_deviceObj;
119 
120  case OT_ROUTER:
121  return objectInstance == 0 ? &_rtObjPrimary : &_rtObjSecondary;
122 
123  case OT_APPLICATION_PROG:
124  return &_appProgram;
125 
126  case OT_RF_MEDIUM:
127  return &_rfMediumObject;
128 #ifdef USE_DATASECURE
129 
130  case OT_SECURITY:
131  return &_secIfObj;
132 #endif
133 #ifdef USE_CEMI_SERVER
134 
135  case OT_CEMI_SERVER:
136  return &_cemiServerObject;
137 #endif
138 
139  default:
140  return nullptr;
141  }
142 }
143 
144 void Bau2920::doMasterReset(EraseCode eraseCode, uint8_t channel)
145 {
146  // Common SystemB objects
147  BauSystemBCoupler::doMasterReset(eraseCode, channel);
148 
149  _rfMediumObject.masterReset(eraseCode, channel);
150  _rtObjPrimary.masterReset(eraseCode, channel);
151  _rtObjSecondary.masterReset(eraseCode, channel);
152 }
153 
155 {
156  return _dlLayerPrimary.enabled() && _dlLayerSecondary.enabled();
157 }
158 
159 void Bau2920::enabled(bool value)
160 {
161  _dlLayerPrimary.enabled(value);
162  _dlLayerSecondary.enabled(value);
163 }
164 
166 {
167  _dlLayerPrimary.loop();
168  _dlLayerSecondary.loop();
170 }
171 
173 {
174  return (TpUartDataLinkLayer*)&_dlLayerPrimary;
175 }
176 
178 {
179  return (RfDataLinkLayer*)&_dlLayerSecondary;
180 }
181 #endif
RfDataLinkLayer * getSecondaryDataLinkLayer()
Definition: bau2920.cpp:177
InterfaceObject * getInterfaceObject(uint8_t idx)
void loop() override
Definition: bau2920.cpp:165
bool enabled() override
Definition: bau2920.cpp:154
Bau2920(Platform &platform)
Definition: bau2920.cpp:12
TpUartDataLinkLayer * getPrimaryDataLinkLayer()
Definition: bau2920.cpp:172
void doMasterReset(EraseCode eraseCode, uint8_t channel) override
Definition: bau2920.cpp:144
NetworkLayerCoupler _netLayer
void doMasterReset(EraseCode eraseCode, uint8_t channel) override
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()
This class represents and interface object.
virtual void masterReset(EraseCode eraseCode, uint8_t channel)
Property * property(PropertyID id)
Gets property with PropertyID id if it exists and nullptr otherwise.
void addSaveRestore(SaveRestore *obj)
Definition: memory.cpp:209
NetworkLayerEntity & getSecondaryInterface()
void rtObjSecondary(RouterObject &rtObjSecondary)
void rtObjPrimary(RouterObject &rtObjPrimary)
NetworkLayerEntity & getPrimaryInterface()
void dataLinkLayer(DataLinkLayer &layer)
virtual uint8_t write(uint16_t start, uint8_t count, const uint8_t *data)=0
void masterReset(EraseCode eraseCode, uint8_t channel) override
void initialize20(uint8_t objIndex, DptMedium mediumType, RouterObjectType rtType, uint16_t maxApduSize)
ObjectType
Enum for the type of an interface object.
@ OT_RF_MEDIUM
RF Medium Object.
@ OT_CEMI_SERVER
cEMI Server Object
@ OT_APPLICATION_PROG
Application program object.
@ OT_DEVICE
Device object.
@ OT_SECURITY
Security Interface Object.
@ OT_ROUTER
Router Object.
EraseCode
Definition: knx_types.h:242
@ KNX_TP1
Definition: knx_types.h:257
@ KNX_RF
Definition: knx_types.h:259
@ PID_IO_LIST
Definition: property.h:98
@ Primary
Definition: router_object.h:18
@ Secondary
Definition: router_object.h:19