void checkrx( void) { int packetreceived = checkpacket(); int pass = 0; if ( packetreceived ) { if ( rxmode == 0) { // rx startup , bind mode xn_readpayload( rxdata , 15); if ( rxdata[0] == 164 ) {// bind packet rfchannel[0] = rxdata[6]; rfchannel[1] = rxdata[7]; rfchannel[2] = rxdata[8]; rfchannel[3] = rxdata[9]; rxaddress[0] = rxdata[1]; rxaddress[1] = rxdata[2]; rxaddress[2] = rxdata[3]; rxaddress[3] = rxdata[4]; rxaddress[4] = rxdata[5]; rxmode = 123; xn_writerxaddress( rxaddress ); xn_writereg(0x25, rfchannel[chan] ); // Set channel frequency #ifdef SERIAL_INFO printf( " BIND \n"); #endif } } else { // normal mode #ifdef RXDEBUG rxdebug.channelcount[chan]++; rxdebug.packettime = gettime() - lastrxtime; #endif // for longer loop times than 3ms it was skipping 2 channels //chan++; //if (chan > 3 ) chan = 0; nextchannel(); lastrxtime = gettime(); xn_readpayload( rxdata , 15); pass = decodepacket(); if (pass) { #ifdef RXDEBUG packetrx++; #endif failsafetime = lastrxtime; failsafe = 0; } else { #ifdef RXDEBUG rxdebug.failcount++; #endif } }// end normal rx mode }// end packet received unsigned long time = gettime(); // sequence period 12000 if( time - lastrxtime > 9000 && rxmode != 0) {// channel with no reception lastrxtime = time; nextchannel(); } if( time - failsafetime > FAILSAFETIME ) {// failsafe failsafe = 1; rx[0] = 0; rx[1] = 0; rx[2] = 0; rx[3] = 0; } #ifdef RXDEBUG if ( gettime() - secondtimer > 1000000) { rxdebug.packetpersecond = packetrx; packetrx = 0; secondtimer = gettime(); } #endif }
void checkrx( void) { if ( checkpacket() ) { xn_readpayload( rxdata , 15); if ( rxmode == RXMODE_BIND) { // rx startup , bind mode if ( rxdata[0] == 0xAA ) {// bind packet received txid[0] = rxdata[1]; txid[1] = rxdata[2]; rxmode = RXMODE_NORMAL; xn_writereg(0x25, (uint8_t)(rxdata[1] - 0x7D) ); // Set channel frequency } } else { // normal mode #ifdef RXDEBUG rxdebug.packettime = gettime() - lastrxtime; lastrxtime = gettime(); #endif int pass = decode_cg023(); if ( pass ) { failsafetime = gettime(); failsafe = 0; } else { #ifdef RXDEBUG rxdebug.failcount++; #endif } }// end normal rx mode }// end packet received unsigned long time = gettime(); if( time - failsafetime > FAILSAFETIME ) {// failsafe failsafe = 1; rx[0] = 0; rx[1] = 0; rx[2] = 0; rx[3] = 0; } #ifdef RXDEBUG // packets per second counter if ( time - secondtimer > 1000000) { rxdebug.packetpersecond = packetrx; packetrx = 0; secondtimer = gettime(); } #endif }
void checkrx(void) { int packetreceived = checkpacket(); int pass = 0; if (packetreceived) { if (rxmode == RXMODE_BIND) { // rx startup , bind mode xn_readpayload(rxdata, 15); if (rxdata[0] == 164) { // bind packet rfchannel[0] = rxdata[6]; rfchannel[1] = rxdata[7]; rfchannel[2] = rxdata[8]; rfchannel[3] = rxdata[9]; int rxaddress[5]; rxaddress[0] = rxdata[1]; rxaddress[1] = rxdata[2]; rxaddress[2] = rxdata[3]; rxaddress[3] = rxdata[4]; rxaddress[4] = rxdata[5]; xn_writerxaddress(rxaddress); xn_writereg(0x25, rfchannel[chan]); // Set channel frequency rxmode = RXMODE_NORMAL; #ifdef SERIAL printf(" BIND \n"); #endif } } else { // normal mode #ifdef RXDEBUG rxdebug.channelcount[chan]++; rxdebug.packettime = gettime() - lastrxtime; if ( skipchannel&& !timingfail ) afterskip[skipchannel]++; if ( timingfail ) afterskip[0]++; #endif unsigned long temptime = gettime(); nextchannel(); xn_readpayload(rxdata, 15); pass = decodepacket(); if (pass) { #ifdef RXDEBUG packetrx++; #endif skipchannel = 0; timingfail = 0; lastrxchan = chan; lastrxtime = temptime; failsafetime = temptime; failsafe = 0; } else { #ifdef RXDEBUG rxdebug.failcount++; #endif } } // end normal rx mode } // end packet received unsigned long time = gettime(); // sequence period 12000 if (time - lastrxtime > (HOPPING_NUMBER*PACKET_PERIOD + 1000) && rxmode != RXMODE_BIND) { // channel with no reception lastrxtime = time; // set channel to last with reception if (!timingfail) chan = lastrxchan; // advance to next channel nextchannel(); // set flag to discard packet timing timingfail = 1; } if ( !timingfail && skipchannel < HOPPING_NUMBER+1 && rxmode != RXMODE_BIND) { unsigned int temp = time - lastrxtime ; if ( temp > 1000 && ( temp + (PACKET_OFFSET) )/((int) PACKET_PERIOD) >= (skipchannel + 1) ) { nextchannel(); #ifdef RXDEBUG skipstats[skipchannel]++; #endif skipchannel++; } } if (time - failsafetime > FAILSAFETIME) { // failsafe failsafe = 1; rx[0] = 0; rx[1] = 0; rx[2] = 0; rx[3] = 0; } #ifdef RXDEBUG if (gettime() - secondtimer > 1000000) { rxdebug.packetpersecond = packetrx; packetrx = 0; secondtimer = gettime(); } #endif }