GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
usrp_block.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015,2019 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_BLOCK_H
24 #define INCLUDED_GR_UHD_USRP_BLOCK_H
25 
26 #include <gnuradio/sync_block.h>
27 #include <gnuradio/uhd/api.h>
28 #include <uhd/usrp/multi_usrp.hpp>
29 
30 namespace gr {
31 namespace uhd {
32 
47 
50 
51 /*! Base class for USRP blocks.
52  * \ingroup uhd_blk
53  *
54  * Note that many of the functions defined here differ between
55  * Rx and Tx configurations. As an example, set_center_freq()
56  * will set the Rx frequency for a usrp_source object, and the
57  * Tx frequency on a usrp_sink object.
58  */
60 {
61 protected:
62  usrp_block(){}; // For virtual sub-classing
63  usrp_block(const std::string& name,
64  gr::io_signature::sptr input_signature,
65  gr::io_signature::sptr output_signature);
66 
67 public:
68  /*!
69  * Set the frontend specification.
70  *
71  * \param spec the subdev spec markup string
72  * \param mboard the motherboard index 0 to M-1
73  */
74  virtual void set_subdev_spec(const std::string& spec, size_t mboard = 0) = 0;
75 
76  /*!
77  * Get the frontend specification.
78  *
79  * \param mboard the motherboard index 0 to M-1
80  * \return the frontend specification in use
81  */
82  virtual std::string get_subdev_spec(size_t mboard = 0) = 0;
83 
84  /*!
85  * Return the number of motherboards in this configuration.
86  */
87  virtual size_t get_num_mboards() = 0;
88 
89  /*!
90  * Set the sample rate for this connection to the USRP.
91  *
92  * \param rate a new rate in Sps
93  */
94  virtual void set_samp_rate(double rate) = 0;
95 
96  /*!
97  * Get the sample rate for this connection to the USRP.
98  * This is the actual sample rate and may differ from the rate set.
99  *
100  * \return the actual rate in Sps
101  */
102  virtual double get_samp_rate(void) = 0;
103 
104  /*!
105  * Get the possible sample rates for this connection.
106  *
107  * \return a range of rates in Sps
108  */
109  virtual ::uhd::meta_range_t get_samp_rates(void) = 0;
110 
111  /*!
112  * Tune the selected channel to the desired center frequency.
113  *
114  * \param tune_request the tune request instructions
115  * \param chan the channel index 0 to N-1
116  * \return a tune result with the actual frequencies
117  */
118  virtual ::uhd::tune_result_t set_center_freq(const ::uhd::tune_request_t tune_request,
119  size_t chan = 0) = 0;
120 
121  /*!
122  * Tune the selected channel to the desired center frequency.
123  *
124  * This is a wrapper around set_center_freq() so that in this case,
125  * the user can pass a single frequency in the call instead of
126  * having to generate a tune_request_t object.
127  *
128  * \param freq the desired frequency in Hz
129  * \param chan the channel index 0 to N-1
130  * \return a tune result with the actual frequencies
131  */
132  ::uhd::tune_result_t set_center_freq(double freq, size_t chan = 0)
133  {
134  return set_center_freq(::uhd::tune_request_t(freq), chan);
135  }
136 
137  /*!
138  * Get the center frequency.
139  *
140  * \param chan the channel index 0 to N-1
141  * \return the frequency in Hz
142  */
143  virtual double get_center_freq(size_t chan = 0) = 0;
144 
145  /*!
146  * Get the tunable frequency range.
147  *
148  * \param chan the channel index 0 to N-1
149  * \return the frequency range in Hz
150  */
151  virtual ::uhd::freq_range_t get_freq_range(size_t chan = 0) = 0;
152 
153  /*!
154  * Set the gain for the selected channel.
155  *
156  * \param gain the gain in dB
157  * \param chan the channel index 0 to N-1
158  */
159  virtual void set_gain(double gain, size_t chan = 0) = 0;
160 
161  /*!
162  * Set the named gain on the dboard.
163  *
164  * \param gain the gain in dB
165  * \param name the name of the gain stage
166  * \param chan the channel index 0 to N-1
167  */
168  virtual void set_gain(double gain, const std::string& name, size_t chan = 0) = 0;
169 
170  /*!
171  * Set the normalized gain.
172  *
173  * The normalized gain is always in [0, 1], regardless of the device.
174  * 0 corresponds to minimum gain (usually 0 dB, but make sure to read the device
175  * notes in the UHD manual) and 1 corresponds to maximum gain.
176  * This will work for any UHD device. Use get_gain() to see which dB value
177  * the normalized gain value corresponds to.
178  *
179  * Note that it is not possible to specify a gain name for this function.
180  *
181  * \throws A runtime_error if \p norm_gain is not within the valid range.
182  *
183  * \param norm_gain the gain in fractions of the gain range (must be 0 <= norm_gain <=
184  * 1) \param chan the channel index 0 to N-1
185  */
186  virtual void set_normalized_gain(double norm_gain, size_t chan = 0) = 0;
187 
188  /*!
189  * Get the actual dboard gain setting.
190  *
191  * \param chan the channel index 0 to N-1
192  * \return the actual gain in dB
193  */
194  virtual double get_gain(size_t chan = 0) = 0;
195 
196  /*!
197  * Get the actual dboard gain setting of named stage.
198  *
199  * \param name the name of the gain stage
200  * \param chan the channel index 0 to N-1
201  * \return the actual gain in dB
202  */
203  virtual double get_gain(const std::string& name, size_t chan = 0) = 0;
204 
205  /*!
206  * Returns the normalized gain.
207  *
208  * The normalized gain is always in [0, 1], regardless of the device.
209  * See also set_normalized_gain().
210  *
211  * Note that it is not possible to specify a gain name for
212  * this function, the result is over the entire gain chain.
213  *
214  * \param chan the channel index 0 to N-1
215  */
216  virtual double get_normalized_gain(size_t chan = 0) = 0;
217 
218  /*!
219  * Get the actual dboard gain setting of named stage.
220  *
221  * \param chan the channel index 0 to N-1
222  * \return the actual gain in dB
223  */
224  virtual std::vector<std::string> get_gain_names(size_t chan = 0) = 0;
225 
226  /*!
227  * Get the settable gain range.
228  *
229  * \param chan the channel index 0 to N-1
230  * \return the gain range in dB
231  */
232  virtual ::uhd::gain_range_t get_gain_range(size_t chan = 0) = 0;
233 
234  /*!
235  * Get the settable gain range.
236  *
237  * \param name the name of the gain stage
238  * \param chan the channel index 0 to N-1
239  * \return the gain range in dB
240  */
241  virtual ::uhd::gain_range_t get_gain_range(const std::string& name,
242  size_t chan = 0) = 0;
243 
244  /*!
245  * Set the antenna to use for a given channel.
246  *
247  * \param ant the antenna string
248  * \param chan the channel index 0 to N-1
249  */
250  virtual void set_antenna(const std::string& ant, size_t chan = 0) = 0;
251 
252  /*!
253  * Get the antenna in use.
254  *
255  * \param chan the channel index 0 to N-1
256  * \return the antenna string
257  */
258  virtual std::string get_antenna(size_t chan = 0) = 0;
259 
260  /*!
261  * Get a list of possible antennas on a given channel.
262  *
263  * \param chan the channel index 0 to N-1
264  * \return a vector of antenna strings
265  */
266  virtual std::vector<std::string> get_antennas(size_t chan = 0) = 0;
267 
268  /*!
269  * Set the bandpass filter on the RF frontend.
270  *
271  * \param bandwidth the filter bandwidth in Hz
272  * \param chan the channel index 0 to N-1
273  */
274  virtual void set_bandwidth(double bandwidth, size_t chan = 0) = 0;
275 
276  /*!
277  * Get the bandpass filter setting on the RF frontend.
278  *
279  * \param chan the channel index 0 to N-1
280  * \return bandwidth of the filter in Hz
281  */
282  virtual double get_bandwidth(size_t chan = 0) = 0;
283 
284  /*!
285  * Get the bandpass filter range of the RF frontend.
286  *
287  * \param chan the channel index 0 to N-1
288  * \return the range of the filter bandwidth in Hz
289  */
290  virtual ::uhd::freq_range_t get_bandwidth_range(size_t chan = 0) = 0;
291 
292  /*!
293  * Get an RF frontend sensor value.
294  * \param name the name of the sensor
295  * \param chan the channel index 0 to N-1
296  * \return a sensor value object
297  */
298  virtual ::uhd::sensor_value_t get_sensor(const std::string& name,
299  size_t chan = 0) = 0;
300 
301  /*!
302  * Get a list of possible RF frontend sensor names.
303  * \param chan the channel index 0 to N-1
304  * \return a vector of sensor names
305  */
306  virtual std::vector<std::string> get_sensor_names(size_t chan = 0) = 0;
307 
308  //! DEPRECATED use get_sensor
309  ::uhd::sensor_value_t get_dboard_sensor(const std::string& name, size_t chan = 0)
310  {
311  return this->get_sensor(name, chan);
312  }
313 
314  //! DEPRECATED use get_sensor_names
315  std::vector<std::string> get_dboard_sensor_names(size_t chan = 0)
316  {
317  return this->get_sensor_names(chan);
318  }
319 
320  /*!
321  * Get a motherboard sensor value.
322  *
323  * \param name the name of the sensor
324  * \param mboard the motherboard index 0 to M-1
325  * \return a sensor value object
326  */
327  virtual ::uhd::sensor_value_t get_mboard_sensor(const std::string& name,
328  size_t mboard = 0) = 0;
329 
330  /*!
331  * Get a list of possible motherboard sensor names.
332  *
333  * \param mboard the motherboard index 0 to M-1
334  * \return a vector of sensor names
335  */
336  virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
337 
338  /*!
339  * Get the currently set time source.
340  *
341  * \param mboard which motherboard to get the config
342  * \return the string representing the time source
343  */
344  virtual std::string get_time_source(const size_t mboard) = 0;
345 
346  /*!
347  * Get a list of possible time sources.
348  *
349  * \param mboard which motherboard to get the list
350  * \return a vector of strings for possible settings
351  */
352  virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
353 
354  /*!
355  * Set the clock source for the usrp device.
356  *
357  * This sets the source for a 10 MHz reference clock.
358  * Typical options for source: internal, external, MIMO.
359  *
360  * \param source a string representing the clock source
361  * \param mboard which motherboard to set the config
362  */
363  virtual void set_clock_source(const std::string& source, const size_t mboard = 0) = 0;
364 
365  /*!
366  * Get the currently set clock source.
367  *
368  * \param mboard which motherboard to get the config
369  * \return the string representing the clock source
370  */
371  virtual std::string get_clock_source(const size_t mboard) = 0;
372 
373  /*!
374  * Get a list of possible clock sources.
375  *
376  * \param mboard which motherboard to get the list
377  * \return a vector of strings for possible settings
378  */
379  virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
380 
381  /*!
382  * Get the master clock rate.
383  *
384  * \param mboard the motherboard index 0 to M-1
385  * \return the clock rate in Hz
386  */
387  virtual double get_clock_rate(size_t mboard = 0) = 0;
388 
389  /*!
390  * Set the master clock rate.
391  *
392  * \param rate the new rate in Hz
393  * \param mboard the motherboard index 0 to M-1
394  */
395  virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
396 
397  /*!
398  * Get the current time registers.
399  *
400  * \param mboard the motherboard index 0 to M-1
401  * \return the current usrp time
402  */
403  virtual ::uhd::time_spec_t get_time_now(size_t mboard = 0) = 0;
404 
405  /*!
406  * Get the time when the last pps pulse occurred.
407  * \param mboard the motherboard index 0 to M-1
408  * \return the current usrp time
409  */
410  virtual ::uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
411 
412  /*!
413  * Sets the time registers immediately.
414  * \param time_spec the new time
415  * \param mboard the motherboard index 0 to M-1
416  */
417  virtual void set_time_now(const ::uhd::time_spec_t& time_spec, size_t mboard = 0) = 0;
418 
419  /*!
420  * Set the time registers at the next pps.
421  * \param time_spec the new time
422  */
423  virtual void set_time_next_pps(const ::uhd::time_spec_t& time_spec) = 0;
424 
425  /*!
426  * Sync the time registers with an unknown pps edge.
427  * \param time_spec the new time
428  */
429  virtual void set_time_unknown_pps(const ::uhd::time_spec_t& time_spec) = 0;
430 
431  /*!
432  * Set the time at which the control commands will take effect.
433  *
434  * A timed command will back-pressure all subsequent timed commands,
435  * assuming that the subsequent commands occur within the time-window.
436  * If the time spec is late, the command will be activated upon arrival.
437  *
438  * \param time_spec the time at which the next command will activate
439  * \param mboard which motherboard to set the config
440  */
441  virtual void set_command_time(const ::uhd::time_spec_t& time_spec,
442  size_t mboard = 0) = 0;
443 
444  /*!
445  * Clear the command time so future commands are sent ASAP.
446  *
447  * \param mboard which motherboard to set the config
448  */
449  virtual void clear_command_time(size_t mboard = 0) = 0;
450 
451  /*!
452  * Get access to the underlying uhd dboard iface object.
453  *
454  * \return the dboard_iface object
455  */
456  virtual ::uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
457 
458  /*!
459  * Get access to the underlying uhd device object.
460  *
461  * NOTE: This function is only available in C++.
462  * \return the multi usrp device object
463  */
464  virtual ::uhd::usrp::multi_usrp::sptr get_device(void) = 0;
465 
466  /*!
467  * Perform write on the user configuration register bus. These
468  * only exist if the user has implemented custom setting
469  * registers in the device FPGA.
470  *
471  * \param addr 8-bit register address
472  * \param data 32-bit register value
473  * \param mboard which motherboard to set the user register
474  */
475  virtual void
476  set_user_register(const uint8_t addr, const uint32_t data, size_t mboard = 0) = 0;
477 
478  /*!
479  * Set the time source for the USRP device.
480  *
481  * This sets the method of time synchronization,
482  * typically a pulse per second or an encoded time.
483  * Typical options for source: external, MIMO.
484  * \param source a string representing the time source
485  * \param mboard which motherboard to set the config
486  */
487  virtual void set_time_source(const std::string& source, const size_t mboard = 0) = 0;
488 
489  /*!
490  * Update the stream args for this device.
491  *
492  * This update will only take effect after a restart of the
493  * streaming, or before streaming and after construction.
494  * This will also delete the current streamer.
495  * Note you cannot change the I/O signature of this block using
496  * this function, or it will throw.
497  *
498  * It is possible to leave the 'channels' fields of \p stream_args
499  * unset. In this case, the previous channels field is used.
500  *
501  * \param stream_args New stream args.
502  * \throws std::runtime_error if new settings are invalid.
503  */
504  virtual void set_stream_args(const ::uhd::stream_args_t& stream_args) = 0;
505 
506  /*******************************************************************
507  * GPIO methods
508  ******************************************************************/
509  /*!
510  * Enumerate GPIO banks on the current device.
511  * \param mboard the motherboard index 0 to M-1
512  * \return a list of string for each bank name
513  */
514  virtual std::vector<std::string> get_gpio_banks(const size_t mboard) = 0;
515 
516  /*!
517  * Set a GPIO attribute on a particular GPIO bank.
518  * Possible attribute names:
519  * - CTRL - 1 for ATR mode 0 for GPIO mode
520  * - DDR - 1 for output 0 for input
521  * - OUT - GPIO output level (not ATR mode)
522  * - ATR_0X - ATR idle state
523  * - ATR_RX - ATR receive only state
524  * - ATR_TX - ATR transmit only state
525  * - ATR_XX - ATR full duplex state
526  * \param bank the name of a GPIO bank
527  * \param attr the name of a GPIO attribute
528  * \param value the new value for this GPIO bank
529  * \param mask the bit mask to effect which pins are changed
530  * \param mboard the motherboard index 0 to M-1
531  */
532  virtual void set_gpio_attr(const std::string& bank,
533  const std::string& attr,
534  const boost::uint32_t value,
535  const boost::uint32_t mask = 0xffffffff,
536  const size_t mboard = 0) = 0;
537 
538  /*!
539  * Get a GPIO attribute on a particular GPIO bank.
540  * Possible attribute names:
541  * - CTRL - 1 for ATR mode 0 for GPIO mode
542  * - DDR - 1 for output 0 for input
543  * - OUT - GPIO output level (not ATR mode)
544  * - ATR_0X - ATR idle state
545  * - ATR_RX - ATR receive only state
546  * - ATR_TX - ATR transmit only state
547  * - ATR_XX - ATR full duplex state
548  * - READBACK - readback input GPIOs
549  * \param bank the name of a GPIO bank
550  * \param attr the name of a GPIO attribute
551  * \param mboard the motherboard index 0 to M-1
552  * \return the value set for this attribute
553  */
554  virtual boost::uint32_t get_gpio_attr(const std::string& bank,
555  const std::string& attr,
556  const size_t mboard = 0) = 0;
557 
558  /*!
559  * Enumerate the available filters in the signal path.
560  * \param search_mask
561  * \parblock
562  * Select only certain filter names by specifying this search mask.
563  *
564  * E.g. if search mask is set to "rx_frontends/A" only filter names including
565  * that string will be returned. \endparblock \return a vector of strings
566  * representing the selected filter names.
567  */
568  virtual std::vector<std::string>
569  get_filter_names(const std::string& search_mask = "") = 0;
570 
571  /*!
572  * Write back a filter obtained by get_filter() to the signal path.
573  * This filter can be a modified version of the originally returned one.
574  * The information about Rx or Tx is contained in the path parameter.
575  * \param path the name of the filter as returned from get_filter_names().
576  * \param filter the filter_info_base::sptr of the filter object to be written
577  */
578  virtual void set_filter(const std::string& path,
579  ::uhd::filter_info_base::sptr filter) = 0;
580 
581  /*!
582  * Return the filter object for the given name.
583  * @param path the name of the filter as returned from get_filter_names()
584  * @return the filter object
585  */
586  virtual ::uhd::filter_info_base::sptr get_filter(const std::string& path) = 0;
587 };
588 
589 } /* namespace uhd */
590 } /* namespace gr */
591 
592 #endif /* INCLUDED_GR_UHD_USRP_BLOCK_H */
GR_UHD_API const pmt::pmt_t cmd_mboard_key()
boost::shared_ptr< io_signature > sptr
Definition: io_signature.h:46
Definition: usrp_block.h:59
GR_UHD_API const pmt::pmt_t cmd_tune_key()
boost::shared_ptr< pmt_base > pmt_t
typedef for shared pointer (transparent reference counting). See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
Definition: pmt.h:96
GR_UHD_API const pmt::pmt_t ant_direction_rx()
GR_UHD_API const pmt::pmt_t cmd_bandwidth_key()
GR_UHD_API const pmt::pmt_t cmd_lo_freq_key()
::uhd::tune_result_t set_center_freq(double freq, size_t chan=0)
Definition: usrp_block.h:132
GR_UHD_API const pmt::pmt_t ant_direction_tx()
usrp_block()
Definition: usrp_block.h:62
GR_UHD_API const pmt::pmt_t cmd_tag_key()
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
GR_UHD_API const pmt::pmt_t cmd_dsp_freq_key()
synchronous 1:1 input to output with historyOverride work to provide the signal processing implementa...
Definition: sync_block.h:37
GR_UHD_API const pmt::pmt_t cmd_lo_offset_key()
GR_UHD_API const pmt::pmt_t cmd_direction_key()
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:30
GR_UHD_API const pmt::pmt_t cmd_gain_key()
GR_UHD_API const pmt::pmt_t cmd_chan_key()
GR_UHD_API const pmt::pmt_t cmd_antenna_key()
GR_UHD_API const pmt::pmt_t cmd_time_key()
std::vector< std::string > get_dboard_sensor_names(size_t chan=0)
DEPRECATED use get_sensor_names.
Definition: usrp_block.h:315
::uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan=0)
DEPRECATED use get_sensor.
Definition: usrp_block.h:309
GR_UHD_API const pmt::pmt_t cmd_rate_key()
GR_UHD_API const pmt::pmt_t cmd_freq_key()