Tarea GSM GPS
Dependencies: GPS7 TextLCD mbed
main.cpp@0:3171e1737767, 2015-06-18 (annotated)
- Committer:
- caarbelaezg
- Date:
- Thu Jun 18 16:26:15 2015 +0000
- Revision:
- 0:3171e1737767
Tarea GPS GSM
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
caarbelaezg | 0:3171e1737767 | 1 | #include "mbed.h" |
caarbelaezg | 0:3171e1737767 | 2 | #include "stdio.h" |
caarbelaezg | 0:3171e1737767 | 3 | #include "string.h" |
caarbelaezg | 0:3171e1737767 | 4 | #include "iostream" |
caarbelaezg | 0:3171e1737767 | 5 | #include "TextLCD.h" |
caarbelaezg | 0:3171e1737767 | 6 | #include "GPS.h" |
caarbelaezg | 0:3171e1737767 | 7 | #include "stdlib.h" |
caarbelaezg | 0:3171e1737767 | 8 | |
caarbelaezg | 0:3171e1737767 | 9 | |
caarbelaezg | 0:3171e1737767 | 10 | Serial gsm(PTE0,PTE1); // Se declaran puertos para la comunicacíón GSM |
caarbelaezg | 0:3171e1737767 | 11 | Serial pc(USBTX,USBRX); // Puerto seríal de la Freescale para el envio de datos |
caarbelaezg | 0:3171e1737767 | 12 | GPS gps(PTD7, PTD6); |
caarbelaezg | 0:3171e1737767 | 13 | DigitalOut myled(LED1); |
caarbelaezg | 0:3171e1737767 | 14 | |
caarbelaezg | 0:3171e1737767 | 15 | |
caarbelaezg | 0:3171e1737767 | 16 | char buf[200], pdu[]="", vect1[]="", vect2[]="", DE[255], DS[255], DEs[255], DSs[255], Ctamanosms[1], Ctiposmsc[1], Csmscnumber[12], Cdeliver[1], Ctamanoaddress[1], Ctipoaddress[1], Cnumero[11], Cprotocolo[1], Cencoding[1], Ctime[14], Ctamano[1], Cdato[30];; // Variables para almacenar las cadenas de caracteres |
caarbelaezg | 0:3171e1737767 | 17 | int i,K,C,LENOUT,LENIN, w, r, ta; // Auxiliares |
caarbelaezg | 0:3171e1737767 | 18 | float lo,la; // Variables para almacenar corrdenadas |
caarbelaezg | 0:3171e1737767 | 19 | char LINK[]= {"http://maps.google.com/?q="}; // Trama base |
caarbelaezg | 0:3171e1737767 | 20 | |
caarbelaezg | 0:3171e1737767 | 21 | |
caarbelaezg | 0:3171e1737767 | 22 | int main() |
caarbelaezg | 0:3171e1737767 | 23 | { pc.printf("************************** INICIO DEL PROGRAMA ***********************"); |
caarbelaezg | 0:3171e1737767 | 24 | // Configuración para la comunicacion con el celular |
caarbelaezg | 0:3171e1737767 | 25 | pc.printf("\n ---------------------- Configuracion para la comunicacion con el celular---------------\n"); |
caarbelaezg | 0:3171e1737767 | 26 | gsm.baud(9600); // Configuracion de los baudios |
caarbelaezg | 0:3171e1737767 | 27 | gsm.format(8,Serial::None,1); // 8 Bits sin paridad |
caarbelaezg | 0:3171e1737767 | 28 | std::string strOK ("OK"); // para comparar con las respuestas AT |
caarbelaezg | 0:3171e1737767 | 29 | |
caarbelaezg | 0:3171e1737767 | 30 | pc.printf("\n Enviamos AT \n"); // Apreton de manos con el gsm |
caarbelaezg | 0:3171e1737767 | 31 | gsm.printf("AT\r\n"); |
caarbelaezg | 0:3171e1737767 | 32 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 33 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 34 | pc.printf("%s\n",buf); |
caarbelaezg | 0:3171e1737767 | 35 | |
caarbelaezg | 0:3171e1737767 | 36 | if(strOK.compare(buf) != 0){ |
caarbelaezg | 0:3171e1737767 | 37 | pc.printf("Aborten comunicacion"); |
caarbelaezg | 0:3171e1737767 | 38 | } |
caarbelaezg | 0:3171e1737767 | 39 | |
caarbelaezg | 0:3171e1737767 | 40 | |
caarbelaezg | 0:3171e1737767 | 41 | |
caarbelaezg | 0:3171e1737767 | 42 | gsm.printf("\n AT+CNMI=1,1\r\n"); // Configuracion para trabjar sobre la memoria de la simcard |
caarbelaezg | 0:3171e1737767 | 43 | pc.printf("AT+CNMI=1,1\r\n"); |
caarbelaezg | 0:3171e1737767 | 44 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 45 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 46 | pc.printf(">%s\n",buf); |
caarbelaezg | 0:3171e1737767 | 47 | if(strOK.compare(buf) != 0){ |
caarbelaezg | 0:3171e1737767 | 48 | pc.printf("Aborten comunicacion"); |
caarbelaezg | 0:3171e1737767 | 49 | } |
caarbelaezg | 0:3171e1737767 | 50 | |
caarbelaezg | 0:3171e1737767 | 51 | |
caarbelaezg | 0:3171e1737767 | 52 | |
caarbelaezg | 0:3171e1737767 | 53 | gsm.printf("\n AT+CPMS= \"SM\",\"SM\",\"SM\"\r\n"); // |
caarbelaezg | 0:3171e1737767 | 54 | pc.printf("AT+CPMS= \"SM\",\"SM\",\"SM\"\n"); |
caarbelaezg | 0:3171e1737767 | 55 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 56 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 57 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 58 | pc.printf(">%s\n",buf); |
caarbelaezg | 0:3171e1737767 | 59 | wait(1); |
caarbelaezg | 0:3171e1737767 | 60 | |
caarbelaezg | 0:3171e1737767 | 61 | |
caarbelaezg | 0:3171e1737767 | 62 | gsm.printf("\n AT+CMGF=0\r\n"); // Configuracion para trabajar en modo PDU |
caarbelaezg | 0:3171e1737767 | 63 | pc.printf("AT+CMGF=0\r\n"); |
caarbelaezg | 0:3171e1737767 | 64 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 65 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 66 | pc.printf(">%s\n",buf); |
caarbelaezg | 0:3171e1737767 | 67 | |
caarbelaezg | 0:3171e1737767 | 68 | if(strOK.compare(buf) != 0){ |
caarbelaezg | 0:3171e1737767 | 69 | pc.printf("Aborten comunicacion"); |
caarbelaezg | 0:3171e1737767 | 70 | } |
caarbelaezg | 0:3171e1737767 | 71 | |
caarbelaezg | 0:3171e1737767 | 72 | pc.printf("\n CBST=0,0,1\r\n"); |
caarbelaezg | 0:3171e1737767 | 73 | gsm.printf("CBST=0,0,1\r\n"); // para dejar en espera de mensajes entrantes |
caarbelaezg | 0:3171e1737767 | 74 | |
caarbelaezg | 0:3171e1737767 | 75 | |
caarbelaezg | 0:3171e1737767 | 76 | |
caarbelaezg | 0:3171e1737767 | 77 | while(1) { |
caarbelaezg | 0:3171e1737767 | 78 | |
caarbelaezg | 0:3171e1737767 | 79 | pc.printf("\n ----------- En espera de Mensaje entrante -------------------\n"); // En espera de mensaje entrante |
caarbelaezg | 0:3171e1737767 | 80 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 81 | pc.printf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 82 | i = strlen(buf); |
caarbelaezg | 0:3171e1737767 | 83 | |
caarbelaezg | 0:3171e1737767 | 84 | |
caarbelaezg | 0:3171e1737767 | 85 | |
caarbelaezg | 0:3171e1737767 | 86 | if(i>3) { // En caso de que se reciba un mensaje se entra al este if |
caarbelaezg | 0:3171e1737767 | 87 | |
caarbelaezg | 0:3171e1737767 | 88 | |
caarbelaezg | 0:3171e1737767 | 89 | |
caarbelaezg | 0:3171e1737767 | 90 | pc.printf("\n ------------- Llego un Mensaje ------------------- \n"); |
caarbelaezg | 0:3171e1737767 | 91 | gsm.printf("AT+CMGR=1\r\n"); // Se lee el menjsae que ente en el indice 1. |
caarbelaezg | 0:3171e1737767 | 92 | |
caarbelaezg | 0:3171e1737767 | 93 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 94 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 95 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 96 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 97 | pc.printf(">%s \n",buf); //Mostrar la cadena en PDU del mensaje leido. |
caarbelaezg | 0:3171e1737767 | 98 | |
caarbelaezg | 0:3171e1737767 | 99 | |
caarbelaezg | 0:3171e1737767 | 100 | int T = strlen(buf); // Se toma la longitud del mensaje leido |
caarbelaezg | 0:3171e1737767 | 101 | |
caarbelaezg | 0:3171e1737767 | 102 | pc.printf("\n ----------------- Comiensa lectura de la trama PDU entrante : %d -------\n", T); // Se comiensa a separar la trama pdu para extraer informacion especifica |
caarbelaezg | 0:3171e1737767 | 103 | |
caarbelaezg | 0:3171e1737767 | 104 | Ctamanosms[0]=buf[0]; // Se toma el tamaño en septetos de toda la trama pdu |
caarbelaezg | 0:3171e1737767 | 105 | Ctamanosms[1]=buf[1]; |
caarbelaezg | 0:3171e1737767 | 106 | pc.printf("Longitud del mensaje en septetos %c%c en septetos \n", Ctamanosms[0], Ctamanosms[1]); |
caarbelaezg | 0:3171e1737767 | 107 | |
caarbelaezg | 0:3171e1737767 | 108 | Ctiposmsc[0]=buf[2]; // Tipo de mensaje |
caarbelaezg | 0:3171e1737767 | 109 | Ctiposmsc[1]=buf[3]; |
caarbelaezg | 0:3171e1737767 | 110 | pc.printf("Tipo de direccion SMSC %c%c \n", Ctiposmsc[0], Ctiposmsc[1]); |
caarbelaezg | 0:3171e1737767 | 111 | |
caarbelaezg | 0:3171e1737767 | 112 | Csmscnumber[0]=buf[4]; // numero del sms |
caarbelaezg | 0:3171e1737767 | 113 | Csmscnumber[1]=buf[5]; |
caarbelaezg | 0:3171e1737767 | 114 | Csmscnumber[2]=buf[6]; |
caarbelaezg | 0:3171e1737767 | 115 | Csmscnumber[3]=buf[7]; |
caarbelaezg | 0:3171e1737767 | 116 | Csmscnumber[4]=buf[8]; |
caarbelaezg | 0:3171e1737767 | 117 | Csmscnumber[5]=buf[9]; |
caarbelaezg | 0:3171e1737767 | 118 | Csmscnumber[6]=buf[10]; |
caarbelaezg | 0:3171e1737767 | 119 | Csmscnumber[7]=buf[11]; |
caarbelaezg | 0:3171e1737767 | 120 | Csmscnumber[8]=buf[12]; |
caarbelaezg | 0:3171e1737767 | 121 | Csmscnumber[9]=buf[13]; |
caarbelaezg | 0:3171e1737767 | 122 | Csmscnumber[10]=buf[14]; |
caarbelaezg | 0:3171e1737767 | 123 | Csmscnumber[11]=buf[15]; |
caarbelaezg | 0:3171e1737767 | 124 | |
caarbelaezg | 0:3171e1737767 | 125 | pc.printf("Numero del SMSC %s \n", Csmscnumber); |
caarbelaezg | 0:3171e1737767 | 126 | Cdeliver[0]=buf[16]; |
caarbelaezg | 0:3171e1737767 | 127 | Cdeliver[1]=buf[17]; |
caarbelaezg | 0:3171e1737767 | 128 | |
caarbelaezg | 0:3171e1737767 | 129 | Ctamanoaddress[0]=buf[18]; |
caarbelaezg | 0:3171e1737767 | 130 | Ctamanoaddress[1]=buf[19]; |
caarbelaezg | 0:3171e1737767 | 131 | |
caarbelaezg | 0:3171e1737767 | 132 | Ctipoaddress[0]=buf[20]; |
caarbelaezg | 0:3171e1737767 | 133 | Ctipoaddress[1]=buf[21]; |
caarbelaezg | 0:3171e1737767 | 134 | |
caarbelaezg | 0:3171e1737767 | 135 | Cnumero[0]=buf[22]; // Numero del usuario |
caarbelaezg | 0:3171e1737767 | 136 | Cnumero[1]=buf[23]; |
caarbelaezg | 0:3171e1737767 | 137 | Cnumero[2]=buf[24]; |
caarbelaezg | 0:3171e1737767 | 138 | Cnumero[3]=buf[25]; |
caarbelaezg | 0:3171e1737767 | 139 | Cnumero[4]=buf[26]; |
caarbelaezg | 0:3171e1737767 | 140 | Cnumero[5]=buf[27]; |
caarbelaezg | 0:3171e1737767 | 141 | Cnumero[6]=buf[28]; |
caarbelaezg | 0:3171e1737767 | 142 | Cnumero[7]=buf[29]; |
caarbelaezg | 0:3171e1737767 | 143 | Cnumero[8]=buf[30]; |
caarbelaezg | 0:3171e1737767 | 144 | Cnumero[9]=buf[31]; |
caarbelaezg | 0:3171e1737767 | 145 | Cnumero[10]=buf[32]; |
caarbelaezg | 0:3171e1737767 | 146 | Cnumero[11]=buf[33]; |
caarbelaezg | 0:3171e1737767 | 147 | |
caarbelaezg | 0:3171e1737767 | 148 | pc.printf("Numero del usuario %s \n", Cnumero); |
caarbelaezg | 0:3171e1737767 | 149 | |
caarbelaezg | 0:3171e1737767 | 150 | |
caarbelaezg | 0:3171e1737767 | 151 | Cprotocolo[0]=buf[34]; // Protocolo utilizado |
caarbelaezg | 0:3171e1737767 | 152 | Cprotocolo[1]=buf[35]; |
caarbelaezg | 0:3171e1737767 | 153 | |
caarbelaezg | 0:3171e1737767 | 154 | Cencoding[0]=buf[36]; // Tipo de cifrado |
caarbelaezg | 0:3171e1737767 | 155 | Cencoding[1]=buf[37]; |
caarbelaezg | 0:3171e1737767 | 156 | |
caarbelaezg | 0:3171e1737767 | 157 | Ctime[0]=buf[38]; // Tiempo en el que se envio el menaje |
caarbelaezg | 0:3171e1737767 | 158 | Ctime[1]=buf[39]; |
caarbelaezg | 0:3171e1737767 | 159 | Ctime[2]=buf[40]; |
caarbelaezg | 0:3171e1737767 | 160 | Ctime[3]=buf[41]; |
caarbelaezg | 0:3171e1737767 | 161 | Ctime[4]=buf[42]; |
caarbelaezg | 0:3171e1737767 | 162 | Ctime[5]=buf[43]; |
caarbelaezg | 0:3171e1737767 | 163 | Ctime[6]=buf[44]; |
caarbelaezg | 0:3171e1737767 | 164 | Ctime[7]=buf[45]; |
caarbelaezg | 0:3171e1737767 | 165 | Ctime[8]=buf[46]; |
caarbelaezg | 0:3171e1737767 | 166 | Ctime[9]=buf[47]; |
caarbelaezg | 0:3171e1737767 | 167 | Ctime[10]=buf[48]; |
caarbelaezg | 0:3171e1737767 | 168 | Ctime[11]=buf[49]; |
caarbelaezg | 0:3171e1737767 | 169 | Ctime[12]=buf[50]; |
caarbelaezg | 0:3171e1737767 | 170 | Ctime[13]=buf[51]; |
caarbelaezg | 0:3171e1737767 | 171 | |
caarbelaezg | 0:3171e1737767 | 172 | Ctamano[0]=buf[50]; // Tamaño de los datos (longitud de la parte legible) |
caarbelaezg | 0:3171e1737767 | 173 | Ctamano[1]=buf[51]; |
caarbelaezg | 0:3171e1737767 | 174 | |
caarbelaezg | 0:3171e1737767 | 175 | |
caarbelaezg | 0:3171e1737767 | 176 | ta=(Ctamano[0]-48)*16+(Ctamano[1]-48); // Suponiendo que son mensajes no muy grandes como solo se espera recibir cor, on y off es suficiente se transforman de caracter a su valor numerico y luego se ponderan |
caarbelaezg | 0:3171e1737767 | 177 | |
caarbelaezg | 0:3171e1737767 | 178 | pc.printf("Numero de carcteres del mensaje entrante %d \n", ta); |
caarbelaezg | 0:3171e1737767 | 179 | |
caarbelaezg | 0:3171e1737767 | 180 | pc.printf(" Posicion de los datos en el mensaje PDU %d \n", T-2*ta); // posicion de los datos en la trama pdu |
caarbelaezg | 0:3171e1737767 | 181 | |
caarbelaezg | 0:3171e1737767 | 182 | for(i=0; i<2*ta; i++){ //Toma de los datos o mensaje |
caarbelaezg | 0:3171e1737767 | 183 | Cdato[i]=buf[52+i]; |
caarbelaezg | 0:3171e1737767 | 184 | } |
caarbelaezg | 0:3171e1737767 | 185 | |
caarbelaezg | 0:3171e1737767 | 186 | ///// Se comeinsa la convercion de PDU a Texto |
caarbelaezg | 0:3171e1737767 | 187 | |
caarbelaezg | 0:3171e1737767 | 188 | pc.printf("\n------------- Comienza la convercion de PDU a texto ------------------\n"); |
caarbelaezg | 0:3171e1737767 | 189 | |
caarbelaezg | 0:3171e1737767 | 190 | LENIN=strlen(Cdato)/2; |
caarbelaezg | 0:3171e1737767 | 191 | w=0; |
caarbelaezg | 0:3171e1737767 | 192 | pc.printf(" Tamano de los datos %d \n", strlen(Cdato)); |
caarbelaezg | 0:3171e1737767 | 193 | for(i=0; i<=strlen(Cdato); i++){ |
caarbelaezg | 0:3171e1737767 | 194 | if(i%2==0){ |
caarbelaezg | 0:3171e1737767 | 195 | if(Cdato[i]>47 & Cdato[i]<58){ // primero se asigna el valor numerico de cada caracter en caso de ser 0-9 se le resta 48 en caso de ser letra se le resta 55 |
caarbelaezg | 0:3171e1737767 | 196 | Cdato[i]= Cdato[i]-48; |
caarbelaezg | 0:3171e1737767 | 197 | } |
caarbelaezg | 0:3171e1737767 | 198 | |
caarbelaezg | 0:3171e1737767 | 199 | if(Cdato[i]>65 & Cdato[i]<71){ |
caarbelaezg | 0:3171e1737767 | 200 | Cdato[i]=Cdato[i]-55; |
caarbelaezg | 0:3171e1737767 | 201 | |
caarbelaezg | 0:3171e1737767 | 202 | } |
caarbelaezg | 0:3171e1737767 | 203 | |
caarbelaezg | 0:3171e1737767 | 204 | } |
caarbelaezg | 0:3171e1737767 | 205 | else{ |
caarbelaezg | 0:3171e1737767 | 206 | if(Cdato[i]>47 & Cdato[i]<58){ |
caarbelaezg | 0:3171e1737767 | 207 | Cdato[i]= Cdato[i]-48; |
caarbelaezg | 0:3171e1737767 | 208 | } |
caarbelaezg | 0:3171e1737767 | 209 | |
caarbelaezg | 0:3171e1737767 | 210 | if(Cdato[i]>65 & Cdato[i]<71){ |
caarbelaezg | 0:3171e1737767 | 211 | Cdato[i]=Cdato[i]-55; |
caarbelaezg | 0:3171e1737767 | 212 | |
caarbelaezg | 0:3171e1737767 | 213 | } |
caarbelaezg | 0:3171e1737767 | 214 | |
caarbelaezg | 0:3171e1737767 | 215 | DE[w]= Cdato[i-1]*16+Cdato[i]; // aqui se pondera cada caracter y se suma con su predecesor par dar el peso de la tupla |
caarbelaezg | 0:3171e1737767 | 216 | pc.printf("Datos en hexagesimal DE[%d] %2X \n", w, DE[w]); // Se guarda la dupla en el vector DE |
caarbelaezg | 0:3171e1737767 | 217 | w=w+1; |
caarbelaezg | 0:3171e1737767 | 218 | } |
caarbelaezg | 0:3171e1737767 | 219 | } |
caarbelaezg | 0:3171e1737767 | 220 | |
caarbelaezg | 0:3171e1737767 | 221 | |
caarbelaezg | 0:3171e1737767 | 222 | //----------------------------------- --------------------------- |
caarbelaezg | 0:3171e1737767 | 223 | LENOUT= LENIN*8/7; |
caarbelaezg | 0:3171e1737767 | 224 | K=7; |
caarbelaezg | 0:3171e1737767 | 225 | C=0; |
caarbelaezg | 0:3171e1737767 | 226 | DS[0]=DE[0] & 0x7F; // la primera sola |
caarbelaezg | 0:3171e1737767 | 227 | pc.printf("%2X,%d,%d\r\n",DS[0],i,K); |
caarbelaezg | 0:3171e1737767 | 228 | for (i=1;i < LENOUT;i++){ // inicia el algoritmo |
caarbelaezg | 0:3171e1737767 | 229 | DS[i]=(DE[i-1-C]>>K | DE[i-C]<<(8-K))& 0x7F; //valido para todos |
caarbelaezg | 0:3171e1737767 | 230 | pc.printf("%2X,%d,%d\r\n",DS[i],i,K); |
caarbelaezg | 0:3171e1737767 | 231 | if (K==0) {K=8;C++;} |
caarbelaezg | 0:3171e1737767 | 232 | K--; |
caarbelaezg | 0:3171e1737767 | 233 | } |
caarbelaezg | 0:3171e1737767 | 234 | pc.printf("\n El Mensaje de llegada es: "); |
caarbelaezg | 0:3171e1737767 | 235 | for (i=0;i < LENOUT;i++){ |
caarbelaezg | 0:3171e1737767 | 236 | pc.printf("%c",DS[i]); |
caarbelaezg | 0:3171e1737767 | 237 | } |
caarbelaezg | 0:3171e1737767 | 238 | pc.printf("\n ------ Fin de la convercion de de los datos desde PDU a texto \n"); |
caarbelaezg | 0:3171e1737767 | 239 | |
caarbelaezg | 0:3171e1737767 | 240 | } |
caarbelaezg | 0:3171e1737767 | 241 | |
caarbelaezg | 0:3171e1737767 | 242 | std::string str1 ("cor"); // Cadenas par comparar el tipo de mensaje entrante |
caarbelaezg | 0:3171e1737767 | 243 | std::string str2 ("on"); |
caarbelaezg | 0:3171e1737767 | 244 | std::string str3 ("off"); |
caarbelaezg | 0:3171e1737767 | 245 | |
caarbelaezg | 0:3171e1737767 | 246 | |
caarbelaezg | 0:3171e1737767 | 247 | if(str2.compare(DS) == 0) { // En caso de que llegue on |
caarbelaezg | 0:3171e1737767 | 248 | pc.printf("\n--------------- LLego on ----------------"); |
caarbelaezg | 0:3171e1737767 | 249 | myled = 0; |
caarbelaezg | 0:3171e1737767 | 250 | gsm.printf("AT+CMGD=1\r\n"); |
caarbelaezg | 0:3171e1737767 | 251 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 252 | pc.printf("\n%s\n",buf); |
caarbelaezg | 0:3171e1737767 | 253 | |
caarbelaezg | 0:3171e1737767 | 254 | }//if de on |
caarbelaezg | 0:3171e1737767 | 255 | |
caarbelaezg | 0:3171e1737767 | 256 | if(str3.compare(DS) == 0) { // En caso de que llegue off |
caarbelaezg | 0:3171e1737767 | 257 | pc.printf("\n---------- LLego off --------------- \n"); |
caarbelaezg | 0:3171e1737767 | 258 | myled = 1; |
caarbelaezg | 0:3171e1737767 | 259 | gsm.printf("AT+CMGD=1\r\n"); |
caarbelaezg | 0:3171e1737767 | 260 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 261 | pc.printf("\n%s\n",buf); |
caarbelaezg | 0:3171e1737767 | 262 | |
caarbelaezg | 0:3171e1737767 | 263 | }//if de off |
caarbelaezg | 0:3171e1737767 | 264 | |
caarbelaezg | 0:3171e1737767 | 265 | if(str1.compare(DS) == 0) { // En caso de que se pidan las coordenadas |
caarbelaezg | 0:3171e1737767 | 266 | |
caarbelaezg | 0:3171e1737767 | 267 | pc.printf("\n ----------------- LLego cor ------------\n"); |
caarbelaezg | 0:3171e1737767 | 268 | pc.printf("Esperando GPS \n"); // Se espera hasta que el gps entregue datos |
caarbelaezg | 0:3171e1737767 | 269 | |
caarbelaezg | 0:3171e1737767 | 270 | while(1) { |
caarbelaezg | 0:3171e1737767 | 271 | i=0; |
caarbelaezg | 0:3171e1737767 | 272 | if(gps.sample()& i==0) { |
caarbelaezg | 0:3171e1737767 | 273 | |
caarbelaezg | 0:3171e1737767 | 274 | pc.printf("--- Comienza la lectura del gps \n"); |
caarbelaezg | 0:3171e1737767 | 275 | //Toma de datos del gps y concatenacion para armar los datos. |
caarbelaezg | 0:3171e1737767 | 276 | |
caarbelaezg | 0:3171e1737767 | 277 | la=gps.longitude; |
caarbelaezg | 0:3171e1737767 | 278 | lo=gps.latitude; |
caarbelaezg | 0:3171e1737767 | 279 | sprintf(vect1, "%f", lo); |
caarbelaezg | 0:3171e1737767 | 280 | strcat(LINK,vect1); |
caarbelaezg | 0:3171e1737767 | 281 | strcat(LINK,","); |
caarbelaezg | 0:3171e1737767 | 282 | |
caarbelaezg | 0:3171e1737767 | 283 | |
caarbelaezg | 0:3171e1737767 | 284 | sprintf(vect2, "%f", la); |
caarbelaezg | 0:3171e1737767 | 285 | strcat(LINK,vect2); |
caarbelaezg | 0:3171e1737767 | 286 | strcat(DEs,LINK); |
caarbelaezg | 0:3171e1737767 | 287 | pc.printf("%s\n",LINK); |
caarbelaezg | 0:3171e1737767 | 288 | |
caarbelaezg | 0:3171e1737767 | 289 | |
caarbelaezg | 0:3171e1737767 | 290 | //Conversion de los datos"LINK" a formatdo PDU |
caarbelaezg | 0:3171e1737767 | 291 | |
caarbelaezg | 0:3171e1737767 | 292 | LENIN=strlen(DEs); |
caarbelaezg | 0:3171e1737767 | 293 | |
caarbelaezg | 0:3171e1737767 | 294 | K=0; |
caarbelaezg | 0:3171e1737767 | 295 | C=0; |
caarbelaezg | 0:3171e1737767 | 296 | for (i=0; i < LENIN; i++) { |
caarbelaezg | 0:3171e1737767 | 297 | DSs[i]=DEs[i+C]>>K | DEs[i+C+1]<<(7-K); |
caarbelaezg | 0:3171e1737767 | 298 | if (DSs[i]==0x00) { |
caarbelaezg | 0:3171e1737767 | 299 | LENOUT=i; |
caarbelaezg | 0:3171e1737767 | 300 | goto salir; |
caarbelaezg | 0:3171e1737767 | 301 | } |
caarbelaezg | 0:3171e1737767 | 302 | K++; |
caarbelaezg | 0:3171e1737767 | 303 | if (K==7) { |
caarbelaezg | 0:3171e1737767 | 304 | K=0; // se chequea que ya se acabaron los bits en un ciclo de conversion. |
caarbelaezg | 0:3171e1737767 | 305 | C++; |
caarbelaezg | 0:3171e1737767 | 306 | } |
caarbelaezg | 0:3171e1737767 | 307 | } |
caarbelaezg | 0:3171e1737767 | 308 | |
caarbelaezg | 0:3171e1737767 | 309 | //-------------------------------------------------------------- |
caarbelaezg | 0:3171e1737767 | 310 | salir: |
caarbelaezg | 0:3171e1737767 | 311 | pc.printf("DEs\n"); |
caarbelaezg | 0:3171e1737767 | 312 | for (i=0; i < LENIN; i++) { |
caarbelaezg | 0:3171e1737767 | 313 | pc.printf("%X",DEs[i]); |
caarbelaezg | 0:3171e1737767 | 314 | } |
caarbelaezg | 0:3171e1737767 | 315 | pc.printf("\n DSs \n"); |
caarbelaezg | 0:3171e1737767 | 316 | for (i=0; i<LENOUT; i++) { |
caarbelaezg | 0:3171e1737767 | 317 | pc.printf("%02X",DSs[i]&0x000000FF); |
caarbelaezg | 0:3171e1737767 | 318 | } |
caarbelaezg | 0:3171e1737767 | 319 | |
caarbelaezg | 0:3171e1737767 | 320 | pc.printf("\n LENOUT:%d,LENIN:%d\r\n",LENOUT,strlen(DEs)); |
caarbelaezg | 0:3171e1737767 | 321 | |
caarbelaezg | 0:3171e1737767 | 322 | |
caarbelaezg | 0:3171e1737767 | 323 | // Enviamos el mensaje |
caarbelaezg | 0:3171e1737767 | 324 | |
caarbelaezg | 0:3171e1737767 | 325 | pc.printf("\n ------------- Comienza el envio del mensaje SMS ---------- \n"); |
caarbelaezg | 0:3171e1737767 | 326 | |
caarbelaezg | 0:3171e1737767 | 327 | if(LENOUT%2==0){ // ponderacion para cuadrar el tamaño del mensaje a enviar |
caarbelaezg | 0:3171e1737767 | 328 | w=27; |
caarbelaezg | 0:3171e1737767 | 329 | } |
caarbelaezg | 0:3171e1737767 | 330 | else{ |
caarbelaezg | 0:3171e1737767 | 331 | w=26; |
caarbelaezg | 0:3171e1737767 | 332 | } |
caarbelaezg | 0:3171e1737767 | 333 | gsm.printf("AT+CMGS=%d\r\n", ((2*LENOUT)+w)/2); // Inicio real del envio del mensaje |
caarbelaezg | 0:3171e1737767 | 334 | pc.printf("\n AT+CMGS=%d\r\n", ((2*LENOUT)+w)/2); |
caarbelaezg | 0:3171e1737767 | 335 | wait(0.5); |
caarbelaezg | 0:3171e1737767 | 336 | |
caarbelaezg | 0:3171e1737767 | 337 | gsm.printf("0011000A91"); // relleno inicial |
caarbelaezg | 0:3171e1737767 | 338 | pc.printf("0011000A91"); |
caarbelaezg | 0:3171e1737767 | 339 | |
caarbelaezg | 0:3171e1737767 | 340 | |
caarbelaezg | 0:3171e1737767 | 341 | for(i=0; i<11; i++){ // NUMERO TELEFONICO DEL USUARIO |
caarbelaezg | 0:3171e1737767 | 342 | gsm.printf("%c", Cnumero[i]); |
caarbelaezg | 0:3171e1737767 | 343 | pc.printf("%c", Cnumero[i]); |
caarbelaezg | 0:3171e1737767 | 344 | |
caarbelaezg | 0:3171e1737767 | 345 | } |
caarbelaezg | 0:3171e1737767 | 346 | |
caarbelaezg | 0:3171e1737767 | 347 | gsm.printf("000AA"); // segundo relleno |
caarbelaezg | 0:3171e1737767 | 348 | pc.printf("000AA"); |
caarbelaezg | 0:3171e1737767 | 349 | |
caarbelaezg | 0:3171e1737767 | 350 | gsm.printf("%2X",LENOUT); // longitud de los datos |
caarbelaezg | 0:3171e1737767 | 351 | pc.printf("%2X",LENOUT); |
caarbelaezg | 0:3171e1737767 | 352 | |
caarbelaezg | 0:3171e1737767 | 353 | |
caarbelaezg | 0:3171e1737767 | 354 | for (i=0; i < LENOUT; i++) { // imprimir los datos |
caarbelaezg | 0:3171e1737767 | 355 | gsm.printf("%02X",DSs[i]&0x000000FF); |
caarbelaezg | 0:3171e1737767 | 356 | pc.printf("%02X",DSs[i]&0x000000FF); |
caarbelaezg | 0:3171e1737767 | 357 | wait(0.1); |
caarbelaezg | 0:3171e1737767 | 358 | } |
caarbelaezg | 0:3171e1737767 | 359 | gsm.putc((char)0x1A); // Punto final del envio de datos |
caarbelaezg | 0:3171e1737767 | 360 | |
caarbelaezg | 0:3171e1737767 | 361 | |
caarbelaezg | 0:3171e1737767 | 362 | gsm.scanf("%s",buf); // Se lee la respuesta del gsm |
caarbelaezg | 0:3171e1737767 | 363 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 364 | |
caarbelaezg | 0:3171e1737767 | 365 | pc.printf("\n Lo que devuelve el cel %s \n",buf); |
caarbelaezg | 0:3171e1737767 | 366 | i=1; |
caarbelaezg | 0:3171e1737767 | 367 | gsm.printf("AT+CMGD=1\r\n"); |
caarbelaezg | 0:3171e1737767 | 368 | |
caarbelaezg | 0:3171e1737767 | 369 | //Limpieza de variables |
caarbelaezg | 0:3171e1737767 | 370 | |
caarbelaezg | 0:3171e1737767 | 371 | for(i=26; i<=strlen(LINK); i++){ |
caarbelaezg | 0:3171e1737767 | 372 | LINK[i]=NULL; |
caarbelaezg | 0:3171e1737767 | 373 | |
caarbelaezg | 0:3171e1737767 | 374 | } |
caarbelaezg | 0:3171e1737767 | 375 | |
caarbelaezg | 0:3171e1737767 | 376 | for(i=0; i<=255; i++){ |
caarbelaezg | 0:3171e1737767 | 377 | DSs[i]=NULL; |
caarbelaezg | 0:3171e1737767 | 378 | DEs[i]=NULL; |
caarbelaezg | 0:3171e1737767 | 379 | } |
caarbelaezg | 0:3171e1737767 | 380 | |
caarbelaezg | 0:3171e1737767 | 381 | pc.printf("\n Se sale de while para la lectura de gps \n "); |
caarbelaezg | 0:3171e1737767 | 382 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 383 | pc.printf(">%s",buf); |
caarbelaezg | 0:3171e1737767 | 384 | goto s; // salida del if de la llegada de cor y de la espera del gps |
caarbelaezg | 0:3171e1737767 | 385 | } |
caarbelaezg | 0:3171e1737767 | 386 | |
caarbelaezg | 0:3171e1737767 | 387 | |
caarbelaezg | 0:3171e1737767 | 388 | |
caarbelaezg | 0:3171e1737767 | 389 | }//if de coord |
caarbelaezg | 0:3171e1737767 | 390 | |
caarbelaezg | 0:3171e1737767 | 391 | |
caarbelaezg | 0:3171e1737767 | 392 | }// if de llegada de SMS |
caarbelaezg | 0:3171e1737767 | 393 | |
caarbelaezg | 0:3171e1737767 | 394 | if(str1.compare(DS) != 0 && str2.compare(DS) != 0 && str3.compare(DS) != 0){ |
caarbelaezg | 0:3171e1737767 | 395 | pc.printf("El mensaje de llegada no es valido"); |
caarbelaezg | 0:3171e1737767 | 396 | gsm.printf("AT+CMGD=1\r\n"); // Borrar el mensaje |
caarbelaezg | 0:3171e1737767 | 397 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 398 | pc.printf("\n%s\n",buf); |
caarbelaezg | 0:3171e1737767 | 399 | } |
caarbelaezg | 0:3171e1737767 | 400 | |
caarbelaezg | 0:3171e1737767 | 401 | |
caarbelaezg | 0:3171e1737767 | 402 | s: |
caarbelaezg | 0:3171e1737767 | 403 | gsm.scanf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 404 | pc.printf("%s",buf); |
caarbelaezg | 0:3171e1737767 | 405 | |
caarbelaezg | 0:3171e1737767 | 406 | }// while |
caarbelaezg | 0:3171e1737767 | 407 | }// Main |