gpt4 book ai didi

arduino - 逆向工程 Panasonic IR 代码校验和

转载 作者:行者123 更新时间:2023-12-02 01:17:24 24 4
gpt4 key购买 nike

我正在研究由 IR Remote 控制的 Panasonic AC Unit。 Remote 发送 12 个字节

5 个字节 始终相同。下面的6个字节分别对应空调温度、风扇、功能等我自己摸索出来的选项。

最后一个 byte 是一个校验和,它是从前 11 个字节(或从 byte 611)

因为我在运行时重新创建了 IR 代码,所以我需要能够为这些数据包计算校验和。我尝试了许多标准校验和算法,但没有一个给出有意义的结果。

你能帮我找出这个设备使用的校验和函数吗?


这是一个数据包的列表,由11字节的 header +数据和1字节的校验和组成,我能够从设备中捕获:

40 00 14 81 25 00 A0 65 00 00 00 26
40 00 14 81 25 00 A0 68 00 00 07 30
40 00 14 81 25 04 28 65 00 00 00 2A
40 00 14 81 25 04 28 68 00 00 00 2D
40 00 14 81 25 04 28 68 00 00 02 2F
40 00 14 81 25 04 28 68 00 00 03 30
40 00 14 81 25 04 28 68 00 00 04 31
40 00 14 81 25 04 28 68 00 00 05 32
40 00 14 81 25 04 28 68 00 00 07 34
40 00 14 81 25 04 28 69 00 00 01 2F
40 00 14 81 25 04 A0 68 00 00 07 34
40 00 14 81 25 08 9A 68 00 00 07 41
40 00 14 81 25 08 9C 68 00 00 07 43
40 00 14 81 25 08 9E 68 00 00 07 45
40 00 14 81 25 08 A0 68 00 00 00 31
40 00 14 81 25 08 A0 68 00 00 01 32
40 00 14 81 25 08 A0 68 00 00 02 33
40 00 14 81 25 08 A0 68 00 00 03 34
40 00 14 81 25 08 A0 68 00 00 07 38
40 00 14 81 25 08 A2 68 00 00 07 3A
40 00 14 81 25 08 A4 68 00 00 07 3C
40 00 14 81 25 08 A6 68 00 00 07 3E
40 00 14 81 25 08 A8 68 00 00 07 40
40 00 14 81 25 08 AA 68 00 00 07 42
40 00 14 81 25 08 AC 68 00 00 07 44
40 00 14 81 25 08 AE 68 00 00 07 46
40 00 14 81 25 09 A0 68 00 00 07 39
40 00 14 81 25 0A A0 68 00 00 07 3A
40 00 14 81 25 0C A0 68 00 00 07 3C
40 00 14 81 25 40 18 65 00 00 00 29
40 00 14 81 25 40 1A 65 00 00 00 2B
40 00 14 81 25 40 1C 65 00 00 00 2D
40 00 14 81 25 40 1E 65 00 00 00 2F
40 00 14 81 25 40 20 65 00 00 00 22
40 00 14 81 25 40 22 65 00 00 00 24
40 00 14 81 25 40 24 65 00 00 00 26
40 00 14 81 25 40 26 65 00 00 00 28
40 00 14 81 25 40 28 65 00 00 00 2A
40 00 14 81 25 40 2A 65 00 00 00 2C
40 00 14 81 25 40 2C 65 00 00 00 2E
40 00 14 81 25 40 2E 65 00 00 00 30
40 00 14 81 25 40 30 65 00 00 00 23
40 00 14 81 25 40 32 65 00 00 00 25
40 00 14 81 25 40 34 65 00 00 00 27
40 00 14 81 25 40 34 68 00 00 04 2E
40 00 14 81 25 80 1C 68 00 00 00 34
40 00 14 81 25 80 20 65 00 00 00 26
40 00 14 81 25 C0 20 65 00 00 00 2A
40 00 14 81 25 C0 28 68 00 00 02 37

最佳答案

我找到了一个候选校验和函数,它匹配您的所有数据,但我认为需要进一步调整,因为我怀疑魔数(Magic Number) 我使用的取决于 其他 我没有正确考虑的东西。


这是我能够逆向工程的函数:

uint8_t get_checksum(const uint8_t data[], const size_t size)
{
assert(data);

uint8_t checksum = 0;

for (size_t i = 0; i < size; ++i)
{
checksum += (data[i] >> 4) + (data[i] & 0x0f);
}

checksum -= 8; /* magic number */

return checksum;
};

