From e2044e13ec4ad94e9739402257134abd92cf1521 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 9 Feb 2010 17:45:35 -0800 Subject: added transport directory and udp transport --- include/uhd/Makefile.am | 2 +- include/uhd/device.hpp | 13 +------ include/uhd/transport/.gitignore | 2 + include/uhd/transport/Makefile.am | 24 ++++++++++++ include/uhd/transport/udp.hpp | 77 +++++++++++++++++++++++++++++++++++++++ include/uhd/usrp/usrp.hpp | 9 +++-- 6 files changed, 111 insertions(+), 16 deletions(-) create mode 100644 include/uhd/transport/.gitignore create mode 100644 include/uhd/transport/Makefile.am create mode 100644 include/uhd/transport/udp.hpp (limited to 'include') diff --git a/include/uhd/Makefile.am b/include/uhd/Makefile.am index 00691d920..772d1e4b9 100644 --- a/include/uhd/Makefile.am +++ b/include/uhd/Makefile.am @@ -17,7 +17,7 @@ include $(top_srcdir)/Makefile.common -SUBDIRS = usrp quadradio +SUBDIRS = quadradio transport usrp this_includedir = $(includedir)/uhd this_include_HEADERS = \ diff --git a/include/uhd/device.hpp b/include/uhd/device.hpp index 63f897f97..84d1c1bfb 100644 --- a/include/uhd/device.hpp +++ b/include/uhd/device.hpp @@ -38,12 +38,6 @@ class device : boost::noncopyable, public wax::obj{ public: typedef boost::shared_ptr sptr; - //argument types for send and recv raw methods - //the send args is a vector of the boost asio buffers - //the recv args is a callback that takes a boost asio buffer - typedef std::vector send_args_t; - typedef boost::function recv_args_t; - //structors device(void); virtual ~device(void); @@ -78,11 +72,8 @@ public: device_addr_t get_device_addr(void); //the io interface - virtual void send_raw(const send_args_t &) = 0; - virtual void recv_raw(const recv_args_t &) = 0; - - //connect dsps and subdevs - void connect(const wax::obj &src, const wax::obj &sink); + virtual void send_raw(const std::vector &) = 0; + virtual const boost::asio::const_buffer recv_raw(void) = 0; }; } //namespace uhd diff --git a/include/uhd/transport/.gitignore b/include/uhd/transport/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/include/uhd/transport/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/include/uhd/transport/Makefile.am b/include/uhd/transport/Makefile.am new file mode 100644 index 000000000..7a62e3051 --- /dev/null +++ b/include/uhd/transport/Makefile.am @@ -0,0 +1,24 @@ +# +# Copyright 2010 Ettus Research LLC +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = + +this_includedir = $(includedir)/uhd/transport +this_include_HEADERS = \ + udp.hpp diff --git a/include/uhd/transport/udp.hpp b/include/uhd/transport/udp.hpp new file mode 100644 index 000000000..67979afac --- /dev/null +++ b/include/uhd/transport/udp.hpp @@ -0,0 +1,77 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . +// + +#include +#include +#include +#include + +#ifndef INCLUDED_UHD_TRANSPORT_UDP_HPP +#define INCLUDED_UHD_TRANSPORT_UDP_HPP + +namespace uhd{ namespace transport{ + +class udp : boost::noncopyable{ +public: + typedef boost::shared_ptr sptr; + + /*! + * Constructor. + * The address will be resolved, it can be a host name or ipv4. + * The port will be resolved, it can be a port type or number. + * \param addr a string representing the destination address + * \param port a string representing the destination port + * \param bcast if true, enable the broadcast option on the socket + */ + udp(const std::string &addr, const std::string &port, bool bcast = false); + + /*! + * Destructor + */ + ~udp(void); + + /*! + * Send a vector of buffer (like send_msg). + * \param buffs a vector of asio buffers + */ + void send(const std::vector &buffs); + + /*! + * Send a single buffer. + * \param buff a pointer into memory + * \param len the length in bytes + */ + void send(const void *buff, size_t len); + + /*! + * Receive a buffer. The memory is managed internally. + * Calling recv will invalidate the buffer of the previous recv. + * \return an asio const buffer with internal memory + */ + const boost::asio::const_buffer recv(void); + +private: + boost::asio::ip::udp::socket *_socket; + boost::asio::ip::udp::endpoint _receiver_endpoint; + boost::asio::ip::udp::endpoint _sender_endpoint; + boost::asio::io_service _io_service; + uint8_t _recv_buff[1500]; //max mtu +}; + +}} //namespace + +#endif /* INCLUDED_UHD_TRANSPORT_UDP_HPP */ diff --git a/include/uhd/usrp/usrp.hpp b/include/uhd/usrp/usrp.hpp index eda8f5fc1..84890b8fe 100644 --- a/include/uhd/usrp/usrp.hpp +++ b/include/uhd/usrp/usrp.hpp @@ -35,16 +35,17 @@ public: usrp(const device_addr_t & device_addr); ~usrp(void); - void send_raw(const send_args_t &); - void recv_raw(const recv_args_t &); + //the io interface + void send_raw(const std::vector &); + const boost::asio::const_buffer recv_raw(void); private: void get(const wax::obj &, wax::obj &); void set(const wax::obj &, const wax::obj &); std::map _mboards; - boost::function _send_raw_cb; - boost::function _recv_raw_cb; + boost::function &)> _send_raw_cb; + boost::function _recv_raw_cb; }; }} //namespace -- cgit v1.2.3