简体   繁体   English

如何链接多部分AIS消息?

[英]How do you link multipart AIS messages?

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. 第二个字段(在这种情况下为2 )指定AIS消息中的部分数,第三个字段(在这种情况下为1 )指示部分或片段序列。

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.] [我知道几个片段可以随机顺序到达。]

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. IEC 61162文档定义了包括AIS消息在内的NMEA语句的结构,规定多部分消息必须是有序的。如果您以随机顺序面对消息,则这是硬件故障,因为制造商必须遵守在其中定义的规则。 IEC 61162标准。

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. AIS有效载荷封装在NMEA消息格式中-NMEA仅将它们视为黑匣子-因此,您不应期望NMEA解析器对编码的AIS内容敏感。

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: 如果您不顾一切,可以尝试按每种AIS有效负载消息类型的预期长度来匹配多部分消息,但是会遇到以下问题:

  1. Some message types (eg type 8: Binary Broadcast Message) have a variable length 某些消息类型(例如,类型8:二进制广播消息)的长度可变
  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 (eg type 15). 并非总是遵循在字节边界上对齐消息的约定,因此,即使定长消息也可以以不同的长度接收(例如,类型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 (eg one message is AIVDM , and the other is SAVDM ). 你可以在实践中做的最好的是假设,如果这两个消息有不同的NMEA消息类型多的消息只能到达交错(例如,一个消息是AIVDM ,另一个是SAVDM )。 This is the approach taken in the NMEA parsing library I wrote, under each_complete_message . 这是NMEA解析库中在each_complete_messageeach_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 TL; DR

No, there is no fail safe method of linking fragments. 不,没有链接片段的故障保护方法。

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 ShineMicro通过以下方式使用它:!AIVDM,X1,X2,X3,A,S--S,X4 * CRC其中X1-传输1条AIS消息所需的句子总数(部分)X2-句子编号(1至9)X3-顺序消息标识符(0-9),按顺序分配,并针对每个新的多句消息递增

If you are using Python, you can use the libais library: https://github.com/schwehr/libais/ . 如果您使用的是Python,则可以使用libais库: https : //github.com/schwehr/libais/ The NmeaQueue works a FIFO queue and does the job for you. NmeaQueue工作FIFO队列并为您完成工作。

Just put all the messages (whatever the order) in the queue, and call the pop method if the length of the queue is positive. 只需将所有消息(无论顺序如何)放入队列中,然后在队列长度为正数时调用pop方法。 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM