summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2010-05-09 20:33:14 -0400
committerEric S. Raymond <esr@thyrsus.com>2010-05-09 20:33:14 -0400
commitc2e8325f27b3023b77c5bb0495407bd5901ba6fe (patch)
tree15e21ee0761515861f118a459896c4c4323eeac8
parentaf0d74e558eccda0296b7884318d8f3bb10ffc67 (diff)
downloadgpsd-c2e8325f27b3023b77c5bb0495407bd5901ba6fe.tar.gz
Teach ais.py to ignore USCG metadata following a checksum.
-rwxr-xr-xdevtools/ais.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/devtools/ais.py b/devtools/ais.py
index 319f5f3d..af4eef20 100755
--- a/devtools/ais.py
+++ b/devtools/ais.py
@@ -791,7 +791,7 @@ class BitVector:
"Used for dumping binary data."
return str(self.bitlen) + ":" + "".join(map(lambda d: "%02x" % d, self.bits[:(self.bitlen + 7)/8]))
-import sys, exceptions
+import sys, exceptions, re
class AISUnpackingException(exceptions.Exception):
def __init__(self, lc, fieldname, value):
@@ -861,8 +861,11 @@ def parse_ais_messages(source, scaled=False, skiperr=False, verbose=0):
if not line:
return
raw += line
+ line = line.strip()
+ # Strip off USCG metadata
+ line = re.sub(r"(?<=\*[0-9A-F][0-9A-F]),.*", "", line)
# Compute CRC-16 checksum
- packet = line.strip()[1:-3] # Strip leading !, trailing * and CRC
+ packet = line[1:-3] # Strip leading !, trailing * and CRC
csum = 0
for c in packet:
csum ^= ord(c)