另一个版本:

uint8_t get_checksum(const uint8_t data[], const size_t size)
{
assert(data);

uint8_t checksum = 0xF8; /* magic number */

for (size_t i = 0; i < size; ++i)
{
checksum += (data[i] >> 4) + (data[i] & 0x0f);
}

return checksum;
};

示例:

#include<stdio.h>
#include<stdint.h>
#include<assert.h>

uint8_t get_checksum(const uint8_t data[], const size_t size)
{
assert(data);

uint8_t checksum = 0xF8; /* magic number */

for (size_t i = 0; i < size; ++i)
{
checksum += (data[i] >> 4) + (data[i] & 0x0f);
}

return checksum;
};

int main ()
{
const size_t xlen = 49;
const size_t ylen = 12;
uint8_t v[49][12] = {
{0x40,0x00,0x14,0x81,0x25,0x00,0xA0,0x65,0x00,0x00,0x00,0x26},
{0x40,0x00,0x14,0x81,0x25,0x00,0xA0,0x68,0x00,0x00,0x07,0x30},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x65,0x00,0x00,0x00,0x2A},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x68,0x00,0x00,0x00,0x2D},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x68,0x00,0x00,0x02,0x2F},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x68,0x00,0x00,0x03,0x30},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x68,0x00,0x00,0x04,0x31},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x68,0x00,0x00,0x05,0x32},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x68,0x00,0x00,0x07,0x34},
{0x40,0x00,0x14,0x81,0x25,0x04,0x28,0x69,0x00,0x00,0x01,0x2F},
{0x40,0x00,0x14,0x81,0x25,0x04,0xA0,0x68,0x00,0x00,0x07,0x34},
{0x40,0x00,0x14,0x81,0x25,0x08,0x9A,0x68,0x00,0x00,0x07,0x41},
{0x40,0x00,0x14,0x81,0x25,0x08,0x9C,0x68,0x00,0x00,0x07,0x43},
{0x40,0x00,0x14,0x81,0x25,0x08,0x9E,0x68,0x00,0x00,0x07,0x45},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA0,0x68,0x00,0x00,0x00,0x31},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA0,0x68,0x00,0x00,0x01,0x32},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA0,0x68,0x00,0x00,0x02,0x33},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA0,0x68,0x00,0x00,0x03,0x34},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA0,0x68,0x00,0x00,0x07,0x38},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA2,0x68,0x00,0x00,0x07,0x3A},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA4,0x68,0x00,0x00,0x07,0x3C},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA6,0x68,0x00,0x00,0x07,0x3E},
{0x40,0x00,0x14,0x81,0x25,0x08,0xA8,0x68,0x00,0x00,0x07,0x40},
{0x40,0x00,0x14,0x81,0x25,0x08,0xAA,0x68,0x00,0x00,0x07,0x42},
{0x40,0x00,0x14,0x81,0x25,0x08,0xAC,0x68,0x00,0x00,0x07,0x44},
{0x40,0x00,0x14,0x81,0x25,0x08,0xAE,0x68,0x00,0x00,0x07,0x46},
{0x40,0x00,0x14,0x81,0x25,0x09,0xA0,0x68,0x00,0x00,0x07,0x39},
{0x40,0x00,0x14,0x81,0x25,0x0A,0xA0,0x68,0x00,0x00,0x07,0x3A},
{0x40,0x00,0x14,0x81,0x25,0x0C,0xA0,0x68,0x00,0x00,0x07,0x3C},
{0x40,0x00,0x14,0x81,0x25,0x40,0x18,0x65,0x00,0x00,0x00,0x29},
{0x40,0x00,0x14,0x81,0x25,0x40,0x1A,0x65,0x00,0x00,0x00,0x2B},
{0x40,0x00,0x14,0x81,0x25,0x40,0x1C,0x65,0x00,0x00,0x00,0x2D},
{0x40,0x00,0x14,0x81,0x25,0x40,0x1E,0x65,0x00,0x00,0x00,0x2F},
{0x40,0x00,0x14,0x81,0x25,0x40,0x20,0x65,0x00,0x00,0x00,0x22},
{0x40,0x00,0x14,0x81,0x25,0x40,0x22,0x65,0x00,0x00,0x00,0x24},
{0x40,0x00,0x14,0x81,0x25,0x40,0x24,0x65,0x00,0x00,0x00,0x26},
{0x40,0x00,0x14,0x81,0x25,0x40,0x26,0x65,0x00,0x00,0x00,0x28},
{0x40,0x00,0x14,0x81,0x25,0x40,0x28,0x65,0x00,0x00,0x00,0x2A},
{0x40,0x00,0x14,0x81,0x25,0x40,0x2A,0x65,0x00,0x00,0x00,0x2C},
{0x40,0x00,0x14,0x81,0x25,0x40,0x2C,0x65,0x00,0x00,0x00,0x2E},
{0x40,0x00,0x14,0x81,0x25,0x40,0x2E,0x65,0x00,0x00,0x00,0x30},
{0x40,0x00,0x14,0x81,0x25,0x40,0x30,0x65,0x00,0x00,0x00,0x23},
{0x40,0x00,0x14,0x81,0x25,0x40,0x32,0x65,0x00,0x00,0x00,0x25},
{0x40,0x00,0x14,0x81,0x25,0x40,0x34,0x65,0x00,0x00,0x00,0x27},
{0x40,0x00,0x14,0x81,0x25,0x40,0x34,0x68,0x00,0x00,0x04,0x2E},
{0x40,0x00,0x14,0x81,0x25,0x80,0x1C,0x68,0x00,0x00,0x00,0x34},
{0x40,0x00,0x14,0x81,0x25,0x80,0x20,0x65,0x00,0x00,0x00,0x26},
{0x40,0x00,0x14,0x81,0x25,0xC0,0x20,0x65,0x00,0x00,0x00,0x2A},
{0x40,0x00,0x14,0x81,0x25,0xC0,0x28,0x68,0x00,0x00,0x02,0x37}
};

