pick first device if no device arguments were specified

gr3.6
Dimitri Stolnikov 11 years ago
parent a6d6602d8a
commit cf1c3ab117
  1. 10
      apps/osmosdr_source.py
  2. 58
      lib/fcd/fcd_source.cc
  3. 56
      lib/osmosdr_source_c_impl.cc
  4. 10
      lib/rtl/rtl_source_c.cc
  5. 2
      lib/rtl/rtl_source_c.h
  6. 13
      lib/uhd/uhd_source_c.cc

@ -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

@ -23,6 +23,7 @@
#include <sstream>
#include <boost/assign.hpp>
#include <boost/foreach.hpp>
#include <gr_io_signature.h>
@ -37,6 +38,36 @@ fcd_source_sptr make_fcd_source(const std::string &args)
return gnuradio::get_initial_sptr(new fcd_source(args));
}
static std::vector< std::string > _get_devices()
{
std::vector< std::string > devices;
std::string line;
std::ifstream cards( "/proc/asound/cards" );
if ( cards.is_open() )
{
while ( cards.good() )
{
getline (cards, line);
if ( line.find( "USB-Audio - FUNcube Dongle" ) != std::string::npos )
{
int id;
std::istringstream( line ) >> id;
std::ostringstream hw_id;
hw_id << "hw:" << id; // build alsa identifier
devices += hw_id.str();
}
}
cards.close();
}
return devices;
}
fcd_source::fcd_source(const std::string &args) :
gr_hier_block2("fcd_source",
gr_make_io_signature (0, 0, 0),
@ -50,7 +81,7 @@ fcd_source::fcd_source(const std::string &args) :
if (dict.count("fcd"))
dev_index = boost::lexical_cast< unsigned int >( dict["fcd"] );
std::vector< std::string > devices = fcd_source::get_devices();
std::vector< std::string > devices = _get_devices();
if ( devices.size() )
dev_name = devices[dev_index];
@ -68,30 +99,11 @@ fcd_source::~fcd_source()
std::vector< std::string > fcd_source::get_devices()
{
int id = 0;
std::vector< std::string > devices;
std::string line;
std::ifstream cards( "/proc/asound/cards" );
if ( cards.is_open() )
{
while ( cards.good() )
{
getline (cards, line);
if ( line.find( "USB-Audio - FUNcube Dongle" ) != std::string::npos )
{
int id;
std::istringstream( line ) >> id;
std::ostringstream hw_id;
hw_id << "hw:" << id; // build alsa identifier
devices += hw_id.str();
}
}
cards.close();
}
BOOST_FOREACH( std::string dev, _get_devices() )
devices.push_back( "fcd=" + boost::lexical_cast< std::string >( id++ ) );
return devices;
}

@ -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);
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::cout << std::endl;
// 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 )

@ -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;

@ -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 );

@ -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;
}

Loading…
Cancel
Save