-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgpgsv.py
105 lines (88 loc) · 3.11 KB
/
gpgsv.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/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/>.
#
class GPGSVSatellite(object):
def __init__(self, prn, elevation, azimuth, snr):
# Satellite ID
self.prn_id = prn
# Elevation, in degrees, 90° maximum
self.elevation = elevation
# Azimuth, degrees from True North, 000° through 359°
self.azimuth = azimuth
# Signal to Noise Ratio, 00 through 99 dB (null when not tracking)
self.snr = snr
def isTracking(self):
return self.elevation != 0 and self.azimuth != 0 and self.snr != 0
def getPrnId(self):
return self.prn_id
def getElevation(self):
return self.elevation
def getAzimuth(self):
return self.azimuth
def getSnr(self):
return self.snr
class GPGSVMessage(object):
def __init__(self):
self.current = -1
self.numberOfMessages = 0
self.satellites = []
def __iter__(self):
return self
def next(self):
self.current += 1
if self.current >= len(self.satellites):
self.current = -1
raise StopIteration
else:
return self.satellites[self.current]
def reset(self):
self.satellites = []
def newSatellite(self, prn, elevation, azimuth, srn):
gpgsvSatellite = GPGSVSatellite(prn, elevation, azimuth, srn)
self.satellites.append(gpgsvSatellite)
class GPGSVCollector(object):
def __init__(self):
self.messages = []
def cleanMessages(self):
self.messages = []
def addMessage(self, msg):
self.messages.append(msg)
def isComplete(self):
if len(self.messages) == 0:
return False
expectedMessages = self._getNumberExpectedMessages(self.messages[0])
if len(self.messages) >= expectedMessages:
return True
def getGPGSVMessage(self):
gpgsvMessage = GPGSVMessage()
for msg in self.messages:
msg = msg.split('*')[0]
sat = []
for dat in msg.split(',')[4:]:
try:
sat.append(int(dat))
except ValueError:
sat.append(0)
if len(sat) == 4:
gpgsvMessage.newSatellite(sat[0], sat[1], sat[2], sat[3])
sat = []
self.cleanMessages()
return gpgsvMessage
def _getNumberExpectedMessages(self, msg):
return int(msg.split(',')[1])