summaryrefslogtreecommitdiffstats
path: root/lib/usrp/mboard/usrp2.cpp
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-02-11 20:24:01 -0800
committerJosh Blum <josh@joshknows.com>2010-02-11 20:24:01 -0800
commit350f5c5decca20a54132867283448fd32226bbc2 (patch)
tree261ec83435d3625ea307e21813ea814113278b79 /lib/usrp/mboard/usrp2.cpp
parent6c7d9f1f7573fc73522499573560bf1aef64f414 (diff)
downloaduhd-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/mboard/usrp2.cpp')
-rw-r--r--lib/usrp/mboard/usrp2.cpp29
1 files changed, 25 insertions, 4 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;
}