Yu Hui Wee
/
GPS_Test
target board c027
Fork of C027_GPSTransparentSerial by
Revision 4:dc72072eb8d0, committed 2016-09-02
- Comitter:
- Ulhingl
- Date:
- Fri Sep 02 04:31:51 2016 +0000
- Parent:
- 3:e8792e374579
- Commit message:
- target board c027
Changed in this revision
--- a/main.cpp Thu Jun 12 07:29:20 2014 +0000 +++ b/main.cpp Fri Sep 02 04:31:51 2016 +0000 @@ -5,6 +5,8 @@ #error "This example is targeted for the C027 platform" #endif +#include "main.h" + /* This example is establishing a transparent link between the mbed serial port and the serial communication interface of the GPS. @@ -16,26 +18,85 @@ C027_Support Example http://mbed.org/teams/ublox/code/C027_SupportTest/ */ + + int main() { c027_gps_powerOn(); - int baud = GPSBAUD; - - // open the gps serial port - Serial gps(GPSTXD, GPSRXD); gps.baud(baud); - - // open the PC serial port and (use the same baudrate) - Serial pc(USBTX, USBRX); pc.baud(baud); + + char c; + int n = 1500; + char cDataBuffer[n]; + int i = 0; + char s[4] = "\n\r"; while (1) { - // transfer data from pc to gps - if (pc.readable() && gps.writeable()) - gps.putc(pc.getc()); - // transfer data from gps to pc - if (gps.readable() && pc.writeable()) - pc.putc(gps.getc()); + + if (gps.readable()) + { + c = gps.getc(); + if (c == '$') + { + while (i < n) + { + cDataBuffer[i] = c; + c = gps.getc(); + i = i + 1; + } + i = 0; + char * output = strtok(cDataBuffer, s); +// printf( "%s ", output ); + parse(output, sizeof(output)); +// pc.printf("%d\n\r", strncmp(output,"$GNGLL",6)); + while( output != NULL ) + { + output = strtok(NULL, s); +// printf( "%s ", output); + parse(output, sizeof(output)); +// pc.printf("%d\n\r", strncmp(output,"$GNGLL",6)); + + } + } + } } } + +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,"$GNGGA", 6) == 0) + { + sscanf(cmd, "$GNGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude); + pc.printf("GNGGA Fix taken at: %f, Latitude: %f %c, Longitude: %f %c, Fix quality: %d, Number of sat: %d, Altitude: %f M\n\r", timefix, latitude, ns, longitude, ew, fq, nst, altitude); + } + + // Satellite status + if(strncmp(cmd,"$GNGSA", 6) == 0) + { + sscanf(cmd, "$GNGSA,%c,%d,%d", &tf, &fix, &nst); + pc.printf("GNGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n\r", tf, fix, nst); + } + + // Geographic position, Latitude and Longitude + if(strncmp(cmd,"$GNGLL", 6) == 0) + { + sscanf(cmd, "$GNGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix); + pc.printf("GNGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n\r", latitude, ns, longitude, ew, timefix); + } + + // Geographic position, Latitude and Longitude + if(strncmp(cmd,"$GNRMC", 6) == 0) + { + sscanf(cmd, "$GNRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date); + pc.printf("GNRMC Fix taken at: %f, Status: %c, Latitude: %f %c, Longitude: %f %c, Speed: %f, Date: %d\n\r", timefix, status, latitude, ns, longitude, ew, speed, date); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.h Fri Sep 02 04:31:51 2016 +0000 @@ -0,0 +1,11 @@ +#include "mbed.h" + +int baud = GPSBAUD; + +// open the gps serial port +Serial gps(GPSTXD, GPSRXD); + +// open the PC serial port and (use the same baudrate) +Serial pc(USBTX, USBRX); + +void parse(char *cmd, int n); \ No newline at end of file
--- a/mbed.bld Thu Jun 12 07:29:20 2014 +0000 +++ b/mbed.bld Fri Sep 02 04:31:51 2016 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/024bf7f99721 \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/2241e3a39974 \ No newline at end of file