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