2010-01-30 03:22:40 +00:00
|
|
|
//
|
|
|
|
|
// Copyright 2010 Ettus Research LLC
|
2018-02-19 23:30:32 +00:00
|
|
|
// Copyright 2018 Ettus Research, a National Instruments Company
|
2010-01-30 03:22:40 +00:00
|
|
|
//
|
2018-02-19 23:30:32 +00:00
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
2010-01-30 03:22:40 +00:00
|
|
|
//
|
|
|
|
|
|
2010-02-26 20:01:03 +00:00
|
|
|
#include <uhd/device.hpp>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <uhd/utils/safe_main.hpp>
|
2010-01-30 03:22:40 +00:00
|
|
|
#include <boost/format.hpp>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <boost/program_options.hpp>
|
2012-10-18 22:33:07 +00:00
|
|
|
#include <cstdlib>
|
2019-01-14 18:35:25 +00:00
|
|
|
#include <iostream>
|
2018-01-24 02:12:55 +00:00
|
|
|
|
|
|
|
|
namespace {
|
2019-01-14 18:35:25 +00:00
|
|
|
//! Conditionally append find_all=1 if the key isn't there yet
|
|
|
|
|
uhd::device_addr_t append_findall(const uhd::device_addr_t& device_args)
|
|
|
|
|
{
|
|
|
|
|
uhd::device_addr_t new_device_args(device_args);
|
|
|
|
|
if (!new_device_args.has_key("find_all")) {
|
|
|
|
|
new_device_args["find_all"] = "1";
|
2018-01-24 02:12:55 +00:00
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
|
|
|
|
|
return new_device_args;
|
2018-01-24 02:12:55 +00:00
|
|
|
}
|
2019-01-14 18:35:25 +00:00
|
|
|
} // namespace
|
2018-01-24 02:12:55 +00:00
|
|
|
|
2010-01-30 03:22:40 +00:00
|
|
|
namespace po = boost::program_options;
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
int UHD_SAFE_MAIN(int argc, char* argv[])
|
|
|
|
|
{
|
2010-01-30 03:22:40 +00:00
|
|
|
po::options_description desc("Allowed options");
|
2019-01-10 23:19:48 +00:00
|
|
|
// clang-format off
|
2010-01-30 03:22:40 +00:00
|
|
|
desc.add_options()
|
|
|
|
|
("help", "help message")
|
2010-04-20 19:05:33 +00:00
|
|
|
("args", po::value<std::string>()->default_value(""), "device address args")
|
2010-01-30 03:22:40 +00:00
|
|
|
;
|
2019-01-10 23:19:48 +00:00
|
|
|
// clang-format on
|
2010-01-30 03:22:40 +00:00
|
|
|
|
|
|
|
|
po::variables_map vm;
|
|
|
|
|
po::store(po::parse_command_line(argc, argv, desc), vm);
|
2010-03-30 22:11:23 +00:00
|
|
|
po::notify(vm);
|
2010-01-30 03:22:40 +00:00
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// print the help message
|
|
|
|
|
if (vm.count("help")) {
|
2010-03-30 22:11:23 +00:00
|
|
|
std::cout << boost::format("UHD Find Devices %s") % desc << std::endl;
|
2018-01-24 02:12:55 +00:00
|
|
|
return EXIT_SUCCESS;
|
2010-01-30 03:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
// discover the usrps and print the results
|
2018-01-24 02:12:55 +00:00
|
|
|
const uhd::device_addr_t args(vm["args"].as<std::string>());
|
2019-01-14 18:35:25 +00:00
|
|
|
uhd::device_addrs_t device_addrs = uhd::device::find(append_findall(args));
|
2018-01-24 02:12:55 +00:00
|
|
|
if (device_addrs.empty()) {
|
2010-03-30 22:11:23 +00:00
|
|
|
std::cerr << "No UHD Devices Found" << std::endl;
|
2012-10-18 22:33:07 +00:00
|
|
|
return EXIT_FAILURE;
|
2010-01-30 03:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2019-01-14 18:35:25 +00:00
|
|
|
typedef std::map<std::string, std::set<std::string>> device_multi_addrs_t;
|
2016-11-23 00:19:38 +00:00
|
|
|
typedef std::map<std::string, device_multi_addrs_t> device_addrs_filtered_t;
|
|
|
|
|
device_addrs_filtered_t found_devices;
|
|
|
|
|
for (auto it = device_addrs.begin(); it != device_addrs.end(); ++it) {
|
2019-01-14 18:35:25 +00:00
|
|
|
std::string serial = (*it)["serial"];
|
2016-11-23 00:19:38 +00:00
|
|
|
found_devices[serial] = device_multi_addrs_t();
|
2019-01-14 18:35:25 +00:00
|
|
|
for (std::string key : it->keys()) {
|
2016-11-23 00:19:38 +00:00
|
|
|
if (key != "serial") {
|
|
|
|
|
found_devices[serial][key].insert(it->get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
for (auto sit = it + 1; sit != device_addrs.end();) {
|
|
|
|
|
if ((*sit)["serial"] == serial) {
|
2019-01-14 18:35:25 +00:00
|
|
|
for (std::string key : sit->keys()) {
|
2016-11-23 00:19:38 +00:00
|
|
|
if (key != "serial") {
|
|
|
|
|
found_devices[serial][key].insert(sit->get(key));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
sit = device_addrs.erase(sit);
|
|
|
|
|
} else {
|
|
|
|
|
sit++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int i = 0;
|
|
|
|
|
for (auto dit = found_devices.begin(); dit != found_devices.end(); ++dit) {
|
2019-01-14 18:35:25 +00:00
|
|
|
std::cout << "--------------------------------------------------" << std::endl;
|
2010-03-30 22:11:23 +00:00
|
|
|
std::cout << "-- UHD Device " << i << std::endl;
|
2019-01-14 18:35:25 +00:00
|
|
|
std::cout << "--------------------------------------------------" << std::endl;
|
2016-11-23 00:19:38 +00:00
|
|
|
std::stringstream ss;
|
|
|
|
|
ss << "Device Address:" << std::endl;
|
|
|
|
|
ss << boost::format(" serial: %s") % dit->first << std::endl;
|
|
|
|
|
for (auto mit = dit->second.begin(); mit != dit->second.end(); ++mit) {
|
2019-01-14 18:35:25 +00:00
|
|
|
for (auto vit = mit->second.begin(); vit != mit->second.end(); ++vit) {
|
|
|
|
|
ss << boost::format(" %s: %s") % mit->first % *vit << std::endl;
|
2016-11-23 00:19:38 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::cout << ss.str() << std::endl << std::endl;
|
|
|
|
|
i++;
|
2010-01-30 03:22:40 +00:00
|
|
|
}
|
|
|
|
|
|
2012-10-18 22:33:07 +00:00
|
|
|
return EXIT_SUCCESS;
|
2010-01-30 03:22:40 +00:00
|
|
|
}
|