Fabio Andres Ibañez Diaz
/
GPSCELU_Grupo8
GPS_grupo8
main.cpp@0:b0461e42dc36, 2015-05-24 (annotated)
- Committer:
- obifandres
- Date:
- Sun May 24 16:54:30 2015 +0000
- Revision:
- 0:b0461e42dc36
GPS_Grupo8
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
obifandres | 0:b0461e42dc36 | 1 | #include "mbed.h" |
obifandres | 0:b0461e42dc36 | 2 | #include "stdio.h" |
obifandres | 0:b0461e42dc36 | 3 | #include "string.h" |
obifandres | 0:b0461e42dc36 | 4 | #include "GPS.h" |
obifandres | 0:b0461e42dc36 | 5 | #include "stdlib.h" |
obifandres | 0:b0461e42dc36 | 6 | |
obifandres | 0:b0461e42dc36 | 7 | |
obifandres | 0:b0461e42dc36 | 8 | Serial gsm(PTE0,PTE1); // Se declaran puertos para la comunicacíón GSM |
obifandres | 0:b0461e42dc36 | 9 | Serial pc(USBTX,USBRX); // Puerto seríal de la Freescale para el envio de datos |
obifandres | 0:b0461e42dc36 | 10 | GPS gps(PTE22, PTE23); |
obifandres | 0:b0461e42dc36 | 11 | |
obifandres | 0:b0461e42dc36 | 12 | |
obifandres | 0:b0461e42dc36 | 13 | char buf[100], bufm[18], tam[2], pdu[]=""; // Variables para almacenar las cadenas de caracteres |
obifandres | 0:b0461e42dc36 | 14 | char v1[]=""; |
obifandres | 0:b0461e42dc36 | 15 | char v2[]=""; |
obifandres | 0:b0461e42dc36 | 16 | char de[255]; |
obifandres | 0:b0461e42dc36 | 17 | char ds[255]; |
obifandres | 0:b0461e42dc36 | 18 | float chk,Long,Lat; |
obifandres | 0:b0461e42dc36 | 19 | int i,j,k,Lout,Lin; |
obifandres | 0:b0461e42dc36 | 20 | |
obifandres | 0:b0461e42dc36 | 21 | |
obifandres | 0:b0461e42dc36 | 22 | char trama[100]={"0791750330960007040AA1137356899000005150323123200A03C3B71C"}; // Definicion de la trama entrante PDU solo para pruebas |
obifandres | 0:b0461e42dc36 | 23 | char Link[]={"http://maps.google.com/?q="}; // Trama base |
obifandres | 0:b0461e42dc36 | 24 | char ENV[]="0011000A9113735689900000AA"; |
obifandres | 0:b0461e42dc36 | 25 | |
obifandres | 0:b0461e42dc36 | 26 | int main() { |
obifandres | 0:b0461e42dc36 | 27 | // Configuración para la comunicacion con el celular |
obifandres | 0:b0461e42dc36 | 28 | |
obifandres | 0:b0461e42dc36 | 29 | gsm.baud(9600); // Configuracion de los baudios |
obifandres | 0:b0461e42dc36 | 30 | gsm.format(8,Serial::None,1); |
obifandres | 0:b0461e42dc36 | 31 | |
obifandres | 0:b0461e42dc36 | 32 | pc.printf("Enviamos AT \n"); |
obifandres | 0:b0461e42dc36 | 33 | gsm.printf("AT\r\n"); |
obifandres | 0:b0461e42dc36 | 34 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 35 | |
obifandres | 0:b0461e42dc36 | 36 | wait(1); |
obifandres | 0:b0461e42dc36 | 37 | |
obifandres | 0:b0461e42dc36 | 38 | |
obifandres | 0:b0461e42dc36 | 39 | gsm.printf("AT+CNMI=1,1\r\n"); |
obifandres | 0:b0461e42dc36 | 40 | pc.printf("AT+CNMI=1,1\r\n"); |
obifandres | 0:b0461e42dc36 | 41 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 42 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 43 | pc.printf(">%s\n",buf); |
obifandres | 0:b0461e42dc36 | 44 | wait(1); |
obifandres | 0:b0461e42dc36 | 45 | |
obifandres | 0:b0461e42dc36 | 46 | |
obifandres | 0:b0461e42dc36 | 47 | gsm.printf("AT+CPMS= \"SM\",\"SM\",\"SM\"\r\n"); |
obifandres | 0:b0461e42dc36 | 48 | pc.printf("AT+CPMS= \"SM\",\"SM\",\"SM\"\n"); |
obifandres | 0:b0461e42dc36 | 49 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 50 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 51 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 52 | pc.printf(">%s\n",buf); |
obifandres | 0:b0461e42dc36 | 53 | wait(1); |
obifandres | 0:b0461e42dc36 | 54 | |
obifandres | 0:b0461e42dc36 | 55 | |
obifandres | 0:b0461e42dc36 | 56 | gsm.printf("AT+CMGF=0\r\n"); |
obifandres | 0:b0461e42dc36 | 57 | pc.printf("AT+CMGF=0\r\n"); |
obifandres | 0:b0461e42dc36 | 58 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 59 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 60 | pc.printf(">%s\n",buf); |
obifandres | 0:b0461e42dc36 | 61 | |
obifandres | 0:b0461e42dc36 | 62 | gsm.printf("CBST=0,0,1\r\n"); |
obifandres | 0:b0461e42dc36 | 63 | |
obifandres | 0:b0461e42dc36 | 64 | |
obifandres | 0:b0461e42dc36 | 65 | while(1) { |
obifandres | 0:b0461e42dc36 | 66 | |
obifandres | 0:b0461e42dc36 | 67 | pc.printf("\n Esperando Mensaje \n"); |
obifandres | 0:b0461e42dc36 | 68 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 69 | pc.printf("%s",buf); |
obifandres | 0:b0461e42dc36 | 70 | i = strlen(buf); |
obifandres | 0:b0461e42dc36 | 71 | if(i>3){ |
obifandres | 0:b0461e42dc36 | 72 | pc.printf("Llego un Mensaje \n"); |
obifandres | 0:b0461e42dc36 | 73 | gsm.printf("AT+CMGR=1 \r\n"); // Se lee el menjsae que ente en el indice 1. |
obifandres | 0:b0461e42dc36 | 74 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 75 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 76 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 77 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 78 | pc.printf(">%s",buf); //Mostrar la cadena en PDU del mensaje leido. |
obifandres | 0:b0461e42dc36 | 79 | |
obifandres | 0:b0461e42dc36 | 80 | |
obifandres | 0:b0461e42dc36 | 81 | i = strlen(buf); |
obifandres | 0:b0461e42dc36 | 82 | |
obifandres | 0:b0461e42dc36 | 83 | if(i==56){ |
obifandres | 0:b0461e42dc36 | 84 | pc.printf("\n LLego on"); |
obifandres | 0:b0461e42dc36 | 85 | |
obifandres | 0:b0461e42dc36 | 86 | gsm.printf("AT+CMGD=1\r\n"); |
obifandres | 0:b0461e42dc36 | 87 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 88 | pc.printf("\n%s\n",buf); |
obifandres | 0:b0461e42dc36 | 89 | |
obifandres | 0:b0461e42dc36 | 90 | } |
obifandres | 0:b0461e42dc36 | 91 | |
obifandres | 0:b0461e42dc36 | 92 | if(i==58){ |
obifandres | 0:b0461e42dc36 | 93 | pc.printf("\n LLego off"); |
obifandres | 0:b0461e42dc36 | 94 | |
obifandres | 0:b0461e42dc36 | 95 | gsm.printf("AT+CMGD=1\r\n"); |
obifandres | 0:b0461e42dc36 | 96 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 97 | pc.printf("\n%s\n",buf); |
obifandres | 0:b0461e42dc36 | 98 | |
obifandres | 0:b0461e42dc36 | 99 | } |
obifandres | 0:b0461e42dc36 | 100 | |
obifandres | 0:b0461e42dc36 | 101 | if(i==62){ |
obifandres | 0:b0461e42dc36 | 102 | |
obifandres | 0:b0461e42dc36 | 103 | |
obifandres | 0:b0461e42dc36 | 104 | gsm.baud(9600); |
obifandres | 0:b0461e42dc36 | 105 | pc.printf("gsm.baud(9600)\n"); |
obifandres | 0:b0461e42dc36 | 106 | |
obifandres | 0:b0461e42dc36 | 107 | |
obifandres | 0:b0461e42dc36 | 108 | gsm.format(8,Serial::None,1); |
obifandres | 0:b0461e42dc36 | 109 | pc.printf("gsm.format(8,Serial::None,1)\n"); |
obifandres | 0:b0461e42dc36 | 110 | |
obifandres | 0:b0461e42dc36 | 111 | pc.printf("Enviamos AT\n"); |
obifandres | 0:b0461e42dc36 | 112 | gsm.printf("AT\r\n"); |
obifandres | 0:b0461e42dc36 | 113 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 114 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 115 | pc.printf(">%s\n",buf); |
obifandres | 0:b0461e42dc36 | 116 | |
obifandres | 0:b0461e42dc36 | 117 | gsm.printf("AT+CMGR=1\r\n"); // Se lee el menjsae que ente en el indice 1. |
obifandres | 0:b0461e42dc36 | 118 | pc.printf("AT+CMGR=1\r\n"); |
obifandres | 0:b0461e42dc36 | 119 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 120 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 121 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 122 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 123 | pc.printf(">%s\n",buf); |
obifandres | 0:b0461e42dc36 | 124 | |
obifandres | 0:b0461e42dc36 | 125 | |
obifandres | 0:b0461e42dc36 | 126 | pc.printf("Esperando por coordenadas del GPS \n"); |
obifandres | 0:b0461e42dc36 | 127 | |
obifandres | 0:b0461e42dc36 | 128 | while(1) { |
obifandres | 0:b0461e42dc36 | 129 | i=0; |
obifandres | 0:b0461e42dc36 | 130 | if(gps.sample()& i==0) { |
obifandres | 0:b0461e42dc36 | 131 | |
obifandres | 0:b0461e42dc36 | 132 | pc.printf("Toma de datos gps y concatenacion \n"); |
obifandres | 0:b0461e42dc36 | 133 | //Toma de datos del gps y concatenacion para armar los datos. |
obifandres | 0:b0461e42dc36 | 134 | |
obifandres | 0:b0461e42dc36 | 135 | Long=gps.longitude; |
obifandres | 0:b0461e42dc36 | 136 | Lat=gps.latitude; |
obifandres | 0:b0461e42dc36 | 137 | sprintf(v1, "%f", Lat); |
obifandres | 0:b0461e42dc36 | 138 | strcat(Link,v1); |
obifandres | 0:b0461e42dc36 | 139 | strcat(Link,","); |
obifandres | 0:b0461e42dc36 | 140 | |
obifandres | 0:b0461e42dc36 | 141 | wait(3); |
obifandres | 0:b0461e42dc36 | 142 | sprintf(v2, "%f", Long); |
obifandres | 0:b0461e42dc36 | 143 | strcat(Link,v2); |
obifandres | 0:b0461e42dc36 | 144 | strcat(de,Link); |
obifandres | 0:b0461e42dc36 | 145 | pc.printf("%s\n",Link); |
obifandres | 0:b0461e42dc36 | 146 | |
obifandres | 0:b0461e42dc36 | 147 | |
obifandres | 0:b0461e42dc36 | 148 | //Conversion a formatdo PDU |
obifandres | 0:b0461e42dc36 | 149 | |
obifandres | 0:b0461e42dc36 | 150 | Lin=strlen(de); |
obifandres | 0:b0461e42dc36 | 151 | |
obifandres | 0:b0461e42dc36 | 152 | j=0;k=0; |
obifandres | 0:b0461e42dc36 | 153 | for (i=0;i < Lin;i++){ |
obifandres | 0:b0461e42dc36 | 154 | ds[i]=de[i+k]>>j | de[i+k+1]<<(7-j); |
obifandres | 0:b0461e42dc36 | 155 | if (ds[i]==0x00) {Lout=i; goto salir;} |
obifandres | 0:b0461e42dc36 | 156 | j++; |
obifandres | 0:b0461e42dc36 | 157 | if (j==7) {j=0;k++;} // se chequea que ya se acabaron los bits en un ciclo de conversion. |
obifandres | 0:b0461e42dc36 | 158 | } |
obifandres | 0:b0461e42dc36 | 159 | |
obifandres | 0:b0461e42dc36 | 160 | //-------------------------------------------------------------- |
obifandres | 0:b0461e42dc36 | 161 | salir: pc.printf("de\n"); |
obifandres | 0:b0461e42dc36 | 162 | for (i=0;i < Lin;i++){ |
obifandres | 0:b0461e42dc36 | 163 | pc.printf("%X",de[i]); |
obifandres | 0:b0461e42dc36 | 164 | } |
obifandres | 0:b0461e42dc36 | 165 | pc.printf("\n ds \n"); |
obifandres | 0:b0461e42dc36 | 166 | for (i=0;i<Lout;i++){ |
obifandres | 0:b0461e42dc36 | 167 | pc.printf("%02X",ds[i]&0x000000FF); |
obifandres | 0:b0461e42dc36 | 168 | } |
obifandres | 0:b0461e42dc36 | 169 | |
obifandres | 0:b0461e42dc36 | 170 | pc.printf("\n Lout:%d,Lin:%d\r\n",Lout,strlen(de)); |
obifandres | 0:b0461e42dc36 | 171 | |
obifandres | 0:b0461e42dc36 | 172 | |
obifandres | 0:b0461e42dc36 | 173 | |
obifandres | 0:b0461e42dc36 | 174 | // Enviamos el mensaje |
obifandres | 0:b0461e42dc36 | 175 | |
obifandres | 0:b0461e42dc36 | 176 | pc.printf("Comienza SMS \n"); |
obifandres | 0:b0461e42dc36 | 177 | |
obifandres | 0:b0461e42dc36 | 178 | |
obifandres | 0:b0461e42dc36 | 179 | gsm.printf("AT+CMGS=53\r\n"); |
obifandres | 0:b0461e42dc36 | 180 | pc.printf("\n AT+CMGS=53\r\n"); |
obifandres | 0:b0461e42dc36 | 181 | wait(0.5); |
obifandres | 0:b0461e42dc36 | 182 | |
obifandres | 0:b0461e42dc36 | 183 | gsm.printf("0011000A9113735689900000AA"); |
obifandres | 0:b0461e42dc36 | 184 | pc.printf("0011000A9113735689900000AA"); |
obifandres | 0:b0461e42dc36 | 185 | wait(0.5); |
obifandres | 0:b0461e42dc36 | 186 | gsm.printf("%2X",Lout); |
obifandres | 0:b0461e42dc36 | 187 | pc.printf("%2X",Lout); |
obifandres | 0:b0461e42dc36 | 188 | |
obifandres | 0:b0461e42dc36 | 189 | |
obifandres | 0:b0461e42dc36 | 190 | for (i=0;i < Lout;i++){ |
obifandres | 0:b0461e42dc36 | 191 | gsm.printf("%02X",ds[i]&0x000000FF); |
obifandres | 0:b0461e42dc36 | 192 | pc.printf("%02X",ds[i]&0x000000FF); |
obifandres | 0:b0461e42dc36 | 193 | wait(0.3); |
obifandres | 0:b0461e42dc36 | 194 | } |
obifandres | 0:b0461e42dc36 | 195 | gsm.putc((char)0x1A); |
obifandres | 0:b0461e42dc36 | 196 | |
obifandres | 0:b0461e42dc36 | 197 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 198 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 199 | |
obifandres | 0:b0461e42dc36 | 200 | pc.printf("\n enviando mensaje y leyendo modem %s \n",buf); |
obifandres | 0:b0461e42dc36 | 201 | i=1; |
obifandres | 0:b0461e42dc36 | 202 | gsm.printf("AT+CMGD=1\r\n"); |
obifandres | 0:b0461e42dc36 | 203 | pc.printf("\n sale del while para lectura de gps \n "); |
obifandres | 0:b0461e42dc36 | 204 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 205 | pc.printf(">%s",buf); |
obifandres | 0:b0461e42dc36 | 206 | goto s; |
obifandres | 0:b0461e42dc36 | 207 | } |
obifandres | 0:b0461e42dc36 | 208 | |
obifandres | 0:b0461e42dc36 | 209 | |
obifandres | 0:b0461e42dc36 | 210 | |
obifandres | 0:b0461e42dc36 | 211 | } |
obifandres | 0:b0461e42dc36 | 212 | |
obifandres | 0:b0461e42dc36 | 213 | }// SMS |
obifandres | 0:b0461e42dc36 | 214 | |
obifandres | 0:b0461e42dc36 | 215 | s: |
obifandres | 0:b0461e42dc36 | 216 | gsm.scanf("%s",buf); |
obifandres | 0:b0461e42dc36 | 217 | pc.printf("%s",buf); |
obifandres | 0:b0461e42dc36 | 218 | |
obifandres | 0:b0461e42dc36 | 219 | } |
obifandres | 0:b0461e42dc36 | 220 | } |
obifandres | 0:b0461e42dc36 | 221 | } |