From 967be2a4e82b1a125b26bb72a60318a4fb2b50c4 Mon Sep 17 00:00:00 2001 From: Brent Stapleton Date: Mon, 14 Jan 2019 10:35:25 -0800 Subject: 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. --- host/utils/b2xx_fx3_utils.cpp | 342 +++++----- host/utils/converter_benchmark.cpp | 278 ++++---- host/utils/fx2_init_eeprom.cpp | 136 ++-- host/utils/latency/include/Responder.hpp | 538 ++++++++------- host/utils/latency/lib/Responder.cpp | 1089 +++++++++++++++--------------- host/utils/latency/responder.cpp | 47 +- host/utils/octoclock_burn_eeprom.cpp | 63 +- host/utils/query_gpsdo_sensors.cpp | 459 +++++++------ host/utils/uhd_cal_rx_iq_balance.cpp | 215 +++--- host/utils/uhd_cal_tx_dc_offset.cpp | 222 +++--- host/utils/uhd_cal_tx_iq_balance.cpp | 222 +++--- host/utils/uhd_config_info.cpp | 40 +- host/utils/uhd_find_devices.cpp | 56 +- host/utils/uhd_image_loader.cpp | 86 +-- host/utils/uhd_usrp_probe.cpp | 327 +++++---- host/utils/usrp_burn_db_eeprom.cpp | 60 +- host/utils/usrp_burn_mb_eeprom.cpp | 60 +- host/utils/usrp_cal_utils.hpp | 267 ++++---- host/utils/usrp_e3x0_network_mode.cpp | 31 +- 19 files changed, 2351 insertions(+), 2187 deletions(-) (limited to 'host/utils') diff --git a/host/utils/b2xx_fx3_utils.cpp b/host/utils/b2xx_fx3_utils.cpp index 75bb1a5bb..e723b904a 100644 --- a/host/utils/b2xx_fx3_utils.cpp +++ b/host/utils/b2xx_fx3_utils.cpp @@ -5,50 +5,47 @@ // SPDX-License-Identifier: GPL-3.0-or-later // +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include -#include -#include #include -#include +#include +#include #include #include -#include -#include -#include #include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include - namespace po = boost::program_options; namespace fs = boost::filesystem; -struct vid_pid_t { +struct vid_pid_t +{ uint16_t vid; uint16_t pid; }; -const static vid_pid_t known_vid_pids[] = { - {FX3_VID, FX3_DEFAULT_PID}, +const static vid_pid_t known_vid_pids[] = {{FX3_VID, FX3_DEFAULT_PID}, {FX3_VID, FX3_REENUM_PID}, {B200_VENDOR_ID, B200_PRODUCT_ID}, {B200_VENDOR_ID, B200MINI_PRODUCT_ID}, {B200_VENDOR_ID, B205MINI_PRODUCT_ID}, {B200_VENDOR_NI_ID, B200_PRODUCT_NI_ID}, - {B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID} -}; -const static std::vector known_vid_pid_vector(known_vid_pids, known_vid_pids + (sizeof(known_vid_pids) / sizeof(known_vid_pids[0]))); + {B200_VENDOR_NI_ID, B210_PRODUCT_NI_ID}}; +const static std::vector known_vid_pid_vector(known_vid_pids, + known_vid_pids + (sizeof(known_vid_pids) / sizeof(known_vid_pids[0]))); static const size_t EEPROM_INIT_VALUE_VECTOR_SIZE = 8; static uhd::byte_vector_t construct_eeprom_init_value_vector(uint16_t vid, uint16_t pid) @@ -65,19 +62,25 @@ static uhd::byte_vector_t construct_eeprom_init_value_vector(uint16_t vid, uint1 return init_values; } -//!used with lexical cast to parse a hex string -template struct to_hex{ +//! used with lexical cast to parse a hex string +template struct to_hex +{ T value; - operator T() const {return value;} - friend std::istream& operator>>(std::istream& in, to_hex& out){ + operator T() const + { + return value; + } + friend std::istream& operator>>(std::istream& in, to_hex& out) + { in >> std::hex >> out.value; return in; } }; -//!parse hex-formatted ASCII text into an int -uint16_t atoh(const std::string &string){ - if (string.substr(0, 2) == "0x"){ +//! parse hex-formatted ASCII text into an int +uint16_t atoh(const std::string& string) +{ + if (string.substr(0, 2) == "0x") { std::stringstream interpreter(string); to_hex hh; interpreter >> hh; @@ -98,42 +101,39 @@ int reset_usb() /* Check each of the possible paths above to find which ones this system * uses. */ - for(std::set::iterator found = path_list.begin(); - found != path_list.end(); ++found) { - - if(fs::exists(*found)) { - + for (std::set::iterator found = path_list.begin(); found != path_list.end(); + ++found) { + if (fs::exists(*found)) { fs::path devpath = *found; std::set globbed; /* Now, glob all of the files in the directory. */ fs::directory_iterator end_itr; - for(fs::directory_iterator itr(devpath); itr != end_itr; ++itr) { + for (fs::directory_iterator itr(devpath); itr != end_itr; ++itr) { globbed.insert((*itr).path()); } /* Check each file path string to see if it is a device file. */ - for(std::set::iterator it = globbed.begin(); - it != globbed.end(); ++it) { - + for (std::set::iterator it = globbed.begin(); it != globbed.end(); + ++it) { std::string file = fs::path((*it).filename()).string(); if (file.length() < 5) continue; - if(file.compare(0, 5, "0000:") == 0) { + if (file.compare(0, 5, "0000:") == 0) { /* Un-bind the device. */ - std::fstream unbind((devpath.string() + "unbind").c_str(), - std::fstream::out); + std::fstream unbind( + (devpath.string() + "unbind").c_str(), std::fstream::out); unbind << file; unbind.close(); /* Re-bind the device. */ - std::cout << "Re-binding: " << file << " in " - << devpath.string() << std::endl; - std::fstream bind((devpath.string() + "bind").c_str(), - std::fstream::out); + std::cout << "Re-binding: " << file << " in " << devpath.string() + << std::endl; + std::fstream bind( + (devpath.string() + "bind").c_str(), std::fstream::out); bind << file; bind.close(); } @@ -144,7 +144,8 @@ int reset_usb() return 0; } -uhd::transport::usb_device_handle::sptr open_device(const uint16_t vid, const uint16_t pid, const bool user_supplied = false) +uhd::transport::usb_device_handle::sptr open_device( + const uint16_t vid, const uint16_t pid, const bool user_supplied = false) { std::vector handles; uhd::transport::usb_device_handle::sptr handle; @@ -152,60 +153,70 @@ uhd::transport::usb_device_handle::sptr open_device(const uint16_t vid, const ui try { // try caller's VID/PID first - std::vector vid_pid_pair_list(1,uhd::transport::usb_device_handle::vid_pid_pair_t(vid,pid)); + std::vector vid_pid_pair_list( + 1, uhd::transport::usb_device_handle::vid_pid_pair_t(vid, pid)); handles = uhd::transport::usb_device_handle::get_device_list(vid_pid_pair_list); - if (handles.size() == 0) - { - if (user_supplied) - { - std::cerr << (boost::format("Failed to open device with VID 0x%04x and PID 0x%04x - trying other known VID/PIDs") % vid % pid).str() << std::endl; + if (handles.size() == 0) { + if (user_supplied) { + std::cerr << (boost::format("Failed to open device with VID 0x%04x and " + "PID 0x%04x - trying other known VID/PIDs") + % vid % pid) + .str() + << std::endl; } // try known VID/PIDs next - for (size_t i = 0; handles.size() == 0 && i < known_vid_pid_vector.size(); i++) - { + for (size_t i = 0; handles.size() == 0 && i < known_vid_pid_vector.size(); + i++) { vp = known_vid_pid_vector[i]; - handles = uhd::transport::usb_device_handle::get_device_list(vp.vid, vp.pid); + handles = + uhd::transport::usb_device_handle::get_device_list(vp.vid, vp.pid); } - } - if (handles.size() > 0) - { + if (handles.size() > 0) { handle = handles[0]; - std::cout << (boost::format("Device opened (VID=0x%04x,PID=0x%04x)") % vp.vid % vp.pid).str() << std::endl; + std::cout << (boost::format("Device opened (VID=0x%04x,PID=0x%04x)") % vp.vid + % vp.pid) + .str() + << std::endl; } if (!handle) std::cerr << "Cannot open device" << std::endl; - } - catch(const std::exception &) { + } catch (const std::exception&) { std::cerr << "Failed to communicate with the device!" << std::endl; - #ifdef UHD_PLATFORM_WIN32 - std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details:\nhttp://files.ettus.com/manual/page_transport.html" << std::endl; - #endif /* UHD_PLATFORM_WIN32 */ +#ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport " + "Application Notes for " + "details:\nhttp://files.ettus.com/manual/page_transport.html" + << std::endl; +#endif /* UHD_PLATFORM_WIN32 */ handle.reset(); } return handle; } -b200_iface::sptr make_b200_iface(const uhd::transport::usb_device_handle::sptr &handle) +b200_iface::sptr make_b200_iface(const uhd::transport::usb_device_handle::sptr& handle) { b200_iface::sptr b200; try { - uhd::transport::usb_control::sptr usb_ctrl = uhd::transport::usb_control::make(handle, 0); + uhd::transport::usb_control::sptr usb_ctrl = + uhd::transport::usb_control::make(handle, 0); b200 = b200_iface::make(usb_ctrl); if (!b200) std::cerr << "Cannot create device interface" << std::endl; - } - catch(const std::exception &) { + } catch (const std::exception&) { std::cerr << "Failed to communicate with the device!" << std::endl; - #ifdef UHD_PLATFORM_WIN32 - std::cerr << "The necessary drivers are not installed. Read the UHD Transport Application Notes for details:\nhttp://files.ettus.com/manual/page_transport.html" << std::endl; - #endif /* UHD_PLATFORM_WIN32 */ +#ifdef UHD_PLATFORM_WIN32 + std::cerr << "The necessary drivers are not installed. Read the UHD Transport " + "Application Notes for " + "details:\nhttp://files.ettus.com/manual/page_transport.html" + << std::endl; +#endif /* UHD_PLATFORM_WIN32 */ b200.reset(); } @@ -216,7 +227,7 @@ int read_eeprom(b200_iface::sptr& b200, uhd::byte_vector_t& data) { try { data = b200->read_eeprom(0x0, 0x0, 8); - } catch (std::exception &e) { + } catch (std::exception& e) { std::cerr << "Exception while reading EEPROM: " << e.what() << std::endl; return -1; } @@ -227,8 +238,8 @@ int read_eeprom(b200_iface::sptr& b200, uhd::byte_vector_t& data) int write_eeprom(b200_iface::sptr& b200, const uhd::byte_vector_t& data) { try { - b200->write_eeprom(0x0, 0x0, data); - } catch (std::exception &e) { + b200->write_eeprom(0x0, 0x0, data); + } catch (std::exception& e) { std::cerr << "Exception while writing EEPROM: " << e.what() << std::endl; return -1; } @@ -243,16 +254,17 @@ int verify_eeprom(b200_iface::sptr& b200, const uhd::byte_vector_t& data) if (read_eeprom(b200, read_bytes)) return -1; - if (data.size() != read_bytes.size()) - { - std::cerr << "ERROR: Only able to verify first " << std::min(data.size(), read_bytes.size()) << " bytes." << std::endl; + if (data.size() != read_bytes.size()) { + std::cerr << "ERROR: Only able to verify first " + << std::min(data.size(), read_bytes.size()) << " bytes." << std::endl; verified = false; } for (size_t i = 0; i < std::min(data.size(), read_bytes.size()); i++) { if (data[i] != read_bytes[i]) { verified = false; - std::cerr << "Byte " << i << " Expected: " << data[i] << ", Got: " << read_bytes[i] << std::endl; + std::cerr << "Byte " << i << " Expected: " << data[i] + << ", Got: " << read_bytes[i] << std::endl; } } @@ -285,39 +297,32 @@ int erase_eeprom(b200_iface::sptr& b200) return 0; } -int32_t main(int32_t argc, char *argv[]) { +int32_t main(int32_t argc, char* argv[]) +{ uint16_t vid, pid; std::string pid_str, vid_str, fw_file, fpga_file, writevid_str, writepid_str; bool user_supplied_vid_pid = false; po::options_description visible("Allowed options"); - visible.add_options() - ("help,h", "help message") - ("vid,v", po::value(&vid_str), - "Specify VID of device to use.") - ("pid,p", po::value(&pid_str), - "Specify PID of device to use.") - ("speed,S", "Read back the USB mode currently in use.") - ("reset-device,D", "Reset the B2xx Device.") - ("reset-fpga,F", "Reset the FPGA (does not require re-programming.") - ("reset-usb,U", "Reset the USB subsystem on your host computer.") - ("load-fw,W", po::value(&fw_file), - "Load a firmware (hex) file into the FX3.") - ("load-fpga,L", po::value(&fpga_file), - "Load a FPGA (bin) file into the FPGA.") - ; + visible.add_options()("help,h", "help message")( + "vid,v", po::value(&vid_str), "Specify VID of device to use.")( + "pid,p", po::value(&pid_str), "Specify PID of device to use.")( + "speed,S", "Read back the USB mode currently in use.")( + "reset-device,D", "Reset the B2xx Device.")( + "reset-fpga,F", "Reset the FPGA (does not require re-programming.")( + "reset-usb,U", "Reset the USB subsystem on your host computer.")("load-fw,W", + po::value(&fw_file), + "Load a firmware (hex) file into the FX3.")("load-fpga,L", + po::value(&fpga_file), + "Load a FPGA (bin) file into the FPGA."); // Hidden options provided for testing - use at your own risk! po::options_description hidden("Hidden options"); - hidden.add_options() - ("init-device,I", "Initialize a B2xx device.") - ("uninit-device", "Uninitialize a B2xx device.") - ("read-eeprom,R", "Read first 8 bytes of EEPROM") - ("erase-eeprom,E", "Erase first 8 bytes of EEPROM") - ("write-vid", po::value(&writevid_str), - "Write VID field of EEPROM") - ("write-pid", po::value(&writepid_str), - "Write PID field of EEPROM"); + hidden.add_options()("init-device,I", "Initialize a B2xx device.")("uninit-device", + "Uninitialize a B2xx device.")("read-eeprom,R", "Read first 8 bytes of EEPROM")( + "erase-eeprom,E", "Erase first 8 bytes of EEPROM")( + "write-vid", po::value(&writevid_str), "Write VID field of EEPROM")( + "write-pid", po::value(&writepid_str), "Write PID field of EEPROM"); po::options_description desc; desc.add(visible); @@ -328,16 +333,17 @@ int32_t main(int32_t argc, char *argv[]) { try { po::store(po::parse_command_line(argc, argv, desc), vm); po::notify(vm); - } catch (std::exception &e) { + } catch (std::exception& e) { std::cerr << "Exception while parsing arguments: " << e.what() << std::endl; std::cout << boost::format("B2xx Utility Program %s") % visible << std::endl; return ~0; } - if (vm.count("help")){ + if (vm.count("help")) { try { std::cout << boost::format("B2xx Utility Program %s") % visible << std::endl; - } catch(...) {} + } catch (...) { + } return ~0; } @@ -348,15 +354,14 @@ int32_t main(int32_t argc, char *argv[]) { uhd::transport::usb_device_handle::sptr handle; b200_iface::sptr b200; - vid = B200_VENDOR_ID; // Default - pid = B200_PRODUCT_ID; // Default - if (vm.count("vid") && vm.count("pid")) - { + vid = B200_VENDOR_ID; // Default + pid = B200_PRODUCT_ID; // Default + if (vm.count("vid") && vm.count("pid")) { try { vid = atoh(vid_str); pid = atoh(pid_str); - } catch (std::exception &e) { - std::cerr << "Exception while parsing VID and PID: " << e.what() << std:: endl; + } catch (std::exception& e) { + std::cerr << "Exception while parsing VID and PID: " << e.what() << std::endl; return ~0; } user_supplied_vid_pid = true; @@ -374,14 +379,13 @@ int32_t main(int32_t argc, char *argv[]) { return -1; std::cout << " Control of B2xx granted..." << std::endl << std::endl; - // if we are supposed to load a new firmware image and one already exists, reset the FX3 so we can load the new one - if (vm.count("load-fw") && handle->firmware_loaded()) - { + // if we are supposed to load a new firmware image and one already exists, reset the + // FX3 so we can load the new one + if (vm.count("load-fw") && handle->firmware_loaded()) { std::cout << "Overwriting existing firmware" << std::endl; // before we reset, make sure we have a good firmware file - if(!(fs::exists(fw_file))) - { + if (!(fs::exists(fw_file))) { std::cerr << "Invalid firmware filepath: " << fw_file << std::endl; return -1; } @@ -389,14 +393,15 @@ int32_t main(int32_t argc, char *argv[]) { // reset the device try { b200->reset_fx3(); - } catch (std::exception &e) { + } catch (std::exception& e) { std::cerr << "Exception while reseting FX3: " << e.what() << std::endl; } // re-open device b200.reset(); handle.reset(); - std::this_thread::sleep_for(std::chrono::seconds(2)); // wait 2 seconds for FX3 to reset + std::this_thread::sleep_for( + std::chrono::seconds(2)); // wait 2 seconds for FX3 to reset handle = open_device(vid, pid); if (!handle) return -1; @@ -406,19 +411,18 @@ int32_t main(int32_t argc, char *argv[]) { } // Check to make sure firmware is loaded - if (!(handle->firmware_loaded())) - { + if (!(handle->firmware_loaded())) { std::cout << "Loading firmware" << std::endl; if (fw_file.empty()) fw_file = uhd::find_image_path(B200_FW_FILE_NAME); - if(fw_file.empty()) { + if (fw_file.empty()) { std::cerr << "Firmware image not found!" << std::endl; return -1; } - if(!(fs::exists(fw_file))) { + if (!(fs::exists(fw_file))) { std::cerr << "Invalid filepath: " << fw_file << std::endl; return -1; } @@ -426,7 +430,7 @@ int32_t main(int32_t argc, char *argv[]) { // load firmware try { b200->load_firmware(fw_file); - } catch (std::exception &e) { + } catch (std::exception& e) { std::cerr << "Exception while loading firmware: " << e.what() << std::endl; return ~0; } @@ -445,8 +449,7 @@ int32_t main(int32_t argc, char *argv[]) { } // Added for testing purposes - not exposed - if (vm.count("read-eeprom")) - { + if (vm.count("read-eeprom")) { uhd::byte_vector_t data; if (read_eeprom(b200, data)) @@ -459,8 +462,7 @@ int32_t main(int32_t argc, char *argv[]) { } // Added for testing purposes - not exposed - if (vm.count("erase-eeprom")) - { + if (vm.count("erase-eeprom")) { if (erase_eeprom(b200)) return -1; @@ -470,90 +472,90 @@ int32_t main(int32_t argc, char *argv[]) { } // Added for testing purposes - not exposed - if (vm.count("uninit-device")) - { + if (vm.count("uninit-device")) { // erase EEPROM erase_eeprom(b200); - std::cout << "EEPROM uninitialized, resetting device..." - << std::endl << std::endl; + std::cout << "EEPROM uninitialized, resetting device..." << std::endl + << std::endl; // reset the device try { b200->reset_fx3(); - } catch (uhd::exception &e) { + } catch (uhd::exception& e) { std::cerr << "Exception while resetting FX3: " << e.what() << std::endl; return -1; } - std::cout << "Uninitialization Process Complete." - << std::endl << std::endl; + std::cout << "Uninitialization Process Complete." << std::endl << std::endl; return 0; } /* If we are initializing the device, the VID/PID should default to the * Cypress VID/PID for the initial FW load, but we can initialize from any state. */ - if (vm.count("init-device")) - { + if (vm.count("init-device")) { uint16_t writevid = B200_VENDOR_ID; uint16_t writepid = B200_PRODUCT_ID; /* Now, initialize the device. */ - // Added for testing purposes - not exposed - if (vm.count("write-vid") && vm.count("write-pid")) - { + // Added for testing purposes - not exposed + if (vm.count("write-vid") && vm.count("write-pid")) { try { - writevid = atoh(writevid_str); - writepid = atoh(writepid_str); - } catch (std::exception &e) { - std::cerr << "Exception while parsing write VID and PID: " << e.what() << std:: endl; - return ~0; + writevid = atoh(writevid_str); + writepid = atoh(writepid_str); + } catch (std::exception& e) { + std::cerr << "Exception while parsing write VID and PID: " << e.what() + << std::endl; + return ~0; } } std::cout << "Writing VID and PID to EEPROM..." << std::endl << std::endl; - if (write_and_verify_eeprom(b200, construct_eeprom_init_value_vector(writevid, writepid))) return -1; + if (write_and_verify_eeprom( + b200, construct_eeprom_init_value_vector(writevid, writepid))) + return -1; - std::cout << "EEPROM initialized, resetting device..." - << std::endl << std::endl; + std::cout << "EEPROM initialized, resetting device..." << std::endl << std::endl; /* Reset the device! */ try { b200->reset_fx3(); - } catch (const std::exception &e) { + } catch (const std::exception& e) { std::cerr << "Exception while resetting device: " << e.what() << std::endl; return -1; } - std::cout << "Initialization Process Complete." - << std::endl << std::endl; + std::cout << "Initialization Process Complete." << std::endl << std::endl; return 0; } uint8_t data_buffer[16]; memset(data_buffer, 0x0, sizeof(data_buffer)); - if (vm.count("speed")){ + if (vm.count("speed")) { uint8_t speed; - try {speed = b200->get_usb_speed();} - catch (uhd::exception &e) { + try { + speed = b200->get_usb_speed(); + } catch (uhd::exception& e) { std::cerr << "Exception while getting USB speed: " << e.what() << std::endl; return -1; } - std::cout << "Currently operating at USB " << (int) speed << std::endl; + std::cout << "Currently operating at USB " << (int)speed << std::endl; } if (vm.count("reset-device")) { - try {b200->reset_fx3();} - catch (uhd::exception &e) { + try { + b200->reset_fx3(); + } catch (uhd::exception& e) { std::cerr << "Exception while resetting FX3: " << e.what() << std::endl; return -1; } } else if (vm.count("reset-fpga")) { - try {b200->set_fpga_reset_pin(true);} - catch (uhd::exception &e) { + try { + b200->set_fpga_reset_pin(true); + } catch (uhd::exception& e) { std::cerr << "Exception while resetting FPGA: " << e.what() << std::endl; return -1; } @@ -561,24 +563,24 @@ int32_t main(int32_t argc, char *argv[]) { } else if (vm.count("load-fpga")) { std::cout << "Loading FPGA image (" << fpga_file << ")" << std::endl; uint32_t fx3_state; - try {fx3_state = b200->load_fpga(fpga_file);} // returns 0 on success, or FX3 state on error - catch (uhd::exception &e) { + try { + fx3_state = b200->load_fpga(fpga_file); + } // returns 0 on success, or FX3 state on error + catch (uhd::exception& e) { std::cerr << "Exception while loading FPGA: " << e.what() << std::endl; return ~0; } if (fx3_state != 0) { - std::cerr << std::flush << "Error loading FPGA. FX3 state (" - << fx3_state << "): " << b200_iface::fx3_state_string(fx3_state) << std::endl; + std::cerr << std::flush << "Error loading FPGA. FX3 state (" << fx3_state + << "): " << b200_iface::fx3_state_string(fx3_state) << std::endl; return ~0; } - std::cout << "FPGA load complete, releasing USB interface..." - << std::endl; + std::cout << "FPGA load complete, releasing USB interface..." << std::endl; } std::cout << "Operation complete! I did it! I did it!" << std::endl; return 0; } - diff --git a/host/utils/converter_benchmark.cpp b/host/utils/converter_benchmark.cpp index cb8cce519..07aec9170 100644 --- a/host/utils/converter_benchmark.cpp +++ b/host/utils/converter_benchmark.cpp @@ -5,32 +5,30 @@ // SPDX-License-Identifier: GPL-3.0-or-later // -#include -#include #include #include -#include +#include +#include +#include +#include #include -#include #include -#include -#include +#include +#include +#include #include +#include #include -#include -#include namespace po = boost::program_options; using namespace uhd::convert; -enum buf_init_t { - RANDOM, INC -}; +enum buf_init_t { RANDOM, INC }; // Convert `sc16_item32_le' -> `sc16' // Finds the first _ in format and returns the string // until then. Returns the entire string if no _ is found. -std::string format_to_type(const std::string &format) +std::string format_to_type(const std::string& format) { std::string ret_val = ""; for (size_t i = 0; i < format.length(); i++) { @@ -44,10 +42,8 @@ std::string format_to_type(const std::string &format) } void configure_conv( - converter::sptr conv, - const std::string &in_type, - const std::string &out_type -) { + converter::sptr conv, const std::string& in_type, const std::string& out_type) +{ if (in_type == "sc16") { if (out_type == "fc32") { std::cout << "Setting scalar to 32767." << std::endl; @@ -68,21 +64,19 @@ void configure_conv( } template -void init_random_vector_complex_float(std::vector &buf_ptr, const size_t n_items) +void init_random_vector_complex_float(std::vector& buf_ptr, const size_t n_items) { - std::complex * const buf = reinterpret_cast * const>(&buf_ptr[0]); + std::complex* const buf = reinterpret_cast* const>(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = std::complex( - T(std::rand()/(RAND_MAX/2.0) - 1), - T(std::rand()/(RAND_MAX/2.0) - 1) - ); + T(std::rand() / (RAND_MAX / 2.0) - 1), T(std::rand() / (RAND_MAX / 2.0) - 1)); } } template -void init_random_vector_complex_int(std::vector &buf_ptr, const size_t n_items) +void init_random_vector_complex_int(std::vector& buf_ptr, const size_t n_items) { - std::complex * const buf = reinterpret_cast * const>(&buf_ptr[0]); + std::complex* const buf = reinterpret_cast* const>(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = std::complex(T(std::rand()), T(std::rand())); } @@ -96,45 +90,45 @@ struct item32_sc12_3x }; template -void init_random_vector_complex_sc12(std::vector &buf_ptr, const size_t n_items) +void init_random_vector_complex_sc12(std::vector& buf_ptr, const size_t n_items) { - item32_sc12_3x *const buf = reinterpret_cast(&buf_ptr[0]); - if (n_items % 4) throw std::invalid_argument(""); + item32_sc12_3x* const buf = reinterpret_cast(&buf_ptr[0]); + if (n_items % 4) + throw std::invalid_argument(""); for (size_t i = 0; i < n_items / 4; i++) { int16_t iq[8]; - for (auto &k : iq) k = rand() & 0xfff; - buf[i].line0 = iq[0] << 20 | iq[1] << 8 | iq[2] >> 4; + for (auto& k : iq) + k = rand() & 0xfff; + buf[i].line0 = iq[0] << 20 | iq[1] << 8 | iq[2] >> 4; buf[i].line1 = iq[2] << 28 | iq[3] << 16 | iq[4] << 4 | iq[5] >> 8; buf[i].line2 = iq[5] << 24 | iq[6] << 12 | iq[7] << 0; } } template -void init_random_vector_real_int(std::vector &buf_ptr, size_t n_items) +void init_random_vector_real_int(std::vector& buf_ptr, size_t n_items) { - T * const buf = reinterpret_cast(&buf_ptr[0]); + T* const buf = reinterpret_cast(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = T(std::rand()); } } // Fill a buffer with increasing numbers -template -void init_inc_vector(std::vector &buf_ptr, size_t n_items) +template void init_inc_vector(std::vector& buf_ptr, size_t n_items) { - T * const buf = reinterpret_cast(&buf_ptr[0]); + T* const buf = reinterpret_cast(&buf_ptr[0]); for (size_t i = 0; i < n_items; i++) { buf[i] = T(i); } } -void init_buffers( - std::vector< std::vector > &buf, - const std::string &type, - size_t bytes_per_item, - buf_init_t buf_seed_mode -) { +void init_buffers(std::vector>& buf, + const std::string& type, + size_t bytes_per_item, + buf_init_t buf_seed_mode) +{ if (buf.empty()) { return; } @@ -144,26 +138,25 @@ void init_buffers( if (buf_seed_mode == INC) { for (size_t i = 0; i < buf.size(); i++) { if (type == "sc8") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "sc16") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "sc32") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "fc32") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "fc64") { - init_inc_vector< std::complex >(buf[i], n_items); + init_inc_vector>(buf[i], n_items); } else if (type == "s8") { - init_inc_vector< int8_t >(buf[i], n_items); + init_inc_vector(buf[i], n_items); } else if (type == "s16") { - init_inc_vector< int16_t >(buf[i], n_items); + init_inc_vector(buf[i], n_items); } else if (type == "item32") { - init_inc_vector< uint32_t >(buf[i], n_items); + init_inc_vector(buf[i], n_items); init_random_vector_real_int(buf[i], n_items); } else { - throw uhd::runtime_error(str( - boost::format("Cannot handle data type: %s") % type - )); + throw uhd::runtime_error( + str(boost::format("Cannot handle data type: %s") % type)); } } @@ -193,21 +186,19 @@ void init_buffers( } else if (type == "item32") { init_random_vector_real_int(buf[i], n_items); } else { - throw uhd::runtime_error(str( - boost::format("Cannot handle data type: %s") % type - )); + throw uhd::runtime_error( + str(boost::format("Cannot handle data type: %s") % type)); } } } // Returns time elapsed -double run_benchmark( - converter::sptr conv, - const std::vector &input_buf_refs, - const std::vector &output_buf_refs, - size_t n_items, - size_t iterations -) { +double run_benchmark(converter::sptr conv, + const std::vector& input_buf_refs, + const std::vector& output_buf_refs, + size_t n_items, + size_t iterations) +{ boost::timer benchmark_timer; for (size_t i = 0; i < iterations; i++) { conv->conv(input_buf_refs, output_buf_refs, n_items); @@ -215,71 +206,58 @@ double run_benchmark( return benchmark_timer.elapsed(); } -template -std::string void_ptr_to_hexstring(const void *v_ptr, size_t index) +template std::string void_ptr_to_hexstring(const void* v_ptr, size_t index) { - const T *ptr = reinterpret_cast(v_ptr); + const T* ptr = reinterpret_cast(v_ptr); return str(boost::format("%X") % ptr[index]); } -std::string item_to_hexstring( - const void *v_ptr, - size_t index, - const std::string &type -) { +std::string item_to_hexstring(const void* v_ptr, size_t index, const std::string& type) +{ if (type == "fc32") { return void_ptr_to_hexstring(v_ptr, index); - } - else if (type == "sc16" || type == "item32") { + } else if (type == "sc16" || type == "item32") { return void_ptr_to_hexstring(v_ptr, index); - } - else if (type == "sc8" || type == "s16") { + } else if (type == "sc8" || type == "s16") { return void_ptr_to_hexstring(v_ptr, index); - } - else if (type == "u8") { + } else if (type == "u8") { return void_ptr_to_hexstring(v_ptr, index); - } - else { + } else { return str(boost::format("") % type); } } std::string item_to_string( - const void *v_ptr, - size_t index, - const std::string &type, - const bool print_hex -) { + const void* v_ptr, size_t index, const std::string& type, const bool print_hex) +{ if (print_hex) { return item_to_hexstring(v_ptr, index, type); } if (type == "sc16") { - const std::complex *ptr = reinterpret_cast *>(v_ptr); + const std::complex* ptr = + reinterpret_cast*>(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "sc8") { - const std::complex *ptr = reinterpret_cast *>(v_ptr); + } else if (type == "sc8") { + const std::complex* ptr = + reinterpret_cast*>(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "fc32") { - const std::complex *ptr = reinterpret_cast *>(v_ptr); + } else if (type == "fc32") { + const std::complex* ptr = + reinterpret_cast*>(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "item32") { - const uint32_t *ptr = reinterpret_cast(v_ptr); + } else if (type == "item32") { + const uint32_t* ptr = reinterpret_cast(v_ptr); return boost::lexical_cast(ptr[index]); - } - else if (type == "s16") { - const int16_t *ptr = reinterpret_cast(v_ptr); + } else if (type == "s16") { + const int16_t* ptr = reinterpret_cast(v_ptr); return boost::lexical_cast(ptr[index]); - } - else { + } else { return str(boost::format("") % type); } } -int UHD_SAFE_MAIN(int argc, char *argv[]) +int UHD_SAFE_MAIN(int argc, char* argv[]) { std::string in_format, out_format; std::string priorities; @@ -311,15 +289,19 @@ 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")){ - std::cout << boost::format("UHD Converter Benchmark Tool %s") % desc << std::endl << std::endl; - std::cout << " Use this to benchmark or debug converters." << std::endl - << " When using as a benchmark tool, it will output the execution time\n" - " for every conversion run in CSV format to stdout. Every line between\n" - " the output delimiters {{{ }}} is of the format: ,