soapy: support step size in gain ranges

* This change is backwards compatible and checks for API support for step size.
* Created soapy_common.cc/h to house common gain range functions
* Moved factory mutex declaration to common source files as well
soapy_support
Josh Blum 6 years ago
parent 3511defbf4
commit 2a2236cc9e
  1. 1
      lib/soapy/CMakeLists.txt
  2. 43
      lib/soapy/soapy_common.cc
  3. 40
      lib/soapy/soapy_common.h
  4. 13
      lib/soapy/soapy_sink_c.cc
  5. 9
      lib/soapy/soapy_source_c.cc

@ -27,6 +27,7 @@ include_directories(
)
set(soapy_srcs
${CMAKE_CURRENT_SOURCE_DIR}/soapy_common.cc
${CMAKE_CURRENT_SOURCE_DIR}/soapy_source_c.cc
${CMAKE_CURRENT_SOURCE_DIR}/soapy_sink_c.cc
)

@ -0,0 +1,43 @@
/* -*- c++ -*- */
/*
* Copyright 2017 Josh Blum <josh@joshknows.com>
*
* 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 "soapy_common.h"
#include <SoapySDR/Version.hpp>
osmosdr::gain_range_t soapy_range_to_gain_range(const SoapySDR::Range &r)
{
//default step size when unspecified
double step = 1.0;
//support the step size in 0.6 API and above
//but do not allow unspecified steps
//to avoid device by zero in some applications
#ifdef SOAPY_SDR_API_HAS_RANGE_TYPE_STEP
if (r.step() != 0.0) step = r.step();
#endif
return osmosdr::gain_range_t(r.minimum(), r.maximum(), step);
}
boost::mutex &get_soapy_maker_mutex(void)
{
static boost::mutex m;
return m;
}

@ -0,0 +1,40 @@
/* -*- c++ -*- */
/*
* Copyright 2017 Josh Blum <josh@joshknows.com>
*
* 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.
*/
#ifndef INCLUDED_SOAPY_COMMON_H
#define INCLUDED_SOAPY_COMMON_H
#include <osmosdr/ranges.h>
#include <SoapySDR/Types.hpp>
#include <boost/thread/mutex.hpp>
/*!
* Convert a soapy range to a gain range.
* Careful to deal with the step size when zero.
*/
osmosdr::gain_range_t soapy_range_to_gain_range(const SoapySDR::Range &r);
/*!
* Global mutex to protect factory routines.
* (optional under 0.5 release above)
*/
boost::mutex &get_soapy_maker_mutex(void);
#endif /* INCLUDED_SOAPY_COMMON_H */

@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
* Copyright 2015-2016 Josh Blum <josh@joshknows.com>
* Copyright 2015-2017 Josh Blum <josh@joshknows.com>
* Copyright 2013 Dimitri Stolnikov <horiz0n@gmx.net>
*
* GNU Radio is free software; you can redistribute it and/or modify
@ -38,17 +38,12 @@
#include "arg_helpers.h"
#include "soapy_sink_c.h"
#include "soapy_common.h"
#include <SoapySDR/Device.hpp>
#include <SoapySDR/Version.hpp>
using namespace boost::assign;
boost::mutex &get_soapy_maker_mutex(void)
{
static boost::mutex m;
return m;
}
/*
* Create a new instance of soapy_sink_c and return
* a boost shared_ptr. This is effectively the public constructor.
@ -185,14 +180,14 @@ std::vector<std::string> soapy_sink_c::get_gain_names( size_t chan)
osmosdr::gain_range_t soapy_sink_c::get_gain_range( size_t chan)
{
SoapySDR::Range r = _device->getGainRange(SOAPY_SDR_TX, chan);
return osmosdr::gain_range_t(r.minimum(), r.maximum(), 1.0);
return soapy_range_to_gain_range(r);
}
osmosdr::gain_range_t soapy_sink_c::get_gain_range( const std::string & name,
size_t chan)
{
SoapySDR::Range r = _device->getGainRange(SOAPY_SDR_TX, chan, name);
return osmosdr::gain_range_t(r.minimum(), r.maximum(), 1.0);
return soapy_range_to_gain_range(r);
}
bool soapy_sink_c::set_gain_mode( bool automatic, size_t chan)

@ -1,6 +1,6 @@
/* -*- c++ -*- */
/*
* Copyright 2015-2016 Josh Blum <josh@joshknows.com>
* Copyright 2015-2017 Josh Blum <josh@joshknows.com>
* Copyright 2013 Dimitri Stolnikov <horiz0n@gmx.net>
*
* GNU Radio is free software; you can redistribute it and/or modify
@ -38,14 +38,13 @@
#include "arg_helpers.h"
#include "soapy_source_c.h"
#include "soapy_common.h"
#include "osmosdr/source.h"
#include <SoapySDR/Device.hpp>
#include <SoapySDR/Version.hpp>
using namespace boost::assign;
boost::mutex &get_soapy_maker_mutex(void);
/*
* Create a new instance of soapy_source_c and return
* a boost shared_ptr. This is effectively the public constructor.
@ -182,14 +181,14 @@ std::vector<std::string> soapy_source_c::get_gain_names( size_t chan )
osmosdr::gain_range_t soapy_source_c::get_gain_range( size_t chan )
{
SoapySDR::Range r = _device->getGainRange(SOAPY_SDR_RX, chan);
return osmosdr::gain_range_t(r.minimum(), r.maximum(), 1.0);
return soapy_range_to_gain_range(r);
}
osmosdr::gain_range_t soapy_source_c::get_gain_range( const std::string & name,
size_t chan )
{
SoapySDR::Range r = _device->getGainRange(SOAPY_SDR_RX, chan, name);
return osmosdr::gain_range_t(r.minimum(), r.maximum(), 1.0);
return soapy_range_to_gain_range(r);
}
bool soapy_source_c::set_gain_mode( bool automatic, size_t chan )

Loading…
Cancel
Save