-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpgga.py
89 lines (81 loc) · 3.32 KB
/
gpgga.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/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/>.
#
# $GPGGA,214551.00,4810.28564,N,01138.16720,E,1,06,5.16,537.4,M,46.2,M,,*52
class GPGGAMessage(object):
def __init__(self):
# hhmmss.ss = UTC of position
self.utc = "000000.00"
self.latitude = "0000.00000"
self.latitudeDirection = "N"
self.longitude = "00000.00000"
self.longitudeDirection = "W"
# GPS Quality indicator (0=no fix, 1=GPS fix, 2=Dif. GPS fix)
self.fixQuality = 0
self.numberOfSatellites = 0
# Horizontal Dilution of Precision (HDOP)
self.hdop = 0.0
# Altitude
self.altitude = 0.0
self.altitudeUnit = "M"
# Height of geoid above WGS84 ellipsoid
self.geoidSeparation = 0.0
self.geoidUnit = "M"
# Age of Differential GPS data (seconds)
self.dgpsAge = 0
# Differential reference station ID
self.dgpsRefStationId = 0
def parseGPGGAMessage(self, msg):
msg = msg.split('*')[0].split(',')
self.utc = msg[1]
self.latitude = msg[2]
self.latitudeDirection = msg[3]
self.longitude = msg[4]
self.longitudeDirection = msg[5]
self.fixQuality = int(msg[6])
self.numberOfSatellites = int(msg[7])
self.hdop = float(msg[8])
self.altitude = msg[9]
self.altitudeUnit = msg[10]
self.geoidSeparation = msg[11]
self.geoidUnit = msg[12]
self.dgpsAge = msg[13]
self.dgpsRefStationId = msg[14]
def hasFix(self):
return self.fixQuality == 1 or self.fixQuality == 2
def formatLatLong(self, degree, minute, direction):
try:
return u"{degree:}°{minute:}'{second:}''{direction:s}".format(degree=int(degree),
minute=int(float(minute)),
second=int(round(float(minute) % 1 * 60)),
direction=direction)
except:
return ''
def getLongitudeString(self):
return self.formatLatLong(self.longitude[0:3],
self.longitude[3:],
self.longitudeDirection)
def getLatitudeString(self):
return self.formatLatLong(self.latitude[0:2],
self.latitude[2:],
self.latitudeDirection)
def getPositionString(self):
return self.getLatitudeString() + " " + self.getLongitudeString()
def getAltitudeString(self):
return str(self.altitude) + str(self.altitudeUnit)