Skip to content

Commit

Permalink
[FEATURE] Add option to export gps log
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanW2 committed Mar 8, 2018
1 parent b0952cc commit 360bb4c
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/roam/api/gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ def safe_int(value):
except (TypeError, ValueError):
return 0

GPSLOGFILENAME = config.get("gpslogfile", None)
GPSLOGGING = not GPSLOGFILENAME is None


class GPSService(QObject):
gpsfixed = pyqtSignal(bool, object)
Expand All @@ -54,6 +57,21 @@ def __init__(self):
self.waypoint = None
self._gpsupdate_frequency = 1.0
self._gpsupdate_last = datetime.min
self.gpslogfile = None

def __del__(self):
if not self.gpslogfile is None:
self.gpslogfile.close()

def log_gps(self, line):
if not GPSLOGGING:
# No logging for you.
return

if self.gpslogfile is None:
self.gpslogfile = open(GPSLOGFILENAME, "w")

self.gpslogfile.write(line)

def gpsinfo(self, attribute):
"""
Expand Down Expand Up @@ -115,6 +133,7 @@ def _gpsfound(self, gpsConnection):
QgsGPSConnectionRegistry.instance().registerConnection(self.gpsConn)

def parse_data(self, datastring):
self.log_gps(datastring)
try:
data = pynmea2.parse(datastring)
except AttributeError as er:
Expand Down

0 comments on commit 360bb4c

Please sign in to comment.