libhackrf: refactor serial number searching to hackrf_open_usb()
This commit is contained in:

committed by
Heikki Hannikainen

parent
35b9e0bea0
commit
c9f8bb2a05
@ -263,21 +263,14 @@ int ADDCALL hackrf_exit(void)
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
int ADDCALL hackrf_open(const char* const desired_serial_number, hackrf_device** device)
|
||||
libusb_device_handle* hackrf_open_usb(const char* const desired_serial_number)
|
||||
{
|
||||
int result;
|
||||
libusb_device_handle* usb_device;
|
||||
hackrf_device* lib_device;
|
||||
|
||||
if( device == NULL )
|
||||
{
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
|
||||
libusb_device_handle* usb_device = NULL;
|
||||
libusb_device** devices = NULL;
|
||||
const ssize_t list_length = libusb_get_device_list(g_libusb_context, &devices);
|
||||
printf("All devices: %ld\n", list_length);
|
||||
|
||||
printf("Number of USB devices: %ld\n", list_length);
|
||||
|
||||
for (ssize_t i=0; i<list_length; i++) {
|
||||
struct libusb_device_descriptor device_descriptor;
|
||||
libusb_get_device_descriptor(devices[i], &device_descriptor);
|
||||
@ -318,17 +311,35 @@ for(ssize_t i=0; i<list_length; i++) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
libusb_free_device_list(devices, 1);
|
||||
|
||||
// TODO: Do proper scanning of available devices, searching for
|
||||
// unit serial number (if specified?).
|
||||
/*
|
||||
return usb_device;
|
||||
}
|
||||
|
||||
int ADDCALL hackrf_open(const char* const desired_serial_number, hackrf_device** device)
|
||||
{
|
||||
int result;
|
||||
libusb_device_handle* usb_device;
|
||||
hackrf_device* lib_device;
|
||||
|
||||
if( device == NULL )
|
||||
{
|
||||
return HACKRF_ERROR_INVALID_PARAM;
|
||||
}
|
||||
|
||||
if( desired_serial_number )
|
||||
{
|
||||
usb_device = hackrf_open_usb(desired_serial_number);
|
||||
} else {
|
||||
usb_device = libusb_open_device_with_vid_pid(g_libusb_context, hackrf_usb_vid, hackrf_one_usb_pid);
|
||||
}
|
||||
|
||||
if( usb_device == NULL )
|
||||
{
|
||||
usb_device = libusb_open_device_with_vid_pid(g_libusb_context, hackrf_usb_vid, hackrf_jawbreaker_usb_pid);
|
||||
}
|
||||
*/
|
||||
|
||||
if( usb_device == NULL )
|
||||
{
|
||||
return HACKRF_ERROR_NOT_FOUND;
|
||||
|
Reference in New Issue
Block a user