diff options
Diffstat (limited to 'host/lib')
-rw-r--r-- | host/lib/gain_handler.cpp | 98 | ||||
-rw-r--r-- | host/lib/simple_device.cpp | 56 | ||||
-rw-r--r-- | host/lib/usrp/dboard/basic.cpp | 44 | ||||
-rw-r--r-- | host/lib/usrp/dboard_manager.cpp | 13 |
4 files changed, 82 insertions, 129 deletions
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) ); } |