diff options
author | Josh Blum <josh@joshknows.com> | 2010-08-05 11:50:30 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-08-06 12:15:05 -0700 |
commit | 53341c286eb71ead76ff11796ab67bd98f73c3ab (patch) | |
tree | 9a60145a06d3614dd99670093b2fc337879e6a98 /host/lib/usrp | |
parent | 7e8a1f296f934a5546cdad575bcbe030a78b8bb1 (diff) | |
download | uhd-53341c286eb71ead76ff11796ab67bd98f73c3ab.tar.gz uhd-53341c286eb71ead76ff11796ab67bd98f73c3ab.tar.bz2 uhd-53341c286eb71ead76ff11796ab67bd98f73c3ab.zip |
usrp: added subdev spec class with parser to specify subdevice specifications for channel config
Diffstat (limited to 'host/lib/usrp')
-rw-r--r-- | host/lib/usrp/CMakeLists.txt | 1 | ||||
-rw-r--r-- | host/lib/usrp/subdev_spec.cpp | 64 |
2 files changed, 65 insertions, 0 deletions
diff --git a/host/lib/usrp/CMakeLists.txt b/host/lib/usrp/CMakeLists.txt index 80ac537ee..a403296fa 100644 --- a/host/lib/usrp/CMakeLists.txt +++ b/host/lib/usrp/CMakeLists.txt @@ -25,6 +25,7 @@ LIBUHD_APPEND_SOURCES( ${CMAKE_SOURCE_DIR}/lib/usrp/dsp_utils.hpp ${CMAKE_SOURCE_DIR}/lib/usrp/mimo_usrp.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/simple_usrp.cpp + ${CMAKE_SOURCE_DIR}/lib/usrp/subdev_spec.cpp ${CMAKE_SOURCE_DIR}/lib/usrp/tune_helper.cpp ) diff --git a/host/lib/usrp/subdev_spec.cpp b/host/lib/usrp/subdev_spec.cpp new file mode 100644 index 000000000..69ab6a339 --- /dev/null +++ b/host/lib/usrp/subdev_spec.cpp @@ -0,0 +1,64 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/usrp/subdev_spec.hpp> +#include <boost/algorithm/string.hpp> +#include <boost/format.hpp> +#include <boost/foreach.hpp> +#include <stdexcept> +#include <sstream> + +using namespace uhd; +using namespace uhd::usrp; + +subdev_spec_t::subdev_spec_t(const std::string &markup){ + std::vector<std::string> pairs; + boost::split(pairs, markup, boost::is_any_of("\t ")); + BOOST_FOREACH(const std::string &pair, pairs){ + if (pair == "") continue; + std::vector<std::string> db_sd; + boost::split(db_sd, pair, boost::is_any_of(":")); + switch(db_sd.size()){ + case 1: this->push_back(pair_t("", db_sd.front())); break; + case 2: this->push_back(pair_t(db_sd.front(), db_sd.back())); break; + default: throw std::runtime_error("invalid subdev-spec markup string: "+markup); + } + } +} + +std::string subdev_spec_t::to_pp_string(void) const{ + if (this->size() == 0) return "Empty Subdevice Specification"; + + std::stringstream ss; + size_t count = 0; + ss << "Subdevice Specification:" << std::endl; + BOOST_FOREACH(const pair_t &pair, *this){ + ss << boost::format( + " Channel %d: Daughterboard %s, Subdevice %s" + ) % (count++) % pair.first % pair.second << std::endl; + } + return ss.str(); +} + +std::string subdev_spec_t::to_string(void) const{ + std::string markup; + size_t count = 0; + BOOST_FOREACH(const pair_t &pair, *this){ + markup += ((count++)? " " : "") + pair.first + ":" + pair.second; + } + return markup; +} |