2010-08-05 18:50:30 +00:00
|
|
|
//
|
2011-01-14 00:22:07 +00:00
|
|
|
// Copyright 2010-2011 Ettus Research LLC
|
2010-08-05 18:50:30 +00:00
|
|
|
//
|
2017-12-22 17:45:24 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0
|
2010-08-05 18:50:30 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <uhd/usrp/subdev_spec.hpp>
|
2011-02-25 00:35:29 +00:00
|
|
|
#include <uhd/exception.hpp>
|
2011-01-06 23:38:56 +00:00
|
|
|
#include <boost/algorithm/string.hpp> //for split
|
|
|
|
|
#include <boost/tokenizer.hpp>
|
2010-08-05 18:50:30 +00:00
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
#include <sstream>
|
2011-01-06 23:38:56 +00:00
|
|
|
#include <vector>
|
2010-08-05 18:50:30 +00:00
|
|
|
|
|
|
|
|
using namespace uhd;
|
|
|
|
|
using namespace uhd::usrp;
|
|
|
|
|
|
2011-01-06 23:38:56 +00:00
|
|
|
#define pair_tokenizer(inp) \
|
|
|
|
|
boost::tokenizer<boost::char_separator<char> > \
|
|
|
|
|
(inp, boost::char_separator<char>(" "))
|
|
|
|
|
|
2010-08-05 23:41:51 +00:00
|
|
|
subdev_spec_pair_t::subdev_spec_pair_t(
|
|
|
|
|
const std::string &db_name, const std::string &sd_name
|
|
|
|
|
):
|
|
|
|
|
db_name(db_name),
|
|
|
|
|
sd_name(sd_name)
|
|
|
|
|
{
|
|
|
|
|
/* NOP */
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-30 18:05:33 +00:00
|
|
|
bool usrp::operator==(const subdev_spec_pair_t &lhs, const subdev_spec_pair_t &rhs){
|
|
|
|
|
return (lhs.db_name == rhs.db_name) and (lhs.sd_name == rhs.sd_name);
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-10 01:36:02 +00:00
|
|
|
bool subdev_spec_pair_t::operator==(const subdev_spec_pair_t &other){
|
|
|
|
|
return (other.db_name == db_name) and (other.sd_name == sd_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool subdev_spec_pair_t::operator!=(const subdev_spec_pair_t &other){
|
|
|
|
|
return (other.db_name != db_name) or (other.sd_name != sd_name);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-05 18:50:30 +00:00
|
|
|
subdev_spec_t::subdev_spec_t(const std::string &markup){
|
2017-02-10 07:19:55 +00:00
|
|
|
for(const std::string &pair: pair_tokenizer(markup)){
|
2011-01-26 19:27:25 +00:00
|
|
|
if (pair.empty()) continue;
|
2011-01-06 23:38:56 +00:00
|
|
|
std::vector<std::string> db_sd; boost::split(db_sd, pair, boost::is_any_of(":"));
|
2010-08-05 18:50:30 +00:00
|
|
|
switch(db_sd.size()){
|
2010-08-05 23:41:51 +00:00
|
|
|
case 1: this->push_back(subdev_spec_pair_t("", db_sd.front())); break;
|
|
|
|
|
case 2: this->push_back(subdev_spec_pair_t(db_sd.front(), db_sd.back())); break;
|
2011-02-25 00:35:29 +00:00
|
|
|
default: throw uhd::value_error("invalid subdev-spec markup string: "+markup);
|
2010-08-05 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
2017-02-10 07:19:55 +00:00
|
|
|
for(const subdev_spec_pair_t &pair: *this){
|
2010-08-05 18:50:30 +00:00
|
|
|
ss << boost::format(
|
|
|
|
|
" Channel %d: Daughterboard %s, Subdevice %s"
|
2010-08-15 08:41:35 +00:00
|
|
|
) % (count++) % pair.db_name % pair.sd_name << std::endl;
|
2010-08-05 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
return ss.str();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string subdev_spec_t::to_string(void) const{
|
|
|
|
|
std::string markup;
|
|
|
|
|
size_t count = 0;
|
2017-02-10 07:19:55 +00:00
|
|
|
for(const subdev_spec_pair_t &pair: *this){
|
2010-08-05 23:41:51 +00:00
|
|
|
markup += ((count++)? " " : "") + pair.db_name + ":" + pair.sd_name;
|
2010-08-05 18:50:30 +00:00
|
|
|
}
|
|
|
|
|
return markup;
|
|
|
|
|
}
|