Revision e4d3f63c host/lib/usrp/usrp2/io_impl.cpp
| b/host/lib/usrp/usrp2/io_impl.cpp | ||
|---|---|---|
| 21 | 21 |
#include "../../transport/super_send_packet_handler.hpp" |
| 22 | 22 |
#include "usrp2_impl.hpp" |
| 23 | 23 |
#include "usrp2_regs.hpp" |
| 24 |
#include "fw_common.h" |
|
| 24 | 25 |
#include <uhd/utils/log.hpp> |
| 25 | 26 |
#include <uhd/utils/msg.hpp> |
| 26 | 27 |
#include <uhd/utils/tasks.hpp> |
| ... | ... | |
| 31 | 32 |
#include <boost/thread/thread.hpp> |
| 32 | 33 |
#include <boost/format.hpp> |
| 33 | 34 |
#include <boost/bind.hpp> |
| 35 |
#include <boost/asio.hpp> |
|
| 34 | 36 |
#include <boost/thread/mutex.hpp> |
| 35 | 37 |
#include <boost/make_shared.hpp> |
| 36 | 38 |
#include <iostream> |
| ... | ... | |
| 361 | 363 |
} |
| 362 | 364 |
|
| 363 | 365 |
/*********************************************************************** |
| 366 |
* Stream destination programmer |
|
| 367 |
**********************************************************************/ |
|
| 368 |
void usrp2_impl::program_stream_dest( |
|
| 369 |
zero_copy_if::sptr &xport, const uhd::stream_args_t &args |
|
| 370 |
){
|
|
| 371 |
//perform an initial flush of transport |
|
| 372 |
while (xport->get_recv_buff(0.0)){}
|
|
| 373 |
|
|
| 374 |
//program the stream command |
|
| 375 |
usrp2_stream_ctrl_t stream_ctrl = usrp2_stream_ctrl_t(); |
|
| 376 |
stream_ctrl.sequence = uhd::htonx(boost::uint32_t(0 /* don't care seq num */)); |
|
| 377 |
stream_ctrl.vrt_hdr = uhd::htonx(boost::uint32_t(USRP2_INVALID_VRT_HEADER)); |
|
| 378 |
|
|
| 379 |
//user has provided an alternative address and port for destination |
|
| 380 |
if (args.args.has_key("addr") and args.args.has_key("port")){
|
|
| 381 |
UHD_MSG(status) << boost::format( |
|
| 382 |
"Programming streaming destination for custom address.\n" |
|
| 383 |
"IPv4 Address: %s, UDP Port: %s\n" |
|
| 384 |
) % args.args["addr"] % args.args["port"] << std::endl; |
|
| 385 |
|
|
| 386 |
asio::io_service io_service; |
|
| 387 |
asio::ip::udp::resolver resolver(io_service); |
|
| 388 |
asio::ip::udp::resolver::query query(asio::ip::udp::v4(), args.args["addr"], args.args["port"]); |
|
| 389 |
asio::ip::udp::endpoint endpoint = *resolver.resolve(query); |
|
| 390 |
stream_ctrl.ip_addr = uhd::htonx(boost::uint32_t(endpoint.address().to_v4().to_ulong())); |
|
| 391 |
stream_ctrl.udp_port = uhd::htonx(boost::uint32_t(endpoint.port())); |
|
| 392 |
|
|
| 393 |
for (size_t i = 0; i < 3; i++){
|
|
| 394 |
UHD_MSG(status) << "ARP attempt " << i << std::endl; |
|
| 395 |
managed_send_buffer::sptr send_buff = xport->get_send_buff(); |
|
| 396 |
std::memcpy(send_buff->cast<void *>(), &stream_ctrl, sizeof(stream_ctrl)); |
|
| 397 |
send_buff->commit(sizeof(stream_ctrl)); |
|
| 398 |
boost::this_thread::sleep(boost::posix_time::milliseconds(300)); |
|
| 399 |
managed_recv_buffer::sptr recv_buff = xport->get_recv_buff(0.0); |
|
| 400 |
if (recv_buff and recv_buff->size() >= sizeof(boost::uint32_t)){
|
|
| 401 |
const boost::uint32_t result = uhd::ntohx(recv_buff->cast<const boost::uint32_t *>()[0]); |
|
| 402 |
if (result == 0){
|
|
| 403 |
UHD_MSG(status) << "Success! " << std::endl; |
|
| 404 |
return; |
|
| 405 |
} |
|
| 406 |
} |
|
| 407 |
} |
|
| 408 |
throw uhd::runtime_error("Device failed to ARP when programming alternative streaming destination.");
|
|
| 409 |
} |
|
| 410 |
|
|
| 411 |
else{
|
|
| 412 |
//send the partial stream control without destination |
|
| 413 |
managed_send_buffer::sptr send_buff = xport->get_send_buff(); |
|
| 414 |
std::memcpy(send_buff->cast<void *>(), &stream_ctrl, sizeof(stream_ctrl)); |
|
| 415 |
send_buff->commit(sizeof(stream_ctrl)/2); |
|
| 416 |
} |
|
| 417 |
} |
|
| 418 |
|
|
| 419 |
/*********************************************************************** |
|
| 364 | 420 |
* Receive streamer |
| 365 | 421 |
**********************************************************************/ |
| 366 | 422 |
rx_streamer::sptr usrp2_impl::get_rx_stream(const uhd::stream_args_t &args_){
|
| ... | ... | |
| 406 | 462 |
const size_t dsp = chan + _mbc[mb].rx_chan_occ - num_chan_so_far; |
| 407 | 463 |
_mbc[mb].rx_dsps[dsp]->set_nsamps_per_packet(spp); //seems to be a good place to set this |
| 408 | 464 |
_mbc[mb].rx_dsps[dsp]->setup(args); |
| 465 |
this->program_stream_dest(_mbc[mb].rx_dsp_xports[dsp], args); |
|
| 409 | 466 |
my_streamer->set_xport_chan_get_buff(chan_i, boost::bind( |
| 410 | 467 |
&zero_copy_if::get_recv_buff, _mbc[mb].rx_dsp_xports[dsp], _1 |
| 411 | 468 |
), true /*flush*/); |
Also available in: Unified diff