2011-07-01 22:07:38 +00:00
|
|
|
//
|
|
|
|
|
// Copyright 2011 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2011-07-01 22:07:38 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2011-07-01 22:07:38 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
|
|
#include <uhd/exception.hpp>
|
|
|
|
|
#include <uhd/utils/assert_has.hpp>
|
2020-03-02 23:25:13 +00:00
|
|
|
#include <uhdlib/usrp/common/validate_subdev_spec.hpp>
|
2011-07-01 22:07:38 +00:00
|
|
|
#include <boost/format.hpp>
|
|
|
|
|
|
|
|
|
|
using namespace uhd;
|
|
|
|
|
using namespace uhd::usrp;
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
namespace uhd { namespace usrp {
|
2011-07-01 22:07:38 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
static std::ostream& operator<<(std::ostream& out, const subdev_spec_pair_t& pair)
|
|
|
|
|
{
|
|
|
|
|
out << pair.db_name << ":" << pair.sd_name;
|
|
|
|
|
return out;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}} // namespace uhd::usrp
|
|
|
|
|
|
|
|
|
|
void uhd::usrp::validate_subdev_spec(property_tree::sptr tree,
|
|
|
|
|
const subdev_spec_t& spec,
|
|
|
|
|
const std::string& type,
|
|
|
|
|
const std::string& mb)
|
|
|
|
|
{
|
|
|
|
|
const size_t num_dsps =
|
|
|
|
|
tree->list(str(boost::format("/mboards/%s/%s_dsps") % mb % type)).size();
|
|
|
|
|
|
|
|
|
|
// sanity checking on the length
|
2021-01-08 08:33:36 +00:00
|
|
|
if (spec.empty())
|
2020-03-02 23:25:13 +00:00
|
|
|
throw uhd::value_error(
|
|
|
|
|
str(boost::format("Empty %s subdevice specification is not supported.\n")
|
|
|
|
|
% type));
|
|
|
|
|
if (spec.size() > num_dsps)
|
|
|
|
|
throw uhd::value_error(
|
|
|
|
|
str(boost::format("The subdevice specification \"%s\" is too long.\n"
|
|
|
|
|
"The user specified %u channels, but there are only %u %s "
|
|
|
|
|
"dsps on mboard %s.\n")
|
|
|
|
|
% spec.to_string() % spec.size() % num_dsps % type % mb));
|
2011-07-01 22:07:38 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// make a list of all possible specs
|
2011-07-01 22:07:38 +00:00
|
|
|
subdev_spec_t all_specs;
|
2020-03-02 23:25:13 +00:00
|
|
|
for (const std::string& db :
|
|
|
|
|
tree->list(str(boost::format("/mboards/%s/dboards") % mb))) {
|
|
|
|
|
for (const std::string& sd :
|
|
|
|
|
tree->list(str(
|
|
|
|
|
boost::format("/mboards/%s/dboards/%s/%s_frontends") % mb % db % type))) {
|
2011-07-01 22:07:38 +00:00
|
|
|
all_specs.push_back(subdev_spec_pair_t(db, sd));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// validate that the spec is possible
|
|
|
|
|
for (const subdev_spec_pair_t& pair : spec) {
|
|
|
|
|
uhd::assert_has(all_specs,
|
|
|
|
|
pair,
|
|
|
|
|
str(boost::format("%s subdevice specification on mboard %s") % type % mb));
|
2011-07-01 22:07:38 +00:00
|
|
|
}
|
2011-07-06 16:18:47 +00:00
|
|
|
|
2020-03-02 23:25:13 +00:00
|
|
|
// enable selected frontends, disable others
|
|
|
|
|
for (const subdev_spec_pair_t& pair : all_specs) {
|
2011-07-06 16:18:47 +00:00
|
|
|
const bool enb = uhd::has(spec, pair);
|
2020-03-02 23:25:13 +00:00
|
|
|
tree->access<bool>(
|
|
|
|
|
str(boost::format("/mboards/%s/dboards/%s/%s_frontends/%s/enabled") % mb
|
|
|
|
|
% pair.db_name % type % pair.sd_name))
|
|
|
|
|
.set(enb);
|
2011-07-06 16:18:47 +00:00
|
|
|
}
|
2011-07-01 22:07:38 +00:00
|
|
|
}
|