das icon indicating copy to clipboard operation
das copied to clipboard

Invalid length error

Open MatthL-SwiftC opened this issue 4 years ago • 2 comments

Hello, I'm so glad to have found this as I want a simple CLI to set color profiles for my 4Q without the heavy software, or node.

Sadly I cannot get it to work, every time I try the all-color demo I get the following error:

go run ./all-color/
dev.Info() = {9456 8247 256 1 1 0 1 56}
dev.Info() = {9456 8247 256 0 0 1 1 56}
-> SetReport(1, []byte{0x1, 0xea, 0xb, 0x78, 0x3, 0x0, 0x0, 0x0})
-> SetReport(1, []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9a, 0x0})
<- GetReport(1) = []byte{0xed, 0x3, 0x78, 0x0, 0x96, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9a, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
2021/06/25 13:11:08 invalid length 0, want at least 2
exit status 1

Running Firmware: v21.27.0

MatthL-SwiftC avatar Jun 25 '21 17:06 MatthL-SwiftC

Hi @MatthL-SwiftC, thanks for reporting this! In this long list of zero bytes (0x0), there is one byte that is not zero (0x9a), which is confusing the decoder.

Ideally we would only read 8 bytes from the keyboard, but the USB package doesn't support specifying a buffer size and is always trying to read 256 bytes. zserge/hid#11 has a fix, but hasn't been applied yet.

I think we have two options:

  • Use go modules to use the patched version of the USB HID package.
  • When reading from the keyboard, discard everything but the first eight bytes. We might miss responses, but since I don't know how to decode responses yet they're mostly ignored anyway.

I have implemented the second option in #3. Could you give this a try?

Thanks again and best regards, —octo

octo avatar Jun 26 '21 06:06 octo

Thanks for the quick reply!

I'm not sure if this is related or not, but all I'm getting now are timeouts and the keyboard stops working thereafter.

~/Documents/das$ go run ./all-color/
dev.Info() = {9456 8247 256 1 1 0 1 124}
dev.Info() = {9456 8247 256 0 0 1 1 124}
-> SetReport(1, []byte{0x1, 0xea, 0xb, 0x78, 0x3, 0x0, 0x0, 0x0})
-> SetReport(1, []byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x9a, 0x0})
<- GetReport(1) = []byte{0xed, 0x3, 0x78, 0x0, 0x96, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0}
response 0 = [][]uint8{[]uint8{0xed, 0x3, 0x78, 0x0, 0x96}}
-> SetReport(1, []byte{0x1, 0xea, 0x8, 0x78, 0x8, 0x0, 0x1, 0x42})
-> SetReport(1, []byte{0x1, 0x85, 0xf4, 0xa0, 0x0, 0x0, 0x0, 0x0})
-> SetReport(1, []byte{0x1, 0xea, 0xb, 0x78, 0x4, 0x0, 0x1e, 0xbd})
-> SetReport(1, []byte{0x1, 0x7a, 0xb, 0x7, 0xd0, 0x0, 0x98, 0x0})
<- GetReport(1) = connection timed out
2021/06/28 10:17:01 connection timed out
exit status 1

But I do seem to be getting slightly further ahead.

MatthL-SwiftC avatar Jun 28 '21 14:06 MatthL-SwiftC