rs usb api and implementations added#3828
Conversation
|
|
||
| std::shared_ptr<usb_device> android_backend::create_usb_device(usb_device_info info) const { | ||
| throw std::runtime_error("create_usb_device Not supported"); | ||
| std::shared_ptr<command_transfer> android_backend::create_usb_device(usb_device_info info) const { |
There was a problem hiding this comment.
The method create_usb_device returns command_transfer ?
If so - please use "_dev" suffix as command_transfer is too vague
Also is this intended to work with non-Realsense devices, such as platform cam ?
There was a problem hiding this comment.
the original usb_device was an empty class which inherited command_transfer, since I removed usb_device I needed to replace it with command_transfer but I don't want to make more changes to the backend API in this PR unless it is necessary .
| } | ||
|
|
||
| std::vector<usb_device_info> android_backend::query_usb_devices() const { | ||
| std::vector<usb_device_info> results; |
There was a problem hiding this comment.
Pls change the name to query_usb_devices_**info** for consistency
|
|
||
| std::shared_ptr<device_watcher> android_backend::create_device_watcher() const { | ||
| return std::make_shared<usb_host::device_watcher>(); | ||
| return device_watcher_usbhost::instance(); |
There was a problem hiding this comment.
There should be no need to wrap a singleton with shared_ptr.
There was a problem hiding this comment.
I need to implement the backend API:
std::shared_ptr<device_watcher> create_device_watcher() const override;
| uvc->vid = dev->get_info().vid; | ||
| uvc->pid = dev->get_info().pid; | ||
| usbhost_open(uvc.get(), mi); | ||
| return uvc; |
There was a problem hiding this comment.
This function will open the first device with matched MI. How can one query the 2nd or 3rd device ?
| if (device->deviceData.ctrl_if.bInterfaceNumber == mi) { | ||
| _device = device; | ||
| if (state == D0 && _power_state == D3) { | ||
| uint16_t vid = _info.vid, pid = _info.pid, mi = _info.mi; |
There was a problem hiding this comment.
vid/pid seem unused in this segment - pls recheck
| { | ||
| auto i = entry.second; | ||
| if(filter == USB_SUBCLASS_ANY || | ||
| i->get_subclass() & filter || |
There was a problem hiding this comment.
function will be removed
|
|
||
| virtual const usb_device_info get_info() const override { return _infos[0]; } | ||
| virtual const std::vector<usb_device_info> get_subdevices_infos() const override { return _infos; } | ||
| virtual const rs_usb_interface get_interface(uint8_t interface_number) const override { return _interfaces.at(interface_number); } |
There was a problem hiding this comment.
This will throw if the index is not in the map
There was a problem hiding this comment.
get_interface(uint8_t interface_number) will be removed, leaving only get_interfaces()
| libusb_device_descriptor desc = { 0 }; | ||
|
|
||
| auto rc = libusb_get_device_descriptor(lusb_device, &desc); | ||
| if (desc.idVendor != 0x8086) |
There was a problem hiding this comment.
For review - probably requires some sort of a mask - T265 , etc'
Log the devices that are filtered out
There was a problem hiding this comment.
devices are filtered on context.cpp via pick__devices
I have also removed the 0x8086 filter
| break; | ||
| } | ||
| } | ||
| libusb_free_device_list(list, 0); |
There was a problem hiding this comment.
A common pattern in this and the next functions:
libusb_get_device_list
...
libusb_free_device_list
- Needs a common RAII support
| class handle_libusb | ||
| { | ||
| public: | ||
| handle_libusb(libusb_device* device, uint8_t interface, int timeout_ms = 100) : |
There was a problem hiding this comment.
Add a comment how this value was selected
There was a problem hiding this comment.
timeout will be removed from the handle signature
|
|
||
| } | ||
|
|
||
| bool usb_messenger_libusb::reset_endpoint(std::shared_ptr<usb_endpoint> endpoint) |
| if(rv) | ||
| LOG_DEBUG("USB pipe " << ep << " reset successfully"); | ||
| else | ||
| LOG_DEBUG("Failed to reset the USB pipe " << ep); |
There was a problem hiding this comment.
The actual result of the transfer is not registered (reduced to bool) will make it harder for debugging and maintenance
There was a problem hiding this comment.
usb status added to the log
ev-mp
left a comment
There was a problem hiding this comment.
A huge transformation.
We'll need multiple things to review and polish.
The one thing - the class diagram should clearly depict the inheritance tree with all the interfaces and concrete classes. It is very hard to navigate otherwise
|
|
||
| int usb_messenger_libusb::control_transfer(int request_type, int request, int value, int index, uint8_t* buffer, uint32_t length, uint32_t timeout_ms) | ||
| { | ||
| handle_libusb handle(_device->get_device(), index & 0xFF, timeout_ms); |
There was a problem hiding this comment.
Please either perform a static_cast or add a note that the actual index is within 0-255.
You also need to check the input against things such as 0xabcd0011, which could be interpret as 0x11 without checking the higher bits
There was a problem hiding this comment.
the upper bytes are required for control transfer, the mask is extracting the interface number
| return rv; | ||
| } | ||
|
|
||
| int usb_messenger_libusb::bulk_transfer(const std::shared_ptr<usb_endpoint>& endpoint, uint8_t* buffer, uint32_t length, uint32_t timeout_ms) |
There was a problem hiding this comment.
PLs make the in and out length param type identical (preferably int)
There was a problem hiding this comment.
returned value replaced with usb status
| } | ||
|
|
||
| std::shared_ptr<usb_device> wmf_backend::create_usb_device(usb_device_info info) const | ||
| std::shared_ptr<command_transfer> wmf_backend::create_usb_device(usb_device_info info) const |
There was a problem hiding this comment.
I prefer to avoid changes to the backend API at this point
| { | ||
| auto dev = _source->create_usb_device(info); | ||
|
|
||
| @@ -1136,7 +1136,7 @@ namespace librealsense | |||
| return _rec->load_uvc_device_info_list(); | |||
| for (auto&& entry : _interfaces) | ||
| { | ||
| auto i = entry.second; | ||
| if(filter == USB_SUBCLASS_ANY || |
There was a problem hiding this comment.
This code is multiplied several times (counted 3) - can it be refactored?
| virtual endpoint_type get_type() const override { return _type; } | ||
| virtual endpoint_direction get_direction() const override | ||
| { | ||
| return _address >= USB_ENDPOINT_DIRECTION_READ ? |
| return false; | ||
| for (auto&& guid : guids) | ||
| { | ||
| for (auto&& id : query_by_interface(guid, L"8086")) |
There was a problem hiding this comment.
The 8086 mask may not recognize T265
There was a problem hiding this comment.
will remove the filter
|
|
||
| for (auto&& guid : guids) | ||
| { | ||
| for (auto&& id : query_by_interface(guid, L"8086")) |
|
|
||
| switch (devices.size()) | ||
| { | ||
| case 0: printf("\nno USB device found\n\n"); break; |
There was a problem hiding this comment.
This case will not be invoked - terminated on previous REQUIRE(devices.size());
This PR creates a common USB API for the different operating systems.
As first step this API will be used for cross platform FW update API and tools.
In the future this infrastructure will allow single implementation for UVC/HID/TM2 for all the supported operating systems.
DSO-10947