Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are the possible ways to encode a counter in a byte?

I am reverse engineering an AC remote control. When I send the temperature values (from 17C to 30C) I get the following stream.

 Temperature - Binary    -  Hex    - Decimal
     17C     - 00000000  -  0x00   - 0
     18C     - 00010000  -  0x10   - 16
     19C     - 00110000  -  0x30   - 48
     20C     - 00100000  -  0x20   - 32
     21C     - 01100000  -  0x60   - 96
     22C     - 01110000  -  0x70   - 112
     23C     - 01010000  -  0x50   - 80
     24C     - 01000000  -  0x40   - 64
     25C     - 11000000  -  0xc0   - 192
     26C     - 11010000  -  0xd0   - 208
     27C     - 10010000  -  0x90   - 144
     28C     - 10000000  -  0x80   - 128
     29C     - 10100000  -  0xa0   - 160
     30C     - 10110000  -  0xb0   - 176

What possible method could they have used to encode the temperature data in the byte? Is there any method to reverse engineer the stream?

Looking at it it's clear that they are adding powers of 2 but I can't figure out the logic behind it.

like image 591
scrafy Avatar asked Jul 28 '14 18:07

scrafy


1 Answers

The first four bits form a 4-bit Gray code, since every two consecutive bit sequences differ in exactly one position:

0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1001
1000
1010
1011
[1111] (missing, probably 31C)

Your sample does not give any indication about what happens outside the [17, 31] range. As for why this pattern would be used, Wikipedia provides some examples:

Gray codes are used in position encoders (linear encoders and rotary encoders), in preference to straightforward binary encoding. This avoids the possibility that, when several bits change in the binary representation of an angle, a misread will result from some of the bits changing before others.

like image 150
Niklas B. Avatar answered Oct 25 '22 19:10

Niklas B.