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

Reserve memory for strings before pushing data

Some more const correctness
This commit is contained in:
Carles Fernandez 2020-07-28 01:23:27 +02:00
parent 76cce022ac
commit 5d326bc902
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
8 changed files with 16 additions and 7 deletions

View File

@ -202,6 +202,7 @@ void beidou_b1i_telemetry_decoder_gs::decode_subframe(float *frame_symbols)
{
// 1. Transform from symbols to bits
std::string data_bits;
data_bits.reserve(BEIDOU_DNAV_WORDS_SUBFRAME * BEIDOU_DNAV_WORD_LENGTH_BITS);
std::array<int32_t, 30> dec_word_bits{};
// Decode each word in subframe

View File

@ -203,6 +203,7 @@ void beidou_b3i_telemetry_decoder_gs::decode_subframe(float *frame_symbols)
{
// 1. Transform from symbols to bits
std::string data_bits;
data_bits.reserve(BEIDOU_DNAV_WORDS_SUBFRAME * BEIDOU_DNAV_WORD_LENGTH_BITS);
std::array<int32_t, 30> dec_word_bits{};
// Decode each word in subframe

View File

@ -237,6 +237,7 @@ void galileo_telemetry_decoder_gs::decode_INAV_word(float *page_part_symbols, in
// 3. Call the Galileo page decoder
std::string page_String;
page_String.reserve(frame_length / 2);
for (int32_t i = 0; i < (frame_length / 2); i++)
{
if (page_part_bits[i] > 0)
@ -328,6 +329,7 @@ void galileo_telemetry_decoder_gs::decode_FNAV_word(float *page_symbols, int32_t
// 3. Call the Galileo page decoder
std::string page_String;
page_String.reserve(frame_length);
for (int32_t i = 0; i < frame_length; i++)
{
if (page_bits[i] > 0)
@ -458,7 +460,7 @@ int galileo_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
{
if ((d_sample_counter - d_last_valid_preamble) > d_max_symbols_without_valid_frame)
{
int message = 1; // bad telemetry
const int message = 1; // bad telemetry
DLOG(INFO) << "sent msg sat " << this->d_satellite;
this->message_port_pub(pmt::mp("telemetry_to_trk"), pmt::make_any(message));
d_sent_tlm_failed_msg = true;

View File

@ -118,8 +118,11 @@ void glonass_l1_ca_telemetry_decoder_gs::decode_string(const double *frame_symbo
// 1. Transform from symbols to bits
std::string bi_binary_code;
bi_binary_code.reserve(frame_length / GLONASS_GNAV_TELEMETRY_SYMBOLS_PER_BIT);
std::string relative_code;
relative_code.reserve(GLONASS_GNAV_STRING_BITS);
std::string data_bits;
data_bits.reserve(GLONASS_GNAV_STRING_BITS + 1);
// Group samples into bi-binary code
for (int32_t i = 0; i < (frame_length); i++)

View File

@ -118,8 +118,11 @@ void glonass_l2_ca_telemetry_decoder_gs::decode_string(const double *frame_symbo
// 1. Transform from symbols to bits
std::string bi_binary_code;
bi_binary_code.reserve(frame_length / GLONASS_GNAV_TELEMETRY_SYMBOLS_PER_BIT);
std::string relative_code;
relative_code.reserve(GLONASS_GNAV_STRING_BITS);
std::string data_bits;
data_bits.reserve(GLONASS_GNAV_STRING_BITS + 1);
// Group samples into bi-binary code
for (int32_t i = 0; i < (frame_length); i++)

View File

@ -334,7 +334,7 @@ int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__
{
if ((d_sample_counter - d_last_valid_preamble) > d_max_symbols_without_valid_frame)
{
int message = 1; // bad telemetry
const int message = 1; // bad telemetry
this->message_port_pub(pmt::mp("telemetry_to_trk"), pmt::make_any(message));
d_sent_tlm_failed_msg = true;
}
@ -376,7 +376,6 @@ int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__
{
// correlate with preamble
int32_t corr_value = 0;
int32_t preamble_diff = 0;
if (d_symbol_history.size() >= GPS_CA_PREAMBLE_LENGTH_BITS)
{
// ******* preamble correlation ********
@ -395,7 +394,7 @@ int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__
if (abs(corr_value) >= d_samples_per_preamble)
{
// check preamble separation
preamble_diff = static_cast<int32_t>(d_sample_counter - d_preamble_index);
const auto preamble_diff = static_cast<int32_t>(d_sample_counter - d_preamble_index);
if (abs(preamble_diff - d_preamble_period_symbols) == 0)
{
DLOG(INFO) << "Preamble confirmation for SAT " << this->d_satellite;

View File

@ -161,7 +161,7 @@ int gps_l2c_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
{
if ((d_sample_counter - d_last_valid_preamble) > d_max_symbols_without_valid_frame)
{
int message = 1; // bad telemetry
const int message = 1; // bad telemetry
this->message_port_pub(pmt::mp("telemetry_to_trk"), pmt::make_any(message));
d_sent_tlm_failed_msg = true;
}

View File

@ -156,7 +156,7 @@ int gps_l5_telemetry_decoder_gs::general_work(int noutput_items __attribute__((u
{
if ((d_sample_counter - d_last_valid_preamble) > d_max_symbols_without_valid_frame)
{
int message = 1; // bad telemetry
const int message = 1; // bad telemetry
this->message_port_pub(pmt::mp("telemetry_to_trk"), pmt::make_any(message));
d_sent_tlm_failed_msg = true;
}
@ -164,7 +164,7 @@ int gps_l5_telemetry_decoder_gs::general_work(int noutput_items __attribute__((u
cnav_msg_t msg;
uint32_t delay;
uint8_t symbol_clip = static_cast<uint8_t>(current_synchro_data.Prompt_Q > 0) * 255;
const auto symbol_clip = static_cast<uint8_t>(current_synchro_data.Prompt_Q > 0) * 255;
// 2. Add the telemetry decoder information
// check if new CNAV frame is available
if (cnav_msg_decoder_add_symbol(&d_cnav_decoder, symbol_clip, &msg, &delay) == true)