aboutsummaryrefslogtreecommitdiffstats
path: root/host
diff options
context:
space:
mode:
Diffstat (limited to 'host')
-rw-r--r--host/apps/discover_usrps.cpp21
-rw-r--r--host/include/uhd/device.hpp4
-rw-r--r--host/include/uhd/device_addr.hpp4
-rw-r--r--host/include/uhd/usrp/CMakeLists.txt1
-rw-r--r--host/include/uhd/usrp/usrp1e.hpp48
-rw-r--r--host/include/uhd/usrp/usrp2.hpp6
-rw-r--r--host/lib/CMakeLists.txt14
-rw-r--r--host/lib/device.cpp100
-rw-r--r--host/lib/device_addr.cpp4
-rw-r--r--host/lib/usrp/usrp1e/usrp1e_none.cpp34
-rw-r--r--host/lib/usrp/usrp2/usrp2_impl.cpp3
11 files changed, 204 insertions, 35 deletions
diff --git a/host/apps/discover_usrps.cpp b/host/apps/discover_usrps.cpp
index 08135a27c..7e8c21673 100644
--- a/host/apps/discover_usrps.cpp
+++ b/host/apps/discover_usrps.cpp
@@ -28,6 +28,7 @@ int main(int argc, char *argv[]){
desc.add_options()
("help", "help message")
("addr", po::value<std::string>(), "resolvable network address")
+ ("node", po::value<std::string>(), "path to linux device node")
;
po::variables_map vm;
@@ -35,22 +36,28 @@ int main(int argc, char *argv[]){
po::notify(vm);
//print the help message
- if (vm.count("help")) {
+ if (vm.count("help")){
std::cout << boost::format("Discover USRPs %s") % desc << std::endl;
return ~0;
}
- //extract the address (not optional for now)
+ //load the options into the address
uhd::device_addr_t device_addr;
- if (vm.count("addr")) {
+ if (vm.count("addr")){
device_addr["addr"] = vm["addr"].as<std::string>();
- } else {
- std::cout << "The address was not set" << std::endl;
+ }
+ if (vm.count("node")){
+ device_addr["node"] = vm["node"].as<std::string>();
+ }
+
+ //discover the usrps and print the results
+ uhd::device_addrs_t device_addrs = uhd::device::discover(device_addr);
+
+ if (device_addrs.size() == 0){
+ std::cerr << "No USRP Devices Found" << std::endl;
return ~0;
}
- //discover the usrps
- std::vector<uhd::device_addr_t> device_addrs = uhd::device::discover(device_addr);
for (size_t i = 0; i < device_addrs.size(); i++){
std::cout << "--------------------------------------------------" << std::endl;
std::cout << "-- USRP Device " << i << std::endl;
diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp
index 596a98bc4..ba5337d33 100644
--- a/host/include/uhd/device.hpp
+++ b/host/include/uhd/device.hpp
@@ -38,10 +38,6 @@ class device : boost::noncopyable, public wax::obj{
public:
typedef boost::shared_ptr<device> sptr;
- //structors
- device(void);
- virtual ~device(void);
-
/*!
* \brief Discover usrp devices attached to the host.
*
diff --git a/host/include/uhd/device_addr.hpp b/host/include/uhd/device_addr.hpp
index 8ea580321..d02febd6c 100644
--- a/host/include/uhd/device_addr.hpp
+++ b/host/include/uhd/device_addr.hpp
@@ -56,7 +56,9 @@ namespace uhd{
* \param device_addr a device address instance
* \return the string representation
*/
- std::string device_addr_to_string(const device_addr_t &device_addr);
+ struct device_addr{
+ static std::string to_string(const device_addr_t &device_addr);
+ };
} //namespace uhd
diff --git a/host/include/uhd/usrp/CMakeLists.txt b/host/include/uhd/usrp/CMakeLists.txt
index e7bdc1784..4e0a92365 100644
--- a/host/include/uhd/usrp/CMakeLists.txt
+++ b/host/include/uhd/usrp/CMakeLists.txt
@@ -21,6 +21,7 @@ INSTALL(FILES
dboard_id.hpp
dboard_interface.hpp
dboard_manager.hpp
+ usrp1e.hpp
usrp2.hpp
DESTINATION ${HEADER_DIR}/uhd/usrp
)
diff --git a/host/include/uhd/usrp/usrp1e.hpp b/host/include/uhd/usrp/usrp1e.hpp
new file mode 100644
index 000000000..00748e55f
--- /dev/null
+++ b/host/include/uhd/usrp/usrp1e.hpp
@@ -0,0 +1,48 @@
+//
+// 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/>.
+//
+
+#ifndef INCLUDED_UHD_USRP_USRP1E_HPP
+#define INCLUDED_UHD_USRP_USRP1E_HPP
+
+#include <uhd/device.hpp>
+
+namespace uhd{ namespace usrp{
+
+/*!
+ * The usrp1e device class.
+ */
+class usrp1e : public device{
+public:
+ /*!
+ * Discover usrp1e devices on the system via the device node.
+ * This static method will be called by the device::discover.
+ * \param hint a device addr with the usrp1e address filled in
+ * \return a vector of device addresses for all usrp1es found
+ */
+ static device_addrs_t discover(const device_addr_t &hint);
+
+ /*!
+ * Make a usrp1e from a device address.
+ * \param addr the device address
+ * \return a device sptr to a new usrp1e
+ */
+ static device::sptr make(const device_addr_t &addr);
+};
+
+}} //namespace
+
+#endif /* INCLUDED_UHD_USRP_USRP1E_HPP */
diff --git a/host/include/uhd/usrp/usrp2.hpp b/host/include/uhd/usrp/usrp2.hpp
index f6e49cbd6..da7ec595a 100644
--- a/host/include/uhd/usrp/usrp2.hpp
+++ b/host/include/uhd/usrp/usrp2.hpp
@@ -15,8 +15,8 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
-#ifndef INCLUDED_UHD_USRP_MBOARD_USRP2_HPP
-#define INCLUDED_UHD_USRP_MBOARD_USRP2_HPP
+#ifndef INCLUDED_UHD_USRP_USRP2_HPP
+#define INCLUDED_UHD_USRP_USRP2_HPP
#include <uhd/device.hpp>
@@ -45,4 +45,4 @@ public:
}} //namespace
-#endif /* INCLUDED_UHD_USRP_MBOARD_USRP2_HPP */
+#endif /* INCLUDED_UHD_USRP_USRP2_HPP */
diff --git a/host/lib/CMakeLists.txt b/host/lib/CMakeLists.txt
index 253f45614..edfefa127 100644
--- a/host/lib/CMakeLists.txt
+++ b/host/lib/CMakeLists.txt
@@ -15,7 +15,9 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
-
+########################################################################
+# Create a list of libuhd sources
+########################################################################
SET(libuhd_sources
device.cpp
device_addr.cpp
@@ -36,6 +38,16 @@ SET(libuhd_sources
usrp/usrp2/usrp2_impl.cpp
)
+########################################################################
+# Conditionally add the usrp1e sources
+########################################################################
+LIST(APPEND libuhd_sources
+ usrp/usrp1e/usrp1e_none.cpp
+)
+
+########################################################################
+# Setup libuhd library
+########################################################################
ADD_LIBRARY(uhd SHARED ${libuhd_sources})
TARGET_LINK_LIBRARIES(uhd ${Boost_LIBRARIES})
diff --git a/host/lib/device.cpp b/host/lib/device.cpp
index f181d31e4..82052708a 100644
--- a/host/lib/device.cpp
+++ b/host/lib/device.cpp
@@ -12,54 +12,122 @@
// 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/>.
+// asize_t with this program. If not, see <http://www.gnu.org/licenses/>.
//
+#include <uhd/usrp/usrp1e.hpp>
#include <uhd/usrp/usrp2.hpp>
-#include <uhd/device.hpp>
+#include <uhd/dict.hpp>
+#include <uhd/utils.hpp>
+#include <boost/foreach.hpp>
#include <boost/format.hpp>
+#include <boost/weak_ptr.hpp>
+#include <boost/functional/hash.hpp>
#include <stdexcept>
+#include <algorithm>
using namespace uhd;
+/*!
+ * Create a new device from a device address.
+ * Based on the address, call the appropriate make functions.
+ * \param dev_addr the device address
+ * \return a smart pointer to a device
+ */
+static device::sptr make_device(const device_addr_t &dev_addr){
+
+ //create a usrp1e
+ if (dev_addr["type"] == "usrp1e"){
+ return usrp::usrp1e::make(dev_addr);
+ }
+
+ //create a usrp2
+ if (dev_addr["type"] == "usrp2"){
+ return usrp::usrp2::make(dev_addr);
+ }
+
+ throw std::runtime_error("cant make a device");
+}
+
+/*!
+ * Make a device hash that maps 1 to 1 with a device address.
+ * The hash will be used to identify created devices.
+ * \param dev_addr the device address
+ * \return the hash number
+ */
+static size_t hash_device_addr(
+ const device_addr_t &dev_addr
+){
+ //sort the keys of the device address
+ std::vector<std::string> keys = dev_addr.get_keys();
+ std::sort(keys.begin(), keys.end());
+
+ //combine the hashes of sorted keys/value pairs
+ size_t hash = 0;
+ BOOST_FOREACH(std::string key, keys){
+ boost::hash_combine(hash, key);
+ boost::hash_combine(hash, dev_addr[key]);
+ }
+ return hash;
+}
+
+/***********************************************************************
+ * Discover
+ **********************************************************************/
device_addrs_t device::discover(const device_addr_t &hint){
device_addrs_t device_addrs;
+
+ //discover the usrp1es
+ std::vector<device_addr_t> usrp2_addrs = usrp::usrp1e::discover(hint);
+ device_addrs.insert(device_addrs.begin(), usrp2_addrs.begin(), usrp2_addrs.end());
+
+ //discover the usrp2s
if (hint.has_key("addr")){
std::vector<device_addr_t> usrp2_addrs = usrp::usrp2::discover(hint);
device_addrs.insert(device_addrs.begin(), usrp2_addrs.begin(), usrp2_addrs.end());
}
+
return device_addrs;
}
+/***********************************************************************
+ * Make
+ **********************************************************************/
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)
+ 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)
+ 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 usrp2 device will be made (until others are supported)
- if (hint.has_key("addr")){
- return usrp::usrp2::make(device_addrs.at(which));
- }
- throw std::runtime_error("cant make a device");
-}
+ //create a unique hash for the device address
+ device_addr_t dev_addr = device_addrs.at(which);
+ size_t dev_hash = hash_device_addr(dev_addr);
+ //std::cout << boost::format("Hash: %u") % dev_hash << std::endl;
-device::device(void){
- /* NOP */
-}
+ //map device address hash to created devices
+ static uhd::dict<size_t, boost::weak_ptr<device> > hash_to_device;
-device::~device(void){
- /* NOP */
+ //try to find an existing device
+ try{
+ ASSERT_THROW(hash_to_device.has_key(dev_hash));
+ ASSERT_THROW(not hash_to_device[dev_hash].expired());
+ return hash_to_device[dev_hash].lock();
+ }
+ //create and register a new device
+ catch(const std::assert_error &e){
+ device::sptr dev = make_device(dev_addr);
+ hash_to_device[dev_hash] = dev;
+ return dev;
+ }
}
diff --git a/host/lib/device_addr.cpp b/host/lib/device_addr.cpp
index ffd511f92..9514df981 100644
--- a/host/lib/device_addr.cpp
+++ b/host/lib/device_addr.cpp
@@ -72,7 +72,7 @@ std::ostream& operator<<(std::ostream &os, const uhd::mac_addr_t &x){
}
//----------------------- usrp device_addr_t wrapper -------------------------//
-std::string uhd::device_addr_to_string(const uhd::device_addr_t &device_addr){
+std::string uhd::device_addr::to_string(const uhd::device_addr_t &device_addr){
std::stringstream ss;
BOOST_FOREACH(std::string key, device_addr.get_keys()){
ss << boost::format("%s: %s") % key % device_addr[key] << std::endl;
@@ -81,6 +81,6 @@ std::string uhd::device_addr_to_string(const uhd::device_addr_t &device_addr){
}
std::ostream& operator<<(std::ostream &os, const uhd::device_addr_t &device_addr){
- os << uhd::device_addr_to_string(device_addr);
+ os << uhd::device_addr::to_string(device_addr);
return os;
}
diff --git a/host/lib/usrp/usrp1e/usrp1e_none.cpp b/host/lib/usrp/usrp1e/usrp1e_none.cpp
new file mode 100644
index 000000000..1c8cf9a5b
--- /dev/null
+++ b/host/lib/usrp/usrp1e/usrp1e_none.cpp
@@ -0,0 +1,34 @@
+//
+// 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/usrp1e.hpp>
+
+using namespace uhd;
+using namespace uhd::usrp;
+
+/*!
+ * This file defines the usrp1e discover and make functions
+ * when the required kernel module headers are not present.
+ */
+
+device_addrs_t usrp1e::discover(const device_addr_t &){
+ return device_addrs_t(); //return empty list
+}
+
+device::sptr usrp1e::make(const device_addr_t &){
+ throw std::runtime_error("this build has no usrp1e support");
+}
diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp
index 770fa3e53..06876d241 100644
--- a/host/lib/usrp/usrp2/usrp2_impl.cpp
+++ b/host/lib/usrp/usrp2/usrp2_impl.cpp
@@ -60,7 +60,8 @@ uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){
//make a boost asio ipv4 with the raw addr in host byte order
boost::asio::ip::address_v4 ip_addr(ntohl(ctrl_data_in.data.ip_addr));
device_addr_t new_addr;
- new_addr["name"] = "usrp2";
+ new_addr["name"] = "USRP2";
+ new_addr["type"] = "usrp2";
new_addr["transport"] = "udp";
new_addr["addr"] = ip_addr.to_string();
usrp2_addrs.push_back(new_addr);