GNU Radio's OsmoSDR Package
source_iface.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 
21 #ifndef OSMOSDR_SOURCE_IFACE_H
22 #define OSMOSDR_SOURCE_IFACE_H
23 
24 #include <osmosdr/ranges.h>
25 #include <gnuradio/basic_block.h>
26 
27 /*!
28  * TODO: document
29  *
30  */
32 {
33 public:
34  /*!
35  * Get the number of channels the underlying radio hardware offers.
36  * \return the number of available channels
37  */
38  virtual size_t get_num_channels( void ) = 0;
39 
40  /*!
41  * \brief seek file to \p seek_point relative to \p whence
42  *
43  * \param seek_point sample offset in file
44  * \param whence one of SEEK_SET, SEEK_CUR, SEEK_END (man fseek)
45  * \return true on success
46  */
47  virtual bool seek( long seek_point, int whence, size_t chan = 0 ) { return false; }
48 
49  /*!
50  * Get the possible sample rates for the underlying radio hardware.
51  * \return a range of rates in Sps
52  */
53  virtual osmosdr::meta_range_t get_sample_rates( void ) = 0;
54 
55  /*!
56  * Set the sample rate for the underlying radio hardware.
57  * This also will select the appropriate IF bandpass, if applicable.
58  * \param rate a new rate in Sps
59  */
60  virtual double set_sample_rate( double rate ) = 0;
61 
62  /*!
63  * Get the sample rate for the underlying radio hardware.
64  * This is the actual sample rate and may differ from the rate set.
65  * \return the actual rate in Sps
66  */
67  virtual double get_sample_rate( void ) = 0;
68 
69  /*!
70  * Get the tunable frequency range for the underlying radio hardware.
71  * \param chan the channel index 0 to N-1
72  * \return the frequency range in Hz
73  */
74  virtual osmosdr::freq_range_t get_freq_range( size_t chan = 0 ) = 0;
75 
76  /*!
77  * Tune the underlying radio hardware to the desired center frequency.
78  * This also will select the appropriate RF bandpass.
79  * \param freq the desired frequency in Hz
80  * \param chan the channel index 0 to N-1
81  * \return the actual frequency in Hz
82  */
83  virtual double set_center_freq( double freq, size_t chan = 0 ) = 0;
84 
85  /*!
86  * Get the center frequency the underlying radio hardware is tuned to.
87  * This is the actual frequency and may differ from the frequency set.
88  * \param chan the channel index 0 to N-1
89  * \return the frequency in Hz
90  */
91  virtual double get_center_freq( size_t chan = 0 ) = 0;
92 
93  /*!
94  * Set the frequency correction value in parts per million.
95  * \param ppm the desired correction value in parts per million
96  * \param chan the channel index 0 to N-1
97  * \return correction value in parts per million
98  */
99  virtual double set_freq_corr( double ppm, size_t chan = 0 ) = 0;
100 
101  /*!
102  * Get the frequency correction value.
103  * \param chan the channel index 0 to N-1
104  * \return correction value in parts per million
105  */
106  virtual double get_freq_corr( size_t chan = 0 ) = 0;
107 
108  /*!
109  * Get the gain stage names of the underlying radio hardware.
110  * \param chan the channel index 0 to N-1
111  * \return a vector of strings containing the names of gain stages
112  */
113  virtual std::vector<std::string> get_gain_names( size_t chan = 0 ) = 0;
114 
115  /*!
116  * Get the settable overall gain range for the underlying radio hardware.
117  * \param chan the channel index 0 to N-1
118  * \return the gain range in dB
119  */
120  virtual osmosdr::gain_range_t get_gain_range( size_t chan = 0 ) = 0;
121 
122  /*!
123  * Get the settable gain range for a specific gain stage.
124  * \param name the name of the gain stage
125  * \param chan the channel index 0 to N-1
126  * \return the gain range in dB
127  */
128  virtual osmosdr::gain_range_t get_gain_range( const std::string & name,
129  size_t chan = 0 ) = 0;
130 
131  /*!
132  * Set the gain mode for the underlying radio hardware.
133  * This might be supported only for certain hardware types.
134  * \param automatic the gain mode (true means automatic gain mode)
135  * \param chan the channel index 0 to N-1
136  * \return the actual gain mode
137  */
138  virtual bool set_gain_mode( bool automatic, size_t chan = 0 ) { return false; }
139 
140  /*!
141  * Get the gain mode selected for the underlying radio hardware.
142  * \param chan the channel index 0 to N-1
143  * \return the actual gain mode (true means automatic gain mode)
144  */
145  virtual bool get_gain_mode( size_t chan = 0 ) { return false; }
146 
147  /*!
148  * Set the gain for the underlying radio hardware.
149  * This function will automatically distribute the desired gain value over
150  * available gain stages in an appropriate way and return the actual value.
151  * \param gain the gain in dB
152  * \param chan the channel index 0 to N-1
153  * \return the actual gain in dB
154  */
155  virtual double set_gain( double gain, size_t chan = 0 ) = 0;
156 
157  /*!
158  * Set the named gain on the underlying radio hardware.
159  * \param gain the gain in dB
160  * \param name the name of the gain stage
161  * \param chan the channel index 0 to N-1
162  * \return the actual gain in dB
163  */
164  virtual double set_gain( double gain,
165  const std::string & name,
166  size_t chan = 0 ) = 0;
167 
168  /*!
169  * Get the actual gain setting of the underlying radio hardware.
170  * \param chan the channel index 0 to N-1
171  * \return the actual gain in dB
172  */
173  virtual double get_gain( size_t chan = 0 ) = 0;
174 
175  /*!
176  * Get the actual gain setting of a named stage.
177  * \param name the name of the gain stage
178  * \param chan the channel index 0 to N-1
179  * \return the actual gain in dB
180  */
181  virtual double get_gain( const std::string & name, size_t chan = 0 ) = 0;
182 
183  /*!
184  * Set the IF gain for the underlying radio hardware.
185  * This function will automatically distribute the desired gain value over
186  * available IF gain stages in an appropriate way and return the actual value.
187  * \param gain the gain in dB
188  * \param chan the channel index 0 to N-1
189  * \return the actual gain in dB
190  */
191  virtual double set_if_gain( double gain, size_t chan = 0 ) { return 0; }
192 
193  /*!
194  * Set the BB gain for the underlying radio hardware.
195  * This function will automatically distribute the desired gain value over
196  * available BB gain stages in an appropriate way and return the actual value.
197  * \param gain the gain in dB
198  * \param chan the channel index 0 to N-1
199  * \return the actual gain in dB
200  */
201  virtual double set_bb_gain( double gain, size_t chan = 0 ) { return 0; }
202 
203  /*!
204  * Get the available antennas of the underlying radio hardware.
205  * \param chan the channel index 0 to N-1
206  * \return a vector of strings containing the names of available antennas
207  */
208  virtual std::vector< std::string > get_antennas( size_t chan = 0 ) = 0;
209 
210  /*!
211  * Select the active antenna of the underlying radio hardware.
212  * \param chan the channel index 0 to N-1
213  * \return the actual antenna's name
214  */
215  virtual std::string set_antenna( const std::string & antenna,
216  size_t chan = 0 ) = 0;
217 
218  /*!
219  * Get the actual underlying radio hardware antenna setting.
220  * \param chan the channel index 0 to N-1
221  * \return the actual antenna's name
222  */
223  virtual std::string get_antenna( size_t chan = 0 ) = 0;
224 
225  /*!
226  * Set the RX frontend DC correction mode.
227  * The automatic correction subtracts out the long-run average.
228  *
229  * When disabled, the averaging option operation is reset.
230  * Once in Manual mode, the average value will be held constant until
231  * the user re-enables the automatic correction or overrides the
232  * value by manually setting the offset.
233  *
234  * \param mode dc offset correction mode: 0 = Off, 1 = Manual, 2 = Automatic
235  * \param chan the channel index 0 to N-1
236  */
237  virtual void set_dc_offset_mode( int mode, size_t chan = 0 ) { }
238 
239  /*!
240  * Set a constant DC offset value.
241  * The value is complex to control both I and Q.
242  * Only set this when automatic correction is disabled.
243  *
244  * \param offset the dc offset (1.0 is full-scale)
245  * \param chan the channel index 0 to N-1
246  */
247  virtual void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 ) { }
248 
249  /*!
250  * Set the RX frontend IQ balance mode.
251  *
252  * \param mode iq balance correction mode: 0 = Off, 1 = Manual, 2 = Automatic
253  * \param chan the channel index 0 to N-1
254  */
255  virtual void set_iq_balance_mode( int mode, size_t chan = 0 ) { }
256 
257  /*!
258  * Set the RX frontend IQ balance correction.
259  * Use this to adjust the magnitude and phase of I and Q.
260  *
261  * \param balance the complex correction value
262  * \param chan the channel index 0 to N-1
263  */
264  virtual void set_iq_balance( const std::complex<double> &balance, size_t chan = 0 ) { }
265 
266  /*!
267  * Set the bandpass filter on the radio frontend.
268  * \param bandwidth the filter bandwidth in Hz, set to 0 for automatic selection
269  * \param chan the channel index 0 to N-1
270  * \return the actual filter bandwidth in Hz
271  */
272  virtual double set_bandwidth( double bandwidth, size_t chan = 0 ) { return 0; }
273 
274  /*!
275  * Get the actual bandpass filter setting on the radio frontend.
276  * \param chan the channel index 0 to N-1
277  * \return the actual filter bandwidth in Hz
278  */
279  virtual double get_bandwidth( size_t chan = 0 ) { return 0; }
280 
281  /*!
282  * Get the possible bandpass filter settings on the radio frontend.
283  * \param chan the channel index 0 to N-1
284  * \return a range of bandwidths in Hz
285  */
286  virtual osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 )
287  { return osmosdr::freq_range_t(); }
288 };
289 
290 #endif // OSMOSDR_SOURCE_IFACE_H
virtual double set_bb_gain(double gain, size_t chan=0)
Definition: source_iface.h:201
Definition: source_iface.h:31
virtual double get_gain(size_t chan=0)=0
meta_range_t freq_range_t
Definition: ranges.h:119
virtual std::vector< std::string > get_antennas(size_t chan=0)=0
virtual bool seek(long seek_point, int whence, size_t chan=0)
seek file to seek_point relative to whence
Definition: source_iface.h:47
virtual bool get_gain_mode(size_t chan=0)
Definition: source_iface.h:145
virtual osmosdr::freq_range_t get_freq_range(size_t chan=0)=0
virtual void set_dc_offset(const std::complex< double > &offset, size_t chan=0)
Definition: source_iface.h:247
virtual osmosdr::gain_range_t get_gain_range(size_t chan=0)=0
virtual osmosdr::meta_range_t get_sample_rates(void)=0
Definition: ranges.h:69
virtual void set_iq_balance_mode(int mode, size_t chan=0)
Definition: source_iface.h:255
virtual std::string get_antenna(size_t chan=0)=0
virtual double get_freq_corr(size_t chan=0)=0
virtual double get_sample_rate(void)=0
virtual double set_sample_rate(double rate)=0
virtual void set_iq_balance(const std::complex< double > &balance, size_t chan=0)
Definition: source_iface.h:264
virtual double set_if_gain(double gain, size_t chan=0)
Definition: source_iface.h:191
virtual std::vector< std::string > get_gain_names(size_t chan=0)=0
virtual std::string set_antenna(const std::string &antenna, size_t chan=0)=0
virtual bool set_gain_mode(bool automatic, size_t chan=0)
Definition: source_iface.h:138
virtual double set_freq_corr(double ppm, size_t chan=0)=0
virtual size_t get_num_channels(void)=0
virtual double get_center_freq(size_t chan=0)=0
virtual double set_center_freq(double freq, size_t chan=0)=0
virtual double set_bandwidth(double bandwidth, size_t chan=0)
Definition: source_iface.h:272
virtual double set_gain(double gain, size_t chan=0)=0
virtual void set_dc_offset_mode(int mode, size_t chan=0)
Definition: source_iface.h:237
virtual double get_bandwidth(size_t chan=0)
Definition: source_iface.h:279
virtual osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)
Definition: source_iface.h:286