For getting RSSI value from xbee
Dependents: XBeeGetRSSISampleProgram Xbee_s2_RX_versao2
Diff: XBeeGetRssi.cpp
- Revision:
- 0:d1ff6ea68ab2
- Child:
- 1:8cb27d9eec8e
diff -r 000000000000 -r d1ff6ea68ab2 XBeeGetRssi.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XBeeGetRssi.cpp Tue Aug 06 14:29:39 2013 +0000 @@ -0,0 +1,65 @@ +#include "XBeeGetRssi.h" +#include "mbed.h" +#include <string.h> + + +XBeeGetRssi::XBeeGetRssi(PinName tx,PinName rx){ + _tx=tx; + _rx=rx; +} + +char* XBeeGetRssi::get(){ + /*int message_counter=0; + int rssi_counter=0; + Serial MyXbee(_tx,_rx);*/ + Serial pc(USBTX,USBRX); //for debugging. + Serial _MyXbee(_tx,_rx); + + pc.printf("At first.\r\n"); + while(1){ + _MyXbee.printf("+++"); //entering AT command mode. + pc.printf("sent +++\r\n"); + _MyXbee.attach(this,&XBeeGetRssi::_rssiGetter,Serial::RxIrq); + pc.printf("waiting for xbee!\r\n"); + return _rssi; + } + //MyXbee.printf("ATDB\r\n"); + //wait(0.3); + /*if(MyXbee.readable()){ + while(_xbee_message!='\0'){ + _rssi[message_counter]=MyXbee.getc(); + message_counter++; + } + }else{ + pc.printf("There is no message.\r\n"); + }*/ +} + +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 OK_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"); + } + +} \ No newline at end of file