GNU Radio's OsmoSDR Package
airspy_source_c.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013 Dimitri Stolnikov <horiz0n@gmx.net>
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  *
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 #ifndef INCLUDED_AIRSPY_SOURCE_C_H
23 #define INCLUDED_AIRSPY_SOURCE_C_H
24 
25 #include <boost/circular_buffer.hpp>
26 #include <boost/thread/mutex.hpp>
27 #include <boost/thread/condition_variable.hpp>
28 
29 #include <gnuradio/sync_block.h>
30 
31 #include <libairspy/airspy.h>
32 
33 #include "source_iface.h"
34 
35 class airspy_source_c;
36 
37 /*
38  * We use boost::shared_ptr's instead of raw pointers for all access
39  * to gr::blocks (and many other data structures). The shared_ptr gets
40  * us transparent reference counting, which greatly simplifies storage
41  * management issues. This is especially helpful in our hybrid
42  * C++ / Python system.
43  *
44  * See http://www.boost.org/libs/smart_ptr/smart_ptr.htm
45  *
46  * As a convention, the _sptr suffix indicates a boost::shared_ptr
47  */
48 typedef boost::shared_ptr<airspy_source_c> airspy_source_c_sptr;
49 
50 /*!
51  * \brief Return a shared_ptr to a new instance of airspy_source_c.
52  *
53  * To avoid accidental use of raw pointers, airspy_source_c's
54  * constructor is private. make_airspy_source_c is the public
55  * interface for creating new instances.
56  */
57 airspy_source_c_sptr make_airspy_source_c (const std::string & args = "");
58 
59 /*!
60  * \brief Provides a stream of complex samples.
61  * \ingroup block
62  */
64  public gr::sync_block,
65  public source_iface
66 {
67 private:
68  // The friend declaration allows make_airspy_source_c to
69  // access the private constructor.
70 
71  friend airspy_source_c_sptr make_airspy_source_c (const std::string & args);
72 
73  /*!
74  * \brief Provides a stream of complex samples.
75  */
76  airspy_source_c (const std::string & args); // private constructor
77 
78 public:
79  ~airspy_source_c (); // public destructor
80 
81  bool start();
82  bool stop();
83 
84  int work( int noutput_items,
85  gr_vector_const_void_star &input_items,
86  gr_vector_void_star &output_items );
87 
88  static std::vector< std::string > get_devices();
89 
90  size_t get_num_channels( void );
91 
93  double set_sample_rate( double rate );
94  double get_sample_rate( void );
95 
96  osmosdr::freq_range_t get_freq_range( size_t chan = 0 );
97  double set_center_freq( double freq, size_t chan = 0 );
98  double get_center_freq( size_t chan = 0 );
99  double set_freq_corr( double ppm, size_t chan = 0 );
100  double get_freq_corr( size_t chan = 0 );
101 
102  std::vector<std::string> get_gain_names( size_t chan = 0 );
103  osmosdr::gain_range_t get_gain_range( size_t chan = 0 );
104  osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
105  bool set_gain_mode( bool automatic, size_t chan = 0 );
106  bool get_gain_mode( size_t chan = 0 );
107  double set_gain( double gain, size_t chan = 0 );
108  double set_gain( double gain, const std::string & name, size_t chan = 0 );
109  double get_gain( size_t chan = 0 );
110  double get_gain( const std::string & name, size_t chan = 0 );
111 
112  double set_mix_gain(double gain, size_t chan = 0 );
113  double set_if_gain( double gain, size_t chan = 0 );
114 
115  std::vector< std::string > get_antennas( size_t chan = 0 );
116  std::string set_antenna( const std::string & antenna, size_t chan = 0 );
117  std::string get_antenna( size_t chan = 0 );
118 
119  double set_bandwidth( double bandwidth, size_t chan = 0 );
120  double get_bandwidth( size_t chan = 0 );
121  osmosdr::freq_range_t get_bandwidth_range( size_t chan = 0 );
122 
123 private:
124  static int _airspy_rx_callback(airspy_transfer* transfer);
125  int airspy_rx_callback(void *samples, int sample_count);
126 
127  static int _usage;
128  static boost::mutex _usage_mutex;
129 
130  airspy_device *_dev;
131 
132  boost::circular_buffer<gr_complex> *_fifo;
133  boost::mutex _fifo_lock;
134  boost::condition_variable _samp_avail;
135 
136  double _sample_rate;
137  double _center_freq;
138  double _freq_corr;
139  bool _auto_gain;
140  double _lna_gain;
141  double _mix_gain;
142  double _vga_gain;
143  double _bandwidth;
144 };
145 
146 #endif /* INCLUDED_AIRSPY_SOURCE_C_H */
double set_if_gain(double gain, size_t chan=0)
airspy_source_c_sptr make_airspy_source_c(const std::string &args="")
Return a shared_ptr to a new instance of airspy_source_c.
osmosdr::gain_range_t get_gain_range(size_t chan=0)
double get_sample_rate(void)
double set_mix_gain(double gain, size_t chan=0)
Definition: source_iface.h:31
size_t get_num_channels(void)
bool set_gain_mode(bool automatic, size_t chan=0)
double get_center_freq(size_t chan=0)
bool get_gain_mode(size_t chan=0)
std::string set_antenna(const std::string &antenna, size_t chan=0)
std::string get_antenna(size_t chan=0)
Definition: ranges.h:69
double get_freq_corr(size_t chan=0)
double get_bandwidth(size_t chan=0)
double set_freq_corr(double ppm, size_t chan=0)
double set_sample_rate(double rate)
osmosdr::freq_range_t get_freq_range(size_t chan=0)
double get_gain(size_t chan=0)
std::vector< std::string > get_antennas(size_t chan=0)
double set_bandwidth(double bandwidth, size_t chan=0)
osmosdr::meta_range_t get_sample_rates(void)
static std::vector< std::string > get_devices()
friend airspy_source_c_sptr make_airspy_source_c(const std::string &args)
Return a shared_ptr to a new instance of airspy_source_c.
double set_gain(double gain, size_t chan=0)
osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)
std::vector< std::string > get_gain_names(size_t chan=0)
double set_center_freq(double freq, size_t chan=0)
Provides a stream of complex samples.
Definition: airspy_source_c.h:63
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)