2012-04-26 17:20:16 +00:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* Copyright 2012 Dimitri Stolnikov <horiz0n@gmx.net>
|
|
|
|
*
|
|
|
|
* GNU Radio is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3, or (at your option)
|
|
|
|
* any later version.
|
|
|
|
*
|
|
|
|
* GNU Radio is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GNU Radio; see the file COPYING. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <boost/foreach.hpp>
|
|
|
|
#include <boost/assign.hpp>
|
2012-06-09 14:00:24 +00:00
|
|
|
#include <boost/algorithm/string.hpp>
|
2012-04-26 17:20:16 +00:00
|
|
|
|
|
|
|
//#include <uhd/property_tree.hpp>
|
|
|
|
|
2013-05-07 20:44:08 +00:00
|
|
|
#include "osmosdr_arg_helpers.h"
|
2012-04-28 18:18:14 +00:00
|
|
|
|
2012-04-26 17:20:16 +00:00
|
|
|
#include "uhd_source_c.h"
|
|
|
|
|
|
|
|
using namespace boost::assign;
|
|
|
|
|
|
|
|
uhd_source_c_sptr make_uhd_source_c(const std::string &args)
|
|
|
|
{
|
2012-04-28 18:18:14 +00:00
|
|
|
return gnuradio::get_initial_sptr(new uhd_source_c(args));
|
2012-04-26 17:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uhd_source_c::uhd_source_c(const std::string &args) :
|
|
|
|
gr_hier_block2("uhd_source_c",
|
|
|
|
gr_make_io_signature (0, 0, 0),
|
2012-11-29 21:38:52 +00:00
|
|
|
args_to_io_signature(args)),
|
|
|
|
_lo_offset(0.0f)
|
2012-04-26 17:20:16 +00:00
|
|
|
{
|
2012-05-20 10:30:28 +00:00
|
|
|
size_t nchan = 1;
|
2012-04-28 18:18:14 +00:00
|
|
|
dict_t dict = params_to_dict(args);
|
|
|
|
|
|
|
|
if (dict.count("nchan"))
|
2012-05-20 10:30:28 +00:00
|
|
|
nchan = boost::lexical_cast< size_t >( dict["nchan"] );
|
|
|
|
|
|
|
|
if (0 == nchan)
|
|
|
|
nchan = 1;
|
2012-04-28 18:18:14 +00:00
|
|
|
|
2012-11-29 21:38:52 +00:00
|
|
|
if (dict.count("lo_offset"))
|
|
|
|
_lo_offset = boost::lexical_cast< double >( dict["lo_offset"] );
|
|
|
|
|
2012-06-09 14:26:49 +00:00
|
|
|
std::string arguments; // rebuild argument string without internal arguments
|
2012-05-05 18:43:34 +00:00
|
|
|
BOOST_FOREACH( dict_t::value_type &entry, dict ) {
|
2012-06-09 14:26:49 +00:00
|
|
|
if ( "uhd" != entry.first &&
|
|
|
|
"nchan" != entry.first &&
|
2012-11-29 21:38:52 +00:00
|
|
|
"subdev" != entry.first &&
|
|
|
|
"lo_offset" != entry.first ) {
|
2012-05-05 18:43:34 +00:00
|
|
|
arguments += entry.first + "=" + entry.second + ",";
|
2012-06-09 14:26:49 +00:00
|
|
|
}
|
2012-05-05 18:43:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
_src = uhd_make_usrp_source( arguments,
|
2012-04-28 18:18:14 +00:00
|
|
|
uhd::io_type_t::COMPLEX_FLOAT32,
|
2012-05-20 10:30:28 +00:00
|
|
|
nchan );
|
2012-04-28 18:18:14 +00:00
|
|
|
|
2012-11-29 21:38:52 +00:00
|
|
|
if (dict.count("subdev")) {
|
2012-04-28 18:18:14 +00:00
|
|
|
_src->set_subdev_spec( dict["subdev"] );
|
2012-04-26 17:20:16 +00:00
|
|
|
|
2012-11-29 21:38:52 +00:00
|
|
|
std::cerr << "-- Using subdev spec '" << _src->get_subdev_spec() << "'."
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0.0 != _lo_offset)
|
|
|
|
std::cerr << "-- Using lo offset of " << _lo_offset << " Hz." << std::endl;
|
|
|
|
|
2012-05-20 10:30:28 +00:00
|
|
|
for ( size_t i = 0; i < nchan; i++ )
|
2012-04-28 18:18:14 +00:00
|
|
|
connect( _src, i, self(), i );
|
2012-04-26 17:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uhd_source_c::~uhd_source_c()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< std::string > uhd_source_c::get_devices()
|
|
|
|
{
|
2012-04-28 18:18:14 +00:00
|
|
|
std::vector< std::string > devices;
|
2012-04-26 17:20:16 +00:00
|
|
|
|
2012-04-28 18:18:14 +00:00
|
|
|
uhd::device_addr_t hint;
|
2012-05-20 10:30:28 +00:00
|
|
|
BOOST_FOREACH(const uhd::device_addr_t &dev, uhd::device::find(hint)) {
|
2013-01-10 19:30:38 +00:00
|
|
|
std::string args = "uhd,subdev='A:0'," + dev.to_string();
|
2012-06-09 14:00:24 +00:00
|
|
|
|
|
|
|
std::string label = "Ettus";
|
|
|
|
|
|
|
|
std::string type = dev.cast< std::string >("type", "USRP");
|
|
|
|
std::string name = dev.cast< std::string >("name", "");
|
|
|
|
std::string serial = dev.cast< std::string >("serial", "");
|
|
|
|
|
|
|
|
if (type.length()) {
|
|
|
|
boost::to_upper(type);
|
|
|
|
label += " " + type;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (name.length())
|
|
|
|
label += " " + name;
|
|
|
|
|
|
|
|
if (serial.length())
|
|
|
|
label += " " + serial;
|
|
|
|
|
|
|
|
args += ",label='" + label + + "'";
|
|
|
|
|
2012-05-20 10:30:28 +00:00
|
|
|
devices.push_back( args );
|
|
|
|
}
|
|
|
|
|
|
|
|
//devices.clear();
|
2012-06-09 14:26:49 +00:00
|
|
|
//devices.push_back( "uhd,type=usrp1,label='Ettus USRP'" );
|
2012-04-26 17:20:16 +00:00
|
|
|
|
2012-04-28 18:18:14 +00:00
|
|
|
return devices;
|
2012-04-26 17:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string uhd_source_c::name()
|
|
|
|
{
|
|
|
|
// uhd::property_tree::sptr prop_tree = _src->get_device()->get_device()->get_tree();
|
|
|
|
// std::string dev_name = prop_tree->access<std::string>("/name").get();
|
|
|
|
std::string mboard_name = _src->get_device()->get_mboard_name();
|
|
|
|
|
2012-05-20 10:30:28 +00:00
|
|
|
// std::cerr << "'" << dev_name << "' '" << mboard_name << "'" << std::endl;
|
2012-04-26 17:20:16 +00:00
|
|
|
// 'USRP1 Device' 'USRP1 (Classic)'
|
|
|
|
// 'B-Series Device' 'B100 (B-Hundo)'
|
|
|
|
|
|
|
|
return mboard_name;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t uhd_source_c::get_num_channels()
|
|
|
|
{
|
|
|
|
return _src->get_device()->get_rx_num_channels();
|
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::meta_range_t uhd_source_c::get_sample_rates( void )
|
|
|
|
{
|
|
|
|
osmosdr::meta_range_t rates;
|
|
|
|
|
|
|
|
BOOST_FOREACH( uhd::range_t rate, _src->get_samp_rates() )
|
|
|
|
rates += osmosdr::range_t( rate.start(), rate.stop(), rate.step() );
|
|
|
|
|
|
|
|
return rates;
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::set_sample_rate( double rate )
|
|
|
|
{
|
|
|
|
_src->set_samp_rate( rate );
|
|
|
|
return get_sample_rate();
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::get_sample_rate( void )
|
|
|
|
{
|
|
|
|
return _src->get_samp_rate();
|
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::freq_range_t uhd_source_c::get_freq_range( size_t chan )
|
|
|
|
{
|
|
|
|
osmosdr::freq_range_t range;
|
|
|
|
|
|
|
|
BOOST_FOREACH( uhd::range_t freq, _src->get_freq_range(chan) )
|
|
|
|
range += osmosdr::range_t( freq.start(), freq.stop(), freq.step() );
|
|
|
|
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::set_center_freq( double freq, size_t chan )
|
|
|
|
{
|
2012-11-29 21:38:52 +00:00
|
|
|
//_src->set_center_freq(freq, chan);
|
|
|
|
|
|
|
|
// advanced tuning with tune_request_t
|
|
|
|
uhd::tune_request_t tune_req(freq, _lo_offset);
|
|
|
|
|
|
|
|
_src->set_center_freq(tune_req, chan);
|
2012-04-26 17:20:16 +00:00
|
|
|
|
|
|
|
return get_center_freq(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::get_center_freq( size_t chan )
|
|
|
|
{
|
|
|
|
return _src->get_center_freq(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::set_freq_corr( double ppm, size_t chan )
|
|
|
|
{
|
|
|
|
return get_freq_corr(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::get_freq_corr( size_t chan )
|
|
|
|
{
|
2012-04-28 18:18:14 +00:00
|
|
|
return 0; // frequency correction is not supported with UHD
|
2012-04-26 17:20:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> uhd_source_c::get_gain_names( size_t chan )
|
|
|
|
{
|
|
|
|
return _src->get_gain_names( chan );
|
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::gain_range_t uhd_source_c::get_gain_range( size_t chan )
|
|
|
|
{
|
|
|
|
osmosdr::gain_range_t range;
|
|
|
|
|
|
|
|
BOOST_FOREACH( uhd::range_t gain, _src->get_gain_range(chan) )
|
|
|
|
range += osmosdr::range_t( gain.start(), gain.stop(), gain.step() );
|
|
|
|
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::gain_range_t uhd_source_c::get_gain_range( const std::string & name, size_t chan )
|
|
|
|
{
|
|
|
|
osmosdr::gain_range_t range;
|
|
|
|
|
|
|
|
BOOST_FOREACH( uhd::range_t gain, _src->get_gain_range(name, chan) )
|
|
|
|
range += osmosdr::range_t( gain.start(), gain.stop(), gain.step() );
|
|
|
|
|
|
|
|
return range;
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::set_gain( double gain, size_t chan )
|
|
|
|
{
|
|
|
|
_src->set_gain(gain, chan);
|
|
|
|
|
|
|
|
return get_gain(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::set_gain( double gain, const std::string & name, size_t chan )
|
|
|
|
{
|
|
|
|
_src->set_gain(gain, name, chan);
|
|
|
|
|
|
|
|
return get_gain(name, chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::get_gain( size_t chan )
|
|
|
|
{
|
|
|
|
return _src->get_gain(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
double uhd_source_c::get_gain( const std::string & name, size_t chan )
|
|
|
|
{
|
|
|
|
return _src->get_gain(name, chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< std::string > uhd_source_c::get_antennas( size_t chan )
|
|
|
|
{
|
|
|
|
return _src->get_antennas(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string uhd_source_c::set_antenna( const std::string & antenna, size_t chan )
|
|
|
|
{
|
|
|
|
_src->set_antenna(antenna, chan);
|
|
|
|
|
|
|
|
return _src->get_antenna(chan);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string uhd_source_c::get_antenna( size_t chan )
|
|
|
|
{
|
|
|
|
return _src->get_antenna(chan);
|
|
|
|
}
|