GNU Radio's TEST 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
27#include <mutex>
28#include <condition_variable>
29
30#include <gnuradio/sync_block.h>
31
32#include <libairspy/airspy.h>
33
34#include "source_iface.h"
35
36class airspy_source_c;
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 */
49typedef std::shared_ptr<airspy_source_c> airspy_source_c_sptr;
50
51/*!
52 * \brief Return a shared_ptr to a new instance of airspy_source_c.
53 *
54 * To avoid accidental use of raw pointers, airspy_source_c's
55 * constructor is private. make_airspy_source_c is the public
56 * interface for creating new instances.
57 */
58airspy_source_c_sptr make_airspy_source_c (const std::string & args = "");
59
60/*!
61 * \brief Provides a stream of complex samples.
62 * \ingroup block
63 */
64class airspy_source_c :
65 public gr::sync_block,
66 public source_iface
67{
68private:
69 // The friend declaration allows make_airspy_source_c to
70 // access the private constructor.
71
72 friend airspy_source_c_sptr make_airspy_source_c (const std::string & args);
73
74 /*!
75 * \brief Provides a stream of complex samples.
76 */
77 airspy_source_c (const std::string & args); // private constructor
78
79public:
80 ~airspy_source_c (); // public destructor
81
82 bool start();
83 bool stop();
84
85 int work( int noutput_items,
86 gr_vector_const_void_star &input_items,
87 gr_vector_void_star &output_items );
88
89 static std::vector< std::string > get_devices();
90
91 size_t get_num_channels( void );
92
94 double set_sample_rate( double rate );
95 double get_sample_rate( void );
96
98 double set_center_freq( double freq, size_t chan = 0 );
99 double get_center_freq( size_t chan = 0 );
100 double set_freq_corr( double ppm, size_t chan = 0 );
101 double get_freq_corr( size_t chan = 0 );
102
103 std::vector<std::string> get_gain_names( size_t chan = 0 );
105 osmosdr::gain_range_t get_gain_range( const std::string & name, size_t chan = 0 );
106 bool set_gain_mode( bool automatic, size_t chan = 0 );
107 bool get_gain_mode( size_t chan = 0 );
108 double set_gain( double gain, size_t chan = 0 );
109 double set_gain( double gain, const std::string & name, size_t chan = 0 );
110 double get_gain( size_t chan = 0 );
111 double get_gain( const std::string & name, size_t chan = 0 );
112
113 double set_lna_gain( double gain, size_t chan = 0 );
114 double set_mix_gain(double gain, size_t chan = 0 );
115 double set_if_gain( double gain, size_t chan = 0 );
116
117 std::vector< std::string > get_antennas( size_t chan = 0 );
118 std::string set_antenna( const std::string & antenna, size_t chan = 0 );
119 std::string get_antenna( size_t chan = 0 );
120
121 double set_bandwidth( double bandwidth, size_t chan = 0 );
122 double get_bandwidth( size_t chan = 0 );
124
125private:
126 static int _airspy_rx_callback(airspy_transfer* transfer);
127 int airspy_rx_callback(void *samples, int sample_count);
128
129 airspy_device *_dev;
130
131 boost::circular_buffer<gr_complex> *_fifo;
132 std::mutex _fifo_lock;
133 std::condition_variable _samp_avail;
134
135 std::vector< std::pair<double, uint32_t> > _sample_rates;
136 double _sample_rate;
137 double _center_freq;
138 double _freq_corr;
139 bool _auto_gain;
140 double _gain;
141 enum gain_policy
142 {
143 linearity,
144 sensitivity
145 };
146 enum gain_policy _gain_policy;
147 double _lna_gain;
148 double _mix_gain;
149 double _vga_gain;
150 double _bandwidth;
151};
152
153#endif /* INCLUDED_AIRSPY_SOURCE_C_H */
airspy_source_c_sptr make_airspy_source_c(const std::string &args="")
Return a shared_ptr to a new instance of airspy_source_c.
Provides a stream of complex samples.
Definition airspy_source_c.h:67
std::vector< std::string > get_gain_names(size_t chan=0)
bool get_gain_mode(size_t chan=0)
double set_gain(double gain, size_t chan=0)
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.
osmosdr::freq_range_t get_freq_range(size_t chan=0)
double set_bandwidth(double bandwidth, size_t chan=0)
std::string set_antenna(const std::string &antenna, size_t chan=0)
double set_mix_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)
double set_sample_rate(double rate)
double set_if_gain(double gain, size_t chan=0)
double get_gain(size_t chan=0)
double get_freq_corr(size_t chan=0)
double get_center_freq(size_t chan=0)
double get_bandwidth(size_t chan=0)
osmosdr::gain_range_t get_gain_range(const std::string &name, size_t chan=0)
double set_lna_gain(double gain, size_t chan=0)
std::vector< std::string > get_antennas(size_t chan=0)
static std::vector< std::string > get_devices()
double set_freq_corr(double ppm, size_t chan=0)
double set_center_freq(double freq, size_t chan=0)
double set_gain(double gain, const std::string &name, size_t chan=0)
osmosdr::freq_range_t get_bandwidth_range(size_t chan=0)
bool set_gain_mode(bool automatic, size_t chan=0)
size_t get_num_channels(void)
double get_sample_rate(void)
std::string get_antenna(size_t chan=0)
osmosdr::gain_range_t get_gain_range(size_t chan=0)
int work(int noutput_items, gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
Definition source_iface.h:33
meta_range_t freq_range_t
Definition ranges.h:125
meta_range_t gain_range_t
Definition ranges.h:124
Definition ranges.h:75