GNU Radio Manual and C++ API Reference  3.10.9.1
The Free & Open Software Radio Ecosystem
usrp_sink.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2010-2016 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * SPDX-License-Identifier: GPL-3.0-or-later
8  *
9  */
10 
11 #ifndef INCLUDED_GR_UHD_USRP_SINK_H
12 #define INCLUDED_GR_UHD_USRP_SINK_H
13 
15 
16 namespace gr {
17 namespace uhd {
18 
19 class uhd_usrp_sink;
20 
21 /*! USRP Sink -- Radio Transmitter
22  * \ingroup uhd_blk
23  *
24  *
25  * The USRP sink block reads a stream and transmits the samples.
26  * The sink block also provides API calls for transmitter settings.
27  * See also gr::uhd::usrp_block for more public API calls.
28  *
29  * \section uhd_tx_tagging TX Stream tagging
30  *
31  * The following tag keys will be consumed by the work function:
32  * - pmt::string_to_symbol("tx_sob")
33  * - pmt::string_to_symbol("tx_eob")
34  * - pmt::string_to_symbol("tx_time")
35  * - pmt::string_to_symbol("tx_freq")
36  * - pmt::string_to_symbol("tx_command")
37  * - pmt::string_to_symbol(tsb_tag_name)
38  *
39  * Any other tag will be ignored.
40  *
41  * \section uhd_tx_burstys Bursty Transmission
42  *
43  * There are multiple ways to do bursty transmission without triggering
44  * underruns:
45  * - Using SOB/EOB tags
46  * - Using tagged streams (See <a
47  * href="https://wiki.gnuradio.org/index.php/Tagged_Stream_Blocks" target="_blank">Tagged
48  * Stream Blocks</a>)
49  *
50  * The sob and eob (start and end of burst) tag values are pmt booleans.
51  * When present, burst tags should be set to true (pmt::PMT_T).
52  *
53  * If `tsb_tag_name` is not an empty string, all "tx_sob" and "tx_eob"
54  * tags will be ignored, and the input is assumed to a tagged stream.
55  *
56  * If sob/eob tags or length tags are used, this block understands that
57  * the data is bursty, and will configure the USRP to make sure there's
58  * no underruns after transmitting the final sample of a burst.
59  *
60  * \section uhd_tx_time Timestamps
61  *
62  * The timestamp tag value is a PMT tuple of the following:
63  * (uint64 seconds, double fractional seconds).
64  *
65  * The tx_freq tag has to be a double or a pair of form (channel, frequency),
66  * with frequency being a double and channel being an integer.
67  * This tag will trigger a tune command to the USRP
68  * to the given frequency, if possible. Note that oscillators need some time
69  * to stabilize after this! Don't expect clean data to be sent immediately after this
70  * command. If channel is omitted, and only a double is given, it will set this frequency
71  * to all channels.
72  *
73  * The command tag can carry a PMT command. See the following section.
74  *
75  * \section uhd_tx_commands Command interface
76  *
77  * There are two ways of passing commands to this block:
78  * 1. tx_command tag. The command is attached to a sample, and will executed
79  * before the sample is transmitted, and after the previous sample.
80  * 2. The 'command' message port. The command is executed asynchronously,
81  * as soon as possible.
82  *
83  * In both cases, the payload of the command is a PMT command, as described
84  * in Section \ref uhd_command_syntax.
85  *
86  * For a more general description of the gr-uhd components, see \ref page_uhd.
87  */
88 class GR_UHD_API usrp_sink : virtual public usrp_block
89 {
90 public:
91  // gr::uhd::usrp_sink::sptr
92  typedef std::shared_ptr<usrp_sink> sptr;
93 
94  /*!
95  * \param device_addr the address to identify the hardware
96  * \param stream_args the IO format and channel specification
97  * \param tsb_tag_name the name of the tag identifying tagged stream length
98  * \return a new USRP sink block object
99  */
100  static sptr make(const ::uhd::device_addr_t& device_addr,
101  const ::uhd::stream_args_t& stream_args,
102  const std::string& tsb_tag_name = "");
103 
104  // Also accept a string for the device_addr
105  static sptr make(const std::string& device_addr_str,
106  const ::uhd::stream_args_t& stream_args,
107  const std::string& tsb_tag_name = "")
108  {
109  return make(::uhd::device_addr_t(device_addr_str), stream_args, tsb_tag_name);
110  }
111 
112  /*!
113  * Set the start time for outgoing samples.
114  * To control when samples are transmitted,
115  * set this value before starting the flow graph.
116  * The value is cleared after each run.
117  * When not specified, the start time will be:
118  * - Immediately for the one channel case
119  * - in the near future for multi-channel
120  *
121  * \param time the absolute time for transmission to begin
122  */
123  virtual void set_start_time(const ::uhd::time_spec_t& time) = 0;
124 
125  /*!
126  * Get a list of possible LO stage names
127  * \param chan the channel index 0 to N-1
128  * \return a vector of strings for possible LO names
129  */
130  virtual std::vector<std::string> get_lo_names(size_t chan = 0) = 0;
131 
132  /*!
133  * Set the LO source for the usrp device.
134  * For usrps that support selectable LOs, this function
135  * allows switching between them.
136  * Typical options for source: internal, external.
137  * \param src a string representing the LO source
138  * \param name the name of the LO stage to update
139  * \param chan the channel index 0 to N-1
140  */
141  virtual void
142  set_lo_source(const std::string& src, const std::string& name, size_t chan = 0) = 0;
143 
144  /*!
145  * Get the currently set LO source.
146  * \param name the name of the LO stage to query
147  * \param chan the channel index 0 to N-1
148  * \return the configured LO source
149  */
150  virtual const std::string get_lo_source(const std::string& name, size_t chan = 0) = 0;
151 
152  /*!
153  * Get a list of possible LO sources.
154  * \param name the name of the LO stage to query
155  * \param chan the channel index 0 to N-1
156  * \return a vector of strings for possible settings
157  */
158  virtual std::vector<std::string> get_lo_sources(const std::string& name,
159  size_t chan = 0) = 0;
160 
161  /*!
162  * Set whether the LO used by the usrp device is exported
163  * For usrps that support exportable LOs, this function
164  * configures if the LO used by chan is exported or not.
165  * \param enabled if true then export the LO
166  * \param name the name of the LO stage to update
167  * \param chan the channel index 0 to N-1 for the source channel
168  */
169  virtual void
170  set_lo_export_enabled(bool enabled, const std::string& name, size_t chan = 0) = 0;
171 
172  /*!
173  * Returns true if the currently selected LO is being exported.
174  * \param name the name of the LO stage to query
175  * \param chan the channel index 0 to N-1
176  */
177  virtual bool get_lo_export_enabled(const std::string& name, size_t chan = 0) = 0;
178 
179  /*!
180  * Set the RX LO frequency (Advanced).
181  * \param freq the frequency to set the LO to
182  * \param name the name of the LO stage to update
183  * \param chan the channel index 0 to N-1
184  * \return a coerced LO frequency
185  */
186  virtual double set_lo_freq(double freq, const std::string& name, size_t chan = 0) = 0;
187 
188  /*!
189  * Get the current RX LO frequency (Advanced).
190  * \param name the name of the LO stage to query
191  * \param chan the channel index 0 to N-1
192  * \return the configured LO frequency
193  */
194  virtual double get_lo_freq(const std::string& name, size_t chan = 0) = 0;
195 
196  /*!
197  * Get the LO frequency range of the RX LO.
198  * \param name the name of the LO stage to query
199  * \param chan the channel index 0 to N-1
200  * \return a frequency range object
201  */
202  virtual ::uhd::freq_range_t get_lo_freq_range(const std::string& name,
203  size_t chan = 0) = 0;
204 
205  /*!
206  * Set a constant DC offset value.
207  * The value is complex to control both I and Q.
208  * \param offset the dc offset (1.0 is full-scale)
209  * \param chan the channel index 0 to N-1
210  */
211  virtual void set_dc_offset(const std::complex<double>& offset, size_t chan = 0) = 0;
212 
213  /*!
214  * Set the RX frontend IQ imbalance correction.
215  * Use this to adjust the magnitude and phase of I and Q.
216  *
217  * \param correction the complex correction (1.0 is full-scale)
218  * \param chan the channel index 0 to N-1
219  */
220  virtual void set_iq_balance(const std::complex<double>& correction,
221  size_t chan = 0) = 0;
222 };
223 
224 } /* namespace uhd */
225 } /* namespace gr */
226 
227 #endif /* INCLUDED_GR_UHD_USRP_SINK_H */
Definition: usrp_block.h:32
Definition: usrp_sink.h:89
virtual std::vector< std::string > get_lo_names(size_t chan=0)=0
virtual void set_lo_source(const std::string &src, const std::string &name, size_t chan=0)=0
virtual void set_lo_export_enabled(bool enabled, const std::string &name, size_t chan=0)=0
virtual void set_start_time(const ::uhd::time_spec_t &time)=0
virtual ::uhd::freq_range_t get_lo_freq_range(const std::string &name, size_t chan=0)=0
virtual bool get_lo_export_enabled(const std::string &name, size_t chan=0)=0
virtual std::vector< std::string > get_lo_sources(const std::string &name, size_t chan=0)=0
virtual double set_lo_freq(double freq, const std::string &name, size_t chan=0)=0
virtual void set_iq_balance(const std::complex< double > &correction, size_t chan=0)=0
virtual const std::string get_lo_source(const std::string &name, size_t chan=0)=0
static sptr make(const std::string &device_addr_str, const ::uhd::stream_args_t &stream_args, const std::string &tsb_tag_name="")
Definition: usrp_sink.h:105
std::shared_ptr< usrp_sink > sptr
Definition: usrp_sink.h:92
virtual void set_dc_offset(const std::complex< double > &offset, size_t chan=0)=0
virtual double get_lo_freq(const std::string &name, size_t chan=0)=0
static sptr make(const ::uhd::device_addr_t &device_addr, const ::uhd::stream_args_t &stream_args, const std::string &tsb_tag_name="")
#define GR_UHD_API
Definition: gr-uhd/include/gnuradio/uhd/api.h:18
GNU Radio logging wrapper.
Definition: basic_block.h:29