schwehr / libais

C++ decoder for Automatic Identification System for tracking ships and decoding maritime information
Other
215 stars 94 forks source link

Message not decoded using tag_block queue, but does decode when calling ais.decode directly #238

Open andyvan-trabus opened 2 years ago

andyvan-trabus commented 2 years ago

I noticed that messages that decode when I call ais.decode don't decode when I use the tag_block interface. I've traced it to the following:

Parse('!ANVDO,1,1,,Y,E>k?g@VWW:3WVRa<gVC2000000M80l=;BCH00000PP20,4*72') Traceback (most recent call last): File "/home/avanpelt/git/libais/ais/vdm.py", line 117, in Parse result = VDM_RE.search(data).groupdict() AttributeError: 'NoneType' object has no attribute 'groupdict'

Here's a test script:

import ais
from ais import tag_block

MESSAGES = ["\\c:1632515401,s:AS-LRP-OHMNTGMR,n:50780*28\\!ANVDO,1,1,,Y,E>k`?g@VWW:3WVRa<gVC2000000M80l=;`BCH00000PP20,4*72"]

queue = tag_block.TagQueue()

for line_no, line in enumerate(MESSAGES):
    queue.put(line, line_no)

while not queue.empty():
    tag_msg = queue.get()
    if "decoded" not in tag_msg:
        print("Message NOT decoded using tag_block queue")
        payload = tag_msg["lines"][0]
        print("payload = '{}'".format(payload))

        body = payload.split(',')[-2]
        pad = int(payload.split('*')[-2][-1])
        print("Calling ais.decode('{}', {})".format(body, pad))
        msg = ais.decode(body, pad)
        print(msg)

    else:
        print("Message decoded using tag_block queue")

Here's the output:

python ./test_236.py Message NOT decoded using tag_block queue payload = '\c:1632515401,s:AS-LRP-OHMNTGMR,n:5078028!ANVDO,1,1,,Y,E>k?g@VWW:3WVRa<gVC2000000M80l=;BCH00000PP20,472' Calling ais.decode('E>k?g@VWW:3WVRa<gVC2000000M80l=;BCH00000PP20', 4) {'id': 21, 'repeat_indicator': 0, 'mmsi': 993660861, 'spare': 0, 'aton_type': 1, 'name': 'MONTGOMERY-L&D@@@@@@', 'position_accuracy': 1, 'x': -80.38525833333334, 'y': 40.647938333333336, 'dim_a': 0, 'dim_b': 0, 'dim_c': 0, 'dim_d': 0, 'fix_type': 1, 'timestamp': 1, 'off_pos': False, 'aton_status': 0, 'raim': True, 'virtual_aton': False, 'assigned_mode': False}