From 708840002eef7104d930e2b25f0d9ca203c5d507 Mon Sep 17 00:00:00 2001 From: Brent Stapleton Date: Mon, 18 Nov 2019 14:39:12 +0530 Subject: uhd: fixing MSVC warnings Small changes to remove various compiler warnings found in MSVC - Adding uhd::narrow_cast to verious spots - wavetable.hpp: all floats literals in the wavetable. - paths_test: unnecessary character escape - replay example: remove unreferenced noc_id - adfXXXX: Fixing qualifiers to match between parent and derived classes - rpc, block_id: Removing unused name in try...catch --- host/examples/replay_samples_from_file.cpp | 2 +- host/examples/wavetable.hpp | 15 ++++++++------ host/include/uhd/rfnoc/traffic_counter.hpp | 5 ++++- host/lib/include/uhdlib/transport/udp_common.hpp | 6 ++++-- host/lib/include/uhdlib/usrp/common/adf435x.hpp | 8 ++++++-- host/lib/include/uhdlib/usrp/common/adf535x.hpp | 25 ++++++++++++++--------- host/lib/include/uhdlib/utils/isatty.hpp | 3 ++- host/lib/include/uhdlib/utils/rpc.hpp | 5 +++-- host/lib/rfnoc/block_id.cpp | 3 ++- host/lib/usrp/dboard/db_tvrx.cpp | 6 +++++- host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp | 5 ++++- host/lib/usrp/usrp2/clock_ctrl.cpp | 26 +++++++++++++----------- host/tests/paths_test.cpp | 3 ++- 13 files changed, 71 insertions(+), 41 deletions(-) diff --git a/host/examples/replay_samples_from_file.cpp b/host/examples/replay_samples_from_file.cpp index 1c0de27ba..c0443adfa 100644 --- a/host/examples/replay_samples_from_file.cpp +++ b/host/examples/replay_samples_from_file.cpp @@ -1,5 +1,6 @@ // // Copyright 2018 Ettus Research, A National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -203,7 +204,6 @@ int UHD_SAFE_MAIN(int argc, char* argv[]) /////////////////////////////////////////////////////////////////////////// // Setup streamer to Replay block - uint64_t noc_id; uhd::device_addr_t streamer_args; uhd::stream_args_t stream_args(cpu_format, wire_format); uhd::tx_streamer::sptr tx_stream; diff --git a/host/examples/wavetable.hpp b/host/examples/wavetable.hpp index 2a1d13f48..73401220f 100644 --- a/host/examples/wavetable.hpp +++ b/host/examples/wavetable.hpp @@ -1,6 +1,7 @@ // // Copyright 2010-2012,2014 Ettus Research LLC // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -23,19 +24,21 @@ public: std::vector real_wave_table(wave_table_len); if (wave_type == "CONST") { for (size_t i = 0; i < wave_table_len; i++) - real_wave_table[i] = 1.0; + real_wave_table[i] = 1.0f; } else if (wave_type == "SQUARE") { for (size_t i = 0; i < wave_table_len; i++) - real_wave_table[i] = (i < wave_table_len / 2) ? 0.0 : 1.0; + real_wave_table[i] = (i < wave_table_len / 2) ? 0.0f : 1.0f; } else if (wave_type == "RAMP") { for (size_t i = 0; i < wave_table_len; i++) - real_wave_table[i] = 2.0 * i / (wave_table_len - 1) - 1.0; + real_wave_table[i] = 2.0f * i / (wave_table_len - 1) - 1.0f; } else if (wave_type == "SINE") { static const double tau = 2 * std::acos(-1.0); - for (size_t i = 0; i < wave_table_len; i++) - real_wave_table[i] = std::sin((tau * i) / wave_table_len); - } else + for (size_t i = 0; i < wave_table_len; i++) { + real_wave_table[i] = static_cast(std::sin((tau * i) / wave_table_len)); + } + } else { throw std::runtime_error("unknown waveform type: " + wave_type); + } // compute i and q pairs with 90% offset and scale to amplitude for (size_t i = 0; i < wave_table_len; i++) { diff --git a/host/include/uhd/rfnoc/traffic_counter.hpp b/host/include/uhd/rfnoc/traffic_counter.hpp index 9a0546f17..b30eff329 100644 --- a/host/include/uhd/rfnoc/traffic_counter.hpp +++ b/host/include/uhd/rfnoc/traffic_counter.hpp @@ -1,5 +1,6 @@ // // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -8,6 +9,7 @@ #define INCLUDED_LIBUHD_TRAFFIC_COUNTER_HPP #include +#include #include #include #include @@ -57,7 +59,8 @@ public: for (size_t i = 0; i < std::extent::value; i++) { tree->create(root_path / "traffic_counter" / counters[i]) .set_publisher([this, i, first_counter_offset]() { - return _read_reg_fn(i + first_counter_offset); + return _read_reg_fn( + uhd::narrow_cast(i) + first_counter_offset); }); } } diff --git a/host/lib/include/uhdlib/transport/udp_common.hpp b/host/lib/include/uhdlib/transport/udp_common.hpp index 6c87ef498..c094fb142 100644 --- a/host/lib/include/uhdlib/transport/udp_common.hpp +++ b/host/lib/include/uhdlib/transport/udp_common.hpp @@ -1,6 +1,7 @@ // // Copyright 2011 Ettus Research LLC // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -14,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -110,7 +112,7 @@ UHD_INLINE size_t recv_udp_packet( #endif if (wait_for_recv_ready(sock_fd, timeout_ms)) { - len = ::recv(sock_fd, (char*)mem, frame_size, 0); + len = uhd::narrow_cast(::recv(sock_fd, (char*)mem, frame_size, 0)); if (len == 0) { throw uhd::io_error("socket closed"); } @@ -130,7 +132,7 @@ UHD_INLINE void send_udp_packet(int sock_fd, void* mem, size_t len) // This is known to occur at least on some OSX systems. // But it should be safe to always check for the error. while (true) { - const ssize_t ret = ::send(sock_fd, (const char*)mem, len, 0); + const ssize_t ret = uhd::narrow_cast(::send(sock_fd, (const char*)mem, len, 0)); if (ret == ssize_t(len)) break; if (ret == -1 and errno == ENOBUFS) { diff --git a/host/lib/include/uhdlib/usrp/common/adf435x.hpp b/host/lib/include/uhdlib/usrp/common/adf435x.hpp index 886c8d335..7989420dd 100644 --- a/host/lib/include/uhdlib/usrp/common/adf435x.hpp +++ b/host/lib/include/uhdlib/usrp/common/adf435x.hpp @@ -1,6 +1,7 @@ // // Copyright 2015 Ettus Research LLC // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -15,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -112,7 +114,8 @@ public: virtual void set_charge_pump_current(charge_pump_current_t cp_current) = 0; - virtual double set_charge_pump_current(double current, bool flush = false) = 0; + virtual double set_charge_pump_current( + const double current, const bool flush = false) = 0; virtual uhd::meta_range_t get_charge_pump_current_range() = 0; @@ -321,7 +324,8 @@ public: const auto cp_range = get_charge_pump_current_range(); const auto coerced_current = cp_range.clip(current, true); - const int current_step = std::round((coerced_current / cp_range.step()) - 1); + const int current_step = + uhd::narrow_cast(std::round((coerced_current / cp_range.step()) - 1)); UHD_ASSERT_THROW(current_step >= 0 and current_step < 16); set_charge_pump_current( diff --git a/host/lib/include/uhdlib/usrp/common/adf535x.hpp b/host/lib/include/uhdlib/usrp/common/adf535x.hpp index c42f05b57..6af8556be 100644 --- a/host/lib/include/uhdlib/usrp/common/adf535x.hpp +++ b/host/lib/include/uhdlib/usrp/common/adf535x.hpp @@ -1,5 +1,6 @@ // // Copyright 2015, 2017 Ettus Research, A National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -13,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -54,22 +56,24 @@ public: MUXOUT_DLD }; - virtual void set_reference_freq(double fref, bool force = false) = 0; + virtual void set_reference_freq(const double fref, const bool force = false) = 0; - virtual void set_pfd_freq(double pfd_freq) = 0; + virtual void set_pfd_freq(const double pfd_freq) = 0; - virtual void set_feedback_select(feedback_sel_t fb_sel) = 0; + virtual void set_feedback_select(const feedback_sel_t fb_sel) = 0; - virtual void set_output_power(output_power_t power) = 0; + virtual void set_output_power(const output_power_t power) = 0; - virtual void set_output_enable(output_t output, bool enable) = 0; + virtual void set_output_enable(const output_t output, const bool enable) = 0; - virtual void set_muxout_mode(muxout_t mode) = 0; + virtual void set_muxout_mode(const muxout_t mode) = 0; - virtual double set_frequency( - double target_freq, double freq_resolution, bool flush = false) = 0; + virtual double set_frequency(const double target_freq, + const double freq_resolution, + const bool flush = false) = 0; - virtual double set_charge_pump_current(double target_current, bool flush = false) = 0; + virtual double set_charge_pump_current( + const double target_current, const bool flush = false) = 0; virtual uhd::meta_range_t get_charge_pump_current_range() = 0; @@ -238,7 +242,8 @@ public: const auto cp_range = get_charge_pump_current_range(); const auto coerced_current = cp_range.clip(current, true); - const int current_step = std::round((coerced_current / cp_range.step()) - 1); + const int current_step = + uhd::narrow_cast(std::round((coerced_current / cp_range.step()) - 1)); UHD_ASSERT_THROW(current_step >= 0 and current_step < 16); _regs.charge_pump_current = diff --git a/host/lib/include/uhdlib/utils/isatty.hpp b/host/lib/include/uhdlib/utils/isatty.hpp index 1ae2c8de4..cb8d07afb 100644 --- a/host/lib/include/uhdlib/utils/isatty.hpp +++ b/host/lib/include/uhdlib/utils/isatty.hpp @@ -8,6 +8,7 @@ #define INCLUDED_UHDLIB_UTILS_ISATTY_HPP #include +#include namespace uhd { @@ -23,7 +24,7 @@ namespace uhd { */ bool is_a_tty(const int fd) { - return _isatty(fd); + return uhd::narrow_cast(_isatty(fd)); } #elif _POSIX_C_SOURCE >= _200112L diff --git a/host/lib/include/uhdlib/utils/rpc.hpp b/host/lib/include/uhdlib/utils/rpc.hpp index 066c6d144..6a45ba61f 100644 --- a/host/lib/include/uhdlib/utils/rpc.hpp +++ b/host/lib/include/uhdlib/utils/rpc.hpp @@ -1,5 +1,6 @@ // // Copyright 2017 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -305,9 +306,9 @@ private: } try { return _client->call(_get_last_error_cmd).as(); - } catch (const ::rpc::rpc_error& ex) { + } catch (const ::rpc::rpc_error&) { // nop - } catch (const std::bad_cast& ex) { + } catch (const std::bad_cast&) { // nop } catch (...) { // nop diff --git a/host/lib/rfnoc/block_id.cpp b/host/lib/rfnoc/block_id.cpp index db7ddb032..e4dc1832f 100644 --- a/host/lib/rfnoc/block_id.cpp +++ b/host/lib/rfnoc/block_id.cpp @@ -1,6 +1,7 @@ // // Copyright 2014 Ettus Research LLC // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -74,7 +75,7 @@ bool block_id_t::match(const std::string& block_str) and (matches[3] == "" or boost::lexical_cast(matches[3]) == _block_ctr) and not(matches[1] == "" and matches[2] == "" and matches[3] == ""); - } catch (const std::bad_cast& e) { + } catch (const std::bad_cast&) { return false; } return false; diff --git a/host/lib/usrp/dboard/db_tvrx.cpp b/host/lib/usrp/dboard/db_tvrx.cpp index 5235b1bfe..cd238ddc8 100644 --- a/host/lib/usrp/dboard/db_tvrx.cpp +++ b/host/lib/usrp/dboard/db_tvrx.cpp @@ -1,6 +1,7 @@ // // Copyright 2010-2012 Ettus Research LLC // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -26,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -264,7 +266,9 @@ static double gain_interp(double gain, const boost::array& db_vector uint8_t gain_step = 0; //find which bin we're in for(size_t i = 0; i < db_vector.size()-1; i++) { - if(gain >= db_vector[i] && gain <= db_vector[i+1]) gain_step = i; + if (gain >= db_vector[i] && gain <= db_vector[i+1]) { + gain_step = uhd::narrow_cast(i); + } } //find the current slope for linear interpolation diff --git a/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp b/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp index 91cfa22ca..85ed3ddb7 100644 --- a/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp +++ b/host/lib/usrp/dboard/twinrx/twinrx_ctrl.cpp @@ -1,5 +1,6 @@ // // Copyright 2015-2017 Ettus Research, A National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -8,6 +9,7 @@ #include "twinrx_ids.hpp" #include #include +#include #include #include #include @@ -41,7 +43,8 @@ public: { // SPI configuration _spi_config.use_custom_divider = true; - _spi_config.divider = std::ceil(_db_iface->get_codec_rate(dboard_iface::UNIT_TX) / TWINRX_SPI_CLOCK_FREQ); + _spi_config.divider = uhd::narrow_cast(std::ceil( + _db_iface->get_codec_rate(dboard_iface::UNIT_TX) / TWINRX_SPI_CLOCK_FREQ)); //Initialize dboard clocks bool found_rate = false; diff --git a/host/lib/usrp/usrp2/clock_ctrl.cpp b/host/lib/usrp/usrp2/clock_ctrl.cpp index c175a8c12..40f7c75f6 100644 --- a/host/lib/usrp/usrp2/clock_ctrl.cpp +++ b/host/lib/usrp/usrp2/clock_ctrl.cpp @@ -1,6 +1,7 @@ // // Copyright 2010-2012,2014 Ettus Research LLC // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, a National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -11,6 +12,7 @@ #include "usrp2_clk_regs.hpp" #include #include +#include #include #include #include @@ -96,8 +98,8 @@ public: ad9510_regs_t::POWER_DOWN_LVPECL_OUT2_SAFE_PD; _ad9510_regs.output_level_lvpecl_out2 = ad9510_regs_t::OUTPUT_LEVEL_LVPECL_OUT2_810MV; //set the registers (divider - 1) - _ad9510_regs.divider_low_cycles_out2 = low - 1; - _ad9510_regs.divider_high_cycles_out2 = high - 1; + _ad9510_regs.divider_low_cycles_out2 = uhd::narrow_cast(low - 1); + _ad9510_regs.divider_high_cycles_out2 = uhd::narrow_cast(high - 1); _ad9510_regs.bypass_divider_out2 = 0; break; @@ -106,8 +108,8 @@ public: _ad9510_regs.lvds_cmos_select_out5 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT5_LVDS; _ad9510_regs.output_level_lvds_out5 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT5_1_75MA; //set the registers (divider - 1) - _ad9510_regs.divider_low_cycles_out5 = low - 1; - _ad9510_regs.divider_high_cycles_out5 = high - 1; + _ad9510_regs.divider_low_cycles_out5 = uhd::narrow_cast(low - 1); + _ad9510_regs.divider_high_cycles_out5 = uhd::narrow_cast(high - 1); _ad9510_regs.bypass_divider_out5 = 0; break; @@ -116,8 +118,8 @@ public: _ad9510_regs.lvds_cmos_select_out6 = ad9510_regs_t::LVDS_CMOS_SELECT_OUT6_LVDS; _ad9510_regs.output_level_lvds_out6 = ad9510_regs_t::OUTPUT_LEVEL_LVDS_OUT6_1_75MA; //set the registers (divider - 1) - _ad9510_regs.divider_low_cycles_out6 = low - 1; - _ad9510_regs.divider_high_cycles_out6 = high - 1; + _ad9510_regs.divider_low_cycles_out6 = uhd::narrow_cast(low - 1); + _ad9510_regs.divider_high_cycles_out6 = uhd::narrow_cast(high - 1); _ad9510_regs.bypass_divider_out5 = 0; break; @@ -159,8 +161,8 @@ public: size_t high = divider/2; size_t low = divider - high; //set the registers (divider - 1) - _ad9510_regs.divider_low_cycles_out7 = low - 1; - _ad9510_regs.divider_high_cycles_out7 = high - 1; + _ad9510_regs.divider_low_cycles_out7 = uhd::narrow_cast(low - 1); + _ad9510_regs.divider_high_cycles_out7 = uhd::narrow_cast(high - 1); //write the registers this->write_reg(clk_regs.div_lo(clk_regs.rx_db)); this->write_reg(clk_regs.div_hi(clk_regs.rx_db)); @@ -217,15 +219,15 @@ public: switch(clk_regs.tx_db) { case 5: //USRP2+ _ad9510_regs.bypass_divider_out5 = (divider == 1)? 1 : 0; - _ad9510_regs.divider_low_cycles_out5 = low - 1; - _ad9510_regs.divider_high_cycles_out5 = high - 1; + _ad9510_regs.divider_low_cycles_out5 = uhd::narrow_cast(low - 1); + _ad9510_regs.divider_high_cycles_out5 = uhd::narrow_cast(high - 1); break; case 6: //USRP2 //bypass when the divider ratio is one _ad9510_regs.bypass_divider_out6 = (divider == 1)? 1 : 0; //set the registers (divider - 1) - _ad9510_regs.divider_low_cycles_out6 = low - 1; - _ad9510_regs.divider_high_cycles_out6 = high - 1; + _ad9510_regs.divider_low_cycles_out6 = uhd::narrow_cast(low - 1); + _ad9510_regs.divider_high_cycles_out6 = uhd::narrow_cast(high - 1); break; } diff --git a/host/tests/paths_test.cpp b/host/tests/paths_test.cpp index ef10414c7..6ff496eb6 100644 --- a/host/tests/paths_test.cpp +++ b/host/tests/paths_test.cpp @@ -1,5 +1,6 @@ // // Copyright 2018 Ettus Research, a National Instruments Company +// Copyright 2019 Ettus Research, A National Instruments Brand // // SPDX-License-Identifier: GPL-3.0-or-later // @@ -16,7 +17,7 @@ BOOST_AUTO_TEST_CASE(test_paths_expandvars) { #ifdef UHD_PLATFORM_WIN32 - const std::string path_to_expand("\%programdata%/uhd/uhd.conf"); + const std::string path_to_expand("%programdata%/uhd/uhd.conf"); #else const std::string path_to_expand("$HOME/.uhd/uhd.conf"); #endif -- cgit v1.2.3