Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add includes for <boost/foreach.hpp>. Resolves PR #5. #6

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 4 additions & 0 deletions cmake/Modules/FindLibbladeRF.cmake
Original file line number Diff line number Diff line change
@@ -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}
Expand Down
2 changes: 2 additions & 0 deletions lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions lib/arg_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -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?");
Expand Down
8 changes: 4 additions & 4 deletions lib/bladerf/bladerf_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ static size_t const STREAM_TIMEOUT_MS = 3000;
using namespace boost::assign;

std::mutex bladerf_common::_devs_mutex;
std::list<std::weak_ptr<struct bladerf>> bladerf_common::_devs;
std::list<std::weak_ptr<struct bladerf> > bladerf_common::_devs;

/* name for system-wide gain (which is not its own libbladeRF gain stage) */
static const char *SYSTEM_GAIN_NAME = "system";
Expand Down Expand Up @@ -133,7 +133,7 @@ size_t num_streams(bladerf_channel_layout layout)
* Public methods
******************************************************************************/
bladerf_common::bladerf_common() :
_dev(NULL),
_dev(std::shared_ptr<struct bladerf>()),
_pfx("[bladeRF common] "),
_failures(0),
_num_buffers(NUM_BUFFERS),
Expand Down Expand Up @@ -1107,15 +1107,15 @@ 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<std::weak_ptr<struct bladerf>>(dev));
_devs.push_back(static_cast<std::weak_ptr<struct bladerf> >(dev));

return dev;
}

void bladerf_common::close(void *dev)
{
std::lock_guard<std::mutex> lock(_devs_mutex);
std::list<std::weak_ptr<struct bladerf>>::iterator it(_devs.begin());
std::list<std::weak_ptr<struct bladerf> >::iterator it(_devs.begin());

/* Prune expired entries from device cache */
while (it != _devs.end()) {
Expand Down
2 changes: 1 addition & 1 deletion lib/bladerf/bladerf_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ class bladerf_common
* Private members
****************************************************************************/
static std::mutex _devs_mutex; /**< mutex for access to _devs */
static std::list<std::weak_ptr<struct bladerf>> _devs; /**< dev cache */
static std::list<std::weak_ptr<struct bladerf> > _devs; /**< dev cache */
};

#endif
2 changes: 1 addition & 1 deletion lib/bladerf/bladerf_compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 11 additions & 10 deletions lib/bladerf/bladerf_sink_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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");
}
}

Expand All @@ -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<gr_complex const **>(&input_items[0]);

Expand Down
10 changes: 4 additions & 6 deletions lib/bladerf/bladerf_source_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}

Expand Down Expand Up @@ -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()
Expand Down
9 changes: 9 additions & 0 deletions lib/sink_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include <gnuradio/io_signature.h>
#include <gnuradio/constants.h>

#include <boost/foreach.hpp>

#ifdef ENABLE_UHD
#include "uhd_sink_c.h"
#endif
Expand Down Expand Up @@ -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()
Expand Down
25 changes: 25 additions & 0 deletions lib/source_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
#include <gnuradio/blocks/throttle.h>
#include <gnuradio/constants.h>

#include <boost/foreach.hpp>

#ifdef ENABLE_FCD
#include <fcd_source_c.h>
#endif
Expand Down Expand Up @@ -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<size_t>( pair.second );
}
}
}

if ( ! device_specified ) {
std::vector< std::string > dev_list;
#ifdef ENABLE_FCD
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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()
Expand Down