GNU Radio's OsmoSDR Package
sink_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_SINK_IFACE_H
22 #define OSMOSDR_SINK_IFACE_H
23 
24 #include <osmosdr/ranges.h>
25 #include <osmosdr/time_spec.h>
26 #include <gnuradio/basic_block.h>
27 
28 /*!
29  * TODO: document
30  *
31  */
33 {
34 public:
35  /*!
36  * Get the number of channels the underlying radio hardware offers.
37  * \return the number of available channels
38  */
39  virtual size_t get_num_channels( void ) = 0;
40 
41  /*!
42  * Get the possible sample rates for the underlying radio hardware.
43  * \return a range of rates in Sps
44  */
45  virtual osmosdr::meta_range_t get_sample_rates( void ) = 0;
46 
47  /*!
48  * Set the sample rate for the underlying radio hardware.
49  * This also will select the appropriate IF bandpass, if applicable.
50  * \param rate a new rate in Sps
51  */
52  virtual double set_sample_rate( double rate ) = 0;
53 
54  /*!
55  * Get the sample rate for the underlying radio hardware.
56  * This is the actual sample rate and may differ from the rate set.
57  * \return the actual rate in Sps
58  */
59  virtual double get_sample_rate( void ) = 0;
60 
61  /*!
62  * Get the tunable frequency range for the underlying radio hardware.
63  * \param chan the channel index 0 to N-1
64  * \return the frequency range in Hz
65  */
66  virtual osmosdr::freq_range_t get_freq_range( size_t chan = 0 ) = 0;
67 
68  /*!
69  * Tune the underlying radio hardware to the desired center frequency.
70  * This also will select the appropriate RF bandpass.
71  * \param freq the desired frequency in Hz
72  * \param chan the channel index 0 to N-1
73  * \return the actual frequency in Hz
74  */
75  virtual double set_center_freq( double freq, size_t chan = 0 ) = 0;
76 
77  /*!
78  * Get the center frequency the underlying radio hardware is tuned to.
79  * This is the actual frequency and may differ from the frequency set.
80  * \param chan the channel index 0 to N-1
81  * \return the frequency in Hz
82  */
83  virtual double get_center_freq( size_t chan = 0 ) = 0;
84 
85  /*!
86  * Set the frequency correction value in parts per million.
87  * \param ppm the desired correction value in parts per million
88  * \param chan the channel index 0 to N-1
89  * \return correction value in parts per million
90  */
91  virtual double set_freq_corr( double ppm, size_t chan = 0 ) = 0;
92 
93  /*!
94  * Get the frequency correction value.
95  * \param chan the channel index 0 to N-1
96  * \return correction value in parts per million
97  */
98  virtual double get_freq_corr( size_t chan = 0 ) = 0;
99 
100  /*!
101  * Get the gain stage names of the underlying radio hardware.
102  * \param chan the channel index 0 to N-1
103  * \return a vector of strings containing the names of gain stages
104  */
105  virtual std::vector<std::string> get_gain_names( size_t chan = 0 ) = 0;
106 
107  /*!
108  * Get the settable overall gain range for the underlying radio hardware.
109  * \param chan the channel index 0 to N-1
110  * \return the gain range in dB
111  */
112  virtual osmosdr::gain_range_t get_gain_range( size_t chan = 0 ) = 0;
113 
114  /*!
115  * Get the settable gain range for a specific gain stage.
116  * \param name the name of the gain stage
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( const std::string & name,
121  size_t chan = 0 ) = 0;
122 
123  /*!
124  * Set the gain mode for the underlying radio hardware.
125  * This might be supported only for certain hardware types.
126  * \param automatic the gain mode (true means automatic gain mode)
127  * \param chan the channel index 0 to N-1
128  * \return the actual gain mode
129  */
130  virtual bool set_gain_mode( bool automatic, size_t chan = 0 ) { return false; }
131 
132  /*!
133  * Get the gain mode selected for the underlying radio hardware.
134  * \param chan the channel index 0 to N-1
135  * \return the actual gain mode (true means automatic gain mode)
136  */
137  virtual bool get_gain_mode( size_t chan = 0 ) { return false; }
138 
139  /*!
140  * Set the gain for the underlying radio hardware.
141  * This function will automatically distribute the desired gain value over
142  * available gain stages in an appropriate way and return the actual value.
143  * \param gain the gain in dB
144  * \param chan the channel index 0 to N-1
145  * \return the actual gain in dB
146  */
147  virtual double set_gain( double gain, size_t chan = 0 ) = 0;
148 
149  /*!
150  * Set the named gain on the underlying radio hardware.
151  * \param gain the gain in dB
152  * \param name the name of the gain stage
153  * \param chan the channel index 0 to N-1
154  * \return the actual gain in dB
155  */
156  virtual double set_gain( double gain,
157  const std::string & name,
158  size_t chan = 0 ) = 0;
159 
160  /*!
161  * Get the actual gain setting of the underlying radio hardware.
162  * \param chan the channel index 0 to N-1
163  * \return the actual gain in dB
164  */
165  virtual double get_gain( size_t chan = 0 ) = 0;
166 
167  /*!
168  * Get the actual gain setting of a named stage.
169  * \param name the name of the gain stage
170  * \param chan the channel index 0 to N-1
171  * \return the actual gain in dB
172  */
173  virtual double get_gain( const std::string & name, size_t chan = 0 ) = 0;
174 
175  /*!
176  * Set the IF gain for the underlying radio hardware.
177  * This function will automatically distribute the desired gain value over
178  * available IF gain stages in an appropriate way and return the actual value.
179  * \param gain the gain in dB
180  * \param chan the channel index 0 to N-1
181  * \return the actual gain in dB
182  */
183  virtual double set_if_gain( double gain, size_t chan = 0 ) { return 0; }
184 
185  /*!
186  * Set the BB gain for the underlying radio hardware.
187  * This function will automatically distribute the desired gain value over
188  * available BB gain stages in an appropriate way and return the actual value.
189  * \param gain the gain in dB
190  * \param chan the channel index 0 to N-1
191  * \return the actual gain in dB
192  */
193  virtual double set_bb_gain( double gain, size_t chan = 0 ) { return 0; }
194 
195  /*!
196  * Get the available antennas of the underlying radio hardware.
197  * \param chan the channel index 0 to N-1
198  * \return a vector of strings containing the names of available antennas
199  */
200  virtual std::vector< std::string > get_antennas( size_t chan = 0 ) = 0;
201 
202  /*!
203  * Select the active antenna of the underlying radio hardware.
204  * \param chan the channel index 0 to N-1
205  * \return the actual antenna's name
206  */
207  virtual std::string set_antenna( const std::string & antenna,
208  size_t chan = 0 ) = 0;
209 
210  /*!
211  * Get the actual underlying radio hardware antenna setting.
212  * \param chan the channel index 0 to N-1
213  * \return the actual antenna's name
214  */
215  virtual std::string get_antenna( size_t chan = 0 ) = 0;
216 
217  /*!
218  * Set the TX frontend DC offset value.
219  * The value is complex to control both I and Q.
220  *
221  * \param offset the dc offset (1.0 is full-scale)
222  * \param chan the channel index 0 to N-1
223  */
224  virtual void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 ) { }
225 
226  /*!
227  * Set the TX frontend IQ balance correction.
228  * Use this to adjust the magnitude and phase of I and Q.
229  *
230  * \param balance the complex correction value
231  * \param chan the channel index 0 to N-1
232  */
233  virtual void set_iq_balance( const std::complex<double> &balance, size_t chan = 0 ) { }
234 
235  /*!
236  * Set the bandpass filter on the radio frontend.
237  * \param bandwidth the filter bandwidth in Hz, set to 0 for automatic selection
238  * \param chan the channel index 0 to N-1
239  * \return the actual filter bandwidth in Hz
240  */
241  virtual double set_bandwidth( double bandwidth, size_t chan = 0 ) { return 0; }
242 
243  /*!
244  * Get the actual bandpass filter setting on the radio frontend.
245  * \param chan the channel index 0 to N-1
246  * \return the actual filter bandwidth in Hz
247  */
248  virtual double get_bandwidth( size_t chan = 0 ) { return 0; }
249 
250  /*!
251  * Get the possible bandpass filter settings on the radio frontend.
252  * \param chan the channel index 0 to N-1
253  * \return a range of bandwidths in Hz
254  */
255  virtual osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 )
256  { return osmosdr::freq_range_t(); }
257 
258  /*!
259  * Set the time source for the device.
260  * This sets the method of time synchronization,
261  * typically a pulse per second or an encoded time.
262  * Typical options for source: external, MIMO.
263  * \param source a string representing the time source
264  * \param mboard which motherboard to set the config
265  */
266  virtual void set_time_source(const std::string &source,
267  const size_t mboard = 0) { }
268 
269  /*!
270  * Get the currently set time source.
271  * \param mboard which motherboard to get the config
272  * \return the string representing the time source
273  */
274  virtual std::string get_time_source(const size_t mboard) { return ""; }
275 
276  /*!
277  * Get a list of possible time sources.
278  * \param mboard which motherboard to get the list
279  * \return a vector of strings for possible settings
280  */
281  virtual std::vector<std::string> get_time_sources(const size_t mboard)
282  {
283  return std::vector<std::string>();
284  }
285 
286  /*!
287  * Set the clock source for the device.
288  * This sets the source for a 10 Mhz reference clock.
289  * Typical options for source: internal, external, MIMO.
290  * \param source a string representing the clock source
291  * \param mboard which motherboard to set the config
292  */
293  virtual void set_clock_source(const std::string &source,
294  const size_t mboard = 0) { }
295 
296  /*!
297  * Get the currently set clock source.
298  * \param mboard which motherboard to get the config
299  * \return the string representing the clock source
300  */
301  virtual std::string get_clock_source(const size_t mboard) { return ""; }
302 
303  /*!
304  * Get a list of possible clock sources.
305  * \param mboard which motherboard to get the list
306  * \return a vector of strings for possible settings
307  */
308  virtual std::vector<std::string> get_clock_sources(const size_t mboard)
309  {
310  return std::vector<std::string>();
311  }
312 
313  /*!
314  * Get the master clock rate.
315  * \param mboard the motherboard index 0 to M-1
316  * \return the clock rate in Hz
317  */
318  virtual double get_clock_rate(size_t mboard = 0) { return 0; }
319 
320  /*!
321  * Set the master clock rate.
322  * \param rate the new rate in Hz
323  * \param mboard the motherboard index 0 to M-1
324  */
325  virtual void set_clock_rate(double rate, size_t mboard = 0) { }
326 
327  /*!
328  * Get the current time registers.
329  * \param mboard the motherboard index 0 to M-1
330  * \return the current device time
331  */
332  virtual ::osmosdr::time_spec_t get_time_now(size_t mboard = 0)
333  {
334  return ::osmosdr::time_spec_t::get_system_time();
335  }
336 
337  /*!
338  * Get the time when the last pps pulse occured.
339  * \param mboard the motherboard index 0 to M-1
340  * \return the current device time
341  */
342  virtual ::osmosdr::time_spec_t get_time_last_pps(size_t mboard = 0)
343  {
344  return ::osmosdr::time_spec_t::get_system_time();
345  }
346 
347  /*!
348  * Sets the time registers immediately.
349  * \param time_spec the new time
350  * \param mboard the motherboard index 0 to M-1
351  */
352  virtual void set_time_now(const ::osmosdr::time_spec_t &time_spec,
353  size_t mboard = 0) { }
354 
355  /*!
356  * Set the time registers at the next pps.
357  * \param time_spec the new time
358  */
359  virtual void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec) { }
360 
361  /*!
362  * Sync the time registers with an unknown pps edge.
363  * \param time_spec the new time
364  */
365  virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec) { }
366 };
367 
368 #endif // OSMOSDR_SINK_IFACE_H
virtual double set_center_freq(double freq, size_t chan=0)=0
virtual double get_center_freq(size_t chan=0)=0
virtual double get_clock_rate(size_t mboard=0)
Definition: sink_iface.h:318
virtual osmosdr::gain_range_t get_gain_range(size_t chan=0)=0
meta_range_t freq_range_t
Definition: ranges.h:125
virtual void set_time_now(const ::osmosdr::time_spec_t &time_spec, size_t mboard=0)
Definition: sink_iface.h:352
virtual std::string get_time_source(const size_t mboard)
Definition: sink_iface.h:274
virtual osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)
Definition: sink_iface.h:255
virtual std::vector< std::string > get_antennas(size_t chan=0)=0
virtual void set_time_source(const std::string &source, const size_t mboard=0)
Definition: sink_iface.h:266
virtual ::osmosdr::time_spec_t get_time_now(size_t mboard=0)
Definition: sink_iface.h:332
virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec)
Definition: sink_iface.h:365
virtual osmosdr::meta_range_t get_sample_rates(void)=0
virtual double set_freq_corr(double ppm, size_t chan=0)=0
virtual double get_gain(size_t chan=0)=0
virtual void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec)
Definition: sink_iface.h:359
virtual double set_if_gain(double gain, size_t chan=0)
Definition: sink_iface.h:183
Definition: ranges.h:75
virtual double set_gain(double gain, size_t chan=0)=0
Definition: sink_iface.h:32
virtual double set_bandwidth(double bandwidth, size_t chan=0)
Definition: sink_iface.h:241
virtual std::vector< std::string > get_clock_sources(const size_t mboard)
Definition: sink_iface.h:308
virtual osmosdr::freq_range_t get_freq_range(size_t chan=0)=0
virtual std::string get_clock_source(const size_t mboard)
Definition: sink_iface.h:301
virtual bool set_gain_mode(bool automatic, size_t chan=0)
Definition: sink_iface.h:130
virtual std::string get_antenna(size_t chan=0)=0
virtual bool get_gain_mode(size_t chan=0)
Definition: sink_iface.h:137
virtual double get_sample_rate(void)=0
virtual void set_iq_balance(const std::complex< double > &balance, size_t chan=0)
Definition: sink_iface.h:233
virtual double get_bandwidth(size_t chan=0)
Definition: sink_iface.h:248
virtual size_t get_num_channels(void)=0
virtual void set_clock_source(const std::string &source, const size_t mboard=0)
Definition: sink_iface.h:293
virtual double set_sample_rate(double rate)=0
virtual void set_clock_rate(double rate, size_t mboard=0)
Definition: sink_iface.h:325
virtual std::vector< std::string > get_gain_names(size_t chan=0)=0
virtual std::vector< std::string > get_time_sources(const size_t mboard)
Definition: sink_iface.h:281
virtual void set_dc_offset(const std::complex< double > &offset, size_t chan=0)
Definition: sink_iface.h:224
virtual std::string set_antenna(const std::string &antenna, size_t chan=0)=0
virtual ::osmosdr::time_spec_t get_time_last_pps(size_t mboard=0)
Definition: sink_iface.h:342
virtual double set_bb_gain(double gain, size_t chan=0)
Definition: sink_iface.h:193
virtual double get_freq_corr(size_t chan=0)=0