summaryrefslogtreecommitdiff
path: root/devtools/ais.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2009-11-30 01:37:49 +0000
committerEric S. Raymond <esr@thyrsus.com>2009-11-30 01:37:49 +0000
commita25d9a2036f3e43276353ca81586d0e4e4f6d4ec (patch)
treee8885cc6ff9aaad5e8039ec66a091b833c80ea36 /devtools/ais.py
parentf431ff9d1b054bfbcddd801c926ec2f9e6e730fa (diff)
downloadgpsd-a25d9a2036f3e43276353ca81586d0e4e4f6d4ec.tar.gz
Document that a trailing @ should terminate a packed-six-bit AIS string.
Ensure that both decoders do this.
Diffstat (limited to 'devtools/ais.py')
-rwxr-xr-xdevtools/ais.py13
1 files changed, 11 insertions, 2 deletions
diff --git a/devtools/ais.py b/devtools/ais.py
index 6f63a097..0f67beac 100755
--- a/devtools/ais.py
+++ b/devtools/ais.py
@@ -758,8 +758,17 @@ def aivdm_unpack(data, offset, values, instructions):
value = data.sbits(offset, inst.width)
elif inst.type == 'string':
value = ''
- for i in range(inst.width/6):
- value += "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^- !\"#$%&`()*+,-./0123456789:;<=>?"[data.ubits(offset + 6*i, 6)]
+ # The try/catch error here is in case we run off the end
+ # of a variable-length string field, as in messages 12 and 14
+ try:
+ for i in range(inst.width/6):
+ newchar = "@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^- !\"#$%&`()*+,-./0123456789:;<=>?"[data.ubits(offset + 6*i, 6)]
+ if newchar == '@':
+ break
+ else:
+ value += newchar
+ except IndexError:
+ pass
value = value.replace("@", " ").rstrip()
elif inst.type == 'raw':
value = BitVector(data.bits[offset/8:], len(data)-offset)