简体   繁体   English

用于船载 AIS 的 CRC16-CCITT

[英]CRC16-CCITT for shipborne AIS

I am trying to decode an AIS transmission and validate it by checking CRC code.我正在尝试解码 AIS 传输并通过检查 CRC 码来验证它。 However, I am not sure of the sequence of steps, nor the expected result.但是,我不确定步骤的顺序,也不确定预期的结果。 My question is, can anyone tell me the correct sequence of steps to use CRC to validate an AIS packet?我的问题是,谁能告诉我使用 CRC 验证 AIS 数据包的正确步骤顺序?

I am following the link layer sequence on page 2 of this guide, in reverse order: https://fidus.com/wp-content/uploads/2016/03/Guide_to_System_Development_March_2009.pdf我按照本指南第 2 页上的链接层顺序,以相反的顺序: https ://fidus.com/wp-content/uploads/2016/03/Guide_to_System_Development_March_2009.pdf

my steps are:我的步骤是:

  1. get stream of bits from FM demodulator从 FM 解调器获取比特流
  2. NRZI decode NRZI 解码
  3. find the start and stop flags and extract the data packet between them找到开始和停止标志并提取它们之间的数据包
  4. remove stuffing bits from the data packet从数据包中删除填充位
  5. split the packet into bytes and reverse each byte, so that bit 0 becomes bit 7.将数据包拆分为字节并反转每个字节,使位 0 变为位 7。
  6. take 16 bits CRC off the end of the packet.从数据包的末尾取出 16 位 CRC。

Then I expect that one of these things will be true:然后我希望其中一件事情是真的:

  • CRC calculated on the packet (data only) matches the received CRC code.对数据包(仅数据)计算的 CRC 与接收到的 CRC 码相匹配。
  • CRC calculated on the packet (data + received CRC) produces a constant product if the message was valid.如果消息有效,则对数据包计算的 CRC(数据 + 接收到的 CRC)产生一个常数乘积。 All valid messages produce the same product.所有有效消息都会产生相同的产品。 According to the source code of RTL-AIS, the product is 0x0f47.根据 RTL-AIS 的源代码,产品为 0x0f47。

however I have not been able to get a result that matches any expectation, and I also can't get two messages to make the same output even if I'm certain they are both valid.但是我无法得到符合任何期望的结果,即使我确定它们都是有效的,我也无法获得两条消息来产生相同的输出。

I am using CRC-16 CCITT with polynomial 0x8408 and initial fill 0xFFFF.我正在使用多项式 0x8408 和初始填充 0xFFFF 的 CRC-16 CCITT。 I have taken these parameters also from the source code of RTL-AIS.我也从 RTL-AIS 的源代码中获取了这些参数。 I tried to learn more from this resource, but it is densely written and without comments, and i cannot understand it.我试图从这个资源中了解更多,但它写得很密集,没有评论,我无法理解。 I am not sure if the CRC process itself involves further reversals.我不确定 CRC 过程本身是否涉及进一步的逆转。

I've tried the CRC process on data from other sources that I can find, with no luck.我已经尝试了对我能找到的其他来源的数据的 CRC 过程,但没有运气。 ( https://www.dsprelated.com/showthread/comp.dsp/79522-1.php shows their data and claims success, as well as explaining the bit order reversal, but I cannot replicate it). https://www.dsprelated.com/showthread/comp.dsp/79522-1.php显示了他们的数据并声称成功,并解释了位顺序反转,但我无法复制它)。

The data from that post is: 000010000000000010111001011100000010101010111110111011101100110001110101001111100110000010001101011110110001000011000110111011001000000100000011100000000000001100011000 The data from that post is: 000010000000000010111001011100000010101010111110111011101100110001110101001111100110000010001101011110110001000011000110111011001000000100000011100000000000001100011000

the checksum is: 1110100000011111校验和为:1110100000011111

using this online CRC tool, https://crccalc.com/ , I have not been able to arrive at that same result.使用此在线 CRC 工具https://crccalc.com/ ,我无法得出相同的结果。 Can anyone show me how to do it?谁能告诉我怎么做?

Cheers to rcgldr for teaching me about the final XOR value!为 rcgldr 教我最终的 XOR 值干杯!

I used this CRC calculator online: http://www.sunshine2k.de/coding/javascript/crc/crc_js.html我在线使用了这个 CRC 计算器:http: //www.sunshine2k.de/coding/javascript/crc/crc_js.html

I used CRC-16 with no input reflection, no result reflection, polynomial 0x1021, initial fill 0xFFFF, final XOR value 0xFFFF.我使用了 CRC-16,没有输入反射,没有结果反射,多项式 0x1021,初始填充 0xFFFF,最终 XOR 值 0xFFFF。

Regarding the sequence of steps, this calculation must be performed on bits straight out of the unstuffer- before any bit or byte order change is applied.关于步骤的顺序,必须在应用任何位或字节顺序更改之前对直接来自 unstuffer 的位执行此计算。

These parameters, on the data from my question, produces CRC result 0xE81F which matches the checksum in my question.这些参数,根据我的问题的数据,产生与我的问题中的校验和匹配的 CRC 结果 0xE81F。

Polynomial 0x1021 comes from the specification for CRC16-CCITT.多项式 0x1021 来自 CRC16-CCITT 规范。

In the RTL-AIS source code, and other projects which inherit from it, polynomial 0x8408 is used along with some unknown sequence of changes to bit and byte order.在 RTL-AIS 源代码和其他继承自它的项目中,使用多项式 0x8408 以及一些未知的位和字节顺序更改序列。 It remains a mystery to me.这对我来说仍然是一个谜。 To the reader in future, I would advise copying what I have done here, as it is much more straightforward!对于将来的读者,我建议复制我在这里所做的,因为它更简单!

Thanks again, I have been battling against this problem for weeks.再次感谢,我已经与这个问题作斗争了好几个星期。

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

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