3 # Copyright (C) 2010 Dmitry Marakasov
5 # This file is part of UberLogger.
7 # UberLogger is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # UberLogger is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with UberLogger. If not, see <http://www.gnu.org/licenses/>.
36 def parse_nmea_string(self, string):
38 string = string.lstrip('$')
39 (data, dummy, csum) = string.rpartition('*')
45 if mycsum != int(csum, 16): # can throw with invalid csum
48 data = data.split(',')
50 if data[0] == 'GPGGA':
54 (temp, n) = re.subn('^(\d{2})(\d{2})(\d{2}\.\d+)$', '\\1:\\2:\\3', data[1])
59 (temp, n) = re.subn('^(\d{2})(\d{2})\.(.*)$', '\\1.\\2\\3', data[2])
61 self.lat = temp + data[3]
64 (temp, n) = re.subn('^0?(\d{2,3}?)(\d{2})\.(.*)$', '\\1.\\2\\3', data[4])
66 self.lon = temp + data[5]
71 elif int(data[6]) == 1:
72 self.quality = "normal"
73 elif int(data[6]) == 2:
75 elif int(data[6]) == 3:
76 self.quality = "precision"
81 self.nsat = int(data[7])
88 return "Time: %s\tQuality: %s\nLat: %s\tSat: %s\nLon: %s\tHDOP: %s\nEle: %s" % (self.time, self.quality, self.lat, self.nsat, self.lon, self.hdop, self.ele)