Allows for a GPS module to be connected to a serial port and exposes an easy to use API to get the GPS data.

Fork of MODGPS by Andy K

Committer:
xanter
Date:
Sat Sep 29 20:31:31 2018 +0000
Revision:
7:049436bc2225
Parent:
3:28a1b60b0f37
Fixed compiler errors/warnings; Removed hardcode for LPC17xx

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AjK 2:8aa059e7d8b1 1 /*
AjK 2:8aa059e7d8b1 2 Copyright (c) 2010 Andy Kirkham
AjK 2:8aa059e7d8b1 3
AjK 2:8aa059e7d8b1 4 Permission is hereby granted, free of charge, to any person obtaining a copy
AjK 2:8aa059e7d8b1 5 of this software and associated documentation files (the "Software"), to deal
AjK 2:8aa059e7d8b1 6 in the Software without restriction, including without limitation the rights
AjK 2:8aa059e7d8b1 7 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
AjK 2:8aa059e7d8b1 8 copies of the Software, and to permit persons to whom the Software is
AjK 2:8aa059e7d8b1 9 furnished to do so, subject to the following conditions:
AjK 2:8aa059e7d8b1 10
AjK 2:8aa059e7d8b1 11 The above copyright notice and this permission notice shall be included in
AjK 2:8aa059e7d8b1 12 all copies or substantial portions of the Software.
AjK 2:8aa059e7d8b1 13
AjK 2:8aa059e7d8b1 14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
AjK 2:8aa059e7d8b1 15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
AjK 2:8aa059e7d8b1 16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AjK 2:8aa059e7d8b1 17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
AjK 2:8aa059e7d8b1 18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
AjK 2:8aa059e7d8b1 19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
AjK 2:8aa059e7d8b1 20 THE SOFTWARE.
AjK 2:8aa059e7d8b1 21 */
AjK 2:8aa059e7d8b1 22
AjK 2:8aa059e7d8b1 23 #include "GPS_VTG.h"
AjK 3:28a1b60b0f37 24 #include <math.h>
AjK 2:8aa059e7d8b1 25
AjK 2:8aa059e7d8b1 26 GPS_VTG::GPS_VTG()
AjK 2:8aa059e7d8b1 27 {
AjK 2:8aa059e7d8b1 28 _velocity_knots = 0;
AjK 2:8aa059e7d8b1 29 _velocity_kph = 0;
AjK 2:8aa059e7d8b1 30 _track_true = 0;
AjK 2:8aa059e7d8b1 31 _track_mag = 0;
AjK 2:8aa059e7d8b1 32 }
AjK 2:8aa059e7d8b1 33
AjK 2:8aa059e7d8b1 34 GPS_VTG *
AjK 2:8aa059e7d8b1 35 GPS_VTG::vtg(GPS_VTG *n)
AjK 2:8aa059e7d8b1 36 {
AjK 2:8aa059e7d8b1 37 if (n == NULL) n = new GPS_VTG;
AjK 2:8aa059e7d8b1 38
AjK 3:28a1b60b0f37 39 n->_velocity_knots = _velocity_knots;
AjK 3:28a1b60b0f37 40 n->_velocity_kph = _velocity_kph;
AjK 3:28a1b60b0f37 41 n->_track_true = _track_true;
AjK 3:28a1b60b0f37 42 n->_track_mag = _track_mag;
AjK 3:28a1b60b0f37 43
AjK 2:8aa059e7d8b1 44 return n;
AjK 2:8aa059e7d8b1 45 }
AjK 2:8aa059e7d8b1 46
AjK 2:8aa059e7d8b1 47 void
AjK 2:8aa059e7d8b1 48 GPS_VTG::nmea_vtg(char *s)
AjK 2:8aa059e7d8b1 49 {
AjK 2:8aa059e7d8b1 50 char *token;
AjK 2:8aa059e7d8b1 51 int token_counter = 0;
AjK 2:8aa059e7d8b1 52 char *vel_knots = (char *)NULL;
AjK 2:8aa059e7d8b1 53 char *vel_kph = (char *)NULL;
AjK 2:8aa059e7d8b1 54 char *trk_t = (char *)NULL;
AjK 2:8aa059e7d8b1 55 char *trk_m = (char *)NULL;
AjK 2:8aa059e7d8b1 56
AjK 2:8aa059e7d8b1 57 token = strtok(s, ",");
AjK 2:8aa059e7d8b1 58 while (token) {
AjK 2:8aa059e7d8b1 59 switch (token_counter) {
AjK 2:8aa059e7d8b1 60 case 5: vel_knots = token; break;
AjK 2:8aa059e7d8b1 61 case 7: vel_kph = token; break;
AjK 2:8aa059e7d8b1 62 case 1: trk_t = token; break;
AjK 2:8aa059e7d8b1 63 case 3: trk_m = token; break;
AjK 2:8aa059e7d8b1 64 }
AjK 2:8aa059e7d8b1 65 token = strtok((char *)NULL, ",");
AjK 2:8aa059e7d8b1 66 token_counter++;
AjK 2:8aa059e7d8b1 67 }
AjK 2:8aa059e7d8b1 68
AjK 3:28a1b60b0f37 69 if (trk_t) { _track_true = atof(trk_t); }
AjK 3:28a1b60b0f37 70 if (trk_m) { _track_mag = atof(trk_m); }
AjK 2:8aa059e7d8b1 71 if (vel_knots) { _velocity_knots = atof(vel_knots); }
AjK 3:28a1b60b0f37 72 if (vel_kph) { _velocity_kph = atof(vel_kph); }
AjK 2:8aa059e7d8b1 73 }
AjK 2:8aa059e7d8b1 74