gps_celular

Dependencies:   GPS7 mbed

Committer:
Rudyedisonlealgarces
Date:
Fri Jun 26 01:28:31 2015 +0000
Revision:
1:df85900c7dc4
Parent:
0:5332dcc305cd
celular

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rudyedisonlealgarces 0:5332dcc305cd 1 #include "mbed.h"
Rudyedisonlealgarces 0:5332dcc305cd 2 #include "GPS.h"
Rudyedisonlealgarces 0:5332dcc305cd 3 #include "string.h"
Rudyedisonlealgarces 0:5332dcc305cd 4 #include "stdio.h"
Rudyedisonlealgarces 0:5332dcc305cd 5 #include "stdlib.h"
Rudyedisonlealgarces 0:5332dcc305cd 6
Rudyedisonlealgarces 0:5332dcc305cd 7 Serial gsm(PTE0,PTE1); // Se declaran puertos para la comunicacíón GSM
Rudyedisonlealgarces 0:5332dcc305cd 8 Serial pc(USBTX,USBRX); // Puerto seríal de la Freescale para el envio de datos
Rudyedisonlealgarces 0:5332dcc305cd 9 GPS gps(PTD7, PTD6);
Rudyedisonlealgarces 0:5332dcc305cd 10
Rudyedisonlealgarces 0:5332dcc305cd 11 DigitalOut myled(LED1);
Rudyedisonlealgarces 0:5332dcc305cd 12
Rudyedisonlealgarces 0:5332dcc305cd 13 char buf[100], bufm[18], tam[2], pdu[]="";
Rudyedisonlealgarces 0:5332dcc305cd 14 // Variables para almacenar las cadenas de caracteres
Rudyedisonlealgarces 0:5332dcc305cd 15 int i,K,C,LENOUT,LENIN;
Rudyedisonlealgarces 0:5332dcc305cd 16 char ME[]="ME";
Rudyedisonlealgarces 0:5332dcc305cd 17 char DE[255];
Rudyedisonlealgarces 0:5332dcc305cd 18 char DS[255];
Rudyedisonlealgarces 0:5332dcc305cd 19 char vector_1[]="";
Rudyedisonlealgarces 0:5332dcc305cd 20 char vector_2[]="";
Rudyedisonlealgarces 0:5332dcc305cd 21
Rudyedisonlealgarces 0:5332dcc305cd 22
Rudyedisonlealgarces 0:5332dcc305cd 23
Rudyedisonlealgarces 0:5332dcc305cd 24 float lo,la;
Rudyedisonlealgarces 0:5332dcc305cd 25
Rudyedisonlealgarces 0:5332dcc305cd 26 char trama[100]={"0691136249209211000A9103700479590000AA03C3B71C"}; // codigo de mi celular en pdu
Rudyedisonlealgarces 0:5332dcc305cd 27 char LINK[]={"http://maps.google.com/?q="}; // GOOGLE MAPS
Rudyedisonlealgarces 0:5332dcc305cd 28 char ENV[]="0011000A9113382624970000AA";
Rudyedisonlealgarces 0:5332dcc305cd 29
Rudyedisonlealgarces 0:5332dcc305cd 30 int main() {
Rudyedisonlealgarces 0:5332dcc305cd 31 // Configuración para la comunicacion con el celular
Rudyedisonlealgarces 0:5332dcc305cd 32 //haciendo pruebas con el programa Termite con el codigo AT
Rudyedisonlealgarces 0:5332dcc305cd 33
Rudyedisonlealgarces 0:5332dcc305cd 34 gsm.baud(9600); // Configuracion de la velocidad de comunicación
Rudyedisonlealgarces 0:5332dcc305cd 35 gsm.format(8,Serial::None,1);
Rudyedisonlealgarces 0:5332dcc305cd 36
Rudyedisonlealgarces 0:5332dcc305cd 37 pc.printf("Enviamos AT \n"); //imprima en la pantalla del computador
Rudyedisonlealgarces 0:5332dcc305cd 38 gsm.printf("AT\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 39 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 40 pc.printf(">%s\n",buf);
Rudyedisonlealgarces 0:5332dcc305cd 41 wait(1);
Rudyedisonlealgarces 0:5332dcc305cd 42
Rudyedisonlealgarces 0:5332dcc305cd 43
Rudyedisonlealgarces 0:5332dcc305cd 44 gsm.printf("AT+CNMI=1,1\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 45 pc.printf("AT+CNMI=1,1\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 46 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 47 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 48 pc.printf(">%s\n",buf);
Rudyedisonlealgarces 0:5332dcc305cd 49 wait(1);
Rudyedisonlealgarces 0:5332dcc305cd 50
Rudyedisonlealgarces 0:5332dcc305cd 51
Rudyedisonlealgarces 0:5332dcc305cd 52 gsm.printf("AT+CPMS= \"SM\",\"SM\",\"SM\"\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 53 pc.printf("AT+CPMS= \"SM\",\"SM\",\"SM\"\n");
Rudyedisonlealgarces 0:5332dcc305cd 54 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 55 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 56 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 57 pc.printf(">%s\n",buf);
Rudyedisonlealgarces 0:5332dcc305cd 58 wait(1);
Rudyedisonlealgarces 0:5332dcc305cd 59
Rudyedisonlealgarces 0:5332dcc305cd 60
Rudyedisonlealgarces 0:5332dcc305cd 61 gsm.printf("AT+CMGF=0\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 62 pc.printf("AT+CMGF=0\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 63 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 64 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 65 pc.printf(">%s\n",buf);
Rudyedisonlealgarces 0:5332dcc305cd 66
Rudyedisonlealgarces 0:5332dcc305cd 67 gsm.printf("CBST=0,0,1\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 68
Rudyedisonlealgarces 0:5332dcc305cd 69 //ingreso al while para esperar el mensaje
Rudyedisonlealgarces 0:5332dcc305cd 70 while(1) {
Rudyedisonlealgarces 0:5332dcc305cd 71
Rudyedisonlealgarces 0:5332dcc305cd 72 pc.printf("\n Esperar_Mensaje \n");
Rudyedisonlealgarces 0:5332dcc305cd 73 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 74 pc.printf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 75 i = strlen(buf);
Rudyedisonlealgarces 0:5332dcc305cd 76 //entro en el while hasta que se cumpla alguna de estas 3 condiciones
Rudyedisonlealgarces 0:5332dcc305cd 77 if(i>3){
Rudyedisonlealgarces 0:5332dcc305cd 78 pc.printf("Llego un Mensaje \n");
Rudyedisonlealgarces 0:5332dcc305cd 79 gsm.printf("AT+CMGR=1 \r\n"); // lee el mensaje que esta entrando
Rudyedisonlealgarces 0:5332dcc305cd 80 gsm.scanf("%s",buf); //borro primer mensaje acumulado
Rudyedisonlealgarces 0:5332dcc305cd 81 gsm.scanf("%s",buf); //borro segundo mensaje acumulado
Rudyedisonlealgarces 0:5332dcc305cd 82 gsm.scanf("%s",buf); //borro tercer mensaje osea que limpio la memoria del celular
Rudyedisonlealgarces 0:5332dcc305cd 83 gsm.scanf("%s",buf); //para que pueda leer el primero y no los acumulados
Rudyedisonlealgarces 0:5332dcc305cd 84 pc.printf(">%s",buf); //Mostrar en PDU del mensaje leido.
Rudyedisonlealgarces 0:5332dcc305cd 85
Rudyedisonlealgarces 0:5332dcc305cd 86
Rudyedisonlealgarces 0:5332dcc305cd 87 i = strlen(buf); // compara la cadena de Pdu que ha llegado
Rudyedisonlealgarces 0:5332dcc305cd 88
Rudyedisonlealgarces 0:5332dcc305cd 89 if(i==56){
Rudyedisonlealgarces 0:5332dcc305cd 90 pc.printf("\n LLego on");
Rudyedisonlealgarces 0:5332dcc305cd 91 myled = 0; //encienda el led
Rudyedisonlealgarces 0:5332dcc305cd 92 gsm.printf("AT+CMGD=1\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 93 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 94 pc.printf("\n%s\n",buf);
Rudyedisonlealgarces 0:5332dcc305cd 95
Rudyedisonlealgarces 0:5332dcc305cd 96 }//if de on
Rudyedisonlealgarces 0:5332dcc305cd 97
Rudyedisonlealgarces 0:5332dcc305cd 98 if(i==58){
Rudyedisonlealgarces 0:5332dcc305cd 99 pc.printf("\n LLego off");
Rudyedisonlealgarces 0:5332dcc305cd 100 myled = 1; //apague el led
Rudyedisonlealgarces 0:5332dcc305cd 101 gsm.printf("AT+CMGD=1\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 102 gsm.scanf("%s",buf); //escaneo el mensaje
Rudyedisonlealgarces 0:5332dcc305cd 103 pc.printf("\n%s\n",buf);// aquí certifico que he boorado el mensaje
Rudyedisonlealgarces 0:5332dcc305cd 104
Rudyedisonlealgarces 0:5332dcc305cd 105 }//if de off
Rudyedisonlealgarces 0:5332dcc305cd 106
Rudyedisonlealgarces 0:5332dcc305cd 107 if(i==62){
Rudyedisonlealgarces 0:5332dcc305cd 108 //llegó elmensaje "cord"
Rudyedisonlealgarces 0:5332dcc305cd 109
Rudyedisonlealgarces 0:5332dcc305cd 110
Rudyedisonlealgarces 0:5332dcc305cd 111
Rudyedisonlealgarces 0:5332dcc305cd 112 gsm.format(8,Serial::None,1); // 8 bit sin paaridad
Rudyedisonlealgarces 0:5332dcc305cd 113 pc.printf("gsm.format(8,Serial::None,1)\n");
Rudyedisonlealgarces 0:5332dcc305cd 114
Rudyedisonlealgarces 0:5332dcc305cd 115 pc.printf("Enviamos AT\n");
Rudyedisonlealgarces 0:5332dcc305cd 116 gsm.printf("AT\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 117 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 118 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 119 pc.printf(">%s\n",buf);
Rudyedisonlealgarces 0:5332dcc305cd 120
Rudyedisonlealgarces 0:5332dcc305cd 121 gsm.printf("AT+CMGR=1\r\n"); // Se lee el menjsae que ente en el indice 1.
Rudyedisonlealgarces 0:5332dcc305cd 122 pc.printf("AT+CMGR=1\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 123 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 124 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 125 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 126 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 127 pc.printf(">%s\n",buf);
Rudyedisonlealgarces 0:5332dcc305cd 128
Rudyedisonlealgarces 0:5332dcc305cd 129
Rudyedisonlealgarces 0:5332dcc305cd 130 pc.printf("gps \n");
Rudyedisonlealgarces 0:5332dcc305cd 131
Rudyedisonlealgarces 0:5332dcc305cd 132 while(1) {
Rudyedisonlealgarces 0:5332dcc305cd 133 i=0;
Rudyedisonlealgarces 0:5332dcc305cd 134 if(gps.sample()& i==0) {
Rudyedisonlealgarces 0:5332dcc305cd 135 // ingresa sí recibe datos del sagem si no quedarse
Rudyedisonlealgarces 0:5332dcc305cd 136 pc.printf("Comienza el gps \n");
Rudyedisonlealgarces 0:5332dcc305cd 137 //Toma de datos del gps y concatenacion para armar los datos.
Rudyedisonlealgarces 0:5332dcc305cd 138
Rudyedisonlealgarces 0:5332dcc305cd 139 la=gps.longitude;
Rudyedisonlealgarces 0:5332dcc305cd 140 lo=gps.latitude;
Rudyedisonlealgarces 0:5332dcc305cd 141 sprintf(vector_1, "%f", lo);//cojo variable "lo" la guardo en vector1 con propiedad flotante
Rudyedisonlealgarces 0:5332dcc305cd 142 strcat(LINK,vector_1);// utilizo para concatenar , en link (GOOGLE MAPS)pego lo q esta en vector1
Rudyedisonlealgarces 0:5332dcc305cd 143 strcat(LINK,","); // concateno una coma para separar los datos mostrados
Rudyedisonlealgarces 0:5332dcc305cd 144
Rudyedisonlealgarces 0:5332dcc305cd 145 sprintf(vector_2, "%f", la);
Rudyedisonlealgarces 0:5332dcc305cd 146 strcat(LINK,vector_2);
Rudyedisonlealgarces 0:5332dcc305cd 147 strcat(DE,LINK); // variable del profesor que pasa de caracteres a pdu
Rudyedisonlealgarces 0:5332dcc305cd 148 pc.printf("%s\n",LINK);
Rudyedisonlealgarces 0:5332dcc305cd 149
Rudyedisonlealgarces 0:5332dcc305cd 150 LENIN=strlen(DE); // combierto los datos a Pdu
Rudyedisonlealgarces 0:5332dcc305cd 151
Rudyedisonlealgarces 0:5332dcc305cd 152 K=0;C=0;
Rudyedisonlealgarces 0:5332dcc305cd 153 for (i=0;i < LENIN;i++){
Rudyedisonlealgarces 0:5332dcc305cd 154 DS[i]=DE[i+C]>>K | DE[i+C+1]<<(7-K);
Rudyedisonlealgarces 0:5332dcc305cd 155 if (DS[i]==0x00) {LENOUT=i; goto salir;}// cambia de sextetos a octetos
Rudyedisonlealgarces 0:5332dcc305cd 156 K++;
Rudyedisonlealgarces 1:df85900c7dc4 157 if (K==7) {K=0;C++;} // se chequea que ya se acabaron los bits
Rudyedisonlealgarces 0:5332dcc305cd 158 }
Rudyedisonlealgarces 0:5332dcc305cd 159 salir: pc.printf("DE\n");
Rudyedisonlealgarces 0:5332dcc305cd 160 for (i=0;i < LENIN;i++){
Rudyedisonlealgarces 0:5332dcc305cd 161 pc.printf("%X",DE[i]);
Rudyedisonlealgarces 0:5332dcc305cd 162 }
Rudyedisonlealgarces 0:5332dcc305cd 163 pc.printf("\n DS \n");// guardo la i esima posición en pantalla
Rudyedisonlealgarces 0:5332dcc305cd 164 for (i=0;i<LENOUT;i++){
Rudyedisonlealgarces 0:5332dcc305cd 165 pc.printf("%02X",DS[i]&0x000000FF);// imprimo con el comando %02X
Rudyedisonlealgarces 0:5332dcc305cd 166 }
Rudyedisonlealgarces 0:5332dcc305cd 167
Rudyedisonlealgarces 0:5332dcc305cd 168 pc.printf("\n LENOUT:%d,LENIN:%d\r\n",LENOUT,strlen(DE));// longitud de la trama Pdu
Rudyedisonlealgarces 0:5332dcc305cd 169
Rudyedisonlealgarces 0:5332dcc305cd 170
Rudyedisonlealgarces 0:5332dcc305cd 171
Rudyedisonlealgarces 0:5332dcc305cd 172 // el mensaje
Rudyedisonlealgarces 0:5332dcc305cd 173
Rudyedisonlealgarces 0:5332dcc305cd 174 pc.printf("Comienza SMS \n");
Rudyedisonlealgarces 0:5332dcc305cd 175
Rudyedisonlealgarces 0:5332dcc305cd 176
Rudyedisonlealgarces 0:5332dcc305cd 177 gsm.printf("AT+CMGS=53\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 178 pc.printf("\n AT+CMGS=53\r\n");
Rudyedisonlealgarces 0:5332dcc305cd 179 wait(1);
Rudyedisonlealgarces 0:5332dcc305cd 180
Rudyedisonlealgarces 0:5332dcc305cd 181 gsm.printf("0011000A9113382624970000AA");
Rudyedisonlealgarces 0:5332dcc305cd 182 pc.printf("0011000A9113382624970000AA");
Rudyedisonlealgarces 0:5332dcc305cd 183 wait(1);
Rudyedisonlealgarces 0:5332dcc305cd 184 gsm.printf("%2X",LENOUT);// imprima el valor hexagesima en celular
Rudyedisonlealgarces 0:5332dcc305cd 185 pc.printf("%2X",LENOUT); //imprima el valor hex en computador
Rudyedisonlealgarces 0:5332dcc305cd 186
Rudyedisonlealgarces 0:5332dcc305cd 187
Rudyedisonlealgarces 0:5332dcc305cd 188 for (i=0;i < LENOUT;i++){
Rudyedisonlealgarces 0:5332dcc305cd 189 gsm.printf("%02X",DS[i]&0x000000FF);
Rudyedisonlealgarces 0:5332dcc305cd 190 pc.printf("%02X",DS[i]&0x000000FF);
Rudyedisonlealgarces 0:5332dcc305cd 191 wait(0.3);
Rudyedisonlealgarces 0:5332dcc305cd 192 }
Rudyedisonlealgarces 0:5332dcc305cd 193 gsm.putc((char)0x1A);
Rudyedisonlealgarces 0:5332dcc305cd 194
Rudyedisonlealgarces 0:5332dcc305cd 195 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 196 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 197
Rudyedisonlealgarces 0:5332dcc305cd 198 pc.printf("\n lo que devuelve el cel %s \n",buf);// compruebo que ha llegado el mensaje
Rudyedisonlealgarces 0:5332dcc305cd 199 i=1;
Rudyedisonlealgarces 0:5332dcc305cd 200 gsm.printf("AT+CMGD=1\r\n"); //borro mensaje para que quede limpio memoria del celular
Rudyedisonlealgarces 0:5332dcc305cd 201 pc.printf("\n Se sale de while para la lectura de gps \n ");
Rudyedisonlealgarces 0:5332dcc305cd 202 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 203 pc.printf(">%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 204 goto esp;
Rudyedisonlealgarces 0:5332dcc305cd 205 }
Rudyedisonlealgarces 0:5332dcc305cd 206
Rudyedisonlealgarces 0:5332dcc305cd 207
Rudyedisonlealgarces 0:5332dcc305cd 208
Rudyedisonlealgarces 0:5332dcc305cd 209 }//if de coord
Rudyedisonlealgarces 0:5332dcc305cd 210
Rudyedisonlealgarces 0:5332dcc305cd 211 }// if de llegada de SMS
Rudyedisonlealgarces 0:5332dcc305cd 212
Rudyedisonlealgarces 0:5332dcc305cd 213 esp:
Rudyedisonlealgarces 0:5332dcc305cd 214 gsm.scanf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 215 pc.printf("%s",buf);
Rudyedisonlealgarces 0:5332dcc305cd 216
Rudyedisonlealgarces 0:5332dcc305cd 217 }//devuelvo al while
Rudyedisonlealgarces 0:5332dcc305cd 218 }// lleva al menú principal
Rudyedisonlealgarces 0:5332dcc305cd 219 }