File tree 3 files changed +53
-0
lines changed
3 files changed +53
-0
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,23 @@ int main(void)
254
254
hackrf_error_name (result ),
255
255
result );
256
256
}
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
+ }
257
274
}
258
275
259
276
hackrf_device_list_free (list );
Original file line number Diff line number Diff line change @@ -860,6 +860,30 @@ int ADDCALL hackrf_device_list_open(
860
860
return hackrf_open_setup (usb_device , device );
861
861
}
862
862
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
+
863
887
int ADDCALL hackrf_set_transceiver_mode (
864
888
hackrf_device * device ,
865
889
hackrf_transceiver_mode value )
Original file line number Diff line number Diff line change @@ -1106,6 +1106,18 @@ extern ADDAPI int ADDCALL hackrf_device_list_open(
1106
1106
int idx ,
1107
1107
hackrf_device * * device );
1108
1108
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
+
1109
1121
/**
1110
1122
* Free a previously allocated @ref hackrf_device_list list.
1111
1123
* @param[in] list list to free
You can’t perform that action at this time.
0 commit comments