GNU Radio Manual and C++ API Reference  3.7.13.4
The Free & Open Software Radio Ecosystem
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  * \param issue_stream_cmd_on_start enable or disable continuous streaming when flowgraph
100  * starts (default true)
101  * \return a new USRP source block object
102  */
103  static sptr make(const ::uhd::device_addr_t &device_addr,
104  const ::uhd::stream_args_t &stream_args,
105  const bool issue_stream_cmd_on_start = true);
106 
107  /*!
108  * Set the start time for incoming samples.
109  * To control when samples are received,
110  * set this value before starting the flow graph.
111  * The value is cleared after each run.
112  * When not specified, the start time will be:
113  * - Immediately for the one channel case
114  * - in the near future for multi-channel
115  *
116  * \param time the absolute time for reception to begin
117  */
118  virtual void set_start_time(const ::uhd::time_spec_t &time) = 0;
119 
120  /*!
121  * *Advanced use only:*
122  * Issue a stream command to all channels in this source block.
123  *
124  * This method is intended to override the default "always on"
125  * behavior. After starting the flow graph, the user should
126  * call stop() on this block, then issue any desired arbitrary
127  * stream_cmd_t structs to the device. The USRP will be able to
128  * enqueue several stream commands in the FPGA.
129  *
130  * \param cmd the stream command to issue to all source channels
131  */
132  virtual void issue_stream_cmd(const ::uhd::stream_cmd_t &cmd) = 0;
133 
134  /*! Configure the timeout value on the UHD recv() call
135  *
136  * This is an advanced use parameter. Changing the timeout value affects
137  * the latency of this block; a high timeout value can be more optimal
138  * for high-throughput applications (e.g., 1 second) and setting it to
139  * zero will have the best latency. Changing the timeout value may also
140  * be useful for custom FPGA modifications, where traffic might not be
141  * continuously streaming.
142  * For specialized high-performance use cases, twiddling these knobs may
143  * improve performance, but changes are not generally applicable.
144  *
145  * Note that UHD's recv() call may block until the timeout is over, which
146  * means this block might also block for up to the timeout value.
147  *
148  * \param timeout Timeout parameter in seconds. Cf. the UHD manual for
149  * uhd::rx_streamer::recv() for more details. A lower
150  * value will mean lower latency, but higher CPU load.
151  * \param one_packet If true, only receive one packet at a time. Cf. the
152  * UHD manual for uhd::rx_streamer::recv() for more
153  * details. A value of true will mean lower latency,
154  * but higher CPU load.
155  */
156  virtual void set_recv_timeout(
157  const double timeout,
158  const bool one_packet=true
159  ) = 0;
160 
161  /*!
162  * Returns identifying information about this USRP's configuration.
163  * Returns motherboard ID, name, and serial.
164  * Returns daughterboard RX ID, subdev name and spec, serial, and antenna.
165  * \param chan channel index 0 to N-1
166  * \return RX info
167  */
168  virtual ::uhd::dict<std::string, std::string> get_usrp_info(size_t chan = 0) = 0;
169 
170 
171  /*!
172  * Get a list of possible LO stage names
173  * \param chan the channel index 0 to N-1
174  * \return a vector of strings for possible LO names
175  */
176  virtual std::vector<std::string> get_lo_names(size_t chan = 0) = 0;
177 
178  /*!
179  * Set the LO source for the usrp device.
180  * For usrps that support selectable LOs, this function
181  * allows switching between them.
182  * Typical options for source: internal, external.
183  * \param src a string representing the LO source
184  * \param name the name of the LO stage to update
185  * \param chan the channel index 0 to N-1
186  */
187  virtual void set_lo_source(const std::string &src, const std::string &name, size_t chan = 0) = 0;
188 
189  /*!
190  * Get the currently set LO source.
191  * \param name the name of the LO stage to query
192  * \param chan the channel index 0 to N-1
193  * \return the configured LO source
194  */
195  virtual const std::string get_lo_source(const std::string &name, size_t chan = 0) = 0;
196 
197  /*!
198  * Get a list of possible LO sources.
199  * \param name the name of the LO stage to query
200  * \param chan the channel index 0 to N-1
201  * \return a vector of strings for possible settings
202  */
203  virtual std::vector<std::string> get_lo_sources(const std::string &name, size_t chan = 0) = 0;
204 
205  /*!
206  * Set whether the LO used by the usrp device is exported
207  * For usrps that support exportable LOs, this function
208  * configures if the LO used by chan is exported or not.
209  * \param enabled if true then export the LO
210  * \param name the name of the LO stage to update
211  * \param chan the channel index 0 to N-1 for the source channel
212  */
213  virtual void set_lo_export_enabled(bool enabled, const std::string &name, size_t chan = 0) = 0;
214 
215  /*!
216  * Returns true if the currently selected LO is being exported.
217  * \param name the name of the LO stage to query
218  * \param chan the channel index 0 to N-1
219  */
220  virtual bool get_lo_export_enabled(const std::string &name, size_t chan = 0) = 0;
221 
222  /*!
223  * Set the RX LO frequency (Advanced).
224  * \param freq the frequency to set the LO to
225  * \param name the name of the LO stage to update
226  * \param chan the channel index 0 to N-1
227  * \return a coerced LO frequency
228  */
229  virtual double set_lo_freq(double freq, const std::string &name, size_t chan = 0) = 0;
230 
231  /*!
232  * Get the current RX LO frequency (Advanced).
233  * \param name the name of the LO stage to query
234  * \param chan the channel index 0 to N-1
235  * \return the configured LO frequency
236  */
237  virtual double get_lo_freq(const std::string &name, size_t chan = 0) = 0;
238 
239  /*!
240  * Get the LO frequency range of the RX LO.
241  * \param name the name of the LO stage to query
242  * \param chan the channel index 0 to N-1
243  * \return a frequency range object
244  */
245  virtual ::uhd::freq_range_t get_lo_freq_range(const std::string &name, size_t chan = 0) = 0;
246 
247  /*!
248  * Enable/disable the automatic DC offset correction.
249  * The automatic correction subtracts out the long-run average.
250  *
251  * When disabled, the averaging option operation is halted.
252  * Once halted, the average value will be held constant until
253  * the user re-enables the automatic correction or overrides the
254  * value by manually setting the offset.
255  *
256  * \param enb true to enable automatic DC offset correction
257  * \param chan the channel index 0 to N-1
258  */
259  virtual void set_auto_dc_offset(const bool enb, size_t chan = 0) = 0;
260 
261  /*!
262  * Set a constant DC offset value.
263  * The value is complex to control both I and Q.
264  * Only set this when automatic correction is disabled.
265  * \param offset the dc offset (1.0 is full-scale)
266  * \param chan the channel index 0 to N-1
267  */
268  virtual void set_dc_offset(const std::complex<double> &offset, size_t chan = 0) = 0;
269 
270  /*!
271  * Enable/Disable the RX frontend IQ imbalance correction.
272  *
273  * \param enb true to enable automatic IQ imbalance correction
274  * \param chan the channel index 0 to N-1
275  */
276  virtual void set_auto_iq_balance(const bool enb, size_t chan = 0) = 0;
277 
278  /*!
279  * Set the RX frontend IQ imbalance correction.
280  * Use this to adjust the magnitude and phase of I and Q.
281  *
282  * \param correction the complex correction value
283  * \param chan the channel index 0 to N-1
284  */
285  virtual void set_iq_balance(const std::complex<double> &correction,
286  size_t chan = 0) = 0;
287 
288  /*!
289  * Convenience function for finite data acquisition.
290  * This is not to be used with the scheduler; rather,
291  * one can request samples from the USRP in python.
292  * //TODO assumes fc32
293  * \param nsamps the number of samples
294  * \return a vector of complex float samples
295  */
296  virtual std::vector<std::complex<float> >
297  finite_acquisition(const size_t nsamps) = 0;
298 
299  /*!
300  * Convenience function for finite data acquisition. This is the
301  * multi-channel version of finite_acquisition; This is not to
302  * be used with the scheduler; rather, one can request samples
303  * from the USRP in python.
304  * //TODO assumes fc32
305  * \param nsamps the number of samples per channel
306  * \return a vector of buffers, where each buffer represents a channel
307  */
308  virtual std::vector<std::vector<std::complex<float> > >
309  finite_acquisition_v(const size_t nsamps) = 0;
310  };
311 
312  } /* namespace uhd */
313 } /* namespace gr */
314 
315 #endif /* INCLUDED_GR_UHD_USRP_SOURCE_H */
Definition: usrp_block.h:59
Definition: usrp_source.h:79
Definition: usrp_sink.h:30
Include this header to use the message passing features.
Definition: logger.h:695
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