diff options
author | michael-west <michael.west@ettus.com> | 2018-10-26 16:49:30 -0700 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2018-12-20 19:18:49 -0800 |
commit | 46bd88639e9ecd6d37f4509805fa6ecc6b41d8d0 (patch) | |
tree | 0356ad236737adbca62295c167e4cf2a3366a6a9 | |
parent | 2de2722fd5a7d39c8d6a0649cce7d01138098dcd (diff) | |
download | uhd-46bd88639e9ecd6d37f4509805fa6ecc6b41d8d0.tar.gz uhd-46bd88639e9ecd6d37f4509805fa6ecc6b41d8d0.tar.bz2 uhd-46bd88639e9ecd6d37f4509805fa6ecc6b41d8d0.zip |
utils: Improve query_gpsdo_sensors
- Sets time source before checking ref_locked
(E310 uses time source for PLL)
- Checks for existence of "gpsdo" time and clock sources before setting
- Only attempts to set them if they exist
- Does not fall back on external sources
- Returns with error if neither can be set to "gpsdo"
-rw-r--r-- | host/utils/query_gpsdo_sensors.cpp | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/host/utils/query_gpsdo_sensors.cpp b/host/utils/query_gpsdo_sensors.cpp index d909f83a9..f37d9cc4a 100644 --- a/host/utils/query_gpsdo_sensors.cpp +++ b/host/utils/query_gpsdo_sensors.cpp @@ -8,6 +8,7 @@ #include <uhd/utils/paths.hpp> #include <uhd/utils/thread.hpp> #include <uhd/utils/safe_main.hpp> +#include <uhd/utils/algorithm.hpp> #include <uhd/usrp/multi_usrp.hpp> #include <uhd/usrp_clock/multi_usrp_clock.hpp> #include <boost/filesystem.hpp> @@ -111,54 +112,50 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ return EXIT_FAILURE; } - std::cout << "\nSetting the reference clock source to \"gpsdo\"...\n"; - try { + bool ref_set_to_gpsdo = false; + + // Set clock source to gpsdo if supported + if (uhd::has(usrp->get_clock_sources(0),"gpsdo")) + { + std::cout << "Setting the reference clock source to \"gpsdo\"..." << std::endl; usrp->set_clock_source("gpsdo"); - } catch (uhd::value_error &e) { - std::cout << "could not set the clock source to \"gpsdo\"; error was:" <<std::endl; - std::cout << e.what() << std::endl; - std::cout << "trying \"external\"..." <<std::endl; - try{ - usrp->set_clock_source("external"); - } catch (uhd::value_error&) { - std::cout << "\"external\" failed, too." << std::endl; - } + ref_set_to_gpsdo = true; + } + std::cout << "Clock source is now " << usrp->get_clock_source(0) << std::endl; + + // Set time source to gpsdo if supported + if (uhd::has(usrp->get_time_sources(0),"gpsdo")) + { + std::cout << "Setting the reference clock source to \"gpsdo\"..." << std::endl; + usrp->set_time_source("gpsdo"); + ref_set_to_gpsdo = true; } - std::cout<< std::endl << "Clock source is now " << usrp->get_clock_source(0) << std::endl; + std::cout << "Time source is now " << usrp->get_time_source(0) << std::endl; - //Check for 10 MHz lock + if (not ref_set_to_gpsdo) + { + std::cerr << "ERROR: Unable to set clock or time reference to \"gpsdo\"" << std::endl; + return EXIT_FAILURE; + } + + //Check for ref lock if(std::find(sensor_names.begin(), sensor_names.end(), "ref_locked") != sensor_names.end()) { uhd::sensor_value_t ref_locked = usrp->get_mboard_sensor("ref_locked",0); - for (size_t i = 0; not ref_locked.to_bool() and i < 100; i++) { + for (size_t i = 0; not ref_locked.to_bool() and i < 300; i++) { std::this_thread::sleep_for(std::chrono::milliseconds(100)); ref_locked = usrp->get_mboard_sensor("ref_locked",0); } if(not ref_locked.to_bool()) { - std::cout << boost::format("USRP NOT Locked to GPSDO 10 MHz Reference.\n"); + std::cout << boost::format("USRP NOT Locked to Reference.\n"); std::cout << boost::format("Double check installation instructions (N2X0/E1X0 only): https://www.ettus.com/content/files/gpsdo-kit_4.pdf\n\n"); return EXIT_FAILURE; } else { - std::cout << boost::format("USRP Locked to GPSDO 10 MHz Reference.\n"); + std::cout << boost::format("USRP Locked to Reference.\n"); } } else { std::cout << boost::format("ref_locked sensor not present on this board.\n"); } - // Explicitly set time source to gpsdo - try { - usrp->set_time_source("gpsdo"); - } catch (uhd::value_error &e) { - std::cout << "could not set the time source to \"gpsdo\"; error was:" <<std::endl; - std::cout << e.what() << std::endl; - std::cout << "trying \"external\"..." <<std::endl; - try { - usrp->set_time_source("external"); - } catch (uhd::value_error&) { - std::cout << "\"external\" failed, too." << std::endl; - } - } - std::cout << std::endl << "Time source is now " << usrp->get_time_source(0) << std::endl; - print_notes(); // The TCXO has a long warm up time, so wait up to 30 seconds for sensor data |