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 | |
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')
-rw-r--r-- | lib/transport/udp.cpp | 16 | ||||
-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 | ||||
-rw-r--r-- | lib/wax.cpp | 8 |
5 files changed, 37 insertions, 21 deletions
diff --git a/lib/transport/udp.cpp b/lib/transport/udp.cpp index 5b221551b..f42ddcb75 100644 --- a/lib/transport/udp.cpp +++ b/lib/transport/udp.cpp @@ -17,6 +17,7 @@ #include <uhd/transport/udp.hpp> #include <boost/format.hpp> +#include <boost/assign/list_of.hpp> #include <iostream> uhd::transport::udp::udp(const std::string &addr, const std::string &port, bool bcast){ @@ -47,19 +48,20 @@ void uhd::transport::udp::send(const std::vector<boost::asio::const_buffer> &buf _socket->send_to(buffs, _receiver_endpoint); } -void uhd::transport::udp::send(const void *buff, size_t len){ - _socket->send_to(boost::asio::buffer(buff, len), _receiver_endpoint); +void uhd::transport::udp::send(const boost::asio::const_buffer &buff){ + std::vector<boost::asio::const_buffer> buffs = boost::assign::list_of(buff); + send(buffs); } -const boost::asio::const_buffer uhd::transport::udp::recv(void){ +boost::asio::const_buffer uhd::transport::udp::recv(void){ + size_t len = 0; //recv if data is available if (_socket->available()){ - size_t len = _socket->receive_from( + len = _socket->receive_from( boost::asio::buffer(_recv_buff, sizeof(_recv_buff)), _sender_endpoint ); - return boost::asio::buffer(_recv_buff, len); } - //return an empty buffer - return boost::asio::buffer(_recv_buff, 0); + //return the buffer with the received length + return boost::asio::buffer(_recv_buff, len); } 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(); } diff --git a/lib/wax.cpp b/lib/wax.cpp index 24f89288c..c08398c50 100644 --- a/lib/wax.cpp +++ b/lib/wax.cpp @@ -144,11 +144,3 @@ void wax::obj::get(const obj &, obj &){ void wax::obj::set(const obj &, const obj &){ throw std::runtime_error("Cannot call set on wax obj base class"); } - -/*********************************************************************** - * Friends - **********************************************************************/ -std::ostream& operator<<(std::ostream &os, const wax::obj &x){ - os << boost::format("WAX obj (%s)") % x.type().name(); - return os; -} |