From 9572b37da7bc60dc664775e4890d670bb1b6043f Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 14 Jul 2019 23:34:07 +0200 Subject: [PATCH] Remove uses of bitwise operations on signed integer types Based in the High Integrity C++ Standard, Section 5.6.1 See https://www.perforce.com/resources/qac/high-integrity-c-coding-standard-expressions Removed some c arrays by std::array --- .../acquisition/adapters/galileo_e5a_pcps_acquisition.cc | 2 +- src/algorithms/libs/beidou_b1i_signal_processing.cc | 4 ++-- src/algorithms/libs/beidou_b3i_signal_processing.cc | 9 ++++----- src/algorithms/libs/geofunctions.cc | 5 +++-- src/algorithms/libs/gps_l2c_signal.cc | 8 ++++---- src/algorithms/libs/gps_sdr_signal_processing.cc | 2 +- .../tracking/gnuradio_blocks/dll_pll_veml_tracking.cc | 6 ++++-- .../galileo_e1_tcp_connector_tracking_cc.cc | 6 +++--- .../gps_l1_ca_tcp_connector_tracking_cc.cc | 8 ++++---- 9 files changed, 26 insertions(+), 24 deletions(-) diff --git a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc index 7f8d72196..442c78e08 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc @@ -234,7 +234,7 @@ void GalileoE5aPcpsAcquisition::init() void GalileoE5aPcpsAcquisition::set_local_code() { std::unique_ptr> code{new std::complex[code_length_]}; - std::array signal_; + std::array signal_{}; signal_[0] = '5'; signal_[2] = '\0'; diff --git a/src/algorithms/libs/beidou_b1i_signal_processing.cc b/src/algorithms/libs/beidou_b1i_signal_processing.cc index 32caba650..7c883607c 100644 --- a/src/algorithms/libs/beidou_b1i_signal_processing.cc +++ b/src/algorithms/libs/beidou_b1i_signal_processing.cc @@ -70,8 +70,8 @@ void beidou_b1i_code_gen_int(gsl::span _dest, int32_t _prn, uint32_t _c G1[lcv] = G1_register[0]; G2[lcv] = G2_register[-(phase1[prn_idx] - 11)] ^ G2_register[-(phase2[prn_idx] - 11)]; - feedback1 = (G1_register[0] + G1_register[1] + G1_register[2] + G1_register[3] + G1_register[4] + G1_register[10]) & 0x1; - feedback2 = (G2_register[0] + G2_register[2] + G2_register[3] + G2_register[6] + G2_register[7] + G2_register[8] + G2_register[9] + G2_register[10]) & 0x1; + feedback1 = G1_register[0] xor G1_register[1] xor G1_register[2] xor G1_register[3] xor G1_register[4] xor G1_register[10]; + feedback2 = G2_register[0] xor G2_register[2] xor G2_register[3] xor G2_register[6] xor G2_register[7] xor G2_register[8] xor G2_register[9] xor G2_register[10]; for (lcv2 = 0; lcv2 < 10; lcv2++) { diff --git a/src/algorithms/libs/beidou_b3i_signal_processing.cc b/src/algorithms/libs/beidou_b3i_signal_processing.cc index fd2ec9bf4..a3a1cfbfb 100644 --- a/src/algorithms/libs/beidou_b3i_signal_processing.cc +++ b/src/algorithms/libs/beidou_b3i_signal_processing.cc @@ -129,10 +129,9 @@ void beidou_b3i_code_gen_int(gsl::span _dest, signed int _prn, unsigned int G2[lcv] = G2_register[0]; //feedback1 = (test_G1_register[0]+test_G1_register[2]+test_G1_register[3]+test_G1_register[12]) & 0x1; - feedback1 = (G1_register[0] + G1_register[9] + G1_register[10] + G1_register[12]) & 0x01; - feedback2 = (G2_register[0] + G2_register[1] + G2_register[3] + G2_register[4] + - G2_register[6] + G2_register[7] + G2_register[8] + G2_register[12]) & - 0x01; + feedback1 = G1_register[0] xor G1_register[9] xor G1_register[10] xor G1_register[12]; + feedback2 = G2_register[0] xor G2_register[1] xor G2_register[3] xor G2_register[4] xor + G2_register[6] xor G2_register[7] xor G2_register[8] xor G2_register[12]; for (lcv2 = 0; lcv2 < 12; lcv2++) { @@ -157,7 +156,7 @@ void beidou_b3i_code_gen_int(gsl::span _dest, signed int _prn, unsigned int // Generate PRN from G1 and G2 Registers for (lcv = 0; lcv < _code_length; lcv++) { - aux = (G1[(lcv + _chip_shift) % _code_length] + G2[delay]) & 0x01; + aux = G1[(lcv + _chip_shift) % _code_length] xor G2[delay]; if (aux == true) { _dest[lcv] = 1; diff --git a/src/algorithms/libs/geofunctions.cc b/src/algorithms/libs/geofunctions.cc index 6da551c80..ec55a9e3c 100644 --- a/src/algorithms/libs/geofunctions.cc +++ b/src/algorithms/libs/geofunctions.cc @@ -30,6 +30,7 @@ */ #include "geofunctions.h" +#include #include // for sin, cos, sqrt, abs, pow const double STRP_PI = 3.1415926535898; // Pi as defined in IS-GPS-200E @@ -350,8 +351,8 @@ arma::mat Euler_to_CTM(const arma::vec &eul) arma::vec cart2geo(const arma::vec &XYZ, int elipsoid_selection) { - const double a[5] = {6378388.0, 6378160.0, 6378135.0, 6378137.0, 6378137.0}; - const double f[5] = {1.0 / 297.0, 1.0 / 298.247, 1.0 / 298.26, 1.0 / 298.257222101, 1.0 / 298.257223563}; + const std::array a{6378388.0, 6378160.0, 6378135.0, 6378137.0, 6378137.0}; + const std::array f{1.0 / 297.0, 1.0 / 298.247, 1.0 / 298.26, 1.0 / 298.257222101, 1.0 / 298.257223563}; double lambda = atan2(XYZ[1], XYZ[0]); double ex2 = (2.0 - f[elipsoid_selection]) * f[elipsoid_selection] / ((1.0 - f[elipsoid_selection]) * (1.0 - f[elipsoid_selection])); diff --git a/src/algorithms/libs/gps_l2c_signal.cc b/src/algorithms/libs/gps_l2c_signal.cc index cfb49082e..364c5ee66 100644 --- a/src/algorithms/libs/gps_l2c_signal.cc +++ b/src/algorithms/libs/gps_l2c_signal.cc @@ -36,19 +36,19 @@ #include -int32_t gps_l2c_m_shift(int32_t x) +uint32_t gps_l2c_m_shift(uint32_t x) { - return static_cast((x >> 1) ^ ((x & 1) * 0445112474)); + return static_cast((x >> 1U) ^ ((x & 1U) * 0445112474U)); } void gps_l2c_m_code(gsl::span _dest, uint32_t _prn) { - int32_t x; + uint32_t x; x = GPS_L2C_M_INIT_REG[_prn - 1]; for (int32_t n = 0; n < GPS_L2_M_CODE_LENGTH_CHIPS; n++) { - _dest[n] = static_cast(x & 1); + _dest[n] = static_cast(x & 1U); x = gps_l2c_m_shift(x); } } diff --git a/src/algorithms/libs/gps_sdr_signal_processing.cc b/src/algorithms/libs/gps_sdr_signal_processing.cc index 24c9630d3..a11ec8bd2 100644 --- a/src/algorithms/libs/gps_sdr_signal_processing.cc +++ b/src/algorithms/libs/gps_sdr_signal_processing.cc @@ -83,7 +83,7 @@ void gps_l1_ca_code_gen_int(gsl::span _dest, int32_t _prn, uint32_t _ch G2[lcv] = G2_register[0]; feedback1 = G1_register[7] ^ G1_register[0]; - feedback2 = (G2_register[8] + G2_register[7] + G2_register[4] + G2_register[2] + G2_register[1] + G2_register[0]) & 0x1; + feedback2 = G2_register[8] xor G2_register[7] xor G2_register[4] xor G2_register[2] xor G2_register[1] xor G2_register[0]; for (lcv2 = 0; lcv2 < 9; lcv2++) { diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc index 4334ca3f6..6cfd022ec 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc @@ -578,8 +578,10 @@ void dll_pll_veml_tracking::start_tracking() d_carrier_phase_rate_step_rad = 0.0; d_carr_ph_history.clear(); d_code_ph_history.clear(); - std::array Signal_; - std::memcpy(Signal_.data(), d_acquisition_gnss_synchro->Signal, 3); + std::array Signal_{}; + Signal_[0] = d_acquisition_gnss_synchro->Signal[0]; + Signal_[1] = d_acquisition_gnss_synchro->Signal[1]; + Signal_[2] = d_acquisition_gnss_synchro->Signal[2]; if (systemName == "GPS" and signal_type == "1C") { diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc index 0966fb809..32225d25f 100644 --- a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc @@ -467,9 +467,9 @@ int Galileo_E1_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attri } //assign the GNURadio block output data current_synchro_data.System = {'E'}; - std::string str_aux = "1B"; - const char *str = str_aux.c_str(); // get a C style null terminated string - std::memcpy(static_cast(current_synchro_data.Signal), str, 3); + current_synchro_data.Signal[0] = '1'; + current_synchro_data.Signal[1] = 'B'; + current_synchro_data.Signal[2] = '\0'; current_synchro_data.fs = d_fs_in; *out[0] = current_synchro_data; diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc index e1481ebdb..6555b0634 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc @@ -500,11 +500,11 @@ int Gps_L1_Ca_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attrib d_tcp_com.send_receive_tcp_packet_gps_l1_ca(tx_variables_array, &tcp_data); } - //assign the GNURadio block output data + // assign the GNU Radio block output data current_synchro_data.System = {'G'}; - std::string str_aux = "1C"; - const char *str = str_aux.c_str(); // get a C style null terminated string - std::memcpy(static_cast(current_synchro_data.Signal), str, 3); + current_synchro_data.Signal[0] = '1'; + current_synchro_data.Signal[1] = 'C'; + current_synchro_data.Signal[2] = '\0'; current_synchro_data.fs = d_fs_in; *out[0] = current_synchro_data;