aboutsummaryrefslogtreecommitdiffstats
path: root/host/examples/test_timed_commands.cpp
diff options
context:
space:
mode:
authorBrent Stapleton <brent.stapleton@ettus.com>2019-01-14 10:35:25 -0800
committerBrent Stapleton <brent.stapleton@ettus.com>2019-01-16 11:40:23 -0800
commit967be2a4e82b1a125b26bb72a60318a4fb2b50c4 (patch)
tree8a24954b54d1546dc8049a17e485adb0a605f74f /host/examples/test_timed_commands.cpp
parentaafe4e8b742a0e21d3818f21f34e3c8613132530 (diff)
downloaduhd-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_timed_commands.cpp')
-rw-r--r--host/examples/test_timed_commands.cpp143
1 files changed, 73 insertions, 70 deletions
diff --git a/host/examples/test_timed_commands.cpp b/host/examples/test_timed_commands.cpp
index f53f3c282..5fe8d818c 100644
--- a/host/examples/test_timed_commands.cpp
+++ b/host/examples/test_timed_commands.cpp
@@ -5,23 +5,24 @@
// SPDX-License-Identifier: GPL-3.0-or-later
//
-#include <uhd/utils/thread.hpp>
-#include <uhd/utils/safe_main.hpp>
#include <uhd/usrp/multi_usrp.hpp>
-#include <boost/program_options.hpp>
+#include <uhd/utils/safe_main.hpp>
+#include <uhd/utils/thread.hpp>
#include <boost/format.hpp>
-#include <iostream>
+#include <boost/program_options.hpp>
#include <complex>
+#include <iostream>
namespace po = boost::program_options;
-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 po
+ // variables to be set by po
std::string args;
- //setup the program options
+ // setup the program options
po::options_description desc("Allowed options");
// clang-format off
desc.add_options()
@@ -33,26 +34,26 @@ 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 << boost::format("UHD Test Timed Commands %s") % desc << std::endl;
return ~0;
}
- //create a usrp device
+ // create a usrp device
std::cout << std::endl;
- std::cout << boost::format("Creating the usrp device with: %s...") % args << std::endl;
+ std::cout << boost::format("Creating the usrp device with: %s...") % args
+ << std::endl;
uhd::usrp::multi_usrp::sptr usrp = uhd::usrp::multi_usrp::make(args);
std::cout << boost::format("Using Device: %s") % usrp->get_pp_string() << std::endl;
- //check if timed commands are supported
+ // check if timed commands are supported
std::cout << std::endl;
std::cout << "Testing support for timed commands on this hardware... " << std::flush;
- try{
+ try {
usrp->set_command_time(uhd::time_spec_t(0.0));
usrp->clear_command_time();
- }
- catch (const std::exception &e){
+ } catch (const std::exception& e) {
std::cout << "fail" << std::endl;
std::cerr << "Got exception: " << e.what() << std::endl;
std::cerr << "Timed commands are not supported on this hardware." << std::endl;
@@ -60,27 +61,27 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
}
std::cout << "pass" << std::endl;
- //readback time really fast, time diff is small
+ // readback time really fast, time diff is small
std::cout << std::endl;
std::cout << "Perform fast readback of registers:" << std::endl;
uhd::time_spec_t total_time;
- for (size_t i = 0; i < 100; i++){
+ for (size_t i = 0; i < 100; i++) {
const uhd::time_spec_t t0 = usrp->get_time_now();
const uhd::time_spec_t t1 = usrp->get_time_now();
- total_time += (t1-t0);
+ total_time += (t1 - t0);
}
- std::cout << boost::format(
- " Difference between paired reads: %f us"
- ) % (total_time.get_real_secs()/100*1e6) << std::endl;
-
- //test timed control command
- //issues get_time_now() command twice a fixed time apart
- //outputs difference for each response time vs. the expected time
- //and difference between actual and expected time deltas
+ std::cout << boost::format(" Difference between paired reads: %f us")
+ % (total_time.get_real_secs() / 100 * 1e6)
+ << std::endl;
+
+ // test timed control command
+ // issues get_time_now() command twice a fixed time apart
+ // outputs difference for each response time vs. the expected time
+ // and difference between actual and expected time deltas
std::cout << std::endl;
std::cout << "Testing control timed command:" << std::endl;
- const uhd::time_spec_t span = uhd::time_spec_t(0.1);
- const uhd::time_spec_t now = usrp->get_time_now();
+ const uhd::time_spec_t span = uhd::time_spec_t(0.1);
+ const uhd::time_spec_t now = usrp->get_time_now();
const uhd::time_spec_t cmd_time1 = now + uhd::time_spec_t(0.1);
const uhd::time_spec_t cmd_time2 = cmd_time1 + span;
usrp->set_command_time(cmd_time1);
@@ -88,63 +89,65 @@ int UHD_SAFE_MAIN(int argc, char *argv[]){
usrp->set_command_time(cmd_time2);
uhd::time_spec_t response_time2 = usrp->get_time_now();
usrp->clear_command_time();
+ std::cout << boost::format(" Span : %f us\n"
+ " Now : %f us\n"
+ " Response 1: %f us\n"
+ " Response 2: %f us")
+ % (span.get_real_secs() * 1e6) % (now.get_real_secs() * 1e6)
+ % (response_time1.get_real_secs() * 1e6)
+ % (response_time2.get_real_secs() * 1e6)
+ << std::endl;
+ std::cout << boost::format(" Difference of response time 1: %f us")
+ % ((response_time1 - cmd_time1).get_real_secs() * 1e6)
+ << std::endl;
+ std::cout << boost::format(" Difference of response time 2: %f us")
+ % ((response_time2 - cmd_time2).get_real_secs() * 1e6)
+ << std::endl;
std::cout << boost::format(
- " Span : %f us\n"
- " Now : %f us\n"
- " Response 1: %f us\n"
- " Response 2: %f us"
- ) % (span.get_real_secs()*1e6) % (now.get_real_secs()*1e6) % (response_time1.get_real_secs()*1e6) % (response_time2.get_real_secs()*1e6) << std::endl;
- std::cout << boost::format(
- " Difference of response time 1: %f us"
- ) % ((response_time1 - cmd_time1).get_real_secs()*1e6) << std::endl;
- std::cout << boost::format(
- " Difference of response time 2: %f us"
- ) % ((response_time2 - cmd_time2).get_real_secs()*1e6) << std::endl;
- std::cout << boost::format(
- " Difference between actual and expected time delta: %f us"
- ) % ((response_time2 - response_time1 - span).get_real_secs()*1e6) << std::endl;
-
- //use a timed command to start a stream at a specific time
- //this is not the right way start streaming at time x,
- //but it should approximate it within control RTT/2
- //setup streaming
+ " Difference between actual and expected time delta: %f us")
+ % ((response_time2 - response_time1 - span).get_real_secs() * 1e6)
+ << std::endl;
+
+ // use a timed command to start a stream at a specific time
+ // this is not the right way start streaming at time x,
+ // but it should approximate it within control RTT/2
+ // setup streaming
std::cout << std::endl;
std::cout << "About to start streaming using timed command:" << std::endl;
- //create a receive streamer
- uhd::stream_args_t stream_args("fc32"); //complex floats
+ // create a receive streamer
+ uhd::stream_args_t stream_args("fc32"); // complex floats
uhd::rx_streamer::sptr rx_stream = usrp->get_rx_stream(stream_args);
uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE);
- stream_cmd.num_samps = 100;
- stream_cmd.stream_now = false;
+ stream_cmd.num_samps = 100;
+ stream_cmd.stream_now = false;
const uhd::time_spec_t stream_time = usrp->get_time_now() + uhd::time_spec_t(0.1);
- stream_cmd.time_spec = stream_time;
+ stream_cmd.time_spec = stream_time;
rx_stream->issue_stream_cmd(stream_cmd);
- //meta-data will be filled in by recv()
+ // meta-data will be filled in by recv()
uhd::rx_metadata_t md;
- //allocate buffer to receive with samples
- std::vector<std::complex<float> > buff(stream_cmd.num_samps);
+ // allocate buffer to receive with samples
+ std::vector<std::complex<float>> buff(stream_cmd.num_samps);
const size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md, 1.0);
- if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE){
- throw std::runtime_error(str(boost::format(
- "Receiver error %s"
- ) % md.strerror()));
+ if (md.error_code != uhd::rx_metadata_t::ERROR_CODE_NONE) {
+ throw std::runtime_error(str(boost::format("Receiver error %s") % md.strerror()));
}
- std::cout << boost::format(
- " Received packet: %u samples, %u full secs, %f frac secs"
- ) % num_rx_samps % md.time_spec.get_full_secs() % md.time_spec.get_frac_secs() << std::endl;
- std::cout << boost::format(
- " Stream time was: %u full secs, %f frac secs"
- ) % stream_time.get_full_secs() % stream_time.get_frac_secs() << std::endl;
- std::cout << boost::format(
- " Difference between stream time and first packet: %f us"
- ) % ((md.time_spec-stream_time).get_real_secs()*1e6) << std::endl;
-
- //finished
+ std::cout << boost::format(" Received packet: %u samples, %u full secs, %f frac secs")
+ % num_rx_samps % md.time_spec.get_full_secs()
+ % md.time_spec.get_frac_secs()
+ << std::endl;
+ std::cout << boost::format(" Stream time was: %u full secs, %f frac secs")
+ % stream_time.get_full_secs() % stream_time.get_frac_secs()
+ << std::endl;
+ std::cout << boost::format(" Difference between stream time and first packet: %f us")
+ % ((md.time_spec - stream_time).get_real_secs() * 1e6)
+ << std::endl;
+
+ // finished
std::cout << std::endl << "Done!" << std::endl << std::endl;
return EXIT_SUCCESS;