summaryrefslogtreecommitdiff
path: root/devtools
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-09-09 01:30:43 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-09-09 01:30:43 +0000
commit53486edd47c6b64d2e789f3500332a67ad6f3025 (patch)
tree0150d6901be3662ee27d20061446b5cdf76b61b4 /devtools
parent0d908bba9cdac96beb4790c4ea8b0d4013826c5f (diff)
downloadgpsd-53486edd47c6b64d2e789f3500332a67ad6f3025.tar.gz
Trying to use the Python standard library JSON parser...
...reveals that we have to be more careful about not generating trailing commas.
Diffstat (limited to 'devtools')
-rwxr-xr-xdevtools/cycle_analyzer16
1 files changed, 11 insertions, 5 deletions
diff --git a/devtools/cycle_analyzer b/devtools/cycle_analyzer
index c34a4291..52482e73 100755
--- a/devtools/cycle_analyzer
+++ b/devtools/cycle_analyzer
@@ -45,6 +45,7 @@ import sys, getopt, json
verbose = 0
suppress_regular = False
+parse_json = False
class analyze_error:
def __init__(self, filename, lineno, msg):
@@ -93,10 +94,15 @@ def extract_from_json(filename, lineno, line):
"Extend sequence of tag/timestamp tuples from a JSON dump of a sentence"
if not line.startswith("{"):
return []
- sentence = json.loads(line)
- if "tag" not in sentence or sentence["tag"] not in ("RMC","GLL","GGA","GBS","PASHR") or "time" not in sentence:
+ try:
+ sentence = json.loads(line)
+ if "tag" not in sentence or sentence["tag"] not in ("RMC","GLL","GGA","GBS","PASHR") or "time" not in sentence:
+ return []
+ return [event(sentence["tag"], sentence["time"])]
+ except ValueError, e:
+ print line.rstrip()
+ print e
return []
- return [event(sentence["tag"], sentence["time"])]
def extract_timestamped_sentences(fp):
"Do the basic work of extracting tags and timestamps"
@@ -109,7 +115,7 @@ def extract_timestamped_sentences(fp):
lineno += 1
if line.startswith("#"):
continue
- if not json and line.startswith("$"):
+ if not parse_json and line.startswith("$"):
sequence += extract_from_nmea(fp.name, lineno, line)
elif json and line.startswith("{"):
sequence + extract_from_json(fp.name, lineno, line)
@@ -228,7 +234,7 @@ if __name__ == "__main__":
if (switch == '-d'): # Debug
stages = val
elif (switch == '-j'): # Interpret JSON, not NMEA
- json = True
+ parse_json = True
elif (switch == '-v'): # Verbose
verbose += 1
elif (switch == '-s'): # Suppress logs with no problems