diff options
Diffstat (limited to 'lib/usrp')
-rw-r--r-- | lib/usrp/mboard/usrp2.cpp | 29 | ||||
-rw-r--r-- | lib/usrp/mboard/usrp2_fw_common.h | 1 | ||||
-rw-r--r-- | lib/usrp/usrp.cpp | 4 |
3 files changed, 28 insertions, 6 deletions
diff --git a/lib/usrp/mboard/usrp2.cpp b/lib/usrp/mboard/usrp2.cpp index d51b37602..9282a541a 100644 --- a/lib/usrp/mboard/usrp2.cpp +++ b/lib/usrp/mboard/usrp2.cpp @@ -21,6 +21,7 @@ #include <uhd/device.hpp> #include <boost/thread.hpp> #include <boost/lexical_cast.hpp> +#include <boost/thread.hpp> #include <netinet/in.h> using namespace uhd::usrp::mboard; @@ -36,11 +37,31 @@ std::vector<uhd::device_addr_t> usrp2::discover(const device_addr_t &hint){ uhd::transport::udp udp_transport(hint.udp_args.addr, ctrl_port, true); //send a hello control packet - usrp2_ctrl_data_t data; - data.id = htonl(USRP2_CTRL_ID_HELLO); - udp_transport.send(&data, sizeof(data)); + usrp2_ctrl_data_t ctrl_data_out; + ctrl_data_out.id = htonl(USRP2_CTRL_ID_HELLO); + udp_transport.send(boost::asio::buffer(&ctrl_data_out, sizeof(ctrl_data_out))); - //TODO start a thread to listen and sleep for timeout + //loop and recieve until the time is up + size_t num_timeouts = 0; + while(true){ + boost::asio::const_buffer buff = udp_transport.recv(); + //std::cout << boost::asio::buffer_size(buff) << "\n"; + if (boost::asio::buffer_size(buff) < sizeof(usrp2_ctrl_data_t)){ + //sleep a little so we dont burn cpu + if (num_timeouts++ > 50) break; + boost::this_thread::sleep(boost::posix_time::milliseconds(1)); + }else{ + //handle the received data + const usrp2_ctrl_data_t *ctrl_data_in = boost::asio::buffer_cast<const usrp2_ctrl_data_t *>(buff); + switch(ntohl(ctrl_data_in->id)){ + case USRP2_CTRL_ID_HELLO: + //make a boost asio ipv4 with the raw addr in host byte order + boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.discovery_addrs.ip_addr)); + std::cout << "hello " << ip_addr.to_string() << "\n"; + break; + } + } + } return usrp2_addrs; } diff --git a/lib/usrp/mboard/usrp2_fw_common.h b/lib/usrp/mboard/usrp2_fw_common.h index 28d58cf7c..217d8cf1c 100644 --- a/lib/usrp/mboard/usrp2_fw_common.h +++ b/lib/usrp/mboard/usrp2_fw_common.h @@ -33,6 +33,7 @@ extern "C" { #define USRP2_UDP_DATA_PORT 49153 typedef enum{ + USRP2_CTRL_ID_NONE, USRP2_CTRL_ID_HELLO } usrp2_ctrl_id_t; diff --git a/lib/usrp/usrp.cpp b/lib/usrp/usrp.cpp index d188f51a7..c49a63d49 100644 --- a/lib/usrp/usrp.cpp +++ b/lib/usrp/usrp.cpp @@ -32,7 +32,7 @@ static void send_raw_default(const std::vector<boost::asio::const_buffer> &){ throw std::runtime_error("No callback registered for send raw"); } -static const boost::asio::const_buffer recv_raw_default(void){ +static boost::asio::const_buffer recv_raw_default(void){ throw std::runtime_error("No callback registered for recv raw"); } @@ -87,6 +87,6 @@ void usrp::send_raw(const std::vector<boost::asio::const_buffer> &buffs){ return _send_raw_cb(buffs); } -const boost::asio::const_buffer usrp::recv_raw(void){ +boost::asio::const_buffer usrp::recv_raw(void){ return _recv_raw_cb(); } |