1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 12:40:35 +00:00

Avoid variable length arrays and other minor fixes

This commit is contained in:
Carles Fernandez 2018-08-16 14:16:43 +02:00
parent c9413e8931
commit a249cd7242
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
7 changed files with 67 additions and 59 deletions

View File

@ -496,7 +496,8 @@ bool rtklib_solver::get_PVT(const std::map<int, Gnss_Synchro>& gnss_observables_
if (rtk_.ssat[i].vsat[0] == 1) used_sats++; if (rtk_.ssat[i].vsat[0] == 1) used_sats++;
} }
double azel[used_sats * 2]; std::vector<double> azel;
azel.reserve(used_sats * 2);
unsigned int index_aux = 0; unsigned int index_aux = 0;
for (unsigned int i = 0; i < MAXSAT; i++) for (unsigned int i = 0; i < MAXSAT; i++)
{ {
@ -507,7 +508,7 @@ bool rtklib_solver::get_PVT(const std::map<int, Gnss_Synchro>& gnss_observables_
index_aux++; index_aux++;
} }
} }
if (index_aux > 0) dops(index_aux, azel, 0.0, dop_); if (index_aux > 0) dops(index_aux, azel.data(), 0.0, dop_);
this->set_valid_position(true); this->set_valid_position(true);
arma::vec rx_position_and_time(4); arma::vec rx_position_and_time(4);

View File

