diff options
author | Josh Blum <josh@joshknows.com> | 2010-03-15 17:00:04 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-03-15 17:00:04 +0000 |
commit | 1bfb556262d12740c71e68a2a071e6e67ed2b3e7 (patch) | |
tree | a081bfd3a61ccb42372a627be7b57ce19a3baa0d /host/test/gain_handler_test.cpp | |
parent | 1b965831ae7588c7879d84de4e5fbd78ca614761 (diff) | |
parent | fc40ff2f1327d01c72c4d7dbc07a14e473251981 (diff) | |
download | uhd-1bfb556262d12740c71e68a2a071e6e67ed2b3e7.tar.gz uhd-1bfb556262d12740c71e68a2a071e6e67ed2b3e7.tar.bz2 uhd-1bfb556262d12740c71e68a2a071e6e67ed2b3e7.zip |
Merge branch 'master' of git@ettus.sourcerepo.com:ettus/uhd into u1e_uhd
Conflicts:
host/apps/CMakeLists.txt
host/lib/usrp/usrp2/usrp2_impl.cpp
Diffstat (limited to 'host/test/gain_handler_test.cpp')
-rw-r--r-- | host/test/gain_handler_test.cpp | 88 |
1 files changed, 41 insertions, 47 deletions
diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp index c81221aac..a4005c0de 100644 --- a/host/test/gain_handler_test.cpp +++ b/host/test/gain_handler_test.cpp @@ -17,33 +17,36 @@ #include <boost/test/unit_test.hpp> #include <uhd/gain_handler.hpp> +#include <uhd/props.hpp> #include <uhd/dict.hpp> +#include <boost/bind.hpp> #include <iostream> using namespace uhd; enum prop_t{ - PROP_GAIN, - PROP_GAIN_MIN, - PROP_GAIN_MAX, - PROP_GAIN_STEP, + PROP_GAIN_VALUE, + PROP_GAIN_RANGE, PROP_GAIN_NAMES }; class gainful_obj : public wax::obj{ public: gainful_obj(void){ - _gain_handler = gain_handler::sptr(new gain_handler( - this, PROP_GAIN, PROP_GAIN_MIN, PROP_GAIN_MAX, PROP_GAIN_STEP, PROP_GAIN_NAMES - )); - _gains["g0"] = 0; - _gains["g1"] = 0; - _gains_min["g0"] = -10; - _gains_min["g1"] = 0; - _gains_max["g0"] = 0; - _gains_max["g1"] = 100; - _gains_step["g0"] = .1; - _gains_step["g1"] = 1.5; + //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, .1); + _gain_ranges["g1"] = gain_range_t(0, 100, 1.5); } ~gainful_obj(void){} @@ -56,25 +59,17 @@ private: boost::tie(key, name) = extract_named_prop(key_); //handle the get request conditioned on the key - switch(wax::cast<prop_t>(key)){ - case PROP_GAIN: - val = _gains[name]; + switch(key.as<prop_t>()){ + case PROP_GAIN_VALUE: + val = _gain_values[name]; return; - case PROP_GAIN_MIN: - val = _gains_min[name]; - return; - - case PROP_GAIN_MAX: - val = _gains_max[name]; - return; - - case PROP_GAIN_STEP: - val = _gains_step[name]; + case PROP_GAIN_RANGE: + val = _gain_ranges[name]; return; case PROP_GAIN_NAMES: - val = prop_names_t(_gains.get_keys()); + val = _gain_values.get_keys(); return; } } @@ -86,24 +81,20 @@ private: boost::tie(key, name) = extract_named_prop(key_); //handle the get request conditioned on the key - switch(wax::cast<prop_t>(key)){ - case PROP_GAIN: - _gains[name] = wax::cast<gain_t>(val); + switch(key.as<prop_t>()){ + case PROP_GAIN_VALUE: + _gain_values[name] = val.as<gain_t>(); return; - case PROP_GAIN_MIN: - case PROP_GAIN_MAX: - case PROP_GAIN_STEP: + case PROP_GAIN_RANGE: case PROP_GAIN_NAMES: throw std::runtime_error("cannot set this property"); } } gain_handler::sptr _gain_handler; - uhd::dict<std::string, gain_t> _gains; - uhd::dict<std::string, gain_t> _gains_min; - uhd::dict<std::string, gain_t> _gains_max; - uhd::dict<std::string, gain_t> _gains_step; + uhd::dict<std::string, gain_t> _gain_values; + uhd::dict<std::string, gain_range_t> _gain_ranges; }; @@ -112,17 +103,20 @@ BOOST_AUTO_TEST_CASE(test_gain_handler){ gainful_obj go0; BOOST_CHECK_THROW( - wax::cast<gain_t>(go0[named_prop_t(PROP_GAIN, "fail")]), - std::invalid_argument + go0[named_prop_t(PROP_GAIN_VALUE, "fail")].as<gain_t>(), + std::exception ); std::cout << "verifying the overall min, max, step" << std::endl; - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_MIN]), gain_t(-10)); - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_MAX]), gain_t(100)); - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN_STEP]), gain_t(1.5)); + gain_t gain_min, gain_max, gain_step; + boost::tie(gain_min, gain_max, gain_step) = \ + go0[PROP_GAIN_RANGE].as<gain_range_t>(); + BOOST_CHECK_EQUAL(gain_min, gain_t(-10)); + BOOST_CHECK_EQUAL(gain_max, gain_t(100)); + BOOST_CHECK_EQUAL(gain_step, gain_t(1.5)); std::cout << "verifying the overall gain" << std::endl; - go0[named_prop_t(PROP_GAIN, "g0")] = gain_t(-5); - go0[named_prop_t(PROP_GAIN, "g1")] = gain_t(30); - BOOST_CHECK_EQUAL(wax::cast<gain_t>(go0[PROP_GAIN]), gain_t(25)); + go0[named_prop_t(PROP_GAIN_VALUE, "g0")] = gain_t(-5); + go0[named_prop_t(PROP_GAIN_VALUE, "g1")] = gain_t(30); + BOOST_CHECK_EQUAL(go0[PROP_GAIN_VALUE].as<gain_t>(), gain_t(25)); } |