pick first device if no device arguments were specified

This commit is contained in:
Dimitri Stolnikov 2012-05-05 20:43:34 +02:00
parent a6d6602d8a
commit cf1c3ab117
6 changed files with 119 additions and 44 deletions

View File

@ -20,14 +20,12 @@ class osmosdr_source_c(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="OsmoSDR Source")
#self.src = osmosdr.source_c()
self.src = osmosdr.source_c("rtl=0")
#self.src = osmosdr.source_c("fcd=0")
#self.src = osmosdr.source_c("uhd=0")
self.src = osmosdr.source_c()
self.src.set_sample_rate(1024000)
self.src.set_center_freq(394.5e6)
self.src.set_gain(10)
self.src.set_center_freq(394.4e6)
self.src.set_gain_mode(0)
self.src.set_gain(9)
##################################################
# Variables

View File

@ -23,6 +23,7 @@
#include <sstream>
#include <boost/assign.hpp>
#include <boost/foreach.hpp>
#include <gr_io_signature.h>
@ -37,36 +38,7 @@ fcd_source_sptr make_fcd_source(const std::string &args)
return gnuradio::get_initial_sptr(new fcd_source(args));
}
fcd_source::fcd_source(const std::string &args) :
gr_hier_block2("fcd_source",
gr_make_io_signature (0, 0, 0),
gr_make_io_signature (1, 1, sizeof (gr_complex)))
{
std::string dev_name;
unsigned int dev_index = 0;
dict_t dict = params_to_dict(args);
if (dict.count("fcd"))
dev_index = boost::lexical_cast< unsigned int >( dict["fcd"] );
std::vector< std::string > devices = fcd_source::get_devices();
if ( devices.size() )
dev_name = devices[dev_index];
else
throw std::runtime_error("No FunCube Dongle found.");
_src = fcd_make_source_c( dev_name );
connect( _src, 0, self(), 0 );
}
fcd_source::~fcd_source()
{
}
std::vector< std::string > fcd_source::get_devices()
static std::vector< std::string > _get_devices()
{
std::vector< std::string > devices;
@ -96,6 +68,46 @@ std::vector< std::string > fcd_source::get_devices()
return devices;
}
fcd_source::fcd_source(const std::string &args) :
gr_hier_block2("fcd_source",
gr_make_io_signature (0, 0, 0),
gr_make_io_signature (1, 1, sizeof (gr_complex)))
{
std::string dev_name;
unsigned int dev_index = 0;
dict_t dict = params_to_dict(args);
if (dict.count("fcd"))
dev_index = boost::lexical_cast< unsigned int >( dict["fcd"] );
std::vector< std::string > devices = _get_devices();
if ( devices.size() )
dev_name = devices[dev_index];
else
throw std::runtime_error("No FunCube Dongle found.");
_src = fcd_make_source_c( dev_name );
connect( _src, 0, self(), 0 );
}
fcd_source::~fcd_source()
{
}
std::vector< std::string > fcd_source::get_devices()
{
int id = 0;
std::vector< std::string > devices;
BOOST_FOREACH( std::string dev, _get_devices() )
devices.push_back( "fcd=" + boost::lexical_cast< std::string >( id++ ) );
return devices;
}
gr_basic_block_sptr fcd_source::self()
{
return gr_hier_block2::self();

View File

@ -71,14 +71,58 @@ osmosdr_source_c_impl::osmosdr_source_c_impl (const std::string &args)
args_to_io_signature(args))
{
size_t channel = 0;
bool device_specified = false;
BOOST_FOREACH(std::string arg, args_to_vector(args)) {
std::vector< std::string > arg_list = args_to_vector(args);
BOOST_FOREACH(std::string arg, arg_list) {
dict_t dict = params_to_dict(arg);
// std::cout << std::endl;
if ( dict.count("osmosdr") |
dict.count("fcd") |
dict.count("file") |
dict.count("rtl") |
dict.count("uhd") )
{
device_specified = true;
}
}
std::vector< std::string > dev_list;
#ifdef ENABLE_OSMOSDR
// TODO: implement
#endif
#ifdef ENABLE_FCD
BOOST_FOREACH( std::string dev, fcd_source::get_devices() )
dev_list.push_back( dev );
#endif
#ifdef ENABLE_RTL
BOOST_FOREACH( std::string dev, rtl_source_c::get_devices() )
dev_list.push_back( dev );
#endif
#ifdef ENABLE_UHD
BOOST_FOREACH( std::string dev, uhd_source_c::get_devices() )
dev_list.push_back( dev );
#endif
// std::cerr << std::endl;
// BOOST_FOREACH( std::string dev, dev_list )
// std::cerr << "'" << dev << "'" << std::endl;
if (!device_specified) {
if ( dev_list.size() )
arg_list.push_back( dev_list.front() );
else
throw std::runtime_error("No supported devices found to pick from.");
}
BOOST_FOREACH(std::string arg, arg_list) {
dict_t dict = params_to_dict(arg);
// std::cerr << std::endl;
// BOOST_FOREACH( dict_t::value_type &entry, dict )
// std::cout << "'" << entry.first << "' = '" << entry.second << "'" << std::endl;
// std::cerr << "'" << entry.first << "' = '" << entry.second << "'" << std::endl;
#ifdef ENABLE_OSMOSDR
if ( dict.count("osmosdr") ) {
@ -143,12 +187,12 @@ size_t osmosdr_source_c_impl::get_num_channels()
osmosdr::meta_range_t osmosdr_source_c_impl::get_sample_rates()
{
return _devs[0]->get_sample_rates();
return _devs[0]->get_sample_rates(); // assume same devices used in the group
}
double osmosdr_source_c_impl::set_sample_rate(double rate)
{
double sample_rate = _sample_rate;
double sample_rate = 0;
if (_sample_rate != rate) {
BOOST_FOREACH( osmosdr_src_iface *dev, _devs )
@ -162,7 +206,7 @@ double osmosdr_source_c_impl::set_sample_rate(double rate)
double osmosdr_source_c_impl::get_sample_rate()
{
return _devs[0]->get_sample_rate();
return _devs[0]->get_sample_rate(); // assume same devices used in the group
}
osmosdr::freq_range_t osmosdr_source_c_impl::get_freq_range( size_t chan )

View File

@ -280,6 +280,16 @@ int rtl_source_c::work( int noutput_items,
return noutput_items;
}
std::vector<std::string> rtl_source_c::get_devices()
{
std::vector<std::string> result;
for (unsigned int i = 0; i < rtlsdr_get_device_count(); i++)
result.push_back( "rtl=" + boost::lexical_cast< std::string >( i ) );
return result;
}
size_t rtl_source_c::get_num_channels()
{
return 1;

View File

@ -83,6 +83,8 @@ public:
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items );
static std::vector< std::string > get_devices();
size_t get_num_channels( void );
osmosdr::meta_range_t get_sample_rates( void );

View File

@ -42,13 +42,22 @@ uhd_source_c::uhd_source_c(const std::string &args) :
args_to_io_signature(args))
{
size_t num_channels = 1;
std::string arguments = args;
dict_t dict = params_to_dict(args);
if (dict.count("nchan"))
num_channels = boost::lexical_cast< unsigned int >( dict["nchan"] );
_src = uhd_make_usrp_source( args,
arguments.clear(); // rebuild argument string without uhd= prefix
BOOST_FOREACH( dict_t::value_type &entry, dict ) {
if ( "uhd" == entry.first )
arguments += entry.second;
else
arguments += entry.first + "=" + entry.second + ",";
}
_src = uhd_make_usrp_source( arguments,
uhd::io_type_t::COMPLEX_FLOAT32,
num_channels );
@ -69,7 +78,7 @@ std::vector< std::string > uhd_source_c::get_devices()
uhd::device_addr_t hint;
BOOST_FOREACH(uhd::device_addr_t device, uhd::device::find(hint))
devices += device.to_string();
devices += "uhd=" + device.to_string();
return devices;
}