From 281307833c8275031bd2469e6aef3f472490749a Mon Sep 17 00:00:00 2001 From: Josh Blum Date: Tue, 30 Mar 2010 15:11:23 -0700 Subject: use find to discover devices --- host/include/uhd/device.hpp | 14 +++---- host/include/uhd/usrp/usrp1e.hpp | 5 +-- host/include/uhd/usrp/usrp2.hpp | 5 +-- host/lib/device.cpp | 8 ++-- host/lib/usrp/usrp1e/usrp1e_none.cpp | 2 +- host/lib/usrp/usrp2/usrp2_impl.cpp | 7 ++-- host/utils/CMakeLists.txt | 6 +-- host/utils/discover_usrps.cpp | 71 ------------------------------------ host/utils/uhd_find_devices.cpp | 71 ++++++++++++++++++++++++++++++++++++ 9 files changed, 93 insertions(+), 96 deletions(-) delete mode 100644 host/utils/discover_usrps.cpp create mode 100644 host/utils/uhd_find_devices.cpp diff --git a/host/include/uhd/device.hpp b/host/include/uhd/device.hpp index 1d0360799..4d4196d98 100644 --- a/host/include/uhd/device.hpp +++ b/host/include/uhd/device.hpp @@ -38,22 +38,22 @@ class UHD_API device : boost::noncopyable, public wax::obj{ public: typedef boost::shared_ptr sptr; - typedef boost::function discover_t; + typedef boost::function find_t; typedef boost::function make_t; /*! * Register a device into the discovery and factory system. * - * \param discover a function that discovers devices + * \param find a function that discovers devices * \param make a factory function that makes a device */ static void register_device( - const discover_t &discover, + const find_t &find, const make_t &make ); /*! - * \brief Discover usrp devices attached to the host. + * \brief Find usrp devices attached to the host. * * The hint device address should be used to narrow down the search * to particular transport types and/or transport arguments. @@ -61,17 +61,17 @@ public: * \param hint a partially (or fully) filled in device address * \return a vector of device addresses for all usrps on the system */ - static device_addrs_t discover(const device_addr_t &hint); + static device_addrs_t find(const device_addr_t &hint); /*! * \brief Create a new usrp device from the device address hint. * - * The make routine will call discover and pick one of the results. + * The make routine will call find and pick one of the results. * By default, the first result will be used to create a new device. * Use the which parameter as an index into the list of results. * * \param hint a partially (or fully) filled in device address - * \param which which address to use when multiple are discovered + * \param which which address to use when multiple are found * \return a shared pointer to a new device instance */ static sptr make(const device_addr_t &hint, size_t which = 0); diff --git a/host/include/uhd/usrp/usrp1e.hpp b/host/include/uhd/usrp/usrp1e.hpp index 5cba4ef52..cee9dc3d5 100644 --- a/host/include/uhd/usrp/usrp1e.hpp +++ b/host/include/uhd/usrp/usrp1e.hpp @@ -29,12 +29,11 @@ namespace uhd{ namespace usrp{ class UHD_API usrp1e : public device{ public: /*! - * Discover usrp1e devices on the system via the device node. - * This static method will be called by the device::discover. + * Find usrp1e devices on the system via the device node. * \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); + static device_addrs_t find(const device_addr_t &hint); /*! * Make a usrp1e from a device address. diff --git a/host/include/uhd/usrp/usrp2.hpp b/host/include/uhd/usrp/usrp2.hpp index 277ddc131..613b40ae3 100644 --- a/host/include/uhd/usrp/usrp2.hpp +++ b/host/include/uhd/usrp/usrp2.hpp @@ -29,17 +29,16 @@ namespace uhd{ namespace usrp{ class UHD_API usrp2 : public device{ public: /*! - * Discover usrp2 devices over the ethernet. + * Find usrp2 devices over the ethernet. * * Recommended key/value pairs for the device hint address: * hint["addr"] = address, where address is a resolvable address * or ip address, which may or may not be a broadcast address. * - * This static method will be called by the device::discover. * \param hint a device addr with the usrp2 address filled in * \return a vector of device addresses for all usrp2s found */ - static device_addrs_t discover(const device_addr_t &hint); + static device_addrs_t find(const device_addr_t &hint); /*! * Make a usrp2 from a device address. diff --git a/host/lib/device.cpp b/host/lib/device.cpp index ca45d0795..27a365d34 100644 --- a/host/lib/device.cpp +++ b/host/lib/device.cpp @@ -57,23 +57,23 @@ static size_t hash_device_addr( /*********************************************************************** * Registration **********************************************************************/ -typedef boost::tuple dev_fcn_reg_t; +typedef boost::tuple dev_fcn_reg_t; // instantiate the device function registry container UHD_SINGLETON_FCN(std::vector, get_dev_fcn_regs) void device::register_device( - const discover_t &discover, + const find_t &find, const make_t &make ){ //std::cout << "registering device" << std::endl; - get_dev_fcn_regs().push_back(dev_fcn_reg_t(discover, make)); + get_dev_fcn_regs().push_back(dev_fcn_reg_t(find, make)); } /*********************************************************************** * Discover **********************************************************************/ -device_addrs_t device::discover(const device_addr_t &hint){ +device_addrs_t device::find(const device_addr_t &hint){ device_addrs_t device_addrs; BOOST_FOREACH(const dev_fcn_reg_t &fcn, get_dev_fcn_regs()){ diff --git a/host/lib/usrp/usrp1e/usrp1e_none.cpp b/host/lib/usrp/usrp1e/usrp1e_none.cpp index 1c8cf9a5b..84fb9276c 100644 --- a/host/lib/usrp/usrp1e/usrp1e_none.cpp +++ b/host/lib/usrp/usrp1e/usrp1e_none.cpp @@ -25,7 +25,7 @@ using namespace uhd::usrp; * when the required kernel module headers are not present. */ -device_addrs_t usrp1e::discover(const device_addr_t &){ +device_addrs_t usrp1e::find(const device_addr_t &){ return device_addrs_t(); //return empty list } diff --git a/host/lib/usrp/usrp2/usrp2_impl.cpp b/host/lib/usrp/usrp2/usrp2_impl.cpp index 9dce351be..b0ee395fb 100644 --- a/host/lib/usrp/usrp2/usrp2_impl.cpp +++ b/host/lib/usrp/usrp2/usrp2_impl.cpp @@ -30,13 +30,13 @@ using namespace uhd::transport; namespace asio = boost::asio; UHD_STATIC_BLOCK(register_usrp2_device){ - device::register_device(&usrp2::discover, &usrp2::make); + device::register_device(&usrp2::find, &usrp2::make); } /*********************************************************************** * Discovery over the udp transport **********************************************************************/ -uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ +uhd::device_addrs_t usrp2::find(const device_addr_t &hint){ device_addrs_t usrp2_addrs; //if no address was specified, send a broadcast on each interface @@ -50,7 +50,7 @@ uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ new_hint["addr"] = if_addrs.bcast; //call discover with the new hint and append results - device_addrs_t new_usrp2_addrs = usrp2::discover(new_hint); + device_addrs_t new_usrp2_addrs = usrp2::find(new_hint); usrp2_addrs.insert(usrp2_addrs.begin(), new_usrp2_addrs.begin(), new_usrp2_addrs.end() ); @@ -83,7 +83,6 @@ uhd::device_addrs_t usrp2::discover(const device_addr_t &hint){ 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["transport"] = "udp"; new_addr["addr"] = ip_addr.to_string(); usrp2_addrs.push_back(new_addr); //dont break here, it will exit the while loop diff --git a/host/utils/CMakeLists.txt b/host/utils/CMakeLists.txt index 1fb132937..aa01d1e35 100644 --- a/host/utils/CMakeLists.txt +++ b/host/utils/CMakeLists.txt @@ -15,9 +15,9 @@ # along with this program. If not, see . # -ADD_EXECUTABLE(discover_usrps discover_usrps.cpp) -TARGET_LINK_LIBRARIES(discover_usrps uhd) -INSTALL(TARGETS discover_usrps RUNTIME DESTINATION ${RUNTIME_DIR}) +ADD_EXECUTABLE(uhd_find_devices uhd_find_devices.cpp) +TARGET_LINK_LIBRARIES(uhd_find_devices uhd) +INSTALL(TARGETS uhd_find_devices RUNTIME DESTINATION ${RUNTIME_DIR}) ADD_EXECUTABLE(usrp2_burner usrp2_burner.cpp) TARGET_LINK_LIBRARIES(usrp2_burner uhd) diff --git a/host/utils/discover_usrps.cpp b/host/utils/discover_usrps.cpp deleted file mode 100644 index 72c5b8822..000000000 --- a/host/utils/discover_usrps.cpp +++ /dev/null @@ -1,71 +0,0 @@ -// -// 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 . -// - -#include -#include -#include -#include -#include -#include - -namespace po = boost::program_options; - -int UHD_SAFE_MAIN(int argc, char *argv[]){ - po::options_description desc("Allowed options"); - desc.add_options() - ("help", "help message") - ("addr", po::value(), "resolvable network address") - ("node", po::value(), "path to linux device node") - ; - - po::variables_map vm; - po::store(po::parse_command_line(argc, argv, desc), vm); - po::notify(vm); - - //print the help message - if (vm.count("help")){ - std::cout << boost::format("Discover USRPs %s") % desc << std::endl; - return ~0; - } - - //load the options into the address - uhd::device_addr_t device_addr; - if (vm.count("addr")){ - device_addr["addr"] = vm["addr"].as(); - } - if (vm.count("node")){ - device_addr["node"] = vm["node"].as(); - } - - //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; - } - - for (size_t i = 0; i < device_addrs.size(); i++){ - std::cout << "--------------------------------------------------" << std::endl; - std::cout << "-- USRP Device " << i << std::endl; - std::cout << "--------------------------------------------------" << std::endl; - std::cout << device_addrs[i].to_string() << std::endl << std::endl; - uhd::device::make(device_addrs[i]); //test make - } - - return 0; -} diff --git a/host/utils/uhd_find_devices.cpp b/host/utils/uhd_find_devices.cpp new file mode 100644 index 000000000..b328216d0 --- /dev/null +++ b/host/utils/uhd_find_devices.cpp @@ -0,0 +1,71 @@ +// +// 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 . +// + +#include +#include +#include +#include +#include +#include + +namespace po = boost::program_options; + +int UHD_SAFE_MAIN(int argc, char *argv[]){ + po::options_description desc("Allowed options"); + desc.add_options() + ("help", "help message") + ("addr", po::value(), "resolvable network address") + ("node", po::value(), "path to linux device node") + ; + + po::variables_map vm; + po::store(po::parse_command_line(argc, argv, desc), vm); + po::notify(vm); + + //print the help message + if (vm.count("help")){ + std::cout << boost::format("UHD Find Devices %s") % desc << std::endl; + return ~0; + } + + //load the options into the address + uhd::device_addr_t device_addr; + if (vm.count("addr")){ + device_addr["addr"] = vm["addr"].as(); + } + if (vm.count("node")){ + device_addr["node"] = vm["node"].as(); + } + + //discover the usrps and print the results + uhd::device_addrs_t device_addrs = uhd::device::find(device_addr); + + if (device_addrs.size() == 0){ + std::cerr << "No UHD Devices Found" << std::endl; + return ~0; + } + + for (size_t i = 0; i < device_addrs.size(); i++){ + std::cout << "--------------------------------------------------" << std::endl; + std::cout << "-- UHD Device " << i << std::endl; + std::cout << "--------------------------------------------------" << std::endl; + std::cout << device_addrs[i].to_string() << std::endl << std::endl; + uhd::device::make(device_addrs[i]); //test make + } + + return 0; +} -- cgit v1.2.3