diff options
author | Josh Blum <josh@joshknows.com> | 2010-07-09 17:56:19 +0000 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-07-09 17:56:19 +0000 |
commit | 8dd01e451e9102db06daed171c18d9fbb848df97 (patch) | |
tree | 2965e6ca706cd140b637d7a44617f55c0e3b5649 /host/lib/usrp/usrp2/usrp2_impl.cpp | |
parent | ad511bd81d726918a11ab1218a4bc48f8eaf6efe (diff) | |
parent | ecd7308793ad639880faf2a44f3b8b603d87c7fd (diff) | |
download | uhd-8dd01e451e9102db06daed171c18d9fbb848df97.tar.gz uhd-8dd01e451e9102db06daed171c18d9fbb848df97.tar.bz2 uhd-8dd01e451e9102db06daed171c18d9fbb848df97.zip |
Merge branch 'error_handling' of ettus.sourcerepo.com:ettus/uhdpriv into usrp_e
Diffstat (limited to 'host/lib/usrp/usrp2/usrp2_impl.cpp')
-rw-r--r-- | host/lib/usrp/usrp2/usrp2_impl.cpp | 19 |
1 files changed, 15 insertions, 4 deletions
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 3402c26b1..02f53bc69 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -99,8 +99,8 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ udp_transport->send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); //loop and recieve until the timeout - boost::uint8_t usrp2_ctrl_data_in_mem[USRP2_UDP_BYTES]; //allocate max bytes for recv - usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem); + boost::uint8_t usrp2_ctrl_data_in_mem[udp_simple::mtu]; //allocate max bytes for recv + const usrp2_ctrl_data_t *ctrl_data_in = reinterpret_cast<const usrp2_ctrl_data_t *>(usrp2_ctrl_data_in_mem); while(true){ size_t len = udp_transport->recv(asio::buffer(usrp2_ctrl_data_in_mem)); //std::cout << len << "\n"; @@ -127,14 +127,25 @@ static uhd::device_addrs_t usrp2_find(const device_addr_t &hint){ /*********************************************************************** * Make **********************************************************************/ +template <typename out_type, typename in_type> +out_type lexical_cast(const in_type &in){ + try{ + return boost::lexical_cast<out_type>(in); + }catch(...){ + throw std::runtime_error(str(boost::format( + "failed to cast \"%s\" to type \"%s\"" + ) % boost::lexical_cast<std::string>(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<double>(device_addr["recv_buff_size"])); + recv_buff_size = size_t(lexical_cast<double>(device_addr["recv_buff_size"])); } if (device_addr.has_key("send_buff_size")){ - send_buff_size = size_t(boost::lexical_cast<double>(device_addr["send_buff_size"])); + send_buff_size = size_t(lexical_cast<double>(device_addr["send_buff_size"])); } //create a ctrl and data transport for each address |