Stripped down extraneous pipe opens, and other un-needed things.

This commit is contained in:
maniacbug 2011-04-30 21:10:33 -07:00
parent 38392fa5f4
commit 39b15c8b55
1 changed files with 20 additions and 29 deletions

View File

@ -32,14 +32,12 @@ RF24 radio(8,9);
// Leave open to be the 'ping' transmitter // Leave open to be the 'ping' transmitter
const short role_pin = 7; const short role_pin = 7;
const short led_pin = 13; // flash the led when a packet has been sent
// //
// Topology // Topology
// //
// Radio pipe addresses for the 2 nodes to communicate. // Radio pipe address for the 2 nodes to communicate.
const uint64_t pipes[2] = { 0xE8E8F0F0E1LL, 0xE8E8F0F0D2LL }; const uint64_t pipe = 0xE8E8F0F0E1LL;
// //
// Role management // Role management
@ -99,27 +97,24 @@ void setup(void)
// Open pipes to other nodes for communication // Open pipes to other nodes for communication
// //
// This simple sketch opens two pipes for these two nodes to communicate // This simple sketch opens a single pipes for these two nodes to communicate
// back and forth. // back and forth. One listens on it, the other talks to it.
// Open 'our' pipe for writing
// Open the 'other' pipe for reading, in position #1 (we can have up to 5 pipes open for reading)
if ( role == role_ping_out ) if ( role == role_ping_out )
{ {
radio.openWritingPipe(pipes[0]); radio.openWritingPipe(pipe);
radio.openReadingPipe(1,pipes[1]);
} }
else else
{ {
radio.openWritingPipe(pipes[1]); radio.openReadingPipe(1,pipe);
radio.openReadingPipe(1,pipes[0]);
} }
// //
// Start listening // Start listening
// //
radio.startListening(); if ( role == role_pong_back )
radio.startListening();
// //
// Dump the configuration of the rf unit for debugging // Dump the configuration of the rf unit for debugging
@ -130,6 +125,8 @@ void setup(void)
void loop(void) void loop(void)
{ {
static uint32_t id = 0;
// //
// Ping out role. Repeatedly send the current time // Ping out role. Repeatedly send the current time
// //
@ -143,16 +140,13 @@ void loop(void)
if ( radio.isAckPayloadAvailable() ) if ( radio.isAckPayloadAvailable() )
{ {
static char response[32]; radio.read(&id,sizeof(id));
radio.read(response,32); printf("Ack: [%lu] ",id);
printf("Ack: [%s]",response);
} }
printf(" OK\n\r"); printf("OK\n\r");
// Try again later // Try again soon
digitalWrite(led_pin,HIGH); delay(2000);
delay(3000);
digitalWrite(led_pin,LOW);
} }
// //
@ -165,7 +159,7 @@ void loop(void)
if ( radio.available() ) if ( radio.available() )
{ {
// Dump the payloads until we've gotten everything // Dump the payloads until we've gotten everything
unsigned long got_time; static unsigned long got_time;
boolean done = false; boolean done = false;
while (!done) while (!done)
{ {
@ -176,13 +170,10 @@ void loop(void)
printf("Got payload %lu\n",got_time); printf("Got payload %lu\n",got_time);
} }
// Add an ack packet for the next time around // Add an ack packet for the next time around. This is a simple
static unsigned id = 0; // packet counter
static char pl_buffer[10]; radio.writeAckPayload( 1, &id, sizeof(id) );
memset(pl_buffer,' ',10); ++id;
pl_buffer[9] = 0;
snprintf(pl_buffer,10,"id %04x",id++);
radio.writeAckPayload( 1, pl_buffer, 10 );
} }
} }
} }