Skip to content

Commit 54e2eb5

Browse files
committed
Improve transfer speeds
1. Only write if network.available() returns 0 2. Rewrite if writing to TUN device fails 3. Lower delay from 2 to 1ms 4. Disable debug by default 5. Change channel to 97 from 90
1 parent 10636c6 commit 54e2eb5

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

rf24totun.cpp

+11-12
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ void radioRxTxThreadFunction() {
137137

138138
network.update();
139139

140-
/**
141-
* RX section
142-
*/
140+
//RX section
141+
143142
while ( network.available() ) { // Is there anything ready for us?
144143

145144
RF24NetworkHeader header; // If so, grab it and print it out
@@ -163,10 +162,10 @@ void radioRxTxThreadFunction() {
163162

164163
network.update();
165164

166-
/**
167-
* TX section
168-
*/
169-
if (!radioTxQueue.empty()) {
165+
166+
// TX section
167+
168+
if(!radioTxQueue.empty() && !radio.available() ) {
170169
Message msg = radioTxQueue.pop();
171170

172171
if (PRINT_DEBUG >= 1) {
@@ -187,7 +186,7 @@ void radioRxTxThreadFunction() {
187186
}
188187
} //End Tx
189188

190-
delay(2);
189+
delay(1);
191190

192191
} catch(boost::thread_interrupted&) {
193192
std::cerr << "radioRxThreadFunction is stopped" << std::endl;
@@ -266,7 +265,7 @@ void tunTxThreadFunction() {
266265
if (msg.getLength() > 0) {
267266

268267
size_t writtenBytes = write(tunFd, msg.getPayload(), msg.getLength());
269-
268+
if(!writtenBytes){ writtenBytes = write(tunFd, msg.getPayload(), msg.getLength()); }
270269
if (writtenBytes != msg.getLength()) {
271270
std::cerr << "Tun: Less bytes written to tun/tap device then requested." << std::endl;
272271
} else {
@@ -382,13 +381,13 @@ int main(int argc, char **argv) {
382381
std::cout << "Choose an address: Enter 0 for master, 1 for child, 2 for Master with 1 Arduino routing node (02), 3 for Child with Arduino routing node (CTRL+C to exit) \n>";
383382
std::getline(std::cin,input);
384383

385-
if(input.length() == 1) {
384+
if(input.length() > 0) {
386385
myChar = input[0];
387386
if(myChar == '0'){
388387
thisNodeAddr = 00;
389-
otherNodeAddr = 01;
388+
otherNodeAddr = 1;
390389
}else if(myChar == '1') {
391-
thisNodeAddr = 01;
390+
thisNodeAddr = 1;
392391
otherNodeAddr = 00;
393392
}else if(myChar == '2') {
394393
thisNodeAddr = 00;

rf24totun.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
#include <RF24Network/RF24Network.h>
5959

6060

61-
#define PRINT_DEBUG 1
61+
#define PRINT_DEBUG 0
6262

6363
#ifndef IFF_MULTI_QUEUE
6464
#define IFF_MULTI_QUEUE 0x0100
@@ -81,7 +81,7 @@ RF24 radio(RPI_V2_GPIO_P1_15, RPI_V2_GPIO_P1_24, BCM2835_SPI_SPEED_8MHZ);
8181
RF24Network network(radio);
8282
uint16_t thisNodeAddr; /**< Address of our node in Octal format (01,021, etc) */
8383
uint16_t otherNodeAddr; /**< Address of the other node */
84-
const uint8_t channel = 90;
84+
const uint8_t channel = 97;
8585
unsigned long packets_sent; /**< How many have we sent already */
8686

8787
/**

0 commit comments

Comments
 (0)