diff options
author | Josh Blum <josh@joshknows.com> | 2010-02-17 00:41:38 -0800 |
---|---|---|
committer | Josh Blum <josh@joshknows.com> | 2010-02-17 00:41:38 -0800 |
commit | eb7e709b7aff162cc7c8f9b8004089846839ffbe (patch) | |
tree | 7dd6527b06297d9b64e8800ffcd63001aa3159e1 /host/lib/device.cpp | |
parent | d8d783ce1b1034495dba86dab104a4f52e2fe09a (diff) | |
download | uhd-eb7e709b7aff162cc7c8f9b8004089846839ffbe.tar.gz uhd-eb7e709b7aff162cc7c8f9b8004089846839ffbe.tar.bz2 uhd-eb7e709b7aff162cc7c8f9b8004089846839ffbe.zip |
moved host code into host directory for clean (unambiguous) top level
Diffstat (limited to 'host/lib/device.cpp')
-rw-r--r-- | host/lib/device.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/host/lib/device.cpp b/host/lib/device.cpp new file mode 100644 index 000000000..822733217 --- /dev/null +++ b/host/lib/device.cpp @@ -0,0 +1,74 @@ +// +// Copyright 2010 Ettus Research LLC +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see <http://www.gnu.org/licenses/>. +// + +#include <uhd/usrp/usrp.hpp> +#include <uhd/usrp/mboard/usrp2.hpp> +#include <uhd/device.hpp> +#include <boost/format.hpp> +#include <stdexcept> + +using namespace uhd; + +device_addrs_t device::discover(const device_addr_t &hint){ + device_addrs_t device_addrs; + if (not hint.has_key("type")){ + //TODO nothing + } + else if (hint["type"] == "test"){ + //make a copy of the hint for testing + device_addr_t test_device_addr = hint; + device_addrs.push_back(test_device_addr); + } + else if (hint["type"] == "udp"){ + std::vector<device_addr_t> usrp2_addrs = usrp::mboard::usrp2::discover(hint); + device_addrs.insert(device_addrs.begin(), usrp2_addrs.begin(), usrp2_addrs.end()); + } + 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") % device_addr_to_string(hint) + )); + } + + //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 % device_addr_to_string(hint) + )); + } + + //create the new device with the discovered address + //TODO only a usrp device will be made (until others are supported) + if (true){ + return sptr(new uhd::usrp::usrp(device_addrs.at(which))); + } + throw std::runtime_error("cant make a device"); +} + +device::device(void){ + /* NOP */ +} + +device::~device(void){ + /* NOP */ +} |