Skip to content

Commit

Permalink
Last bunch of SonarQube fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandet committed Nov 18, 2022
1 parent f565d89 commit b878f0d
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 30 deletions.
16 changes: 14 additions & 2 deletions LFR_basic-parameters/basic_parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,13 @@ inline float wave_ellipticity_estimator(const float mag_PSD, const float nvec_de
float wave_ellipticity_estimator(const float mag_PSD, const float nvec_denom)
{
if (mag_PSD != 0.f)
{
return 2.f * nvec_denom / mag_PSD;
}
else
{
return 0.;
}
}

inline float degree_of_polarization(const float mag_PSD, const float* const spectral_matrix)
Expand All @@ -138,9 +142,13 @@ float degree_of_polarization(const float mag_PSD, const float* const spectral_ma
+ square(spectral_matrix[ASM_COMP_B2B3_imag]));
const float square_B_trace = square(mag_PSD);
if (square_B_trace != 0.)
{
return sqrtf((3.f * B_square_trace - square_B_trace) / (2.f * square_B_trace));
}
else
{
return 0.f;
}
}

inline compressed_complex X_poynting_vector(const float* const spectral_matrix)
Expand Down Expand Up @@ -213,9 +221,13 @@ compressed_complex phase_velocity_estimator(
else
{
if (__real__ NEBX >= 0.)
vphi.real = 1.e+20;
{
vphi.real = 1.e+20f;
}
else
vphi.real = -1.e+20;
{
vphi.real = -1.e+20f;
}
}
vphi.arg = fabs(__imag__ NEBX) > fabs(__real__ NEBX);
}
Expand Down
4 changes: 4 additions & 0 deletions LFR_basic-parameters/custom_floats.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ uint16_t to_custom_float_6_10(const float value)
str_float_t v = { .value = value };

if ((v.str.exponent - 127) < -27)
{
return 0;
}
if ((v.str.exponent - 127) > 36)
{
return 0xFFFF;
}

result.str.exponent = v.str.exponent - 127 + 27;
result.str.mantissa = v.str.mantissa >> 13;
Expand Down
7 changes: 3 additions & 4 deletions header/processing/ASM/spectralmatrices.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ extern "C"
unsigned int numberOfSMInASMSBM;
} asm_msg;

