bool RF24Gateway::begin(bool configTUN, bool meshEnable, uint16_t address, uint8_t mesh_nodeID, rf24_datarate_e data_rate, uint8_t _channel) { #if(DEBUG>=1) printf("GW Begin\n"); printf("Config Device address 0%o nodeID %d\n",address,mesh_nodeID); #endif config_TUN = configTUN; ///FIX channel = _channel;//97; dataRate = data_rate; configDevice(address); mesh_enabled = meshEnable; thisNodeID = mesh_nodeID; 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{ if(!mesh_nodeID){ mesh_nodeID = 253; } mesh.setNodeID(mesh_nodeID); //Try not to conflict with any low-numbered node-ids } mesh.begin(channel,data_rate); thisNodeAddress = mesh.mesh_address; }else{ radio.begin(); delay(5); const uint16_t this_node = address; radio.setDataRate(dataRate); radio.setChannel(channel); network.begin(/*node address*/ this_node); thisNodeAddress = this_node; } network.multicastRelay=1; //#if (DEBUG >= 1) radio.printDetails(); //#endif return true; }
int main(int argc, char *argv[]){ unsigned char stop, temp; unsigned char cmd; unsigned char arg1, arg2; char arg1buf[4], arg2buf[4]; packet recievepkt; packet sendpkt; int fd_joy; // File Descriptor for joystick int temp1; struct js_event e; temp1 = 0; // Set first time stamp to zero fd_joy = open_joystick(); // /Initalize the joystick // printf("fd_joy: %d\n", fd_joy); strncpy(device, argv[1], DEVICE_MAX_SIZE); //set up serial port if((fd = configDevice()) < 2){ perror("Error opening/configuring device\n"); return -1; } menu(); //set handler for close command signal(SIGUSR2, catchClose); signal(SIGTERM, catchClose); //create timer for ping pid = fork(); if (pid < 0) printf("Error creating ping timer process\n"); else if(pid == 0){ //die if parent dies prctl(PR_SET_PDEATHSIG, SIGHUP); //set alarm for ping timeout signal(SIGALRM, sendPing); //prime Timeout reset handler signal(SIGUSR1, catchTimeoutReset); alarm(PING_INTERVAL); for(timeouts = 0; timeouts < PING_RETRIES;){ //spin wheels. exit if ping timeout occurs } //kill parent process if ping timeout printf("Ping timeout. %d unanswered pings\n", timeouts); //tell parent to exit kill(getppid(), SIGKILL); return 1; } int readcount; char zeroflag; //main control loop for(stop = 0; stop <= 0;){ //cmd = 'V'; //arg1 = 0; //arg2 = 0; /*scanf("%c %s %s%c", &cmd, arg1buf, arg2buf, NULL); //get command //strcpy(arg1buf, "Z"); arg1 = (unsigned char)atoi(arg1buf); arg2 = (unsigned char)atoi(arg2buf); if(arg1 == 0){ arg1 = 1; } if(arg2 == 0){ arg2 = 1; }*/ readcount = read (fd_joy, &e, sizeof(e)); //printf("servo: %d\r", e.time); //printf("bytes read from joystick: %d\n", readcount); //if(e.time > temp1) { //printf("Bryan\n"); if(e.type == 1 && e.value == 1){ if(e.time > temp1){ button_press(e.number); temp1 = e.time; } } if(e.type == 2 /*&& e.value != 0*/){ if(!zeroflag){ axis_press(e.number, e.value); } //set zeroflag if event input zero //necessary to not keep resending packages //when in the zero (stopped) position zeroflag = (e.value == 0) ? 1 : 0; //printf("zeroflag %c\n", zeroflag); } } //while((temp = getchar()) != '\n' && temp != EOF); //clear buffer //printf("CMD: %c ARG1: %c ARG2: %c\n", cmd, arg1, arg2); //stop = parseCommand(cmd, arg1, arg2); } close(fd); //tell child to exit kill(pid, SIGUSR2); t1.join(); scanf("", NULL); return 0; }