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 
35 #include <gnuradio/thread/thread.h>
36 #include <gnuradio/gr_complex.h>
37 
38 #include <libbladeRF.h>
39 
40 #include "osmosdr/ranges.h"
41 #include "arg_helpers.h"
42 
43 typedef boost::shared_ptr<struct bladerf> bladerf_sptr;
44 
46 {
47 public:
49  virtual ~bladerf_common();
50 
51 protected:
52  /* Handle initialized and parameters common to both source & sink */
53  void init(dict_t &dict, bladerf_module module);
54 
55  bool start(bladerf_module module);
56  bool stop(bladerf_module module);
57 
58  double set_sample_rate(bladerf_module module, double rate);
59  double get_sample_rate(bladerf_module module);
60 
61  int set_dc_offset(bladerf_module module, const std::complex<double> &offset, size_t chan);
62  int set_iq_balance(bladerf_module module, const std::complex<double> &balance, size_t chan);
63 
67 
68  static std::vector< std::string > devices();
69 
70  bladerf_sptr _dev;
71 
72  size_t _num_buffers;
75  unsigned int _stream_timeout_ms;
76 
77  int16_t *_conv_buf;
78  int _conv_buf_size; /* In units of samples */
79 
82 
83  std::string _pfx;
84 
86 
87  /* BladeRF IQ correction parameters */
88  static const int16_t DCOFF_SCALE = 2048;
89  static const int16_t GAIN_SCALE = 4096;
90  static const int16_t PHASE_SCALE = 4096;
91 
92 private:
93  bladerf_sptr open(const std::string &device_name);
94  static void close(void *dev); /* called by shared_ptr */
95  static bladerf_sptr get_cached_device(struct bladerf_devinfo devinfo);
96 
97  void set_verbosity(const std::string &verbosity);
98  void set_loopback_mode(const std::string &loopback);
99 
100  static boost::mutex _devs_mutex;
101  static std::list<boost::weak_ptr<struct bladerf> > _devs;
102 };
103 
104 #endif
size_t _num_transfers
Definition: bladerf_common.h:74
size_t _samples_per_buffer
Definition: bladerf_common.h:73
double set_sample_rate(bladerf_module module, double rate)
size_t _num_buffers
Definition: bladerf_common.h:72
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:69
int _conv_buf_size
Definition: bladerf_common.h:78
osmosdr::gain_range_t _vga2_range
Definition: bladerf_common.h:81
static const int16_t PHASE_SCALE
Definition: bladerf_common.h:90
bool start(bladerf_module module)
osmosdr::freq_range_t filter_bandwidths()
static const int16_t DCOFF_SCALE
Definition: bladerf_common.h:88
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:85
unsigned int _stream_timeout_ms
Definition: bladerf_common.h:75
static const int16_t GAIN_SCALE
Definition: bladerf_common.h:89
Definition: bladerf_common.h:45
virtual ~bladerf_common()
osmosdr::gain_range_t _vga1_range
Definition: bladerf_common.h:80
std::string _pfx
Definition: bladerf_common.h:83
int16_t * _conv_buf
Definition: bladerf_common.h:77
std::map< std::string, std::string > dict_t
Definition: arg_helpers.h:34
bladerf_sptr _dev
Definition: bladerf_common.h:70