diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-11 20:24:01 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-11 20:24:01 -0800 |
commit | 350f5c5decca20a54132867283448fd32226bbc2 (patch) | |
tree | 261ec83435d3625ea307e21813ea814113278b79 /lib/usrp | |
parent | 6c7d9f1f7573fc73522499573560bf1aef64f414 (diff) | |
download | uhd-350f5c5decca20a54132867283448fd32226bbc2.tar.gz uhd-350f5c5decca20a54132867283448fd32226bbc2.tar.bz2 uhd-350f5c5decca20a54132867283448fd32226bbc2.zip |
Getting hello packets from the usrp2 with ip and mac addrs.
Cleaned up the mb build system a bit.
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(); } |