Skip to content

Commit

Permalink
A bit of cleanup and additions for RF24Mesh testing
Browse files Browse the repository at this point in the history
- No network ACKs for address request/response
- cleanup some stuff
  • Loading branch information
TMRh20 committed Oct 1, 2014
1 parent 324e413 commit 414192f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
20 changes: 8 additions & 12 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,17 +470,14 @@ bool RF24Network::_write(RF24NetworkHeader& header,const void* message, size_t l
bool RF24Network::write(uint16_t to_node, uint8_t directTo) // Direct To: 0 = First Payload, standard routing, 1=routed payload, 2=directRoute to host, 3=directRoute to Route
{
bool ok = false;
bool multicast = 0; // Radio ACK requested = 0
//const uint16_t fromAddress = frame_buffer[0] | (frame_buffer[1] << 8);

// Throw it away if it's not a valid address
if ( !is_valid_address(to_node) )
return false;

//Load info into our conversion structure, and get the converted address info
conversion.send_node = to_node;
conversion.send_pipe = directTo;
conversion.multicast = multicast;
logicalToPhysicalStruct conversion = { to_node,directTo,0};
logicalToPhysicalAddress(&conversion);

IF_SERIAL_DEBUG(printf_P(PSTR("%lu: MAC Sending to 0%o via 0%o on pipe %x\n\r"),millis(),to_node,conversion.send_node,conversion.send_pipe));
Expand All @@ -491,20 +488,21 @@ bool RF24Network::write(uint16_t to_node, uint8_t directTo) // Direct To: 0 = F

if(!ok){ IF_SERIAL_DEBUG_ROUTING( printf_P(PSTR("%lu: MAC Send fail to 0%o via 0%o on pipe %x\n\r"),millis(),to_node,conversion.send_node,conversion.send_pipe);); }

if( directTo == TX_ROUTED && ok && conversion.send_node == to_node && frame_buffer[6] != NETWORK_ACK ){
if( directTo == TX_ROUTED && ok && conversion.send_node == to_node && frame_buffer[6] != NETWORK_ACK && frame_buffer[6] != NETWORK_REQ_ADDRESS && frame_buffer[6] != NETWORK_ADDR_RESPONSE){

RF24NetworkHeader& header = * reinterpret_cast<RF24NetworkHeader*>(frame_buffer);
header.type = NETWORK_ACK; // Set the payload type to NETWORK_ACK
header.to_node = header.from_node; // Change the 'to' address to the 'from' address

dynLen=8;

conversion.send_node=header.from_node;
conversion.send_pipe = TX_ROUTED;
//conversion.send_node=header.from_node;
//conversion.send_pipe = TX_ROUTED;
conversion = { header.from_node,TX_ROUTED,0};
logicalToPhysicalAddress(&conversion);

//Write the data using the resulting physical address
write_to_pipe(conversion.send_node, conversion.send_pipe, multicast);
write_to_pipe(conversion.send_node, conversion.send_pipe, conversion.multicast);

dynLen=0;
IF_SERIAL_DEBUG_ROUTING( printf_P(PSTR("%lu MAC: Route OK to 0%o ACK sent to 0%o\n"),millis(),to_node,header.to_node); );
Expand All @@ -517,7 +515,7 @@ bool RF24Network::write(uint16_t to_node, uint8_t directTo) // Direct To: 0 = F
radio.startListening();
#endif

if( ok && (conversion.send_node != to_node) && (directTo==0 || directTo == 3 )){
if( ok && conversion.send_node != to_node && (directTo==0 || directTo == 3 )){
uint32_t reply_time = millis();
while( update() != NETWORK_ACK){
if(millis() - reply_time > routeTimeout){
Expand Down Expand Up @@ -592,12 +590,11 @@ bool RF24Network::logicalToPhysicalAddress(logicalToPhysicalStruct *conversionIn
bool RF24Network::write_to_pipe( uint16_t node, uint8_t pipe, bool multicast )
{
bool ok = false;

uint64_t out_pipe = pipe_address( node, pipe );

#if !defined (DUAL_HEAD_RADIO)
// Open the correct pipe for writing.

// First, stop listening so we can talk
radio.stopListening();
radio.openWritingPipe(out_pipe);
Expand Down Expand Up @@ -760,7 +757,6 @@ bool RF24Network::is_valid_address( uint16_t node )
{
result = false;
IF_SERIAL_DEBUG_MINIMAL(printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"),node););
printf_P(PSTR("*** WARNING *** Invalid address 0%o\n\r"),node);
break;
}
node >>= 3;
Expand Down
17 changes: 9 additions & 8 deletions RF24Network.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,27 @@
#define MIN_USER_DEFINED_HEADER_TYPE 0
#define MAX_USER_DEFINED_HEADER_TYPE 127

/** System Discard Types */

#define NETWORK_ACK_REQUEST 128
#define NETWORK_ACK 129
#define NETWORK_REQ_ADDRESS 151
#define NETWORK_ADDR_RESPONSE 152

/**System-Sub Types (0-255)*/
//#define NETWORK_REQ_STREAM 11;
#define NETWORK_POLL 130

/** System retained types */
#define NETWORK_FIRST_FRAGMENT 148
#define NETWORK_MORE_FRAGMENTS 149
#define NETWORK_LAST_FRAGMENT 150
/* System retained - response messages */
#define NETWORK_REQ_ADDRESS 151
#define NETWORK_ADDR_RESPONSE 152



/** Defines for handling written payloads */
#define TX_NORMAL 0
#define TX_ROUTED 1
#define USER_TX_TO_PHYSICAL_ADDRESS 2
#define USER_TX_TO_LOGICAL_ADDRESS 3
#define USER_TX_TO_PHYSICAL_ADDRESS 2 //no network ACK
#define USER_TX_TO_LOGICAL_ADDRESS 3 // network ACK
#define USER_TX_MULTICAST 4

/** System defines */
Expand Down Expand Up @@ -407,7 +408,7 @@ class RF24Network
uint16_t send_node;
uint8_t send_pipe;
bool multicast;
}conversion;
};

bool logicalToPhysicalAddress(logicalToPhysicalStruct *conversionInfo);

Expand Down

0 comments on commit 414192f

Please sign in to comment.