target board c027

Dependencies:   mbed

Fork of C027_GPSTransparentSerial by u-blox

Committer:
Ulhingl
Date:
Fri Sep 02 04:31:51 2016 +0000
Revision:
4:dc72072eb8d0
Parent:
3:e8792e374579
target board c027

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mazgch 0:7f124c0a351a 1 #include "mbed.h"
mazgch 3:e8792e374579 2 #ifdef TARGET_UBLOX_C027
mazgch 3:e8792e374579 3 #include "C027_api.h"
mazgch 3:e8792e374579 4 #else
mazgch 3:e8792e374579 5 #error "This example is targeted for the C027 platform"
mazgch 3:e8792e374579 6 #endif
mazgch 0:7f124c0a351a 7
Ulhingl 4:dc72072eb8d0 8 #include "main.h"
Ulhingl 4:dc72072eb8d0 9
mazgch 3:e8792e374579 10 /* This example is establishing a transparent link between
mazgch 3:e8792e374579 11 the mbed serial port and the serial communication interface
mazgch 3:e8792e374579 12 of the GPS.
mazgch 3:e8792e374579 13
mazgch 3:e8792e374579 14 For a more advanced driver for the GPS or Modem(MDM) please
mazgch 3:e8792e374579 15 look at the follwing library and example:
mazgch 3:e8792e374579 16 C027_Support Library
mazgch 3:e8792e374579 17 http://mbed.org/teams/ublox/code/C027_Support/
mazgch 3:e8792e374579 18 C027_Support Example
mazgch 3:e8792e374579 19 http://mbed.org/teams/ublox/code/C027_SupportTest/
mazgch 3:e8792e374579 20 */
Ulhingl 4:dc72072eb8d0 21
Ulhingl 4:dc72072eb8d0 22
mazgch 0:7f124c0a351a 23 int main()
mazgch 0:7f124c0a351a 24 {
mazgch 3:e8792e374579 25 c027_gps_powerOn();
mazgch 2:490b4b087576 26 gps.baud(baud);
mazgch 2:490b4b087576 27 pc.baud(baud);
Ulhingl 4:dc72072eb8d0 28
Ulhingl 4:dc72072eb8d0 29 char c;
Ulhingl 4:dc72072eb8d0 30 int n = 1500;
Ulhingl 4:dc72072eb8d0 31 char cDataBuffer[n];
Ulhingl 4:dc72072eb8d0 32 int i = 0;
Ulhingl 4:dc72072eb8d0 33 char s[4] = "\n\r";
mazgch 0:7f124c0a351a 34
mazgch 0:7f124c0a351a 35 while (1)
mazgch 0:7f124c0a351a 36 {
Ulhingl 4:dc72072eb8d0 37
Ulhingl 4:dc72072eb8d0 38 if (gps.readable())
Ulhingl 4:dc72072eb8d0 39 {
Ulhingl 4:dc72072eb8d0 40 c = gps.getc();
Ulhingl 4:dc72072eb8d0 41 if (c == '$')
Ulhingl 4:dc72072eb8d0 42 {
Ulhingl 4:dc72072eb8d0 43 while (i < n)
Ulhingl 4:dc72072eb8d0 44 {
Ulhingl 4:dc72072eb8d0 45 cDataBuffer[i] = c;
Ulhingl 4:dc72072eb8d0 46 c = gps.getc();
Ulhingl 4:dc72072eb8d0 47 i = i + 1;
Ulhingl 4:dc72072eb8d0 48 }
Ulhingl 4:dc72072eb8d0 49 i = 0;
Ulhingl 4:dc72072eb8d0 50 char * output = strtok(cDataBuffer, s);
Ulhingl 4:dc72072eb8d0 51 // printf( "%s ", output );
Ulhingl 4:dc72072eb8d0 52 parse(output, sizeof(output));
Ulhingl 4:dc72072eb8d0 53 // pc.printf("%d\n\r", strncmp(output,"$GNGLL",6));
Ulhingl 4:dc72072eb8d0 54 while( output != NULL )
Ulhingl 4:dc72072eb8d0 55 {
Ulhingl 4:dc72072eb8d0 56 output = strtok(NULL, s);
Ulhingl 4:dc72072eb8d0 57 // printf( "%s ", output);
Ulhingl 4:dc72072eb8d0 58 parse(output, sizeof(output));
Ulhingl 4:dc72072eb8d0 59 // pc.printf("%d\n\r", strncmp(output,"$GNGLL",6));
Ulhingl 4:dc72072eb8d0 60
Ulhingl 4:dc72072eb8d0 61 }
Ulhingl 4:dc72072eb8d0 62 }
Ulhingl 4:dc72072eb8d0 63 }
mazgch 0:7f124c0a351a 64 }
mazgch 0:7f124c0a351a 65 }
Ulhingl 4:dc72072eb8d0 66
Ulhingl 4:dc72072eb8d0 67 void parse(char *cmd, int n)
Ulhingl 4:dc72072eb8d0 68 {
Ulhingl 4:dc72072eb8d0 69
Ulhingl 4:dc72072eb8d0 70 char ns, ew, tf, status;
Ulhingl 4:dc72072eb8d0 71 int fq, nst, fix, date; // fix quality, Number of satellites being tracked, 3D fix
Ulhingl 4:dc72072eb8d0 72 float latitude, longitude, timefix, speed, altitude;
Ulhingl 4:dc72072eb8d0 73
Ulhingl 4:dc72072eb8d0 74
Ulhingl 4:dc72072eb8d0 75 // Global Positioning System Fix Data
Ulhingl 4:dc72072eb8d0 76 if(strncmp(cmd,"$GNGGA", 6) == 0)
Ulhingl 4:dc72072eb8d0 77 {
Ulhingl 4:dc72072eb8d0 78 sscanf(cmd, "$GNGGA,%f,%f,%c,%f,%c,%d,%d,%*f,%f", &timefix, &latitude, &ns, &longitude, &ew, &fq, &nst, &altitude);
Ulhingl 4:dc72072eb8d0 79 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);
Ulhingl 4:dc72072eb8d0 80 }
Ulhingl 4:dc72072eb8d0 81
Ulhingl 4:dc72072eb8d0 82 // Satellite status
Ulhingl 4:dc72072eb8d0 83 if(strncmp(cmd,"$GNGSA", 6) == 0)
Ulhingl 4:dc72072eb8d0 84 {
Ulhingl 4:dc72072eb8d0 85 sscanf(cmd, "$GNGSA,%c,%d,%d", &tf, &fix, &nst);
Ulhingl 4:dc72072eb8d0 86 pc.printf("GNGSA Type fix: %c, 3D fix: %d, number of sat: %d\r\n\r", tf, fix, nst);
Ulhingl 4:dc72072eb8d0 87 }
Ulhingl 4:dc72072eb8d0 88
Ulhingl 4:dc72072eb8d0 89 // Geographic position, Latitude and Longitude
Ulhingl 4:dc72072eb8d0 90 if(strncmp(cmd,"$GNGLL", 6) == 0)
Ulhingl 4:dc72072eb8d0 91 {
Ulhingl 4:dc72072eb8d0 92 sscanf(cmd, "$GNGLL,%f,%c,%f,%c,%f", &latitude, &ns, &longitude, &ew, &timefix);
Ulhingl 4:dc72072eb8d0 93 pc.printf("GNGLL Latitude: %f %c, Longitude: %f %c, Fix taken at: %f\n\r", latitude, ns, longitude, ew, timefix);
Ulhingl 4:dc72072eb8d0 94 }
Ulhingl 4:dc72072eb8d0 95
Ulhingl 4:dc72072eb8d0 96 // Geographic position, Latitude and Longitude
Ulhingl 4:dc72072eb8d0 97 if(strncmp(cmd,"$GNRMC", 6) == 0)
Ulhingl 4:dc72072eb8d0 98 {
Ulhingl 4:dc72072eb8d0 99 sscanf(cmd, "$GNRMC,%f,%c,%f,%c,%f,%c,%f,,%d", &timefix, &status, &latitude, &ns, &longitude, &ew, &speed, &date);
Ulhingl 4:dc72072eb8d0 100 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);
Ulhingl 4:dc72072eb8d0 101 }
Ulhingl 4:dc72072eb8d0 102 }