Concox跟踪器的16位CRC-ITU计算 [英] 16bit CRC-ITU calculation for Concox tracker

查看:237
本文介绍了Concox跟踪器的16位CRC-ITU计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为通过TCP从Concox TR06 GPS追踪器接收数据的服务器程序创建C#代码:



在上面的表格中,我很确定的位列应该被标记为字节,而不是......

现在,我的主要问题是计算错误检查。根据文件:

校验码由CRC-ITU检查方法生成。协议结构中从数据包长度到信息序列号(包括数据包长度和信息序列号)的数据校验码是CRC-ITU的数值。

好的,所以在上面的例子中,我需要计算CRC 0x 0x01 0x00 0x01

现在,我猜测它是16位的CRC如上图所示,CRC长度为2个字节。我已经在 http://www.sanity- free.org/134/standard_crc_16_in_csharp.html http:// www。 sanity-free.org/133/crc_16_ccitt_in_csharp.html ,但都没有给我答案,根据上面的图我应该得到 - 0xD9 0xDC。我甚至使用过这个网站 - https://www.lammertbies.nl/ comm / info / crc-calculation.html - 手动输入4个字节,但没有给我结果我应该根据上面的图得到...



任何想法可能会出错?任何指针/提示将不胜感激。谢谢

解决方案

ITU-T的CRC-16也被称为X-25 CRC。您可以在此处找到其规格,它是:

  width = 16 poly = 0x1021 init = 0xffff refin = true refout = true xorout = 0xffff check = 0x906e name =X -25

我的 crcany代码将采用该规范并生成C代码来计算CRC。 这里是按位(慢)代码从而生成:

  #include  

unsigned crc16x_25_bit(unsigned crc,void const * data,size_t len){
if(data == NULL)
return 0;
crc =〜crc;
crc& = 0xffff;
while(len--){
crc ^ = *(unsigned char const *)data ++;
(unsigned k = 0; k <8; k ++)
crc = crc& 1? (crc>> 1)^ 0x8408:crc>> 1;
}
crc ^ = 0xffff;
return crc;
}


I am creating C# code for a server program that receives data from a Concox TR06 GPS tracker via TCP:

http://www.iconcox.com/uploads/soft/140920/1-140920023130.pdf

When first starting up, the tracker sends a login message, which needs to be acknowledged before it will send any position data. My first problem is that, according to the documentation, the acknowledge message is 18 bytes long, yet the example they provide is only 10 bytes long:

P.s. in the table above, the "bits" column I'm pretty sure should be labelled "bytes" instead...

Now, my main problem is in calculating the Error Check. According to the documentation:

The check code is generated by the CRC-ITU checking method. The check codes of data in the structure of the protocol, from the Packet Length to the Information Serial Number (including "Packet Length" and "Information Serial Number"), are values of CRC-ITU.

Ok, so in the above example, I need to calculate CRC on 0x05 0x01 0x00 0x01

Now, I'm guessing it's 16 bit CRC, as according to the diagram above, the CRC is 2 bytes long. I've implemented two different CRC implementations I found online at http://www.sanity-free.org/134/standard_crc_16_in_csharp.html and http://www.sanity-free.org/133/crc_16_ccitt_in_csharp.html but neither give me the answer that, according to the diagram above I am supposed to be getting - 0xD9 0xDC. I've even used this site - https://www.lammertbies.nl/comm/info/crc-calculation.html - to manually enter the 4 bytes, but nothing gives me the result I'm supposed to be getting according to the diagram above...

Any ideas where I might be going wrong? Any pointers/hints would be greatly appreciated. Thank you

解决方案

The ITU CRC-16 is also called the X-25 CRC. You can find its specification here, which is:

width=16 poly=0x1021 init=0xffff refin=true refout=true xorout=0xffff check=0x906e name="X-25"

My crcany code will take that specification and generate C code to compute the CRC.

Here is the bit-wise (slow) code thusly generated:

#include <stddef.h>

unsigned crc16x_25_bit(unsigned crc, void const *data, size_t len) {
    if (data == NULL)
        return 0;
    crc = ~crc;
    crc &= 0xffff;
    while (len--) {
        crc ^= *(unsigned char const *)data++;
        for (unsigned k = 0; k < 8; k++)
            crc = crc & 1 ? (crc >> 1) ^ 0x8408 : crc >> 1;
    }
    crc ^= 0xffff;
    return crc;
}

这篇关于Concox跟踪器的16位CRC-ITU计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