summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-01-26 11:29:14 -0800
committerJosh Blum <josh@joshknows.com>2010-01-26 11:29:14 -0800
commita98e387578a3aceb15e2bcce4a9cc54d78c30dda (patch)
treeb5e34c422c36a16a3f2379698e81af4c00a66ee3
parent998aebf83c2796fdfabc2efd804ca14103adcaaf (diff)
downloaduhd-a98e387578a3aceb15e2bcce4a9cc54d78c30dda.tar.gz
uhd-a98e387578a3aceb15e2bcce4a9cc54d78c30dda.tar.bz2
uhd-a98e387578a3aceb15e2bcce4a9cc54d78c30dda.zip
Switched from indexed properties to named properties.
Added some new properties for getting a list of antenna names, pps sources, ref sources...
-rw-r--r--include/usrp_uhd/Makefile.am1
-rw-r--r--include/usrp_uhd/props.hpp25
-rw-r--r--include/usrp_uhd/usrp/dboard/base.hpp8
-rw-r--r--include/usrp_uhd/usrp/dboard/manager.hpp19
-rw-r--r--include/usrp_uhd/usrp/mboard/test.hpp4
-rw-r--r--include/usrp_uhd/usrp/usrp.hpp4
-rw-r--r--include/usrp_uhd/utils.hpp30
-rw-r--r--lib/usrp/dboard/base.cpp6
-rw-r--r--lib/usrp/dboard/manager.cpp63
-rw-r--r--lib/usrp/mboard/test.cpp57
-rw-r--r--lib/usrp/usrp.cpp23
-rw-r--r--test/device_test.cpp4
-rw-r--r--test/usrp_dboard_test.cpp12
13 files changed, 158 insertions, 98 deletions
diff --git a/include/usrp_uhd/Makefile.am b/include/usrp_uhd/Makefile.am
index 40c7d9f99..fdb881498 100644
--- a/include/usrp_uhd/Makefile.am
+++ b/include/usrp_uhd/Makefile.am
@@ -11,4 +11,5 @@ this_include_HEADERS = \
device.hpp \
device_addr.hpp \
props.hpp \
+ utils.hpp \
wax.hpp
diff --git a/include/usrp_uhd/props.hpp b/include/usrp_uhd/props.hpp
index c66f40674..6e416192c 100644
--- a/include/usrp_uhd/props.hpp
+++ b/include/usrp_uhd/props.hpp
@@ -6,6 +6,7 @@
#include <usrp_uhd/wax.hpp>
#include <complex>
#include <vector>
+#include <stdint.h>
#ifndef INCLUDED_USRP_UHD_PROPS_HPP
#define INCLUDED_USRP_UHD_PROPS_HPP
@@ -56,8 +57,9 @@ namespace usrp_uhd{
typedef std::vector<real_scalar_t> real_vec_t;
typedef std::vector<complex_scalar_t> complex_vec_t;
- //typedef for addressing indexable components
- typedef boost::tuple<wax::type, size_t> indexed_prop_t;
+ //typedef for handling named properties
+ typedef std::vector<std::string> prop_names_t;
+ typedef boost::tuple<wax::type, std::string> named_prop_t;
/*!
* Possible device properties.
@@ -65,7 +67,7 @@ namespace usrp_uhd{
enum device_prop_t{
DEVICE_PROP_NAME, //ro, std::string
DEVICE_PROP_MBOARD, //ro, wax::obj
- DEVICE_PROP_NUM_MBOARDS //ro, size_t
+ DEVICE_PROP_MBOARD_NAMES //ro, prop_names_t
};
/*!
@@ -76,16 +78,18 @@ namespace usrp_uhd{
MBOARD_PROP_MTU, //ro, size_t
MBOARD_PROP_CLOCK_RATE, //ro, freq_t
MBOARD_PROP_RX_DSP, //ro, wax::obj
- MBOARD_PROP_NUM_RX_DSPS, //ro, size_t
+ MBOARD_PROP_RX_DSP_NAMES, //ro, prop_names_t
MBOARD_PROP_TX_DSP, //ro, wax::obj
- MBOARD_PROP_NUM_TX_DSPS, //ro, size_t
+ MBOARD_PROP_TX_DSP_NAMES, //ro, prop_names_t
MBOARD_PROP_RX_DBOARD, //ro, wax::obj
- MBOARD_PROP_NUM_RX_DBOARDS, //ro, size_t
+ MBOARD_PROP_RX_DBOARD_NAMES, //ro, prop_names_t
MBOARD_PROP_TX_DBOARD, //ro, wax::obj
- MBOARD_PROP_NUM_TX_DBOARDS, //ro, size_t
+ MBOARD_PROP_TX_DBOARD_NAMES, //ro, prop_names_t
MBOARD_PROP_PPS_SOURCE, //rw, std::string (sma, mimo)
+ MBOARD_PROP_PPS_SOURCE_NAMES, //ro, prop_names_t
MBOARD_PROP_PPS_POLARITY, //rw, int, +/- 1
MBOARD_PROP_REF_SOURCE, //rw, std::string (int, sma, mimo)
+ MBOARD_PROP_REF_SOURCE_NAMES, //ro, prop_names_t
MBOARD_PROP_TIME_NOW, //wo, time_spec_t
MBOARD_PROP_TIME_NEXT_PPS //wo, time_spec_t
};
@@ -108,7 +112,7 @@ namespace usrp_uhd{
enum dboard_prop_t{
DBOARD_PROP_NAME, //ro, std::string
DBOARD_PROP_SUBDEV, //ro, wax::obj
- DBOARD_PROP_NUM_SUBDEVS, //ro, size_t
+ DBOARD_PROP_SUBDEV_NAMES, //ro, prop_names_t
DBOARD_PROP_CODEC //ro, wax::obj
};
@@ -121,7 +125,7 @@ namespace usrp_uhd{
CODEC_PROP_GAIN_MAX, //ro, gain_t
CODEC_PROP_GAIN_MIN, //ro, gain_t
CODEC_PROP_GAIN_STEP, //ro, gain_t
- CODEC_PROP_NUM_GAINS, //ro, size_t
+ CODEC_PROP_GAIN_NAMES, //ro, prop_names_t
CODEC_PROP_CLOCK_RATE //ro, freq_t
};
@@ -134,11 +138,12 @@ namespace usrp_uhd{
SUBDEV_PROP_GAIN_MAX, //ro, gain_t
SUBDEV_PROP_GAIN_MIN, //ro, gain_t
SUBDEV_PROP_GAIN_STEP, //ro, gain_t
- SUBDEV_PROP_NUM_GAINS, //ro, size_t
+ SUBDEV_PROP_GAIN_NAMES, //ro, prop_names_t
SUBDEV_PROP_FREQ, //rw, freq_t
SUBDEV_PROP_FREQ_MAX, //ro, freq_t
SUBDEV_PROP_FREQ_MIN, //ro, freq_t
SUBDEV_PROP_ANTENNA, //rw, std::string
+ SUBDEV_PROP_ANTENNA_NAMES, //ro, prop_names_t
SUBDEV_PROP_ENABLED, //rw, bool
SUBDEV_PROP_QUADRATURE, //ro, bool
SUBDEV_PROP_IQ_SWAPPED, //ro, bool
diff --git a/include/usrp_uhd/usrp/dboard/base.hpp b/include/usrp_uhd/usrp/dboard/base.hpp
index 0c207f564..2b839a6fc 100644
--- a/include/usrp_uhd/usrp/dboard/base.hpp
+++ b/include/usrp_uhd/usrp/dboard/base.hpp
@@ -20,10 +20,10 @@ namespace usrp_uhd{ namespace usrp{ namespace dboard{
class base : boost::noncopyable{
public:
typedef boost::shared_ptr<base> sptr;
- //the constructor args consist of a subdev index and an interface
+ //the constructor args consist of a subdev name and an interface
//derived classes should pass the args into the base class ctor
//but should not have to deal with the internals of the args
- typedef boost::tuple<size_t, interface::sptr> ctor_args_t;
+ typedef boost::tuple<std::string, interface::sptr> ctor_args_t;
//structors
base(ctor_args_t const&);
@@ -36,11 +36,11 @@ public:
virtual void tx_set(const wax::type &key, const wax::type &val) = 0;
protected:
- size_t get_subdev_index(void);
+ std::string get_subdev_name(void);
interface::sptr get_interface(void);
private:
- size_t _subdev_index;
+ std::string _subdev_name;
interface::sptr _dboard_interface;
};
diff --git a/include/usrp_uhd/usrp/dboard/manager.hpp b/include/usrp_uhd/usrp/dboard/manager.hpp
index d977fa527..4eaa9f889 100644
--- a/include/usrp_uhd/usrp/dboard/manager.hpp
+++ b/include/usrp_uhd/usrp/dboard/manager.hpp
@@ -5,8 +5,9 @@
#ifndef INCLUDED_USRP_UHD_USRP_DBOARD_MANAGER_HPP
#define INCLUDED_USRP_UHD_USRP_DBOARD_MANAGER_HPP
-#include <vector>
+#include <map>
#include <usrp_uhd/wax.hpp>
+#include <usrp_uhd/props.hpp>
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <usrp_uhd/usrp/dboard/base.hpp>
@@ -32,12 +33,12 @@ public:
*
* \param dboard_id the dboard id (rx or tx)
* \param dboard_ctor the dboard constructor function pointer
- * \param num_subdevs the number of subdevs in this dboard
+ * \param subdev_names the names of the subdevs on this dboard
*/
static void register_subdevs(
dboard_id_t dboard_id,
dboard_ctor_t dboard_ctor,
- size_t num_subdevs
+ const prop_names_t &subdev_names
);
public:
@@ -51,16 +52,16 @@ public:
~manager(void);
//interface
- size_t get_num_rx_subdevs(void);
- size_t get_num_tx_subdevs(void);
- wax::obj::sptr get_rx_subdev(size_t subdev_index);
- wax::obj::sptr get_tx_subdev(size_t subdev_index);
+ prop_names_t get_rx_subdev_names(void);
+ prop_names_t get_tx_subdev_names(void);
+ wax::obj::sptr get_rx_subdev(const std::string &subdev_name);
+ wax::obj::sptr get_tx_subdev(const std::string &subdev_name);
private:
//list of rx and tx dboards in this manager
//each dboard here is actually a subdevice
- std::vector<base::sptr> _rx_dboards;
- std::vector<base::sptr> _tx_dboards;
+ std::map<std::string, base::sptr> _rx_dboards;
+ std::map<std::string, base::sptr> _tx_dboards;
};
}}} //namespace
diff --git a/include/usrp_uhd/usrp/mboard/test.hpp b/include/usrp_uhd/usrp/mboard/test.hpp
index 10b46c7fc..4b28bba29 100644
--- a/include/usrp_uhd/usrp/mboard/test.hpp
+++ b/include/usrp_uhd/usrp/mboard/test.hpp
@@ -8,7 +8,7 @@
#include <usrp_uhd/usrp/mboard/base.hpp>
#include <usrp_uhd/device_addr.hpp>
#include <usrp_uhd/usrp/dboard/manager.hpp>
-#include <vector>
+#include <map>
namespace usrp_uhd{ namespace usrp{ namespace mboard{
@@ -25,7 +25,7 @@ private:
void get(const wax::type &, wax::type &);
void set(const wax::type &, const wax::type &);
- std::vector<dboard::manager::sptr> _dboard_managers;
+ std::map<std::string, dboard::manager::sptr> _dboard_managers;
};
}}} //namespace
diff --git a/include/usrp_uhd/usrp/usrp.hpp b/include/usrp_uhd/usrp/usrp.hpp
index 7506f798f..239f8b494 100644
--- a/include/usrp_uhd/usrp/usrp.hpp
+++ b/include/usrp_uhd/usrp/usrp.hpp
@@ -4,7 +4,7 @@
#include <usrp_uhd/device.hpp>
#include <usrp_uhd/usrp/mboard/base.hpp>
-#include <vector>
+#include <map>
#ifndef INCLUDED_USRP_UHD_USRP_USRP_HPP
#define INCLUDED_USRP_UHD_USRP_USRP_HPP
@@ -29,7 +29,7 @@ private:
void get(const wax::type &, wax::type &);
void set(const wax::type &, const wax::type &);
- std::vector<mboard::base::sptr> _mboards;
+ std::map<std::string, mboard::base::sptr> _mboards;
boost::function<void(const device::send_args_t &)> _send_raw_cb;
boost::function<void(const device::recv_args_t &)> _recv_raw_cb;
};
diff --git a/include/usrp_uhd/utils.hpp b/include/usrp_uhd/utils.hpp
new file mode 100644
index 000000000..6fe5bd4d4
--- /dev/null
+++ b/include/usrp_uhd/utils.hpp
@@ -0,0 +1,30 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+
+#include <boost/foreach.hpp>
+#include <map>
+#include <vector>
+
+#ifndef INCLUDED_USRP_UHD_UTILS_HPP
+#define INCLUDED_USRP_UHD_UTILS_HPP
+
+namespace usrp_uhd{
+
+template <class Key, class T>
+std::vector<Key> get_map_keys(const std::map<Key, T> &m){
+ std::vector<Key> v;
+ std::pair<Key, T> p;
+ BOOST_FOREACH(p, m){
+ v.push_back(p.first);
+ }
+ return v;
+}
+
+//TODO check name in vector of names
+
+//TODO optionally extract a name from the named_prop_t
+
+} //namespace usrp_uhd
+
+#endif /* INCLUDED_USRP_UHD_UTILS_HPP */
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 <usrp_uhd/usrp/dboard/manager.hpp>
+#include <usrp_uhd/utils.hpp>
+#include <boost/assign/list_of.hpp>
#include <boost/format.hpp>
-#include <map>
+#include <boost/foreach.hpp>
#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<manager::dboard_id_t, manager::dboard_ctor_t> id_to_ctor_map;
-//map a dboard constructor to number of subdevices
-static std::map<manager::dboard_ctor_t, size_t> ctor_to_num_map;
+//map a dboard constructor to subdevice names
+static std::map<manager::dboard_ctor_t, prop_names_t> 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)
);
}
diff --git a/lib/usrp/mboard/test.cpp b/lib/usrp/mboard/test.cpp
index 6bcbea94f..cf9a5cb52 100644
--- a/lib/usrp/mboard/test.cpp
+++ b/lib/usrp/mboard/test.cpp
@@ -3,7 +3,10 @@
//
#include <usrp_uhd/usrp/mboard/test.hpp>
+#include <usrp_uhd/utils.hpp>
#include <usrp_uhd/props.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/format.hpp>
#include <stdexcept>
using namespace usrp_uhd;
@@ -42,10 +45,10 @@ public:
~shell_dboard(void){}
private:
void get(const wax::type &key_, wax::type &val){
- //extract the index if key is an indexed prop
- wax::type key = key_; size_t index = 0;
- if (key.type() == typeid(indexed_prop_t)){
- boost::tie(key, index) = wax::cast<indexed_prop_t>(key);
+ //extract the index if key is a named prop
+ wax::type key = key_; std::string name = "";
+ if (key.type() == typeid(named_prop_t)){
+ boost::tie(key, name) = wax::cast<named_prop_t>(key);
}
//handle the get request conditioned on the key
@@ -57,22 +60,22 @@ private:
case DBOARD_PROP_SUBDEV:
switch(_type){
case TYPE_RX:
- val = _mgr->get_rx_subdev(index);
+ val = _mgr->get_rx_subdev(name);
return;
case TYPE_TX:
- val = _mgr->get_tx_subdev(index);
+ val = _mgr->get_tx_subdev(name);
return;
}
- case DBOARD_PROP_NUM_SUBDEVS:
+ case DBOARD_PROP_SUBDEV_NAMES:
switch(_type){
case TYPE_RX:
- val = _mgr->get_num_rx_subdevs();
+ val = _mgr->get_rx_subdev_names();
return;
case TYPE_TX:
- val = _mgr->get_num_tx_subdevs();
+ val = _mgr->get_tx_subdev_names();
return;
}
@@ -97,9 +100,9 @@ test::test(const device_addr_t &device_addr){
//create a manager for each dboard
for (size_t i = 0; i < device_addr.virtual_args.num_dboards; i++){
dboard::interface::sptr ifc(new dummy_interface());
- _dboard_managers.push_back(dboard::manager::sptr(
+ _dboard_managers[boost::lexical_cast<std::string>(i)] = dboard::manager::sptr(
new dboard::manager(0x0001, 0x0000, ifc)
- ));
+ );
}
}
@@ -108,10 +111,10 @@ test::~test(void){
}
void test::get(const wax::type &key_, wax::type &val){
- //extract the index if key is an indexed prop
- wax::type key = key_; size_t index = 0;
- if (key.type() == typeid(indexed_prop_t)){
- boost::tie(key, index) = wax::cast<indexed_prop_t>(key);
+ //extract the index if key is a named prop
+ wax::type key = key_; std::string name = "";
+ if (key.type() == typeid(named_prop_t)){
+ boost::tie(key, name) = wax::cast<named_prop_t>(key);
}
//handle the get request conditioned on the key
@@ -121,34 +124,42 @@ void test::get(const wax::type &key_, wax::type &val){
return;
case MBOARD_PROP_RX_DBOARD:
+ if (_dboard_managers.count(name) == 0) throw std::invalid_argument(
+ str(boost::format("Unknown rx dboard name %s") % name)
+ );
val = wax::obj::sptr(
- new shell_dboard(_dboard_managers.at(index), shell_dboard::TYPE_RX)
+ new shell_dboard(_dboard_managers[name], shell_dboard::TYPE_RX)
);
return;
- case MBOARD_PROP_NUM_RX_DBOARDS:
- val = size_t(_dboard_managers.size());
+ case MBOARD_PROP_RX_DBOARD_NAMES:
+ val = prop_names_t(get_map_keys(_dboard_managers));
return;
case MBOARD_PROP_TX_DBOARD:
+ if (_dboard_managers.count(name) == 0) throw std::invalid_argument(
+ str(boost::format("Unknown tx dboard name %s") % name)
+ );
val = wax::obj::sptr(
- new shell_dboard(_dboard_managers.at(index), shell_dboard::TYPE_TX)
+ new shell_dboard(_dboard_managers[name], shell_dboard::TYPE_TX)
);
return;
- case MBOARD_PROP_NUM_TX_DBOARDS:
- val = size_t(_dboard_managers.size());
+ case MBOARD_PROP_TX_DBOARD_NAMES:
+ val = prop_names_t(get_map_keys(_dboard_managers));
return;
case MBOARD_PROP_MTU:
case MBOARD_PROP_CLOCK_RATE:
case MBOARD_PROP_RX_DSP:
- case MBOARD_PROP_NUM_RX_DSPS:
+ case MBOARD_PROP_RX_DSP_NAMES:
case MBOARD_PROP_TX_DSP:
- case MBOARD_PROP_NUM_TX_DSPS:
+ case MBOARD_PROP_TX_DSP_NAMES:
case MBOARD_PROP_PPS_SOURCE:
+ case MBOARD_PROP_PPS_SOURCE_NAMES:
case MBOARD_PROP_PPS_POLARITY:
case MBOARD_PROP_REF_SOURCE:
+ case MBOARD_PROP_REF_SOURCE_NAMES:
case MBOARD_PROP_TIME_NOW:
case MBOARD_PROP_TIME_NEXT_PPS:
throw std::runtime_error("unhandled prop is usrp test mboard");
diff --git a/lib/usrp/usrp.cpp b/lib/usrp/usrp.cpp
index 5838ab90a..02446c8d1 100644
--- a/lib/usrp/usrp.cpp
+++ b/lib/usrp/usrp.cpp
@@ -4,6 +4,8 @@
#include <usrp_uhd/usrp/usrp.hpp>
#include <usrp_uhd/usrp/mboard/test.hpp>
+#include <usrp_uhd/utils.hpp>
+#include <boost/format.hpp>
#include <boost/bind.hpp>
#include <stdexcept>
@@ -31,9 +33,7 @@ usrp::usrp(const device_addr_t & device_addr){
//create mboard based on the device addr
if (device_addr.type == DEVICE_ADDR_TYPE_VIRTUAL){
- _mboards.push_back(
- mboard::base::sptr(new mboard::test(device_addr))
- );
+ _mboards[""] = mboard::base::sptr(new mboard::test(device_addr));
}
}
@@ -42,10 +42,10 @@ usrp::~usrp(void){
}
void usrp::get(const wax::type &key_, wax::type &val){
- //extract the index if key is an indexed prop
- wax::type key = key_; size_t index = 0;
- if (key.type() == typeid(indexed_prop_t)){
- boost::tie(key, index) = wax::cast<indexed_prop_t>(key);
+ //extract the index if key is a named prop
+ wax::type key = key_; std::string name = "";
+ if (key.type() == typeid(named_prop_t)){
+ boost::tie(key, name) = wax::cast<named_prop_t>(key);
}
//handle the get request conditioned on the key
@@ -55,13 +55,16 @@ void usrp::get(const wax::type &key_, wax::type &val){
return;
case DEVICE_PROP_MBOARD:
+ if (_mboards.count(name) == 0) throw std::invalid_argument(
+ str(boost::format("Unknown mboard name %s") % name)
+ );
//turn the mboard sptr object into a wax::obj::sptr
//this allows the properties access through the wax::proxy
- val = wax::obj::cast(_mboards.at(index));
+ val = wax::obj::cast(_mboards[name]);
return;
- case DEVICE_PROP_NUM_MBOARDS:
- val = size_t(_mboards.size());
+ case DEVICE_PROP_MBOARD_NAMES:
+ val = prop_names_t(get_map_keys(_mboards));
return;
}
}
diff --git a/test/device_test.cpp b/test/device_test.cpp
index db305097b..db5810d3d 100644
--- a/test/device_test.cpp
+++ b/test/device_test.cpp
@@ -22,11 +22,11 @@ BOOST_AUTO_TEST_CASE(test_device){
std::cout << wax::cast<std::string>(mb0[MBOARD_PROP_NAME]) << std::endl;
BOOST_CHECK_EQUAL(
device_addr.virtual_args.num_dboards,
- wax::cast<size_t>(mb0[MBOARD_PROP_NUM_RX_DBOARDS])
+ wax::cast<prop_names_t>(mb0[MBOARD_PROP_RX_DBOARD_NAMES]).size()
);
BOOST_CHECK_EQUAL(
device_addr.virtual_args.num_dboards,
- wax::cast<size_t>(mb0[MBOARD_PROP_NUM_TX_DBOARDS])
+ wax::cast<prop_names_t>(mb0[MBOARD_PROP_TX_DBOARD_NAMES]).size()
);
}
diff --git a/test/usrp_dboard_test.cpp b/test/usrp_dboard_test.cpp
index 1e89f36f9..e95068be6 100644
--- a/test/usrp_dboard_test.cpp
+++ b/test/usrp_dboard_test.cpp
@@ -34,12 +34,12 @@ BOOST_AUTO_TEST_CASE(test_manager){
manager::sptr mgr0(new manager(0x0001, 0x0000, ifc0)); //basic rx, basic tx
std::cout << "Testing the dboard manager..." << std::endl;
- BOOST_CHECK_EQUAL(size_t(3), mgr0->get_num_rx_subdevs());
- BOOST_CHECK_EQUAL(size_t(1), mgr0->get_num_tx_subdevs());
+ BOOST_CHECK_EQUAL(size_t(3), mgr0->get_rx_subdev_names().size());
+ BOOST_CHECK_EQUAL(size_t(1), mgr0->get_tx_subdev_names().size());
std::cout << "Testing access (will fail later when db code filled in)..." << std::endl;
- BOOST_CHECK_THROW(mgr0->get_rx_subdev(3), std::out_of_range);
- BOOST_CHECK_THROW(mgr0->get_tx_subdev(1), std::out_of_range);
- (*mgr0->get_rx_subdev(0))[NULL];
- (*mgr0->get_tx_subdev(0))[NULL];
+ BOOST_CHECK_THROW(mgr0->get_rx_subdev(""), std::invalid_argument);
+ BOOST_CHECK_THROW(mgr0->get_tx_subdev("x"), std::invalid_argument);
+ (*mgr0->get_rx_subdev("a"))[NULL];
+ (*mgr0->get_tx_subdev(""))[NULL];
}