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