Renan Alves
/
GPS_Test_Code
test code
Fork of GPS_U-blox_NEO-6M_Test_Code by
Revision 2:4cc7f42f94c1, committed 2018-05-25
- Comitter:
- renanbmx123
- Date:
- Fri May 25 19:57:58 2018 +0000
- Parent:
- 1:acd907fbcbae
- Commit message:
- test code
Changed in this revision
diff -r acd907fbcbae -r 4cc7f42f94c1 MODSERIAL.lib --- a/MODSERIAL.lib Fri Aug 22 12:43:55 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/edodm85/code/MODSERIAL/#4213f9a7c3ad
diff -r acd907fbcbae -r 4cc7f42f94c1 TextLCD.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Fri May 25 19:57:58 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r acd907fbcbae -r 4cc7f42f94c1 main.cpp --- 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); - } -} - - - - + +
diff -r acd907fbcbae -r 4cc7f42f94c1 main.h --- a/main.h Fri Aug 22 12:43:55 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,19 +0,0 @@ -#pragma once -#include "mbed.h" -#include "MODSERIAL.h" - -MODSERIAL pc(USBTX,USBRX); - -#if defined(TARGET_LPC1768) -MODSERIAL gps(p13, p14); -#elif defined(TARGET_LPC4330_M4) -MODSERIAL gps(UART0_TX, UART0_RX); -#endif - - -char cDataBuffer[500]; -int i = 0; - - -void Init(); -void parse(char *cmd, int n);
diff -r acd907fbcbae -r 4cc7f42f94c1 mbed-src.lib --- a/mbed-src.lib Fri Aug 22 12:43:55 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/mbed-src/#ec1b66a3d094
diff -r acd907fbcbae -r 4cc7f42f94c1 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Fri May 25 19:57:58 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/5aab5a7997ee \ No newline at end of file