// packet has 11 bytes, 1 byte is for the checksum
for (size_t i = 0; i < xlen; ++i)
{
uint8_t checksum = get_checksum(v[i], 11);

printf("result: %02x -- should be: %02x -- %s\n",
checksum, v[i][ylen - 1],
(checksum - v[i][ylen - 1] == 0 ? "OK" : "ERROR"));
}
}

输出:

result: 26 -- should be: 26 -- OK
result: 30 -- should be: 30 -- OK
result: 2a -- should be: 2a -- OK
result: 2d -- should be: 2d -- OK
result: 2f -- should be: 2f -- OK
result: 30 -- should be: 30 -- OK
result: 31 -- should be: 31 -- OK
result: 32 -- should be: 32 -- OK
result: 34 -- should be: 34 -- OK
result: 2f -- should be: 2f -- OK
result: 34 -- should be: 34 -- OK
result: 41 -- should be: 41 -- OK
result: 43 -- should be: 43 -- OK
result: 45 -- should be: 45 -- OK
result: 31 -- should be: 31 -- OK
result: 32 -- should be: 32 -- OK
result: 33 -- should be: 33 -- OK
result: 34 -- should be: 34 -- OK
result: 38 -- should be: 38 -- OK
result: 3a -- should be: 3a -- OK
result: 3c -- should be: 3c -- OK
result: 3e -- should be: 3e -- OK
result: 40 -- should be: 40 -- OK
result: 42 -- should be: 42 -- OK
result: 44 -- should be: 44 -- OK
result: 46 -- should be: 46 -- OK
result: 39 -- should be: 39 -- OK
result: 3a -- should be: 3a -- OK
result: 3c -- should be: 3c -- OK
result: 29 -- should be: 29 -- OK
result: 2b -- should be: 2b -- OK
result: 2d -- should be: 2d -- OK
result: 2f -- should be: 2f -- OK
result: 22 -- should be: 22 -- OK
result: 24 -- should be: 24 -- OK
result: 26 -- should be: 26 -- OK
result: 28 -- should be: 28 -- OK
result: 2a -- should be: 2a -- OK
result: 2c -- should be: 2c -- OK
result: 2e -- should be: 2e -- OK
result: 30 -- should be: 30 -- OK
result: 23 -- should be: 23 -- OK
result: 25 -- should be: 25 -- OK
result: 27 -- should be: 27 -- OK
result: 2e -- should be: 2e -- OK
result: 34 -- should be: 34 -- OK
result: 26 -- should be: 26 -- OK
result: 2a -- should be: 2a -- OK
result: 37 -- should be: 37 -- OK

关于arduino - 逆向工程 Panasonic IR 代码校验和,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42092565/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com