summaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-03-12 16:01:01 -0800
committerJosh Blum <josh@joshknows.com>2010-03-12 16:01:01 -0800
commit2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2 (patch)
tree48dbcb58924a3c547979cb4a95a5de35278aeec1 /host
parentdaed43a8a873ad5cc16ac8a3eb6db5a8fe126fa5 (diff)
downloaduhd-2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2.tar.gz
uhd-2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2.tar.bz2
uhd-2147c5f61c2eb6ef1a68419d7b1041a54cbb14a2.zip
Removed freq min and max and gain min, max, and step...
replaced it with gain and freq range tuples. This simplifies the api calls and subdev properties.
Diffstat (limited to 'host')
-rw-r--r--host/include/uhd/gain_handler.hpp14
-rw-r--r--host/include/uhd/props.hpp13
-rw-r--r--host/include/uhd/simple_device.hpp14
-rw-r--r--host/include/uhd/utils.hpp5
-rw-r--r--host/lib/gain_handler.cpp98
-rw-r--r--host/lib/simple_device.cpp56
-rw-r--r--host/lib/usrp/dboard/basic.cpp44
-rw-r--r--host/lib/usrp/dboard_manager.cpp13
-rw-r--r--host/test/gain_handler_test.cpp80
9 files changed, 131 insertions, 206 deletions
diff --git a/host/include/uhd/gain_handler.hpp b/host/include/uhd/gain_handler.hpp
index fade86f53..2d3f8a3f4 100644
--- a/host/include/uhd/gain_handler.hpp
+++ b/host/include/uhd/gain_handler.hpp
@@ -32,13 +32,9 @@ public:
/*!
* A set of properties for dealing with gains.
*/
- struct gain_props_t{
- wax::obj gain_val_prop;
- wax::obj gain_min_prop;
- wax::obj gain_max_prop;
- wax::obj gain_step_prop;
- wax::obj gain_names_prop;
- gain_props_t(void); //default constructor
+ struct props_t{
+ wax::obj value, range, names;
+ props_t(void); //default constructor
};
/*!
@@ -47,12 +43,12 @@ public:
* 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 gain_props a struct of properties keys
+ * \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 gain_props_t &gain_props,
+ const props_t &props,
is_equal_t is_equal
);
diff --git a/host/include/uhd/props.hpp b/host/include/uhd/props.hpp
index dea2baf52..f2ba1769f 100644
--- a/host/include/uhd/props.hpp
+++ b/host/include/uhd/props.hpp
@@ -30,6 +30,12 @@ namespace uhd{
typedef float gain_t;
typedef double freq_t;
+ //gain range tuple (min, max, step)
+ typedef boost::tuple<gain_t, gain_t, gain_t> gain_range_t;
+
+ //freq range tuple (min, max)
+ typedef boost::tuple<freq_t, freq_t> freq_range_t;
+
//scalar types (have not used yet, dont uncomment until needed)
//typedef int int_scalar_t;
//typedef float real_scalar_t;
@@ -143,13 +149,10 @@ namespace uhd{
SUBDEV_PROP_NAME, //ro, std::string
SUBDEV_PROP_OTHERS, //ro, prop_names_t
SUBDEV_PROP_GAIN, //rw, gain_t
- SUBDEV_PROP_GAIN_MAX, //ro, gain_t
- SUBDEV_PROP_GAIN_MIN, //ro, gain_t
- SUBDEV_PROP_GAIN_STEP, //ro, gain_t
+ SUBDEV_PROP_GAIN_RANGE, //ro, gain_range_t
SUBDEV_PROP_GAIN_NAMES, //ro, prop_names_t
SUBDEV_PROP_FREQ, //rw, freq_t
- SUBDEV_PROP_FREQ_MAX, //ro, freq_t
- SUBDEV_PROP_FREQ_MIN, //ro, freq_t
+ SUBDEV_PROP_FREQ_RANGE, //ro, freq_range_t
SUBDEV_PROP_ANTENNA, //rw, std::string
SUBDEV_PROP_ANTENNA_NAMES, //ro, prop_names_t
SUBDEV_PROP_ENABLED, //rw, bool
diff --git a/host/include/uhd/simple_device.hpp b/host/include/uhd/simple_device.hpp
index 69f13a8b5..c43155ff2 100644
--- a/host/include/uhd/simple_device.hpp
+++ b/host/include/uhd/simple_device.hpp
@@ -71,14 +71,11 @@ public:
virtual std::vector<double> get_rx_rates(void) = 0;
virtual tune_result_t set_rx_freq(double freq) = 0;
- virtual double get_rx_freq_min(void) = 0;
- virtual double get_rx_freq_max(void) = 0;
+ virtual std::vector<double> get_rx_freq_range(void) = 0;
virtual void set_rx_gain(float gain) = 0;
virtual float get_rx_gain(void) = 0;
- virtual float get_rx_gain_min(void) = 0;
- virtual float get_rx_gain_max(void) = 0;
- virtual float get_rx_gain_step(void) = 0;
+ virtual std::vector<float> get_rx_gain_range(void) = 0;
virtual void set_rx_antenna(const std::string &ant) = 0;
virtual std::string get_rx_antenna(void) = 0;
@@ -92,14 +89,11 @@ public:
virtual std::vector<double> get_tx_rates(void) = 0;
virtual tune_result_t set_tx_freq(double freq) = 0;
- virtual double get_tx_freq_min(void) = 0;
- virtual double get_tx_freq_max(void) = 0;
+ virtual std::vector<double> get_tx_freq_range(void) = 0;
virtual void set_tx_gain(float gain) = 0;
virtual float get_tx_gain(void) = 0;
- virtual float get_tx_gain_min(void) = 0;
- virtual float get_tx_gain_max(void) = 0;
- virtual float get_tx_gain_step(void) = 0;
+ virtual std::vector<float> get_tx_gain_range(void) = 0;
virtual void set_tx_antenna(const std::string &ant) = 0;
virtual std::string get_tx_antenna(void) = 0;
diff --git a/host/include/uhd/utils.hpp b/host/include/uhd/utils.hpp
index 5d6a18b3a..2f6e4fd87 100644
--- a/host/include/uhd/utils.hpp
+++ b/host/include/uhd/utils.hpp
@@ -70,11 +70,6 @@ namespace std{
return has(iterable.begin(), iterable.end(), elem);
}
- template<class T>
- T sum(const T &a, const T &b){
- return a + b;
- }
-
template<typename T> T signum(T n){
if (n < 0) return -1;
if (n > 0) return 1;
diff --git a/host/lib/gain_handler.cpp b/host/lib/gain_handler.cpp
index 8f840ae7f..7eb87558c 100644
--- a/host/lib/gain_handler.cpp
+++ b/host/lib/gain_handler.cpp
@@ -26,23 +26,13 @@
using namespace uhd;
/***********************************************************************
- * helper functions
- **********************************************************************/
-static gain_t gain_max(gain_t a, gain_t b){
- return std::max(a, b);
-}
-static gain_t gain_sum(gain_t a, gain_t b){
- return std::sum(a, b);
-}
-
-/***********************************************************************
* gain handler implementation interface
**********************************************************************/
class gain_handler_impl : public gain_handler{
public:
gain_handler_impl(
const wax::obj &link,
- const gain_props_t &gain_props,
+ const props_t &props,
is_equal_t is_equal
);
~gain_handler_impl(void);
@@ -51,15 +41,15 @@ public:
private:
wax::obj _link;
- gain_props_t _gain_props;
+ props_t _props;
is_equal_t _is_equal;
prop_names_t get_gain_names(void);
- std::vector<gain_t> get_gains(const wax::obj &prop_key);
gain_t get_overall_gain_val(void);
- gain_t get_overall_gain_min(void);
- gain_t get_overall_gain_max(void);
- gain_t get_overall_gain_step(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 wax::cast<T>(_link[named_prop_t(prop, name)]);
+ }
};
/***********************************************************************
@@ -67,26 +57,26 @@ private:
**********************************************************************/
gain_handler::sptr gain_handler::make(
const wax::obj &link,
- const gain_props_t &gain_props,
+ const props_t &props,
is_equal_t is_equal
){
- return sptr(new gain_handler_impl(link, gain_props, is_equal));
+ return sptr(new gain_handler_impl(link, props, is_equal));
}
/***********************************************************************
* gain handler implementation methods
**********************************************************************/
-gain_handler::gain_props_t::gain_props_t(void){
+gain_handler::props_t::props_t(void){
/* NOP */
}
gain_handler_impl::gain_handler_impl(
const wax::obj &link,
- const gain_props_t &gain_props,
+ const props_t &props,
is_equal_t is_equal
){
_link = link;
- _gain_props = gain_props;
+ _props = props;
_is_equal = is_equal;
}
@@ -95,31 +85,28 @@ gain_handler_impl::~gain_handler_impl(void){
}
prop_names_t gain_handler_impl::get_gain_names(void){
- return wax::cast<prop_names_t>(_link[_gain_props.gain_names_prop]);
+ return wax::cast<prop_names_t>(_link[_props.names]);
}
-std::vector<gain_t> gain_handler_impl::get_gains(const wax::obj &prop_key){
- std::vector<gain_t> gains;
+gain_t gain_handler_impl::get_overall_gain_val(void){
+ gain_t gain_val = 0;
BOOST_FOREACH(std::string name, get_gain_names()){
- gains.push_back(wax::cast<gain_t>(_link[named_prop_t(prop_key, name)]));
+ gain_val += get_named_prop<gain_t>(_props.value, name);
}
- return gains;
-}
-
-gain_t gain_handler_impl::get_overall_gain_val(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_val_prop), gain_sum);
-}
-
-gain_t gain_handler_impl::get_overall_gain_min(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_min_prop), gain_sum);
-}
-
-gain_t gain_handler_impl::get_overall_gain_max(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_max_prop), gain_sum);
+ return gain_val;
}
-gain_t gain_handler_impl::get_overall_gain_step(void){
- return std::reduce<gain_t>(get_gains(_gain_props.gain_step_prop), gain_max);
+gain_range_t gain_handler_impl::get_overall_gain_range(void){
+ gain_t gain_min = 0, gain_max = 0, gain_step = 0;
+ BOOST_FOREACH(std::string name, get_gain_names()){
+ gain_t gain_min_tmp, gain_max_tmp, gain_step_tmp;
+ boost::tie(gain_min_tmp, gain_max_tmp, gain_step_tmp) = \
+ get_named_prop<gain_range_t>(_props.range, name);
+ gain_min += gain_min_tmp;
+ gain_max += gain_max_tmp;
+ gain_step = std::max(gain_step, gain_step_tmp);
+ }
+ return gain_range_t(gain_min, gain_max, gain_step);
}
/***********************************************************************
@@ -135,23 +122,13 @@ bool gain_handler_impl::intercept_get(const wax::obj &key_, wax::obj &val){
return false;
}
- if (_is_equal(key, _gain_props.gain_val_prop)){
+ if (_is_equal(key, _props.value)){
val = get_overall_gain_val();
return true;
}
- if (_is_equal(key, _gain_props.gain_min_prop)){
- val = get_overall_gain_min();
- return true;
- }
-
- if (_is_equal(key, _gain_props.gain_max_prop)){
- val = get_overall_gain_max();
- return true;
- }
-
- if (_is_equal(key, _gain_props.gain_step_prop)){
- val = get_overall_gain_step();
+ if (_is_equal(key, _props.range)){
+ val = get_overall_gain_range();
return true;
}
@@ -166,15 +143,16 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val)
boost::tie(key, name) = extract_named_prop(key_);
//not a gain value key... dont handle
- if (not _is_equal(key, _gain_props.gain_val_prop)) return false;
+ if (not _is_equal(key, _props.value)) return false;
gain_t gain_val = wax::cast<gain_t>(val);
//not a wildcard... dont handle (but check name and range)
if (name != ""){
assert_has(get_gain_names(), name, "gain name");
- gain_t gain_min = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_min_prop, name)]);
- gain_t gain_max = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_max_prop, name)]);
+ gain_t gain_min, gain_max, gain_step;
+ boost::tie(gain_min, gain_max, gain_step) = \
+ 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
@@ -185,16 +163,16 @@ bool gain_handler_impl::intercept_set(const wax::obj &key_, const wax::obj &val)
//set the overall gain
BOOST_FOREACH(std::string name, get_gain_names()){
//get the min, max, step for this gain name
- gain_t gain_min = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_min_prop, name)]);
- gain_t gain_max = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_max_prop, name)]);
- gain_t gain_step = wax::cast<gain_t>(_link[named_prop_t(_gain_props.gain_step_prop, name)]);
+ gain_t gain_min, gain_max, gain_step;
+ boost::tie(gain_min, gain_max, gain_step) = \
+ get_named_prop<gain_range_t>(_props.range, name);
//clip g to be within the allowed range
gain_t g = std::min(std::max(gain_val, gain_min), gain_max);
//set g to be a multiple of the step size
g -= fmod(g, gain_step);
//set g to be the new gain
- _link[named_prop_t(_gain_props.gain_val_prop, name)] = g;
+ _link[named_prop_t(_props.value, name)] = g;
//subtract g out of the total gain left to apply
gain_val -= g;
}
diff --git a/host/lib/simple_device.cpp b/host/lib/simple_device.cpp
index 76f3c1262..ac83ffaed 100644
--- a/host/lib/simple_device.cpp
+++ b/host/lib/simple_device.cpp
@@ -188,12 +188,11 @@ public:
return tune(target_freq, lo_offset, _rx_subdev, _rx_ddc, false/* not tx */);
}
- double get_rx_freq_min(void){
- return wax::cast<double>(_rx_subdev[SUBDEV_PROP_FREQ_MIN]);
- }
-
- double get_rx_freq_max(void){
- return wax::cast<double>(_rx_subdev[SUBDEV_PROP_FREQ_MAX]);
+ std::vector<double> get_rx_freq_range(void){
+ std::vector<double> range(2);
+ boost::tie(range[0], range[1]) = \
+ wax::cast<freq_range_t>(_rx_subdev[SUBDEV_PROP_FREQ_RANGE]);
+ return range;
}
void set_rx_gain(float gain){
@@ -201,19 +200,14 @@ public:
}
float get_rx_gain(void){
- return wax::cast<float>(_rx_subdev[SUBDEV_PROP_GAIN]);
- }
-
- float get_rx_gain_min(void){
- return wax::cast<float>(_rx_subdev[SUBDEV_PROP_GAIN_MIN]);
- }
-
- float get_rx_gain_max(void){
- return wax::cast<float>(_rx_subdev[SUBDEV_PROP_GAIN_MAX]);
+ return wax::cast<gain_t>(_rx_subdev[SUBDEV_PROP_GAIN]);
}
- float get_rx_gain_step(void){
- return wax::cast<float>(_rx_subdev[SUBDEV_PROP_GAIN_STEP]);
+ std::vector<float> get_rx_gain_range(void){
+ std::vector<float> range(3);
+ boost::tie(range[0], range[1], range[2]) = \
+ wax::cast<gain_range_t>(_rx_subdev[SUBDEV_PROP_GAIN_RANGE]);
+ return range;
}
void set_rx_antenna(const std::string &ant){
@@ -256,12 +250,11 @@ public:
return tune(target_freq, lo_offset, _tx_subdev, _tx_duc, true/* is tx */);
}
- double get_tx_freq_min(void){
- return wax::cast<double>(_tx_subdev[SUBDEV_PROP_FREQ_MIN]);
- }
-
- double get_tx_freq_max(void){
- return wax::cast<double>(_tx_subdev[SUBDEV_PROP_FREQ_MAX]);
+ std::vector<double> get_tx_freq_range(void){
+ std::vector<double> range(2);
+ boost::tie(range[0], range[1]) = \
+ wax::cast<freq_range_t>(_tx_subdev[SUBDEV_PROP_FREQ_RANGE]);
+ return range;
}
void set_tx_gain(float gain){
@@ -269,19 +262,14 @@ public:
}
float get_tx_gain(void){
- return wax::cast<float>(_tx_subdev[SUBDEV_PROP_GAIN]);
- }
-
- float get_tx_gain_min(void){
- return wax::cast<float>(_tx_subdev[SUBDEV_PROP_GAIN_MIN]);
- }
-
- float get_tx_gain_max(void){
- return wax::cast<float>(_tx_subdev[SUBDEV_PROP_GAIN_MAX]);
+ return wax::cast<gain_t>(_tx_subdev[SUBDEV_PROP_GAIN]);
}
- float get_tx_gain_step(void){
- return wax::cast<float>(_tx_subdev[SUBDEV_PROP_GAIN_STEP]);
+ std::vector<float> get_tx_gain_range(void){
+ std::vector<float> range(3);
+ boost::tie(range[0], range[1], range[2]) = \
+ wax::cast<gain_range_t>(_tx_subdev[SUBDEV_PROP_GAIN_RANGE]);
+ return range;
}
void set_tx_antenna(const std::string &ant){
diff --git a/host/lib/usrp/dboard/basic.cpp b/host/lib/usrp/dboard/basic.cpp
index 4b74e4a47..1059feb19 100644
--- a/host/lib/usrp/dboard/basic.cpp
+++ b/host/lib/usrp/dboard/basic.cpp
@@ -111,12 +111,13 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){
return;
case SUBDEV_PROP_GAIN:
- case SUBDEV_PROP_GAIN_MAX:
- case SUBDEV_PROP_GAIN_MIN:
- case SUBDEV_PROP_GAIN_STEP:
val = gain_t(0);
return;
+ case SUBDEV_PROP_GAIN_RANGE:
+ val = gain_range_t(0, 0, 0);
+ return;
+
case SUBDEV_PROP_GAIN_NAMES:
val = prop_names_t(); //empty
return;
@@ -125,12 +126,8 @@ void basic_rx::rx_get(const wax::obj &key_, wax::obj &val){
val = freq_t(0);
return;
- case SUBDEV_PROP_FREQ_MAX:
- val = +_max_freq;
- return;
-
- case SUBDEV_PROP_FREQ_MIN:
- val = -_max_freq;
+ case SUBDEV_PROP_FREQ_RANGE:
+ val = freq_range_t(+_max_freq, -_max_freq);
return;
case SUBDEV_PROP_ANTENNA:
@@ -177,13 +174,10 @@ void basic_rx::rx_set(const wax::obj &key_, const wax::obj &val){
case SUBDEV_PROP_NAME:
case SUBDEV_PROP_OTHERS:
- case SUBDEV_PROP_GAIN_MAX:
- case SUBDEV_PROP_GAIN_MIN:
- case SUBDEV_PROP_GAIN_STEP:
+ case SUBDEV_PROP_GAIN_RANGE:
case SUBDEV_PROP_GAIN_NAMES:
case SUBDEV_PROP_FREQ:
- case SUBDEV_PROP_FREQ_MAX:
- case SUBDEV_PROP_FREQ_MIN:
+ case SUBDEV_PROP_FREQ_RANGE:
case SUBDEV_PROP_ANTENNA_NAMES:
case SUBDEV_PROP_QUADRATURE:
case SUBDEV_PROP_IQ_SWAPPED:
@@ -223,12 +217,13 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){
return;
case SUBDEV_PROP_GAIN:
- case SUBDEV_PROP_GAIN_MAX:
- case SUBDEV_PROP_GAIN_MIN:
- case SUBDEV_PROP_GAIN_STEP:
val = gain_t(0);
return;
+ case SUBDEV_PROP_GAIN_RANGE:
+ val = gain_range_t(0, 0, 0);
+ return;
+
case SUBDEV_PROP_GAIN_NAMES:
val = prop_names_t(); //empty
return;
@@ -237,12 +232,8 @@ void basic_tx::tx_get(const wax::obj &key_, wax::obj &val){
val = freq_t(0);
return;
- case SUBDEV_PROP_FREQ_MAX:
- val = +_max_freq;
- return;
-
- case SUBDEV_PROP_FREQ_MIN:
- val = -_max_freq;
+ case SUBDEV_PROP_FREQ_RANGE:
+ val = freq_range_t(+_max_freq, -_max_freq);
return;
case SUBDEV_PROP_ANTENNA:
@@ -289,13 +280,10 @@ void basic_tx::tx_set(const wax::obj &key_, const wax::obj &val){
case SUBDEV_PROP_NAME:
case SUBDEV_PROP_OTHERS:
- case SUBDEV_PROP_GAIN_MAX:
- case SUBDEV_PROP_GAIN_MIN:
- case SUBDEV_PROP_GAIN_STEP:
+ case SUBDEV_PROP_GAIN_RANGE:
case SUBDEV_PROP_GAIN_NAMES:
case SUBDEV_PROP_FREQ:
- case SUBDEV_PROP_FREQ_MAX:
- case SUBDEV_PROP_FREQ_MIN:
+ case SUBDEV_PROP_FREQ_RANGE:
case SUBDEV_PROP_ANTENNA_NAMES:
case SUBDEV_PROP_QUADRATURE:
case SUBDEV_PROP_IQ_SWAPPED:
diff --git a/host/lib/usrp/dboard_manager.cpp b/host/lib/usrp/dboard_manager.cpp
index 08b92e62a..23c2921d2 100644
--- a/host/lib/usrp/dboard_manager.cpp
+++ b/host/lib/usrp/dboard_manager.cpp
@@ -70,16 +70,15 @@ public:
subdev_proxy(dboard_base::sptr subdev, type_t type)
: _subdev(subdev), _type(type){
//initialize gain props struct
- gain_handler::gain_props_t gain_props;
- gain_props.gain_val_prop = SUBDEV_PROP_GAIN;
- gain_props.gain_min_prop = SUBDEV_PROP_GAIN_MIN;
- gain_props.gain_max_prop = SUBDEV_PROP_GAIN_MAX;
- gain_props.gain_step_prop = SUBDEV_PROP_GAIN_STEP;
- gain_props.gain_names_prop = SUBDEV_PROP_GAIN_NAMES;
+ 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)
+ this->get_link(), gain_props,
+ boost::bind(&gain_handler::is_equal<subdev_prop_t>, _1, _2)
);
}
diff --git a/host/test/gain_handler_test.cpp b/host/test/gain_handler_test.cpp
index 9a6a50dab..51497b741 100644
--- a/host/test/gain_handler_test.cpp
+++ b/host/test/gain_handler_test.cpp
@@ -25,10 +25,8 @@
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
};
@@ -36,24 +34,19 @@ class gainful_obj : public wax::obj{
public:
gainful_obj(void){
//initialize gain props struct
- gain_handler::gain_props_t gain_props;
- gain_props.gain_val_prop = PROP_GAIN;
- gain_props.gain_min_prop = PROP_GAIN_MIN;
- gain_props.gain_max_prop = PROP_GAIN_MAX;
- gain_props.gain_step_prop = PROP_GAIN_STEP;
- gain_props.gain_names_prop = PROP_GAIN_NAMES;
+ 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)
+ this->get_link(), gain_props,
+ boost::bind(&gain_handler::is_equal<prop_t>, _1, _2)
);
- _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;
+ _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){}
@@ -67,24 +60,16 @@ private:
//handle the get request conditioned on the key
switch(wax::cast<prop_t>(key)){
- case PROP_GAIN:
- val = _gains[name];
+ 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;
}
}
@@ -97,23 +82,19 @@ private:
//handle the get request conditioned on the key
switch(wax::cast<prop_t>(key)){
- case PROP_GAIN:
- _gains[name] = wax::cast<gain_t>(val);
+ case PROP_GAIN_VALUE:
+ _gain_values[name] = wax::cast<gain_t>(val);
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;
};
@@ -122,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")]),
+ wax::cast<gain_t>(go0[named_prop_t(PROP_GAIN_VALUE, "fail")]),
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) = \
+ wax::cast<gain_range_t>(go0[PROP_GAIN_RANGE]);
+ 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(wax::cast<gain_t>(go0[PROP_GAIN_VALUE]), gain_t(25));
}