For getting RSSI value from xbee
Dependents: XBeeGetRSSISampleProgram Xbee_s2_RX_versao2
Diff: XBeeGetRssi.cpp
- Revision:
- 3:602329ee6a01
- Parent:
- 2:befae843036e
diff -r befae843036e -r 602329ee6a01 XBeeGetRssi.cpp --- a/XBeeGetRssi.cpp Sat Aug 17 03:51:52 2013 +0000 +++ b/XBeeGetRssi.cpp Sun Aug 18 08:42:24 2013 +0000 @@ -8,27 +8,76 @@ _rx=rx; } -int XBeeGetRssi::get(){ - //int message_counter=0; - //int rssi_counter=0; +char* XBeeGetRssi::get(){ + + //------------variables------------------------ + int message_counter=0; //for containing message from xbee. + int temp_counter=1; //for judging '/r' Serial pc(USBTX,USBRX); //for debugging. Serial _MyXbee(_tx,_rx); - _rssi=0; //initial value + _rssi[0]='Z'; //initial value + _rssi[1]='Z'; + //------------------------------------------- - + //----sending message to another Xbee for getting RSSI value.------------ pc.printf("At the first of xbee class.\r\n"); _MyXbee.putc('T'); if(_MyXbee.readable()){ _MyXbee.getc(); }else{ - pc.printf("couldn't get return message."); + pc.printf("couldn't get return message.\r\n"); } wait(1.0); - _MyXbee.printf("+++"); //entering AT command mode. + //-------------------------------------------- + + //_MyXbee.printf("+++"); //entering AT command mode. + //-----------entering AT Mode--------------- + for(int i=0;i<3;i++){ + _MyXbee.putc('+'); + wait_ms(100); + } pc.printf("sent +++\r\n"); - wait(1.0); - //while(_rssi[rssi_counter]!='\0'){ + wait(0.9); + //------------------------------------------------ + + //-------------------send ATDB command----------- + _MyXbee.putc('A'); + wait_ms(100); + _MyXbee.putc('T'); + wait_ms(100); + _MyXbee.putc('D'); + wait_ms(100); + _MyXbee.putc('B'); + wait_ms(100); + _MyXbee.putc('\r'); + wait_ms(100); + pc.printf("sent ATDB \r\n"); + //----------------------------------------------- + + //------------get RSSI value-------------------- + while(_rssi[temp_counter-1]!='\r'){ + if(_MyXbee.readable()){ + _rssi[message_counter]=_MyXbee.getc(); + wait_ms(100); + message_counter++; + temp_counter++; + pc.printf("in the while loop.\r\n"); + }else{ + pc.printf("xbee isn't available.\r\n"); + //-----------entering AT Mode--------------- + for(int i=0;i<3;i++){ + _MyXbee.putc('+'); + wait_ms(100); + } + pc.printf("sent +++\r\n"); + wait(0.9); + //------------------------------------------------ + } + } + //----------------------------------------------- + + /*while(_rssi[rssi_counter]!='\0'){ if(_MyXbee.readable()){ _MyXbee.printf("ATDB\r"); //quering rssi value _rssi=_MyXbee.getc(); @@ -40,9 +89,23 @@ //wait(1.0); //pc.printf("+++ again.\r\n"); } - //}_rssi[rssi_counter]='\0'; //contain rssi value to _rssi[] + }_rssi[rssi_counter]='\0'; //contain rssi value to _rssi[] + ----------the code block above is previous ver-----------------*/ + pc.printf("Here is class end!\r\n"); - _MyXbee.printf("ATCN\r"); + //-----------send ATCN command------------- + //_MyXbee.printf("ATCN\r"); + _MyXbee.putc('A'); + wait_ms(100); + _MyXbee.putc('T'); + wait_ms(100); + _MyXbee.putc('C'); + wait_ms(100); + _MyXbee.putc('N'); + wait_ms(100); + _MyXbee.putc('\r'); + wait_ms(100); + //----------------------------------------- return _rssi;