-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Refactor USB Communication: Implement Multiple Buffers and Remove Read Timeouts #614
base: master
Are you sure you want to change the base?
Conversation
Now it just shutting down itself, like before.
I wasn't aware that one can queue multiple requests on the same endpoint. Do you have numbers for the performance improvement? I ran tests against real devices. These showed that On recent Android versions I could observe that buffers are used round-robin. I will check with older versions too. |
crashes on Android 5.0 at |
More classic approach to inject mocked `UsbRequest`
added some additional error checks if length 0 is returned
Hi @kai-morich, Thanks for reviewing the changes! The refactor was driven by my work transferring audio through USB serial in this project, where we faced issues with USB stack inserting zeros, especially with CP2102 "S1LABS" variants. Despite using a 16k buffer and separate thread processing, sporadic zero-filled chunks persisted. Implementing multiple small buffers fixed the issue and reduced latency, which is crucial for audio. I’ve also addressed your suggestions: removed the Supplier for older Android compatibility and added error checks for length 0 returns. Regarding the suggestion to move the logic to UsbSerialPort, I believe keeping SerialInputOutputManager is more appropriate. Since SerialInputOutputManager provides async functionality through callbacks, it is more logical to use the Android UsbRequest.queue(...) API there. UsbSerialPort provides blocking operations via .read() and .write(), so using UsbConnection.bulkTransfer(...) there is more appropriate. Mixing these would reduce clarity, so separating them maintains a clear distinction between async and blocking operations. |
Make .stop() async
Hi @kai-morich By aligning the behavior of .stop() with the existing design, the issue of .stop() hanging should now be addressed. Regarding the zero-length checks, I found them likely redundant from this perspective. However, I decided to retain them in the PR to ensure consistency with the rest of the implementation and to safeguard against any unexpected edge cases. BTW: I also kept |
please split the PR
If called by SerialInputOutputManager very likely has to be reconfigurable while the connection is open. Adding requests could be done immediately, for removing might be better to not re-queue them at the end of read(). I always prefer if everybody could benefit from optimizations without having to enable explicitly. Would a default re-queue at the end of read() have impact on applications only doing ocasional reads, e.g. then returning oldest instead of newest data? |
Hi @kai-morich Thanks for the suggestions! I have a concern about pre-filling the request queue in I was thinking about adding a dedicated async API in What would you recommend for managing the queue without causing issues with control requests or making things too complicated? |
Also, you mentioned FTDI post-processing and error checks—could you clarify which checks you're referring to and why they’re important to include in this flow? |
I have an idea for lightweight integration into |
Hey @kai-morich , I’ve pulled in the latest upstream changes to keep things up-to-date. Can you also share how to run the integration tests for this? Would be great to verify everything’s working as expected. |
here you can find instructions to run the integration tests |
@kai-morich The "wrongDriver()" actually crashing usb stack and "dataBits()" crashing |
Doesn't look that bad. A few tests are always flaky. I enhanced the wiki page with missing control line loop-back connection. What does wrongDriver crash? USB stack of Android or serial device. As some serial devices do not recover from this test I already excluded some combinations. Where do you run rfc2217 server? I use Linux on Raspi. What is the actual error? |
Hi @kai-morich |
|
|
you might have to change this setting:
|
Hi @kai-morich, Looks like I've fixed the integration tests to the same level of flakiness as before. Any updates on your idea of lightweight integration? |
Refactored
SerialInputOutputManager
:These changes enhance the responsiveness, reliability, and robustness of USB communication.