ok

Dependencies:   mbed-rtos mbed

Fork of STINGR_PDR by JOEL CONTRERAS

Committer:
Sumobot
Date:
Mon Oct 30 19:58:19 2017 +0000
Revision:
1:d140f24cf386
Parent:
0:88a700f174a3
Child:
2:a79ceae53e04
Se agreg? un ciclo infinito en el hilo "Respuesta"

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Sumobot 0:88a700f174a3 1 #include "mbed.h" //Se declara la librería mbed.
Sumobot 0:88a700f174a3 2 #include "rtos.h"
Sumobot 0:88a700f174a3 3
Sumobot 0:88a700f174a3 4 DigitalOut led1(LED1);
Sumobot 0:88a700f174a3 5 DigitalOut led2(LED2);
Sumobot 0:88a700f174a3 6 DigitalOut led3(LED3);
Sumobot 0:88a700f174a3 7 DigitalOut led4(LED4);
Sumobot 0:88a700f174a3 8 Serial pc(USBTX, USBRX, 9600); // tx, rx Conunicación Serial con la PC
Sumobot 0:88a700f174a3 9 Serial device(p9, p10, 9600); // tx, rx Comunicación Serial con el Módulo STX3
Sumobot 0:88a700f174a3 10 DigitalOut RTS(p7, 1); // Pin Digital de Salida "RTS"; Predefinido para valer 1 en su estado inactivo dentro del código.
Sumobot 0:88a700f174a3 11 DigitalIn CTS(p8, PullUp); // Pin Digital de entrada "CTS" en modo Pull-Up, para encontrarse normalmente a VCC cuando no haya un pulso.
Sumobot 0:88a700f174a3 12 int flag=1; // Declaración de la Bandera.
Sumobot 0:88a700f174a3 13 Thread thread;
Sumobot 0:88a700f174a3 14
Sumobot 0:88a700f174a3 15 void respuesta(){
Sumobot 1:d140f24cf386 16 while(1){
Sumobot 0:88a700f174a3 17 if(device.readable()) { // Se esperan datos provenientes del TX del módulo STX3
Sumobot 0:88a700f174a3 18 pc.putc(device.getc()); // Se muestra en pantalla la respuesta recibida por el módulo STX3 como una reacción al mensaje en HEX enviado
Sumobot 0:88a700f174a3 19 }
Sumobot 1:d140f24cf386 20 }
Sumobot 0:88a700f174a3 21 }
Sumobot 0:88a700f174a3 22
Sumobot 0:88a700f174a3 23 void stx3()
Sumobot 0:88a700f174a3 24 {
Sumobot 0:88a700f174a3 25 Thread::wait(5000); // Se da un tiempo para que el analizador se estabilice
Sumobot 0:88a700f174a3 26 pc.printf("El valor de CTS 1 es %d\n\r",CTS.read()); // Se lee el valor de la variable CTS, la cual debe ser 1
Sumobot 0:88a700f174a3 27 pc.printf("El valor de RTS 1 es %d\n\r",RTS.read()); // Se lee el valor de la variable RTS, la cual debe ser 1
Sumobot 0:88a700f174a3 28 RTS=0; // Se manda un pulso en bajo en RTS, para inicial el proceso de transmisión
Sumobot 0:88a700f174a3 29 while(flag==1){ // Flag inicialmente vale 1, así que el ciclo while cambiará hasta que esa condición no se cumpla
Sumobot 0:88a700f174a3 30 flag=CTS.read(); // Cuando entra el ciclo, se iguala flag a CTS, el cual cuando cambie a 0 provocará que termine el while (máx 125 ms)
Sumobot 0:88a700f174a3 31 pc.printf("El valor de flag es %d\n\r", flag); // Se imprime el valor de flag, para identificar cuando termina el ciclo while
Sumobot 0:88a700f174a3 32 }
Sumobot 0:88a700f174a3 33 }
Sumobot 0:88a700f174a3 34
Sumobot 0:88a700f174a3 35 int main() {
Sumobot 0:88a700f174a3 36 thread.start(respuesta);
Sumobot 0:88a700f174a3 37
Sumobot 0:88a700f174a3 38 while(1) {
Sumobot 0:88a700f174a3 39
Sumobot 0:88a700f174a3 40 switch (pc.getc())
Sumobot 0:88a700f174a3 41 {
Sumobot 0:88a700f174a3 42 case '1':
Sumobot 0:88a700f174a3 43 {
Sumobot 0:88a700f174a3 44 led1=!led1;
Sumobot 0:88a700f174a3 45 stx3();
Sumobot 1:d140f24cf386 46 Thread::wait(100); // Query ESN
Sumobot 1:d140f24cf386 47 device.putc(0XAA);
Sumobot 0:88a700f174a3 48 device.putc(0X05);
Sumobot 1:d140f24cf386 49 device.putc(0X01);
Sumobot 1:d140f24cf386 50 device.putc(0X50);
Sumobot 1:d140f24cf386 51 device.putc(0XD5);
Sumobot 0:88a700f174a3 52 Thread::wait(100); // Se esperan .1 segundos una vez que se terminaron de hacer las transmisiones
Sumobot 0:88a700f174a3 53 //El tiempo total de transmisión es; el wait previo a las transmisiones, el tiempo que tarda el Mu en enviar los datos y el wait posterior a la transmisión
Sumobot 0:88a700f174a3 54 RTS=1;
Sumobot 0:88a700f174a3 55 flag=1;
Sumobot 0:88a700f174a3 56 }
Sumobot 0:88a700f174a3 57 break;
Sumobot 0:88a700f174a3 58
Sumobot 0:88a700f174a3 59 case '2':
Sumobot 0:88a700f174a3 60 {
Sumobot 0:88a700f174a3 61 led2=!led2;
Sumobot 0:88a700f174a3 62 stx3();
Sumobot 1:d140f24cf386 63 Thread::wait(100); // Query Bursts Remaining
Sumobot 1:d140f24cf386 64 device.putc(0XAA);
Sumobot 0:88a700f174a3 65 device.putc(0X05);
Sumobot 0:88a700f174a3 66 device.putc(0X04);
Sumobot 0:88a700f174a3 67 device.putc(0XFD);
Sumobot 0:88a700f174a3 68 device.putc(0X82);
Sumobot 0:88a700f174a3 69 Thread::wait(100); // Se esperan .1 segundos una vez que se terminaron de hacer las transmisiones
Sumobot 0:88a700f174a3 70 //El tiempo total de transmisión es; el wait previo a las transmisiones, el tiempo que tarda el Mu en enviar los datos y el wait posterior a la transmisión
Sumobot 0:88a700f174a3 71 RTS=1;
Sumobot 0:88a700f174a3 72 flag=1;
Sumobot 0:88a700f174a3 73 }
Sumobot 0:88a700f174a3 74 break;
Sumobot 0:88a700f174a3 75
Sumobot 0:88a700f174a3 76 case '3':
Sumobot 0:88a700f174a3 77 {
Sumobot 0:88a700f174a3 78 led3=!led3;
Sumobot 0:88a700f174a3 79 stx3();
Sumobot 1:d140f24cf386 80 Thread::wait(100); // Query Firmware Version
Sumobot 1:d140f24cf386 81 device.putc(0XAA);
Sumobot 0:88a700f174a3 82 device.putc(0X05);
Sumobot 1:d140f24cf386 83 device.putc(0X05);
Sumobot 1:d140f24cf386 84 device.putc(0X74);
Sumobot 1:d140f24cf386 85 device.putc(0X93);
Sumobot 0:88a700f174a3 86 Thread::wait(100); // Se esperan .1 segundos una vez que se terminaron de hacer las transmisiones
Sumobot 0:88a700f174a3 87 //El tiempo total de transmisión es; el wait previo a las transmisiones, el tiempo que tarda el Mu en enviar los datos y el wait posterior a la transmisión
Sumobot 0:88a700f174a3 88 RTS=1;
Sumobot 0:88a700f174a3 89 flag=1;
Sumobot 0:88a700f174a3 90 }
Sumobot 0:88a700f174a3 91 break;
Sumobot 0:88a700f174a3 92 }
Sumobot 0:88a700f174a3 93 }
Sumobot 0:88a700f174a3 94 }
Sumobot 0:88a700f174a3 95