summaryrefslogtreecommitdiff
path: root/devtools
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2011-02-14 09:13:35 -0500
committerEric S. Raymond <esr@thyrsus.com>2011-02-14 09:13:35 -0500
commitc2e9b19e54010b79fc6ffa1864d356c0ea24e32a (patch)
treeede5d31f119373b0edd441adb93ba933bcdf2a24 /devtools
parent1385c3d80c5766bf15e8dfdd9e28898308fe1232 (diff)
downloadgpsd-c2e9b19e54010b79fc6ffa1864d356c0ea24e32a.tar.gz
Add tablecheck.py to the repo.
Diffstat (limited to 'devtools')
-rw-r--r--devtools/README3
-rwxr-xr-xdevtools/tablecheck.py49
2 files changed, 52 insertions, 0 deletions
diff --git a/devtools/README b/devtools/README
index 4a16a5b0..7647317b 100644
--- a/devtools/README
+++ b/devtools/README
@@ -78,6 +78,9 @@ May be useful for comparing logs when regression tests break.
Strip leading comment lines from NMEA sentence logs. gpsfake can do
this itself now, so this script has a lot of dust on it.
+== tablecheck.py ==
+Redo bit offsets of AIVDM message layout tables to be conformant with list
+lengths.
diff --git a/devtools/tablecheck.py b/devtools/tablecheck.py
new file mode 100755
index 00000000..3f48dc0d
--- /dev/null
+++ b/devtools/tablecheck.py
@@ -0,0 +1,49 @@
+#!/usr/bin/env python
+#
+# Compute offsets for an AIVDM message breakdown, given the bit widths.
+# Takes a single argument, the line number of a table start.
+# Writes the corrected table to standard output.
+
+import sys
+
+if __name__ == '__main__':
+ startline = int(sys.argv[1])
+
+ table = []
+ keep = False
+ i = 0
+ for line in sys.stdin:
+ i += 1
+ if i == startline:
+ if line.startswith("|="):
+ keep = True
+ else:
+ print >>sys.stderr, "Bad table start"
+ sys.exit(1)
+ elif line.startswith("|="):
+ keep = False
+ if keep:
+ table.append(line)
+ table = table[2:]
+
+ widths = map(lambda s: s.split('|')[2].strip(), table)
+
+ offsets = []
+ base = 0
+ for w in widths:
+ if not w:
+ offsets.append('')
+ else:
+ w = int(w)
+ offsets.append("%d-%d" % (base, base + w - 1))
+ base += w
+ print >>sys.stderr, "Total bits:", base
+ owidth = max(*map(len, offsets))
+ for (i, off) in enumerate(offsets):
+ offsets[i] += " " * (owidth - len(offsets[i]))
+
+ for (i, t) in enumerate(table):
+ print "|" + offsets[i] + t[owidth+1:].rstrip()
+
+
+