Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: FreePilot PinDetect mbed-src
Fork of FreePilot_V2-2 by
Diff: gps.h
- Revision:
- 48:5d9c63364c94
- Parent:
- 47:d3123bb4f673
- Child:
- 50:07dfcda65732
--- a/gps.h Sat Mar 14 01:28:37 2015 +0000 +++ b/gps.h Sat Mar 14 01:56:28 2015 +0000 @@ -3,11 +3,44 @@ #define norm(v) sqrt(dot(v,v)) // norm = length of vector #define d(u,v) norm(point_sub(u,v)) // distance = norm of difference +//gga: int num_of_gps_sats; double decimal_latitude; int gps_satellite_quality; double decimal_lon; +Point position; +//rmc: +Point old_position; +int day; +int hour; +int minute; +int second; +int tenths; +int hundreths; +char status; +double track; // track made good . angle +char magvar_dir; +double magvar; +int year; +int month; +double speed_km = 0; +double speed_m_s = 0; +double velocity; // speed in knot +char *time_s = (char *)NULL; +char *date = (char *)NULL; +char *stat = (char *)NULL; +char *vel = (char *)NULL; +char *trk = (char *)NULL; +char *magv = (char *)NULL; +char *magd = (char *)NULL; +char *latit = ""; +char *longit = ""; +char *latitude_s = (char *)NULL; +char *longitude_s = (char *)NULL; +char *lat_dir = (char *)NULL; +char *lon_dir = (char *)NULL; + Point point_add(Point a, Point b) { return Point(a.GetX() + b.GetX(), a.GetY() + b.GetY()); @@ -173,4 +206,88 @@ ydist = sinr * distance; lat2 = lat1 + (ydist / (69.09 * -1609.344)); lon2 = lon1 - (xdist / (69.09 * 1609.344 * cos(lat1/57.295779513))); +} + +bool nmea_rmc(char *s) +{ + char *token; + int token_counter = 0; + time_s = (char *)NULL; + date = (char *)NULL; + stat = (char *)NULL; + vel = (char *)NULL; + trk = (char *)NULL; + magv = (char *)NULL; + magd = (char *)NULL; + latit = ""; + longit = ""; + latitude_s = (char *)NULL; + longitude_s = (char *)NULL; + lat_dir = (char *)NULL; + lon_dir = (char *)NULL; + while ((token = strsep(&s, ",")) != NULL) { + switch (token_counter) { + case 1: + time_s = token; + break; + case 2: + stat = token; + break; + case 3: + if ( token ) { + latit = token; + latitude_s = token; + } + break; + case 4: + lat_dir = token; + break; + case 5: + longit = token; + longitude_s = token; + break; + case 6: + lon_dir = token; + break; + case 7: + vel = token; + break; + case 8: + trk = token; + break; + case 9: + date = token; + break; + case 10: + magv = token; + break; + case 11: + magd = token; + break; + } + token_counter++; + } + if (stat!= '\0' && date!= '\0' && time_s!= '\0') { + hour = (char)((time_s[0] - '0') * 10) + (time_s[1] - '0'); + minute = (char)((time_s[2] - '0') * 10) + (time_s[3] - '0'); + second = (char)((time_s[4] - '0') * 10) + (time_s[5] - '0'); + day = (char)((date[0] - '0') * 10) + (date[1] - '0'); + month = (char)((date[2] - '0') * 10) + (date[3] - '0'); + year = (int)((date[4] - '0') * 10) + (date[5] - '0') + 2000; + status = stat[0]; + velocity = atof(vel); + speed_km = velocity * 1.852; + speed_m_s = speed_km * 3600.0 / 1000.0; + track = atof(trk); + magvar = atof(magv); + return true; + } + if ( longit != '\0' && latit != '\0' ) { + old_position = position; + position.SetX(lat_to_deg(latitude_s, lat_dir[0])); + position.SetY(lon_to_deg(longitude_s, lon_dir[0])); + return true; + } else { + return false; + } } \ No newline at end of file