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