20 const auto max_usb_depth = 8;
21 uint8_t usb_ports[max_usb_depth] = {};
22 std::stringstream port_path;
23 auto port_count = libusb_get_port_numbers(usb_device, usb_ports, max_usb_depth);
24 auto usb_dev =
std::to_string(libusb_get_device_address(usb_device));
25 libusb_device_descriptor dev_desc;
26 auto r= libusb_get_device_descriptor(usb_device,&dev_desc);
28 for (
size_t i = 0;
i < port_count; ++
i)
30 port_path <<
std::to_string(usb_ports[
i]) << (((i+1) < port_count)?
".":
"");
33 return usb_bus +
"-" + port_path.str() +
"-" + usb_dev;
38 std::vector<usb_device_info> rv;
39 for (
uint8_t c = 0;
c < desc.bNumConfigurations; ++
c)
41 libusb_config_descriptor *
config =
nullptr;
42 auto ret = libusb_get_config_descriptor(device,
c, &config);
43 if (LIBUSB_SUCCESS != ret)
45 LOG_WARNING(
"failed to read USB config descriptor: error = " << std::dec << ret);
49 for (
uint8_t i = 0;
i < config->bNumInterfaces; ++
i)
51 auto inf = config->interface[
i];
54 if(inf.altsetting->bInterfaceSubClass == 2)
68 info.vid = desc.idVendor;
69 info.pid = desc.idProduct;
75 libusb_free_config_descriptor(config);
82 std::vector<usb_device_info> rv;
83 auto ctx = std::make_shared<usb_context>();
90 libusb_device_descriptor desc{};
93 auto ret = libusb_get_device_descriptor(
device, &desc);
94 if (LIBUSB_SUCCESS == ret)
97 rv.insert(rv.end(),
sd.begin(),
sd.end());
100 LOG_WARNING(
"failed to read USB device descriptor: error = " << std::dec << ret);
107 auto ctx = std::make_shared<usb_context>();
115 libusb_device_descriptor desc{};
116 auto ret = libusb_get_device_descriptor(
device, &desc);
117 if (LIBUSB_SUCCESS == ret)
121 return std::make_shared<usb_device_libusb>(
device, desc,
info,
ctx);
123 catch (std::exception
e)
129 LOG_WARNING(
"failed to read USB device descriptor: error = " << std::dec << ret);
GLsizei const GLchar *const * path
GLsizei const GLchar *const * string
def info(name, value, persistent=False)
std::string to_string(T value)