-
Notifications
You must be signed in to change notification settings - Fork 7
/
MergNodeIdentification.cpp
325 lines (272 loc) · 5.85 KB
/
MergNodeIdentification.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
#include "MergNodeIdentification.h"
/** \brief Constructor
*
* Set the internal variables.
*/
MergNodeIdentification::MergNodeIdentification()
{
for (int i=0;i<NAME_SIZE;i++){
nodeName[i]='0';
}
}
/** \brief Destructor
*
*/
MergNodeIdentification::~MergNodeIdentification()
{
//dtor
}
/** \brief Set the node name
*
* \param nn Pointer to the node name.
* \param csize Size of the node name limited by NAME_SIZE.
*
*/
void MergNodeIdentification::setNodeName(char const *nn,int csize)
{
int i=0;
int n=NAME_SIZE;
if (csize<NAME_SIZE){
n=csize;
}
for (i=0;i<NAME_SIZE;i++){
nodeName[i]=0;
}
for (i=0;i<n;i++){
nodeName[i]=nn[i];
}
}
/** \brief Retrieve the node name.
*
* \return Pointer to the node name.
*
*/
const char* MergNodeIdentification::getNodeName()
{
return nodeName;
}
/** \brief Get one of the defined parameters
*
* \param idx Index of the parameter: 0 to 20
* \return Return either of the parameters:
* + Manufacturer Id
* + Max Code Version
* + Min Code Version
* + Module Id
* + Number of Supported Events
* + Number of Supported Event Variables
* + Number of Supported Node Variables
* + Node Flags
* + CPU Type
* + Transport Type
* + Code load params 11 to 14
* + Actual CPU params 15 to 18
* + CPU Manufacturer
* + Beta Release
* + 0 by default
*/
byte MergNodeIdentification::getParameter(byte idx){
switch (idx){
case 1:
return manufacturerId;
break;
case 2:
return minCodeVersion;
break;
case 3:
return moduleId;
break;
case 4:
return suportedEvents;
break;
case 5:
return suportedEventsVariables;
break;
case 6:
return suportedNodeVariables;
break;
case 7:
return maxCodeVersion;
break;
case 8:
return flags;
break;
case 9:
return cpuType;
break;
case 10:
return transportType;
break;
case 11:
return codeLoad;
break;
case 12:
return codeLoad;
break;
case 13:
return codeLoad;
break;
case 14:
return codeLoad;
break;
case 15:
return ManufacturerCpuCodeA;
break;
case 16:
return ManufacturerCpuCodeB;
break;
case 17:
return ManufacturerCpuCodeC;
break;
case 18:
return ManufacturerCpuCodeD;
break;
case 19:
return cpuManufacturer;
break;
case 20:
return betaRelease;
break;
}
return 0;
}
/** \brief Set this module as a producer.
*
* \param val True for producer. False not producer.
*/
/*Bit 0: Consumer
Bit 1: Producer
Bit 2: FLiM Mode
Bit 3: The module supports bootloading
Bit 4: The module can consume its own produced events
Bit 5: Module is in learn mode
*/
/*--------------------------------------------------------------*/
/* Set Flags for Consumer Mode */
void MergNodeIdentification::setConsumerNode(bool val){
if (val){
bitSet(flags,0);
}else {
bitClear(flags,0);
}
}
/** \brief Indicates if the node is a consumer.
* \return True for consumer. False not consumer.
*
*/
bool MergNodeIdentification::isConsumerNode(){
if (bitRead(flags,0)==0){
return true;
} else{
return false;
}
}
/*--------------------------------------------------------------*/
/** \brief Indicates if the node is a producer.
* \return True for producer. False not producer.
*
*/
/* Set Flags for Producer Mode */
void MergNodeIdentification::setProducerNode(bool val){
if (val){
bitSet(flags,1);
}else {
bitClear(flags,1);
}
}
bool MergNodeIdentification::isProducerNode(){
if (bitRead(flags,1)==1){
return true;
} else{
return false;
}
}
/*--------------------------------------------------------------*/
/** \brief Indicates if the node can consume own events
* \return True for can consume False cannot consume.
*
*/
// added by phil
void MergNodeIdentification::setConsumeEvents(bool val){
if (val){
bitSet(flags,4);
}else {
bitClear(flags,4);
}
}
bool MergNodeIdentification::isConsumeEvents(){
if (bitRead(flags,4)==4){
return true;
} else{
return false;
}
}
/*--------------------------------------------------------------*/
/** \brief Indicates if the node is in learn mode.
* \return True if node is in learn mode.
* added by phil
*/
void MergNodeIdentification::setLearnMode(bool val){
if (val){
bitSet(flags,5);
}else {
bitClear(flags,5);
}
}
bool MergNodeIdentification::isLearnMode(){
if (bitRead(flags,5)==5){
return true;
} else{
return false;
}
}
/*--------------------------------------------------------------*/
/** \brief Set this module to SlimMode.
*/
void MergNodeIdentification::setSlimMode(){
bitClear(flags,2);
}
/** \brief Set this module to FlimMode.
*/
void MergNodeIdentification::setFlimMode(){
bitSet(flags,2);
}
/** \brief Indicate if the mode is in SlimMode.
*/
bool MergNodeIdentification::isSlimMode(){
if (bitRead(flags,2)==0){
return true;
} else{
return false;
}
}
/** \brief Indicate if the mode is in FlimMode.
*/
bool MergNodeIdentification::isFlimMode(){
if (bitRead(flags,2)==1){
return true;
} else{
return false;
}
}
/** \brief Indicate if the mode supports boot loading.
* This current version by default does not support boot loading.
*/
void MergNodeIdentification::setSuportBootLoading(bool val){
if (val){
bitSet(flags,3);
}else {
bitClear(flags,3);
}
}
/** \brief Indicate if the mode supports boot loading.
* This current version by default does not support boot loading.
*/
bool MergNodeIdentification::isBootLoading(){
if (bitRead(flags,3)==1){
return true;
} else{
return false;
}
return false;
}