diff options
author | Ben Hilburn <ben.hilburn@ettus.com> | 2014-02-04 10:53:36 -0800 |
---|---|---|
committer | Ben Hilburn <ben.hilburn@ettus.com> | 2014-02-04 10:53:36 -0800 |
commit | 2718ac110fa931cc29daf7cb3dc5ab6230ee02ab (patch) | |
tree | 151949ec69c6c478b2f20db01a195ae963e213e2 /host | |
parent | ef100213a47a8560e6c2e09e623be198498dbd26 (diff) | |
parent | c0fd48ac35442009f1413fcd33736576dd76f9df (diff) | |
download | uhd-2718ac110fa931cc29daf7cb3dc5ab6230ee02ab.tar.gz uhd-2718ac110fa931cc29daf7cb3dc5ab6230ee02ab.tar.bz2 uhd-2718ac110fa931cc29daf7cb3dc5ab6230ee02ab.zip |
Merge branch 'origin/mwest/gain_name_check'
Diffstat (limited to 'host')
-rw-r--r-- | host/lib/usrp/multi_usrp.cpp | 62 | ||||
-rw-r--r-- | host/lib/utils/gain_group.cpp | 6 |
2 files changed, 59 insertions, 9 deletions
diff --git a/host/lib/usrp/multi_usrp.cpp b/host/lib/usrp/multi_usrp.cpp index 26ce1ccdd..4bd7d1bfe 100644 --- a/host/lib/usrp/multi_usrp.cpp +++ b/host/lib/usrp/multi_usrp.cpp @@ -35,6 +35,14 @@ using namespace uhd::usrp; const std::string multi_usrp::ALL_GAINS = ""; +UHD_INLINE std::string string_vector_to_string(std::vector<std::string> values, std::string delimeter = std::string(" ")) +{ + std::string out = ""; + for (std::vector<std::string>::iterator iter = values.begin(); iter != values.end(); iter++) + out += delimeter + *iter; + return out; +} + /*********************************************************************** * Helper methods **********************************************************************/ @@ -620,15 +628,36 @@ public: } void set_rx_gain(double gain, const std::string &name, size_t chan){ - return rx_gain_group(chan)->set_value(gain, name); + try { + return rx_gain_group(chan)->set_value(gain, name); + } catch (uhd::key_error &e) { + std::stringstream err; + err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << + "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; + throw uhd::exception::runtime_error(err.str()); + } } double get_rx_gain(const std::string &name, size_t chan){ - return rx_gain_group(chan)->get_value(name); + try { + return rx_gain_group(chan)->get_value(name); + } catch (uhd::key_error &e) { + std::stringstream err; + err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << + "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; + throw uhd::exception::runtime_error(err.str()); + } } gain_range_t get_rx_gain_range(const std::string &name, size_t chan){ - return rx_gain_group(chan)->get_range(name); + try { + return rx_gain_group(chan)->get_range(name); + } catch (uhd::key_error &e) { + std::stringstream err; + err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << + "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; + throw uhd::exception::runtime_error(err.str()); + } } std::vector<std::string> get_rx_gain_names(size_t chan){ @@ -789,15 +818,36 @@ public: } void set_tx_gain(double gain, const std::string &name, size_t chan){ - return tx_gain_group(chan)->set_value(gain, name); + try { + return tx_gain_group(chan)->set_value(gain, name); + } catch (uhd::key_error &e) { + std::stringstream err; + err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << + "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; + throw uhd::exception::runtime_error(err.str()); + } } double get_tx_gain(const std::string &name, size_t chan){ - return tx_gain_group(chan)->get_value(name); + try { + return tx_gain_group(chan)->get_value(name); + } catch (uhd::key_error &e) { + std::stringstream err; + err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << + "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; + throw uhd::exception::runtime_error(err.str()); + } } gain_range_t get_tx_gain_range(const std::string &name, size_t chan){ - return tx_gain_group(chan)->get_range(name); + try { + return tx_gain_group(chan)->get_range(name); + } catch (uhd::key_error &e) { + std::stringstream err; + err << __FUNCTION__ << "(\"" << name << "\"): gain not found.\n" << + "Available gains: " << string_vector_to_string(get_rx_gain_names(chan)) << std::endl; + throw uhd::exception::runtime_error(err.str()); + } } std::vector<std::string> get_tx_gain_names(size_t chan){ diff --git a/host/lib/utils/gain_group.cpp b/host/lib/utils/gain_group.cpp index 85f4977a6..d422b3d52 100644 --- a/host/lib/utils/gain_group.cpp +++ b/host/lib/utils/gain_group.cpp @@ -64,7 +64,7 @@ public: } gain_range_t get_range(const std::string &name){ - if (not name.empty()) return _name_to_fcns[name].get_range(); + if (not name.empty()) return _name_to_fcns.get(name).get_range(); double overall_min = 0, overall_max = 0, overall_step = 0; BOOST_FOREACH(const gain_fcns_t &fcns, get_all_fcns()){ @@ -79,7 +79,7 @@ public: } double get_value(const std::string &name){ - if (not name.empty()) return _name_to_fcns[name].get_value(); + if (not name.empty()) return _name_to_fcns.get(name).get_value(); double overall_gain = 0; BOOST_FOREACH(const gain_fcns_t &fcns, get_all_fcns()){ @@ -89,7 +89,7 @@ public: } void set_value(double gain, const std::string &name){ - if (not name.empty()) return _name_to_fcns[name].set_value(gain); + if (not name.empty()) return _name_to_fcns.get(name).set_value(gain); std::vector<gain_fcns_t> all_fcns = get_all_fcns(); if (all_fcns.size() == 0) return; //nothing to set! |