diff options
Diffstat (limited to 'lib/hackrf/hackrf_source_c.cc')
-rw-r--r-- | lib/hackrf/hackrf_source_c.cc | 54 |
1 files changed, 49 insertions, 5 deletions
diff --git a/lib/hackrf/hackrf_source_c.cc b/lib/hackrf/hackrf_source_c.cc index c8ff0b5..fc11020 100644 --- a/lib/hackrf/hackrf_source_c.cc +++ b/lib/hackrf/hackrf_source_c.cc @@ -27,8 +27,8 @@ #include "config.h" #endif -#include "hackrf_source_c.h" -#include <gnuradio/gr_io_signature.h> +#include <stdexcept> +#include <iostream> #include <boost/assign.hpp> #include <boost/format.hpp> @@ -36,8 +36,9 @@ #include <boost/algorithm/string.hpp> #include <boost/thread/thread.hpp> -#include <stdexcept> -#include <iostream> +#include <gnuradio/gr_io_signature.h> + +#include "hackrf_source_c.h" #include <osmosdr_arg_helpers.h> @@ -163,6 +164,7 @@ hackrf_source_c::hackrf_source_c (const std::string &args) << std::endl; } + set_center_freq( (get_freq_range().start() + get_freq_range().stop()) / 2.0 ); set_sample_rate( get_sample_rates().start() ); set_bandwidth( 0 ); @@ -341,7 +343,7 @@ std::vector<std::string> hackrf_source_c::get_devices() { std::vector<std::string> devices; std::string label; - +#if 0 for (unsigned int i = 0; i < 1 /* TODO: missing libhackrf api */; i++) { std::string args = "hackrf=" + boost::lexical_cast< std::string >( i ); @@ -354,7 +356,49 @@ std::vector<std::string> hackrf_source_c::get_devices() args += ",label='" + label + "'"; devices.push_back( args ); } +#else + + { + boost::mutex::scoped_lock lock( _usage_mutex ); + + if ( _usage == 0 ) + hackrf_init(); /* call only once before the first open */ + + _usage++; + } + + int ret; + hackrf_device *dev = NULL; + ret = hackrf_open(&dev); + if ( HACKRF_SUCCESS == ret ) + { + std::string args = "hackrf=0"; + + label = "HackRF"; + + uint8_t board_id; + ret = hackrf_board_id_read( dev, &board_id ); + if ( HACKRF_SUCCESS == ret ) + { + label += std::string(" ") + hackrf_board_id_name(hackrf_board_id(board_id)); + } + + args += ",label='" + label + "'"; + devices.push_back( args ); + + ret = hackrf_close(dev); + } + + { + boost::mutex::scoped_lock lock( _usage_mutex ); + + _usage--; + + if ( _usage == 0 ) + hackrf_exit(); /* call only once after last close */ + } +#endif return devices; } |