root / host / utils / uhd_usrp_probe.cpp @ 4bcab9c5
History | View | Annotate | Download (9.41 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2010-2011 Ettus Research LLC
|
| 3 |
//
|
| 4 |
// This program is free software: you can redistribute it and/or modify
|
| 5 |
// it under the terms of the GNU General Public License as published by
|
| 6 |
// the Free Software Foundation, either version 3 of the License, or
|
| 7 |
// (at your option) any later version.
|
| 8 |
//
|
| 9 |
// This program is distributed in the hope that it will be useful,
|
| 10 |
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 11 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 12 |
// GNU General Public License for more details.
|
| 13 |
//
|
| 14 |
// You should have received a copy of the GNU General Public License
|
| 15 |
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 16 |
//
|
| 17 |
|
| 18 |
#include <uhd/utils/safe_main.hpp> |
| 19 |
#include <uhd/device.hpp> |
| 20 |
#include <uhd/types/ranges.hpp> |
| 21 |
#include <uhd/property_tree.hpp> |
| 22 |
#include <boost/algorithm/string.hpp> //for split |
| 23 |
#include <uhd/usrp/dboard_id.hpp> |
| 24 |
#include <uhd/usrp/mboard_eeprom.hpp> |
| 25 |
#include <uhd/usrp/dboard_eeprom.hpp> |
| 26 |
#include <boost/program_options.hpp> |
| 27 |
#include <boost/format.hpp> |
| 28 |
#include <boost/foreach.hpp> |
| 29 |
#include <iostream> |
| 30 |
#include <sstream> |
| 31 |
#include <vector> |
| 32 |
|
| 33 |
namespace po = boost::program_options;
|
| 34 |
using namespace uhd; |
| 35 |
|
| 36 |
static std::string indent(size_t level){ |
| 37 |
return (level)? (indent(level-1) + " ") : ""; |
| 38 |
} |
| 39 |
|
| 40 |
static std::string make_border(const std::string &text){ |
| 41 |
std::stringstream ss; |
| 42 |
ss << boost::format(" _____________________________________________________") << std::endl;
|
| 43 |
ss << boost::format(" /") << std::endl;
|
| 44 |
std::vector<std::string> lines; boost::split(lines, text, boost::is_any_of("\n")); |
| 45 |
while (lines.back().empty()) lines.pop_back(); //strip trailing newlines |
| 46 |
if (lines.size()) lines[0] = " " + lines[0]; //indent the title line |
| 47 |
BOOST_FOREACH(const std::string &line, lines){ |
| 48 |
ss << boost::format("| %s") % line << std::endl;
|
| 49 |
} |
| 50 |
//ss << boost::format(" \\_____________________________________________________") << std::endl;
|
| 51 |
return ss.str();
|
| 52 |
} |
| 53 |
|
| 54 |
static std::string get_dsp_pp_string(const std::string &type, property_tree::sptr tree, const property_tree::path_type &path){ |
| 55 |
std::stringstream ss; |
| 56 |
ss << boost::format("%s DSP: %s") % type % path.leaf() << std::endl;
|
| 57 |
//ss << std::endl;
|
| 58 |
meta_range_t freq_range = tree->access<meta_range_t>(path / "freq/range").get();
|
| 59 |
ss << boost::format("Freq range: %.3f to %.3f Mhz") % (freq_range.start()/1e6) % (freq_range.stop()/1e6) << std::endl;; |
| 60 |
return ss.str();
|
| 61 |
} |
| 62 |
|
| 63 |
static std::string prop_names_to_pp_string(const std::vector<std::string> &prop_names){ |
| 64 |
std::stringstream ss; size_t count = 0;
|
| 65 |
BOOST_FOREACH(const std::string &prop_name, prop_names){ |
| 66 |
ss << ((count++)? ", " : "") << prop_name; |
| 67 |
} |
| 68 |
return ss.str();
|
| 69 |
} |
| 70 |
|
| 71 |
static std::string get_subdev_pp_string(const std::string &type, property_tree::sptr tree, const property_tree::path_type &path){ |
| 72 |
std::stringstream ss; |
| 73 |
ss << boost::format("%s Subdev: %s") % type % path.leaf() << std::endl;
|
| 74 |
//ss << std::endl;
|
| 75 |
|
| 76 |
ss << boost::format("Name: %s") % (tree->access<std::string>(path / "name").get()) << std::endl; |
| 77 |
ss << boost::format("Antennas: %s") % prop_names_to_pp_string(tree->access<std::vector<std::string> >(path / "antenna/options").get()) << std::endl; |
| 78 |
ss << boost::format("Sensors: %s") % prop_names_to_pp_string(tree->list(path / "sensors")) << std::endl; |
| 79 |
|
| 80 |
meta_range_t freq_range = tree->access<meta_range_t>(path / "freq/range").get();
|
| 81 |
ss << boost::format("Freq range: %.3f to %.3f Mhz") % (freq_range.start()/1e6) % (freq_range.stop()/1e6) << std::endl; |
| 82 |
|
| 83 |
std::vector<std::string> gain_names = tree->list(path / "gains"); |
| 84 |
if (gain_names.size() == 0) ss << "Gain Elements: None" << std::endl; |
| 85 |
BOOST_FOREACH(const std::string &name, gain_names){ |
| 86 |
meta_range_t gain_range = tree->access<meta_range_t>(path / "gains" / name / "range").get(); |
| 87 |
ss << boost::format("Gain range %s: %.1f to %.1f step %.1f dB") % name % gain_range.start() % gain_range.stop() % gain_range.step() << std::endl;
|
| 88 |
} |
| 89 |
|
| 90 |
ss << boost::format("Connection Type: %s") % (tree->access<std::string>(path / "connection").get()) << std::endl; |
| 91 |
ss << boost::format("Uses LO offset: %s") % ((tree->access<bool>(path / "use_lo_offset").get())? "Yes" : "No") << std::endl; |
| 92 |
|
| 93 |
return ss.str();
|
| 94 |
} |
| 95 |
|
| 96 |
static std::string get_codec_pp_string(const std::string &type, property_tree::sptr tree, const property_tree::path_type &path){ |
| 97 |
std::stringstream ss; |
| 98 |
ss << boost::format("%s Codec: %s") % type % path.leaf() << std::endl;
|
| 99 |
//ss << std::endl;
|
| 100 |
|
| 101 |
ss << boost::format("Name: %s") % (tree->access<std::string>(path / "name").get()) << std::endl; |
| 102 |
std::vector<std::string> gain_names = tree->list(path / "gains"); |
| 103 |
if (gain_names.size() == 0) ss << "Gain Elements: None" << std::endl; |
| 104 |
BOOST_FOREACH(const std::string &name, gain_names){ |
| 105 |
meta_range_t gain_range = tree->access<meta_range_t>(path / "gains" / name / "range").get(); |
| 106 |
ss << boost::format("Gain range %s: %.1f to %.1f step %.1f dB") % name % gain_range.start() % gain_range.stop() % gain_range.step() << std::endl;
|
| 107 |
} |
| 108 |
return ss.str();
|
| 109 |
} |
| 110 |
|
| 111 |
static std::string get_dboard_pp_string(const std::string &type, property_tree::sptr tree, const property_tree::path_type &path){ |
| 112 |
std::stringstream ss; |
| 113 |
ss << boost::format("%s Dboard: %s") % type % path.leaf() << std::endl;
|
| 114 |
//ss << std::endl;
|
| 115 |
const std::string prefix = (type == "RX")? "rx" : "tx"; |
| 116 |
usrp::dboard_eeprom_t db_eeprom = tree->access<usrp::dboard_eeprom_t>(path / (prefix + "_eeprom")).get();
|
| 117 |
if (db_eeprom.id != usrp::dboard_id_t::none()) ss << boost::format("ID: %s") % db_eeprom.id.to_pp_string() << std::endl; |
| 118 |
if (not db_eeprom.serial.empty()) ss << boost::format("Serial: %s") % db_eeprom.serial << std::endl; |
| 119 |
if (type == "TX"){ |
| 120 |
usrp::dboard_eeprom_t gdb_eeprom = tree->access<usrp::dboard_eeprom_t>(path / "gdb_eeprom").get();
|
| 121 |
if (gdb_eeprom.id != usrp::dboard_id_t::none()) ss << boost::format("ID: %s") % gdb_eeprom.id.to_pp_string() << std::endl; |
| 122 |
if (not gdb_eeprom.serial.empty()) ss << boost::format("Serial: %s") % gdb_eeprom.serial << std::endl; |
| 123 |
} |
| 124 |
BOOST_FOREACH(const std::string &name, tree->list(path / (prefix + "_frontends"))){ |
| 125 |
ss << make_border(get_subdev_pp_string(type, tree, path / (prefix + "_frontends") / name));
|
| 126 |
} |
| 127 |
ss << make_border(get_codec_pp_string(type, tree, path.branch_path().branch_path() / (prefix + "_codecs") / path.leaf()));
|
| 128 |
return ss.str();
|
| 129 |
} |
| 130 |
|
| 131 |
static std::string get_mboard_pp_string(property_tree::sptr tree, const property_tree::path_type &path){ |
| 132 |
std::stringstream ss; |
| 133 |
ss << boost::format("Mboard: %s") % (tree->access<std::string>(path / "name").get()) << std::endl; |
| 134 |
//ss << std::endl;
|
| 135 |
usrp::mboard_eeprom_t mb_eeprom = tree->access<usrp::mboard_eeprom_t>(path / "eeprom").get();
|
| 136 |
BOOST_FOREACH(const std::string &key, mb_eeprom.keys()){ |
| 137 |
if (not mb_eeprom[key].empty()) ss << boost::format("%s: %s") % key % mb_eeprom[key] << std::endl; |
| 138 |
} |
| 139 |
ss << std::endl; |
| 140 |
ss << "Time sources: " << prop_names_to_pp_string(tree->access<std::vector<std::string> >(path / "time_source" / "options").get()) << std::endl; |
| 141 |
ss << "Clock sources: " << prop_names_to_pp_string(tree->access<std::vector<std::string> >(path / "clock_source" / "options").get()) << std::endl; |
| 142 |
ss << "Sensors: " << prop_names_to_pp_string(tree->list(path / "sensors")) << std::endl; |
| 143 |
BOOST_FOREACH(const std::string &name, tree->list(path / "rx_dsps")){ |
| 144 |
ss << make_border(get_dsp_pp_string("RX", tree, path / "rx_dsps" / name)); |
| 145 |
} |
| 146 |
BOOST_FOREACH(const std::string &name, tree->list(path / "dboards")){ |
| 147 |
ss << make_border(get_dboard_pp_string("RX", tree, path / "dboards" / name)); |
| 148 |
} |
| 149 |
BOOST_FOREACH(const std::string &name, tree->list(path / "tx_dsps")){ |
| 150 |
ss << make_border(get_dsp_pp_string("TX", tree, path / "tx_dsps" / name)); |
| 151 |
} |
| 152 |
BOOST_FOREACH(const std::string &name, tree->list(path / "dboards")){ |
| 153 |
ss << make_border(get_dboard_pp_string("TX", tree, path / "dboards" / name)); |
| 154 |
} |
| 155 |
return ss.str();
|
| 156 |
} |
| 157 |
|
| 158 |
|
| 159 |
static std::string get_device_pp_string(property_tree::sptr tree){ |
| 160 |
std::stringstream ss; |
| 161 |
ss << boost::format("Device: %s") % (tree->access<std::string>("/name").get()) << std::endl; |
| 162 |
//ss << std::endl;
|
| 163 |
BOOST_FOREACH(const std::string &name, tree->list("/mboards")){ |
| 164 |
ss << make_border(get_mboard_pp_string(tree, "/mboards/" + name));
|
| 165 |
} |
| 166 |
return ss.str();
|
| 167 |
} |
| 168 |
|
| 169 |
void print_tree(const uhd::property_tree::path_type &path, uhd::property_tree::sptr tree){ |
| 170 |
std::cout << path << std::endl; |
| 171 |
BOOST_FOREACH(const std::string &name, tree->list(path)){ |
| 172 |
print_tree(path / name, tree); |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
int UHD_SAFE_MAIN(int argc, char *argv[]){ |
| 177 |
po::options_description desc("Allowed options");
|
| 178 |
desc.add_options() |
| 179 |
("help", "help message") |
| 180 |
("args", po::value<std::string>()->default_value(""), "device address args") |
| 181 |
("tree", "specify to print a complete property tree") |
| 182 |
; |
| 183 |
|
| 184 |
po::variables_map vm; |
| 185 |
po::store(po::parse_command_line(argc, argv, desc), vm); |
| 186 |
po::notify(vm); |
| 187 |
|
| 188 |
//print the help message
|
| 189 |
if (vm.count("help")){ |
| 190 |
std::cout << boost::format("UHD USRP Probe %s") % desc << std::endl;
|
| 191 |
return ~0; |
| 192 |
} |
| 193 |
|
| 194 |
device::sptr dev = device::make(vm["args"].as<std::string>()); |
| 195 |
property_tree::sptr tree = (*dev)[0].as<property_tree::sptr>();
|
| 196 |
|
| 197 |
if (vm.count("tree") != 0) print_tree("/", tree); |
| 198 |
else std::cout << make_border(get_device_pp_string(tree)) << std::endl;
|
| 199 |
|
| 200 |
return 0; |
| 201 |
} |