diff options
author | Eric S. Raymond <esr@thyrsus.com> | 2009-06-18 23:41:57 +0000 |
---|---|---|
committer | Eric S. Raymond <esr@thyrsus.com> | 2009-06-18 23:41:57 +0000 |
commit | f3d7910fb31936cc6ad4726ac4f16d33c06eaf79 (patch) | |
tree | f445887a2b9432608340957b62e60998215e0ee4 /ais.py | |
parent | 90db4cebf612956116aefbb70df3f40440b0d6e3 (diff) | |
download | gpsd-f3d7910fb31936cc6ad4726ac4f16d33c06eaf79.tar.gz |
Handle AIS Type 21 name extension field.
Diffstat (limited to 'ais.py')
-rwxr-xr-x | ais.py | 19 |
1 files changed, 15 insertions, 4 deletions
@@ -8,9 +8,7 @@ # and a small amount of code for interpreting it. # # Known bugs: -# 1. Does not aggregate the Type 21 Name Extension field with the Name field. -# 3. Does not handle the small-boat variant of 24 part B. -# 2. A subtle problem near certain variable-length messages: CSV +# * A subtle problem near certain variable-length messages: CSV # reports will sometimes have fewer fields than expected, because the # unpacker never generates cooked tuples for the omitted part of the # message. Presently a known issue for types 15 and 16 only. (Will @@ -554,7 +552,7 @@ type21 = ( bitfield("virtual_aid", 1, 'unsigned', 0, "Virtual-aid flag"), bitfield("assigned", 1, 'unsigned', 0, "Assigned-mode flag"), spare(2), - bitfield("extension", 88, 'string', 0, "Name Extension"), + bitfield("name", 88, 'string', 0, "Name Extension"), ) type22 = ( @@ -763,6 +761,19 @@ def parse_ais_messages(source, scaled=False): group = formatter(*map(lambda x: x[1], segment)) group = (label, group, 'string', legend, None) cooked = cooked[:offset]+[group]+cooked[offset+len(template):] + # If there are multiple string fields with the same name, + # treat all but the first as extensions; that is, concatenate the values + # of the later ones to the first, then delete those tuples. + retry = True + while retry: + retry = False + for i in range(len(cooked)): + if cooked[i][2] == 'string': + for j in range(i+1, len(cooked)): + if cooked[j][2] == 'string' and cooked[i][0] == cooked[j][0]: + cooked[i][1] += cooked[j][1] + cooked = cooked[:j] + cooked[j+1:] + retry = True # Now apply custom formatting hooks. if scaled: for (i, (name,value,dtype,legend,formatter)) in enumerate(cooked): |