1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-14 01:06:51 +00:00

Improve const correctness

This commit is contained in:
Carles Fernandez 2020-07-22 01:33:01 +02:00
parent 23c2dab8b7
commit 0aa6d6afc3
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
13 changed files with 48 additions and 64 deletions

View File

@ -85,12 +85,12 @@ uint32_t getbitu(const uint8_t *buff, uint32_t pos, uint8_t len)
*/
int32_t getbits(const uint8_t *buff, uint32_t pos, uint8_t len)
{
int32_t bits = (int32_t)getbitu(buff, pos, len);
const int32_t bits = (int32_t)getbitu(buff, pos, len);
/* Sign extend, taken from:
* http://graphics.stanford.edu/~seander/bithacks.html#VariableSignExtend
*/
int32_t m = 1U << (len - 1);
const int32_t m = 1U << (len - 1);
return (bits ^ m) - m;
}
@ -161,9 +161,9 @@ void bitshl(void *buf, uint32_t size, uint32_t shift)
unsigned char *dst = buf; /* Destination byte. */
const unsigned char *src = dst + shift / CHAR_BIT; /* First source byte, possibly incomplete. */
uint32_t copy_bits = size * CHAR_BIT - shift; /* Number of bits to move */
uint32_t byte_shift = copy_bits % CHAR_BIT; /* Shift of data */
uint32_t full_bytes = copy_bits / CHAR_BIT; /* Number of bytes to move */
const uint32_t copy_bits = size * CHAR_BIT - shift; /* Number of bits to move */
const uint32_t byte_shift = copy_bits % CHAR_BIT; /* Shift of data */
const uint32_t full_bytes = copy_bits / CHAR_BIT; /* Number of bytes to move */
if (0 == byte_shift)
{
@ -209,19 +209,19 @@ void bitshl(void *buf, uint32_t size, uint32_t shift)
void bitcopy(void *dst, uint32_t dst_index, const void *src, uint32_t src_index,
uint32_t count)
{
uint32_t limit1 = count / 32;
uint32_t limit2 = count % 32;
const uint32_t limit1 = count / 32;
const uint32_t limit2 = count % 32;
uint32_t idx = 0;
for (idx = 0; idx < limit1; ++idx)
{
uint32_t tmp = getbitu(src, src_index, 32);
const uint32_t tmp = getbitu(src, src_index, 32);
setbitu(dst, dst_index, 32, tmp);
src_index += 32;
dst_index += 32;
}
if (0 != limit2)
{
uint32_t tmp = getbitu(src, src_index, limit2);
const uint32_t tmp = getbitu(src, src_index, limit2);
setbitu(dst, dst_index, limit2, tmp);
}
}

View File

@ -126,7 +126,7 @@ static void _cnav_rescan_preamble(cnav_v27_part_t *part)
size_t j = 0;
for (i = 1, j = part->n_decoded - GPS_CNAV_PREAMBLE_LENGTH; i < j; ++i)
{
uint32_t c = getbitu(part->decoded, i, GPS_CNAV_PREAMBLE_LENGTH);
const uint32_t c = getbitu(part->decoded, i, GPS_CNAV_PREAMBLE_LENGTH);
if (GPS_CNAV_PREAMBLE1 == c || GPS_CNAV_PREAMBLE2 == c)
{
part->preamble_seen = true;
@ -182,7 +182,7 @@ static void _cnav_add_symbol(cnav_v27_part_t *part, uint8_t ch)
/* Feed accumulated symbols into the buffer, reset the number of accumulated
* symbols. */
v27_update(&part->dec, part->symbols, part->n_symbols / 2);
v27_update(&part->dec, part->symbols, (int)part->n_symbols / 2);
part->n_symbols = 0;
/* Decode N+M bits, where:
@ -230,8 +230,8 @@ static void _cnav_add_symbol(cnav_v27_part_t *part, uint8_t ch)
{
/* We have collected 300 bits starting from message preamble. Now try
* to compute CRC-24Q */
uint32_t crc = _cnav_compute_crc(part);
uint32_t crc2 = _cnav_extract_crc(part);
const uint32_t crc = _cnav_compute_crc(part);
const uint32_t crc2 = _cnav_extract_crc(part);
if (part->message_lock)
{

View File

@ -108,7 +108,7 @@ uint32_t crc24q_bits(uint32_t crc, const uint8_t *buf, uint32_t n_bits, bool inv
{
uint16_t acc = 0;
uint8_t b = 0;
uint32_t shift = 8 - n_bits % 8;
const uint32_t shift = 8 - n_bits % 8;
uint32_t i = 0;
for (i = 0; i < n_bits / 8; ++i)

View File

@ -115,7 +115,6 @@ void v27_update(v27_t *v, const unsigned char *syms, int nbits)
unsigned char sym0;
unsigned char sym1;
unsigned int *tmp;
int normalize = 0;
while (nbits--)
{
@ -176,8 +175,6 @@ void v27_update(v27_t *v, const unsigned char *syms, int nbits)
{
v->new_metrics[i] -= minmetric;
}
normalize += minmetric;
}
/* Advance decision index */

View File

@ -74,9 +74,6 @@ void Viterbi_Decoder::reset()
*/
float Viterbi_Decoder::decode_block(const double input_c[], int output_u_int[], const int LL)
{
int state;
int decoding_length_mismatch;
VLOG(FLOW) << "decode_block(): LL=" << LL;
// init
@ -84,9 +81,9 @@ float Viterbi_Decoder::decode_block(const double input_c[], int output_u_int[],
// do add compare select
do_acs(input_c, LL + d_mm);
// tail, no need to output -> traceback, but don't decode
state = do_traceback(d_mm);
const int state = do_traceback(d_mm);
// traceback and decode
decoding_length_mismatch = do_tb_and_decode(d_mm, LL, state, output_u_int, d_indicator_metric);
const int decoding_length_mismatch = do_tb_and_decode(d_mm, LL, state, output_u_int, d_indicator_metric);
VLOG(FLOW) << "decoding length mismatch: " << decoding_length_mismatch;
@ -100,18 +97,15 @@ float Viterbi_Decoder::decode_continuous(const double sym[],
const int nbits_requested,
int& nbits_decoded)
{
int state;
int decoding_length_mismatch;
VLOG(FLOW) << "decode_continuous(): nbits_requested=" << nbits_requested;
// do add compare select
do_acs(sym, nbits_requested);
// the ML sequence in the newest part of the trellis can not be decoded
// since it depends on the future values -> traceback, but don't decode
state = do_traceback(traceback_depth);
const int state = do_traceback(traceback_depth);
// traceback and decode
decoding_length_mismatch = do_tb_and_decode(traceback_depth, nbits_requested, state, bits, d_indicator_metric);
const int decoding_length_mismatch = do_tb_and_decode(traceback_depth, nbits_requested, state, bits, d_indicator_metric);
nbits_decoded = nbits_requested + decoding_length_mismatch;
VLOG(FLOW) << "decoding length mismatch (continuous decoding): " << decoding_length_mismatch;
@ -193,11 +187,11 @@ int Viterbi_Decoder::do_acs(const double sym[], int nbits)
/* step through all states */
for (state_at_t = 0; state_at_t < d_states; state_at_t++)
{
int next_state_if_0 = d_state0[state_at_t];
int next_state_if_1 = d_state1[state_at_t];
const int next_state_if_0 = d_state0[state_at_t];
const int next_state_if_1 = d_state1[state_at_t];
/* hypothesis: info bit is a zero */
float bm_0 = d_metric_c[d_out0[state_at_t]];
const float bm_0 = d_metric_c[d_out0[state_at_t]];
metric = d_pm_t[state_at_t] + bm_0; // path metric + zerobranch metric
/* store new metric if more than metric in storage */
@ -210,7 +204,7 @@ int Viterbi_Decoder::do_acs(const double sym[], int nbits)
}
/* hypothesis: info bit is a one */
float bm_1 = d_metric_c[d_out1[state_at_t]];
const float bm_1 = d_metric_c[d_out1[state_at_t]];
metric = d_pm_t[state_at_t] + bm_1; // path metric + onebranch metric
/* store new metric if more than metric in storage */
@ -272,17 +266,14 @@ int Viterbi_Decoder::do_traceback(size_t traceback_length)
int Viterbi_Decoder::do_tb_and_decode(int traceback_length, int requested_decoding_length, int state, int output_u_int[], float& indicator_metric)
{
int n_of_branches_for_indicator_metric = 500;
int t_out;
std::deque<Prev>::iterator it;
int decoding_length_mismatch;
int overstep_length;
int n_im = 0;
VLOG(FLOW) << "do_tb_and_decode(): requested_decoding_length=" << requested_decoding_length;
// decode only decode_length bits -> overstep newer bits which are too much
decoding_length_mismatch = static_cast<int>(d_trellis_paths.size()) - (traceback_length + requested_decoding_length);
const int decoding_length_mismatch = static_cast<int>(d_trellis_paths.size()) - (traceback_length + requested_decoding_length);
VLOG(BLOCK) << "decoding_length_mismatch=" << decoding_length_mismatch;
overstep_length = decoding_length_mismatch >= 0 ? decoding_length_mismatch : 0;
const int overstep_length = decoding_length_mismatch >= 0 ? decoding_length_mismatch : 0;
VLOG(BLOCK) << "overstep_length=" << overstep_length;
for (it = d_trellis_paths.begin() + traceback_length;
@ -290,7 +281,7 @@ int Viterbi_Decoder::do_tb_and_decode(int traceback_length, int requested_decodi
{
state = it->get_anchestor_state_of_current_state(state);
}
t_out = static_cast<int>(d_trellis_paths.end() - (d_trellis_paths.begin() + traceback_length + overstep_length) - 1); // requested_decoding_length-1;
int t_out = static_cast<int>(d_trellis_paths.end() - (d_trellis_paths.begin() + traceback_length + overstep_length) - 1); // requested_decoding_length-1;
indicator_metric = 0;
for (it = d_trellis_paths.begin() + traceback_length + overstep_length; it < d_trellis_paths.end(); ++it)
{
@ -358,8 +349,7 @@ void Viterbi_Decoder::nsc_transit(int output_p[], int trans_p[], int input, cons
{
int nextstate[1];
int state;
int states;
states = static_cast<int>(1U << (KK - 1)); /* The number of states: 2^mm */
const int states = static_cast<int>(1U << (KK - 1)); /* The number of states: 2^mm */
/* Determine the output and next state for each possible starting state */
for (state = 0; state < states; state++)
@ -411,6 +401,7 @@ int Viterbi_Decoder::nsc_enc_bit(int state_out_p[], int input, int state_in,
return (out);
}
/* function parity_counter()
Description: Determines if a symbol has odd (1) or even (0) parity

View File

@ -41,7 +41,7 @@ GalileoE5bDllPllTracking::GalileoE5bDllPllTracking(
DLOG(INFO) << "role " << role;
trk_params.SetFromConfiguration(configuration, role);
auto vector_length = static_cast<int>(std::round(trk_params.fs_in / (GALILEO_E5B_CODE_CHIP_RATE_CPS / GALILEO_E5B_CODE_LENGTH_CHIPS)));
const auto vector_length = static_cast<int>(std::round(trk_params.fs_in / (GALILEO_E5B_CODE_CHIP_RATE_CPS / GALILEO_E5B_CODE_LENGTH_CHIPS)));
trk_params.vector_length = vector_length;
if (trk_params.extend_correlation_symbols < 1)
{
@ -58,7 +58,7 @@ GalileoE5bDllPllTracking::GalileoE5bDllPllTracking(
std::cout << TEXT_RED << "WARNING: Galileo E5b. PLL or DLL narrow tracking bandwidth is higher than wide tracking one" << TEXT_RESET << '\n';
}
trk_params.system = 'E';
std::array<char, 3> sig_{'7', 'X', '\0'};
const std::array<char, 3> sig_{'7', 'X', '\0'};
std::memcpy(trk_params.signal, sig_.data(), 3);
// ################# Make a GNU Radio Tracking block object ################

View File

@ -693,7 +693,7 @@ void dll_pll_veml_tracking::start_tracking()
else if (d_systemName == "Galileo" and d_signal_type == "7X")
{
volk_gnsssdr::vector<gr_complex> aux_code(d_code_length_chips);
std::array<char, 3> signal_type_ = {{'7', 'X', '\0'}};
const std::array<char, 3> signal_type_ = {{'7', 'X', '\0'}};
galileo_e5_b_code_gen_complex_primary(aux_code, d_acquisition_gnss_synchro->PRN, signal_type_);
if (d_trk_parameters.track_pilot)
{
@ -1076,10 +1076,10 @@ void dll_pll_veml_tracking::run_dll_pll()
if (d_dll_filt_history.full())
{
float avg_code_error_chips_s = static_cast<float>(std::accumulate(d_dll_filt_history.begin(), d_dll_filt_history.end(), 0.0)) / static_cast<float>(d_dll_filt_history.capacity());
const float avg_code_error_chips_s = static_cast<float>(std::accumulate(d_dll_filt_history.begin(), d_dll_filt_history.end(), 0.0)) / static_cast<float>(d_dll_filt_history.capacity());
if (std::fabs(avg_code_error_chips_s) > 1.0)
{
float carrier_doppler_error_hz = static_cast<float>(d_signal_carrier_freq) * avg_code_error_chips_s / static_cast<float>(d_code_chip_rate);
const float carrier_doppler_error_hz = static_cast<float>(d_signal_carrier_freq) * avg_code_error_chips_s / static_cast<float>(d_code_chip_rate);
LOG(INFO) << "Detected and corrected carrier doppler error: " << carrier_doppler_error_hz << " [Hz] on sat " << Gnss_Satellite(d_systemName, d_acquisition_gnss_synchro->PRN);
d_carrier_loop_filter.initialize(static_cast<float>(d_carrier_doppler_hz) - carrier_doppler_error_hz);
d_corrected_doppler = true;

View File

@ -98,7 +98,7 @@ float cn0_m2m4_estimator(const gr_complex* Prompt_buffer, int length, float coh_
float m_2 = 0.0;
float m_4 = 0.0;
float aux;
auto n = static_cast<float>(length);
const auto n = static_cast<float>(length);
for (int i = 0; i < length; i++)
{
Psig += std::abs(Prompt_buffer[i].real());

View File

@ -30,7 +30,7 @@
void Tracking_2nd_DLL_filter::calculate_lopp_coef(float* tau1, float* tau2, float lbw, float zeta, float k)
{
// Solve natural frequency
float Wn = lbw * 8.0F * zeta / (4.0F * zeta * zeta + 1.0F);
const float Wn = lbw * 8.0F * zeta / (4.0F * zeta * zeta + 1.0F);
// solve for t1 & t2
*tau1 = k / (Wn * Wn);
*tau2 = 2.0F * zeta / Wn;

View File

@ -29,7 +29,7 @@
void Tracking_2nd_PLL_filter::calculate_lopp_coef(float* tau1, float* tau2, float lbw, float zeta, float k)
{
// Solve natural frequency
float Wn = lbw * 8.0F * zeta / (4.0F * zeta * zeta + 1.0F);
const float Wn = lbw * 8.0F * zeta / (4.0F * zeta * zeta + 1.0F);
// solve for t1 & t2
*tau1 = k / (Wn * Wn);
*tau2 = 2.0F * zeta / Wn;

View File

@ -105,8 +105,7 @@ float Tracking_FLL_PLL_filter::get_carrier_error(float FLL_discriminator, float
/*
* 2nd order PLL with 1st order FLL assist
*/
float pll_w_new;
pll_w_new = d_pll_w + PLL_discriminator * d_pll_w0p2 * correlation_time_s + FLL_discriminator * d_pll_w0f * correlation_time_s;
const float pll_w_new = d_pll_w + PLL_discriminator * d_pll_w0p2 * correlation_time_s + FLL_discriminator * d_pll_w0f * correlation_time_s;
carrier_error_hz = 0.5F * (pll_w_new + d_pll_w) + d_pll_a2 * d_pll_w0p * PLL_discriminator;
d_pll_w = pll_w_new;
/* std::cout << " d_pll_w = " << carrier_error_hz << ", pll_w_new = " << pll_w_new

View File

@ -54,10 +54,8 @@ double phase_unwrap(double phase_rad)
*/
double fll_four_quadrant_atan(gr_complex prompt_s1, gr_complex prompt_s2, double t1, double t2)
{
float cross;
float dot;
dot = prompt_s1.real() * prompt_s2.real() + prompt_s1.imag() * prompt_s2.imag();
cross = prompt_s1.real() * prompt_s2.imag() - prompt_s2.real() * prompt_s1.imag();
const float dot = prompt_s1.real() * prompt_s2.real() + prompt_s1.imag() * prompt_s2.imag();
const float cross = prompt_s1.real() * prompt_s2.imag() - prompt_s2.real() * prompt_s1.imag();
return std::atan2(cross, dot) / (t2 - t1);
}
@ -120,9 +118,9 @@ double pll_cloop_two_quadrant_atan(gr_complex prompt_s1)
*/
double dll_nc_e_minus_l_normalized(gr_complex early_s1, gr_complex late_s1, float spc, float slope, float y_intercept)
{
double P_early = std::abs(early_s1);
double P_late = std::abs(late_s1);
double E_plus_L = P_early + P_late;
const double P_early = std::abs(early_s1);
const double P_late = std::abs(late_s1);
const double E_plus_L = P_early + P_late;
if (E_plus_L == 0.0)
{
return 0.0;
@ -142,10 +140,9 @@ double dll_nc_e_minus_l_normalized(gr_complex early_s1, gr_complex late_s1, floa
*/
double dll_nc_vemlp_normalized(gr_complex very_early_s1, gr_complex early_s1, gr_complex late_s1, gr_complex very_late_s1)
{
double Early = std::sqrt(very_early_s1.real() * very_early_s1.real() + very_early_s1.imag() * very_early_s1.imag() + early_s1.real() * early_s1.real() + early_s1.imag() * early_s1.imag());
double Late = std::sqrt(late_s1.real() * late_s1.real() + late_s1.imag() * late_s1.imag() + very_late_s1.real() * very_late_s1.real() + very_late_s1.imag() * very_late_s1.imag());
double E_plus_L = Early + Late;
const double Early = std::sqrt(very_early_s1.real() * very_early_s1.real() + very_early_s1.imag() * very_early_s1.imag() + early_s1.real() * early_s1.real() + early_s1.imag() * early_s1.imag());
const double Late = std::sqrt(late_s1.real() * late_s1.real() + late_s1.imag() * late_s1.imag() + very_late_s1.real() * very_late_s1.real() + very_late_s1.imag() * very_late_s1.imag());
const double E_plus_L = Early + Late;
if (E_plus_L == 0.0)
{
return 0.0;

View File

@ -104,9 +104,9 @@ void Tracking_loop_filter::update_coefficients()
// Natural frequency
float wn;
float T = d_update_interval;
const float T = d_update_interval;
float zeta = 1.0F / std::sqrt(2.0F);
const float zeta = 1.0F / std::sqrt(2.0F);
// The following is based on the bilinear transform approximation of
// the analog integrator. The loop format is from Kaplan & Hegarty
@ -167,8 +167,8 @@ void Tracking_loop_filter::update_coefficients()
break;
case 3:
wn = d_noise_bandwidth / 0.7845F; // From Kaplan
float a3 = 1.1;
float b3 = 2.4;
const float a3 = 1.1;
const float b3 = 2.4;
g1 = wn * wn * wn;
g2 = a3 * wn * wn;
g3 = b3 * wn;