![](/media/cache/profiles/6781be9b5eb16b142d24c60a04c821e2.jpg.50x50_q85.jpg)
test code
Fork of GPS_U-blox_NEO-6M_Test_Code by
Diff: main.cpp
- Revision:
- 2:4cc7f42f94c1
- Parent:
- 1:acd907fbcbae
--- a/main.cpp Fri Aug 22 12:43:55 2014 +0000 +++ b/main.cpp Fri May 25 19:57:58 2018 +0000 @@ -1,90 +1,144 @@ /* - * Author: Edoardo De Marchi - * Date: 22-08-14 - * Notes: Firmware for GPS U-Blox NEO-6M + * Author: Renan + * Date: 27-02-18 + * Notes: Firmware for GPS GP 735T */ + +#include "mbed.h" +#include <stdio.h> +#include "TextLCD.h" -#include "main.h" - +int dateRef = 90318; + +Serial pc(USBTX,USBRX); +Serial gps(p9, p10); +TextLCD lcd(p11, p12, p15, p16, p29, p30); // rs, e, d4, d5, d6, d7 void Init() { gps.baud(9600); - pc.baud(115200); - - pc.printf("Init OK\n"); + pc.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; + if (longitude != 0) + *lon = longitude; + + *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; + + if (longitude != 0) + *lon = longitude; + + *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; + + if (longitude != 0) + *lon = longitude; + + //*alt = altitude; + *tmf = timefix; + + if (nortSouth == 'N' | nortSouth == 'S') + *ns = nortSouth; + + if (eastWest == 'W' | eastWest == 'E') + *ew = eastWest; + return 0; + + } + return -1; +} + + int main() { Init(); - char c; + 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; while(true) { if(gps.readable()) - { - if(gps.getc() == '$'); // wait a $ - { - for(int i=0; i<sizeof(cDataBuffer); i++) - { - c = gps.getc(); - if( c == '\r' ) - { - //pc.printf("%s\n", cDataBuffer); - parse(cDataBuffer, i); - i = sizeof(cDataBuffer); - } - else - { - cDataBuffer[i] = c; - } + { + 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) + { + lcd.printf("HORA:%d\n",(int)timefix); + lcd.printf("DATA:%d\n",date); + pc.printf("GPRMC Fix: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", timefix, status, latitude, ns, longitude, ew, speed, date); + wait(.2); + /* lcd.cls(); + lcd.printf("LATITUDE:\n%f %c ",latitude,ns); + wait(2); + lcd.cls(); + lcd.printf("LONGITUDE:\n%f %c ",longitude,ew); + wait(2);*/ + } + + + } } - - -void parse(char *cmd, int n) -{ - - char ns, ew, tf, status; - int fq, nst, fix, date; // fix quality, Number of satellites being tracked, 3D fix - float latitude, longitude, timefix, speed, altitude; - - - // Global Positioning System Fix Data - if(strncmp(cmd,"$GPGGA", 6) == 0) - { - sscanf(cmd, "$GPGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude); - pc.printf("GPGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n", timefix, latitude, ns, longitude, ew, fq, nst, altitude); - } - - // Satellite status - if(strncmp(cmd,"$GPGSA", 6) == 0) - { - sscanf(cmd, "$GPGSA,%c,%d,%d", &tf, &fix, &nst); - pc.printf("GPGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n", tf, fix, nst); - } - - // Geographic position, Latitude and Longitude - if(strncmp(cmd,"$GPGLL", 6) == 0) - { - sscanf(cmd, "$GPGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix); - pc.printf("GPGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n", latitude, ns, longitude, ew, timefix); - } - - // Geographic position, Latitude and Longitude - if(strncmp(cmd,"$GPRMC", 6) == 0) - { - sscanf(cmd, "$GPRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date); - pc.printf("GPRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n", timefix, status, latitude, ns, longitude, ew, speed, date); - } -} - - - - + +