PROGRAMA SIMPLE QUE LEE UNA TRAMA DE GPS Y LA PONE EN PANTALLA DE LA TERMINAL DEL PC
Fork of GPS_Google_Cadenas by
main.cpp
00001 //ESTE PROGRAMA SE ENCARGA DE LEER UN GPS Y GENERAR UNA CADENA DE GEOLOCALIZACION 00002 //PARA SER ENVIADA COMO LINK EN UN MENSAJE DE TEXTO 00003 //UTIL PARA IMPLEMENTAR UN RASTREADOR SATELITAL 00004 //EN CASO DE NO TENER GPS USE UN EMULADOR COMO SATGEMNMEA 00005 //https://www.labsat.co.uk/index.php/en/free-gps-nmea-simulator-software 00006 00007 #include "mbed.h" 00008 #include "GPS.h" 00009 #include <stdio.h> 00010 #include <string.h> 00011 #include <math.h> 00012 00013 Serial pc(USBTX, USBRX); 00014 GPS gps(PTE0, PTE1); 00015 int z; 00016 int Lo_E,Lo_F,La_E,La_F;//longitud entera y fraccionaria 00017 float frac_long, frac_lat; //fraccion longitud y fraccion latitud 00018 char long_E[4]; //Subcadena con la longitud entera 00019 char long_F[7];//Subcadena con la longitud fraccionaria(6 digitos) 00020 char lat_E[4];//Subcadena con la latitud entera 00021 char lat_F[7];////Subcadena con la latitud fraccionaria(6 digitos) 00022 char GooMap[55]="http://maps.google.com/maps?q="; 00023 char str[55]; 00024 void tostring(char[], int); //FUNCION QUE CONVIERTE UN ENTERO EN CARACTER Y VICEVERSA 00025 int num; 00026 int main() { 00027 00028 while(1) { 00029 if(gps.sample()) { 00030 Lo_E = abs((int)gps.longitude); 00031 Lo_F = (int)abs(1000000*(gps.longitude-(int)gps.longitude)); 00032 La_E = abs((int)gps.latitude); 00033 La_F = (int)abs(1000000*(gps.latitude-(int)gps.latitude)); 00034 00035 //calculo las cuatro subcadenas de las partes enteras y fraccionarias falta adicionar los puntos,las comas y los signos 00036 tostring(long_E, Lo_E); 00037 tostring(long_F, Lo_F); 00038 tostring(lat_E, La_E); 00039 tostring(lat_F, La_F); 00040 00041 if(gps.latitude<0){ 00042 strcat(GooMap,"-"); 00043 } 00044 strcat(GooMap,lat_E); 00045 strcat(GooMap,"."); 00046 strcat(GooMap,lat_F); 00047 strcat(GooMap,","); 00048 if(gps.longitude<0){ 00049 strcat(GooMap,"-"); 00050 } 00051 strcat(GooMap,long_E); 00052 strcat(GooMap,"."); 00053 strcat(GooMap,long_F); 00054 strcat(GooMap,"\n"); 00055 pc.printf("%s\n",GooMap); //la omprimo o hago algo con ella 00056 for(z=30;z<51;z++){ //la lleno de ceros para evitar problemas despues!! 00057 GooMap[z]=0; 00058 } 00059 } 00060 00061 else { 00062 00063 pc.printf("Oh Dear! No lock :(\n"); 00064 } 00065 } 00066 } 00067 00068 00069 //*********************************************************************************************** 00070 //funcion que convierte entero en caracter 00071 void tostring(char str[], int num) 00072 { 00073 int i, rem, len = 0, n; 00074 00075 n = num; 00076 while (n != 0) 00077 { 00078 len++; 00079 n /= 10; 00080 } 00081 for (i = 0; i < len; i++) 00082 { 00083 rem = num % 10; 00084 num = num / 10; 00085 str[len - (i + 1)] = rem + '0'; 00086 } 00087 str[len] = '\0'; 00088 } 00089 00090
Generated on Wed Jul 20 2022 12:41:07 by 1.7.2