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 /* We currently read/write 1024 samples (pairs of 16-bit signed ints) */
44 #define BLADERF_SAMPLE_BLOCK_SIZE (1024)
45 
46 typedef boost::shared_ptr<struct bladerf> bladerf_sptr;
47 
49 {
50 public:
52  virtual ~bladerf_common();
53 
54 protected:
55  /* Handle initialized and parameters common to both source & sink */
56  void init(dict_t &dict, const char *type);
57 
61 
62  static std::vector< std::string > devices();
63 
64  bool is_running();
65  void set_running(bool is_running);
66 
67  bladerf_sptr _dev;
68 
69  void **_buffers;
70  struct bladerf_stream *_stream;
71  size_t _num_buffers;
72  size_t _buf_index;
75 
76  gr::thread::thread _thread;
77 
80 
81  std::string _pfx;
82 
83 private:
84  bladerf_sptr open(const std::string &device_name);
85 
86  bool _is_running;
87  boost::shared_mutex _state_lock;
88 
89  static boost::mutex _devs_mutex;
90  static std::list<boost::weak_ptr<struct bladerf> > _devs;
91 
92  static bladerf_sptr get_cached_device(struct bladerf_devinfo devinfo);
93  static void close(void *dev); /* called by shared_ptr */
94 };
95 
96 #endif
size_t _num_transfers
Definition: bladerf_common.h:74
size_t _samples_per_buffer
Definition: bladerf_common.h:73
size_t _num_buffers
Definition: bladerf_common.h:71
gr::thread::thread _thread
Definition: bladerf_common.h:76
osmosdr::meta_range_t sample_rates()
Definition: ranges.h:69
osmosdr::gain_range_t _vga2_range
Definition: bladerf_common.h:79
void ** _buffers
Definition: bladerf_common.h:69
size_t _buf_index
Definition: bladerf_common.h:72
osmosdr::freq_range_t filter_bandwidths()
osmosdr::freq_range_t freq_range()
static std::vector< std::string > devices()
void init(dict_t &dict, const char *type)
Definition: bladerf_common.h:48
struct bladerf_stream * _stream
Definition: bladerf_common.h:70
virtual ~bladerf_common()
void set_running(bool is_running)
osmosdr::gain_range_t _vga1_range
Definition: bladerf_common.h:78
std::string _pfx
Definition: bladerf_common.h:81
std::map< std::string, std::string > dict_t
Definition: arg_helpers.h:34
bladerf_sptr _dev
Definition: bladerf_common.h:67