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