GNU Radio C++ API
gr_uhd_usrp_source.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2011 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_SOURCE_H
23 #define INCLUDED_GR_UHD_USRP_SOURCE_H
24 
25 #include <gr_uhd_api.h>
26 #include <gr_sync_block.h>
27 #include <uhd/usrp/multi_usrp.hpp>
28 
29 class uhd_usrp_source;
30 
31 /*!
32  * \brief Make a new USRP source block.
33  * \ingroup uhd_blk
34  *
35  * The USRP source block receives samples and writes to a stream.
36  * The source block also provides API calls for receiver settings.
37  *
38  * RX Stream tagging:
39  *
40  * The following tag keys will be produced by the work function:
41  * - pmt::pmt_string_to_symbol("rx_time")
42  *
43  * The timstamp tag value is a pmt tuple of the following:
44  * (uint64 seconds, and double fractional seconds).
45  * A timestamp tag is produced at start() and after overflows.
46  *
47  * See the UHD manual for more detailed documentation:
48  * http://code.ettus.com/redmine/ettus/projects/uhd/wiki
49  *
50  * \param device_addr the address to identify the hardware
51  * \param io_type the desired output data type
52  * \param num_channels number of stream from the device
53  * \return a new USRP source block object
54  */
56  const uhd::device_addr_t &device_addr,
57  const uhd::io_type_t &io_type,
58  size_t num_channels
59 );
60 
61 class GR_UHD_API uhd_usrp_source : virtual public gr_sync_block{
62 public:
63 
64  /*!
65  * Set the subdevice specification.
66  * \param spec the subdev spec markup string
67  * \param mboard the motherboard index 0 to M-1
68  */
69  virtual void set_subdev_spec(const std::string &spec, size_t mboard = 0) = 0;
70 
71  /*!
72  * Set the sample rate for the usrp device.
73  * \param rate a new rate in Sps
74  */
75  virtual void set_samp_rate(double rate) = 0;
76 
77  /*!
78  * Get the sample rate for the usrp device.
79  * This is the actual sample rate and may differ from the rate set.
80  * \return the actual rate in Sps
81  */
82  virtual double get_samp_rate(void) = 0;
83 
84  /*!
85  * Tune the usrp device to the desired center frequency.
86  * \param tune_request the tune request instructions
87  * \param chan the channel index 0 to N-1
88  * \return a tune result with the actual frequencies
89  */
90  virtual uhd::tune_result_t set_center_freq(
91  const uhd::tune_request_t tune_request, size_t chan = 0
92  ) = 0;
93 
94  /*!
95  * Tune the usrp device to the desired center frequency.
96  * This is a wrapper around set center freq so that in this case,
97  * the user can pass a single frequency in the call through swig.
98  * \param freq the desired frequency in Hz
99  * \param chan the channel index 0 to N-1
100  * \return a tune result with the actual frequencies
101  */
102  uhd::tune_result_t set_center_freq(double freq, size_t chan = 0){
103  return set_center_freq(uhd::tune_request_t(freq), chan);
104  }
105 
106  /*!
107  * Get the center frequency.
108  * \param chan the channel index 0 to N-1
109  * \return the frequency in Hz
110  */
111  virtual double get_center_freq(size_t chan = 0) = 0;
112 
113  /*!
114  * Get the tunable frequency range.
115  * \param chan the channel index 0 to N-1
116  * \return the frequency range in Hz
117  */
118  virtual uhd::freq_range_t get_freq_range(size_t chan = 0) = 0;
119 
120  /*!
121  * Set the gain for the dboard.
122  * \param gain the gain in dB
123  * \param chan the channel index 0 to N-1
124  */
125  virtual void set_gain(double gain, size_t chan = 0) = 0;
126 
127  /*!
128  * Set the named gain on the dboard.
129  * \param gain the gain in dB
130  * \param name the name of the gain stage
131  * \param chan the channel index 0 to N-1
132  */
133  virtual void set_gain(double gain, const std::string &name, size_t chan = 0) = 0;
134 
135  /*!
136  * Get the actual dboard gain setting.
137  * \param chan the channel index 0 to N-1
138  * \return the actual gain in dB
139  */
140  virtual double get_gain(size_t chan = 0) = 0;
141 
142  /*!
143  * Get the actual dboard gain setting of named stage.
144  * \param name the name of the gain stage
145  * \param chan the channel index 0 to N-1
146  * \return the actual gain in dB
147  */
148  virtual double get_gain(const std::string &name, size_t chan = 0) = 0;
149 
150  /*!
151  * Get the actual dboard gain setting of named stage.
152  * \param chan the channel index 0 to N-1
153  * \return the actual gain in dB
154  */
155  virtual std::vector<std::string> get_gain_names(size_t chan = 0) = 0;
156 
157  /*!
158  * Get the settable gain range.
159  * \param chan the channel index 0 to N-1
160  * \return the gain range in dB
161  */
162  virtual uhd::gain_range_t get_gain_range(size_t chan = 0) = 0;
163 
164  /*!
165  * Get the settable gain range.
166  * \param name the name of the gain stage
167  * \param chan the channel index 0 to N-1
168  * \return the gain range in dB
169  */
170  virtual uhd::gain_range_t get_gain_range(const std::string &name, size_t chan = 0) = 0;
171 
172  /*!
173  * Set the antenna to use.
174  * \param ant the antenna string
175  * \param chan the channel index 0 to N-1
176  */
177  virtual void set_antenna(const std::string &ant, size_t chan = 0) = 0;
178 
179  /*!
180  * Get the antenna in use.
181  * \param chan the channel index 0 to N-1
182  * \return the antenna string
183  */
184  virtual std::string get_antenna(size_t chan = 0) = 0;
185 
186  /*!
187  * Get a list of possible antennas.
188  * \param chan the channel index 0 to N-1
189  * \return a vector of antenna strings
190  */
191  virtual std::vector<std::string> get_antennas(size_t chan = 0) = 0;
192 
193  /*!
194  * Set the subdevice bandpass filter.
195  * \param bandwidth the filter bandwidth in Hz
196  * \param chan the channel index 0 to N-1
197  */
198  virtual void set_bandwidth(double bandwidth, size_t chan = 0) = 0;
199 
200  /*!
201  * Get a daughterboard sensor value.
202  * \param name the name of the sensor
203  * \param chan the channel index 0 to N-1
204  * \return a sensor value object
205  */
206  virtual uhd::sensor_value_t get_dboard_sensor(const std::string &name, size_t chan = 0) = 0;
207 
208  /*!
209  * Get a list of possible daughterboard sensor names.
210  * \param chan the channel index 0 to N-1
211  * \return a vector of sensor names
212  */
213  virtual std::vector<std::string> get_dboard_sensor_names(size_t chan = 0) = 0;
214 
215  /*!
216  * Get a motherboard sensor value.
217  * \param name the name of the sensor
218  * \param mboard the motherboard index 0 to M-1
219  * \return a sensor value object
220  */
221  virtual uhd::sensor_value_t get_mboard_sensor(const std::string &name, size_t mboard = 0) = 0;
222 
223  /*!
224  * Get a list of possible motherboard sensor names.
225  * \param mboard the motherboard index 0 to M-1
226  * \return a vector of sensor names
227  */
228  virtual std::vector<std::string> get_mboard_sensor_names(size_t mboard = 0) = 0;
229 
230  /*!
231  * Set the clock configuration.
232  * \param clock_config the new configuration
233  * \param mboard the motherboard index 0 to M-1
234  */
235  virtual void set_clock_config(const uhd::clock_config_t &clock_config, size_t mboard = 0) = 0;
236 
237  /*!
238  * Get the master clock rate.
239  * \param mboard the motherboard index 0 to M-1
240  * \return the clock rate in Hz
241  */
242  virtual double get_clock_rate(size_t mboard = 0) = 0;
243 
244  /*!
245  * Set the master clock rate.
246  * \param rate the new rate in Hz
247  * \param mboard the motherboard index 0 to M-1
248  */
249  virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
250 
251  /*!
252  * Get the current time registers.
253  * \param mboard the motherboard index 0 to M-1
254  * \return the current usrp time
255  */
256  virtual uhd::time_spec_t get_time_now(size_t mboard = 0) = 0;
257 
258  /*!
259  * Get the time when the last pps pulse occured.
260  * \param mboard the motherboard index 0 to M-1
261  * \return the current usrp time
262  */
263  virtual uhd::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
264 
265  /*!
266  * Sets the time registers immediately.
267  * \param time_spec the new time
268  * \param mboard the motherboard index 0 to M-1
269  */
270  virtual void set_time_now(const uhd::time_spec_t &time_spec, size_t mboard = 0) = 0;
271 
272  /*!
273  * Set the time registers at the next pps.
274  * \param time_spec the new time
275  */
276  virtual void set_time_next_pps(const uhd::time_spec_t &time_spec) = 0;
277 
278  /*!
279  * Sync the time registers with an unknown pps edge.
280  * \param time_spec the new time
281  */
282  virtual void set_time_unknown_pps(const uhd::time_spec_t &time_spec) = 0;
283 
284  /*!
285  * Get access to the underlying uhd dboard iface object.
286  * \return the dboard_iface object
287  */
288  virtual uhd::usrp::dboard_iface::sptr get_dboard_iface(size_t chan = 0) = 0;
289 
290  /*!
291  * Get access to the underlying uhd device object.
292  * \return the multi usrp device object
293  */
294  virtual uhd::usrp::multi_usrp::sptr get_device(void) = 0;
295 };
296 
297 #endif /* INCLUDED_GR_UHD_USRP_SOURCE_H */