GNU Radio's TEST 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 <osmosdr/time_spec.h>
26 #include <gnuradio/hier_block2.h>
27 
28 namespace osmosdr {
29 
30 class source;
31 
32 /*!
33  * \brief Provides a stream of complex samples.
34  * \ingroup block
35  *
36  * This uses the preferred technique: subclassing gr::hier_block2.
37  */
38 class OSMOSDR_API source : virtual public gr::hier_block2
39 {
40 public:
41  typedef std::shared_ptr< source > sptr;
42 
43  /*!
44  * \brief Return a shared_ptr to a new instance of source.
45  *
46  * To avoid accidental use of raw pointers, source's
47  * constructor is private. osmosdr::source::make is the public
48  * interface for creating new instances.
49  *
50  * \param args the address to identify the hardware
51  * \return a new osmosdr source block object
52  */
53  static sptr make( const std::string & args = "" );
54 
55  /*!
56  * Get the number of channels the underlying radio hardware offers.
57  * \return the number of available channels
58  */
59  virtual size_t get_num_channels( void ) = 0;
60 
61  /*!
62  * \brief seek file to \p seek_point relative to \p whence
63  *
64  * \param seek_point sample offset in file
65  * \param whence one of SEEK_SET, SEEK_CUR, SEEK_END (man fseek)
66  * \param chan the channel index 0 to N-1
67  * \return true on success
68  */
69  virtual bool seek( long seek_point, int whence, size_t chan = 0 ) = 0;
70 
71  /*!
72  * Get the possible sample rates for the underlying radio hardware.
73  * \return a range of rates in Sps
74  */
76 
77  /*!
78  * Set the sample rate for the underlying radio hardware.
79  * This also will select the appropriate IF bandpass, if applicable.
80  * \param rate a new rate in Sps
81  */
82  virtual double set_sample_rate( double rate ) = 0;
83 
84  /*!
85  * Get the sample rate for the underlying radio hardware.
86  * This is the actual sample rate and may differ from the rate set.
87  * \return the actual rate in Sps
88  */
89  virtual double get_sample_rate( void ) = 0;
90 
91  /*!
92  * Get the tunable frequency range for the underlying radio hardware.
93  * \param chan the channel index 0 to N-1
94  * \return the frequency range in Hz
95  */
96  virtual osmosdr::freq_range_t get_freq_range( size_t chan = 0 ) = 0;
97 
98  /*!
99  * Tune the underlying radio hardware to the desired center frequency.
100  * This also will select the appropriate RF bandpass.
101  * \param freq the desired frequency in Hz
102  * \param chan the channel index 0 to N-1
103  * \return the actual frequency in Hz
104  */
105  virtual double set_center_freq( double freq, size_t chan = 0 ) = 0;
106 
107  /*!
108  * Get the center frequency the underlying radio hardware is tuned to.
109  * This is the actual frequency and may differ from the frequency set.
110  * \param chan the channel index 0 to N-1
111  * \return the frequency in Hz
112  */
113  virtual double get_center_freq( size_t chan = 0 ) = 0;
114 
115  /*!
116  * Set the frequency correction value in parts per million.
117  * \param ppm the desired correction value in parts per million
118  * \param chan the channel index 0 to N-1
119  * \return correction value in parts per million
120  */
121  virtual double set_freq_corr( double ppm, size_t chan = 0 ) = 0;
122 
123  /*!
124  * Get the frequency correction value.
125  * \param chan the channel index 0 to N-1
126  * \return correction value in parts per million
127  */
128  virtual double get_freq_corr( size_t chan = 0 ) = 0;
129 
130  /*!
131  * Get the gain stage names of the underlying radio hardware.
132  * \param chan the channel index 0 to N-1
133  * \return a vector of strings containing the names of gain stages
134  */
135  virtual std::vector<std::string> get_gain_names( size_t chan = 0 ) = 0;
136 
137  /*!
138  * Get the settable overall gain range for the underlying radio hardware.
139  * \param chan the channel index 0 to N-1
140  * \return the gain range in dB
141  */
142  virtual osmosdr::gain_range_t get_gain_range( size_t chan = 0 ) = 0;
143 
144  /*!
145  * Get the settable gain range for a specific gain stage.
146  * \param name the name of the gain stage
147  * \param chan the channel index 0 to N-1
148  * \return the gain range in dB
149  */
150  virtual osmosdr::gain_range_t get_gain_range( const std::string & name,
151  size_t chan = 0 ) = 0;
152 
153  /*!
154  * Set the gain mode for the underlying radio hardware.
155  * This might be supported only for certain hardware types.
156  * \param automatic the gain mode (true means automatic gain mode)
157  * \param chan the channel index 0 to N-1
158  * \return the actual gain mode
159  */
160  virtual bool set_gain_mode( bool automatic, size_t chan = 0 ) = 0;
161 
162  /*!
163  * Get the gain mode selected for the underlying radio hardware.
164  * \param chan the channel index 0 to N-1
165  * \return the actual gain mode (true means automatic gain mode)
166  */
167  virtual bool get_gain_mode( size_t chan = 0 ) = 0;
168 
169  /*!
170  * Set the gain for the underlying radio hardware.
171  * This function will automatically distribute the desired gain value over
172  * available gain stages in an appropriate way and return the actual value.
173  * \param gain the gain in dB
174  * \param chan the channel index 0 to N-1
175  * \return the actual gain in dB
176  */
177  virtual double set_gain( double gain, size_t chan = 0 ) = 0;
178 
179  /*!
180  * Set the named gain on the underlying radio hardware.
181  * \param gain the gain in dB
182  * \param name the name of the gain stage
183  * \param chan the channel index 0 to N-1
184  * \return the actual gain in dB
185  */
186  virtual double set_gain( double gain,
187  const std::string & name,
188  size_t chan = 0 ) = 0;
189 
190  /*!
191  * Get the actual gain setting of the underlying radio hardware.
192  * \param chan the channel index 0 to N-1
193  * \return the actual gain in dB
194  */
195  virtual double get_gain( size_t chan = 0 ) = 0;
196 
197  /*!
198  * Get the actual gain setting of a named stage.
199  * \param name the name of the gain stage
200  * \param chan the channel index 0 to N-1
201  * \return the actual gain in dB
202  */
203  virtual double get_gain( const std::string & name, size_t chan = 0 ) = 0;
204 
205  /*!
206  * Set the IF gain for the underlying radio hardware.
207  * This function will automatically distribute the desired gain value over
208  * available IF gain stages in an appropriate way and return the actual value.
209  * \param gain the gain in dB
210  * \param chan the channel index 0 to N-1
211  * \return the actual gain in dB
212  */
213  virtual double set_if_gain( double gain, size_t chan = 0 ) = 0;
214 
215  /*!
216  * Set the BB gain for the underlying radio hardware.
217  * This function will automatically distribute the desired gain value over
218  * available BB gain stages in an appropriate way and return the actual value.
219  * \param gain the gain in dB
220  * \param chan the channel index 0 to N-1
221  * \return the actual gain in dB
222  */
223  virtual double set_bb_gain( double gain, size_t chan = 0 ) = 0;
224 
225  /*!
226  * Get the available antennas of the underlying radio hardware.
227  * \param chan the channel index 0 to N-1
228  * \return a vector of strings containing the names of available antennas
229  */
230  virtual std::vector< std::string > get_antennas( size_t chan = 0 ) = 0;
231 
232  /*!
233  * Select the active antenna of the underlying radio hardware.
234  * \param antenna name of the antenna to be selected
235  * \param chan the channel index 0 to N-1
236  * \return the actual antenna's name
237  */
238  virtual std::string set_antenna( const std::string & antenna,
239  size_t chan = 0 ) = 0;
240 
241  /*!
242  * Get the actual underlying radio hardware antenna setting.
243  * \param chan the channel index 0 to N-1
244  * \return the actual antenna's name
245  */
246  virtual std::string get_antenna( size_t chan = 0 ) = 0;
247 
249  DCOffsetOff = 0,
251  DCOffsetAutomatic
252  };
253 
254  /*!
255  * Set the RX frontend DC correction mode.
256  * The automatic correction subtracts out the long-run average.
257  *
258  * When disabled, the averaging option operation is reset.
259  * Once in Manual mode, the average value will be held constant until
260  * the user re-enables the automatic correction or overrides the
261  * value by manually setting the offset.
262  *
263  * \param mode dc offset correction mode: 0 = Off, 1 = Manual, 2 = Automatic
264  * \param chan the channel index 0 to N-1
265  */
266  virtual void set_dc_offset_mode( int mode, size_t chan = 0) = 0;
267 
268  /*!
269  * Set the RX frontend DC offset value.
270  * The value is complex to control both I and Q.
271  * Only set this when automatic correction is disabled.
272  *
273  * \param offset the dc offset (1.0 is full-scale)
274  * \param chan the channel index 0 to N-1
275  */
276  virtual void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 ) = 0;
277 
279  IQBalanceOff = 0,
281  IQBalanceAutomatic
282  };
283 
284  /*!
285  * Set the RX frontend IQ balance mode.
286  *
287  * \param mode iq balance correction mode: 0 = Off, 1 = Manual, 2 = Automatic
288  * \param chan the channel index 0 to N-1
289  */
290  virtual void set_iq_balance_mode( int mode, size_t chan = 0 ) = 0;
291 
292  /*!
293  * Set the RX frontend IQ balance correction.
294  * Use this to adjust the magnitude and phase of I and Q.
295  *
296  * \param balance the complex correction value
297  * \param chan the channel index 0 to N-1
298  */
299  virtual void set_iq_balance( const std::complex<double> &balance, size_t chan = 0 ) = 0;
300 
301  /*!
302  * Set the bandpass filter on the radio frontend.
303  * \param bandwidth the filter bandwidth in Hz, set to 0 for automatic selection
304  * \param chan the channel index 0 to N-1
305  * \return the actual filter bandwidth in Hz
306  */
307  virtual double set_bandwidth( double bandwidth, size_t chan = 0 ) = 0;
308 
309  /*!
310  * Get the actual bandpass filter setting on the radio frontend.
311  * \param chan the channel index 0 to N-1
312  * \return the actual filter bandwidth in Hz
313  */
314  virtual double get_bandwidth( size_t chan = 0 ) = 0;
315 
316  /*!
317  * Get the possible bandpass filter settings on the radio frontend.
318  * \param chan the channel index 0 to N-1
319  * \return a range of bandwidths in Hz
320  */
321  virtual osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 ) = 0;
322 
323  /*!
324  * Set the time source for the device.
325  * This sets the method of time synchronization,
326  * typically a pulse per second or an encoded time.
327  * Typical options for source: external, MIMO.
328  * \param source a string representing the time source
329  * \param mboard which motherboard to set the config
330  */
331  virtual void set_time_source(const std::string &source,
332  const size_t mboard = 0) = 0;
333 
334  /*!
335  * Get the currently set time source.
336  * \param mboard which motherboard to get the config
337  * \return the string representing the time source
338  */
339  virtual std::string get_time_source(const size_t mboard) = 0;
340 
341  /*!
342  * Get a list of possible time sources.
343  * \param mboard which motherboard to get the list
344  * \return a vector of strings for possible settings
345  */
346  virtual std::vector<std::string> get_time_sources(const size_t mboard) = 0;
347 
348  /*!
349  * Set the clock source for the device.
350  * This sets the source for a 10 Mhz reference clock.
351  * Typical options for source: internal, external, MIMO.
352  * \param source a string representing the clock source
353  * \param mboard which motherboard to set the config
354  */
355  virtual void set_clock_source(const std::string &source,
356  const size_t mboard = 0) = 0;
357 
358  /*!
359  * Get the currently set clock source.
360  * \param mboard which motherboard to get the config
361  * \return the string representing the clock source
362  */
363  virtual std::string get_clock_source(const size_t mboard) = 0;
364 
365  /*!
366  * Get a list of possible clock sources.
367  * \param mboard which motherboard to get the list
368  * \return a vector of strings for possible settings
369  */
370  virtual std::vector<std::string> get_clock_sources(const size_t mboard) = 0;
371 
372  /*!
373  * Get the master clock rate.
374  * \param mboard the motherboard index 0 to M-1
375  * \return the clock rate in Hz
376  */
377  virtual double get_clock_rate(size_t mboard = 0) = 0;
378 
379  /*!
380  * Set the master clock rate.
381  * \param rate the new rate in Hz
382  * \param mboard the motherboard index 0 to M-1
383  */
384  virtual void set_clock_rate(double rate, size_t mboard = 0) = 0;
385 
386  /*!
387  * Get the current time registers.
388  * \param mboard the motherboard index 0 to M-1
389  * \return the current device time
390  */
391  virtual ::osmosdr::time_spec_t get_time_now(size_t mboard = 0) = 0;
392 
393  /*!
394  * Get the time when the last pps pulse occured.
395  * \param mboard the motherboard index 0 to M-1
396  * \return the current device time
397  */
398  virtual ::osmosdr::time_spec_t get_time_last_pps(size_t mboard = 0) = 0;
399 
400  /*!
401  * Sets the time registers immediately.
402  * \param time_spec the new time
403  * \param mboard the motherboard index 0 to M-1
404  */
405  virtual void set_time_now(const ::osmosdr::time_spec_t &time_spec,
406  size_t mboard = 0) = 0;
407 
408  /*!
409  * Set the time registers at the next pps.
410  * \param time_spec the new time
411  */
412  virtual void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec) = 0;
413 
414  /*!
415  * Sync the time registers with an unknown pps edge.
416  * \param time_spec the new time
417  */
418  virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec) = 0;
419 };
420 
421 } /* namespace osmosdr */
422 
423 #endif /* INCLUDED_OSMOSDR_SOURCE_H */
#define OSMOSDR_API
Definition: api.h:30
Provides a stream of complex samples.
Definition: source.h:39
virtual void set_clock_rate(double rate, size_t mboard=0)=0
DCOffsetMode
Definition: source.h:248
@ DCOffsetManual
Definition: source.h:250
virtual double get_sample_rate(void)=0
virtual void set_time_next_pps(const ::osmosdr::time_spec_t &time_spec)=0
virtual double get_gain(const std::string &name, size_t chan=0)=0
virtual double get_freq_corr(size_t chan=0)=0
virtual double set_freq_corr(double ppm, size_t chan=0)=0
virtual double set_center_freq(double freq, size_t chan=0)=0
virtual double set_if_gain(double gain, size_t chan=0)=0
virtual double set_bandwidth(double bandwidth, size_t chan=0)=0
virtual void set_dc_offset(const std::complex< double > &offset, size_t chan=0)=0
virtual bool get_gain_mode(size_t chan=0)=0
virtual double get_clock_rate(size_t mboard=0)=0
virtual bool set_gain_mode(bool automatic, size_t chan=0)=0
virtual osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)=0
virtual std::string get_time_source(const size_t mboard)=0
virtual std::vector< std::string > get_antennas(size_t chan=0)=0
virtual osmosdr::freq_range_t get_freq_range(size_t chan=0)=0
virtual double get_bandwidth(size_t chan=0)=0
virtual osmosdr::meta_range_t get_sample_rates(void)=0
virtual double set_sample_rate(double rate)=0
virtual double get_gain(size_t chan=0)=0
virtual size_t get_num_channels(void)=0
virtual std::vector< std::string > get_time_sources(const size_t mboard)=0
virtual double get_center_freq(size_t chan=0)=0
virtual std::string set_antenna(const std::string &antenna, size_t chan=0)=0
std::shared_ptr< source > sptr
Definition: source.h:41
virtual std::string get_antenna(size_t chan=0)=0
IQBalanceMode
Definition: source.h:278
@ IQBalanceManual
Definition: source.h:280
virtual std::vector< std::string > get_clock_sources(const size_t mboard)=0
static sptr make(const std::string &args="")
Return a shared_ptr to a new instance of source.
virtual double set_gain(double gain, const std::string &name, size_t chan=0)=0
virtual void set_clock_source(const std::string &source, const size_t mboard=0)=0
virtual double set_gain(double gain, size_t chan=0)=0
virtual std::string get_clock_source(const size_t mboard)=0
virtual void set_iq_balance(const std::complex< double > &balance, size_t chan=0)=0
virtual void set_dc_offset_mode(int mode, size_t chan=0)=0
virtual void set_time_unknown_pps(const ::osmosdr::time_spec_t &time_spec)=0
virtual void set_iq_balance_mode(int mode, size_t chan=0)=0
virtual osmosdr::gain_range_t get_gain_range(size_t chan=0)=0
virtual ::osmosdr::time_spec_t get_time_now(size_t mboard=0)=0
virtual ::osmosdr::time_spec_t get_time_last_pps(size_t mboard=0)=0
virtual void set_time_source(const std::string &source, const size_t mboard=0)=0
virtual osmosdr::gain_range_t get_gain_range(const std::string &name, size_t chan=0)=0
virtual bool seek(long seek_point, int whence, size_t chan=0)=0
seek file to seek_point relative to whence
virtual std::vector< std::string > get_gain_names(size_t chan=0)=0
virtual void set_time_now(const ::osmosdr::time_spec_t &time_spec, size_t mboard=0)=0
virtual double set_bb_gain(double gain, size_t chan=0)=0
Definition: device.h:35
Definition: ranges.h:75