For getting RSSI value from xbee
Dependents: XBeeGetRSSISampleProgram Xbee_s2_RX_versao2
XBeeGetRssi.cpp@1:8cb27d9eec8e, 2013-08-16 (annotated)
- Committer:
- ATKINZ117
- Date:
- Fri Aug 16 06:37:46 2013 +0000
- Revision:
- 1:8cb27d9eec8e
- Parent:
- 0:d1ff6ea68ab2
- Child:
- 2:befae843036e
partly worked
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ATKINZ117 | 0:d1ff6ea68ab2 | 1 | #include "XBeeGetRssi.h" |
ATKINZ117 | 0:d1ff6ea68ab2 | 2 | #include "mbed.h" |
ATKINZ117 | 0:d1ff6ea68ab2 | 3 | #include <string.h> |
ATKINZ117 | 0:d1ff6ea68ab2 | 4 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 5 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 6 | XBeeGetRssi::XBeeGetRssi(PinName tx,PinName rx){ |
ATKINZ117 | 0:d1ff6ea68ab2 | 7 | _tx=tx; |
ATKINZ117 | 0:d1ff6ea68ab2 | 8 | _rx=rx; |
ATKINZ117 | 0:d1ff6ea68ab2 | 9 | } |
ATKINZ117 | 0:d1ff6ea68ab2 | 10 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 11 | char* XBeeGetRssi::get(){ |
ATKINZ117 | 1:8cb27d9eec8e | 12 | //int message_counter=0; |
ATKINZ117 | 0:d1ff6ea68ab2 | 13 | int rssi_counter=0; |
ATKINZ117 | 0:d1ff6ea68ab2 | 14 | Serial pc(USBTX,USBRX); //for debugging. |
ATKINZ117 | 0:d1ff6ea68ab2 | 15 | Serial _MyXbee(_tx,_rx); |
ATKINZ117 | 0:d1ff6ea68ab2 | 16 | |
ATKINZ117 | 1:8cb27d9eec8e | 17 | _rssi[0]='a'; |
ATKINZ117 | 1:8cb27d9eec8e | 18 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 19 | pc.printf("At first.\r\n"); |
ATKINZ117 | 1:8cb27d9eec8e | 20 | _MyXbee.printf("+++"); //entering AT command mode. |
ATKINZ117 | 1:8cb27d9eec8e | 21 | pc.printf("sent +++\r\n"); |
ATKINZ117 | 1:8cb27d9eec8e | 22 | wait(3.0); |
ATKINZ117 | 1:8cb27d9eec8e | 23 | while(_rssi[rssi_counter]!='\0'){ |
ATKINZ117 | 1:8cb27d9eec8e | 24 | if(_MyXbee.readable()){ |
ATKINZ117 | 1:8cb27d9eec8e | 25 | _MyXbee.printf("ATDB\r\n"); //quering rssi value |
ATKINZ117 | 1:8cb27d9eec8e | 26 | _rssi[rssi_counter]=_MyXbee.getc(); |
ATKINZ117 | 1:8cb27d9eec8e | 27 | rssi_counter++; |
ATKINZ117 | 1:8cb27d9eec8e | 28 | pc.printf("I'm in the while loop!\r\n"); |
ATKINZ117 | 1:8cb27d9eec8e | 29 | }else{ |
ATKINZ117 | 1:8cb27d9eec8e | 30 | pc.printf("couldn't read.\r\n"); |
ATKINZ117 | 0:d1ff6ea68ab2 | 31 | } |
ATKINZ117 | 1:8cb27d9eec8e | 32 | }_rssi[rssi_counter]='\0'; //contain rssi value to _rssi[] |
ATKINZ117 | 1:8cb27d9eec8e | 33 | pc.printf("Ended!\r\n"); |
ATKINZ117 | 1:8cb27d9eec8e | 34 | _MyXbee.printf("ATCN\r\n"); |
ATKINZ117 | 1:8cb27d9eec8e | 35 | |
ATKINZ117 | 1:8cb27d9eec8e | 36 | return _rssi; |
ATKINZ117 | 1:8cb27d9eec8e | 37 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 38 | } |
ATKINZ117 | 0:d1ff6ea68ab2 | 39 | |
ATKINZ117 | 1:8cb27d9eec8e | 40 | /*void XBeeGetRssi::_rssiGetter(){ |
ATKINZ117 | 0:d1ff6ea68ab2 | 41 | int message_counter=0; |
ATKINZ117 | 0:d1ff6ea68ab2 | 42 | int rssi_counter=0; |
ATKINZ117 | 0:d1ff6ea68ab2 | 43 | Serial pc(USBTX,USBRX); |
ATKINZ117 | 0:d1ff6ea68ab2 | 44 | Serial _MyXbee(_tx,_rx); |
ATKINZ117 | 0:d1ff6ea68ab2 | 45 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 46 | pc.printf("got some message from xbee.\r\n"); |
ATKINZ117 | 0:d1ff6ea68ab2 | 47 | while(_xbee_message[message_counter]!='\0'){ |
ATKINZ117 | 0:d1ff6ea68ab2 | 48 | _xbee_message[message_counter]=_MyXbee.getc(); |
ATKINZ117 | 0:d1ff6ea68ab2 | 49 | message_counter++; |
ATKINZ117 | 0:d1ff6ea68ab2 | 50 | }_xbee_message[message_counter]='\0'; //get the message from xbee. |
ATKINZ117 | 1:8cb27d9eec8e | 51 | pc.printf("contained some message.\r\n"); |
ATKINZ117 | 0:d1ff6ea68ab2 | 52 | pc.printf(_xbee_message); |
ATKINZ117 | 0:d1ff6ea68ab2 | 53 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 54 | if(strcmp(_xbee_message,"OK\r\n")==0){ |
ATKINZ117 | 0:d1ff6ea68ab2 | 55 | _MyXbee.printf("ATDB\r\n"); //quering rssi value |
ATKINZ117 | 0:d1ff6ea68ab2 | 56 | while(_rssi[rssi_counter]!='\0'){ |
ATKINZ117 | 0:d1ff6ea68ab2 | 57 | _rssi[rssi_counter]=_MyXbee.getc(); |
ATKINZ117 | 0:d1ff6ea68ab2 | 58 | rssi_counter++; |
ATKINZ117 | 0:d1ff6ea68ab2 | 59 | pc.printf("I'm in the while loop!\r\n"); |
ATKINZ117 | 0:d1ff6ea68ab2 | 60 | }_rssi[rssi_counter]='\0'; //contain rssi value to _rssi[] |
ATKINZ117 | 0:d1ff6ea68ab2 | 61 | pc.printf("Ended!\r\n"); |
ATKINZ117 | 0:d1ff6ea68ab2 | 62 | _MyXbee.printf("ATCN\r\n"); |
ATKINZ117 | 0:d1ff6ea68ab2 | 63 | }else{ |
ATKINZ117 | 0:d1ff6ea68ab2 | 64 | pc.printf("There were some error.\r\n"); |
ATKINZ117 | 0:d1ff6ea68ab2 | 65 | } |
ATKINZ117 | 0:d1ff6ea68ab2 | 66 | |
ATKINZ117 | 1:8cb27d9eec8e | 67 | }*/ |