aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/soapy/CMakeLists.txt1
-rw-r--r--lib/soapy/soapy_common.cc43
-rw-r--r--lib/soapy/soapy_common.h40
-rw-r--r--lib/soapy/soapy_sink_c.cc13
-rw-r--r--lib/soapy/soapy_source_c.cc9
5 files changed, 92 insertions, 14 deletions
diff --git a/lib/soapy/CMakeLists.txt b/lib/soapy/CMakeLists.txt
index 6ada023..338bcaf 100644
--- a/lib/soapy/CMakeLists.txt
+++ b/lib/soapy/CMakeLists.txt
@@ -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
)
diff --git a/lib/soapy/soapy_common.cc b/lib/soapy/soapy_common.cc
new file mode 100644
index 0000000..0e277e4
--- /dev/null
+++ b/lib/soapy/soapy_common.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;
+}
diff --git a/lib/soapy/soapy_common.h b/lib/soapy/soapy_common.h
new file mode 100644
index 0000000..87e46a5
--- /dev/null
+++ b/lib/soapy/soapy_common.h
@@ -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 */
diff --git a/lib/soapy/soapy_sink_c.cc b/lib/soapy/soapy_sink_c.cc
index 9e3c364..1af5a65 100644
--- a/lib/soapy/soapy_sink_c.cc
+++ b/lib/soapy/soapy_sink_c.cc
@@ -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)
diff --git a/lib/soapy/soapy_source_c.cc b/lib/soapy/soapy_source_c.cc
index 608138e..d066ed8 100644
--- a/lib/soapy/soapy_source_c.cc
+++ b/lib/soapy/soapy_source_c.cc
@@ -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 )