GNU Radio's OsmoSDR Package
source.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
4  *
5  * GNU Radio is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3, or (at your option)
8  * any later version.
9  *
10  * GNU Radio is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with GNU Radio; see the file COPYING. If not, write to
17  * the Free Software Foundation, Inc., 51 Franklin Street,
18  * Boston, MA 02110-1301, USA.
19  */
20 #ifndef INCLUDED_OSMOSDR_SOURCE_H
21 #define INCLUDED_OSMOSDR_SOURCE_H
22 
23 #include <osmosdr/api.h>
24 #include <osmosdr/ranges.h>
25 #include <gnuradio/hier_block2.h>
26 
27 namespace osmosdr {
28 
29 class source;
30 
31 /*!
32  * \brief Provides a stream of complex samples.
33  * \ingroup block
34  *
35  * This uses the preferred technique: subclassing gr::hier_block2.
36  */
37 class OSMOSDR_API source : virtual public gr::hier_block2
38 {
39 public:
40  typedef boost::shared_ptr< source > sptr;
41 
42  /*!
43  * \brief Return a shared_ptr to a new instance of source.
44  *
45  * To avoid accidental use of raw pointers, source's
46  * constructor is private. osmosdr::source::make is the public
47  * interface for creating new instances.
48  *
49  * \param args the address to identify the hardware
50  * \return a new osmosdr source block object
51  */
52  static sptr make( const std::string & args = "" );
53 
54  /*!
55  * Get the number of channels the underlying radio hardware offers.
56  * \return the number of available channels
57  */
58  virtual size_t get_num_channels( void ) = 0;
59 
60  /*!
61  * Get the possible sample rates for the underlying radio hardware.
62  * \return a range of rates in Sps
63  */
64  virtual osmosdr::meta_range_t get_sample_rates( void ) = 0;
65 
66  /*!
67  * Set the sample rate for the underlying radio hardware.
68  * This also will select the appropriate IF bandpass, if applicable.
69  * \param rate a new rate in Sps
70  */
71  virtual double set_sample_rate( double rate ) = 0;
72 
73  /*!
74  * Get the sample rate for the underlying radio hardware.
75  * This is the actual sample rate and may differ from the rate set.
76  * \return the actual rate in Sps
77  */
78  virtual double get_sample_rate( void ) = 0;
79 
80  /*!
81  * Get the tunable frequency range for the underlying radio hardware.
82  * \param chan the channel index 0 to N-1
83  * \return the frequency range in Hz
84  */
85  virtual osmosdr::freq_range_t get_freq_range( size_t chan = 0 ) = 0;
86 
87  /*!
88  * Tune the underlying radio hardware to the desired center frequency.
89  * This also will select the appropriate RF bandpass.
90  * \param freq the desired frequency in Hz
91  * \param chan the channel index 0 to N-1
92  * \return the actual frequency in Hz
93  */
94  virtual double set_center_freq( double freq, size_t chan = 0 ) = 0;
95 
96  /*!
97  * Get the center frequency the underlying radio hardware is tuned to.
98  * This is the actual frequency and may differ from the frequency set.
99  * \param chan the channel index 0 to N-1
100  * \return the frequency in Hz
101  */
102  virtual double get_center_freq( size_t chan = 0 ) = 0;
103 
104  /*!
105  * Set the frequency correction value in parts per million.
106  * \param ppm the desired correction value in parts per million
107  * \param chan the channel index 0 to N-1
108  * \return correction value in parts per million
109  */
110  virtual double set_freq_corr( double ppm, size_t chan = 0 ) = 0;
111 
112  /*!
113  * Get the frequency correction value.
114  * \param chan the channel index 0 to N-1
115  * \return correction value in parts per million
116  */
117  virtual double get_freq_corr( size_t chan = 0 ) = 0;
118 
119  /*!
120  * Get the gain stage names of the underlying radio hardware.
121  * \param chan the channel index 0 to N-1
122  * \return a vector of strings containing the names of gain stages
123  */
124  virtual std::vector<std::string> get_gain_names( size_t chan = 0 ) = 0;
125 
126  /*!
127  * Get the settable overall gain range for the underlying radio hardware.
128  * \param chan the channel index 0 to N-1
129  * \return the gain range in dB
130  */
131  virtual osmosdr::gain_range_t get_gain_range( size_t chan = 0 ) = 0;
132 
133  /*!
134  * Get the settable gain range for a specific gain stage.
135  * \param name the name of the gain stage
136  * \param chan the channel index 0 to N-1
137  * \return the gain range in dB
138  */
139  virtual osmosdr::gain_range_t get_gain_range( const std::string & name,
140  size_t chan = 0 ) = 0;
141 
142  /*!
143  * Set the gain mode for the underlying radio hardware.
144  * This might be supported only for certain hardware types.
145  * \param automatic the gain mode (true means automatic gain mode)
146  * \param chan the channel index 0 to N-1
147  * \return the actual gain mode
148  */
149  virtual bool set_gain_mode( bool automatic, size_t chan = 0 ) = 0;
150 
151  /*!
152  * Get the gain mode selected for the underlying radio hardware.
153  * \param chan the channel index 0 to N-1
154  * \return the actual gain mode (true means automatic gain mode)
155  */
156  virtual bool get_gain_mode( size_t chan = 0 ) = 0;
157 
158  /*!
159  * Set the gain for the underlying radio hardware.
160  * This function will automatically distribute the desired gain value over
161  * available gain stages in an appropriate way and return the actual value.
162  * \param gain the gain in dB
163  * \param chan the channel index 0 to N-1
164  * \return the actual gain in dB
165  */
166  virtual double set_gain( double gain, size_t chan = 0 ) = 0;
167 
168  /*!
169  * Set the named gain on the underlying radio hardware.
170  * \param gain the gain in dB
171  * \param name the name of the gain stage
172  * \param chan the channel index 0 to N-1
173  * \return the actual gain in dB
174  */
175  virtual double set_gain( double gain,
176  const std::string & name,
177  size_t chan = 0 ) = 0;
178 
179  /*!
180  * Get the actual gain setting of the underlying radio hardware.
181  * \param chan the channel index 0 to N-1
182  * \return the actual gain in dB
183  */
184  virtual double get_gain( size_t chan = 0 ) = 0;
185 
186  /*!
187  * Get the actual gain setting of a named stage.
188  * \param name the name of the gain stage
189  * \param chan the channel index 0 to N-1
190  * \return the actual gain in dB
191  */
192  virtual double get_gain( const std::string & name, size_t chan = 0 ) = 0;
193 
194  /*!
195  * Set the IF gain for the underlying radio hardware.
196  * This function will automatically distribute the desired gain value over
197  * available IF gain stages in an appropriate way and return the actual value.
198  * \param gain the gain in dB
199  * \param chan the channel index 0 to N-1
200  * \return the actual gain in dB
201  */
202  virtual double set_if_gain( double gain, size_t chan = 0 ) = 0;
203 
204  /*!
205  * Set the BB gain for the underlying radio hardware.
206  * This function will automatically distribute the desired gain value over
207  * available BB gain stages in an appropriate way and return the actual value.
208  * \param gain the gain in dB
209  * \param chan the channel index 0 to N-1
210  * \return the actual gain in dB
211  */
212  virtual double set_bb_gain( double gain, size_t chan = 0 ) = 0;
213 
214  /*!
215  * Get the available antennas of the underlying radio hardware.
216  * \param chan the channel index 0 to N-1
217  * \return a vector of strings containing the names of available antennas
218  */
219  virtual std::vector< std::string > get_antennas( size_t chan = 0 ) = 0;
220 
221  /*!
222  * Select the active antenna of the underlying radio hardware.
223  * \param antenna name of the antenna to be selected
224  * \param chan the channel index 0 to N-1
225  * \return the actual antenna's name
226  */
227  virtual std::string set_antenna( const std::string & antenna,
228  size_t chan = 0 ) = 0;
229 
230  /*!
231  * Get the actual underlying radio hardware antenna setting.
232  * \param chan the channel index 0 to N-1
233  * \return the actual antenna's name
234  */
235  virtual std::string get_antenna( size_t chan = 0 ) = 0;
236 
238  DCOffsetOff = 0,
240  DCOffsetAutomatic
241  };
242 
243  /*!
244  * Set the RX frontend DC correction mode.
245  * The automatic correction subtracts out the long-run average.
246  *
247  * When disabled, the averaging option operation is reset.
248  * Once in Manual mode, the average value will be held constant until
249  * the user re-enables the automatic correction or overrides the
250  * value by manually setting the offset.
251  *
252  * \param mode dc offset correction mode: 0 = Off, 1 = Manual, 2 = Automatic
253  * \param chan the channel index 0 to N-1
254  */
255  virtual void set_dc_offset_mode( int mode, size_t chan = 0) = 0;
256 
257  /*!
258  * Set the RX frontend DC offset value.
259  * The value is complex to control both I and Q.
260  * Only set this when automatic correction is disabled.
261  *
262  * \param offset the dc offset (1.0 is full-scale)
263  * \param chan the channel index 0 to N-1
264  */
265  virtual void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 ) = 0;
266 
268  IQBalanceOff = 0,
270  IQBalanceAutomatic
271  };
272 
273  /*!
274  * Set the RX frontend IQ balance mode.
275  *
276  * \param mode iq balance correction mode: 0 = Off, 1 = Manual, 2 = Automatic
277  * \param chan the channel index 0 to N-1
278  */
279  virtual void set_iq_balance_mode( int mode, size_t chan = 0 ) = 0;
280 
281  /*!
282  * Set the RX frontend IQ balance correction.
283  * Use this to adjust the magnitude and phase of I and Q.
284  *
285  * \param balance the complex correction value
286  * \param chan the channel index 0 to N-1
287  */
288  virtual void set_iq_balance( const std::complex<double> &balance, size_t chan = 0 ) = 0;
289 
290  /*!
291  * Set the bandpass filter on the radio frontend.
292  * \param bandwidth the filter bandwidth in Hz
293  * \param chan the channel index 0 to N-1
294  * \return the actual filter bandwidth in Hz
295  */
296  virtual double set_bandwidth( double bandwidth, size_t chan = 0 ) = 0;
297 
298  /*!
299  * Get the actual bandpass filter setting on the radio frontend.
300  * \param chan the channel index 0 to N-1
301  * \return the actual filter bandwidth in Hz
302  */
303  virtual double get_bandwidth( size_t chan = 0 ) = 0;
304 
305  /*!
306  * Get the possible bandpass filter settings on the radio frontend.
307  * \param chan the channel index 0 to N-1
308  * \return a range of bandwidths in Hz
309  */
310  virtual osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 ) = 0;
311 };
312 
313 } /* namespace osmosdr */
314 
315 #endif /* INCLUDED_OSMOSDR_SOURCE_H */
Definition: source.h:239
Definition: ranges.h:69
Provides a stream of complex samples.This uses the preferred technique: subclassing gr::hier_block2...
Definition: source.h:37
IQBalanceMode
Definition: source.h:267
boost::shared_ptr< source > sptr
Definition: source.h:40
Definition: source.h:269
#define OSMOSDR_API
Definition: api.h:30
DCOffsetMode
Definition: source.h:237