10
10
#include < fstream>
11
11
#endif
12
12
13
- #if defined NRF52_RADIO_LIBRARY
14
- RF24Mesh::RF24Mesh (nrf_to_nrf& _radio, RF24Network& _network) : radio(_radio), network(_network)
15
- #else
16
13
RF24Mesh::RF24Mesh (RF24& _radio, RF24Network& _network) : radio(_radio), network(_network)
17
- #endif
18
14
{
19
15
setCallback (NULL );
20
16
meshStarted = false ;
@@ -27,7 +23,7 @@ RF24Mesh::RF24Mesh(RF24& _radio, RF24Network& _network) : radio(_radio), network
27
23
28
24
bool RF24Mesh::begin (uint8_t channel, rf24_datarate_e data_rate, uint32_t timeout)
29
25
{
30
- // delay(1); // Found problems w/SPIDEV & ncurses. Without this, getch() returns a stream of garbage
26
+ // delay(1); // Found problems w/SPIDEV & ncurses. Without this, getch() returns a stream of garbage
31
27
if (meshStarted) {
32
28
radio.stopListening ();
33
29
}
@@ -38,7 +34,7 @@ bool RF24Mesh::begin(uint8_t channel, rf24_datarate_e data_rate, uint32_t timeou
38
34
radio.setDataRate (data_rate);
39
35
network.returnSysMsgs = true ;
40
36
41
- if (getNodeID () > 0 ) { // Not master node
37
+ if (getNodeID () > 0 ) { // Not master node
42
38
if (renewAddress (timeout) == MESH_DEFAULT_ADDRESS) {
43
39
return false ;
44
40
}
@@ -97,7 +93,7 @@ uint8_t RF24Mesh::update()
97
93
}
98
94
}
99
95
}
100
- #endif // ! NO_MASTER
96
+ #endif // !NO_MASTER
101
97
102
98
return type;
103
99
}
@@ -168,13 +164,13 @@ bool RF24Mesh::checkConnection()
168
164
int16_t RF24Mesh::getAddress (uint8_t nodeID)
169
165
{ // Master will return and send 00 address for a nodeID with address 0, -1 if not found
170
166
171
- // if (nodeID == _nodeID) return mesh_address;
167
+ // if (nodeID == _nodeID) return mesh_address;
172
168
if (!nodeID) return 0 ;
173
169
if (mesh_address == MESH_DEFAULT_ADDRESS) return -2 ;
174
170
175
171
// Lets say 0 if nodeID 0, -1 if write failed or timed out, -2 if not found in list or address is default,
176
172
#if !defined(MESH_NOMASTER)
177
- if (!getNodeID ()) { // Master Node
173
+ if (!getNodeID ()) { // Master Node
178
174
for (uint8_t i = 0 ; i < addrListTop; i++) {
179
175
if (addrList[i].nodeID == nodeID) {
180
176
return addrList[i].address ;
@@ -209,7 +205,7 @@ int16_t RF24Mesh::getNodeID(uint16_t address)
209
205
if (mesh_address == MESH_DEFAULT_ADDRESS) return -2 ;
210
206
211
207
#if !defined(MESH_NOMASTER)
212
- if (!mesh_address) { // Master Node
208
+ if (!mesh_address) { // Master Node
213
209
for (uint8_t i = 0 ; i < addrListTop; i++) {
214
210
if (addrList[i].address == address) {
215
211
return addrList[i].nodeID ;
@@ -302,7 +298,7 @@ uint16_t RF24Mesh::renewAddress(uint32_t timeout)
302
298
bool RF24Mesh::requestAddress (uint8_t level)
303
299
{
304
300
RF24NetworkHeader header (MESH_MULTICAST_ADDRESS, NETWORK_POLL);
305
- // Find another radio, starting with level 0 multicast
301
+ // Find another radio, starting with level 0 multicast
306
302
IF_MESH_DEBUG (printf_P (PSTR (" %u: MSH Poll\n " ), millis ()));
307
303
network.multicast (header, 0 , 0 , level);
308
304
@@ -319,7 +315,7 @@ bool RF24Mesh::requestAddress(uint8_t level)
319
315
if (network.update () == NETWORK_POLL) {
320
316
321
317
memcpy (&contactNode[pollCount], &network.frame_buffer [0 ], sizeof (uint16_t ));
322
- if (pollCount > 0 && contactNode[pollCount] != contactNode[pollCount - 1 ]) { // Drop duplicate polls to help prevent duplicate requests
318
+ if (pollCount > 0 && contactNode[pollCount] != contactNode[pollCount - 1 ]) { // Drop duplicate polls to help prevent duplicate requests
323
319
++pollCount;
324
320
}
325
321
else {
@@ -418,20 +414,20 @@ void RF24Mesh::setStaticAddress(uint8_t nodeID, uint16_t address)
418
414
419
415
void RF24Mesh::setAddress (uint8_t nodeID, uint16_t address, bool searchBy)
420
416
{
421
- // Look for the node in the list
417
+ // Look for the node in the list
422
418
for (uint8_t i = 0 ; i < addrListTop; i++) {
423
419
if (searchBy == false ) {
424
420
if (addrList[i].nodeID == nodeID) {
425
421
addrList[i].address = address;
426
422
#if defined(__linux) && !defined(__ARDUINO_X86__)
427
423
saveDHCP ();
428
424
#endif
429
- return ; // Found & set, complete
425
+ return ; // Found & set, complete
430
426
}
431
427
}
432
428
else { // Search by address, set the nodeID
433
429
if (addrList[i].address == address) {
434
- // printf("*** Addr 0%o Found, reassign fr ID %d to ID %d ***\n", addrList[i].address, addrList[i].nodeID, nodeID);
430
+ // printf("*** Addr 0%o Found, reassign fr ID %d to ID %d ***\n", addrList[i].address, addrList[i].nodeID, nodeID);
435
431
addrList[i].nodeID = nodeID;
436
432
#if defined(__linux) && !defined(__ARDUINO_X86__)
437
433
saveDHCP ();
@@ -445,7 +441,7 @@ void RF24Mesh::setAddress(uint8_t nodeID, uint16_t address, bool searchBy)
445
441
addrList = (addrListStruct*)realloc (addrList, (addrListTop + MESH_MEM_ALLOC_SIZE) * sizeof (addrListStruct));
446
442
}
447
443
addrList[addrListTop].address = address;
448
- addrList[addrListTop++].nodeID = nodeID; // Set the value AND increment Top without another line of code
444
+ addrList[addrListTop++].nodeID = nodeID; // Set the value AND increment Top without another line of code
449
445
#if defined(__linux) && !defined(__ARDUINO_X86__)
450
446
saveDHCP ();
451
447
#endif
@@ -517,14 +513,14 @@ void RF24Mesh::DHCP()
517
513
uint16_t m = fwd_by;
518
514
uint8_t count = 0 ;
519
515
520
- while (m) { // Octal addresses convert nicely to binary in threes. Address 03 = B011 Address 033 = B011011
521
- m >>= 3 ; // Find out how many digits are in the octal address
516
+ while (m) { // Octal addresses convert nicely to binary in threes. Address 03 = B011 Address 033 = B011011
517
+ m >>= 3 ; // Find out how many digits are in the octal address
522
518
count += 3 ;
523
519
}
524
- shiftVal = count; // Now we know how many bits to shift when adding a child node 1-5 (B001 to B101) to any address
520
+ shiftVal = count; // Now we know how many bits to shift when adding a child node 1-5 (B001 to B101) to any address
525
521
}
526
522
else {
527
- // If request is coming from level 1, add an extra child to the master
523
+ // If request is coming from level 1, add an extra child to the master
528
524
extraChild = 1 ;
529
525
}
530
526
@@ -548,22 +544,22 @@ void RF24Mesh::DHCP()
548
544
if (!found) {
549
545
header.type = NETWORK_ADDR_RESPONSE;
550
546
header.to_node = header.from_node ;
551
- // This is a routed request to 00
547
+ // This is a routed request to 00
552
548
553
549
setAddress (header.reserved , newAddress);
554
550
// without this delay, address renewal fails for children with slower execution speed
555
551
#if defined(SLOW_ADDR_POLL_RESPONSE)
556
552
delay (SLOW_ADDR_POLL_RESPONSE);
557
553
#endif // defined (SLOW_ADDR_POLL_RESPONSE)
558
554
559
- if (header.from_node != MESH_DEFAULT_ADDRESS) { // Is NOT node 01 to 05
560
- // delay(2);
555
+ if (header.from_node != MESH_DEFAULT_ADDRESS) { // Is NOT node 01 to 05
556
+ // delay(2);
561
557
if (!network.write (header, &newAddress, sizeof (newAddress))) {
562
558
network.write (header, &newAddress, sizeof (newAddress));
563
559
}
564
560
}
565
561
else {
566
- // delay(2);
562
+ // delay(2);
567
563
network.write (header, &newAddress, sizeof (newAddress), header.to_node );
568
564
}
569
565
0 commit comments