Envía la palabra Coordenadas o coordenadas y retorna un link de google maps con la ubicación actual del celular usando GPS virtual

Dependencies:   GPS_G mbed

/media/uploads/jufzapataov/foto_de_juan_fernando_zapata.jpg

Committer:
jufzapataov
Date:
Tue Jun 05 02:52:23 2018 +0000
Revision:
3:9a7f48bbfbaa
Parent:
2:ea6275d1222f
Env?a palabra Coordenadas o coordenada y retorna un link de google maps con la localizaci?n mediante un GPS virtual

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jufzapataov 3:9a7f48bbfbaa 1 //* EL PROGRAMA UN CELULAR SIEMENS A56i COMO MODULO GSM DE COMUNICACIONES, SE USA UNA DE LAS UART DE LA TARJETA PARA EMULAR UN GPS
jufzapataov 3:9a7f48bbfbaa 2 //AL ENVIAR UN MENSAJE AL MODEM ESTE SE ENCARGA DE DEVOLVER UN MENSAJES CON LAS COORDENADAS DEL DISPOSITIVO CON UN LINK DE GOOGLE MAPS
jufzapataov 3:9a7f48bbfbaa 3 //HECHO POR SANTIAO GOMEZ ESTRADA, JUAN ERNANDO ZAPATA Y MATEO
joshema216 2:ea6275d1222f 4
jufzapataov 3:9a7f48bbfbaa 5
joshema216 2:ea6275d1222f 6
jufzapataov 3:9a7f48bbfbaa 7 // LIBRERIAS QUE SE USARON
procesadores_FAC 0:b2a6aa7c0c8c 8 #include "mbed.h"
procesadores_FAC 0:b2a6aa7c0c8c 9 #include "DebouncedIn.h"
procesadores_FAC 0:b2a6aa7c0c8c 10 #include "stdio.h"
procesadores_FAC 0:b2a6aa7c0c8c 11 #include "string.h"
procesadores_FAC 0:b2a6aa7c0c8c 12 #include "GPS.h"
joshema216 2:ea6275d1222f 13
jufzapataov 3:9a7f48bbfbaa 14 //LEDS PARA VER EL ESTADO DEL PROGRAMA
procesadores_FAC 0:b2a6aa7c0c8c 15 Timer t;
procesadores_FAC 0:b2a6aa7c0c8c 16 DigitalOut LedVerde(LED2);
procesadores_FAC 0:b2a6aa7c0c8c 17 DigitalOut LedRojo(LED1);
procesadores_FAC 0:b2a6aa7c0c8c 18 DigitalOut LedAzul(LED3);
procesadores_FAC 0:b2a6aa7c0c8c 19
jufzapataov 3:9a7f48bbfbaa 20 // PUERTOS PARA LA COMUNICACION SERIAL
jufzapataov 3:9a7f48bbfbaa 21 Serial GSM(PTE0,PTE1); // MODEM
jufzapataov 3:9a7f48bbfbaa 22 Serial pc(USBTX,USBRX); // VISUALIZACIモN DEL ESTADO DEL PROGRAMA EN EL PC
jufzapataov 3:9a7f48bbfbaa 23 GPS gps(PTE22, PTE23); // RECEPCIモN DE DATOS GPS.
joshema216 2:ea6275d1222f 24
jufzapataov 3:9a7f48bbfbaa 25 // DECLARACION DE VARIABLES
jufzapataov 3:9a7f48bbfbaa 26 // CADENAS QUE SE USARON DURANTE EL PROGRAMA
joshema216 2:ea6275d1222f 27 char DE1[255];
joshema216 2:ea6275d1222f 28 char DS1[255];
joshema216 2:ea6275d1222f 29 char DE2[255];
joshema216 2:ea6275d1222f 30 char DS2[255];
procesadores_FAC 0:b2a6aa7c0c8c 31 char buffer[512];
joshema216 2:ea6275d1222f 32 char resp[6];
joshema216 2:ea6275d1222f 33 char tam[2];
procesadores_FAC 0:b2a6aa7c0c8c 34 char mensaje[100];
joshema216 2:ea6275d1222f 35
jufzapataov 3:9a7f48bbfbaa 36 //Variables enteras y caracteres ----------------------------------------------- REVISAR
procesadores_FAC 0:b2a6aa7c0c8c 37 int count;
joshema216 2:ea6275d1222f 38 int i, K, LENOUT1, LENIN1, LENOUT2, LENIN2, C;
procesadores_FAC 0:b2a6aa7c0c8c 39 int c=0;
procesadores_FAC 0:b2a6aa7c0c8c 40 char r[]="";
procesadores_FAC 0:b2a6aa7c0c8c 41 char msg[256];
procesadores_FAC 0:b2a6aa7c0c8c 42 char char1;
joshema216 2:ea6275d1222f 43 int ind;
joshema216 2:ea6275d1222f 44 float med;
joshema216 2:ea6275d1222f 45 char outmed[16], outmedn[16];
joshema216 2:ea6275d1222f 46 int ret = 1;
joshema216 2:ea6275d1222f 47
jufzapataov 3:9a7f48bbfbaa 48 // DEDICADA PARA EL TELEFONO QUE ENVIA Y RECIBIRチ
joshema216 2:ea6275d1222f 49 char tel[15];
procesadores_FAC 0:b2a6aa7c0c8c 50
jufzapataov 3:9a7f48bbfbaa 51 // COORDENADAS GPS EN LATITUD Y LONGITUD
procesadores_FAC 0:b2a6aa7c0c8c 52 float lo,la;
jufzapataov 3:9a7f48bbfbaa 53 char clo[255], cla[255]; // CADENAS PARA LATITUD Y LONGITUD
jufzapataov 3:9a7f48bbfbaa 54 char la_lo[255];//--------------------------------------------------- REVISAR
joshema216 2:ea6275d1222f 55
jufzapataov 3:9a7f48bbfbaa 56 // LINK DE GOOGLE MAPS
procesadores_FAC 0:b2a6aa7c0c8c 57 char http2[255];
procesadores_FAC 0:b2a6aa7c0c8c 58 char http[] = "http://maps.google.com/maps?q=";
procesadores_FAC 0:b2a6aa7c0c8c 59 char buf[100];
procesadores_FAC 0:b2a6aa7c0c8c 60
jufzapataov 3:9a7f48bbfbaa 61 // DATOS DE RELLENO PROPIOS DEL SMS.
joshema216 2:ea6275d1222f 62 char relle1[] = "0011000A91";
joshema216 2:ea6275d1222f 63 char relle2[] = "0000AA";
procesadores_FAC 0:b2a6aa7c0c8c 64
jufzapataov 3:9a7f48bbfbaa 65 // DEFINICION DE FUNCIONES
joshema216 2:ea6275d1222f 66 void callback(){
joshema216 2:ea6275d1222f 67 // Note: you need to actually read from the serial to clear the RX interrupt
joshema216 2:ea6275d1222f 68 pc.printf("%c\n", GSM.getc());
joshema216 2:ea6275d1222f 69 }
joshema216 2:ea6275d1222f 70
joshema216 2:ea6275d1222f 71 // Esta funcion de abajo lee todo un bufer hasta encontrar CR o LF y el resto lo rellena de
joshema216 2:ea6275d1222f 72 // $, count es lo que va a leer. Lo leido lo mete en buffer que es una cadena previamente definida
joshema216 2:ea6275d1222f 73 // incorpora medida de tiempo si se demora mas de tres segundos retorna fracaso con -1
joshema216 2:ea6275d1222f 74 int readBuffer(char *buffer,int count){
procesadores_FAC 0:b2a6aa7c0c8c 75 int i=0;
joshema216 2:ea6275d1222f 76 t.start(); // start timer
procesadores_FAC 0:b2a6aa7c0c8c 77 while(1) {
procesadores_FAC 0:b2a6aa7c0c8c 78 while (GSM.readable()) {
procesadores_FAC 0:b2a6aa7c0c8c 79 char c = GSM.getc();
procesadores_FAC 0:b2a6aa7c0c8c 80 if (c == '\r' || c == '\n') c = '$';
procesadores_FAC 0:b2a6aa7c0c8c 81 buffer[i++] = c;
procesadores_FAC 0:b2a6aa7c0c8c 82 if(i > count)break;
procesadores_FAC 0:b2a6aa7c0c8c 83 }
joshema216 2:ea6275d1222f 84 if(i > count)break;
procesadores_FAC 0:b2a6aa7c0c8c 85 if(t.read() > 3) {
procesadores_FAC 0:b2a6aa7c0c8c 86 t.stop();
procesadores_FAC 0:b2a6aa7c0c8c 87 t.reset();
procesadores_FAC 0:b2a6aa7c0c8c 88 break;
procesadores_FAC 0:b2a6aa7c0c8c 89 }
procesadores_FAC 0:b2a6aa7c0c8c 90 }
procesadores_FAC 0:b2a6aa7c0c8c 91 wait(0.5);
joshema216 2:ea6275d1222f 92 while(GSM.readable()){ // display the other thing..
joshema216 2:ea6275d1222f 93 char c = GSM.getc();
joshema216 2:ea6275d1222f 94 }
joshema216 2:ea6275d1222f 95 return 0;
joshema216 2:ea6275d1222f 96 }
joshema216 2:ea6275d1222f 97
jufzapataov 3:9a7f48bbfbaa 98 // Esta funcion de abajo limpia o borra todo un "buffer" de tama "count",
joshema216 2:ea6275d1222f 99 // lo revisa elemento por elemento y le mete el caracter null que indica fin de cadena.
joshema216 2:ea6275d1222f 100 // No retorna nada.
joshema216 2:ea6275d1222f 101 void cleanBuffer(char *buffer, int count){
joshema216 2:ea6275d1222f 102 for(int i=0; i < count; i++) {
joshema216 2:ea6275d1222f 103 buffer[i] = '\0';
joshema216 2:ea6275d1222f 104 }
joshema216 2:ea6275d1222f 105 }
joshema216 2:ea6275d1222f 106
jufzapataov 3:9a7f48bbfbaa 107 // Esta funcion de abajo envia un comando parametrizado como cadena
joshema216 2:ea6275d1222f 108 // puede ser un comando tipo AT.
joshema216 2:ea6275d1222f 109 void sendCmd(char *cmd){
joshema216 2:ea6275d1222f 110 GSM.puts(cmd);
joshema216 2:ea6275d1222f 111 }
joshema216 2:ea6275d1222f 112
jufzapataov 3:9a7f48bbfbaa 113 // Esta funcion de abajo espera la respuesta de un comando que debe ser id駭tica a la cadena "resp" y un tiempo "timeout",
joshema216 2:ea6275d1222f 114 // si todo sale bien retorna un cero que en la programacion hay que validar,
joshema216 2:ea6275d1222f 115 // si algo sale mal (no se parece o se demora mucho) retorna -1 que debera validarse con alguna expresion logica.
joshema216 2:ea6275d1222f 116 int waitForResp(char *resp, int timeout){
joshema216 2:ea6275d1222f 117 int len = strlen(resp);
joshema216 2:ea6275d1222f 118 int sum=0;
joshema216 2:ea6275d1222f 119 t.start();
joshema216 2:ea6275d1222f 120
joshema216 2:ea6275d1222f 121 while(1) {
joshema216 2:ea6275d1222f 122 if(GSM.readable()) {
joshema216 2:ea6275d1222f 123 char c = GSM.getc();
joshema216 2:ea6275d1222f 124 sum = (c==resp[sum]) ? sum+1 : 0;// esta linea de C# sum se incrementa o se hace cero segun c
joshema216 2:ea6275d1222f 125 if(sum == len)break; //ya acabo se sale
joshema216 2:ea6275d1222f 126 }
joshema216 2:ea6275d1222f 127 if(t.read() > timeout) { // time out chequea el tiempo minimo antes de salir perdiendo
joshema216 2:ea6275d1222f 128 t.stop();
joshema216 2:ea6275d1222f 129 t.reset();
joshema216 2:ea6275d1222f 130 return -1;
joshema216 2:ea6275d1222f 131 }
joshema216 2:ea6275d1222f 132 }
joshema216 2:ea6275d1222f 133 t.stop(); // stop timer antes de retornar
joshema216 2:ea6275d1222f 134 t.reset(); // clear timer
joshema216 2:ea6275d1222f 135 while(GSM.readable()) { // display the other thing..
procesadores_FAC 0:b2a6aa7c0c8c 136 char c = GSM.getc();
procesadores_FAC 0:b2a6aa7c0c8c 137 }
procesadores_FAC 0:b2a6aa7c0c8c 138 return 0;
procesadores_FAC 0:b2a6aa7c0c8c 139 }
procesadores_FAC 0:b2a6aa7c0c8c 140
jufzapataov 3:9a7f48bbfbaa 141 // Esta funcion es muy completa y 偀il, se encarga de enviar el comando y esperar la respuesta.
jufzapataov 3:9a7f48bbfbaa 142 // Si todo sale bien retorna un cero
joshema216 2:ea6275d1222f 143 int sendCmdAndWaitForResp(char *cmd, char *resp, int timeout){
joshema216 2:ea6275d1222f 144 sendCmd(cmd);
joshema216 2:ea6275d1222f 145 return waitForResp(resp,timeout);
joshema216 2:ea6275d1222f 146 }
joshema216 2:ea6275d1222f 147
jufzapataov 3:9a7f48bbfbaa 148 // Esta funcion chequea que el mem este vivo, envia AT, le contesta con OK y espera 2 segundos.
jufzapataov 3:9a7f48bbfbaa 149 int powerCheck(void){ // Este comando se manda para verificar si el mem esta vivo o conectado.
joshema216 2:ea6275d1222f 150 return sendCmdAndWaitForResp("AT\r\n", "OK", 2);
joshema216 2:ea6275d1222f 151 }
joshema216 2:ea6275d1222f 152
jufzapataov 3:9a7f48bbfbaa 153 // Esta funcion de abajo chequea el estado de la sim card
joshema216 2:ea6275d1222f 154 // y si todo sale bien retorna un cero que en la programacion hay que validar
jufzapataov 3:9a7f48bbfbaa 155 // con alguna expresion lica.
joshema216 2:ea6275d1222f 156 int checkSIMStatus(void){
joshema216 2:ea6275d1222f 157 char gprsBuffer[30];
joshema216 2:ea6275d1222f 158 int count = 0;
joshema216 2:ea6275d1222f 159 cleanBuffer(gprsBuffer, 30);
joshema216 2:ea6275d1222f 160 while(count < 3){
joshema216 2:ea6275d1222f 161 sendCmd("AT+CPIN?\r\n");
joshema216 2:ea6275d1222f 162 readBuffer(gprsBuffer,30);
joshema216 2:ea6275d1222f 163 if((NULL != strstr(gprsBuffer,"+CPIN: READY"))){
joshema216 2:ea6275d1222f 164 break;
joshema216 2:ea6275d1222f 165 }
joshema216 2:ea6275d1222f 166 count++;
joshema216 2:ea6275d1222f 167 wait(1);
joshema216 2:ea6275d1222f 168 }
joshema216 2:ea6275d1222f 169
joshema216 2:ea6275d1222f 170 if(count == 3){
joshema216 2:ea6275d1222f 171 return -1;
joshema216 2:ea6275d1222f 172 }
joshema216 2:ea6275d1222f 173 return 0;
joshema216 2:ea6275d1222f 174 }
joshema216 2:ea6275d1222f 175
jufzapataov 3:9a7f48bbfbaa 176 // Esta funcion de abajo chequea la calidad de la sel
jufzapataov 3:9a7f48bbfbaa 177 // y si todo sale bien retorna con el valor de sel 偀il o un -1 si no es aceptable, en la programacion hay que validar
jufzapataov 3:9a7f48bbfbaa 178 // con alguna expresion lica.
joshema216 2:ea6275d1222f 179 int checkSignalStrength(void){
joshema216 2:ea6275d1222f 180 char gprsBuffer[100];
joshema216 2:ea6275d1222f 181 int index, count = 0;
joshema216 2:ea6275d1222f 182 cleanBuffer(gprsBuffer,100);
joshema216 2:ea6275d1222f 183 while(count < 3){
joshema216 2:ea6275d1222f 184 sendCmd("AT+CSQ\r\n");
joshema216 2:ea6275d1222f 185 readBuffer(gprsBuffer,25);
joshema216 2:ea6275d1222f 186 if(sscanf(gprsBuffer, "AT+CSQ$$$$+CSQ: %d", &index)>0) {
joshema216 2:ea6275d1222f 187 break;
joshema216 2:ea6275d1222f 188 }
joshema216 2:ea6275d1222f 189 count++;
joshema216 2:ea6275d1222f 190 wait(1);
joshema216 2:ea6275d1222f 191 }
joshema216 2:ea6275d1222f 192 if(count == 3){
joshema216 2:ea6275d1222f 193 return -1;
joshema216 2:ea6275d1222f 194 }
joshema216 2:ea6275d1222f 195 return index;
joshema216 2:ea6275d1222f 196 }
joshema216 2:ea6275d1222f 197
jufzapataov 3:9a7f48bbfbaa 198 // Esta funcion inicaliza el mem.
jufzapataov 3:9a7f48bbfbaa 199 // Se compone de un grupo de subfunciones ya definidas previamente:
joshema216 2:ea6275d1222f 200 // primero chequea que este vivo,
joshema216 2:ea6275d1222f 201 // segundo chequea el estado de la simcard,
jufzapataov 3:9a7f48bbfbaa 202 // tercero chequea la intencidad de sel celular,
joshema216 2:ea6275d1222f 203 // cuarto aplica la configuracion
jufzapataov 3:9a7f48bbfbaa 204 // y si todo sale bien retorna un cero
joshema216 2:ea6275d1222f 205 int init(){
joshema216 2:ea6275d1222f 206 if (0 != sendCmdAndWaitForResp("AT\r\n", "OK", 3)){
joshema216 2:ea6275d1222f 207 return -1;
joshema216 2:ea6275d1222f 208 }
joshema216 2:ea6275d1222f 209 if (0 != sendCmdAndWaitForResp("AT+CNMI=1,1\r\n", "OK", 3)){
joshema216 2:ea6275d1222f 210 return -1;
joshema216 2:ea6275d1222f 211 }
joshema216 2:ea6275d1222f 212 if (0 != sendCmdAndWaitForResp("AT+CMGF=0\r\n", "OK", 3)){
joshema216 2:ea6275d1222f 213 return -1;
joshema216 2:ea6275d1222f 214 }
jufzapataov 3:9a7f48bbfbaa 215 if (0 != sendCmdAndWaitForResp("AT+CBST=7,0,1\r\n", "OK", 3)){ //velocidad fija a 9600
joshema216 2:ea6275d1222f 216 return -1;
joshema216 2:ea6275d1222f 217 }
joshema216 2:ea6275d1222f 218 if (0 != sendCmdAndWaitForResp("ATE\r\n", "OK", 3)){ //se le quita el eco al modem GSM
joshema216 2:ea6275d1222f 219 return -1;
joshema216 2:ea6275d1222f 220 }
joshema216 2:ea6275d1222f 221 LedVerde=0;
joshema216 2:ea6275d1222f 222 return 0;
joshema216 2:ea6275d1222f 223 }
joshema216 2:ea6275d1222f 224
joshema216 2:ea6275d1222f 225 // Esta funcion de abajo intenta leer un mensaje de texto en formato PDU o HEX
joshema216 2:ea6275d1222f 226 // y si todo sale bien retorna un cero que en la programacion hay que validar
jufzapataov 3:9a7f48bbfbaa 227 // con alguna expresion lica.
joshema216 2:ea6275d1222f 228 int readSMSpdu(char *message, int index){
joshema216 2:ea6275d1222f 229 int i = 0;
joshema216 2:ea6275d1222f 230 char gprsBuffer[100];
joshema216 2:ea6275d1222f 231 char *p,*s;
joshema216 2:ea6275d1222f 232 GSM.printf("AT+CMGR=%d\r\n",index);
joshema216 2:ea6275d1222f 233 cleanBuffer(gprsBuffer,100);
joshema216 2:ea6275d1222f 234 readBuffer(gprsBuffer,100);
joshema216 2:ea6275d1222f 235 if(NULL == ( s = strstr(gprsBuffer,"+CMGR"))) {
joshema216 2:ea6275d1222f 236 return -1;
joshema216 2:ea6275d1222f 237 }
joshema216 2:ea6275d1222f 238 if(NULL != ( s = strstr(gprsBuffer,"+32"))) {
joshema216 2:ea6275d1222f 239 p = s + 6;
joshema216 2:ea6275d1222f 240 while((*p != '$')&&(i < 5)) {
joshema216 2:ea6275d1222f 241 message[i++] = *(p++);
joshema216 2:ea6275d1222f 242 }
joshema216 2:ea6275d1222f 243 message[i] = '\0';
joshema216 2:ea6275d1222f 244 }
joshema216 2:ea6275d1222f 245 return 0;
joshema216 2:ea6275d1222f 246 }
joshema216 2:ea6275d1222f 247
jufzapataov 3:9a7f48bbfbaa 248 // Esta funcion de abajo borra mensajes SMS del modem
joshema216 2:ea6275d1222f 249 // y si todo sale bien retorna un cero que en la programacion hay que validar
joshema216 2:ea6275d1222f 250 // con alguna expresion logica.
joshema216 2:ea6275d1222f 251 int deleteSMS(int index){
joshema216 2:ea6275d1222f 252 char cmd[32];
joshema216 2:ea6275d1222f 253 snprintf(cmd,sizeof(cmd),"AT+CMGD=%d\r\n",index);
joshema216 2:ea6275d1222f 254 sendCmd(cmd);
joshema216 2:ea6275d1222f 255 return 0;
joshema216 2:ea6275d1222f 256 }
joshema216 2:ea6275d1222f 257
jufzapataov 3:9a7f48bbfbaa 258 ////////////////////////////////////////////// FUNCIモN PRINCIPAL //////////////////////////////////////////////////////////
joshema216 2:ea6275d1222f 259 int main(){
jufzapataov 3:9a7f48bbfbaa 260 //configuramos los puertos seriales
joshema216 2:ea6275d1222f 261 GSM.baud(9600);//configura los baudios de la FRDMKL25Z en 9600
jufzapataov 3:9a7f48bbfbaa 262 GSM.format(8,Serial::None,1); //configura el formato de los datos de la UART
joshema216 2:ea6275d1222f 263 LedVerde = 1; // APAGO LOS LEDS
joshema216 2:ea6275d1222f 264 LedRojo = 1;
joshema216 2:ea6275d1222f 265 LedAzul = 1;
joshema216 2:ea6275d1222f 266 LedRojo = 0; // PRENDO EL LED ROJO
procesadores_FAC 0:b2a6aa7c0c8c 267
jufzapataov 3:9a7f48bbfbaa 268 // CONFIGURACIモN DEL MODEM GSM (TELEFONO CELULAR SIEMENS A56i).
joshema216 2:ea6275d1222f 269 inicio1:
joshema216 2:ea6275d1222f 270 ret = init();
joshema216 2:ea6275d1222f 271 if(ret==0){
joshema216 2:ea6275d1222f 272 LedRojo = 1;
jufzapataov 3:9a7f48bbfbaa 273 LedVerde = 0; //ENCENDER LED VERDE PARA CONFIRMAR LA CONEXIモN
jufzapataov 3:9a7f48bbfbaa 274 pc.printf("El Modem se ha configurado correctamente\n");
joshema216 2:ea6275d1222f 275 }
joshema216 2:ea6275d1222f 276 else{
joshema216 2:ea6275d1222f 277 wait(1);
joshema216 2:ea6275d1222f 278 goto inicio1;
joshema216 2:ea6275d1222f 279 }
joshema216 2:ea6275d1222f 280
joshema216 2:ea6275d1222f 281 while(1){
joshema216 2:ea6275d1222f 282 if (GSM.readable()){
joshema216 2:ea6275d1222f 283 readBuffer(buffer,110);
joshema216 2:ea6275d1222f 284 for(i=0; i<5; i++){
joshema216 2:ea6275d1222f 285 resp[i] = buffer[i];
joshema216 2:ea6275d1222f 286 }
joshema216 2:ea6275d1222f 287
jufzapataov 3:9a7f48bbfbaa 288 if(strcmp("$$+CM", resp) == 0){ //COMPARA resp CON "+CMTI"
jufzapataov 3:9a7f48bbfbaa 289 pc.printf("\nHa llegado un mensaje!\r\n");
joshema216 2:ea6275d1222f 290 cleanBuffer(buffer,10);
jufzapataov 3:9a7f48bbfbaa 291 GSM.printf("AT+CMGL=0\r\n"); // Env卲 comando para leer mensaje
joshema216 2:ea6275d1222f 292 readBuffer(buffer,110);
AaronGonzalez 1:e2bd083802c0 293
jufzapataov 3:9a7f48bbfbaa 294 // LECTURA DEL TELEFONO QUE ENVIモ EL MENSAJE
joshema216 2:ea6275d1222f 295 for(i=0; i<10; i++){
joshema216 2:ea6275d1222f 296 tel[i] = buffer[i+40];
joshema216 2:ea6275d1222f 297 }
jufzapataov 3:9a7f48bbfbaa 298 pc.printf("\nTelefono que envio el mensaje: %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 299
jufzapataov 3:9a7f48bbfbaa 300 // LECTURA DEL TAMAムO
joshema216 2:ea6275d1222f 301 for(i=0;i<2;i++){
joshema216 2:ea6275d1222f 302 tam[i] = buffer[i + 68];
jufzapataov 3:9a7f48bbfbaa 303 }
joshema216 2:ea6275d1222f 304
jufzapataov 3:9a7f48bbfbaa 305 // LECTURA DEL MENSAJE
joshema216 2:ea6275d1222f 306 for(i=0;i<26;i++){
jufzapataov 3:9a7f48bbfbaa 307 msg[i] = buffer[i+70]; // Lee un mensaje de 26 caracteres m痊imo desde la posicion 70 del buffer.
joshema216 2:ea6275d1222f 308 }
jufzapataov 3:9a7f48bbfbaa 309
jufzapataov 3:9a7f48bbfbaa 310 // DECODIFICACIモN DEL MENSAJE
joshema216 2:ea6275d1222f 311
jufzapataov 3:9a7f48bbfbaa 312 deleteSMS(1); // Se borran los mensajes por medio de una funcion
joshema216 2:ea6275d1222f 313 readBuffer(buffer, 200);
jufzapataov 3:9a7f48bbfbaa 314
jufzapataov 3:9a7f48bbfbaa 315 // COMPARA resp con "E3F75B4E2EBBC3E4F01C" que es "coordenadas", o "C3F75B4E2EBBC3E4F01C" que es "Coordenadas".
joshema216 2:ea6275d1222f 316 if((strncmp("E3F75B4E2EBBC3E4F01C", msg, 20) == 0) || (strncmp("C3F75B4E2EBBC3E4F01C", msg, 20) == 0)){
jufzapataov 3:9a7f48bbfbaa 317
jufzapataov 3:9a7f48bbfbaa 318 LedVerde = 1;
jufzapataov 3:9a7f48bbfbaa 319 LedAzul = 0; // ENCENDER LED AZUL
jufzapataov 3:9a7f48bbfbaa 320 LedRojo=0; // ENCENDER LED ROJO
joshema216 2:ea6275d1222f 321 wait(2);
joshema216 2:ea6275d1222f 322
jufzapataov 3:9a7f48bbfbaa 323 if(gps.sample()){ // SE RECIBEN COORDENADAS DEL GPS
joshema216 2:ea6275d1222f 324 lo = gps.longitude;
jufzapataov 3:9a7f48bbfbaa 325 la = gps.latitude;
joshema216 2:ea6275d1222f 326
joshema216 2:ea6275d1222f 327 //LONGITUD
joshema216 2:ea6275d1222f 328 sprintf (clo, "%f", lo);
joshema216 2:ea6275d1222f 329 pc.printf ("\nLongitud = %s\n",clo);
jufzapataov 3:9a7f48bbfbaa 330 wait(0.5);
joshema216 2:ea6275d1222f 331
joshema216 2:ea6275d1222f 332 // LATITUD
joshema216 2:ea6275d1222f 333 sprintf (cla, "%f", la);
joshema216 2:ea6275d1222f 334 pc.printf ( "\nLatitud = %s\n",cla);
jufzapataov 3:9a7f48bbfbaa 335 wait(0.5);
joshema216 2:ea6275d1222f 336
jufzapataov 3:9a7f48bbfbaa 337 // SE CONCATENAN LAS COORDENADAS DE LATITUD Y LONGITUD
joshema216 2:ea6275d1222f 338 strcpy(la_lo,cla);
joshema216 2:ea6275d1222f 339 strcat(la_lo,",");
joshema216 2:ea6275d1222f 340 strcat(la_lo,clo);
procesadores_FAC 0:b2a6aa7c0c8c 341
jufzapataov 3:9a7f48bbfbaa 342 //SE UNEN LAS CADENAS Y SE ARMA EL URL
joshema216 2:ea6275d1222f 343 strcpy(DE1,http);
joshema216 2:ea6275d1222f 344 strcat(DE1,la_lo);
jufzapataov 3:9a7f48bbfbaa 345 pc.printf("\nDireccion URL que se enviara: %s\n",DE1);
joshema216 2:ea6275d1222f 346 pc.printf("\n");
joshema216 2:ea6275d1222f 347 LENIN1 = strlen(DE1);
joshema216 2:ea6275d1222f 348
jufzapataov 3:9a7f48bbfbaa 349 //CONVERSIモN A OCTETOS
joshema216 2:ea6275d1222f 350 K = 0;
joshema216 2:ea6275d1222f 351 C = 0;
joshema216 2:ea6275d1222f 352 for (i = 0; i < LENIN1; i++){
joshema216 2:ea6275d1222f 353 DS1[i] = DE1[i + C] >> K | DE1[i + C + 1] << (7 - K);
joshema216 2:ea6275d1222f 354 if(DS1[i] == 0x00) {LENOUT1 = i; goto salir1;}
joshema216 2:ea6275d1222f 355 K++;
joshema216 2:ea6275d1222f 356 if (K == 7) {K = 0; C++;} // se chequea que ya se acabaron los bits en un ciclo de conversion.
joshema216 2:ea6275d1222f 357 }
joshema216 2:ea6275d1222f 358
joshema216 2:ea6275d1222f 359 salir1:
joshema216 2:ea6275d1222f 360 for (i = 0; i < LENIN1; i++){
joshema216 2:ea6275d1222f 361 pc.printf("%X", DE1[i]);
joshema216 2:ea6275d1222f 362 }
joshema216 2:ea6275d1222f 363
joshema216 2:ea6275d1222f 364 pc.printf(":\r\n");
joshema216 2:ea6275d1222f 365 for (i = 0; i < LENOUT1; i++){
joshema216 2:ea6275d1222f 366 pc.printf("%2X", DS1[i]&0x000000FF);
joshema216 2:ea6275d1222f 367 }
joshema216 2:ea6275d1222f 368 pc.printf("\r\nLENOUT GPS: %d, LENIN GPS: %2X\r\n", LENOUT1, LENIN1);
joshema216 2:ea6275d1222f 369
jufzapataov 3:9a7f48bbfbaa 370 // Concatenacion del mensaje en formato PDU y env卲 del mismo.
joshema216 2:ea6275d1222f 371 ind = 14 + LENOUT1 - 1;
joshema216 2:ea6275d1222f 372
joshema216 2:ea6275d1222f 373 GSM.printf("AT+CMGS=%d\r\n",ind);
joshema216 2:ea6275d1222f 374 pc.printf("AT+CMGS=%d\r\n",ind);
joshema216 2:ea6275d1222f 375 pc.printf(relle1);
joshema216 2:ea6275d1222f 376 GSM.printf(relle1);
joshema216 2:ea6275d1222f 377
joshema216 2:ea6275d1222f 378 for (i=0 ;i<=9; i++) {
joshema216 2:ea6275d1222f 379 pc.printf("%c",tel[i]);
joshema216 2:ea6275d1222f 380 GSM.printf("%c",tel[i]);
joshema216 2:ea6275d1222f 381 }
joshema216 2:ea6275d1222f 382
joshema216 2:ea6275d1222f 383 pc.printf(relle2);
joshema216 2:ea6275d1222f 384 GSM.printf(relle2);
joshema216 2:ea6275d1222f 385 pc.printf("%2X", LENIN1);
joshema216 2:ea6275d1222f 386 GSM.printf("%2X", LENIN1);
joshema216 2:ea6275d1222f 387
joshema216 2:ea6275d1222f 388 for (i = 0; i < LENOUT1; i++){
joshema216 2:ea6275d1222f 389 pc.printf("%02X", DS1[i]&0x000000FF);
joshema216 2:ea6275d1222f 390 GSM.printf("%02X", DS1[i]&0x000000FF);
joshema216 2:ea6275d1222f 391 }
joshema216 2:ea6275d1222f 392 wait(1);
joshema216 2:ea6275d1222f 393 GSM.putc((char)0x1A); // Ctrl - Z.
jufzapataov 3:9a7f48bbfbaa 394 GSM.scanf("%s",buf); // Estado del mensaje (Envi・o Error).
jufzapataov 3:9a7f48bbfbaa 395 pc.printf("\n>%s\n",buf);
joshema216 2:ea6275d1222f 396 }
joshema216 2:ea6275d1222f 397
joshema216 2:ea6275d1222f 398 wait(1);
jufzapataov 3:9a7f48bbfbaa 399 LedAzul = 1;
jufzapataov 3:9a7f48bbfbaa 400 LedRojo = 1;
jufzapataov 3:9a7f48bbfbaa 401 LedVerde = 0;
jufzapataov 3:9a7f48bbfbaa 402 GSM.printf("AT+CMGD=0\r\n"); // Borra el mensaje actual (Posicion "0").
jufzapataov 3:9a7f48bbfbaa 403 pc.printf("%s\n\n", "El mensaje ha sido borrado del celular");
jufzapataov 3:9a7f48bbfbaa 404 goto inicio1; // SE RECONFIGURA EL MODEM PARA ESTAR PENDIENTE A OTRO NUEVO MENSAJE
joshema216 2:ea6275d1222f 405 }
joshema216 2:ea6275d1222f 406 }
joshema216 2:ea6275d1222f 407 }
joshema216 2:ea6275d1222f 408 }
AaronGonzalez 1:e2bd083802c0 409 }