GNU Radio's SDR Package
sdr_helpers.h
Go to the documentation of this file.
1 /*
2  * Copyright 2010-2014 Free Software Foundation, Inc.
3  *
4  * This file is part of GNU Radio
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 
22 #ifndef INCLUDED_GR_SDR_SDR_HELPERS_H
23 #define INCLUDED_GR_SDR_SDR_HELPERS_H
24 
25 #include <SoapySDR/Version.hpp>
26 #include <SoapySDR/Types.hpp>
27 #include <gnuradio/sdr/types.h>
28 #include <gnuradio/io_signature.h>
29 #include <boost/lexical_cast.hpp>
30 #include <boost/foreach.hpp>
31 #include <sstream>
32 #include <cctype>
33 #include <stdexcept>
34 
35 static void check_abi(const std::string &what)
36 {
37  if (SoapySDR::getABIVersion() == SOAPY_SDR_ABI_VERSION) return;
38  std::stringstream ss;
39  ss << what << "() failed ABI check" << std::endl;
40  ss << " GNURadio Client ABI Version: " << SOAPY_SDR_ABI_VERSION << std::endl;
41  ss << " SoapySDR Library ABI Version: " << SoapySDR::getABIVersion() << std::endl;
42  ss << " Rebuild module against installed library..." << std::endl;
43  throw std::runtime_error(ss.str());
44 }
45 
46 static gr::io_signature::sptr stream_args_to_io_signature(const std::string &format, std::vector<size_t> &channels)
47 {
48  //create a single channel if unspecified
49  if (channels.empty()) channels.push_back(0);
50 
51  //parse the format string
52  bool isComplex = false;
53  std::string numStr;
54  BOOST_FOREACH (const char ch, format)
55  {
56  if (ch == 'C') isComplex = true;
57  if (std::isdigit(ch)) numStr += ch;
58  }
59 
60  //create io signature
61  int bits = boost::lexical_cast<int>(numStr);
62  if (isComplex) bits *= 2;
63  return gr::io_signature::make(channels.size(), channels.size(), bits/8);
64 }
65 
66 static gr::sdr::range_t toRange(const SoapySDR::Range &r)
67 {
68  return gr::sdr::range_t(r.minimum(), r.maximum());
69 }
70 
71 static std::vector<gr::sdr::range_t> toRanges(const std::vector<SoapySDR::Range> &ranges)
72 {
73  std::vector<gr::sdr::range_t> out;
74  BOOST_FOREACH (const SoapySDR::Range &r, ranges) out.push_back(toRange(r));
75  return out;
76 }
77 
78 #endif /* INCLUDED_GR_SDR_SDR_HELPERS_H */
static gr::sdr::range_t toRange(const SoapySDR::Range &r)
Definition: sdr_helpers.h:66
static gr::io_signature::sptr stream_args_to_io_signature(const std::string &format, std::vector< size_t > &channels)
Definition: sdr_helpers.h:46
Definition: types.h:39
static void check_abi(const std::string &what)
Definition: sdr_helpers.h:35
static std::vector< gr::sdr::range_t > toRanges(const std::vector< SoapySDR::Range > &ranges)
Definition: sdr_helpers.h:71