libhackrf: refactor serial number searching to hackrf_open_usb()

This commit is contained in:
Heikki Hannikainen
2015-02-23 21:31:31 +02:00
committed by Heikki Hannikainen
parent 35b9e0bea0
commit c9f8bb2a05

View File

@ -263,22 +263,15 @@ 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;
libusb_device_handle* usb_device = NULL;
libusb_device** devices = NULL;
const ssize_t list_length = libusb_get_device_list(g_libusb_context, &devices);
if( device == NULL )
{
return HACKRF_ERROR_INVALID_PARAM;
}
printf("Number of USB devices: %ld\n", list_length);
libusb_device** devices = NULL;
const ssize_t list_length = libusb_get_device_list(g_libusb_context, &devices);
printf("All devices: %ld\n", list_length);
for(ssize_t i=0; i<list_length; i++) {
for (ssize_t i=0; i<list_length; i++) {
struct libusb_device_descriptor device_descriptor;
libusb_get_device_descriptor(devices[i], &device_descriptor);
if( device_descriptor.idVendor == hackrf_usb_vid ) {
@ -317,18 +310,36 @@ 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?).
/*
libusb_free_device_list(devices, 1);
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;