diff options
author | Josh Blum <josh@joshknows.com> | 2010-01-21 15:30:34 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-01-21 15:30:34 -0800 |
commit | e3483c7451d20b7ed1d8d4865e15751f18cdef78 (patch) | |
tree | f309a95a1b0ecd3dc3295ebc71ee5ad697c9f7a8 /lib | |
parent | 5b42b774d9ac1e74fb2916bf58085fe19ecb6720 (diff) | |
download | uhd-e3483c7451d20b7ed1d8d4865e15751f18cdef78.tar.gz uhd-e3483c7451d20b7ed1d8d4865e15751f18cdef78.tar.bz2 uhd-e3483c7451d20b7ed1d8d4865e15751f18cdef78.zip |
Added a usrp device abstration that creates usrp mboards.
Added a usrp mboard named test, its empty for now.
Diffstat (limited to 'lib')
-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 |
8 files changed, 137 insertions, 9 deletions
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 +} |