Allows for a GPS module to be connected to a serial port and exposes an easy to use API to get the GPS data. New feature, added Mbed/LPC17xx RTC synchronisation
Fork of MODGPS by
Diff: GPS_VTG.cpp
- Revision:
- 2:8aa059e7d8b1
- Child:
- 3:28a1b60b0f37
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/GPS_VTG.cpp Fri Apr 15 12:23:52 2011 +0000 @@ -0,0 +1,72 @@ +/* + Copyright (c) 2010 Andy Kirkham + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + THE SOFTWARE. +*/ + +#include "GPS_VTG.h" + +GPS_VTG::GPS_VTG() +{ + _velocity_knots = 0; + _velocity_kph = 0; + _track_true = 0; + _track_mag = 0; +} + +GPS_VTG * +GPS_VTG::vtg(GPS_VTG *n) +{ + if (n == NULL) n = new GPS_VTG; + + do { + memcpy(n, this, sizeof(GPS_VTG)); + } + while (memcmp(n, this, sizeof(GPS_VTG))); + return n; +} + +void +GPS_VTG::nmea_vtg(char *s) +{ + char *token; + int token_counter = 0; + char *vel_knots = (char *)NULL; + char *vel_kph = (char *)NULL; + char *trk_t = (char *)NULL; + char *trk_m = (char *)NULL; + + token = strtok(s, ","); + while (token) { + switch (token_counter) { + case 5: vel_knots = token; break; + case 7: vel_kph = token; break; + case 1: trk_t = token; break; + case 3: trk_m = token; break; + } + token = strtok((char *)NULL, ","); + token_counter++; + } + + if (vel_knots) { _velocity_knots = atof(vel_knots); } + if (vel_kph) { _velocity_kph = atof(vel_kph); } + if (trk_t) { _track_true = atof(trk_t); } + if (trk_m) { _track_mag = atof(trk_m); } +} +