root / host / lib / transport / libusb1_base.hpp @ ad55e25a
History | View | Annotate | Download (4 kB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#ifndef INCLUDED_TRANSPORT_LIBUSB_HPP
|
| 19 |
#define INCLUDED_TRANSPORT_LIBUSB_HPP
|
| 20 |
|
| 21 |
#include <uhd/config.hpp> |
| 22 |
#include <uhd/transport/usb_device_handle.hpp> |
| 23 |
#include <libusb-1.0/libusb.h> |
| 24 |
|
| 25 |
namespace uhd { namespace transport { |
| 26 |
|
| 27 |
namespace libusb {
|
| 28 |
/*
|
| 29 |
* Initialize libusb and set debug level
|
| 30 |
* Takes a pointer to context pointer because that's
|
| 31 |
* how libusb rolls. Debug levels.
|
| 32 |
*
|
| 33 |
* Level 0: no messages ever printed by the library (default)
|
| 34 |
* Level 1: error messages are printed to stderr
|
| 35 |
* Level 2: warning and error messages are printed to stderr
|
| 36 |
* Level 3: informational messages are printed to stdout, warning
|
| 37 |
* and error messages are printed to stderr
|
| 38 |
*
|
| 39 |
* \param ctx pointer to context pointer
|
| 40 |
* \param debug_level
|
| 41 |
*/
|
| 42 |
void init(libusb_context **ctx, int debug_level); |
| 43 |
|
| 44 |
/*
|
| 45 |
* Get a list of Free Software Foundation devices (Vendor ID 0xfffe)
|
| 46 |
* As opposed to the public USB device handle interface, which returns
|
| 47 |
* generic identifiers, this call returns device pointers speficic
|
| 48 |
* to libusb.
|
| 49 |
* \param ctx the libusb context used for init
|
| 50 |
* \return a vector of libusb devices
|
| 51 |
*/
|
| 52 |
std::vector<libusb_device *> get_fsf_device_list(libusb_context *ctx); |
| 53 |
|
| 54 |
/*
|
| 55 |
* Open the device specified by a generic handle
|
| 56 |
* Find the libusb_device cooresponding to the generic handle
|
| 57 |
* and open it for I/O, which returns a libusb_device_handle
|
| 58 |
* ready for an interface
|
| 59 |
* \param ctx the libusb context used for init
|
| 60 |
* \return a libusb_device_handle ready for action
|
| 61 |
*/
|
| 62 |
libusb_device_handle *open_device(libusb_context *ctx, |
| 63 |
usb_device_handle::sptr handle); |
| 64 |
|
| 65 |
/*
|
| 66 |
* Compare a libusb device with a generic handle
|
| 67 |
* Check the descriptors and open the device to check the
|
| 68 |
* serial number string. Compare values against the given
|
| 69 |
* handle. The libusb context is already implied in the
|
| 70 |
* libusb_device.
|
| 71 |
* \param dev a libusb_device pointer
|
| 72 |
* \param handle a generic handle specifier
|
| 73 |
* \return true if handle and device match, false otherwise
|
| 74 |
*/
|
| 75 |
bool compare_device(libusb_device *dev, usb_device_handle::sptr handle);
|
| 76 |
|
| 77 |
/*
|
| 78 |
* Open an interface to the device
|
| 79 |
* This is a logical operation for operating system housekeeping as
|
| 80 |
* nothing is sent over the bus. The interface much correspond
|
| 81 |
* to the USB device descriptors.
|
| 82 |
* \param dev_handle libusb handle to an opened device
|
| 83 |
* \param interface integer of the interface to use
|
| 84 |
* \return true on success, false on error
|
| 85 |
*/
|
| 86 |
bool open_interface(libusb_device_handle *dev_handle, int interface); |
| 87 |
|
| 88 |
/*
|
| 89 |
* Get serial number
|
| 90 |
* The standard USB device descriptor contains an index to an
|
| 91 |
* actual serial number string descriptor. The index is readily
|
| 92 |
* readble, but the string descriptor requires probing the device.
|
| 93 |
* Because this call attempts to open the device, it may not
|
| 94 |
* succeed because not all USB devices are readily opened.
|
| 95 |
* The default language is used for the request (English).
|
| 96 |
* \param dev a libusb_device pointer
|
| 97 |
* \return string serial number or 0 on error or unavailablity
|
| 98 |
*/
|
| 99 |
std::string get_serial(libusb_device *dev);
|
| 100 |
} |
| 101 |
|
| 102 |
}} //namespace
|
| 103 |
|
| 104 |
#endif /* INCLUDED_TRANSPORT_LIBUSB_HPP */ |