diff --git a/cmake/Modules/FindLibbladeRF.cmake b/cmake/Modules/FindLibbladeRF.cmake index 0971344..fc67082 100644 --- a/cmake/Modules/FindLibbladeRF.cmake +++ b/cmake/Modules/FindLibbladeRF.cmake @@ -1,5 +1,9 @@ if(NOT LIBBLADERF_FOUND) pkg_check_modules (LIBBLADERF_PKG libbladeRF) + if (LIBBLADERF_PKG_FOUND AND LIBBLADERF_PKG_VERSION VERSION_LESS "2") + message( FATAL_ERROR "Install version 2 or greater of libbladeRF." + " Current version ( ${LIBBLADERF_PKG_VERSION} ) is out of date." ) + endif() find_path(LIBBLADERF_INCLUDE_DIRS NAMES libbladeRF.h PATHS ${LIBBLADERF_PKG_INCLUDE_DIRS} diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt index c7cfec3..4408fc9 100644 --- a/lib/CMakeLists.txt +++ b/lib/CMakeLists.txt @@ -34,6 +34,8 @@ list(APPEND gr_osmosdr_srcs time_spec.cc ) +set(CMAKE_CXX_STANDARD 11) + #-pthread Adds support for multithreading with the pthreads library. #This option sets flags for both the preprocessor and linker. (man gcc) if(CMAKE_COMPILER_IS_GNUCXX) diff --git a/lib/arg_helpers.h b/lib/arg_helpers.h index 3b02b8f..bef1d74 100644 --- a/lib/arg_helpers.h +++ b/lib/arg_helpers.h @@ -153,6 +153,8 @@ inline gr::io_signature::sptr args_to_io_signature( const std::string &args ) } } + if (arg_list.size() <= 2 && max_nchan > dev_nchan) + dev_nchan = max_nchan; // if at least one nchan was given, perform a sanity check if ( max_nchan && dev_nchan && max_nchan != dev_nchan ) throw std::runtime_error("Wrong device arguments specified. Missing nchan?"); diff --git a/lib/bladerf/bladerf_common.cc b/lib/bladerf/bladerf_common.cc index 67bf736..0548027 100644 --- a/lib/bladerf/bladerf_common.cc +++ b/lib/bladerf/bladerf_common.cc @@ -49,7 +49,7 @@ static size_t const STREAM_TIMEOUT_MS = 3000; using namespace boost::assign; std::mutex bladerf_common::_devs_mutex; -std::list> bladerf_common::_devs; +std::list > bladerf_common::_devs; /* name for system-wide gain (which is not its own libbladeRF gain stage) */ static const char *SYSTEM_GAIN_NAME = "system"; @@ -133,7 +133,7 @@ size_t num_streams(bladerf_channel_layout layout) * Public methods ******************************************************************************/ bladerf_common::bladerf_common() : - _dev(NULL), + _dev(std::shared_ptr()), _pfx("[bladeRF common] "), _failures(0), _num_buffers(NUM_BUFFERS), @@ -1107,7 +1107,7 @@ bladerf_sptr bladerf_common::open(std::string const &device_name) /* Add the device handle to our cache */ bladerf_sptr dev = bladerf_sptr(raw_dev, bladerf_common::close); - _devs.push_back(static_cast>(dev)); + _devs.push_back(static_cast >(dev)); return dev; } @@ -1115,7 +1115,7 @@ bladerf_sptr bladerf_common::open(std::string const &device_name) void bladerf_common::close(void *dev) { std::lock_guard lock(_devs_mutex); - std::list>::iterator it(_devs.begin()); + std::list >::iterator it(_devs.begin()); /* Prune expired entries from device cache */ while (it != _devs.end()) { diff --git a/lib/bladerf/bladerf_common.h b/lib/bladerf/bladerf_common.h index 741b1e7..32e8101 100644 --- a/lib/bladerf/bladerf_common.h +++ b/lib/bladerf/bladerf_common.h @@ -287,7 +287,7 @@ class bladerf_common * Private members ****************************************************************************/ static std::mutex _devs_mutex; /**< mutex for access to _devs */ - static std::list> _devs; /**< dev cache */ + static std::list > _devs; /**< dev cache */ }; #endif diff --git a/lib/bladerf/bladerf_compat.h b/lib/bladerf/bladerf_compat.h index 2ad24be..45e6a16 100644 --- a/lib/bladerf/bladerf_compat.h +++ b/lib/bladerf/bladerf_compat.h @@ -66,7 +66,7 @@ } /* Changed enums/defines */ - #define BLADERF_GAIN_DEFAULT BLADERF_GAIN_AUTOMATIC + #define BLADERF_GAIN_DEFAULT BLADERF_GAIN_MANUAL #define BLADERF_GAIN_MGC BLADERF_GAIN_MANUAL #define BLADERF_RX_MUX_BASEBAND BLADERF_RX_MUX_BASEBAND_LMS diff --git a/lib/bladerf/bladerf_sink_c.cc b/lib/bladerf/bladerf_sink_c.cc index 6ee3acd..ad09d2a 100644 --- a/lib/bladerf/bladerf_sink_c.cc +++ b/lib/bladerf/bladerf_sink_c.cc @@ -174,11 +174,9 @@ bool bladerf_sink_c::start() for (size_t ch = 0; ch < get_max_channels(); ++ch) { bladerf_channel brfch = BLADERF_CHANNEL_TX(ch); - if (get_channel_enable(brfch)) { - status = bladerf_enable_module(_dev.get(), brfch, true); - if (status != 0) { - BLADERF_THROW_STATUS(status, "bladerf_enable_module failed"); - } + status = bladerf_enable_module(_dev.get(), brfch, get_channel_enable(brfch)); + if (status != 0) { + BLADERF_THROW_STATUS(status, "bladerf_enable_module failed"); } } @@ -210,11 +208,9 @@ bool bladerf_sink_c::stop() for (size_t ch = 0; ch < get_max_channels(); ++ch) { bladerf_channel brfch = BLADERF_CHANNEL_TX(ch); - if (get_channel_enable(brfch)) { - status = bladerf_enable_module(_dev.get(), brfch, false); - if (status != 0) { - BLADERF_THROW_STATUS(status, "bladerf_enable_module failed"); - } + status = bladerf_enable_module(_dev.get(), brfch, get_channel_enable(brfch)); + if (status != 0) { + BLADERF_THROW_STATUS(status, "bladerf_enable_module failed"); } } @@ -241,6 +237,11 @@ int bladerf_sink_c::work(int noutput_items, return 0; } + noutput_items &= ~(3ULL); + if (!noutput_items) { + return 0; + } + // copy the samples from input_items gr_complex const **in = reinterpret_cast(&input_items[0]); diff --git a/lib/bladerf/bladerf_source_c.cc b/lib/bladerf/bladerf_source_c.cc index 83db677..16cfcac 100644 --- a/lib/bladerf/bladerf_source_c.cc +++ b/lib/bladerf/bladerf_source_c.cc @@ -230,11 +230,9 @@ bool bladerf_source_c::start() for (size_t ch = 0; ch < get_max_channels(); ++ch) { bladerf_channel brfch = BLADERF_CHANNEL_RX(ch); - if (get_channel_enable(brfch)) { - status = bladerf_enable_module(_dev.get(), brfch, true); - if (status != 0) { - BLADERF_THROW_STATUS(status, "bladerf_enable_module failed"); - } + status = bladerf_enable_module(_dev.get(), brfch, get_channel_enable(brfch)); + if (status != 0) { + BLADERF_THROW_STATUS(status, "bladerf_enable_module failed"); } } @@ -344,7 +342,7 @@ int bladerf_source_c::work(int noutput_items, memcpy(out[0], _32fcbuf, sizeof(gr_complex) * noutput_items); } - return noutput_items; + return noutput_items/(get_num_channels()); } osmosdr::meta_range_t bladerf_source_c::get_sample_rates() diff --git a/lib/sink_impl.cc b/lib/sink_impl.cc index 317855a..55d67c6 100644 --- a/lib/sink_impl.cc +++ b/lib/sink_impl.cc @@ -30,6 +30,8 @@ #include #include +#include + #ifdef ENABLE_UHD #include "uhd_sink_c.h" #endif @@ -245,6 +247,13 @@ sink_impl::sink_impl( const std::string &args ) if (!_devs.size()) throw std::runtime_error("No devices specified via device arguments."); + + /* Populate the _gain and _gain_mode arrays with the hardware state */ + BOOST_FOREACH( sink_iface *dev, _devs ) + for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++) { + _gain_mode[dev_chan] = dev->get_gain_mode(dev_chan); + _gain[dev_chan] = dev->get_gain(dev_chan); + } } size_t sink_impl::get_num_channels() diff --git a/lib/source_impl.cc b/lib/source_impl.cc index 8f2028b..46fb0e0 100644 --- a/lib/source_impl.cc +++ b/lib/source_impl.cc @@ -32,6 +32,8 @@ #include #include +#include + #ifdef ENABLE_FCD #include #endif @@ -191,6 +193,19 @@ source_impl::source_impl( const std::string &args ) } } + bool force_arg = false; + int force_val = 0; + + if (arg_list.size() <= 2) { + BOOST_FOREACH(std::string arg, arg_list) { + if ( arg.find( "numchan=" ) == 0 ) { + pair_t pair = param_to_pair( arg ); + force_arg = true; + force_val = boost::lexical_cast( pair.second ); + } + } + } + if ( ! device_specified ) { std::vector< std::string > dev_list; #ifdef ENABLE_FCD @@ -258,6 +273,9 @@ source_impl::source_impl( const std::string &args ) for (std::string arg : arg_list) { + if(force_arg) + arg += ",nchan=" + std::to_string(force_val); + dict_t dict = params_to_dict(arg); // std::cerr << std::endl; @@ -403,6 +421,13 @@ source_impl::source_impl( const std::string &args ) if (!_devs.size()) throw std::runtime_error("No devices specified via device arguments."); + + /* Populate the _gain and _gain_mode arrays with the hardware state */ + BOOST_FOREACH( source_iface *dev, _devs ) + for (size_t dev_chan = 0; dev_chan < dev->get_num_channels(); dev_chan++) { + _gain_mode[dev_chan] = dev->get_gain_mode(dev_chan); + _gain[dev_chan] = dev->get_gain(dev_chan); + } } size_t source_impl::get_num_channels()