Statistics
| Branch: | Tag: | Revision:

root / host / lib / transport / libusb1_base.hpp @ b96088b6

History | View | Annotate | Download (3.6 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
     * Open the device specified by a generic handle
46
     * Find the libusb_device cooresponding to the generic handle
47
     * and open it for I/O, which returns a libusb_device_handle
48
     * ready for an interface
49
     * \param ctx the libusb context used for init
50
     * \return a libusb_device_handle ready for action 
51
     */
52
    libusb_device_handle *open_device(libusb_context *ctx,
53
                                      usb_device_handle::sptr handle);
54

    
55
    /*
56
     * Compare a libusb device with a generic handle 
57
     * Check the descriptors and open the device to check the
58
     * serial number string. Compare values against the given
59
     * handle. The libusb context is already implied in the
60
     * libusb_device.
61
     * \param dev a libusb_device pointer
62
     * \param handle a generic handle specifier
63
     * \return true if handle and device match, false otherwise
64
     */
65
    bool compare_device(libusb_device *dev, usb_device_handle::sptr handle);
66

    
67
    /*
68
     * Open an interface to the device
69
     * This is a logical operation for operating system housekeeping as
70
     * nothing is sent over the bus. The interface much correspond
71
     * to the USB device descriptors.
72
     * \param dev_handle libusb handle to an opened device
73
     * \param interface integer of the interface to use
74
     * \return true on success, false on error
75
     */
76
    bool open_interface(libusb_device_handle *dev_handle, int interface);
77

    
78
    /*
79
     * Get serial number 
80
     * The standard USB device descriptor contains an index to an
81
     * actual serial number string descriptor. The index is readily
82
     * readble, but the string descriptor requires probing the device.
83
     * Because this call attempts to open the device, it may not
84
     * succeed because not all USB devices are readily opened.
85
     * The default language is used for the request (English).
86
     * \param dev a libusb_device pointer
87
     * \return string serial number or 0 on error or unavailablity
88
     */
89
    std::string get_serial(libusb_device *dev);
90
}
91

    
92
}} //namespace
93

    
94
#endif /* INCLUDED_TRANSPORT_LIBUSB_HPP */