GNU Radio 3.6.2 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  * Set a constant DC offset value.
294  * The value is complex to control both I and Q.
295  * \param offset the dc offset (1.0 is full-scale)
296  * \param chan the channel index 0 to N-1
297  */
298  virtual void set_dc_offset(const std::complex<double> &offset, size_t chan = 0) = 0;
299 
300  /*!
301  * Set the RX frontend IQ imbalance correction.
302  * Use this to adjust the magnitude and phase of I and Q.
303  *
304  * \param correction the complex correction (1.0 is full-scale)
305  * \param chan the channel index 0 to N-1
306  */
307  virtual void set_iq_balance(const std::complex<double> &correction, size_t chan = 0) = 0;
308 
309  /*!
310  * Get an RF frontend sensor value.
311  * \param name the name of the sensor
312  * \param chan the channel index 0 to N-1
313  * \return a sensor value object
314  */
315  virtual uhd::sensor_value_t get_sensor(const std::string &name, size_t chan = 0) = 0;
316 
317  /*!
318  * Get a list of possible RF frontend sensor names.
319  * \param chan the channel index 0 to N-1
320  * \return a vector of sensor names
321  */
322  virtual std::vector<std::string> get_sensor_names(size_t chan = 0) = 0;
323 
324  //! DEPRECATED use get_sensor
325  uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan = 0){
326  return this->get_sensor(name, chan);
327  }
328 
329  //! DEPRECATED use get_sensor_names
330  std::vector<std::string> get_dboard_sensor_names(size_t chan = 0){
331  return this->get_sensor_names(chan);
332  }
333 
334  /*!
335  * Get a motherboard sensor value.
336  * \param name the name of the sensor
337  * \param mboard the motherboard index 0 to M-1
338  * \return a sensor value object
339  */
340  virtual uhd::sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard = 0) = 0;
341 
342  /*!
343  * Get a list of possible motherboard sensor names.
344  * \param mboard the motherboard index 0 to M-1
345  * \return a vector of sensor names
346  */
347  virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
348 
349  /*!
350  * Set the clock configuration.
351  * DEPRECATED for set_time/clock_source.
352  * \param clock_config the new configuration
353  * \param mboard the motherboard index 0 to M-1
354  */
355  virtual void set_clock_config(const uhd::clock_config_t &clock_config, size_t mboard = 0) = 0;
356 
357  /*!
358  * Set the time source for the usrp device.
359  * This sets the method of time synchronization,
360  * typically a pulse per second or an encoded time.
361  * Typical options for source: external, MIMO.
362  * \param source a string representing the time source
363  * \param mboard which motherboard to set the config
364  */
365  virtual void set_time_source(const std::string &source, const size_t mboard = 0) = 0;
366 
367  /*!
368  * Get the currently set time source.
369  * \param mboard which motherboard to get the config
370  * \return the string representing the time source
371  */
372  virtual std::string get_time_source(const size_t mboard) = 0;
373 
374  /*!
375  * Get a list of possible time sources.
376  * \param mboard which motherboard to get the list
377  * \return a vector of strings for possible settings
378  */
379  virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
380 
381  /*!
382  * Set the clock source for the usrp device.
383  * This sets the source for a 10 Mhz reference clock.
384  * Typical options for source: internal, external, MIMO.
385  * \param source a string representing the clock source
386  * \param mboard which motherboard to set the config
387  */
388  virtual void set_clock_source(const std::string &source, const size_t mboard = 0) = 0;
389 
390  /*!
391  * Get the currently set clock source.
392  * \param mboard which motherboard to get the config
393  * \return the string representing the clock source
394  */
395  virtual std::string get_clock_source(const size_t mboard) = 0;
396 
397  /*!
398  * Get a list of possible clock sources.
399  * \param mboard which motherboard to get the list
400  * \return a vector of strings for possible settings
401  */
402  virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
403 
404  /*!
405  * Get the master clock rate.
406  * \param mboard the motherboard index 0 to M-1
407  * \return the clock rate in Hz
408  */
409  virtual double get_clock_rate(size_t mboard = 0) = 0;
410 
411  /*!
412  * Set the master clock rate.
413  * \param rate the new rate in Hz
414  * \param mboard the motherboard index 0 to M-1
415  */
416  virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
417 
418  /*!
419  * Get the current time registers.
420  * \param mboard the motherboard index 0 to M-1
421  * \return the current usrp time
422  */
423  virtual uhd::time_spec_t get_time_now(size_t mboard = 0) = 0;
424 
425  /*!
426  * Get the time when the last pps pulse occured.
427  * \param mboard the motherboard index 0 to M-1
428  * \return the current usrp time
429  */
430  virtual uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
431 
432  /*!
433  * Sets the time registers immediately.
434  * \param time_spec the new time
435  * \param mboard the motherboard index 0 to M-1
436  */
437  virtual void set_time_now(const uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
438 
439  /*!
440  * Set the time registers at the next pps.
441  * \param time_spec the new time
442  */
443  virtual void set_time_next_pps(const uhd::time_spec_t &time_spec) = 0;
444 
445  /*!
446  * Sync the time registers with an unknown pps edge.
447  * \param time_spec the new time
448  */
449  virtual void set_time_unknown_pps(const uhd::time_spec_t &time_spec) = 0;
450 
451  /*!
452  * Set the time at which the control commands will take effect.
453  *
454  * A timed command will back-pressure all subsequent timed commands,
455  * assuming that the subsequent commands occur within the time-window.
456  * If the time spec is late, the command will be activated upon arrival.
457  *
458  * \param time_spec the time at which the next command will activate
459  * \param mboard which motherboard to set the config
460  */
461  virtual void set_command_time(const uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
462 
463  /*!
464  * Clear the command time so future commands are sent ASAP.
465  *
466  * \param mboard which motherboard to set the config
467  */
468  virtual void clear_command_time(size_t mboard = 0) = 0;
469 
470  /*!
471  * Get access to the underlying uhd dboard iface object.
472  * \return the dboard_iface object
473  */
474  virtual uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
475 
476  /*!
477  * Get access to the underlying uhd device object.
478  * \return the multi usrp device object
479  */
480  virtual uhd::usrp::multi_usrp::sptr get_device(void) = 0;
481 
482  /*!
483  * Perform write on the user configuration register bus. These only exist if
484  * the user has implemented custom setting registers in the device FPGA.
485  * \param addr 8-bit register address
486  * \param data 32-bit register value
487  * \param mboard which motherboard to set the user register
488  */
489  virtual void set_user_register(const uint8_t addr, const uint32_t data, size_t mboard = 0) = 0;
490 };
491 
492 #endif /* INCLUDED_GR_UHD_USRP_SINK_H */