From 1fef438d8ba54d07760a21e8e8b50c05b7ddc051 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 20 Dec 2011 14:37:05 -0800 Subject: usrp2: use the socket to determine the device addr --- host/lib/transport/udp_simple.cpp | 15 ++++++++++----- host/lib/usrp/usrp2/fw_common.h | 3 --- host/lib/usrp/usrp2/usrp2_impl.cpp | 7 +++++-- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'host/lib') diff --git a/host/lib/transport/udp_simple.cpp b/host/lib/transport/udp_simple.cpp index bc1bdaf2f..d6c55eae7 100644 --- a/host/lib/transport/udp_simple.cpp +++ b/host/lib/transport/udp_simple.cpp @@ -36,7 +36,7 @@ public: //resolve the address asio::ip::udp::resolver resolver(_io_service); asio::ip::udp::resolver::query query(asio::ip::udp::v4(), addr, port); - _receiver_endpoint = *resolver.resolve(query); + _send_endpoint = *resolver.resolve(query); //create and open the socket _socket = socket_sptr(new asio::ip::udp::socket(_io_service)); @@ -46,25 +46,30 @@ public: _socket->set_option(asio::socket_base::broadcast(bcast)); //connect the socket - if (connect) _socket->connect(_receiver_endpoint); + if (connect) _socket->connect(_send_endpoint); } size_t send(const asio::const_buffer &buff){ if (_connected) return _socket->send(asio::buffer(buff)); - return _socket->send_to(asio::buffer(buff), _receiver_endpoint); + return _socket->send_to(asio::buffer(buff), _send_endpoint); } size_t recv(const asio::mutable_buffer &buff, double timeout){ if (not wait_for_recv_ready(_socket->native(), timeout)) return 0; - return _socket->receive(asio::buffer(buff)); + return _socket->receive_from(asio::buffer(buff), _recv_endpoint); + } + + std::string get_recv_addr(void){ + return _recv_endpoint.address().to_string(); } private: bool _connected; asio::io_service _io_service; socket_sptr _socket; - asio::ip::udp::endpoint _receiver_endpoint; + asio::ip::udp::endpoint _send_endpoint; + asio::ip::udp::endpoint _recv_endpoint; }; /*********************************************************************** diff --git a/host/lib/usrp/usrp2/fw_common.h b/host/lib/usrp/usrp2/fw_common.h index 62ba2d792..ed485023e 100644 --- a/host/lib/usrp/usrp2/fw_common.h +++ b/host/lib/usrp/usrp2/fw_common.h @@ -88,9 +88,6 @@ typedef enum{ USRP2_CTRL_ID_GET_THIS_REGISTER_FOR_ME_BRO = 'r', USRP2_CTRL_ID_OMG_GOT_REGISTER_SO_BAD_DUDE = 'R', - USRP2_CTRL_ID_HEY_WRITE_THIS_UART_FOR_ME_BRO = 'u', - USRP2_CTRL_ID_MAN_I_TOTALLY_WROTE_THAT_UART_DUDE = 'U', - USRP2_CTRL_ID_HOLLER_AT_ME_BRO = 'l', USRP2_CTRL_ID_HOLLER_BACK_DUDE = 'L', diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 87e5596a3..4d7f221c6 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -113,10 +113,13 @@ static device_addrs_t usrp2_find(const device_addr_t &hint_){ if (len > offsetof(usrp2_ctrl_data_t, data) and ntohl(ctrl_data_in->id) == USRP2_CTRL_ID_WAZZUP_DUDE){ //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.ip_addr)); device_addr_t new_addr; new_addr["type"] = "usrp2"; - new_addr["addr"] = ip_addr.to_string(); + //We used to get the address from the control packet. + //Now now uses the socket itself to yield the address. + //boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in->data.ip_addr)); + //new_addr["addr"] = ip_addr.to_string(); + new_addr["addr"] = udp_transport->get_recv_addr(); //Attempt to read the name from the EEPROM and perform filtering. //This operation can throw due to compatibility mismatch. -- cgit v1.2.3