GNU Radio Manual and C++ API Reference  3.7.10
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  * \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  /*!
135  * Returns identifying information about this USRP's configuration.
136  * Returns motherboard ID, name, and serial.
137  * Returns daughterboard RX ID, subdev name and spec, serial, and antenna.
138  * \param chan channel index 0 to N-1
139  * \return RX info
140  */
141  virtual ::uhd::dict<std::string, std::string> get_usrp_info(size_t chan = 0) = 0;
142 
143 
144  /*!
145  * Get a list of possible LO stage names
146  * \param chan the channel index 0 to N-1
147  * \return a vector of strings for possible LO names
148  */
149  virtual std::vector<std::string> get_lo_names(size_t chan = 0) = 0;
150 
151  /*!
152  * Set the LO source for the usrp device.
153  * For usrps that support selectable LOs, this function
154  * allows switching between them.
155  * Typical options for source: internal, external.
156  * \param src a string representing the LO source
157  * \param name the name of the LO stage to update
158  * \param chan the channel index 0 to N-1
159  */
160  virtual void set_lo_source(const std::string &src, const std::string &name, size_t chan = 0) = 0;
161 
162  /*!
163  * Get the currently set LO source.
164  * \param name the name of the LO stage to query
165  * \param chan the channel index 0 to N-1
166  * \return the configured LO source
167  */
168  virtual const std::string get_lo_source(const std::string &name, size_t chan = 0) = 0;
169 
170  /*!
171  * Get a list of possible LO sources.
172  * \param name the name of the LO stage to query
173  * \param chan the channel index 0 to N-1
174  * \return a vector of strings for possible settings
175  */
176  virtual std::vector<std::string> get_lo_sources(const std::string &name, size_t chan = 0) = 0;
177 
178  /*!
179  * Set whether the LO used by the usrp device is exported
180  * For usrps that support exportable LOs, this function
181  * configures if the LO used by chan is exported or not.
182  * \param enabled if true then export the LO
183  * \param name the name of the LO stage to update
184  * \param chan the channel index 0 to N-1 for the source channel
185  */
186  virtual void set_lo_export_enabled(bool enabled, const std::string &name, size_t chan = 0) = 0;
187 
188  /*!
189  * Returns true if the currently selected LO is being exported.
190  * \param name the name of the LO stage to query
191  * \param chan the channel index 0 to N-1
192  */
193  virtual bool get_lo_export_enabled(const std::string &name, size_t chan = 0) = 0;
194 
195  /*!
196  * Set the RX LO frequency (Advanced).
197  * \param freq the frequency to set the LO to
198  * \param name the name of the LO stage to update
199  * \param chan the channel index 0 to N-1
200  * \return a coerced LO frequency
201  */
202  virtual double set_lo_freq(double freq, const std::string &name, size_t chan = 0) = 0;
203 
204  /*!
205  * Get the current RX LO frequency (Advanced).
206  * \param name the name of the LO stage to query
207  * \param chan the channel index 0 to N-1
208  * \return the configured LO frequency
209  */
210  virtual double get_lo_freq(const std::string &name, size_t chan = 0) = 0;
211 
212  /*!
213  * Get the LO frequency range of the RX LO.
214  * \param name the name of the LO stage to query
215  * \param chan the channel index 0 to N-1
216  * \return a frequency range object
217  */
218  virtual ::uhd::freq_range_t get_lo_freq_range(const std::string &name, size_t chan = 0) = 0;
219 
220  /*!
221  * Enable/disable the automatic DC offset correction.
222  * The automatic correction subtracts out the long-run average.
223  *
224  * When disabled, the averaging option operation is halted.
225  * Once halted, the average value will be held constant until
226  * the user re-enables the automatic correction or overrides the
227  * value by manually setting the offset.
228  *
229  * \param enb true to enable automatic DC offset correction
230  * \param chan the channel index 0 to N-1
231  */
232  virtual void set_auto_dc_offset(const bool enb, size_t chan = 0) = 0;
233 
234  /*!
235  * Set a constant DC offset value.
236  * The value is complex to control both I and Q.
237  * Only set this when automatic correction is disabled.
238  * \param offset the dc offset (1.0 is full-scale)
239  * \param chan the channel index 0 to N-1
240  */
241  virtual void set_dc_offset(const std::complex<double> &offset, size_t chan = 0) = 0;
242 
243  /*!
244  * Enable/Disable the RX frontend IQ imbalance correction.
245  *
246  * \param enb true to enable automatic IQ imbalance correction
247  * \param chan the channel index 0 to N-1
248  */
249  virtual void set_auto_iq_balance(const bool enb, size_t chan = 0) = 0;
250 
251  /*!
252  * Set the RX frontend IQ imbalance correction.
253  * Use this to adjust the magnitude and phase of I and Q.
254  *
255  * \param correction the complex correction value
256  * \param chan the channel index 0 to N-1
257  */
258  virtual void set_iq_balance(const std::complex<double> &correction,
259  size_t chan = 0) = 0;
260 
261  /*!
262  * Convenience function for finite data acquisition.
263  * This is not to be used with the scheduler; rather,
264  * one can request samples from the USRP in python.
265  * //TODO assumes fc32
266  * \param nsamps the number of samples
267  * \return a vector of complex float samples
268  */
269  virtual std::vector<std::complex<float> >
270  finite_acquisition(const size_t nsamps) = 0;
271 
272  /*!
273  * Convenience function for finite data acquisition. This is the
274  * multi-channel version of finite_acquisition; This is not to
275  * be used with the scheduler; rather, one can request samples
276  * from the USRP in python.
277  * //TODO assumes fc32
278  * \param nsamps the number of samples per channel
279  * \return a vector of buffers, where each buffer represents a channel
280  */
281  virtual std::vector<std::vector<std::complex<float> > >
282  finite_acquisition_v(const size_t nsamps) = 0;
283  };
284 
285  } /* namespace uhd */
286 } /* namespace gr */
287 
288 #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