Ported Arduino RF24Network library.
Revision 1:b5836d9f8de5, committed 2015-03-09
- Comitter:
- zcw607
- Date:
- Mon Mar 09 21:23:56 2015 +0000
- Parent:
- 0:df0a8886a0e9
- Commit message:
- Clean up errors
Changed in this revision
diff -r df0a8886a0e9 -r b5836d9f8de5 RF24Network.cpp --- a/RF24Network.cpp Mon Mar 09 20:49:13 2015 +0000 +++ b/RF24Network.cpp Mon Mar 09 21:23:56 2015 +0000 @@ -57,7 +57,7 @@ while ( radio.available(&pipe_num) ) { // Dump the payloads until we've gotten everything - boolean done = false; + bool done = false; while (!done) { // Fetch the payload, and see if this was the last one. @@ -66,8 +66,8 @@ // Read the beginning of the frame as the header const RF24NetworkHeader& header = * reinterpret_cast<RF24NetworkHeader*>(frame_buffer); - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Received on %u %s\n\r"),millis(),pipe_num,header.toString())); - IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast<const uint16_t*>(frame_buffer + sizeof(RF24NetworkHeader));printf_P(PSTR("%lu: NET message %04x\n\r"),millis(),*i)); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Received on %u %s\n\r"),millis(),pipe_num,header.toString())); + //IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast<const uint16_t*>(frame_buffer + sizeof(RF24NetworkHeader));printf_P(PSTR("%lu: NET message %04x\n\r"),millis(),*i)); // Throw it away if it's not a valid address if ( !is_valid_address(header.to_node) ) @@ -106,7 +106,7 @@ { bool result = false; - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Enqueue @%x "),millis(),next_frame-frame_queue)); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Enqueue @%x "),millis(),next_frame-frame_queue)); // Copy the current frame into the frame queue if ( next_frame < frame_queue + sizeof(frame_queue) ) @@ -115,11 +115,11 @@ next_frame += frame_size; result = true; - IF_SERIAL_DEBUG(printf_P(PSTR("ok\n\r"))); + //IF_SERIAL_DEBUG(printf_P(PSTR("ok\n\r"))); } else { - IF_SERIAL_DEBUG(printf_P(PSTR("failed\n\r"))); + //IF_SERIAL_DEBUG(printf_P(PSTR("failed\n\r"))); } return result; @@ -163,7 +163,7 @@ memcpy(&header,frame,sizeof(RF24NetworkHeader)); memcpy(message,frame+sizeof(RF24NetworkHeader),bufsize); - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Received %s\n\r"),millis(),header.toString())); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Received %s\n\r"),millis(),header.toString())); } return bufsize; @@ -181,10 +181,10 @@ if (len) memcpy(frame_buffer + sizeof(RF24NetworkHeader),message,min(frame_size-sizeof(RF24NetworkHeader),len)); - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Sending %s\n\r"),millis(),header.toString())); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: NET Sending %s\n\r"),millis(),header.toString())); if (len) { - IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast<const uint16_t*>(message);printf_P(PSTR("%lu: NET message %04x\n\r"),millis(),*i)); + //IF_SERIAL_DEBUG(const uint16_t* i = reinterpret_cast<const uint16_t*>(message);printf_P(PSTR("%lu: NET message %04x\n\r"),millis(),*i)); } // If the user is trying to send it to himself @@ -232,7 +232,7 @@ send_pipe = 0; } - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Sending to 0%o via 0%o on pipe %x\n\r"),millis(),to_node,send_node,send_pipe)); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Sending to 0%o via 0%o on pipe %x\n\r"),millis(),to_node,send_node,send_pipe)); // First, stop listening so we can talk radio.stopListening(); @@ -275,7 +275,7 @@ } while ( !ok && --attempts ); - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Sent on %lx %S\n\r"),millis(),(uint32_t)out_pipe,ok?PSTR("ok"):PSTR("failed"))); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Sent on %lx %S\n\r"),millis(),(uint32_t)out_pipe,ok?PSTR("ok"):PSTR("failed"))); return ok; } @@ -285,7 +285,7 @@ const char* RF24NetworkHeader::toString(void) const { static char buffer[45]; - snprintf_P(buffer,sizeof(buffer),PSTR("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type); + //snprintf_P(buffer,sizeof(buffer),("id %04x from 0%o to 0%o type %c"),id,from_node,to_node,type); return buffer; } @@ -357,7 +357,7 @@ { // Presumes that this is in fact a child!! - uint16_t child_mask = ( node_mask << 3 ) | 0B111; + uint16_t child_mask = ( node_mask << 3 ) | 7; return node & child_mask ; } @@ -374,7 +374,7 @@ m >>= 3; } - return i & 0B111; + return i & 7; } /******************************************************************/ @@ -385,11 +385,11 @@ while(node) { - uint8_t digit = node & 0B111; + uint8_t digit = node & 7; if (digit < 1 || digit > 5) { result = false; - printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"),node); + //printf_P(("*** WARNING *** Invalid address 0%o\n\r"),node); break; } node >>= 3; @@ -421,9 +421,17 @@ shift -= 4; } - IF_SERIAL_DEBUG(uint32_t* top = reinterpret_cast<uint32_t*>(out+1);printf_P(PSTR("%lu: NET Pipe %i on node 0%o has address %lx%x\n\r"),millis(),pipe,node,*top,*out)); + //IF_SERIAL_DEBUG(uint32_t* top = reinterpret_cast<uint32_t*>(out+1);printf_P(PSTR("%lu: NET Pipe %i on node 0%o has address %lx%x\n\r"),millis(),pipe,node,*top,*out)); return result; } // vim:ai:cin:sts=2 sw=2 ft=cpp + +uint8_t RF24Network::min(uint8_t a, uint8_t b) +{ + if(a < b) + return a; + else + return b; +} \ No newline at end of file
diff -r df0a8886a0e9 -r b5836d9f8de5 RF24Network.h --- a/RF24Network.h Mon Mar 09 20:49:13 2015 +0000 +++ b/RF24Network.h Mon Mar 09 21:23:56 2015 +0000 @@ -171,6 +171,7 @@ uint16_t parent_node; /**< Our parent's node address */ uint8_t parent_pipe; /**< The pipe our parent uses to listen to us */ uint16_t node_mask; /**< The bits which contain signfificant node address information */ + uint8_t min(uint8_t, uint8_t); }; /**
diff -r df0a8886a0e9 -r b5836d9f8de5 Sync.cpp --- a/Sync.cpp Mon Mar 09 20:49:13 2015 +0000 +++ b/Sync.cpp Mon Mar 09 21:23:56 2015 +0000 @@ -64,7 +64,7 @@ switch (header.type) { case 'S': - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: SYN Received sync message\n\r"),millis())); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: SYN Received sync message\n\r"),millis())); network.read(header,&message,sizeof(message)); // Parse the message and update the vars @@ -78,7 +78,7 @@ uint8_t pos = (*mptr++) - 1; uint8_t val = *mptr++; - IF_SERIAL_DEBUG(printf_P(PSTR("%lu: SYN Updated position %u to value %u\n\r"),millis(),pos,val)); + //IF_SERIAL_DEBUG(printf_P(PSTR("%lu: SYN Updated position %u to value %u\n\r"),millis(),pos,val)); app_data[pos] = val; internal_data[pos] = val;