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#include <boost/thread/mutex.hpp>
28#include <boost/thread/condition_variable.hpp>
29
30#include "osmosdr/ranges.h"
31
32#include "source_iface.h"
33
35typedef struct sdrplay_dev sdrplay_dev_t;
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 */
48typedef std::shared_ptr<sdrplay_source_c> sdrplay_source_c_sptr;
49
50/*!
51 * \brief Return a shared_ptr to a new instance of sdrplay_source_c.
52 *
53 * To avoid accidental use of raw pointers, sdrplay_source_c's
54 * constructor is private. make_sdrplay_source_c is the public
55 * interface for creating new instances.
56 */
57sdrplay_source_c_sptr make_sdrplay_source_c (const std::string & args = "");
58
59/*!
60 * \brief Provides a stream of complex samples.
61 * \ingroup block
62 */
63class sdrplay_source_c :
64 public gr::sync_block,
65 public source_iface
66{
67private:
68 // The friend declaration allows make_sdrplay_source_c to
69 // access the private constructor.
70
71 friend sdrplay_source_c_sptr make_sdrplay_source_c (const std::string & args);
72
73 /*!
74 * \brief Provides a stream of complex samples.
75 */
76 sdrplay_source_c (const std::string & args); // private constructor
77
78public:
79 ~sdrplay_source_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 std::vector< std::string > get_antennas( size_t chan = 0 );
110 std::string set_antenna( const std::string & antenna, size_t chan = 0 );
111 std::string get_antenna( size_t chan = 0 );
112
113 void set_dc_offset_mode( int mode, size_t chan = 0 );
114 void set_dc_offset( const std::complex<double> &offset, size_t chan = 0 );
115
116 double set_bandwidth( double bandwidth, size_t chan = 0 );
117 double get_bandwidth( size_t chan = 0 );
119
120private:
121 void reinit_device(void);
122 void set_gain_limits(double freq);
123
124 sdrplay_dev_t *_dev;
125
126 std::vector< short > _bufi;
127 std::vector< short > _bufq;
128 int _buf_offset;
129 boost::mutex _buf_mutex;
130
131 bool _running;
132 bool _uninit;
133 bool _auto_gain;
134};
135
136#endif /* INCLUDED_SDRPLAY_SOURCE_C_H */
Provides a stream of complex samples.
Definition sdrplay_source_c.h:66
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)
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)
std::vector< std::string > get_gain_names(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)
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 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)
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
meta_range_t freq_range_t
Definition ranges.h:125
meta_range_t gain_range_t
Definition ranges.h:124
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:35
Definition ranges.h:75