envio teste
Dependencies: C12832 XBeeGetRssi mbed xbee_lib
Revision 0:f087a480051a, committed 2015-06-24
- Comitter:
- mbastos
- Date:
- Wed Jun 24 19:06:55 2015 +0000
- Commit message:
- teste comunica??o
Changed in this revision
diff -r 000000000000 -r f087a480051a C12832.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/C12832.lib Wed Jun 24 19:06:55 2015 +0000 @@ -0,0 +1,1 @@ +https://mbed.org/users/chris/code/C12832/#7de323fa46fe
diff -r 000000000000 -r f087a480051a XBeeGetRssi.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/XBeeGetRssi.lib Wed Jun 24 19:06:55 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/ATKINZ117/code/XBeeGetRssi/#e2fd29cb22d7
diff -r 000000000000 -r f087a480051a main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed Jun 24 19:06:55 2015 +0000 @@ -0,0 +1,145 @@ +#include "mbed.h" +#include "C12832.h" + +Serial pc(USBTX, USBRX); // tx, rx +Serial xbee1(p9,p10); +DigitalOut rst1(p11); //Digital reset for the XBee, 200ns for reset +Serial serial (p9,p10); +C12832 lcd(p5, p7, p6, p8, p11); //C12832(PinName mosi, PinName sck, PinName reset, PinName a0, PinName ncs, const char* name = "LCD"); + + +//variaveis globais +int rssi=0; +int atdb=0; +int recepcao; +char mens[20]; +char mens1[20]; +unsigned char cont=0; +unsigned char cont1=0; +unsigned char tam=0; +unsigned char cks=0; +unsigned char estado=0; +unsigned char estado1=0; +//unsigned char rssi=0; +unsigned char temp=0; +unsigned char temp1=0; + + + +int main(void){ + + xbee1.baud(9600); + pc.baud(9600); + lcd.locate(0,3); + while(1){ + switch(estado){ + case 0: + INI: + while(!xbee1.readable()){ + lcd.locate(0,0); + lcd.cls(); + lcd.printf("Aguardando..."); + } + temp = xbee1.getc(); + if(temp==0x7E){ + cont=0; + } + mens[cont]=temp; + //lcd.locate(0,0); + //lcd.cls(); + //lcd.printf("Recebeu %x cont=%d",temp,cont);//debug - recebeu o primeiro caracter? + //wait(0.5); + temp = 0; + cont++; + if(cont==(mens[2]+4)){ //compara o tamanho enviado + 4 bytes (1 de inicio,2 de tamanho e checksum) para + estado = 1; // verificar se chegou ao final do frame, de maneira dinâmica + //lcd.cls(); + //lcd.locate(0,10); + //lcd.printf("Frame 1 - Completo");//debug - completou o frame? + //wait(0.5); + } + break; + case 1: //montou o primeiro pacote + //lcd.locate(0,20); + //lcd.printf("M[%x %x %x %x %x %x %x %x %x %x ]",mens[0],mens[1],mens[2],mens[3],mens[4],mens[5],mens[6],mens[7],mens[8],mens[9]);//debug - recebeu o primeiro caracter? + //wait(7);//debug + + //lcd.locate(0,0); + //lcd.cls();//debug + //lcd.printf("Verificando..."); + //wait(0.5); + REP: xbee1.printf("%c%c%c%c%c%c%c%c",0x7E,0X00,0X04,0X08,0X01,0X64,0X62,0X30); + //wait(2); + //lcd.locate(0,10); + //lcd.cls();//debug + //lcd.printf("passou."); + //wait(1); + while (atdb==0){ + switch(estado1){ + case 0: + while(!xbee1.readable()){ + lcd.locate(0,0); + lcd.cls(); + lcd.printf("Aguardando ATDB..."); + } + temp1 = xbee1.getc();//gets(temp); + if(temp1==0x7E){ + cont1=0; + } + mens1[cont1]=temp1; + //lcd.locate(0,0); + //lcd.cls(); + //lcd.printf("Recebeu %x ATDB=%d",temp1,cont1);//debug - recebeu o primeiro caracter? + //wait(1); + temp1 = 0; + cont1++; + if(cont1==(mens1[2]+4)){ + estado1 = 1; + //lcd.locate(0,10); + //lcd.cls(); + //lcd.printf("Frame 2 - Completo");//debug - completou o frame? + //wait(0.5); + } + break; + case 1: //ja montou o frame AT response + atdb=1; + switch(mens1[3]){ + case 0x88: + lcd.locate(0,10); + lcd.cls(); + lcd.printf("Frame ATDB:mens1[3]=%x",mens1[3]);//debug para confirmar frame ATDB + //wait(1); + rssi=mens1[8]; + lcd.locate(0,10); + lcd.cls(); + lcd.printf("RSSI=%x",mens1[8]);//debug para confirmar frame ATDB + wait(0.1); + estado=0; + cont=0; + atdb=0; + goto INI; + break; + default: + estado1=0; + cont1=0; + temp1=0; + lcd.locate(0,10); + lcd.cls(); + lcd.printf("ERRO: Nao eh ATDB:mens1[3]=%x",mens1[3]);//debug para confirmar frame ATDB + wait(1); + estado=0; + cont=0; + atdb=0; + goto INI; + }//fecha switch mensg[3]=0x88 + break; + }//fecha switch estado1 + }//fecha while atdb + break; + }//fecha switch estado + + + }//fecha while1 +}//fecha int main() + + \ No newline at end of file
diff -r 000000000000 -r f087a480051a mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Wed Jun 24 19:06:55 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/cd19af002ccc \ No newline at end of file
diff -r 000000000000 -r f087a480051a xbee_lib.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/xbee_lib.lib Wed Jun 24 19:06:55 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/tristanjph/code/xbee_lib/#ede20c047d8b