GNU Radio's OsmoSDR Package
bladerf_common.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2013 Nuand LLC
4  * Copyright 2013 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_BLADERF_COMMON_H
22 #define INCLUDED_BLADERF_COMMON_H
23 
24 #include <vector>
25 #include <string>
26 
27 #include <boost/circular_buffer.hpp>
28 #include <boost/thread/mutex.hpp>
29 #include <boost/thread/shared_mutex.hpp>
30 #include <boost/thread/condition_variable.hpp>
31 #include <boost/assign.hpp>
32 #include <boost/format.hpp>
33 #include <boost/lexical_cast.hpp>
34 #include <boost/weak_ptr.hpp>
35 
36 #include <gnuradio/thread/thread.h>
37 #include <gnuradio/gr_complex.h>
38 
39 #include <libbladeRF.h>
40 
41 #include "osmosdr/ranges.h"
42 #include "arg_helpers.h"
43 
44 #ifdef _MSC_VER
45 #include <cstddef>
46 typedef ptrdiff_t ssize_t;
47 #endif //_MSC_VER
48 
49 typedef boost::shared_ptr<struct bladerf> bladerf_sptr;
50 
52 {
53 public:
55  virtual ~bladerf_common();
56 
57 protected:
58  /* Handle initialized and parameters common to both source & sink */
59  void init(dict_t &dict, bladerf_module module);
60 
61  bool start(bladerf_module module);
62  bool stop(bladerf_module module);
63 
64  double set_sample_rate(bladerf_module module, double rate);
65  double get_sample_rate(bladerf_module module);
66 
67  int set_dc_offset(bladerf_module module, const std::complex<double> &offset, size_t chan);
68  int set_iq_balance(bladerf_module module, const std::complex<double> &balance, size_t chan);
69 
70  void set_clock_source(const std::string &source, const size_t mboard = 0);
71  std::string get_clock_source(const size_t mboard = 0);
72  std::vector<std::string> get_clock_sources(const size_t mboard = 0);
73 
74  void set_smb_frequency(double frequency);
75  double get_smb_frequency();
76 
80 
81  static std::vector< std::string > devices();
82 
83  bladerf_sptr _dev;
84 
85  size_t _num_buffers;
88  unsigned int _stream_timeout_ms;
89 
90  int16_t *_conv_buf;
91  int _conv_buf_size; /* In units of samples */
92 
94 
97 
98  std::string _pfx;
99 
101  unsigned int _consecutive_failures;
102 
103  /* BladeRF IQ correction parameters */
104  static const int16_t DCOFF_SCALE = 2048;
105  static const int16_t GAIN_SCALE = 4096;
106  static const int16_t PHASE_SCALE = 4096;
107 
108  static const unsigned int MAX_CONSECUTIVE_FAILURES = 3;
109 
110 private:
111  bladerf_sptr open(const std::string &device_name);
112  static void close(void *dev); /* called by shared_ptr */
113  static bladerf_sptr get_cached_device(struct bladerf_devinfo devinfo);
114 
115  void set_verbosity(const std::string &verbosity);
116  void set_loopback_mode(const std::string &loopback);
117 
118  static boost::mutex _devs_mutex;
119  static std::list<boost::weak_ptr<struct bladerf> > _devs;
120 };
121 
122 #endif
size_t _num_transfers
Definition: bladerf_common.h:87
bool _use_metadata
Definition: bladerf_common.h:93
std::vector< std::string > get_clock_sources(const size_t mboard=0)
size_t _samples_per_buffer
Definition: bladerf_common.h:86
double set_sample_rate(bladerf_module module, double rate)
size_t _num_buffers
Definition: bladerf_common.h:85
double get_sample_rate(bladerf_module module)
int set_iq_balance(bladerf_module module, const std::complex< double > &balance, size_t chan)
osmosdr::meta_range_t sample_rates()
Definition: ranges.h:75
int _conv_buf_size
Definition: bladerf_common.h:91
static const unsigned int MAX_CONSECUTIVE_FAILURES
Definition: bladerf_common.h:108
std::string get_clock_source(const size_t mboard=0)
osmosdr::gain_range_t _vga2_range
Definition: bladerf_common.h:96
static const int16_t PHASE_SCALE
Definition: bladerf_common.h:106
unsigned int _consecutive_failures
Definition: bladerf_common.h:101
bool start(bladerf_module module)
osmosdr::freq_range_t filter_bandwidths()
void set_clock_source(const std::string &source, const size_t mboard=0)
static const int16_t DCOFF_SCALE
Definition: bladerf_common.h:104
int set_dc_offset(bladerf_module module, const std::complex< double > &offset, size_t chan)
osmosdr::freq_range_t freq_range()
static std::vector< std::string > devices()
void init(dict_t &dict, bladerf_module module)
bool stop(bladerf_module module)
bool _xb_200_attached
Definition: bladerf_common.h:100
unsigned int _stream_timeout_ms
Definition: bladerf_common.h:88
static const int16_t GAIN_SCALE
Definition: bladerf_common.h:105
Definition: bladerf_common.h:51
virtual ~bladerf_common()
double get_smb_frequency()
osmosdr::gain_range_t _vga1_range
Definition: bladerf_common.h:95
std::string _pfx
Definition: bladerf_common.h:98
int16_t * _conv_buf
Definition: bladerf_common.h:90
std::map< std::string, std::string > dict_t
Definition: arg_helpers.h:35
bladerf_sptr _dev
Definition: bladerf_common.h:83
void set_smb_frequency(double frequency)