From cbb8e474bb5592753a340ba31d3afbab7226f7c6 Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 12 Jan 2010 14:43:43 -0800 Subject: Reorganized structure into include, lib, test, firmware, fpga. The fpga and firmware are empty placeholders for now. --- .gitignore | 1 + Makefile.am | 22 ++++- Makefile.common | 22 ++--- configure.ac | 19 ++-- firmware/README | 4 + fpga/README | 4 + include/.gitignore | 2 + include/Makefile.am | 11 +++ include/usrp_uhd.hpp | 43 +++++++++ include/usrp_uhd/.gitignore | 2 + include/usrp_uhd/Makefile.am | 12 +++ include/usrp_uhd/device_addr.hpp | 90 ++++++++++++++++++ include/usrp_uhd/quadradio/.gitignore | 2 + include/usrp_uhd/quadradio/Makefile.am | 7 ++ include/usrp_uhd/usrp/.gitignore | 2 + include/usrp_uhd/usrp/Makefile.am | 7 ++ include/usrp_uhd/usrp/dboard/.gitignore | 2 + include/usrp_uhd/usrp/dboard/Makefile.am | 7 ++ include/usrp_uhd/usrp/mboard/.gitignore | 2 + include/usrp_uhd/usrp/mboard/Makefile.am | 7 ++ include/usrp_uhd/wax.hpp | 129 ++++++++++++++++++++++++++ lib/.gitignore | 2 + lib/Makefile.am | 21 +++++ lib/device_addr.cpp | 116 +++++++++++++++++++++++ lib/quadradio/.gitignore | 2 + lib/quadradio/Makefile.am | 7 ++ lib/usrp/.gitignore | 2 + lib/usrp/Makefile.am | 7 ++ lib/usrp/dboard/.gitignore | 2 + lib/usrp/dboard/Makefile.am | 7 ++ lib/usrp/mboard/.gitignore | 2 + lib/usrp/mboard/Makefile.am | 7 ++ lib/usrp_uhd.cpp | 8 ++ lib/wax.cpp | 71 ++++++++++++++ test/.gitignore | 3 + test/Makefile.am | 20 ++++ test/wax_test.cpp | 81 ++++++++++++++++ usrp_dboard/.gitignore | 2 - usrp_dboard/Makefile.am | 7 -- usrp_dboard/include/.gitignore | 2 - usrp_dboard/include/Makefile.am | 10 -- usrp_dboard/include/usrp_dboard/interface.hpp | 119 ------------------------ usrp_dboard/lib/.gitignore | 2 - usrp_dboard/lib/Makefile.am | 23 ----- usrp_dboard/lib/interface.cpp | 13 --- usrp_uhd.pc.in | 11 +++ usrp_uhd/.gitignore | 3 - usrp_uhd/Makefile.am | 13 --- usrp_uhd/include/.gitignore | 2 - usrp_uhd/include/Makefile.am | 16 ---- usrp_uhd/include/usrp_uhd.hpp | 43 --------- usrp_uhd/include/usrp_uhd/usrp_addr.hpp | 90 ------------------ usrp_uhd/include/usrp_uhd/wax.hpp | 129 -------------------------- usrp_uhd/lib/.gitignore | 2 - usrp_uhd/lib/Makefile.am | 26 ------ usrp_uhd/lib/usrp_addr.cpp | 116 ----------------------- usrp_uhd/lib/usrp_uhd.cpp | 10 -- usrp_uhd/lib/wax.cpp | 71 -------------- usrp_uhd/usrp_uhd.pc.in | 11 --- 59 files changed, 741 insertions(+), 735 deletions(-) create mode 100644 firmware/README create mode 100644 fpga/README create mode 100644 include/.gitignore create mode 100644 include/Makefile.am create mode 100644 include/usrp_uhd.hpp create mode 100644 include/usrp_uhd/.gitignore create mode 100644 include/usrp_uhd/Makefile.am create mode 100644 include/usrp_uhd/device_addr.hpp create mode 100644 include/usrp_uhd/quadradio/.gitignore create mode 100644 include/usrp_uhd/quadradio/Makefile.am create mode 100644 include/usrp_uhd/usrp/.gitignore create mode 100644 include/usrp_uhd/usrp/Makefile.am create mode 100644 include/usrp_uhd/usrp/dboard/.gitignore create mode 100644 include/usrp_uhd/usrp/dboard/Makefile.am create mode 100644 include/usrp_uhd/usrp/mboard/.gitignore create mode 100644 include/usrp_uhd/usrp/mboard/Makefile.am create mode 100644 include/usrp_uhd/wax.hpp create mode 100644 lib/.gitignore create mode 100644 lib/Makefile.am create mode 100644 lib/device_addr.cpp create mode 100644 lib/quadradio/.gitignore create mode 100644 lib/quadradio/Makefile.am create mode 100644 lib/usrp/.gitignore create mode 100644 lib/usrp/Makefile.am create mode 100644 lib/usrp/dboard/.gitignore create mode 100644 lib/usrp/dboard/Makefile.am create mode 100644 lib/usrp/mboard/.gitignore create mode 100644 lib/usrp/mboard/Makefile.am create mode 100644 lib/usrp_uhd.cpp create mode 100644 lib/wax.cpp create mode 100644 test/.gitignore create mode 100644 test/Makefile.am create mode 100644 test/wax_test.cpp delete mode 100644 usrp_dboard/.gitignore delete mode 100644 usrp_dboard/Makefile.am delete mode 100644 usrp_dboard/include/.gitignore delete mode 100644 usrp_dboard/include/Makefile.am delete mode 100644 usrp_dboard/include/usrp_dboard/interface.hpp delete mode 100644 usrp_dboard/lib/.gitignore delete mode 100644 usrp_dboard/lib/Makefile.am delete mode 100644 usrp_dboard/lib/interface.cpp create mode 100644 usrp_uhd.pc.in delete mode 100644 usrp_uhd/.gitignore delete mode 100644 usrp_uhd/Makefile.am delete mode 100644 usrp_uhd/include/.gitignore delete mode 100644 usrp_uhd/include/Makefile.am delete mode 100644 usrp_uhd/include/usrp_uhd.hpp delete mode 100644 usrp_uhd/include/usrp_uhd/usrp_addr.hpp delete mode 100644 usrp_uhd/include/usrp_uhd/wax.hpp delete mode 100644 usrp_uhd/lib/.gitignore delete mode 100644 usrp_uhd/lib/Makefile.am delete mode 100644 usrp_uhd/lib/usrp_addr.cpp delete mode 100644 usrp_uhd/lib/usrp_uhd.cpp delete mode 100644 usrp_uhd/lib/wax.cpp delete mode 100644 usrp_uhd/usrp_uhd.pc.in diff --git a/.gitignore b/.gitignore index 6a9409823..e9db284b3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +/usrp_uhd.pc /Makefile /Makefile.in /aclocal.m4 diff --git a/Makefile.am b/Makefile.am index 3fe105aa3..84f1bf68d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -4,6 +4,22 @@ include $(top_srcdir)/Makefile.common -SUBDIRS = \ - usrp_dboard \ - usrp_uhd +SUBDIRS = include lib test + +######################################################################## +## Handle the pkgconfig file generation +######################################################################## +pkgconfigdir = $(libdir)/pkgconfig +pkgconfig_DATA = usrp_uhd.pc + +EXTRA_DIST = $(srcdir)/usrp_uhd.pc.in +BUILT_SOURCES = usrp_uhd.pc + +usrp_uhd.pc: $(srcdir)/usrp_uhd.pc.in Makefile + $(SED) \ + -e 's|@prefix[@]|$(prefix)|g' \ + -e 's|@exec_prefix[@]|$(exec_prefix)|g' \ + -e 's|@libdir[@]|$(libdir)|g' \ + -e 's|@includedir[@]|$(includedir)|g' \ + -e 's|@VERSION[@]|$(VERSION)|g' \ + $< > $@ diff --git a/Makefile.common b/Makefile.common index b7e672baf..3b1464439 100644 --- a/Makefile.common +++ b/Makefile.common @@ -2,20 +2,12 @@ # Copyright 2010 Ettus Research LLC # -######################################################################## -## Makefile variables for the top level component: the uhd -######################################################################## -USRP_UHD_INCLUDES = \ - -I$(top_srcdir)/usrp_uhd/include +USRP_UHD_LA = $(top_srcdir)/lib/libusrp_uhd.la -USRP_UHD_LA = \ - $(top_srcdir)/usrp_uhd/lib/libusrp_uhd.la - -######################################################################## -## Makefile variables for the usrp dboard component -######################################################################## -USRP_DBOARD_INCLUDES = \ - -I$(top_srcdir)/usrp_dboard/include +GENERAL_CPPFLAGS = \ + -I$(top_srcdir)/include \ + $(BOOST_CPPFLAGS) -USRP_DBOARD_LA = \ - $(top_srcdir)/usrp_dboard/lib/libusrp_dboard.la +GENERAL_LDDFLAGS = \ + $(BOOST_LDFLAGS) \ + $(BOOST_THREAD_LIB) diff --git a/configure.ac b/configure.ac index c9c59fbcf..e36fce8ef 100644 --- a/configure.ac +++ b/configure.ac @@ -28,12 +28,17 @@ AC_PATH_PROG(PYTHON, python) ################################################## AC_CONFIG_FILES([ \ Makefile \ - usrp_uhd/usrp_uhd.pc \ - usrp_uhd/Makefile \ - usrp_uhd/include/Makefile \ - usrp_uhd/lib/Makefile \ - usrp_dboard/Makefile \ - usrp_dboard/include/Makefile \ - usrp_dboard/lib/Makefile \ + include/Makefile \ + include/usrp_uhd/Makefile \ + include/usrp_uhd/usrp/Makefile \ + include/usrp_uhd/usrp/dboard/Makefile \ + include/usrp_uhd/usrp/mboard/Makefile \ + include/usrp_uhd/quadradio/Makefile \ + lib/Makefile \ + lib/usrp/Makefile \ + lib/usrp/dboard/Makefile \ + lib/usrp/mboard/Makefile \ + lib/quadradio/Makefile \ + test/Makefile \ ]) AC_OUTPUT diff --git a/firmware/README b/firmware/README new file mode 100644 index 000000000..a010493c8 --- /dev/null +++ b/firmware/README @@ -0,0 +1,4 @@ +This is a placeholder for the firmware code (microblaze and 8051). + +The layout should have a common library of source and header files. +Each usrp-like will have its own device-specific libs and apps. diff --git a/fpga/README b/fpga/README new file mode 100644 index 000000000..aacafecfd --- /dev/null +++ b/fpga/README @@ -0,0 +1,4 @@ +This is a placeholder for the fpga code (verilog, makefiles, corgens...) + +The layout should have a common library and various top level builds +and testbenches that are organized hierarchically. diff --git a/include/.gitignore b/include/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/include/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/include/Makefile.am b/include/Makefile.am new file mode 100644 index 000000000..0ffe6f3d1 --- /dev/null +++ b/include/Makefile.am @@ -0,0 +1,11 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = usrp_uhd + +this_includedir = $(includedir) +this_include_HEADERS = \ + usrp_uhd.hpp diff --git a/include/usrp_uhd.hpp b/include/usrp_uhd.hpp new file mode 100644 index 000000000..1cbd064b7 --- /dev/null +++ b/include/usrp_uhd.hpp @@ -0,0 +1,43 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#ifndef INCLUDED_USRP_UHD_HPP +#define INCLUDED_USRP_UHD_HPP + +#include +#include +#include +#include +#include +#include + +namespace usrp_uhd{ + + class usrp_uhd{ + + public: + typedef boost::shared_ptr sptr; + typedef boost::function recv_hdlr_t; + usrp_uhd(device_addr_t device_addr); + ~usrp_uhd(void); + + //the io interface + void send(const std::vector &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 + +#endif /* INCLUDED_USRP_UHD_HPP */ diff --git a/include/usrp_uhd/.gitignore b/include/usrp_uhd/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/include/usrp_uhd/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/include/usrp_uhd/Makefile.am b/include/usrp_uhd/Makefile.am new file mode 100644 index 000000000..9d12f2097 --- /dev/null +++ b/include/usrp_uhd/Makefile.am @@ -0,0 +1,12 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = usrp quadradio + +this_includedir = $(includedir)/usrp_uhd +this_include_HEADERS = \ + device_addr.hpp \ + wax.hpp diff --git a/include/usrp_uhd/device_addr.hpp b/include/usrp_uhd/device_addr.hpp new file mode 100644 index 000000000..f0be44c1f --- /dev/null +++ b/include/usrp_uhd/device_addr.hpp @@ -0,0 +1,90 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#ifndef INCLUDED_USRP_UHD_DEVICE_ADDR_HPP +#define INCLUDED_USRP_UHD_DEVICE_ADDR_HPP + +#include +#include +#include +#include + +namespace usrp_uhd{ + + /*! + * Wrapper for an ethernet mac address. + * Provides conversion between string and binary formats. + */ + struct mac_addr_t{ + struct ether_addr mac_addr; + mac_addr_t(const std::string &str = "00:00:00:00:00:00"); + std::string to_string(void) const; + }; + + /*! + * Wrapper for an ipv4 address. + * Provides conversion between string and binary formats. + */ + struct ip_addr_t{ + struct in_addr ip_addr; + ip_addr_t(const std::string &str = "0.0.0.0"); + std::string to_string(void) const; + }; + + /*! + * Possible usrp device interface types. + */ + enum device_addr_type_t{ + DEVICE_ADDR_TYPE_AUTO, + DEVICE_ADDR_TYPE_VIRTUAL, + DEVICE_ADDR_TYPE_USB, + DEVICE_ADDR_TYPE_ETH, + DEVICE_ADDR_TYPE_UDP, + DEVICE_ADDR_TYPE_GPMC + }; + + /*! + * Structure to hold properties that identify a usrp device. + */ + struct device_addr_t{ + device_addr_type_t type; + struct{ + size_t num_rx_dsps; + size_t num_tx_dsps; + size_t num_dboards; + } virtual_args; + struct{ + uint16_t vendor_id; + uint16_t product_id; + } usb_args; + struct{ + std::string ifc; + mac_addr_t mac_addr; + } eth_args; + struct{ + ip_addr_t ip_addr; + } udp_args; + struct{ + //TODO unknown for now + } gpmc_args; + + /*! + * \brief Convert a usrp device_addr_t into a string representation + */ + std::string to_string(void) const; + + /*! + * \brief Default constructor to initialize the device_addr_t struct + */ + device_addr_t(device_addr_type_t device_addr_type = DEVICE_ADDR_TYPE_AUTO); + }; + +} //namespace usrp_uhd + +//ability to use types with stream operators +std::ostream& operator<<(std::ostream &os, const usrp_uhd::device_addr_t &x); +std::ostream& operator<<(std::ostream &os, const usrp_uhd::mac_addr_t &x); +std::ostream& operator<<(std::ostream &os, const usrp_uhd::ip_addr_t &x); + +#endif /* INCLUDED_USRP_UHD_DEVICE_ADDR_HPP */ diff --git a/include/usrp_uhd/quadradio/.gitignore b/include/usrp_uhd/quadradio/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/include/usrp_uhd/quadradio/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/include/usrp_uhd/quadradio/Makefile.am b/include/usrp_uhd/quadradio/Makefile.am new file mode 100644 index 000000000..66fc4dd71 --- /dev/null +++ b/include/usrp_uhd/quadradio/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = diff --git a/include/usrp_uhd/usrp/.gitignore b/include/usrp_uhd/usrp/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/include/usrp_uhd/usrp/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/include/usrp_uhd/usrp/Makefile.am b/include/usrp_uhd/usrp/Makefile.am new file mode 100644 index 000000000..913f80a6d --- /dev/null +++ b/include/usrp_uhd/usrp/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = mboard dboard diff --git a/include/usrp_uhd/usrp/dboard/.gitignore b/include/usrp_uhd/usrp/dboard/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/include/usrp_uhd/usrp/dboard/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/include/usrp_uhd/usrp/dboard/Makefile.am b/include/usrp_uhd/usrp/dboard/Makefile.am new file mode 100644 index 000000000..66fc4dd71 --- /dev/null +++ b/include/usrp_uhd/usrp/dboard/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = diff --git a/include/usrp_uhd/usrp/mboard/.gitignore b/include/usrp_uhd/usrp/mboard/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/include/usrp_uhd/usrp/mboard/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/include/usrp_uhd/usrp/mboard/Makefile.am b/include/usrp_uhd/usrp/mboard/Makefile.am new file mode 100644 index 000000000..66fc4dd71 --- /dev/null +++ b/include/usrp_uhd/usrp/mboard/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = diff --git a/include/usrp_uhd/wax.hpp b/include/usrp_uhd/wax.hpp new file mode 100644 index 000000000..9d32314f7 --- /dev/null +++ b/include/usrp_uhd/wax.hpp @@ -0,0 +1,129 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#ifndef INCLUDED_WAX_HPP +#define INCLUDED_WAX_HPP + +#include +#include +#include +#include +#include +#include + +/*! + * WAX - it's a metaphor! + * + * The WAX framework allows object to have generic/anytype properties. + * These properties can be addressed through generic/anytype identifiers. + * A property of a WAX object may even be another WAX object. + * + * When a property is a WAX object, the returned value must be an obj pointer. + * A WAX object provides two types of pointers: obj::ptr and obj::sptr. + * The choice of pointer vs smart pointer depends on the owner of the memory. + * + * Proprties may be referenced though the [] overloaded operator. + * The [] operator returns a special proxy that allows for assigment. + * Also, the [] operators may be chained as in the folowing examples: + * my_obj[prop1][prop2][prop3] = value + * value = my_obj[prop1][prop2][prop3] + * + * Any value returned from an access operation is of wax::type. + * To use this value, it must be cast with wax::cast(value). + */ + +namespace wax{ + + //general typedefs + typedef boost::any type; + typedef boost::bad_any_cast bad_cast; + + //dummy class declarations + class obj; class proxy; + + /*! + * WAX object base class: + * A wax object subclass should override the set and get methods. + * The magic of operator chaining is handled by the [] operator. + */ + class obj{ + public: + //obj pointer typedefs + typedef boost::shared_ptr sptr; + typedef obj* ptr; + + //cast derived pointer to obj base class pointer + template static sptr cast(boost::shared_ptr r){ + return boost::static_pointer_cast(r); + } + template static ptr cast(T *r){ + return dynamic_cast(r); + } + + //structors + obj(void); + virtual ~obj(void); + + //public interface + proxy operator[](const type &key); + + private: + //private interface + virtual void get(const type &key, type &val) = 0; + virtual void set(const type &key, const type &val) = 0; + }; + + /*! + * WAX proxy class: + * Allows the obj [] operator to return a proxy result. + * This result can be assigned to via the = operator. + * Or this result can be called again with the [] operator. + */ + class proxy{ + public: + //destructors + ~proxy(void); + + //overloaded + type operator()(void); + proxy operator[](const type &key); + proxy operator=(const type &key); + + private: + //typedefs for callables from the object that built this proxy + typedef boost::function setter_t; + typedef boost::function getter_t; + + //private contructor + proxy(getter_t, setter_t); + //access to private contructor + friend proxy obj::operator[](const type &key); + + getter_t d_getter; + setter_t d_setter; + }; + + /*! + * Cast a wax::type into the desired type + * Usage wax::cast(my_value). + * + * \param val the any type to cast + * \return data of the desired type + * \throw wax::bad_cast when the cast fails + */ + template T cast(const type & val){ + //special case to handle the proxy + if (val.type() == typeid(proxy)){ + return cast(boost::any_cast(val)()); + } + //do the type cast + return boost::any_cast(val); + } + +} //namespace wax + +//ability to use types with stream operators +std::ostream& operator<<(std::ostream &os, const wax::type &x); + +#endif /* INCLUDED_WAX_HPP */ diff --git a/lib/.gitignore b/lib/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/lib/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/lib/Makefile.am b/lib/Makefile.am new file mode 100644 index 000000000..efb655640 --- /dev/null +++ b/lib/Makefile.am @@ -0,0 +1,21 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = usrp quadradio + +AM_CPPFLAGS = $(GENERAL_CPPFLAGS) + +lib_LTLIBRARIES = \ + libusrp_uhd.la + +libusrp_uhd_la_SOURCES = \ + device_addr.cpp \ + usrp_uhd.cpp \ + wax.cpp + +libusrp_uhd_la_LIBADD = $(GENERAL_LDDFLAGS) + +noinst_HEADERS = diff --git a/lib/device_addr.cpp b/lib/device_addr.cpp new file mode 100644 index 000000000..ac66c0d25 --- /dev/null +++ b/lib/device_addr.cpp @@ -0,0 +1,116 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include +#include +#include +#include +#include + +//----------------------- u2 mac addr wrapper ------------------------// +usrp_uhd::mac_addr_t::mac_addr_t(const std::string &str){ + //ether_aton_r(str.c_str(), &mac_addr); + bool good = false; + char p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB + + switch (str.size()){ + case 5: + good = sscanf(str.c_str(), "%hhx:%hhx", &p[4], &p[5]) == 2; + break; + case 17: + good = sscanf(str.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", + &p[0], &p[1], &p[2], &p[3], &p[4], &p[5]) == 6; + break; + } + + if (not good) throw std::runtime_error("Invalid mac address: " + str); + memcpy(&mac_addr, p, sizeof(mac_addr)); +} + +std::string usrp_uhd::mac_addr_t::to_string(void) const{ + char addr_buf[128]; + //ether_ntoa_r(&mac_addr, addr_buf); + const uint8_t *p = reinterpret_cast(&mac_addr); + sprintf(addr_buf, "%02x:%02x:%02x:%02x:%02x:%02x", + p[0], p[1], p[2], p[3], p[4], p[5]); + return std::string(addr_buf); +} + +std::ostream& operator<<(std::ostream &os, const usrp_uhd::mac_addr_t &x){ + os << x.to_string(); + return os; +} + +//----------------------- u2 ipv4 wrapper ----------------------------// +usrp_uhd::ip_addr_t::ip_addr_t(const std::string &str){ + int ret = inet_pton(AF_INET, str.c_str(), &ip_addr); + if (ret == 0) throw std::runtime_error("Invalid ip address: " + str); +} + +std::string usrp_uhd::ip_addr_t::to_string(void) const{ + char addr_buf[128]; + inet_ntop(AF_INET, &ip_addr, addr_buf, INET_ADDRSTRLEN); + return std::string(addr_buf); +} + +std::ostream& operator<<(std::ostream &os, const usrp_uhd::ip_addr_t &x){ + os << x.to_string(); + return os; +} + +//----------------------- usrp device_addr_t wrapper -------------------------// +usrp_uhd::device_addr_t::device_addr_t(device_addr_type_t device_addr_type){ + type = device_addr_type; + virtual_args.num_rx_dsps = 0; + virtual_args.num_tx_dsps = 0; + virtual_args.num_dboards = 0; + 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"); +} + +std::string usrp_uhd::device_addr_t::to_string(void) const{ + std::stringstream out; + out << "USRP Type: "; + switch(type){ + case DEVICE_ADDR_TYPE_AUTO: + out << "Automatic" << std::endl; + break; + case DEVICE_ADDR_TYPE_VIRTUAL: + out << "Virtual" << std::endl; + out << "Num RX DSPs: " << virtual_args.num_rx_dsps << std::endl; + out << "Num TX DSPs: " << virtual_args.num_rx_dsps << std::endl; + out << "Num dboards: " << virtual_args.num_dboards << std::endl; + break; + case DEVICE_ADDR_TYPE_USB: + out << "USB Port" << std::endl; + out << "Vendor ID: 0x" << std::hex << usb_args.vendor_id << std::endl; + out << "Product ID: 0x" << std::hex << usb_args.product_id << std::endl; + break; + case DEVICE_ADDR_TYPE_ETH: + out << "Raw Ethernet" << std::endl; + out << "Interface: " << eth_args.ifc << std::endl; + out << "MAC Addr: " << eth_args.mac_addr << std::endl; + break; + case DEVICE_ADDR_TYPE_UDP: + out << "UDP Socket" << std::endl; + out << "IP Addr: " << udp_args.ip_addr << std::endl; + break; + case DEVICE_ADDR_TYPE_GPMC: + out << "GPMC" << std::endl; + break; + default: + out << "Unknown" << std::endl; + } + out << std::endl; + return out.str(); +} + +std::ostream& operator<<(std::ostream &os, const usrp_uhd::device_addr_t &x) +{ + os << x.to_string(); + return os; +} diff --git a/lib/quadradio/.gitignore b/lib/quadradio/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/lib/quadradio/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/lib/quadradio/Makefile.am b/lib/quadradio/Makefile.am new file mode 100644 index 000000000..66fc4dd71 --- /dev/null +++ b/lib/quadradio/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = diff --git a/lib/usrp/.gitignore b/lib/usrp/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/lib/usrp/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/lib/usrp/Makefile.am b/lib/usrp/Makefile.am new file mode 100644 index 000000000..913f80a6d --- /dev/null +++ b/lib/usrp/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = mboard dboard diff --git a/lib/usrp/dboard/.gitignore b/lib/usrp/dboard/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/lib/usrp/dboard/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/lib/usrp/dboard/Makefile.am b/lib/usrp/dboard/Makefile.am new file mode 100644 index 000000000..66fc4dd71 --- /dev/null +++ b/lib/usrp/dboard/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = diff --git a/lib/usrp/mboard/.gitignore b/lib/usrp/mboard/.gitignore new file mode 100644 index 000000000..b336cc7ce --- /dev/null +++ b/lib/usrp/mboard/.gitignore @@ -0,0 +1,2 @@ +/Makefile +/Makefile.in diff --git a/lib/usrp/mboard/Makefile.am b/lib/usrp/mboard/Makefile.am new file mode 100644 index 000000000..66fc4dd71 --- /dev/null +++ b/lib/usrp/mboard/Makefile.am @@ -0,0 +1,7 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = diff --git a/lib/usrp_uhd.cpp b/lib/usrp_uhd.cpp new file mode 100644 index 000000000..a838b717b --- /dev/null +++ b/lib/usrp_uhd.cpp @@ -0,0 +1,8 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include + +usrp_uhd::usrp_uhd::usrp_uhd(device_addr_t device_addr){} +usrp_uhd::usrp_uhd::~usrp_uhd(void){} diff --git a/lib/wax.cpp b/lib/wax.cpp new file mode 100644 index 000000000..888e581f3 --- /dev/null +++ b/lib/wax.cpp @@ -0,0 +1,71 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include +#include +#include +#include + +/*********************************************************************** + * WAX Object + **********************************************************************/ +wax::obj::obj(void){ + /* NOP */ +} + +wax::obj::~obj(void){ + /* NOP */ +} + +wax::proxy wax::obj::operator[](const type &key){ + return proxy( + boost::bind(&obj::get, this, key, _1), + boost::bind(&obj::set, this, key, _1) + ); +} + +/*********************************************************************** + * WAX Proxy + **********************************************************************/ +wax::proxy::proxy(wax::proxy::getter_t getter, wax::proxy::setter_t setter) +: d_getter(getter), d_setter(setter){ + /* NOP */ +} + +wax::proxy::~proxy(void){ + /* NOP */ +} + +wax::proxy wax::proxy::operator[](const type &key){ + type val((*this)()); + //check if its a regular pointer and call + if (val.type() == typeid(obj::ptr)){ + return (*cast(val))[key]; + } + //check if its a smart pointer and call + if (val.type() == typeid(obj::sptr)){ + return (*cast(val))[key]; + } + //unknown type + throw std::runtime_error("cannot use [] on non wax::obj pointer"); +} + +wax::proxy wax::proxy::operator=(const type &val){ + d_setter(val); + return *this; +} + +wax::type wax::proxy::operator()(void){ + type val; + d_getter(val); + return val; +} + +/*********************************************************************** + * WAX Type + **********************************************************************/ +std::ostream& operator<<(std::ostream &os, const wax::type &x){ + os << boost::format("WAX type (%s)") % x.type().name(); + return os; +} diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 000000000..3d6649c66 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,3 @@ +/Makefile +/Makefile.in +/wax_test diff --git a/test/Makefile.am b/test/Makefile.am new file mode 100644 index 000000000..3373d838c --- /dev/null +++ b/test/Makefile.am @@ -0,0 +1,20 @@ +# +# Copyright 2010 Ettus Research LLC +# + +include $(top_srcdir)/Makefile.common + +SUBDIRS = + +AM_CPPFLAGS = $(GENERAL_CPPFLAGS) + +LDADD = \ + $(GENERAL_LDDFLAGS) + $(USRP_UHD_LA) + +noinst_PROGRAMS = \ + wax_test + +wax_test_SOURCES = wax_test.cpp + +TESTS = $(noinst_PROGRAMS) diff --git a/test/wax_test.cpp b/test/wax_test.cpp new file mode 100644 index 000000000..88c9e0f32 --- /dev/null +++ b/test/wax_test.cpp @@ -0,0 +1,81 @@ +// +// Copyright 2010 Ettus Research LLC +// + +#include +#include +#include +#include +#include + +class wax_demo : public wax::obj{ +private: + std::vector d_nums; + std::vector d_subs; +public: + wax_demo(size_t sub_demos, size_t len){ + d_nums = std::vector(len); + if (sub_demos != 0){ + for (size_t i = 0; i < len; i++){ + d_subs.push_back(wax_demo(sub_demos-1, len)); + } + } + } + ~wax_demo(void){ + /* NOP */ + } + void get(const wax::type &key, wax::type &value){ + if (d_subs.size() == 0){ + value = d_nums[wax::cast(key)]; + }else{ + value = obj::cast(&d_subs[wax::cast(key)]); + } + } + void set(const wax::type &key, const wax::type &value){ + if (d_subs.size() == 0){ + d_nums[wax::cast(key)] = wax::cast(value); + }else{ + throw std::runtime_error("cant set to a wax demo with sub demos"); + } + } +}; + +#define transform(i, j, k) float(i * j * k + i + j + k); + +int main(void){ + try{ + wax_demo wd(2, 10); + //test chained access + std::cout << "chain 1" << std::endl; + wd[size_t(0)]; + std::cout << "chain 2" << std::endl; + wd[size_t(0)][size_t(0)]; + std::cout << "chain 3" << std::endl; + wd[size_t(0)][size_t(0)][size_t(0)]; + //set a bunch of values + std::cout << "set and get all" << std::endl; + for (size_t i = 0; i < 10; i++){ + for (size_t j = 0; j < 10; j++){ + for (size_t k = 0; k < 10; k++){ + float val = transform(i, j, k); + //std::cout << i << " " << j << " " << k << std::endl; + wd[i][j][k] = val; + BOOST_ASSERT(wax::cast(wd[i][j][k]) == val); + } + } + } + //test storing a proxy + std::cout << "store proxy" << std::endl; + wax::proxy p = wd[size_t(0)][size_t(0)]; + p[size_t(0)] = float(5); + //test printing a type + std::cout << "print type" << std::endl; + wax::type test_type = float(3.33); + std::cout << test_type << std::endl; + std::cout << "done" << std::endl; + }catch(std::exception const& e){ + std::cout << "Exception: " << e.what() << std::endl; + return ~0; + } + return 0; +} diff --git a/usrp_dboard/.gitignore b/usrp_dboard/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/usrp_dboard/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/usrp_dboard/Makefile.am b/usrp_dboard/Makefile.am deleted file mode 100644 index a5a0ceb25..000000000 --- a/usrp_dboard/Makefile.am +++ /dev/null @@ -1,7 +0,0 @@ -# -# Copyright 2010 Ettus Research LLC -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = include lib diff --git a/usrp_dboard/include/.gitignore b/usrp_dboard/include/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/usrp_dboard/include/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/usrp_dboard/include/Makefile.am b/usrp_dboard/include/Makefile.am deleted file mode 100644 index fc549bfe0..000000000 --- a/usrp_dboard/include/Makefile.am +++ /dev/null @@ -1,10 +0,0 @@ -# -# Copyright 2010 Ettus Research LLC -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = - -noinst_HEADERS = \ - usrp_dboard/interface.hpp diff --git a/usrp_dboard/include/usrp_dboard/interface.hpp b/usrp_dboard/include/usrp_dboard/interface.hpp deleted file mode 100644 index c8e655736..000000000 --- a/usrp_dboard/include/usrp_dboard/interface.hpp +++ /dev/null @@ -1,119 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#ifndef INCLUDED_USRP_DBOARD_INTERFACE_HPP -#define INCLUDED_USRP_DBOARD_INTERFACE_HPP - -#include -#include - -namespace usrp_dboard{ - -/*! - * The daughter board interface to be subclassed. - * Each mboard should have a specially taylored dboard interface. - * This interface provides i2c, spi, gpio access for dboard instances. - */ -class interface{ -public: - typedef boost::shared_ptr sptr; - - //tells the host which device to use - enum spi_dev_t{ - SPI_TX_DEV, - SPI_RX_DEV, - }; - - //args for writing spi data - enum spi_push_t{ - SPI_PUSH_RISE, - SPI_PUSH_FALL - }; - - //args for reading spi data - enum spi_latch_t{ - SPI_LATCH_RISE, - SPI_LATCH_FALL - }; - - //tell the host which gpio bank - enum gpio_bank_t{ - GPIO_TX_BANK, - GPIO_RX_BANK - }; - - //structors - interface(void); - virtual ~interface(void); - - /*! - * Set daughterboard GPIO data direction register. - * - * \param bank GPIO_TX_BANK or GPIO_RX_BANK - * \param value 16-bits, 0=FPGA input, 1=FPGA output - * \param mask 16-bits, 0=ignore, 1=set - */ - virtual void set_gpio_ddr(gpio_bank_t bank, uint16_t value, uint16_t mask) = 0; - - /*! - * Set daughterboard GPIO pin values. - * - * \param bank GPIO_TX_BANK or GPIO_RX_BANK - * \param value 16 bits, 0=low, 1=high - * \param mask 16 bits, 0=ignore, 1=set - */ - virtual void write_gpio(gpio_bank_t bank, uint16_t value, uint16_t mask) = 0; - - /*! - * Read daughterboard GPIO pin values - * - * \param bank GPIO_TX_BANK or GPIO_RX_BANK - * \return the value of the gpio bank - */ - virtual uint16_t read_gpio(gpio_bank_t bank) = 0; - - /*! - * \brief Write to I2C peripheral - * \param i2c_addr I2C bus address (7-bits) - * \param buf the data to write - * Writes are limited to a maximum of of 64 bytes. - */ - virtual void write_i2c (int i2c_addr, const std::string &buf) = 0; - - /*! - * \brief Read from I2C peripheral - * \param i2c_addr I2C bus address (7-bits) - * \param len number of bytes to read - * \return the data read if successful, else a zero length string. - * Reads are limited to a maximum of 64 bytes. - */ - virtual std::string read_i2c (int i2c_addr, size_t len) = 0; - - /*! - * \brief Write data to SPI bus peripheral. - * - * \param dev which spi device - * \param push args for writing - * \param buf the data to write - * - * Writes are limited to a maximum of 64 bytes. - */ - virtual void write_spi (spi_dev_t dev, spi_push_t push, const std::string &buf) = 0; - - /*! - * \brief Read data from SPI bus peripheral. - * - * \param dev which spi device - * \param push args for reading - * \param len number of bytes to read. Must be in [0,64]. - * \return the data read if sucessful, else a zero length string. - * - * Reads are limited to a maximum of 64 bytes. - */ - virtual std::string read_spi (spi_dev_t dev, spi_latch_t latch, size_t len) = 0; -}; - -} //namespace usrp_dboard - -#endif /* INCLUDED_USRP_DBOARD_INTERFACE_HPP */ diff --git a/usrp_dboard/lib/.gitignore b/usrp_dboard/lib/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/usrp_dboard/lib/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/usrp_dboard/lib/Makefile.am b/usrp_dboard/lib/Makefile.am deleted file mode 100644 index 69f2c8568..000000000 --- a/usrp_dboard/lib/Makefile.am +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright 2010 Ettus Research LLC -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = - -AM_CPPFLAGS = \ - $(USRP_DBOARD_INCLUDES) \ - $(BOOST_CPPFLAGS) - -noinst_LTLIBRARIES = \ - libusrp_dboard.la - -libusrp_dboard_la_SOURCES = \ - interface.cpp - -libusrp_dboard_la_LIBADD = \ - $(BOOST_LDFLAGS) \ - $(BOOST_THREAD_LIB) - -noinst_HEADERS = diff --git a/usrp_dboard/lib/interface.cpp b/usrp_dboard/lib/interface.cpp deleted file mode 100644 index 5fedf9c46..000000000 --- a/usrp_dboard/lib/interface.cpp +++ /dev/null @@ -1,13 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#include - -usrp_dboard::interface::interface(void){ - /* NOP */ -} - -usrp_dboard::interface::~interface(void){ - /* NOP */ -} diff --git a/usrp_uhd.pc.in b/usrp_uhd.pc.in new file mode 100644 index 000000000..18194a741 --- /dev/null +++ b/usrp_uhd.pc.in @@ -0,0 +1,11 @@ +prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +includedir=@includedir@ + +Name: usrp_uhd +Description: Universal Software Radio Peripheral - Unified Hardware Driver +Requires: +Version: @VERSION@ +Libs: -L${libdir} -lusrp_uhd +Cflags: -I${includedir} diff --git a/usrp_uhd/.gitignore b/usrp_uhd/.gitignore deleted file mode 100644 index 2cc79dbab..000000000 --- a/usrp_uhd/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -/Makefile -/Makefile.in -/usrp_uhd.pc diff --git a/usrp_uhd/Makefile.am b/usrp_uhd/Makefile.am deleted file mode 100644 index c218af41a..000000000 --- a/usrp_uhd/Makefile.am +++ /dev/null @@ -1,13 +0,0 @@ -# -# Copyright 2010 Ettus Research LLC -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = include lib - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = usrp_uhd.pc - -EXTRA_DIST = \ - usrp_uhd.pc.in diff --git a/usrp_uhd/include/.gitignore b/usrp_uhd/include/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/usrp_uhd/include/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/usrp_uhd/include/Makefile.am b/usrp_uhd/include/Makefile.am deleted file mode 100644 index 1ec431648..000000000 --- a/usrp_uhd/include/Makefile.am +++ /dev/null @@ -1,16 +0,0 @@ -# -# Copyright 2010 Ettus Research LLC -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = - -this_includedir = $(includedir) -this_include_HEADERS = \ - usrp_uhd.hpp - -usrp_uhd_includedir = $(includedir)/usrp_uhd -usrp_uhd_include_HEADERS = \ - usrp_uhd/usrp_addr.hpp \ - usrp_uhd/wax.hpp diff --git a/usrp_uhd/include/usrp_uhd.hpp b/usrp_uhd/include/usrp_uhd.hpp deleted file mode 100644 index 6bf97a5a4..000000000 --- a/usrp_uhd/include/usrp_uhd.hpp +++ /dev/null @@ -1,43 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#ifndef INCLUDED_USRP_UHD_HPP -#define INCLUDED_USRP_UHD_HPP - -#include -#include -#include -#include -#include -#include - -namespace usrp{ - - class uhd{ - - public: - typedef boost::shared_ptr sptr; - typedef boost::function recv_hdlr_t; - uhd(usrp_addr_t usrp_addr); - ~uhd(void); - - //the io interface - void send(const std::vector &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 - -#endif /* INCLUDED_USRP_UHD_HPP */ diff --git a/usrp_uhd/include/usrp_uhd/usrp_addr.hpp b/usrp_uhd/include/usrp_uhd/usrp_addr.hpp deleted file mode 100644 index e8c282288..000000000 --- a/usrp_uhd/include/usrp_uhd/usrp_addr.hpp +++ /dev/null @@ -1,90 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#ifndef INCLUDED_USRP_ADDR_HPP -#define INCLUDED_USRP_ADDR_HPP - -#include -#include -#include -#include - -namespace usrp{ - - /*! - * Wrapper for an ethernet mac address. - * Provides conversion between string and binary formats. - */ - struct mac_addr_t{ - struct ether_addr d_mac_addr; - mac_addr_t(const std::string &str = "00:00:00:00:00:00"); - std::string to_string(void) const; - }; - - /*! - * Wrapper for an ipv4 address. - * Provides conversion between string and binary formats. - */ - struct ip_addr_t{ - struct in_addr d_ip_addr; - ip_addr_t(const std::string &str = "0.0.0.0"); - std::string to_string(void) const; - }; - - /*! - * Possible usrp mboard interface types. - */ - enum usrp_addr_type_t{ - USRP_ADDR_TYPE_AUTO, - USRP_ADDR_TYPE_VIRTUAL, - USRP_ADDR_TYPE_USB, - USRP_ADDR_TYPE_ETH, - USRP_ADDR_TYPE_UDP, - USRP_ADDR_TYPE_GPMC - }; - - /*! - * Structure to hold properties that identify a usrp mboard. - */ - struct usrp_addr_t{ - usrp_addr_type_t type; - struct{ - size_t num_rx_dsps; - size_t num_tx_dsps; - size_t num_dboards; - } virtual_args; - struct{ - uint16_t vendor_id; - uint16_t product_id; - } usb_args; - struct{ - std::string ifc; - mac_addr_t mac_addr; - } eth_args; - struct{ - ip_addr_t ip_addr; - } udp_args; - struct{ - //TODO unknown for now - } gpmc_args; - - /*! - * \brief Convert a usrp usrp_addr_t into a string representation - */ - std::string to_string(void) const; - - /*! - * \brief Default constructor to initialize the usrp_addr_t struct - */ - usrp_addr_t(usrp_addr_type_t usrp_addr_type = USRP_ADDR_TYPE_AUTO); - }; - -} //namespace usrp - -//ability to use types with stream operators -std::ostream& operator<<(std::ostream &os, const usrp::usrp_addr_t &x); -std::ostream& operator<<(std::ostream &os, const usrp::mac_addr_t &x); -std::ostream& operator<<(std::ostream &os, const usrp::ip_addr_t &x); - -#endif /* INCLUDED_USRP_ADDR_HPP */ diff --git a/usrp_uhd/include/usrp_uhd/wax.hpp b/usrp_uhd/include/usrp_uhd/wax.hpp deleted file mode 100644 index 9d32314f7..000000000 --- a/usrp_uhd/include/usrp_uhd/wax.hpp +++ /dev/null @@ -1,129 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#ifndef INCLUDED_WAX_HPP -#define INCLUDED_WAX_HPP - -#include -#include -#include -#include -#include -#include - -/*! - * WAX - it's a metaphor! - * - * The WAX framework allows object to have generic/anytype properties. - * These properties can be addressed through generic/anytype identifiers. - * A property of a WAX object may even be another WAX object. - * - * When a property is a WAX object, the returned value must be an obj pointer. - * A WAX object provides two types of pointers: obj::ptr and obj::sptr. - * The choice of pointer vs smart pointer depends on the owner of the memory. - * - * Proprties may be referenced though the [] overloaded operator. - * The [] operator returns a special proxy that allows for assigment. - * Also, the [] operators may be chained as in the folowing examples: - * my_obj[prop1][prop2][prop3] = value - * value = my_obj[prop1][prop2][prop3] - * - * Any value returned from an access operation is of wax::type. - * To use this value, it must be cast with wax::cast(value). - */ - -namespace wax{ - - //general typedefs - typedef boost::any type; - typedef boost::bad_any_cast bad_cast; - - //dummy class declarations - class obj; class proxy; - - /*! - * WAX object base class: - * A wax object subclass should override the set and get methods. - * The magic of operator chaining is handled by the [] operator. - */ - class obj{ - public: - //obj pointer typedefs - typedef boost::shared_ptr sptr; - typedef obj* ptr; - - //cast derived pointer to obj base class pointer - template static sptr cast(boost::shared_ptr r){ - return boost::static_pointer_cast(r); - } - template static ptr cast(T *r){ - return dynamic_cast(r); - } - - //structors - obj(void); - virtual ~obj(void); - - //public interface - proxy operator[](const type &key); - - private: - //private interface - virtual void get(const type &key, type &val) = 0; - virtual void set(const type &key, const type &val) = 0; - }; - - /*! - * WAX proxy class: - * Allows the obj [] operator to return a proxy result. - * This result can be assigned to via the = operator. - * Or this result can be called again with the [] operator. - */ - class proxy{ - public: - //destructors - ~proxy(void); - - //overloaded - type operator()(void); - proxy operator[](const type &key); - proxy operator=(const type &key); - - private: - //typedefs for callables from the object that built this proxy - typedef boost::function setter_t; - typedef boost::function getter_t; - - //private contructor - proxy(getter_t, setter_t); - //access to private contructor - friend proxy obj::operator[](const type &key); - - getter_t d_getter; - setter_t d_setter; - }; - - /*! - * Cast a wax::type into the desired type - * Usage wax::cast(my_value). - * - * \param val the any type to cast - * \return data of the desired type - * \throw wax::bad_cast when the cast fails - */ - template T cast(const type & val){ - //special case to handle the proxy - if (val.type() == typeid(proxy)){ - return cast(boost::any_cast(val)()); - } - //do the type cast - return boost::any_cast(val); - } - -} //namespace wax - -//ability to use types with stream operators -std::ostream& operator<<(std::ostream &os, const wax::type &x); - -#endif /* INCLUDED_WAX_HPP */ diff --git a/usrp_uhd/lib/.gitignore b/usrp_uhd/lib/.gitignore deleted file mode 100644 index b336cc7ce..000000000 --- a/usrp_uhd/lib/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/Makefile -/Makefile.in diff --git a/usrp_uhd/lib/Makefile.am b/usrp_uhd/lib/Makefile.am deleted file mode 100644 index 2b744b4fc..000000000 --- a/usrp_uhd/lib/Makefile.am +++ /dev/null @@ -1,26 +0,0 @@ -# -# Copyright 2010 Ettus Research LLC -# - -include $(top_srcdir)/Makefile.common - -SUBDIRS = - -AM_CPPFLAGS = \ - $(USRP_UHD_INCLUDES) \ - $(BOOST_CPPFLAGS) - -lib_LTLIBRARIES = \ - libusrp_uhd.la - -libusrp_uhd_la_SOURCES = \ - usrp_addr.cpp \ - usrp_uhd.cpp \ - wax.cpp - -libusrp_uhd_la_LIBADD = \ - $(BOOST_LDFLAGS) \ - $(BOOST_THREAD_LIB) \ - $(USRP_DBOARD_LA) - -noinst_HEADERS = diff --git a/usrp_uhd/lib/usrp_addr.cpp b/usrp_uhd/lib/usrp_addr.cpp deleted file mode 100644 index ddae7cd80..000000000 --- a/usrp_uhd/lib/usrp_addr.cpp +++ /dev/null @@ -1,116 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#include -#include -#include -#include -#include - -//----------------------- u2 mac addr wrapper ------------------------// -usrp::mac_addr_t::mac_addr_t(const std::string &str){ - //ether_aton_r(str.c_str(), &d_mac_addr); - bool good = false; - char p[6] = {0x00, 0x50, 0xC2, 0x85, 0x30, 0x00}; // Matt's IAB - - switch (str.size()){ - case 5: - good = sscanf(str.c_str(), "%hhx:%hhx", &p[4], &p[5]) == 2; - break; - case 17: - good = sscanf(str.c_str(), "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", - &p[0], &p[1], &p[2], &p[3], &p[4], &p[5]) == 6; - break; - } - - if (not good) throw std::runtime_error("Invalid mac address: " + str); - memcpy(&d_mac_addr, p, sizeof(d_mac_addr)); -} - -std::string usrp::mac_addr_t::to_string(void) const{ - char addr_buf[128]; - //ether_ntoa_r(&d_mac_addr, addr_buf); - const uint8_t *p = reinterpret_cast(&d_mac_addr); - sprintf(addr_buf, "%02x:%02x:%02x:%02x:%02x:%02x", - p[0], p[1], p[2], p[3], p[4], p[5]); - return std::string(addr_buf); -} - -std::ostream& operator<<(std::ostream &os, const usrp::mac_addr_t &x){ - os << x.to_string(); - return os; -} - -//----------------------- u2 ipv4 wrapper ----------------------------// -usrp::ip_addr_t::ip_addr_t(const std::string &str){ - int ret = inet_pton(AF_INET, str.c_str(), &d_ip_addr); - if (ret == 0) throw std::runtime_error("Invalid ip address: " + str); -} - -std::string usrp::ip_addr_t::to_string(void) const{ - char addr_buf[128]; - inet_ntop(AF_INET, &d_ip_addr, addr_buf, INET_ADDRSTRLEN); - return std::string(addr_buf); -} - -std::ostream& operator<<(std::ostream &os, const usrp::ip_addr_t &x){ - os << x.to_string(); - return os; -} - -//----------------------- usrp usrp_addr_t wrapper -------------------------// -usrp::usrp_addr_t::usrp_addr_t(usrp_addr_type_t usrp_addr_type){ - type = usrp_addr_type; - virtual_args.num_rx_dsps = 0; - virtual_args.num_tx_dsps = 0; - virtual_args.num_dboards = 0; - 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"); -} - -std::string usrp::usrp_addr_t::to_string(void) const{ - std::stringstream out; - out << "USRP Type: "; - switch(type){ - case USRP_ADDR_TYPE_AUTO: - out << "Automatic" << std::endl; - break; - case USRP_ADDR_TYPE_VIRTUAL: - out << "Virtual" << std::endl; - out << "Num RX DSPs: " << virtual_args.num_rx_dsps << std::endl; - out << "Num TX DSPs: " << virtual_args.num_rx_dsps << std::endl; - out << "Num dboards: " << virtual_args.num_dboards << std::endl; - break; - case USRP_ADDR_TYPE_USB: - out << "USB Port" << std::endl; - out << "Vendor ID: 0x" << std::hex << usb_args.vendor_id << std::endl; - out << "Product ID: 0x" << std::hex << usb_args.product_id << std::endl; - break; - case USRP_ADDR_TYPE_ETH: - out << "Raw Ethernet" << std::endl; - out << "Interface: " << eth_args.ifc << std::endl; - out << "MAC Addr: " << eth_args.mac_addr << std::endl; - break; - case USRP_ADDR_TYPE_UDP: - out << "UDP Socket" << std::endl; - out << "IP Addr: " << udp_args.ip_addr << std::endl; - break; - case USRP_ADDR_TYPE_GPMC: - out << "GPMC" << std::endl; - break; - default: - out << "Unknown" << std::endl; - } - out << std::endl; - return out.str(); -} - -std::ostream& operator<<(std::ostream &os, const usrp::usrp_addr_t &x) -{ - os << x.to_string(); - return os; -} diff --git a/usrp_uhd/lib/usrp_uhd.cpp b/usrp_uhd/lib/usrp_uhd.cpp deleted file mode 100644 index 6dd9bee7b..000000000 --- a/usrp_uhd/lib/usrp_uhd.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#include - -using namespace usrp; - -uhd::uhd(usrp_addr_t usrp_addr){} -uhd::~uhd(void){} diff --git a/usrp_uhd/lib/wax.cpp b/usrp_uhd/lib/wax.cpp deleted file mode 100644 index 888e581f3..000000000 --- a/usrp_uhd/lib/wax.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// -// Copyright 2010 Ettus Research LLC -// - -#include -#include -#include -#include - -/*********************************************************************** - * WAX Object - **********************************************************************/ -wax::obj::obj(void){ - /* NOP */ -} - -wax::obj::~obj(void){ - /* NOP */ -} - -wax::proxy wax::obj::operator[](const type &key){ - return proxy( - boost::bind(&obj::get, this, key, _1), - boost::bind(&obj::set, this, key, _1) - ); -} - -/*********************************************************************** - * WAX Proxy - **********************************************************************/ -wax::proxy::proxy(wax::proxy::getter_t getter, wax::proxy::setter_t setter) -: d_getter(getter), d_setter(setter){ - /* NOP */ -} - -wax::proxy::~proxy(void){ - /* NOP */ -} - -wax::proxy wax::proxy::operator[](const type &key){ - type val((*this)()); - //check if its a regular pointer and call - if (val.type() == typeid(obj::ptr)){ - return (*cast(val))[key]; - } - //check if its a smart pointer and call - if (val.type() == typeid(obj::sptr)){ - return (*cast(val))[key]; - } - //unknown type - throw std::runtime_error("cannot use [] on non wax::obj pointer"); -} - -wax::proxy wax::proxy::operator=(const type &val){ - d_setter(val); - return *this; -} - -wax::type wax::proxy::operator()(void){ - type val; - d_getter(val); - return val; -} - -/*********************************************************************** - * WAX Type - **********************************************************************/ -std::ostream& operator<<(std::ostream &os, const wax::type &x){ - os << boost::format("WAX type (%s)") % x.type().name(); - return os; -} diff --git a/usrp_uhd/usrp_uhd.pc.in b/usrp_uhd/usrp_uhd.pc.in deleted file mode 100644 index 18194a741..000000000 --- a/usrp_uhd/usrp_uhd.pc.in +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@prefix@ -exec_prefix=@exec_prefix@ -libdir=@libdir@ -includedir=@includedir@ - -Name: usrp_uhd -Description: Universal Software Radio Peripheral - Unified Hardware Driver -Requires: -Version: @VERSION@ -Libs: -L${libdir} -lusrp_uhd -Cflags: -I${includedir} -- cgit v1.2.3