For getting RSSI value from xbee
Dependents: XBeeGetRSSISampleProgram Xbee_s2_RX_versao2
XBeeGetRssi.cpp@11:ecd033d3e211, 2013-08-28 (annotated)
- Committer:
- ATKINZ117
- Date:
- Wed Aug 28 08:57:07 2013 +0000
- Revision:
- 11:ecd033d3e211
- Parent:
- 10:c33541aecc99
- Child:
- 12:7ec2a4147b44
the best version at 2013082817:56
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ATKINZ117 | 6:2e725705db90 | 1 | /*---------------------------------------------------------- |
ATKINZ117 | 6:2e725705db90 | 2 | 20130824:Todos:improve the performance of this program. |
ATKINZ117 | 6:2e725705db90 | 3 | get only the rssi value. |
ATKINZ117 | 6:2e725705db90 | 4 | |
ATKINZ117 | 6:2e725705db90 | 5 | |
ATKINZ117 | 6:2e725705db90 | 6 | ----------------------------------------------------------*/ |
ATKINZ117 | 6:2e725705db90 | 7 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 8 | #include "XBeeGetRssi.h" |
ATKINZ117 | 0:d1ff6ea68ab2 | 9 | #include "mbed.h" |
ATKINZ117 | 4:16396d9ec459 | 10 | //#include <string.h> |
ATKINZ117 | 0:d1ff6ea68ab2 | 11 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 12 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 13 | XBeeGetRssi::XBeeGetRssi(PinName tx,PinName rx){ |
ATKINZ117 | 0:d1ff6ea68ab2 | 14 | _tx=tx; |
ATKINZ117 | 0:d1ff6ea68ab2 | 15 | _rx=rx; |
ATKINZ117 | 0:d1ff6ea68ab2 | 16 | } |
ATKINZ117 | 0:d1ff6ea68ab2 | 17 | |
ATKINZ117 | 9:eb8838ce9d65 | 18 | char* XBeeGetRssi::getRssi(/*int n*/){ |
ATKINZ117 | 4:16396d9ec459 | 19 | //int judge_counter=0; |
ATKINZ117 | 4:16396d9ec459 | 20 | int judge_counter=0; |
ATKINZ117 | 11:ecd033d3e211 | 21 | int rssi_counter=2; |
ATKINZ117 | 7:588a7745cc0e | 22 | //int xbee_message_counter=0; |
ATKINZ117 | 4:16396d9ec459 | 23 | |
ATKINZ117 | 0:d1ff6ea68ab2 | 24 | Serial pc(USBTX,USBRX); //for debugging. |
ATKINZ117 | 0:d1ff6ea68ab2 | 25 | Serial _MyXbee(_tx,_rx); |
ATKINZ117 | 0:d1ff6ea68ab2 | 26 | |
ATKINZ117 | 11:ecd033d3e211 | 27 | _rssi[0]='0'; |
ATKINZ117 | 11:ecd033d3e211 | 28 | _rssi[1]='0'; |
ATKINZ117 | 11:ecd033d3e211 | 29 | |
ATKINZ117 | 11:ecd033d3e211 | 30 | for(int i=2;i<20;i++){ |
ATKINZ117 | 11:ecd033d3e211 | 31 | _rssi[i]='0'; //initial value |
ATKINZ117 | 6:2e725705db90 | 32 | } |
ATKINZ117 | 1:8cb27d9eec8e | 33 | |
ATKINZ117 | 2:befae843036e | 34 | _MyXbee.putc('T'); |
ATKINZ117 | 0:d1ff6ea68ab2 | 35 | |
ATKINZ117 | 4:16396d9ec459 | 36 | wait(1.0); |
ATKINZ117 | 4:16396d9ec459 | 37 | _MyXbee.putc('+'); |
ATKINZ117 | 6:2e725705db90 | 38 | wait_ms(1); |
ATKINZ117 | 4:16396d9ec459 | 39 | _MyXbee.putc('+'); |
ATKINZ117 | 6:2e725705db90 | 40 | wait_ms(1); |
ATKINZ117 | 4:16396d9ec459 | 41 | _MyXbee.putc('+'); |
ATKINZ117 | 6:2e725705db90 | 42 | wait_ms(1); |
ATKINZ117 | 7:588a7745cc0e | 43 | |
ATKINZ117 | 11:ecd033d3e211 | 44 | //judge_counter=0; //reset counter for later use |
ATKINZ117 | 7:588a7745cc0e | 45 | |
ATKINZ117 | 4:16396d9ec459 | 46 | wait(1.0); |
ATKINZ117 | 4:16396d9ec459 | 47 | |
ATKINZ117 | 4:16396d9ec459 | 48 | _MyXbee.putc('A'); |
ATKINZ117 | 6:2e725705db90 | 49 | wait_ms(5); |
ATKINZ117 | 4:16396d9ec459 | 50 | _MyXbee.putc('T'); |
ATKINZ117 | 6:2e725705db90 | 51 | wait_ms(10); |
ATKINZ117 | 4:16396d9ec459 | 52 | _MyXbee.putc('D'); |
ATKINZ117 | 6:2e725705db90 | 53 | wait_ms(10); |
ATKINZ117 | 4:16396d9ec459 | 54 | _MyXbee.putc('B'); |
ATKINZ117 | 6:2e725705db90 | 55 | wait_ms(10); |
ATKINZ117 | 4:16396d9ec459 | 56 | _MyXbee.putc('\r'); |
ATKINZ117 | 6:2e725705db90 | 57 | wait_ms(10); |
ATKINZ117 | 4:16396d9ec459 | 58 | |
ATKINZ117 | 5:790675fae748 | 59 | while(_rssi[judge_counter++]!='\0'){ |
ATKINZ117 | 4:16396d9ec459 | 60 | while(_MyXbee.readable()){ |
ATKINZ117 | 4:16396d9ec459 | 61 | _rssi[rssi_counter++]=_MyXbee.getc(); |
ATKINZ117 | 4:16396d9ec459 | 62 | } |
ATKINZ117 | 7:588a7745cc0e | 63 | } |
ATKINZ117 | 11:ecd033d3e211 | 64 | if(_rssi[5]=='T'){ |
ATKINZ117 | 11:ecd033d3e211 | 65 | _rssi_address=&_rssi[9]; |
ATKINZ117 | 11:ecd033d3e211 | 66 | }else{ |
ATKINZ117 | 11:ecd033d3e211 | 67 | _rssi_address=&_rssi[0]; |
ATKINZ117 | 11:ecd033d3e211 | 68 | } |
ATKINZ117 | 4:16396d9ec459 | 69 | |
ATKINZ117 | 4:16396d9ec459 | 70 | _MyXbee.putc('A'); |
ATKINZ117 | 6:2e725705db90 | 71 | wait_ms(5); |
ATKINZ117 | 4:16396d9ec459 | 72 | _MyXbee.putc('T'); |
ATKINZ117 | 6:2e725705db90 | 73 | wait_ms(5); |
ATKINZ117 | 4:16396d9ec459 | 74 | _MyXbee.putc('C'); |
ATKINZ117 | 6:2e725705db90 | 75 | wait_ms(5); |
ATKINZ117 | 4:16396d9ec459 | 76 | _MyXbee.putc('N'); |
ATKINZ117 | 6:2e725705db90 | 77 | wait_ms(5); |
ATKINZ117 | 4:16396d9ec459 | 78 | _MyXbee.putc('\r'); |
ATKINZ117 | 4:16396d9ec459 | 79 | |
ATKINZ117 | 9:eb8838ce9d65 | 80 | return _rssi_address; |
ATKINZ117 | 4:16396d9ec459 | 81 | |
ATKINZ117 | 4:16396d9ec459 | 82 | } |