diff --git a/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.cc index c911af3d4..1c266882b 100644 --- a/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.cc @@ -40,6 +40,7 @@ #include #include #include +#include BeidouB1iPcpsAcquisition::BeidouB1iPcpsAcquisition( @@ -91,7 +92,7 @@ BeidouB1iPcpsAcquisition::BeidouB1iPcpsAcquisition( vector_length_ *= 2; } - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "cshort") { @@ -136,10 +137,7 @@ BeidouB1iPcpsAcquisition::BeidouB1iPcpsAcquisition( } -BeidouB1iPcpsAcquisition::~BeidouB1iPcpsAcquisition() -{ - delete[] code_; -} +BeidouB1iPcpsAcquisition::~BeidouB1iPcpsAcquisition() = default; void BeidouB1iPcpsAcquisition::stop_acquisition() @@ -205,18 +203,17 @@ void BeidouB1iPcpsAcquisition::init() void BeidouB1iPcpsAcquisition::set_local_code() { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; beidou_b1i_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_, 0); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.h b/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.h index f274d3ee6..503b6409e 100644 --- a/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/beidou_b1i_pcps_acquisition.h @@ -42,7 +42,9 @@ #include #include #include +#include #include +#include class ConfigurationInterface; @@ -100,15 +102,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } - /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -159,7 +160,6 @@ public: */ void set_resampler_latency(uint32_t latency_samples) override; - private: ConfigurationInterface* configuration_; pcps_acquisition_sptr acquisition_; @@ -183,12 +183,11 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; uint32_t in_streams_; uint32_t out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.cc index 6c86d08f1..3a51a2a77 100644 --- a/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.cc @@ -91,7 +91,7 @@ BeidouB3iPcpsAcquisition::BeidouB3iPcpsAcquisition( vector_length_ *= 2; } - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "cshort") { @@ -136,10 +136,7 @@ BeidouB3iPcpsAcquisition::BeidouB3iPcpsAcquisition( } -BeidouB3iPcpsAcquisition::~BeidouB3iPcpsAcquisition() -{ - delete[] code_; -} +BeidouB3iPcpsAcquisition::~BeidouB3iPcpsAcquisition() = default; void BeidouB3iPcpsAcquisition::stop_acquisition() @@ -205,18 +202,17 @@ void BeidouB3iPcpsAcquisition::init() void BeidouB3iPcpsAcquisition::set_local_code() { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; beidou_b3i_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_, 0); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.h b/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.h index d824c132a..db2c6fbaa 100644 --- a/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/beidou_b3i_pcps_acquisition.h @@ -41,7 +41,9 @@ #include #include #include +#include #include +#include class ConfigurationInterface; @@ -99,15 +101,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } - /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -158,7 +159,6 @@ public: */ void set_resampler_latency(uint32_t latency_samples) override; - private: ConfigurationInterface* configuration_; pcps_acquisition_sptr acquisition_; @@ -182,12 +182,11 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.cc index 330016bd2..431a8142c 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.cc @@ -87,7 +87,7 @@ GalileoE1Pcps8msAmbiguousAcquisition::GalileoE1Pcps8msAmbiguousAcquisition( int samples_per_ms = code_length_ / 4; - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "gr_complex") { @@ -123,10 +123,7 @@ GalileoE1Pcps8msAmbiguousAcquisition::GalileoE1Pcps8msAmbiguousAcquisition( } -GalileoE1Pcps8msAmbiguousAcquisition::~GalileoE1Pcps8msAmbiguousAcquisition() -{ - delete[] code_; -} +GalileoE1Pcps8msAmbiguousAcquisition::~GalileoE1Pcps8msAmbiguousAcquisition() = default; void GalileoE1Pcps8msAmbiguousAcquisition::stop_acquisition() @@ -217,22 +214,20 @@ void GalileoE1Pcps8msAmbiguousAcquisition::set_local_code() bool cboc = configuration_->property( "Acquisition" + std::to_string(channel_) + ".cboc", false); - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; std::array Signal_; std::memcpy(Signal_.data(), gnss_synchro_->Signal, 3); galileo_e1_code_gen_complex_sampled(gsl::span>(code, code_length_), Signal_, cboc, gnss_synchro_->PRN, fs_in_, 0, false); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_ / 4; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_cc_->set_local_code(code_); - - delete[] code; + acquisition_cc_->set_local_code(code_.data()); } } @@ -245,6 +240,7 @@ void GalileoE1Pcps8msAmbiguousAcquisition::reset() } } + float GalileoE1Pcps8msAmbiguousAcquisition::calculate_threshold(float pfa) { unsigned int frequency_bins = 0; diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.h index 27e9049de..a3be14fce 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.h +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_8ms_ambiguous_acquisition.h @@ -36,7 +36,9 @@ #include "galileo_pcps_8ms_acquisition_cc.h" #include "gnss_synchro.h" #include +#include #include +#include class ConfigurationInterface; @@ -165,7 +167,7 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc index f0cfce6a3..60082fc4c 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.cc @@ -127,7 +127,7 @@ GalileoE1PcpsAmbiguousAcquisition::GalileoE1PcpsAmbiguousAcquisition( vector_length_ *= 2; } - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "cshort") { @@ -167,16 +167,14 @@ GalileoE1PcpsAmbiguousAcquisition::GalileoE1PcpsAmbiguousAcquisition( } -GalileoE1PcpsAmbiguousAcquisition::~GalileoE1PcpsAmbiguousAcquisition() -{ - delete[] code_; -} +GalileoE1PcpsAmbiguousAcquisition::~GalileoE1PcpsAmbiguousAcquisition() = default; void GalileoE1PcpsAmbiguousAcquisition::stop_acquisition() { } + void GalileoE1PcpsAmbiguousAcquisition::set_threshold(float threshold) { float pfa = configuration_->property(role_ + std::to_string(channel_) + ".pfa", 0.0); @@ -243,7 +241,8 @@ void GalileoE1PcpsAmbiguousAcquisition::set_local_code() bool cboc = configuration_->property( "Acquisition" + std::to_string(channel_) + ".cboc", false); - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; + gsl::span> code_span(code.get(), code_length_); if (acquire_pilot_ == true) { @@ -251,12 +250,12 @@ void GalileoE1PcpsAmbiguousAcquisition::set_local_code() std::array pilot_signal = {{'1', 'C', '\0'}}; if (acq_parameters_.use_automatic_resampler) { - galileo_e1_code_gen_complex_sampled(gsl::span>(code, code_length_), pilot_signal, + galileo_e1_code_gen_complex_sampled(code_span, pilot_signal, cboc, gnss_synchro_->PRN, acq_parameters_.resampled_fs, 0, false); } else { - galileo_e1_code_gen_complex_sampled(gsl::span>(code, code_length_), pilot_signal, + galileo_e1_code_gen_complex_sampled(code_span, pilot_signal, cboc, gnss_synchro_->PRN, fs_in_, 0, false); } } @@ -266,24 +265,23 @@ void GalileoE1PcpsAmbiguousAcquisition::set_local_code() std::memcpy(Signal_.data(), gnss_synchro_->Signal, 3); if (acq_parameters_.use_automatic_resampler) { - galileo_e1_code_gen_complex_sampled(gsl::span>(code, code_length_), Signal_, + galileo_e1_code_gen_complex_sampled(code_span, Signal_, cboc, gnss_synchro_->PRN, acq_parameters_.resampled_fs, 0, false); } else { - galileo_e1_code_gen_complex_sampled(gsl::span>(code, code_length_), Signal_, + galileo_e1_code_gen_complex_sampled(code_span, Signal_, cboc, gnss_synchro_->PRN, fs_in_, 0, false); } } - gsl::span code_span(code_, vector_length_); + gsl::span code__span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_ / 4; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code__span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.h index 12aebab73..92c25724b 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.h +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition.h @@ -39,7 +39,9 @@ #include "pcps_acquisition.h" #include #include +#include #include +#include class ConfigurationInterface; @@ -98,13 +100,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -153,10 +156,8 @@ public: /*! * \brief Sets the resampler latency to account it in the acquisition code delay estimation */ - void set_resampler_latency(uint32_t latency_samples) override; - private: ConfigurationInterface* configuration_; Acq_Conf acq_parameters_; @@ -181,7 +182,7 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.cc index 24e275ff6..0742b0ff5 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.cc +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.cc @@ -109,10 +109,11 @@ GalileoE1PcpsAmbiguousAcquisitionFpga::GalileoE1PcpsAmbiguousAcquisitionFpga( // compute all the GALILEO E1 PRN Codes (this is done only once in the class constructor in order to avoid re-computing the PRN codes every time // a channel is assigned) auto* fft_if = new gr::fft::fft_complex(nsamples_total, true); // Direct FFT - auto* code = new std::complex[nsamples_total]; // buffer for the local code + //auto code = std::make_shared>(nsamples_total); // buffer for the local code + std::vector> code(nsamples_total); auto* fft_codes_padded = static_cast(volk_gnsssdr_malloc(nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_all_fft_codes_ = new uint32_t[(nsamples_total * GALILEO_E1_NUMBER_OF_CODES)]; // memory containing all the possible fft codes for PRN 0 to 32 - float max; // temporary maxima search + d_all_fft_codes_ = std::vector(nsamples_total * GALILEO_E1_NUMBER_OF_CODES); // memory containing all the possible fft codes for PRN 0 to 32 + float max; // temporary maxima search int32_t tmp, tmp2, local_code, fft_data; for (uint32_t PRN = 1; PRN <= GALILEO_E1_NUMBER_OF_CODES; PRN++) @@ -123,13 +124,13 @@ GalileoE1PcpsAmbiguousAcquisitionFpga::GalileoE1PcpsAmbiguousAcquisitionFpga( { //set local signal generator to Galileo E1 pilot component (1C) std::array pilot_signal = {{'1', 'C', '\0'}}; - galileo_e1_code_gen_complex_sampled(gsl::span>(code, nsamples_total), pilot_signal, + galileo_e1_code_gen_complex_sampled(gsl::span>(code.data(), nsamples_total), pilot_signal, cboc, PRN, fs_in, 0, false); } else { std::array data_signal = {{'1', 'B', '\0'}}; - galileo_e1_code_gen_complex_sampled(gsl::span>(code, nsamples_total), data_signal, + galileo_e1_code_gen_complex_sampled(gsl::span>(code.data(), nsamples_total), data_signal, cboc, PRN, fs_in, 0, false); } @@ -144,7 +145,7 @@ GalileoE1PcpsAmbiguousAcquisitionFpga::GalileoE1PcpsAmbiguousAcquisitionFpga( code[s] = std::complex(0.0, 0.0); } - std::copy_n(code, nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer + std::copy_n(code.data(), nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer fft_if->execute(); // Run the FFT of local code volk_32fc_conjugate_32fc(fft_codes_padded, fft_if->get_outbuf(), nsamples_total); // conjugate values @@ -173,7 +174,7 @@ GalileoE1PcpsAmbiguousAcquisitionFpga::GalileoE1PcpsAmbiguousAcquisitionFpga( } } - acq_parameters.all_fft_codes = d_all_fft_codes_; + acq_parameters.all_fft_codes = d_all_fft_codes_.data(); acq_parameters.num_doppler_bins_step2 = configuration_->property(role + ".second_nbins", 4); acq_parameters.doppler_step2 = configuration_->property(role + ".second_doppler_step", 125.0); @@ -189,16 +190,12 @@ GalileoE1PcpsAmbiguousAcquisitionFpga::GalileoE1PcpsAmbiguousAcquisitionFpga( gnss_synchro_ = nullptr; // temporary buffers that we can delete - delete[] code; delete fft_if; - delete[] fft_codes_padded; + volk_gnsssdr_free(fft_codes_padded); } -GalileoE1PcpsAmbiguousAcquisitionFpga::~GalileoE1PcpsAmbiguousAcquisitionFpga() -{ - delete[] d_all_fft_codes_; -} +GalileoE1PcpsAmbiguousAcquisitionFpga::~GalileoE1PcpsAmbiguousAcquisitionFpga() = default; void GalileoE1PcpsAmbiguousAcquisitionFpga::stop_acquisition() diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.h index 83c3f66f5..a92b65e31 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.h +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_ambiguous_acquisition_fpga.h @@ -37,7 +37,9 @@ #include // for basic_block_sptr, top_block_sptr #include // for lv_16sc_t #include // for size_t +#include #include +#include class Gnss_Synchro; class ConfigurationInterface; @@ -97,8 +99,8 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; @@ -165,8 +167,7 @@ private: std::string role_; unsigned int in_streams_; unsigned int out_streams_; - - uint32_t* d_all_fft_codes_; // memory that contains all the code ffts + std::vector d_all_fft_codes_; // memory that contains all the code ffts }; #endif /* GNSS_SDR_GALILEO_E1_PCPS_AMBIGUOUS_ACQUISITION_FPGA_H_ */ diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.cc index d29e896a5..f16c6e5da 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.cc @@ -86,8 +86,8 @@ GalileoE1PcpsCccwsrAmbiguousAcquisition::GalileoE1PcpsCccwsrAmbiguousAcquisition int samples_per_ms = code_length_ / 4; - code_data_ = new gr_complex[vector_length_]; - code_pilot_ = new gr_complex[vector_length_]; + code_data_ = std::vector>(vector_length_); + code_pilot_ = std::vector>(vector_length_); if (item_type_ == "gr_complex") { @@ -123,11 +123,7 @@ GalileoE1PcpsCccwsrAmbiguousAcquisition::GalileoE1PcpsCccwsrAmbiguousAcquisition } -GalileoE1PcpsCccwsrAmbiguousAcquisition::~GalileoE1PcpsCccwsrAmbiguousAcquisition() -{ - delete[] code_data_; - delete[] code_pilot_; -} +GalileoE1PcpsCccwsrAmbiguousAcquisition::~GalileoE1PcpsCccwsrAmbiguousAcquisition() = default; void GalileoE1PcpsCccwsrAmbiguousAcquisition::stop_acquisition() @@ -168,6 +164,7 @@ void GalileoE1PcpsCccwsrAmbiguousAcquisition::set_doppler_step(unsigned int dopp } } + void GalileoE1PcpsCccwsrAmbiguousAcquisition::set_gnss_synchro( Gnss_Synchro* gnss_synchro) { @@ -205,15 +202,15 @@ void GalileoE1PcpsCccwsrAmbiguousAcquisition::set_local_code() std::array signal = {{'1', 'B', '\0'}}; - galileo_e1_code_gen_complex_sampled(gsl::span(code_data_, vector_length_), signal, + galileo_e1_code_gen_complex_sampled(gsl::span(code_data_.data(), vector_length_), signal, cboc, gnss_synchro_->PRN, fs_in_, 0, false); std::array signal_C = {{'1', 'C', '\0'}}; - galileo_e1_code_gen_complex_sampled(gsl::span(code_pilot_, vector_length_), signal_C, + galileo_e1_code_gen_complex_sampled(gsl::span(code_pilot_.data(), vector_length_), signal_C, cboc, gnss_synchro_->PRN, fs_in_, 0, false); - acquisition_cc_->set_local_code(code_data_, code_pilot_); + acquisition_cc_->set_local_code(code_data_.data(), code_pilot_.data()); } } @@ -226,6 +223,7 @@ void GalileoE1PcpsCccwsrAmbiguousAcquisition::reset() } } + void GalileoE1PcpsCccwsrAmbiguousAcquisition::set_state(int state) { acquisition_cc_->set_state(state); diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.h index b79fe2d33..eac80983c 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.h +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_cccwsr_ambiguous_acquisition.h @@ -36,7 +36,9 @@ #include "gnss_synchro.h" #include "pcps_cccwsr_acquisition_cc.h" #include +#include #include +#include class ConfigurationInterface; @@ -94,13 +96,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_cc_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of CCCWSR algorithm */ @@ -153,7 +156,6 @@ private: std::string item_type_; unsigned int vector_length_; unsigned int code_length_; - //unsigned int satellite_; unsigned int channel_; std::weak_ptr channel_fsm_; float threshold_; @@ -164,8 +166,8 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_data_; - std::complex* code_pilot_; + std::vector> code_data_; + std::vector> code_pilot_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.cc index 4e4c06ba9..9a3462407 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.cc @@ -115,7 +115,7 @@ GalileoE1PcpsQuickSyncAmbiguousAcquisition::GalileoE1PcpsQuickSyncAmbiguousAcqui dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename); - code_ = new gr_complex[code_length_]; + code_ = std::vector>(code_length_); LOG(INFO) << "Vector Length: " << vector_length_ << ", Samples per ms: " << samples_per_ms << ", Folding factor: " << folding_factor_ @@ -157,10 +157,7 @@ GalileoE1PcpsQuickSyncAmbiguousAcquisition::GalileoE1PcpsQuickSyncAmbiguousAcqui } -GalileoE1PcpsQuickSyncAmbiguousAcquisition::~GalileoE1PcpsQuickSyncAmbiguousAcquisition() -{ - delete[] code_; -} +GalileoE1PcpsQuickSyncAmbiguousAcquisition::~GalileoE1PcpsQuickSyncAmbiguousAcquisition() = default; void GalileoE1PcpsQuickSyncAmbiguousAcquisition::stop_acquisition() @@ -251,23 +248,20 @@ void GalileoE1PcpsQuickSyncAmbiguousAcquisition::set_local_code() bool cboc = configuration_->property( "Acquisition" + std::to_string(channel_) + ".cboc", false); - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; std::array Signal_; std::memcpy(Signal_.data(), gnss_synchro_->Signal, 3); - galileo_e1_code_gen_complex_sampled(gsl::span>(code, code_length_), Signal_, + galileo_e1_code_gen_complex_sampled(gsl::span>(code.get(), code_length_), Signal_, cboc, gnss_synchro_->PRN, fs_in_, 0, false); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < (sampled_ms_ / (folding_factor_ * 4)); i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_cc_->set_local_code(code_); - - delete[] code; - code = nullptr; + acquisition_cc_->set_local_code(code_.data()); } } @@ -280,6 +274,7 @@ void GalileoE1PcpsQuickSyncAmbiguousAcquisition::reset() } } + void GalileoE1PcpsQuickSyncAmbiguousAcquisition::set_state(int state) { if (item_type_ == "gr_complex") diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.h index c717c4ed7..ecbac95b6 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.h +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_quicksync_ambiguous_acquisition.h @@ -36,7 +36,9 @@ #include "gnss_synchro.h" #include "pcps_quicksync_acquisition_cc.h" #include +#include #include +#include class ConfigurationInterface; @@ -169,7 +171,7 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.cc index 4ab468fe8..3bb75b971 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.cc @@ -90,7 +90,7 @@ GalileoE1PcpsTongAmbiguousAcquisition::GalileoE1PcpsTongAmbiguousAcquisition( int samples_per_ms = code_length_ / 4; - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "gr_complex") { @@ -127,10 +127,7 @@ GalileoE1PcpsTongAmbiguousAcquisition::GalileoE1PcpsTongAmbiguousAcquisition( } -GalileoE1PcpsTongAmbiguousAcquisition::~GalileoE1PcpsTongAmbiguousAcquisition() -{ - delete[] code_; -} +GalileoE1PcpsTongAmbiguousAcquisition::~GalileoE1PcpsTongAmbiguousAcquisition() = default; void GalileoE1PcpsTongAmbiguousAcquisition::stop_acquisition() @@ -221,21 +218,19 @@ void GalileoE1PcpsTongAmbiguousAcquisition::set_local_code() bool cboc = configuration_->property( "Acquisition" + std::to_string(channel_) + ".cboc", false); - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; std::array Signal_; std::memcpy(Signal_.data(), gnss_synchro_->Signal, 3); - galileo_e1_code_gen_complex_sampled(gsl::span>(code, code_length_), Signal_, + galileo_e1_code_gen_complex_sampled(gsl::span>(code.get(), code_length_), Signal_, cboc, gnss_synchro_->PRN, fs_in_, 0, false); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_ / 4; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_cc_->set_local_code(code_); - - delete[] code; + acquisition_cc_->set_local_code(code_.data()); } } @@ -248,6 +243,7 @@ void GalileoE1PcpsTongAmbiguousAcquisition::reset() } } + void GalileoE1PcpsTongAmbiguousAcquisition::set_state(int state) { acquisition_cc_->set_state(state); diff --git a/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.h index 2cb201866..402383fcb 100644 --- a/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.h +++ b/src/algorithms/acquisition/adapters/galileo_e1_pcps_tong_ambiguous_acquisition.h @@ -36,7 +36,9 @@ #include "gnss_synchro.h" #include "pcps_tong_acquisition_cc.h" #include +#include #include +#include class ConfigurationInterface; @@ -168,7 +170,7 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.cc b/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.cc index e12e893e2..e02e6b97f 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.cc +++ b/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.cc @@ -94,8 +94,8 @@ GalileoE5aNoncoherentIQAcquisitionCaf::GalileoE5aNoncoherentIQAcquisitionCaf( vector_length_ = code_length_ * sampled_ms_; - codeI_ = new gr_complex[vector_length_]; - codeQ_ = new gr_complex[vector_length_]; + codeI_ = std::vector>(vector_length_); + codeQ_ = std::vector>(vector_length_); both_signal_components = false; std::string sig_ = configuration_->property("Channel.signal", std::string("5X")); @@ -132,11 +132,7 @@ GalileoE5aNoncoherentIQAcquisitionCaf::GalileoE5aNoncoherentIQAcquisitionCaf( } -GalileoE5aNoncoherentIQAcquisitionCaf::~GalileoE5aNoncoherentIQAcquisitionCaf() -{ - delete[] codeI_; - delete[] codeQ_; -} +GalileoE5aNoncoherentIQAcquisitionCaf::~GalileoE5aNoncoherentIQAcquisitionCaf() = default; void GalileoE5aNoncoherentIQAcquisitionCaf::stop_acquisition() @@ -224,53 +220,51 @@ void GalileoE5aNoncoherentIQAcquisitionCaf::set_local_code() { if (item_type_ == "gr_complex") { - auto* codeI = new std::complex[code_length_]; - auto* codeQ = new std::complex[code_length_]; + std::vector> codeI(code_length_); + std::vector> codeQ(code_length_); if (gnss_synchro_->Signal[0] == '5' && gnss_synchro_->Signal[1] == 'X') { std::array a = {{'5', 'I', '\0'}}; - galileo_e5_a_code_gen_complex_sampled(gsl::span>(codeI, code_length_), a, + galileo_e5_a_code_gen_complex_sampled(gsl::span>(codeI.data(), code_length_), a, gnss_synchro_->PRN, fs_in_, 0); std::array b = {{'5', 'Q', '\0'}}; - galileo_e5_a_code_gen_complex_sampled(gsl::span>(codeQ, code_length_), b, + galileo_e5_a_code_gen_complex_sampled(gsl::span>(codeQ.data(), code_length_), b, gnss_synchro_->PRN, fs_in_, 0); } else { std::array signal_type_ = {{'5', 'X', '\0'}}; - galileo_e5_a_code_gen_complex_sampled(gsl::span>(codeI, code_length_), signal_type_, + galileo_e5_a_code_gen_complex_sampled(gsl::span>(codeI.data(), code_length_), signal_type_, gnss_synchro_->PRN, fs_in_, 0); } // WARNING: 3ms are coherently integrated. Secondary sequence (1,1,1) // is generated, and modulated in the 'block'. - gsl::span codeQ_span(codeQ_, vector_length_); - gsl::span codeI_span(codeI_, vector_length_); + gsl::span codeQ_span(codeQ_.data(), vector_length_); + gsl::span codeI_span(codeI_.data(), vector_length_); if (Zero_padding == 0) // if no zero_padding { for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(codeI, code_length_, codeI_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(codeI.data(), code_length_, codeI_span.subspan(i * code_length_, code_length_).data()); if (gnss_synchro_->Signal[0] == '5' && gnss_synchro_->Signal[1] == 'X') { - std::copy_n(codeQ, code_length_, codeQ_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(codeQ.data(), code_length_, codeQ_span.subspan(i * code_length_, code_length_).data()); } } } else { // 1ms code + 1ms zero padding - std::copy_n(codeI, code_length_, codeI_); + std::copy_n(codeI.data(), code_length_, codeI_.data()); if (gnss_synchro_->Signal[0] == '5' && gnss_synchro_->Signal[1] == 'X') { - std::copy_n(codeQ, code_length_, codeQ_); + std::copy_n(codeQ.data(), code_length_, codeQ_.data()); } } - acquisition_cc_->set_local_code(codeI_, codeQ_); - delete[] codeI; - delete[] codeQ; + acquisition_cc_->set_local_code(codeI_.data(), codeQ_.data()); } } diff --git a/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.h b/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.h index aefcd7a23..7064c0aa9 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.h +++ b/src/algorithms/acquisition/adapters/galileo_e5a_noncoherent_iq_acquisition_caf.h @@ -41,7 +41,9 @@ #include "channel_fsm.h" #include "galileo_e5a_noncoherent_iq_acquisition_caf_cc.h" #include "gnss_synchro.h" +#include #include +#include class ConfigurationInterface; @@ -95,13 +97,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_cc_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -171,8 +174,8 @@ private: std::string dump_filename_; int Zero_padding; int CAF_window_hz_; - std::complex* codeI_; - std::complex* codeQ_; + std::vector> codeI_; + std::vector> codeQ_; bool both_signal_components; Gnss_Synchro* gnss_synchro_; std::string role_; diff --git a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc index 7da2a1bd6..7f8d72196 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.cc @@ -124,7 +124,7 @@ GalileoE5aPcpsAcquisition::GalileoE5aPcpsAcquisition(ConfigurationInterface* con code_length_ = static_cast(std::round(static_cast(fs_in_) / GALILEO_E5A_CODE_CHIP_RATE_HZ * static_cast(GALILEO_E5A_CODE_LENGTH_CHIPS))); vector_length_ = code_length_ * sampled_ms_; - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "gr_complex") { @@ -165,10 +165,7 @@ GalileoE5aPcpsAcquisition::GalileoE5aPcpsAcquisition(ConfigurationInterface* con } -GalileoE5aPcpsAcquisition::~GalileoE5aPcpsAcquisition() -{ - delete[] code_; -} +GalileoE5aPcpsAcquisition::~GalileoE5aPcpsAcquisition() = default; void GalileoE5aPcpsAcquisition::stop_acquisition() @@ -236,7 +233,7 @@ void GalileoE5aPcpsAcquisition::init() void GalileoE5aPcpsAcquisition::set_local_code() { - auto* code = new gr_complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; std::array signal_; signal_[0] = '5'; signal_[2] = '\0'; @@ -256,20 +253,19 @@ void GalileoE5aPcpsAcquisition::set_local_code() if (acq_parameters_.use_automatic_resampler) { - galileo_e5_a_code_gen_complex_sampled(gsl::span(code, code_length_), signal_, gnss_synchro_->PRN, acq_parameters_.resampled_fs, 0); + galileo_e5_a_code_gen_complex_sampled(gsl::span(code.get(), code_length_), signal_, gnss_synchro_->PRN, acq_parameters_.resampled_fs, 0); } else { - galileo_e5_a_code_gen_complex_sampled(gsl::span(code, code_length_), signal_, gnss_synchro_->PRN, fs_in_, 0); + galileo_e5_a_code_gen_complex_sampled(gsl::span(code.get(), code_length_), signal_, gnss_synchro_->PRN, fs_in_, 0); } - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.h b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.h index 832f3223a..f6b694a67 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition.h @@ -35,7 +35,9 @@ #include "channel_fsm.h" #include "gnss_synchro.h" #include "pcps_acquisition.h" +#include #include +#include class ConfigurationInterface; @@ -86,13 +88,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -143,29 +146,23 @@ public: /*! * \brief Sets the resampler latency to account it in the acquisition code delay estimation */ - void set_resampler_latency(uint32_t latency_samples) override; private: float calculate_threshold(float pfa); - ConfigurationInterface* configuration_; - pcps_acquisition_sptr acquisition_; Acq_Conf acq_parameters_; size_t item_size_; - std::string item_type_; std::string dump_filename_; std::string role_; - bool bit_transition_flag_; bool dump_; bool acq_pilot_; bool use_CFAR_; bool blocking_; bool acq_iq_; - unsigned int vector_length_; unsigned int code_length_; unsigned int channel_; @@ -176,18 +173,10 @@ private: unsigned int max_dwells_; unsigned int in_streams_; unsigned int out_streams_; - int64_t fs_in_; - float threshold_; - - /* - std::complex* codeI_; - std::complex* codeQ_; - */ - - gr_complex* code_; - + std::vector> code_; Gnss_Synchro* gnss_synchro_; }; + #endif /* GALILEO_E5A_PCPS_ACQUISITION_H_ */ diff --git a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.cc b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.cc index 15361509f..54f367158 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.cc +++ b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.cc @@ -110,9 +110,9 @@ GalileoE5aPcpsAcquisitionFpga::GalileoE5aPcpsAcquisitionFpga(ConfigurationInterf // compute all the GALILEO E5 PRN Codes (this is done only once in the class constructor in order to avoid re-computing the PRN codes every time // a channel is assigned) auto* fft_if = new gr::fft::fft_complex(nsamples_total, true); // Direct FFT - auto* code = new std::complex[nsamples_total]; // buffer for the local code + std::vector> code(nsamples_total); // buffer for the local code auto* fft_codes_padded = static_cast(volk_gnsssdr_malloc(nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_all_fft_codes_ = new uint32_t[(nsamples_total * GALILEO_E5A_NUMBER_OF_CODES)]; // memory containing all the possible fft codes for PRN 0 to 32 + d_all_fft_codes_ = std::vector(nsamples_total * GALILEO_E5A_NUMBER_OF_CODES); // memory containing all the possible fft codes for PRN 0 to 32 float max; // temporary maxima search int32_t tmp, tmp2, local_code, fft_data; @@ -136,7 +136,7 @@ GalileoE5aPcpsAcquisitionFpga::GalileoE5aPcpsAcquisitionFpga(ConfigurationInterf signal_[1] = 'I'; } - galileo_e5_a_code_gen_complex_sampled(gsl::span>(code, nsamples_total), signal_, PRN, fs_in, 0); + galileo_e5_a_code_gen_complex_sampled(gsl::span>(code.data(), nsamples_total), signal_, PRN, fs_in, 0); for (uint32_t s = code_length; s < 2 * code_length; s++) { @@ -149,7 +149,7 @@ GalileoE5aPcpsAcquisitionFpga::GalileoE5aPcpsAcquisitionFpga(ConfigurationInterf code[s] = std::complex(0.0, 0.0); } - std::copy_n(code, nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer + std::copy_n(code.data(), nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer fft_if->execute(); // Run the FFT of local code volk_32fc_conjugate_32fc(fft_codes_padded, fft_if->get_outbuf(), nsamples_total); // conjugate values @@ -177,7 +177,7 @@ GalileoE5aPcpsAcquisitionFpga::GalileoE5aPcpsAcquisitionFpga(ConfigurationInterf } } - acq_parameters.all_fft_codes = d_all_fft_codes_; + acq_parameters.all_fft_codes = d_all_fft_codes_.data(); // reference for the FPGA FFT-IFFT attenuation factor acq_parameters.total_block_exp = configuration_->property(role + ".total_block_exp", 13); @@ -193,16 +193,12 @@ GalileoE5aPcpsAcquisitionFpga::GalileoE5aPcpsAcquisitionFpga(ConfigurationInterf gnss_synchro_ = nullptr; // temporary buffers that we can delete - delete[] code; delete fft_if; - delete[] fft_codes_padded; + volk_gnsssdr_free(fft_codes_padded); } -GalileoE5aPcpsAcquisitionFpga::~GalileoE5aPcpsAcquisitionFpga() -{ - delete[] d_all_fft_codes_; -} +GalileoE5aPcpsAcquisitionFpga::~GalileoE5aPcpsAcquisitionFpga() = default; void GalileoE5aPcpsAcquisitionFpga::stop_acquisition() diff --git a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.h b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.h index d30868547..37e0bf9dd 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.h +++ b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.h @@ -39,7 +39,9 @@ #include // for lv_16sc_t #include // for size_t #include +#include #include +#include class Gnss_Synchro; class ConfigurationInterface; @@ -99,8 +101,8 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; @@ -167,24 +169,19 @@ public: private: ConfigurationInterface* configuration_; pcps_acquisition_fpga_sptr acquisition_fpga_; - std::string item_type_; std::string dump_filename_; std::string role_; - bool acq_pilot_; bool acq_iq_; - uint32_t channel_; std::weak_ptr channel_fsm_; uint32_t doppler_max_; uint32_t doppler_step_; unsigned int in_streams_; unsigned int out_streams_; - Gnss_Synchro* gnss_synchro_; - - uint32_t* d_all_fft_codes_; // memory that contains all the code ffts + std::vector d_all_fft_codes_; // memory that contains all the code ffts }; #endif /* GNSS_SDR_GALILEO_E5A_PCPS_ACQUISITION_FPGA_H_ */ diff --git a/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.cc index 45c7645bb..bdac10535 100644 --- a/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.cc @@ -94,7 +94,7 @@ GlonassL1CaPcpsAcquisition::GlonassL1CaPcpsAcquisition( vector_length_ *= 2; } - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "cshort") { @@ -138,16 +138,14 @@ GlonassL1CaPcpsAcquisition::GlonassL1CaPcpsAcquisition( } -GlonassL1CaPcpsAcquisition::~GlonassL1CaPcpsAcquisition() -{ - delete[] code_; -} +GlonassL1CaPcpsAcquisition::~GlonassL1CaPcpsAcquisition() = default; void GlonassL1CaPcpsAcquisition::stop_acquisition() { } + void GlonassL1CaPcpsAcquisition::set_threshold(float threshold) { float pfa = configuration_->property(role_ + ".pfa", 0.0); @@ -207,18 +205,17 @@ void GlonassL1CaPcpsAcquisition::init() void GlonassL1CaPcpsAcquisition::set_local_code() { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; glonass_l1_ca_code_gen_complex_sampled(gsl::span>(code, code_length_), /* gnss_synchro_->PRN,*/ fs_in_, 0); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.h b/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.h index a9a6fd18a..1768c3bb4 100644 --- a/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/glonass_l1_ca_pcps_acquisition.h @@ -39,7 +39,9 @@ #include "gnss_synchro.h" #include "pcps_acquisition.h" #include +#include #include +#include class ConfigurationInterface; @@ -86,6 +88,7 @@ public: * tracking blocks */ void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro) override; + /*! * \brief Set acquisition channel unique ID */ @@ -96,13 +99,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -172,12 +176,11 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.cc index 217f31d31..2210eebbf 100644 --- a/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.cc @@ -93,7 +93,7 @@ GlonassL2CaPcpsAcquisition::GlonassL2CaPcpsAcquisition( vector_length_ *= 2; } - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "cshort") { @@ -137,10 +137,7 @@ GlonassL2CaPcpsAcquisition::GlonassL2CaPcpsAcquisition( } -GlonassL2CaPcpsAcquisition::~GlonassL2CaPcpsAcquisition() -{ - delete[] code_; -} +GlonassL2CaPcpsAcquisition::~GlonassL2CaPcpsAcquisition() = default; void GlonassL2CaPcpsAcquisition::stop_acquisition() @@ -207,18 +204,17 @@ void GlonassL2CaPcpsAcquisition::init() void GlonassL2CaPcpsAcquisition::set_local_code() { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; glonass_l2_ca_code_gen_complex_sampled(gsl::span>(code, code_length_), /* gnss_synchro_->PRN,*/ fs_in_, 0); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.h b/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.h index 09b66fbe7..efe36e7ea 100644 --- a/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/glonass_l2_ca_pcps_acquisition.h @@ -38,7 +38,9 @@ #include "gnss_synchro.h" #include "pcps_acquisition.h" #include +#include #include +#include class ConfigurationInterface; @@ -96,13 +98,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -172,12 +175,11 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc index 297464005..9c50bb3c1 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.cc @@ -123,7 +123,7 @@ GpsL1CaPcpsAcquisition::GpsL1CaPcpsAcquisition( acq_parameters_.samples_per_code = acq_parameters_.samples_per_ms * static_cast(GPS_L1_CA_CODE_PERIOD * 1000.0); vector_length_ = std::floor(acq_parameters_.sampled_ms * acq_parameters_.samples_per_ms) * (acq_parameters_.bit_transition_flag ? 2 : 1); - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "cshort") { @@ -161,16 +161,14 @@ GpsL1CaPcpsAcquisition::GpsL1CaPcpsAcquisition( } -GpsL1CaPcpsAcquisition::~GpsL1CaPcpsAcquisition() -{ - delete[] code_; -} +GpsL1CaPcpsAcquisition::~GpsL1CaPcpsAcquisition() = default; void GpsL1CaPcpsAcquisition::stop_acquisition() { } + void GpsL1CaPcpsAcquisition::set_threshold(float threshold) { float pfa = configuration_->property(role_ + ".pfa", 0.0); @@ -228,7 +226,7 @@ void GpsL1CaPcpsAcquisition::init() void GpsL1CaPcpsAcquisition::set_local_code() { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; if (acq_parameters_.use_automatic_resampler) { @@ -238,14 +236,13 @@ void GpsL1CaPcpsAcquisition::set_local_code() { gps_l1_ca_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_, 0); } - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h index 8d3f0fb64..bef0202bc 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition.h @@ -43,7 +43,9 @@ #include "pcps_acquisition.h" #include #include +#include #include +#include class ConfigurationInterface; @@ -102,13 +104,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -157,10 +160,8 @@ public: /*! * \brief Sets the resampler latency to account it in the acquisition code delay estimation */ - void set_resampler_latency(uint32_t latency_samples) override; - private: ConfigurationInterface* configuration_; pcps_acquisition_sptr acquisition_; @@ -184,12 +185,11 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc index 6a4cfa7fd..1c67657b8 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.cc @@ -80,7 +80,7 @@ GpsL1CaPcpsAcquisitionFineDoppler::GpsL1CaPcpsAcquisitionFineDoppler( //--- Find number of samples per spreading code ------------------------- vector_length_ = round(fs_in_ / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); acq_parameters.samples_per_ms = vector_length_; - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "gr_complex") { @@ -109,10 +109,7 @@ GpsL1CaPcpsAcquisitionFineDoppler::GpsL1CaPcpsAcquisitionFineDoppler( } -GpsL1CaPcpsAcquisitionFineDoppler::~GpsL1CaPcpsAcquisitionFineDoppler() -{ - delete[] code_; -} +GpsL1CaPcpsAcquisitionFineDoppler::~GpsL1CaPcpsAcquisitionFineDoppler() = default; void GpsL1CaPcpsAcquisitionFineDoppler::stop_acquisition() @@ -163,8 +160,8 @@ void GpsL1CaPcpsAcquisitionFineDoppler::init() void GpsL1CaPcpsAcquisitionFineDoppler::set_local_code() { - gps_l1_ca_code_gen_complex_sampled(gsl::span>(code_, vector_length_), gnss_synchro_->PRN, fs_in_, 0); - acquisition_cc_->set_local_code(code_); + gps_l1_ca_code_gen_complex_sampled(gsl::span>(code_.data(), vector_length_), gnss_synchro_->PRN, fs_in_, 0); + acquisition_cc_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h index d310bcfbb..80fc080b6 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fine_doppler.h @@ -37,7 +37,9 @@ #include "channel_fsm.h" #include "gnss_synchro.h" #include "pcps_acquisition_fine_doppler_cc.h" +#include #include +#include class ConfigurationInterface; @@ -95,13 +97,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_cc_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -161,7 +164,7 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.cc index 7c6d7ad2d..a1307b68f 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.cc @@ -105,15 +105,15 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( // a channel is assigned) auto* fft_if = new gr::fft::fft_complex(nsamples_total, true); // Direct FFT // allocate memory to compute all the PRNs and compute all the possible codes - auto* code = new std::complex[nsamples_total]; // buffer for the local code + std::vector> code(nsamples_total); // buffer for the local code auto* fft_codes_padded = static_cast(volk_gnsssdr_malloc(nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_all_fft_codes_ = new uint32_t[(nsamples_total * NUM_PRNs)]; // memory containing all the possible fft codes for PRN 0 to 32 + d_all_fft_codes_ = std::vector(nsamples_total * NUM_PRNs); // memory containing all the possible fft codes for PRN 0 to 32 float max; int32_t tmp, tmp2, local_code, fft_data; // temporary maxima search for (uint32_t PRN = 1; PRN <= NUM_PRNs; PRN++) { - gps_l1_ca_code_gen_complex_sampled(gsl::span>(code, nsamples_total), PRN, fs_in, 0); // generate PRN code + gps_l1_ca_code_gen_complex_sampled(gsl::span>(code.data(), nsamples_total), PRN, fs_in, 0); // generate PRN code for (uint32_t s = code_length; s < 2 * code_length; s++) { @@ -126,7 +126,7 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( code[s] = std::complex(0.0, 0.0); } - std::copy_n(code, nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer + std::copy_n(code.data(), nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer fft_if->execute(); // Run the FFT of local code volk_32fc_conjugate_32fc(fft_codes_padded, fft_if->get_outbuf(), nsamples_total); // conjugate values @@ -155,7 +155,7 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( } //acq_parameters - acq_parameters.all_fft_codes = d_all_fft_codes_; + acq_parameters.all_fft_codes = d_all_fft_codes_.data(); // reference for the FPGA FFT-IFFT attenuation factor acq_parameters.total_block_exp = configuration_->property(role + ".total_block_exp", 10); @@ -171,16 +171,12 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( gnss_synchro_ = nullptr; // temporary buffers that we can delete - delete[] code; delete fft_if; - delete[] fft_codes_padded; + volk_gnsssdr_free(fft_codes_padded); } -GpsL1CaPcpsAcquisitionFpga::~GpsL1CaPcpsAcquisitionFpga() -{ - delete[] d_all_fft_codes_; -} +GpsL1CaPcpsAcquisitionFpga::~GpsL1CaPcpsAcquisitionFpga() = default; void GpsL1CaPcpsAcquisitionFpga::stop_acquisition() diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.h index f0f652a99..39b8d2e1f 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_acquisition_fpga.h @@ -41,7 +41,9 @@ #include // for basic_block_sptr, top_block_sptr #include // for lv_16sc_t #include // for size_t -#include // for string +#include +#include +#include class Gnss_Synchro; class ConfigurationInterface; @@ -167,7 +169,7 @@ private: std::string role_; unsigned int in_streams_; unsigned int out_streams_; - uint32_t* d_all_fft_codes_; // memory that contains all the code ffts + std::vector d_all_fft_codes_; // memory that contains all the code ffts }; #endif /* GNSS_SDR_GPS_L1_CA_PCPS_ACQUISITION_FPGA_H_ */ diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc index d603eb216..592648bd6 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.cc @@ -70,7 +70,7 @@ GpsL1CaPcpsAssistedAcquisition::GpsL1CaPcpsAssistedAcquisition( //--- Find number of samples per spreading code ------------------------- vector_length_ = round(fs_in_ / (GPS_L1_CA_CODE_RATE_HZ / GPS_L1_CA_CODE_LENGTH_CHIPS)); - code_ = new gr_complex[vector_length_]; + code_ = std::make_shared>(vector_length_); if (item_type_ == "gr_complex") { @@ -101,10 +101,7 @@ GpsL1CaPcpsAssistedAcquisition::GpsL1CaPcpsAssistedAcquisition( } -GpsL1CaPcpsAssistedAcquisition::~GpsL1CaPcpsAssistedAcquisition() -{ - delete[] code_; -} +GpsL1CaPcpsAssistedAcquisition::~GpsL1CaPcpsAssistedAcquisition() = default; void GpsL1CaPcpsAssistedAcquisition::stop_acquisition() @@ -154,8 +151,8 @@ void GpsL1CaPcpsAssistedAcquisition::init() void GpsL1CaPcpsAssistedAcquisition::set_local_code() { - gps_l1_ca_code_gen_complex_sampled(gsl::span(code_, vector_length_), gnss_synchro_->PRN, fs_in_, 0); - acquisition_cc_->set_local_code(code_); + gps_l1_ca_code_gen_complex_sampled(gsl::span(code_.get(), vector_length_), gnss_synchro_->PRN, fs_in_, 0); + acquisition_cc_->set_local_code(code_.get()); } void GpsL1CaPcpsAssistedAcquisition::reset() diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.h index 222bfafe8..9b38e6608 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_assisted_acquisition.h @@ -37,7 +37,9 @@ #include "channel_fsm.h" #include "gnss_synchro.h" #include "pcps_assisted_acquisition_cc.h" +#include #include +#include class ConfigurationInterface; @@ -95,13 +97,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_cc_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -147,7 +150,6 @@ private: size_t item_size_; std::string item_type_; unsigned int vector_length_; - //unsigned int satellite_; unsigned int channel_; std::weak_ptr channel_fsm_; float threshold_; @@ -159,7 +161,7 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::shared_ptr> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.cc index f5d193d13..de5832cf1 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.cc @@ -85,7 +85,7 @@ GpsL1CaPcpsOpenClAcquisition::GpsL1CaPcpsOpenClAcquisition( vector_length_ = code_length_ * sampled_ms_; - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "gr_complex") { @@ -121,16 +121,14 @@ GpsL1CaPcpsOpenClAcquisition::GpsL1CaPcpsOpenClAcquisition( } -GpsL1CaPcpsOpenClAcquisition::~GpsL1CaPcpsOpenClAcquisition() -{ - delete[] code_; -} +GpsL1CaPcpsOpenClAcquisition::~GpsL1CaPcpsOpenClAcquisition() = default; void GpsL1CaPcpsOpenClAcquisition::stop_acquisition() { } + void GpsL1CaPcpsOpenClAcquisition::set_threshold(float threshold) { float pfa = configuration_->property(role_ + std::to_string(channel_) + ".pfa", 0.0); @@ -211,19 +209,17 @@ void GpsL1CaPcpsOpenClAcquisition::set_local_code() { if (item_type_ == "gr_complex") { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; gps_l1_ca_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_, 0); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_cc_->set_local_code(code_); - - delete[] code; + acquisition_cc_->set_local_code(code_.data()); } } diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.h index 350589f17..c70d77a54 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_opencl_acquisition.h @@ -36,7 +36,9 @@ #include "gnss_synchro.h" #include "pcps_opencl_acquisition_cc.h" #include +#include #include +#include class ConfigurationInterface; @@ -94,13 +96,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_cc_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -169,12 +172,11 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.cc index 2867b53a0..251216eab 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.cc @@ -105,7 +105,7 @@ GpsL1CaPcpsQuickSyncAcquisition::GpsL1CaPcpsQuickSyncAcquisition( dump_filename_ = configuration_->property(role + ".dump_filename", default_dump_filename); int samples_per_ms = round(code_length_); - code_ = new gr_complex[code_length_](); + code_ = std::vector>(code_length_); /*Object relevant information for debugging*/ LOG(INFO) << "Implementation: " << this->implementation() << ", Vector Length: " << vector_length_ @@ -150,16 +150,14 @@ GpsL1CaPcpsQuickSyncAcquisition::GpsL1CaPcpsQuickSyncAcquisition( } -GpsL1CaPcpsQuickSyncAcquisition::~GpsL1CaPcpsQuickSyncAcquisition() -{ - delete[] code_; -} +GpsL1CaPcpsQuickSyncAcquisition::~GpsL1CaPcpsQuickSyncAcquisition() = default; void GpsL1CaPcpsQuickSyncAcquisition::stop_acquisition() { } + void GpsL1CaPcpsQuickSyncAcquisition::set_threshold(float threshold) { float pfa = configuration_->property(role_ + std::to_string(channel_) + ".pfa", 0.0); @@ -237,19 +235,17 @@ void GpsL1CaPcpsQuickSyncAcquisition::set_local_code() { if (item_type_ == "gr_complex") { - auto* code = new std::complex[code_length_](); + std::unique_ptr> code{new std::complex[code_length_]}; gps_l1_ca_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_, 0); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < (sampled_ms_ / folding_factor_); i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_cc_->set_local_code(code_); - - delete[] code; + acquisition_cc_->set_local_code(code_.data()); } } diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.h index 110589952..7f5390782 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_quicksync_acquisition.h @@ -38,7 +38,9 @@ #include "gnss_synchro.h" #include "pcps_quicksync_acquisition_cc.h" #include +#include #include +#include class ConfigurationInterface; @@ -96,13 +98,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_cc_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -170,12 +173,11 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.cc index 731bd2e77..c670cc0bb 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.cc @@ -76,7 +76,7 @@ GpsL1CaPcpsTongAcquisition::GpsL1CaPcpsTongAcquisition( vector_length_ = code_length_ * sampled_ms_; - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "gr_complex") { @@ -112,16 +112,14 @@ GpsL1CaPcpsTongAcquisition::GpsL1CaPcpsTongAcquisition( } -GpsL1CaPcpsTongAcquisition::~GpsL1CaPcpsTongAcquisition() -{ - delete[] code_; -} +GpsL1CaPcpsTongAcquisition::~GpsL1CaPcpsTongAcquisition() = default; void GpsL1CaPcpsTongAcquisition::stop_acquisition() { } + void GpsL1CaPcpsTongAcquisition::set_threshold(float threshold) { float pfa = configuration_->property(role_ + std::to_string(channel_) + ".pfa", 0.0); @@ -194,23 +192,22 @@ void GpsL1CaPcpsTongAcquisition::init() //set_local_code(); } + void GpsL1CaPcpsTongAcquisition::set_local_code() { if (item_type_ == "gr_complex") { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; gps_l1_ca_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_, 0); - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < sampled_ms_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_cc_->set_local_code(code_); - - delete[] code; + acquisition_cc_->set_local_code(code_.data()); } } diff --git a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.h b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.h index 856b1c603..7193e5466 100644 --- a/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l1_ca_pcps_tong_acquisition.h @@ -37,7 +37,9 @@ #include "gnss_synchro.h" #include "pcps_tong_acquisition_cc.h" #include +#include #include +#include class ConfigurationInterface; @@ -95,13 +97,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_cc_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of TONG algorithm */ @@ -169,12 +172,11 @@ private: int64_t fs_in_; bool dump_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.cc index 2777d8440..d424bdb5f 100644 --- a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.cc @@ -127,7 +127,7 @@ GpsL2MPcpsAcquisition::GpsL2MPcpsAcquisition( acq_parameters_.samples_per_code = acq_parameters_.samples_per_ms * static_cast(GPS_L2_M_PERIOD * 1000.0); vector_length_ = acq_parameters_.sampled_ms * acq_parameters_.samples_per_ms * (acq_parameters_.bit_transition_flag ? 2 : 1); - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); if (item_type_ == "cshort") { @@ -165,10 +165,7 @@ GpsL2MPcpsAcquisition::GpsL2MPcpsAcquisition( } -GpsL2MPcpsAcquisition::~GpsL2MPcpsAcquisition() -{ - delete[] code_; -} +GpsL2MPcpsAcquisition::~GpsL2MPcpsAcquisition() = default; void GpsL2MPcpsAcquisition::stop_acquisition() @@ -240,25 +237,24 @@ void GpsL2MPcpsAcquisition::init() void GpsL2MPcpsAcquisition::set_local_code() { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; if (acq_parameters_.use_automatic_resampler) { - gps_l2c_m_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, acq_parameters_.resampled_fs); + gps_l2c_m_code_gen_complex_sampled(gsl::span>(code.get(), code_length_), gnss_synchro_->PRN, acq_parameters_.resampled_fs); } else { - gps_l2c_m_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_); + gps_l2c_m_code_gen_complex_sampled(gsl::span>(code.get(), code_length_), gnss_synchro_->PRN, fs_in_); } - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < num_codes_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } diff --git a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.h b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.h index d189a3032..25a792d69 100644 --- a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition.h @@ -40,7 +40,9 @@ #include "pcps_acquisition.h" #include #include +#include #include +#include class ConfigurationInterface; @@ -99,13 +101,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -154,10 +157,8 @@ public: /*! * \brief Sets the resampler latency to account it in the acquisition code delay estimation */ - void set_resampler_latency(uint32_t latency_samples) override; - private: ConfigurationInterface* configuration_; pcps_acquisition_sptr acquisition_; @@ -180,13 +181,12 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int in_streams_; unsigned int out_streams_; unsigned int num_codes_; - float calculate_threshold(float pfa); }; diff --git a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.cc b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.cc index dcbbd331a..a92f5c158 100644 --- a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.cc +++ b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.cc @@ -104,22 +104,21 @@ GpsL2MPcpsAcquisitionFpga::GpsL2MPcpsAcquisitionFpga( // a channel is assigned) auto* fft_if = new gr::fft::fft_complex(vector_length, true); // Direct FFT // allocate memory to compute all the PRNs and compute all the possible codes - auto* code = new std::complex[nsamples_total]; // buffer for the local code + std::vector> code(nsamples_total); // buffer for the local code auto* fft_codes_padded = static_cast(volk_gnsssdr_malloc(nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - //d_all_fft_codes_ = new lv_16sc_t[nsamples_total * NUM_PRNs]; // memory containing all the possible fft codes for PRN 0 to 32 - d_all_fft_codes_ = new uint32_t[(nsamples_total * NUM_PRNs)]; // memory containing all the possible fft codes for PRN 0 to 32 - float max; // temporary maxima search + d_all_fft_codes_ = std::vector(nsamples_total * NUM_PRNs); // memory containing all the possible fft codes for PRN 0 to 32 + float max; // temporary maxima search int32_t tmp, tmp2, local_code, fft_data; for (unsigned int PRN = 1; PRN <= NUM_PRNs; PRN++) { - gps_l2c_m_code_gen_complex_sampled(gsl::span>(code, nsamples_total), PRN, fs_in_); + gps_l2c_m_code_gen_complex_sampled(gsl::span>(code.data(), nsamples_total), PRN, fs_in_); // fill in zero padding for (unsigned int s = code_length; s < nsamples_total; s++) { code[s] = std::complex(0.0, 0.0); } - std::copy_n(code, nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer + std::copy_n(code.data(), nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer fft_if->execute(); // Run the FFT of local code volk_32fc_conjugate_32fc(fft_codes_padded, fft_if->get_outbuf(), nsamples_total); // conjugate values max = 0; // initialize maximum value @@ -149,12 +148,11 @@ GpsL2MPcpsAcquisitionFpga::GpsL2MPcpsAcquisitionFpga( } } - acq_parameters.all_fft_codes = d_all_fft_codes_; + acq_parameters.all_fft_codes = d_all_fft_codes_.data(); // temporary buffers that we can delete - delete[] code; delete fft_if; - delete[] fft_codes_padded; + volk_gnsssdr_free(fft_codes_padded); acquisition_fpga_ = pcps_make_acquisition_fpga(acq_parameters); @@ -162,15 +160,11 @@ GpsL2MPcpsAcquisitionFpga::GpsL2MPcpsAcquisitionFpga( doppler_step_ = 0; gnss_synchro_ = nullptr; - threshold_ = 0.0; } -GpsL2MPcpsAcquisitionFpga::~GpsL2MPcpsAcquisitionFpga() -{ - delete[] d_all_fft_codes_; -} +GpsL2MPcpsAcquisitionFpga::~GpsL2MPcpsAcquisitionFpga() = default; void GpsL2MPcpsAcquisitionFpga::stop_acquisition() diff --git a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.h b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.h index 7c30efb85..9507abffd 100644 --- a/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.h +++ b/src/algorithms/acquisition/adapters/gps_l2_m_pcps_acquisition_fpga.h @@ -39,7 +39,9 @@ #include // for basic_block_sptr, top_block_sptr #include // for lv_16sc_t #include // for size_t +#include // for weak_ptr #include // for string +#include class Gnss_Synchro; class ConfigurationInterface; @@ -98,8 +100,8 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; @@ -168,10 +170,7 @@ private: std::string role_; unsigned int in_streams_; unsigned int out_streams_; - - uint32_t* d_all_fft_codes_; // memory that contains all the code ffts - - //float calculate_threshold(float pfa); + std::vector d_all_fft_codes_; // memory that contains all the code ffts }; #endif /* GNSS_SDR_GPS_L2_M_PCPS_ACQUISITION_FPGA_H_ */ diff --git a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.cc b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.cc index 3c30f8e5f..8b0a6e793 100644 --- a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.cc +++ b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.cc @@ -134,7 +134,7 @@ GpsL5iPcpsAcquisition::GpsL5iPcpsAcquisition( acq_parameters_.samples_per_code = acq_parameters_.samples_per_ms * static_cast(GPS_L5I_PERIOD * 1000.0); vector_length_ = std::floor(acq_parameters_.sampled_ms * acq_parameters_.samples_per_ms) * (acq_parameters_.bit_transition_flag ? 2 : 1); - code_ = new gr_complex[vector_length_]; + code_ = std::vector>(vector_length_); acquisition_ = pcps_make_acquisition(acq_parameters_); DLOG(INFO) << "acquisition(" << acquisition_->unique_id() << ")"; @@ -160,10 +160,7 @@ GpsL5iPcpsAcquisition::GpsL5iPcpsAcquisition( } -GpsL5iPcpsAcquisition::~GpsL5iPcpsAcquisition() -{ - delete[] code_; -} +GpsL5iPcpsAcquisition::~GpsL5iPcpsAcquisition() = default; void GpsL5iPcpsAcquisition::stop_acquisition() @@ -234,25 +231,24 @@ void GpsL5iPcpsAcquisition::init() void GpsL5iPcpsAcquisition::set_local_code() { - auto* code = new std::complex[code_length_]; + std::unique_ptr> code{new std::complex[code_length_]}; if (acq_parameters_.use_automatic_resampler) { - gps_l5i_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, acq_parameters_.resampled_fs); + gps_l5i_code_gen_complex_sampled(gsl::span>(code.get(), code_length_), gnss_synchro_->PRN, acq_parameters_.resampled_fs); } else { - gps_l5i_code_gen_complex_sampled(gsl::span>(code, code_length_), gnss_synchro_->PRN, fs_in_); + gps_l5i_code_gen_complex_sampled(gsl::span>(code.get(), code_length_), gnss_synchro_->PRN, fs_in_); } - gsl::span code_span(code_, vector_length_); + gsl::span code_span(code_.data(), vector_length_); for (unsigned int i = 0; i < num_codes_; i++) { - std::copy_n(code, code_length_, code_span.subspan(i * code_length_, code_length_).data()); + std::copy_n(code.get(), code_length_, code_span.subspan(i * code_length_, code_length_).data()); } - acquisition_->set_local_code(code_); - delete[] code; + acquisition_->set_local_code(code_.data()); } @@ -261,6 +257,7 @@ void GpsL5iPcpsAcquisition::reset() acquisition_->set_active(true); } + void GpsL5iPcpsAcquisition::set_state(int state) { acquisition_->set_state(state); @@ -360,6 +357,7 @@ gr::basic_block_sptr GpsL5iPcpsAcquisition::get_right_block() return acquisition_; } + void GpsL5iPcpsAcquisition::set_resampler_latency(uint32_t latency_samples) { acquisition_->set_resampler_latency(latency_samples); diff --git a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.h b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.h index 576c86e33..17a1b634c 100644 --- a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.h +++ b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition.h @@ -31,8 +31,8 @@ * ------------------------------------------------------------------------- */ -#ifndef GNSS_SDR_GPS_L5i_PCPS_ACQUISITION_H_ -#define GNSS_SDR_GPS_L5i_PCPS_ACQUISITION_H_ +#ifndef GNSS_SDR_GPS_L5I_PCPS_ACQUISITION_H_ +#define GNSS_SDR_GPS_L5I_PCPS_ACQUISITION_H_ #include "channel_fsm.h" #include "complex_byte_to_float_x2.h" @@ -40,7 +40,9 @@ #include "pcps_acquisition.h" #include #include +#include #include +#include class ConfigurationInterface; @@ -99,13 +101,14 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; acquisition_->set_channel_fsm(channel_fsm); } + /*! * \brief Set statistics threshold of PCPS algorithm */ @@ -154,7 +157,6 @@ public: /*! * \brief Sets the resampler latency to account it in the acquisition code delay estimation */ - void set_resampler_latency(uint32_t latency_samples) override; private: @@ -179,14 +181,13 @@ private: bool dump_; bool blocking_; std::string dump_filename_; - std::complex* code_; + std::vector> code_; Gnss_Synchro* gnss_synchro_; std::string role_; unsigned int num_codes_; unsigned int in_streams_; unsigned int out_streams_; - float calculate_threshold(float pfa); }; -#endif /* GNSS_SDR_GPS_L5i_PCPS_ACQUISITION_H_ */ +#endif /* GNSS_SDR_GPS_L5I_PCPS_ACQUISITION_H_ */ diff --git a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.cc b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.cc index 118fdf651..c25f65672 100644 --- a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.cc +++ b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.cc @@ -109,16 +109,16 @@ GpsL5iPcpsAcquisitionFpga::GpsL5iPcpsAcquisitionFpga( // compute all the GPS L5 PRN Codes (this is done only once upon the class constructor in order to avoid re-computing the PRN codes every time // a channel is assigned) auto* fft_if = new gr::fft::fft_complex(nsamples_total, true); // Direct FFT - auto* code = new gr_complex[nsamples_total]; + std::vector> code(nsamples_total); auto* fft_codes_padded = static_cast(volk_gnsssdr_malloc(nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_all_fft_codes_ = new uint32_t[(nsamples_total * NUM_PRNs)]; // memory containing all the possible fft codes for PRN 0 to 32 + d_all_fft_codes_ = std::vector(nsamples_total * NUM_PRNs); // memory containing all the possible fft codes for PRN 0 to 32 float max; // temporary maxima search int32_t tmp, tmp2, local_code, fft_data; for (uint32_t PRN = 1; PRN <= NUM_PRNs; PRN++) { - gps_l5i_code_gen_complex_sampled(gsl::span(code, nsamples_total), PRN, fs_in); + gps_l5i_code_gen_complex_sampled(gsl::span(code.data(), nsamples_total), PRN, fs_in); for (uint32_t s = code_length; s < 2 * code_length; s++) { @@ -130,7 +130,7 @@ GpsL5iPcpsAcquisitionFpga::GpsL5iPcpsAcquisitionFpga( // fill in zero padding code[s] = std::complex(0.0, 0.0); } - std::copy_n(code, nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer + std::copy_n(code.data(), nsamples_total, fft_if->get_inbuf()); // copy to FFT buffer fft_if->execute(); // Run the FFT of local code volk_32fc_conjugate_32fc(fft_codes_padded, fft_if->get_outbuf(), nsamples_total); // conjugate values @@ -158,7 +158,7 @@ GpsL5iPcpsAcquisitionFpga::GpsL5iPcpsAcquisitionFpga( } } - acq_parameters.all_fft_codes = d_all_fft_codes_; + acq_parameters.all_fft_codes = d_all_fft_codes_.data(); // reference for the FPGA FFT-IFFT attenuation factor acq_parameters.total_block_exp = configuration_->property(role + ".total_block_exp", 13); @@ -174,17 +174,12 @@ GpsL5iPcpsAcquisitionFpga::GpsL5iPcpsAcquisitionFpga( gnss_synchro_ = nullptr; // temporary buffers that we can delete - delete[] code; delete fft_if; - delete[] fft_codes_padded; + volk_gnsssdr_free(fft_codes_padded); } -GpsL5iPcpsAcquisitionFpga::~GpsL5iPcpsAcquisitionFpga() -{ - //delete[] code_; - delete[] d_all_fft_codes_; -} +GpsL5iPcpsAcquisitionFpga::~GpsL5iPcpsAcquisitionFpga() = default; void GpsL5iPcpsAcquisitionFpga::stop_acquisition() diff --git a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.h b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.h index ebcbe5f31..1d5c8e922 100644 --- a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.h +++ b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.h @@ -40,7 +40,9 @@ #include // for basic_block_sptr, top_block_sptr #include // for lv_16sc_t #include // for size_t +#include #include +#include class Gnss_Synchro; class ConfigurationInterface; @@ -99,8 +101,8 @@ public: } /*! - * \brief Set channel fsm associated to this acquisition instance - */ + * \brief Set channel fsm associated to this acquisition instance + */ inline void set_channel_fsm(std::weak_ptr channel_fsm) override { channel_fsm_ = channel_fsm; @@ -167,9 +169,7 @@ private: std::string role_; unsigned int in_streams_; unsigned int out_streams_; - - uint32_t* d_all_fft_codes_; // memory that contains all the code ffts - + std::vector d_all_fft_codes_; // memory that contains all the code ffts float calculate_threshold(float pfa); }; diff --git a/src/algorithms/libs/galileo_e1_signal_processing.cc b/src/algorithms/libs/galileo_e1_signal_processing.cc index 1bf97f3b2..5bed837ee 100644 --- a/src/algorithms/libs/galileo_e1_signal_processing.cc +++ b/src/algorithms/libs/galileo_e1_signal_processing.cc @@ -34,6 +34,7 @@ #include "Galileo_E1.h" #include "gnss_signal_processing.h" #include +#include #include @@ -171,10 +172,8 @@ void galileo_e1_code_gen_float_sampled(gsl::span _dest, const std::array< galileo_e1_code_gen_int(gsl::span(primary_code_E1_chips, static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS)), _Signal, _prn); // generate Galileo E1 code, 1 sample per chip - float* _signal_E1; - _codeLength = _samplesPerChip * GALILEO_E1_B_CODE_LENGTH_CHIPS; - _signal_E1 = new float[_codeLength]; + std::unique_ptr _signal_E1{new float[_codeLength]}; gsl::span _signal_E1_span(_signal_E1, _codeLength); if (_cboc == true) @@ -196,12 +195,11 @@ void galileo_e1_code_gen_float_sampled(gsl::span _dest, const std::array< if (_fs != _samplesPerChip * _codeFreqBasis) { - auto* _resampled_signal = new float[_samplesPerCode]; + std::unique_ptr _resampled_signal{new float[_samplesPerCode]}; resampler(gsl::span(_signal_E1, _codeLength), gsl::span(_resampled_signal, _samplesPerCode), _samplesPerChip * _codeFreqBasis, _fs); // resamples code to fs - delete[] _signal_E1; - _signal_E1 = _resampled_signal; + _signal_E1 = std::move(_resampled_signal); } uint32_t size_signal_E1 = _codeLength; if (_fs != _samplesPerChip * _codeFreqBasis) @@ -211,7 +209,7 @@ void galileo_e1_code_gen_float_sampled(gsl::span _dest, const std::array< gsl::span _signal_E1_span_aux(_signal_E1, size_signal_E1); if (_galileo_signal.rfind("1C") != std::string::npos && _galileo_signal.length() >= 2 && _secondary_flag) { - auto* _signal_E1C_secondary = new float[static_cast(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * _samplesPerCode]; + std::unique_ptr _signal_E1C_secondary{new float[static_cast(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * _samplesPerCode]}; gsl::span _signal_E1C_secondary_span(_signal_E1C_secondary, static_cast(GALILEO_E1_C_SECONDARY_CODE_LENGTH) * _samplesPerCode); for (uint32_t i = 0; i < static_cast(GALILEO_E1_C_SECONDARY_CODE_LENGTH); i++) { @@ -223,8 +221,7 @@ void galileo_e1_code_gen_float_sampled(gsl::span _dest, const std::array< _samplesPerCode *= static_cast(GALILEO_E1_C_SECONDARY_CODE_LENGTH); - delete[] _signal_E1; - _signal_E1 = _signal_E1C_secondary_span.data(); + _signal_E1 = std::move(_signal_E1C_secondary); } if (_galileo_signal.rfind("1C") != std::string::npos && _galileo_signal.length() >= 2 && _secondary_flag) { @@ -236,7 +233,6 @@ void galileo_e1_code_gen_float_sampled(gsl::span _dest, const std::array< _dest[(i + delay) % _samplesPerCode] = _signal_E1_span_aux2[i]; } - delete[] _signal_E1; volk_gnsssdr_free(primary_code_E1_chips); } diff --git a/src/algorithms/libs/galileo_e5_signal_processing.cc b/src/algorithms/libs/galileo_e5_signal_processing.cc index 38a6e79e3..070e8c756 100644 --- a/src/algorithms/libs/galileo_e5_signal_processing.cc +++ b/src/algorithms/libs/galileo_e5_signal_processing.cc @@ -35,6 +35,7 @@ #include "Galileo_E5a.h" #include "gnss_signal_processing.h" #include +#include void galileo_e5_a_code_gen_complex_primary(gsl::span> _dest, int32_t _prn, const std::array& _Signal) @@ -108,7 +109,7 @@ void galileo_e5_a_code_gen_complex_sampled(gsl::span> _dest, const uint32_t _codeLength = GALILEO_E5A_CODE_LENGTH_CHIPS; const int32_t _codeFreqBasis = GALILEO_E5A_CODE_CHIP_RATE_HZ; - auto* _code = new std::complex[_codeLength](); + std::unique_ptr> _code{new std::complex[_codeLength]}; gsl::span> _code_span(_code, _codeLength); galileo_e5_a_code_gen_complex_primary(_code_span, _prn, _Signal); @@ -118,13 +119,9 @@ void galileo_e5_a_code_gen_complex_sampled(gsl::span> _dest, if (_fs != _codeFreqBasis) { - std::complex* _resampled_signal; - if (posix_memalign(reinterpret_cast(&_resampled_signal), 16, _samplesPerCode * sizeof(gr_complex)) == 0) - { - }; + std::unique_ptr> _resampled_signal{new std::complex[_samplesPerCode]}; resampler(_code_span, gsl::span>(_resampled_signal, _samplesPerCode), _codeFreqBasis, _fs); // resamples code to fs - delete[] _code; - _code = _resampled_signal; + _code = std::move(_resampled_signal); } uint32_t size_code = _codeLength; if (_fs != _codeFreqBasis) @@ -136,12 +133,4 @@ void galileo_e5_a_code_gen_complex_sampled(gsl::span> _dest, { _dest[(i + delay) % _samplesPerCode] = _code_span_aux[i]; } - if (_fs != _codeFreqBasis) - { - free(_code); - } - else - { - delete[] _code; - } } diff --git a/src/algorithms/libs/gps_l2c_signal.cc b/src/algorithms/libs/gps_l2c_signal.cc index 2708926f7..cfb49082e 100644 --- a/src/algorithms/libs/gps_l2c_signal.cc +++ b/src/algorithms/libs/gps_l2c_signal.cc @@ -33,6 +33,7 @@ #include "gps_l2c_signal.h" #include "GPS_L2C.h" #include +#include int32_t gps_l2c_m_shift(int32_t x) @@ -55,7 +56,7 @@ void gps_l2c_m_code(gsl::span _dest, uint32_t _prn) void gps_l2c_m_code_gen_complex(gsl::span> _dest, uint32_t _prn) { - auto* _code = new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L2_M_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -66,14 +67,12 @@ void gps_l2c_m_code_gen_complex(gsl::span> _dest, uint32_t _ { _dest[i] = std::complex(1.0 - 2.0 * _code_span[i], 0.0); } - - delete[] _code; } void gps_l2c_m_code_gen_float(gsl::span _dest, uint32_t _prn) { - auto* _code = new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L2_M_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -84,8 +83,6 @@ void gps_l2c_m_code_gen_float(gsl::span _dest, uint32_t _prn) { _dest[i] = 1.0 - 2.0 * static_cast(_code_span[i]); } - - delete[] _code; } @@ -94,7 +91,7 @@ void gps_l2c_m_code_gen_float(gsl::span _dest, uint32_t _prn) */ void gps_l2c_m_code_gen_complex_sampled(gsl::span> _dest, uint32_t _prn, int32_t _fs) { - auto* _code = new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L2_M_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L2_M_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -131,5 +128,4 @@ void gps_l2c_m_code_gen_complex_sampled(gsl::span> _dest, ui _dest[i] = std::complex(1.0 - 2.0 * _code_span[_codeValueIndex], 0); //repeat the chip -> upsample } } - delete[] _code; } diff --git a/src/algorithms/libs/gps_l5_signal.cc b/src/algorithms/libs/gps_l5_signal.cc index 9a9b89e03..8fa132b63 100644 --- a/src/algorithms/libs/gps_l5_signal.cc +++ b/src/algorithms/libs/gps_l5_signal.cc @@ -173,7 +173,7 @@ void make_l5q(gsl::span _dest, int32_t prn) void gps_l5i_code_gen_complex(gsl::span> _dest, uint32_t _prn) { - auto* _code = new int32_t[GPS_L5I_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L5I_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L5I_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -184,14 +184,12 @@ void gps_l5i_code_gen_complex(gsl::span> _dest, uint32_t _pr { _dest[i] = std::complex(1.0 - 2.0 * _code_span[i], 0.0); } - - delete[] _code; } void gps_l5i_code_gen_float(gsl::span _dest, uint32_t _prn) { - auto* _code = new int32_t[GPS_L5I_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L5I_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L5I_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -202,8 +200,6 @@ void gps_l5i_code_gen_float(gsl::span _dest, uint32_t _prn) { _dest[i] = 1.0 - 2.0 * static_cast(_code_span[i]); } - - delete[] _code; } @@ -212,7 +208,7 @@ void gps_l5i_code_gen_float(gsl::span _dest, uint32_t _prn) */ void gps_l5i_code_gen_complex_sampled(gsl::span> _dest, uint32_t _prn, int32_t _fs) { - auto* _code = new int32_t[GPS_L5I_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L5I_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L5I_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -249,13 +245,12 @@ void gps_l5i_code_gen_complex_sampled(gsl::span> _dest, uint _dest[i] = std::complex(1.0 - 2.0 * _code_span[_codeValueIndex], 0.0); // repeat the chip -> upsample } } - delete[] _code; } void gps_l5q_code_gen_complex(gsl::span> _dest, uint32_t _prn) { - auto* _code = new int32_t[GPS_L5Q_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L5Q_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L5Q_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -266,14 +261,12 @@ void gps_l5q_code_gen_complex(gsl::span> _dest, uint32_t _pr { _dest[i] = std::complex(1.0 - 2.0 * _code_span[i], 0.0); } - - delete[] _code; } void gps_l5q_code_gen_float(gsl::span _dest, uint32_t _prn) { - auto* _code = new int32_t[GPS_L5Q_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L5Q_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L5Q_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -284,8 +277,6 @@ void gps_l5q_code_gen_float(gsl::span _dest, uint32_t _prn) { _dest[i] = 1.0 - 2.0 * static_cast(_code_span[i]); } - - delete[] _code; } @@ -294,7 +285,7 @@ void gps_l5q_code_gen_float(gsl::span _dest, uint32_t _prn) */ void gps_l5q_code_gen_complex_sampled(gsl::span> _dest, uint32_t _prn, int32_t _fs) { - auto* _code = new int32_t[GPS_L5Q_CODE_LENGTH_CHIPS]; + std::unique_ptr _code{new int32_t[GPS_L5Q_CODE_LENGTH_CHIPS]}; gsl::span _code_span(_code, GPS_L5Q_CODE_LENGTH_CHIPS); if (_prn > 0 and _prn < 51) { @@ -332,5 +323,4 @@ void gps_l5q_code_gen_complex_sampled(gsl::span> _dest, uint _dest[i] = std::complex(1.0 - 2.0 * _code_span[_codeValueIndex], 0); // repeat the chip -> upsample } } - delete[] _code; }