Skip to content

Feature: retrieve strings from device descriptor #97

@petrmanek

Description

@petrmanek

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>.

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions