Skip to content

Commit

Permalink
hackrf_info: Report whether other devices are sharing the USB bus.
Browse files Browse the repository at this point in the history
  • Loading branch information
martinling committed Sep 26, 2024
1 parent 17f3943 commit f4612c3
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions host/hackrf-tools/src/hackrf_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
*/

#include <hackrf.h>
#include <libusb-1.0/libusb.h>

#include <stdio.h>
#include <stdlib.h>
Expand Down Expand Up @@ -95,6 +96,8 @@ int main(void)
hackrf_device_list_t* list;
hackrf_device* device;
int i, j;
libusb_device *usb_dev, *hackrf_dev;
uint8_t hackrf_bus, other_device_count;

result = hackrf_init();
if (result != HACKRF_SUCCESS) {
Expand Down Expand Up @@ -254,6 +257,31 @@ int main(void)
hackrf_error_name(result),
result);
}

// Count devices that are sharing the USB bus with this HackRF.
hackrf_dev = list->usb_devices[list->usb_device_index[i]];
hackrf_bus = libusb_get_bus_number(hackrf_dev);
other_device_count = 0;
for (j = 0; j < list->usb_devicecount; j++) {
usb_dev = (libusb_device*) list->usb_devices[j];
// 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++;
}
}
if (other_device_count == 0) {
printf("This device is on its own USB bus.\n");
} else {
if (other_device_count == 1) {
printf("There is 1 other device on the same USB bus.\n");
} else {
printf("There are %d other devices on the same USB bus.\n",
other_device_count);
}
printf("You may have problems at high sample rates.\n");
}
}

hackrf_device_list_free(list);
Expand Down

0 comments on commit f4612c3

Please sign in to comment.