aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--host/apps/discover_usrps.cpp4
-rw-r--r--host/include/uhd/usrp/dboard/base.hpp6
-rw-r--r--host/include/uhd/usrp/dboard/id.hpp8
-rw-r--r--host/lib/usrp/dboard/base.cpp36
-rw-r--r--host/lib/usrp/dboard/id.cpp11
-rw-r--r--host/lib/usrp/dboard/manager.cpp54
6 files changed, 82 insertions, 37 deletions
diff --git a/host/apps/discover_usrps.cpp b/host/apps/discover_usrps.cpp
index 92c90f89a..02c05b7cc 100644
--- a/host/apps/discover_usrps.cpp
+++ b/host/apps/discover_usrps.cpp
@@ -16,6 +16,7 @@
//
#include <uhd.hpp>
+#include <uhd/props.hpp>
#include <boost/program_options.hpp>
#include <boost/format.hpp>
#include <iostream>
@@ -58,7 +59,8 @@ int main(int argc, char *argv[]){
std::cout << "--------------------------------------------------" << std::endl;
std::cout << device_addrs[i] << std::endl << std::endl;
//make each device just to test (TODO: remove this)
- device::make(device_addrs[i]);
+ uhd::device::sptr dev = device::make(device_addrs[i]);
+ std::cout << wax::cast<std::string>((*dev)[uhd::DEVICE_PROP_MBOARD][uhd::MBOARD_PROP_NAME]) << std::endl;
}
return 0;
diff --git a/host/include/uhd/usrp/dboard/base.hpp b/host/include/uhd/usrp/dboard/base.hpp
index 845e2f669..111820a8b 100644
--- a/host/include/uhd/usrp/dboard/base.hpp
+++ b/host/include/uhd/usrp/dboard/base.hpp
@@ -22,6 +22,7 @@
#include <boost/utility.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/tuple/tuple.hpp>
+#include <uhd/usrp/dboard/id.hpp>
#include <uhd/usrp/dboard/interface.hpp>
namespace uhd{ namespace usrp{ namespace dboard{
@@ -36,7 +37,7 @@ public:
//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<std::string, interface::sptr> ctor_args_t;
+ typedef boost::tuple<std::string, interface::sptr, dboard_id_t, dboard_id_t> ctor_args_t;
//structors
base(ctor_args_t const&);
@@ -51,10 +52,13 @@ public:
protected:
std::string get_subdev_name(void);
interface::sptr get_interface(void);
+ dboard_id_t get_rx_id(void);
+ dboard_id_t get_tx_id(void);
private:
std::string _subdev_name;
interface::sptr _dboard_interface;
+ dboard_id_t _rx_id, _tx_id;
};
/*!
diff --git a/host/include/uhd/usrp/dboard/id.hpp b/host/include/uhd/usrp/dboard/id.hpp
index 98c0acc3a..a890ee096 100644
--- a/host/include/uhd/usrp/dboard/id.hpp
+++ b/host/include/uhd/usrp/dboard/id.hpp
@@ -15,7 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#include <iostream>
+#include <string>
#ifndef INCLUDED_UHD_USRP_DBOARD_ID_HPP
#define INCLUDED_UHD_USRP_DBOARD_ID_HPP
@@ -28,8 +28,10 @@ enum dboard_id_t{
ID_BASIC_RX = 0x0001
};
-}}} //namespace
+struct id{
+ static std::string to_string(const dboard_id_t &id);
+};
-std::ostream& operator<<(std::ostream &, const uhd::usrp::dboard::dboard_id_t &);
+}}} //namespace
#endif /* INCLUDED_UHD_USRP_DBOARD_ID_HPP */
diff --git a/host/lib/usrp/dboard/base.cpp b/host/lib/usrp/dboard/base.cpp
index de8db323a..92a886407 100644
--- a/host/lib/usrp/dboard/base.cpp
+++ b/host/lib/usrp/dboard/base.cpp
@@ -16,6 +16,7 @@
//
#include <uhd/usrp/dboard/base.hpp>
+#include <boost/format.hpp>
#include <stdexcept>
using namespace uhd::usrp::dboard;
@@ -24,7 +25,7 @@ using namespace uhd::usrp::dboard;
* base dboard base class
**********************************************************************/
base::base(ctor_args_t const& args){
- boost::tie(_subdev_name, _dboard_interface) = args;
+ boost::tie(_subdev_name, _dboard_interface, _rx_id, _tx_id) = args;
}
base::~base(void){
@@ -39,11 +40,28 @@ interface::sptr base::get_interface(void){
return _dboard_interface;
}
+dboard_id_t base::get_rx_id(void){
+ return _rx_id;
+}
+
+dboard_id_t base::get_tx_id(void){
+ return _tx_id;
+}
+
/***********************************************************************
* xcvr dboard base class
**********************************************************************/
xcvr_base::xcvr_base(ctor_args_t const& args) : base(args){
- /* NOP */
+ if (get_rx_id() == ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create xcvr board when the rx id is \"%s\""
+ ) % id::to_string(ID_NONE)));
+ }
+ if (get_tx_id() == ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create xcvr board when the tx id is \"%s\""
+ ) % id::to_string(ID_NONE)));
+ }
}
xcvr_base::~xcvr_base(void){
@@ -54,7 +72,12 @@ xcvr_base::~xcvr_base(void){
* rx dboard base class
**********************************************************************/
rx_base::rx_base(ctor_args_t const& args) : base(args){
- /* NOP */
+ if (get_tx_id() != ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create rx board when the tx id is \"%s\""
+ " -> expected a tx id of \"%s\""
+ ) % id::to_string(get_tx_id()) % id::to_string(ID_NONE)));
+ }
}
rx_base::~rx_base(void){
@@ -73,7 +96,12 @@ void rx_base::tx_set(const wax::obj &, const wax::obj &){
* tx dboard base class
**********************************************************************/
tx_base::tx_base(ctor_args_t const& args) : base(args){
- /* NOP */
+ if (get_rx_id() != ID_NONE){
+ throw std::runtime_error(str(boost::format(
+ "cannot create tx board when the rx id is \"%s\""
+ " -> expected a rx id of \"%s\""
+ ) % id::to_string(get_rx_id()) % id::to_string(ID_NONE)));
+ }
}
tx_base::~tx_base(void){
diff --git a/host/lib/usrp/dboard/id.cpp b/host/lib/usrp/dboard/id.cpp
index 80162240e..b62e469de 100644
--- a/host/lib/usrp/dboard/id.cpp
+++ b/host/lib/usrp/dboard/id.cpp
@@ -21,7 +21,7 @@
using namespace uhd::usrp::dboard;
-std::ostream& operator<<(std::ostream &os, const dboard_id_t &id){
+std::string id::to_string(const dboard_id_t &id){
//map the dboard ids to string representations
uhd::dict<dboard_id_t, std::string> id_to_str;
id_to_str[ID_NONE] = "none";
@@ -29,11 +29,6 @@ std::ostream& operator<<(std::ostream &os, const dboard_id_t &id){
id_to_str[ID_BASIC_RX] = "basic rx";
//get the string representation
- if (id_to_str.has_key(id)){
- os << id_to_str[id];
- }
- else{
- os << boost::format("dboard id %u") % unsigned(id);
- }
- return os;
+ std::string name = (id_to_str.has_key(id))? id_to_str[id] : "unknown";
+ return str(boost::format("%s (0x%.4x)") % name % id);
}
diff --git a/host/lib/usrp/dboard/manager.cpp b/host/lib/usrp/dboard/manager.cpp
index 3540cd1bc..337c31ad6 100644
--- a/host/lib/usrp/dboard/manager.cpp
+++ b/host/lib/usrp/dboard/manager.cpp
@@ -16,7 +16,9 @@
//
#include <uhd/usrp/dboard/manager.hpp>
+#include <uhd/utils.hpp>
#include <boost/assign/list_of.hpp>
+#include <boost/tuple/tuple.hpp>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include "dboards.hpp"
@@ -42,8 +44,6 @@ static void register_internal_dboards(void){
static bool called = false;
if (called) return; called = true;
//register the known dboards (dboard id, constructor, subdev names)
- manager::register_subdevs(ID_NONE, &basic_tx::make, list_of("")); //for none, make a basic tx
- manager::register_subdevs(ID_NONE, &basic_rx::make, list_of("ab")); //for none, make a basic rx (one subdev)
manager::register_subdevs(ID_BASIC_TX, &basic_tx::make, list_of(""));
manager::register_subdevs(ID_BASIC_RX, &basic_rx::make, list_of("a")("b")("ab"));
}
@@ -51,11 +51,10 @@ static void register_internal_dboards(void){
/***********************************************************************
* storage and registering for dboards
**********************************************************************/
-//map a dboard id to a dboard constructor
-static uhd::dict<dboard_id_t, manager::dboard_ctor_t> id_to_ctor_map;
+typedef boost::tuple<manager::dboard_ctor_t, prop_names_t> args_t;
-//map a dboard constructor to subdevice names
-static uhd::dict<manager::dboard_ctor_t, prop_names_t> ctor_to_names_map;
+//map a dboard id to a dboard constructor
+static uhd::dict<dboard_id_t, args_t> id_to_args_map;
void manager::register_subdevs(
dboard_id_t dboard_id,
@@ -63,8 +62,7 @@ void manager::register_subdevs(
const prop_names_t &subdev_names
){
register_internal_dboards(); //always call first
- id_to_ctor_map[dboard_id] = dboard_ctor;
- ctor_to_names_map[dboard_ctor] = subdev_names;
+ id_to_args_map[dboard_id] = args_t(dboard_ctor, subdev_names);
}
/***********************************************************************
@@ -113,18 +111,29 @@ private:
/***********************************************************************
* dboard manager methods
**********************************************************************/
-static manager::dboard_ctor_t const& get_dboard_ctor(
+static args_t get_dboard_args(
dboard_id_t dboard_id,
std::string const& xx_type
){
+ //special case, its rx and the none id (0xffff)
+ if (xx_type == "rx" and dboard_id == ID_NONE){
+ return args_t(&basic_rx::make, list_of("ab"));
+ }
+
+ //special case, its tx and the none id (0xffff)
+ if (xx_type == "tx" and dboard_id == ID_NONE){
+ return args_t(&basic_tx::make, list_of(""));
+ }
+
//verify that there is a registered constructor for this id
- if (not id_to_ctor_map.has_key(dboard_id)){
+ if (not id_to_args_map.has_key(dboard_id)){
throw std::runtime_error(str(
boost::format("Unknown %s dboard id: 0x%04x") % xx_type % dboard_id
));
}
- //return the dboard constructor for this id
- return id_to_ctor_map[dboard_id];
+
+ //return the dboard args for this id
+ return id_to_args_map[dboard_id];
}
manager::manager(
@@ -133,8 +142,12 @@ manager::manager(
interface::sptr dboard_interface
){
register_internal_dboards(); //always call first
- const dboard_ctor_t rx_dboard_ctor = get_dboard_ctor(rx_dboard_id, "rx");
- const dboard_ctor_t tx_dboard_ctor = get_dboard_ctor(tx_dboard_id, "tx");
+
+ dboard_ctor_t rx_dboard_ctor; prop_names_t rx_subdevs;
+ boost::tie(rx_dboard_ctor, rx_subdevs) = get_dboard_args(rx_dboard_id, "rx");
+
+ dboard_ctor_t tx_dboard_ctor; prop_names_t tx_subdevs;
+ boost::tie(tx_dboard_ctor, tx_subdevs) = get_dboard_args(tx_dboard_id, "tx");
//initialize the gpio pins before creating subdevs
dboard_interface->set_gpio_ddr(interface::GPIO_RX_BANK, 0x0000, 0xffff); //all inputs
@@ -148,9 +161,10 @@ manager::manager(
//make xcvr subdevs (make one subdev for both rx and tx dboards)
if (rx_dboard_ctor == tx_dboard_ctor){
- BOOST_FOREACH(std::string name, ctor_to_names_map[rx_dboard_ctor]){
+ ASSERT_THROW(rx_subdevs == tx_subdevs);
+ BOOST_FOREACH(std::string name, rx_subdevs){
base::sptr xcvr_dboard = rx_dboard_ctor(
- base::ctor_args_t(name, dboard_interface)
+ base::ctor_args_t(name, dboard_interface, rx_dboard_id, tx_dboard_id)
);
//create a rx proxy for this xcvr board
_rx_dboards[name] = subdev_proxy::sptr(
@@ -166,9 +180,9 @@ manager::manager(
//make tx and rx subdevs (separate subdevs for rx and tx dboards)
else{
//make the rx subdevs
- BOOST_FOREACH(std::string name, ctor_to_names_map[rx_dboard_ctor]){
+ BOOST_FOREACH(std::string name, rx_subdevs){
base::sptr rx_dboard = rx_dboard_ctor(
- base::ctor_args_t(name, dboard_interface)
+ base::ctor_args_t(name, dboard_interface, rx_dboard_id, ID_NONE)
);
//create a rx proxy for this rx board
_rx_dboards[name] = subdev_proxy::sptr(
@@ -176,9 +190,9 @@ manager::manager(
);
}
//make the tx subdevs
- BOOST_FOREACH(std::string name, ctor_to_names_map[tx_dboard_ctor]){
+ BOOST_FOREACH(std::string name, tx_subdevs){
base::sptr tx_dboard = tx_dboard_ctor(
- base::ctor_args_t(name, dboard_interface)
+ base::ctor_args_t(name, dboard_interface, ID_NONE, tx_dboard_id)
);
//create a tx proxy for this tx board
_tx_dboards[name] = subdev_proxy::sptr(