diff options
| -rw-r--r-- | Makefile.common | 3 | ||||
| -rw-r--r-- | config/ax_boost_asio.m4 | 106 | ||||
| -rw-r--r-- | configure.ac | 2 | ||||
| -rw-r--r-- | include/usrp_uhd/Makefile.am | 1 | ||||
| -rw-r--r-- | include/usrp_uhd/device.hpp | 37 | ||||
| -rw-r--r-- | include/usrp_uhd/device_addr.hpp | 9 | ||||
| -rw-r--r-- | include/usrp_uhd/props.hpp | 154 | ||||
| -rw-r--r-- | include/usrp_uhd/usrp/Makefile.am | 4 | ||||
| -rw-r--r-- | include/usrp_uhd/usrp/mboard/Makefile.am | 5 | ||||
| -rw-r--r-- | include/usrp_uhd/usrp/mboard/base.hpp | 32 | ||||
| -rw-r--r-- | include/usrp_uhd/usrp/mboard/test.hpp | 29 | ||||
| -rw-r--r-- | include/usrp_uhd/usrp/usrp.hpp | 37 | ||||
| -rw-r--r-- | lib/Makefile.am | 2 | ||||
| -rw-r--r-- | lib/device.cpp | 17 | ||||
| -rw-r--r-- | lib/device_addr.cpp | 7 | ||||
| -rw-r--r-- | lib/usrp/Makefile.am | 12 | ||||
| -rw-r--r-- | lib/usrp/mboard/Makefile.am | 10 | ||||
| -rw-r--r-- | lib/usrp/mboard/base.cpp | 16 | ||||
| -rw-r--r-- | lib/usrp/mboard/test.cpp | 24 | ||||
| -rw-r--r-- | lib/usrp/usrp.cpp | 58 | ||||
| -rw-r--r-- | test/Makefile.am | 3 | ||||
| -rw-r--r-- | test/device_test.cpp | 31 | 
22 files changed, 572 insertions, 27 deletions
| diff --git a/Makefile.common b/Makefile.common index 8972e4f42..7bbee585f 100644 --- a/Makefile.common +++ b/Makefile.common @@ -4,7 +4,9 @@  USRP_UHD_LA = $(abs_top_builddir)/lib/libusrp_uhd.la +USRP_UHD_USRP_LA = $(abs_top_builddir)/lib/usrp/lib.la  USRP_UHD_USRP_DBOARD_LA = $(abs_top_builddir)/lib/usrp/dboard/lib.la +USRP_UHD_USRP_MBOARD_LA = $(abs_top_builddir)/lib/usrp/mboard/lib.la  GENERAL_CPPFLAGS = \  	-I$(top_srcdir)/include \ @@ -12,4 +14,5 @@ GENERAL_CPPFLAGS = \  GENERAL_LDDFLAGS = \  	$(BOOST_LDFLAGS) \ +	$(BOOST_ASIO_LIB) \  	$(BOOST_THREAD_LIB) diff --git a/config/ax_boost_asio.m4 b/config/ax_boost_asio.m4 new file mode 100644 index 000000000..4f2175bba --- /dev/null +++ b/config/ax_boost_asio.m4 @@ -0,0 +1,106 @@ +# =========================================================================== +#          http://www.nongnu.org/autoconf-archive/ax_boost_asio.html +# =========================================================================== +# +# SYNOPSIS +# +#   AX_BOOST_ASIO +# +# DESCRIPTION +# +#   Test for Asio library from the Boost C++ libraries. The macro requires a +#   preceding call to AX_BOOST_BASE. Further documentation is available at +#   <http://randspringer.de/boost/index.html>. +# +#   This macro calls: +# +#     AC_SUBST(BOOST_ASIO_LIB) +# +#   And sets: +# +#     HAVE_BOOST_ASIO +# +# LICENSE +# +#   Copyright (c) 2008 Thomas Porschberg <thomas@randspringer.de> +#   Copyright (c) 2008 Pete Greenwell <pete@mu.org> +# +#   Copying and distribution of this file, with or without modification, are +#   permitted in any medium without royalty provided the copyright notice +#   and this notice are preserved. This file is offered as-is, without any +#   warranty. + +AC_DEFUN([AX_BOOST_ASIO], +[ +	AC_ARG_WITH([boost-asio], +	AS_HELP_STRING([--with-boost-asio@<:@=special-lib@:>@], +                   [use the ASIO library from boost - it is possible to specify a certain library for the linker +                        e.g. --with-boost-asio=boost_system-gcc41-mt-1_34 ]), +        [ +        if test "$withval" = "no"; then +			want_boost="no" +        elif test "$withval" = "yes"; then +            want_boost="yes" +            ax_boost_user_asio_lib="" +        else +		    want_boost="yes" +        	ax_boost_user_asio_lib="$withval" +		fi +        ], +        [want_boost="yes"] +	) + +	if test "x$want_boost" = "xyes"; then +        AC_REQUIRE([AC_PROG_CC]) +		CPPFLAGS_SAVED="$CPPFLAGS" +		CPPFLAGS="$CPPFLAGS $BOOST_CPPFLAGS" +		export CPPFLAGS + +		LDFLAGS_SAVED="$LDFLAGS" +		LDFLAGS="$LDFLAGS $BOOST_LDFLAGS" +		export LDFLAGS + +        AC_CACHE_CHECK(whether the Boost::ASIO library is available, +					   ax_cv_boost_asio, +        [AC_LANG_PUSH([C++]) +		 AC_COMPILE_IFELSE(AC_LANG_PROGRAM([[ @%:@include <boost/asio.hpp> +											]], +                                  [[ + +                                    boost::asio::io_service io; +                                    boost::system::error_code timer_result; +                                    boost::asio::deadline_timer t(io); +                                    t.cancel(); +                                    io.run_one(); +									return 0; +                                   ]]), +                             ax_cv_boost_asio=yes, ax_cv_boost_asio=no) +         AC_LANG_POP([C++]) +		]) +		if test "x$ax_cv_boost_asio" = "xyes"; then +			AC_DEFINE(HAVE_BOOST_ASIO,,[define if the Boost::ASIO library is available]) +			BN=boost_system +            if test "x$ax_boost_user_asio_lib" = "x"; then +				for ax_lib in $BN $BN-$CC $BN-$CC-mt $BN-$CC-mt-s $BN-$CC-s \ +                              lib$BN lib$BN-$CC lib$BN-$CC-mt lib$BN-$CC-mt-s lib$BN-$CC-s \ +                              $BN-mgw $BN-mgw $BN-mgw-mt $BN-mgw-mt-s $BN-mgw-s ; do +				    AC_CHECK_LIB($ax_lib, main, [BOOST_ASIO_LIB="-l$ax_lib" AC_SUBST(BOOST_ASIO_LIB) link_thread="yes" break], +                                 [link_thread="no"]) +  				done +            else +               for ax_lib in $ax_boost_user_asio_lib $BN-$ax_boost_user_asio_lib; do +				      AC_CHECK_LIB($ax_lib, main, +                                   [BOOST_ASIO_LIB="-l$ax_lib" AC_SUBST(BOOST_ASIO_LIB) link_asio="yes" break], +                                   [link_asio="no"]) +                  done + +            fi +			if test "x$link_asio" = "xno"; then +				AC_MSG_ERROR(Could not link against $ax_lib !) +			fi +		fi + +		CPPFLAGS="$CPPFLAGS_SAVED" +    	LDFLAGS="$LDFLAGS_SAVED" +	fi +]) diff --git a/configure.ac b/configure.ac index 0036488c8..c31aa363f 100644 --- a/configure.ac +++ b/configure.ac @@ -16,6 +16,7 @@ AC_PROG_CXX  LT_INIT  AX_BOOST_BASE([1.36], [], AC_MSG_ERROR("cannot find boost")) +AX_BOOST_ASIO  AX_BOOST_THREAD  AM_PATH_CPPUNIT([1.9.6], [HAVE_CPPUNIT=true], [HAVE_CPPUNIT=false]) @@ -28,7 +29,6 @@ AC_DEFUN([UHD_CHECK_HEADER],[      AC_CHECK_HEADER([$1], [], AC_MSG_ERROR("cannot find header $1"))  ]) -UHD_CHECK_HEADER([sys/uio.h])  UHD_CHECK_HEADER([arpa/inet.h])  UHD_CHECK_HEADER([netinet/ether.h]) diff --git a/include/usrp_uhd/Makefile.am b/include/usrp_uhd/Makefile.am index 02a129484..40c7d9f99 100644 --- a/include/usrp_uhd/Makefile.am +++ b/include/usrp_uhd/Makefile.am @@ -10,4 +10,5 @@ this_includedir = $(includedir)/usrp_uhd  this_include_HEADERS = \  	device.hpp \  	device_addr.hpp \ +	props.hpp \  	wax.hpp diff --git a/include/usrp_uhd/device.hpp b/include/usrp_uhd/device.hpp index 9d70b9ac3..ad2d3b368 100644 --- a/include/usrp_uhd/device.hpp +++ b/include/usrp_uhd/device.hpp @@ -6,11 +6,13 @@  #define INCLUDED_USRP_UHD_DEVICE_HPP  #include <usrp_uhd/device_addr.hpp> +#include <usrp_uhd/props.hpp>  #include <usrp_uhd/wax.hpp> +#include <boost/utility.hpp>  #include <boost/shared_ptr.hpp>  #include <boost/function.hpp>  #include <vector> -#include <sys/uio.h> +#include <boost/asio/buffer.hpp>  namespace usrp_uhd{ @@ -18,11 +20,14 @@ namespace usrp_uhd{   * The usrp device interface represents the usrp hardware.   * The api allows for discovery, configuration, and streaming.   */ -class device{ +class device : boost::noncopyable, public wax::obj{  public:      typedef boost::shared_ptr<device> sptr; -    typedef boost::function<bool(void *data, size_t len)> recv_hdlr_t; + +    //argument types for send and recv raw methods +    typedef std::vector<boost::asio::const_buffer> send_args_t; +    typedef boost::function<bool(const boost::asio::const_buffer &)> recv_args_t;      /*!       * \brief Discover usrp devices attached to the host. @@ -33,7 +38,7 @@ public:       * \param hint a partially (or fully) filled in device address       * \return a vector of device addresses for all usrps on the system       */ -    static std::vector<device_addr_t> discover(const device_addr_t& hint); +    static std::vector<device_addr_t> discover(const device_addr_t & hint);      /*!       * \brief Create a new usrp device from the device address hint. @@ -46,27 +51,31 @@ public:       * \param which which address to use when multiple are discovered       * \return a shared pointer to a new device instance       */ -    static sptr make(const device_addr_t& hint, size_t which = 0); +    static sptr make(const device_addr_t & hint, size_t which = 0); + +    /*! +     * Constructor: Called in derived classes. +     */ +    device(void);      /*!       * Deconstructor: called automatically by the shared pointer.       */ -    ~device(void); +    virtual ~device(void); + +    /*! +     * Get the device address for this board. +     */ +    device_addr_t get_device_addr(void);      //the io interface -    void send_raw(const std::vector<iovec> &iovs); -    void recv_raw(const recv_hdlr_t &recv_hdlr); +    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::type &src, const wax::type &sink); -    //the properties interface -    wax::proxy props(void); -  private: -    device(const device_addr_t& hint); - -    wax::type d_mboard;  };  } //namespace usrp_uhd diff --git a/include/usrp_uhd/device_addr.hpp b/include/usrp_uhd/device_addr.hpp index c082d9f84..38c6c32dd 100644 --- a/include/usrp_uhd/device_addr.hpp +++ b/include/usrp_uhd/device_addr.hpp @@ -60,15 +60,20 @@ namespace usrp_uhd{          } usb_args;          struct{              std::string ifc; -            mac_addr_t mac_addr; +            std::string mac_addr;          } eth_args;          struct{ -            ip_addr_t ip_addr; +            std::string addr;          } udp_args;          struct{              //TODO unknown for now          } gpmc_args; +        //the discovery args are filled in by the discovery routine +        struct{ +            uint16_t mboard_id; +        } discovery_args; +          /*!           * \brief Convert a usrp device_addr_t into a string representation           */ diff --git a/include/usrp_uhd/props.hpp b/include/usrp_uhd/props.hpp new file mode 100644 index 000000000..c66f40674 --- /dev/null +++ b/include/usrp_uhd/props.hpp @@ -0,0 +1,154 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <boost/tuple/tuple.hpp> +#include <usrp_uhd/wax.hpp> +#include <complex> +#include <vector> + +#ifndef INCLUDED_USRP_UHD_PROPS_HPP +#define INCLUDED_USRP_UHD_PROPS_HPP + +namespace usrp_uhd{ + +    /*! +     * A time_spec_t holds a seconds and ticks time value. +     * The temporal width of a tick depends on the device's clock rate. +     * The time_spec_t can be used when setting the time on devices +     * and for controlling the start of streaming for applicable dsps. +     */ +    struct time_spec_t{ +        uint32_t secs; +        uint32_t ticks; + +        /*! +         * Create a time_spec_t that holds a wildcard time. +         * This will have implementation-specific meaning. +         */ +        time_spec_t(void){ +            secs = ~0; +            ticks = ~0; +        } + +        /*! +         * Create a time_spec_t from seconds and ticks. +         * \param new_secs the new seconds +         * \param new_ticks the new ticks (default = 0) +         */ +        time_spec_t(uint32_t new_secs, uint32_t new_ticks = 0){ +            secs = new_secs; +            ticks = new_ticks; +        } +    }; + +    //common typedefs for board properties +    typedef float gain_t; +    typedef double freq_t; + +    //scalar types +    typedef int int_scalar_t; +    typedef float real_scalar_t; +    typedef std::complex<real_scalar_t> complex_scalar_t; + +    //vector types +    typedef std::vector<int_scalar_t> int_vec_t; +    typedef std::vector<real_scalar_t> real_vec_t; +    typedef std::vector<complex_scalar_t> complex_vec_t; + +    //typedef for addressing indexable components +    typedef boost::tuple<wax::type, size_t> indexed_prop_t; + +    /*! +    * Possible device properties. +    */ +    enum device_prop_t{ +        DEVICE_PROP_NAME,              //ro, std::string +        DEVICE_PROP_MBOARD,            //ro, wax::obj +        DEVICE_PROP_NUM_MBOARDS        //ro, size_t +    }; + +    /*! +    * Possible device mboard properties +    */ +    enum mboard_prop_t{ +        MBOARD_PROP_NAME,              //ro, std::string +        MBOARD_PROP_MTU,               //ro, size_t +        MBOARD_PROP_CLOCK_RATE,        //ro, freq_t +        MBOARD_PROP_RX_DSP,            //ro, wax::obj +        MBOARD_PROP_NUM_RX_DSPS,       //ro, size_t +        MBOARD_PROP_TX_DSP,            //ro, wax::obj +        MBOARD_PROP_NUM_TX_DSPS,       //ro, size_t +        MBOARD_PROP_RX_DBOARD,         //ro, wax::obj +        MBOARD_PROP_NUM_RX_DBOARDS,    //ro, size_t +        MBOARD_PROP_TX_DBOARD,         //ro, wax::obj +        MBOARD_PROP_NUM_TX_DBOARDS,    //ro, size_t +        MBOARD_PROP_PPS_SOURCE,        //rw, std::string (sma, mimo) +        MBOARD_PROP_PPS_POLARITY,      //rw, int, +/- 1 +        MBOARD_PROP_REF_SOURCE,        //rw, std::string (int, sma, mimo) +        MBOARD_PROP_TIME_NOW,          //wo, time_spec_t +        MBOARD_PROP_TIME_NEXT_PPS      //wo, time_spec_t +    }; + +    /*! +    * Possible device dsp properties +    */ +    enum dsp_prop_t{ +        DSP_PROP_NAME,                 //ro, std::string +        DSP_PROP_FREQ,                 //rw, freq_t +        DSP_PROP_TAPS,                 //rw, *_vec_t +        DSP_PROP_RATE,                 //rw, *_scalar_t, decim/interp +        DSP_PROP_SCALAR,               //rw, *_scalar_t +        DSP_PROP_ENABLED               //rw, bool or time_spec_t +    }; + +    /*! +    * Possible device dboard properties +    */ +    enum dboard_prop_t{ +        DBOARD_PROP_NAME,              //ro, std::string +        DBOARD_PROP_SUBDEV,            //ro, wax::obj +        DBOARD_PROP_NUM_SUBDEVS,       //ro, size_t +        DBOARD_PROP_CODEC              //ro, wax::obj +    }; + +    /*! +    * Possible device codec properties +    */ +    enum codec_prop_t{ +        CODEC_PROP_NAME,               //ro, std::string +        CODEC_PROP_GAIN,               //rw, gain_t +        CODEC_PROP_GAIN_MAX,           //ro, gain_t +        CODEC_PROP_GAIN_MIN,           //ro, gain_t +        CODEC_PROP_GAIN_STEP,          //ro, gain_t +        CODEC_PROP_NUM_GAINS,          //ro, size_t +        CODEC_PROP_CLOCK_RATE          //ro, freq_t +    }; + +    /*! +    * Possible device subdev properties +    */ +    enum subdev_prop_t{ +        SUBDEV_PROP_NAME,              //ro, std::string +        SUBDEV_PROP_GAIN,              //rw, gain_t +        SUBDEV_PROP_GAIN_MAX,          //ro, gain_t +        SUBDEV_PROP_GAIN_MIN,          //ro, gain_t +        SUBDEV_PROP_GAIN_STEP,         //ro, gain_t +        SUBDEV_PROP_NUM_GAINS,         //ro, size_t +        SUBDEV_PROP_FREQ,              //rw, freq_t +        SUBDEV_PROP_FREQ_MAX,          //ro, freq_t +        SUBDEV_PROP_FREQ_MIN,          //ro, freq_t +        SUBDEV_PROP_ANTENNA,           //rw, std::string +        SUBDEV_PROP_ENABLED,           //rw, bool +        SUBDEV_PROP_QUADRATURE,        //ro, bool +        SUBDEV_PROP_IQ_SWAPPED,        //ro, bool +        SUBDEV_PROP_SPECTRUM_INVERTED, //ro, bool +        SUBDEV_PROP_IS_TX,             //ro, bool +        SUBDEV_PROP_RSSI,              //ro, gain_t +        SUBDEV_PROP_BANDWIDTH,         //rw, freq_t +        SUBDEV_PROP_CLOCK_RATE         //ro, freq_t +    }; + +} //namespace usrp_uhd + +#endif /* INCLUDED_USRP_UHD_PROPS_HPP */ diff --git a/include/usrp_uhd/usrp/Makefile.am b/include/usrp_uhd/usrp/Makefile.am index 913f80a6d..d15eb6ddc 100644 --- a/include/usrp_uhd/usrp/Makefile.am +++ b/include/usrp_uhd/usrp/Makefile.am @@ -5,3 +5,7 @@  include $(top_srcdir)/Makefile.common  SUBDIRS = mboard dboard + +this_includedir = $(includedir)/usrp_uhd/usrp +this_include_HEADERS = \ +	usrp.hpp diff --git a/include/usrp_uhd/usrp/mboard/Makefile.am b/include/usrp_uhd/usrp/mboard/Makefile.am index 66fc4dd71..3197353ce 100644 --- a/include/usrp_uhd/usrp/mboard/Makefile.am +++ b/include/usrp_uhd/usrp/mboard/Makefile.am @@ -5,3 +5,8 @@  include $(top_srcdir)/Makefile.common  SUBDIRS = + +this_includedir = $(includedir)/usrp_uhd/usrp/mboard +this_include_HEADERS = \ +	base.hpp \ +	test.hpp diff --git a/include/usrp_uhd/usrp/mboard/base.hpp b/include/usrp_uhd/usrp/mboard/base.hpp new file mode 100644 index 000000000..ef455151b --- /dev/null +++ b/include/usrp_uhd/usrp/mboard/base.hpp @@ -0,0 +1,32 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#ifndef INCLUDED_USRP_UHD_USRP_MBOARD_BASE_HPP +#define INCLUDED_USRP_UHD_USRP_MBOARD_BASE_HPP + +#include <usrp_uhd/wax.hpp> +#include <boost/utility.hpp> +#include <boost/shared_ptr.hpp> + +namespace usrp_uhd{ namespace usrp{ namespace mboard{ + +/*! + * A base class for usrp mboard objects. + */ +class base : boost::noncopyable, public wax::obj{ +public: +    typedef boost::shared_ptr<base> sptr; +    base(void); +    ~base(void); + +    //TODO other api calls + +private: +    virtual void get(const wax::type &, wax::type &) = 0; +    virtual void set(const wax::type &, const wax::type &) = 0; +}; + +}}} //namespace + +#endif /* INCLUDED_USRP_UHD_USRP_MBOARD_BASE_HPP */ diff --git a/include/usrp_uhd/usrp/mboard/test.hpp b/include/usrp_uhd/usrp/mboard/test.hpp new file mode 100644 index 000000000..f3c2899cf --- /dev/null +++ b/include/usrp_uhd/usrp/mboard/test.hpp @@ -0,0 +1,29 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#ifndef INCLUDED_USRP_UHD_USRP_MBOARD_TEST_HPP +#define INCLUDED_USRP_UHD_USRP_MBOARD_TEST_HPP + +#include <usrp_uhd/usrp/mboard/base.hpp> +#include <usrp_uhd/device_addr.hpp> + +namespace usrp_uhd{ namespace usrp{ namespace mboard{ + +/*! + * A test usrp mboard object. + * Exercises access routines for the test suite. + */ +class test : public base{ +public: +    test(const device_addr_t &); +    ~test(void); + +private: +    void get(const wax::type &, wax::type &); +    void set(const wax::type &, const wax::type &); +}; + +}}} //namespace + +#endif /* INCLUDED_USRP_UHD_USRP_MBOARD_TEST_HPP */ diff --git a/include/usrp_uhd/usrp/usrp.hpp b/include/usrp_uhd/usrp/usrp.hpp new file mode 100644 index 000000000..b280b0d40 --- /dev/null +++ b/include/usrp_uhd/usrp/usrp.hpp @@ -0,0 +1,37 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/device.hpp> +#include <usrp_uhd/usrp/mboard/base.hpp> +#include <vector> + +#ifndef INCLUDED_USRP_UHD_USRP_USRP_HPP +#define INCLUDED_USRP_UHD_USRP_USRP_HPP + +namespace usrp_uhd{ namespace usrp{ + +/*! + * A usrp device provides a device-level interface to usrp mboards. + * In most cases, a usrp device will have only one mboard. + * In the usrp2 mimo case, this device will have two mboards, + * where one talks through the other's control port. + */ +class usrp : public device{ +public: +    usrp(const device_addr_t & device_addr); +    ~usrp(void); + +    void send_raw(const send_args_t &); +    void recv_raw(const recv_args_t &); + +private: +    void get(const wax::type &, wax::type &); +    void set(const wax::type &, const wax::type &); + +    std::vector<mboard::base::sptr> _mboards; +}; + +}} //namespace + +#endif /* INCLUDED_USRP_UHD_USRP_USRP_HPP */ diff --git a/lib/Makefile.am b/lib/Makefile.am index a4b053b0a..69c242c6c 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -18,6 +18,6 @@ libusrp_uhd_la_SOURCES = \  libusrp_uhd_la_LIBADD = \  	$(GENERAL_LDDFLAGS) \ -	$(USRP_UHD_USRP_DBOARD_LA) +	$(USRP_UHD_USRP_LA)  noinst_HEADERS = diff --git a/lib/device.cpp b/lib/device.cpp index fe655ec7a..4f942ebaf 100644 --- a/lib/device.cpp +++ b/lib/device.cpp @@ -2,20 +2,24 @@  // Copyright 2010 Ettus Research LLC  // +#include <usrp_uhd/usrp/usrp.hpp>  #include <usrp_uhd/device.hpp>  #include <boost/format.hpp> +#include <stdexcept>  using namespace usrp_uhd; -std::vector<device_addr_t> device::discover(const device_addr_t& hint){ +std::vector<device_addr_t> device::discover(const device_addr_t & hint = device_addr_t()){      std::vector<device_addr_t> device_addrs;      if (hint.type == DEVICE_ADDR_TYPE_VIRTUAL){ -        //TODO device_addrs.push_back(...); +        //make a copy of the hint for virtual testing +        device_addr_t virtual_device_addr = hint; +        device_addrs.push_back(virtual_device_addr);      }      return device_addrs;  } -device::sptr device::make(const device_addr_t& hint, size_t which){ +device::sptr device::make(const device_addr_t & hint, size_t which){      std::vector<device_addr_t> device_addrs = discover(hint);      //check that we found any devices      if (device_addrs.size() == 0){ @@ -31,10 +35,13 @@ device::sptr device::make(const device_addr_t& hint, size_t which){          ));      }      //create the new device with the discovered address -    return sptr(new device(device_addrs.at(which))); +    if (hint.type == DEVICE_ADDR_TYPE_VIRTUAL){ +        return sptr(new usrp_uhd::usrp::usrp(device_addrs.at(which))); +    } +    throw std::runtime_error("cant make a device");  } -device::device(const device_addr_t&){ +device::device(void){      /* NOP */  } diff --git a/lib/device_addr.cpp b/lib/device_addr.cpp index 34c61ede8..b28082069 100644 --- a/lib/device_addr.cpp +++ b/lib/device_addr.cpp @@ -81,8 +81,9 @@ usrp_uhd::device_addr_t::device_addr_t(device_addr_type_t device_addr_type){      usb_args.vendor_id = 0xffff;      usb_args.product_id = 0xffff;      eth_args.ifc = "eth0"; -    eth_args.mac_addr = mac_addr_t("ff:ff:ff:ff:ff:ff"); -    udp_args.ip_addr = ip_addr_t("255.255.255.255"); +    eth_args.mac_addr = "ff:ff:ff:ff:ff:ff"; +    udp_args.addr = "255.255.255.255"; +    discovery_args.mboard_id = ~0;  }  std::string usrp_uhd::device_addr_t::to_string(void) const{ @@ -110,7 +111,7 @@ std::string usrp_uhd::device_addr_t::to_string(void) const{          break;      case DEVICE_ADDR_TYPE_UDP:          out << "UDP Socket" << std::endl; -        out << "IP Addr: " << udp_args.ip_addr << std::endl; +        out << "Address: " << udp_args.addr << std::endl;          break;      case DEVICE_ADDR_TYPE_GPMC:          out << "GPMC" << std::endl; diff --git a/lib/usrp/Makefile.am b/lib/usrp/Makefile.am index ac06d5b5b..757e7dd5f 100644 --- a/lib/usrp/Makefile.am +++ b/lib/usrp/Makefile.am @@ -5,3 +5,15 @@  include $(top_srcdir)/Makefile.common  SUBDIRS = dboard mboard + +AM_CPPFLAGS = $(GENERAL_CPPFLAGS) + +noinst_LTLIBRARIES = lib.la + +lib_la_SOURCES = \ +	usrp.cpp + +lib_la_LIBADD = \ +	$(GENERAL_LDDFLAGS) \ +	$(USRP_UHD_USRP_DBOARD_LA) \ +	$(USRP_UHD_USRP_MBOARD_LA) diff --git a/lib/usrp/mboard/Makefile.am b/lib/usrp/mboard/Makefile.am index 66fc4dd71..0296163b5 100644 --- a/lib/usrp/mboard/Makefile.am +++ b/lib/usrp/mboard/Makefile.am @@ -5,3 +5,13 @@  include $(top_srcdir)/Makefile.common  SUBDIRS = + +AM_CPPFLAGS = $(GENERAL_CPPFLAGS) + +noinst_LTLIBRARIES = lib.la + +lib_la_SOURCES = \ +	base.cpp \ +	test.cpp + +lib_la_LIBADD = $(GENERAL_LDDFLAGS) diff --git a/lib/usrp/mboard/base.cpp b/lib/usrp/mboard/base.cpp new file mode 100644 index 000000000..4036b74b2 --- /dev/null +++ b/lib/usrp/mboard/base.cpp @@ -0,0 +1,16 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/usrp/mboard/base.hpp> +#include <stdexcept> + +using namespace usrp_uhd::usrp::mboard; + +base::base(void){ +    /* NOP */ +} + +base::~base(void){ +    /* NOP */ +} diff --git a/lib/usrp/mboard/test.cpp b/lib/usrp/mboard/test.cpp new file mode 100644 index 000000000..564f19efc --- /dev/null +++ b/lib/usrp/mboard/test.cpp @@ -0,0 +1,24 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/usrp/mboard/test.hpp> +#include <stdexcept> + +using namespace usrp_uhd::usrp::mboard; + +test::test(const device_addr_t &){ +    // +} + +test::~test(void){ +    // +} + +void test::get(const wax::type &, wax::type &){ +    // +} + +void test::set(const wax::type &, const wax::type &){ +    // +} diff --git a/lib/usrp/usrp.cpp b/lib/usrp/usrp.cpp new file mode 100644 index 000000000..af0e66e9f --- /dev/null +++ b/lib/usrp/usrp.cpp @@ -0,0 +1,58 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/usrp/usrp.hpp> +#include <usrp_uhd/usrp/mboard/test.hpp> +#include <stdexcept> + +using namespace usrp_uhd::usrp; + +usrp::usrp(const device_addr_t & device_addr){ +    if (device_addr.type == DEVICE_ADDR_TYPE_VIRTUAL){ +        _mboards.push_back( +            mboard::base::sptr(new mboard::test(device_addr)) +        ); +    } +} + +usrp::~usrp(void){ +    /* NOP */ +} + +void usrp::get(const wax::type &key_, wax::type &val){ +    //extract the index if key is an indexed prop +    wax::type key = key_; size_t index = 0; +    if (key.type() == typeid(indexed_prop_t)){ +        boost::tie(key, index) = wax::cast<indexed_prop_t>(key); +    } + +    //handle the get request conditioned on the key +    switch(wax::cast<device_prop_t>(key)){ +    case DEVICE_PROP_NAME: +        val = std::string("usrp device"); +        return; + +    case DEVICE_PROP_MBOARD: +        //turn the mboard sptr object into a wax::obj::sptr +        //this allows the properties access through the wax::proxy +        val = wax::obj::cast(_mboards.at(index)); +        return; + +    case DEVICE_PROP_NUM_MBOARDS: +        val = size_t(_mboards.size()); +        return; +    } +} + +void usrp::set(const wax::type &, const wax::type &){ +    throw std::runtime_error("Cannot set in usrp device"); +} + +void usrp::send_raw(const send_args_t &){ +    //TODO make the call on the mboard +} + +void usrp::recv_raw(const recv_args_t &){ +    //TODO make the call on the mboard +} diff --git a/test/Makefile.am b/test/Makefile.am index bd32206bf..0fbb18bf8 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -20,8 +20,9 @@ LDADD = \  noinst_PROGRAMS = cppunit_test  cppunit_test_SOURCES = \ -	cppunit_test.cpp \  	addr_test.cpp \ +	device_test.cpp \ +	cppunit_test.cpp \  	usrp_dboard_test.cpp \  	wax_test.cpp diff --git a/test/device_test.cpp b/test/device_test.cpp new file mode 100644 index 000000000..bbcada3ab --- /dev/null +++ b/test/device_test.cpp @@ -0,0 +1,31 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include <usrp_uhd/device.hpp> +#include <cppunit/extensions/HelperMacros.h> + +/*********************************************************************** + * cpp unit setup + **********************************************************************/ +class device_test : public CppUnit::TestFixture{ +    CPPUNIT_TEST_SUITE(device_test); +    CPPUNIT_TEST(test); +    CPPUNIT_TEST_SUITE_END(); + +public: +    void test(void); +}; + +CPPUNIT_TEST_SUITE_REGISTRATION(device_test); + +using namespace usrp_uhd; + +void device_test::test(void){ +    device_addr_t device_addr(DEVICE_ADDR_TYPE_VIRTUAL); +    device_addr.virtual_args.num_dboards = 2; +    device_addr.virtual_args.num_rx_dsps = 3; +    device_addr.virtual_args.num_tx_dsps = 4; +    device::sptr dev = device::make(device_addr); +    std::cout << wax::cast<std::string>((*dev)[DEVICE_PROP_NAME]) << std::endl; +} | 
