diff options
author | Josh Blum <josh@joshknows.com> | 2011-02-21 11:01:05 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2011-02-21 11:01:05 -0800 |
commit | 436387677320e371bb9a2efa6b0c2ec97027bc05 (patch) | |
tree | 79707ad4bc9699b11aeff2b0a040f27d1ee5c5b9 /host/lib/types | |
parent | 607f5df7013810e94bbe049e457858ec68f8dd0e (diff) | |
download | uhd-436387677320e371bb9a2efa6b0c2ec97027bc05.tar.gz uhd-436387677320e371bb9a2efa6b0c2ec97027bc05.tar.bz2 uhd-436387677320e371bb9a2efa6b0c2ec97027bc05.zip |
uhd: moved indexed device addr routines into api
implement in usrp2, also combine non specified args into addr
when initializing the mboard so we can use a single addr
Diffstat (limited to 'host/lib/types')
-rw-r--r-- | host/lib/types/device_addr.cpp | 51 |
1 files changed, 50 insertions, 1 deletions
diff --git a/host/lib/types/device_addr.cpp b/host/lib/types/device_addr.cpp index 14afaa24b..7f2031272 100644 --- a/host/lib/types/device_addr.cpp +++ b/host/lib/types/device_addr.cpp @@ -16,10 +16,11 @@ // #include <uhd/types/device_addr.hpp> -#include <boost/algorithm/string.hpp> //for trim +#include <boost/algorithm/string.hpp> #include <boost/tokenizer.hpp> #include <boost/foreach.hpp> #include <boost/format.hpp> +#include <boost/regex.hpp> #include <stdexcept> #include <sstream> @@ -71,3 +72,51 @@ std::string device_addr_t::to_string(void) const{ } return args_str; } + +#include <uhd/utils/warning.hpp> + +device_addrs_t uhd::separate_device_addr(const device_addr_t &dev_addr){ + //------------ support old deprecated way and print warning -------- + if (dev_addr.has_key("addr") and not dev_addr["addr"].empty()){ + std::vector<std::string> addrs; boost::split(addrs, dev_addr["addr"], boost::is_any_of(" ")); + if (addrs.size() > 1){ + device_addr_t fixed_dev_addr = dev_addr; + fixed_dev_addr.pop("addr"); + for (size_t i = 0; i < addrs.size(); i++){ + fixed_dev_addr[str(boost::format("addr%d") % i)] = addrs[i]; + } + uhd::warning::post( + "addr = <space separated list of ip addresses> is deprecated.\n" + "To address a multi-device, use multiple <key><index> = <val>.\n" + "See the USRP-NXXX application notes. Two device example:\n" + " addr0 = 192.168.10.2\n" + " addr1 = 192.168.10.3\n" + ); + return separate_device_addr(fixed_dev_addr); + } + } + //------------------------------------------------------------------ + device_addrs_t dev_addrs; + BOOST_FOREACH(const std::string &key, dev_addr.keys()){ + boost::cmatch matches; + if (not boost::regex_match(key.c_str(), matches, boost::regex("^(\\D+)(\\d*)$"))){ + throw std::runtime_error("unknown key format: " + key); + } + std::string key_part(matches[1].first, matches[1].second); + std::string num_part(matches[2].first, matches[2].second); + size_t num = (num_part.empty())? 0 : boost::lexical_cast<size_t>(num_part); + dev_addrs.resize(std::max(num+1, dev_addrs.size())); + dev_addrs[num][key_part] = dev_addr[key]; + } + return dev_addrs; +} + +device_addr_t uhd::combine_device_addrs(const device_addrs_t &dev_addrs){ + device_addr_t dev_addr; + for (size_t i = 0; i < dev_addrs.size(); i++){ + BOOST_FOREACH(const std::string &key, dev_addrs[i].keys()){ + dev_addr[str(boost::format("%s%d") % key % i)] = dev_addrs[i][key]; + } + } + return dev_addr; +} |