diff --git a/RF24Gateway.cpp b/RF24Gateway.cpp index 2177915..db689f5 100644 --- a/RF24Gateway.cpp +++ b/RF24Gateway.cpp @@ -2,6 +2,7 @@ #include "RF24Gateway.h" +#include "RF24Mesh/RF24Mesh_config.h" /***************************************************************************************/ @@ -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); @@ -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{ @@ -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; @@ -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 @@ -521,4 +531,6 @@ void printPayload(std::string buffer, std::string debugMsg = "") { void printPayload(char *buffer, int nread, std::string debugMsg = "") { -} \ No newline at end of file +} + +/***************************************************************************************/ diff --git a/examples/ncurses/RF24Gateway_ncurses.cpp b/examples/ncurses/RF24Gateway_ncurses.cpp index 13c7594..bff4509 100644 --- a/examples/ncurses/RF24Gateway_ncurses.cpp +++ b/examples/ncurses/RF24Gateway_ncurses.cpp @@ -37,7 +37,7 @@ #include #include -//#include +#include #include #include #include @@ -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(); @@ -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++) { @@ -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));