diff options
author | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-14 10:35:25 -0800 |
---|---|---|
committer | Brent Stapleton <brent.stapleton@ettus.com> | 2019-01-16 11:40:23 -0800 |
commit | 967be2a4e82b1a125b26bb72a60318a4fb2b50c4 (patch) | |
tree | 8a24954b54d1546dc8049a17e485adb0a605f74f /host/examples/test_clock_synch.cpp | |
parent | aafe4e8b742a0e21d3818f21f34e3c8613132530 (diff) | |
download | uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.gz uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.tar.bz2 uhd-967be2a4e82b1a125b26bb72a60318a4fb2b50c4.zip |
uhd: mpm: apply clang-format to all files
Applying formatting changes to all .cpp and .hpp files in the following
directories:
```
find host/examples/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/tests/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/dboard/neon/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/dboard/magnesium/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/device3/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/mpmd/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/lib/usrp/x300/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find host/utils/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
find mpm/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
```
Also formatted host/include/, except Cpp03 was used as a the language
standard instead of Cpp11.
```
sed -i 's/ Cpp11/ Cpp03/g' .clang-format
find host/include/ -iname *.hpp -o -iname *.cpp | \
xargs clang-format -i -style=file
```
Formatting style was designated by the .clang-format file.
Diffstat (limited to 'host/examples/test_clock_synch.cpp')
-rw-r--r-- | host/examples/test_clock_synch.cpp | 91 |
1 files changed, 52 insertions, 39 deletions
diff --git a/host/examples/test_clock_synch.cpp b/host/examples/test_clock_synch.cpp index cb34e625c..96ebd05a6 100644 --- a/host/examples/test_clock_synch.cpp +++ b/host/examples/test_clock_synch.cpp @@ -7,17 +7,15 @@ #include <uhd/device.hpp> #include <uhd/exception.hpp> -#include <uhd/usrp_clock/multi_usrp_clock.hpp> #include <uhd/types/time_spec.hpp> #include <uhd/usrp/multi_usrp.hpp> +#include <uhd/usrp_clock/multi_usrp_clock.hpp> #include <uhd/utils/safe_main.hpp> #include <uhd/utils/thread.hpp> - #include <boost/format.hpp> #include <boost/program_options.hpp> - -#include <iostream> #include <chrono> +#include <iostream> #include <thread> namespace po = boost::program_options; @@ -25,18 +23,20 @@ namespace po = boost::program_options; using namespace uhd::usrp_clock; using namespace uhd::usrp; -void get_usrp_time(multi_usrp::sptr usrp, size_t mboard, std::vector<int64_t> *times){ +void get_usrp_time(multi_usrp::sptr usrp, size_t mboard, std::vector<int64_t>* times) +{ (*times)[mboard] = usrp->get_time_now(mboard).get_full_secs(); } -int UHD_SAFE_MAIN(int argc, char *argv[]){ +int UHD_SAFE_MAIN(int argc, char* argv[]) +{ uhd::set_thread_priority_safe(); - //Variables to be set by command line options + // Variables to be set by command line options std::string clock_args, usrp_args; uint32_t max_interval, num_tests; - //Set up program options + // Set up program options po::options_description desc("Allowed options"); // clang-format off desc.add_options() @@ -51,83 +51,96 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){ po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); - //Print the help message - if (vm.count("help")){ + // Print the help message + if (vm.count("help")) { std::cout << std::endl << "Test Clock Synchronization" << std::endl << std::endl; std::cout << "This example shows how to use a clock device to" << std::endl - << "synchronize the time on multiple USRP devices." << std::endl << std::endl; + << "synchronize the time on multiple USRP devices." << std::endl + << std::endl; std::cout << desc << std::endl; return EXIT_SUCCESS; } - //Create a Multi-USRP-Clock device (currently OctoClock only) - std::cout << boost::format("\nCreating the Clock device with: %s") % clock_args << std::endl; + // Create a Multi-USRP-Clock device (currently OctoClock only) + std::cout << boost::format("\nCreating the Clock device with: %s") % clock_args + << std::endl; multi_usrp_clock::sptr clock = multi_usrp_clock::make(clock_args); - //Make sure Clock configuration is correct - if(clock->get_sensor("gps_detected").value == "false"){ + // Make sure Clock configuration is correct + if (clock->get_sensor("gps_detected").value == "false") { throw uhd::runtime_error("No GPSDO detected on Clock."); } - if(clock->get_sensor("using_ref").value != "internal"){ + if (clock->get_sensor("using_ref").value != "internal") { throw uhd::runtime_error("Clock must be using an internal reference."); } - //Create a Multi-USRP device - std::cout << boost::format("\nCreating the USRP device with: %s") % usrp_args << std::endl; + // Create a Multi-USRP device + std::cout << boost::format("\nCreating the USRP device with: %s") % usrp_args + << std::endl; multi_usrp::sptr usrp = multi_usrp::make(usrp_args); - //Store USRP device serials for useful output + // Store USRP device serials for useful output std::vector<std::string> serials; - for(size_t ch = 0; ch < usrp->get_num_mboards(); ch++){ + for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) { serials.push_back(usrp->get_usrp_tx_info(ch)["mboard_serial"]); } std::cout << std::endl << "Checking USRP devices for lock." << std::endl; bool all_locked = true; - for(size_t ch = 0; ch < usrp->get_num_mboards(); ch++){ - std::string ref_locked = usrp->get_mboard_sensor("ref_locked",ch).value; + for (size_t ch = 0; ch < usrp->get_num_mboards(); ch++) { + std::string ref_locked = usrp->get_mboard_sensor("ref_locked", ch).value; std::cout << boost::format(" * %s: %s") % serials[ch] % ref_locked << std::endl; - if(ref_locked != "true") all_locked = false; + if (ref_locked != "true") + all_locked = false; } - if(not all_locked) std::cout << std::endl << "WARNING: One or more devices not locked." << std::endl; + if (not all_locked) + std::cout << std::endl << "WARNING: One or more devices not locked." << std::endl; - //Get GPS time to initially set USRP devices - std::cout << std::endl << "Querying Clock for time and setting USRP times..." << std::endl << std::endl; + // Get GPS time to initially set USRP devices + std::cout << std::endl + << "Querying Clock for time and setting USRP times..." << std::endl + << std::endl; int64_t clock_time = clock->get_time(); - usrp->set_time_next_pps(uhd::time_spec_t(double(clock_time+1))); + usrp->set_time_next_pps(uhd::time_spec_t(double(clock_time + 1))); srand((unsigned int)time(NULL)); - std::cout << boost::format("Running %d comparisons at random intervals.") % num_tests << std::endl; + std::cout << boost::format("Running %d comparisons at random intervals.") % num_tests + << std::endl; uint32_t num_matches = 0; - for(size_t i = 0; i < num_tests; i++){ - //Wait random time before querying + for (size_t i = 0; i < num_tests; i++) { + // Wait random time before querying uint16_t wait_time = rand() % max_interval; std::this_thread::sleep_for(std::chrono::milliseconds(wait_time)); - //Get all times before output + // Get all times before output std::vector<int64_t> usrp_times(usrp->get_num_mboards()); boost::thread_group thread_group; clock_time = clock->get_time(); - for(size_t j = 0; j < usrp->get_num_mboards(); j++){ + for (size_t j = 0; j < usrp->get_num_mboards(); j++) { thread_group.create_thread(boost::bind(&get_usrp_time, usrp, j, &usrp_times)); } - //Wait for threads to complete + // Wait for threads to complete thread_group.join_all(); - std::cout << boost::format("Comparison #%d") % (i+1) << std::endl; + std::cout << boost::format("Comparison #%d") % (i + 1) << std::endl; bool all_match = true; std::cout << boost::format(" * Clock time: %d") % clock_time << std::endl; - for(size_t j = 0; j < usrp->get_num_mboards(); j++){ - std::cout << boost::format(" * %s time: %d") % serials[j] % usrp_times[j] << std::endl; - if(usrp_times[j] != clock_time) all_match = false; + for (size_t j = 0; j < usrp->get_num_mboards(); j++) { + std::cout << boost::format(" * %s time: %d") % serials[j] % usrp_times[j] + << std::endl; + if (usrp_times[j] != clock_time) + all_match = false; } - if(all_match) num_matches++; + if (all_match) + num_matches++; } - std::cout << std::endl << boost::format("Number of matches: %d/%d") % num_matches % num_tests << std::endl; + std::cout << std::endl + << boost::format("Number of matches: %d/%d") % num_matches % num_tests + << std::endl; return EXIT_SUCCESS; } |