For getting RSSI value from xbee

Dependents:   XBeeGetRSSISampleProgram Xbee_s2_RX_versao2

XBeeGetRssi.cpp

Committer:
ATKINZ117
Date:
2013-08-27
Revision:
9:eb8838ce9d65
Parent:
7:588a7745cc0e
Child:
10:c33541aecc99

File content as of revision 9:eb8838ce9d65:

/*----------------------------------------------------------
20130824:Todos:improve the performance of this program.
get only the rssi value.


----------------------------------------------------------*/

#include "XBeeGetRssi.h"
#include "mbed.h"
//#include <string.h>


XBeeGetRssi::XBeeGetRssi(PinName tx,PinName rx){
    _tx=tx;
    _rx=rx;
}

char* XBeeGetRssi::getRssi(/*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);
    
    for(int i=0;i<20;i++){
        _rssi[i]='^'; //initial value
    }
    
    _MyXbee.putc('T');
    
    wait(1.0);
    _MyXbee.putc('+');
    wait_ms(1);
    _MyXbee.putc('+');
    wait_ms(1);
    _MyXbee.putc('+');
    wait_ms(1);

    judge_counter=0; //reset counter for later use

    wait(1.0);
    judge_counter=0;
    
    _MyXbee.putc('A');
    wait_ms(5);
    _MyXbee.putc('T');
    wait_ms(10);
    _MyXbee.putc('D');
    wait_ms(10);
    _MyXbee.putc('B');
    wait_ms(10);
    _MyXbee.putc('\r');
    wait_ms(10);
    
    while(_rssi[judge_counter++]!='\0'){
        //_rssi[0]='0';
        while(_MyXbee.readable()){
            _rssi[rssi_counter++]=_MyXbee.getc();
        }
    }
    _rssi_address=&_rssi[7];
    
    _MyXbee.putc('A');
    wait_ms(5);
    _MyXbee.putc('T');
    wait_ms(5);
    _MyXbee.putc('C');
    wait_ms(5);
    _MyXbee.putc('N');
    wait_ms(5);
    _MyXbee.putc('\r');
    
    return _rssi_address;
    
}