root / host / examples / test_dboard_coercion.cpp @ a80b7155
History | View | Annotate | Download (24.4 KB)
| 1 |
//
|
|---|---|
| 2 |
// Copyright 2012 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/thread_priority.hpp> |
| 19 |
#include <uhd/utils/safe_main.hpp> |
| 20 |
#include <uhd/usrp/multi_usrp.hpp> |
| 21 |
#include <boost/program_options.hpp> |
| 22 |
#include <boost/format.hpp> |
| 23 |
#include <boost/thread/thread.hpp> |
| 24 |
#include <boost/math/special_functions/round.hpp> |
| 25 |
#include <iostream> |
| 26 |
#include <complex> |
| 27 |
#include <vector> |
| 28 |
|
| 29 |
namespace po = boost::program_options;
|
| 30 |
|
| 31 |
/************************************************************************
|
| 32 |
* Misc functions
|
| 33 |
************************************************************************/
|
| 34 |
|
| 35 |
std::string return_MHz_string(double freq){ |
| 36 |
std::string nice_string = std::string(str(boost::format("%5.2f MHz") % (freq / 1e6))); |
| 37 |
return nice_string;
|
| 38 |
} |
| 39 |
|
| 40 |
std::string return_USRP_config_string(uhd::usrp::multi_usrp::sptr usrp, bool test_tx, bool test_rx){ |
| 41 |
uhd::dict<std::string, std::string> tx_info = usrp->get_usrp_tx_info(); |
| 42 |
uhd::dict<std::string, std::string> rx_info = usrp->get_usrp_rx_info(); |
| 43 |
std::string info_string;
|
| 44 |
std::string mboard_id, mboard_serial;
|
| 45 |
std::string tx_serial, tx_subdev_name, tx_subdev_spec;
|
| 46 |
std::string rx_serial, rx_subdev_name, rx_subdev_spec;
|
| 47 |
|
| 48 |
mboard_id = tx_info.get("mboard_id");
|
| 49 |
if(tx_info.get("mboard_serial") != "") mboard_serial = tx_info.get("mboard_serial"); |
| 50 |
else mboard_serial = "no serial"; |
| 51 |
|
| 52 |
info_string = std::string(str(boost::format("Motherboard: %s (%s)\n") % mboard_id % mboard_serial)); |
| 53 |
|
| 54 |
if(test_tx){
|
| 55 |
if(tx_info.get("tx_serial") != "") tx_serial = tx_info.get("tx_serial"); |
| 56 |
else tx_serial = "no serial"; |
| 57 |
tx_subdev_name = tx_info.get("tx_subdev_name");
|
| 58 |
tx_subdev_spec = tx_info.get("tx_subdev_spec");
|
| 59 |
|
| 60 |
info_string += std::string(str(boost::format("TX: %s (%s, %s)") % tx_subdev_name % tx_serial % tx_subdev_spec)); |
| 61 |
} |
| 62 |
if(test_tx and test_rx) info_string += "\n"; |
| 63 |
if(test_rx){
|
| 64 |
if(rx_info.get("rx_serial") != "") rx_serial = rx_info.get("rx_serial"); |
| 65 |
else rx_serial = "no serial"; |
| 66 |
rx_subdev_name = rx_info.get("rx_subdev_name");
|
| 67 |
rx_subdev_spec = rx_info.get("rx_subdev_spec");
|
| 68 |
|
| 69 |
info_string += std::string(str(boost::format("RX: %s (%s, %s)") % rx_subdev_name % rx_serial % rx_subdev_spec)); |
| 70 |
} |
| 71 |
|
| 72 |
return info_string;
|
| 73 |
} |
| 74 |
|
| 75 |
/************************************************************************
|
| 76 |
* TX Frequency/Gain Coercion
|
| 77 |
************************************************************************/
|
| 78 |
|
| 79 |
std::string tx_test(uhd::usrp::multi_usrp::sptr usrp, bool test_gain, bool verbose){ |
| 80 |
|
| 81 |
//Establish frequency range
|
| 82 |
|
| 83 |
std::vector<double> freqs;
|
| 84 |
std::vector<double> xcvr_freqs;
|
| 85 |
|
| 86 |
BOOST_FOREACH(const uhd::range_t &range, usrp->get_fe_tx_freq_range()){
|
| 87 |
double freq_begin = range.start();
|
| 88 |
double freq_end = range.stop();
|
| 89 |
double freq_step;
|
| 90 |
|
| 91 |
if(usrp->get_usrp_tx_info().get("tx_subdev_name") == "XCVR2450 TX"){ |
| 92 |
xcvr_freqs.push_back(freq_begin); |
| 93 |
xcvr_freqs.push_back(freq_end); |
| 94 |
} |
| 95 |
|
| 96 |
if(freq_end - freq_begin > 1000e6) freq_step = 100e6; |
| 97 |
else if(freq_end - freq_begin < 300e6) freq_step = 10e6; |
| 98 |
else freq_step = 50e6; |
| 99 |
|
| 100 |
double current_freq = freq_begin;
|
| 101 |
|
| 102 |
while(current_freq < freq_end){
|
| 103 |
freqs.push_back(current_freq); |
| 104 |
current_freq += freq_step; |
| 105 |
} |
| 106 |
if(freq_end != *freqs.end()) freqs.push_back(freq_end);
|
| 107 |
} |
| 108 |
|
| 109 |
std::vector<double> gains;
|
| 110 |
|
| 111 |
if(test_gain){
|
| 112 |
|
| 113 |
//Establish gain range
|
| 114 |
|
| 115 |
double gain_begin = usrp->get_tx_gain_range().start();
|
| 116 |
if(gain_begin < 0.0) gain_begin = 0.0; |
| 117 |
double gain_end = usrp->get_tx_gain_range().stop();
|
| 118 |
|
| 119 |
double current_gain = gain_begin;
|
| 120 |
while(current_gain < gain_end){
|
| 121 |
gains.push_back(current_gain); |
| 122 |
current_gain++; |
| 123 |
} |
| 124 |
if(gain_end != *gains.end()) gains.push_back(gain_end);
|
| 125 |
|
| 126 |
} |
| 127 |
|
| 128 |
//Establish error-storing variables
|
| 129 |
|
| 130 |
std::vector<double> bad_tune_freqs;
|
| 131 |
std::vector<double> no_lock_freqs;
|
| 132 |
std::vector< std::vector< double > > bad_gain_vals;
|
| 133 |
std::vector<std::string> dboard_sensor_names = usrp->get_tx_sensor_names();
|
| 134 |
std::vector<std::string> mboard_sensor_names = usrp->get_mboard_sensor_names();
|
| 135 |
bool has_sensor = (std::find(dboard_sensor_names.begin(), dboard_sensor_names.end(), "lo_locked")) != dboard_sensor_names.end(); |
| 136 |
|
| 137 |
for(std::vector<double>::iterator f = freqs.begin(); f != freqs.end(); ++f){ |
| 138 |
|
| 139 |
//Testing for successful frequency tune
|
| 140 |
|
| 141 |
usrp->set_tx_freq(*f); |
| 142 |
boost::this_thread::sleep(boost::posix_time::microseconds(long(1000))); |
| 143 |
|
| 144 |
double actual_freq = usrp->get_tx_freq();
|
| 145 |
|
| 146 |
if(*f == 0.0){ |
| 147 |
if(floor(actual_freq + 0.5) == 0.0){ |
| 148 |
if(verbose) std::cout << boost::format("\nTX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl; |
| 149 |
} |
| 150 |
else{
|
| 151 |
if(verbose) std::cout << boost::format("\nTX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl; |
| 152 |
} |
| 153 |
} |
| 154 |
else{
|
| 155 |
if((*f / actual_freq > 0.9999) and (*f / actual_freq < 1.0001)){ |
| 156 |
if(verbose) std::cout << boost::format("\nTX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl; |
| 157 |
} |
| 158 |
else{
|
| 159 |
if(verbose) std::cout << boost::format("\nTX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl; |
| 160 |
bad_tune_freqs.push_back(*f); |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
//Testing for successful lock
|
| 165 |
|
| 166 |
if(has_sensor){
|
| 167 |
bool is_locked = false; |
| 168 |
for(int i = 0; i < 1000; i++){ |
| 169 |
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
|
| 170 |
if(usrp->get_tx_sensor("lo_locked",0).to_bool()){ |
| 171 |
is_locked = true;
|
| 172 |
break;
|
| 173 |
} |
| 174 |
} |
| 175 |
if(is_locked){
|
| 176 |
if(verbose) std::cout << boost::format("LO successfully locked at TX frequency %s.") % return_MHz_string(*f) << std::endl; |
| 177 |
} |
| 178 |
else{
|
| 179 |
if(verbose) std::cout << boost::format("LO did not successfully lock at TX frequency %s.") % return_MHz_string(*f) << std::endl; |
| 180 |
no_lock_freqs.push_back(*f); |
| 181 |
} |
| 182 |
} |
| 183 |
|
| 184 |
if(test_gain){
|
| 185 |
|
| 186 |
//Testing for successful gain tune
|
| 187 |
|
| 188 |
for(std::vector<double>::iterator g = gains.begin(); g != gains.end(); ++g){ |
| 189 |
usrp->set_tx_gain(*g); |
| 190 |
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
|
| 191 |
|
| 192 |
double actual_gain = usrp->get_tx_gain();
|
| 193 |
|
| 194 |
if(*g == 0.0){ |
| 195 |
if(actual_gain == 0.0){ |
| 196 |
if(verbose) std::cout << boost::format("TX gain successfully set to %5.2f at TX frequency %s.") % *g % return_MHz_string(*f) << std::endl; |
| 197 |
} |
| 198 |
else{
|
| 199 |
if(verbose) std::cout << boost::format("TX gain set to %5.2f instead of %5.2f at TX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl; |
| 200 |
std::vector<double> bad_gain_freq;
|
| 201 |
bad_gain_freq.push_back(*f); |
| 202 |
bad_gain_freq.push_back(*g); |
| 203 |
bad_gain_vals.push_back(bad_gain_freq); |
| 204 |
} |
| 205 |
} |
| 206 |
else{
|
| 207 |
if((*g / actual_gain) > 0.9 and (*g / actual_gain) < 1.1){ |
| 208 |
if(verbose) std::cout << boost::format("TX gain successfully set to %5.2f at TX frequency %s.") % *g % return_MHz_string(*f) << std::endl; |
| 209 |
} |
| 210 |
else{
|
| 211 |
if(verbose) std::cout << boost::format("TX gain set to %5.2f instead of %5.2f at TX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl; |
| 212 |
std::vector<double> bad_gain_freq;
|
| 213 |
bad_gain_freq.push_back(*f); |
| 214 |
bad_gain_freq.push_back(*g); |
| 215 |
bad_gain_vals.push_back(bad_gain_freq); |
| 216 |
} |
| 217 |
} |
| 218 |
} |
| 219 |
} |
| 220 |
} |
| 221 |
|
| 222 |
std::string tx_results = "TX Summary:\n"; |
| 223 |
if(usrp->get_usrp_tx_info().get("tx_subdev_name") == "XCVR2450 TX"){ |
| 224 |
tx_results += std::string(str(boost::format("Frequency Range: %s - %s, %s - %s\n") % return_MHz_string(xcvr_freqs.at(0)) % return_MHz_string(xcvr_freqs.at(1)) % |
| 225 |
return_MHz_string(xcvr_freqs.at(2)) % return_MHz_string(xcvr_freqs.at(3)))); |
| 226 |
} |
| 227 |
else tx_results += std::string(str(boost::format("Frequency Range: %s - %s\n") % return_MHz_string(freqs.front()) % return_MHz_string(freqs.back()))); |
| 228 |
if(test_gain) tx_results += std::string(str(boost::format("Gain Range: %5.2f - %5.2f\n") % gains.front() % gains.back())); |
| 229 |
|
| 230 |
if(bad_tune_freqs.empty()) tx_results += "USRP successfully tuned to all frequencies."; |
| 231 |
else{
|
| 232 |
tx_results += "USRP did not successfully tune to the following frequencies: ";
|
| 233 |
for(std::vector<double>::iterator i = bad_tune_freqs.begin(); i != bad_tune_freqs.end(); ++i){ |
| 234 |
if(i != bad_tune_freqs.begin()) tx_results += ", "; |
| 235 |
tx_results += return_MHz_string(*i); |
| 236 |
} |
| 237 |
} |
| 238 |
if(has_sensor){
|
| 239 |
|
| 240 |
tx_results += "\n";
|
| 241 |
if(no_lock_freqs.empty()) tx_results += "LO successfully locked at all frequencies."; |
| 242 |
else{
|
| 243 |
tx_results += "LO did not lock at the following frequencies: ";
|
| 244 |
for(std::vector<double>::iterator i = no_lock_freqs.begin(); i != no_lock_freqs.end(); ++i){ |
| 245 |
if(i != no_lock_freqs.begin()) tx_results += ", "; |
| 246 |
tx_results += return_MHz_string(*i); |
| 247 |
} |
| 248 |
} |
| 249 |
} |
| 250 |
if(test_gain){
|
| 251 |
tx_results += "\n";
|
| 252 |
if(bad_gain_vals.empty()) tx_results += "USRP successfully set all specified gain values at all frequencies."; |
| 253 |
else{
|
| 254 |
tx_results += "USRP did not successfully set gain under the following circumstances:";
|
| 255 |
for(std::vector< std::vector<double> >::iterator i = bad_gain_vals.begin(); i != bad_gain_vals.end(); ++i){ |
| 256 |
std::vector<double> bad_pair = *i;
|
| 257 |
double bad_freq = bad_pair.front();
|
| 258 |
double bad_gain = bad_pair.back();
|
| 259 |
tx_results += std::string(str(boost::format("\nFrequency: %s, Gain: %5.2f") % return_MHz_string(bad_freq) % bad_gain)); |
| 260 |
} |
| 261 |
} |
| 262 |
} |
| 263 |
|
| 264 |
return tx_results;
|
| 265 |
} |
| 266 |
|
| 267 |
/************************************************************************
|
| 268 |
* RX Frequency/Gain Coercion
|
| 269 |
************************************************************************/
|
| 270 |
|
| 271 |
std::string rx_test(uhd::usrp::multi_usrp::sptr usrp, bool test_gain, bool verbose){ |
| 272 |
|
| 273 |
//Establish frequency range
|
| 274 |
|
| 275 |
std::vector<double> freqs;
|
| 276 |
std::vector<double> xcvr_freqs;
|
| 277 |
|
| 278 |
BOOST_FOREACH(const uhd::range_t &range, usrp->get_fe_rx_freq_range()){
|
| 279 |
double freq_begin = range.start();
|
| 280 |
double freq_end = range.stop();
|
| 281 |
|
| 282 |
if(usrp->get_usrp_rx_info().get("rx_subdev_name") == "XCVR2450 RX"){ |
| 283 |
xcvr_freqs.push_back(freq_begin); |
| 284 |
xcvr_freqs.push_back(freq_end); |
| 285 |
} |
| 286 |
|
| 287 |
double freq_step;
|
| 288 |
|
| 289 |
if(freq_end - freq_begin > 1000e6) freq_step = 100e6; |
| 290 |
else if(freq_end - freq_begin < 300e6) freq_step = 10e6; |
| 291 |
else freq_step = 50e6; |
| 292 |
|
| 293 |
double current_freq = freq_begin;
|
| 294 |
|
| 295 |
while(current_freq < freq_end){
|
| 296 |
freqs.push_back(current_freq); |
| 297 |
current_freq += freq_step; |
| 298 |
} |
| 299 |
} |
| 300 |
|
| 301 |
std::vector<double> gains;
|
| 302 |
|
| 303 |
if(test_gain){
|
| 304 |
|
| 305 |
//Establish gain range
|
| 306 |
|
| 307 |
double gain_begin = usrp->get_rx_gain_range().start();
|
| 308 |
if(gain_begin < 0.0) gain_begin = 0.0; |
| 309 |
double gain_end = usrp->get_rx_gain_range().stop();
|
| 310 |
|
| 311 |
double current_gain = gain_begin;
|
| 312 |
while(current_gain < gain_end){
|
| 313 |
gains.push_back(current_gain); |
| 314 |
current_gain++; |
| 315 |
} |
| 316 |
if(gain_end != *gains.end()) gains.push_back(gain_end);
|
| 317 |
|
| 318 |
} |
| 319 |
|
| 320 |
//Establish error-storing variables
|
| 321 |
|
| 322 |
std::vector<double> bad_tune_freqs;
|
| 323 |
std::vector<double> no_lock_freqs;
|
| 324 |
std::vector< std::vector< double > > bad_gain_vals;
|
| 325 |
std::vector<std::string> dboard_sensor_names = usrp->get_rx_sensor_names();
|
| 326 |
std::vector<std::string> mboard_sensor_names = usrp->get_mboard_sensor_names();
|
| 327 |
bool has_sensor = (std::find(dboard_sensor_names.begin(), dboard_sensor_names.end(), "lo_locked")) != dboard_sensor_names.end(); |
| 328 |
|
| 329 |
for(std::vector<double>::iterator f = freqs.begin(); f != freqs.end(); ++f){ |
| 330 |
|
| 331 |
//Testing for successful frequency tune
|
| 332 |
|
| 333 |
usrp->set_rx_freq(*f); |
| 334 |
boost::this_thread::sleep(boost::posix_time::microseconds(long(1000))); |
| 335 |
|
| 336 |
double actual_freq = usrp->get_rx_freq();
|
| 337 |
|
| 338 |
if(*f == 0.0){ |
| 339 |
if(floor(actual_freq + 0.5) == 0.0){ |
| 340 |
if(verbose) std::cout << boost::format("\nRX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl; |
| 341 |
} |
| 342 |
else{
|
| 343 |
if(verbose) std::cout << boost::format("\nRX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl; |
| 344 |
} |
| 345 |
} |
| 346 |
else{
|
| 347 |
if((*f / actual_freq > 0.9999) and (*f / actual_freq < 1.0001)){ |
| 348 |
if(verbose) std::cout << boost::format("\nRX frequency successfully tuned to %s.") % return_MHz_string(*f) << std::endl; |
| 349 |
} |
| 350 |
else{
|
| 351 |
if(verbose) std::cout << boost::format("\nRX frequency tuned to %s instead of %s.") % return_MHz_string(actual_freq) % return_MHz_string(*f) << std::endl; |
| 352 |
bad_tune_freqs.push_back(*f); |
| 353 |
} |
| 354 |
} |
| 355 |
|
| 356 |
//Testing for successful lock
|
| 357 |
|
| 358 |
if(has_sensor){
|
| 359 |
bool is_locked = false; |
| 360 |
for(int i = 0; i < 1000; i++){ |
| 361 |
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
|
| 362 |
if(usrp->get_rx_sensor("lo_locked",0).to_bool()){ |
| 363 |
is_locked = true;
|
| 364 |
break;
|
| 365 |
} |
| 366 |
} |
| 367 |
if(is_locked){
|
| 368 |
if(verbose) std::cout << boost::format("LO successfully locked at RX frequency %s.") % return_MHz_string(*f) << std::endl; |
| 369 |
} |
| 370 |
else{
|
| 371 |
if(verbose) std::cout << boost::format("LO did not successfully lock at RX frequency %s.") % return_MHz_string(*f) << std::endl; |
| 372 |
no_lock_freqs.push_back(*f); |
| 373 |
} |
| 374 |
} |
| 375 |
|
| 376 |
if(test_gain){
|
| 377 |
|
| 378 |
//Testing for successful gain tune
|
| 379 |
|
| 380 |
for(std::vector<double>::iterator g = gains.begin(); g != gains.end(); ++g){ |
| 381 |
usrp->set_rx_gain(*g); |
| 382 |
boost::this_thread::sleep(boost::posix_time::microseconds(1000));
|
| 383 |
|
| 384 |
double actual_gain = usrp->get_rx_gain();
|
| 385 |
|
| 386 |
if(*g == 0.0){ |
| 387 |
if(actual_gain == 0.0){ |
| 388 |
if(verbose) std::cout << boost::format("RX gain successfully set to %5.2f at RX frequency %s.") % *g % return_MHz_string(*f) << std::endl; |
| 389 |
} |
| 390 |
else{
|
| 391 |
if(verbose) std::cout << boost::format("RX gain set to %5.2f instead of %5.2f at RX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl; |
| 392 |
std::vector<double> bad_gain_freq;
|
| 393 |
bad_gain_freq.push_back(*f); |
| 394 |
bad_gain_freq.push_back(*g); |
| 395 |
bad_gain_vals.push_back(bad_gain_freq); |
| 396 |
} |
| 397 |
} |
| 398 |
else{
|
| 399 |
if((*g / actual_gain) > 0.9 and (*g / actual_gain) < 1.1){ |
| 400 |
if(verbose) std::cout << boost::format("RX gain successfully set to %5.2f at RX frequency %s.") % *g % return_MHz_string(*f) << std::endl; |
| 401 |
} |
| 402 |
else{
|
| 403 |
if(verbose) std::cout << boost::format("RX gain set to %5.2f instead of %5.2f at RX frequency %s.") % actual_gain % *g % return_MHz_string(*f) << std::endl; |
| 404 |
std::vector<double> bad_gain_freq;
|
| 405 |
bad_gain_freq.push_back(*f); |
| 406 |
bad_gain_freq.push_back(*g); |
| 407 |
bad_gain_vals.push_back(bad_gain_freq); |
| 408 |
} |
| 409 |
} |
| 410 |
} |
| 411 |
} |
| 412 |
} |
| 413 |
|
| 414 |
std::string rx_results = "RX Summary:\n"; |
| 415 |
if(usrp->get_usrp_rx_info().get("rx_subdev_name") == "XCVR2450 RX"){ |
| 416 |
rx_results += std::string(str(boost::format("Frequency Range: %s - %s, %s - %s\n") % return_MHz_string(xcvr_freqs.at(0)) % return_MHz_string(xcvr_freqs.at(1)) % |
| 417 |
return_MHz_string(xcvr_freqs.at(2)) % return_MHz_string(xcvr_freqs.at(3)))); |
| 418 |
} |
| 419 |
else rx_results += std::string(str(boost::format("Frequency Range: %s - %s\n") % return_MHz_string(freqs.front()) % return_MHz_string(freqs.back()))); |
| 420 |
if(test_gain) rx_results += std::string(str(boost::format("Gain Range: %5.2f - %5.2f\n") % gains.front() % gains.back())); |
| 421 |
|
| 422 |
if(bad_tune_freqs.empty()) rx_results += "USRP successfully tuned to all frequencies."; |
| 423 |
else{
|
| 424 |
rx_results += "USRP did not successfully tune to the following frequencies: ";
|
| 425 |
for(std::vector<double>::iterator i = bad_tune_freqs.begin(); i != bad_tune_freqs.end(); ++i){ |
| 426 |
if(i != bad_tune_freqs.begin()) rx_results += ", "; |
| 427 |
rx_results += return_MHz_string(*i); |
| 428 |
} |
| 429 |
} |
| 430 |
if(has_sensor){
|
| 431 |
|
| 432 |
rx_results += "\n";
|
| 433 |
if(no_lock_freqs.empty()) rx_results += "LO successfully locked at all frequencies."; |
| 434 |
else{
|
| 435 |
rx_results += "LO did not successfully lock at the following frequencies: ";
|
| 436 |
for(std::vector<double>::iterator i = no_lock_freqs.begin(); i != no_lock_freqs.end(); ++i){ |
| 437 |
if( i != no_lock_freqs.begin()) rx_results += ", "; |
| 438 |
rx_results += return_MHz_string(*i); |
| 439 |
} |
| 440 |
} |
| 441 |
} |
| 442 |
if(test_gain){
|
| 443 |
rx_results += "\n";
|
| 444 |
if(bad_gain_vals.empty()) rx_results += "USRP successfully set all specified gain values at all frequencies."; |
| 445 |
else{
|
| 446 |
rx_results += "USRP did not successfully set gain under the following circumstances:";
|
| 447 |
for(std::vector< std::vector<double> >::iterator i = bad_gain_vals.begin(); i != bad_gain_vals.end(); ++i){ |
| 448 |
std::vector<double> bad_pair = *i;
|
| 449 |
double bad_freq = bad_pair.front();
|
| 450 |
double bad_gain = bad_pair.back();
|
| 451 |
rx_results += std::string(str(boost::format("\nFrequency: %s, Gain: %5.2f") % return_MHz_string(bad_freq) % bad_gain)); |
| 452 |
} |
| 453 |
} |
| 454 |
} |
| 455 |
|
| 456 |
return rx_results;
|
| 457 |
} |
| 458 |
|
| 459 |
/************************************************************************
|
| 460 |
* Initial Setup
|
| 461 |
************************************************************************/
|
| 462 |
|
| 463 |
int UHD_SAFE_MAIN(int argc, char *argv[]){ |
| 464 |
|
| 465 |
//Variables
|
| 466 |
std::string args;
|
| 467 |
double gain_step;
|
| 468 |
std::string ref;
|
| 469 |
std::string tx_results;
|
| 470 |
std::string rx_results;
|
| 471 |
std::string usrp_config;
|
| 472 |
|
| 473 |
//Set up the program options
|
| 474 |
po::options_description desc("Allowed Options");
|
| 475 |
desc.add_options() |
| 476 |
("help", "help message") |
| 477 |
("args", po::value<std::string>(&args)->default_value(""), "Specify the UHD device") |
| 478 |
("gain_step", po::value<double>(&gain_step)->default_value(1.0), "Specify the delta between gain scans") |
| 479 |
("tx", "Specify to test TX frequency and gain coercion") |
| 480 |
("rx", "Specify to test RX frequency and gain coercion") |
| 481 |
("ref", po::value<std::string>(&ref)->default_value("internal"), "Waveform type: internal, external, or mimo") |
| 482 |
("no_tx_gain", "Do not test TX gain") |
| 483 |
("no_rx_gain", "Do not test RX gain") |
| 484 |
("verbose", "Output every frequency and gain check instead of just final summary") |
| 485 |
; |
| 486 |
po::variables_map vm; |
| 487 |
po::store(po::parse_command_line(argc, argv, desc), vm); |
| 488 |
po::notify(vm); |
| 489 |
|
| 490 |
//Create a USRP device
|
| 491 |
std::cout << std::endl; |
| 492 |
uhd::device_addrs_t device_addrs = uhd::device::find(args); |
| 493 |
std::cout << boost::format("Creating the USRP device with: %s...") % args << std::endl;
|
| 494 |
uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args); |
| 495 |
std::cout << std::endl << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
|
| 496 |
usrp->set_tx_rate(1e6);
|
| 497 |
usrp->set_rx_rate(1e6);
|
| 498 |
|
| 499 |
//Boolean variables based on command line input
|
| 500 |
bool test_tx = vm.count("tx") > 0; |
| 501 |
bool test_rx = vm.count("rx") > 0; |
| 502 |
bool test_tx_gain = !(vm.count("no_tx_gain") > 0) and (usrp->get_tx_gain_range().stop() > 0); |
| 503 |
bool test_rx_gain = !(vm.count("no_rx_gain") > 0) and (usrp->get_rx_gain_range().stop() > 0); |
| 504 |
bool verbose = vm.count("verbose") > 0; |
| 505 |
|
| 506 |
//Help messages, errors
|
| 507 |
if(vm.count("help") > 0){ |
| 508 |
std::cout << "UHD Daughterboard Coercion Test\n"
|
| 509 |
"This program tests your USRP daughterboard(s) to\n"
|
| 510 |
"make sure that they can successfully tune to all\n"
|
| 511 |
"frequencies and gains in their advertised ranges.\n\n";
|
| 512 |
std::cout << desc << std::endl; |
| 513 |
return ~0; |
| 514 |
} |
| 515 |
|
| 516 |
if(ref != "internal" and ref != "external" and ref != "mimo"){ |
| 517 |
std::cout << desc << std::endl; |
| 518 |
std::cout << "REF must equal internal, external, or mimo." << std::endl;
|
| 519 |
return ~0; |
| 520 |
} |
| 521 |
|
| 522 |
if(vm.count("tx") + vm.count("rx") == 0){ |
| 523 |
std::cout << desc << std::endl; |
| 524 |
std::cout << "Specify --tx to test for TX frequency coercion\n"
|
| 525 |
"Specify --rx to test for RX frequency coercion\n";
|
| 526 |
return ~0; |
| 527 |
} |
| 528 |
|
| 529 |
if(test_rx and usrp->get_usrp_rx_info().get("rx_id") == "Basic RX (0x0001)"){ |
| 530 |
std::cout << desc << std::endl; |
| 531 |
std::cout << "This test does not work with the Basic RX daughterboard." << std::endl;
|
| 532 |
return ~0; |
| 533 |
} |
| 534 |
else if(test_rx and usrp->get_usrp_rx_info().get("rx_id") == "Unknown (0xffff)"){ |
| 535 |
std::cout << desc << std::endl; |
| 536 |
std::cout << "This daughterboard is unrecognized, or there is no RX daughterboard." << std::endl;
|
| 537 |
return ~0; |
| 538 |
} |
| 539 |
|
| 540 |
if(test_tx and usrp->get_usrp_tx_info().get("tx_id") == "Basic TX (0x0000)"){ |
| 541 |
std::cout << desc << std::endl; |
| 542 |
std::cout << "This test does not work with the Basic TX daughterboard." << std::endl;
|
| 543 |
return ~0; |
| 544 |
} |
| 545 |
else if(test_tx and usrp->get_usrp_tx_info().get("tx_id") == "Unknown (0xffff)"){ |
| 546 |
std::cout << desc << std::endl; |
| 547 |
std::cout << "This daughterboard is unrecognized, or there is no TX daughterboard." << std::endl;
|
| 548 |
return ~0; |
| 549 |
} |
| 550 |
|
| 551 |
//Setting clock source
|
| 552 |
usrp->set_clock_source(ref); |
| 553 |
boost::this_thread::sleep(boost::posix_time::seconds(1));
|
| 554 |
|
| 555 |
std::vector<std::string> sensor_names = usrp->get_mboard_sensor_names(0); |
| 556 |
if ((ref == "mimo") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) { |
| 557 |
uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); |
| 558 |
std::cout << boost::format("Checking MIMO lock: %s ...") % mimo_locked.to_pp_string() << std::endl;
|
| 559 |
UHD_ASSERT_THROW(mimo_locked.to_bool()); |
| 560 |
} |
| 561 |
if ((ref == "external") and (std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end())) { |
| 562 |
uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); |
| 563 |
std::cout << boost::format("Checking REF lock: %s ...") % ref_locked.to_pp_string() << std::endl;
|
| 564 |
UHD_ASSERT_THROW(ref_locked.to_bool()); |
| 565 |
} |
| 566 |
usrp_config = return_USRP_config_string(usrp, test_tx, test_rx); |
| 567 |
if(test_tx) tx_results = tx_test(usrp, test_tx_gain, verbose);
|
| 568 |
if(test_rx) rx_results = rx_test(usrp, test_rx_gain, verbose);
|
| 569 |
|
| 570 |
if(verbose) std::cout << std::endl;
|
| 571 |
std::cout << usrp_config << std::endl << std::endl; |
| 572 |
if(test_tx) std::cout << tx_results << std::endl;
|
| 573 |
if(test_tx and test_rx) std::cout << std::endl; |
| 574 |
if(test_rx) std::cout << rx_results << std::endl;
|
| 575 |
|
| 576 |
return 0; |
| 577 |
} |