-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpvtg.py
61 lines (54 loc) · 2.15 KB
/
gpvtg.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
#
# This file is part of Camino.
# Copyright (C) 2017 Manuel Luitz <[email protected]>
#
# Camino is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Camino is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Camino. If not, see <http://www.gnu.org/licenses/>.
#
# $GPVTG,054.7,T,034.4,M,005.5,N,010.2,K*48
class GPVTGMessage(object):
def __init__(self):
# hhmmss.ss = UTC of position
self.track_made_good = "0.0"
self.degrees_true = "T"
self.track_magnetic = "0.0"
self.degrees_magnetic = "M"
self.speed_over_ground_knots = "0.0"
self.speed_over_ground_knots_unit = "N"
# Fixed text "K" (knots)
self.speed_over_ground_kmh = "0.0"
# Fixed text "K" (km/h)
self.speed_over_ground_kmh_unit = "K"
def parseGPVTGMessage(self, msg):
msg = msg.split('*')[0].split(',')
self.track_made_good = msg[1]
self.degrees_true = msg[2]
self.track_magnetic = msg[3]
self.degrees_magnetic = msg[4]
self.speed_over_ground_knots = msg[5]
self.speed_over_ground_knots_unit = msg[6]
self.speed_over_ground_kmh = msg[7]
self.speed_over_ground_kmh_unit = msg[8]
def formatSpeedOverGroundKmh(self):
try:
return u"{sog:} km/h".format(sog=float(self.speed_over_ground_kmh))
except:
return u"0.0 km/h"
def formatSpeedOverGroundKnots(self):
return u"{sog:} knots".format(sog=float(self.speed_over_ground_knots))
def getSpeedOverGroundStringMetric(self):
return self.formatSpeedOverGroundKmh()
def getSpeedOverGroundStringImperial(self):
return self.formatSpeedOverGroundKnots()