summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-24 00:11:44 -0700
committerJosh Blum <josh@joshknows.com>2010-07-27 15:45:49 -0700
commitd769ff8cc3dbb579b3c050a9b184f2bdd5c9a71d (patch)
tree7a51aebff51c48a8b7d3fb833ebbaa641076a168 /host
parent9775ddc5215b0d5c950757ac6ae1d3226784f670 (diff)
downloaduhd-d769ff8cc3dbb579b3c050a9b184f2bdd5c9a71d.tar.gz
uhd-d769ff8cc3dbb579b3c050a9b184f2bdd5c9a71d.tar.bz2
uhd-d769ff8cc3dbb579b3c050a9b184f2bdd5c9a71d.zip
usrp: removed gain handler code (replaced by gain group)
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/utils/CMakeLists.txt1
-rw-r--r--host/include/uhd/utils/gain_handler.hpp90
-rw-r--r--host/lib/CMakeLists.txt1
-rw-r--r--host/lib/gain_handler.cpp177
-rw-r--r--host/lib/usrp/dboard_manager.cpp23
-rw-r--r--host/test/CMakeLists.txt1
-rw-r--r--host/test/gain_handler_test.cpp121
-rw-r--r--host/utils/uhd_usrp_probe.cpp2
8 files changed, 4 insertions, 412 deletions
diff --git a/host/include/uhd/utils/CMakeLists.txt b/host/include/uhd/utils/CMakeLists.txt
index 4a5f20e3c..f7feab5a8 100644
--- a/host/include/uhd/utils/CMakeLists.txt
+++ b/host/include/uhd/utils/CMakeLists.txt
@@ -23,7 +23,6 @@ INSTALL(FILES
byteswap.ipp
exception.hpp
gain_group.hpp
- gain_handler.hpp
pimpl.hpp
props.hpp
safe_main.hpp
diff --git a/host/include/uhd/utils/gain_handler.hpp b/host/include/uhd/utils/gain_handler.hpp
deleted file mode 100644
index f4629e6a7..000000000
--- a/host/include/uhd/utils/gain_handler.hpp
+++ /dev/null
@@ -1,90 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#ifndef INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP
-#define INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP
-
-#include <uhd/config.hpp>
-#include <uhd/wax.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/function.hpp>
-
-namespace uhd{
-
-class UHD_API gain_handler{
-public:
- typedef boost::shared_ptr<gain_handler> sptr;
- typedef boost::function<bool(const wax::obj &, const wax::obj &)> is_equal_t;
-
- /*!
- * A set of properties for dealing with gains.
- */
- struct UHD_API props_t{
- wax::obj value, range, names;
- props_t(void); //default constructor
- };
-
- /*!
- * Make a new gain handler.
- * The construction arguments are agnostic to the property type.
- * It is up to the caller to provide an "is_equal" function that
- * can tell weather two properties (in a wax obj) are equal.
- * \param link a link to the wax obj with properties
- * \param props a struct of properties keys
- * \param is_equal the function that tests for equal properties
- */
- static sptr make(
- const wax::obj &link,
- const props_t &props,
- is_equal_t is_equal
- );
-
- /*!
- * Intercept gets for overall gain, min, max, step.
- * Ensures that the gain name is valid.
- * \return true for handled, false to pass on
- */
- virtual bool intercept_get(const wax::obj &key, wax::obj &val) = 0;
-
- /*!
- * Intercept sets for overall gain.
- * Ensures that the gain name is valid.
- * Ensures that the new gain is within range.
- * \return true for handled, false to pass on
- */
- virtual bool intercept_set(const wax::obj &key, const wax::obj &val) = 0;
-
- /*!
- * Function template to test if two wax types are equal:
- * The constructor will bind an instance of this for a specific type.
- * This bound equals functions allows the intercept methods to be non-templated.
- */
- template <class T> static bool is_equal(const wax::obj &a, const wax::obj &b){
- try{
- return a.as<T>() == b.as<T>();
- }
- catch(const wax::bad_cast &){
- return false;
- }
- }
-
-};
-
-} //namespace uhd
-
-#endif /* INCLUDED_UHD_UTILS_GAIN_HANDLER_HPP */
-
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index 010478821..4899d3dbc 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -113,7 +113,6 @@ CONFIGURE_FILE(
LIBUHD_APPEND_SOURCES(
${CMAKE_CURRENT_SOURCE_DIR}/device.cpp
${CMAKE_CURRENT_SOURCE_DIR}/gain_group.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/gain_handler.cpp
${CMAKE_CURRENT_SOURCE_DIR}/load_modules.cpp
${CMAKE_CURRENT_SOURCE_DIR}/thread_priority.cpp
${CMAKE_CURRENT_SOURCE_DIR}/types.cpp
diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp
deleted file mode 100644
index 36e2e8ed3..000000000
--- a/host/lib/gain_handler.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include <uhd/utils/gain_handler.hpp>
-#include <uhd/utils/assert.hpp>
-#include <uhd/types/ranges.hpp>
-#include <uhd/utils/props.hpp>
-#include <boost/assign/list_of.hpp>
-#include <boost/foreach.hpp>
-#include <boost/format.hpp>
-#include <cmath>
-#include <vector>
-
-using namespace uhd;
-
-/***********************************************************************
- * gain handler implementation interface
- **********************************************************************/
-class gain_handler_impl : public gain_handler{
-public:
- gain_handler_impl(
- const wax::obj &link,
- const props_t &props,
- is_equal_t is_equal
- );
- ~gain_handler_impl(void);
- bool intercept_get(const wax::obj &key, wax::obj &val);
- bool intercept_set(const wax::obj &key, const wax::obj &val);
-
-private:
- wax::obj _link;
- props_t _props;
- is_equal_t _is_equal;
-
- prop_names_t get_gain_names(void);
- float get_overall_gain_val(void);
- gain_range_t get_overall_gain_range(void);
- template <class T> T get_named_prop(const wax::obj &prop, const std::string &name){
- return _link[named_prop_t(prop, name)].as<T>();
- }
-};
-
-/***********************************************************************
- * the make function
- **********************************************************************/
-gain_handler::sptr gain_handler::make(
- const wax::obj &link,
- const props_t &props,
- is_equal_t is_equal
-){
- return sptr(new gain_handler_impl(link, props, is_equal));
-}
-
-/***********************************************************************
- * gain handler implementation methods
- **********************************************************************/
-gain_handler::props_t::props_t(void){
- /* NOP */
-}
-
-gain_handler_impl::gain_handler_impl(
- const wax::obj &link,
- const props_t &props,
- is_equal_t is_equal
-){
- _link = link;
- _props = props;
- _is_equal = is_equal;
-}
-
-gain_handler_impl::~gain_handler_impl(void){
- /* NOP */
-}
-
-prop_names_t gain_handler_impl::get_gain_names(void){
- return _link[_props.names].as<prop_names_t>();
-}
-
-float gain_handler_impl::get_overall_gain_val(void){
- float gain_val = 0;
- BOOST_FOREACH(std::string name, get_gain_names()){
- gain_val += get_named_prop<float>(_props.value, name);
- }
- return gain_val;
-}
-
-gain_range_t gain_handler_impl::get_overall_gain_range(void){
- float gain_min = 0, gain_max = 0, gain_step = 0;
- BOOST_FOREACH(std::string name, get_gain_names()){
- gain_range_t floatmp = get_named_prop<gain_range_t>(_props.range, name);
- gain_min += floatmp.min;
- gain_max += floatmp.max;
- gain_step = std::max(gain_step, floatmp.step);
- }
- return gain_range_t(gain_min, gain_max, gain_step);
-}
-
-/***********************************************************************
- * gain handler implementation get method
- **********************************************************************/
-bool gain_handler_impl::intercept_get(const wax::obj &key_, wax::obj &val){
- wax::obj key; std::string name;
- boost::tie(key, name) = extract_named_prop(key_);
-
- //not a wildcard... dont handle (but check name)
- if (name != ""){
- assert_has(get_gain_names(), name, "gain name");
- return false;
- }
-
- if (_is_equal(key, _props.value)){
- val = get_overall_gain_val();
- return true;
- }
-
- if (_is_equal(key, _props.range)){
- val = get_overall_gain_range();
- return true;
- }
-
- return false; //not handled
-}
-
-/***********************************************************************
- * gain handler implementation set method
- **********************************************************************/
-bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val){
- wax::obj key; std::string name;
- boost::tie(key, name) = extract_named_prop(key_);
-
- //not a gain value key... dont handle
- if (not _is_equal(key, _props.value)) return false;
-
- float gain_val = val.as<float>();
-
- //not a wildcard... dont handle (but check name and range)
- if (name != ""){
- assert_has(get_gain_names(), name, "gain name");
- gain_range_t gain = get_named_prop<gain_range_t>(_props.range, name);
- if (gain_val > gain.max or gain_val < gain.min) throw std::range_error(str(
- boost::format("A value of %f for gain %s is out of range of (%f, %f)")
- % gain_val % name % gain.min % gain.max
- ));
- return false;
- }
-
- //set the overall gain
- BOOST_FOREACH(std::string name, get_gain_names()){
- //get the min, max, step for this gain name
- gain_range_t gain = get_named_prop<gain_range_t>(_props.range, name);
-
- //clip g to be within the allowed range
- float g = std::min(std::max(gain_val, gain.min), gain.max);
- //set g to be a multiple of the step size
- g -= std::fmod(g, gain.step);
- //set g to be the new gain
- _link[named_prop_t(_props.value, name)] = g;
- //subtract g out of the total gain left to apply
- gain_val -= g;
- }
-
- return true;
-}
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index bfaaf0969..ab80875f5 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -18,7 +18,6 @@
#include "dboard_ctor_args.hpp"
#include <uhd/usrp/dboard_manager.hpp>
#include <uhd/usrp/subdev_props.hpp>
-#include <uhd/utils/gain_handler.hpp>
#include <uhd/utils/static.hpp>
#include <uhd/utils/assert.hpp>
#include <uhd/types/dict.hpp>
@@ -98,33 +97,18 @@ public:
enum type_t{RX_TYPE, TX_TYPE};
//structors
- subdev_proxy(dboard_base::sptr subdev, type_t type)
- : _subdev(subdev), _type(type){
- //initialize gain props struct
- gain_handler::props_t gain_props;
- gain_props.value = SUBDEV_PROP_GAIN;
- gain_props.range = SUBDEV_PROP_GAIN_RANGE;
- gain_props.names = SUBDEV_PROP_GAIN_NAMES;
-
- //make a new gain handler
- _gain_handler = gain_handler::make(
- this->get_link(), gain_props,
- boost::bind(&gain_handler::is_equal<subdev_prop_t>, _1, _2)
- );
- }
-
- ~subdev_proxy(void){
+ subdev_proxy(dboard_base::sptr subdev, type_t type):
+ _subdev(subdev), _type(type)
+ {
/* NOP */
}
private:
- gain_handler::sptr _gain_handler;
dboard_base::sptr _subdev;
type_t _type;
//forward the get calls to the rx or tx
void get(const wax::obj &key, wax::obj &val){
- if (_gain_handler->intercept_get(key, val)) return;
switch(_type){
case RX_TYPE: return _subdev->rx_get(key, val);
case TX_TYPE: return _subdev->tx_get(key, val);
@@ -133,7 +117,6 @@ private:
//forward the set calls to the rx or tx
void set(const wax::obj &key, const wax::obj &val){
- if (_gain_handler->intercept_set(key, val)) return;
switch(_type){
case RX_TYPE: return _subdev->rx_set(key, val);
case TX_TYPE: return _subdev->tx_set(key, val);
diff --git a/host/test/CMakeLists.txt b/host/test/CMakeLists.txt
index 25cae6e7f..37832edde 100644
--- a/host/test/CMakeLists.txt
+++ b/host/test/CMakeLists.txt
@@ -27,7 +27,6 @@ ADD_EXECUTABLE(main_test
dict_test.cpp
error_test.cpp
gain_group_test.cpp
- gain_handler_test.cpp
tune_helper_test.cpp
vrt_test.cpp
wax_test.cpp
diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp
deleted file mode 100644
index 5a9f2b714..000000000
--- a/host/test/gain_handler_test.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-//
-// Copyright 2010 Ettus Research LLC
-//
-// This program 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 of the License, or
-// (at your option) any later version.
-//
-// This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
-//
-
-#include <boost/test/unit_test.hpp>
-#include <uhd/utils/gain_handler.hpp>
-#include <uhd/types/ranges.hpp>
-#include <uhd/types/dict.hpp>
-#include <uhd/utils/props.hpp>
-#include <boost/bind.hpp>
-#include <iostream>
-
-using namespace uhd;
-
-enum prop_t{
- PROP_GAIN_VALUE,
- PROP_GAIN_RANGE,
- PROP_GAIN_NAMES
-};
-
-class gainful_obj : public wax::obj{
-public:
- gainful_obj(void){
- //initialize gain props struct
- gain_handler::props_t gain_props;
- gain_props.value = PROP_GAIN_VALUE;
- gain_props.range = PROP_GAIN_RANGE;
- gain_props.names = PROP_GAIN_NAMES;
- //make a new gain handler
- _gain_handler = gain_handler::make(
- this->get_link(), gain_props,
- boost::bind(&gain_handler::is_equal<prop_t>, _1, _2)
- );
- _gain_values["g0"] = 0;
- _gain_values["g1"] = 0;
- _gain_ranges["g0"] = gain_range_t(-10, 0, float(.1));
- _gain_ranges["g1"] = gain_range_t(0, 100, float(1.5));
- }
-
- ~gainful_obj(void){}
-
-private:
- void get(const wax::obj &key_, wax::obj &val){
- if (_gain_handler->intercept_get(key_, val)) return;
-
- wax::obj key; std::string name;
- boost::tie(key, name) = extract_named_prop(key_);
-
- //handle the get request conditioned on the key
- switch(key.as<prop_t>()){
- case PROP_GAIN_VALUE:
- val = _gain_values[name];
- return;
-
- case PROP_GAIN_RANGE:
- val = _gain_ranges[name];
- return;
-
- case PROP_GAIN_NAMES:
- val = _gain_values.keys();
- return;
-
- default: UHD_THROW_PROP_GET_ERROR();
- }
- }
-
- void set(const wax::obj &key_, const wax::obj &val){
- if (_gain_handler->intercept_set(key_, val)) return;
-
- wax::obj key; std::string name;
- boost::tie(key, name) = extract_named_prop(key_);
-
- //handle the get request conditioned on the key
- switch(key.as<prop_t>()){
- case PROP_GAIN_VALUE:
- _gain_values[name] = val.as<float>();
- return;
-
- default: UHD_THROW_PROP_SET_ERROR();
- }
- }
-
- gain_handler::sptr _gain_handler;
- uhd::dict<std::string, float> _gain_values;
- uhd::dict<std::string, gain_range_t> _gain_ranges;
-
-};
-
-BOOST_AUTO_TEST_CASE(test_gain_handler){
- std::cout << "Testing the gain handler..." << std::endl;
- gainful_obj go0;
-
- BOOST_CHECK_THROW(
- go0[named_prop_t(PROP_GAIN_VALUE, "fail")].as<float>(),
- std::exception
- );
-
- std::cout << "verifying the overall min, max, step" << std::endl;
- gain_range_t gain = go0[PROP_GAIN_RANGE].as<gain_range_t>();
- BOOST_CHECK_EQUAL(gain.min, float(-10));
- BOOST_CHECK_EQUAL(gain.max, float(100));
- BOOST_CHECK_EQUAL(gain.step, float(1.5));
-
- std::cout << "verifying the overall gain" << std::endl;
- go0[named_prop_t(PROP_GAIN_VALUE, "g0")] = float(-5);
- go0[named_prop_t(PROP_GAIN_VALUE, "g1")] = float(30);
- BOOST_CHECK_EQUAL(go0[PROP_GAIN_VALUE].as<float>(), float(25));
-}
diff --git a/host/utils/uhd_usrp_probe.cpp b/host/utils/uhd_usrp_probe.cpp
index 9587ea9a3..097317516 100644
--- a/host/utils/uhd_usrp_probe.cpp
+++ b/host/utils/uhd_usrp_probe.cpp
@@ -89,7 +89,7 @@ static std::string get_subdev_pp_string(const std::string &type, wax::obj subdev
ss << boost::format("Gain range %s: %.1f to %.1f step %.1f dB") % gain_name % gain_range.min % gain_range.max % gain_range.step << std::endl;
}
- ss << boost::format("Connection Type: %c") % (subdev[usrp::SUBDEV_PROP_CONNECTION].as<usrp::subdev_conn_t>()) << std::endl;
+ ss << boost::format("Connection Type: %c") % char(subdev[usrp::SUBDEV_PROP_CONNECTION].as<usrp::subdev_conn_t>()) << std::endl;
ss << boost::format("Uses LO offset: %s") % (subdev[usrp::SUBDEV_PROP_USE_LO_OFFSET].as<bool>()? "Yes" : "No") << std::endl;
return ss.str();