rtl: print a user friendly message if unable to parse the argument

This commit is contained in:
Dimitri Stolnikov 2012-11-04 15:08:16 +01:00
parent 933c0e21b1
commit cf807398c8
1 changed files with 9 additions and 3 deletions

View File

@ -98,10 +98,16 @@ rtl_source_c::rtl_source_c (const std::string &args)
dict_t dict = params_to_dict(args);
if (dict.count("rtl")) {
if ( (index = rtlsdr_get_index_by_serial( dict["rtl"].c_str() )) >= 0 )
if ( (index = rtlsdr_get_index_by_serial( dict["rtl"].c_str() )) >= 0 ) {
dev_index = index; /* use the resolved index value */
else /* use the numeric value of the argument */
dev_index = boost::lexical_cast< unsigned int >( dict["rtl"] );
} else { /* use the numeric value of the argument */
try {
dev_index = boost::lexical_cast< unsigned int >( dict["rtl"] );
} catch ( std::exception &ex ) {
throw std::runtime_error(
"Failed to use '" + dict["rtl"] + "' as index: " + ex.what());
}
}
}
if ( dev_index >= rtlsdr_get_device_count() )