diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2010-05-09 20:33:14 -0400 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2010-05-09 20:33:14 -0400 |
commit | c2e8325f27b3023b77c5bb0495407bd5901ba6fe (patch) | |
tree | 15e21ee0761515861f118a459896c4c4323eeac8 | |
parent | af0d74e558eccda0296b7884318d8f3bb10ffc67 (diff) | |
download | gpsd-c2e8325f27b3023b77c5bb0495407bd5901ba6fe.tar.gz |
Teach ais.py to ignore USCG metadata following a checksum.
-rwxr-xr-x | devtools/ais.py | 7 |
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) |