Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report whether other devices are sharing the USB bus #1484

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions host/hackrf-tools/src/hackrf_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 24 additions & 0 deletions host/libhackrf/src/hackrf.c
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,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)
Expand Down
12 changes: 12 additions & 0 deletions host/libhackrf/src/hackrf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down