diff options
author | Josh Blum <josh@joshknows.com> | 2010-07-07 02:23:38 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-07-07 02:23:38 +0000 |
commit | f2e9d3ed0941dc5738149dd82d1eac158bdf0a0f (patch) | |
tree | 82a350987e32cd329ab5fe56b6dd9fbfef08230f /host/lib/usrp/usrp2/usrp2_impl.cpp | |
parent | 998fee6ef064f1d53a61dd0eec79276d1e85291e (diff) | |
parent | 5c2cccfe8c4a9c6c912a4d18dc1e7a6f84c79609 (diff) | |
download | uhd-f2e9d3ed0941dc5738149dd82d1eac158bdf0a0f.tar.gz uhd-f2e9d3ed0941dc5738149dd82d1eac158bdf0a0f.tar.bz2 uhd-f2e9d3ed0941dc5738149dd82d1eac158bdf0a0f.zip |
Merge branch 'master' of ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Conflicts:
host/examples/rx_timed_samples.cpp
Diffstat (limited to 'host/lib/usrp/usrp2/usrp2_impl.cpp')
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 123 |
1 files changed, 60 insertions, 63 deletions
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 36c264c3c..3402c26b1 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -21,6 +21,7 @@ #include <uhd/usrp/device_props.hpp> #include <uhd/utils/assert.hpp> #include <uhd/utils/static.hpp> +#include <boost/algorithm/string.hpp> #include <boost/assign/list_of.hpp> #include <boost/format.hpp> #include <boost/foreach.hpp> @@ -34,14 +35,23 @@ using namespace uhd::usrp; using namespace uhd::transport; namespace asio = boost::asio; -UHD_STATIC_BLOCK(register_usrp2_device){ - device::register_device(&usrp2::find, &usrp2::make); +/*********************************************************************** + * Helper Functions + **********************************************************************/ +std::vector<std::string> split_addrs(const std::string &addrs_str){ + std::vector<std::string> addrs; + boost::split(addrs, addrs_str, boost::is_any_of("\t ")); + return addrs; +} + +template <class T> std::string num2str(T num){ + return boost::lexical_cast<std::string>(num); } /*********************************************************************** * Discovery over the udp transport **********************************************************************/ -uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ +static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ device_addrs_t usrp2_addrs; //return an empty list of addresses when type is set to non-usrp2 @@ -58,7 +68,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ new_hint["addr"] = if_addrs.bcast; //call discover with the new hint and append results - device_addrs_t new_usrp2_addrs = usrp2::find(new_hint); + device_addrs_t new_usrp2_addrs = usrp2_find(new_hint); usrp2_addrs.insert(usrp2_addrs.begin(), new_usrp2_addrs.begin(), new_usrp2_addrs.end() ); @@ -66,6 +76,16 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ return usrp2_addrs; } + //if there are multiple addresses, just return good, dont test + std::vector<std::string> addrs = split_addrs(hint["addr"]); + if (addrs.size() > 1){ + device_addr_t new_addr; + new_addr["type"] = "usrp2"; + new_addr["addr"] = hint["addr"]; + usrp2_addrs.push_back(new_addr); + return usrp2_addrs; + } + //create a udp transport to communicate std::string ctrl_port = boost::lexical_cast<std::string>(USRP2_UDP_CTRL_PORT); udp_simple::sptr udp_transport = udp_simple::make_broadcast( @@ -107,16 +127,7 @@ uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ /*********************************************************************** * Make **********************************************************************/ -template <class T> std::string num2str(T num){ - return boost::lexical_cast<std::string>(num); -} - -device::sptr usrp2::make(const device_addr_t &device_addr){ - //create a control transport - udp_simple::sptr ctrl_transport = udp_simple::make_connected( - device_addr["addr"], num2str(USRP2_UDP_CTRL_PORT) - ); - +static device::sptr usrp2_make(const device_addr_t &device_addr){ //extract the receive and send buffer sizes size_t recv_buff_size = 0, send_buff_size= 0 ; if (device_addr.has_key("recv_buff_size")){ @@ -126,62 +137,48 @@ device::sptr usrp2::make(const device_addr_t &device_addr){ send_buff_size = size_t(boost::lexical_cast<double>(device_addr["send_buff_size"])); } - //create a data transport - udp_zero_copy::sptr data_transport = udp_zero_copy::make( - device_addr["addr"], - num2str(USRP2_UDP_DATA_PORT), - recv_buff_size, - send_buff_size - ); + //create a ctrl and data transport for each address + std::vector<udp_simple::sptr> ctrl_transports; + std::vector<udp_zero_copy::sptr> data_transports; + + BOOST_FOREACH(const std::string &addr, split_addrs(device_addr["addr"])){ + ctrl_transports.push_back(udp_simple::make_connected( + addr, num2str(USRP2_UDP_CTRL_PORT) + )); + data_transports.push_back(udp_zero_copy::make( + addr, num2str(USRP2_UDP_DATA_PORT), + recv_buff_size, send_buff_size + )); + } //create the usrp2 implementation guts return device::sptr( - new usrp2_impl(ctrl_transport, data_transport) + new usrp2_impl(ctrl_transports, data_transports) ); } +UHD_STATIC_BLOCK(register_usrp2_device){ + device::register_device(&usrp2_find, &usrp2_make); +} + /*********************************************************************** * Structors **********************************************************************/ usrp2_impl::usrp2_impl( - udp_simple::sptr ctrl_transport, - udp_zero_copy::sptr data_transport -){ - _data_transport = data_transport; - - //make a new interface for usrp2 stuff - _iface = usrp2_iface::make(ctrl_transport); - _clock_ctrl = usrp2_clock_ctrl::make(_iface); - _codec_ctrl = usrp2_codec_ctrl::make(_iface); - _serdes_ctrl = usrp2_serdes_ctrl::make(_iface); - - //load the allowed decim/interp rates - //_USRP2_RATES = range(4, 128+1, 1) + range(130, 256+1, 2) + range(260, 512+1, 4) - _allowed_decim_and_interp_rates.clear(); - for (size_t i = 4; i <= 128; i+=1){ - _allowed_decim_and_interp_rates.push_back(i); + std::vector<udp_simple::sptr> ctrl_transports, + std::vector<udp_zero_copy::sptr> data_transports +): + _data_transports(data_transports) +{ + //create a new mboard handler for each control transport + for(size_t i = 0; i < ctrl_transports.size(); i++){ + _mboards.push_back(usrp2_mboard_impl::sptr( + new usrp2_mboard_impl(i, ctrl_transports[i], _io_helper) + )); + //use an empty name when there is only one mboard + std::string name = (ctrl_transports.size() > 1)? boost::lexical_cast<std::string>(i) : ""; + _mboard_dict[name] = _mboards.back(); } - for (size_t i = 130; i <= 256; i+=2){ - _allowed_decim_and_interp_rates.push_back(i); - } - for (size_t i = 260; i <= 512; i+=4){ - _allowed_decim_and_interp_rates.push_back(i); - } - - //init the mboard - mboard_init(); - - //init the ddc - init_ddc_config(); - - //init the duc - init_duc_config(); - - //initialize the clock configuration - init_clock_config(); - - //init the tx and rx dboards (do last) - dboard_init(); //init the send and recv io io_init(); @@ -202,16 +199,16 @@ void usrp2_impl::get(const wax::obj &key_, wax::obj &val){ //handle the get request conditioned on the key switch(key.as<device_prop_t>()){ case DEVICE_PROP_NAME: - val = std::string("usrp2 device"); + if (_mboards.size() > 1) val = std::string("usrp2 mimo device"); + else val = std::string("usrp2 device"); return; case DEVICE_PROP_MBOARD: - UHD_ASSERT_THROW(name == ""); - val = _mboard_proxy->get_link(); + val = _mboard_dict[name]->get_link(); return; case DEVICE_PROP_MBOARD_NAMES: - val = prop_names_t(1, ""); + val = prop_names_t(_mboard_dict.keys()); return; default: UHD_THROW_PROP_GET_ERROR(); |