5 typedef unsigned char byte;
6 typedef unsigned int uint;
12 if (scanf("%x", &x) == 1)
20 u16 crc_update(u16 crc, byte data)
22 crc = crc ^ (data << 8);
23 for (uint i=0; i<8; i++) {
25 crc = (crc << 1) ^ 0x1021;
39 printf("# Bad sync: %02x\n", pkt[0]);
44 while (len < 4 || len < pkt[3]) {
48 for (int i=0; i<len; i++)
49 printf("%02x ", pkt[i]);
52 for (int i=0; i<len; i++)
53 crc = crc_update(crc, pkt[i]);
55 printf("[BAD CRC]\n");
61 printf("[TOO SHORT]\n");
65 printf("\n\t%02x -> %02x: ", pkt[1] ^ 0x80, pkt[2]);
68 printf("INFO %04x:%04x =", (pkt[5]<<8) | pkt[6], (pkt[7]<<8) | pkt[8]);
69 for (int i=9; i<len; i++)
70 printf(" %02x", pkt[i]);
74 printf("GET %04x:%04x\n", (pkt[6]<<8) | pkt[5], (pkt[7]<<8) | pkt[8]);
77 printf("RET %04x:%04x =", (pkt[5]<<8) | pkt[6], (pkt[7]<<8) | pkt[8]);
78 for (int i=9; i<len; i++)
79 printf(" %02x", pkt[i]);
83 printf("??? type=%02x\n", pkt[4]);