Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RUCHE2-CODES RUCHE2-CODES_correctiondepoids RUCHE2-CODES_correction_de_poids
gps.cpp
00001 00002 #include "gps.h" 00003 00004 int dateRef = 90318; 00005 00006 00007 Serial gps(D1, D0); 00008 //TextLCD lcd(p11, p12, p15, p16, p29, p30); // rs, e, d4, d5, d6, d7 00009 00010 void Init() 00011 { 00012 gps.baud(9600); 00013 } 00014 00015 int getGPS(char* cDataBuffer,float *lat,float *lon,float *tmf,float *spd, int *dat, char *ns, char *ew, char *stat) 00016 { 00017 char nortSouth, eastWest, status; 00018 int date,fq, nst; // fix quality, Number of satellites being tracked, 3D fix 00019 float latitude, longitude, timefix, speed,altitude; 00020 00021 if(strncmp(cDataBuffer,"$GPRMC", 6) == 0) 00022 { 00023 sscanf(cDataBuffer, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &nortSouth, &longitude, &eastWest, &speed, &date); 00024 00025 if (latitude !=0) 00026 *lat = latitude*0.01; 00027 if (longitude != 0) 00028 *lon = longitude*0.01; 00029 00030 *tmf = timefix; 00031 00032 *spd = speed; 00033 if (date >= dateRef) 00034 *dat = date; 00035 00036 if (nortSouth == 'N' | nortSouth == 'S') 00037 *ns = nortSouth; 00038 if (eastWest == 'W' | eastWest == 'E') 00039 *ew = eastWest; 00040 *stat = status; 00041 // pc.printf("GPRMC Fix: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", timefix, status, latitude, nortSouth, longitude, eastWest, speed, date); 00042 // pc.printf("GPRMC Fix: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", *tmf, *stat, *lat, *ns, *lon, *ew, *spd, *dat); 00043 return 0; 00044 } 00045 if(strncmp(cDataBuffer,"$GPGLL", 6) == 0) 00046 { 00047 sscanf(cDataBuffer, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &nortSouth, &longitude, &eastWest, &timefix); 00048 //pc.printf("%s",cDataBuffer); 00049 if (latitude !=0) 00050 *lat = latitude * 0.01; 00051 00052 if (longitude != 0) 00053 *lon = longitude * 0.01; 00054 00055 *tmf = timefix; 00056 *spd = speed; 00057 00058 if (nortSouth == 'N' | nortSouth == 'S') 00059 *ns = nortSouth; 00060 00061 if (eastWest == 'W' | eastWest == 'E') 00062 *ew = eastWest; 00063 return 0; 00064 } 00065 00066 if(strncmp(cDataBuffer,"$GPGGA", 6) == 0) 00067 { 00068 sscanf(cDataBuffer, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &nortSouth, &longitude, &eastWest, &fq, &nst, &altitude); 00069 if (latitude !=0) 00070 *lat = latitude * 0.01; 00071 00072 if (longitude != 0) 00073 *lon = longitude * 0.01; 00074 00075 //*alt = altitude; 00076 *tmf = timefix; 00077 00078 if (nortSouth == 'N' | nortSouth == 'S') 00079 *ns = nortSouth; 00080 00081 if (eastWest == 'W' | eastWest == 'E') 00082 *ew = eastWest; 00083 return 0; 00084 00085 } 00086 return -1; 00087 00088 00089 } 00090 00091 00092 00093 int getLatLong(float &lat , float &lon) 00094 { 00095 Init(); 00096 char Buffer[128],str[7]; 00097 char ns, ew, status; 00098 int date,gpsACK; // fix quality, Number of satellites being tracked, 3D fix 00099 float latitude, longitude, timefix, speed; 00100 memset(Buffer,0,sizeof(Buffer)); 00101 date = 0; 00102 latitude = longitude = timefix = speed = 0; 00103 ns = ew = status =0; 00104 00105 if(gps.readable()) 00106 { 00107 gps.gets(Buffer,90); 00108 if(Buffer[0] == '$'){ 00109 memcpy(str,Buffer, 6); 00110 //printf("\nrecv: %s\n",str); 00111 gpsACK = getGPS(Buffer, &latitude, &longitude, &timefix, &speed, &date, &ns, &ew, &status); 00112 00113 } 00114 } 00115 00116 if (gpsACK == 0) 00117 { 00118 lat = latitude; 00119 lon = longitude; 00120 } 00121 00122 00123 00124 } 00125 00126
Generated on Sun Jul 17 2022 23:14:29 by
1.7.2