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 <gnuradio/thread/thread.h>
27 
28 #include <mutex>
29 #include <condition_variable>
30 
31 #include "osmosdr/ranges.h"
32 
33 #include "source_iface.h"
34 
35 class sdrplay_source_c;
36 typedef struct sdrplay_dev sdrplay_dev_t;
37 
38 /*
39  * We use std::shared_ptr's instead of raw pointers for all access
40  * to gr::blocks (and many other data structures). The shared_ptr gets
41  * us transparent reference counting, which greatly simplifies storage
42  * management issues. This is especially helpful in our hybrid
43  * C++ / Python system.
44  *
45  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
46  *
47  * As a convention, the _sptr suffix indicates a std::shared_ptr
48  */
49 typedef std::shared_ptr<sdrplay_source_c> sdrplay_source_c_sptr;
50 
51 /*!
52  * \brief Return a shared_ptr to a new instance of sdrplay_source_c.
53  *
54  * To avoid accidental use of raw pointers, sdrplay_source_c's
55  * constructor is private. make_sdrplay_source_c is the public
56  * interface for creating new instances.
57  */
58 sdrplay_source_c_sptr make_sdrplay_source_c (const std::string & args = "");
59 
60 /*!
61  * \brief Provides a stream of complex samples.
62  * \ingroup block
63  */
65  public gr::sync_block,
66  public source_iface
67 {
68 private:
69  // The friend declaration allows make_sdrplay_source_c to
70  // access the private constructor.
71 
72  friend sdrplay_source_c_sptr make_sdrplay_source_c (const std::string & args);
73 
74  /*!
75  * \brief Provides a stream of complex samples.
76  */
77  sdrplay_source_c (const std::string & args); // private constructor
78 
79 public:
80  ~sdrplay_source_c (); // public destructor
81 
82  int work( int noutput_items,
83  gr_vector_const_void_star &input_items,
84  gr_vector_void_star &output_items );
85 
86  static std::vector< std::string > get_devices();
87 
88  size_t get_num_channels( void );
89 
91  double set_sample_rate( double rate );
92  double get_sample_rate( void );
93 
95  double set_center_freq( double freq, size_t chan = 0 );
96  double get_center_freq( size_t chan = 0 );
97  double set_freq_corr( double ppm, size_t chan = 0 );
98  double get_freq_corr( size_t chan = 0 );
99 
100  std::vector<std::string> get_gain_names( size_t chan = 0 );
102  osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
103  bool set_gain_mode( bool automatic, size_t chan = 0 );
104  bool get_gain_mode( size_t chan = 0 );
105  double set_gain( double gain, size_t chan = 0 );
106  double set_gain( double gain, const std::string & name, size_t chan = 0 );
107  double get_gain( size_t chan = 0 );
108  double get_gain( const std::string & name, size_t chan = 0 );
109 
110  std::vector< std::string > get_antennas( size_t chan = 0 );
111  std::string set_antenna( const std::string & antenna, size_t chan = 0 );
112  std::string get_antenna( size_t chan = 0 );
113 
114  void set_dc_offset_mode( int mode, size_t chan = 0 );
115  void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 );
116 
117  double set_bandwidth( double bandwidth, size_t chan = 0 );
118  double get_bandwidth( size_t chan = 0 );
120 
121 private:
122  void reinit_device(void);
123  void set_gain_limits(double freq);
124 
125  sdrplay_dev_t *_dev;
126 
127  std::vector< short > _bufi;
128  std::vector< short > _bufq;
129  int _buf_offset;
130  std::mutex _buf_mutex;
131 
132  bool _running;
133  bool _uninit;
134  bool _auto_gain;
135 };
136 
137 #endif /* INCLUDED_SDRPLAY_SOURCE_C_H */
Provides a stream of complex samples.
Definition: sdrplay_source_c.h:67
double get_gain(const std::string &name, size_t chan=0)
double get_sample_rate(void)
double get_bandwidth(size_t chan=0)
osmosdr::gain_range_t get_gain_range(size_t chan=0)
double set_center_freq(double freq, size_t chan=0)
double set_gain(double gain, size_t chan=0)
std::vector< std::string > get_gain_names(size_t chan=0)
size_t get_num_channels(void)
osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)
osmosdr::freq_range_t get_freq_range(size_t chan=0)
osmosdr::meta_range_t get_sample_rates(void)
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
std::string set_antenna(const std::string &antenna, size_t chan=0)
double set_sample_rate(double rate)
double set_freq_corr(double ppm, size_t chan=0)
void set_dc_offset(const std::complex< double > &offset, size_t chan=0)
double get_freq_corr(size_t chan=0)
static std::vector< std::string > get_devices()
std::vector< std::string > get_antennas(size_t chan=0)
double get_gain(size_t chan=0)
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.
double set_gain(double gain, const std::string &name, size_t chan=0)
bool get_gain_mode(size_t chan=0)
double set_bandwidth(double bandwidth, size_t chan=0)
void set_dc_offset_mode(int mode, size_t chan=0)
double get_center_freq(size_t chan=0)
std::string get_antenna(size_t chan=0)
osmosdr::gain_range_t get_gain_range(const std::string &name, size_t chan=0)
bool set_gain_mode(bool automatic, size_t chan=0)
Definition: source_iface.h:33
sdrplay_source_c_sptr make_sdrplay_source_c(const std::string &args="")
Return a shared_ptr to a new instance of sdrplay_source_c.
struct sdrplay_dev sdrplay_dev_t
Definition: sdrplay_source_c.h:36
Definition: ranges.h:75