Skip to content

Commit

Permalink
Fix ncurses example, channel setting with RF24Mesh
Browse files Browse the repository at this point in the history
  • Loading branch information
TMRh20 committed Apr 7, 2015
1 parent 78e716a commit fd3e767
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
32 changes: 22 additions & 10 deletions RF24Gateway.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@


#include "RF24Gateway.h"
#include "RF24Mesh/RF24Mesh_config.h"

/***************************************************************************************/

Expand Down Expand Up @@ -36,7 +37,9 @@ bool RF24Gateway::begin(bool configTUN, bool meshEnable, uint16_t address, uint8
config_TUN = configTUN;

///FIX

channel = _channel;//97;

dataRate = data_rate;

configDevice(address);
Expand All @@ -45,7 +48,11 @@ bool RF24Gateway::begin(bool configTUN, bool meshEnable, uint16_t address, uint8
thisNodeAddress = address;

if(meshEnable){

// GW radio channel setting takes precedence over mesh_default_channel
if(channel == 97 && MESH_DEFAULT_CHANNEL != 97){
channel = MESH_DEFAULT_CHANNEL;
}

if(!thisNodeAddress && !mesh_nodeID){
mesh.setNodeID(0);
}else{
Expand All @@ -54,22 +61,25 @@ bool RF24Gateway::begin(bool configTUN, bool meshEnable, uint16_t address, uint8
}
mesh.setNodeID(mesh_nodeID); //Try not to conflict with any low-numbered node-ids
}
mesh.setChannel(channel);
mesh.begin();
mesh.begin(channel,data_rate);
thisNodeAddress = mesh.mesh_address;
}else{
radio.begin();
delay(5);
const uint16_t this_node = address;
network.begin(/*channel*/ channel, /*node address*/ this_node);
radio.setDataRate(dataRate);
radio.setChannel(channel);

network.begin(/*node address*/ this_node);
thisNodeAddress = this_node;

}
network.multicastRelay=1;

radio.setDataRate(dataRate);
#if (DEBUG >= 1)

//#if (DEBUG >= 1)
radio.printDetails();
#endif
//#endif


return true;
Expand Down Expand Up @@ -128,11 +138,11 @@ int RF24Gateway::allocateTunDevice(char *dev, int flags, uint16_t address) {
// Create device
if(ioctl(fd, TUNSETIFF, (void *) &ifr) < 0) {
//close(fd);
#if (DEBUG >= 1)
//#if (DEBUG >= 1)
std::cerr << "RF24Gw: Error: enabling TUNSETIFF" << std::endl;
std::cerr << "RF24Gw: If changing from TAP/TUN, run 'sudo ip link delete tun_nrf24' to remove the interface" << std::endl;
return -1;
#endif
//#endif
}

//Make persistent
Expand Down Expand Up @@ -521,4 +531,6 @@ void printPayload(std::string buffer, std::string debugMsg = "") {
void printPayload(char *buffer, int nread, std::string debugMsg = "") {


}
}

/***************************************************************************************/
19 changes: 13 additions & 6 deletions examples/ncurses/RF24Gateway_ncurses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <fstream>

#include <stdlib.h>
//#include <net/if.h>
#include <linux/if.h>
#include <net/if_arp.h>
#include <sys/ioctl.h>
#include <linux/sockios.h>
Expand Down Expand Up @@ -90,6 +90,12 @@ int main() {

gw.begin();

//uint8_t nodeID = 22;
//gw.begin(nodeID,3,RF24_2MBPS);

//uint16_t address = 0;
//gw.begin(address,3,RF24_2MBPS);

/** Setup NCurses**/
/*******************************/
win = initscr();
Expand Down Expand Up @@ -219,17 +225,18 @@ void drawMain(){
wprintw(win,"RF24Gateway Ncurses Interface by TMRh20 - 2015\n");
whline(win,ACS_HLINE, maxY-2);
attroff(COLOR_PAIR(1));

refresh();
/** Display Network Interface Info **/
/*******************************/

retryIF:


//Interface Information
struct ifaddrs *ifap, *ifa;
int family,s,n;
char host[NI_MAXHOST];


retryIF:

getifaddrs (&ifap);
for (ifa = ifap, n=0; ifa != NULL; ifa = ifa->ifa_next, n++) {
Expand Down Expand Up @@ -294,12 +301,12 @@ void drawHelp(){

void drawCfg(bool isConf){

drawMain();
if(isConf){drawMain();}
nocbreak();
echo();
timeout(30000);

sleep(0.5);
sleep(1);
wattron(win,COLOR_PAIR(1));
mvwprintw(win,5,1, isConf ? "IP Configuration\n" : "**Interface Not Configured:**\n");
wattroff(win,COLOR_PAIR(1));
Expand Down

0 comments on commit fd3e767

Please # to comment.