6 #include <libusb-1.0/libusb.h> 14 , m_idVendor(idVendor)
15 , m_idProduct(idProduct)
17 int result = libusb_init(&m_ctx);
18 if (result != LIBUSB_SUCCESS) {
19 throw std::runtime_error(libusb_error_name(result));
27 libusb_release_interface(
m_handle, 0);
42 int result = libusb_init(&ctx);
43 if (result != LIBUSB_SUCCESS) {
44 throw std::runtime_error(libusb_error_name(result));
49 ssize_t cnt = libusb_get_device_list(NULL, &list);
54 throw std::runtime_error(
"Error during get_device_list");
56 for (i = 0; i < cnt; i++) {
57 libusb_device *device = list[i];
58 libusb_device_descriptor deviceDescriptor;
59 err = libusb_get_device_descriptor(device, &deviceDescriptor);
60 if (err != LIBUSB_SUCCESS) {
61 libusb_free_device_list(list, 1);
62 throw std::runtime_error(libusb_error_name(err));
64 else if (deviceDescriptor.idVendor == idVendor &&
65 deviceDescriptor.idProduct == idProduct) {
69 libusb_free_device_list(list, 1);
82 libusb_device *found = NULL;
83 ssize_t cnt = libusb_get_device_list(NULL, &list);
88 throw std::runtime_error(
"Error during get_device_list");
90 for (i = 0; i < cnt; i++) {
91 libusb_device *device = list[i];
92 libusb_device_descriptor deviceDescriptor;
93 err = libusb_get_device_descriptor(device, &deviceDescriptor);
94 if (err != LIBUSB_SUCCESS) {
95 libusb_free_device_list(list, 1);
96 throw std::runtime_error(libusb_error_name(err));
98 else if (deviceDescriptor.idVendor ==
m_idVendor &&
100 if (foundid == devid) {
108 err = libusb_open(found, &
m_handle);
109 if (err != LIBUSB_SUCCESS) {
110 libusb_free_device_list(list, 1);
111 throw std::runtime_error(libusb_error_name(err));
113 libusb_device_descriptor deviceDescriptor;
114 err = libusb_get_device_descriptor(found, &deviceDescriptor);
115 if (err != LIBUSB_SUCCESS) {
116 throw std::runtime_error(libusb_error_name(err));
118 std::stringstream sstr;
119 sstr << std::hex << (deviceDescriptor.bcdDevice >> 8) <<
"." << (deviceDescriptor.bcdDevice & 0xFF);
122 libusb_free_device_list(list, 1);
127 err = libusb_set_configuration(
m_handle, 1);
128 if (err != LIBUSB_SUCCESS) {
129 throw std::runtime_error(libusb_error_name(err));
132 err = libusb_claim_interface(
m_handle, 0);
133 if (err != LIBUSB_SUCCESS) {
134 throw std::runtime_error(libusb_error_name(err));
139 std::stringstream sstr;
140 sstr <<
"No matching USB Device with devid = " << devid <<
" found! Do you have a Crazyradio dongle connected?";
141 throw std::runtime_error(sstr.str());
149 const unsigned char*
data,
153 throw std::runtime_error(
"No valid device handle!");
156 int status = libusb_control_transfer(
158 LIBUSB_REQUEST_TYPE_VENDOR,
162 (
unsigned char*)data,
165 if (status != LIBUSB_SUCCESS) {
166 throw std::runtime_error(libusb_error_name(status));
static uint32_t numDevices(uint16_t idVendor, uint16_t idProduct)
void sendVendorSetup(uint8_t request, uint16_t value, uint16_t index, const unsigned char *data, uint16_t length)
crtpParamTocGetItemRequest request
void open(uint32_t devid)
USBDevice(uint16_t idVendor, uint16_t idProduct)
libusb_device_handle * m_handle