简体   繁体   English

校验和/ CRC计算

[英]Checksum/CRC calculation

I am decoding a message sent by an wireless outdoor weather station. 我正在解码无线室外气象站发送的消息。 I have figured out what most of the protocol means except haven't been able to determine how to calculate the checksum. 我已经弄清了大多数协议的含义,除了无法确定如何计算校验和。 Here is what I've found so far: 到目前为止,这是我发现的内容:

 0100 0111 0110 0000 0111 0100 0011 0010 1110 0110
|----|---------|--------------|---------|---------|
 start   id         temp        humidity  checksum?

So in the above example the temperature was 11.6 degrees and 50% humidity. 因此,在以上示例中,温度为11.6度,湿度为50%。 The "id" field changes to a "random" value when I replace the batteries in the outdoor transmitter. 当我更换室外变送器中的电池时,“ id”字段将变为“ random”值。 The last 8 bits only change when the id/temp/humidity changes so I'm fairly certain those are the checksum/crc bits. 最后8位仅在ID /温度/湿度变化时才变化,因此我可以肯定的是校验和/ CRC位。

Here are a bunch of different transmissions: 这是一堆不同的传输方式:

0100 1110 0101 0000 1001 0010 0011 0011 1010 0001
0100 1110 0101 0000 1001 0010 0011 0100 0011 0110
0100 0111 0110 0000 1001 0010 0011 0100 0110 1100
0100 0111 0110 0000 1001 0010 0011 0101 0101 1101
0100 0111 0110 0000 1001 0100 0011 0101 0000 0111
0100 0111 0110 0000 1001 0101 0011 0110 1010 0000
0100 0111 0110 0000 1001 1000 0011 0111 1101 0001
0100 0111 0110 0000 1010 1000 0011 0111 0110 0011
0100 0111 0110 0000 1010 1001 0011 0111 1001 0111
0100 0111 0110 0000 1010 1010 0011 0111 1011 1010
0100 0111 0110 0000 0111 0100 0011 0010 1110 0110
0100 0111 0110 0000 0111 0101 0011 0010 0001 0010
0100 0111 0110 0000 0111 0110 0011 0010 0011 1111

I'm not familiar with checksum/crc techniques, can anyone see what might be being used here or point me in a direction for how to determine this? 我对校验和/ CRC技术不熟悉,任何人都可以看到这里使用的内容或为我确定方法的方向吗?

Seriously, your best bet is probably to go to the weather station and look at the manufacturer and model number, then either plug that into Google or send email to the manufacturer asking how the checksum is calculated. 认真地说,最好的选择是去气象站,查看制造商和型号,然后将其插入Google或向制造商发送电子邮件,询问如何计算校验和。

If they baulk at releasing the information, tell them you're evaluating a solution and you may make a decision to buy ten to a hundred of their devices based on how easy it is to write software for it (information requests aren't delivered under oath and social engineering is still usually the easiest way to get at information you wouldn't normally get to see). 如果他们不愿意发布信息,请告诉他们您正在评估一种解决方案,并且您可能会根据为其编写软件的容易程度(购买信息的要求不达标)决定购买十到一百个设备。宣誓和社会工程学通常仍然是获取您通常不会看到的信息的最简单方法。

Hacked OK. 砍死了 Here's the C# code to generate the 5-th byte out of the previous 4 bytes. 这是C#代码,用于生成前4个字节中的第5个字节。

/// <summary>A variant of CRC-8</summary>
/// <param name="data">Pass here the first 4 bytes of data, e.g. { 0x4E 0x50 0x92 0x33 }</param>
/// <returns>The computed SRC value, e.g. 0xA1 for the data specified above.</returns>
static byte src8( byte[] data )
{
    byte res = 0;
    foreach( byte b in data )
    {
        byte val = b;
        for( int i = 0; i < 8; i++ )
        {
            byte tmp = (byte)( ( res ^ val ) & 0x80 );
            res <<= 1;
            if( 0 != tmp )
                res ^= 0x31;
            val <<= 1;
        }
    }
    return res;
}

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

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