For getting RSSI value from xbee
Dependents: XBeeGetRSSISampleProgram Xbee_s2_RX_versao2
Diff: XBeeGetRssi.cpp
- Revision:
- 4:16396d9ec459
- Parent:
- 2:befae843036e
- Child:
- 5:790675fae748
diff -r befae843036e -r 16396d9ec459 XBeeGetRssi.cpp --- a/XBeeGetRssi.cpp Sat Aug 17 03:51:52 2013 +0000 +++ b/XBeeGetRssi.cpp Sat Aug 24 04:12:49 2013 +0000 @@ -1,6 +1,6 @@ #include "XBeeGetRssi.h" #include "mbed.h" -#include <string.h> +//#include <string.h> XBeeGetRssi::XBeeGetRssi(PinName tx,PinName rx){ @@ -8,71 +8,80 @@ _rx=rx; } -int XBeeGetRssi::get(){ - //int message_counter=0; - //int rssi_counter=0; +char XBeeGetRssi::get(int n){ + //int judge_counter=0; + int judge_counter=0; + int rssi_counter=0; + int xbee_message_counter=0; + Serial pc(USBTX,USBRX); //for debugging. Serial _MyXbee(_tx,_rx); - _rssi=0; //initial value + _rssi[0]='P'; //initial value + _xbee_message[0]='P';//initial value; - pc.printf("At the first of xbee class.\r\n"); +// 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."); - } - wait(1.0); - _MyXbee.printf("+++"); //entering AT command mode. - pc.printf("sent +++\r\n"); - wait(1.0); - //while(_rssi[rssi_counter]!='\0'){ - if(_MyXbee.readable()){ - _MyXbee.printf("ATDB\r"); //quering rssi value - _rssi=_MyXbee.getc(); - //rssi_counter++; - pc.printf("sent ATDB!\r\n"); - }else{ - pc.printf("couldn't read.\r\n"); - //_MyXbee.printf("+++"); - //wait(1.0); - //pc.printf("+++ again.\r\n"); - } - //}_rssi[rssi_counter]='\0'; //contain rssi value to _rssi[] - pc.printf("Here is class end!\r\n"); - _MyXbee.printf("ATCN\r"); - - return _rssi; - -} - -/*void XBeeGetRssi::_rssiGetter(){ - int message_counter=0; - int rssi_counter=0; - Serial pc(USBTX,USBRX); - Serial _MyXbee(_tx,_rx); - - pc.printf("got some message from xbee.\r\n"); - while(_xbee_message[message_counter]!='\0'){ - _xbee_message[message_counter]=_MyXbee.getc(); - message_counter++; - }_xbee_message[message_counter]='\0'; //get the message from xbee. - pc.printf("contained some message.\r\n"); - pc.printf(_xbee_message); - - if(strcmp(_xbee_message,"OK\r\n")==0){ - _MyXbee.printf("ATDB\r\n"); //quering rssi value - while(_rssi[rssi_counter]!='\0'){ - _rssi[rssi_counter]=_MyXbee.getc(); - rssi_counter++; - pc.printf("I'm in the while loop!\r\n"); - }_rssi[rssi_counter]='\0'; //contain rssi value to _rssi[] - pc.printf("Ended!\r\n"); - _MyXbee.printf("ATCN\r\n"); - }else{ - pc.printf("There were some error.\r\n"); + while(_MyXbee.readable()){ + _xbee_message[0]=_MyXbee.getc(); } -}*/ \ No newline at end of file +// pc.printf("first message from xbee;%s\r\n",_xbee_message[0]); + wait(1.0); + //_MyXbee.printf("+++"); //entering AT command mode. + _MyXbee.putc('+'); + wait_ms(100); + _MyXbee.putc('+'); + wait_ms(100); + _MyXbee.putc('+'); + wait_ms(100); +// pc.printf("sent +++\r\n"); + while(_xbee_message[judge_counter++]!='\r'){ + while(_MyXbee.readable()){ + _xbee_message[xbee_message_counter++]=_MyXbee.getc(); + } + }_xbee_message[judge_counter]='\0'; + judge_counter=0; //reset counter for later use + xbee_message_counter=0; //reset counter for later use + + // while(_xbee_message[judge_counter++]!='\0'){ +// pc.printf("got xbee message;%s\r\n",_xbee_message[xbee_message_counter++]); + //} + wait(1.0); + judge_counter=0; + xbee_message_counter=0; + + _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"); + + while(_rssi[judge_counter++]!='\r'){ + while(_MyXbee.readable()){ + _rssi[rssi_counter++]=_MyXbee.getc(); + //rssi_counter++; + } + }//_rssi[rssi_counter]='\0'; //contain rssi value to _rssi[] +// pc.printf("Here is class end!\r\n"); + + _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'); + + return _rssi[n]; + +} \ No newline at end of file