mirror of
https://github.com/greatscottgadgets/hackrf.git
synced 2026-03-03 05:55:18 +01:00
Merge pull request #1484 from martinling/warn-bus-sharing
Report whether other devices are sharing the USB bus
This commit is contained in:
@@ -254,6 +254,23 @@ int main(void)
|
||||
hackrf_error_name(result),
|
||||
result);
|
||||
}
|
||||
|
||||
result = hackrf_device_list_bus_sharing(list, i);
|
||||
if (result < 0) {
|
||||
fprintf(stderr,
|
||||
"hackrf_device_list_bus_sharing() failed: %s (%d)\n",
|
||||
hackrf_error_name(result),
|
||||
result);
|
||||
} else if (result == 0) {
|
||||
printf("This device is on its own USB bus.\n");
|
||||
} else if (result == 1) {
|
||||
printf("There is 1 other device on the same USB bus.\n"
|
||||
"You may have problems at high sample rates.\n");
|
||||
} else {
|
||||
printf("There are %d other devices on the same USB bus.\n"
|
||||
"You may have problems at high sample rates.\n",
|
||||
result);
|
||||
}
|
||||
}
|
||||
|
||||
hackrf_device_list_free(list);
|
||||
|
||||
@@ -862,6 +862,30 @@ int ADDCALL hackrf_device_list_open(
|
||||
return hackrf_open_setup(usb_device, device);
|
||||
}
|
||||
|
||||
int ADDCALL hackrf_device_list_bus_sharing(hackrf_device_list_t* list, int idx)
|
||||
{
|
||||
libusb_device *usb_dev, *hackrf_dev;
|
||||
uint8_t hackrf_bus;
|
||||
int other_device_count = 0;
|
||||
int i;
|
||||
if (list == NULL || list->usb_devices == NULL || list->usb_device_index == NULL ||
|
||||
idx < 0 || idx > list->devicecount) {
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
hackrf_dev = list->usb_devices[list->usb_device_index[idx]];
|
||||
hackrf_bus = libusb_get_bus_number(hackrf_dev);
|
||||
for (i = 0; i < list->usb_devicecount; i++) {
|
||||
usb_dev = (libusb_device*) list->usb_devices[i];
|
||||
// Don't count the HackRF, devices on other buses, or the root hub.
|
||||
if (usb_dev != hackrf_dev &&
|
||||
libusb_get_bus_number(usb_dev) == hackrf_bus &&
|
||||
libusb_get_parent(usb_dev) != NULL) {
|
||||
other_device_count++;
|
||||
}
|
||||
}
|
||||
return other_device_count;
|
||||
}
|
||||
|
||||
int ADDCALL hackrf_set_transceiver_mode(
|
||||
hackrf_device* device,
|
||||
hackrf_transceiver_mode value)
|
||||
|
||||
@@ -1106,6 +1106,18 @@ extern ADDAPI int ADDCALL hackrf_device_list_open(
|
||||
int idx,
|
||||
hackrf_device** device);
|
||||
|
||||
/**
|
||||
* Check if a listed HackRF device is sharing its USB bus with other devices.
|
||||
*
|
||||
* @param[in] list device list to query
|
||||
* @param[in] idx index of the HackRF device in the list
|
||||
* @return The number of devices sharing the USB bus with the specified HackRF, or a negative error code from @ref hackrf_error
|
||||
*
|
||||
*/
|
||||
extern ADDAPI int ADDCALL hackrf_device_list_bus_sharing(
|
||||
hackrf_device_list_t* list,
|
||||
int idx);
|
||||
|
||||
/**
|
||||
* Free a previously allocated @ref hackrf_device_list list.
|
||||
* @param[in] list list to free
|
||||
|
||||
Reference in New Issue
Block a user