GNU Radio Manual and C++ API Reference  3.7.9.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
usrp_source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010-2015 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 #ifndef INCLUDED_GR_UHD_USRP_SOURCE_H
24 #define INCLUDED_GR_UHD_USRP_SOURCE_H
25 
27 
28 // TODO In 3.8, UHD 3.6 will be required and we can remove all these ifdefs
29 #ifndef INCLUDED_UHD_STREAM_HPP
30 namespace uhd {
31  struct GR_UHD_API stream_args_t
32  {
33  stream_args_t(const std::string &cpu = "",
34  const std::string &otw = "")
35  {
36  cpu_format = cpu;
37  otw_format = otw;
38  }
39  std::string cpu_format;
40  std::string otw_format;
41  device_addr_t args;
42  std::vector<size_t> channels;
43  };
44 }
45 # define INCLUDED_UHD_STREAM_HPP
46 #else
47 # define GR_UHD_USE_STREAM_API
48 #endif
49 
50 namespace gr {
51  namespace uhd {
52 
53  class uhd_usrp_source;
54 
55  /*! USRP Source -- Radio Receiver
56  * \ingroup uhd_blk
57  *
58  * The USRP source block receives samples and writes to a stream.
59  * The source block also provides API calls for receiver settings.
60  * See also gr::uhd::usrp_block for more public API calls.
61  *
62  * RX Stream tagging:
63  *
64  * The following tag keys will be produced by the work function:
65  * - pmt::string_to_symbol("rx_time")
66  *
67  * The timestamp tag value is a pmt tuple of the following:
68  * (uint64 seconds, and double fractional seconds).
69  * A timestamp tag is produced at start() and after overflows.
70  *
71  * \section uhd_rx_command_iface Command interface
72  *
73  * This block has a message port, which consumes UHD PMT commands.
74  * For a description of the command syntax, see Section \ref uhd_command_syntax.
75  *
76  * For a more general description of the gr-uhd components, see \ref page_uhd.
77  *
78  */
79  class GR_UHD_API usrp_source : virtual public usrp_block
80  {
81  public:
82  // gr::uhd::usrp_source::sptr
83  typedef boost::shared_ptr<usrp_source> sptr;
84 
85  /*!
86  * \brief DEPRECATED Make a new USRP source block using the deprecated io_type_t.
87  * \ingroup uhd_blk
88  *
89  * This function will be removed in the future. Please use the other make function,
90  * gr::uhd::make(const ::uhd::device_addr_t, const ::uhd::stream_args_t, const std::string).
91  */
92  static sptr make(const ::uhd::device_addr_t &device_addr,
93  const ::uhd::io_type_t &io_type,
94  size_t num_channels);
95 
96  /*!
97  * \param device_addr the address to identify the hardware
98  * \param stream_args the IO format and channel specification
99  * \return a new USRP source block object
100  */
101  static sptr make(const ::uhd::device_addr_t &device_addr,
102  const ::uhd::stream_args_t &stream_args);
103 
104  /*!
105  * Set the start time for incoming samples.
106  * To control when samples are received,
107  * set this value before starting the flow graph.
108  * The value is cleared after each run.
109  * When not specified, the start time will be:
110  * - Immediately for the one channel case
111  * - in the near future for multi-channel
112  *
113  * \param time the absolute time for reception to begin
114  */
115  virtual void set_start_time(const ::uhd::time_spec_t &time) = 0;
116 
117  /*!
118  * *Advanced use only:*
119  * Issue a stream command to all channels in this source block.
120  *
121  * This method is intended to override the default "always on"
122  * behavior. After starting the flow graph, the user should
123  * call stop() on this block, then issue any desired arbitrary
124  * stream_cmd_t structs to the device. The USRP will be able to
125  * enqueue several stream commands in the FPGA.
126  *
127  * \param cmd the stream command to issue to all source channels
128  */
129  virtual void issue_stream_cmd(const ::uhd::stream_cmd_t &cmd) = 0;
130 
131  /*!
132  * Returns identifying information about this USRP's configuration.
133  * Returns motherboard ID, name, and serial.
134  * Returns daughterboard RX ID, subdev name and spec, serial, and antenna.
135  * \param chan channel index 0 to N-1
136  * \return RX info
137  */
138  virtual ::uhd::dict<std::string, std::string> get_usrp_info(size_t chan = 0) = 0;
139 
140  /*!
141  * Enable/disable the automatic DC offset correction.
142  * The automatic correction subtracts out the long-run average.
143  *
144  * When disabled, the averaging option operation is halted.
145  * Once halted, the average value will be held constant until
146  * the user re-enables the automatic correction or overrides the
147  * value by manually setting the offset.
148  *
149  * \param enb true to enable automatic DC offset correction
150  * \param chan the channel index 0 to N-1
151  */
152  virtual void set_auto_dc_offset(const bool enb, size_t chan = 0) = 0;
153 
154  /*!
155  * Set a constant DC offset value.
156  * The value is complex to control both I and Q.
157  * Only set this when automatic correction is disabled.
158  * \param offset the dc offset (1.0 is full-scale)
159  * \param chan the channel index 0 to N-1
160  */
161  virtual void set_dc_offset(const std::complex<double> &offset, size_t chan = 0) = 0;
162 
163  /*!
164  * Enable/Disable the RX frontend IQ imbalance correction.
165  *
166  * \param enb true to enable automatic IQ imbalance correction
167  * \param chan the channel index 0 to N-1
168  */
169  virtual void set_auto_iq_balance(const bool enb, size_t chan = 0) = 0;
170 
171  /*!
172  * Set the RX frontend IQ imbalance correction.
173  * Use this to adjust the magnitude and phase of I and Q.
174  *
175  * \param correction the complex correction value
176  * \param chan the channel index 0 to N-1
177  */
178  virtual void set_iq_balance(const std::complex<double> &correction,
179  size_t chan = 0) = 0;
180 
181  /*!
182  * Convenience function for finite data acquisition.
183  * This is not to be used with the scheduler; rather,
184  * one can request samples from the USRP in python.
185  * //TODO assumes fc32
186  * \param nsamps the number of samples
187  * \return a vector of complex float samples
188  */
189  virtual std::vector<std::complex<float> >
190  finite_acquisition(const size_t nsamps) = 0;
191 
192  /*!
193  * Convenience function for finite data acquisition. This is the
194  * multi-channel version of finite_acquisition; This is not to
195  * be used with the scheduler; rather, one can request samples
196  * from the USRP in python.
197  * //TODO assumes fc32
198  * \param nsamps the number of samples per channel
199  * \return a vector of buffers, where each buffer represents a channel
200  */
201  virtual std::vector<std::vector<std::complex<float> > >
202  finite_acquisition_v(const size_t nsamps) = 0;
203  };
204 
205  } /* namespace uhd */
206 } /* namespace gr */
207 
208 #endif /* INCLUDED_GR_UHD_USRP_SOURCE_H */
Definition: usrp_block.h:41
Definition: usrp_source.h:79
Definition: usrp_sink.h:30
Include this header to use the message passing features.
Definition: logger.h:131
stream_args_t(const std::string &cpu="", const std::string &otw="")
Definition: usrp_source.h:33
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:30
boost::shared_ptr< usrp_source > sptr
Definition: usrp_source.h:83