Programa para establecer la comunicación con un módem Siemens A56 y un modulo FRDMKL25Z opera como rastreador satelital para Geolocalizacion. Por la UART (1) se conecta el MODEM y por la uart (2) el GPS (se lee en modo NEMEA) Este sistema genera una cadena de geolocalizacion para GoogleMaps con las coordenadas locales Si previamente se envia el mensaje (Coordenadas o coordenadas) El sistema ademas recibe ordenes de tipo mensaje GSM PDU para accionar cargas
main.cpp@2:ea6275d1222f, 2016-11-18 (annotated)
- Committer:
- joshema216
- Date:
- Fri Nov 18 21:27:40 2016 +0000
- Revision:
- 2:ea6275d1222f
- Parent:
- 1:e2bd083802c0
- Child:
- 3:8aef67673965
Version 1.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joshema216 | 2:ea6275d1222f | 1 | // Programa para establecer la comunicación con un módem Siemens A56 por una de las UART. |
joshema216 | 2:ea6275d1222f | 2 | // Por otra UART se envían datos de GPS de una región seleccionada de la aplicación de |
joshema216 | 2:ea6275d1222f | 3 | // Google Earth en formato .kml leídos por el programa SatGen de NMEA por un puerto COM |
joshema216 | 2:ea6275d1222f | 4 | // del Micro hacia un Dongle USB. Se deberá enviar un mensaje de texto al módem el cual |
joshema216 | 2:ea6275d1222f | 5 | // podrá ser la palabra "coordenadas" o "voltaje". Si se envía "coordenadas" el programa |
joshema216 | 2:ea6275d1222f | 6 | // calcula la latitud y la longitud de la coordenada actual de GPS y envía un mensaje de |
joshema216 | 2:ea6275d1222f | 7 | // texto al mismo número con las coordenadas en formato de Google Maps. Si se envía |
joshema216 | 2:ea6275d1222f | 8 | // "voltaje" se lee el voltaje de un puerto que se puede variar con un potenciómetro y |
joshema216 | 2:ea6275d1222f | 9 | // envía un mensaje de texto con la medida. Los mensajes de texto recibidos se interpretan |
joshema216 | 2:ea6275d1222f | 10 | // y decodifican de formato PDU a caracteres y los mensajes enviados se codifican de |
joshema216 | 2:ea6275d1222f | 11 | // caracteres a formato PDU para ser enviados. |
joshema216 | 2:ea6275d1222f | 12 | |
joshema216 | 2:ea6275d1222f | 13 | // Oswaldo Andrés Giraldo Giraldo - C.C.: 1152458465 |
joshema216 | 2:ea6275d1222f | 14 | // Héctor Andrés Hoyos Ceballos - C.C.: 1039466317 |
joshema216 | 2:ea6275d1222f | 15 | // Jose Fernando Montoya Vargas - C.C.: 1039468676 |
joshema216 | 2:ea6275d1222f | 16 | // María Fernanda Villa Tamayo - C.C.: 1152457490 |
joshema216 | 2:ea6275d1222f | 17 | |
procesadores_FAC | 0:b2a6aa7c0c8c | 18 | #include "mbed.h" |
procesadores_FAC | 0:b2a6aa7c0c8c | 19 | #include "DebouncedIn.h" |
procesadores_FAC | 0:b2a6aa7c0c8c | 20 | #include "stdio.h" |
procesadores_FAC | 0:b2a6aa7c0c8c | 21 | #include "string.h" |
procesadores_FAC | 0:b2a6aa7c0c8c | 22 | #include "GPS.h" |
joshema216 | 2:ea6275d1222f | 23 | |
AaronGonzalez | 1:e2bd083802c0 | 24 | //Salidas digitales |
procesadores_FAC | 0:b2a6aa7c0c8c | 25 | Timer t; |
procesadores_FAC | 0:b2a6aa7c0c8c | 26 | DigitalOut LedVerde(LED2); |
procesadores_FAC | 0:b2a6aa7c0c8c | 27 | DigitalOut LedRojo(LED1); |
procesadores_FAC | 0:b2a6aa7c0c8c | 28 | DigitalOut LedAzul(LED3); |
procesadores_FAC | 0:b2a6aa7c0c8c | 29 | |
joshema216 | 2:ea6275d1222f | 30 | // Entrada análoga |
joshema216 | 2:ea6275d1222f | 31 | AnalogIn v(PTB0); |
joshema216 | 2:ea6275d1222f | 32 | float medi; |
joshema216 | 2:ea6275d1222f | 33 | |
joshema216 | 2:ea6275d1222f | 34 | // Declaración de los puertos de la FRDM, Módem y GPS. |
joshema216 | 2:ea6275d1222f | 35 | Serial GSM(PTE0,PTE1); // Puertos del FRDM para el Módem. |
procesadores_FAC | 0:b2a6aa7c0c8c | 36 | Serial pc(USBTX,USBRX); |
joshema216 | 2:ea6275d1222f | 37 | GPS gps(PTE22, PTE23); // Puerto del FDRM para el GPS. |
procesadores_FAC | 0:b2a6aa7c0c8c | 38 | |
joshema216 | 2:ea6275d1222f | 39 | // Declaración de variables |
joshema216 | 2:ea6275d1222f | 40 | // Cadenas de caracteres con las que se va a trabajar. |
joshema216 | 2:ea6275d1222f | 41 | char DE1[255]; |
joshema216 | 2:ea6275d1222f | 42 | char DS1[255]; |
joshema216 | 2:ea6275d1222f | 43 | char DE2[255]; |
joshema216 | 2:ea6275d1222f | 44 | char DS2[255]; |
procesadores_FAC | 0:b2a6aa7c0c8c | 45 | char buffer[512]; |
joshema216 | 2:ea6275d1222f | 46 | char resp[6]; |
joshema216 | 2:ea6275d1222f | 47 | char tam[2]; |
procesadores_FAC | 0:b2a6aa7c0c8c | 48 | char mensaje[100]; |
joshema216 | 2:ea6275d1222f | 49 | |
AaronGonzalez | 1:e2bd083802c0 | 50 | //Variables enteras y caracteres |
procesadores_FAC | 0:b2a6aa7c0c8c | 51 | int count; |
joshema216 | 2:ea6275d1222f | 52 | int i, K, LENOUT1, LENIN1, LENOUT2, LENIN2, C; |
procesadores_FAC | 0:b2a6aa7c0c8c | 53 | int c=0; |
procesadores_FAC | 0:b2a6aa7c0c8c | 54 | char r[]=""; |
procesadores_FAC | 0:b2a6aa7c0c8c | 55 | char msg[256]; |
procesadores_FAC | 0:b2a6aa7c0c8c | 56 | char char1; |
joshema216 | 2:ea6275d1222f | 57 | int ind; |
joshema216 | 2:ea6275d1222f | 58 | float med; |
joshema216 | 2:ea6275d1222f | 59 | char outmed[16], outmedn[16]; |
joshema216 | 2:ea6275d1222f | 60 | int ret = 1; |
joshema216 | 2:ea6275d1222f | 61 | |
joshema216 | 2:ea6275d1222f | 62 | // Adquisición de números de teléfono, emisor - receptor |
joshema216 | 2:ea6275d1222f | 63 | char tel[15]; |
procesadores_FAC | 0:b2a6aa7c0c8c | 64 | |
joshema216 | 2:ea6275d1222f | 65 | // El GPS entregará al celular coordenadas expresadas en latitud y longitud |
joshema216 | 2:ea6275d1222f | 66 | // según la ubicación que encuentre, por lo tanto se declaran estas variables. |
procesadores_FAC | 0:b2a6aa7c0c8c | 67 | float lo,la; |
joshema216 | 2:ea6275d1222f | 68 | char clo[255], cla[255]; // Cadenas a capturar para latitud y longitud. |
joshema216 | 2:ea6275d1222f | 69 | char la_lo[255], volt[255]; |
joshema216 | 2:ea6275d1222f | 70 | |
joshema216 | 2:ea6275d1222f | 71 | // Cadena de google maps |
procesadores_FAC | 0:b2a6aa7c0c8c | 72 | char http2[255]; |
procesadores_FAC | 0:b2a6aa7c0c8c | 73 | char http[] = "http://maps.google.com/maps?q="; |
procesadores_FAC | 0:b2a6aa7c0c8c | 74 | char buf[100]; |
procesadores_FAC | 0:b2a6aa7c0c8c | 75 | |
joshema216 | 2:ea6275d1222f | 76 | // Relleno de datos propio del protocolo de SMS. |
joshema216 | 2:ea6275d1222f | 77 | char relle1[] = "0011000A91"; |
joshema216 | 2:ea6275d1222f | 78 | char relle2[] = "0000AA"; |
procesadores_FAC | 0:b2a6aa7c0c8c | 79 | |
joshema216 | 2:ea6275d1222f | 80 | // Reverses a string 'str' of length 'len' |
joshema216 | 2:ea6275d1222f | 81 | // driver program to test above funtion. |
joshema216 | 2:ea6275d1222f | 82 | void reverse(char *str, int len) |
joshema216 | 2:ea6275d1222f | 83 | { |
joshema216 | 2:ea6275d1222f | 84 | int i=0, j=len-1, temp; |
joshema216 | 2:ea6275d1222f | 85 | while (i<j) |
joshema216 | 2:ea6275d1222f | 86 | { |
joshema216 | 2:ea6275d1222f | 87 | temp = str[i]; |
joshema216 | 2:ea6275d1222f | 88 | str[i] = str[j]; |
joshema216 | 2:ea6275d1222f | 89 | str[j] = temp; |
joshema216 | 2:ea6275d1222f | 90 | i++; j--; |
joshema216 | 2:ea6275d1222f | 91 | } |
joshema216 | 2:ea6275d1222f | 92 | } |
joshema216 | 2:ea6275d1222f | 93 | |
joshema216 | 2:ea6275d1222f | 94 | // Converts a given integer x to string str[]. d is the number |
joshema216 | 2:ea6275d1222f | 95 | // of digits required in output. If d is more than the number |
joshema216 | 2:ea6275d1222f | 96 | // of digits in x, then 0s are added at the beginning. |
joshema216 | 2:ea6275d1222f | 97 | int intToStr(int x, char str[], int d) |
joshema216 | 2:ea6275d1222f | 98 | { |
joshema216 | 2:ea6275d1222f | 99 | int i = 0; |
joshema216 | 2:ea6275d1222f | 100 | while (x) |
joshema216 | 2:ea6275d1222f | 101 | { |
joshema216 | 2:ea6275d1222f | 102 | str[i++] = (x%10) + '0'; |
joshema216 | 2:ea6275d1222f | 103 | x = x/10; |
joshema216 | 2:ea6275d1222f | 104 | } |
joshema216 | 2:ea6275d1222f | 105 | |
joshema216 | 2:ea6275d1222f | 106 | // If number of digits required is more, then |
joshema216 | 2:ea6275d1222f | 107 | // add 0s at the beginning |
joshema216 | 2:ea6275d1222f | 108 | while (i < d) |
joshema216 | 2:ea6275d1222f | 109 | str[i++] = '0'; |
joshema216 | 2:ea6275d1222f | 110 | |
joshema216 | 2:ea6275d1222f | 111 | reverse(str, i); |
joshema216 | 2:ea6275d1222f | 112 | str[i] = '\0'; |
joshema216 | 2:ea6275d1222f | 113 | return i; |
joshema216 | 2:ea6275d1222f | 114 | } |
procesadores_FAC | 0:b2a6aa7c0c8c | 115 | |
joshema216 | 2:ea6275d1222f | 116 | // Converts a floating point number to string. |
joshema216 | 2:ea6275d1222f | 117 | void ftoa(float n, char *res, int afterpoint) |
joshema216 | 2:ea6275d1222f | 118 | { |
joshema216 | 2:ea6275d1222f | 119 | // Extract integer part |
joshema216 | 2:ea6275d1222f | 120 | int ipart = (int)n; |
joshema216 | 2:ea6275d1222f | 121 | |
joshema216 | 2:ea6275d1222f | 122 | // Extract floating part |
joshema216 | 2:ea6275d1222f | 123 | float fpart = n - (float)ipart; |
joshema216 | 2:ea6275d1222f | 124 | |
joshema216 | 2:ea6275d1222f | 125 | // convert integer part to string |
joshema216 | 2:ea6275d1222f | 126 | int i = intToStr(ipart, res, 0); |
joshema216 | 2:ea6275d1222f | 127 | |
joshema216 | 2:ea6275d1222f | 128 | // check for display option after point |
joshema216 | 2:ea6275d1222f | 129 | if (afterpoint != 0) |
joshema216 | 2:ea6275d1222f | 130 | { |
joshema216 | 2:ea6275d1222f | 131 | res[i] = '.'; // add dot |
procesadores_FAC | 0:b2a6aa7c0c8c | 132 | |
joshema216 | 2:ea6275d1222f | 133 | // Get the value of fraction part upto given no. |
joshema216 | 2:ea6275d1222f | 134 | // of points after dot. The third parameter is needed |
joshema216 | 2:ea6275d1222f | 135 | // to handle cases like 233.007 |
joshema216 | 2:ea6275d1222f | 136 | float fp=10; |
joshema216 | 2:ea6275d1222f | 137 | fpart =fpart * pow(fp,afterpoint); |
joshema216 | 2:ea6275d1222f | 138 | |
joshema216 | 2:ea6275d1222f | 139 | intToStr((int)fpart, res + i + 1, afterpoint); |
joshema216 | 2:ea6275d1222f | 140 | } |
joshema216 | 2:ea6275d1222f | 141 | } |
joshema216 | 2:ea6275d1222f | 142 | |
joshema216 | 2:ea6275d1222f | 143 | void FlushGSM(void) { |
joshema216 | 2:ea6275d1222f | 144 | char1 = 0; |
joshema216 | 2:ea6275d1222f | 145 | while (GSM.readable()){ |
joshema216 | 2:ea6275d1222f | 146 | char1 = GSM.getc(); |
joshema216 | 2:ea6275d1222f | 147 | } |
joshema216 | 2:ea6275d1222f | 148 | return; |
joshema216 | 2:ea6275d1222f | 149 | } |
joshema216 | 2:ea6275d1222f | 150 | |
joshema216 | 2:ea6275d1222f | 151 | void callback(){ |
joshema216 | 2:ea6275d1222f | 152 | // Note: you need to actually read from the serial to clear the RX interrupt |
joshema216 | 2:ea6275d1222f | 153 | pc.printf("%c\n", GSM.getc()); |
joshema216 | 2:ea6275d1222f | 154 | } |
joshema216 | 2:ea6275d1222f | 155 | |
joshema216 | 2:ea6275d1222f | 156 | // Esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de |
joshema216 | 2:ea6275d1222f | 157 | // $, count es lo que va a leer. Lo leido lo mete en buffer que es una cadena previamente definida |
joshema216 | 2:ea6275d1222f | 158 | // incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1 |
joshema216 | 2:ea6275d1222f | 159 | int readBuffer(char *buffer,int count){ |
procesadores_FAC | 0:b2a6aa7c0c8c | 160 | int i=0; |
joshema216 | 2:ea6275d1222f | 161 | t.start(); // start timer |
procesadores_FAC | 0:b2a6aa7c0c8c | 162 | while(1) { |
procesadores_FAC | 0:b2a6aa7c0c8c | 163 | while (GSM.readable()) { |
procesadores_FAC | 0:b2a6aa7c0c8c | 164 | char c = GSM.getc(); |
procesadores_FAC | 0:b2a6aa7c0c8c | 165 | if (c == '\r' || c == '\n') c = '$'; |
procesadores_FAC | 0:b2a6aa7c0c8c | 166 | buffer[i++] = c; |
procesadores_FAC | 0:b2a6aa7c0c8c | 167 | if(i > count)break; |
procesadores_FAC | 0:b2a6aa7c0c8c | 168 | } |
joshema216 | 2:ea6275d1222f | 169 | if(i > count)break; |
procesadores_FAC | 0:b2a6aa7c0c8c | 170 | if(t.read() > 3) { |
procesadores_FAC | 0:b2a6aa7c0c8c | 171 | t.stop(); |
procesadores_FAC | 0:b2a6aa7c0c8c | 172 | t.reset(); |
procesadores_FAC | 0:b2a6aa7c0c8c | 173 | break; |
procesadores_FAC | 0:b2a6aa7c0c8c | 174 | } |
procesadores_FAC | 0:b2a6aa7c0c8c | 175 | } |
procesadores_FAC | 0:b2a6aa7c0c8c | 176 | wait(0.5); |
joshema216 | 2:ea6275d1222f | 177 | while(GSM.readable()){ // display the other thing.. |
joshema216 | 2:ea6275d1222f | 178 | char c = GSM.getc(); |
joshema216 | 2:ea6275d1222f | 179 | } |
joshema216 | 2:ea6275d1222f | 180 | return 0; |
joshema216 | 2:ea6275d1222f | 181 | } |
joshema216 | 2:ea6275d1222f | 182 | |
joshema216 | 2:ea6275d1222f | 183 | // Esta función de abajo limpia o borra todo un "buffer" de tamaño "count", |
joshema216 | 2:ea6275d1222f | 184 | // lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena. |
joshema216 | 2:ea6275d1222f | 185 | // No retorna nada. |
joshema216 | 2:ea6275d1222f | 186 | void cleanBuffer(char *buffer, int count){ |
joshema216 | 2:ea6275d1222f | 187 | for(int i=0; i < count; i++) { |
joshema216 | 2:ea6275d1222f | 188 | buffer[i] = '\0'; |
joshema216 | 2:ea6275d1222f | 189 | } |
joshema216 | 2:ea6275d1222f | 190 | } |
joshema216 | 2:ea6275d1222f | 191 | |
joshema216 | 2:ea6275d1222f | 192 | // Esta función de abajo envia un comando parametrizado como cadena |
joshema216 | 2:ea6275d1222f | 193 | // puede ser un comando tipo AT. |
joshema216 | 2:ea6275d1222f | 194 | void sendCmd(char *cmd){ |
joshema216 | 2:ea6275d1222f | 195 | GSM.puts(cmd); |
joshema216 | 2:ea6275d1222f | 196 | } |
joshema216 | 2:ea6275d1222f | 197 | |
joshema216 | 2:ea6275d1222f | 198 | // Esta función de abajo espera la respuesta de un comando que debe ser idéntica a la cadena "resp" y un tiempo "timeout", |
joshema216 | 2:ea6275d1222f | 199 | // si todo sale bien retorna un cero que en la programacion hay que validar, |
joshema216 | 2:ea6275d1222f | 200 | // si algo sale mal (no se parece o se demora mucho) retorna -1 que debera validarse con alguna expresion logica. |
joshema216 | 2:ea6275d1222f | 201 | int waitForResp(char *resp, int timeout){ |
joshema216 | 2:ea6275d1222f | 202 | int len = strlen(resp); |
joshema216 | 2:ea6275d1222f | 203 | int sum=0; |
joshema216 | 2:ea6275d1222f | 204 | t.start(); |
joshema216 | 2:ea6275d1222f | 205 | |
joshema216 | 2:ea6275d1222f | 206 | while(1) { |
joshema216 | 2:ea6275d1222f | 207 | if(GSM.readable()) { |
joshema216 | 2:ea6275d1222f | 208 | char c = GSM.getc(); |
joshema216 | 2:ea6275d1222f | 209 | sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c |
joshema216 | 2:ea6275d1222f | 210 | if(sum == len)break; //ya acabo se sale |
joshema216 | 2:ea6275d1222f | 211 | } |
joshema216 | 2:ea6275d1222f | 212 | if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo |
joshema216 | 2:ea6275d1222f | 213 | t.stop(); |
joshema216 | 2:ea6275d1222f | 214 | t.reset(); |
joshema216 | 2:ea6275d1222f | 215 | return -1; |
joshema216 | 2:ea6275d1222f | 216 | } |
joshema216 | 2:ea6275d1222f | 217 | } |
joshema216 | 2:ea6275d1222f | 218 | t.stop(); // stop timer antes de retornar |
joshema216 | 2:ea6275d1222f | 219 | t.reset(); // clear timer |
joshema216 | 2:ea6275d1222f | 220 | while(GSM.readable()) { // display the other thing.. |
procesadores_FAC | 0:b2a6aa7c0c8c | 221 | char c = GSM.getc(); |
procesadores_FAC | 0:b2a6aa7c0c8c | 222 | } |
procesadores_FAC | 0:b2a6aa7c0c8c | 223 | return 0; |
procesadores_FAC | 0:b2a6aa7c0c8c | 224 | } |
procesadores_FAC | 0:b2a6aa7c0c8c | 225 | |
joshema216 | 2:ea6275d1222f | 226 | // Esta función de abajo es muy completa y útil, se encarga de enviar el comando y esperar la respuesta. |
joshema216 | 2:ea6275d1222f | 227 | // Si todo sale bien retorna un cero (herencia de las funciones contenedoras) que en la programacion hay que validar |
joshema216 | 2:ea6275d1222f | 228 | // con alguna expresion lógica. |
joshema216 | 2:ea6275d1222f | 229 | int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout){ |
joshema216 | 2:ea6275d1222f | 230 | sendCmd(cmd); |
joshema216 | 2:ea6275d1222f | 231 | return waitForResp(resp,timeout); |
joshema216 | 2:ea6275d1222f | 232 | } |
joshema216 | 2:ea6275d1222f | 233 | |
joshema216 | 2:ea6275d1222f | 234 | // Esta función de abajo chequea que el módem este vivo, envia AT, le contesta con OK y espera 2 segundos. |
joshema216 | 2:ea6275d1222f | 235 | int powerCheck(void){ // Este comando se manda para verificar si el módem esta vivo o conectado. |
joshema216 | 2:ea6275d1222f | 236 | return sendCmdAndWaitForResp("AT\r\n", "OK", 2); |
joshema216 | 2:ea6275d1222f | 237 | } |
joshema216 | 2:ea6275d1222f | 238 | |
joshema216 | 2:ea6275d1222f | 239 | // Esta función de abajo chequea el estado de la sim card |
joshema216 | 2:ea6275d1222f | 240 | // y si todo sale bien retorna un cero que en la programacion hay que validar |
joshema216 | 2:ea6275d1222f | 241 | // con alguna expresión lógica. |
joshema216 | 2:ea6275d1222f | 242 | int checkSIMStatus(void){ |
joshema216 | 2:ea6275d1222f | 243 | char gprsBuffer[30]; |
joshema216 | 2:ea6275d1222f | 244 | int count = 0; |
joshema216 | 2:ea6275d1222f | 245 | cleanBuffer(gprsBuffer, 30); |
joshema216 | 2:ea6275d1222f | 246 | while(count < 3){ |
joshema216 | 2:ea6275d1222f | 247 | sendCmd("AT+CPIN?\r\n"); |
joshema216 | 2:ea6275d1222f | 248 | readBuffer(gprsBuffer,30); |
joshema216 | 2:ea6275d1222f | 249 | if((NULL != strstr(gprsBuffer,"+CPIN: READY"))){ |
joshema216 | 2:ea6275d1222f | 250 | break; |
joshema216 | 2:ea6275d1222f | 251 | } |
joshema216 | 2:ea6275d1222f | 252 | count++; |
joshema216 | 2:ea6275d1222f | 253 | wait(1); |
joshema216 | 2:ea6275d1222f | 254 | } |
joshema216 | 2:ea6275d1222f | 255 | |
joshema216 | 2:ea6275d1222f | 256 | if(count == 3){ |
joshema216 | 2:ea6275d1222f | 257 | return -1; |
joshema216 | 2:ea6275d1222f | 258 | } |
joshema216 | 2:ea6275d1222f | 259 | return 0; |
joshema216 | 2:ea6275d1222f | 260 | } |
joshema216 | 2:ea6275d1222f | 261 | |
joshema216 | 2:ea6275d1222f | 262 | // Esta función de abajo chequea la calidad de la señal |
joshema216 | 2:ea6275d1222f | 263 | // y si todo sale bien retorna con el valor de señal útil o un -1 si no es aceptable, en la programacion hay que validar |
joshema216 | 2:ea6275d1222f | 264 | // con alguna expresión lógica. |
joshema216 | 2:ea6275d1222f | 265 | int checkSignalStrength(void){ |
joshema216 | 2:ea6275d1222f | 266 | char gprsBuffer[100]; |
joshema216 | 2:ea6275d1222f | 267 | int index, count = 0; |
joshema216 | 2:ea6275d1222f | 268 | cleanBuffer(gprsBuffer,100); |
joshema216 | 2:ea6275d1222f | 269 | while(count < 3){ |
joshema216 | 2:ea6275d1222f | 270 | sendCmd("AT+CSQ\r\n"); |
joshema216 | 2:ea6275d1222f | 271 | readBuffer(gprsBuffer,25); |
joshema216 | 2:ea6275d1222f | 272 | if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) { |
joshema216 | 2:ea6275d1222f | 273 | break; |
joshema216 | 2:ea6275d1222f | 274 | } |
joshema216 | 2:ea6275d1222f | 275 | count++; |
joshema216 | 2:ea6275d1222f | 276 | wait(1); |
joshema216 | 2:ea6275d1222f | 277 | } |
joshema216 | 2:ea6275d1222f | 278 | if(count == 3){ |
joshema216 | 2:ea6275d1222f | 279 | return -1; |
joshema216 | 2:ea6275d1222f | 280 | } |
joshema216 | 2:ea6275d1222f | 281 | return index; |
joshema216 | 2:ea6275d1222f | 282 | } |
joshema216 | 2:ea6275d1222f | 283 | |
joshema216 | 2:ea6275d1222f | 284 | // Esta funcion de abajo inicaliza el módem. Se compone de un grupo de subfunciones ya definidas previamente |
joshema216 | 2:ea6275d1222f | 285 | // primero chequea que este vivo, |
joshema216 | 2:ea6275d1222f | 286 | // segundo chequea el estado de la simcard, |
joshema216 | 2:ea6275d1222f | 287 | // tercero chequea la intencidad de señal celular, |
joshema216 | 2:ea6275d1222f | 288 | // cuarto aplica la configuracion |
joshema216 | 2:ea6275d1222f | 289 | // y si todo sale bien retorna un cero que en la programacion hay que validar |
joshema216 | 2:ea6275d1222f | 290 | // con alguna expresión lógica. |
joshema216 | 2:ea6275d1222f | 291 | int init(){ |
joshema216 | 2:ea6275d1222f | 292 | if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 3)){ |
joshema216 | 2:ea6275d1222f | 293 | return -1; |
joshema216 | 2:ea6275d1222f | 294 | } |
joshema216 | 2:ea6275d1222f | 295 | if (0 != sendCmdAndWaitForResp("AT+CNMI=1,1\r\n", "OK", 3)){ |
joshema216 | 2:ea6275d1222f | 296 | return -1; |
joshema216 | 2:ea6275d1222f | 297 | } |
joshema216 | 2:ea6275d1222f | 298 | if (0 != sendCmdAndWaitForResp("AT+CMGF=0\r\n", "OK", 3)){ |
joshema216 | 2:ea6275d1222f | 299 | return -1; |
joshema216 | 2:ea6275d1222f | 300 | } |
joshema216 | 2:ea6275d1222f | 301 | if (0 != sendCmdAndWaitForResp("AT+CBST=7,0,1\r\n", "OK", 3)){ //velocidad fija a 9600, modem asincronico no transparente |
joshema216 | 2:ea6275d1222f | 302 | return -1; |
joshema216 | 2:ea6275d1222f | 303 | } |
joshema216 | 2:ea6275d1222f | 304 | if (0 != sendCmdAndWaitForResp("ATE\r\n", "OK", 3)){ //se le quita el eco al modem GSM |
joshema216 | 2:ea6275d1222f | 305 | return -1; |
joshema216 | 2:ea6275d1222f | 306 | } |
joshema216 | 2:ea6275d1222f | 307 | LedVerde=0; |
joshema216 | 2:ea6275d1222f | 308 | return 0; |
joshema216 | 2:ea6275d1222f | 309 | } |
joshema216 | 2:ea6275d1222f | 310 | |
joshema216 | 2:ea6275d1222f | 311 | // Esta funcion de abajo intenta leer un mensaje de texto en formato PDU o HEX |
joshema216 | 2:ea6275d1222f | 312 | // y si todo sale bien retorna un cero que en la programacion hay que validar |
joshema216 | 2:ea6275d1222f | 313 | // con alguna expresión lógica. |
joshema216 | 2:ea6275d1222f | 314 | int readSMSpdu(char *message, int index){ |
joshema216 | 2:ea6275d1222f | 315 | int i = 0; |
joshema216 | 2:ea6275d1222f | 316 | char gprsBuffer[100]; |
joshema216 | 2:ea6275d1222f | 317 | char *p,*s; |
joshema216 | 2:ea6275d1222f | 318 | GSM.printf("AT+CMGR=%d\r\n",index); |
joshema216 | 2:ea6275d1222f | 319 | cleanBuffer(gprsBuffer,100); |
joshema216 | 2:ea6275d1222f | 320 | readBuffer(gprsBuffer,100); |
joshema216 | 2:ea6275d1222f | 321 | if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) { |
joshema216 | 2:ea6275d1222f | 322 | return -1; |
joshema216 | 2:ea6275d1222f | 323 | } |
joshema216 | 2:ea6275d1222f | 324 | if(NULL != ( s = strstr(gprsBuffer,"+32"))) { |
joshema216 | 2:ea6275d1222f | 325 | p = s + 6; |
joshema216 | 2:ea6275d1222f | 326 | while((*p != '$')&&(i < 5)) { |
joshema216 | 2:ea6275d1222f | 327 | message[i++] = *(p++); |
joshema216 | 2:ea6275d1222f | 328 | } |
joshema216 | 2:ea6275d1222f | 329 | message[i] = '\0'; |
joshema216 | 2:ea6275d1222f | 330 | } |
joshema216 | 2:ea6275d1222f | 331 | return 0; |
joshema216 | 2:ea6275d1222f | 332 | } |
joshema216 | 2:ea6275d1222f | 333 | |
joshema216 | 2:ea6275d1222f | 334 | // Esta función de abajo borra mensajes SMS del modem |
joshema216 | 2:ea6275d1222f | 335 | // y si todo sale bien retorna un cero que en la programacion hay que validar |
joshema216 | 2:ea6275d1222f | 336 | // con alguna expresion logica. |
joshema216 | 2:ea6275d1222f | 337 | int deleteSMS(int index){ |
joshema216 | 2:ea6275d1222f | 338 | char cmd[32]; |
joshema216 | 2:ea6275d1222f | 339 | snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index); |
joshema216 | 2:ea6275d1222f | 340 | sendCmd(cmd); |
joshema216 | 2:ea6275d1222f | 341 | return 0; |
joshema216 | 2:ea6275d1222f | 342 | } |
joshema216 | 2:ea6275d1222f | 343 | |
joshema216 | 2:ea6275d1222f | 344 | // Esta función devuelve la confirmacion del mensaje a quien lo envio. |
joshema216 | 2:ea6275d1222f | 345 | int recibe_ok(){ |
joshema216 | 2:ea6275d1222f | 346 | GSM.printf("AT+CMGS=27\n\r"); |
joshema216 | 2:ea6275d1222f | 347 | pc.printf("AT+CMGS=27\n\r"); |
joshema216 | 2:ea6275d1222f | 348 | wait_ms(100); |
joshema216 | 2:ea6275d1222f | 349 | GSM.printf("0011000A91%s0000AA10CDB27B1E569741F2F2382D4E93DF",tel); |
joshema216 | 2:ea6275d1222f | 350 | pc.printf("0011000A91%s0000AA10CDB27B1E569741F2F2382D4E93DF",tel); |
joshema216 | 2:ea6275d1222f | 351 | wait_ms(100); |
joshema216 | 2:ea6275d1222f | 352 | GSM.putc((char)0x1A); |
joshema216 | 2:ea6275d1222f | 353 | return 0; |
joshema216 | 2:ea6275d1222f | 354 | } |
joshema216 | 2:ea6275d1222f | 355 | |
joshema216 | 2:ea6275d1222f | 356 | // Programas a ejecutar. |
joshema216 | 2:ea6275d1222f | 357 | int main(){ |
joshema216 | 2:ea6275d1222f | 358 | //configuramos los puertos seriales |
joshema216 | 2:ea6275d1222f | 359 | GSM.baud(9600);//configura los baudios de la FRDMKL25Z en 9600 |
joshema216 | 2:ea6275d1222f | 360 | GSM.format(8,Serial::None,1); //configura el formato de los datos de la UART |
joshema216 | 2:ea6275d1222f | 361 | LedVerde = 1; // APAGO LOS LEDS |
joshema216 | 2:ea6275d1222f | 362 | LedRojo = 1; |
joshema216 | 2:ea6275d1222f | 363 | LedAzul = 1; |
joshema216 | 2:ea6275d1222f | 364 | LedRojo = 0; // PRENDO EL LED ROJO |
joshema216 | 2:ea6275d1222f | 365 | // Quito el eco del modem |
procesadores_FAC | 0:b2a6aa7c0c8c | 366 | |
joshema216 | 2:ea6275d1222f | 367 | // CONFIGURACIÓN DEL MODEM GSM (TELEFONO CELULAR SIEMENS A56i). |
joshema216 | 2:ea6275d1222f | 368 | inicio1: |
joshema216 | 2:ea6275d1222f | 369 | ret = init(); |
joshema216 | 2:ea6275d1222f | 370 | if(ret==0){ |
joshema216 | 2:ea6275d1222f | 371 | LedRojo = 1; |
joshema216 | 2:ea6275d1222f | 372 | LedVerde = 0; // Apagar LED Verde para confirmar la comunicación con el módem. |
joshema216 | 2:ea6275d1222f | 373 | pc.printf("Modem configurado\n"); |
joshema216 | 2:ea6275d1222f | 374 | } |
joshema216 | 2:ea6275d1222f | 375 | else{ |
joshema216 | 2:ea6275d1222f | 376 | wait(1); |
joshema216 | 2:ea6275d1222f | 377 | goto inicio1; |
joshema216 | 2:ea6275d1222f | 378 | } |
joshema216 | 2:ea6275d1222f | 379 | |
joshema216 | 2:ea6275d1222f | 380 | while(1){ |
joshema216 | 2:ea6275d1222f | 381 | if (GSM.readable()){ |
joshema216 | 2:ea6275d1222f | 382 | readBuffer(buffer,110); |
joshema216 | 2:ea6275d1222f | 383 | pc.printf("%s\r\n",buffer); |
joshema216 | 2:ea6275d1222f | 384 | for(i=0; i<5; i++){ |
joshema216 | 2:ea6275d1222f | 385 | resp[i] = buffer[i]; |
joshema216 | 2:ea6275d1222f | 386 | } |
joshema216 | 2:ea6275d1222f | 387 | |
joshema216 | 2:ea6275d1222f | 388 | pc.printf("%s\r\n", resp); |
joshema216 | 2:ea6275d1222f | 389 | if(strcmp("$$+CM", resp) == 0){ //COMPARA resp con "+CMTI" |
joshema216 | 2:ea6275d1222f | 390 | pc.printf("Llego MSG\r\n"); |
joshema216 | 2:ea6275d1222f | 391 | cleanBuffer(buffer,10); |
joshema216 | 2:ea6275d1222f | 392 | GSM.printf("AT+CMGL=0\r\n"); // Envío comando para leer mensaje |
joshema216 | 2:ea6275d1222f | 393 | pc.printf("AT+CMGL=0\r\n"); |
joshema216 | 2:ea6275d1222f | 394 | //GSM.printf("AT+CMGD=0\r\n"); // Envío comando para borrar el mensaje. |
joshema216 | 2:ea6275d1222f | 395 | readBuffer(buffer,110); |
joshema216 | 2:ea6275d1222f | 396 | pc.printf("%s\r\n",buffer); |
AaronGonzalez | 1:e2bd083802c0 | 397 | |
joshema216 | 2:ea6275d1222f | 398 | // Lectura el teléfono emisor |
joshema216 | 2:ea6275d1222f | 399 | for(i=0; i<10; i++){ |
joshema216 | 2:ea6275d1222f | 400 | tel[i] = buffer[i+40]; |
joshema216 | 2:ea6275d1222f | 401 | } |
joshema216 | 2:ea6275d1222f | 402 | pc.printf("Telefono: %c%c%c%c%c%c%c%c%c%c\r\n", tel[1], tel[0], tel[3], tel[2], tel[5], tel[4], tel[7], tel[6], tel[9], tel[8]); |
joshema216 | 2:ea6275d1222f | 403 | |
joshema216 | 2:ea6275d1222f | 404 | // Lectura del tamaño |
joshema216 | 2:ea6275d1222f | 405 | for(i=0;i<2;i++){ |
joshema216 | 2:ea6275d1222f | 406 | tam[i] = buffer[i + 68]; |
joshema216 | 2:ea6275d1222f | 407 | } |
joshema216 | 2:ea6275d1222f | 408 | pc.printf("%s-\r\n", tam); |
joshema216 | 2:ea6275d1222f | 409 | |
joshema216 | 2:ea6275d1222f | 410 | // Lectura del mensaje |
joshema216 | 2:ea6275d1222f | 411 | for(i=0;i<26;i++){ |
joshema216 | 2:ea6275d1222f | 412 | msg[i] = buffer[i+70]; // Lee un mensaje de 26 caracteres máximo desde la posición 70 del buffer. |
joshema216 | 2:ea6275d1222f | 413 | } |
joshema216 | 2:ea6275d1222f | 414 | pc.printf("%s-\r\n", msg); |
joshema216 | 2:ea6275d1222f | 415 | |
joshema216 | 2:ea6275d1222f | 416 | // Decodificación del mensaje |
joshema216 | 2:ea6275d1222f | 417 | |
joshema216 | 2:ea6275d1222f | 418 | // Comparar el mensaje |
joshema216 | 2:ea6275d1222f | 419 | deleteSMS(1); // Se borran los mensajes por medio de una función |
joshema216 | 2:ea6275d1222f | 420 | readBuffer(buffer, 200); |
joshema216 | 2:ea6275d1222f | 421 | // COMPARA resp con "E3F75B4E2EBBC3E4F01C" que es "coordenadas", o "C3F75B4E2EBBC3E4F01C" que es "Coordenadas". |
joshema216 | 2:ea6275d1222f | 422 | if((strncmp("E3F75B4E2EBBC3E4F01C", msg, 20) == 0) || (strncmp("C3F75B4E2EBBC3E4F01C", msg, 20) == 0)){ |
joshema216 | 2:ea6275d1222f | 423 | //recibe_ok(); |
joshema216 | 2:ea6275d1222f | 424 | LedVerde = 1; // Encender LED azul. |
joshema216 | 2:ea6275d1222f | 425 | LedAzul = 0; |
joshema216 | 2:ea6275d1222f | 426 | wait(2); |
joshema216 | 2:ea6275d1222f | 427 | |
joshema216 | 2:ea6275d1222f | 428 | if(gps.sample()){ |
joshema216 | 2:ea6275d1222f | 429 | lo = gps.longitude; |
joshema216 | 2:ea6275d1222f | 430 | la = gps.latitude; |
joshema216 | 2:ea6275d1222f | 431 | pc.printf("\nLongitud entera = %f, Latitud entera = %f\n", lo, la); |
joshema216 | 2:ea6275d1222f | 432 | //wait(0.5); |
joshema216 | 2:ea6275d1222f | 433 | |
joshema216 | 2:ea6275d1222f | 434 | //LONGITUD |
joshema216 | 2:ea6275d1222f | 435 | sprintf (clo, "%f", lo); |
joshema216 | 2:ea6275d1222f | 436 | pc.printf ("\nLongitud = %s\n",clo); |
joshema216 | 2:ea6275d1222f | 437 | //wait(0.5); |
joshema216 | 2:ea6275d1222f | 438 | |
joshema216 | 2:ea6275d1222f | 439 | // LATITUD |
joshema216 | 2:ea6275d1222f | 440 | sprintf (cla, "%f", la); |
joshema216 | 2:ea6275d1222f | 441 | pc.printf ( "\nLatitud = %s\n",cla); |
joshema216 | 2:ea6275d1222f | 442 | //wait(0.5); |
joshema216 | 2:ea6275d1222f | 443 | |
joshema216 | 2:ea6275d1222f | 444 | // Concatenando las cadenas de Latitud y Longitud |
joshema216 | 2:ea6275d1222f | 445 | strcpy(la_lo,cla); |
joshema216 | 2:ea6275d1222f | 446 | strcat(la_lo,","); |
joshema216 | 2:ea6275d1222f | 447 | strcat(la_lo,clo); |
joshema216 | 2:ea6275d1222f | 448 | pc.printf("\nLatitud, Longitud: %s\n",la_lo); |
procesadores_FAC | 0:b2a6aa7c0c8c | 449 | |
joshema216 | 2:ea6275d1222f | 450 | //Ahora se juntan las cadenas obtenidas y se agrega el protocolo de transferencia de hipertextos http |
joshema216 | 2:ea6275d1222f | 451 | strcpy(DE1,http); |
joshema216 | 2:ea6275d1222f | 452 | strcat(DE1,la_lo); |
joshema216 | 2:ea6275d1222f | 453 | pc.printf("\nDireccion: %s\n",DE1); |
joshema216 | 2:ea6275d1222f | 454 | pc.printf("\n"); |
joshema216 | 2:ea6275d1222f | 455 | LENIN1 = strlen(DE1); |
joshema216 | 2:ea6275d1222f | 456 | |
joshema216 | 2:ea6275d1222f | 457 | //Conversión a octetos. |
joshema216 | 2:ea6275d1222f | 458 | K = 0; |
joshema216 | 2:ea6275d1222f | 459 | C = 0; |
joshema216 | 2:ea6275d1222f | 460 | for (i = 0; i < LENIN1; i++){ |
joshema216 | 2:ea6275d1222f | 461 | DS1[i] = DE1[i + C] >> K | DE1[i + C + 1] << (7 - K); |
joshema216 | 2:ea6275d1222f | 462 | if(DS1[i] == 0x00) {LENOUT1 = i; goto salir1;} |
joshema216 | 2:ea6275d1222f | 463 | K++; |
joshema216 | 2:ea6275d1222f | 464 | if (K == 7) {K = 0; C++;} // se chequea que ya se acabaron los bits en un ciclo de conversion. |
joshema216 | 2:ea6275d1222f | 465 | } |
joshema216 | 2:ea6275d1222f | 466 | |
joshema216 | 2:ea6275d1222f | 467 | salir1: |
joshema216 | 2:ea6275d1222f | 468 | for (i = 0; i < LENIN1; i++){ |
joshema216 | 2:ea6275d1222f | 469 | pc.printf("%X", DE1[i]); |
joshema216 | 2:ea6275d1222f | 470 | } |
joshema216 | 2:ea6275d1222f | 471 | |
joshema216 | 2:ea6275d1222f | 472 | pc.printf(":\r\n"); |
joshema216 | 2:ea6275d1222f | 473 | for (i = 0; i < LENOUT1; i++){ |
joshema216 | 2:ea6275d1222f | 474 | pc.printf("%2X", DS1[i]&0x000000FF); |
joshema216 | 2:ea6275d1222f | 475 | } |
joshema216 | 2:ea6275d1222f | 476 | pc.printf("\r\nLENOUT GPS: %d, LENIN GPS: %2X\r\n", LENOUT1, LENIN1); |
joshema216 | 2:ea6275d1222f | 477 | |
joshema216 | 2:ea6275d1222f | 478 | // Concatenación del mensaje en formato PDU y envío del mismo. |
joshema216 | 2:ea6275d1222f | 479 | ind = 14 + LENOUT1 - 1; |
joshema216 | 2:ea6275d1222f | 480 | |
joshema216 | 2:ea6275d1222f | 481 | GSM.printf("AT+CMGS=%d\r\n",ind); |
joshema216 | 2:ea6275d1222f | 482 | pc.printf("AT+CMGS=%d\r\n",ind); |
joshema216 | 2:ea6275d1222f | 483 | pc.printf(relle1); |
joshema216 | 2:ea6275d1222f | 484 | GSM.printf(relle1); |
joshema216 | 2:ea6275d1222f | 485 | |
joshema216 | 2:ea6275d1222f | 486 | for (i=0 ;i<=9; i++) { |
joshema216 | 2:ea6275d1222f | 487 | pc.printf("%c",tel[i]); |
joshema216 | 2:ea6275d1222f | 488 | GSM.printf("%c",tel[i]); |
joshema216 | 2:ea6275d1222f | 489 | } |
joshema216 | 2:ea6275d1222f | 490 | |
joshema216 | 2:ea6275d1222f | 491 | pc.printf(relle2); |
joshema216 | 2:ea6275d1222f | 492 | GSM.printf(relle2); |
joshema216 | 2:ea6275d1222f | 493 | pc.printf("%2X", LENIN1); |
joshema216 | 2:ea6275d1222f | 494 | GSM.printf("%2X", LENIN1); |
joshema216 | 2:ea6275d1222f | 495 | |
joshema216 | 2:ea6275d1222f | 496 | for (i = 0; i < LENOUT1; i++){ |
joshema216 | 2:ea6275d1222f | 497 | pc.printf("%02X", DS1[i]&0x000000FF); |
joshema216 | 2:ea6275d1222f | 498 | GSM.printf("%02X", DS1[i]&0x000000FF); |
joshema216 | 2:ea6275d1222f | 499 | } |
joshema216 | 2:ea6275d1222f | 500 | wait(1); |
joshema216 | 2:ea6275d1222f | 501 | GSM.putc((char)0x1A); // Ctrl - Z. |
joshema216 | 2:ea6275d1222f | 502 | GSM.scanf("%s",buf); // Estado del mensaje (Envió o Error). |
joshema216 | 2:ea6275d1222f | 503 | pc.printf(">%s\n",buf); |
joshema216 | 2:ea6275d1222f | 504 | pc.printf("\n"); |
procesadores_FAC | 0:b2a6aa7c0c8c | 505 | } |
procesadores_FAC | 0:b2a6aa7c0c8c | 506 | |
joshema216 | 2:ea6275d1222f | 507 | wait(2); |
joshema216 | 2:ea6275d1222f | 508 | LedAzul = 1; |
joshema216 | 2:ea6275d1222f | 509 | LedVerde = 0; |
joshema216 | 2:ea6275d1222f | 510 | GSM.printf("AT+CMGD=0\r\n"); // Borra el mensaje actual (Posición "0"). |
joshema216 | 2:ea6275d1222f | 511 | //pc.printf("\n%s\n\n", "Borro mensaje"); |
joshema216 | 2:ea6275d1222f | 512 | } |
joshema216 | 2:ea6275d1222f | 513 | |
joshema216 | 2:ea6275d1222f | 514 | // COMPARA resp con "F6379B1E569701" que es "voltaje", o "F6379B1E569701" que es "Voltaje". |
joshema216 | 2:ea6275d1222f | 515 | if((strncmp("F6379B1E569701", msg, 14) == 0) || (strncmp("D6379B1E569701", msg, 14) == 0)){ |
joshema216 | 2:ea6275d1222f | 516 | //recibe_ok(); |
joshema216 | 2:ea6275d1222f | 517 | LedRojo = 0; // Encender LED amarillo. |
joshema216 | 2:ea6275d1222f | 518 | LedVerde = 0; |
joshema216 | 2:ea6275d1222f | 519 | LedAzul = 1; |
joshema216 | 2:ea6275d1222f | 520 | wait(2); |
joshema216 | 2:ea6275d1222f | 521 | |
joshema216 | 2:ea6275d1222f | 522 | med = v.read()*3.3; |
joshema216 | 2:ea6275d1222f | 523 | medi = v.read(); |
joshema216 | 2:ea6275d1222f | 524 | pc.printf("\n%f\n", medi); |
joshema216 | 2:ea6275d1222f | 525 | |
joshema216 | 2:ea6275d1222f | 526 | cleanBuffer(outmed, 16); |
joshema216 | 2:ea6275d1222f | 527 | if (med < 1){ // Se convierte la Medida a caracter. |
joshema216 | 2:ea6275d1222f | 528 | strcat(outmed, "0"); |
joshema216 | 2:ea6275d1222f | 529 | ftoa(med, outmedn, 5); |
joshema216 | 2:ea6275d1222f | 530 | strcat(outmed, outmedn); |
joshema216 | 2:ea6275d1222f | 531 | } |
joshema216 | 2:ea6275d1222f | 532 | else{ |
joshema216 | 2:ea6275d1222f | 533 | ftoa(med, outmed, 5); |
joshema216 | 2:ea6275d1222f | 534 | } |
joshema216 | 2:ea6275d1222f | 535 | strcpy(DE2,"Voltaje: "); |
joshema216 | 2:ea6275d1222f | 536 | strcat(DE2,outmed); |
joshema216 | 2:ea6275d1222f | 537 | pc.printf("\n%s\n\n", DE2); |
joshema216 | 2:ea6275d1222f | 538 | LENIN2 = strlen(DE2); |
joshema216 | 2:ea6275d1222f | 539 | |
joshema216 | 2:ea6275d1222f | 540 | //Conversión a octetos. |
joshema216 | 2:ea6275d1222f | 541 | K = 0; |
joshema216 | 2:ea6275d1222f | 542 | C = 0; |
joshema216 | 2:ea6275d1222f | 543 | for (i = 0; i < LENIN2; i++){ |
joshema216 | 2:ea6275d1222f | 544 | DS2[i] = DE2[i + C] >> K | DE2[i + C + 1] << (7 - K); |
joshema216 | 2:ea6275d1222f | 545 | if(DS2[i] == 0x00) {LENOUT2 = i; goto salir2;} |
joshema216 | 2:ea6275d1222f | 546 | K++; |
joshema216 | 2:ea6275d1222f | 547 | if (K == 7) {K = 0; C++;} // se chequea que ya se acabaron los bits en un ciclo de conversion. |
joshema216 | 2:ea6275d1222f | 548 | } |
joshema216 | 2:ea6275d1222f | 549 | |
joshema216 | 2:ea6275d1222f | 550 | salir2: |
joshema216 | 2:ea6275d1222f | 551 | for (i = 0; i < LENIN2; i++){ |
joshema216 | 2:ea6275d1222f | 552 | pc.printf("%X", DE2[i]); |
joshema216 | 2:ea6275d1222f | 553 | } |
joshema216 | 2:ea6275d1222f | 554 | |
joshema216 | 2:ea6275d1222f | 555 | pc.printf(":\r\n"); |
joshema216 | 2:ea6275d1222f | 556 | for (i = 0; i < LENOUT2; i++){ |
joshema216 | 2:ea6275d1222f | 557 | pc.printf("%2X", DS2[i]&0x000000FF); |
joshema216 | 2:ea6275d1222f | 558 | } |
joshema216 | 2:ea6275d1222f | 559 | pc.printf("\r\nLENOUT VOLTAJE: %d, LENIN VOLTAJE: %2X\r\n", LENOUT2, LENIN2); |
joshema216 | 2:ea6275d1222f | 560 | |
joshema216 | 2:ea6275d1222f | 561 | // Concatenación del mensaje en formato PDU y envío del mismo. |
joshema216 | 2:ea6275d1222f | 562 | ind = 14 + LENOUT2 - 1; |
joshema216 | 2:ea6275d1222f | 563 | |
joshema216 | 2:ea6275d1222f | 564 | GSM.printf("AT+CMGS=%d\r\n",ind); |
joshema216 | 2:ea6275d1222f | 565 | pc.printf("AT+CMGS=%d\r\n",ind); |
joshema216 | 2:ea6275d1222f | 566 | pc.printf(relle1); |
joshema216 | 2:ea6275d1222f | 567 | GSM.printf(relle1); |
joshema216 | 2:ea6275d1222f | 568 | |
joshema216 | 2:ea6275d1222f | 569 | for (i=0; i <= 9; i++) { |
joshema216 | 2:ea6275d1222f | 570 | pc.printf("%c",tel[i]); |
joshema216 | 2:ea6275d1222f | 571 | GSM.printf("%c",tel[i]); |
joshema216 | 2:ea6275d1222f | 572 | } |
joshema216 | 2:ea6275d1222f | 573 | |
joshema216 | 2:ea6275d1222f | 574 | pc.printf(relle2); |
joshema216 | 2:ea6275d1222f | 575 | GSM.printf(relle2); |
joshema216 | 2:ea6275d1222f | 576 | pc.printf("%2X", LENIN2); |
joshema216 | 2:ea6275d1222f | 577 | GSM.printf("%2X", LENIN2); |
joshema216 | 2:ea6275d1222f | 578 | /*pc.printf("0F"); |
joshema216 | 2:ea6275d1222f | 579 | GSM.printf("0F");*/ |
joshema216 | 2:ea6275d1222f | 580 | |
joshema216 | 2:ea6275d1222f | 581 | for (i = 0; i < LENOUT2; i++){ |
joshema216 | 2:ea6275d1222f | 582 | pc.printf("%02X", DS2[i]&0x000000FF); |
joshema216 | 2:ea6275d1222f | 583 | GSM.printf("%02X", DS2[i]&0x000000FF); |
joshema216 | 2:ea6275d1222f | 584 | } |
joshema216 | 2:ea6275d1222f | 585 | |
joshema216 | 2:ea6275d1222f | 586 | wait(1); |
joshema216 | 2:ea6275d1222f | 587 | GSM.putc((char)0x1A); // Ctrl - Z |
joshema216 | 2:ea6275d1222f | 588 | GSM.scanf("%s",buf); // Estado del mensaje (Envió o Error). |
joshema216 | 2:ea6275d1222f | 589 | pc.printf(">%s\n\n",buf); |
procesadores_FAC | 0:b2a6aa7c0c8c | 590 | pc.printf("\n"); |
procesadores_FAC | 0:b2a6aa7c0c8c | 591 | |
joshema216 | 2:ea6275d1222f | 592 | wait(2); |
joshema216 | 2:ea6275d1222f | 593 | LedRojo=1; |
joshema216 | 2:ea6275d1222f | 594 | LedVerde=0; |
joshema216 | 2:ea6275d1222f | 595 | GSM.printf("AT+CMGD=0\r\n"); // Borra el mensaje actual (Posición "0"). |
joshema216 | 2:ea6275d1222f | 596 | //pc.printf("\n%s\n\n", "Borro mensaje"); |
joshema216 | 2:ea6275d1222f | 597 | } |
joshema216 | 2:ea6275d1222f | 598 | } |
joshema216 | 2:ea6275d1222f | 599 | } |
joshema216 | 2:ea6275d1222f | 600 | } |
AaronGonzalez | 1:e2bd083802c0 | 601 | } |