From a98e387578a3aceb15e2bcce4a9cc54d78c30dda Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 26 Jan 2010 11:29:14 -0800 Subject: Switched from indexed properties to named properties. Added some new properties for getting a list of antenna names, pps sources, ref sources... --- lib/usrp/dboard/base.cpp | 6 ++--- lib/usrp/dboard/manager.cpp | 63 ++++++++++++++++++++++++++------------------- 2 files changed, 39 insertions(+), 30 deletions(-) (limited to 'lib/usrp/dboard') diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp index c80cdadeb..82f4b4016 100644 --- a/lib/usrp/dboard/base.cpp +++ b/lib/usrp/dboard/base.cpp @@ -10,15 +10,15 @@ using namespace usrp_uhd::usrp::dboard; * base dboard base class **********************************************************************/ base::base(ctor_args_t const& args){ - boost::tie(_subdev_index, _dboard_interface) = args; + boost::tie(_subdev_name, _dboard_interface) = args; } base::~base(void){ /* NOP */ } -size_t base::get_subdev_index(void){ - return _subdev_index; +std::string base::get_subdev_name(void){ + return _subdev_name; } interface::sptr base::get_interface(void){ diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp index 6486fadf2..e9d973cb5 100644 --- a/lib/usrp/dboard/manager.cpp +++ b/lib/usrp/dboard/manager.cpp @@ -3,10 +3,13 @@ // #include +#include +#include #include -#include +#include #include "dboards.hpp" +using namespace usrp_uhd; using namespace usrp_uhd::usrp::dboard; /*********************************************************************** @@ -26,8 +29,8 @@ static void register_internal_dboards(void){ static bool called = false; if (called) return; called = true; //register the known dboards (dboard id, constructor, num subdevs) - manager::register_subdevs(0x0000, &basic_tx::make, 1); - manager::register_subdevs(0x0001, &basic_rx::make, 3); + manager::register_subdevs(0x0000, &basic_tx::make, boost::assign::list_of("")); + manager::register_subdevs(0x0001, &basic_rx::make, boost::assign::list_of("a")("b")("ab")); } /*********************************************************************** @@ -36,17 +39,17 @@ static void register_internal_dboards(void){ //map a dboard id to a dboard constructor static std::map id_to_ctor_map; -//map a dboard constructor to number of subdevices -static std::map ctor_to_num_map; +//map a dboard constructor to subdevice names +static std::map ctor_to_names_map; void manager::register_subdevs( dboard_id_t dboard_id, dboard_ctor_t dboard_ctor, - size_t num_subdevs + const prop_names_t &subdev_names ){ register_internal_dboards(); //always call first id_to_ctor_map[dboard_id] = dboard_ctor; - ctor_to_num_map[dboard_ctor] = num_subdevs; + ctor_to_names_map[dboard_ctor] = subdev_names; } /*********************************************************************** @@ -119,27 +122,27 @@ manager::manager( const dboard_ctor_t tx_dboard_ctor = get_dboard_ctor(tx_dboard_id, "tx"); //make xcvr subdevs (make one subdev for both rx and tx dboards) if (rx_dboard_ctor == tx_dboard_ctor){ - for (size_t i = 0; i < ctor_to_num_map[rx_dboard_ctor]; i++){ + BOOST_FOREACH(std::string name, ctor_to_names_map[rx_dboard_ctor]){ base::sptr xcvr_dboard = rx_dboard_ctor( - base::ctor_args_t(i, dboard_interface) + base::ctor_args_t(name, dboard_interface) ); - _rx_dboards.push_back(xcvr_dboard); - _tx_dboards.push_back(xcvr_dboard); + _rx_dboards[name] = xcvr_dboard; + _tx_dboards[name] = xcvr_dboard; } } //make tx and rx subdevs (separate subdevs for rx and tx dboards) else{ //make the rx subdevs - for (size_t i = 0; i < ctor_to_num_map[rx_dboard_ctor]; i++){ - _rx_dboards.push_back(rx_dboard_ctor( - base::ctor_args_t(i, dboard_interface) - )); + BOOST_FOREACH(std::string name, ctor_to_names_map[rx_dboard_ctor]){ + _rx_dboards[name] = rx_dboard_ctor( + base::ctor_args_t(name, dboard_interface) + ); } //make the tx subdevs - for (size_t i = 0; i < ctor_to_num_map[tx_dboard_ctor]; i++){ - _tx_dboards.push_back(tx_dboard_ctor( - base::ctor_args_t(i, dboard_interface) - )); + BOOST_FOREACH(std::string name, ctor_to_names_map[tx_dboard_ctor]){ + _tx_dboards[name] = tx_dboard_ctor( + base::ctor_args_t(name, dboard_interface) + ); } } } @@ -148,22 +151,28 @@ manager::~manager(void){ /* NOP */ } -size_t manager::get_num_rx_subdevs(void){ - return _rx_dboards.size(); +prop_names_t manager::get_rx_subdev_names(void){ + return get_map_keys(_rx_dboards); } -size_t manager::get_num_tx_subdevs(void){ - return _tx_dboards.size(); +prop_names_t manager::get_tx_subdev_names(void){ + return get_map_keys(_tx_dboards); } -wax::obj::sptr manager::get_rx_subdev(size_t subdev_index){ +wax::obj::sptr manager::get_rx_subdev(const std::string &subdev_name){ + if (_rx_dboards.count(subdev_name) == 0) throw std::invalid_argument( + str(boost::format("Unknown rx subdev name %s") % subdev_name) + ); return wax::obj::sptr(new subdev_proxy( - _rx_dboards.at(subdev_index), subdev_proxy::RX_TYPE) + _rx_dboards[subdev_name], subdev_proxy::RX_TYPE) ); } -wax::obj::sptr manager::get_tx_subdev(size_t subdev_index){ +wax::obj::sptr manager::get_tx_subdev(const std::string &subdev_name){ + if (_tx_dboards.count(subdev_name) == 0) throw std::invalid_argument( + str(boost::format("Unknown tx subdev name %s") % subdev_name) + ); return wax::obj::sptr(new subdev_proxy( - _tx_dboards.at(subdev_index), subdev_proxy::TX_TYPE) + _tx_dboards[subdev_name], subdev_proxy::TX_TYPE) ); } -- cgit v1.2.3