summaryrefslogtreecommitdiffstats
path: root/lib/usrp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/usrp')
-rw-r--r--lib/usrp/mboard/usrp2.cpp77
-rw-r--r--lib/usrp/usrp.cpp14
2 files changed, 12 insertions, 79 deletions
diff --git a/lib/usrp/mboard/usrp2.cpp b/lib/usrp/mboard/usrp2.cpp
index ffbfe69fc..d51b37602 100644
--- a/lib/usrp/mboard/usrp2.cpp
+++ b/lib/usrp/mboard/usrp2.cpp
@@ -16,96 +16,29 @@
//
#include <uhd/usrp/mboard/usrp2.hpp>
+#include <uhd/transport/udp.hpp>
#include "usrp2_fw_common.h"
#include <uhd/device.hpp>
-#include <boost/asio.hpp>
#include <boost/thread.hpp>
-#include <boost/format.hpp>
-#include <boost/utility.hpp>
#include <boost/lexical_cast.hpp>
#include <netinet/in.h>
-using namespace uhd;
using namespace uhd::usrp::mboard;
-using boost::asio::ip::udp;
-
-/***********************************************************************
- * Wrapper for the udp transport
- **********************************************************************/
-class udp_transport : boost::noncopyable{
-public:
- udp_transport(const std::string &addr, const std::string &port, bool bcast = false){
- //std::cout << boost::format("Creating udp transport for %s %s") % addr % port << std::endl;
-
- // resolve the address
- udp::resolver resolver(_io_service);
- udp::resolver::query query(udp::v4(), addr, port);
- _receiver_endpoint = *resolver.resolve(query);
-
- // Create and open the socket
- _socket = new udp::socket(_io_service);
- _socket->open(udp::v4());
-
- if (bcast){
- // Allow broadcasting
- boost::asio::socket_base::broadcast option(true);
- _socket->set_option(option);
- }
-
- }
-
- ~udp_transport(void){
- delete _socket;
- }
-
- void send(const device::send_args_t &buffs){
- _socket->send_to(buffs, _receiver_endpoint);
- }
-
- void send(const void *buff, size_t len){
- _socket->send_to(boost::asio::buffer(buff, len), _receiver_endpoint);
- }
-
- void recv(const device::recv_args_t &handler){
- // make sure that bytes are available (crappy timeout 100 ms)
- for (size_t i = 0; i < 10; i++){
- if (_socket->available()) break;
- boost::this_thread::sleep(boost::posix_time::milliseconds(10));
- }
-
- // receive the bytes and call the handler
- udp::endpoint sender_endpoint;
- while (_socket->available()){
- size_t len = _socket->receive_from(
- boost::asio::buffer(_recv_buff, sizeof(_recv_buff)),
- sender_endpoint
- );
- bool done = handler(boost::asio::buffer(_recv_buff, len));
- if (done) return;
- }
- }
-
-private:
- udp::socket *_socket;
- udp::endpoint _receiver_endpoint;
- boost::asio::io_service _io_service;
- uint8_t _recv_buff[1500];
-};
/***********************************************************************
* Discovery over the udp transport
**********************************************************************/
-std::vector<device_addr_t> usrp2::discover(const device_addr_t &hint){
- std::vector<device_addr_t> usrp2_addrs;
+std::vector<uhd::device_addr_t> usrp2::discover(const device_addr_t &hint){
+ std::vector<uhd::device_addr_t> usrp2_addrs;
//create a udp transport to communicate
std::string ctrl_port = boost::lexical_cast<std::string>(USRP2_UDP_CTRL_PORT);
- udp_transport trans(hint.udp_args.addr, ctrl_port, true);
+ 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);
- trans.send(&data, sizeof(data));
+ udp_transport.send(&data, sizeof(data));
//TODO start a thread to listen and sleep for timeout
diff --git a/lib/usrp/usrp.cpp b/lib/usrp/usrp.cpp
index 59dd49dd1..d188f51a7 100644
--- a/lib/usrp/usrp.cpp
+++ b/lib/usrp/usrp.cpp
@@ -28,11 +28,11 @@ using namespace uhd::usrp;
* default callbacks for the send and recv
* these should be replaced with callbacks from the mboard object
**********************************************************************/
-static void send_raw_default(const uhd::device::send_args_t &){
+static void send_raw_default(const std::vector<boost::asio::const_buffer> &){
throw std::runtime_error("No callback registered for send raw");
}
-static void recv_raw_default(const uhd::device::recv_args_t &){
+static const boost::asio::const_buffer recv_raw_default(void){
throw std::runtime_error("No callback registered for recv raw");
}
@@ -42,7 +42,7 @@ static void recv_raw_default(const uhd::device::recv_args_t &){
usrp::usrp(const device_addr_t & device_addr){
//set the default callbacks, the code below should replace them
_send_raw_cb = boost::bind(&send_raw_default, _1);
- _recv_raw_cb = boost::bind(&recv_raw_default, _1);
+ _recv_raw_cb = boost::bind(&recv_raw_default);
//create mboard based on the device addr
if (device_addr.type == DEVICE_ADDR_TYPE_VIRTUAL){
@@ -83,10 +83,10 @@ void usrp::set(const wax::obj &, const wax::obj &){
throw std::runtime_error("Cannot set in usrp device");
}
-void usrp::send_raw(const send_args_t &args){
- return _send_raw_cb(args);
+void usrp::send_raw(const std::vector<boost::asio::const_buffer> &buffs){
+ return _send_raw_cb(buffs);
}
-void usrp::recv_raw(const recv_args_t &args){
- return _recv_raw_cb(args);
+const boost::asio::const_buffer usrp::recv_raw(void){
+ return _recv_raw_cb();
}