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