messenger-usbhost.cpp
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2015 Intel Corporation. All Rights Reserved.
3 
4 #include "messenger-usbhost.h"
5 #include "device-usbhost.h"
6 #include "../usb/usb-enumerator.h"
7 #include "../hw-monitor.h"
8 #include "usbhost.h"
9 #include "endpoint-usbhost.h"
10 #include "interface-usbhost.h"
11 #include "../uvc/uvc-types.h"
12 #include "request-usbhost.h"
13 
14 #include <string>
15 #include <regex>
16 #include <sstream>
17 #include <mutex>
18 
19 #define CLEAR_FEATURE 0x01
20 #define UVC_FEATURE 0x02
21 
22 namespace librealsense
23 {
24  namespace platform
25  {
26  usb_messenger_usbhost::usb_messenger_usbhost(const std::shared_ptr<usb_device_usbhost>& device,
27  std::shared_ptr<handle_usbhost> handle)
28  : _device(device), _handle(handle)
29  {
30 
31  }
32 
34  {
35 
36  }
37 
39  {
40  uint32_t transferred = 0;
41  int requestType = UVC_FEATURE;
42  int request = CLEAR_FEATURE;
43  int value = 0;
44  int ep = endpoint->get_address();
45  uint8_t* buffer = NULL;
46  int length = 0;
47  usb_status rv = control_transfer(requestType, request, value, ep, buffer, length, transferred, timeout_ms);
48  if(rv == RS2_USB_STATUS_SUCCESS)
49  LOG_INFO("USB pipe " << ep << " reset successfully");
50  else
51  LOG_WARNING("Failed to reset the USB pipe " << ep << ", error: " << usb_status_to_string.at(rv).c_str());
52  return rv;
53  }
54 
55  usb_status usb_messenger_usbhost::control_transfer(int request_type, int request, int value, int index, uint8_t* buffer, uint32_t length, uint32_t& transferred, uint32_t timeout_ms)
56  {
57  auto sts = usb_device_control_transfer(_device->get_handle(), request_type, request, value, index, buffer, length, timeout_ms);
58  if(sts < 0)
59  {
60  std::string strerr = strerror(errno);
61  LOG_WARNING("control_transfer returned error, index: " << index << ", error: " << strerr << ", number: " << (int)errno);
62  return usbhost_status_to_rs(errno);
63  }
64  transferred = sts;
66  }
67 
68  usb_status usb_messenger_usbhost::bulk_transfer(const std::shared_ptr<usb_endpoint>& endpoint, uint8_t* buffer, uint32_t length, uint32_t& transferred, uint32_t timeout_ms)
69  {
70  auto sts = usb_device_bulk_transfer(_device->get_handle(), endpoint->get_address(), buffer, length, timeout_ms);
71  if(sts < 0)
72  {
73  std::string strerr = strerror(errno);
74  LOG_WARNING("bulk_transfer returned error, endpoint: " << (int)endpoint->get_address() << ", error: " << strerr << ", number: " << (int)errno);
75  return usbhost_status_to_rs(errno);
76  }
77  transferred = sts;
79  }
80 
82  {
83  auto rv = std::make_shared<usb_request_usbhost>(_device, endpoint);
84  rv->set_shared(rv);
85  return rv;
86  }
87 
89  {
90  return _device->submit_request(request);
91  }
92 
94  {
95  return _device->cancel_request(request);
96  }
97  }
98 }
#define CLEAR_FEATURE
usb_messenger_usbhost(const std::shared_ptr< usb_device_usbhost > &device, std::shared_ptr< handle_usbhost > handle)
virtual usb_status reset_endpoint(const rs_usb_endpoint &endpoint, uint32_t timeout_ms) override
std::shared_ptr< usb_request > rs_usb_request
Definition: usb-request.h:41
static usb_status usbhost_status_to_rs(int sts)
#define UVC_FEATURE
#define LOG_WARNING(...)
Definition: src/types.h:241
GLuint64 GLenum void * handle
Definition: glext.h:7785
GLfloat value
virtual usb_status cancel_request(const rs_usb_request &request) override
GLsizei const GLchar *const * string
unsigned char uint8_t
Definition: stdint.h:78
GLenum GLfloat * buffer
enum librealsense::platform::_usb_status usb_status
static std::map< usb_status, std::string > usb_status_to_string
Definition: usb-types.h:162
GLuint index
virtual usb_status submit_request(const rs_usb_request &request) override
unsigned int uint32_t
Definition: stdint.h:80
std::shared_ptr< usb_endpoint > rs_usb_endpoint
Definition: usb-endpoint.h:24
std::shared_ptr< usb_device_usbhost > _device
virtual rs_usb_request create_request(rs_usb_endpoint endpoint) override
LOG_INFO("Log message using LOG_INFO()")
virtual usb_status bulk_transfer(const std::shared_ptr< usb_endpoint > &endpoint, uint8_t *buffer, uint32_t length, uint32_t &transferred, uint32_t timeout_ms) override
int usb_device_control_transfer(struct usb_device *device, int requestType, int request, int value, int index, void *buffer, int length, unsigned int timeout)
Definition: usbhost.c:640
#define NULL
Definition: tinycthread.c:47
GLenum GLuint GLenum GLsizei length
int usb_device_bulk_transfer(struct usb_device *device, int endpoint, void *buffer, unsigned int length, unsigned int timeout)
Definition: usbhost.c:666
virtual usb_status control_transfer(int request_type, int request, int value, int index, uint8_t *buffer, uint32_t length, uint32_t &transferred, uint32_t timeout_ms) override


librealsense2
Author(s): Sergey Dorodnicov , Doron Hirshberg , Mark Horn , Reagan Lopez , Itay Carpis
autogenerated on Mon May 3 2021 02:47:21