Skip to content

Commit

Permalink
Initial implementation of FINDER message on RX
Browse files Browse the repository at this point in the history
  • Loading branch information
maniacbug committed Dec 20, 2011
1 parent 99f61e4 commit 879fb9a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
13 changes: 12 additions & 1 deletion tests/unit/README
Original file line number Diff line number Diff line change
@@ -1 +1,12 @@
These unit tests only work on Maple.
These unit tests only work on Maple. This test runs on a Maple,
as node #00. One other node is expected on node #01, running the
"unit_rx" sketch, which runs on Arduino.

In the future, it would be interesting to write a test which enumerated
the entire tree. Each node could implement a "child finder", where it
sends a message to each child. Upon receiving the message, each child
sends the message out to ITS children, AND sends a "Hello" to the base node.

This requires a 'F' finder request. For the response, we can re-use
the 'E' echo response. The 'E' echo system presumes that the base is
the requestor and the RX nodes are the responder.
53 changes: 53 additions & 0 deletions tests/unit_rx/unit_rx.pde
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ uint16_t old_first;
// Message buffer space
uint8_t message[32];

void send_finder_request(void);

void setup(void)
{
Serial.begin(57600);
Expand Down Expand Up @@ -107,6 +109,18 @@ void loop(void)
printf_P(PSTR("%lu: APP Received ECHO request from %o\n\r"),millis(),from);
network.write(header = RF24NetworkHeader(from,'E'),message,sizeof(message));
break;

// Find child nodes
case 'F':
network.read(header,message,sizeof(message));
from = header.from_node;
printf_P(PSTR("%lu: APP Received FINDER request from %o\n\r"),millis(),from);

// Send an 'E' Echo response back to the BASE
network.write(header = RF24NetworkHeader(00,'E'),message,sizeof(message));

send_finder_request();
break;

// Unrecognized message type
default:
Expand All @@ -116,4 +130,43 @@ void loop(void)
};
}
}

// 'Finder' message
void send_finder_request(void)
{
// Send a 'F' Finder message to each child. Only do this if it's possible for us
// to have children. Four-digit nodes (e.g. 05555) cannot have children
if ( ! ( this_node & 07000 ) )
{
// Figure out the address of the first child. e.g. if our node is 045, our
// first child is 0145. So we need to shift 01 up enough places to be the
// highest digit
uint16_t child = 01;
uint16_t temp = this_node;
while ( temp )
{
child <<= 3;
temp >>= 3;
}

// Loop through each child address, and send an 'F' Finder message to them.
uint16_t to_node = child + this_node;
int i = 5;
while ( i-- )
{
RF24NetworkHeader header(to_node,'F');
bool ok = network.write(header,message,sizeof(message));
to_node += child;

// If it worked, let the base know to expect a response
if ( ok )
{
printf_P(PSTR("%lu: APP Sent FINDER request to %o\n\r"),millis(),to_node);
network.write(header = RF24NetworkHeader(00,'F'),&to_node,sizeof(to_node));
}
else
printf_P(PSTR("%lu: APP Failed sending FINDER request to %o\n\r"),millis(),to_node);
}
}
}
// vim:ai:cin:sts=2 sw=2 ft=cpp

0 comments on commit 879fb9a

Please sign in to comment.