diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/usrp/dboard/Makefile.am | 4 | ||||
-rw-r--r-- | lib/usrp/dboard/base.cpp | 67 | ||||
-rw-r--r-- | lib/usrp/dboard/manager.cpp | 100 |
3 files changed, 170 insertions, 1 deletions
diff --git a/lib/usrp/dboard/Makefile.am b/lib/usrp/dboard/Makefile.am index 8d77dcc42..7bbf4e4f8 100644 --- a/lib/usrp/dboard/Makefile.am +++ b/lib/usrp/dboard/Makefile.am @@ -11,7 +11,9 @@ AM_CPPFLAGS = $(GENERAL_CPPFLAGS) noinst_LTLIBRARIES = lib.la lib_la_SOURCES = \ - interface.cpp + base.cpp \ + interface.cpp \ + manager.cpp lib_la_LIBADD = $(GENERAL_LDDFLAGS) diff --git a/lib/usrp/dboard/base.cpp b/lib/usrp/dboard/base.cpp new file mode 100644 index 000000000..3166cdedc --- /dev/null +++ b/lib/usrp/dboard/base.cpp @@ -0,0 +1,67 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/usrp/dboard/base.hpp> + +using namespace usrp_uhd::usrp::dboard; + +/*********************************************************************** + * xcvr dboard base class + **********************************************************************/ +xcvr_base::xcvr_base(size_t subdev_index, interface::sptr dboard_interface) + : _subdev_index(subdev_index), _dboard_interface(dboard_interface){ + /* NOP */ +} + +xcvr_base::~xcvr_base(void){ + /* NOP */ +} + +size_t xcvr_base::get_subdev_index(void){ + return _subdev_index; +} + +interface::sptr xcvr_base::get_interface(void){ + return _dboard_interface; +} + +/*********************************************************************** + * rx dboard base class + **********************************************************************/ +rx_base::rx_base(size_t subdev_index, interface::sptr dboard_interface) +: xcvr_base(subdev_index, dboard_interface){ + /* NOP */ +} + +rx_base::~rx_base(void){ + /* NOP */ +} + +void rx_base::tx_get(const wax::type &key, wax::type &val){ + throw std::runtime_error("cannot call tx_get on a rx dboard"); +} + +void rx_base::tx_set(const wax::type &key, const wax::type &val){ + throw std::runtime_error("cannot call tx_set on a rx dboard"); +} + +/*********************************************************************** + * tx dboard base class + **********************************************************************/ +tx_base::tx_base(size_t subdev_index, interface::sptr dboard_interface) +: xcvr_base(subdev_index, dboard_interface){ + /* NOP */ +} + +tx_base::~tx_base(void){ + /* NOP */ +} + +void tx_base::rx_get(const wax::type &key, wax::type &val){ + throw std::runtime_error("cannot call rx_get on a tx dboard"); +} + +void tx_base::rx_set(const wax::type &key, const wax::type &val){ + throw std::runtime_error("cannot call rx_set on a tx dboard"); +} diff --git a/lib/usrp/dboard/manager.cpp b/lib/usrp/dboard/manager.cpp new file mode 100644 index 000000000..1ed563777 --- /dev/null +++ b/lib/usrp/dboard/manager.cpp @@ -0,0 +1,100 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/usrp/dboard/manager.hpp> + +using namespace usrp_uhd::usrp::dboard; + +/*********************************************************************** + * internal helper classes + **********************************************************************/ +/*! + * A special wax proxy object that forwards calls to a subdev. + * A sptr to an instance will be used in the properties structure. + */ +class subdev_proxy : boost::noncopyable, public wax::obj{ +public: + typedef boost::shared_ptr<subdev_proxy> sptr; + enum type_t{RX_TYPE, TX_TYPE}; + + //structors + subdev_proxy(xcvr_base::sptr dboard, type_t type) + : _dboard(dboard), _type(type){ + /* NOP */ + } + + ~subdev_proxy(void){ + /* NOP */ + } + +private: + xcvr_base::sptr _dboard; + type_t _type; + + //forward the get calls to the rx or tx + void get(const wax::type &key, wax::type &val){ + switch(_type){ + case RX_TYPE: return _dboard->rx_get(key, val); + case TX_TYPE: return _dboard->tx_get(key, val); + } + } + + //forward the set calls to the rx or tx + void set(const wax::type &key, const wax::type &val){ + switch(_type){ + case RX_TYPE: return _dboard->rx_set(key, val); + case TX_TYPE: return _dboard->tx_set(key, val); + } + } +}; + +/*********************************************************************** + * dboard manager methods + **********************************************************************/ +//include dboard derived classes: +//TODO #inlude "basic.hpp" + +#define MAKE_DBOARD_ID_WORD(rx_id, tx_id) \ + ((uint32_t(rx_id) << 16) | (uint32_t(tx_id) << 0)) + +manager::manager( + uint16_t rx_dboard_id, + uint16_t tx_dboard_id, + interface::sptr dboard_interface +){ + //TODO build some boards based on ids + //xcvrs will be added to both vectors + switch(MAKE_DBOARD_ID_WORD(rx_dboard_id, tx_dboard_id)){ + default: + //_rx_dboards.push_back(xcvr_base::sptr(new basic_rx(0, dboard_interface))); + //_rx_dboards.push_back(xcvr_base::sptr(new basic_rx(1, dboard_interface))); + //_rx_dboards.push_back(xcvr_base::sptr(new basic_rx(2, dboard_interface))); + //_tx_dboards.push_back(xcvr_base::sptr(new basic_tx(0, dboard_interface))); + break; + } +} + +manager::~manager(void){ + /* NOP */ +} + +size_t manager::get_num_rx_subdevs(void){ + return _rx_dboards.size(); +} + +size_t manager::get_num_tx_subdevs(void){ + return _tx_dboards.size(); +} + +wax::obj::sptr manager::get_rx_subdev(size_t subdev_index){ + return wax::obj::sptr(new subdev_proxy( + _rx_dboards.at(subdev_index), subdev_proxy::RX_TYPE) + ); +} + +wax::obj::sptr manager::get_tx_subdev(size_t subdev_index){ + return wax::obj::sptr(new subdev_proxy( + _tx_dboards.at(subdev_index), subdev_proxy::TX_TYPE) + ); +} |