summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosh Blum <josh@joshknows.com>2010-01-16 16:29:31 -0800
committerJosh Blum <josh@joshknows.com>2010-01-16 16:29:31 -0800
commit5b42b774d9ac1e74fb2916bf58085fe19ecb6720 (patch)
treeb19c441ac2f5d2ff6be09142916775b78a646d9b
parent379d486ed21aace7f8b37d61f713bdc6088b39e5 (diff)
downloaduhd-5b42b774d9ac1e74fb2916bf58085fe19ecb6720.tar.gz
uhd-5b42b774d9ac1e74fb2916bf58085fe19ecb6720.tar.bz2
uhd-5b42b774d9ac1e74fb2916bf58085fe19ecb6720.zip
Created device interface for discovery, access, configuration...
-rw-r--r--include/usrp_uhd.hpp36
-rw-r--r--include/usrp_uhd/Makefile.am1
-rw-r--r--include/usrp_uhd/device.hpp74
-rw-r--r--lib/Makefile.am1
-rw-r--r--lib/device.cpp43
-rw-r--r--lib/usrp_uhd.cpp3
6 files changed, 122 insertions, 36 deletions
diff --git a/include/usrp_uhd.hpp b/include/usrp_uhd.hpp
index 1cbd064b7..deaf6e0c6 100644
--- a/include/usrp_uhd.hpp
+++ b/include/usrp_uhd.hpp
@@ -5,39 +5,7 @@
#ifndef INCLUDED_USRP_UHD_HPP
#define INCLUDED_USRP_UHD_HPP
-#include <usrp_uhd/device_addr.hpp>
-#include <usrp_uhd/wax.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/function.hpp>
-#include <vector>
-#include <sys/uio.h>
-
-namespace usrp_uhd{
-
- class usrp_uhd{
-
- public:
- typedef boost::shared_ptr<usrp_uhd> sptr;
- typedef boost::function<bool(void *data, size_t len)> recv_hdlr_t;
- usrp_uhd(device_addr_t device_addr);
- ~usrp_uhd(void);
-
- //the io interface
- void send(const std::vector<iovec> &iovs);
- void send(void* data, size_t len); //wrapper
- void recv(const recv_hdlr_t &recv_hdlr);
- void recv(void* &data, size_t &len); //wrapper
-
- //connect dsps and subdevs
- void connect(const wax::type &src, const wax::type &sink);
-
- //the properties interface
- wax::proxy props(void);
-
- private:
- wax::type d_mboard;
- };
-
-} //namespace usrp_uhd
+//include convenience headers
+#include <usrp_uhd/device.hpp>
#endif /* INCLUDED_USRP_UHD_HPP */
diff --git a/include/usrp_uhd/Makefile.am b/include/usrp_uhd/Makefile.am
index 9d12f2097..02a129484 100644
--- a/include/usrp_uhd/Makefile.am
+++ b/include/usrp_uhd/Makefile.am
@@ -8,5 +8,6 @@ SUBDIRS = usrp quadradio
this_includedir = $(includedir)/usrp_uhd
this_include_HEADERS = \
+ device.hpp \
device_addr.hpp \
wax.hpp
diff --git a/include/usrp_uhd/device.hpp b/include/usrp_uhd/device.hpp
new file mode 100644
index 000000000..9d70b9ac3
--- /dev/null
+++ b/include/usrp_uhd/device.hpp
@@ -0,0 +1,74 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+
+#ifndef INCLUDED_USRP_UHD_DEVICE_HPP
+#define INCLUDED_USRP_UHD_DEVICE_HPP
+
+#include <usrp_uhd/device_addr.hpp>
+#include <usrp_uhd/wax.hpp>
+#include <boost/shared_ptr.hpp>
+#include <boost/function.hpp>
+#include <vector>
+#include <sys/uio.h>
+
+namespace usrp_uhd{
+
+/*!
+ * The usrp device interface represents the usrp hardware.
+ * The api allows for discovery, configuration, and streaming.
+ */
+class device{
+
+public:
+ typedef boost::shared_ptr<device> sptr;
+ typedef boost::function<bool(void *data, size_t len)> recv_hdlr_t;
+
+ /*!
+ * \brief Discover usrp devices attached to the host.
+ *
+ * The hint device address should be used to narrow down the search
+ * to particular transport types and/or transport arguments.
+ *
+ * \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);
+
+ /*!
+ * \brief Create a new usrp device from the device address hint.
+ *
+ * The make routine will call discover and pick one of the results.
+ * By default, the first result will be used to create a new device.
+ * Use the which parameter as an index into the list of results.
+ *
+ * \param hint a partially (or fully) filled in device address
+ * \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);
+
+ /*!
+ * Deconstructor: called automatically by the shared pointer.
+ */
+ ~device(void);
+
+ //the io interface
+ void send_raw(const std::vector<iovec> &iovs);
+ void recv_raw(const recv_hdlr_t &recv_hdlr);
+
+ //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
+
+#endif /* INCLUDED_USRP_UHD_DEVICE_HPP */
diff --git a/lib/Makefile.am b/lib/Makefile.am
index 6146f4025..a4b053b0a 100644
--- a/lib/Makefile.am
+++ b/lib/Makefile.am
@@ -11,6 +11,7 @@ AM_CPPFLAGS = $(GENERAL_CPPFLAGS)
lib_LTLIBRARIES = libusrp_uhd.la
libusrp_uhd_la_SOURCES = \
+ device.cpp \
device_addr.cpp \
usrp_uhd.cpp \
wax.cpp
diff --git a/lib/device.cpp b/lib/device.cpp
new file mode 100644
index 000000000..fe655ec7a
--- /dev/null
+++ b/lib/device.cpp
@@ -0,0 +1,43 @@
+//
+// Copyright 2010 Ettus Research LLC
+//
+
+#include <usrp_uhd/device.hpp>
+#include <boost/format.hpp>
+
+using namespace usrp_uhd;
+
+std::vector<device_addr_t> device::discover(const device_addr_t& hint){
+ std::vector<device_addr_t> device_addrs;
+ if (hint.type == DEVICE_ADDR_TYPE_VIRTUAL){
+ //TODO device_addrs.push_back(...);
+ }
+ return device_addrs;
+}
+
+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){
+ throw std::runtime_error(str(
+ boost::format("No devices found for %s") % hint.to_string()
+ ));
+ }
+ //check that the which index is valid
+ if (device_addrs.size() <= which){
+ throw std::runtime_error(str(
+ boost::format("No device at index %d for %s")
+ % which % hint.to_string()
+ ));
+ }
+ //create the new device with the discovered address
+ return sptr(new device(device_addrs.at(which)));
+}
+
+device::device(const device_addr_t&){
+ /* NOP */
+}
+
+device::~device(void){
+ /* NOP */
+}
diff --git a/lib/usrp_uhd.cpp b/lib/usrp_uhd.cpp
index 7d1e62a13..7591d3bea 100644
--- a/lib/usrp_uhd.cpp
+++ b/lib/usrp_uhd.cpp
@@ -4,5 +4,4 @@
#include <usrp_uhd.hpp>
-usrp_uhd::usrp_uhd::usrp_uhd(device_addr_t){}
-usrp_uhd::usrp_uhd::~usrp_uhd(void){}
+//nothing here, just includes the header so the compiler can check