@@ -27,11 +27,9 @@ inline MyMessage& build (MyMessage &msg, uint8_t sender, uint8_t destination, ui
27
27
return msg;
28
28
}
29
29
30
-
31
30
MySensor::MySensor (uint8_t _cepin, uint8_t _cspin) : RF24(_cepin, _cspin) {
32
31
}
33
32
34
-
35
33
void MySensor::begin (void (*_msgCallback)(const MyMessage &), uint8_t _nodeId, boolean _repeaterMode, uint8_t _parentNodeId, rf24_pa_dbm_e paLevel, uint8_t channel, rf24_datarate_e dataRate) {
36
34
Serial.begin (BAUD_RATE);
37
35
isGateway = false ;
@@ -125,7 +123,6 @@ void MySensor::setupRepeaterMode(){
125
123
eeprom_read_block ((void *)childNodeTable, (void *)EEPROM_ROUTES_ADDRESS, 256 );
126
124
}
127
125
128
-
129
126
uint8_t MySensor::getNodeId () {
130
127
return nc.nodeId ;
131
128
}
@@ -141,7 +138,6 @@ void MySensor::requestNodeId() {
141
138
waitForReply ();
142
139
}
143
140
144
-
145
141
void MySensor::findParentNode () {
146
142
failedTransmissions = 0 ;
147
143
@@ -228,7 +224,6 @@ boolean MySensor::sendWrite(uint8_t next, MyMessage &message, bool broadcast) {
228
224
return ok;
229
225
}
230
226
231
-
232
227
bool MySensor::send (MyMessage &message, bool enableAck) {
233
228
message.sender = nc.nodeId ;
234
229
mSetCommand (message,C_SET);
@@ -262,7 +257,6 @@ void MySensor::requestTime(void (* _timeCallback)(unsigned long)) {
262
257
sendRoute (build (msg, nc.nodeId , GATEWAY_ADDRESS, NODE_SENSOR_ID, C_INTERNAL, I_TIME, false ).set (" " ));
263
258
}
264
259
265
-
266
260
boolean MySensor::process () {
267
261
uint8_t pipe;
268
262
boolean available = RF24::available (&pipe);
@@ -289,18 +283,7 @@ boolean MySensor::process() {
289
283
uint8_t last = msg.last ;
290
284
uint8_t destination = msg.destination ;
291
285
292
- if (repeaterMode && command == C_INTERNAL && type == I_FIND_PARENT) {
293
- if (nc.distance == 255 ) {
294
- findParentNode ();
295
- } else if (sender != nc.parentNodeId ) {
296
- // Relaying nodes should always answer ping messages
297
- // Wait a random delay of 0-2 seconds to minimize collision
298
- // between ping ack messages from other relaying nodes
299
- delay (millis () & 0x3ff );
300
- sendWrite (sender, build (msg, nc.nodeId , sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false ).set (nc.distance ), true );
301
- }
302
- return false ;
303
- } else if (destination == nc.nodeId ) {
286
+ if (destination == nc.nodeId ) {
304
287
// Check if sender requests an ack back.
305
288
if (mGetRequestAck (msg)) {
306
289
// Copy message
@@ -390,54 +373,66 @@ boolean MySensor::process() {
390
373
}
391
374
// Return true if message was addressed for this node...
392
375
return true ;
393
- } else if (repeaterMode && pipe == CURRENT_NODE_PIPE) {
394
- // We should try to relay this message to another node
395
-
396
- uint8_t route = getChildRoute (msg.destination );
397
- if (route>0 && route<255 ) {
398
- // This message should be forwarded to a child node. If we send message
399
- // to this nodes pipe then all children will receive it because the are
400
- // all listening to this nodes pipe.
401
- //
402
- // +----B
403
- // -A
404
- // +----C------D
405
- //
406
- // We're node C, Message comes from A and has destination D
407
- //
408
- // lookup route in table and send message there
409
- sendWrite (route, msg);
410
- } else if (sender == GATEWAY_ADDRESS && destination == BROADCAST_ADDRESS) {
411
- // A net gateway reply to a message previously sent by us from a 255 node
412
- // We should broadcast this back to the node
413
- sendWrite (destination, msg, true );
414
- } else {
415
- // A message comes from a child node and we have no
416
- // route for it.
417
- //
418
- // +----B
419
- // -A
420
- // +----C------D <-- Message comes from D
421
- //
422
- // We're node C
423
- //
424
- // Message should be passed to node A (this nodes relay)
425
-
426
- // This message should be routed back towards sensor net gateway
427
- sendWrite (nc.parentNodeId , msg);
428
- // Add this child to our "routing table" if it not already exist
429
- addChildRoute (sender, last);
376
+ } else if (repeaterMode && nc.nodeId != AUTO) {
377
+ // Relaying nodes should answer only after set an id
378
+
379
+ if (command == C_INTERNAL && type == I_FIND_PARENT) {
380
+ if (nc.distance == 255 ) {
381
+ findParentNode ();
382
+ } else if (sender != nc.parentNodeId ) {
383
+ // Relaying nodes should always answer ping messages
384
+ // Wait a random delay of 0-2 seconds to minimize collision
385
+ // between ping ack messages from other relaying nodes
386
+ delay (millis () & 0x3ff );
387
+ sendWrite (sender, build (msg, nc.nodeId , sender, NODE_SENSOR_ID, C_INTERNAL, I_FIND_PARENT_RESPONSE, false ).set (nc.distance ), true );
388
+ }
389
+ } else if (pipe == CURRENT_NODE_PIPE) {
390
+ // We should try to relay this message to another node
391
+
392
+ uint8_t route = getChildRoute (msg.destination );
393
+ if (route>0 && route<255 ) {
394
+ // This message should be forwarded to a child node. If we send message
395
+ // to this nodes pipe then all children will receive it because the are
396
+ // all listening to this nodes pipe.
397
+ //
398
+ // +----B
399
+ // -A
400
+ // +----C------D
401
+ //
402
+ // We're node C, Message comes from A and has destination D
403
+ //
404
+ // lookup route in table and send message there
405
+ sendWrite (route, msg);
406
+ } else if (sender == GATEWAY_ADDRESS && destination == BROADCAST_ADDRESS) {
407
+ // A net gateway reply to a message previously sent by us from a 255 node
408
+ // We should broadcast this back to the node
409
+ sendWrite (destination, msg, true );
410
+ } else {
411
+ // A message comes from a child node and we have no
412
+ // route for it.
413
+ //
414
+ // +----B
415
+ // -A
416
+ // +----C------D <-- Message comes from D
417
+ //
418
+ // We're node C
419
+ //
420
+ // Message should be passed to node A (this nodes relay)
421
+
422
+ // This message should be routed back towards sensor net gateway
423
+ sendWrite (nc.parentNodeId , msg);
424
+ // Add this child to our "routing table" if it not already exist
425
+ addChildRoute (sender, last);
426
+ }
430
427
}
431
428
}
432
429
return false ;
433
430
}
434
431
435
-
436
432
MyMessage& MySensor::getLastMessage () {
437
433
return msg;
438
434
}
439
435
440
-
441
436
void MySensor::saveState (uint8_t pos, uint8_t value) {
442
437
if (loadState (pos) != value) {
443
438
eeprom_write_byte ((uint8_t *)(EEPROM_LOCAL_CONFIG_ADDRESS+pos), value);
@@ -447,7 +442,6 @@ uint8_t MySensor::loadState(uint8_t pos) {
447
442
return eeprom_read_byte ((uint8_t *)(EEPROM_LOCAL_CONFIG_ADDRESS+pos));
448
443
}
449
444
450
-
451
445
void MySensor::addChildRoute (uint8_t childId, uint8_t route) {
452
446
if (childNodeTable[childId] != route) {
453
447
childNodeTable[childId] = route;
@@ -466,7 +460,6 @@ uint8_t MySensor::getChildRoute(uint8_t childId) {
466
460
return childNodeTable[childId];
467
461
}
468
462
469
-
470
463
int8_t pinIntTrigger = 0 ;
471
464
void wakeUp () // place to send the interrupts
472
465
{
@@ -589,7 +582,6 @@ void MySensor::debugPrint(const char *fmt, ... ) {
589
582
}
590
583
#endif
591
584
592
-
593
585
#ifdef DEBUG
594
586
int MySensor::freeRam (void ) {
595
587
extern int __heap_start, *__brkval;
0 commit comments