Skip to content

Commit 44cff98

Browse files
committed
Report whether other devices are sharing the USB bus.
1 parent 17f3943 commit 44cff98

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

host/hackrf-tools/src/hackrf_info.c

+17
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,23 @@ int main(void)
254254
hackrf_error_name(result),
255255
result);
256256
}
257+
258+
result = hackrf_device_list_bus_sharing(list, i);
259+
if (result < 0) {
260+
fprintf(stderr,
261+
"hackrf_device_list_bus_sharing() failed: %s (%d)\n",
262+
hackrf_error_name(result),
263+
result);
264+
} else if (result == 0) {
265+
printf("This device is on its own USB bus.\n");
266+
} else if (result == 1) {
267+
printf("There is 1 other device on the same USB bus.\n"
268+
"You may have problems at high sample rates.\n");
269+
} else {
270+
printf("There are %d other devices on the same USB bus.\n"
271+
"You may have problems at high sample rates.\n",
272+
result);
273+
}
257274
}
258275

259276
hackrf_device_list_free(list);

host/libhackrf/src/hackrf.c

+24
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,30 @@ int ADDCALL hackrf_device_list_open(
860860
return hackrf_open_setup(usb_device, device);
861861
}
862862

863+
int ADDCALL hackrf_device_list_bus_sharing(hackrf_device_list_t* list, int idx)
864+
{
865+
libusb_device *usb_dev, *hackrf_dev;
866+
uint8_t hackrf_bus;
867+
int other_device_count = 0;
868+
int i;
869+
if (list == NULL || list->usb_devices == NULL || list->usb_device_index == NULL ||
870+
idx < 0 || idx > list->devicecount) {
871+
return HACKRF_ERROR_INVALID_PARAM;
872+
}
873+
hackrf_dev = list->usb_devices[list->usb_device_index[idx]];
874+
hackrf_bus = libusb_get_bus_number(hackrf_dev);
875+
for (i = 0; i < list->usb_devicecount; i++) {
876+
usb_dev = (libusb_device*) list->usb_devices[i];
877+
// Don't count the HackRF, devices on other buses, or the root hub.
878+
if (usb_dev != hackrf_dev &&
879+
libusb_get_bus_number(usb_dev) == hackrf_bus &&
880+
libusb_get_parent(usb_dev) != NULL) {
881+
other_device_count++;
882+
}
883+
}
884+
return other_device_count;
885+
}
886+
863887
int ADDCALL hackrf_set_transceiver_mode(
864888
hackrf_device* device,
865889
hackrf_transceiver_mode value)

host/libhackrf/src/hackrf.h

+12
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,18 @@ extern ADDAPI int ADDCALL hackrf_device_list_open(
11061106
int idx,
11071107
hackrf_device** device);
11081108

1109+
/**
1110+
* Check if a listed HackRF device is sharing its USB bus with other devices.
1111+
*
1112+
* @param[in] list device list to query
1113+
* @param[in] idx index of the HackRF device in the list
1114+
* @return The number of devices sharing the USB bus with the specified HackRF, or a negative error code from @ref hackrf_error
1115+
*
1116+
*/
1117+
extern ADDAPI int ADDCALL hackrf_device_list_bus_sharing(
1118+
hackrf_device_list_t* list,
1119+
int idx);
1120+
11091121
/**
11101122
* Free a previously allocated @ref hackrf_device_list list.
11111123
* @param[in] list list to free

0 commit comments

Comments
 (0)