From da9d47011e02f2b18fccda00dbea0b9d9c0dc704 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Thu, 8 Jul 2010 13:01:49 -0700 Subject: usrp2: added notes on multiple device network setup, improved warnings for buff size stuff --- host/lib/transport/udp_zero_copy_asio.cpp | 12 ++++++------ host/lib/usrp/usrp2/usrp2_impl.cpp | 15 +++++++++++++-- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'host/lib') diff --git a/host/lib/transport/udp_zero_copy_asio.cpp b/host/lib/transport/udp_zero_copy_asio.cpp index 86ea275c1..e3f3ef5bf 100644 --- a/host/lib/transport/udp_zero_copy_asio.cpp +++ b/host/lib/transport/udp_zero_copy_asio.cpp @@ -155,17 +155,17 @@ template static void resize_buff_helper( else std::cout << boost::format( "Current %s sock buff size: %d bytes" ) % name % actual_size << std::endl; + if (actual_size < target_size) std::cerr << boost::format( + "Warning:\n" + " The %s buffer is smaller than the requested size.\n" + " The minimum recommended buffer size is %d bytes.\n" + " See the USRP2 application notes on buffer resizing.\n" + ) % name % MIN_SOCK_BUFF_SIZE << std::endl; } //otherwise, ensure that the buffer is at least the minimum size else if (udp_trans->get_buff_size() < MIN_SOCK_BUFF_SIZE){ resize_buff_helper(udp_trans, MIN_SOCK_BUFF_SIZE, name); - if (udp_trans->get_buff_size() < MIN_SOCK_BUFF_SIZE){ - std::cerr << boost::format( - "Warning: the %s buffer size is smaller than the recommended size of %d bytes.\n" - " See the USRP2 application notes on buffer resizing." - ) % name % MIN_SOCK_BUFF_SIZE << std::endl; - } } } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 9d1ac991f..02f53bc69 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -127,14 +127,25 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ /*********************************************************************** * Make **********************************************************************/ +template +out_type lexical_cast(const in_type &in){ + try{ + return boost::lexical_cast(in); + }catch(...){ + throw std::runtime_error(str(boost::format( + "failed to cast \"%s\" to type \"%s\"" + ) % boost::lexical_cast(in) % typeid(out_type).name())); + } +} + 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")){ - recv_buff_size = size_t(boost::lexical_cast(device_addr["recv_buff_size"])); + recv_buff_size = size_t(lexical_cast(device_addr["recv_buff_size"])); } if (device_addr.has_key("send_buff_size")){ - send_buff_size = size_t(boost::lexical_cast(device_addr["send_buff_size"])); + send_buff_size = size_t(lexical_cast(device_addr["send_buff_size"])); } //create a ctrl and data transport for each address -- cgit v1.2.3