Skip to content

Some fixes#1

Open
cstrahan wants to merge 5 commits intoantage:masterfrom
cstrahan:master
Open

Some fixes#1
cstrahan wants to merge 5 commits intoantage:masterfrom
cstrahan:master

Conversation

@cstrahan
Copy link
Copy Markdown

Hello,

Thanks for writing this crate!

Unfortunately, I ran into a couple problems:

  1. I couldn't open my device -- I believe I was running into this problem here: I'm getting NotFound error when trying to open a HID device. meh/rust-hid#6
  2. After I swapped out hid for hidapi, I ran into an issue where read would request N bytes from the HID layer, which would return a buffer wherein buffer[0] (i.e. the RX FIFO report length) -- call it M -- was such that M > N. This would then entail writing more bytes to data than data.len(), causing a panic.
  3. The logic was reversed for read's timeout.

To resolve No. 2, I did the only thing I could think of: create a buffer within HidUart that can handle the worst case scenario of up to the max report length being unused; subsequent reads would first drain that buffer before hitting the HID layer. (Admittedly I could save a couple bytes -- INTERRUPT_REPORT_LENGTH isn't strictly necessary, since one byte from the report is always the length, and we'll always read at least one byte (otherwise we wouldn't have requested the report in the first place) -- so something like INTERRUPT_REPORT_LENGTH - 2 for this buffer's size should suffice, but I figured I'd keep it simple).

Hopefully the other changes are pretty straightforward, but I'd be happy to answer any questions and/or implement any feedback.

I'm currently using this branch while I develop my ut61e-rs crate, which provides a means for reading measurement messages from the UT61E digital multi-meter, and it's going well so far, for what that's worth.

cstrahan added 5 commits July 30, 2023 00:43
When we call read_timeout to fill the report buffer,
if we specify a size smaller than the max input report length,
the report can become truncated. The report will indicate that
it has length M, where the read size is N; when M > N,
the data would be lost.

So we need to buffer up to the max input report length to avoid
losing data.

This also fixes a bug that resulted in a panic: the existing code
might try to fill the last N bytes of the data output buffer,
while in actuality attempting to write M bytes to the data slice,
resulting in an out-of-range panic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant