GNU Radio's TEST Package
osmosdr_src_c.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_SRC_C_H
21 #define INCLUDED_OSMOSDR_SRC_C_H
22 
23 #include <gnuradio/sync_block.h>
24 
25 #include <gnuradio/thread/thread.h>
26 
27 #include <mutex>
28 #include <condition_variable>
29 
30 #include "source_iface.h"
31 
32 class osmosdr_src_c;
33 typedef struct osmosdr_dev osmosdr_dev_t;
34 
35 /*
36  * We use boost::shared_ptr's instead of raw pointers for all access
37  * to gr::blocks (and many other data structures). The shared_ptr gets
38  * us transparent reference counting, which greatly simplifies storage
39  * management issues. This is especially helpful in our hybrid
40  * C++ / Python system.
41  *
42  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
43  *
44  * As a convention, the _sptr suffix indicates a boost::shared_ptr
45  */
46 typedef boost::shared_ptr<osmosdr_src_c> osmosdr_src_c_sptr;
47 
48 /*!
49  * \brief Return a shared_ptr to a new instance of osmosdr_src_c.
50  *
51  * To avoid accidental use of raw pointers, osmosdr_src_c's
52  * constructor is private. osmosdr_make_src_c is the public
53  * interface for creating new instances.
54  */
55 osmosdr_src_c_sptr osmosdr_make_src_c (const std::string & args = "");
56 
57 /*!
58  * \brief Provides a stream of complex samples.
59  * \ingroup block
60  *
61  * \sa sink for a version that subclasses gr::hier_block2.
62  */
64  public gr::sync_block,
65  public source_iface
66 {
67 private:
68  // The friend declaration allows osmosdr_make_src_c to
69  // access the private constructor.
70 
71  friend osmosdr_src_c_sptr osmosdr_make_src_c (const std::string & args);
72 
73  /*!
74  * \brief Provides a stream of complex samples.
75  */
76  osmosdr_src_c (const std::string & args); // private constructor
77 
78  public:
79  ~osmosdr_src_c (); // public destructor
80 
81  int work( int noutput_items,
82  gr_vector_const_void_star &input_items,
83  gr_vector_void_star &output_items );
84 
85  static std::vector< std::string > get_devices();
86 
87  size_t get_num_channels( void );
88 
90  double set_sample_rate( double rate );
91  double get_sample_rate( void );
92 
94  double set_center_freq( double freq, size_t chan = 0 );
95  double get_center_freq( size_t chan = 0 );
96  double set_freq_corr( double ppm, size_t chan = 0 );
97  double get_freq_corr( size_t chan = 0 );
98 
99  std::vector<std::string> get_gain_names( size_t chan = 0 );
101  osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
102  bool set_gain_mode( bool automatic, size_t chan = 0 );
103  bool get_gain_mode( size_t chan = 0 );
104  double set_gain( double gain, size_t chan = 0 );
105  double set_gain( double gain, const std::string & name, size_t chan = 0 );
106  double get_gain( size_t chan = 0 );
107  double get_gain( const std::string & name, size_t chan = 0 );
108 
109  double set_if_gain( double gain, size_t chan = 0 );
110 
111  std::vector< std::string > get_antennas( size_t chan = 0 );
112  std::string set_antenna( const std::string & antenna, size_t chan = 0 );
113  std::string get_antenna( size_t chan = 0 );
114 
115 private:
116  static void _osmosdr_callback(unsigned char *buf, uint32_t len, void *ctx);
117  void osmosdr_callback(unsigned char *buf, uint32_t len);
118  static void _osmosdr_wait(osmosdr_src_c *obj);
119  void osmosdr_wait();
120 
121  osmosdr_dev_t *_dev;
122  gr::thread::thread _thread;
123  unsigned short **_buf;
124  unsigned int _buf_num;
125  unsigned int _buf_len;
126  unsigned int _buf_head;
127  unsigned int _buf_used;
128  std::mutex _buf_mutex;
129  std::condition_variable _buf_cond;
130  bool _running;
131 
132  unsigned int _buf_offset;
133  int _samp_avail;
134 
135  bool _auto_gain;
136  double _if_gain;
137  unsigned int _skipped;
138 };
139 
140 #endif /* INCLUDED_OSMOSDR_SRC_C_H */
Provides a stream of complex samples.
Definition: osmosdr_src_c.h:66
osmosdr::gain_range_t get_gain_range(const std::string &name, size_t chan=0)
double get_center_freq(size_t chan=0)
osmosdr::freq_range_t get_freq_range(size_t chan=0)
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
double set_freq_corr(double ppm, size_t chan=0)
std::string get_antenna(size_t chan=0)
static std::vector< std::string > get_devices()
double set_sample_rate(double rate)
double get_gain(size_t chan=0)
std::vector< std::string > get_gain_names(size_t chan=0)
std::vector< std::string > get_antennas(size_t chan=0)
double set_if_gain(double gain, size_t chan=0)
osmosdr::meta_range_t get_sample_rates(void)
double get_gain(const std::string &name, size_t chan=0)
friend osmosdr_src_c_sptr osmosdr_make_src_c(const std::string &args)
Return a shared_ptr to a new instance of osmosdr_src_c.
double get_sample_rate(void)
size_t get_num_channels(void)
osmosdr::gain_range_t get_gain_range(size_t chan=0)
std::string set_antenna(const std::string &antenna, size_t chan=0)
bool get_gain_mode(size_t chan=0)
double set_gain(double gain, size_t chan=0)
double get_freq_corr(size_t chan=0)
double set_gain(double gain, const std::string &name, size_t chan=0)
double set_center_freq(double freq, size_t chan=0)
bool set_gain_mode(bool automatic, size_t chan=0)
Definition: source_iface.h:33
osmosdr_src_c_sptr osmosdr_make_src_c(const std::string &args="")
Return a shared_ptr to a new instance of osmosdr_src_c.
struct osmosdr_dev osmosdr_dev_t
Definition: osmosdr_src_c.h:33
Definition: ranges.h:75