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

Replace raw pointers by smart pointers

This commit is contained in:
Carles Fernandez 2019-07-27 11:24:39 +02:00
parent 8aaf6019e9
commit 9772f8ef07
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
2 changed files with 26 additions and 32 deletions

View File

@ -46,8 +46,9 @@
#define LMORE 5 //
sbas_l1_telemetry_decoder_gs_sptr
sbas_l1_make_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump)
sbas_l1_telemetry_decoder_gs_sptr sbas_l1_make_telemetry_decoder_gs(
const Gnss_Satellite &satellite,
bool dump)
{
return sbas_l1_telemetry_decoder_gs_sptr(new sbas_l1_telemetry_decoder_gs(satellite, dump));
}
@ -114,9 +115,6 @@ sbas_l1_telemetry_decoder_gs::Sample_Aligner::Sample_Aligner()
}
sbas_l1_telemetry_decoder_gs::Sample_Aligner::~Sample_Aligner() = default;
void sbas_l1_telemetry_decoder_gs::Sample_Aligner::reset()
{
d_past_sample = 0;
@ -194,19 +192,12 @@ sbas_l1_telemetry_decoder_gs::Symbol_Aligner_And_Decoder::Symbol_Aligner_And_Dec
const int32_t nn = 2;
std::array<int32_t, nn> g_encoder{121, 91};
d_vd1 = new Viterbi_Decoder(g_encoder.data(), d_KK, nn);
d_vd2 = new Viterbi_Decoder(g_encoder.data(), d_KK, nn);
d_vd1 = std::make_shared<Viterbi_Decoder>(g_encoder.data(), d_KK, nn);
d_vd1 = std::make_shared<Viterbi_Decoder>(g_encoder.data(), d_KK, nn);
d_past_symbol = 0;
}
sbas_l1_telemetry_decoder_gs::Symbol_Aligner_And_Decoder::~Symbol_Aligner_And_Decoder()
{
delete d_vd1;
delete d_vd2;
}
void sbas_l1_telemetry_decoder_gs::Symbol_Aligner_And_Decoder::reset()
{
d_past_symbol = 0;
@ -229,11 +220,11 @@ bool sbas_l1_telemetry_decoder_gs::Symbol_Aligner_And_Decoder::get_bits(const st
symbols_vd2.push_back(*symbol_it);
}
// arrays for decoded bits
auto *bits_vd1 = new int32_t[nbits_requested];
auto *bits_vd2 = new int32_t[nbits_requested];
std::vector<int32_t> bits_vd1(nbits_requested);
std::vector<int32_t> bits_vd2(nbits_requested);
// decode
float metric_vd1 = d_vd1->decode_continuous(symbols_vd1.data(), traceback_depth, bits_vd1, nbits_requested, nbits_decoded);
float metric_vd2 = d_vd2->decode_continuous(symbols_vd2.data(), traceback_depth, bits_vd2, nbits_requested, nbits_decoded);
float metric_vd1 = d_vd1->decode_continuous(symbols_vd1.data(), traceback_depth, bits_vd1.data(), nbits_requested, nbits_decoded);
float metric_vd2 = d_vd2->decode_continuous(symbols_vd2.data(), traceback_depth, bits_vd2.data(), nbits_requested, nbits_decoded);
// choose the bits with the better metric
for (int32_t i = 0; i < nbits_decoded; i++)
{
@ -247,8 +238,6 @@ bool sbas_l1_telemetry_decoder_gs::Symbol_Aligner_And_Decoder::get_bits(const st
}
}
d_past_symbol = symbols.back();
delete[] bits_vd1;
delete[] bits_vd2;
return metric_vd1 > metric_vd2;
}

View File

@ -5,7 +5,7 @@
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
*
* GNSS-SDR is a software defined Global Navigation
* Satellite Systems receiver
@ -40,6 +40,7 @@
#include <cstdint>
#include <deque>
#include <fstream>
#include <memory>
#include <string>
#include <utility> // for pair
#include <vector>
@ -50,12 +51,13 @@ class sbas_l1_telemetry_decoder_gs;
using sbas_l1_telemetry_decoder_gs_sptr = boost::shared_ptr<sbas_l1_telemetry_decoder_gs>;
sbas_l1_telemetry_decoder_gs_sptr
sbas_l1_make_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
sbas_l1_telemetry_decoder_gs_sptr sbas_l1_make_telemetry_decoder_gs(
const Gnss_Satellite &satellite,
bool dump);
/*!
* \brief This class implements a block that decodes the SBAS integrity and corrections data defined in RTCA MOPS DO-229
*
* \brief This class implements a block that decodes the SBAS integrity and
* corrections data defined in RTCA MOPS DO-229
*/
class sbas_l1_telemetry_decoder_gs : public gr::block
{
@ -67,6 +69,7 @@ public:
{
return;
}
/*!
* \brief This is where all signal processing takes place
*/
@ -74,8 +77,10 @@ public:
gr_vector_const_void_star &input_items, gr_vector_void_star &output_items);
private:
friend sbas_l1_telemetry_decoder_gs_sptr
sbas_l1_make_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
friend sbas_l1_telemetry_decoder_gs_sptr sbas_l1_make_telemetry_decoder_gs(
const Gnss_Satellite &satellite,
bool dump);
sbas_l1_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
void viterbi_decoder(double *page_part_symbols, int32_t *page_part_bits);
@ -103,7 +108,7 @@ private:
{
public:
Sample_Aligner();
~Sample_Aligner();
~Sample_Aligner() = default;
void reset();
/*
* samples length must be a multiple of two
@ -125,14 +130,14 @@ private:
{
public:
Symbol_Aligner_And_Decoder();
~Symbol_Aligner_And_Decoder();
~Symbol_Aligner_And_Decoder() = default;
void reset();
bool get_bits(const std::vector<double> &symbols, std::vector<int32_t> &bits);
private:
int32_t d_KK;
Viterbi_Decoder *d_vd1;
Viterbi_Decoder *d_vd2;
std::shared_ptr<Viterbi_Decoder> d_vd1;
std::shared_ptr<Viterbi_Decoder> d_vd2;
double d_past_symbol;
} d_symbol_aligner_and_decoder;
@ -157,7 +162,7 @@ private:
void get_valid_frames(const std::vector<msg_candiate_int_t> &msg_candidates, std::vector<msg_candiate_char_t> &valid_msgs);
private:
typedef boost::crc_optimal<24, 0x1864CFBu, 0x0, 0x0, false, false> crc_24_q_type;
typedef boost::crc_optimal<24, 0x1864CFBU, 0x0, 0x0, false, false> crc_24_q_type;
crc_24_q_type d_checksum_agent;
void zerropad_front_and_convert_to_bytes(const std::vector<int32_t> &msg_candidate, std::vector<uint8_t> &bytes);
void zerropad_back_and_convert_to_bytes(const std::vector<int32_t> &msg_candidate, std::vector<uint8_t> &bytes);