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