gps
Dependents: RUCHE2-CODES RUCHE2-CODES_correctiondepoids RUCHE2-CODES_correction_de_poids
Revision 0:0c2f0ae3493e, committed 2019-01-28
- Comitter:
- mohayonor
- Date:
- Mon Jan 28 17:04:37 2019 +0000
- Commit message:
- gps actu
Changed in this revision
diff -r 000000000000 -r 0c2f0ae3493e TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Mon Jan 28 17:04:37 2019 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 0c2f0ae3493e gps.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gps.cpp Mon Jan 28 17:04:37 2019 +0000 @@ -0,0 +1,126 @@ + +#include "gps.h" + +int dateRef = 90318; + + +Serial gps(D1, D0); +//TextLCD lcd(p11, p12, p15, p16, p29, p30); // rs, e, d4, d5, d6, d7 + +void Init() +{ + gps.baud(9600); +} + +int getGPS(char* cDataBuffer,float *lat,float *lon,float *tmf,float *spd, int *dat, char *ns, char *ew, char *stat) +{ + char nortSouth, eastWest, status; + int date,fq, nst; // fix quality, Number of satellites being tracked, 3D fix + float latitude, longitude, timefix, speed,altitude; + + if(strncmp(cDataBuffer,"$GPRMC", 6) == 0) + { + sscanf(cDataBuffer, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &nortSouth, &longitude, &eastWest, &speed, &date); + + if (latitude !=0) + *lat = latitude*0.01; + if (longitude != 0) + *lon = longitude*0.01; + + *tmf = timefix; + + *spd = speed; + if (date >= dateRef) + *dat = date; + + if (nortSouth == 'N' | nortSouth == 'S') + *ns = nortSouth; + if (eastWest == 'W' | eastWest == 'E') + *ew = eastWest; + *stat = status; + // 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); + // 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); + return 0; + } + if(strncmp(cDataBuffer,"$GPGLL", 6) == 0) + { + sscanf(cDataBuffer, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &nortSouth, &longitude, &eastWest, &timefix); + //pc.printf("%s",cDataBuffer); + if (latitude !=0) + *lat = latitude * 0.01; + + if (longitude != 0) + *lon = longitude * 0.01; + + *tmf = timefix; + *spd = speed; + + if (nortSouth == 'N' | nortSouth == 'S') + *ns = nortSouth; + + if (eastWest == 'W' | eastWest == 'E') + *ew = eastWest; + return 0; + } + + if(strncmp(cDataBuffer,"$GPGGA", 6) == 0) + { + sscanf(cDataBuffer, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &nortSouth, &longitude, &eastWest, &fq, &nst, &altitude); + if (latitude !=0) + *lat = latitude * 0.01; + + if (longitude != 0) + *lon = longitude * 0.01; + + //*alt = altitude; + *tmf = timefix; + + if (nortSouth == 'N' | nortSouth == 'S') + *ns = nortSouth; + + if (eastWest == 'W' | eastWest == 'E') + *ew = eastWest; + return 0; + + } + return -1; + + +} + + + +int getLatLong(float &lat , float &lon) +{ + Init(); + char Buffer[128],str[7]; + char ns, ew, status; + int date,gpsACK; // fix quality, Number of satellites being tracked, 3D fix + float latitude, longitude, timefix, speed; + memset(Buffer,0,sizeof(Buffer)); + date = 0; + latitude = longitude = timefix = speed = 0; + ns = ew = status =0; + + if(gps.readable()) + { + gps.gets(Buffer,90); + if(Buffer[0] == '$'){ + memcpy(str,Buffer, 6); + //printf("\nrecv: %s\n",str); + gpsACK = getGPS(Buffer, &latitude, &longitude, &timefix, &speed, &date, &ns, &ew, &status); + + } + } + + if (gpsACK == 0) + { + lat = latitude; + lon = longitude; + } + + + +} + +
diff -r 000000000000 -r 0c2f0ae3493e gps.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gps.h Mon Jan 28 17:04:37 2019 +0000 @@ -0,0 +1,12 @@ + +#include "mbed.h" +#include <stdio.h> +#include "TextLCD.h" + +extern int dateRef ; + +//TextLCD lcd(p11, p12, p15, p16, p29, p30); // rs, e, d4, d5, d6, d7 + +void Init(); +int getGPS(char* cDataBuffer,float *lat,float *lon,float *tmf,float *spd, int *dat, char *ns, char *ew, char *stat); +int getLatLong(float &lat , float &lon); \ No newline at end of file