Dependencies:   mbed

Committer:
pd0wm
Date:
Tue Sep 27 19:46:30 2011 +0000
Revision:
0:bec310bde899

        

Who changed what in which revision?

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