Skip to content

Commit

Permalink
Increase throughput, adjust delays, etc
Browse files Browse the repository at this point in the history
- Reduce routeTimeout variable to 1/3 of previous
- Only respond to network polls if using an address other than 04444
(RF24Mesh default address)
- Add delay equal to parent pipe to NETWORK_POLL responses

- Modify the write() sequence as follows:
1. Leave the radio in standby-II mode during fragmented writes
2. Call txStandby and setAutoAck in write() function for fragmented
writes
3.  Remove delay for multicast writes (increases throughput)
  • Loading branch information
TMRh20 committed Dec 14, 2015
1 parent 53b0a75 commit baacbd2
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions RF24Network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void RF24Network::begin(uint8_t _channel, uint16_t _node_address )

// Use different retry periods to reduce data collisions
uint8_t retryVar = (((node_address % 6)+1) *2) + 3;
radio.setRetries(retryVar, 5);
radio.setRetries(retryVar, 5); // max about 85ms per attempt
txTimeout = 25;
routeTimeout = txTimeout*9; // Adjust for max delay per node
routeTimeout = txTimeout*3; // Adjust for max delay per node within a single chain


#if defined (DUAL_HEAD_RADIO)
Expand Down Expand Up @@ -233,11 +233,12 @@ uint8_t RF24Network::update(void)
if( header->to_node == 0100){


if(header->type == NETWORK_POLL ){
if(header->type == NETWORK_POLL && node_address != 04444 ){
if( !(networkFlags & FLAG_NO_POLL) ){
header->to_node = header->from_node;
header->from_node = node_address;
write(header->to_node,USER_TX_TO_PHYSICAL_ADDRESS);
delay(parent_pipe);
write(header->to_node,USER_TX_TO_PHYSICAL_ADDRESS);
}
continue;
}
Expand Down Expand Up @@ -714,7 +715,8 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, uint16_t

uint8_t retriesPerFrag = 0;
uint8_t type = header.type;

bool ok = 0;

while (fragment_id > 0) {

//Copy and fill out the header
Expand All @@ -737,8 +739,8 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, uint16_t

//Try to send the payload chunk with the copied header
frame_size = sizeof(RF24NetworkHeader)+fragmentLen;
bool ok = _write(header,((char *)message)+offset,fragmentLen,writeDirect);
ok = _write(header,((char *)message)+offset,fragmentLen,writeDirect);

if (!ok) {
delay(2);
++retriesPerFrag;
Expand All @@ -749,7 +751,7 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, uint16_t
msgCount++;
}

if(writeDirect != 070){ delay(2); } //Delay 2ms between sending multicast payloads
//if(writeDirect != 070){ delay(2); } //Delay 2ms between sending multicast payloads

if (!ok && retriesPerFrag >= 3) {
IF_SERIAL_DEBUG_FRAGMENTATION(printf("%lu: FRG TX with fragmentID '%d' failed after %d fragments. Abort.\n\r",millis(),fragment_id,msgCount););
Expand All @@ -765,8 +767,13 @@ bool RF24Network::write(RF24NetworkHeader& header,const void* message, uint16_t
}
header.type = type;
#if !defined (DUAL_HEAD_RADIO)
if(networkFlags & FLAG_FAST_FRAG){
radio.startListening();
if(networkFlags & FLAG_FAST_FRAG){
ok = radio.txStandBy(txTimeout);
}
radio.startListening();
radio.setAutoAck(0,0);
if(!ok){
return false;
}
#endif
networkFlags &= ~FLAG_FAST_FRAG
Expand Down Expand Up @@ -915,7 +922,9 @@ bool RF24Network::write(uint16_t to_node, uint8_t directTo) // Direct To: 0 = F
uint32_t reply_time = millis();

while( update() != NETWORK_ACK){
delayMicroseconds(900);
#if defined (RF24_LINUX)
delayMicroseconds(900);
#endif
if(millis() - reply_time > routeTimeout){
#if defined (RF24_LINUX)
IF_SERIAL_DEBUG_ROUTING( printf_P(PSTR("%u: MAC Network ACK fail from 0%o via 0%o on pipe %x\n\r"),millis(),to_node,conversion.send_node,conversion.send_pipe); );
Expand Down Expand Up @@ -1012,10 +1021,13 @@ bool RF24Network::write_to_pipe( uint16_t node, uint8_t pipe, bool multicast )
if(multicast){ radio.setAutoAck(0,0);}else{radio.setAutoAck(0,1);}

radio.openWritingPipe(out_pipe);
radio.writeFast(frame_buffer, frame_size,multicast);
ok = radio.txStandBy(txTimeout);

ok = radio.writeFast(frame_buffer, frame_size,multicast);

radio.setAutoAck(0,0);
if(!(networkFlags & FLAG_FAST_FRAG)){
ok = radio.txStandBy(txTimeout);
radio.setAutoAck(0,0);
}

#else
radio1.openWritingPipe(out_pipe);
Expand Down

1 comment on commit baacbd2

@TMRh20
Copy link
Member Author

@TMRh20 TMRh20 commented on baacbd2 Dec 14, 2015

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.