How do you link multipart AIS messages?

1.9k Views Asked by At

The message format is

!AIVDM,2,1,,B,177KQJ5000G?tO`K>RA1wUbN0TKH,0*5C

The second field (in this case, 2), designates the number of parts in the AIS message and the third field (in this case, 1) indicates the part or fragment sequence.

If the messages do NOT arrive in sequence, is there a fail safe method of linking the message fragments? [I understand that several fragments can arrive in random order.]

4

There are 4 best solutions below

0
On

The AIS payloads are encapsulated within the NMEA message format -- NMEA sees them only as a black box -- so you should not expect a NMEA parser to be sensitive to the encoded AIS content.

If you were desperate, you could try to match the multipart messages by the expected lengths of each AIS payload message type, but you'd run into the following problems:

  1. Some message types (e.g. type 8: Binary Broadcast Message) have a variable length
  2. There are conventions for aligning messages on byte boundaries that are not always followed, so even fixed-length messages can be received with differing lengths (e.g. type 15).

The best you can do in practice is assume that multipart messages may only arrive interleaved if the two messages have different NMEA message types (e.g. one message is AIVDM, and the other is SAVDM). This is the approach taken in the NMEA parsing library I wrote, under each_complete_message.

You could go further and use the total number of message parts as a way to differentiate messages, but in practice 3-part messages seem to be exceedingly rare.

TL;DR

No, there is no fail safe method of linking fragments.

0
On

Message parts must follow an order.If they are not sequential you should not take the message into account.IEC 61162 document which is a standard defines the structures of NMEA sentences including AIS messages,says that the multipart messages have to be in order.If you are facing messages in random order it is a hardware failure as manufacturer have to obey the rules defined in IEC 61162 Standard.

0
On

If you are using Python, you can use the libais library: https://github.com/schwehr/libais/. The NmeaQueue works a FIFO queue and does the job for you.

Just put all the messages (whatever the order) in the queue, and call the pop method if the length of the queue is positive. It handles single & multipart messages.

import ais
q = ais.nmea_queue.NmeaQueue()
for msg in msg_generator: # can be a list for instance
    q.put(msg)
    if q.qsize():
        d = q.get().get('decoded', None)
        print
0
On

Maybe you can check why the third field is empty and whether it can be activated.

ShineMicro uses it in the following way: !AIVDM,X1,X2,X3,A,S--S,X4*CRC where X1 - total number of sentences (parts) needed to transmit 1 AIS message X2 - sentence number (1 to 9) X3 - sequential message identifier (0-9), sequentially assigned and is incremented for each new multy-sentences message