subraizada3 / 27gn950controller

Control bias lighting on the LG 27GN950 monitor
Other
63 stars 12 forks source link

Figure out how checksums are calculated for video sync mode #7

Closed subraizada3 closed 2 years ago

subraizada3 commented 2 years ago

The code to send video sync data is implemented. However, each message sent to the monitor includes a checksum, and we need to figure out how to compute the checksum.

For the 'fixed' commands like "turn lighting on", the checksums were captured from the USB logs. For example, the turn on command is always the same:

5343cf02020100 de 4544

Where de is the checksum. It never changes since the command is constant.

However, the video sync commands are dynamically generated and we need to be able to calculate the correct checksum to put it into the command. Otherwise the monitor ignores the data we're sending.

I captured a few minutes of USB video sync transactions from the LG control application. I can 're-play' the captured video sync through the library, since the captured transactions have the checksums in them. But we can't send new data that we create.

I've uploaded some files which contain various commands and their checksums. We need to analyze these and figure out how the checksums are computed, so that we can generate correct checksums for new video sync data that we create.

The files are:


Some details that may help with analyzing this data:

Every single USB HID message sent to the monitor follows the same format:

For example, the HID message to switch to dynamic color mode is:

5343ca02020306df4544 followed by the zero padding

It can be broken down into:

The video sync data messages are like this, but the "command data" part is much, much longer. These messages follow the format:

5343c1029100ff0000ff0000ff0000...ff0000ff0000ff0000424544

That example will set the ring of LEDs to fully red.

The message can be broken down to:

koshisan commented 2 years ago

Very exited to see this happening :) You probably did google https://reveng.sourceforge.io/ yourself by this point? ;)

subraizada3 commented 2 years ago

You probably did google https://reveng.sourceforge.io/ yourself by this point? ;)

I did suspect it might be CRC (because what else would it be?) but I did not google :)

Well, that was pretty easy with reveng. The parameters it found are:

width=8 poly=0x01 init=0x00 xorout=0x00 check=0x31

./reveng -c -w8 -p1 -i0 -x0 {bytes} correctly calculates CRCs for messages outside the 'training set' I fed it to reverse.

subraizada3 commented 2 years ago

Resolved with https://github.com/subraizada3/27gn950controller/commit/c5be3ff553c286c1f0bbcf4f3b5b128d763c6c15