kopia lustrzana https://github.com/inmcm/micropyGPS
Ensure GGA sentence parses cleanly before updating any object data
Add active sentence checks to update()pull/4/head
rodzic
4c8bc4218b
commit
a21c1d69d8
|
@ -170,38 +170,34 @@ class MicropyGPS(object):
|
||||||
"""Parse Global Positioning System Fix Data (GGA) Sentence. Updates UTC timestamp, latitude, longitude,
|
"""Parse Global Positioning System Fix Data (GGA) Sentence. Updates UTC timestamp, latitude, longitude,
|
||||||
fix status, satellites in use, Horizontal Dilution of Precision (HDOP), altitude, and geoid height"""
|
fix status, satellites in use, Horizontal Dilution of Precision (HDOP), altitude, and geoid height"""
|
||||||
|
|
||||||
# UTC Timestamp
|
|
||||||
try:
|
try:
|
||||||
|
# UTC Timestamp
|
||||||
utc_string = self.gps_segments[1]
|
utc_string = self.gps_segments[1]
|
||||||
|
|
||||||
# Skip timestamp if receiver doesn't have on yet
|
# Skip timestamp if receiver doesn't have on yet
|
||||||
if utc_string:
|
if utc_string:
|
||||||
hours = int(utc_string[0:2]) + self.local_offset
|
hours = int(utc_string[0:2]) + self.local_offset
|
||||||
minutes = int(utc_string[2:4])
|
minutes = int(utc_string[2:4])
|
||||||
seconds = float(utc_string[4:])
|
seconds = float(utc_string[4:])
|
||||||
self.timestamp = (hours, minutes, seconds)
|
else:
|
||||||
except ValueError:
|
hours = 0
|
||||||
return False
|
minutes = 0
|
||||||
|
seconds = 0.0
|
||||||
|
|
||||||
# Number of Satellites in Use
|
# Number of Satellites in Use
|
||||||
try:
|
satellites_in_use = int(self.gps_segments[7])
|
||||||
self.satellites_in_use = int(self.gps_segments[7])
|
|
||||||
except ValueError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
# Horizontal Dilution of Precision
|
# Horizontal Dilution of Precision
|
||||||
try:
|
hdop = float(self.gps_segments[8])
|
||||||
self.hdop = float(self.gps_segments[8])
|
|
||||||
except ValueError:
|
# Get Fix Status
|
||||||
return False
|
fix_stat = int(self.gps_segments[6])
|
||||||
|
|
||||||
# Get Fix Status
|
|
||||||
try:
|
|
||||||
self.fix_stat = int(self.gps_segments[6])
|
|
||||||
except ValueError:
|
except ValueError:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
# Process Location and Speed Data if Fix is GOOD
|
# Process Location and Speed Data if Fix is GOOD
|
||||||
if self.fix_stat:
|
if fix_stat:
|
||||||
|
|
||||||
# Longitude / Latitude
|
# Longitude / Latitude
|
||||||
try:
|
try:
|
||||||
|
@ -238,6 +234,12 @@ class MicropyGPS(object):
|
||||||
self.altitude = altitude
|
self.altitude = altitude
|
||||||
self.geoid_height = geoid_height
|
self.geoid_height = geoid_height
|
||||||
|
|
||||||
|
# Update Object Data
|
||||||
|
self.timestamp = (hours, minutes, seconds)
|
||||||
|
self.satellites_in_use = satellites_in_use
|
||||||
|
self.hdop = hdop
|
||||||
|
self.fix_stat = fix_stat
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def gpgsa(self):
|
def gpgsa(self):
|
||||||
|
@ -359,7 +361,7 @@ class MicropyGPS(object):
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# Check if sentence is ending (*)
|
# Check if sentence is ending (*)
|
||||||
elif new_char == '*':
|
elif new_char == '*' and self.sentence_active:
|
||||||
self.process_crc = False
|
self.process_crc = False
|
||||||
self.active_segment += 1
|
self.active_segment += 1
|
||||||
self.gps_segments.append('')
|
self.gps_segments.append('')
|
||||||
|
@ -367,7 +369,7 @@ class MicropyGPS(object):
|
||||||
|
|
||||||
# Check if a section is ended (,), Create a new substring to feed
|
# Check if a section is ended (,), Create a new substring to feed
|
||||||
# characters to
|
# characters to
|
||||||
elif new_char == ',':
|
elif new_char == ',' and self.sentence_active:
|
||||||
self.active_segment += 1
|
self.active_segment += 1
|
||||||
self.gps_segments.append('')
|
self.gps_segments.append('')
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue