gpsd-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gpsd-dev] [PATCH 1/2] gpsprof: fix replot


From: Robin H. Johnson
Subject: [gpsd-dev] [PATCH 1/2] gpsprof: fix replot
Date: Sun, 28 May 2017 13:51:30 -0700

gpsprof's replot functionality feeds JSON back to a session, but relies
on the oldstyle keydict to read fields out for analysis.

Refactor gps.gps.read() to have common code for handling JSON input &
using the shim-setter, then wire gpsprof to feed JSON into the new
function.

For any JSON errors detected, print a useful message and continue
instead of aborting.

Signed-off-by: Robin H. Johnson <address@hidden>
---
 gps/gps.py | 10 +++++++---
 gpsprof    |  5 ++++-
 2 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/gps/gps.py b/gps/gps.py
index d6188c7c..213b0920 100755
--- a/gps/gps.py
+++ b/gps/gps.py
@@ -257,11 +257,15 @@ class gps(gpscommon, gpsdata, gpsjson):
         if status <= 0:
             return status
         if self.response.startswith("{") and self.response.endswith("}\r\n"):
-            self.unpack(self.response)
-            self.__oldstyle_shim()
-            self.valid |= PACKET_SET
+            self.interpret_json(self.response)
         return 0
 
+    def read_json(self, json):
+        "Read and interpret provided JSON data."
+        self.unpack(json)
+        self.__oldstyle_shim()
+        self.valid |= PACKET_SET
+
     def __next__(self):
         "Python 3 version of next()."
         if self.read() == -1:
diff --git a/gpsprof b/gpsprof
index 73d064ef..05483506 100755
--- a/gpsprof
+++ b/gpsprof
@@ -149,7 +149,10 @@ class plotter(object):
         self.session = gps.gps(host=None)
         for line in infp:
             baton.twirl()
-            self.session.unpack(line)
+            try:
+                self.session.read_json(line)
+            except gps.client.json_error:
+                sys.stderr.write("WARNING: JSON parsing error:", line.strip())
             if self.session.data["class"] == "DEVICES":
                 self.device = copy.copy(self.session.data["devices"][0])
             elif self.session.data["class"] not in self.watch:
-- 
2.13.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]