GNU Radio's OsmoSDR Package
sink.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_SINK_H
21 #define INCLUDED_OSMOSDR_SINK_H
22 
23 #include <osmosdr/api.h>
24 #include <osmosdr/ranges.h>
25 #include <gnuradio/hier_block2.h>
26 
27 namespace osmosdr {
28 
29 class sink;
30 
31 /*!
32  * \brief Takes a stream of complex samples.
33  * \ingroup block
34  *
35  * This uses the preferred technique: subclassing gr::hier_block2.
36  */
37 class OSMOSDR_API sink : virtual public gr::hier_block2
38 {
39 public:
40  typedef boost::shared_ptr< sink > sptr;
41 
42  /*!
43  * \brief Return a shared_ptr to a new instance of sink.
44  *
45  * To avoid accidental use of raw pointers, sink's
46  * constructor is private. osmosdr::sink::make is the public
47  * interface for creating new instances.
48  *
49  * \param args the address to identify the hardware
50  * \return a new osmosdr sink block object
51  */
52  static sptr make( const std::string & args = "" );
53 
54  /*!
55  * Get the number of channels the underlying radio hardware offers.
56  * \return the number of available channels
57  */
58  virtual size_t get_num_channels( void ) = 0;
59 
60  /*!
61  * Get the possible sample rates for the underlying radio hardware.
62  * \return a range of rates in Sps
63  */
64  virtual osmosdr::meta_range_t get_sample_rates( void ) = 0;
65 
66  /*!
67  * Set the sample rate for the underlying radio hardware.
68  * This also will select the appropriate IF bandpass, if applicable.
69  * \param rate a new rate in Sps
70  */
71  virtual double set_sample_rate( double rate ) = 0;
72 
73  /*!
74  * Get the sample rate for the underlying radio hardware.
75  * This is the actual sample rate and may differ from the rate set.
76  * \return the actual rate in Sps
77  */
78  virtual double get_sample_rate( void ) = 0;
79 
80  /*!
81  * Get the tunable frequency range for the underlying radio hardware.
82  * \param chan the channel index 0 to N-1
83  * \return the frequency range in Hz
84  */
85  virtual osmosdr::freq_range_t get_freq_range( size_t chan = 0 ) = 0;
86 
87  /*!
88  * Tune the underlying radio hardware to the desired center frequency.
89  * This also will select the appropriate RF bandpass.
90  * \param freq the desired frequency in Hz
91  * \param chan the channel index 0 to N-1
92  * \return the actual frequency in Hz
93  */
94  virtual double set_center_freq( double freq, size_t chan = 0 ) = 0;
95 
96  /*!
97  * Get the center frequency the underlying radio hardware is tuned to.
98  * This is the actual frequency and may differ from the frequency set.
99  * \param chan the channel index 0 to N-1
100  * \return the frequency in Hz
101  */
102  virtual double get_center_freq( size_t chan = 0 ) = 0;
103 
104  /*!
105  * Set the frequency correction value in parts per million.
106  * \param ppm the desired correction value in parts per million
107  * \param chan the channel index 0 to N-1
108  * \return correction value in parts per million
109  */
110  virtual double set_freq_corr( double ppm, size_t chan = 0 ) = 0;
111 
112  /*!
113  * Get the frequency correction value.
114  * \param chan the channel index 0 to N-1
115  * \return correction value in parts per million
116  */
117  virtual double get_freq_corr( size_t chan = 0 ) = 0;
118 
119  /*!
120  * Get the gain stage names of the underlying radio hardware.
121  * \param chan the channel index 0 to N-1
122  * \return a vector of strings containing the names of gain stages
123  */
124  virtual std::vector<std::string> get_gain_names( size_t chan = 0 ) = 0;
125 
126  /*!
127  * Get the settable overall gain range for the underlying radio hardware.
128  * \param chan the channel index 0 to N-1
129  * \return the gain range in dB
130  */
131  virtual osmosdr::gain_range_t get_gain_range( size_t chan = 0 ) = 0;
132 
133  /*!
134  * Get the settable gain range for a specific gain stage.
135  * \param name the name of the gain stage
136  * \param chan the channel index 0 to N-1
137  * \return the gain range in dB
138  */
139  virtual osmosdr::gain_range_t get_gain_range( const std::string & name,
140  size_t chan = 0 ) = 0;
141 
142  /*!
143  * Set the gain mode for the underlying radio hardware.
144  * This might be supported only for certain hardware types.
145  * \param automatic the gain mode (true means automatic gain mode)
146  * \param chan the channel index 0 to N-1
147  * \return the actual gain mode
148  */
149  virtual bool set_gain_mode( bool automatic, size_t chan = 0 ) = 0;
150 
151  /*!
152  * Get the gain mode selected for the underlying radio hardware.
153  * \param chan the channel index 0 to N-1
154  * \return the actual gain mode (true means automatic gain mode)
155  */
156  virtual bool get_gain_mode( size_t chan = 0 ) = 0;
157 
158  /*!
159  * Set the gain for the underlying radio hardware.
160  * This function will automatically distribute the desired gain value over
161  * available gain stages in an appropriate way and return the actual value.
162  * \param gain the gain in dB
163  * \param chan the channel index 0 to N-1
164  * \return the actual gain in dB
165  */
166  virtual double set_gain( double gain, size_t chan = 0 ) = 0;
167 
168  /*!
169  * Set the named gain on the underlying radio hardware.
170  * \param gain the gain in dB
171  * \param name the name of the gain stage
172  * \param chan the channel index 0 to N-1
173  * \return the actual gain in dB
174  */
175  virtual double set_gain( double gain,
176  const std::string & name,
177  size_t chan = 0 ) = 0;
178 
179  /*!
180  * Get the actual gain setting of the underlying radio hardware.
181  * \param chan the channel index 0 to N-1
182  * \return the actual gain in dB
183  */
184  virtual double get_gain( size_t chan = 0 ) = 0;
185 
186  /*!
187  * Get the actual gain setting of a named stage.
188  * \param name the name of the gain stage
189  * \param chan the channel index 0 to N-1
190  * \return the actual gain in dB
191  */
192  virtual double get_gain( const std::string & name, size_t chan = 0 ) = 0;
193 
194  /*!
195  * Set the IF gain for the underlying radio hardware.
196  * This function will automatically distribute the desired gain value over
197  * available IF 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_if_gain( double gain, size_t chan = 0 ) = 0;
203 
204  /*!
205  * Set the BB gain for the underlying radio hardware.
206  * This function will automatically distribute the desired gain value over
207  * available BB gain stages in an appropriate way and return the actual value.
208  * \param gain the gain in dB
209  * \param chan the channel index 0 to N-1
210  * \return the actual gain in dB
211  */
212  virtual double set_bb_gain( double gain, size_t chan = 0 ) = 0;
213 
214  /*!
215  * Get the available antennas of the underlying radio hardware.
216  * \param chan the channel index 0 to N-1
217  * \return a vector of strings containing the names of available antennas
218  */
219  virtual std::vector< std::string > get_antennas( size_t chan = 0 ) = 0;
220 
221  /*!
222  * Select the active antenna of the underlying radio hardware.
223  * \param antenna name of the antenna to be selected
224  * \param chan the channel index 0 to N-1
225  * \return the actual antenna's name
226  */
227  virtual std::string set_antenna( const std::string & antenna,
228  size_t chan = 0 ) = 0;
229 
230  /*!
231  * Get the actual underlying radio hardware antenna setting.
232  * \param chan the channel index 0 to N-1
233  * \return the actual antenna's name
234  */
235  virtual std::string get_antenna( size_t chan = 0 ) = 0;
236 
237  /*!
238  * Set the TX frontend DC offset value.
239  * The value is complex to control both I and Q.
240  *
241  * \param offset the dc offset (1.0 is full-scale)
242  * \param chan the channel index 0 to N-1
243  */
244  virtual void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 ) = 0;
245 
246  /*!
247  * Set the TX frontend IQ balance correction.
248  * Use this to adjust the magnitude and phase of I and Q.
249  *
250  * \param balance the complex correction value
251  * \param chan the channel index 0 to N-1
252  */
253  virtual void set_iq_balance( const std::complex<double> &balance, size_t chan = 0 ) = 0;
254 
255  /*!
256  * Set the bandpass filter on the radio frontend.
257  * \param bandwidth the filter bandwidth in Hz, set to 0 for automatic selection
258  * \param chan the channel index 0 to N-1
259  * \return the actual filter bandwidth in Hz
260  */
261  virtual double set_bandwidth( double bandwidth, size_t chan = 0 ) = 0;
262 
263  /*!
264  * Get the actual bandpass filter setting on the radio frontend.
265  * \param chan the channel index 0 to N-1
266  * \return the actual filter bandwidth in Hz
267  */
268  virtual double get_bandwidth( size_t chan = 0 ) = 0;
269 
270  /*!
271  * Get the possible bandpass filter settings on the radio frontend.
272  * \param chan the channel index 0 to N-1
273  * \return a range of bandwidths in Hz
274  */
275  virtual osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 ) = 0;
276 };
277 
278 } /* namespace osmosdr */
279 
280 #endif /* INCLUDED_OSMOSDR_SINK_H */
Takes a stream of complex samples.This uses the preferred technique: subclassing gr::hier_block2.
Definition: sink.h:37
Definition: ranges.h:69
boost::shared_ptr< sink > sptr
Definition: sink.h:40
#define OSMOSDR_API
Definition: api.h:30
Definition: device.h:35