aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-07-28 12:15:09 -0700
committerJosh Blum <josh@joshknows.com>2010-07-28 12:15:09 -0700
commit702d5af8ca0bab8ef295c817017df5952f6aea51 (patch)
treef9320b8265c3ffa6cc81dd7e3123e4215edb5514
parent06eeab272d89e6491b48c7bed4d97bb68b821946 (diff)
downloaduhd-702d5af8ca0bab8ef295c817017df5952f6aea51.tar.gz
uhd-702d5af8ca0bab8ef295c817017df5952f6aea51.tar.bz2
uhd-702d5af8ca0bab8ef295c817017df5952f6aea51.zip
usrp: codec gains, dont bind function pointers, also add priorities
-rw-r--r--host/lib/usrp/misc_utils.cpp71
1 files changed, 57 insertions, 14 deletions
diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp
index 2e94e9d47..0aa03a6cc 100644
--- a/host/lib/usrp/misc_utils.cpp
+++ b/host/lib/usrp/misc_utils.cpp
@@ -25,47 +25,90 @@
using namespace uhd;
using namespace uhd::usrp;
+static const size_t subdev_gain_priority = 1; //higher, closer to the antenna
+static const size_t codec_gain_priority = 0;
+
/***********************************************************************
- * gain group functions
+ * codec gain group helper functions:
+ * do this so we dont have to bind a templated function
**********************************************************************/
-static void gg_set_iq_value(wax::obj codec, const std::string &name, float gain){
+static gain_range_t get_codec_gain_range(wax::obj codec, const std::string &name){
+ return codec[named_prop_t(CODEC_PROP_GAIN_RANGE, name)].as<gain_range_t>();
+}
+
+static float get_codec_gain_i(wax::obj codec, const std::string &name){
+ return codec[named_prop_t(CODEC_PROP_GAIN_I, name)].as<float>();
+}
+
+static float get_codec_gain_q(wax::obj codec, const std::string &name){
+ return codec[named_prop_t(CODEC_PROP_GAIN_Q, name)].as<float>();
+}
+
+static void set_codec_gain_both(wax::obj codec, const std::string &name, float gain){
codec[named_prop_t(CODEC_PROP_GAIN_I, name)] = gain;
codec[named_prop_t(CODEC_PROP_GAIN_Q, name)] = gain;
}
+static void set_codec_gain_i(wax::obj codec, const std::string &name, float gain){
+ codec[named_prop_t(CODEC_PROP_GAIN_I, name)] = gain;
+}
+
+static void set_codec_gain_q(wax::obj codec, const std::string &name, float gain){
+ codec[named_prop_t(CODEC_PROP_GAIN_Q, name)] = gain;
+}
+
+/***********************************************************************
+ * subdev gain group helper functions:
+ * do this so we dont have to bind a templated function
+ **********************************************************************/
+static float get_subdev_gain(wax::obj subdev, const std::string &name){
+ return subdev[named_prop_t(SUBDEV_PROP_GAIN, name)].as<float>();
+}
+
+static gain_range_t get_subdev_gain_range(wax::obj subdev, const std::string &name){
+ return subdev[named_prop_t(SUBDEV_PROP_GAIN_RANGE, name)].as<gain_range_t>();
+}
+
+static void set_subdev_gain(wax::obj subdev, const std::string &name, float gain){
+ subdev[named_prop_t(SUBDEV_PROP_GAIN, name)] = gain;
+}
+
+/***********************************************************************
+ * gain group factory function for usrp
+ **********************************************************************/
gain_group::sptr usrp::make_gain_group(wax::obj subdev, wax::obj codec){
gain_group::sptr gg = gain_group::make();
gain_fcns_t fcns;
//add all the subdev gains first (antenna to dsp order)
BOOST_FOREACH(const std::string &name, subdev[SUBDEV_PROP_GAIN_NAMES].as<prop_names_t>()){
- fcns.get_range = boost::bind(&wax::obj::as<gain_range_t>, subdev[named_prop_t(SUBDEV_PROP_GAIN_RANGE, name)]);
- fcns.get_value = boost::bind(&wax::obj::as<float>, subdev[named_prop_t(SUBDEV_PROP_GAIN, name)]);
- fcns.set_value = boost::bind(&wax::obj::operator[], subdev[named_prop_t(SUBDEV_PROP_GAIN, name)], _1);
- gg->register_fcns(fcns);
+ fcns.get_range = boost::bind(&get_subdev_gain_range, subdev, name);
+ fcns.get_value = boost::bind(&get_subdev_gain, subdev, name);
+ fcns.set_value = boost::bind(&set_subdev_gain, subdev, name, _1);
+ gg->register_fcns(fcns, subdev_gain_priority);
}
//add all the codec gains last (antenna to dsp order)
BOOST_FOREACH(const std::string &name, codec[CODEC_PROP_GAIN_NAMES].as<prop_names_t>()){
- fcns.get_range = boost::bind(&wax::obj::as<gain_range_t>, codec[named_prop_t(CODEC_PROP_GAIN_RANGE, name)]);
+ fcns.get_range = boost::bind(&get_codec_gain_range, codec, name);
//register the value functions depending upon the connection type
switch(subdev[SUBDEV_PROP_CONNECTION].as<subdev_conn_t>()){
case SUBDEV_CONN_COMPLEX_IQ:
case SUBDEV_CONN_COMPLEX_QI:
- fcns.get_value = boost::bind(&wax::obj::as<float>, codec[named_prop_t(CODEC_PROP_GAIN_I, name)]); //same as Q
- fcns.set_value = boost::bind(&gg_set_iq_value, codec, name, _1); //sets both
+ fcns.get_value = boost::bind(&get_codec_gain_i, codec, name); //same as Q
+ fcns.set_value = boost::bind(&set_codec_gain_both, codec, name, _1); //sets both
break;
case SUBDEV_CONN_REAL_I:
- fcns.get_value = boost::bind(&wax::obj::as<float>, codec[named_prop_t(CODEC_PROP_GAIN_I, name)]);
- fcns.set_value = boost::bind(&wax::obj::operator[], codec[named_prop_t(CODEC_PROP_GAIN_I, name)], _1);
+ fcns.get_value = boost::bind(&get_codec_gain_i, codec, name);
+ fcns.set_value = boost::bind(&set_codec_gain_i, codec, name, _1);
break;
case SUBDEV_CONN_REAL_Q:
- fcns.get_value = boost::bind(&wax::obj::as<float>, codec[named_prop_t(CODEC_PROP_GAIN_Q, name)]);
- fcns.set_value = boost::bind(&wax::obj::operator[], codec[named_prop_t(CODEC_PROP_GAIN_Q, name)], _1);
+ fcns.get_value = boost::bind(&get_codec_gain_q, codec, name);
+ fcns.set_value = boost::bind(&set_codec_gain_q, codec, name, _1);
break;
}
- gg->register_fcns(fcns);
+ gg->register_fcns(fcns, codec_gain_priority);
}
return gg;
}