summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/.gitignore2
-rw-r--r--lib/Makefile.am21
-rw-r--r--lib/device_addr.cpp116
-rw-r--r--lib/quadradio/.gitignore2
-rw-r--r--lib/quadradio/Makefile.am7
-rw-r--r--lib/usrp/.gitignore2
-rw-r--r--lib/usrp/Makefile.am7
-rw-r--r--lib/usrp/dboard/.gitignore2
-rw-r--r--lib/usrp/dboard/Makefile.am7
-rw-r--r--lib/usrp/mboard/.gitignore2
-rw-r--r--lib/usrp/mboard/Makefile.am7
-rw-r--r--lib/usrp_uhd.cpp8
-rw-r--r--lib/wax.cpp71
13 files changed, 254 insertions, 0 deletions
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 <usrp_uhd/device_addr.hpp>
+#include <sstream>
+#include <cstring>
+#include <cstdio>
+#include <stdexcept>
+
+//----------------------- 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<const uint8_t *>(&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.hpp>
+
+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 <usrp_uhd/wax.hpp>
+#include <stdexcept>
+#include <boost/bind.hpp>
+#include <boost/format.hpp>
+
+/***********************************************************************
+ * 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<obj::ptr>(val))[key];
+ }
+ //check if its a smart pointer and call
+ if (val.type() == typeid(obj::sptr)){
+ return (*cast<obj::sptr>(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;
+}