diff options
| author | Josh Blum <josh@joshknows.com> | 2010-10-20 15:32:41 -0700 | 
|---|---|---|
| committer | Josh Blum <josh@joshknows.com> | 2010-10-20 15:32:41 -0700 | 
| commit | 26aef3bae98aae5364deb40a62b52ba65b9aa16a (patch) | |
| tree | 00b40426474768298322275b7c81c01b24120c6a /host | |
| parent | e0c48ba5cc1033cd330e2ce73ceb03740923e954 (diff) | |
| download | uhd-26aef3bae98aae5364deb40a62b52ba65b9aa16a.tar.gz uhd-26aef3bae98aae5364deb40a62b52ba65b9aa16a.tar.bz2 uhd-26aef3bae98aae5364deb40a62b52ba65b9aa16a.zip | |
uhd: added name parameter to gain group, get range, set/get value by name
Diffstat (limited to 'host')
| -rw-r--r-- | host/include/uhd/utils/gain_group.hpp | 43 | ||||
| -rw-r--r-- | host/lib/usrp/misc_utils.cpp | 4 | ||||
| -rw-r--r-- | host/lib/utils/gain_group.cpp | 26 | ||||
| -rw-r--r-- | host/test/gain_group_test.cpp | 4 | 
4 files changed, 59 insertions, 18 deletions
| diff --git a/host/include/uhd/utils/gain_group.hpp b/host/include/uhd/utils/gain_group.hpp index 3955dfa9a..c863248ce 100644 --- a/host/include/uhd/utils/gain_group.hpp +++ b/host/include/uhd/utils/gain_group.hpp @@ -23,6 +23,8 @@  #include <boost/shared_ptr.hpp>  #include <boost/function.hpp>  #include <boost/utility.hpp> +#include <vector> +#include <string>  namespace uhd{ @@ -40,36 +42,57 @@ public:      typedef boost::shared_ptr<gain_group> sptr;      /*! -     * Get the overall gain range for this group. +     * Get the gain range for the gain element specified by name. +     * For an empty name, get the overall gain range for this group.       * Overall step is defined as the minimum step size. +     * \param name name of the gain element (optional)       * \return a gain range with overall min, max, step       */ -    virtual gain_range_t get_range(void) = 0; +    virtual gain_range_t get_range(const std::string &name = "") = 0;      /*! -     * Get the overall gain value for this group. -     * \return a summation of all the gain values +     * Get the gain value for the gain element specified by name. +     * For an empty name, get the overall gain value for this group. +     * \param name name of the gain element (optional) +     * \return a gain value of the element or all elements       */ -    virtual float get_value(void) = 0; +    virtual float get_value(const std::string &name = "") = 0;      /*! -     * Set the overall gain value for this group. +     * Set the gain value for the gain element specified by name. +     * For an empty name, set the overall gain value for this group.       * The power will be distributed across individual gain elements.       * The semantics of how to do this are determined by the priority. -     * \param gain the gain to set across the group +     * \param gain the gain to set for the lement or across the group +     * \param name name of the gain element (optional)       */ -    virtual void set_value(float gain) = 0; +    virtual void set_value(float gain, const std::string &name = "") = 0;      /*! -     * Register a set of gain functions into this group. +     * Get a list of names of registered gain elements. +     * The names are in the order that they were registered. +     * \return a vector of gain name strings +     */ +    virtual const std::vector<std::string> get_names(void) = 0; + +    /*! +     * Register a set of gain functions into this group: +     * +     * The name should be a unique and non-empty name. +     * Othwerwise, the implementation will rename it. +     *       * Priority determines how power will be distributed       * with higher priorities getting the power first,       * and lower priorities getting the remainder power. +     * +     * \param name the name of the gain element       * \param gain_fcns the set of gain functions       * \param priority the priority of the gain element       */      virtual void register_fcns( -        const gain_fcns_t &gain_fcns, size_t priority = 0 +        const std::string &name, +        const gain_fcns_t &gain_fcns, +        size_t priority = 0      ) = 0;      /*! diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp index 05308baba..499a6ebfb 100644 --- a/host/lib/usrp/misc_utils.cpp +++ b/host/lib/usrp/misc_utils.cpp @@ -95,7 +95,7 @@ gain_group::sptr usrp::make_gain_group(          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); +        gg->register_fcns(name, 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>()){ @@ -119,7 +119,7 @@ gain_group::sptr usrp::make_gain_group(              fcns.set_value = boost::bind(&set_codec_gain_q, codec, name, _1);              break;          } -        gg->register_fcns(fcns, codec_gain_priority); +        gg->register_fcns(name, fcns, codec_gain_priority);      }      return gg;  } diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp index 078fe56b2..54146726a 100644 --- a/host/lib/utils/gain_group.cpp +++ b/host/lib/utils/gain_group.cpp @@ -63,7 +63,9 @@ public:          /*NOP*/      } -    gain_range_t get_range(void){ +    gain_range_t get_range(const std::string &name){ +        if (not name.empty()) return _name_to_fcns[name].get_range(); +          float overall_min = 0, overall_max = 0, overall_step = 0;          BOOST_FOREACH(const gain_fcns_t &fcns, get_all_fcns()){              const gain_range_t range = fcns.get_range(); @@ -76,7 +78,9 @@ public:          return gain_range_t(overall_min, overall_max, overall_step);      } -    float get_value(void){ +    float get_value(const std::string &name){ +        if (not name.empty()) return _name_to_fcns[name].get_value(); +          float overall_gain = 0;          BOOST_FOREACH(const gain_fcns_t &fcns, get_all_fcns()){              overall_gain += fcns.get_value(); @@ -84,7 +88,9 @@ public:          return overall_gain;      } -    void set_value(float gain){ +    void set_value(float gain, const std::string &name){ +        if (not name.empty()) return _name_to_fcns[name].set_value(gain); +          std::vector<gain_fcns_t> all_fcns = get_all_fcns();          if (all_fcns.size() == 0) return; //nothing to set! @@ -140,10 +146,21 @@ public:          }      } +    const std::vector<std::string> get_names(void){ +        return _name_to_fcns.keys(); +    } +      void register_fcns( -        const gain_fcns_t &gain_fcns, size_t priority +        const std::string &name, +        const gain_fcns_t &gain_fcns, +        size_t priority      ){ +        if (name.empty() or _name_to_fcns.has_key(name)){ +            //ensure the name name is unique and non-empty +            return register_fcns(name + "_", gain_fcns, priority); +        }          _registry[priority].push_back(gain_fcns); +        _name_to_fcns[name] = gain_fcns;      }  private: @@ -158,6 +175,7 @@ private:      }      uhd::dict<size_t, std::vector<gain_fcns_t> > _registry; +    uhd::dict<std::string, gain_fcns_t> _name_to_fcns;  };  /*********************************************************************** diff --git a/host/test/gain_group_test.cpp b/host/test/gain_group_test.cpp index 761372e5a..555ccaed3 100644 --- a/host/test/gain_group_test.cpp +++ b/host/test/gain_group_test.cpp @@ -81,12 +81,12 @@ static gain_group::sptr get_gain_group(size_t pri1 = 0, size_t pri2 = 0){      gain_fcns.get_range = boost::bind(&gain_element1::get_range, &g1);      gain_fcns.get_value = boost::bind(&gain_element1::get_value, &g1);      gain_fcns.set_value = boost::bind(&gain_element1::set_value, &g1, _1); -    gg->register_fcns(gain_fcns, pri1); +    gg->register_fcns("g1", gain_fcns, pri1);      gain_fcns.get_range = boost::bind(&gain_element2::get_range, &g2);      gain_fcns.get_value = boost::bind(&gain_element2::get_value, &g2);      gain_fcns.set_value = boost::bind(&gain_element2::set_value, &g2, _1); -    gg->register_fcns(gain_fcns, pri2); +    gg->register_fcns("g2", gain_fcns, pri2);      return gg;  } | 
