bladerf: formatting/consistency fixes

This commit is contained in:
Ryan Tucker 2017-06-28 14:03:29 -04:00 committed by Dimitri Stolnikov
parent ed4dda192b
commit 399db91385
3 changed files with 643 additions and 600 deletions

View File

@ -76,7 +76,8 @@ bladerf_board_type bladerf_common::get_board_type( struct bladerf *dev )
return BLADERF_REV_2;
}
std::cerr << _pfx << "board name \"" << boardname << "\" unknown"
std::cerr << _pfx
<< "board name \"" << boardname << "\" unknown"
<< std::endl;
return BLADERF_REV_INVALID;
}
@ -84,8 +85,7 @@ bladerf_board_type bladerf_common::get_board_type( struct bladerf *dev )
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 )
{
BOOST_FOREACH(boost::weak_ptr < struct bladerf >dev, _devs) {
int status;
struct bladerf_devinfo other_devinfo;
@ -229,7 +229,11 @@ bool bladerf_common::start( bladerf_direction direction )
bladerf_format format;
bladerf_channel_layout layout;
format = _use_metadata ? BLADERF_FORMAT_SC16_Q11_META : BLADERF_FORMAT_SC16_Q11;
if (_use_metadata) {
format = BLADERF_FORMAT_SC16_Q11_META;
} else {
format = BLADERF_FORMAT_SC16_Q11;
}
switch (direction) {
case BLADERF_RX:
@ -274,8 +278,8 @@ bool bladerf_common::stop( bladerf_direction direction )
}
static bool version_greater_or_equal(const struct bladerf_version *version,
unsigned int major, unsigned int minor,
unsigned int patch )
unsigned int major,
unsigned int minor, unsigned int patch)
{
if (version->major > major) {
return true;
@ -347,7 +351,8 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
try {
std::cerr << _pfx
<< "Opening nuand bladeRF with device identifier string: \""
<< device_name << "\"" << std::endl;
<< device_name << "\""
<< std::endl;
_dev = open(device_name);
} catch (...) {
@ -362,21 +367,24 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
std::cerr << _pfx
<< "FPGA is already loaded. Set fpga-reload=1 to force a "
"reload." << std::endl;
<< "reload."
<< std::endl;
} else {
std::string fpga = dict["fpga"];
std::cerr << _pfx << "Loading FPGA bitstream " << fpga << "..."
std::cerr << _pfx
<< "Loading FPGA bitstream " << fpga << "..."
<< std::endl;
status = bladerf_load_fpga(_dev.get(), fpga.c_str());
if (status != 0) {
std::cerr << _pfx << "bladerf_load_fpga has failed with "
<< bladerf_strerror(status) << std::endl;
std::cerr << _pfx
<< "bladerf_load_fpga has failed with "
<< bladerf_strerror(status)
<< std::endl;
} else {
std::cerr << _pfx << "The FPGA bitstream was successfully loaded."
std::cerr << _pfx
<< "The FPGA bitstream was successfully loaded."
<< std::endl;
}
}
@ -398,8 +406,8 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
} else if (direction == BLADERF_TX && dict.count("loopback")) {
std::cerr << _pfx
<< "Warning: 'loopback' has been specified on a bladeRF "
"sink, and will have no effect. This parameter should "
"be specified on the associated bladeRF source."
<< "sink, and will have no effect. This parameter should "
<< "be specified on the associated bladeRF source."
<< std::endl;
}
@ -429,14 +437,15 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
status = bladerf_xb200_set_filterbank(_dev.get(), direction, filter);
if (status != 0) {
std::cerr << _pfx << "Could not set XB-200 filter: "
<< bladerf_strerror(status) << std::endl;
std::cerr << _pfx
<< "Could not set XB-200 filter: "
<< bladerf_strerror(status)
<< std::endl;
}
}
}
/* Show some info about the device we've opened */
std::cerr << _pfx;
if (bladerf_get_serial(_dev.get(), serial) == 0) {
@ -461,12 +470,16 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
if (dict.count("tamer")) {
set_clock_source(dict["tamer"]);
std::cerr << _pfx << "Tamer mode set to '" << get_clock_source() << "'";
std::cerr << _pfx
<< "Tamer mode set to '" << get_clock_source() << "'"
<< std::endl;
}
if (dict.count("smb")) {
set_smb_frequency(boost::lexical_cast<double>(dict["smb"]));
std::cerr << _pfx << "SMB frequency set to " << get_smb_frequency() << " Hz";
std::cerr << _pfx
<< "SMB frequency set to " << get_smb_frequency() << " Hz"
<< std::endl;
}
/* Initialize buffer and sample configuration */
@ -492,7 +505,8 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
_use_metadata = dict.count("enable_metadata") != 0;
_use_mimo = ( dict.count("enable_mimo") != 0 ) && ( get_num_channels(direction) >= 2 );
_use_mimo = (dict.count("enable_mimo") != 0) &&
(get_num_channels(direction) >= 2);
/* Require value to be >= 2 so we can ensure we have twice as many
* buffers as transfers */
@ -503,13 +517,14 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
if (0 == _samples_per_buffer) {
_samples_per_buffer = NUM_SAMPLES_PER_BUFFER;
} else {
if ( (_samples_per_buffer < 1024) || ((_samples_per_buffer % 1024) != 0) ) {
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;
<< "required. Defaulting to " << NUM_SAMPLES_PER_BUFFER
<< std::endl;
}
_samples_per_buffer = NUM_SAMPLES_PER_BUFFER;
@ -524,12 +539,11 @@ void bladerf_common::init( dict_t &dict, bladerf_direction direction )
if (_num_transfers > 32) {
_num_transfers = 32;
}
} else if (_num_transfers >= _num_buffers) {
_num_transfers = _num_buffers - 1;
std::cerr << _pfx
<< "Clamping num_tranfers to " << _num_transfers << ". "
"Try using a smaller num_transfers value if timeouts occur."
<< "Try using a smaller num_transfers value if timeouts occur."
<< std::endl;
}
@ -547,7 +561,7 @@ osmosdr::freq_range_t bladerf_common::freq_range( bladerf_channel chan )
status = bladerf_get_frequency_range(_dev.get(), chan, &range);
if( status ) {
if (status != 0) {
throw std::runtime_error(_pfx +
"bladerf_get_frequency_range failed: " +
bladerf_strerror(status));
@ -567,7 +581,7 @@ osmosdr::meta_range_t bladerf_common::sample_rates()
/* assuming the same for RX & TX */
status = bladerf_get_sample_rate_range(_dev.get(), BLADERF_CHANNEL_RX(0),
&brf_sample_rates);
if( status ) {
if (status != 0) {
throw std::runtime_error(_pfx +
"bladerf_get_sample_rate_range failed: " +
bladerf_strerror(status));
@ -595,7 +609,7 @@ osmosdr::freq_range_t bladerf_common::filter_bandwidths()
status = bladerf_get_bandwidth_range(_dev.get(), BLADERF_CHANNEL_RX(0),
&range);
if( status ) {
if (status != 0) {
throw std::runtime_error(_pfx +
"bladerf_get_bandwidth_range failed: " +
bladerf_strerror(status));
@ -619,14 +633,15 @@ std::vector< std::string > bladerf_common::devices()
std::stringstream s;
std::string serial(devices[i].serial);
s << "bladerf=" << devices[i].instance
<< ",label='nuand bladeRF";
s << "bladerf=" << devices[i].instance << ",label='nuand bladeRF";
if ( serial.length() == 32 )
if (serial.length() == 32) {
serial.replace(4, 24, "...");
}
if ( serial.length() )
if (serial.length()) {
s << " SN " << serial;
}
s << "'";
@ -652,8 +667,7 @@ size_t bladerf_common::get_num_channels( bladerf_direction direction )
// return 1;
}
double bladerf_common::set_sample_rate( bladerf_direction direction,
double rate )
double bladerf_common::set_sample_rate(bladerf_direction direction, double rate)
{
int status;
struct bladerf_rational_rate rational_rate, actual;
@ -664,9 +678,8 @@ double bladerf_common::set_sample_rate( bladerf_direction direction,
status = bladerf_set_rational_sample_rate(_dev.get(), direction,
&rational_rate, &actual);
if ( status ) {
throw std::runtime_error( _pfx +
"Failed to set sample rate:" +
if (status != 0) {
throw std::runtime_error(_pfx + "Failed to set sample rate:" +
bladerf_strerror(status));
}
@ -680,8 +693,7 @@ double bladerf_common::get_sample_rate( bladerf_direction direction )
status = bladerf_get_rational_sample_rate(_dev.get(), direction, &rate);
if (status != 0) {
throw std::runtime_error( _pfx +
"Failed to get sample rate:" +
throw std::runtime_error(_pfx + "Failed to get sample rate:" +
bladerf_strerror(status));
}
@ -705,7 +717,7 @@ double bladerf_common::set_center_freq( double freq, size_t chan )
status = bladerf_set_frequency(_dev.get(),
static_cast<bladerf_channel>(chan),
static_cast<uint64_t>(freq));
if( status ) {
if (status != 0) {
throw std::runtime_error(_pfx +
"failed to set center frequency " +
boost::lexical_cast<std::string>(freq) + ": " +
@ -724,9 +736,8 @@ double bladerf_common::get_center_freq( size_t chan )
status = bladerf_get_frequency(_dev.get(),
static_cast<bladerf_channel>(chan),
&freq);
if( status ) {
throw std::runtime_error( _pfx +
"failed to get center frequency: " +
if (status != 0) {
throw std::runtime_error(_pfx + "failed to get center frequency: " +
bladerf_strerror(status));
}
@ -779,13 +790,14 @@ osmosdr::gain_range_t bladerf_common::get_gain_range( const std::string & name,
} else {
status = bladerf_get_gain_stage_range(_dev.get(),
static_cast<bladerf_channel>(chan),
name.c_str(), &range );
name.c_str(),
&range);
}
if( status ) {
if (status != 0) {
throw std::runtime_error(_pfx +
"bladerf_get_gain_range " + name + " failed: " +
bladerf_strerror(status) );
"bladerf_get_gain_range " + name +
" failed: " + bladerf_strerror(status));
}
return osmosdr::gain_range_t(range.min, range.max, range.step);
@ -800,12 +812,11 @@ bool bladerf_common::set_gain_mode( bool automatic, size_t chan )
static_cast<bladerf_channel>(chan),
mode);
if( status ) {
if (status != 0) {
throw std::runtime_error(_pfx +
"bladerf_set_gain_mode " +
(automatic ? "automatic" : "manual") +
" failed: " +
bladerf_strerror(status) );
" failed: " + bladerf_strerror(status));
}
return get_gain_mode(chan);
@ -820,9 +831,8 @@ bool bladerf_common::get_gain_mode( size_t chan )
static_cast<bladerf_channel>(chan),
&gainmode);
if( status ) {
throw std::runtime_error( _pfx +
"bladerf_get_gain_mode failed: " +
if (status != 0) {
throw std::runtime_error(_pfx + "bladerf_get_gain_mode failed: " +
bladerf_strerror(status));
}
@ -834,7 +844,8 @@ double bladerf_common::set_gain( double gain, size_t chan )
return set_gain(gain, SYSTEM_GAIN_NAME, chan);
}
double bladerf_common::set_gain( double gain, const std::string & name, size_t chan )
double bladerf_common::set_gain(double gain,
const std::string &name, size_t chan)
{
int status;
@ -850,7 +861,7 @@ double bladerf_common::set_gain( double gain, const std::string & name, size_t c
}
/* Check for errors */
if( status ) {
if (status != 0) {
std::string errmsg = _pfx + "could not set " + name + " gain: " +
bladerf_strerror(status);
if (BLADERF_ERR_UNSUPPORTED == status) {
@ -886,7 +897,7 @@ double bladerf_common::get_gain( const std::string & name, size_t chan )
}
/* Check for errors */
if( status ) {
if (status != 0) {
throw std::runtime_error(_pfx + "could not get " + name + " gain: " +
bladerf_strerror(status));
}
@ -999,7 +1010,8 @@ void bladerf_common::set_smb_frequency( double frequency )
}
if (static_cast<uint32_t>(frequency) != actual_frequency) {
std::cerr << _pfx << "Wanted SMB frequency is " << frequency
std::cerr << _pfx
<< "Wanted SMB frequency is " << frequency
<< ", actual is " << actual_frequency
<< std::endl;
}
@ -1011,9 +1023,10 @@ double bladerf_common::get_smb_frequency()
unsigned int actual_frequency;
status = bladerf_get_smb_frequency(_dev.get(), &actual_frequency);
if ( status != 0 )
if (status != 0) {
throw std::runtime_error(_pfx + "Failed to get SMB frequency: " +
bladerf_strerror(status));
}
return static_cast<double>(actual_frequency);
}

View File

@ -104,8 +104,8 @@ bool bladerf_sink_c::stop()
int bladerf_sink_c::transmit_with_tags(int noutput_items)
{
int status;
int count = 0;
int status = 0;
// For a long burst, we may be transmitting the burst contents over
// multiple work calls, so we'll just be sending the entire buffer
@ -138,12 +138,12 @@ int bladerf_sink_c::transmit_with_tags(int noutput_items)
static_cast < void *>(_conv_buf),
noutput_items, &meta, _stream_timeout_ms);
} else {
std::cerr << _pfx << "Dropping " << noutput_items
<< " samples not in a burst." << std::endl;
std::cerr << _pfx
<< "Dropping " << noutput_items << " samples not in a burst."
<< std::endl;
}
}
BOOST_FOREACH(gr::tag_t tag, tags) {
// Upon seeing an SOB tag, update our offset. We'll TX the start of the
@ -151,13 +151,14 @@ int bladerf_sink_c::transmit_with_tags(int noutput_items)
// occurs first.
if (pmt::symbol_to_string(tag.key) == "tx_sob") {
if (_in_burst) {
std::cerr << ("Got SOB while already within a burst");
std::cerr << ("Got SOB while already within a burst") << std::endl;
return BLADERF_ERR_INVAL;
} else {
start_idx = static_cast < int >(tag.offset - nitems_read(0));
DBG("Got SOB " << start_idx << " samples into work payload");
meta.flags |= (BLADERF_META_FLAG_TX_NOW | BLADERF_META_FLAG_TX_BURST_START);
meta.flags |=
(BLADERF_META_FLAG_TX_NOW | BLADERF_META_FLAG_TX_BURST_START);
_in_burst = true;
}
@ -166,7 +167,6 @@ int bladerf_sink_c::transmit_with_tags(int noutput_items)
std::cerr << _pfx << "Got EOB while not in burst" << std::endl;
return BLADERF_ERR_INVAL;
}
// Upon seeing an EOB, transmit what we have and reset our state
end_idx = static_cast < int >(tag.offset - nitems_read(0));
DBG("Got EOB " << end_idx << " samples into work payload");
@ -202,7 +202,6 @@ int bladerf_sink_c::transmit_with_tags(int noutput_items)
static_cast < void *>(zeros),
4, &meta, _stream_timeout_ms);
/* Reset our state */
start_idx = INVALID_IDX;
end_idx = (noutput_items - 1);
@ -236,7 +235,7 @@ int bladerf_sink_c::work( int noutput_items,
{
const gr_complex *in = (const gr_complex *) input_items[0];
const float scaling = 2000.0f;
int ret;
int status;
if (noutput_items > _conv_buf_size) {
void *tmp;
@ -244,8 +243,7 @@ int bladerf_sink_c::work( int noutput_items,
_conv_buf_size = noutput_items;
tmp = realloc(_conv_buf, _conv_buf_size * 2 * sizeof(int16_t));
if (tmp == NULL) {
throw std::runtime_error( std::string(__FUNCTION__) +
"Failed to realloc _conv_buf" );
throw std::runtime_error(_pfx + "Failed to realloc _conv_buf");
} else {
DBG("Resized _conv_buf to " << _conv_buf_size << " samples");
}
@ -254,18 +252,20 @@ int bladerf_sink_c::work( int noutput_items,
}
/* Convert floating point samples into fixed point */
volk_32f_s32f_convert_16i(_conv_buf, (float*)in, scaling, 2 * noutput_items);
volk_32f_s32f_convert_16i(_conv_buf, (float *) in, scaling,
2 * noutput_items);
if (_use_metadata) {
ret = transmit_with_tags(noutput_items);
status = transmit_with_tags(noutput_items);
} else {
ret = bladerf_sync_tx(_dev.get(), static_cast<void *>(_conv_buf),
status = bladerf_sync_tx(_dev.get(), static_cast < void *>(_conv_buf),
noutput_items, NULL, _stream_timeout_ms);
}
if ( ret != 0 ) {
std::cerr << _pfx << "bladerf_sync_tx error: "
<< bladerf_strerror(ret) << std::endl;
if (status != 0) {
std::cerr << _pfx
<< "bladerf_sync_tx error: " << bladerf_strerror(status)
<< std::endl;
_consecutive_failures++;
@ -282,7 +282,6 @@ int bladerf_sink_c::work( int noutput_items,
return noutput_items;
}
std::vector < std::string > bladerf_sink_c::get_devices()
{
return bladerf_common::devices();
@ -345,7 +344,8 @@ osmosdr::gain_range_t bladerf_sink_c::get_gain_range( size_t chan )
return bladerf_common::get_gain_range(BLADERF_CHANNEL_TX(chan));
}
osmosdr::gain_range_t bladerf_sink_c::get_gain_range( const std::string & name, size_t chan )
osmosdr::gain_range_t bladerf_sink_c::get_gain_range(const std::string &name,
size_t chan)
{
return bladerf_common::get_gain_range(name, BLADERF_CHANNEL_TX(chan));
}
@ -365,7 +365,8 @@ double bladerf_sink_c::set_gain( double gain, size_t chan )
return bladerf_common::set_gain(gain, BLADERF_CHANNEL_TX(chan));
}
double bladerf_sink_c::set_gain( double gain, const std::string & name, size_t chan)
double bladerf_sink_c::set_gain(double gain, const std::string &name,
size_t chan)
{
return bladerf_common::set_gain(gain, name, BLADERF_CHANNEL_TX(chan));
}
@ -393,7 +394,8 @@ std::vector< std::string > bladerf_sink_c::get_antennas( size_t chan )
return antennas;
}
std::string bladerf_sink_c::set_antenna( const std::string & antenna, size_t chan )
std::string bladerf_sink_c::set_antenna(const std::string &antenna,
size_t chan)
{
return get_antenna(BLADERF_CHANNEL_TX(chan));
}
@ -405,45 +407,48 @@ std::string bladerf_sink_c::get_antenna( size_t chan )
return "TX0";
}
void bladerf_sink_c::set_dc_offset( const std::complex<double> &offset, size_t chan )
void bladerf_sink_c::set_dc_offset(const std::complex < double > &offset,
size_t chan)
{
int ret = 0;
int status;
ret = bladerf_common::set_dc_offset(BLADERF_TX, offset, chan);
status = bladerf_common::set_dc_offset(BLADERF_TX, offset, chan);
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not set dc offset: " +
std::string(bladerf_strerror(ret)) );
if (status != 0) {
throw std::runtime_error(_pfx + "could not set dc offset: " +
bladerf_strerror(status));
}
}
void bladerf_sink_c::set_iq_balance( const std::complex<double> &balance, size_t chan )
void bladerf_sink_c::set_iq_balance(const std::complex < double > &balance,
size_t chan)
{
int ret = 0;
int status;
ret = bladerf_common::set_iq_balance(BLADERF_TX, balance, chan);
status = bladerf_common::set_iq_balance(BLADERF_TX, balance, chan);
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not set iq balance: " +
std::string(bladerf_strerror(ret)) );
if (status != 0) {
throw std::runtime_error(_pfx + "could not set iq balance: " +
bladerf_strerror(status));
}
}
double bladerf_sink_c::set_bandwidth(double bandwidth, size_t chan)
{
int ret;
int status;
uint32_t actual;
if ( bandwidth == 0.0 ) /* bandwidth of 0 means automatic filter selection */
bandwidth = get_sample_rate() * 0.75; /* select narrower filters to prevent aliasing */
if (bandwidth == 0.0) {
/* bandwidth of 0 means automatic filter selection */
/* select narrower filters to prevent aliasing */
bandwidth = get_sample_rate() * 0.75;
}
ret = bladerf_set_bandwidth( _dev.get(), BLADERF_TX, (uint32_t)bandwidth, &actual );
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not set bandwidth:" +
std::string(bladerf_strerror(ret)) );
status = bladerf_set_bandwidth(_dev.get(), BLADERF_TX, (uint32_t) bandwidth,
&actual);
if (status != 0) {
throw std::runtime_error(_pfx + "could not set bandwidth:" +
bladerf_strerror(status));
}
return get_bandwidth();
@ -451,14 +456,13 @@ double bladerf_sink_c::set_bandwidth( double bandwidth, size_t chan )
double bladerf_sink_c::get_bandwidth(size_t chan)
{
int status;
uint32_t bandwidth;
int ret;
ret = bladerf_get_bandwidth( _dev.get(), BLADERF_TX, &bandwidth );
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not get bandwidth: " +
std::string(bladerf_strerror(ret)) );
status = bladerf_get_bandwidth(_dev.get(), BLADERF_TX, &bandwidth);
if (status != 0) {
throw std::runtime_error(_pfx + "could not get bandwidth: " +
bladerf_strerror(status));
}
return (double) bandwidth;
@ -469,7 +473,8 @@ osmosdr::freq_range_t bladerf_sink_c::get_bandwidth_range( size_t chan )
return filter_bandwidths();
}
void bladerf_sink_c::set_clock_source(const std::string &source, const size_t mboard)
void bladerf_sink_c::set_clock_source(const std::string &source,
const size_t mboard)
{
bladerf_common::set_clock_source(source, mboard);
}

View File

@ -75,7 +75,7 @@ bladerf_source_c::bladerf_source_c (const std::string &args)
gr::io_signature::make(MIN_IN, MAX_IN, sizeof(gr_complex)),
gr::io_signature::make(MIN_OUT, MAX_OUT, sizeof(gr_complex)))
{
int ret;
int status;
std::string device_name;
struct bladerf_version fpga_version;
@ -83,21 +83,31 @@ bladerf_source_c::bladerf_source_c (const std::string &args)
init(dict, BLADERF_RX);
if (dict.count("sampling"))
{
if (dict.count("sampling")) {
std::string sampling = dict["sampling"];
std::cerr << _pfx << "Setting bladerf sampling to " << sampling << std::endl;
std::cerr << _pfx
<< "Setting bladerf sampling to " << sampling
<< std::endl;
if (sampling == "internal") {
ret = bladerf_set_sampling( _dev.get(), BLADERF_SAMPLING_INTERNAL );
if ( ret != 0 )
std::cerr << _pfx << "Problem while setting sampling mode:"
<< bladerf_strerror(ret) << std::endl;
status = bladerf_set_sampling(_dev.get(), BLADERF_SAMPLING_INTERNAL);
if (status != 0) {
std::cerr << _pfx
<< "Problem while setting sampling mode: "
<< bladerf_strerror(status)
<< std::endl;
}
} else if (sampling == "external") {
ret = bladerf_set_sampling( _dev.get(), BLADERF_SAMPLING_EXTERNAL );
if ( ret != 0 )
std::cerr << _pfx << "Problem while setting sampling mode:"
<< bladerf_strerror(ret) << std::endl;
status = bladerf_set_sampling(_dev.get(), BLADERF_SAMPLING_EXTERNAL);
if (status != 0) {
std::cerr << _pfx
<< "Problem while setting sampling mode: "
<< bladerf_strerror(status)
<< std::endl;
}
} else {
std::cerr << _pfx << "Invalid sampling mode " << sampling << std::endl;
}
@ -108,11 +118,11 @@ bladerf_source_c::bladerf_source_c (const std::string &args)
if (bladerf_fpga_version(_dev.get(), &fpga_version) != 0) {
std::cerr << _pfx << "Failed to get FPGA version" << std::endl;
} else if (fpga_version.major <= 0 &&
fpga_version.minor <= 0 &&
fpga_version.patch < 1 ) {
fpga_version.minor <= 0 && fpga_version.patch < 1) {
std::cerr << _pfx << "Warning: FPGA version v0.0.1 or later is required. "
<< "Using an earlier FPGA version will result in misinterpeted samples. "
std::cerr << _pfx
<< "Warning: FPGA version v0.0.1 or later is required. Using an "
<< "earlier FPGA version will result in misinterpeted samples."
<< std::endl;
}
}
@ -131,8 +141,8 @@ int bladerf_source_c::work( int noutput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
int ret;
const float scaling = 2048.0f;
int status;
gr_complex *out = static_cast<gr_complex *>(output_items[0]);
struct bladerf_metadata meta;
struct bladerf_metadata *meta_ptr = NULL;
@ -143,8 +153,7 @@ int bladerf_source_c::work( int noutput_items,
_conv_buf_size = noutput_items;
tmp = realloc(_conv_buf, _conv_buf_size * 2 * sizeof(int16_t));
if (tmp == NULL) {
throw std::runtime_error( std::string(__FUNCTION__) +
"Failed to realloc _conv_buf" );
throw std::runtime_error(_pfx + "Failed to realloc _conv_buf");
}
_conv_buf = static_cast<int16_t *>(tmp);
@ -157,11 +166,12 @@ int bladerf_source_c::work( int noutput_items,
}
/* Grab all the samples into the temporary buffer */
ret = bladerf_sync_rx(_dev.get(), static_cast<void *>(_conv_buf),
status = bladerf_sync_rx(_dev.get(), static_cast<void *>(_conv_buf),
noutput_items, meta_ptr, _stream_timeout_ms);
if ( ret != 0 ) {
std::cerr << _pfx << "bladerf_sync_rx error: "
<< bladerf_strerror(ret) << std::endl;
if (status != 0) {
std::cerr << _pfx
<< "bladerf_sync_rx error: " << bladerf_strerror(status)
<< std::endl;
_consecutive_failures++;
@ -176,7 +186,8 @@ int bladerf_source_c::work( int noutput_items,
}
/* Convert them from fixed to floating point */
volk_16i_s32f_convert_32f((float*)out, _conv_buf, scaling, 2*noutput_items);
volk_16i_s32f_convert_32f((float *) out, _conv_buf, scaling,
2 * noutput_items);
return noutput_items;
}
@ -243,7 +254,8 @@ osmosdr::gain_range_t bladerf_source_c::get_gain_range( size_t chan )
return bladerf_common::get_gain_range(BLADERF_CHANNEL_RX(chan));
}
osmosdr::gain_range_t bladerf_source_c::get_gain_range( const std::string & name, size_t chan )
osmosdr::gain_range_t bladerf_source_c::get_gain_range(const std::string &name,
size_t chan)
{
return bladerf_common::get_gain_range(name, BLADERF_CHANNEL_RX(chan));
}
@ -263,7 +275,8 @@ double bladerf_source_c::set_gain( double gain, size_t chan )
return bladerf_common::set_gain(gain, BLADERF_CHANNEL_RX(chan));
}
double bladerf_source_c::set_gain( double gain, const std::string & name, size_t chan)
double bladerf_source_c::set_gain(double gain, const std::string &name,
size_t chan)
{
return bladerf_common::set_gain(gain, name, BLADERF_CHANNEL_RX(chan));
}
@ -291,7 +304,8 @@ std::vector< std::string > bladerf_source_c::get_antennas( size_t chan )
return antennas;
}
std::string bladerf_source_c::set_antenna( const std::string & antenna, size_t chan )
std::string bladerf_source_c::set_antenna(const std::string &antenna,
size_t chan)
{
return get_antenna(BLADERF_CHANNEL_RX(chan));
}
@ -307,25 +321,29 @@ void bladerf_source_c::set_dc_offset_mode( int mode, size_t chan )
{
if (osmosdr::source::DCOffsetOff == mode) {
//_src->set_auto_dc_offset( false, chan );
set_dc_offset( std::complex<double>(0.0, 0.0), chan ); /* reset to default for off-state */
/* reset to default for off-state */
set_dc_offset(std::complex < double >(0.0, 0.0), chan);
} else if (osmosdr::source::DCOffsetManual == mode) {
//_src->set_auto_dc_offset( false, chan ); /* disable auto mode, but keep correcting with last known values */
/* disable auto mode, but keep correcting with last known values */
//_src->set_auto_dc_offset( false, chan );
} else if (osmosdr::source::DCOffsetAutomatic == mode) {
//_src->set_auto_dc_offset( true, chan );
std::cerr << "Automatic DC correction mode is not implemented." << std::endl;
std::cerr << _pfx
<< "Automatic DC correction mode is not implemented."
<< std::endl;
}
}
void bladerf_source_c::set_dc_offset( const std::complex<double> &offset, size_t chan )
void bladerf_source_c::set_dc_offset(const std::complex < double > &offset,
size_t chan)
{
int ret = 0;
int status;
ret = bladerf_common::set_dc_offset(BLADERF_RX, offset, chan);
status = bladerf_common::set_dc_offset(BLADERF_RX, offset, chan);
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not set dc offset: " +
std::string(bladerf_strerror(ret)) );
if (status != 0) {
throw std::runtime_error(_pfx + "could not set dc offset: " +
bladerf_strerror(status));
}
}
@ -333,41 +351,48 @@ void bladerf_source_c::set_iq_balance_mode( int mode, size_t chan )
{
if (osmosdr::source::IQBalanceOff == mode) {
//_src->set_auto_iq_balance( false, chan );
set_iq_balance( std::complex<double>(0.0, 0.0), chan ); /* reset to default for off-state */
/* reset to default for off-state */
set_iq_balance(std::complex < double >(0.0, 0.0), chan);
} else if (osmosdr::source::IQBalanceManual == mode) {
//_src->set_auto_iq_balance( false, chan ); /* disable auto mode, but keep correcting with last known values */
/* disable auto mode, but keep correcting with last known values */
//_src->set_auto_iq_balance( false, chan );
} else if (osmosdr::source::IQBalanceAutomatic == mode) {
//_src->set_auto_iq_balance( true, chan );
std::cerr << "Automatic IQ correction mode is not implemented." << std::endl;
std::cerr << _pfx
<< "Automatic IQ correction mode is not implemented."
<< std::endl;
}
}
void bladerf_source_c::set_iq_balance( const std::complex<double> &balance, size_t chan )
void bladerf_source_c::set_iq_balance(const std::complex < double > &balance,
size_t chan)
{
int ret = 0;
int status;
ret = bladerf_common::set_iq_balance(BLADERF_RX, balance, chan);
status = bladerf_common::set_iq_balance(BLADERF_RX, balance, chan);
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not set iq balance: " +
std::string(bladerf_strerror(ret)) );
if (status != 0) {
throw std::runtime_error(_pfx + "could not set iq balance: " +
bladerf_strerror(status));
}
}
double bladerf_source_c::set_bandwidth(double bandwidth, size_t chan)
{
int ret;
int status;
uint32_t actual;
if ( bandwidth == 0.0 ) /* bandwidth of 0 means automatic filter selection */
bandwidth = get_sample_rate() * 0.75; /* select narrower filters to prevent aliasing */
if (bandwidth == 0.0) {
/* bandwidth of 0 means automatic filter selection */
/* select narrower filters to prevent aliasing */
bandwidth = get_sample_rate() * 0.75;
}
ret = bladerf_set_bandwidth( _dev.get(), BLADERF_RX, (uint32_t)bandwidth, &actual );
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not set bandwidth: " +
std::string(bladerf_strerror(ret)) );
status = bladerf_set_bandwidth(_dev.get(), BLADERF_RX, (uint32_t) bandwidth,
&actual);
if (status != 0) {
throw std::runtime_error(_pfx + "could not set bandwidth: " +
bladerf_strerror(status));
}
return get_bandwidth();
@ -375,14 +400,13 @@ double bladerf_source_c::set_bandwidth( double bandwidth, size_t chan )
double bladerf_source_c::get_bandwidth(size_t chan)
{
int status;
uint32_t bandwidth;
int ret;
ret = bladerf_get_bandwidth( _dev.get(), BLADERF_RX, &bandwidth );
if( ret ) {
throw std::runtime_error( std::string(__FUNCTION__) + " " +
"could not get bandwidth:" +
std::string(bladerf_strerror(ret)) );
status = bladerf_get_bandwidth(_dev.get(), BLADERF_RX, &bandwidth);
if (status != 0) {
throw std::runtime_error(_pfx + "could not get bandwidth: " +
bladerf_strerror(status));
}
return (double) bandwidth;
@ -393,7 +417,8 @@ osmosdr::freq_range_t bladerf_source_c::get_bandwidth_range( size_t chan )
return filter_bandwidths();
}
void bladerf_source_c::set_clock_source(const std::string &source, const size_t mboard)
void bladerf_source_c::set_clock_source(const std::string &source,
const size_t mboard)
{
bladerf_common::set_clock_source(source, mboard);
}