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/rx_samples_to_udp.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/rx_samples_to_udp.cpp')
-rw-r--r-- | host/examples/rx_samples_to_udp.cpp | 179 |
1 files changed, 101 insertions, 78 deletions
diff --git a/host/examples/rx_samples_to_udp.cpp b/host/examples/rx_samples_to_udp.cpp index 5268de020..6dd04ec6a 100644 --- a/host/examples/rx_samples_to_udp.cpp +++ b/host/examples/rx_samples_to_udp.cpp @@ -5,31 +5,32 @@ // SPDX-License-Identifier: GPL-3.0-or-later // +#include <uhd/exception.hpp> +#include <uhd/transport/udp_simple.hpp> #include <uhd/types/tune_request.hpp> -#include <uhd/utils/thread.hpp> -#include <uhd/utils/safe_main.hpp> #include <uhd/usrp/multi_usrp.hpp> -#include <uhd/transport/udp_simple.hpp> -#include <uhd/exception.hpp> -#include <boost/program_options.hpp> +#include <uhd/utils/safe_main.hpp> +#include <uhd/utils/thread.hpp> #include <boost/format.hpp> -#include <iostream> -#include <complex> +#include <boost/program_options.hpp> #include <chrono> +#include <complex> +#include <iostream> #include <thread> 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, file, ant, subdev, ref; size_t total_num_samps; double rate, freq, gain, bw; std::string addr, port; - //setup the program options + // setup the program options po::options_description desc("Allowed options"); // clang-format off desc.add_options() @@ -52,122 +53,144 @@ 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 RX to UDP %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; - //Lock mboard clocks + // Lock mboard clocks usrp->set_clock_source(ref); - //always select the subdevice first, the channel mapping affects the other settings + // always select the subdevice first, the channel mapping affects the other settings if (vm.count("subdev")) { usrp->set_rx_subdev_spec(subdev); } - //set the rx sample rate - std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate/1e6) << std::endl; + // set the rx sample rate + std::cout << boost::format("Setting RX Rate: %f Msps...") % (rate / 1e6) << std::endl; usrp->set_rx_rate(rate); - std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate()/1e6) << std::endl << std::endl; + std::cout << boost::format("Actual RX Rate: %f Msps...") % (usrp->get_rx_rate() / 1e6) + << std::endl + << std::endl; - //set the rx center frequency - std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq/1e6) << std::endl; + // set the rx center frequency + std::cout << boost::format("Setting RX Freq: %f MHz...") % (freq / 1e6) << std::endl; uhd::tune_request_t tune_request(freq); - if(vm.count("int-n")) tune_request.args = uhd::device_addr_t("mode_n=integer"); + if (vm.count("int-n")) + tune_request.args = uhd::device_addr_t("mode_n=integer"); usrp->set_rx_freq(tune_request); - std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq()/1e6) << std::endl << std::endl; + std::cout << boost::format("Actual RX Freq: %f MHz...") % (usrp->get_rx_freq() / 1e6) + << std::endl + << std::endl; - //set the rx rf gain + // set the rx rf gain std::cout << boost::format("Setting RX Gain: %f dB...") % gain << std::endl; usrp->set_rx_gain(gain); - std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() << std::endl << std::endl; - - //set the analog frontend filter bandwidth - if (vm.count("bw")){ - std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % (bw/1e6) << std::endl; + std::cout << boost::format("Actual RX Gain: %f dB...") % usrp->get_rx_gain() + << std::endl + << std::endl; + + // set the analog frontend filter bandwidth + if (vm.count("bw")) { + std::cout << boost::format("Setting RX Bandwidth: %f MHz...") % (bw / 1e6) + << std::endl; usrp->set_rx_bandwidth(bw); - std::cout << boost::format("Actual RX Bandwidth: %f MHz...") % (usrp->get_rx_bandwidth()/1e6) << std::endl << std::endl; + std::cout << boost::format("Actual RX Bandwidth: %f MHz...") + % (usrp->get_rx_bandwidth() / 1e6) + << std::endl + << std::endl; } - //set the antenna - if (vm.count("ant")) usrp->set_rx_antenna(ant); + // set the antenna + if (vm.count("ant")) + usrp->set_rx_antenna(ant); - std::this_thread::sleep_for(std::chrono::seconds(1)); //allow for some setup time + std::this_thread::sleep_for(std::chrono::seconds(1)); // allow for some setup time - //Check Ref and LO Lock detect + // Check Ref and LO Lock detect std::vector<std::string> sensor_names; sensor_names = usrp->get_rx_sensor_names(0); - if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") != sensor_names.end()) { - uhd::sensor_value_t lo_locked = usrp->get_rx_sensor("lo_locked",0); - std::cout << boost::format("Checking RX: %s ...") % lo_locked.to_pp_string() << std::endl; + if (std::find(sensor_names.begin(), sensor_names.end(), "lo_locked") + != sensor_names.end()) { + uhd::sensor_value_t lo_locked = usrp->get_rx_sensor("lo_locked", 0); + std::cout << boost::format("Checking RX: %s ...") % lo_locked.to_pp_string() + << std::endl; UHD_ASSERT_THROW(lo_locked.to_bool()); } sensor_names = usrp->get_mboard_sensor_names(0); - if ((ref == "mimo") and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") != sensor_names.end())) { - uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked",0); - std::cout << boost::format("Checking RX: %s ...") % mimo_locked.to_pp_string() << std::endl; + if ((ref == "mimo") + and (std::find(sensor_names.begin(), sensor_names.end(), "mimo_locked") + != sensor_names.end())) { + uhd::sensor_value_t mimo_locked = usrp->get_mboard_sensor("mimo_locked", 0); + std::cout << boost::format("Checking RX: %s ...") % mimo_locked.to_pp_string() + << std::endl; UHD_ASSERT_THROW(mimo_locked.to_bool()); } - if ((ref == "external") and (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); - std::cout << boost::format("Checking RX: %s ...") % ref_locked.to_pp_string() << std::endl; + if ((ref == "external") + and (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); + std::cout << boost::format("Checking RX: %s ...") % ref_locked.to_pp_string() + << std::endl; UHD_ASSERT_THROW(ref_locked.to_bool()); } - //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); - //setup streaming + // setup streaming uhd::stream_cmd_t stream_cmd(uhd::stream_cmd_t::STREAM_MODE_NUM_SAMPS_AND_DONE); - stream_cmd.num_samps = total_num_samps; + stream_cmd.num_samps = total_num_samps; stream_cmd.stream_now = true; rx_stream->issue_stream_cmd(stream_cmd); - //loop until total number of samples reached - size_t num_acc_samps = 0; //number of accumulated samples + // loop until total number of samples reached + size_t num_acc_samps = 0; // number of accumulated samples uhd::rx_metadata_t md; - std::vector<std::complex<float> > buff(rx_stream->get_max_num_samps()); - uhd::transport::udp_simple::sptr udp_xport = uhd::transport::udp_simple::make_connected(addr, port); - - while(num_acc_samps < total_num_samps){ - size_t num_rx_samps = rx_stream->recv( - &buff.front(), buff.size(), md - ); - - //handle the error codes - switch(md.error_code){ - case uhd::rx_metadata_t::ERROR_CODE_NONE: - break; - - case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT: - if (num_acc_samps == 0) continue; - std::cout << boost::format( - "Got timeout before all samples received, possible packet loss, exiting loop..." - ) << std::endl; - goto done_loop; - - default: - std::cout << boost::format( - "Got error code 0x%x, exiting loop..." - ) % md.error_code << std::endl; - goto done_loop; + std::vector<std::complex<float>> buff(rx_stream->get_max_num_samps()); + uhd::transport::udp_simple::sptr udp_xport = + uhd::transport::udp_simple::make_connected(addr, port); + + while (num_acc_samps < total_num_samps) { + size_t num_rx_samps = rx_stream->recv(&buff.front(), buff.size(), md); + + // handle the error codes + switch (md.error_code) { + case uhd::rx_metadata_t::ERROR_CODE_NONE: + break; + + case uhd::rx_metadata_t::ERROR_CODE_TIMEOUT: + if (num_acc_samps == 0) + continue; + std::cout << boost::format("Got timeout before all samples received, " + "possible packet loss, exiting loop...") + << std::endl; + goto done_loop; + + default: + std::cout << boost::format("Got error code 0x%x, exiting loop...") + % md.error_code + << std::endl; + goto done_loop; } - //send complex single precision floating point samples over udp - udp_xport->send(boost::asio::buffer(buff, num_rx_samps*sizeof(buff.front()))); + // send complex single precision floating point samples over udp + udp_xport->send(boost::asio::buffer(buff, num_rx_samps * sizeof(buff.front()))); num_acc_samps += num_rx_samps; - } done_loop: + } +done_loop: - //finished + // finished std::cout << std::endl << "Done!" << std::endl << std::endl; return EXIT_SUCCESS; |