2013-07-20 16:14:20 +00:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Nuand LLC
|
|
|
|
* Copyright 2013 Dimitri Stolnikov <horiz0n@gmx.net>
|
|
|
|
*
|
|
|
|
* GNU Radio is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* GNU Radio is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Radio; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* config.h is generated by configure. It contains the results
|
|
|
|
* of probing for features, options etc. It should be the first
|
|
|
|
* file included in your .cc file.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <iomanip>
|
|
|
|
#include <iostream>
|
|
|
|
#include <sstream>
|
|
|
|
|
|
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
#include <boost/assign.hpp>
|
|
|
|
#include <boost/foreach.hpp>
|
2013-10-19 16:00:38 +00:00
|
|
|
#include <boost/shared_ptr.hpp>
|
2013-07-20 16:14:20 +00:00
|
|
|
|
|
|
|
#include "bladerf_common.h"
|
|
|
|
|
2013-10-26 19:59:23 +00:00
|
|
|
#define NUM_BUFFERS 32
|
|
|
|
#define NUM_SAMPLES_PER_BUFFER (4 * 1024)
|
|
|
|
|
2013-07-20 16:14:20 +00:00
|
|
|
using namespace boost::assign;
|
|
|
|
|
2013-10-19 16:00:38 +00:00
|
|
|
boost::mutex bladerf_common::_devs_mutex;
|
|
|
|
std::list<boost::weak_ptr<struct bladerf> > bladerf_common::_devs;
|
|
|
|
|
2014-02-16 22:42:32 +00:00
|
|
|
bladerf_common::bladerf_common() : _conv_buf(NULL), _conv_buf_size(4096) {}
|
|
|
|
|
|
|
|
bladerf_common::~bladerf_common()
|
|
|
|
{
|
|
|
|
free(_conv_buf);
|
|
|
|
}
|
2013-07-20 16:14:20 +00:00
|
|
|
|
2013-10-19 16:00:38 +00:00
|
|
|
bladerf_sptr bladerf_common:: get_cached_device(struct bladerf_devinfo devinfo)
|
|
|
|
{
|
|
|
|
/* Lock to _devs must be aquired by caller */
|
|
|
|
BOOST_FOREACH( boost::weak_ptr<struct bladerf> dev, _devs )
|
|
|
|
{
|
|
|
|
struct bladerf_devinfo other_devinfo;
|
|
|
|
|
|
|
|
int rv = bladerf_get_devinfo(bladerf_sptr(dev).get(), &other_devinfo);
|
|
|
|
if (rv < 0)
|
|
|
|
throw std::runtime_error(std::string(__FUNCTION__) + " " +
|
|
|
|
"Failed to get devinfo for cached device.");
|
|
|
|
|
|
|
|
if (bladerf_devinfo_matches(&devinfo, &other_devinfo)) {
|
|
|
|
return bladerf_sptr(dev);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return bladerf_sptr();
|
|
|
|
}
|
|
|
|
|
2014-03-07 06:44:17 +00:00
|
|
|
/* This is called when a bladerf_sptr hits a refcount of 0 */
|
2013-10-19 16:00:38 +00:00
|
|
|
void bladerf_common::close(void* dev)
|
|
|
|
{
|
|
|
|
boost::unique_lock<boost::mutex> lock(_devs_mutex);
|
|
|
|
|
2014-03-07 06:44:17 +00:00
|
|
|
/* Prune expired entries from device cache */
|
|
|
|
std::list<boost::weak_ptr<struct bladerf> >::iterator it(_devs.begin());
|
|
|
|
while ( it != _devs.end() ) {
|
|
|
|
if ( (*it).expired() ) {
|
|
|
|
it = _devs.erase(it);
|
|
|
|
} else {
|
|
|
|
++it;
|
|
|
|
}
|
|
|
|
}
|
2013-10-19 16:00:38 +00:00
|
|
|
|
|
|
|
bladerf_close((struct bladerf *)dev);
|
|
|
|
}
|
|
|
|
|
|
|
|
bladerf_sptr bladerf_common::open(const std::string &device_name)
|
|
|
|
{
|
|
|
|
int rv;
|
|
|
|
struct bladerf *raw_dev;
|
|
|
|
struct bladerf_devinfo devinfo;
|
|
|
|
|
|
|
|
boost::unique_lock<boost::mutex> lock(_devs_mutex);
|
|
|
|
|
|
|
|
rv = bladerf_get_devinfo_from_str(device_name.c_str(), &devinfo);
|
|
|
|
if (rv < 0)
|
|
|
|
throw std::runtime_error(std::string(__FUNCTION__) + " " +
|
|
|
|
"Failed to get devinfo for '" + device_name + "'");
|
|
|
|
|
|
|
|
bladerf_sptr cached_dev = get_cached_device(devinfo);
|
|
|
|
|
|
|
|
if (cached_dev)
|
|
|
|
return cached_dev;
|
|
|
|
|
|
|
|
rv = bladerf_open_with_devinfo(&raw_dev, &devinfo);
|
|
|
|
if (rv < 0)
|
|
|
|
throw std::runtime_error(std::string(__FUNCTION__) + " " +
|
|
|
|
"Failed to open device for '" + device_name + "'");
|
|
|
|
|
|
|
|
bladerf_sptr dev = bladerf_sptr(raw_dev, bladerf_common::close);
|
|
|
|
|
|
|
|
_devs.push_back(boost::weak_ptr<struct bladerf>(dev));
|
|
|
|
|
|
|
|
return dev;
|
|
|
|
}
|
|
|
|
|
bladerf: Added 'verbosity' and 'loopback' device parameters
The 'verbosity' parameter may be used to increase or suppress output from
libbladeRF. The available log levels are, in order of decreasing
verbosity are:
verbose, debug, info, warning, critical, silent
The 'loopback' parameter may be used to put the bladeRF into one of the
supported loopback modes. The valid modes are listed below. Their
descriptions may be found in the libbladeRF documentation:
bb_txlpf_rxvga2, bb_txlpf_rxlpf bb_txvga1_rxvga2, bb_txvga1_rxlpf
rf_lna1, rf_lna2, rf_lna3
2014-02-13 20:59:44 +00:00
|
|
|
void bladerf_common::set_loopback_mode(const std::string &loopback)
|
|
|
|
{
|
|
|
|
bladerf_loopback mode;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
if (loopback == "bb_txlpf_rxvga2") {
|
|
|
|
mode = BLADERF_LB_BB_TXLPF_RXVGA2;
|
|
|
|
} else if (loopback == "bb_txlpf_rxlpf") {
|
|
|
|
mode = BLADERF_LB_BB_TXLPF_RXLPF;
|
|
|
|
} else if (loopback == "bb_txvga1_rxvga2") {
|
|
|
|
mode = BLADERF_LB_BB_TXVGA1_RXVGA2;
|
|
|
|
} else if (loopback == "bb_txvga1_rxlpf") {
|
|
|
|
mode = BLADERF_LB_BB_TXVGA1_RXLPF;
|
|
|
|
} else if (loopback == "rf_lna1") {
|
|
|
|
mode = BLADERF_LB_RF_LNA1;
|
|
|
|
} else if (loopback == "rf_lna2") {
|
|
|
|
mode = BLADERF_LB_RF_LNA2;
|
|
|
|
} else if (loopback == "rf_lna3") {
|
|
|
|
mode = BLADERF_LB_RF_LNA3;
|
|
|
|
} else if (loopback == "none") {
|
|
|
|
mode = BLADERF_LB_NONE;
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error( _pfx + "Invalid loopback mode:" + loopback );
|
|
|
|
}
|
|
|
|
|
|
|
|
status = bladerf_set_loopback( _dev.get(), mode);
|
|
|
|
if ( status != 0 ) {
|
|
|
|
throw std::runtime_error( _pfx + "Failed to set loopback mode: " +
|
|
|
|
bladerf_strerror(status) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void bladerf_common::set_verbosity(const std::string &verbosity)
|
|
|
|
{
|
|
|
|
bladerf_log_level l;
|
|
|
|
|
|
|
|
if (verbosity == "verbose") {
|
|
|
|
l = BLADERF_LOG_LEVEL_VERBOSE;
|
|
|
|
} else if (verbosity == "debug") {
|
|
|
|
l = BLADERF_LOG_LEVEL_DEBUG;
|
|
|
|
} else if (verbosity == "info") {
|
|
|
|
l = BLADERF_LOG_LEVEL_INFO;
|
|
|
|
} else if (verbosity == "warning") {
|
|
|
|
l = BLADERF_LOG_LEVEL_WARNING;
|
|
|
|
} else if (verbosity == "error") {
|
|
|
|
l = BLADERF_LOG_LEVEL_ERROR;
|
|
|
|
} else if (verbosity == "critical") {
|
|
|
|
l = BLADERF_LOG_LEVEL_CRITICAL;
|
|
|
|
} else if (verbosity == "silent") {
|
|
|
|
l = BLADERF_LOG_LEVEL_SILENT;
|
|
|
|
} else {
|
|
|
|
throw std::runtime_error( _pfx + "Invalid log level: " + verbosity );
|
|
|
|
}
|
|
|
|
|
|
|
|
bladerf_log_set_verbosity(l);
|
|
|
|
}
|
|
|
|
|
2014-02-16 22:42:32 +00:00
|
|
|
bool bladerf_common::start(bladerf_module module)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = bladerf_sync_config(_dev.get(), module, BLADERF_FORMAT_SC16_Q11,
|
|
|
|
_num_buffers, _samples_per_buffer,
|
|
|
|
_num_transfers, _stream_timeout_ms);
|
|
|
|
|
|
|
|
if ( ret != 0 ) {
|
|
|
|
std::cerr << _pfx << "bladerf_sync_config failed: "
|
|
|
|
<< bladerf_strerror(ret) << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
ret = bladerf_enable_module(_dev.get(), module, true);
|
|
|
|
if ( ret != 0 ) {
|
|
|
|
std::cerr << _pfx << "bladerf_enable_module failed: "
|
|
|
|
<< bladerf_strerror(ret) << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool bladerf_common::stop(bladerf_module module)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = bladerf_enable_module(_dev.get(), module, false);
|
|
|
|
|
|
|
|
if ( ret != 0 ) {
|
|
|
|
std::cerr << _pfx << "bladerf_enable_modue failed: "
|
|
|
|
<< bladerf_strerror(ret) << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void bladerf_common::init(dict_t &dict, bladerf_module module)
|
2013-10-26 19:59:23 +00:00
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
unsigned int device_number = 0;
|
|
|
|
std::string device_name;
|
|
|
|
struct bladerf_version ver;
|
|
|
|
char serial[BLADERF_SERIAL_LENGTH];
|
2014-02-16 22:42:32 +00:00
|
|
|
const char *type = (module == BLADERF_MODULE_TX ? "sink" : "source");
|
2013-10-26 19:59:23 +00:00
|
|
|
|
|
|
|
_pfx = std::string("[bladeRF ") + std::string(type) + std::string("] ");
|
|
|
|
|
|
|
|
if (dict.count("bladerf"))
|
|
|
|
{
|
|
|
|
std::string value = dict["bladerf"];
|
|
|
|
if ( value.length() )
|
|
|
|
{
|
|
|
|
try {
|
|
|
|
device_number = boost::lexical_cast< unsigned int >( value );
|
|
|
|
} catch ( std::exception &ex ) {
|
|
|
|
throw std::runtime_error( _pfx + "Failed to use '" + value +
|
|
|
|
"' as device number: " + ex.what());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
device_name = boost::str(boost::format( "libusb:instance=%d" ) % device_number);
|
|
|
|
|
|
|
|
try {
|
|
|
|
_dev = open(device_name);
|
|
|
|
} catch(...) {
|
|
|
|
throw std::runtime_error( _pfx + "Failed to open bladeRF device " +
|
|
|
|
device_name );
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load an FPGA */
|
|
|
|
if ( dict.count("fpga") )
|
|
|
|
{
|
2013-10-26 20:26:16 +00:00
|
|
|
|
|
|
|
if ( dict.count("fpga-reload") == 0 &&
|
|
|
|
bladerf_is_fpga_configured( _dev.get() ) == 1 ) {
|
|
|
|
|
|
|
|
std::cerr << _pfx << "FPGA is already loaded. Set fpga-reload=1 "
|
|
|
|
<< "to force a reload." << std::endl;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
std::string fpga = dict["fpga"];
|
|
|
|
|
|
|
|
std::cerr << _pfx << "Loading FPGA bitstream " << fpga << "..." << std::endl;
|
|
|
|
ret = bladerf_load_fpga( _dev.get(), fpga.c_str() );
|
|
|
|
if ( ret != 0 )
|
|
|
|
std::cerr << _pfx << "bladerf_load_fpga has failed with " << ret << std::endl;
|
|
|
|
else
|
|
|
|
std::cerr << _pfx << "The FPGA bitstream has been successfully loaded." << std::endl;
|
|
|
|
}
|
2013-10-26 19:59:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( bladerf_is_fpga_configured( _dev.get() ) != 1 )
|
|
|
|
{
|
|
|
|
std::ostringstream oss;
|
|
|
|
oss << _pfx << "The FPGA is not configured! "
|
|
|
|
<< "Provide device argument fpga=/path/to/the/bitstream.rbf to load it.";
|
|
|
|
|
|
|
|
throw std::runtime_error( oss.str() );
|
|
|
|
}
|
|
|
|
|
bladerf: Added 'verbosity' and 'loopback' device parameters
The 'verbosity' parameter may be used to increase or suppress output from
libbladeRF. The available log levels are, in order of decreasing
verbosity are:
verbose, debug, info, warning, critical, silent
The 'loopback' parameter may be used to put the bladeRF into one of the
supported loopback modes. The valid modes are listed below. Their
descriptions may be found in the libbladeRF documentation:
bb_txlpf_rxvga2, bb_txlpf_rxlpf bb_txvga1_rxvga2, bb_txvga1_rxlpf
rf_lna1, rf_lna2, rf_lna3
2014-02-13 20:59:44 +00:00
|
|
|
if ( dict.count("loopback") )
|
|
|
|
set_loopback_mode( dict["loopback"] );
|
|
|
|
else
|
|
|
|
set_loopback_mode( "none" );
|
|
|
|
|
|
|
|
if ( dict.count("verbosity") )
|
|
|
|
set_verbosity( dict["verbosity"] );
|
|
|
|
|
2013-10-26 19:59:23 +00:00
|
|
|
|
|
|
|
/* Show some info about the device we've opened */
|
|
|
|
std::cerr << _pfx << "Using nuand LLC bladeRF #" << device_number;
|
|
|
|
|
|
|
|
if ( bladerf_get_serial( _dev.get(), serial ) == 0 )
|
2014-01-11 08:03:28 +00:00
|
|
|
{
|
|
|
|
std::string strser(serial);
|
|
|
|
|
|
|
|
if ( strser.length() == 32 )
|
|
|
|
strser.replace( 4, 24, "..." );
|
|
|
|
|
|
|
|
std::cerr << " SN " << strser;
|
|
|
|
}
|
2013-10-26 19:59:23 +00:00
|
|
|
|
|
|
|
if ( bladerf_fw_version( _dev.get(), &ver ) == 0 )
|
|
|
|
std::cerr << " FW v" << ver.major << "." << ver.minor << "." << ver.patch;
|
|
|
|
|
|
|
|
if ( bladerf_fpga_version( _dev.get(), &ver ) == 0 )
|
|
|
|
std::cerr << " FPGA v" << ver.major << "." << ver.minor << "." << ver.patch;
|
|
|
|
|
|
|
|
std::cerr << std::endl;
|
|
|
|
|
|
|
|
/* Initialize buffer and sample configuration */
|
|
|
|
_num_buffers = 0;
|
|
|
|
if (dict.count("buffers")) {
|
|
|
|
_num_buffers = boost::lexical_cast< size_t >( dict["buffers"] );
|
|
|
|
}
|
|
|
|
|
|
|
|
_samples_per_buffer = 0;
|
|
|
|
if (dict.count("buflen")) {
|
|
|
|
_samples_per_buffer = boost::lexical_cast< size_t >( dict["buflen"] );
|
|
|
|
}
|
|
|
|
|
|
|
|
_num_transfers = 0;
|
|
|
|
if (dict.count("transfers")) {
|
|
|
|
_num_transfers = boost::lexical_cast< size_t >( dict["transfers"] );
|
|
|
|
}
|
|
|
|
|
2014-02-16 22:42:32 +00:00
|
|
|
_stream_timeout_ms = 3000;
|
|
|
|
if (dict.count("stream_timeout_ms")) {
|
|
|
|
_stream_timeout_ms = boost::lexical_cast< unsigned int >(dict["stream_timout_ms"] );
|
|
|
|
}
|
|
|
|
|
2013-10-26 19:59:23 +00:00
|
|
|
/* Require value to be >= 2 so we can ensure we have twice as many
|
|
|
|
* buffers as transfers */
|
|
|
|
if (_num_buffers <= 1) {
|
|
|
|
_num_buffers = NUM_BUFFERS;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 == _samples_per_buffer) {
|
|
|
|
_samples_per_buffer = NUM_SAMPLES_PER_BUFFER;
|
|
|
|
} else {
|
|
|
|
if (_samples_per_buffer < 1024 || _samples_per_buffer % 1024 != 0) {
|
|
|
|
|
|
|
|
/* 0 likely implies the user did not specify this, so don't warn */
|
|
|
|
if (_samples_per_buffer != 0 ) {
|
|
|
|
std::cerr << _pfx << "Invalid \"buflen\" value. "
|
|
|
|
<< "A multiple of 1024 is required. Defaulting to "
|
|
|
|
<< NUM_SAMPLES_PER_BUFFER << std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
_samples_per_buffer = NUM_SAMPLES_PER_BUFFER;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_num_transfers == 0 || _num_transfers > (_num_buffers / 2)) {
|
|
|
|
_num_transfers = _num_buffers / 2;
|
|
|
|
}
|
2014-02-16 22:42:32 +00:00
|
|
|
|
|
|
|
_conv_buf = static_cast<int16_t*>(malloc(_conv_buf_size * 2 * sizeof(int16_t)));
|
|
|
|
|
|
|
|
if (_conv_buf == NULL) {
|
|
|
|
throw std::runtime_error( std::string(__FUNCTION__) +
|
|
|
|
"Failed to allocate _conv_buf" );
|
|
|
|
}
|
2013-10-26 19:59:23 +00:00
|
|
|
}
|
|
|
|
|
2013-07-20 16:14:20 +00:00
|
|
|
osmosdr::freq_range_t bladerf_common::freq_range()
|
|
|
|
{
|
|
|
|
/* assuming the same for RX & TX */
|
|
|
|
return osmosdr::freq_range_t( 300e6, 3.8e9 );
|
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::meta_range_t bladerf_common::sample_rates()
|
|
|
|
{
|
2013-07-28 14:35:48 +00:00
|
|
|
osmosdr::meta_range_t sample_rates;
|
|
|
|
|
2013-07-20 16:14:20 +00:00
|
|
|
/* assuming the same for RX & TX */
|
2013-07-28 14:35:48 +00:00
|
|
|
sample_rates += osmosdr::range_t( 160e3, 200e3, 40e3 );
|
|
|
|
sample_rates += osmosdr::range_t( 300e3, 900e3, 100e3 );
|
|
|
|
sample_rates += osmosdr::range_t( 1e6, 40e6, 1e6 );
|
|
|
|
|
|
|
|
return sample_rates;
|
2013-07-20 16:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::freq_range_t bladerf_common::filter_bandwidths()
|
|
|
|
{
|
|
|
|
/* the same for RX & TX according to the datasheet */
|
|
|
|
osmosdr::freq_range_t bandwidths;
|
|
|
|
|
2013-07-28 14:35:48 +00:00
|
|
|
std::vector<double> half_bandwidths; /* in MHz */
|
2013-07-20 16:14:20 +00:00
|
|
|
half_bandwidths += \
|
|
|
|
0.75, 0.875, 1.25, 1.375, 1.5, 1.92, 2.5,
|
|
|
|
2.75, 3, 3.5, 4.375, 5, 6, 7, 10, 14;
|
|
|
|
|
2013-07-28 14:35:48 +00:00
|
|
|
BOOST_FOREACH( double half_bw, half_bandwidths )
|
2013-09-20 19:41:15 +00:00
|
|
|
bandwidths += osmosdr::range_t( half_bw * 2e6 );
|
2013-07-20 16:14:20 +00:00
|
|
|
|
|
|
|
return bandwidths;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< std::string > bladerf_common::devices()
|
|
|
|
{
|
2013-08-27 20:37:08 +00:00
|
|
|
struct bladerf_devinfo *devices;
|
2013-07-20 16:14:20 +00:00
|
|
|
ssize_t n_devices;
|
|
|
|
std::vector< std::string > ret;
|
|
|
|
|
|
|
|
n_devices = bladerf_get_device_list(&devices);
|
|
|
|
|
2013-09-20 19:41:15 +00:00
|
|
|
if (n_devices > 0)
|
|
|
|
{
|
|
|
|
for (ssize_t i = 0; i < n_devices; i++)
|
|
|
|
{
|
2013-07-20 16:14:20 +00:00
|
|
|
std::stringstream s;
|
2013-08-27 20:37:08 +00:00
|
|
|
std::string serial(devices[i].serial);
|
2013-07-20 16:14:20 +00:00
|
|
|
|
2013-08-27 20:37:08 +00:00
|
|
|
s << "bladerf=" << devices[i].instance << ","
|
|
|
|
<< "label='nuand bladeRF";
|
|
|
|
|
2014-01-11 08:03:28 +00:00
|
|
|
if ( serial.length() == 32 )
|
|
|
|
serial.replace( 4, 24, "..." );
|
|
|
|
|
2013-08-27 20:37:08 +00:00
|
|
|
if ( serial.length() )
|
|
|
|
s << " SN " << serial;
|
|
|
|
|
|
|
|
s << "'";
|
2013-07-20 16:14:20 +00:00
|
|
|
|
|
|
|
ret.push_back(s.str());
|
|
|
|
}
|
|
|
|
|
2013-08-27 20:37:08 +00:00
|
|
|
bladerf_free_device_list(devices);
|
2013-07-20 16:14:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-01-12 19:25:14 +00:00
|
|
|
double bladerf_common::set_sample_rate( bladerf_module module, double rate )
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
struct bladerf_rational_rate rational_rate, actual;
|
|
|
|
|
|
|
|
rational_rate.integer = (uint32_t)rate;
|
|
|
|
rational_rate.den = 10000;
|
|
|
|
rational_rate.num = (rate - rational_rate.integer) * rational_rate.den;
|
|
|
|
|
|
|
|
status = bladerf_set_rational_sample_rate( _dev.get(), module,
|
|
|
|
&rational_rate, &actual );
|
|
|
|
|
|
|
|
if ( status != 0 ) {
|
|
|
|
throw std::runtime_error( std::string(__FUNCTION__) + " " +
|
|
|
|
"Failed to set integer rate:" +
|
|
|
|
std::string(bladerf_strerror(status)));
|
|
|
|
}
|
|
|
|
|
|
|
|
return actual.integer + actual.num / (double)actual.den;
|
|
|
|
}
|
|
|
|
|
|
|
|
double bladerf_common::get_sample_rate( bladerf_module module )
|
|
|
|
{
|
|
|
|
int status;
|
|
|
|
double ret = 0.0;
|
|
|
|
struct bladerf_rational_rate rate;
|
|
|
|
|
|
|
|
|
|
|
|
status = bladerf_get_rational_sample_rate( _dev.get(), module, &rate );
|
|
|
|
|
|
|
|
if ( status != 0 ) {
|
|
|
|
throw std::runtime_error( std::string(__FUNCTION__) +
|
|
|
|
"Failed to get sample rate:" +
|
|
|
|
std::string(bladerf_strerror(status)) );
|
|
|
|
} else {
|
|
|
|
ret = rate.integer + rate.num / (double)rate.den;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
2014-01-18 19:12:02 +00:00
|
|
|
|
|
|
|
int bladerf_common::set_dc_offset(bladerf_module module, const std::complex<double> &offset, size_t chan)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int16_t val_i, val_q;
|
|
|
|
|
|
|
|
val_i = (int16_t)(offset.real() * DCOFF_SCALE);
|
|
|
|
val_q = (int16_t)(offset.imag() * DCOFF_SCALE);
|
|
|
|
|
|
|
|
ret = bladerf_set_correction(_dev.get(), module, BLADERF_CORR_LMS_DCOFF_I, val_i);
|
|
|
|
ret |= bladerf_set_correction(_dev.get(), module, BLADERF_CORR_LMS_DCOFF_Q, val_q);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
int bladerf_common::set_iq_balance(bladerf_module module, const std::complex<double> &balance, size_t chan)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
int16_t val_gain, val_phase;
|
|
|
|
|
|
|
|
val_gain = (int16_t)(balance.real() * GAIN_SCALE);
|
|
|
|
val_phase = (int16_t)(balance.imag() * PHASE_SCALE);
|
|
|
|
|
|
|
|
ret = bladerf_set_correction(_dev.get(), module, BLADERF_CORR_FPGA_GAIN, val_gain);
|
|
|
|
ret |= bladerf_set_correction(_dev.get(), module, BLADERF_CORR_FPGA_PHASE, val_phase);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|