Statistics
| Branch: | Tag: | Revision:

root / host / include / uhd / device.hpp @ 8740bc71

History | View | Annotate | Download (5.3 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_UHD_DEVICE_HPP
19
#define INCLUDED_UHD_DEVICE_HPP
20

    
21
#include <uhd/config.hpp>
22
#include <uhd/types/device_addr.hpp>
23
#include <uhd/types/metadata.hpp>
24
#include <uhd/types/io_type.hpp>
25
#include <uhd/wax.hpp>
26
#include <boost/utility.hpp>
27
#include <boost/shared_ptr.hpp>
28
#include <boost/function.hpp>
29
#include <boost/asio/buffer.hpp>
30

    
31
namespace uhd{
32

    
33
/*!
34
 * The usrp device interface represents the usrp hardware.
35
 * The api allows for discovery, configuration, and streaming.
36
 */
37
class UHD_API device : boost::noncopyable, public wax::obj{
38

    
39
public:
40
    typedef boost::shared_ptr<device> sptr;
41
    typedef boost::function<device_addrs_t(const device_addr_t &)> find_t;
42
    typedef boost::function<sptr(const device_addr_t &)> make_t;
43

    
44
    /*!
45
     * Register a device into the discovery and factory system.
46
     *
47
     * \param find a function that discovers devices
48
     * \param make a factory function that makes a device
49
     */
50
    static void register_device(
51
        const find_t &find,
52
        const make_t &make
53
    );
54

    
55
    /*!
56
     * \brief Find usrp devices attached to the host.
57
     *
58
     * The hint device address should be used to narrow down the search
59
     * to particular transport types and/or transport arguments.
60
     *
61
     * \param hint a partially (or fully) filled in device address
62
     * \return a vector of device addresses for all usrps on the system
63
     */
64
    static device_addrs_t find(const device_addr_t &hint);
65

    
66
    /*!
67
     * \brief Create a new usrp device from the device address hint.
68
     *
69
     * The make routine will call find and pick one of the results.
70
     * By default, the first result will be used to create a new device.
71
     * Use the which parameter as an index into the list of results.
72
     *
73
     * \param hint a partially (or fully) filled in device address
74
     * \param which which address to use when multiple are found
75
     * \return a shared pointer to a new device instance
76
     */
77
    static sptr make(const device_addr_t &hint, size_t which = 0);
78

    
79
    /*!
80
     * Send a buffer containing IF data with its metadata.
81
     *
82
     * Send handles fragmentation as follows:
83
     * If the buffer has more samples than the maximum supported,
84
     * the send method will send the maximum number of samples
85
     * as supported by the transport and return the number sent.
86
     * In this case, the end of burst flag will be forced to false.
87
     * It is up to the caller to call send again on the un-sent
88
     * portions of the buffer, until the buffer is exhausted.
89
     *
90
     * This is a blocking call and will not return until the number
91
     * of samples returned have been read out of the buffer.
92
     *
93
     * \param buff a buffer pointing to some read-only memory
94
     * \param metadata data describing the buffer's contents
95
     * \param io_type the type of data loaded in the buffer
96
     * \return the number of samples sent
97
     */
98
    virtual size_t send(
99
        const boost::asio::const_buffer &buff,
100
        const tx_metadata_t &metadata,
101
        const io_type_t &io_type
102
    ) = 0;
103

    
104
    /*!
105
     * Receive a buffer containing IF data and its metadata.
106
     *
107
     * Receive handles fragmentation as follows:
108
     * If the buffer has insufficient space to hold all samples
109
     * that were received in a single packet over-the-wire,
110
     * then the buffer will be completely filled and the implementation
111
     * will hold a pointer into the remaining portion of the packet.
112
     * Subsequent calls will load from the remainder of the packet,
113
     * and will flag the metadata to show that this is a fragment.
114
     * The next call to receive, after the remainder becomes exahausted,
115
     * will perform an over-the-wire receive as usual.
116
     * See the rx metadata fragment flags and offset fields for details.
117
     *
118
     * This is a blocking call and will not return until the number
119
     * of samples returned have been written into the buffer.
120
     * However, a call to receive may timeout and return zero samples.
121
     * The timeout duration is decided by the underlying transport layer.
122
     * The caller should assume that the call to receive will not return
123
     * immediately when no packets are available to the transport layer,
124
     * and that the timeout duration is reasonably tuned for performance.
125
     *
126
     * \param buff the buffer to fill with IF data
127
     * \param metadata data to fill describing the buffer
128
     * \param io_type the type of data to fill into the buffer
129
     * \return the number of samples received
130
     */
131
    virtual size_t recv(
132
        const boost::asio::mutable_buffer &buff,
133
        rx_metadata_t &metadata,
134
        const io_type_t &io_type
135
    ) = 0;
136
};
137

    
138
} //namespace uhd
139

    
140
#endif /* INCLUDED_UHD_DEVICE_HPP */