Skip to content
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

Feature: retrieve strings from device descriptor #97

Open
petrmanek opened this issue Oct 18, 2023 · 2 comments
Open

Feature: retrieve strings from device descriptor #97

petrmanek opened this issue Oct 18, 2023 · 2 comments
Assignees
Labels

Comments

@petrmanek
Copy link
Contributor

Is your feature request related to a problem? Please describe.
I am trying to read device information from the device descriptor (iManufacturer, iProduct, iSerial). In libusb, there is libusb_get_device_descriptor and libusb_get_string_descriptor_ascii but in QtUsb there seems no nice way to do this.

Describe the solution you'd like
QtUsb already uses libusb_get_device_descriptor in QUsb and QUsbDevice but it does not save the descriptor anywhere. I would propose that QUsbDevice is extended with:

  1. A single struct property, say QUsbDeviceDescriptor descriptor(), that is modeled after the structure of struct libusb_device_descriptor (it could possibly be Qt-ified, so as to use QString instead of const char* and the Q_GADGET macro, etc.)
  2. Multiple properties that would have been fields of QUsbDeviceDescriptor, so that user code can access directly device->manufacturer() or device->product() etc.

In the first case, it would be easy to envision that the getter internally calls libusb_get_device_descriptor and just re-arranges returned data into a neater form. In the second case, there would have to be some sort of lazy loading logic implemented (i.e. the first call to device->manufacturer() populates some internal fields, which would also feed other getters). Alternatively, we could just pass the device descriptor first retrieved in QUsb into QUsbDevice's constructor but that may be too much work for a little effect.

Describe alternatives you've considered
I have considered using libusb directly but I think it is never a good idea to bypass an abstraction layer.

Additional context
Here is an example showing how a device descriptor can be retrieved and its contents can be printed.

One more perhaps related issue, while QUsbEndpoint offers the makeControlPacket() function that prepares a buffer for control transfer, it is not clear how large this buffer should be. To this end, libusb defines the LIBUSB_CONTROL_SETUP_SIZE macro, which is unfortunately not accessible because QtUsb does not expose libusb headers to user code. Currently I am working around this by defining the constant in my code, however it would be great if QtUsb could somehow repackage this macro in its interface. Perhaps as a static qsizetype QUsbEndpoint::controlSetupSize(), or even better something that can be used at compile-time, so as to enable the use of templates such as std::array<char, LIBUSB_CONTROL_SETUP_SIZE>.

@petrmanek petrmanek changed the title Feature: retrieve configuration strings Feature: retrieve strings from device descriptor Oct 18, 2023
@petrmanek
Copy link
Contributor Author

@fpoussin Bumping this in case it got lost in the inbox.

@petrmanek
Copy link
Contributor Author

@fpoussin Anyone here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants