GNU Radio Manual and C++ API Reference  3.7.6.2
The Free & Open Software Radio Ecosystem
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
usrp_source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010-2014 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 
26 #include <gnuradio/uhd/api.h>
27 #include <gnuradio/sync_block.h>
28 #include <uhd/usrp/multi_usrp.hpp>
29 
30 // TODO In 3.8, UHD 3.4 will be required and we can remove all these ifdefs
31 #ifndef INCLUDED_UHD_STREAM_HPP
32 namespace uhd {
33  struct GR_UHD_API stream_args_t
34  {
35  stream_args_t(const std::string &cpu = "",
36  const std::string &otw = "")
37  {
38  cpu_format = cpu;
39  otw_format = otw;
40  }
41  std::string cpu_format;
42  std::string otw_format;
43  device_addr_t args;
44  std::vector<size_t> channels;
45  };
46 }
47 # define INCLUDED_UHD_STREAM_HPP
48 #else
49 # define GR_UHD_USE_STREAM_API
50 #endif
51 
52 namespace gr {
53  namespace uhd {
54 
55  class uhd_usrp_source;
56 
57  class GR_UHD_API usrp_source : virtual public sync_block
58  {
59  public:
60  // gr::uhd::usrp_source::sptr
61  typedef boost::shared_ptr<usrp_source> sptr;
62 
63  /*!
64  * \brief DEPRECATED Make a new USRP source block using the deprecated io_type_t.
65  * \ingroup uhd_blk
66  *
67  * This function will be removed in the future. Please use the other make function,
68  * gr::uhd::make(const ::uhd::device_addr_t, const ::uhd::stream_args_t, const std::string).
69  */
70  static sptr make(const ::uhd::device_addr_t &device_addr,
71  const ::uhd::io_type_t &io_type,
72  size_t num_channels);
73 
74  /*!
75  * \brief Make a new USRP source block (usually a radio receiver).
76  *
77  * The USRP source block receives samples and writes to a stream.
78  * The source block also provides API calls for receiver settings.
79  *
80  * RX Stream tagging:
81  *
82  * The following tag keys will be produced by the work function:
83  * - pmt::string_to_symbol("rx_time")
84  *
85  * The timestamp tag value is a pmt tuple of the following:
86  * (uint64 seconds, and double fractional seconds).
87  * A timestamp tag is produced at start() and after overflows.
88  *
89  * \section uhd_rx_command_iface Command interface
90  *
91  * This block has a message port, which consumes UHD PMT commands.
92  * For a description of the command syntax, see Section \ref uhd_command_syntax.
93  *
94  * For a more general description of the gr-uhd components, see \ref page_uhd.
95  *
96  * \param device_addr the address to identify the hardware
97  * \param stream_args the IO format and channel specification
98  * \return a new USRP source block object
99  */
100  static sptr make(const ::uhd::device_addr_t &device_addr,
101  const ::uhd::stream_args_t &stream_args);
102 
103  /*!
104  * Set the start time for incoming samples.
105  * To control when samples are received,
106  * set this value before starting the flow graph.
107  * The value is cleared after each run.
108  * When not specified, the start time will be:
109  * - Immediately for the one channel case
110  * - in the near future for multi-channel
111  *
112  * \param time the absolute time for reception to begin
113  */
114  virtual void set_start_time(const ::uhd::time_spec_t &time) = 0;
115 
116  /*!
117  * *Advanced use only:*
118  * Issue a stream command to all channels in this source block.
119  *
120  * This method is intended to override the default "always on"
121  * behavior. After starting the flow graph, the user should
122  * call stop() on this block, then issue any desired arbitrary
123  * stream_cmd_t structs to the device. The USRP will be able to
124  * enqueue several stream commands in the FPGA.
125  *
126  * \param cmd the stream command to issue to all source channels
127  */
128  virtual void issue_stream_cmd(const ::uhd::stream_cmd_t &cmd) = 0;
129 
130  /*!
131  * Returns identifying information about this USRP's configuration.
132  * Returns motherboard ID, name, and serial.
133  * Returns daughterboard RX ID, subdev name and spec, serial, and antenna.
134  * \param chan channel index 0 to N-1
135  * \return RX info
136  */
137  virtual ::uhd::dict<std::string, std::string> get_usrp_info(size_t chan = 0) = 0;
138 
139  /*!
140  * Set the frontend specification.
141  * \param spec the subdev spec markup string
142  * \param mboard the motherboard index 0 to M-1
143  */
144  virtual void set_subdev_spec(const std::string &spec, size_t mboard = 0) = 0;
145 
146  /*!
147  * Get the RX frontend specification.
148  * \param mboard the motherboard index 0 to M-1
149  * \return the frontend specification in use
150  */
151  virtual std::string get_subdev_spec(size_t mboard = 0) = 0;
152 
153  /*!
154  * Set the sample rate for the usrp device.
155  * \param rate a new rate in Sps
156  */
157  virtual void set_samp_rate(double rate) = 0;
158 
159  /*!
160  * Get the sample rate for the usrp device.
161  * This is the actual sample rate and may differ from the rate set.
162  * \return the actual rate in Sps
163  */
164  virtual double get_samp_rate(void) = 0;
165 
166  /*!
167  * Get the possible sample rates for the usrp device.
168  * \return a range of rates in Sps
169  */
170  virtual ::uhd::meta_range_t get_samp_rates(void) = 0;
171 
172  /*!
173  * Tune the usrp device to the desired center frequency.
174  * \param tune_request the tune request instructions
175  * \param chan the channel index 0 to N-1
176  * \return a tune result with the actual frequencies
177  */
178  virtual ::uhd::tune_result_t set_center_freq
179  (const ::uhd::tune_request_t tune_request, size_t chan = 0) = 0;
180 
181  /*!
182  * Tune the usrp device to the desired center frequency.
183  * This is a wrapper around set center freq so that in this case,
184  * the user can pass a single frequency in the call through swig.
185  * \param freq the desired frequency in Hz
186  * \param chan the channel index 0 to N-1
187  * \return a tune result with the actual frequencies
188  */
189  ::uhd::tune_result_t set_center_freq(double freq, size_t chan = 0)
190  {
191  return set_center_freq(::uhd::tune_request_t(freq), chan);
192  }
193 
194  /*!
195  * Get the center frequency.
196  * \param chan the channel index 0 to N-1
197  * \return the frequency in Hz
198  */
199  virtual double get_center_freq(size_t chan = 0) = 0;
200 
201  /*!
202  * Get the tunable frequency range.
203  * \param chan the channel index 0 to N-1
204  * \return the frequency range in Hz
205  */
206  virtual ::uhd::freq_range_t get_freq_range(size_t chan = 0) = 0;
207 
208  /*!
209  * Set the gain for the dboard.
210  * \param gain the gain in dB
211  * \param chan the channel index 0 to N-1
212  */
213  virtual void set_gain(double gain, size_t chan = 0) = 0;
214 
215  /*!
216  * Set the named gain on the dboard.
217  * \param gain the gain in dB
218  * \param name the name of the gain stage
219  * \param chan the channel index 0 to N-1
220  */
221  virtual void set_gain(double gain,
222  const std::string &name,
223  size_t chan = 0) = 0;
224 
225  /*!
226  * Get the actual dboard gain setting.
227  * \param chan the channel index 0 to N-1
228  * \return the actual gain in dB
229  */
230  virtual double get_gain(size_t chan = 0) = 0;
231 
232  /*!
233  * Get the actual dboard gain setting of named stage.
234  * \param name the name of the gain stage
235  * \param chan the channel index 0 to N-1
236  * \return the actual gain in dB
237  */
238  virtual double get_gain(const std::string &name,
239  size_t chan = 0) = 0;
240 
241  /*!
242  * Get the actual dboard gain setting of named stage.
243  * \param chan the channel index 0 to N-1
244  * \return the actual gain in dB
245  */
246  virtual std::vector<std::string> get_gain_names(size_t chan = 0) = 0;
247 
248  /*!
249  * Get the settable gain range.
250  * \param chan the channel index 0 to N-1
251  * \return the gain range in dB
252  */
253  virtual ::uhd::gain_range_t get_gain_range(size_t chan = 0) = 0;
254 
255  /*!
256  * Get the settable gain range.
257  * \param name the name of the gain stage
258  * \param chan the channel index 0 to N-1
259  * \return the gain range in dB
260  */
261  virtual ::uhd::gain_range_t get_gain_range(const std::string &name,
262  size_t chan = 0) = 0;
263 
264  /*!
265  * Set the antenna to use.
266  * \param ant the antenna string
267  * \param chan the channel index 0 to N-1
268  */
269  virtual void set_antenna(const std::string &ant,
270  size_t chan = 0) = 0;
271 
272  /*!
273  * Get the antenna in use.
274  * \param chan the channel index 0 to N-1
275  * \return the antenna string
276  */
277  virtual std::string get_antenna(size_t chan = 0) = 0;
278 
279  /*!
280  * Get a list of possible antennas.
281  * \param chan the channel index 0 to N-1
282  * \return a vector of antenna strings
283  */
284  virtual std::vector<std::string> get_antennas(size_t chan = 0) = 0;
285 
286  /*!
287  * Set the bandpass filter on the RF frontend.
288  * \param bandwidth the filter bandwidth in Hz
289  * \param chan the channel index 0 to N-1
290  */
291  virtual void set_bandwidth(double bandwidth, size_t chan = 0) = 0;
292 
293  /*!
294  * Get the bandpass filter setting on the RF frontend.
295  * \param chan the channel index 0 to N-1
296  * \return bandwidth of the filter in Hz
297  */
298  virtual double get_bandwidth(size_t chan = 0) = 0;
299 
300  /*!
301  * Get the bandpass filter range of the RF frontend.
302  * \param chan the channel index 0 to N-1
303  * \return the range of the filter bandwidth in Hz
304  */
305  virtual ::uhd::freq_range_t get_bandwidth_range(size_t chan = 0) = 0;
306 
307  /*!
308  * Enable/disable the automatic DC offset correction.
309  * The automatic correction subtracts out the long-run average.
310  *
311  * When disabled, the averaging option operation is halted.
312  * Once halted, the average value will be held constant until
313  * the user re-enables the automatic correction or overrides the
314  * value by manually setting the offset.
315  *
316  * \param enb true to enable automatic DC offset correction
317  * \param chan the channel index 0 to N-1
318  */
319  virtual void set_auto_dc_offset(const bool enb, size_t chan = 0) = 0;
320 
321  /*!
322  * Set a constant DC offset value.
323  * The value is complex to control both I and Q.
324  * Only set this when automatic correction is disabled.
325  * \param offset the dc offset (1.0 is full-scale)
326  * \param chan the channel index 0 to N-1
327  */
328  virtual void set_dc_offset(const std::complex<double> &offset, size_t chan = 0) = 0;
329 
330  /*!
331  * Set the RX frontend IQ imbalance correction.
332  * Use this to adjust the magnitude and phase of I and Q.
333  *
334  * \param correction the complex correction value
335  * \param chan the channel index 0 to N-1
336  */
337  virtual void set_iq_balance(const std::complex<double> &correction,
338  size_t chan = 0) = 0;
339 
340  /*!
341  * Get a RF frontend sensor value.
342  * \param name the name of the sensor
343  * \param chan the channel index 0 to N-1
344  * \return a sensor value object
345  */
346  virtual ::uhd::sensor_value_t get_sensor(const std::string &name,
347  size_t chan = 0) = 0;
348 
349  /*!
350  * Get a list of possible RF frontend sensor names.
351  * \param chan the channel index 0 to N-1
352  * \return a vector of sensor names
353  */
354  virtual std::vector<std::string> get_sensor_names(size_t chan = 0) = 0;
355 
356  //! DEPRECATED use get_sensor
357  ::uhd::sensor_value_t get_dboard_sensor(const std::string &name,
358  size_t chan = 0)
359  {
360  return this->get_sensor(name, chan);
361  }
362 
363  //! DEPRECATED use get_sensor_names
364  std::vector<std::string> get_dboard_sensor_names(size_t chan = 0)
365  {
366  return this->get_sensor_names(chan);
367  }
368 
369  /*!
370  * Get a motherboard sensor value.
371  * \param name the name of the sensor
372  * \param mboard the motherboard index 0 to M-1
373  * \return a sensor value object
374  */
375  virtual ::uhd::sensor_value_t get_mboard_sensor(const std::string &name,
376  size_t mboard = 0) = 0;
377 
378  /*!
379  * Get a list of possible motherboard sensor names.
380  * \param mboard the motherboard index 0 to M-1
381  * \return a vector of sensor names
382  */
383  virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
384 
385  /*!
386  * Set the clock configuration.
387  * DEPRECATED for set_time/clock_source.
388  * \param clock_config the new configuration
389  * \param mboard the motherboard index 0 to M-1
390  */
391  virtual void set_clock_config(const ::uhd::clock_config_t &clock_config,
392  size_t mboard = 0) = 0;
393 
394  /*!
395  * Set the time source for the usrp device.
396  * This sets the method of time synchronization,
397  * typically a pulse per second or an encoded time.
398  * Typical options for source: external, MIMO.
399  * \param source a string representing the time source
400  * \param mboard which motherboard to set the config
401  */
402  virtual void set_time_source(const std::string &source,
403  const size_t mboard = 0) = 0;
404 
405  /*!
406  * Get the currently set time source.
407  * \param mboard which motherboard to get the config
408  * \return the string representing the time source
409  */
410  virtual std::string get_time_source(const size_t mboard) = 0;
411 
412  /*!
413  * Get a list of possible time sources.
414  * \param mboard which motherboard to get the list
415  * \return a vector of strings for possible settings
416  */
417  virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
418 
419  /*!
420  * Set the clock source for the usrp device.
421  * This sets the source for a 10 Mhz reference clock.
422  * Typical options for source: internal, external, MIMO.
423  * \param source a string representing the clock source
424  * \param mboard which motherboard to set the config
425  */
426  virtual void set_clock_source(const std::string &source,
427  const size_t mboard = 0) = 0;
428 
429  /*!
430  * Get the currently set clock source.
431  * \param mboard which motherboard to get the config
432  * \return the string representing the clock source
433  */
434  virtual std::string get_clock_source(const size_t mboard) = 0;
435 
436  /*!
437  * Get a list of possible clock sources.
438  * \param mboard which motherboard to get the list
439  * \return a vector of strings for possible settings
440  */
441  virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
442 
443  /*!
444  * Get the master clock rate.
445  * \param mboard the motherboard index 0 to M-1
446  * \return the clock rate in Hz
447  */
448  virtual double get_clock_rate(size_t mboard = 0) = 0;
449 
450  /*!
451  * Set the master clock rate.
452  * \param rate the new rate in Hz
453  * \param mboard the motherboard index 0 to M-1
454  */
455  virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
456 
457  /*!
458  * Get the current time registers.
459  * \param mboard the motherboard index 0 to M-1
460  * \return the current usrp time
461  */
462  virtual ::uhd::time_spec_t get_time_now(size_t mboard = 0) = 0;
463 
464  /*!
465  * Get the time when the last pps pulse occured.
466  * \param mboard the motherboard index 0 to M-1
467  * \return the current usrp time
468  */
469  virtual ::uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
470 
471  /*!
472  * Sets the time registers immediately.
473  * \param time_spec the new time
474  * \param mboard the motherboard index 0 to M-1
475  */
476  virtual void set_time_now(const ::uhd::time_spec_t &time_spec,
477  size_t mboard = 0) = 0;
478 
479  /*!
480  * Set the time registers at the next pps.
481  * \param time_spec the new time
482  */
483  virtual void set_time_next_pps(const ::uhd::time_spec_t &time_spec) = 0;
484 
485  /*!
486  * Sync the time registers with an unknown pps edge.
487  * \param time_spec the new time
488  */
489  virtual void set_time_unknown_pps(const ::uhd::time_spec_t &time_spec) = 0;
490 
491  /*!
492  * Set the time at which the control commands will take effect.
493  *
494  * A timed command will back-pressure all subsequent timed
495  * commands, assuming that the subsequent commands occur within
496  * the time-window. If the time spec is late, the command will
497  * be activated upon arrival.
498  *
499  * \param time_spec the time at which the next command will activate
500  * \param mboard which motherboard to set the config
501  */
502  virtual void set_command_time(const ::uhd::time_spec_t &time_spec,
503  size_t mboard = 0) = 0;
504 
505  /*!
506  * Clear the command time so future commands are sent ASAP.
507  *
508  * \param mboard which motherboard to set the config
509  */
510  virtual void clear_command_time(size_t mboard = 0) = 0;
511 
512  /*!
513  * Get access to the underlying uhd dboard iface object.
514  * \return the dboard_iface object
515  */
516  virtual ::uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
517 
518  /*!
519  * Get access to the underlying uhd device object.
520  *
521  * NOTE: This function is only available in C++.
522  * \return the multi usrp device object
523  */
524  virtual ::uhd::usrp::multi_usrp::sptr get_device(void) = 0;
525 
526  /*!
527  * Perform write on the user configuration register bus. These
528  * only exist if the user has implemented custom setting
529  * registers in the device FPGA.
530  * \param addr 8-bit register address
531  * \param data 32-bit register value
532  * \param mboard which motherboard to set the user register
533  */
534  virtual void set_user_register(const uint8_t addr,
535  const uint32_t data,
536  size_t mboard = 0) = 0;
537 
538  /*!
539  * Convenience function for finite data acquisition.
540  * This is not to be used with the scheduler; rather,
541  * one can request samples from the USRP in python.
542  * //TODO assumes fc32
543  * \param nsamps the number of samples
544  * \return a vector of complex float samples
545  */
546  virtual std::vector<std::complex<float> >
547  finite_acquisition(const size_t nsamps) = 0;
548 
549  /*!
550  * Convenience function for finite data acquisition. This is the
551  * multi-channel version of finite_acquisition; This is not to
552  * be used with the scheduler; rather, one can request samples
553  * from the USRP in python.
554  * //TODO assumes fc32
555  * \param nsamps the number of samples per channel
556  * \return a vector of buffers, where each buffer represents a channel
557  */
558  virtual std::vector<std::vector<std::complex<float> > >
559  finite_acquisition_v(const size_t nsamps) = 0;
560  };
561 
562  } /* namespace uhd */
563 } /* namespace gr */
564 
565 #endif /* INCLUDED_GR_UHD_USRP_SOURCE_H */
::uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan=0)
DEPRECATED use get_sensor.
Definition: usrp_source.h:357
Definition: usrp_source.h:57
::uhd::tune_result_t set_center_freq(double freq, size_t chan=0)
Definition: usrp_source.h:189
stream_args_t(const std::string &cpu="", const std::string &otw="")
Definition: usrp_source.h:35
synchronous 1:1 input to output with historyOverride work to provide the signal processing implementa...
Definition: sync_block.h:37
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:30
std::vector< std::string > get_dboard_sensor_names(size_t chan=0)
DEPRECATED use get_sensor_names.
Definition: usrp_source.h:364
boost::shared_ptr< usrp_source > sptr
Definition: usrp_source.h:61