gsm

Dependencies:   DebouncedIn mbed

Fork of CLASEDELGSM1 by Gustavo Ramirez

Committer:
demo71
Date:
Wed Nov 08 21:05:02 2017 +0000
Revision:
3:fa94bd2cb170
Parent:
2:0377af333c98
gsm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tony63 0:edc50cf04b46 1 // Programa para enviar desde la FRDMKL25Z un mensaje de texto en formatp PDU
tony63 0:edc50cf04b46 2 // Como modem usa un celular SIEMENS a56i
tony63 0:edc50cf04b46 3 // ENVIAR -----la palabra "ALARMA 1"
tony63 0:edc50cf04b46 4 //
tony63 0:edc50cf04b46 5
tony63 0:edc50cf04b46 6 // OJO CON ESTO
tony63 0:edc50cf04b46 7 // conector del siemens cable verde es RX conectelo a PTE0 cable blanco es TX conectelo a PTE1
tony63 0:edc50cf04b46 8 #include "mbed.h"
tony63 0:edc50cf04b46 9 #include "DebouncedIn.h"
tony63 0:edc50cf04b46 10 #include "stdio.h"
tony63 0:edc50cf04b46 11 #include "string.h"
tony63 0:edc50cf04b46 12 Timer t;
tony63 0:edc50cf04b46 13 DigitalOut LedVerde(LED2);
tony63 0:edc50cf04b46 14 DigitalOut LedRojo(LED1);
tony63 0:edc50cf04b46 15 DigitalOut LedAzul(LED3);
tony63 0:edc50cf04b46 16 DebouncedIn button1(PTC12); //señal que inicia el envio del mensaje
tony63 0:edc50cf04b46 17 Serial GSM(PTE0,PTE1); //Configura puerto UART de la FRDMKL25Z
tony63 0:edc50cf04b46 18 Serial pc(USBTX,USBRX);//Configura puerto USB a la consola serial del PC conectado.
tony63 0:edc50cf04b46 19 void Rx_interrupt();
tony63 0:edc50cf04b46 20 int position=0;
tony63 2:0377af333c98 21 int intentos=0;
tony63 0:edc50cf04b46 22 int lenpack=6;
tony63 2:0377af333c98 23 int ret=1;
tony63 0:edc50cf04b46 24 int longi=0;
tony63 1:6b506dde0a6e 25 char tel[11];
tony63 0:edc50cf04b46 26 char DE[50];
tony63 1:6b506dde0a6e 27 char buffer[100];
tony63 2:0377af333c98 28 char buffermsg[100];
tony63 2:0377af333c98 29 char buffer1[100];
tony63 1:6b506dde0a6e 30 char datos[100];
tony63 2:0377af333c98 31 char NUMBER[13];
tony63 2:0377af333c98 32 char resp[6];
tony63 2:0377af333c98 33 char CMT[]="+CMTI";
tony63 2:0377af333c98 34 char tam[2];
tony63 0:edc50cf04b46 35 int index;
tony63 0:edc50cf04b46 36 int count;
tony63 0:edc50cf04b46 37 int i = 0;
tony63 1:6b506dde0a6e 38 int j = 0;
tony63 0:edc50cf04b46 39 int c=0;
tony63 0:edc50cf04b46 40 unsigned char CtrlZ = 0x1A; // comodin de emision controlZ
tony63 0:edc50cf04b46 41 bool Flag = false; // bandera
tony63 0:edc50cf04b46 42 char r[]=""; //Cadena de recepcion de la trama PDU si se usa!!
tony63 0:edc50cf04b46 43 char msg[256];
tony63 0:edc50cf04b46 44 char char1;
tony63 0:edc50cf04b46 45 //Flush serial para el buffer
tony63 0:edc50cf04b46 46 void FlushGSM(void) {
tony63 0:edc50cf04b46 47 char1 = 0;
tony63 0:edc50cf04b46 48 while (GSM.readable()){
tony63 0:edc50cf04b46 49 char1 = GSM.getc();}
tony63 0:edc50cf04b46 50 return;}
tony63 0:edc50cf04b46 51
tony63 0:edc50cf04b46 52 void callback() {
tony63 0:edc50cf04b46 53 // Note: you need to actually read from the serial to clear the RX interrupt
tony63 0:edc50cf04b46 54 pc.printf("%c\n", GSM.getc());
tony63 0:edc50cf04b46 55
tony63 0:edc50cf04b46 56 }
tony63 2:0377af333c98 57 //****************************************************************************************************************
tony63 2:0377af333c98 58 //esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de
tony63 2:0377af333c98 59 //$, count es lo que va a leer.Lo leido lo mete en buffer que es una cadena previamente definida
tony63 2:0377af333c98 60 //incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1
tony63 2:0377af333c98 61 //****************************************************************************************************************
tony63 0:edc50cf04b46 62 int readBuffer(char *buffer,int count)
tony63 0:edc50cf04b46 63 {
tony63 0:edc50cf04b46 64 int i=0;
tony63 0:edc50cf04b46 65 t.start(); // start timer
tony63 0:edc50cf04b46 66 while(1) {
tony63 0:edc50cf04b46 67 while (GSM.readable()) {
tony63 0:edc50cf04b46 68 char c = GSM.getc();
tony63 0:edc50cf04b46 69 if (c == '\r' || c == '\n') c = '$';
tony63 0:edc50cf04b46 70 buffer[i++] = c;
tony63 0:edc50cf04b46 71 if(i > count)break;
tony63 0:edc50cf04b46 72 }
tony63 0:edc50cf04b46 73 if(i > count)break;
tony63 0:edc50cf04b46 74 if(t.read() > 3) {
tony63 0:edc50cf04b46 75 t.stop();
tony63 0:edc50cf04b46 76 t.reset();
tony63 0:edc50cf04b46 77 break;
tony63 0:edc50cf04b46 78 }
tony63 0:edc50cf04b46 79 }
tony63 0:edc50cf04b46 80 wait(0.5);
tony63 0:edc50cf04b46 81 while(GSM.readable()) { // display the other thing..
tony63 0:edc50cf04b46 82 char c = GSM.getc();
tony63 0:edc50cf04b46 83 }
tony63 0:edc50cf04b46 84 return 0;
tony63 0:edc50cf04b46 85 }
tony63 2:0377af333c98 86 //********************************************************************************
tony63 0:edc50cf04b46 87 /* esta funcion de abajo limpia o borra todo un "buffer" de tamaño "count"
tony63 2:0377af333c98 88 lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena
tony63 0:edc50cf04b46 89 no retorna nada
tony63 0:edc50cf04b46 90 */
tony63 0:edc50cf04b46 91 //***************************************************************************************
tony63 0:edc50cf04b46 92 void cleanBuffer(char *buffer, int count)
tony63 0:edc50cf04b46 93 {
tony63 0:edc50cf04b46 94 for(int i=0; i < count; i++) {
tony63 0:edc50cf04b46 95 buffer[i] = '\0';
tony63 0:edc50cf04b46 96 }
tony63 0:edc50cf04b46 97 }
tony63 0:edc50cf04b46 98 /* esta funcion de abajo envia un comando parametrizado como cadena
tony63 2:0377af333c98 99 puede ser un comando tipo AT
tony63 0:edc50cf04b46 100 */
tony63 0:edc50cf04b46 101 //***************************************************************************************
tony63 0:edc50cf04b46 102 void sendCmd(char *cmd)
tony63 0:edc50cf04b46 103 {
tony63 0:edc50cf04b46 104 GSM.puts(cmd);
tony63 0:edc50cf04b46 105 }
tony63 2:0377af333c98 106 //****************************************************************************************
tony63 0:edc50cf04b46 107 /* esta funcion de abajo espera la respuesta de un comando que debe ser identica a la cadena "resp" y un tiempo timeout"
tony63 0:edc50cf04b46 108 si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 109 si algo sale mal ( no se parece o se demora mucho )retorna -1 que debera validarse con alguna expresion logica
tony63 0:edc50cf04b46 110 */
tony63 0:edc50cf04b46 111 //***************************************************************************************
tony63 0:edc50cf04b46 112 int waitForResp(char *resp, int timeout)
tony63 0:edc50cf04b46 113 {
tony63 0:edc50cf04b46 114 int len = strlen(resp);
tony63 0:edc50cf04b46 115 int sum=0;
tony63 0:edc50cf04b46 116 t.start();
tony63 0:edc50cf04b46 117
tony63 0:edc50cf04b46 118 while(1) {
tony63 0:edc50cf04b46 119 if(GSM.readable()) {
tony63 0:edc50cf04b46 120 char c = GSM.getc();
tony63 0:edc50cf04b46 121 sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c
tony63 0:edc50cf04b46 122 if(sum == len)break; //ya acabo se sale
tony63 0:edc50cf04b46 123 }
tony63 0:edc50cf04b46 124 if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo
tony63 0:edc50cf04b46 125 t.stop();
tony63 0:edc50cf04b46 126 t.reset();
tony63 0:edc50cf04b46 127 return -1;
tony63 0:edc50cf04b46 128 }
tony63 0:edc50cf04b46 129 }
tony63 0:edc50cf04b46 130 t.stop(); // stop timer antes de retornar
tony63 0:edc50cf04b46 131 t.reset(); // clear timer
tony63 0:edc50cf04b46 132 while(GSM.readable()) { // display the other thing..
tony63 0:edc50cf04b46 133 char c = GSM.getc();
tony63 0:edc50cf04b46 134 }
tony63 0:edc50cf04b46 135
tony63 0:edc50cf04b46 136 return 0;
tony63 0:edc50cf04b46 137 }
tony63 0:edc50cf04b46 138 /* esta funcion de abajo es muy completa e util se encarga de enviar el comando y esperar la respuesta
tony63 0:edc50cf04b46 139 si todo sale bien retorna un cero(herencia de las funciones contenedoras) que en la programacion hay que validar
tony63 0:edc50cf04b46 140 con alguna expresion logica
tony63 0:edc50cf04b46 141 */
tony63 0:edc50cf04b46 142 //***************************************************************************************
tony63 0:edc50cf04b46 143 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout)
tony63 0:edc50cf04b46 144 {
tony63 0:edc50cf04b46 145 sendCmd(cmd);
tony63 0:edc50cf04b46 146 return waitForResp(resp,timeout);
tony63 0:edc50cf04b46 147 }
tony63 0:edc50cf04b46 148 /* esta funcion de abajo chequea que el modem este vivo envia AT y le contesta con OK y espera 2 segundos
tony63 0:edc50cf04b46 149 */
tony63 0:edc50cf04b46 150 //***************************************************************************************
tony63 0:edc50cf04b46 151 int powerCheck(void)// este comando se manda para verificar si el modem esta vivo o conectado
tony63 0:edc50cf04b46 152 {
tony63 0:edc50cf04b46 153 return sendCmdAndWaitForResp("AT\r\n", "OK", 2);
tony63 0:edc50cf04b46 154 }
tony63 0:edc50cf04b46 155 /* esta funcion de abajo chequea el estado de la sim card
tony63 0:edc50cf04b46 156 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 157 con alguna expresion logica
tony63 0:edc50cf04b46 158 */
tony63 0:edc50cf04b46 159 //***************************************************************************************
tony63 0:edc50cf04b46 160 int checkSIMStatus(void)
tony63 0:edc50cf04b46 161 {
tony63 0:edc50cf04b46 162 char gprsBuffer[30];
tony63 0:edc50cf04b46 163 int count = 0;
tony63 0:edc50cf04b46 164 cleanBuffer(gprsBuffer,30);
tony63 0:edc50cf04b46 165 while(count < 3) {
tony63 0:edc50cf04b46 166 sendCmd("AT+CPIN?\r\n");
tony63 0:edc50cf04b46 167 readBuffer(gprsBuffer,30);
tony63 0:edc50cf04b46 168 if((NULL != strstr(gprsBuffer,"+CPIN: READY"))) {
tony63 0:edc50cf04b46 169 break;
tony63 0:edc50cf04b46 170 }
tony63 0:edc50cf04b46 171 count++;
tony63 0:edc50cf04b46 172 wait(1);
tony63 0:edc50cf04b46 173 }
tony63 0:edc50cf04b46 174
tony63 0:edc50cf04b46 175 if(count == 3) {
tony63 0:edc50cf04b46 176 return -1;
tony63 0:edc50cf04b46 177 }
tony63 0:edc50cf04b46 178 return 0;
tony63 0:edc50cf04b46 179 }
tony63 0:edc50cf04b46 180 /* esta funcion de abajo chequea la calidad de la señal
tony63 2:0377af333c98 181 y si todo sale bien retorna con el valor de señal util o un -1 si no es aceptable, en la programacion hay que validar
tony63 0:edc50cf04b46 182 con alguna expresion logica
tony63 0:edc50cf04b46 183 */
tony63 0:edc50cf04b46 184 //***************************************************************************************
tony63 0:edc50cf04b46 185 int checkSignalStrength(void)
tony63 0:edc50cf04b46 186 {
tony63 0:edc50cf04b46 187 char gprsBuffer[100];
tony63 0:edc50cf04b46 188 int index,count = 0;
tony63 0:edc50cf04b46 189 cleanBuffer(gprsBuffer,100);
tony63 0:edc50cf04b46 190 while(count < 3) {
tony63 0:edc50cf04b46 191 sendCmd("AT+CSQ\r\n");
tony63 0:edc50cf04b46 192 readBuffer(gprsBuffer,25);
tony63 0:edc50cf04b46 193 if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) {
tony63 0:edc50cf04b46 194 break;
tony63 0:edc50cf04b46 195 }
tony63 0:edc50cf04b46 196 count++;
tony63 0:edc50cf04b46 197 wait(1);
tony63 0:edc50cf04b46 198 }
tony63 0:edc50cf04b46 199 if(count == 3) {
tony63 0:edc50cf04b46 200 return -1;
tony63 0:edc50cf04b46 201 }
tony63 0:edc50cf04b46 202 return index;
tony63 0:edc50cf04b46 203 }
tony63 0:edc50cf04b46 204
tony63 0:edc50cf04b46 205 /* esta funcion de abajo inicaliza el modem se compone de un grupo de subfunciones ya definidas previamente
tony63 0:edc50cf04b46 206 primero chequea que este vivo
tony63 0:edc50cf04b46 207 segundo chequea el estado de la simcard
tony63 0:edc50cf04b46 208 tercero chequea la intencidad de señal celular
tony63 0:edc50cf04b46 209 cuarto aplica la configuracion
tony63 0:edc50cf04b46 210 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 211 con alguna expresion logica
tony63 0:edc50cf04b46 212 */
tony63 0:edc50cf04b46 213 //***************************************************************************************
tony63 0:edc50cf04b46 214 int init()
tony63 0:edc50cf04b46 215 {
tony63 2:0377af333c98 216 if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 3)){
tony63 2:0377af333c98 217 return -1;
tony63 2:0377af333c98 218 }
tony63 2:0377af333c98 219 if (0 != sendCmdAndWaitForResp("AT+CNMI=1,1\r\n", "OK", 3)){
tony63 2:0377af333c98 220 return -1;
tony63 2:0377af333c98 221 }
tony63 2:0377af333c98 222 if (0 != sendCmdAndWaitForResp("AT+CMGF=0\r\n", "OK", 3)){
tony63 0:edc50cf04b46 223 return -1;
tony63 2:0377af333c98 224 }
tony63 2:0377af333c98 225 if (0 != sendCmdAndWaitForResp("AT+CBST=0,0,1\r\n", "OK", 3)){
tony63 0:edc50cf04b46 226 return -1;
tony63 2:0377af333c98 227 }
tony63 2:0377af333c98 228 LedVerde=0;
tony63 2:0377af333c98 229 return 0;
tony63 2:0377af333c98 230 }
tony63 2:0377af333c98 231
tony63 0:edc50cf04b46 232 /* esta funcion de abajo intenta leer un mensaje de texto en formato PDU o HEX
tony63 0:edc50cf04b46 233 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 234 con alguna expresion logica
tony63 0:edc50cf04b46 235 */
tony63 0:edc50cf04b46 236 //***************************************************************************************
tony63 0:edc50cf04b46 237 int readSMSpdu(char *message, int index)
tony63 0:edc50cf04b46 238 {
tony63 0:edc50cf04b46 239 int i = 0;
tony63 0:edc50cf04b46 240 char gprsBuffer[100];
tony63 0:edc50cf04b46 241 char *p,*s;
tony63 0:edc50cf04b46 242 GSM.printf("AT+CMGR=%d\r\n",index);
tony63 0:edc50cf04b46 243 cleanBuffer(gprsBuffer,100);
tony63 0:edc50cf04b46 244 readBuffer(gprsBuffer,100);
tony63 0:edc50cf04b46 245 if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) {
tony63 0:edc50cf04b46 246 return -1;
tony63 0:edc50cf04b46 247 }
tony63 0:edc50cf04b46 248 if(NULL != ( s = strstr(gprsBuffer,"+32"))) {
tony63 0:edc50cf04b46 249 p = s + 6;
tony63 0:edc50cf04b46 250 while((*p != '$')&&(i < 5)) {
tony63 0:edc50cf04b46 251 message[i++] = *(p++);
tony63 0:edc50cf04b46 252 }
tony63 0:edc50cf04b46 253 message[i] = '\0';
tony63 0:edc50cf04b46 254 }
tony63 0:edc50cf04b46 255 return 0;
tony63 0:edc50cf04b46 256 }
tony63 0:edc50cf04b46 257 /* esta funcion de abajo borra mensajes SMS del modem
tony63 0:edc50cf04b46 258 y si todo sale bien retorna un cero que en la programacion hay que validar
tony63 0:edc50cf04b46 259 con alguna expresion logica
tony63 0:edc50cf04b46 260 */
tony63 0:edc50cf04b46 261 //***************************************************************************************
tony63 0:edc50cf04b46 262 int deleteSMS(int index)
tony63 0:edc50cf04b46 263 {
tony63 0:edc50cf04b46 264 char cmd[32];
tony63 0:edc50cf04b46 265 snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index);
tony63 0:edc50cf04b46 266 sendCmd(cmd);
tony63 0:edc50cf04b46 267 return 0;
tony63 0:edc50cf04b46 268 }
tony63 2:0377af333c98 269 //************************************************************************************
tony63 0:edc50cf04b46 270
tony63 2:0377af333c98 271 //RUTINA PRINCIPAL*******************************************************************************************
tony63 0:edc50cf04b46 272 int main(void)
tony63 2:0377af333c98 273 {
tony63 2:0377af333c98 274 //configuramos los puertos seriales
tony63 2:0377af333c98 275 GSM.baud(9600);//configura los baudios de la FRDMKL25Z en 9600
tony63 2:0377af333c98 276 GSM.format(8,Serial::None,1); //configura el formato de los datos de la UART
tony63 0:edc50cf04b46 277 //apagamos los 3 leds
tony63 0:edc50cf04b46 278 LedVerde=1;
tony63 0:edc50cf04b46 279 LedRojo=1;
tony63 0:edc50cf04b46 280 LedAzul=1;
tony63 2:0377af333c98 281 //quito el eco del modem
tony63 2:0377af333c98 282 GSM.printf("ATE0\r\n");
tony63 2:0377af333c98 283 pc.printf("ATE0\r\n");
tony63 2:0377af333c98 284 for(i=0;i<6;i++){
tony63 2:0377af333c98 285 GSM.printf("AT+CMGD=%d\r\n",i);
tony63 2:0377af333c98 286 wait(0.2);
tony63 2:0377af333c98 287 }
tony63 2:0377af333c98 288 //cleanBuffer(buffer,10);
tony63 2:0377af333c98 289 //definicion de algunas variables
tony63 0:edc50cf04b46 290 lenpack=6; //tamaño de "ALARMA"
tony63 2:0377af333c98 291 //Configuro el Modem, le doy solo 10 intentos si esos fracasan se bloquea y prende intermitente el led rojo
tony63 2:0377af333c98 292 inicio:if(init()<0){
tony63 2:0377af333c98 293 intentos++;
tony63 2:0377af333c98 294 if (intentos==10){goto loop1;}
tony63 2:0377af333c98 295 goto inicio;
tony63 2:0377af333c98 296 }
tony63 2:0377af333c98 297 //cleanBuffer(buffer,50);
tony63 2:0377af333c98 298 //inicia el programa ciclico
tony63 2:0377af333c98 299 //esperar señales de alarma por boton1
tony63 2:0377af333c98 300 //se envia "Alarma1"
tony63 2:0377af333c98 301 //al telefono que envio mensaje antes
tony63 2:0377af333c98 302
tony63 2:0377af333c98 303 //*********************************************************************************************************************
tony63 2:0377af333c98 304 while(1){
tony63 2:0377af333c98 305 if (button1.falling())
tony63 2:0377af333c98 306 {
tony63 0:edc50cf04b46 307 wait(2);
tony63 0:edc50cf04b46 308 if (!button1)
tony63 2:0377af333c98 309 {
tony63 2:0377af333c98 310 //inicia el envio de un sms
tony63 2:0377af333c98 311 index=19;
tony63 2:0377af333c98 312 GSM.printf("AT+CMGS=%d\r\n",index);
tony63 2:0377af333c98 313 wait(0.2);
tony63 2:0377af333c98 314 GSM.printf("0011000A91");
tony63 2:0377af333c98 315 GSM.printf("%s",tel);
tony63 2:0377af333c98 316 GSM.printf("0000AA07417658DE0EC7");
tony63 2:0377af333c98 317 GSM.printf("\r\n");
tony63 2:0377af333c98 318 wait(0.2);
tony63 2:0377af333c98 319 GSM.putc(0x1A); //el mensaje ya fue enviado con esto
tony63 2:0377af333c98 320 for(i=0;i<6;i++){
tony63 2:0377af333c98 321 LedVerde=1;
tony63 2:0377af333c98 322 wait(0.5);
tony63 2:0377af333c98 323 LedVerde=0;
tony63 2:0377af333c98 324 wait(0.5);
tony63 2:0377af333c98 325 }
tony63 2:0377af333c98 326 }
tony63 2:0377af333c98 327 }
tony63 2:0377af333c98 328
tony63 2:0377af333c98 329
tony63 2:0377af333c98 330
tony63 2:0377af333c98 331 //inicia la recepcion de un mensaje de texto
tony63 2:0377af333c98 332 if (GSM.readable()) {
tony63 2:0377af333c98 333 readBuffer(buffer,100);
tony63 2:0377af333c98 334 pc.printf("%s\r\n",buffer);
tony63 2:0377af333c98 335 for(i=0;i<5;i++)
tony63 2:0377af333c98 336 {
tony63 2:0377af333c98 337 resp[i]=buffer[i];
tony63 2:0377af333c98 338 }
tony63 2:0377af333c98 339
tony63 2:0377af333c98 340 pc.printf("%s\r\n",resp);
tony63 2:0377af333c98 341 if(strcmp("$$+CM",resp) == 0){ //COMPARA resp con "+CMTI"
tony63 2:0377af333c98 342 pc.printf("llego MSG\r\n");
tony63 2:0377af333c98 343 cleanBuffer(buffer,10);
tony63 2:0377af333c98 344 wait(0.5);
tony63 2:0377af333c98 345 GSM.printf("AT+CMGL=0\r\n");//envio comando para leer mensaje
tony63 2:0377af333c98 346 pc.printf("AT+CMGL=0\r\n");
tony63 2:0377af333c98 347 //if (GSM.readable()) {
tony63 2:0377af333c98 348 GSM.printf("AT+CMGD=0\r\n");
tony63 2:0377af333c98 349 readBuffer(buffer,100);
tony63 2:0377af333c98 350 pc.printf("%s\r\n",buffer);
tony63 2:0377af333c98 351 wait(5);
tony63 2:0377af333c98 352 //leer telefono
tony63 2:0377af333c98 353 for(i=0;i<10;i++){
tony63 2:0377af333c98 354 tel[i]=buffer[i+40];
tony63 2:0377af333c98 355 }
demo71 3:fa94bd2cb170 356 pc.printf("TELEFONO");
tony63 2:0377af333c98 357 pc.printf("%s-\r\n",tel);
tony63 2:0377af333c98 358 //leer tamaño
tony63 2:0377af333c98 359 for(i=0;i<2;i++){
tony63 2:0377af333c98 360 tam[i]=buffer[i+68];
tony63 2:0377af333c98 361 }
tony63 2:0377af333c98 362 pc.printf("%s-\r\n",tam);
tony63 2:0377af333c98 363 //leer mensaje
tony63 2:0377af333c98 364 for(i=0;i<14;i++){
tony63 2:0377af333c98 365 msg[i]=buffer[i+70];
tony63 2:0377af333c98 366 }
tony63 2:0377af333c98 367 pc.printf("%s-\r\n",msg);
tony63 2:0377af333c98 368 //decodificar mensaje
tony63 2:0377af333c98 369 //comparar mensaje
tony63 2:0377af333c98 370 if(strcmp("417658DE0EC700",msg) == 0){ //COMPARA resp con "417658DE0EC700" que es Alarma1
tony63 2:0377af333c98 371 LedVerde=1;
tony63 2:0377af333c98 372 LedAzul=0;
tony63 2:0377af333c98 373 wait(15);
tony63 2:0377af333c98 374 LedAzul=1;
tony63 2:0377af333c98 375 LedVerde=0;
tony63 2:0377af333c98 376 }
tony63 2:0377af333c98 377 if(strcmp("417658DE0ECB00",msg) == 0){ //COMPARA resp con "417658DE0ECB00" que es Alarma2
tony63 2:0377af333c98 378 LedVerde=1;
tony63 2:0377af333c98 379 LedRojo=0;
tony63 2:0377af333c98 380 wait(15);
tony63 2:0377af333c98 381 LedRojo=1;
tony63 2:0377af333c98 382 LedVerde=0;
tony63 2:0377af333c98 383 }
tony63 2:0377af333c98 384
tony63 2:0377af333c98 385
tony63 2:0377af333c98 386 //ejecurar orden
tony63 2:0377af333c98 387 cleanBuffer(buffer,100);
tony63 2:0377af333c98 388
tony63 2:0377af333c98 389 }
tony63 1:6b506dde0a6e 390 }
tony63 2:0377af333c98 391
tony63 2:0377af333c98 392
tony63 2:0377af333c98 393 }
tony63 2:0377af333c98 394
tony63 1:6b506dde0a6e 395
tony63 2:0377af333c98 396 //**********************************************************************************************************************
tony63 2:0377af333c98 397 loop1: LedRojo=0;
tony63 2:0377af333c98 398 wait(0.3);
tony63 2:0377af333c98 399 LedRojo=1;
tony63 2:0377af333c98 400 wait(0.3);
tony63 2:0377af333c98 401 goto loop1;
tony63 2:0377af333c98 402
tony63 2:0377af333c98 403 }