gr-osmosdr/lib/osmosdr_source_c_impl.cc

316 lines
8.4 KiB
C++

/* -*- 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.
*/
/*
* config.h is generated by configure. It contains the results
* of probing for features, options etc. It should be the first
* file included in your .cc file.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <osmosdr_source_c_impl.h>
#include <gr_io_signature.h>
#ifdef ENABLE_OSMOSDR
#include <osmosdr_src_c.h>
#endif
#ifdef ENABLE_FCD
#include <fcd_source.h>
#endif
#ifdef ENABLE_RTL
#include <rtl_source_c.h>
#endif
#ifdef ENABLE_UHD
#include <uhd_source_c.h>
#endif
#include <osmosdr_arg_helpers.h>
/*
* Create a new instance of osmosdr_source_c_impl and return
* a boost shared_ptr. This is effectively the public constructor.
*/
osmosdr_source_c_sptr
osmosdr_make_source_c (const std::string &args)
{
return gnuradio::get_initial_sptr(new osmosdr_source_c_impl (args));
}
/*
* The private constructor
*/
osmosdr_source_c_impl::osmosdr_source_c_impl (const std::string &args)
: gr_hier_block2 ("osmosdr_source_c_impl",
gr_make_io_signature (0, 0, 0),
args_to_io_signature(args))
{
size_t channel = 0;
BOOST_FOREACH(std::string arg, args_to_vector(args)) {
dict_t dict = params_to_dict(arg);
// std::cout << std::endl;
// BOOST_FOREACH( dict_t::value_type &entry, dict )
// std::cout << "'" << entry.first << "' = '" << entry.second << "'" << std::endl;
#ifdef ENABLE_OSMOSDR
if ( dict.count("osmosdr") ) {
osmosdr_src_c_sptr src = osmosdr_make_src_c( arg );
// for (size_t i = 0; i < src->get_num_channels(); i++)
// connect(src, i, self(), channel++);
// _srcs.push_back( (osmosdr_src_iface *)src.get() ); // FIXME: implement
}
#endif
#ifdef ENABLE_FCD
if ( dict.count("fcd") ) {
fcd_source_sptr src = make_fcd_source( arg );
connect(src, 0, self(), channel++);
_srcs.push_back( (osmosdr_src_iface *)src.get() );
}
#endif
#ifdef ENABLE_RTL
if ( dict.count("rtl") ) {
rtl_source_c_sptr src = make_rtl_source_c( arg );
connect(src, 0, self(), channel++);
_srcs.push_back( (osmosdr_src_iface *)src.get() );
}
#endif
#ifdef ENABLE_UHD
if ( dict.count("uhd") ) {
uhd_source_c_sptr src = make_uhd_source_c( arg );
for (size_t i = 0; i < src->get_num_channels(); i++)
connect(src, i, self(), channel++);
_srcs.push_back( (osmosdr_src_iface *)src.get() );
}
#endif
}
if (!_srcs.size())
throw std::runtime_error("No devices specified via device arguments.");
}
size_t osmosdr_source_c_impl::get_num_channels()
{
size_t channels = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
channels += dev->get_num_channels();
return channels;
}
osmosdr::meta_range_t osmosdr_source_c_impl::get_sample_rates()
{
return _srcs[0]->get_sample_rates();
}
double osmosdr_source_c_impl::set_sample_rate(double rate)
{
double sample_rate = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
sample_rate = dev->set_sample_rate(rate);
return sample_rate;
}
double osmosdr_source_c_impl::get_sample_rate()
{
return _srcs[0]->get_sample_rate();
}
osmosdr::freq_range_t osmosdr_source_c_impl::get_freq_range( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_freq_range( chan );
return osmosdr::freq_range_t();
}
double osmosdr_source_c_impl::set_center_freq( double freq, size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->set_center_freq( freq, chan );
return 0;
}
double osmosdr_source_c_impl::get_center_freq( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_center_freq( chan );
return 0;
}
double osmosdr_source_c_impl::set_freq_corr( double ppm, size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->set_freq_corr( ppm, chan );
return 0;
}
double osmosdr_source_c_impl::get_freq_corr( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_freq_corr( chan );
return 0;
}
std::vector<std::string> osmosdr_source_c_impl::get_gain_names( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_gain_names( chan );
return std::vector< std::string >();
}
osmosdr::gain_range_t osmosdr_source_c_impl::get_gain_range( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_gain_range( chan );
return osmosdr::gain_range_t();
}
osmosdr::gain_range_t osmosdr_source_c_impl::get_gain_range( const std::string & name, size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_gain_range( name, chan );
return osmosdr::gain_range_t();
}
double osmosdr_source_c_impl::set_gain( double gain, size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->set_gain( gain, chan );
return 0;
}
double osmosdr_source_c_impl::set_gain( double gain, const std::string & name, size_t chan)
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->set_gain( gain, name, chan );
return 0;
}
double osmosdr_source_c_impl::get_gain( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_gain( chan );
return 0;
}
double osmosdr_source_c_impl::get_gain( const std::string & name, size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_gain( name, chan );
return 0;
}
std::vector< std::string > osmosdr_source_c_impl::get_antennas( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_antennas( chan );
return std::vector< std::string >();
}
std::string osmosdr_source_c_impl::set_antenna( const std::string & antenna, size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->set_antenna( antenna, chan );
return "";
}
std::string osmosdr_source_c_impl::get_antenna( size_t chan )
{
size_t channel = 0;
BOOST_FOREACH( osmosdr_src_iface *dev, _srcs )
for (size_t i = 0; i < dev->get_num_channels(); i++)
if ( chan == channel++ )
return _srcs[chan]->get_antenna( chan );
return "";
}