void Matrix_change_of_basis(_Complex float intermediary[25], float* input_matrix,
void Matrix_change_of_basis(_Complex float intermediary[25], const float* input_matrix,
const float* mag_transition_matrix, const float* elec_transition_matrix,
float* output_matrix);

Expand Down Expand Up @@ -79,22 +79,21 @@ extern "C"
{
float* out_ptr = dest_matrix;
const float* in_block_ptr = vhdl_spec_mat;
const float* in_ptr = in_block_ptr;
for (unsigned int line = 0; line < 5; line++)
{
for (unsigned int column = line; column < 5; column++)
{
if (line != column) // imaginary part
{
in_ptr = in_block_ptr + (2 * fbin);
const float* in_ptr = in_block_ptr + (2 * fbin);
out_ptr[0] = in_ptr[0];
out_ptr[1] = in_ptr[1];
in_block_ptr += (2 * NB_BINS_PER_SM);
out_ptr += 2;
}
else
{
in_ptr = in_block_ptr + fbin;
const float* in_ptr = in_block_ptr + fbin;
out_ptr[0] = in_ptr[0];
out_ptr++;
in_block_ptr += NB_BINS_PER_SM;
Expand Down
6 changes: 3 additions & 3 deletions src/fsw_processing_globals.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*
*/

#include <math.h>

// TOTAL = 32 coefficients * 4 = 128 octets * 3 * 12 = 4608 octets
// SX 12 coefficients
float K14_sx_re = 1;
Expand Down Expand Up @@ -43,6 +45,4 @@ float K55_pe = 1;
float K45_pe_re = 1;
float K45_pe_im = 1;

#define ALPHA_M (M_PI / 4)

float Alpha_M = ALPHA_M;
float Alpha_M = (float)(M_PI_4);
14 changes: 3 additions & 11 deletions src/mitigations/PAS_filtering.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,25 +65,19 @@ unsigned char acquisitionTimeIsValid(
uint64_t t0;
uint64_t t1;
uint64_t tc;
uint64_t tbad0;
uint64_t tbad1;

uint64_t modulusInFineTime;
uint64_t offsetInFineTime;
uint64_t shiftInFineTime;
uint64_t tbadInFineTime;

uint64_t timecodeReference;

unsigned char pasFilteringIsEnabled;
unsigned char ret;

// compute acquisition time from caoarseTime and fineTime
t0 = (((uint64_t)coarseTime) << SHIFT_2_BYTES) + (uint64_t)fineTime;
t1 = t0;
tc = t0;
tbad0 = t0;
tbad1 = t0;

switch (channel)
{
Expand All @@ -108,10 +102,8 @@ unsigned char acquisitionTimeIsValid(
offsetInFineTime = filterPar.offset_in_finetime;
shiftInFineTime = filterPar.shift_in_finetime;
tbadInFineTime = filterPar.tbad_in_finetime;
timecodeReference = INIT_INT;

pasFilteringIsEnabled = (filterPar.spare_sy_lfr_pas_filter_enabled & 1); // [0000 0001]
ret = MATRIX_IS_NOT_POLLUTED;

if ((tbadInFineTime == 0) || (pasFilteringIsEnabled == 0))
{
Expand All @@ -120,9 +112,9 @@ unsigned char acquisitionTimeIsValid(
else
{
// INTERSECTION TEST #1
timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime;
tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
uint64_t timecodeReference = (tc - (tc % modulusInFineTime)) - modulusInFineTime;
uint64_t tbad0 = timecodeReference + offsetInFineTime + shiftInFineTime;
uint64_t tbad1 = timecodeReference + offsetInFineTime + shiftInFineTime + tbadInFineTime;
ret = isPolluted(t0, t1, tbad0, tbad1);

// INTERSECTION TEST #2
Expand Down
2 changes: 1 addition & 1 deletion src/mitigations/reaction_wheel_filtering.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ int getFBinMask(int index, unsigned char channel)
unsigned int indexInChar;
unsigned int indexInTheChar;
int fbin;
unsigned char* sy_lfr_fbins_fx_word1;
const unsigned char* sy_lfr_fbins_fx_word1;

sy_lfr_fbins_fx_word1 = parameter_dump_packet.sy_lfr_fbins_f0_word1;

Expand Down
17 changes: 8 additions & 9 deletions src/processing/ASM/spectralmatrices.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ void SM_average(float* averaged_spec_mat_NORM, float* averaged_spec_mat_SBM,
register float sum2 = 0.;
for (unsigned int SM_index = 0; SM_index < numberOfValidSM; SM_index++)
{
sum1 += valid_matrices[SM_index][i];
sum2 += valid_matrices[SM_index][i + 1];
sum1 += (float)(valid_matrices[SM_index][i]);
sum2 += (float)(valid_matrices[SM_index][i + 1]);
}
averaged_spec_mat_SBM[i] += sum1;
averaged_spec_mat_NORM[i] += sum1;
Expand Down Expand Up @@ -138,15 +138,14 @@ void SM_average_f2(float* averaged_spec_mat_f2, ring_node* ring_node, unsigned i
DEBUG_CHECK_PTR(msgForMATR);
DEBUG_PRINTF("in SM_average_f2");
float sm_bin;
unsigned int i;
unsigned char keepMatrix;

// test acquisitionTime validity
keepMatrix = acquisitionTimeIsValid(ring_node->coarseTime, ring_node->fineTime, CHANNELF2);

for (i = 0; i < TOTAL_SIZE_SM; i++)
for (unsigned int i = 0; i < TOTAL_SIZE_SM; i++)
{
sm_bin = ((int*)(ring_node->buffer_address))[i];
sm_bin = (float)(((int*)(ring_node->buffer_address))[i]);
if (nbAverageNormF2 == 0) // average initialization
{
if (keepMatrix == MATRIX_IS_NOT_POLLUTED) // keep the matrix and add it to the average
Expand Down Expand Up @@ -198,7 +197,7 @@ void SM_average_f2(float* averaged_spec_mat_f2, ring_node* ring_node, unsigned i
DEBUG_PRINTF("leaving SM_average_f2");
}

// TODO add unit test

void ASM_compress_divide_and_mask(const float* const averaged_spec_mat, float* compressed_spec_mat,
const float divider, const unsigned char nbBinsCompressedMatrix,
const unsigned char nbBinsToAverage, const unsigned char ASMIndexStart,
Expand Down Expand Up @@ -239,7 +238,7 @@ void ASM_compress_divide_and_mask(const float* const averaged_spec_mat, float* c
= compressed_spec_mat + (compressed_frequency_bin * NB_FLOATS_PER_SM);
for (int asm_component = 0; asm_component < NB_FLOATS_PER_SM; asm_component++)
{
*compressed_asm_ptr += (*input_asm_ptr * fBinMask);
*compressed_asm_ptr += (*input_asm_ptr * (float)fBinMask);
compressed_asm_ptr++;
input_asm_ptr++;
}
Expand Down Expand Up @@ -298,7 +297,7 @@ Where each matrix product is done sequencialy for mag and elec transition matric
Note that this code is generated with LFR_Flight_Software/python_scripts/Matrix_calibration_code_gen.ipynb
*/
// clang-format on
void Matrix_change_of_basis(_Complex float _intermediary[25], float* input_matrix,
void Matrix_change_of_basis(_Complex float _intermediary[25], const float* input_matrix,
const float* mag_transition_matrix, const float* elec_transition_matrix, float* output_matrix)
{
DEBUG_CHECK_PTR(_intermediary);
Expand Down Expand Up @@ -603,7 +602,7 @@ void Matrix_change_of_basis(_Complex float _intermediary[25], float* input_matri
}

void SM_calibrate_and_reorder(_Complex float intermediary[25], float work_matrix[NB_FLOATS_PER_SM],
float* input_asm, const float* mag_calibration_matrices, const float* elec_calibration_matrices,
const float* input_asm, const float* mag_calibration_matrices, const float* elec_calibration_matrices,
float* output_asm, unsigned int start_indice, unsigned int stop_indice)
{
DEBUG_CHECK_PTR(intermediary);
Expand Down
2 changes: 2 additions & 0 deletions src/tc_tm/tc_load_dump_parameters.c
Original file line number Diff line number Diff line change
Expand Up @@ -1802,7 +1802,9 @@ int set_sy_lfr_kcoeff(const ccsdsTelecommandPacket_t* const TC, rtems_id queue_i
= elec_calibration_matrices_f2 + (ASM_F2_KEEP_BINS * NB_FLOATS_ELEC_CAL_MATRIX);

if (sy_lfr_kcoeff_frequency == NB_BINS_COMPRESSED_SM - 1)
{
interpolate = yes;
}
}
else if (sy_lfr_kcoeff_frequency >= F1_COMPRESSED_BIN_OFFSET)
{
Expand Down

0 comments on commit b878f0d

Please sign in to comment.