@ -33,6 +33,7 @@
#include "galileo_e1_signal_processing.h" #include "galileo_e1_signal_processing.h"
#include "Galileo_E1.h" #include "Galileo_E1.h"
#include "gnss_signal_processing.h" #include "gnss_signal_processing.h"
#include <volk_gnsssdr/volk_gnsssdr.h>
#include <string> #include <string>
@ -42,7 +43,7 @@ void galileo_e1_code_gen_int(int* _dest, char _Signal[3], int32_t _prn)
int32_t prn = _prn - 1; int32_t prn = _prn - 1;
int32_t index = 0; int32_t index = 0;
/* A simple error check */ // A simple error check
if ((_prn < 1) || (_prn > 50)) if ((_prn < 1) || (_prn > 50))
{ {
return; return;
@ -107,7 +108,7 @@ void galileo_e1_sinboc_61_gen_int(int* _dest, int* _prn, uint32_t _length_out)
void galileo_e1_code_gen_sinboc11_float(float* _dest, char _Signal[3], uint32_t _prn) void galileo_e1_code_gen_sinboc11_float(float* _dest, char _Signal[3], uint32_t _prn)
{ {
std::string _galileo_signal = _Signal; std::string _galileo_signal = _Signal;
uint32_t _codeLength = static_cast<uint32_t>(Galileo_E1_B_CODE_LENGTH_CHIPS); uint32_t _codeLength = static_cast<const uint32_t>(Galileo_E1_B_CODE_LENGTH_CHIPS);
int32_t primary_code_E1_chips[4092]; // _codeLength not accepted by Clang int32_t primary_code_E1_chips[4092]; // _codeLength not accepted by Clang
galileo_e1_code_gen_int(primary_code_E1_chips, _Signal, _prn); //generate Galileo E1 code, 1 sample per chip galileo_e1_code_gen_int(primary_code_E1_chips, _Signal, _prn); //generate Galileo E1 code, 1 sample per chip
for (uint32_t i = 0; i < _codeLength; i++) for (uint32_t i = 0; i < _codeLength; i++)
@ -158,8 +159,9 @@ void galileo_e1_code_gen_float_sampled(float* _dest, char _Signal[3],
std::string _galileo_signal = _Signal; std::string _galileo_signal = _Signal;
uint32_t _samplesPerCode; uint32_t _samplesPerCode;
const int32_t _codeFreqBasis = Galileo_E1_CODE_CHIP_RATE_HZ; // Hz const int32_t _codeFreqBasis = Galileo_E1_CODE_CHIP_RATE_HZ; // Hz
uint32_t _codeLength = Galileo_E1_B_CODE_LENGTH_CHIPS; uint32_t _codeLength = static_cast<const uint32_t>(Galileo_E1_B_CODE_LENGTH_CHIPS);
int32_t primary_code_E1_chips[static_cast<int32_t>(Galileo_E1_B_CODE_LENGTH_CHIPS)]; int32_t* primary_code_E1_chips = static_cast<int32_t*>(volk_gnsssdr_malloc(static_cast<const uint32_t>(Galileo_E1_B_CODE_LENGTH_CHIPS) * sizeof(int32_t), volk_gnsssdr_get_alignment()));
_samplesPerCode = static_cast<uint32_t>(static_cast<double>(_fs) / (static_cast<double>(_codeFreqBasis) / static_cast<double>(_codeLength))); _samplesPerCode = static_cast<uint32_t>(static_cast<double>(_fs) / (static_cast<double>(_codeFreqBasis) / static_cast<double>(_codeLength)));
const int32_t _samplesPerChip = (_cboc == true) ? 12 : 2; const int32_t _samplesPerChip = (_cboc == true) ? 12 : 2;
@ -178,18 +180,20 @@ void galileo_e1_code_gen_float_sampled(float* _dest, char _Signal[3],
} }
else else
{ {
int32_t _signal_E1_int[_codeLength]; int32_t* _signal_E1_int = static_cast<int32_t*>(volk_gnsssdr_malloc(_codeLength * sizeof(int32_t), volk_gnsssdr_get_alignment()));
galileo_e1_sinboc_11_gen_int(_signal_E1_int, primary_code_E1_chips, _codeLength); // generate sinboc(1,1) 2 samples per chip galileo_e1_sinboc_11_gen_int(_signal_E1_int, primary_code_E1_chips, _codeLength); // generate sinboc(1,1) 2 samples per chip
for (uint32_t ii = 0; ii < _codeLength; ++ii) for (uint32_t ii = 0; ii < _codeLength; ++ii)
{ {
_signal_E1[ii] = static_cast<float>(_signal_E1_int[ii]); _signal_E1[ii] = static_cast<float>(_signal_E1_int[ii]);
} }
volk_gnsssdr_free(_signal_E1_int);
} }
if (_fs != _samplesPerChip * _codeFreqBasis) if (_fs != _samplesPerChip * _codeFreqBasis)
{ {
float* _resampled_signal = new float[_samplesPerCode]; float* _resampled_signal = new float[_samplesPerCode];
resampler(_signal_E1, _resampled_signal, _samplesPerChip * _codeFreqBasis, _fs, resampler(_signal_E1, _resampled_signal, _samplesPerChip * _codeFreqBasis, _fs,
_codeLength, _samplesPerCode); // resamples code to fs _codeLength, _samplesPerCode); // resamples code to fs
@ -221,6 +225,7 @@ void galileo_e1_code_gen_float_sampled(float* _dest, char _Signal[3],
} }
delete[] _signal_E1; delete[] _signal_E1;
volk_gnsssdr_free(primary_code_E1_chips);
} }
@ -238,7 +243,7 @@ void galileo_e1_code_gen_complex_sampled(std::complex<float>* _dest, char _Signa
_samplesPerCode *= static_cast<int32_t>(Galileo_E1_C_SECONDARY_CODE_LENGTH); _samplesPerCode *= static_cast<int32_t>(Galileo_E1_C_SECONDARY_CODE_LENGTH);
} }
float real_code[_samplesPerCode]; float* real_code = static_cast<float*>(volk_gnsssdr_malloc(_samplesPerCode * sizeof(float), volk_gnsssdr_get_alignment()));
galileo_e1_code_gen_float_sampled(real_code, _Signal, _cboc, _prn, _fs, _chip_shift, _secondary_flag); galileo_e1_code_gen_float_sampled(real_code, _Signal, _cboc, _prn, _fs, _chip_shift, _secondary_flag);
@ -246,6 +251,7 @@ void galileo_e1_code_gen_complex_sampled(std::complex<float>* _dest, char _Signa
{ {
_dest[ii] = std::complex<float>(real_code[ii], 0.0f); _dest[ii] = std::complex<float>(real_code[ii], 0.0f);
} }
volk_gnsssdr_free(real_code);
} }

View File

@ -158,7 +158,7 @@ void hex_to_binary_converter(int32_t* _dest, char _from)
} }
void resampler(float* _from, float* _dest, float _fs_in, void resampler(const float* _from, float* _dest, float _fs_in,
float _fs_out, uint32_t _length_in, uint32_t _length_out) float _fs_out, uint32_t _length_in, uint32_t _length_out)
{ {
uint32_t _codeValueIndex; uint32_t _codeValueIndex;
@ -182,7 +182,7 @@ void resampler(float* _from, float* _dest, float _fs_in,
} }
void resampler(std::complex<float>* _from, std::complex<float>* _dest, float _fs_in, void resampler(const std::complex<float>* _from, std::complex<float>* _dest, float _fs_in,
float _fs_out, uint32_t _length_in, uint32_t _length_out) float _fs_out, uint32_t _length_in, uint32_t _length_out)
{ {
uint32_t _codeValueIndex; uint32_t _codeValueIndex;

View File

@ -65,14 +65,14 @@ void hex_to_binary_converter(int32_t* _dest, char _from);
* \brief This function resamples a sequence of float values. * \brief This function resamples a sequence of float values.
* *
*/ */
void resampler(float* _from, float* _dest, void resampler(const float* _from, float* _dest,
float _fs_in, float _fs_out, uint32_t _length_in, float _fs_in, float _fs_out, uint32_t _length_in,
uint32_t _length_out); uint32_t _length_out);
/*! /*!
* \brief This function resamples a sequence of complex values. * \brief This function resamples a sequence of complex values.
* *
*/ */
void resampler(std::complex<float>* _from, std::complex<float>* _dest, void resampler(const std::complex<float>* _from, std::complex<float>* _dest,
float _fs_in, float _fs_out, uint32_t _length_in, float _fs_in, float _fs_out, uint32_t _length_in,
uint32_t _length_out); uint32_t _length_out);

View File

@ -116,7 +116,7 @@ void gps_l1_ca_code_gen_int(int32_t* _dest, int32_t _prn, uint32_t _chip_shift)
void gps_l1_ca_code_gen_float(float* _dest, int32_t _prn, uint32_t _chip_shift) void gps_l1_ca_code_gen_float(float* _dest, int32_t _prn, uint32_t _chip_shift)
{ {
uint32_t _code_length = 1023; const uint32_t _code_length = 1023;
int32_t ca_code_int[_code_length]; int32_t ca_code_int[_code_length];
gps_l1_ca_code_gen_int(ca_code_int, _prn, _chip_shift); gps_l1_ca_code_gen_int(ca_code_int, _prn, _chip_shift);
@ -130,7 +130,7 @@ void gps_l1_ca_code_gen_float(float* _dest, int32_t _prn, uint32_t _chip_shift)
void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, int32_t _prn, uint32_t _chip_shift) void gps_l1_ca_code_gen_complex(std::complex<float>* _dest, int32_t _prn, uint32_t _chip_shift)
{ {
uint32_t _code_length = 1023; const uint32_t _code_length = 1023;
int32_t ca_code_int[_code_length]; int32_t ca_code_int[_code_length];
gps_l1_ca_code_gen_int(ca_code_int, _prn, _chip_shift); gps_l1_ca_code_gen_int(ca_code_int, _prn, _chip_shift);

View File

@ -30,7 +30,6 @@
*/ */
#include "edc.h" #include "edc.h"
#include "bits.h" #include "bits.h"
#include "cnav_msg.h" #include "cnav_msg.h"
@ -57,9 +56,9 @@
*/ */
/** GPS L2C preamble */ /** GPS L2C preamble */
#define GPS_CNAV_PREAMBLE1 (0b10001011u) const u32 GPS_CNAV_PREAMBLE1 = 0x989A73u;
/** Inverted GPS L2C preamble */ /** Inverted GPS L2C preamble */
#define GPS_CNAV_PREAMBLE2 (0b01110100u) const u32 GPS_CNAV_PREAMBLE2 = 0x010F054u;
/** GPS L2C preamble length in bits */ /** GPS L2C preamble length in bits */
#define GPS_CNAV_PREAMBLE_LENGTH (8) #define GPS_CNAV_PREAMBLE_LENGTH (8)
/** GPS L2C CNAV message length in bits */ /** GPS L2C CNAV message length in bits */
@ -201,7 +200,8 @@ static void _cnav_add_symbol(cnav_v27_part_t *part, u8 ch)
* - M - Number of bits in the tail to ignore. * - M - Number of bits in the tail to ignore.
*/ */
unsigned char tmp_bits[(GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS + unsigned char tmp_bits[(GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS +
CHAR_BIT - 1) / CHAR_BIT]; CHAR_BIT - 1) /
CHAR_BIT];
v27_chainback_likely(&part->dec, tmp_bits, v27_chainback_likely(&part->dec, tmp_bits,
GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS); GPS_L2C_V27_DECODE_BITS + GPS_L2C_V27_DELAY_BITS);
@ -238,7 +238,6 @@ static void _cnav_add_symbol(cnav_v27_part_t *part, u8 ch)
} }
if (part->preamble_seen && GPS_CNAV_MSG_LENGTH <= part->n_decoded) if (part->preamble_seen && GPS_CNAV_MSG_LENGTH <= part->n_decoded)
{ {
/* We have collected 300 bits starting from message preamble. Now try /* We have collected 300 bits starting from message preamble. Now try
* to compute CRC-24Q */ * to compute CRC-24Q */
u32 crc = _cnav_compute_crc(part); u32 crc = _cnav_compute_crc(part);

View File

@ -189,7 +189,9 @@ std::string Rtcm::bin_to_binary_data(const std::string& s) const
{ {
std::string s_aux; std::string s_aux;
int32_t remainder = static_cast<int32_t>(std::fmod(s.length(), 8)); int32_t remainder = static_cast<int32_t>(std::fmod(s.length(), 8));
uint8_t c[s.length()]; std::vector<uint8_t> c;
c.reserve(s.length());
uint32_t k = 0; uint32_t k = 0;
if (remainder != 0) if (remainder != 0)
{ {
@ -213,7 +215,7 @@ std::string Rtcm::bin_to_binary_data(const std::string& s) const
k++; k++;
} }
std::string ret(c, c + k / sizeof(c[0])); std::string ret(c.begin(), c.begin() + k);
return ret; return ret;
} }