diff options
Diffstat (limited to 'lib/usrp')
-rw-r--r-- | lib/usrp/mboard/usrp2.cpp | 8 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2_dboard_interface.hpp | 6 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2_impl.cpp | 122 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2_impl.hpp | 33 |
4 files changed, 156 insertions, 13 deletions
diff --git a/lib/usrp/mboard/usrp2.cpp b/lib/usrp/mboard/usrp2.cpp index 6bd9bee83..79b9429c8 100644 --- a/lib/usrp/mboard/usrp2.cpp +++ b/lib/usrp/mboard/usrp2.cpp @@ -105,13 +105,13 @@ usrp2::~usrp2(void){ /*********************************************************************** * Get Properties **********************************************************************/ -void usrp2::get(const wax::obj &, wax::obj &){ - +void usrp2::get(const wax::obj &key, wax::obj &val){ + return wax::cast<usrp2_impl::sptr>(_impl)->get(key, val); } /*********************************************************************** * Set Properties **********************************************************************/ -void usrp2::set(const wax::obj &, const wax::obj &){ - +void usrp2::set(const wax::obj &key, const wax::obj &val){ + return wax::cast<usrp2_impl::sptr>(_impl)->set(key, val); } diff --git a/lib/usrp/mboard/usrp2_dboard_interface.hpp b/lib/usrp/mboard/usrp2_dboard_interface.hpp index 24dff797b..c2bb9edb0 100644 --- a/lib/usrp/mboard/usrp2_dboard_interface.hpp +++ b/lib/usrp/mboard/usrp2_dboard_interface.hpp @@ -23,8 +23,8 @@ class usrp2_dboard_interface : public uhd::usrp::dboard::interface{ public: - usrp2_dboard_interface(const usrp2_impl *impl) : _impl(impl){ - /* NOP */ + usrp2_dboard_interface(usrp2_impl *impl){ + _impl = impl; } ~usrp2_dboard_interface(void){ @@ -60,7 +60,7 @@ public: } private: - const usrp2_impl *_impl; + usrp2_impl *_impl; }; #endif /* INCLUDED_USRP2_DBOARD_INTERFACE_HPP */ diff --git a/lib/usrp/mboard/usrp2_impl.cpp b/lib/usrp/mboard/usrp2_impl.cpp index a9c58c4fe..d607bb7e7 100644 --- a/lib/usrp/mboard/usrp2_impl.cpp +++ b/lib/usrp/mboard/usrp2_impl.cpp @@ -15,15 +15,72 @@ // along with this program. If not, see <http://www.gnu.org/licenses/>. // -#include <boost/thread.hpp> #include <boost/format.hpp> #include <uhd/utils.hpp> +#include <uhd/props.hpp> #include <iostream> #include "usrp2_impl.hpp" #include "usrp2_dboard_interface.hpp" +using namespace uhd; using namespace uhd::usrp; +/*********************************************************************** + * USRP2 DBoard Wrapper + **********************************************************************/ +usrp2_dboard::usrp2_dboard(uhd::usrp::dboard::manager::sptr mgr, type_t type){ + _mgr = mgr; + _type = type; +} + +usrp2_dboard::~usrp2_dboard(void){ + /* NOP */ +} + +void usrp2_dboard::get(const wax::obj &key_, wax::obj &val){ + wax::obj key; std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(wax::cast<dboard_prop_t>(key)){ + case DBOARD_PROP_NAME: + val = std::string("usrp2 dboard"); + return; + + case DBOARD_PROP_SUBDEV: + switch(_type){ + case TYPE_RX: + val = _mgr->get_rx_subdev(name); + return; + + case TYPE_TX: + val = _mgr->get_tx_subdev(name); + return; + } + + case DBOARD_PROP_SUBDEV_NAMES: + switch(_type){ + case TYPE_RX: + val = _mgr->get_rx_subdev_names(); + return; + + case TYPE_TX: + val = _mgr->get_tx_subdev_names(); + return; + } + + case DBOARD_PROP_CODEC: + throw std::runtime_error("unhandled prop in usrp2 dboard"); + } +} + +void usrp2_dboard::set(const wax::obj &, const wax::obj &){ + throw std::runtime_error("Cannot set on usrp2 dboard"); +} + +/*********************************************************************** + * USRP2 Implementation + **********************************************************************/ usrp2_impl::usrp2_impl( uhd::transport::udp::sptr ctrl_transport, uhd::transport::udp::sptr data_transport @@ -49,19 +106,31 @@ usrp2_impl::usrp2_impl( ); //create a new dboard interface and manager - _dboard_interface = dboard::interface::sptr( + dboard::interface::sptr dboard_interface( new usrp2_dboard_interface(this) ); - _dboard_manager = dboard::manager::sptr( - new dboard::manager(rx_dboard_id, tx_dboard_id, _dboard_interface) + dboard::manager::sptr dboard_manager( + new dboard::manager(rx_dboard_id, tx_dboard_id, dboard_interface) ); + + //load dboards + _rx_dboards[""] = usrp2_dboard::sptr(new usrp2_dboard(dboard_manager, usrp2_dboard::TYPE_RX)); + _tx_dboards[""] = usrp2_dboard::sptr(new usrp2_dboard(dboard_manager, usrp2_dboard::TYPE_TX)); + + //TOD load dsps + } usrp2_impl::~usrp2_impl(void){ /* NOP */ } +/*********************************************************************** + * Control Send/Recv + **********************************************************************/ usrp2_ctrl_data_t usrp2_impl::ctrl_send_and_recv(const usrp2_ctrl_data_t &out_data){ + boost::mutex::scoped_lock lock(_ctrl_mutex); + //fill in the seq number and send usrp2_ctrl_data_t out_copy = out_data; out_copy.seq = htonl(++_ctrl_seq_num); @@ -86,3 +155,48 @@ usrp2_ctrl_data_t usrp2_impl::ctrl_send_and_recv(const usrp2_ctrl_data_t &out_da } throw std::runtime_error("usrp2 no control response"); } + +/*********************************************************************** + * Get Properties + **********************************************************************/ +void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ + wax::obj key; std::string name; + boost::tie(key, name) = extract_named_prop(key_); + + //handle the get request conditioned on the key + switch(wax::cast<mboard_prop_t>(key)){ + case MBOARD_PROP_NAME: + val = std::string("usrp2 mboard"); + return; + + case MBOARD_PROP_OTHERS: + val = prop_names_t(); //empty other props + return; + + case MBOARD_PROP_RX_DBOARD: + case MBOARD_PROP_RX_DBOARD_NAMES: + case MBOARD_PROP_TX_DBOARD: + case MBOARD_PROP_TX_DBOARD_NAMES: + case MBOARD_PROP_MTU: + case MBOARD_PROP_CLOCK_RATE: + case MBOARD_PROP_RX_DSP: + case MBOARD_PROP_RX_DSP_NAMES: + case MBOARD_PROP_TX_DSP: + 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 in usrp2 mboard"); + } +} + +/*********************************************************************** + * Set Properties + **********************************************************************/ +void usrp2_impl::set(const wax::obj &, const wax::obj &){ + throw std::runtime_error("Cannot set on usrp2 mboard"); +} diff --git a/lib/usrp/mboard/usrp2_impl.hpp b/lib/usrp/mboard/usrp2_impl.hpp index 0c2c2292e..23f81d711 100644 --- a/lib/usrp/mboard/usrp2_impl.hpp +++ b/lib/usrp/mboard/usrp2_impl.hpp @@ -17,13 +17,38 @@ #include <uhd/usrp/dboard/manager.hpp> #include <boost/utility.hpp> +#include <boost/thread.hpp> #include <boost/shared_ptr.hpp> #include <uhd/transport/udp.hpp> +#include <uhd/dict.hpp> #include "usrp2_fw_common.h" #ifndef INCLUDED_USRP2_IMPL_HPP #define INCLUDED_USRP2_IMPL_HPP +/*********************************************************************** + * USRP2 DBoard Wrapper + **********************************************************************/ +class usrp2_dboard : boost::noncopyable, public wax::obj{ +public: + typedef boost::shared_ptr<usrp2_dboard> sptr; + enum type_t {TYPE_RX, TYPE_TX}; + + usrp2_dboard(uhd::usrp::dboard::manager::sptr manager, type_t type); + + ~usrp2_dboard(void); + + void get(const wax::obj &, wax::obj &); + void set(const wax::obj &, const wax::obj &); + +private: + uhd::usrp::dboard::manager::sptr _mgr; + type_t _type; +}; + +/*********************************************************************** + * USRP2 Implementation + **********************************************************************/ class usrp2_impl : boost::noncopyable{ public: typedef boost::shared_ptr<usrp2_impl> sptr; @@ -37,14 +62,18 @@ public: usrp2_ctrl_data_t ctrl_send_and_recv(const usrp2_ctrl_data_t &); + void get(const wax::obj &, wax::obj &); + void set(const wax::obj &, const wax::obj &); + private: uhd::transport::udp::sptr _ctrl_transport; uhd::transport::udp::sptr _data_transport; uint32_t _ctrl_seq_num; + boost::mutex _ctrl_mutex; - uhd::usrp::dboard::manager::sptr _dboard_manager; - uhd::usrp::dboard::interface::sptr _dboard_interface; + uhd::dict<std::string, usrp2_dboard::sptr> _rx_dboards; + uhd::dict<std::string, usrp2_dboard::sptr> _tx_dboards; }; #endif /* INCLUDED_USRP2_IMPL_HPP */ |