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/>.
35 def parse_nmea_string(self, string):
37 string = string.lstrip('$')
38 (data, dummy, csum) = string.rpartition('*')
44 if mycsum != int(csum, 16): # can throw with invalid csum
47 data = data.split(',')
49 if data[0] == 'GPGGA':
53 (temp, n) = re.subn('^(\d{2})(\d{2})(\d{2}\.\d+)$', '\\1:\\2:\\3', data[1])
58 (temp, n) = re.subn('^(\d{2})(\d{2})\.(.*)$', '\\1.\\2\\3', data[2])
60 self.lat = temp + data[3]
63 (temp, n) = re.subn('^0?(\d{2,3}?)(\d{2})\.(.*)$', '\\1.\\2\\3', data[4])
65 self.lon = temp + data[5]
70 elif int(data[6]) == 1:
71 self.quality = "normal"
72 elif int(data[6]) == 2:
74 elif int(data[6]) == 3:
75 self.quality = "precision"
80 self.nsat = int(data[7])
87 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)