aboutsummaryrefslogtreecommitdiffstats
path: root/lib/fcd
diff options
context:
space:
mode:
authorDimitri Stolnikov <horiz0n@gmx.net>2012-05-05 20:43:34 +0200
committerDimitri Stolnikov <horiz0n@gmx.net>2012-05-05 20:43:34 +0200
commitcf1c3ab117ee76cac3c574331c42173e0444aedd (patch)
tree3151ce897679b5d331791aff4f1e932e6fb75bca /lib/fcd
parenta6d6602d8ae405e2f20820fa5cdb972b53b716a5 (diff)
pick first device if no device arguments were specified
Diffstat (limited to 'lib/fcd')
-rw-r--r--lib/fcd/fcd_source.cc58
1 files changed, 35 insertions, 23 deletions
diff --git a/lib/fcd/fcd_source.cc b/lib/fcd/fcd_source.cc
index 8ed7103..c77e33a 100644
--- a/lib/fcd/fcd_source.cc
+++ b/lib/fcd/fcd_source.cc
@@ -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;
}