GNU Radio's OsmoSDR Package
osmosdr_source_c.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_C_H
21 #define INCLUDED_OSMOSDR_SOURCE_C_H
22 
23 #include <osmosdr/osmosdr_api.h>
24 #include <osmosdr/osmosdr_ranges.h>
25 #include <gnuradio/gr_hier_block2.h>
26 
27 class osmosdr_source_c;
28 
29 /*
30  * We use boost::shared_ptr's instead of raw pointers for all access
31  * to gr_blocks (and many other data structures). The shared_ptr gets
32  * us transparent reference counting, which greatly simplifies storage
33  * management issues. This is especially helpful in our hybrid
34  * C++ / Python system.
35  *
36  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
37  *
38  * As a convention, the _sptr suffix indicates a boost::shared_ptr
39  */
40 typedef boost::shared_ptr<osmosdr_source_c> osmosdr_source_c_sptr;
41 
42 /*!
43  * \brief Return a shared_ptr to a new instance of osmosdr_source_c.
44  *
45  * To avoid accidental use of raw pointers, osmosdr_source_c's
46  * constructor is private. osmosdr_make_source_c is the public
47  * interface for creating new instances.
48  */
49 OSMOSDR_API osmosdr_source_c_sptr osmosdr_make_source_c ( const std::string & args = "" );
50 
51 /*!
52  * \brief Provides a stream of complex samples.
53  * \ingroup block
54  *
55  * This uses the preferred technique: subclassing gr_hier_block2.
56  */
57 class OSMOSDR_API osmosdr_source_c : virtual public gr_hier_block2
58 {
59 public:
60  /*!
61  * Get the number of channels the underlying radio hardware offers.
62  * \return the number of available channels
63  */
64  virtual size_t get_num_channels( void ) = 0;
65 
66  /*!
67  * Get the possible sample rates for the underlying radio hardware.
68  * \return a range of rates in Sps
69  */
70  virtual osmosdr::meta_range_t get_sample_rates( void ) = 0;
71 
72  /*!
73  * Set the sample rate for the underlying radio hardware.
74  * This also will select the appropriate IF bandpass, if applicable.
75  * \param rate a new rate in Sps
76  */
77  virtual double set_sample_rate( double rate ) = 0;
78 
79  /*!
80  * Get the sample rate for the underlying radio hardware.
81  * This is the actual sample rate and may differ from the rate set.
82  * \return the actual rate in Sps
83  */
84  virtual double get_sample_rate( void ) = 0;
85 
86  /*!
87  * Get the tunable frequency range for the underlying radio hardware.
88  * \param chan the channel index 0 to N-1
89  * \return the frequency range in Hz
90  */
91  virtual osmosdr::freq_range_t get_freq_range( size_t chan = 0 ) = 0;
92 
93  /*!
94  * Tune the underlying radio hardware to the desired center frequency.
95  * This also will select the appropriate RF bandpass.
96  * \param freq the desired frequency in Hz
97  * \param chan the channel index 0 to N-1
98  * \return the actual frequency in Hz
99  */
100  virtual double set_center_freq( double freq, size_t chan = 0 ) = 0;
101 
102  /*!
103  * Get the center frequency the underlying radio hardware is tuned to.
104  * This is the actual frequency and may differ from the frequency set.
105  * \param chan the channel index 0 to N-1
106  * \return the frequency in Hz
107  */
108  virtual double get_center_freq( size_t chan = 0 ) = 0;
109 
110  /*!
111  * Set the frequency correction value in parts per million.
112  * \param ppm the desired correction value in parts per million
113  * \param chan the channel index 0 to N-1
114  * \return correction value in parts per million
115  */
116  virtual double set_freq_corr( double ppm, size_t chan = 0 ) = 0;
117 
118  /*!
119  * Get the frequency correction value.
120  * \param chan the channel index 0 to N-1
121  * \return correction value in parts per million
122  */
123  virtual double get_freq_corr( size_t chan = 0 ) = 0;
124 
125  /*!
126  * Get the gain stage names of the underlying radio hardware.
127  * \param chan the channel index 0 to N-1
128  * \return a vector of strings containing the names of gain stages
129  */
130  virtual std::vector<std::string> get_gain_names( size_t chan = 0 ) = 0;
131 
132  /*!
133  * Get the settable overall gain range for the underlying radio hardware.
134  * \param chan the channel index 0 to N-1
135  * \return the gain range in dB
136  */
137  virtual osmosdr::gain_range_t get_gain_range( size_t chan = 0 ) = 0;
138 
139  /*!
140  * Get the settable gain range for a specific gain stage.
141  * \param name the name of the gain stage
142  * \param chan the channel index 0 to N-1
143  * \return the gain range in dB
144  */
145  virtual osmosdr::gain_range_t get_gain_range( const std::string & name,
146  size_t chan = 0 ) = 0;
147 
148  /*!
149  * Set the gain mode for the underlying radio hardware.
150  * This might be supported only for certain hardware types.
151  * \param automatic the gain mode (true means automatic gain mode)
152  * \param chan the channel index 0 to N-1
153  * \return the actual gain mode
154  */
155  virtual bool set_gain_mode( bool automatic, size_t chan = 0 ) = 0;
156 
157  /*!
158  * Get the gain mode selected for the underlying radio hardware.
159  * \param chan the channel index 0 to N-1
160  * \return the actual gain mode (true means automatic gain mode)
161  */
162  virtual bool get_gain_mode( size_t chan = 0 ) = 0;
163 
164  /*!
165  * Set the gain for the underlying radio hardware.
166  * This function will automatically distribute the desired gain value over
167  * available gain stages in an appropriate way and return the actual value.
168  * \param gain the gain in dB
169  * \param chan the channel index 0 to N-1
170  * \return the actual gain in dB
171  */
172  virtual double set_gain( double gain, size_t chan = 0 ) = 0;
173 
174  /*!
175  * Set the named gain on the underlying radio hardware.
176  * \param gain the gain in dB
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 set_gain( double gain,
182  const std::string & name,
183  size_t chan = 0 ) = 0;
184 
185  /*!
186  * Get the actual gain setting of the underlying radio hardware.
187  * \param chan the channel index 0 to N-1
188  * \return the actual gain in dB
189  */
190  virtual double get_gain( size_t chan = 0 ) = 0;
191 
192  /*!
193  * Get the actual gain setting of a named stage.
194  * \param name the name of the gain stage
195  * \param chan the channel index 0 to N-1
196  * \return the actual gain in dB
197  */
198  virtual double get_gain( const std::string & name, size_t chan = 0 ) = 0;
199 
200  /*!
201  * Set the IF gain for the underlying radio hardware.
202  * This function will automatically distribute the desired gain value over
203  * available IF gain stages in an appropriate way and return the actual value.
204  * \param gain the gain in dB
205  * \param chan the channel index 0 to N-1
206  * \return the actual gain in dB
207  */
208  virtual double set_if_gain( double gain, size_t chan = 0 ) = 0;
209 
210  /*!
211  * Get the available antennas of the underlying radio hardware.
212  * \param chan the channel index 0 to N-1
213  * \return a vector of strings containing the names of available antennas
214  */
215  virtual std::vector< std::string > get_antennas( size_t chan = 0 ) = 0;
216 
217  /*!
218  * Select the active antenna of the underlying radio hardware.
219  * \param antenna name of the antenna to be selected
220  * \param chan the channel index 0 to N-1
221  * \return the actual antenna's name
222  */
223  virtual std::string set_antenna( const std::string & antenna,
224  size_t chan = 0 ) = 0;
225 
226  /*!
227  * Get the actual underlying radio hardware antenna setting.
228  * \param chan the channel index 0 to N-1
229  * \return antenna the actual antenna's name
230  */
231  virtual std::string get_antenna( size_t chan = 0 ) = 0;
232 
234  IQBalanceOff = 0,
236  IQBalanceAutomatic
237  };
238 
239  /*!
240  * Set the RX frontend IQ balance mode.
241  *
242  * \param mode iq balance correction mode: 0 = Off, 1 = Manual, 2 = Automatic
243  * \param chan the channel index 0 to N-1
244  */
245  virtual void set_iq_balance_mode( int mode, size_t chan = 0 ) = 0;
246 
247  /*!
248  * Set the RX frontend IQ balance correction.
249  * Use this to adjust the magnitude and phase of I and Q.
250  *
251  * \param correction the complex correction value
252  * \param chan the channel index 0 to N-1
253  */
254  virtual void set_iq_balance( const std::complex<double> &correction,
255  size_t chan = 0 ) = 0;
256 };
257 
258 #endif /* INCLUDED_OSMOSDR_SOURCE_C_H */