From b1166de1a0a2fc7edfab333d28adeb3b355f0f34 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sat, 26 Oct 2019 22:24:42 +0200 Subject: [PATCH 1/4] Introduce volk:gnsssdr::vector The usual benefits of using objects as opposed to pointers (RAII) + the type information is manifest (no void* pointers) The best of both worlds: automatic destruction, aligned memory --- .../gnuradio_blocks/CMakeLists.txt | 3 +- .../gnuradio_blocks/pcps_acquisition.cc | 16 ++-- .../gnuradio_blocks/pcps_acquisition.h | 28 +++--- .../volk_gnsssdr/CMakeLists.txt | 1 + .../include/volk_gnsssdr/volk_gnsssdr_alloc.h | 84 ++++++++++++++++ .../gnuradio_blocks/dll_pll_veml_tracking.cc | 80 +++++++--------- .../gnuradio_blocks/dll_pll_veml_tracking.h | 28 +++--- .../dll_pll_veml_tracking_fpga.cc | 38 ++++---- .../dll_pll_veml_tracking_fpga.h | 24 ++--- .../galileo_e1_tcp_connector_tracking_cc.cc | 38 +++----- .../galileo_e1_tcp_connector_tracking_cc.h | 11 +-- ...glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc | 36 +++---- .../glonass_l1_ca_dll_pll_c_aid_tracking_cc.h | 11 ++- ...glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc | 41 ++++---- .../glonass_l1_ca_dll_pll_c_aid_tracking_sc.h | 14 ++- .../glonass_l1_ca_dll_pll_tracking_cc.cc | 42 +++----- .../glonass_l1_ca_dll_pll_tracking_cc.h | 10 +- ...glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc | 41 +++----- .../glonass_l2_ca_dll_pll_c_aid_tracking_cc.h | 11 +-- ...glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc | 41 ++++---- .../glonass_l2_ca_dll_pll_c_aid_tracking_sc.h | 15 ++- .../glonass_l2_ca_dll_pll_tracking_cc.cc | 41 +++----- .../glonass_l2_ca_dll_pll_tracking_cc.h | 11 ++- .../gps_l1_ca_kf_tracking_cc.cc | 34 +++---- .../gps_l1_ca_kf_tracking_cc.h | 10 +- .../gps_l1_ca_tcp_connector_tracking_cc.cc | 43 ++++----- .../gps_l1_ca_tcp_connector_tracking_cc.h | 10 +- .../unit-tests/arithmetic/conjugate_test.cc | 20 ++++ .../arithmetic/magnitude_squared_test.cc | 29 +++++- .../unit-tests/arithmetic/multiply_test.cc | 43 +++++++-- .../cpu_multicorrelator_real_codes_test.cc | 95 ++++++++++++++++++- .../tracking/cpu_multicorrelator_test.cc | 95 ++++++++++++++++++- 32 files changed, 654 insertions(+), 390 deletions(-) create mode 100644 src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/include/volk_gnsssdr/volk_gnsssdr_alloc.h diff --git a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt index 6cc0041d8..860191fd1 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt +++ b/src/algorithms/acquisition/gnuradio_blocks/CMakeLists.txt @@ -76,12 +76,11 @@ target_link_libraries(acquisition_gr_blocks Gnuradio::runtime Gnuradio::fft Volk::volk + Volkgnsssdr::volkgnsssdr PRIVATE Gflags::gflags Glog::glog Matio::matio - Volkgnsssdr::volkgnsssdr - ) target_include_directories(acquisition_gr_blocks diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc index 8baaa7e1a..46d09882d 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.cc @@ -135,9 +135,9 @@ pcps_acquisition::pcps_acquisition(const Acq_Conf& conf_) : gr::block("pcps_acqu acq_parameters.max_dwells = 1; // Activation of acq_parameters.bit_transition_flag invalidates the value of acq_parameters.max_dwells } - d_tmp_buffer = std::vector(d_fft_size); - d_fft_codes = std::vector>(d_fft_size); - d_input_signal = std::vector>(d_fft_size); + d_tmp_buffer = volk_gnsssdr::vector(d_fft_size); + d_fft_codes = volk_gnsssdr::vector>(d_fft_size); + d_input_signal = volk_gnsssdr::vector>(d_fft_size); // Direct FFT d_fft_if = std::make_shared(d_fft_size, true); @@ -147,10 +147,10 @@ pcps_acquisition::pcps_acquisition(const Acq_Conf& conf_) : gr::block("pcps_acqu d_gnss_synchro = nullptr; d_worker_active = false; - d_data_buffer = std::vector>(d_consumed_samples); + d_data_buffer = volk_gnsssdr::vector>(d_consumed_samples); if (d_cshort) { - d_data_buffer_sc = std::vector(d_consumed_samples); + d_data_buffer_sc = volk_gnsssdr::vector(d_consumed_samples); } grid_ = arma::fmat(); narrow_grid_ = arma::fmat(); @@ -304,16 +304,16 @@ void pcps_acquisition::init() // Create the carrier Doppler wipeoff signals if (d_grid_doppler_wipeoffs.empty()) { - d_grid_doppler_wipeoffs = std::vector>>(d_num_doppler_bins, std::vector>(d_fft_size)); + d_grid_doppler_wipeoffs = volk_gnsssdr::vector>>(d_num_doppler_bins, volk_gnsssdr::vector>(d_fft_size)); } if (acq_parameters.make_2_steps && (d_grid_doppler_wipeoffs_step_two.empty())) { - d_grid_doppler_wipeoffs_step_two = std::vector>>(d_num_doppler_bins_step2, std::vector>(d_fft_size)); + d_grid_doppler_wipeoffs_step_two = volk_gnsssdr::vector>>(d_num_doppler_bins_step2, volk_gnsssdr::vector>(d_fft_size)); } if (d_magnitude_grid.empty()) { - d_magnitude_grid = std::vector>(d_num_doppler_bins, std::vector(d_fft_size)); + d_magnitude_grid = volk_gnsssdr::vector>(d_num_doppler_bins, volk_gnsssdr::vector(d_fft_size)); } for (uint32_t doppler_index = 0; doppler_index < d_num_doppler_bins; doppler_index++) diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h index 30ca0102e..6d4ff4bb6 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition.h @@ -62,17 +62,17 @@ #include #include #include -#include // for gr_complex -#include // for scoped_lock -#include // for gr_vector_const_void_star -#include // for Guidelines Support Library -#include // for lv_16sc_t +#include // for gr_complex +#include // for scoped_lock +#include // for gr_vector_const_void_star +#include // for Guidelines Support Library +#include // for lv_16sc_t +#include // for volk_gnsssdr::vector #include #include #include #include #include -#include class Gnss_Synchro; class pcps_acquisition; @@ -243,14 +243,14 @@ private: float d_test_statistics; float d_doppler_center_step_two; std::string d_dump_filename; - std::vector> d_magnitude_grid; - std::vector d_tmp_buffer; - std::vector> d_input_signal; - std::vector>> d_grid_doppler_wipeoffs; - std::vector>> d_grid_doppler_wipeoffs_step_two; - std::vector> d_fft_codes; - std::vector> d_data_buffer; - std::vector d_data_buffer_sc; + volk_gnsssdr::vector> d_magnitude_grid; + volk_gnsssdr::vector d_tmp_buffer; + volk_gnsssdr::vector> d_input_signal; + volk_gnsssdr::vector>> d_grid_doppler_wipeoffs; + volk_gnsssdr::vector>> d_grid_doppler_wipeoffs_step_two; + volk_gnsssdr::vector> d_fft_codes; + volk_gnsssdr::vector> d_data_buffer; + volk_gnsssdr::vector d_data_buffer_sc; std::shared_ptr d_fft_if; std::shared_ptr d_ifft; std::weak_ptr d_channel_fsm; diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt index ff83b6231..26b6bcf59 100644 --- a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/CMakeLists.txt @@ -325,6 +325,7 @@ install( ) install(FILES + ${PROJECT_SOURCE_DIR}/include/volk_gnsssdr/volk_gnsssdr_alloc.h ${PROJECT_SOURCE_DIR}/include/volk_gnsssdr/volk_gnsssdr_prefs.h ${PROJECT_SOURCE_DIR}/include/volk_gnsssdr/volk_gnsssdr_complex.h ${PROJECT_SOURCE_DIR}/include/volk_gnsssdr/volk_gnsssdr_common.h diff --git a/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/include/volk_gnsssdr/volk_gnsssdr_alloc.h b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/include/volk_gnsssdr/volk_gnsssdr_alloc.h new file mode 100644 index 000000000..369e09927 --- /dev/null +++ b/src/algorithms/libs/volk_gnsssdr_module/volk_gnsssdr/include/volk_gnsssdr/volk_gnsssdr_alloc.h @@ -0,0 +1,84 @@ +/*! + * \file volk_gnsssdr_alloc.h + * \author Carles Fernandez, 2019. cfernandez(at)cttc.es + * \brief C++11 allocator using volk_gnsssdr_malloc and volk_gnsssdr_free. + * Based on https://github.com/gnuradio/volk/pull/284/ by @hcab14 + * + * Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors) + * + * This file is part of GNSS-SDR. + * + * GNSS-SDR is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * GNSS-SDR is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with GNSS-SDR. If not, see . + */ + +#ifndef INCLUDED_VOLK_GNSSSDR_ALLOC_H +#define INCLUDED_VOLK_GNSSSDR_ALLOC_H + +#include +#include +#include +#include +#include + +namespace volk_gnsssdr +{ +/*! + * \brief C++11 allocator using volk_gnsssdr_malloc and volk_gnsssdr_free + * + * \details + * adapted from https://en.cppreference.com/w/cpp/named_req/Alloc + */ +template +struct alloc +{ + typedef T value_type; + + alloc() = default; + + template + constexpr alloc(alloc const&) noexcept {} + + T* allocate(std::size_t n) + { + if (n > std::numeric_limits::max() / sizeof(T)) throw std::bad_alloc(); + + if (auto p = static_cast(volk_gnsssdr_malloc(n * sizeof(T), volk_gnsssdr_get_alignment()))) + return p; + + throw std::bad_alloc(); + } + + void deallocate(T* p, std::size_t) noexcept { volk_gnsssdr_free(p); } +}; + +template +bool operator==(alloc const&, alloc const&) { return true; } + +template +bool operator!=(alloc const&, alloc const&) { return false; } + + +/*! + * \brief type alias for std::vector using volk_gnsssdr::alloc + * + * \details + * example code: + * volk_gnsssdr::vector v(100); // vector using volk_gnsssdr_malloc, volk_gnsssdr_free + */ +template +using vector = std::vector >; + +} // namespace volk_gnsssdr + +#endif // INCLUDED_VOLK_GNSSSDR_ALLOC_H diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc index abc9051e4..f9fa89e27 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc @@ -68,6 +68,7 @@ #include // for cout, cerr #include #include +#include #if HAS_STD_FILESYSTEM #if HAS_STD_FILESYSTEM_EXPERIMENTAL @@ -352,7 +353,7 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl // Initialization of local code replica // Get space for a vector with the sinboc(1,1) replica sampled 2x/chip - d_tracking_code = static_cast(volk_gnsssdr_malloc(2 * d_code_length_chips * sizeof(float), volk_gnsssdr_get_alignment())); + d_tracking_code.resize(2 * d_code_length_chips); // correlator outputs (scalar) if (d_veml) { @@ -365,9 +366,8 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl d_n_correlator_taps = 3; } - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); - + d_correlator_outs.resize(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // map memory pointers of correlator outputs if (d_veml) { @@ -414,11 +414,7 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl // Extra correlator for the data component correlator_data_cpu.init(2 * trk_parameters.vector_length, 1); correlator_data_cpu.set_high_dynamics_resampler(trk_parameters.high_dyn); - d_data_code = static_cast(volk_gnsssdr_malloc(2 * d_code_length_chips * sizeof(float), volk_gnsssdr_get_alignment())); - } - else - { - d_data_code = nullptr; + d_data_code.resize(2 * d_code_length_chips); } // --- Initializations --- @@ -440,13 +436,13 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(trk_parameters.cn0_samples); + d_Prompt_buffer = volk_gnsssdr::vector(trk_parameters.cn0_samples); d_carrier_lock_test = 1.0; d_CN0_SNV_dB_Hz = 0.0; d_carrier_lock_fail_counter = 0; d_code_lock_fail_counter = 0; d_carrier_lock_threshold = trk_parameters.carrier_lock_th; - d_Prompt_Data = static_cast(volk_gnsssdr_malloc(sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_Prompt_Data.resize(1); d_cn0_smoother = Exponential_Smoother(); d_cn0_smoother.set_alpha(trk_parameters.cn0_smoother_alpha); @@ -580,24 +576,24 @@ void dll_pll_veml_tracking::start_tracking() if (systemName == "GPS" and signal_type == "1C") { - gps_l1_ca_code_gen_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), d_acquisition_gnss_synchro->PRN, 0); + gps_l1_ca_code_gen_float(d_tracking_code, d_acquisition_gnss_synchro->PRN, 0); } else if (systemName == "GPS" and signal_type == "2S") { - gps_l2c_m_code_gen_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), d_acquisition_gnss_synchro->PRN); + gps_l2c_m_code_gen_float(d_tracking_code, d_acquisition_gnss_synchro->PRN); } else if (systemName == "GPS" and signal_type == "L5") { if (trk_parameters.track_pilot) { - gps_l5q_code_gen_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), d_acquisition_gnss_synchro->PRN); - gps_l5i_code_gen_float(gsl::span(d_data_code, 2 * d_code_length_chips), d_acquisition_gnss_synchro->PRN); + gps_l5q_code_gen_float(d_tracking_code, d_acquisition_gnss_synchro->PRN); + gps_l5i_code_gen_float(d_data_code, d_acquisition_gnss_synchro->PRN); d_Prompt_Data[0] = gr_complex(0.0, 0.0); - correlator_data_cpu.set_local_code_and_taps(d_code_length_chips, d_data_code, d_prompt_data_shift); + correlator_data_cpu.set_local_code_and_taps(d_code_length_chips, d_data_code.data(), d_prompt_data_shift); } else { - gps_l5i_code_gen_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), d_acquisition_gnss_synchro->PRN); + gps_l5i_code_gen_float(d_tracking_code, d_acquisition_gnss_synchro->PRN); } } else if (systemName == "Galileo" and signal_type == "1B") @@ -605,21 +601,21 @@ void dll_pll_veml_tracking::start_tracking() if (trk_parameters.track_pilot) { std::array pilot_signal = {{'1', 'C', '\0'}}; - galileo_e1_code_gen_sinboc11_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), pilot_signal, d_acquisition_gnss_synchro->PRN); - galileo_e1_code_gen_sinboc11_float(gsl::span(d_data_code, 2 * d_code_length_chips), Signal_, d_acquisition_gnss_synchro->PRN); + galileo_e1_code_gen_sinboc11_float(d_tracking_code, pilot_signal, d_acquisition_gnss_synchro->PRN); + galileo_e1_code_gen_sinboc11_float(d_data_code, Signal_, d_acquisition_gnss_synchro->PRN); d_Prompt_Data[0] = gr_complex(0.0, 0.0); - correlator_data_cpu.set_local_code_and_taps(d_code_samples_per_chip * d_code_length_chips, d_data_code, d_prompt_data_shift); + correlator_data_cpu.set_local_code_and_taps(d_code_samples_per_chip * d_code_length_chips, d_data_code.data(), d_prompt_data_shift); } else { - galileo_e1_code_gen_sinboc11_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), Signal_, d_acquisition_gnss_synchro->PRN); + galileo_e1_code_gen_sinboc11_float(d_tracking_code, Signal_, d_acquisition_gnss_synchro->PRN); } } else if (systemName == "Galileo" and signal_type == "5X") { - auto *aux_code = static_cast(volk_gnsssdr_malloc(sizeof(gr_complex) * d_code_length_chips, volk_gnsssdr_get_alignment())); + volk_gnsssdr::vector aux_code(d_code_length_chips); std::array signal_type_ = {{'5', 'X', '\0'}}; - galileo_e5_a_code_gen_complex_primary(gsl::span(aux_code, d_code_length_chips), d_acquisition_gnss_synchro->PRN, signal_type_); + galileo_e5_a_code_gen_complex_primary(aux_code, d_acquisition_gnss_synchro->PRN, signal_type_); if (trk_parameters.track_pilot) { d_secondary_code_string = const_cast(&GALILEO_E5A_Q_SECONDARY_CODE[d_acquisition_gnss_synchro->PRN - 1]); @@ -629,7 +625,7 @@ void dll_pll_veml_tracking::start_tracking() d_data_code[i] = aux_code[i].real(); // the same because it is generated the full signal (E5aI + E5aQ) } d_Prompt_Data[0] = gr_complex(0.0, 0.0); - correlator_data_cpu.set_local_code_and_taps(d_code_length_chips, d_data_code, d_prompt_data_shift); + correlator_data_cpu.set_local_code_and_taps(d_code_length_chips, d_data_code.data(), d_prompt_data_shift); } else { @@ -638,11 +634,10 @@ void dll_pll_veml_tracking::start_tracking() d_tracking_code[i] = aux_code[i].real(); } } - volk_gnsssdr_free(aux_code); } else if (systemName == "Beidou" and signal_type == "B1") { - beidou_b1i_code_gen_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), d_acquisition_gnss_synchro->PRN, 0); + beidou_b1i_code_gen_float(d_tracking_code, d_acquisition_gnss_synchro->PRN, 0); // GEO Satellites use different secondary code if (d_acquisition_gnss_synchro->PRN > 0 and d_acquisition_gnss_synchro->PRN < 6) { @@ -675,7 +670,7 @@ void dll_pll_veml_tracking::start_tracking() else if (systemName == "Beidou" and signal_type == "B3") { - beidou_b3i_code_gen_float(gsl::span(d_tracking_code, 2 * d_code_length_chips), d_acquisition_gnss_synchro->PRN, 0); + beidou_b3i_code_gen_float(d_tracking_code, d_acquisition_gnss_synchro->PRN, 0); // Update secondary code settings for geo satellites if (d_acquisition_gnss_synchro->PRN > 0 and d_acquisition_gnss_synchro->PRN < 6) { @@ -706,8 +701,8 @@ void dll_pll_veml_tracking::start_tracking() } } - multicorrelator_cpu.set_local_code_and_taps(d_code_samples_per_chip * d_code_length_chips, d_tracking_code, d_local_code_shift_chips); - std::fill_n(d_correlator_outs, d_n_correlator_taps, gr_complex(0.0, 0.0)); + multicorrelator_cpu.set_local_code_and_taps(d_code_samples_per_chip * d_code_length_chips, d_tracking_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_code_lock_fail_counter = 0; @@ -765,7 +760,7 @@ dll_pll_veml_tracking::~dll_pll_veml_tracking() } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } if (d_dump_mat) @@ -781,20 +776,15 @@ dll_pll_veml_tracking::~dll_pll_veml_tracking() } try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_tracking_code); - volk_gnsssdr_free(d_Prompt_Data); if (trk_parameters.track_pilot) { - volk_gnsssdr_free(d_data_code); correlator_data_cpu.free(); } multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -907,7 +897,7 @@ void dll_pll_veml_tracking::do_correlation_step(const gr_complex *input_samples) { // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, input_samples); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), input_samples); multicorrelator_cpu.Carrier_wipeoff_multicorrelator_resampler( d_rem_carr_phase_rad, d_carrier_phase_step_rad, d_carrier_phase_rate_step_rad, @@ -919,7 +909,7 @@ void dll_pll_veml_tracking::do_correlation_step(const gr_complex *input_samples) // DATA CORRELATOR (if tracking tracks the pilot signal) if (trk_parameters.track_pilot) { - correlator_data_cpu.set_input_output_vectors(d_Prompt_Data, input_samples); + correlator_data_cpu.set_input_output_vectors(d_Prompt_Data.data(), input_samples); correlator_data_cpu.Carrier_wipeoff_multicorrelator_resampler( d_rem_carr_phase_rad, d_carrier_phase_step_rad, d_carrier_phase_rate_step_rad, @@ -1019,7 +1009,7 @@ void dll_pll_veml_tracking::run_dll_pll() void dll_pll_veml_tracking::clear_tracking_vars() { - std::fill_n(d_correlator_outs, d_n_correlator_taps, gr_complex(0.0, 0.0)); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); if (trk_parameters.track_pilot) { d_Prompt_Data[0] = gr_complex(0.0, 0.0); @@ -1166,11 +1156,11 @@ void dll_pll_veml_tracking::save_correlation_results() { if (d_data_secondary_code_string->at(d_current_data_symbol) == '0') { - d_P_data_accu += *d_Prompt_Data; + d_P_data_accu += d_Prompt_Data[0]; } else { - d_P_data_accu -= *d_Prompt_Data; + d_P_data_accu -= d_Prompt_Data[0]; } } else @@ -1193,7 +1183,7 @@ void dll_pll_veml_tracking::save_correlation_results() { if (trk_parameters.track_pilot) { - d_P_data_accu += *d_Prompt_Data; + d_P_data_accu += d_Prompt_Data[0]; } else { @@ -1208,7 +1198,7 @@ void dll_pll_veml_tracking::save_correlation_results() { if (trk_parameters.track_pilot) { - d_P_data_accu = *d_Prompt_Data; + d_P_data_accu = d_Prompt_Data[0]; } else { @@ -1245,8 +1235,8 @@ void dll_pll_veml_tracking::log_data() uint64_t tmp_long_int; if (trk_parameters.track_pilot) { - prompt_I = d_Prompt_Data->real(); - prompt_Q = d_Prompt_Data->imag(); + prompt_I = d_Prompt_Data.data()->real(); + prompt_Q = d_Prompt_Data.data()->imag(); } else { diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h index 414838a7f..1c39eee8d 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.h @@ -38,16 +38,16 @@ #include "tracking_FLL_PLL_filter.h" // for PLL/FLL filter #include "tracking_loop_filter.h" // for DLL filter #include -#include // for boost::shared_ptr -#include // for block -#include // for gr_complex -#include // for gr_vector_int, gr_vector... -#include // for pmt_t -#include // for int32_t -#include // for string, ofstream +#include // for boost::shared_ptr +#include // for block +#include // for gr_complex +#include // for gr_vector_int, gr_vector... +#include // for pmt_t +#include // for volk_gnsssdr::vector +#include // for int32_t +#include // for string, ofstream #include #include // for pair -#include class Gnss_Synchro; class dll_pll_veml_tracking; @@ -123,9 +123,9 @@ private: int32_t d_correlation_length_ms; int32_t d_n_correlator_taps; - float *d_tracking_code; - float *d_data_code; - float *d_local_code_shift_chips; + volk_gnsssdr::vector d_tracking_code; + volk_gnsssdr::vector d_data_code; + volk_gnsssdr::vector d_local_code_shift_chips; float *d_prompt_data_shift; Cpu_Multicorrelator_Real_Codes multicorrelator_cpu; Cpu_Multicorrelator_Real_Codes correlator_data_cpu; // for data channel @@ -135,7 +135,7 @@ private: Implement this functionality inside multicorrelator class as an enhancement to increase the performance */ - gr_complex *d_correlator_outs; + volk_gnsssdr::vector d_correlator_outs; gr_complex *d_Very_Early; gr_complex *d_Early; gr_complex *d_Prompt; @@ -155,7 +155,7 @@ private: gr_complex d_VL_accu; gr_complex d_P_data_accu; - gr_complex *d_Prompt_Data; + volk_gnsssdr::vector d_Prompt_Data; double d_code_phase_step_chips; double d_code_phase_rate_step_chips; @@ -207,7 +207,7 @@ private: double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; boost::circular_buffer d_Prompt_circular_buffer; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; Exponential_Smoother d_cn0_smoother; Exponential_Smoother d_carrier_lock_test_smoother; // file dump diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc index 0462c4eaf..13d35604a 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc @@ -309,9 +309,8 @@ dll_pll_veml_tracking_fpga::dll_pll_veml_tracking_fpga(const Dll_Pll_Conf_Fpga & d_n_correlator_taps = 3; } - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); - + d_correlator_outs.reserve(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // map memory pointers of correlator outputs if (d_veml) { @@ -370,13 +369,13 @@ dll_pll_veml_tracking_fpga::dll_pll_veml_tracking_fpga(const Dll_Pll_Conf_Fpga & // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(trk_parameters.cn0_samples); + d_Prompt_buffer = volk_gnsssdr::vector(trk_parameters.cn0_samples); d_carrier_lock_test = 1.0; d_CN0_SNV_dB_Hz = 0.0; d_carrier_lock_fail_counter = 0; d_code_lock_fail_counter = 0; d_carrier_lock_threshold = trk_parameters.carrier_lock_th; - d_Prompt_Data = static_cast(volk_gnsssdr_malloc(sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_Prompt_Data.reserve(1); d_cn0_smoother = Exponential_Smoother(); d_cn0_smoother.set_alpha(trk_parameters.cn0_smoother_alpha); if (d_code_period > 0.0) @@ -458,7 +457,7 @@ dll_pll_veml_tracking_fpga::dll_pll_veml_tracking_fpga(const Dll_Pll_Conf_Fpga & int32_t *ca_codes = trk_parameters.ca_codes; int32_t *data_codes = trk_parameters.data_codes; multicorrelator_fpga = std::make_shared(d_n_correlator_taps, device_name, dev_file_num, num_prev_assigned_ch, ca_codes, data_codes, d_code_length_chips, trk_parameters.track_pilot, d_code_samples_per_chip); - multicorrelator_fpga->set_output_vectors(d_correlator_outs, d_Prompt_Data); + multicorrelator_fpga->set_output_vectors(d_correlator_outs.data(), d_Prompt_Data.data()); d_sample_counter_next = 0ULL; d_corrected_doppler = false; @@ -531,7 +530,7 @@ dll_pll_veml_tracking_fpga::~dll_pll_veml_tracking_fpga() } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } if (d_dump_mat) @@ -547,14 +546,11 @@ dll_pll_veml_tracking_fpga::~dll_pll_veml_tracking_fpga() } try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_Prompt_Data); multicorrelator_fpga->free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -766,7 +762,7 @@ void dll_pll_veml_tracking_fpga::run_dll_pll() void dll_pll_veml_tracking_fpga::clear_tracking_vars() { - std::fill_n(d_correlator_outs, d_n_correlator_taps, gr_complex(0.0, 0.0)); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); if (trk_parameters.track_pilot) { d_Prompt_Data[0] = gr_complex(0.0, 0.0); @@ -917,16 +913,16 @@ void dll_pll_veml_tracking_fpga::save_correlation_results() { if (d_data_secondary_code_string->at(d_current_data_symbol) == '0') { - d_P_data_accu += *d_Prompt_Data; + d_P_data_accu += d_Prompt_Data[0]; } else { - d_P_data_accu -= *d_Prompt_Data; + d_P_data_accu -= d_Prompt_Data[0]; } } else { - d_P_data_accu += *d_Prompt_Data; + d_P_data_accu += d_Prompt_Data[0]; } } else @@ -955,7 +951,7 @@ void dll_pll_veml_tracking_fpga::save_correlation_results() { if (trk_parameters.track_pilot) { - d_P_data_accu += *d_Prompt_Data; + d_P_data_accu += d_Prompt_Data[0]; } else { @@ -970,7 +966,7 @@ void dll_pll_veml_tracking_fpga::save_correlation_results() { if (trk_parameters.track_pilot) { - d_P_data_accu = *d_Prompt_Data; + d_P_data_accu = d_Prompt_Data[0]; } else { @@ -1007,8 +1003,8 @@ void dll_pll_veml_tracking_fpga::log_data() uint64_t tmp_long_int; if (trk_parameters.track_pilot) { - prompt_I = d_Prompt_Data->real(); - prompt_Q = d_Prompt_Data->imag(); + prompt_I = d_Prompt_Data.data()->real(); + prompt_Q = d_Prompt_Data.data()->imag(); } else { @@ -1406,7 +1402,7 @@ void dll_pll_veml_tracking_fpga::set_gnss_synchro(Gnss_Synchro *p_gnss_synchro) } } - std::fill_n(d_correlator_outs, d_n_correlator_taps, gr_complex(0.0, 0.0)); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_code_lock_fail_counter = 0; @@ -1441,7 +1437,7 @@ void dll_pll_veml_tracking_fpga::set_gnss_synchro(Gnss_Synchro *p_gnss_synchro) d_code_loop_filter.set_update_interval(d_code_period); d_code_loop_filter.initialize(); // initialize the code filter - multicorrelator_fpga->set_local_code_and_taps(d_local_code_shift_chips, d_prompt_data_shift, d_acquisition_gnss_synchro->PRN); + multicorrelator_fpga->set_local_code_and_taps(d_local_code_shift_chips.data(), d_prompt_data_shift, d_acquisition_gnss_synchro->PRN); d_pull_in_transitory = true; diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h index 1dc78d85f..bda30b1cd 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.h @@ -37,17 +37,17 @@ #include "tracking_FLL_PLL_filter.h" // for PLL/FLL filter #include "tracking_loop_filter.h" // for DLL filter #include -#include // for boost::shared_ptr -#include // for block -#include // for gr_complex -#include // for gr_vector_int, gr_vector... -#include // for pmt_t -#include // for int32_t -#include // for string, ofstream +#include // for boost::shared_ptr +#include // for block +#include // for gr_complex +#include // for gr_vector_int, gr_vector... +#include // for pmt_t +#include // for volk_gnsssdr::vector +#include // for int32_t +#include // for string, ofstream #include #include #include // for pair -#include class Fpga_Multicorrelator_8sc; class Gnss_Synchro; @@ -152,10 +152,10 @@ private: int32_t d_correlation_length_ms; int32_t d_n_correlator_taps; - float *d_local_code_shift_chips; + volk_gnsssdr::vector d_local_code_shift_chips; float *d_prompt_data_shift; std::shared_ptr multicorrelator_fpga; - gr_complex *d_correlator_outs; + volk_gnsssdr::vector d_correlator_outs; gr_complex *d_Very_Early; gr_complex *d_Early; gr_complex *d_Prompt; @@ -175,7 +175,7 @@ private: gr_complex d_VL_accu; gr_complex d_P_data_accu; - gr_complex *d_Prompt_Data; + volk_gnsssdr::vector d_Prompt_Data; double d_code_phase_step_chips; double d_code_phase_rate_step_chips; @@ -228,7 +228,7 @@ private: double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; boost::circular_buffer d_Prompt_circular_buffer; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; Exponential_Smoother d_cn0_smoother; Exponential_Smoother d_carrier_lock_test_smoother; // file dump diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc index faa362312..b4e9d9e1f 100644 --- a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc @@ -48,6 +48,7 @@ #include #include #include +#include // for fill_n #include #include #include @@ -116,15 +117,12 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( // Initialization of local code replica // Get space for a vector with the sinboc(1,1) replica sampled 2x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc((2 * GALILEO_E1_B_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(2 * GALILEO_E1_B_CODE_LENGTH_CHIPS); // correlator outputs (scalar) d_n_correlator_taps = 5; // Very-Early, Early, Prompt, Late, Very-Late - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + d_correlator_outs.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); // map memory pointers of correlator outputs d_Very_Early = &d_correlator_outs[0]; d_Early = &d_correlator_outs[1]; @@ -132,7 +130,7 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( d_Late = &d_correlator_outs[3]; d_Very_Late = &d_correlator_outs[4]; - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_very_early_late_spc_chips; d_local_code_shift_chips[1] = -d_early_late_spc_chips; @@ -163,7 +161,7 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer = volk_gnsssdr::vector(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -192,18 +190,15 @@ void Galileo_E1_Tcp_Connector_Tracking_cc::start_tracking() std::memcpy(Signal_.data(), d_acquisition_gnss_synchro->Signal, 3); // generate local reference ALWAYS starting at chip 1 (2 samples per chip) - galileo_e1_code_gen_complex_sampled(gsl::span(d_ca_code, (2 * GALILEO_E1_B_CODE_LENGTH_CHIPS)), + galileo_e1_code_gen_complex_sampled(d_ca_code, Signal_, false, d_acquisition_gnss_synchro->PRN, 2 * GALILEO_E1_CODE_CHIP_RATE_CPS, 0); - multicorrelator_cpu.set_local_code_and_taps(static_cast(2 * GALILEO_E1_B_CODE_LENGTH_CHIPS), d_ca_code, d_local_code_shift_chips); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + multicorrelator_cpu.set_local_code_and_taps(static_cast(2 * GALILEO_E1_B_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_rem_code_phase_samples = 0.0; @@ -239,20 +234,17 @@ Galileo_E1_Tcp_Connector_Tracking_cc::~Galileo_E1_Tcp_Connector_Tracking_cc() } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_ca_code); d_tcp_com.close_tcp_connection(d_port); multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -335,7 +327,7 @@ int Galileo_E1_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attri // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, in); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), in); double carr_phase_step_rad = GALILEO_TWO_PI * d_carrier_doppler_hz / static_cast(d_fs_in); double code_phase_step_half_chips = (2.0 * d_code_freq_chips) / (static_cast(d_fs_in)); @@ -457,9 +449,9 @@ int Galileo_E1_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attri } else { - *d_Early = gr_complex(0, 0); - *d_Prompt = gr_complex(0, 0); - *d_Late = gr_complex(0, 0); + *d_Early = gr_complex(0.0, 0.0); + *d_Prompt = gr_complex(0.0, 0.0); + *d_Late = gr_complex(0.0, 0.0); current_synchro_data.Tracking_sample_counter = d_sample_counter + static_cast(d_current_prn_length_samples); // When tracking is disabled an array of 1's is sent to maintain the TCP connection boost::array tx_variables_array = {{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0}}; diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.h index 80f093a9e..ff5e35a9d 100644 --- a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.h +++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.h @@ -43,11 +43,10 @@ #include "gnss_synchro.h" #include "tcp_communication.h" #include -#include +#include // for volk_gnsssdr::vector #include #include #include -#include class Galileo_E1_Tcp_Connector_Tracking_cc; @@ -123,7 +122,7 @@ private: float d_early_late_spc_chips; float d_very_early_late_spc_chips; - gr_complex *d_ca_code; + volk_gnsssdr::vector d_ca_code; gr_complex *d_Very_Early; gr_complex *d_Early; @@ -141,8 +140,8 @@ private: float d_acq_carrier_doppler_hz; // correlator - float *d_local_code_shift_chips; - gr_complex *d_correlator_outs; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs; Cpu_Multicorrelator multicorrelator_cpu; // tracking vars @@ -167,7 +166,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; float d_carrier_lock_test; float d_CN0_SNV_dB_Hz; float d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc index 0d71e133f..84e81a8de 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ #include #include #include +#include #define CN0_ESTIMATION_SAMPLES 10 @@ -143,16 +145,14 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::glonass_l1_ca_dll_pll_c_aid_tracking_cc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_correlator_outs.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -176,7 +176,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::glonass_l1_ca_dll_pll_c_aid_tracking_cc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -274,13 +274,10 @@ void glonass_l1_ca_dll_pll_c_aid_tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l1_ca_code_gen_complex(gsl::span(d_ca_code, GLONASS_L1_CA_CODE_LENGTH_CHIPS), 0); + glonass_l1_ca_code_gen_complex(d_ca_code, 0); - multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code, d_local_code_shift_chips); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_rem_code_phase_samples = 0.0; @@ -318,7 +315,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::~glonass_l1_ca_dll_pll_c_aid_tracking_c } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -344,14 +341,11 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::~glonass_l1_ca_dll_pll_c_aid_tracking_c try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_ca_code); multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -601,7 +595,7 @@ int glonass_l1_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __at // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, in); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), in); multicorrelator_cpu.Carrier_wipeoff_multicorrelator_resampler(d_rem_carrier_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, @@ -819,7 +813,7 @@ int glonass_l1_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __at { for (int32_t n = 0; n < d_n_correlator_taps; n++) { - d_correlator_outs[n] = gr_complex(0, 0); + d_correlator_outs[n] = gr_complex(0.0, 0.0); } current_synchro_data.System = {'R'}; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.h index 4c9473a50..df2d47df2 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.h +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.h @@ -46,11 +46,12 @@ #include "cpu_multicorrelator.h" #include #include +#include // for volk_gnsssdr::vector #include #include #include #include -#include + class glonass_l1_ca_dll_pll_c_aid_tracking_cc; @@ -123,9 +124,9 @@ private: double d_early_late_spc_chips; int32_t d_n_correlator_taps; - gr_complex* d_ca_code; - float* d_local_code_shift_chips; - gr_complex* d_correlator_outs; + volk_gnsssdr::vector d_ca_code; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs; Cpu_Multicorrelator multicorrelator_cpu; // remaining code phase and carrier phase between tracking loops @@ -181,7 +182,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; double d_carrier_lock_test; double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc index 3afb80df9..4cd642a0d 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -54,6 +55,7 @@ #include #include #include +#include #define CN0_ESTIMATION_SAMPLES 10 @@ -139,19 +141,16 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::glonass_l1_ca_dll_pll_c_aid_tracking_sc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_ca_code_16sc = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(lv_16sc_t), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code_16sc.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs_16sc = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(lv_16sc_t), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs_16sc[n] = lv_cmake(0, 0); - } + d_correlator_outs_16sc.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs_16sc.begin(), d_n_correlator_taps, lv_cmake(0, 0)); - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -175,7 +174,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::glonass_l1_ca_dll_pll_c_aid_tracking_sc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -269,10 +268,10 @@ void glonass_l1_ca_dll_pll_c_aid_tracking_sc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l1_ca_code_gen_complex(gsl::span(d_ca_code, GLONASS_L1_CA_CODE_LENGTH_CHIPS), 0); - volk_gnsssdr_32fc_convert_16ic(d_ca_code_16sc, d_ca_code, static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + glonass_l1_ca_code_gen_complex(d_ca_code, 0); + volk_gnsssdr_32fc_convert_16ic(d_ca_code_16sc.data(), d_ca_code.data(), static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); - multicorrelator_cpu_16sc.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code_16sc, d_local_code_shift_chips); + multicorrelator_cpu_16sc.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code_16sc.data(), d_local_code_shift_chips.data()); for (int32_t n = 0; n < d_n_correlator_taps; n++) { d_correlator_outs_16sc[n] = lv_16sc_t(0, 0); @@ -486,7 +485,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::~glonass_l1_ca_dll_pll_c_aid_tracking_s } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -511,12 +510,14 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::~glonass_l1_ca_dll_pll_c_aid_tracking_s } } - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_ca_code); - volk_gnsssdr_free(d_ca_code_16sc); - volk_gnsssdr_free(d_correlator_outs_16sc); - - multicorrelator_cpu_16sc.free(); + try + { + multicorrelator_cpu_16sc.free(); + } + catch (const std::exception &ex) + { + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); + } } @@ -594,7 +595,7 @@ int glonass_l1_ca_dll_pll_c_aid_tracking_sc::general_work(int noutput_items __at // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu_16sc.set_input_output_vectors(d_correlator_outs_16sc, in); + multicorrelator_cpu_16sc.set_input_output_vectors(d_correlator_outs_16sc.data(), in); multicorrelator_cpu_16sc.Carrier_wipeoff_multicorrelator_resampler(d_rem_carrier_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.h b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.h index 085f7b01e..458dae3a8 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.h +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.h @@ -46,11 +46,11 @@ #include "tracking_FLL_PLL_filter.h" #include #include +#include // for volk_gnsssdr::vector #include #include #include #include -#include class glonass_l1_ca_dll_pll_c_aid_tracking_sc; @@ -123,12 +123,10 @@ private: double d_early_late_spc_chips; int32_t d_n_correlator_taps; - gr_complex* d_ca_code; - lv_16sc_t* d_ca_code_16sc; - float* d_local_code_shift_chips; - // gr_complex* d_correlator_outs; - lv_16sc_t* d_correlator_outs_16sc; - // cpu_multicorrelator multicorrelator_cpu; + volk_gnsssdr::vector d_ca_code; + volk_gnsssdr::vector d_ca_code_16sc; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs_16sc; Cpu_Multicorrelator_16sc multicorrelator_cpu_16sc; // remaining code phase and carrier phase between tracking loops @@ -183,7 +181,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; double d_carrier_lock_test; double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc index 2c59ed0db..a9173b9e6 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,7 +53,7 @@ #include #include #include - +#include #define CN0_ESTIMATION_SAMPLES 10 @@ -111,16 +111,14 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::Glonass_L1_Ca_Dll_Pll_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_correlator_outs.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -146,7 +144,7 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::Glonass_L1_Ca_Dll_Pll_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -228,13 +226,10 @@ void Glonass_L1_Ca_Dll_Pll_Tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l1_ca_code_gen_complex(gsl::span(d_ca_code, GLONASS_L1_CA_CODE_LENGTH_CHIPS), 0); + glonass_l1_ca_code_gen_complex(d_ca_code, 0); - multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code, d_local_code_shift_chips); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_rem_code_phase_samples = 0; @@ -271,7 +266,7 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::~Glonass_L1_Ca_Dll_Pll_Tracking_cc() } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } if (d_dump) @@ -296,14 +291,11 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::~Glonass_L1_Ca_Dll_Pll_Tracking_cc() } try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_ca_code); multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -556,7 +548,7 @@ int Glonass_L1_Ca_Dll_Pll_Tracking_cc::general_work(int noutput_items __attribut // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, in); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), in); multicorrelator_cpu.Carrier_wipeoff_multicorrelator_resampler(d_rem_carr_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, @@ -658,11 +650,7 @@ int Glonass_L1_Ca_Dll_Pll_Tracking_cc::general_work(int noutput_items __attribut } else { - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); current_synchro_data.Tracking_sample_counter = d_sample_counter + static_cast(d_current_prn_length_samples); current_synchro_data.System = {'R'}; current_synchro_data.correlation_length_ms = 1; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.h index fd6e3cd16..440be623d 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.h +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.h @@ -44,10 +44,10 @@ #include "tracking_2nd_DLL_filter.h" #include "tracking_2nd_PLL_filter.h" #include +#include // for volk_gnsssdr::vector #include #include #include -#include class Glonass_L1_Ca_Dll_Pll_Tracking_cc; @@ -124,9 +124,9 @@ private: double d_acq_carrier_doppler_hz; // correlator int32_t d_n_correlator_taps; - gr_complex* d_ca_code; - float* d_local_code_shift_chips; - gr_complex* d_correlator_outs; + volk_gnsssdr::vector d_ca_code; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs; Cpu_Multicorrelator multicorrelator_cpu; // tracking vars @@ -148,7 +148,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; double d_carrier_lock_test; double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc index a14a7b018..3f1d5c25d 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,6 +53,7 @@ #include #include #include +#include #define CN0_ESTIMATION_SAMPLES 10 @@ -140,16 +141,14 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::glonass_l2_ca_dll_pll_c_aid_tracking_cc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_correlator_outs.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -173,7 +172,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::glonass_l2_ca_dll_pll_c_aid_tracking_cc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -271,13 +270,10 @@ void glonass_l2_ca_dll_pll_c_aid_tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l2_ca_code_gen_complex(gsl::span(d_ca_code, static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)), 0); + glonass_l2_ca_code_gen_complex(d_ca_code, 0); - multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), d_ca_code, d_local_code_shift_chips); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_rem_code_phase_samples = 0.0; @@ -315,7 +311,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::~glonass_l2_ca_dll_pll_c_aid_tracking_c } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -342,14 +338,11 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::~glonass_l2_ca_dll_pll_c_aid_tracking_c try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_ca_code); multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -599,7 +592,7 @@ int glonass_l2_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __at // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, in); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), in); multicorrelator_cpu.Carrier_wipeoff_multicorrelator_resampler(d_rem_carrier_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, @@ -815,11 +808,7 @@ int glonass_l2_ca_dll_pll_c_aid_tracking_cc::general_work(int noutput_items __at } else { - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); current_synchro_data.System = {'R'}; current_synchro_data.Tracking_sample_counter = d_sample_counter + static_cast(d_correlation_length_samples); } diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.h index 81156f64f..b01cd5586 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.h +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.h @@ -40,15 +40,14 @@ #include "gnss_synchro.h" #include "tracking_2nd_DLL_filter.h" #include "tracking_FLL_PLL_filter.h" -// #include "tracking_loop_filter.h" #include "cpu_multicorrelator.h" #include #include +#include // for volk_gnsssdr::vector #include #include #include #include -#include class glonass_l2_ca_dll_pll_c_aid_tracking_cc; @@ -121,9 +120,9 @@ private: double d_early_late_spc_chips; int32_t d_n_correlator_taps; - gr_complex* d_ca_code; - float* d_local_code_shift_chips; - gr_complex* d_correlator_outs; + volk_gnsssdr::vector d_ca_code; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs; Cpu_Multicorrelator multicorrelator_cpu; // remaining code phase and carrier phase between tracking loops @@ -179,7 +178,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; double d_carrier_lock_test; double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc index ac4104dfc..f558ab61e 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc @@ -45,6 +45,7 @@ #include #include #include +#include #include #include #include @@ -52,6 +53,7 @@ #include #include #include +#include #define CN0_ESTIMATION_SAMPLES 10 @@ -137,19 +139,16 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::glonass_l2_ca_dll_pll_c_aid_tracking_sc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_ca_code_16sc = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS) * sizeof(lv_16sc_t), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code_16sc.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs_16sc = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(lv_16sc_t), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs_16sc[n] = lv_cmake(0, 0); - } + d_correlator_outs_16sc.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs_16sc.begin(), d_n_correlator_taps, lv_cmake(0, 0)); - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -173,7 +172,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::glonass_l2_ca_dll_pll_c_aid_tracking_sc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -267,10 +266,10 @@ void glonass_l2_ca_dll_pll_c_aid_tracking_sc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l2_ca_code_gen_complex(gsl::span(d_ca_code, static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)), 0); - volk_gnsssdr_32fc_convert_16ic(d_ca_code_16sc, d_ca_code, static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + glonass_l2_ca_code_gen_complex(d_ca_code, 0); + volk_gnsssdr_32fc_convert_16ic(d_ca_code_16sc.data(), d_ca_code.data(), static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); - multicorrelator_cpu_16sc.set_local_code_and_taps(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), d_ca_code_16sc, d_local_code_shift_chips); + multicorrelator_cpu_16sc.set_local_code_and_taps(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), d_ca_code_16sc.data(), d_local_code_shift_chips.data()); for (int32_t n = 0; n < d_n_correlator_taps; n++) { d_correlator_outs_16sc[n] = lv_16sc_t(0, 0); @@ -484,7 +483,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::~glonass_l2_ca_dll_pll_c_aid_tracking_s } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -509,12 +508,14 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::~glonass_l2_ca_dll_pll_c_aid_tracking_s } } - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_ca_code); - volk_gnsssdr_free(d_ca_code_16sc); - volk_gnsssdr_free(d_correlator_outs_16sc); - - multicorrelator_cpu_16sc.free(); + try + { + multicorrelator_cpu_16sc.free(); + } + catch (const std::exception &ex) + { + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); + } } @@ -592,7 +593,7 @@ int glonass_l2_ca_dll_pll_c_aid_tracking_sc::general_work(int noutput_items __at // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu_16sc.set_input_output_vectors(d_correlator_outs_16sc, in); + multicorrelator_cpu_16sc.set_input_output_vectors(d_correlator_outs_16sc.data(), in); multicorrelator_cpu_16sc.Carrier_wipeoff_multicorrelator_resampler(d_rem_carrier_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.h b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.h index 04cc89f9d..5c64bd2d6 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.h +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.h @@ -43,12 +43,11 @@ #include "tracking_2nd_DLL_filter.h" #include "tracking_FLL_PLL_filter.h" #include -#include +#include // for volk_gnsssdr::vector #include #include #include #include -#include class glonass_l2_ca_dll_pll_c_aid_tracking_sc; @@ -121,12 +120,10 @@ private: double d_early_late_spc_chips; int32_t d_n_correlator_taps; - gr_complex* d_ca_code; - lv_16sc_t* d_ca_code_16sc; - float* d_local_code_shift_chips; - // gr_complex* d_correlator_outs; - lv_16sc_t* d_correlator_outs_16sc; - // cpu_multicorrelator multicorrelator_cpu; + volk_gnsssdr::vector d_ca_code; + volk_gnsssdr::vector d_ca_code_16sc; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs_16sc; Cpu_Multicorrelator_16sc multicorrelator_cpu_16sc; // remaining code phase and carrier phase between tracking loops @@ -181,7 +178,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; double d_carrier_lock_test; double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc index 0a2dc7db9..15c991504 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include @@ -53,6 +53,7 @@ #include #include #include +#include #define CN0_ESTIMATION_SAMPLES 10 @@ -111,16 +112,14 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::Glonass_L2_Ca_Dll_Pll_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_correlator_outs.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -146,7 +145,7 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::Glonass_L2_Ca_Dll_Pll_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -228,13 +227,10 @@ void Glonass_L2_Ca_Dll_Pll_Tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l2_ca_code_gen_complex(gsl::span(d_ca_code, static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)), 0); + glonass_l2_ca_code_gen_complex(d_ca_code, 0); - multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), d_ca_code, d_local_code_shift_chips); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_rem_code_phase_samples = 0; @@ -271,7 +267,7 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::~Glonass_L2_Ca_Dll_Pll_Tracking_cc() } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } if (d_dump) @@ -296,14 +292,11 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::~Glonass_L2_Ca_Dll_Pll_Tracking_cc() } try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_ca_code); multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -556,7 +549,7 @@ int Glonass_L2_Ca_Dll_Pll_Tracking_cc::general_work(int noutput_items __attribut // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, in); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), in); multicorrelator_cpu.Carrier_wipeoff_multicorrelator_resampler(d_rem_carr_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, @@ -658,11 +651,7 @@ int Glonass_L2_Ca_Dll_Pll_Tracking_cc::general_work(int noutput_items __attribut } else { - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); current_synchro_data.Tracking_sample_counter = d_sample_counter + static_cast(d_current_prn_length_samples); current_synchro_data.System = {'R'}; current_synchro_data.correlation_length_ms = 1; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.h index 95bd10dfb..4e58bea2b 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.h +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.h @@ -42,10 +42,10 @@ #include "tracking_2nd_DLL_filter.h" #include "tracking_2nd_PLL_filter.h" #include +#include // for volk_gnsssdr::vector #include #include #include -#include class Glonass_L2_Ca_Dll_Pll_Tracking_cc; @@ -122,9 +122,10 @@ private: double d_acq_carrier_doppler_hz; // correlator int32_t d_n_correlator_taps; - gr_complex* d_ca_code; - float* d_local_code_shift_chips; - gr_complex* d_correlator_outs; + + volk_gnsssdr::vector d_ca_code; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs; Cpu_Multicorrelator multicorrelator_cpu; // tracking vars @@ -146,7 +147,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; double d_carrier_lock_test; double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc index 80bb7b0cb..a0c677a0e 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc @@ -48,6 +48,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,7 @@ #include #include #include +#include gps_l1_ca_kf_tracking_cc_sptr @@ -127,16 +129,14 @@ Gps_L1_Ca_Kf_Tracking_cc::Gps_L1_Ca_Kf_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(float), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_correlator_outs.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -163,7 +163,7 @@ Gps_L1_Ca_Kf_Tracking_cc::Gps_L1_Ca_Kf_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -324,13 +324,10 @@ void Gps_L1_Ca_Kf_Tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - gps_l1_ca_code_gen_float(gsl::span(d_ca_code, static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(float)), d_acquisition_gnss_synchro->PRN, 0); + gps_l1_ca_code_gen_float(d_ca_code, d_acquisition_gnss_synchro->PRN, 0); - multicorrelator_cpu.set_local_code_and_taps(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code, d_local_code_shift_chips); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + multicorrelator_cpu.set_local_code_and_taps(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_rem_code_phase_samples = 0; @@ -368,7 +365,7 @@ Gps_L1_Ca_Kf_Tracking_cc::~Gps_L1_Ca_Kf_Tracking_cc() } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } if (d_dump) @@ -393,14 +390,11 @@ Gps_L1_Ca_Kf_Tracking_cc::~Gps_L1_Ca_Kf_Tracking_cc() } try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_ca_code); multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -693,7 +687,7 @@ int Gps_L1_Ca_Kf_Tracking_cc::general_work(int noutput_items __attribute__((unus // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // Perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, in); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), in); multicorrelator_cpu.Carrier_wipeoff_multicorrelator_resampler(d_rem_carr_phase_rad, d_carrier_phase_step_rad, d_rem_code_phase_chips, diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.h index 5ee81500e..0b8efb857 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.h +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.h @@ -49,12 +49,12 @@ #include "gnss_synchro.h" #include "tracking_2nd_DLL_filter.h" #include "tracking_2nd_PLL_filter.h" +#include // for volk_gnsssdr::vector #include #include #include #include #include -#include class Gps_L1_Ca_Kf_Tracking_cc; @@ -175,9 +175,9 @@ private: double d_acq_carrier_doppler_hz; // correlator int32_t d_n_correlator_taps; - float* d_ca_code; - float* d_local_code_shift_chips; - gr_complex* d_correlator_outs; + volk_gnsssdr::vector d_ca_code; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs; Cpu_Multicorrelator_Real_Codes multicorrelator_cpu; // tracking vars @@ -203,7 +203,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; double d_carrier_lock_test; double d_CN0_SNV_dB_Hz; double d_carrier_lock_threshold; diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc index d44e9a5ac..003b80133 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc @@ -45,7 +45,7 @@ #include "tracking_discriminators.h" #include #include -#include +#include #include #include #include @@ -53,8 +53,7 @@ #include -gps_l1_ca_tcp_connector_tracking_cc_sptr -gps_l1_ca_tcp_connector_make_tracking_cc( +gps_l1_ca_tcp_connector_tracking_cc_sptr gps_l1_ca_tcp_connector_make_tracking_cc( int64_t fs_in, uint32_t vector_length, bool dump, @@ -105,21 +104,19 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::Gps_L1_Ca_Tcp_Connector_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code = static_cast(volk_gnsssdr_malloc((GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + d_ca_code.reserve(GPS_L1_CA_CODE_LENGTH_CHIPS); // correlator outputs (scalar) d_n_correlator_taps = 3; // Very-Early, Early, Prompt, Late, Very-Late - d_correlator_outs = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + d_correlator_outs.reserve(d_n_correlator_taps); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + // map memory pointers of correlator outputs d_Early = &d_correlator_outs[0]; d_Prompt = &d_correlator_outs[1]; d_Late = &d_correlator_outs[2]; - d_local_code_shift_chips = static_cast(volk_gnsssdr_malloc(d_n_correlator_taps * sizeof(float), volk_gnsssdr_get_alignment())); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -149,7 +146,7 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::Gps_L1_Ca_Tcp_Connector_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = std::vector(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -224,13 +221,10 @@ void Gps_L1_Ca_Tcp_Connector_Tracking_cc::start_tracking() d_carrier_doppler_hz = d_acq_carrier_doppler_hz; // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - gps_l1_ca_code_gen_complex(gsl::span(d_ca_code, (GPS_L1_CA_CODE_LENGTH_CHIPS) * sizeof(gr_complex)), d_acquisition_gnss_synchro->PRN, 0); + gps_l1_ca_code_gen_complex(d_ca_code, d_acquisition_gnss_synchro->PRN, 0); - multicorrelator_cpu.set_local_code_and_taps(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code, d_local_code_shift_chips); - for (int32_t n = 0; n < d_n_correlator_taps; n++) - { - d_correlator_outs[n] = gr_complex(0, 0); - } + multicorrelator_cpu.set_local_code_and_taps(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); d_carrier_lock_fail_counter = 0; d_rem_code_phase_samples = 0; @@ -268,20 +262,17 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::~Gps_L1_Ca_Tcp_Connector_Tracking_cc() } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } try { - volk_gnsssdr_free(d_local_code_shift_chips); - volk_gnsssdr_free(d_correlator_outs); - volk_gnsssdr_free(d_ca_code); d_tcp_com.close_tcp_connection(d_port); multicorrelator_cpu.free(); } catch (const std::exception &ex) { - LOG(WARNING) << "Exception in destructor " << ex.what(); + LOG(WARNING) << "Exception in Tracking block destructor: " << ex.what(); } } @@ -375,7 +366,7 @@ int Gps_L1_Ca_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attrib // ################# CARRIER WIPEOFF AND CORRELATORS ############################## // perform carrier wipe-off and compute Early, Prompt and Late correlation - multicorrelator_cpu.set_input_output_vectors(d_correlator_outs, in); + multicorrelator_cpu.set_input_output_vectors(d_correlator_outs.data(), in); double carr_phase_step_rad = GPS_TWO_PI * d_carrier_doppler_hz / static_cast(d_fs_in); double rem_code_phase_chips = d_rem_code_phase_samples * (d_code_freq_hz / d_fs_in); @@ -491,9 +482,9 @@ int Gps_L1_Ca_Tcp_Connector_Tracking_cc::general_work(int noutput_items __attrib } else { - *d_Early = gr_complex(0, 0); - *d_Prompt = gr_complex(0, 0); - *d_Late = gr_complex(0, 0); + *d_Early = gr_complex(0.0, 0.0); + *d_Prompt = gr_complex(0.0, 0.0); + *d_Late = gr_complex(0.0, 0.0); // GNSS_SYNCHRO OBJECT to interchange data between tracking->telemetry_decoder current_synchro_data.Tracking_sample_counter = d_sample_counter + static_cast(d_correlation_length_samples); // When tracking is disabled an array of 1's is sent to maintain the TCP connection diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.h index 482fc6d95..61ba56bcc 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.h +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.h @@ -41,10 +41,10 @@ #include "gnss_synchro.h" #include "tcp_communication.h" #include +#include // for volk_gnsssdr::vector #include #include #include -#include class Gps_L1_Ca_Tcp_Connector_Tracking_cc; @@ -112,7 +112,7 @@ private: double d_code_phase_step_chips; - gr_complex *d_ca_code; + volk_gnsssdr::vector d_ca_code; gr_complex *d_Early; gr_complex *d_Prompt; @@ -127,8 +127,8 @@ private: float d_acq_code_phase_samples; float d_acq_carrier_doppler_hz; // correlator - float *d_local_code_shift_chips; - gr_complex *d_correlator_outs; + volk_gnsssdr::vector d_local_code_shift_chips; + volk_gnsssdr::vector d_correlator_outs; Cpu_Multicorrelator multicorrelator_cpu; // tracking vars @@ -153,7 +153,7 @@ private: // CN0 estimation and lock detector int32_t d_cn0_estimation_counter; - std::vector d_Prompt_buffer; + volk_gnsssdr::vector d_Prompt_buffer; float d_carrier_lock_test; float d_CN0_SNV_dB_Hz; float d_carrier_lock_threshold; diff --git a/src/tests/unit-tests/arithmetic/conjugate_test.cc b/src/tests/unit-tests/arithmetic/conjugate_test.cc index 00702b802..0d03558c9 100644 --- a/src/tests/unit-tests/arithmetic/conjugate_test.cc +++ b/src/tests/unit-tests/arithmetic/conjugate_test.cc @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -132,3 +133,22 @@ TEST(ConjugateTest, VolkComplexImplementation) volk_gnsssdr_free(input); volk_gnsssdr_free(output); } + + +TEST(ConjugateTest, VolkComplexImplementationAlloc) +{ + volk_gnsssdr::vector> input(FLAGS_size_conjugate_test, std::complex(0.0, 0.0)); + volk_gnsssdr::vector> output(FLAGS_size_conjugate_test); + + std::chrono::time_point start, end; + start = std::chrono::system_clock::now(); + + volk_32fc_conjugate_32fc(output.data(), input.data(), FLAGS_size_conjugate_test); + + end = std::chrono::system_clock::now(); + std::chrono::duration elapsed_seconds = end - start; + std::cout << "Conjugate of a " << FLAGS_size_conjugate_test + << "-length complex float vector using VOLK ALLOC finished in " << elapsed_seconds.count() * 1e6 + << " microseconds" << std::endl; + ASSERT_LE(0, elapsed_seconds.count() * 1e6); +} diff --git a/src/tests/unit-tests/arithmetic/magnitude_squared_test.cc b/src/tests/unit-tests/arithmetic/magnitude_squared_test.cc index be4b9dd24..3eaa958b8 100644 --- a/src/tests/unit-tests/arithmetic/magnitude_squared_test.cc +++ b/src/tests/unit-tests/arithmetic/magnitude_squared_test.cc @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -45,6 +46,10 @@ TEST(MagnitudeSquaredTest, StandardCComplexImplementation) auto* input = new std::complex[FLAGS_size_magnitude_test]; auto* output = new float[FLAGS_size_magnitude_test]; unsigned int number = 0; + for (number = 0; number < static_cast(FLAGS_size_magnitude_test); number++) + { + input[number] = std::complex(0.0, 0.0); + } std::chrono::time_point start, end; start = std::chrono::system_clock::now(); @@ -56,7 +61,7 @@ TEST(MagnitudeSquaredTest, StandardCComplexImplementation) end = std::chrono::system_clock::now(); std::chrono::duration elapsed_seconds = end - start; std::cout << "The squared magnitude of a " << FLAGS_size_magnitude_test - << "-length vector in standard C computed in " << elapsed_seconds.count() * 1e6 + << "-length complex vector in standard C computed in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; delete[] input; delete[] output; @@ -132,4 +137,24 @@ TEST(MagnitudeSquaredTest, VolkComplexImplementation) ASSERT_LE(0, elapsed_seconds.count() * 1e6); } -// volk_32f_accumulator_s32f(&d_input_power, d_magnitude, d_fft_size); + +TEST(MagnitudeSquaredTest, VolkComplexImplementationAlloc) +{ + volk_gnsssdr::vector> input(FLAGS_size_magnitude_test); // or: input(FLAGS_size_magnitude_test, std::complex(0.0, 0.0)); + std::fill_n(input.begin(), FLAGS_size_magnitude_test, std::complex(0.0, 0.0)); + volk_gnsssdr::vector output(FLAGS_size_magnitude_test); + + std::chrono::time_point start, end; + start = std::chrono::system_clock::now(); + + volk_32fc_magnitude_squared_32f(output.data(), input.data(), static_cast(FLAGS_size_magnitude_test)); + + end = std::chrono::system_clock::now(); + std::chrono::duration elapsed_seconds = end - start; + std::cout << "The squared magnitude of a " << FLAGS_size_magnitude_test + << "-length vector using VOLK ALLOC computed in " << elapsed_seconds.count() * 1e6 + << " microseconds" << std::endl; + ASSERT_LE(0, elapsed_seconds.count() * 1e6); +} + +// volk_32f_accumulator_s32f(&d_input_power, d_magnitude, d_fft_size); diff --git a/src/tests/unit-tests/arithmetic/multiply_test.cc b/src/tests/unit-tests/arithmetic/multiply_test.cc index 27bc4295f..2587b5516 100644 --- a/src/tests/unit-tests/arithmetic/multiply_test.cc +++ b/src/tests/unit-tests/arithmetic/multiply_test.cc @@ -60,8 +60,8 @@ TEST(MultiplyTest, StandardCDoubleImplementation) << " doubles in standard C finished in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; - double acc = 0; - double expected = 0; + double acc = 0.0; + double expected = 0.0; for (int i = 0; i < FLAGS_size_multiply_test; i++) { acc += output[i]; @@ -112,8 +112,8 @@ TEST(MultiplyTest, StandardCComplexImplementation) << " complex in standard C finished in " << elapsed_seconds.count() * 1e6 << " microseconds" << std::endl; - std::complex expected(0, 0); - std::complex result(0, 0); + std::complex expected(0.0, 0.0); + std::complex result(0.0, 0.0); for (int i = 0; i < FLAGS_size_multiply_test; i++) { result += output[i]; @@ -146,7 +146,7 @@ TEST(MultiplyTest, C11ComplexImplementation) << " microseconds" << std::endl; ASSERT_LE(0, elapsed_seconds.count() * 1e6); - std::complex expected(0, 0); + std::complex expected(0.0, 0.0); auto result = std::inner_product(output.begin(), output.end(), output.begin(), expected); ASSERT_EQ(expected, result); } @@ -193,14 +193,43 @@ TEST(MultiplyTest, VolkComplexImplementation) auto* mag = static_cast(volk_gnsssdr_malloc(FLAGS_size_multiply_test * sizeof(float), volk_gnsssdr_get_alignment())); volk_32fc_magnitude_32f(mag, output, FLAGS_size_multiply_test); - auto* result = new float(0); + auto* result = new float(0.0); volk_32f_accumulator_s32f(result, mag, FLAGS_size_multiply_test); // Comparing floating-point numbers is tricky. // Due to round-off errors, it is very unlikely that two floating-points will match exactly. // See http://code.google.com/p/googletest/wiki/AdvancedGuide#Floating-Point_Comparison - float expected = 0; + float expected = 0.0; ASSERT_FLOAT_EQ(expected, result[0]); volk_gnsssdr_free(input); volk_gnsssdr_free(output); volk_gnsssdr_free(mag); } + + +TEST(MultiplyTest, VolkComplexImplementationAlloc) +{ + volk_gnsssdr::vector> input(FLAGS_size_multiply_test, std::complex(0.0, 0.0)); + volk_gnsssdr::vector> output(FLAGS_size_multiply_test); + + std::chrono::time_point start, end; + start = std::chrono::system_clock::now(); + + volk_32fc_x2_multiply_32fc(output.data(), input.data(), input.data(), FLAGS_size_multiply_test); + + end = std::chrono::system_clock::now(); + std::chrono::duration elapsed_seconds = end - start; + std::cout << "Element-wise multiplication of " << FLAGS_size_multiply_test + << "-length complex float vector using VOLK ALLOC finished in " << elapsed_seconds.count() * 1e6 + << " microseconds" << std::endl; + ASSERT_LE(0, elapsed_seconds.count() * 1e6); + volk_gnsssdr::vector mag(FLAGS_size_multiply_test); + volk_32fc_magnitude_32f(mag.data(), output.data(), FLAGS_size_multiply_test); + + auto* result = new float(0.0); + volk_32f_accumulator_s32f(result, mag.data(), FLAGS_size_multiply_test); + // Comparing floating-point numbers is tricky. + // Due to round-off errors, it is very unlikely that two floating-points will match exactly. + // See http://code.google.com/p/googletest/wiki/AdvancedGuide#Floating-Point_Comparison + float expected = 0.0; + ASSERT_FLOAT_EQ(expected, result[0]); +} diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_real_codes_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_real_codes_test.cc index 078ab9f6c..dcf34905b 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_real_codes_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_real_codes_test.cc @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -173,3 +173,96 @@ TEST(CpuMulticorrelatorRealCodesTest, MeasureExecutionTime) correlator_pool[n]->free(); } } + + +TEST(CpuMulticorrelatorRealCodesTest, MeasureExecutionTimeAlloc) +{ + std::chrono::time_point start; + std::chrono::time_point end; + std::chrono::duration elapsed_seconds(0); + int max_threads = FLAGS_cpu_multicorrelator_real_codes_max_threads_test; + std::vector thread_pool; + std::vector correlator_pool(max_threads); + unsigned int correlation_sizes[3] = {2048, 4096, 8192}; + double execution_times[3]; + volk_gnsssdr::vector d_ca_code(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS)); + int d_n_correlator_taps = 3; + int d_vector_length = correlation_sizes[2]; // max correlation size to allocate all the necessary memory + volk_gnsssdr::vector in_cpu(2 * d_vector_length); + + // correlator outputs (scalar) + d_n_correlator_taps = 3; // Early, Prompt, and Late + volk_gnsssdr::vector d_correlator_outs(d_n_correlator_taps, gr_complex(0.0, 0.0)); + volk_gnsssdr::vector d_local_code_shift_chips(d_n_correlator_taps); + + // Set TAPs delay values [chips] + float d_early_late_spc_chips = 0.5; + d_local_code_shift_chips[0] = -d_early_late_spc_chips; + d_local_code_shift_chips[1] = 0.0; + d_local_code_shift_chips[2] = d_early_late_spc_chips; + + // --- Perform initializations ------------------------------ + + // local code resampler on GPU + // generate local reference (1 sample per chip) + gps_l1_ca_code_gen_float(d_ca_code, 1, 0); + // generate inut signal + std::random_device r; + std::default_random_engine e1(r()); + std::uniform_real_distribution uniform_dist(0, 1); + for (int n = 0; n < 2 * d_vector_length; n++) + { + in_cpu[n] = std::complex(uniform_dist(e1), uniform_dist(e1)); + } + + for (int n = 0; n < max_threads; n++) + { + correlator_pool[n] = new Cpu_Multicorrelator_Real_Codes(); + correlator_pool[n]->init(d_vector_length, d_n_correlator_taps); + correlator_pool[n]->set_input_output_vectors(d_correlator_outs.data(), in_cpu.data()); + correlator_pool[n]->set_local_code_and_taps(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + } + + float d_rem_carrier_phase_rad = 0.0; + float d_carrier_phase_step_rad = 0.1; + float d_code_phase_step_chips = 0.3; + float d_code_phase_rate_step_chips = 0.00001; + float d_rem_code_phase_chips = 0.4; + + EXPECT_NO_THROW( + for (int correlation_sizes_idx = 0; correlation_sizes_idx < 3; correlation_sizes_idx++) { + for (int current_max_threads = 1; current_max_threads < (max_threads + 1); current_max_threads++) + { + std::cout << "Running " << current_max_threads << " concurrent correlators" << std::endl; + start = std::chrono::system_clock::now(); + // create the concurrent correlator threads + for (int current_thread = 0; current_thread < current_max_threads; current_thread++) + { + thread_pool.emplace_back(std::thread(run_correlator_cpu_real_codes, + correlator_pool[current_thread], + d_rem_carrier_phase_rad, + d_carrier_phase_step_rad, + d_code_phase_step_chips, + d_code_phase_rate_step_chips, + d_rem_code_phase_chips, + correlation_sizes[correlation_sizes_idx])); + } + // wait the threads to finish they work and destroy the thread objects + for (auto& t : thread_pool) + { + t.join(); + } + thread_pool.clear(); + end = std::chrono::system_clock::now(); + elapsed_seconds = end - start; + execution_times[correlation_sizes_idx] = elapsed_seconds.count() / static_cast(FLAGS_cpu_multicorrelator_real_codes_iterations_test); + std::cout << "CPU Multicorrelator (real codes) execution time for length=" << correlation_sizes[correlation_sizes_idx] + << " : " << execution_times[correlation_sizes_idx] << " [s]" << std::endl; + } + }); + + for (int n = 0; n < max_threads; n++) + { + correlator_pool[n]->free(); + } +} diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc index 0726fc32f..4130c464d 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/cpu_multicorrelator_test.cc @@ -35,7 +35,7 @@ #include #include #include -#include +#include #include #include #include @@ -168,3 +168,96 @@ TEST(CpuMulticorrelatorTest, MeasureExecutionTime) correlator_pool[n]->free(); } } + + +TEST(CpuMulticorrelatorTest, MeasureExecutionTimeAlloc) +{ + std::chrono::time_point start, end; + std::chrono::duration elapsed_seconds(0); + int max_threads = FLAGS_cpu_multicorrelator_max_threads_test; + std::vector thread_pool; + std::vector correlator_pool(max_threads); + unsigned int correlation_sizes[3] = {2048, 4096, 8192}; + double execution_times[3]; + + int d_n_correlator_taps = 3; + int d_vector_length = correlation_sizes[2]; // max correlation size to allocate all the necessary memory + + // allocate host memory + // Get space for a vector with the C/A code replica sampled 1x/chip + volk_gnsssdr::vector d_ca_code(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS)); + volk_gnsssdr::vector in_cpu(2 * d_vector_length); + + // correlator outputs (scalar) + d_n_correlator_taps = 3; // Early, Prompt, and Late + volk_gnsssdr::vector d_correlator_outs(d_n_correlator_taps, gr_complex(0.0, 0.0)); + volk_gnsssdr::vector d_local_code_shift_chips(d_n_correlator_taps); + // Set TAPs delay values [chips] + float d_early_late_spc_chips = 0.5; + d_local_code_shift_chips[0] = -d_early_late_spc_chips; + d_local_code_shift_chips[1] = 0.0; + d_local_code_shift_chips[2] = d_early_late_spc_chips; + + // -- Perform initializations ------------------------------ + + // local code resampler on GPU + // generate local reference (1 sample per chip) + gps_l1_ca_code_gen_complex(d_ca_code, 1, 0); + // generate inut signal + std::random_device r; + std::default_random_engine e1(r()); + std::uniform_real_distribution uniform_dist(0, 1); + for (int n = 0; n < 2 * d_vector_length; n++) + { + in_cpu[n] = std::complex(uniform_dist(e1), uniform_dist(e1)); + } + + for (int n = 0; n < max_threads; n++) + { + correlator_pool[n] = new Cpu_Multicorrelator(); + correlator_pool[n]->init(d_vector_length, d_n_correlator_taps); + correlator_pool[n]->set_input_output_vectors(d_correlator_outs.data(), in_cpu.data()); + correlator_pool[n]->set_local_code_and_taps(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); + } + + float d_rem_carrier_phase_rad = 0.0; + float d_carrier_phase_step_rad = 0.1; + float d_code_phase_step_chips = 0.3; + float d_rem_code_phase_chips = 0.4; + + EXPECT_NO_THROW( + for (int correlation_sizes_idx = 0; correlation_sizes_idx < 3; correlation_sizes_idx++) { + for (int current_max_threads = 1; current_max_threads < (max_threads + 1); current_max_threads++) + { + std::cout << "Running " << current_max_threads << " concurrent correlators" << std::endl; + start = std::chrono::system_clock::now(); + // create the concurrent correlator threads + for (int current_thread = 0; current_thread < current_max_threads; current_thread++) + { + thread_pool.push_back(std::thread(run_correlator_cpu, + correlator_pool[current_thread], + d_rem_carrier_phase_rad, + d_carrier_phase_step_rad, + d_code_phase_step_chips, + d_rem_code_phase_chips, + correlation_sizes[correlation_sizes_idx])); + } + // wait the threads to finish they work and destroy the thread objects + for (auto& t : thread_pool) + { + t.join(); + } + thread_pool.clear(); + end = std::chrono::system_clock::now(); + elapsed_seconds = end - start; + execution_times[correlation_sizes_idx] = elapsed_seconds.count() / static_cast(FLAGS_cpu_multicorrelator_iterations_test); + std::cout << "CPU Multicorrelator execution time for length=" << correlation_sizes[correlation_sizes_idx] + << " : " << execution_times[correlation_sizes_idx] << " [s]" << std::endl; + } + }); + + for (int n = 0; n < max_threads; n++) + { + correlator_pool[n]->free(); + } +} From 82089979feb422b8f0df16872903838f04b5d3dc Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 27 Oct 2019 11:25:31 +0100 Subject: [PATCH 2/4] Fix usage of resize instead of reserve --- .../pcps_acquisition_fine_doppler_cc.cc | 61 +++++++------------ .../pcps_acquisition_fine_doppler_cc.h | 18 +++--- .../galileo_e1_tcp_connector_tracking_cc.cc | 8 +-- ...glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc | 13 ++-- ...glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc | 13 ++-- .../glonass_l1_ca_dll_pll_tracking_cc.cc | 12 ++-- ...glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc | 12 ++-- ...glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc | 13 ++-- .../glonass_l2_ca_dll_pll_tracking_cc.cc | 13 ++-- .../gps_l1_ca_kf_tracking_cc.cc | 11 ++-- .../gps_l1_ca_tcp_connector_tracking_cc.cc | 8 +-- ...onass_l1_ca_dll_pll_c_aid_tracking_test.cc | 7 --- 12 files changed, 78 insertions(+), 111 deletions(-) diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc index 80028c607..a2d4541ae 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc @@ -47,10 +47,10 @@ #include #include #include -#include #include // std::rotate, std::fill_n #include #include +#include #if HAS_STD_FILESYSTEM #if HAS_STD_FILESYSTEM_EXPERIMENTAL @@ -87,12 +87,9 @@ pcps_acquisition_fine_doppler_cc::pcps_acquisition_fine_doppler_cc(const Acq_Con d_max_dwells = conf_.max_dwells; d_gnuradio_forecast_samples = d_fft_size; d_state = 0; - d_carrier = static_cast(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_fft_codes = static_cast(volk_gnsssdr_malloc(d_fft_size * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - d_magnitude = static_cast(volk_gnsssdr_malloc(d_fft_size * sizeof(float), volk_gnsssdr_get_alignment())); - - d_10_ms_buffer = static_cast(volk_gnsssdr_malloc(50 * d_samples_per_ms * sizeof(gr_complex), volk_gnsssdr_get_alignment())); - + d_fft_codes.resize(d_fft_size); + d_magnitude.resize(d_fft_size); + d_10_ms_buffer.resize(50 * d_samples_per_ms); // Direct FFT d_fft_if = std::make_shared(d_fft_size, true); @@ -175,7 +172,7 @@ void pcps_acquisition_fine_doppler_cc::set_doppler_step(unsigned int doppler_ste d_num_doppler_points = floor(std::abs(2 * d_config_doppler_max) / d_doppler_step); - d_grid_data = std::vector>(d_num_doppler_points, std::vector(d_fft_size)); + d_grid_data = volk_gnsssdr::vector>(d_num_doppler_points, volk_gnsssdr::vector(d_fft_size)); if (d_dump) { @@ -186,21 +183,12 @@ void pcps_acquisition_fine_doppler_cc::set_doppler_step(unsigned int doppler_ste } -pcps_acquisition_fine_doppler_cc::~pcps_acquisition_fine_doppler_cc() -{ - volk_gnsssdr_free(d_carrier); - volk_gnsssdr_free(d_fft_codes); - volk_gnsssdr_free(d_magnitude); - volk_gnsssdr_free(d_10_ms_buffer); -} - - void pcps_acquisition_fine_doppler_cc::set_local_code(std::complex *code) { memcpy(d_fft_if->get_inbuf(), code, sizeof(gr_complex) * d_fft_size); d_fft_if->execute(); // We need the FFT of local code // Conjugate the local code - volk_32fc_conjugate_32fc(d_fft_codes, d_fft_if->get_outbuf(), d_fft_size); + volk_32fc_conjugate_32fc(d_fft_codes.data(), d_fft_if->get_outbuf(), d_fft_size); } @@ -247,7 +235,7 @@ void pcps_acquisition_fine_doppler_cc::update_carrier_wipeoff() // create the carrier Doppler wipeoff signals int doppler_hz; float phase_step_rad; - d_grid_doppler_wipeoffs = std::vector>>(d_num_doppler_points, std::vector>(d_fft_size)); + d_grid_doppler_wipeoffs = volk_gnsssdr::vector>>(d_num_doppler_points, volk_gnsssdr::vector>(d_fft_size)); for (int doppler_index = 0; doppler_index < d_num_doppler_points; doppler_index++) { doppler_hz = d_doppler_step * doppler_index - d_config_doppler_max; @@ -338,8 +326,8 @@ float pcps_acquisition_fine_doppler_cc::estimate_input_power(gr_vector_const_voi const auto *in = reinterpret_cast(input_items[0]); // Get the input samples pointer // Compute the input signal power estimation float power = 0; - volk_32fc_magnitude_squared_32f(d_magnitude, in, d_fft_size); - volk_32f_accumulator_s32f(&power, d_magnitude, d_fft_size); + volk_32fc_magnitude_squared_32f(d_magnitude.data(), in, d_fft_size); + volk_32f_accumulator_s32f(&power, d_magnitude.data(), d_fft_size); power /= static_cast(d_fft_size); return power; } @@ -357,7 +345,7 @@ int pcps_acquisition_fine_doppler_cc::compute_and_accumulate_grid(gr_vector_cons << ", doppler_step: " << d_doppler_step; // 2- Doppler frequency search loop - auto *p_tmp_vector = static_cast(volk_gnsssdr_malloc(d_fft_size * sizeof(float), volk_gnsssdr_get_alignment())); + volk_gnsssdr::vector p_tmp_vector(d_fft_size); for (int doppler_index = 0; doppler_index < d_num_doppler_points; doppler_index++) { @@ -371,18 +359,17 @@ int pcps_acquisition_fine_doppler_cc::compute_and_accumulate_grid(gr_vector_cons // Multiply carrier wiped--off, Fourier transformed incoming signal // with the local FFT'd code reference using SIMD operations with VOLK library - volk_32fc_x2_multiply_32fc(d_ifft->get_inbuf(), d_fft_if->get_outbuf(), d_fft_codes, d_fft_size); + volk_32fc_x2_multiply_32fc(d_ifft->get_inbuf(), d_fft_if->get_outbuf(), d_fft_codes.data(), d_fft_size); // compute the inverse FFT d_ifft->execute(); // save the grid matrix delay file - volk_32fc_magnitude_squared_32f(p_tmp_vector, d_ifft->get_outbuf(), d_fft_size); + volk_32fc_magnitude_squared_32f(p_tmp_vector.data(), d_ifft->get_outbuf(), d_fft_size); // accumulate grid values - volk_32f_x2_add_32f(d_grid_data[doppler_index].data(), d_grid_data[doppler_index].data(), p_tmp_vector, d_fft_size); + volk_32f_x2_add_32f(d_grid_data[doppler_index].data(), d_grid_data[doppler_index].data(), p_tmp_vector.data(), d_fft_size); } - volk_gnsssdr_free(p_tmp_vector); return d_fft_size; // debug // std::cout << "iff=["; @@ -408,39 +395,38 @@ int pcps_acquisition_fine_doppler_cc::estimate_Doppler() std::fill_n(fft_operator->get_inbuf(), fft_size_extended, gr_complex(0.0, 0.0)); // 1. generate local code aligned with the acquisition code phase estimation - auto *code_replica = static_cast(volk_gnsssdr_malloc(signal_samples * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + volk_gnsssdr::vector code_replica(signal_samples); - gps_l1_ca_code_gen_complex_sampled(gsl::span(code_replica, signal_samples * sizeof(gr_complex)), d_gnss_synchro->PRN, d_fs_in, 0); + gps_l1_ca_code_gen_complex_sampled(code_replica, d_gnss_synchro->PRN, d_fs_in, 0); int shift_index = static_cast(d_gnss_synchro->Acq_delay_samples); // Rotate to align the local code replica using acquisition time delay estimation if (shift_index != 0) { - std::rotate(code_replica, code_replica + (d_fft_size - shift_index), code_replica + d_fft_size - 1); + std::rotate(code_replica.data(), code_replica.data() + (d_fft_size - shift_index), code_replica.data() + d_fft_size - 1); } for (int n = 0; n < prn_replicas - 1; n++) { - memcpy(&code_replica[(n + 1) * d_fft_size], code_replica, d_fft_size * sizeof(gr_complex)); + memcpy(&code_replica[(n + 1) * d_fft_size], code_replica.data(), d_fft_size * sizeof(gr_complex)); } // 2. Perform code wipe-off - volk_32fc_x2_multiply_32fc(fft_operator->get_inbuf(), d_10_ms_buffer, code_replica, signal_samples); + volk_32fc_x2_multiply_32fc(fft_operator->get_inbuf(), d_10_ms_buffer.data(), code_replica.data(), signal_samples); // 3. Perform the FFT (zero padded!) fft_operator->execute(); // 4. Compute the magnitude and find the maximum - auto *p_tmp_vector = static_cast(volk_gnsssdr_malloc(fft_size_extended * sizeof(float), volk_gnsssdr_get_alignment())); - - volk_32fc_magnitude_squared_32f(p_tmp_vector, fft_operator->get_outbuf(), fft_size_extended); + volk_gnsssdr::vector p_tmp_vector(fft_size_extended); + volk_32fc_magnitude_squared_32f(p_tmp_vector.data(), fft_operator->get_outbuf(), fft_size_extended); uint32_t tmp_index_freq = 0; - volk_gnsssdr_32f_index_max_32u(&tmp_index_freq, p_tmp_vector, fft_size_extended); + volk_gnsssdr_32f_index_max_32u(&tmp_index_freq, p_tmp_vector.data(), fft_size_extended); // case even int counter = 0; - auto fftFreqBins = std::vector(fft_size_extended); + auto fftFreqBins = volk_gnsssdr::vector(fft_size_extended); for (int k = 0; k < (fft_size_extended / 2); k++) { @@ -466,9 +452,6 @@ int pcps_acquisition_fine_doppler_cc::estimate_Doppler() DLOG(INFO) << "Error estimating fine frequency Doppler"; } - // free memory!! - volk_gnsssdr_free(code_replica); - volk_gnsssdr_free(p_tmp_vector); return d_fft_size; } diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.h b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.h index 92b2d6e93..981f6a975 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.h +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.h @@ -60,12 +60,12 @@ #include #include #include +#include // for volk_gnsssdr::vector #include #include #include #include #include -#include class pcps_acquisition_fine_doppler_cc; @@ -83,7 +83,7 @@ public: /*! * \brief Default destructor. */ - ~pcps_acquisition_fine_doppler_cc(); + ~pcps_acquisition_fine_doppler_cc() = default; /*! * \brief Set acquisition/tracking common Gnss_Synchro object pointer @@ -192,8 +192,7 @@ public: gr_vector_void_star& output_items); private: - friend pcps_acquisition_fine_doppler_cc_sptr - pcps_make_acquisition_fine_doppler_cc(const Acq_Conf& conf_); + friend pcps_acquisition_fine_doppler_cc_sptr pcps_make_acquisition_fine_doppler_cc(const Acq_Conf& conf_); explicit pcps_acquisition_fine_doppler_cc(const Acq_Conf& conf_); int compute_and_accumulate_grid(gr_vector_const_void_star& input_items); @@ -215,12 +214,11 @@ private: int d_doppler_step; unsigned int d_fft_size; uint64_t d_sample_counter; - gr_complex* d_carrier; - gr_complex* d_fft_codes; - gr_complex* d_10_ms_buffer; - float* d_magnitude; - std::vector> d_grid_data; - std::vector>> d_grid_doppler_wipeoffs; + volk_gnsssdr::vector d_fft_codes; + volk_gnsssdr::vector d_10_ms_buffer; + volk_gnsssdr::vector d_magnitude; + volk_gnsssdr::vector> d_grid_data; + volk_gnsssdr::vector>> d_grid_doppler_wipeoffs; std::shared_ptr d_fft_if; std::shared_ptr d_ifft; Gnss_Synchro* d_gnss_synchro; diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc index b4e9d9e1f..dfe543d31 100644 --- a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc @@ -117,11 +117,11 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( // Initialization of local code replica // Get space for a vector with the sinboc(1,1) replica sampled 2x/chip - d_ca_code.reserve(2 * GALILEO_E1_B_CODE_LENGTH_CHIPS); + d_ca_code.resize(2 * GALILEO_E1_B_CODE_LENGTH_CHIPS); // correlator outputs (scalar) d_n_correlator_taps = 5; // Very-Early, Early, Prompt, Late, Very-Late - d_correlator_outs.reserve(d_n_correlator_taps); + d_correlator_outs.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); // map memory pointers of correlator outputs d_Very_Early = &d_correlator_outs[0]; @@ -130,7 +130,7 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( d_Late = &d_correlator_outs[3]; d_Very_Late = &d_correlator_outs[4]; - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_very_early_late_spc_chips; d_local_code_shift_chips[1] = -d_early_late_spc_chips; @@ -161,7 +161,7 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = volk_gnsssdr::vector(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc index 84e81a8de..eb1cc3947 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc @@ -62,8 +62,7 @@ #define CN0_ESTIMATION_SAMPLES 10 -glonass_l1_ca_dll_pll_c_aid_tracking_cc_sptr -glonass_l1_ca_dll_pll_c_aid_make_tracking_cc( +glonass_l1_ca_dll_pll_c_aid_tracking_cc_sptr glonass_l1_ca_dll_pll_c_aid_make_tracking_cc( int64_t fs_in, uint32_t vector_length, bool dump, @@ -145,14 +144,14 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::glonass_l1_ca_dll_pll_c_aid_tracking_cc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.reserve(d_n_correlator_taps); + d_correlator_outs.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -176,7 +175,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::glonass_l1_ca_dll_pll_c_aid_tracking_cc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -274,7 +273,7 @@ void glonass_l1_ca_dll_pll_c_aid_tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l1_ca_code_gen_complex(d_ca_code, 0); + glonass_l1_ca_code_gen_complex(gsl::span(d_ca_code.data(), GLONASS_L1_CA_CODE_LENGTH_CHIPS), 0); multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc index 4cd642a0d..665b272a3 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc @@ -60,8 +60,7 @@ #define CN0_ESTIMATION_SAMPLES 10 -glonass_l1_ca_dll_pll_c_aid_tracking_sc_sptr -glonass_l1_ca_dll_pll_c_aid_make_tracking_sc( +glonass_l1_ca_dll_pll_c_aid_tracking_sc_sptr glonass_l1_ca_dll_pll_c_aid_make_tracking_sc( int64_t fs_in, uint32_t vector_length, bool dump, @@ -141,16 +140,16 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::glonass_l1_ca_dll_pll_c_aid_tracking_sc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); - d_ca_code_16sc.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code_16sc.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs_16sc.reserve(d_n_correlator_taps); + d_correlator_outs_16sc.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs_16sc.begin(), d_n_correlator_taps, lv_cmake(0, 0)); - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -174,7 +173,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::glonass_l1_ca_dll_pll_c_aid_tracking_sc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc index a9173b9e6..c680a6e09 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc @@ -57,8 +57,7 @@ #define CN0_ESTIMATION_SAMPLES 10 -glonass_l1_ca_dll_pll_tracking_cc_sptr -glonass_l1_ca_dll_pll_make_tracking_cc( +glonass_l1_ca_dll_pll_tracking_cc_sptr glonass_l1_ca_dll_pll_make_tracking_cc( int64_t fs_in, uint32_t vector_length, bool dump, @@ -111,14 +110,14 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::Glonass_L1_Ca_Dll_Pll_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.reserve(d_n_correlator_taps); + d_correlator_outs.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -144,7 +143,7 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::Glonass_L1_Ca_Dll_Pll_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -226,6 +225,7 @@ void Glonass_L1_Ca_Dll_Pll_Tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) + //glonass_l1_ca_code_gen_complex(gsl::span(d_ca_code.data(), GLONASS_L1_CA_CODE_LENGTH_CHIPS), 0); glonass_l1_ca_code_gen_complex(d_ca_code, 0); multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc index 3f1d5c25d..df835f078 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc @@ -58,8 +58,7 @@ #define CN0_ESTIMATION_SAMPLES 10 -glonass_l2_ca_dll_pll_c_aid_tracking_cc_sptr -glonass_l2_ca_dll_pll_c_aid_make_tracking_cc( +glonass_l2_ca_dll_pll_c_aid_tracking_cc_sptr glonass_l2_ca_dll_pll_c_aid_make_tracking_cc( int64_t fs_in, uint32_t vector_length, bool dump, @@ -141,14 +140,14 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::glonass_l2_ca_dll_pll_c_aid_tracking_cc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.reserve(d_n_correlator_taps); + d_correlator_outs.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -172,7 +171,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::glonass_l2_ca_dll_pll_c_aid_tracking_cc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -264,7 +263,6 @@ void glonass_l2_ca_dll_pll_c_aid_tracking_cc::start_tracking() d_carrier_doppler_hz = d_acq_carrier_doppler_hz; d_carrier_phase_step_rad = GLONASS_TWO_PI * d_carrier_frequency_hz / static_cast(d_fs_in); - // DLL/PLL filter initialization d_carrier_loop_filter.initialize(d_carrier_frequency_hz); // The carrier loop filter implements the Doppler accumulator d_code_loop_filter.initialize(); // initialize the code filter diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc index f558ab61e..2f2d6dbcf 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc @@ -58,8 +58,7 @@ #define CN0_ESTIMATION_SAMPLES 10 -glonass_l2_ca_dll_pll_c_aid_tracking_sc_sptr -glonass_l2_ca_dll_pll_c_aid_make_tracking_sc( +glonass_l2_ca_dll_pll_c_aid_tracking_sc_sptr glonass_l2_ca_dll_pll_c_aid_make_tracking_sc( int64_t fs_in, uint32_t vector_length, bool dump, @@ -139,16 +138,16 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::glonass_l2_ca_dll_pll_c_aid_tracking_sc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); - d_ca_code_16sc.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code_16sc.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs_16sc.reserve(d_n_correlator_taps); + d_correlator_outs_16sc.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs_16sc.begin(), d_n_correlator_taps, lv_cmake(0, 0)); - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -172,7 +171,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::glonass_l2_ca_dll_pll_c_aid_tracking_sc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc index 15c991504..4790870a5 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc @@ -58,8 +58,7 @@ #define CN0_ESTIMATION_SAMPLES 10 -glonass_l2_ca_dll_pll_tracking_cc_sptr -glonass_l2_ca_dll_pll_make_tracking_cc( +glonass_l2_ca_dll_pll_tracking_cc_sptr glonass_l2_ca_dll_pll_make_tracking_cc( int64_t fs_in, uint32_t vector_length, bool dump, @@ -112,14 +111,14 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::Glonass_L2_Ca_Dll_Pll_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.reserve(d_n_correlator_taps); + d_correlator_outs.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -145,7 +144,7 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::Glonass_L2_Ca_Dll_Pll_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; @@ -227,7 +226,7 @@ void Glonass_L2_Ca_Dll_Pll_Tracking_cc::start_tracking() d_code_loop_filter.initialize(); // initialize the code filter // generate local reference ALWAYS starting at chip 1 (1 sample per chip) - glonass_l2_ca_code_gen_complex(d_ca_code, 0); + glonass_l2_ca_code_gen_complex(gsl::span(d_ca_code.data(), GLONASS_L2_CA_CODE_LENGTH_CHIPS), 0); multicorrelator_cpu.set_local_code_and_taps(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), d_ca_code.data(), d_local_code_shift_chips.data()); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc index a0c677a0e..f373987d5 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc @@ -59,8 +59,7 @@ #include -gps_l1_ca_kf_tracking_cc_sptr -gps_l1_ca_kf_make_tracking_cc( +gps_l1_ca_kf_tracking_cc_sptr gps_l1_ca_kf_make_tracking_cc( uint32_t order, int64_t if_freq, int64_t fs_in, @@ -129,14 +128,14 @@ Gps_L1_Ca_Kf_Tracking_cc::Gps_L1_Ca_Kf_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GPS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.reserve(d_n_correlator_taps); + d_correlator_outs.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -163,7 +162,7 @@ Gps_L1_Ca_Kf_Tracking_cc::Gps_L1_Ca_Kf_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc index 003b80133..da8a3ebd4 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc @@ -104,11 +104,11 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::Gps_L1_Ca_Tcp_Connector_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.reserve(GPS_L1_CA_CODE_LENGTH_CHIPS); + d_ca_code.resize(GPS_L1_CA_CODE_LENGTH_CHIPS); // correlator outputs (scalar) d_n_correlator_taps = 3; // Very-Early, Early, Prompt, Late, Very-Late - d_correlator_outs.reserve(d_n_correlator_taps); + d_correlator_outs.resize(d_n_correlator_taps); std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); // map memory pointers of correlator outputs @@ -116,7 +116,7 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::Gps_L1_Ca_Tcp_Connector_Tracking_cc( d_Prompt = &d_correlator_outs[1]; d_Late = &d_correlator_outs[2]; - d_local_code_shift_chips.reserve(d_n_correlator_taps); + d_local_code_shift_chips.resize(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -146,7 +146,7 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::Gps_L1_Ca_Tcp_Connector_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.reserve(FLAGS_cn0_samples); + d_Prompt_buffer.resize(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/tests/unit-tests/signal-processing-blocks/tracking/glonass_l1_ca_dll_pll_c_aid_tracking_test.cc b/src/tests/unit-tests/signal-processing-blocks/tracking/glonass_l1_ca_dll_pll_c_aid_tracking_test.cc index 86a2c06de..8cd8501ea 100644 --- a/src/tests/unit-tests/signal-processing-blocks/tracking/glonass_l1_ca_dll_pll_c_aid_tracking_test.cc +++ b/src/tests/unit-tests/signal-processing-blocks/tracking/glonass_l1_ca_dll_pll_c_aid_tracking_test.cc @@ -39,7 +39,6 @@ #include "gnss_synchro.h" #include "in_memory_configuration.h" #include "tracking_interface.h" -#include #include #include #include @@ -47,11 +46,6 @@ #include #include #include -#ifdef GR_GREATER_38 -#include -#else -#include -#endif // ######## GNURADIO BLOCK MESSAGE RECEVER ######### class GlonassL1CaDllPllCAidTrackingTest_msg_rx; @@ -179,7 +173,6 @@ TEST_F(GlonassL1CaDllPllCAidTrackingTest, ValidationOfResults) }) << "Failure connecting tracking to the top_block."; ASSERT_NO_THROW({ - gr::analog::sig_source_c::sptr sin_source = gr::analog::sig_source_c::make(fs_in, gr::analog::GR_SIN_WAVE, 1000, 1, gr_complex(0)); std::string path = std::string(TEST_PATH); std::string file = path + "signal_samples/NT1065_GLONASS_L1_20160831_fs6625e6_if0e3_4ms.bin"; const char* file_name = file.c_str(); From 9a9c8825edb2c31285f282bf3208a66435251392 Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 27 Oct 2019 12:51:01 +0100 Subject: [PATCH 3/4] Improved usage of reserve/resize --- .../pcps_acquisition_fine_doppler_cc.cc | 8 ++++---- .../gnuradio_blocks/dll_pll_veml_tracking.cc | 12 ++++++------ .../gnuradio_blocks/dll_pll_veml_tracking_fpga.cc | 2 +- .../galileo_e1_tcp_connector_tracking_cc.cc | 9 ++++----- .../glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc | 9 ++++----- .../glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc | 12 +++++------- .../glonass_l1_ca_dll_pll_tracking_cc.cc | 9 ++++----- .../glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc | 9 ++++----- .../glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc | 12 +++++------- .../glonass_l2_ca_dll_pll_tracking_cc.cc | 9 ++++----- .../gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc | 7 +++---- .../gps_l1_ca_tcp_connector_tracking_cc.cc | 4 ++-- 12 files changed, 46 insertions(+), 56 deletions(-) diff --git a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc index a2d4541ae..23ac3b535 100644 --- a/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc +++ b/src/algorithms/acquisition/gnuradio_blocks/pcps_acquisition_fine_doppler_cc.cc @@ -87,9 +87,9 @@ pcps_acquisition_fine_doppler_cc::pcps_acquisition_fine_doppler_cc(const Acq_Con d_max_dwells = conf_.max_dwells; d_gnuradio_forecast_samples = d_fft_size; d_state = 0; - d_fft_codes.resize(d_fft_size); - d_magnitude.resize(d_fft_size); - d_10_ms_buffer.resize(50 * d_samples_per_ms); + d_fft_codes.reserve(d_fft_size); + d_magnitude.reserve(d_fft_size); + d_10_ms_buffer.reserve(50 * d_samples_per_ms); // Direct FFT d_fft_if = std::make_shared(d_fft_size, true); @@ -426,7 +426,7 @@ int pcps_acquisition_fine_doppler_cc::estimate_Doppler() // case even int counter = 0; - auto fftFreqBins = volk_gnsssdr::vector(fft_size_extended); + volk_gnsssdr::vector fftFreqBins(fft_size_extended); for (int k = 0; k < (fft_size_extended / 2); k++) { diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc index f9fa89e27..1dabf6b84 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking.cc @@ -353,7 +353,7 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl // Initialization of local code replica // Get space for a vector with the sinboc(1,1) replica sampled 2x/chip - d_tracking_code.resize(2 * d_code_length_chips); + d_tracking_code.resize(2 * d_code_length_chips, 0.0); // correlator outputs (scalar) if (d_veml) { @@ -366,8 +366,8 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl d_n_correlator_taps = 3; } - d_correlator_outs.resize(d_n_correlator_taps); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_correlator_outs.reserve(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // map memory pointers of correlator outputs if (d_veml) { @@ -414,7 +414,7 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl // Extra correlator for the data component correlator_data_cpu.init(2 * trk_parameters.vector_length, 1); correlator_data_cpu.set_high_dynamics_resampler(trk_parameters.high_dyn); - d_data_code.resize(2 * d_code_length_chips); + d_data_code.resize(2 * d_code_length_chips, 0.0); } // --- Initializations --- @@ -436,13 +436,13 @@ dll_pll_veml_tracking::dll_pll_veml_tracking(const Dll_Pll_Conf &conf_) : gr::bl // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = volk_gnsssdr::vector(trk_parameters.cn0_samples); + d_Prompt_buffer.reserve(trk_parameters.cn0_samples); d_carrier_lock_test = 1.0; d_CN0_SNV_dB_Hz = 0.0; d_carrier_lock_fail_counter = 0; d_code_lock_fail_counter = 0; d_carrier_lock_threshold = trk_parameters.carrier_lock_th; - d_Prompt_Data.resize(1); + d_Prompt_Data.reserve(1); d_cn0_smoother = Exponential_Smoother(); d_cn0_smoother.set_alpha(trk_parameters.cn0_smoother_alpha); diff --git a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc index 13d35604a..c93ee9906 100644 --- a/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc +++ b/src/algorithms/tracking/gnuradio_blocks/dll_pll_veml_tracking_fpga.cc @@ -369,7 +369,7 @@ dll_pll_veml_tracking_fpga::dll_pll_veml_tracking_fpga(const Dll_Pll_Conf_Fpga & // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer = volk_gnsssdr::vector(trk_parameters.cn0_samples); + d_Prompt_buffer.reserve(trk_parameters.cn0_samples); d_carrier_lock_test = 1.0; d_CN0_SNV_dB_Hz = 0.0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc index dfe543d31..892e24c72 100644 --- a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_tcp_connector_tracking_cc.cc @@ -117,12 +117,11 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( // Initialization of local code replica // Get space for a vector with the sinboc(1,1) replica sampled 2x/chip - d_ca_code.resize(2 * GALILEO_E1_B_CODE_LENGTH_CHIPS); + d_ca_code.resize(2 * GALILEO_E1_B_CODE_LENGTH_CHIPS, gr_complex(0.0, 0.0)); // correlator outputs (scalar) d_n_correlator_taps = 5; // Very-Early, Early, Prompt, Late, Very-Late - d_correlator_outs.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + d_correlator_outs.resize(d_n_correlator_taps, gr_complex(0.0, 0.0)); // map memory pointers of correlator outputs d_Very_Early = &d_correlator_outs[0]; d_Early = &d_correlator_outs[1]; @@ -130,7 +129,7 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( d_Late = &d_correlator_outs[3]; d_Very_Late = &d_correlator_outs[4]; - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_very_early_late_spc_chips; d_local_code_shift_chips[1] = -d_early_late_spc_chips; @@ -161,7 +160,7 @@ Galileo_E1_Tcp_Connector_Tracking_cc::Galileo_E1_Tcp_Connector_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc index eb1cc3947..e87e15d23 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_cc.cc @@ -144,14 +144,13 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::glonass_l1_ca_dll_pll_c_aid_tracking_cc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), gr_complex(0.0, 0.0)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + d_correlator_outs.resize(d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -175,7 +174,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_cc::glonass_l1_ca_dll_pll_c_aid_tracking_cc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc index 665b272a3..cd712c5b6 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_c_aid_tracking_sc.cc @@ -47,7 +47,6 @@ #include #include #include -#include #include #include #include @@ -140,16 +139,15 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::glonass_l1_ca_dll_pll_c_aid_tracking_sc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); - d_ca_code_16sc.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), gr_complex(0.0, 0.0)); + d_ca_code_16sc.reserve(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs_16sc.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs_16sc.begin(), d_n_correlator_taps, lv_cmake(0, 0)); + d_correlator_outs_16sc.resize(d_n_correlator_taps, lv_cmake(0, 0)); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -173,7 +171,7 @@ glonass_l1_ca_dll_pll_c_aid_tracking_sc::glonass_l1_ca_dll_pll_c_aid_tracking_sc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc index c680a6e09..ac1ad9a91 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l1_ca_dll_pll_tracking_cc.cc @@ -110,14 +110,13 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::Glonass_L1_Ca_Dll_Pll_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L1_CA_CODE_LENGTH_CHIPS), gr_complex(0.0, 0.0)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + d_correlator_outs.resize(d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -143,7 +142,7 @@ Glonass_L1_Ca_Dll_Pll_Tracking_cc::Glonass_L1_Ca_Dll_Pll_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc index df835f078..1e8445b73 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_cc.cc @@ -140,14 +140,13 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::glonass_l2_ca_dll_pll_c_aid_tracking_cc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), gr_complex(0.0, 0.0)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + d_correlator_outs.resize(d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -171,7 +170,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_cc::glonass_l2_ca_dll_pll_c_aid_tracking_cc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc index 2f2d6dbcf..4a8609aa5 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_c_aid_tracking_sc.cc @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include @@ -138,16 +137,15 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::glonass_l2_ca_dll_pll_c_aid_tracking_sc // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); - d_ca_code_16sc.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), gr_complex(0.0, 0.0)); + d_ca_code_16sc.reserve(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs_16sc.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs_16sc.begin(), d_n_correlator_taps, lv_cmake(0, 0)); + d_correlator_outs_16sc.resize(d_n_correlator_taps, lv_cmake(0, 0)); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -171,7 +169,7 @@ glonass_l2_ca_dll_pll_c_aid_tracking_sc::glonass_l2_ca_dll_pll_c_aid_tracking_sc // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc index 4790870a5..53d6a2d81 100644 --- a/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/glonass_l2_ca_dll_pll_tracking_cc.cc @@ -111,14 +111,13 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::Glonass_L2_Ca_Dll_Pll_Tracking_cc( // Initialization of local code replica // Get space for a vector with the C/A code replica sampled 1x/chip - d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS)); + d_ca_code.resize(static_cast(GLONASS_L2_CA_CODE_LENGTH_CHIPS), gr_complex(0.0, 0.0)); // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + d_correlator_outs.resize(d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -144,7 +143,7 @@ Glonass_L2_Ca_Dll_Pll_Tracking_cc::Glonass_L2_Ca_Dll_Pll_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc index f373987d5..898ec4113 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_kf_tracking_cc.cc @@ -132,10 +132,9 @@ Gps_L1_Ca_Kf_Tracking_cc::Gps_L1_Ca_Kf_Tracking_cc( // correlator outputs (scalar) d_n_correlator_taps = 3; // Early, Prompt, and Late - d_correlator_outs.resize(d_n_correlator_taps); - std::fill_n(d_correlator_outs.begin(), d_n_correlator_taps, gr_complex(0.0, 0.0)); + d_correlator_outs.resize(d_n_correlator_taps, gr_complex(0.0, 0.0)); - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -162,7 +161,7 @@ Gps_L1_Ca_Kf_Tracking_cc::Gps_L1_Ca_Kf_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; diff --git a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc index da8a3ebd4..7e6a93b7d 100644 --- a/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc +++ b/src/algorithms/tracking/gnuradio_blocks/gps_l1_ca_tcp_connector_tracking_cc.cc @@ -116,7 +116,7 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::Gps_L1_Ca_Tcp_Connector_Tracking_cc( d_Prompt = &d_correlator_outs[1]; d_Late = &d_correlator_outs[2]; - d_local_code_shift_chips.resize(d_n_correlator_taps); + d_local_code_shift_chips.reserve(d_n_correlator_taps); // Set TAPs delay values [chips] d_local_code_shift_chips[0] = -d_early_late_spc_chips; d_local_code_shift_chips[1] = 0.0; @@ -146,7 +146,7 @@ Gps_L1_Ca_Tcp_Connector_Tracking_cc::Gps_L1_Ca_Tcp_Connector_Tracking_cc( // CN0 estimation and lock detector buffers d_cn0_estimation_counter = 0; - d_Prompt_buffer.resize(FLAGS_cn0_samples); + d_Prompt_buffer.reserve(FLAGS_cn0_samples); d_carrier_lock_test = 1; d_CN0_SNV_dB_Hz = 0; d_carrier_lock_fail_counter = 0; From b4e4c849b1ffd6aa9ce5de9f30013f43ef1892dd Mon Sep 17 00:00:00 2001 From: Carles Fernandez Date: Sun, 27 Oct 2019 21:34:19 +0100 Subject: [PATCH 4/4] More usage of volk_gnsssdr::vector --- ...ileo_e1_pcps_ambiguous_acquisition_fpga.cc | 15 +++--- .../galileo_e5a_pcps_acquisition_fpga.cc | 15 +++--- .../gps_l1_ca_pcps_acquisition_fpga.cc | 15 +++--- .../gps_l2_m_pcps_acquisition_fpga.cc | 19 +++---- .../adapters/gps_l5i_pcps_acquisition_fpga.cc | 15 +++--- .../galileo_e1_dll_pll_veml_tracking_fpga.cc | 20 +++---- .../galileo_e5a_dll_pll_tracking_fpga.cc | 7 ++- .../gps_l2_m_dll_pll_tracking_fpga.cc | 10 ++-- .../adapters/gps_l5_dll_pll_tracking_fpga.cc | 25 +++------ .../tracking/libs/fpga_multicorrelator.cc | 52 ++++++------------- .../tracking/libs/fpga_multicorrelator.h | 11 ++-- 11 files changed, 74 insertions(+), 130 deletions(-) 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 92055b5ac..afcf81f92 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 @@ -38,7 +38,7 @@ #include // for fft_complex #include // for gr_complex #include // for volk_32fc_conjugate_32fc -#include +#include #include // for copy_n #include // for abs, pow, floor #include // for complex @@ -99,8 +99,8 @@ 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 = std::unique_ptr(new gr::fft::fft_complex(nsamples_total, true)); // Direct FFT - 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())); + volk_gnsssdr::vector> code(nsamples_total); // buffer for the local code + volk_gnsssdr::vector fft_codes_padded(nsamples_total); 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 @@ -138,9 +138,9 @@ GalileoE1PcpsAmbiguousAcquisitionFpga::GalileoE1PcpsAmbiguousAcquisitionFpga( code[s] = std::complex(0.0, 0.0); } - 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 + 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.data(), fft_if->get_outbuf(), nsamples_total); // conjugate values // normalize the code max = 0; // initialize maximum value @@ -182,9 +182,6 @@ GalileoE1PcpsAmbiguousAcquisitionFpga::GalileoE1PcpsAmbiguousAcquisitionFpga( doppler_step_ = 0; gnss_synchro_ = nullptr; - // temporary buffers that we can release - volk_gnsssdr_free(fft_codes_padded); - if (in_streams_ > 1) { LOG(ERROR) << "This implementation only supports one input stream"; 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 f331d5d4e..c81e3c126 100644 --- a/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.cc +++ b/src/algorithms/acquisition/adapters/galileo_e5a_pcps_acquisition_fpga.cc @@ -38,7 +38,7 @@ #include // for fft_complex #include // for gr_complex #include // for volk_32fc_conjugate_32fc -#include +#include #include // for copy_n #include // for abs, pow, floor #include // for complex @@ -100,8 +100,8 @@ 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 = std::unique_ptr(new gr::fft::fft_complex(nsamples_total, true)); // Direct FFT - 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())); + volk_gnsssdr::vector> code(nsamples_total); + volk_gnsssdr::vector> fft_codes_padded(nsamples_total); 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 @@ -142,9 +142,9 @@ GalileoE5aPcpsAcquisitionFpga::GalileoE5aPcpsAcquisitionFpga(ConfigurationInterf code[s] = std::complex(0.0, 0.0); } - 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 + 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.data(), fft_if->get_outbuf(), nsamples_total); // conjugate values max = 0; // initialize maximum value for (uint32_t i = 0; i < nsamples_total; i++) // search for maxima @@ -185,9 +185,6 @@ GalileoE5aPcpsAcquisitionFpga::GalileoE5aPcpsAcquisitionFpga(ConfigurationInterf doppler_step_ = 0; gnss_synchro_ = nullptr; - // temporary buffers that we can release - volk_gnsssdr_free(fft_codes_padded); - if (in_streams_ > 1) { LOG(ERROR) << "This implementation only supports one input stream"; 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 4530cb821..39ccdb307 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 @@ -41,7 +41,7 @@ #include #include // for gr_complex #include // for volk_32fc_conjugate_32fc -#include +#include #include // for copy_n #include // for abs, pow, floor #include // for complex @@ -93,8 +93,8 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( // a channel is assigned) auto fft_if = std::unique_ptr(new gr::fft::fft_complex(nsamples_total, true)); // allocate memory to compute all the PRNs and compute all the possible codes - 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())); + volk_gnsssdr::vector> code(nsamples_total); + volk_gnsssdr::vector> fft_codes_padded(nsamples_total); 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; @@ -117,9 +117,9 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( code[s] = std::complex(0.0, 0.0); } - 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 + 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.data(), fft_if->get_outbuf(), nsamples_total); // conjugate values max = 0; // initialize maximum value for (uint32_t i = 0; i < nsamples_total; i++) // search for maxima @@ -161,9 +161,6 @@ GpsL1CaPcpsAcquisitionFpga::GpsL1CaPcpsAcquisitionFpga( doppler_step_ = 0; gnss_synchro_ = nullptr; - // temporary buffers that we can release - volk_gnsssdr_free(fft_codes_padded); - if (in_streams_ > 1) { LOG(ERROR) << "This implementation only supports one input stream"; 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 866bbc498..0113711c2 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 @@ -41,7 +41,7 @@ #include // for fft_complex #include // for gr_complex #include // for volk_32fc_conjugate_32fc -#include +#include #include // for copy_n #include // for abs, pow, floor #include // for complex @@ -94,8 +94,8 @@ GpsL2MPcpsAcquisitionFpga::GpsL2MPcpsAcquisitionFpga( // a channel is assigned) auto fft_if = std::unique_ptr(new gr::fft::fft_complex(nsamples_total, true)); // Direct FFT // allocate memory to compute all the PRNs and compute all the possible codes - 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())); + volk_gnsssdr::vector> code(nsamples_total); + volk_gnsssdr::vector> fft_codes_padded(nsamples_total); 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 @@ -112,11 +112,11 @@ GpsL2MPcpsAcquisitionFpga::GpsL2MPcpsAcquisitionFpga( { code[s] = std::complex(0.0, 0.0); } - 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 - for (unsigned int i = 0; i < nsamples_total; i++) // search for maxima + 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.data(), fft_if->get_outbuf(), nsamples_total); // conjugate values + max = 0; // initialize maximum value + for (unsigned int i = 0; i < nsamples_total; i++) // search for maxima { if (std::abs(fft_codes_padded[i].real()) > max) { @@ -152,9 +152,6 @@ GpsL2MPcpsAcquisitionFpga::GpsL2MPcpsAcquisitionFpga( threshold_ = 0.0; - // temporary buffers that we can release - volk_gnsssdr_free(fft_codes_padded); - if (in_streams_ > 1) { LOG(ERROR) << "This implementation only supports one input stream"; 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 335ae1a66..4ec52ac37 100644 --- a/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.cc +++ b/src/algorithms/acquisition/adapters/gps_l5i_pcps_acquisition_fpga.cc @@ -41,7 +41,7 @@ #include // for fft_complex #include // for gr_complex #include // for volk_32fc_conjugate_32fc -#include +#include #include // for copy_n #include // for abs, pow, floor #include // for complex @@ -97,8 +97,8 @@ 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 = std::unique_ptr(new gr::fft::fft_complex(nsamples_total, true)); // Direct FFT - std::vector> code(nsamples_total); - auto* fft_codes_padded = static_cast(volk_gnsssdr_malloc(nsamples_total * sizeof(gr_complex), volk_gnsssdr_get_alignment())); + volk_gnsssdr::vector> code(nsamples_total); + volk_gnsssdr::vector> fft_codes_padded(nsamples_total); 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 @@ -121,9 +121,9 @@ GpsL5iPcpsAcquisitionFpga::GpsL5iPcpsAcquisitionFpga( // fill in zero padding code[s] = std::complex(0.0, 0.0); } - 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 + 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.data(), fft_if->get_outbuf(), nsamples_total); // conjugate values max = 0; // initialize maximum value for (uint32_t i = 0; i < nsamples_total; i++) // search for maxima @@ -164,9 +164,6 @@ GpsL5iPcpsAcquisitionFpga::GpsL5iPcpsAcquisitionFpga( doppler_step_ = 0; gnss_synchro_ = nullptr; - // temporary buffers that we can release - volk_gnsssdr_free(fft_codes_padded); - if (in_streams_ > 1) { LOG(ERROR) << "This implementation only supports one input stream"; diff --git a/src/algorithms/tracking/adapters/galileo_e1_dll_pll_veml_tracking_fpga.cc b/src/algorithms/tracking/adapters/galileo_e1_dll_pll_veml_tracking_fpga.cc index f296aee9d..3705c2886 100644 --- a/src/algorithms/tracking/adapters/galileo_e1_dll_pll_veml_tracking_fpga.cc +++ b/src/algorithms/tracking/adapters/galileo_e1_dll_pll_veml_tracking_fpga.cc @@ -42,7 +42,7 @@ #include "galileo_e1_signal_processing.h" #include "gnss_sdr_flags.h" #include -#include +#include #include GalileoE1DllPllVemlTrackingFpga::GalileoE1DllPllVemlTrackingFpga( @@ -193,19 +193,18 @@ GalileoE1DllPllVemlTrackingFpga::GalileoE1DllPllVemlTrackingFpga( //################# PRE-COMPUTE ALL THE CODES ################# uint32_t code_samples_per_chip = 2; d_ca_codes = static_cast(volk_gnsssdr_malloc(static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS) * code_samples_per_chip * GALILEO_E1_NUMBER_OF_CODES * sizeof(int32_t), volk_gnsssdr_get_alignment())); - float* ca_codes_f; - float* data_codes_f = nullptr; + volk_gnsssdr::vector ca_codes_f(static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS) * code_samples_per_chip); + volk_gnsssdr::vector data_codes_f; d_data_codes = nullptr; if (d_track_pilot) { d_data_codes = static_cast(volk_gnsssdr_malloc((static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS)) * code_samples_per_chip * GALILEO_E1_NUMBER_OF_CODES * sizeof(int32_t), volk_gnsssdr_get_alignment())); } - ca_codes_f = static_cast(volk_gnsssdr_malloc(static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS) * code_samples_per_chip * sizeof(float), volk_gnsssdr_get_alignment())); if (d_track_pilot) { - data_codes_f = static_cast(volk_gnsssdr_malloc((static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS)) * code_samples_per_chip * sizeof(float), volk_gnsssdr_get_alignment())); + data_codes_f.resize(static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS) * code_samples_per_chip, 0.0); } for (uint32_t PRN = 1; PRN <= GALILEO_E1_NUMBER_OF_CODES; PRN++) @@ -214,8 +213,8 @@ GalileoE1DllPllVemlTrackingFpga::GalileoE1DllPllVemlTrackingFpga( if (d_track_pilot) { std::array pilot_signal = {'1', 'C', '\0'}; - galileo_e1_code_gen_sinboc11_float(gsl::span(ca_codes_f, static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS) * code_samples_per_chip), pilot_signal, PRN); - galileo_e1_code_gen_sinboc11_float(gsl::span(data_codes_f, static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS) * code_samples_per_chip), data_signal, PRN); + galileo_e1_code_gen_sinboc11_float(ca_codes_f, pilot_signal, PRN); + galileo_e1_code_gen_sinboc11_float(data_codes_f, data_signal, PRN); // The code is generated as a series of 1s and -1s. In order to store the values using only one bit, a -1 is stored as a 0 in the FPGA for (uint32_t s = 0; s < 2 * GALILEO_E1_B_CODE_LENGTH_CHIPS; s++) @@ -238,7 +237,7 @@ GalileoE1DllPllVemlTrackingFpga::GalileoE1DllPllVemlTrackingFpga( } else { - galileo_e1_code_gen_sinboc11_float(gsl::span(ca_codes_f, static_cast(GALILEO_E1_B_CODE_LENGTH_CHIPS) * code_samples_per_chip), data_signal, PRN); + galileo_e1_code_gen_sinboc11_float(ca_codes_f, data_signal, PRN); // The code is generated as a series of 1s and -1s. In order to store the values using only one bit, a -1 is stored as a 0 in the FPGA for (uint32_t s = 0; s < 2 * GALILEO_E1_B_CODE_LENGTH_CHIPS; s++) @@ -254,11 +253,6 @@ GalileoE1DllPllVemlTrackingFpga::GalileoE1DllPllVemlTrackingFpga( } } - volk_gnsssdr_free(ca_codes_f); - if (d_track_pilot) - { - volk_gnsssdr_free(data_codes_f); - } trk_param_fpga.ca_codes = d_ca_codes; trk_param_fpga.data_codes = d_data_codes; trk_param_fpga.code_length_chips = GALILEO_E1_B_CODE_LENGTH_CHIPS; diff --git a/src/algorithms/tracking/adapters/galileo_e5a_dll_pll_tracking_fpga.cc b/src/algorithms/tracking/adapters/galileo_e5a_dll_pll_tracking_fpga.cc index c3914cf3e..4fb32b9d9 100644 --- a/src/algorithms/tracking/adapters/galileo_e5a_dll_pll_tracking_fpga.cc +++ b/src/algorithms/tracking/adapters/galileo_e5a_dll_pll_tracking_fpga.cc @@ -37,7 +37,7 @@ #include "galileo_e5_signal_processing.h" #include "gnss_sdr_flags.h" #include -#include +#include #include GalileoE5aDllPllTrackingFpga::GalileoE5aDllPllTrackingFpga( @@ -193,7 +193,7 @@ GalileoE5aDllPllTrackingFpga::GalileoE5aDllPllTrackingFpga( uint32_t code_samples_per_chip = 1; auto code_length_chips = static_cast(GALILEO_E5A_CODE_LENGTH_CHIPS); - auto *aux_code = static_cast(volk_gnsssdr_malloc(sizeof(gr_complex) * code_length_chips * code_samples_per_chip, volk_gnsssdr_get_alignment())); + volk_gnsssdr::vector aux_code(code_length_chips * code_samples_per_chip, gr_complex(0.0, 0.0)); d_ca_codes = static_cast(volk_gnsssdr_malloc(static_cast(code_length_chips) * code_samples_per_chip * GALILEO_E5A_NUMBER_OF_CODES * sizeof(int32_t), volk_gnsssdr_get_alignment())); @@ -205,7 +205,7 @@ GalileoE5aDllPllTrackingFpga::GalileoE5aDllPllTrackingFpga( for (uint32_t PRN = 1; PRN <= GALILEO_E5A_NUMBER_OF_CODES; PRN++) { std::array sig_a = {'5', 'X', '\0'}; - galileo_e5_a_code_gen_complex_primary(gsl::span(aux_code, code_length_chips * code_samples_per_chip), PRN, sig_a); + galileo_e5_a_code_gen_complex_primary(aux_code, PRN, sig_a); if (trk_param_fpga.track_pilot) { @@ -245,7 +245,6 @@ GalileoE5aDllPllTrackingFpga::GalileoE5aDllPllTrackingFpga( } } - volk_gnsssdr_free(aux_code); trk_param_fpga.ca_codes = d_ca_codes; trk_param_fpga.data_codes = d_data_codes; trk_param_fpga.code_length_chips = code_length_chips; diff --git a/src/algorithms/tracking/adapters/gps_l2_m_dll_pll_tracking_fpga.cc b/src/algorithms/tracking/adapters/gps_l2_m_dll_pll_tracking_fpga.cc index d2e024a30..4b9ade868 100644 --- a/src/algorithms/tracking/adapters/gps_l2_m_dll_pll_tracking_fpga.cc +++ b/src/algorithms/tracking/adapters/gps_l2_m_dll_pll_tracking_fpga.cc @@ -44,7 +44,7 @@ #include "gnss_synchro.h" #include "gps_l2c_signal.h" #include -#include +#include #include #include // for round #include // for memcpy @@ -123,22 +123,18 @@ GpsL2MDllPllTrackingFpga::GpsL2MDllPllTrackingFpga( // GNSS-SDR instantiates the tracking channels i L1, L2, L5, E1, E5a trk_param_fpga.num_prev_assigned_ch = configuration->property("Channels_1C.count", 0); - - auto* ca_codes_f = static_cast(volk_gnsssdr_malloc(static_cast(GPS_L2_M_CODE_LENGTH_CHIPS) * sizeof(float), volk_gnsssdr_get_alignment())); - + volk_gnsssdr::vector ca_codes_f(static_cast(GPS_L2_M_CODE_LENGTH_CHIPS), 0.0); // ################# PRE-COMPUTE ALL THE CODES ################# d_ca_codes = static_cast(volk_gnsssdr_malloc(static_cast(GPS_L2_M_CODE_LENGTH_CHIPS * NUM_PRNs) * sizeof(int), volk_gnsssdr_get_alignment())); for (uint32_t PRN = 1; PRN <= NUM_PRNs; PRN++) { - gps_l2c_m_code_gen_float(gsl::span(ca_codes_f, static_cast(GPS_L2_M_CODE_LENGTH_CHIPS)), PRN); + gps_l2c_m_code_gen_float(ca_codes_f, PRN); for (unsigned int s = 0; s < 2 * static_cast(GPS_L2_M_CODE_LENGTH_CHIPS); s++) { d_ca_codes[static_cast(GPS_L2_M_CODE_LENGTH_CHIPS) * (PRN - 1) + s] = static_cast(ca_codes_f[s]); } } - volk_gnsssdr_free(ca_codes_f); - trk_param_fpga.ca_codes = d_ca_codes; trk_param_fpga.code_length_chips = GPS_L2_M_CODE_LENGTH_CHIPS; trk_param_fpga.code_samples_per_chip = 1; // 1 sample per chip diff --git a/src/algorithms/tracking/adapters/gps_l5_dll_pll_tracking_fpga.cc b/src/algorithms/tracking/adapters/gps_l5_dll_pll_tracking_fpga.cc index 98d8ef03a..5c949defe 100644 --- a/src/algorithms/tracking/adapters/gps_l5_dll_pll_tracking_fpga.cc +++ b/src/algorithms/tracking/adapters/gps_l5_dll_pll_tracking_fpga.cc @@ -44,7 +44,7 @@ #include "gnss_sdr_flags.h" #include "gps_l5_signal.h" #include -#include +#include #include GpsL5DllPllTrackingFpga::GpsL5DllPllTrackingFpga( @@ -193,18 +193,12 @@ GpsL5DllPllTrackingFpga::GpsL5DllPllTrackingFpga( uint32_t code_samples_per_chip = 1; auto code_length_chips = static_cast(GPS_L5I_CODE_LENGTH_CHIPS); - float *tracking_code; - float *data_code = nullptr; - - tracking_code = static_cast(volk_gnsssdr_malloc(code_length_chips * sizeof(float), volk_gnsssdr_get_alignment())); + volk_gnsssdr::vector data_code; + volk_gnsssdr::vector tracking_code(code_length_chips, 0.0); if (track_pilot) { - data_code = static_cast(volk_gnsssdr_malloc(code_length_chips * sizeof(float), volk_gnsssdr_get_alignment())); - for (uint32_t i = 0; i < code_length_chips; i++) - { - data_code[i] = 0.0; - } + data_code.resize(code_length_chips, 0.0); } d_ca_codes = static_cast(volk_gnsssdr_malloc(static_cast(code_length_chips * NUM_PRNs) * sizeof(int32_t), volk_gnsssdr_get_alignment())); @@ -219,8 +213,8 @@ GpsL5DllPllTrackingFpga::GpsL5DllPllTrackingFpga( { if (track_pilot) { - gps_l5q_code_gen_float(gsl::span(tracking_code, code_length_chips), PRN); - gps_l5i_code_gen_float(gsl::span(data_code, code_length_chips), PRN); + gps_l5q_code_gen_float(tracking_code, PRN); + gps_l5i_code_gen_float(data_code, PRN); // The code is generated as a series of 1s and -1s. In order to store the values using only one bit, a -1 is stored as a 0 in the FPGA for (uint32_t s = 0; s < code_length_chips; s++) @@ -244,7 +238,7 @@ GpsL5DllPllTrackingFpga::GpsL5DllPllTrackingFpga( } else { - gps_l5i_code_gen_float(gsl::span(tracking_code, code_length_chips), PRN); + gps_l5i_code_gen_float(tracking_code, PRN); // The code is generated as a series of 1s and -1s. In order to store the values using only one bit, a -1 is stored as a 0 in the FPGA for (uint32_t s = 0; s < code_length_chips; s++) @@ -260,11 +254,6 @@ GpsL5DllPllTrackingFpga::GpsL5DllPllTrackingFpga( } } - volk_gnsssdr_free(tracking_code); - if (track_pilot) - { - volk_gnsssdr_free(data_code); - } trk_param_fpga.ca_codes = d_ca_codes; trk_param_fpga.data_codes = d_data_codes; trk_param_fpga.code_length_chips = code_length_chips; diff --git a/src/algorithms/tracking/libs/fpga_multicorrelator.cc b/src/algorithms/tracking/libs/fpga_multicorrelator.cc index 9567f12bd..2d92edada 100644 --- a/src/algorithms/tracking/libs/fpga_multicorrelator.cc +++ b/src/algorithms/tracking/libs/fpga_multicorrelator.cc @@ -61,9 +61,14 @@ const float PHASE_CARR_MAX_DIV_PI = 683565275.5764316; // 2^(31)/pi const float TWO_PI = 6.283185307179586; Fpga_Multicorrelator_8sc::Fpga_Multicorrelator_8sc(int32_t n_correlators, - const std::string &device_name, uint32_t dev_file_num, uint32_t num_prev_assigned_ch, int32_t *ca_codes, int32_t *data_codes, uint32_t code_length_chips, bool track_pilot, + const std::string &device_name, + uint32_t dev_file_num, + uint32_t num_prev_assigned_ch, + int32_t *ca_codes, + int32_t *data_codes, + uint32_t code_length_chips, + bool track_pilot, uint32_t code_samples_per_chip) - { d_n_correlators = n_correlators; d_device_name = device_name; @@ -77,17 +82,13 @@ Fpga_Multicorrelator_8sc::Fpga_Multicorrelator_8sc(int32_t n_correlators, // instantiate variable length vectors if (d_track_pilot) { - d_initial_index = static_cast(volk_gnsssdr_malloc( - (n_correlators + 1) * sizeof(uint32_t), volk_gnsssdr_get_alignment())); - d_initial_interp_counter = static_cast(volk_gnsssdr_malloc( - (n_correlators + 1) * sizeof(uint32_t), volk_gnsssdr_get_alignment())); + d_initial_index.reserve(n_correlators + 1); + d_initial_interp_counter.reserve(n_correlators + 1); } else { - d_initial_index = static_cast(volk_gnsssdr_malloc( - n_correlators * sizeof(uint32_t), volk_gnsssdr_get_alignment())); - d_initial_interp_counter = static_cast(volk_gnsssdr_malloc( - n_correlators * sizeof(uint32_t), volk_gnsssdr_get_alignment())); + d_initial_index.reserve(n_correlators); + d_initial_interp_counter.reserve(n_correlators); } d_shifts_chips = nullptr; d_prompt_data_shift = nullptr; @@ -109,8 +110,6 @@ Fpga_Multicorrelator_8sc::Fpga_Multicorrelator_8sc(int32_t n_correlators, d_data_codes = data_codes; d_code_samples_per_chip = code_samples_per_chip; d_code_length_samples = d_code_length_chips * d_code_samples_per_chip; - - d_secondary_code_enabled = false; DLOG(INFO) << "TRACKING FPGA CLASS CREATED"; @@ -120,14 +119,6 @@ Fpga_Multicorrelator_8sc::Fpga_Multicorrelator_8sc(int32_t n_correlators, Fpga_Multicorrelator_8sc::~Fpga_Multicorrelator_8sc() { close_device(); - if (d_initial_index != nullptr) - { - volk_gnsssdr_free(d_initial_index); - } - if (d_initial_interp_counter != nullptr) - { - volk_gnsssdr_free(d_initial_interp_counter); - } } @@ -219,20 +210,6 @@ bool Fpga_Multicorrelator_8sc::free() { // unlock the channel Fpga_Multicorrelator_8sc::unlock_channel(); - - // free the FPGA dynamically created variables - if (d_initial_index != nullptr) - { - volk_gnsssdr_free(d_initial_index); - d_initial_index = nullptr; - } - - if (d_initial_interp_counter != nullptr) - { - volk_gnsssdr_free(d_initial_interp_counter); - d_initial_interp_counter = nullptr; - } - return true; } @@ -305,7 +282,6 @@ uint32_t Fpga_Multicorrelator_8sc::fpga_acquisition_test_register( void Fpga_Multicorrelator_8sc::fpga_configure_tracking_gps_local_code(int32_t PRN) { uint32_t k; - d_map_base[prog_mems_addr] = local_code_fpga_clear_address_counter; for (k = 0; k < d_code_length_samples; k++) { @@ -339,7 +315,6 @@ void Fpga_Multicorrelator_8sc::fpga_compute_code_shift_parameters() } d_initial_index[i] = dec_part; - frac_part = fmod(d_shifts_chips[i] - d_rem_code_phase_chips, 1.0); if (frac_part < 0) { @@ -464,7 +439,6 @@ void Fpga_Multicorrelator_8sc::unlock_channel() // unlock the channel to let the next samples go through d_map_base[drop_samples_reg_addr] = drop_samples; // unlock the channel and disable secondary codes d_map_base[stop_tracking_reg_addr] = 1; // set the tracking module back to idle - d_secondary_code_enabled = false; } @@ -498,12 +472,14 @@ void Fpga_Multicorrelator_8sc::set_secondary_code_lengths(uint32_t secondary_cod d_map_base[secondary_code_lengths_reg_addr] = secondary_code_length_1_minus_1 * 256 + secondary_code_length_0_minus_1; } + void Fpga_Multicorrelator_8sc::update_prn_code_length(uint32_t first_prn_length, uint32_t next_prn_length) { d_map_base[first_prn_length_minus_1_reg_addr] = first_prn_length - 1; d_map_base[next_prn_length_minus_1_reg_addr] = next_prn_length - 1; } + void Fpga_Multicorrelator_8sc::initialize_secondary_code(uint32_t secondary_code, std::string *secondary_code_string) { uint32_t secondary_code_length; @@ -566,12 +542,14 @@ void Fpga_Multicorrelator_8sc::write_secondary_code(uint32_t secondary_code_leng d_map_base[reg_addr] = write_val; } + void Fpga_Multicorrelator_8sc::enable_secondary_codes() { d_map_base[drop_samples_reg_addr] = init_secondary_code_addresses | enable_secondary_code; // enable secondary codes and clear secondary code indices d_secondary_code_enabled = true; } + void Fpga_Multicorrelator_8sc::disable_secondary_codes() { // this function is to be called before starting the tracking process in order to disable the secondary codes by default diff --git a/src/algorithms/tracking/libs/fpga_multicorrelator.h b/src/algorithms/tracking/libs/fpga_multicorrelator.h index af3f13e4e..dc0ebd7bc 100644 --- a/src/algorithms/tracking/libs/fpga_multicorrelator.h +++ b/src/algorithms/tracking/libs/fpga_multicorrelator.h @@ -38,6 +38,7 @@ #define GNSS_SDR_FPGA_MULTICORRELATOR_H_ #include +#include #include #include @@ -86,9 +87,11 @@ public: * \brief Perform a multicorrelation */ void Carrier_wipeoff_multicorrelator_resampler( - float rem_carrier_phase_in_rad, float phase_step_rad, + float rem_carrier_phase_in_rad, + float phase_step_rad, float carrier_phase_rate_step_rad, - float rem_code_phase_chips, float code_phase_step_chips, + float rem_code_phase_chips, + float code_phase_step_chips, float code_phase_rate_step_chips, int32_t signal_length_samples); @@ -226,8 +229,8 @@ private: bool d_track_pilot; // configuration data computed in the format that the FPGA expects - uint32_t *d_initial_index; - uint32_t *d_initial_interp_counter; + volk_gnsssdr::vector d_initial_index; + volk_gnsssdr::vector d_initial_interp_counter; uint32_t d_code_phase_step_chips_num; uint32_t d_code_phase_rate_step_chips_num; int32_t d_rem_carr_phase_rad_int;