GNU Radio's TEST Package
sdrplay_source_c.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2015 SDRplay Ltd <support@sdrplay.com>
4  * Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
5  *
6  * GNU Radio is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 3, or (at your option)
9  * any later version.
10  *
11  * GNU Radio is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with GNU Radio; see the file COPYING. If not, write to
18  * the Free Software Foundation, Inc., 51 Franklin Street,
19  * Boston, MA 02110-1301, USA.
20  */
21 #ifndef INCLUDED_SDRPLAY_SOURCE_C_H
22 #define INCLUDED_SDRPLAY_SOURCE_C_H
23 
24 #include <gnuradio/sync_block.h>
25 
26 #include <mutex>
27 #include <condition_variable>
28 
29 #include "osmosdr/ranges.h"
30 
31 #include "source_iface.h"
32 
33 class sdrplay_source_c;
34 typedef struct sdrplay_dev sdrplay_dev_t;
35 
36 /*
37  * We use boost::shared_ptr's instead of raw pointers for all access
38  * to gr::blocks (and many other data structures). The shared_ptr gets
39  * us transparent reference counting, which greatly simplifies storage
40  * management issues. This is especially helpful in our hybrid
41  * C++ / Python system.
42  *
43  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
44  *
45  * As a convention, the _sptr suffix indicates a boost::shared_ptr
46  */
47 typedef boost::shared_ptr<sdrplay_source_c> sdrplay_source_c_sptr;
48 
49 /*!
50  * \brief Return a shared_ptr to a new instance of sdrplay_source_c.
51  *
52  * To avoid accidental use of raw pointers, sdrplay_source_c's
53  * constructor is private. make_sdrplay_source_c is the public
54  * interface for creating new instances.
55  */
56 sdrplay_source_c_sptr make_sdrplay_source_c (const std::string & args = "");
57 
58 /*!
59  * \brief Provides a stream of complex samples.
60  * \ingroup block
61  */
63  public gr::sync_block,
64  public source_iface
65 {
66 private:
67  // The friend declaration allows make_sdrplay_source_c to
68  // access the private constructor.
69 
70  friend sdrplay_source_c_sptr make_sdrplay_source_c (const std::string & args);
71 
72  /*!
73  * \brief Provides a stream of complex samples.
74  */
75  sdrplay_source_c (const std::string & args); // private constructor
76 
77 public:
78  ~sdrplay_source_c (); // public destructor
79 
80  bool start();
81  bool stop();
82 
83  int work( int noutput_items,
84  gr_vector_const_void_star &input_items,
85  gr_vector_void_star &output_items );
86 
87  static std::vector< std::string > get_devices();
88 
89  size_t get_num_channels( void );
90 
92  double set_sample_rate( double rate );
93  double get_sample_rate( void );
94 
95  osmosdr::freq_range_t get_freq_range( size_t chan = 0 );
96  double set_center_freq( double freq, size_t chan = 0 );
97  double get_center_freq( size_t chan = 0 );
98  double set_freq_corr( double ppm, size_t chan = 0 );
99  double get_freq_corr( size_t chan = 0 );
100 
101  std::vector<std::string> get_gain_names( size_t chan = 0 );
102  osmosdr::gain_range_t get_if_gain_range( size_t chan = 0 );
103  osmosdr::gain_range_t get_rf_gain_range( size_t chan = 0 );
104  osmosdr::gain_range_t get_rf_notch_range( size_t chan = 0 );
105  osmosdr::gain_range_t get_dab_notch_range( size_t chan = 0 );
106  osmosdr::gain_range_t get_gain_range( size_t chan = 0 );
107  osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
108  bool set_gain_mode( bool automatic, size_t chan = 0 );
109  bool get_gain_mode( size_t chan = 0 );
110  double set_if_gain( double gain, size_t chan = 0 );
111  double set_rf_gain( double gain, size_t chan = 0 );
112  bool set_rf_notch( double gain, size_t chan = 0 );
113  bool set_dab_notch( double gain, size_t chan = 0 );
114  double set_gain( double gain, size_t chan = 0 );
115  double set_gain( double gain, const std::string & name, size_t chan = 0 );
116  double get_if_gain( size_t chan = 0 );
117  double get_rf_gain( size_t chan = 0 );
118  bool get_rf_notch( size_t chan = 0 );
119  bool get_dab_notch( size_t chan = 0 );
120  double get_gain( size_t chan = 0 );
121  double get_gain( const std::string & name, size_t chan = 0 );
122 
123  std::vector< std::string > get_antennas( size_t chan = 0 );
124  std::string set_antenna( const std::string & antenna, size_t chan = 0 );
125  std::string get_antenna( size_t chan = 0 );
126 
127  void set_dc_offset_mode( int mode, size_t chan = 0 );
128  void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 );
129 
130  double set_bandwidth( double bandwidth, size_t chan = 0 );
131  double get_bandwidth( size_t chan = 0 );
132  osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 );
133  void _buf_transfer(short *xi, short *xq, unsigned int numSamples,
134  unsigned int firstSampleNum, size_t chan = 0);
135  void _sample_gaps_check(unsigned int numSamples,
136  unsigned int firstSampleNum);
137  void _ack_overload_msg();
138  void _save_rspduo_mode_change(const int modeChangeType);
139  bool _is_running() { return _running; }
140 
141 private:
142  bool select_device();
143  bool select_rspduo_device();
144  void set_device_antenna();
145  std::string set_rspduo_antenna(const std::string & antenna, size_t chan = 0);
146  void set_rf_gain_values();
147 
148  sdrplay_dev_t *_dev;
149 
150  short *_bufi;
151  short *_bufq;
152  int _buf_length;
153  std::mutex _buf_mutex;
154  std::condition_variable _buf_ready;
155 
156  bool _selected;
157  bool _started;
158  bool _running;
159  bool _auto_gain;
160 
161  unsigned int _next_sample_num;
162 };
163 
164 #endif /* INCLUDED_SDRPLAY_SOURCE_C_H */
size_t get_num_channels(void)
osmosdr::gain_range_t get_if_gain_range(size_t chan=0)
Definition: source_iface.h:32
bool set_rf_notch(double gain, size_t chan=0)
double set_sample_rate(double rate)
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
osmosdr::gain_range_t get_dab_notch_range(size_t chan=0)
osmosdr::gain_range_t get_rf_notch_range(size_t chan=0)
double get_sample_rate(void)
std::vector< std::string > get_antennas(size_t chan=0)
void _sample_gaps_check(unsigned int numSamples, unsigned int firstSampleNum)
double set_bandwidth(double bandwidth, size_t chan=0)
osmosdr::gain_range_t get_rf_gain_range(size_t chan=0)
double set_center_freq(double freq, size_t chan=0)
double get_gain(size_t chan=0)
bool _is_running()
Definition: sdrplay_source_c.h:139
Definition: ranges.h:75
osmosdr::freq_range_t get_freq_range(size_t chan=0)
sdrplay_source_c_sptr make_sdrplay_source_c(const std::string &args="")
Return a shared_ptr to a new instance of sdrplay_source_c.
friend sdrplay_source_c_sptr make_sdrplay_source_c(const std::string &args)
Return a shared_ptr to a new instance of sdrplay_source_c.
void _buf_transfer(short *xi, short *xq, unsigned int numSamples, unsigned int firstSampleNum, size_t chan=0)
double get_bandwidth(size_t chan=0)
void _save_rspduo_mode_change(const int modeChangeType)
std::string get_antenna(size_t chan=0)
double get_freq_corr(size_t chan=0)
osmosdr::meta_range_t get_sample_rates(void)
double set_freq_corr(double ppm, size_t chan=0)
double set_gain(double gain, size_t chan=0)
std::string set_antenna(const std::string &antenna, size_t chan=0)
void _ack_overload_msg()
bool set_gain_mode(bool automatic, size_t chan=0)
osmosdr::gain_range_t get_gain_range(size_t chan=0)
double get_if_gain(size_t chan=0)
double get_rf_gain(size_t chan=0)
bool set_dab_notch(double gain, size_t chan=0)
void set_dc_offset(const std::complex< double > &offset, size_t chan=0)
struct sdrplay_dev sdrplay_dev_t
Definition: sdrplay_source_c.h:34
Provides a stream of complex samples.
Definition: sdrplay_source_c.h:62
std::vector< std::string > get_gain_names(size_t chan=0)
void set_dc_offset_mode(int mode, size_t chan=0)
static std::vector< std::string > get_devices()
double set_if_gain(double gain, size_t chan=0)
double get_center_freq(size_t chan=0)
double set_rf_gain(double gain, size_t chan=0)
bool get_rf_notch(size_t chan=0)
osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)
bool get_gain_mode(size_t chan=0)
bool get_dab_notch(size_t chan=0)