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

1

9

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.

Audi answered 28/7, 2014 at 18:29 Comment(2)
Just a shot in the dark - compare the values in Fahrenheit?Rhombencephalon
don't see how F could help, the numbers don't rise, 24C has a lower encoding that 23CSaponin
C
9

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.

Charlottcharlotta answered 28/7, 2014 at 19:0 Comment(1)
Thank you Niklas! That is exactly what I was looking for. You learn something new every day.Audi

© 2022 - 2024 — McMap. All rights reserved.