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_sink.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_SINK_H
24 #define INCLUDED_GR_UHD_USRP_SINK_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 {
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_sink;
56 
57  class GR_UHD_API usrp_sink : virtual public sync_block
58  {
59  public:
60  // gr::uhd::usrp_sink::sptr
61  typedef boost::shared_ptr<usrp_sink> sptr;
62 
63  /*!
64  * \brief DEPRECATED Make a new USRP sink 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::usrp_sink::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 sink block (usually a radio transmitter).
76  *
77  * The USRP sink block reads a stream and transmits the samples.
78  * The sink block also provides API calls for transmitter settings.
79  *
80  * \section uhd_tx_tagging TX Stream tagging
81  *
82  * The following tag keys will be consumed by the work function:
83  * - pmt::string_to_symbol("tx_sob")
84  * - pmt::string_to_symbol("tx_eob")
85  * - pmt::string_to_symbol("tx_time")
86  * - pmt::string_to_symbol("tx_freq")
87  * - pmt::string_to_symbol("tx_command")
88  * - pmt::string_to_symbol(tsb_tag_name)
89  *
90  * Any other tag will be ignored.
91  *
92  * The sob and eob (start and end of burst) tag values are pmt booleans.
93  * When present, burst tags should be set to true (pmt::PMT_T).
94  *
95  * If `tsb_tag_name` is not an empty string, all "tx_sob" and "tx_eob"
96  * tags will be ignored, and the input is assumed to a tagged stream,
97  * as described in \ref page_tagged_stream_blocks.
98  *
99  * If sob/eob tags or length tags are used, this block understands that
100  * the data is bursty, and will configure the USRP to make sure there's
101  * no underruns after transmitting the final sample of a burst.
102  *
103  * The timestamp tag value is a PMT tuple of the following:
104  * (uint64 seconds, double fractional seconds).
105  *
106  * The tx_freq tag has to be a double or a pair of form (channel, frequency),
107  * with frequency being a double and channel being an integer.
108  * This tag will trigger a tune command to the USRP
109  * to the given frequency, if possible. Note that oscillators need some time
110  * to stabilize after this! Don't expect clean data to be sent immediately after this command.
111  * If channel is omitted, and only a double is given, it will set this frequency to all
112  * channels.
113  *
114  * The command tag can carry a PMT command. See the following section.
115  *
116  * \section uhd_tx_commands Command interface
117  *
118  * There are two ways of passing commands to this block:
119  * 1. tx_command tag. The command is attached to a sample, and will executed
120  * before the sample is transmitted, and after the previous sample.
121  * 2. The 'command' message port. The command is executed asynchronously,
122  * as soon as possible.
123  *
124  * In both cases, the payload of the command is a PMT command, as described
125  * in Section \ref uhd_command_syntax.
126  *
127  * For a more general description of the gr-uhd components, see \ref page_uhd.
128  *
129  * \param device_addr the address to identify the hardware
130  * \param stream_args the IO format and channel specification
131  * \param tsb_tag_name the name of the tag identifying tagged stream length
132  * \return a new USRP sink block object
133  */
134  static sptr make(const ::uhd::device_addr_t &device_addr,
135  const ::uhd::stream_args_t &stream_args,
136  const std::string &tsb_tag_name = "");
137 
138  /*!
139  * Set the start time for outgoing samples.
140  * To control when samples are transmitted,
141  * set this value before starting the flow graph.
142  * The value is cleared after each run.
143  * When not specified, the start time will be:
144  * - Immediately for the one channel case
145  * - in the near future for multi-channel
146  *
147  * \param time the absolute time for transmission to begin
148  */
149  virtual void set_start_time(const ::uhd::time_spec_t &time) = 0;
150 
151  /*!
152  * Returns identifying information about this USRP's configuration.
153  * Returns motherboard ID, name, and serial.
154  * Returns daughterboard TX ID, subdev name and spec, serial, and antenna.
155  * \param chan channel index 0 to N-1
156  * \return TX info
157  */
158  virtual ::uhd::dict<std::string, std::string> get_usrp_info(size_t chan = 0) = 0;
159 
160  /*!
161  * Set the frontend specification.
162  * \param spec the subdev spec markup string
163  * \param mboard the motherboard index 0 to M-1
164  */
165  virtual void set_subdev_spec(const std::string &spec, size_t mboard = 0) = 0;
166 
167  /*!
168  * Get the TX frontend specification.
169  * \param mboard the motherboard index 0 to M-1
170  * \return the frontend specification in use
171  */
172  virtual std::string get_subdev_spec (size_t mboard = 0) = 0;
173 
174  /*!
175  * Set the sample rate for the usrp device.
176  * \param rate a new rate in Sps
177  */
178  virtual void set_samp_rate(double rate) = 0;
179 
180  /*!
181  * Get the sample rate for the usrp device.
182  * This is the actual sample rate and may differ from the rate set.
183  * \return the actual rate in Sps
184  */
185  virtual double get_samp_rate(void) = 0;
186 
187  /*!
188  * Get the possible sample rates for the usrp device.
189  * \return a range of rates in Sps
190  */
191  virtual ::uhd::meta_range_t get_samp_rates(void) = 0;
192 
193  /*!
194  * Tune the usrp device to the desired center frequency.
195  * \param tune_request the tune request instructions
196  * \param chan the channel index 0 to N-1
197  * \return a tune result with the actual frequencies
198  */
199  virtual ::uhd::tune_result_t set_center_freq
200  (const ::uhd::tune_request_t tune_request, size_t chan = 0) = 0;
201 
202  /*!
203  * Tune the usrp device to the desired center frequency.
204  * This is a wrapper around set center freq so that in this case,
205  * the user can pass a single frequency in the call through swig.
206  * \param freq the desired frequency in Hz
207  * \param chan the channel index 0 to N-1
208  * \return a tune result with the actual frequencies
209  */
210  ::uhd::tune_result_t set_center_freq(double freq, size_t chan = 0)
211  {
212  return set_center_freq(::uhd::tune_request_t(freq), chan);
213  }
214 
215  /*!
216  * Get the center frequency.
217  * \param chan the channel index 0 to N-1
218  * \return the frequency in Hz
219  */
220  virtual double get_center_freq(size_t chan = 0) = 0;
221 
222  /*!
223  * Get the tunable frequency range.
224  * \param chan the channel index 0 to N-1
225  * \return the frequency range in Hz
226  */
227  virtual ::uhd::freq_range_t get_freq_range(size_t chan = 0) = 0;
228 
229  /*!
230  * Set the gain for the dboard.
231  * \param gain the gain in dB
232  * \param chan the channel index 0 to N-1
233  */
234  virtual void set_gain(double gain, size_t chan = 0) = 0;
235 
236  /*!
237  * Set the named gain on the dboard.
238  * \param gain the gain in dB
239  * \param name the name of the gain stage
240  * \param chan the channel index 0 to N-1
241  */
242  virtual void set_gain(double gain,
243  const std::string &name,
244  size_t chan = 0) = 0;
245 
246  /*!
247  * Get the actual dboard gain setting.
248  * \param chan the channel index 0 to N-1
249  * \return the actual gain in dB
250  */
251  virtual double get_gain(size_t chan = 0) = 0;
252 
253  /*!
254  * Get the actual dboard gain setting of named stage.
255  * \param name the name of the gain stage
256  * \param chan the channel index 0 to N-1
257  * \return the actual gain in dB
258  */
259  virtual double get_gain(const std::string &name,
260  size_t chan = 0) = 0;
261 
262  /*!
263  * Get the actual dboard gain setting of named stage.
264  * \param chan the channel index 0 to N-1
265  * \return the actual gain in dB
266  */
267  virtual std::vector<std::string> get_gain_names(size_t chan = 0) = 0;
268 
269  /*!
270  * Get the settable gain range.
271  * \param chan the channel index 0 to N-1
272  * \return the gain range in dB
273  */
274  virtual ::uhd::gain_range_t get_gain_range(size_t chan = 0) = 0;
275 
276  /*!
277  * Get the settable gain range.
278  * \param name the name of the gain stage
279  * \param chan the channel index 0 to N-1
280  * \return the gain range in dB
281  */
282  virtual ::uhd::gain_range_t get_gain_range(const std::string &name,
283  size_t chan = 0) = 0;
284 
285  /*!
286  * Set the antenna to use.
287  * \param ant the antenna string
288  * \param chan the channel index 0 to N-1
289  */
290  virtual void set_antenna(const std::string &ant,
291  size_t chan = 0) = 0;
292 
293  /*!
294  * Get the antenna in use.
295  * \param chan the channel index 0 to N-1
296  * \return the antenna string
297  */
298  virtual std::string get_antenna(size_t chan = 0) = 0;
299 
300  /*!
301  * Get a list of possible antennas.
302  * \param chan the channel index 0 to N-1
303  * \return a vector of antenna strings
304  */
305  virtual std::vector<std::string> get_antennas(size_t chan = 0) = 0;
306 
307  /*!
308  * Set the bandpass filter on the RF frontend.
309  * \param bandwidth the filter bandwidth in Hz
310  * \param chan the channel index 0 to N-1
311  */
312  virtual void set_bandwidth(double bandwidth, size_t chan = 0) = 0;
313 
314  /*!
315  * Get the bandpass filter setting on the RF frontend.
316  * \param chan the channel index 0 to N-1
317  * \return bandwidth of the filter in Hz
318  */
319  virtual double get_bandwidth(size_t chan = 0) = 0;
320 
321  /*!
322  * Get the bandpass filter range of the RF frontend.
323  * \param chan the channel index 0 to N-1
324  * \return the range of the filter bandwidth in Hz
325  */
326  virtual ::uhd::freq_range_t get_bandwidth_range(size_t chan = 0) = 0;
327 
328  /*!
329  * Set a constant DC offset value.
330  * The value is complex to control both I and Q.
331  * \param offset the dc offset (1.0 is full-scale)
332  * \param chan the channel index 0 to N-1
333  */
334  virtual void set_dc_offset(const std::complex<double> &offset,
335  size_t chan = 0) = 0;
336 
337  /*!
338  * Set the RX frontend IQ imbalance correction.
339  * Use this to adjust the magnitude and phase of I and Q.
340  *
341  * \param correction the complex correction (1.0 is full-scale)
342  * \param chan the channel index 0 to N-1
343  */
344  virtual void set_iq_balance(const std::complex<double> &correction,
345  size_t chan = 0) = 0;
346 
347  /*!
348  * Get an RF frontend sensor value.
349  * \param name the name of the sensor
350  * \param chan the channel index 0 to N-1
351  * \return a sensor value object
352  */
353  virtual ::uhd::sensor_value_t get_sensor(const std::string &name,
354  size_t chan = 0) = 0;
355 
356  /*!
357  * Get a list of possible RF frontend sensor names.
358  * \param chan the channel index 0 to N-1
359  * \return a vector of sensor names
360  */
361  virtual std::vector<std::string> get_sensor_names(size_t chan = 0) = 0;
362 
363  //! DEPRECATED use get_sensor
364  ::uhd::sensor_value_t get_dboard_sensor(const std::string &name,
365  size_t chan = 0)
366  {
367  return this->get_sensor(name, chan);
368  }
369 
370  //! DEPRECATED use get_sensor_names
371  std::vector<std::string> get_dboard_sensor_names(size_t chan = 0)
372  {
373  return this->get_sensor_names(chan);
374  }
375 
376  /*!
377  * Get a motherboard sensor value.
378  * \param name the name of the sensor
379  * \param mboard the motherboard index 0 to M-1
380  * \return a sensor value object
381  */
382  virtual ::uhd::sensor_value_t get_mboard_sensor(const std::string &name,
383  size_t mboard = 0) = 0;
384 
385  /*!
386  * Get a list of possible motherboard sensor names.
387  * \param mboard the motherboard index 0 to M-1
388  * \return a vector of sensor names
389  */
390  virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
391 
392  /*!
393  * Set the clock configuration.
394  * DEPRECATED for set_time/clock_source.
395  * \param clock_config the new configuration
396  * \param mboard the motherboard index 0 to M-1
397  */
398  virtual void set_clock_config(const ::uhd::clock_config_t &clock_config,
399  size_t mboard = 0) = 0;
400 
401  /*!
402  * Set the time source for the usrp device.
403  * This sets the method of time synchronization,
404  * typically a pulse per second or an encoded time.
405  * Typical options for source: external, MIMO.
406  * \param source a string representing the time source
407  * \param mboard which motherboard to set the config
408  */
409  virtual void set_time_source(const std::string &source,
410  const size_t mboard = 0) = 0;
411 
412  /*!
413  * Get the currently set time source.
414  * \param mboard which motherboard to get the config
415  * \return the string representing the time source
416  */
417  virtual std::string get_time_source(const size_t mboard) = 0;
418 
419  /*!
420  * Get a list of possible time sources.
421  * \param mboard which motherboard to get the list
422  * \return a vector of strings for possible settings
423  */
424  virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
425 
426  /*!
427  * Set the clock source for the usrp device.
428  * This sets the source for a 10 Mhz reference clock.
429  * Typical options for source: internal, external, MIMO.
430  * \param source a string representing the clock source
431  * \param mboard which motherboard to set the config
432  */
433  virtual void set_clock_source(const std::string &source,
434  const size_t mboard = 0) = 0;
435 
436  /*!
437  * Get the currently set clock source.
438  * \param mboard which motherboard to get the config
439  * \return the string representing the clock source
440  */
441  virtual std::string get_clock_source(const size_t mboard) = 0;
442 
443  /*!
444  * Get a list of possible clock sources.
445  * \param mboard which motherboard to get the list
446  * \return a vector of strings for possible settings
447  */
448  virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
449 
450  /*!
451  * Get the master clock rate.
452  * \param mboard the motherboard index 0 to M-1
453  * \return the clock rate in Hz
454  */
455  virtual double get_clock_rate(size_t mboard = 0) = 0;
456 
457  /*!
458  * Set the master clock rate.
459  * \param rate the new rate in Hz
460  * \param mboard the motherboard index 0 to M-1
461  */
462  virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
463 
464  /*!
465  * Get the current time registers.
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_now(size_t mboard = 0) = 0;
470 
471  /*!
472  * Get the time when the last pps pulse occured.
473  * \param mboard the motherboard index 0 to M-1
474  * \return the current usrp time
475  */
476  virtual ::uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
477 
478  /*!
479  * Sets the time registers immediately.
480  * \param time_spec the new time
481  * \param mboard the motherboard index 0 to M-1
482  */
483  virtual void set_time_now(const ::uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
484 
485  /*!
486  * Set the time registers at the next pps.
487  * \param time_spec the new time
488  */
489  virtual void set_time_next_pps(const ::uhd::time_spec_t &time_spec) = 0;
490 
491  /*!
492  * Sync the time registers with an unknown pps edge.
493  * \param time_spec the new time
494  */
495  virtual void set_time_unknown_pps(const ::uhd::time_spec_t &time_spec) = 0;
496 
497  /*!
498  * Set the time at which the control commands will take effect.
499  *
500  * A timed command will back-pressure all subsequent timed commands,
501  * assuming that the subsequent commands occur within the time-window.
502  * If the time spec is late, the command will be activated upon arrival.
503  *
504  * \param time_spec the time at which the next command will activate
505  * \param mboard which motherboard to set the config
506  */
507  virtual void set_command_time(const ::uhd::time_spec_t &time_spec,
508  size_t mboard = 0) = 0;
509 
510  /*!
511  * Clear the command time so future commands are sent ASAP.
512  *
513  * \param mboard which motherboard to set the config
514  */
515  virtual void clear_command_time(size_t mboard = 0) = 0;
516 
517  /*!
518  * Get access to the underlying uhd dboard iface object.
519  * \return the dboard_iface object
520  */
521  virtual ::uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
522 
523  /*!
524  * Get access to the underlying uhd device object.
525  *
526  * NOTE: This function is only available in C++.
527  * \return the multi usrp device object
528  */
529  virtual ::uhd::usrp::multi_usrp::sptr get_device(void) = 0;
530 
531  /*!
532  * Perform write on the user configuration register bus. These
533  * only exist if the user has implemented custom setting
534  * registers in the device FPGA.
535  * \param addr 8-bit register address
536  * \param data 32-bit register value
537  * \param mboard which motherboard to set the user register
538  */
539  virtual void set_user_register(const uint8_t addr,
540  const uint32_t data,
541  size_t mboard = 0) = 0;
542  };
543 
544  } /* namespace uhd */
545 } /* namespace gr */
546 
547 #endif /* INCLUDED_GR_UHD_USRP_SINK_H */
std::vector< std::string > get_dboard_sensor_names(size_t chan=0)
DEPRECATED use get_sensor_names.
Definition: usrp_sink.h:371
::uhd::tune_result_t set_center_freq(double freq, size_t chan=0)
Definition: usrp_sink.h:210
::uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan=0)
DEPRECATED use get_sensor.
Definition: usrp_sink.h:364
Definition: usrp_sink.h:57
std::string otw_format
Definition: usrp_sink.h:42
std::string cpu_format
Definition: usrp_sink.h:41
boost::shared_ptr< usrp_sink > sptr
Definition: usrp_sink.h:61
stream_args_t(const std::string &cpu="", const std::string &otw="")
Definition: usrp_sink.h:35
synchronous 1:1 input to output with historyOverride work to provide the signal processing implementa...
Definition: sync_block.h:37
device_addr_t args
Definition: usrp_sink.h:43
Definition: usrp_sink.h:33
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:30
std::vector< size_t > channels
Definition: usrp_sink.h:44