From c16a562ddc5949a395845bc2bef3b3fc0e0e11c9 Mon Sep 17 00:00:00 2001 From: Dimitri Stolnikov Date: Tue, 27 Aug 2013 22:37:08 +0200 Subject: [PATCH] bladerf: follow recent API changes tested against aea04c5f119288370166ece05166a8a4157da6fa --- lib/bladerf/bladerf_common.cc | 16 +++++++----- lib/bladerf/bladerf_sink_c.cc | 34 ++++++++++++------------- lib/bladerf/bladerf_source_c.cc | 44 ++++++++++++++++----------------- 3 files changed, 49 insertions(+), 45 deletions(-) diff --git a/lib/bladerf/bladerf_common.cc b/lib/bladerf/bladerf_common.cc index 72db844..43b58ec 100644 --- a/lib/bladerf/bladerf_common.cc +++ b/lib/bladerf/bladerf_common.cc @@ -123,7 +123,7 @@ osmosdr::freq_range_t bladerf_common::filter_bandwidths() std::vector< std::string > bladerf_common::devices() { - struct ::bladerf_devinfo *devices; + struct bladerf_devinfo *devices; ssize_t n_devices; std::vector< std::string > ret; @@ -133,16 +133,20 @@ std::vector< std::string > bladerf_common::devices() for (ssize_t i = 0; i < n_devices; i++) { std::stringstream s; - std::string dev(devices[i].path); + std::string serial(devices[i].serial); - s << "bladerf=" << dev.substr(dev.find_first_of("01234567890")) << "," - << "label='nuand bladeRF SN " << std::setfill('0') << std::setw(16) - << devices[i].serial << "'"; + s << "bladerf=" << devices[i].instance << "," + << "label='nuand bladeRF"; + + if ( serial.length() ) + s << " SN " << serial; + + s << "'"; ret.push_back(s.str()); } - bladerf_free_device_list(devices, n_devices); + bladerf_free_device_list(devices); } return ret; diff --git a/lib/bladerf/bladerf_sink_c.cc b/lib/bladerf/bladerf_sink_c.cc index b3faf6c..1c6fb94 100644 --- a/lib/bladerf/bladerf_sink_c.cc +++ b/lib/bladerf/bladerf_sink_c.cc @@ -93,11 +93,11 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) } } - device_name = boost::str(boost::format( "/dev/bladerf%d" ) % device_number); + device_name = boost::str(boost::format( "libusb:instance=%d" ) % device_number); /* Open a handle to the device */ - this->dev = bladerf_open( device_name.c_str() ); - if( NULL == this->dev ) { + ret = bladerf_open( &this->dev, device_name.c_str() ); + if ( ret != 0 ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "failed to open bladeRF device " + device_name ); } @@ -132,9 +132,9 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) std::cerr << "Using nuand LLC bladeRF #" << device_number; - u_int64_t serial; - if ( bladerf_get_serial( this->dev, &serial ) == 0 ) - std::cerr << " SN " << std::setfill('0') << std::setw(16) << serial; + char serial[33]; + if ( bladerf_get_serial( this->dev, serial ) == 0 ) + std::cerr << " SN " << serial; unsigned int major, minor; if ( bladerf_get_fw_version( this->dev, &major, &minor) == 0 ) @@ -158,7 +158,7 @@ bladerf_sink_c::bladerf_sink_c (const std::string &args) /* Set the range of VGA2, VGA2GAIN[4:0] */ this->vga2_range = osmosdr::gain_range_t( 0, 25, 1 ); - ret = bladerf_enable_module(this->dev, TX, true); + ret = bladerf_enable_module(this->dev, BLADERF_MODULE_TX, true); if ( ret != 0 ) std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; @@ -175,7 +175,7 @@ bladerf_sink_c::~bladerf_sink_c () this->set_running(false); this->thread.join(); - ret = bladerf_enable_module(this->dev, TX, false); + ret = bladerf_enable_module(this->dev, BLADERF_MODULE_TX, false); if ( ret != 0 ) std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; @@ -223,8 +223,8 @@ void bladerf_sink_c::write_task() this->samples_available.notify_one(); /* Samples are available to write out */ - n_samples = bladerf_send_c16(this->dev, this->raw_sample_buf, - BLADERF_SAMPLE_BLOCK_SIZE); + n_samples = bladerf_tx(this->dev, BLADERF_FORMAT_SC16_Q12, this->raw_sample_buf, + BLADERF_SAMPLE_BLOCK_SIZE, NULL); /* Check n_samples return value */ if( n_samples < 0 ) { @@ -321,7 +321,7 @@ double bladerf_sink_c::set_sample_rate(double rate) /* Check to see if the sample rate is an integer */ if( (uint32_t)round(rate) == (uint32_t)rate ) { - ret = bladerf_set_sample_rate( this->dev, TX, (uint32_t)rate, &actual ); + ret = bladerf_set_sample_rate( this->dev, BLADERF_MODULE_TX, (uint32_t)rate, &actual ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "has failed to set integer rate, error " + @@ -329,7 +329,7 @@ double bladerf_sink_c::set_sample_rate(double rate) } } else { /* TODO: Fractional sample rate */ - ret = bladerf_set_sample_rate( this->dev, TX, (uint32_t)rate, &actual ); + ret = bladerf_set_sample_rate( this->dev, BLADERF_MODULE_TX, (uint32_t)rate, &actual ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "has failed to set fractional rate, error " + @@ -345,7 +345,7 @@ double bladerf_sink_c::get_sample_rate() int ret; unsigned int rate = 0; - ret = bladerf_get_sample_rate( this->dev, TX, &rate ); + ret = bladerf_get_sample_rate( this->dev, BLADERF_MODULE_TX, &rate ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "has failed to get sample rate, error " + @@ -369,7 +369,7 @@ double bladerf_sink_c::set_center_freq( double freq, size_t chan ) freq > get_freq_range( chan ).stop() ) { std::cerr << "Failed to set out of bound frequency: " << freq << std::endl; } else { - ret = bladerf_set_frequency( this->dev, TX, (uint32_t)freq ); + ret = bladerf_set_frequency( this->dev, BLADERF_MODULE_TX, (uint32_t)freq ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "failed to set center frequency " + @@ -387,7 +387,7 @@ double bladerf_sink_c::get_center_freq( size_t chan ) uint32_t freq; int ret; - ret = bladerf_get_frequency( this->dev, TX, &freq ); + ret = bladerf_get_frequency( this->dev, BLADERF_MODULE_TX, &freq ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "failed to get center frequency, error " + @@ -546,7 +546,7 @@ double bladerf_sink_c::set_bandwidth( double bandwidth, size_t chan ) int ret; uint32_t actual; - ret = bladerf_set_bandwidth( this->dev, TX, (uint32_t)bandwidth, &actual ); + ret = bladerf_set_bandwidth( this->dev, BLADERF_MODULE_TX, (uint32_t)bandwidth, &actual ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "could not set bandwidth, error " + @@ -561,7 +561,7 @@ double bladerf_sink_c::get_bandwidth( size_t chan ) uint32_t bandwidth; int ret; - ret = bladerf_get_bandwidth( this->dev, TX, &bandwidth ); + ret = bladerf_get_bandwidth( this->dev, BLADERF_MODULE_TX, &bandwidth ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "could not get bandwidth, error " + diff --git a/lib/bladerf/bladerf_source_c.cc b/lib/bladerf/bladerf_source_c.cc index b73b2a5..31f72b7 100644 --- a/lib/bladerf/bladerf_source_c.cc +++ b/lib/bladerf/bladerf_source_c.cc @@ -93,11 +93,11 @@ bladerf_source_c::bladerf_source_c (const std::string &args) } } - device_name = boost::str(boost::format( "/dev/bladerf%d" ) % device_number); + device_name = boost::str(boost::format( "libusb:instance=%d" ) % device_number); /* Open a handle to the device */ - this->dev = bladerf_open( device_name.c_str() ); - if( NULL == this->dev ) { + ret = bladerf_open( &this->dev, NULL ); + if ( ret != 0 ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "failed to open bladeRF device " + device_name ); } @@ -132,9 +132,9 @@ bladerf_source_c::bladerf_source_c (const std::string &args) std::cerr << "Using nuand LLC bladeRF #" << device_number; - u_int64_t serial; - if ( bladerf_get_serial( this->dev, &serial ) == 0 ) - std::cerr << " SN " << std::setfill('0') << std::setw(16) << serial; + char serial[33]; + if ( bladerf_get_serial( this->dev, serial ) == 0 ) + std::cerr << " SN " << serial; unsigned int major, minor; if ( bladerf_get_fw_version( this->dev, &major, &minor) == 0 ) @@ -161,7 +161,7 @@ bladerf_source_c::bladerf_source_c (const std::string &args) /* Set the range of VGA2 VGA2GAIN[4:0], not recommended to be used above 30dB */ this->vga2_range = osmosdr::gain_range_t( 0, 60, 3 ); - ret = bladerf_enable_module(this->dev, RX, true); + ret = bladerf_enable_module(this->dev, BLADERF_MODULE_RX, true); if ( ret != 0 ) std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; @@ -178,7 +178,7 @@ bladerf_source_c::~bladerf_source_c () this->set_running(false); this->thread.join(); - ret = bladerf_enable_module(this->dev, RX, false); + ret = bladerf_enable_module(this->dev, BLADERF_MODULE_RX, false); if ( ret != 0 ) std::cerr << "bladerf_enable_module has returned with " << ret << std::endl; @@ -200,8 +200,8 @@ void bladerf_source_c::read_task() while ( this->is_running() ) { - n_samples = bladerf_read_c16(this->dev, this->raw_sample_buf, - BLADERF_SAMPLE_BLOCK_SIZE); + n_samples = bladerf_rx(this->dev, BLADERF_FORMAT_SC16_Q12, this->raw_sample_buf, + BLADERF_SAMPLE_BLOCK_SIZE, NULL); if (n_samples < 0) { std::cerr << "Failed to read samples: " @@ -315,7 +315,7 @@ double bladerf_source_c::set_sample_rate( double rate ) /* Check to see if the sample rate is an integer */ if( (uint32_t)round(rate) == (uint32_t)rate ) { - ret = bladerf_set_sample_rate( this->dev, RX, (uint32_t)rate, &actual ); + ret = bladerf_set_sample_rate( this->dev, BLADERF_MODULE_RX, (uint32_t)rate, &actual ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "has failed to set integer rate, error " + @@ -323,7 +323,7 @@ double bladerf_source_c::set_sample_rate( double rate ) } } else { /* TODO: Fractional sample rate */ - ret = bladerf_set_sample_rate( this->dev, RX, (uint32_t)rate, &actual ); + ret = bladerf_set_sample_rate( this->dev, BLADERF_MODULE_RX, (uint32_t)rate, &actual ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "has failed to set fractional rate, error " + @@ -339,7 +339,7 @@ double bladerf_source_c::get_sample_rate() int ret; unsigned int rate = 0; - ret = bladerf_get_sample_rate( this->dev, RX, &rate ); + ret = bladerf_get_sample_rate( this->dev, BLADERF_MODULE_RX, &rate ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "has failed to get sample rate, error " + @@ -363,7 +363,7 @@ double bladerf_source_c::set_center_freq( double freq, size_t chan ) freq > get_freq_range( chan ).stop() ) { std::cerr << "Failed to set out of bound frequency: " << freq << std::endl; } else { - ret = bladerf_set_frequency( this->dev, RX, (uint32_t)freq ); + ret = bladerf_set_frequency( this->dev, BLADERF_MODULE_RX, (uint32_t)freq ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "failed to set center frequency " + @@ -381,7 +381,7 @@ double bladerf_source_c::get_center_freq( size_t chan ) uint32_t freq; int ret; - ret = bladerf_get_frequency( this->dev, RX, &freq ); + ret = bladerf_get_frequency( this->dev, BLADERF_MODULE_RX, &freq ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "failed to get center frequency, error " + @@ -462,15 +462,15 @@ double bladerf_source_c::set_gain( double gain, const std::string & name, size_t if( name == "LNA" ) { bladerf_lna_gain g; if( gain == 0.0 ) { - g = LNA_BYPASS; + g = BLADERF_LNA_GAIN_BYPASS; } else if( gain == 3.0 ) { - g = LNA_MID; + g = BLADERF_LNA_GAIN_MID; } else if( gain == 6.0 ) { - g = LNA_MAX; + g = BLADERF_LNA_GAIN_MAX; } else { std::cerr << "Invalid LNA gain requested: " << gain << ", " << "setting to LNA_MAX (6dB)" << std::endl; - g = LNA_MAX; + g = BLADERF_LNA_GAIN_MAX; } ret = bladerf_set_lna_gain( this->dev, g ); } else if( name == "VGA1" ) { @@ -507,7 +507,7 @@ double bladerf_source_c::get_gain( const std::string & name, size_t chan ) if( name == "LNA" ) { bladerf_lna_gain lna_g; ret = bladerf_get_lna_gain( this->dev, &lna_g ); - g = lna_g == LNA_BYPASS ? 0 : lna_g == LNA_MID ? 3 : 6; + g = lna_g == BLADERF_LNA_GAIN_BYPASS ? 0 : lna_g == BLADERF_LNA_GAIN_MID ? 3 : 6; } else if( name == "VGA1" ) { ret = bladerf_get_rxvga1( this->dev, &g ); } else if( name == "VGA2" ) { @@ -564,7 +564,7 @@ double bladerf_source_c::set_bandwidth( double bandwidth, size_t chan ) int ret; uint32_t actual; - ret = bladerf_set_bandwidth( this->dev, RX, (uint32_t)bandwidth, &actual ); + ret = bladerf_set_bandwidth( this->dev, BLADERF_MODULE_RX, (uint32_t)bandwidth, &actual ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "could not set bandwidth, error " + @@ -579,7 +579,7 @@ double bladerf_source_c::get_bandwidth( size_t chan ) uint32_t bandwidth; int ret; - ret = bladerf_get_bandwidth( this->dev, RX, &bandwidth ); + ret = bladerf_get_bandwidth( this->dev, BLADERF_MODULE_RX, &bandwidth ); if( ret ) { throw std::runtime_error( std::string(__FUNCTION__) + " " + "could not get bandwidth, error " +