diff options
author | Josh Blum <josh@joshknows.com> | 2010-08-11 12:27:18 -0700 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-08-11 12:27:18 -0700 |
commit | 54048fd9b227633c724edd975347c81152ab37b2 (patch) | |
tree | f922ac5f19fa26249360b3c6614ceb45d482b391 /host/lib/usrp/misc_utils.cpp | |
parent | 9503c5101007ba1261b8d23ee6a17305bbaa6f2a (diff) | |
download | uhd-54048fd9b227633c724edd975347c81152ab37b2.tar.gz uhd-54048fd9b227633c724edd975347c81152ab37b2.tar.bz2 uhd-54048fd9b227633c724edd975347c81152ab37b2.zip |
usrp: added subdev spec verification functions
Diffstat (limited to 'host/lib/usrp/misc_utils.cpp')
-rw-r--r-- | host/lib/usrp/misc_utils.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/host/lib/usrp/misc_utils.cpp b/host/lib/usrp/misc_utils.cpp index 0aa03a6cc..da22d79f1 100644 --- a/host/lib/usrp/misc_utils.cpp +++ b/host/lib/usrp/misc_utils.cpp @@ -16,8 +16,12 @@ // #include "misc_utils.hpp" +#include <uhd/utils/assert.hpp> #include <uhd/utils/gain_group.hpp> +#include <uhd/usrp/dboard_id.hpp> #include <uhd/usrp/subdev_props.hpp> +#include <uhd/usrp/mboard_props.hpp> +#include <uhd/usrp/dboard_props.hpp> #include <uhd/usrp/codec_props.hpp> #include <boost/bind.hpp> #include <boost/foreach.hpp> @@ -112,3 +116,59 @@ gain_group::sptr usrp::make_gain_group(wax::obj subdev, wax::obj codec){ } return gg; } + +/*********************************************************************** + * verify subdev specs + **********************************************************************/ +static void verify_xx_subdev_spec( + mboard_prop_t dboard_names_prop, + mboard_prop_t dboard_prop, + subdev_spec_t &subdev_spec, + wax::obj mboard, + std::string xx_type +){ + //the subdevice specification is empty: handle automatic + if (subdev_spec.empty()){ + BOOST_FOREACH(const std::string &db_name, mboard[dboard_names_prop].as<prop_names_t>()){ + wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; + + //if the dboard slot is populated, take the first subdevice + if (dboard[DBOARD_PROP_DBOARD_ID].as<dboard_id_t>() != dboard_id_t::none()){ + std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>().at(0); + subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name)); + break; + } + } + + //didnt find any populated dboards: add the first subdevice + if (subdev_spec.empty()){ + std::string db_name = mboard[dboard_names_prop].as<prop_names_t>().at(0); + wax::obj dboard = mboard[named_prop_t(dboard_prop, db_name)]; + std::string sd_name = dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>().at(0); + subdev_spec.push_back(subdev_spec_pair_t(db_name, sd_name)); + } + } + + //sanity check that the dboard/subdevice names exist for this mboard + BOOST_FOREACH(const subdev_spec_pair_t &pair, subdev_spec){ + uhd::assert_has(mboard[dboard_names_prop].as<prop_names_t>(), pair.db_name, xx_type + " dboard name"); + wax::obj dboard = mboard[named_prop_t(dboard_prop, pair.db_name)]; + uhd::assert_has(dboard[DBOARD_PROP_SUBDEV_NAMES].as<prop_names_t>(), pair.sd_name, xx_type + " subdev name"); + } +} + +void usrp::verify_rx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard){ + return verify_xx_subdev_spec( + MBOARD_PROP_RX_DBOARD_NAMES, + MBOARD_PROP_RX_DBOARD, + subdev_spec, mboard, "rx" + ); +} + +void usrp::verify_tx_subdev_spec(subdev_spec_t &subdev_spec, wax::obj mboard){ + return verify_xx_subdev_spec( + MBOARD_PROP_TX_DBOARD_NAMES, + MBOARD_PROP_TX_DBOARD, + subdev_spec, mboard, "tx" + ); +} |