diff --git a/src/algorithms/tracking/adapters/CMakeLists.txt b/src/algorithms/tracking/adapters/CMakeLists.txt
index c1d680861..e57529c96 100644
--- a/src/algorithms/tracking/adapters/CMakeLists.txt
+++ b/src/algorithms/tracking/adapters/CMakeLists.txt
@@ -33,6 +33,7 @@ set(TRACKING_ADAPTER_SOURCES
galileo_e5a_dll_pll_tracking.cc
gps_l2_m_dll_pll_tracking.cc
galileo_e1_de_tracking.cc
+ galileo_e1_prs_de_tracking.cc
${OPT_TRACKING_ADAPTERS}
)
diff --git a/src/algorithms/tracking/adapters/galileo_e1_prs_de_tracking.cc b/src/algorithms/tracking/adapters/galileo_e1_prs_de_tracking.cc
new file mode 100644
index 000000000..43be26652
--- /dev/null
+++ b/src/algorithms/tracking/adapters/galileo_e1_prs_de_tracking.cc
@@ -0,0 +1,191 @@
+/*!
+ * \file galileo_e1_prs_de_tracking.h
+ * \brief Adapts a double estimator tracking loop block
+ * to a TrackingInterface for Galileo E1 signals including PRS
+ * \author Cillian O'Driscoll, 2015. cillian.odriscoll(at)gmail.com
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ * Satellite Systems receiver
+ *
+ * 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 .
+ *
+ * -------------------------------------------------------------------------
+ */
+
+#include "galileo_e1_prs_de_tracking.h"
+#include
+#include "GPS_L1_CA.h"
+#include "Galileo_E1.h"
+#include "configuration_interface.h"
+#include "spirent_prs_code_generator.h"
+
+
+using google::LogMessage;
+
+GalileoE1PrsDeTracking::GalileoE1PrsDeTracking(
+ ConfigurationInterface* configuration, std::string role,
+ unsigned int in_streams, unsigned int out_streams,
+ boost::shared_ptr queue) :
+ role_(role), in_streams_(in_streams), out_streams_(out_streams),
+ queue_(queue)
+{
+ DLOG(INFO) << "role " << role;
+ //################# CONFIGURATION PARAMETERS ########################
+ int fs_in;
+ int vector_length;
+ int f_if;
+ bool dump;
+ std::string dump_filename;
+ std::string item_type;
+ std::string default_item_type = "gr_complex";
+ float pll_bw_hz;
+ float dll_bw_hz;
+ float sll_bw_hz;
+ float early_late_code_space_chips;
+ float early_late_subcarrier_space_chips;
+ bool aid_subcarrier_with_carrier;
+ bool aid_code_with_subcarrier;
+
+ item_type = configuration->property(role + ".item_type", default_item_type);
+ fs_in = configuration->property("GNSS-SDR.internal_fs_hz", 2048000);
+ f_if = configuration->property(role + ".if", 0);
+ dump = configuration->property(role + ".dump", false);
+ pll_bw_hz = configuration->property(role + ".pll_bw_hz", 15.0);
+ sll_bw_hz = configuration->property(role + ".sll_bw_hz", 2.0);
+ dll_bw_hz = configuration->property(role + ".dll_bw_hz", 0.5);
+ early_late_code_space_chips = configuration->property(role + ".early_late_code_space_chips", 0.5);
+ early_late_subcarrier_space_chips = configuration->property(role + ".early_late_subcarrier_space_cycles", 0.125);
+ aid_subcarrier_with_carrier = configuration->property(role + ".aid_subcarrier_with_carrier", false );
+ aid_code_with_subcarrier = configuration->property(role + ".aid_code_with_subcarrier", false );
+
+ std::string default_code_type = "Spirent";
+ std::string code_type = configuration->property(role + ".prs_code_type", default_code_type );
+
+ std::string default_dump_filename = "./track_de_";
+ dump_filename = configuration->property(role + ".dump_filename",
+ default_dump_filename); //unused!
+ vector_length = std::round(fs_in / (Galileo_E1_CODE_CHIP_RATE_HZ / Galileo_E1_B_CODE_LENGTH_CHIPS));
+
+ boost::shared_ptr< LongCodeInterface > code_gen;
+
+ if( not code_type.compare("Spirent") )// anything other than zero means not a match
+ {
+ code_gen = boost::shared_ptr< LongCodeInterface >(
+ new SpirentPrsCodeGenerator( 1, true ) );
+
+ if( code_gen == 0 )
+ {
+ LOG(ERROR) << "Unable to create a SpirentPrsCodeGenerator";
+ }
+ }
+ else
+ {
+ LOG(ERROR) << code_type << " unknown PRS code type";
+ }
+
+ //################# MAKE TRACKING GNURadio object ###################
+ if (item_type.compare("gr_complex") == 0)
+ {
+ item_size_ = sizeof(gr_complex);
+ tracking_ = galileo_e1_prs_de_make_tracking_cc(
+ f_if,
+ fs_in,
+ vector_length,
+ queue_,
+ dump,
+ dump_filename,
+ pll_bw_hz,
+ dll_bw_hz,
+ sll_bw_hz,
+ early_late_code_space_chips,
+ early_late_subcarrier_space_chips,
+ aid_subcarrier_with_carrier,
+ aid_code_with_subcarrier,
+ code_gen);
+ }
+ else
+ {
+ item_size_ = sizeof(gr_complex);
+ LOG(WARNING) << item_type << " unknown tracking item type.";
+ }
+
+ channel_ = 0;
+ channel_internal_queue_ = 0;
+
+ DLOG(INFO) << "tracking(" << tracking_->unique_id() << ")";
+}
+
+GalileoE1PrsDeTracking::~GalileoE1PrsDeTracking()
+{}
+
+void GalileoE1PrsDeTracking::start_tracking()
+{
+ tracking_->start_tracking();
+}
+
+/*
+ * Set tracking channel unique ID
+ */
+void GalileoE1PrsDeTracking::set_channel(unsigned int channel)
+{
+ channel_ = channel;
+ tracking_->set_channel(channel);
+}
+
+/*
+ * Set tracking channel internal queue
+ */
+void GalileoE1PrsDeTracking::set_channel_queue(
+ concurrent_queue *channel_internal_queue)
+{
+ channel_internal_queue_ = channel_internal_queue;
+
+ tracking_->set_channel_queue(channel_internal_queue_);
+
+}
+
+void GalileoE1PrsDeTracking::set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
+{
+ tracking_->set_gnss_synchro(p_gnss_synchro);
+}
+
+void GalileoE1PrsDeTracking::connect(gr::top_block_sptr top_block)
+{
+ if(top_block) { /* top_block is not null */};
+ //nothing to connect, now the tracking uses gr_sync_decimator
+}
+
+void GalileoE1PrsDeTracking::disconnect(gr::top_block_sptr top_block)
+{
+ if(top_block) { /* top_block is not null */};
+ //nothing to disconnect, now the tracking uses gr_sync_decimator
+}
+
+gr::basic_block_sptr GalileoE1PrsDeTracking::get_left_block()
+{
+ return tracking_;
+}
+
+gr::basic_block_sptr GalileoE1PrsDeTracking::get_right_block()
+{
+ return tracking_;
+}
+
+
diff --git a/src/algorithms/tracking/adapters/galileo_e1_prs_de_tracking.h b/src/algorithms/tracking/adapters/galileo_e1_prs_de_tracking.h
new file mode 100644
index 000000000..e5f197b4d
--- /dev/null
+++ b/src/algorithms/tracking/adapters/galileo_e1_prs_de_tracking.h
@@ -0,0 +1,116 @@
+/*!
+ * \file galileo_e1_prs_de_tracking.h
+ * \brief Adapts a double estimator tracking loop block
+ * to a TrackingInterface for Galileo E1 signals inclding PRS
+ * \author Cillian O'Driscoll, 2015. cillian.odriscoll(at)gmail.com
+ *
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ * Satellite Systems receiver
+ *
+ * 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 GNSS_SDR_GALILEO_E1_PRS_DE_TRACKING_H_
+#define GNSS_SDR_GALILEO_E1_PRS_DE_TRACKING_H_
+
+#include
+#include
+#include "tracking_interface.h"
+#include "galileo_e1_prs_de_tracking_cc.h"
+
+
+class ConfigurationInterface;
+
+/*!
+ * \brief This class Adapts a DLL+PLL VEML (Very Early Minus Late) tracking
+ * loop block to a TrackingInterface for Galileo E1 signals
+ */
+class GalileoE1PrsDeTracking : public TrackingInterface
+{
+
+public:
+
+ GalileoE1PrsDeTracking(ConfigurationInterface* configuration,
+ std::string role,
+ unsigned int in_streams,
+ unsigned int out_streams,
+ boost::shared_ptr queue);
+
+ virtual ~GalileoE1PrsDeTracking();
+
+ std::string role()
+ {
+ return role_;
+ }
+
+ //! Returns "Galileo_E1_DE_Tracking"
+ std::string implementation()
+ {
+ return "Galileo_E1_PRS_DE_Tracking";
+ }
+ size_t item_size()
+ {
+ return item_size_;
+ }
+
+ void connect(gr::top_block_sptr top_block);
+ void disconnect(gr::top_block_sptr top_block);
+ gr::basic_block_sptr get_left_block();
+ gr::basic_block_sptr get_right_block();
+
+
+ /*!
+ * \brief Set tracking channel unique ID
+ */
+ void set_channel(unsigned int channel);
+
+ /*!
+ * \brief Set acquisition/tracking common Gnss_Synchro object pointer
+ * to efficiently exchange synchronization data between acquisition and
+ * tracking blocks
+ */
+ void set_gnss_synchro(Gnss_Synchro* p_gnss_synchro);
+
+ /*!
+ * \brief Set tracking channel internal queue
+ */
+ void set_channel_queue(concurrent_queue *channel_internal_queue);
+
+ void start_tracking();
+
+private:
+
+ galileo_e1_prs_de_tracking_cc_sptr tracking_;
+ size_t item_size_;
+
+ unsigned int channel_;
+
+ std::string role_;
+ unsigned int in_streams_;
+ unsigned int out_streams_;
+ boost::shared_ptr queue_;
+ concurrent_queue *channel_internal_queue_;
+};
+
+#endif // GNSS_SDR_GALILEO_E1_PRS_DE_TRACKING_H_
+
diff --git a/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt b/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt
index 38449252d..d000909c5 100644
--- a/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt
+++ b/src/algorithms/tracking/gnuradio_blocks/CMakeLists.txt
@@ -35,7 +35,8 @@ set(TRACKING_GR_BLOCKS_SOURCES
gps_l2_m_dll_pll_tracking_cc.cc
gps_l1_ca_dll_pll_c_aid_tracking_cc.cc
galileo_e1_de_tracking_cc.cc
- ${OPT_TRACKING_BLOCKS}
+ galileo_e1_prs_de_tracking_cc.cc
+ ${OPT_TRACKING_BLOCKS}
)
include_directories(
diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_prs_de_tracking_cc.cc b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_prs_de_tracking_cc.cc
new file mode 100644
index 000000000..1af8e49fe
--- /dev/null
+++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_prs_de_tracking_cc.cc
@@ -0,0 +1,1230 @@
+/*!
+ * \file galileo_e1_prs_de_tracking_cc.cc
+ * \brief Implementation of a code DLL + carrier PLL VEML (Very Early
+ * Minus Late) tracking block for Galileo E1 signals
+ * \author Luis Esteve, 2012. luis(at)epsilon-formacion.com
+ *
+ * Code DLL + carrier PLL according to the algorithms described in:
+ * [1] K.Borre, D.M.Akos, N.Bertelsen, P.Rinder, and S.H.Jensen,
+ * A Software-Defined GPS and Galileo Receiver. A Single-Frequency
+ * Approach, Birkhauser, 2007
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ * Satellite Systems receiver
+ *
+ * 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 .
+ *
+ * -------------------------------------------------------------------------
+ */
+
+#include "galileo_e1_prs_de_tracking_cc.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include // fixed point sine and cosine
+#include
+#include "gnss_synchro.h"
+#include "galileo_e1_signal_processing.h"
+#include "tracking_discriminators.h"
+#include "lock_detectors.h"
+#include "Galileo_E1.h"
+#include "control_message_factory.h"
+#include "fxpt64.h"
+
+
+
+/*!
+ * \todo Include in definition header file
+ */
+#define CN0_ESTIMATION_SAMPLES 20
+#define MINIMUM_VALID_CN0 25
+#define MAXIMUM_LOCK_FAIL_COUNTER 50
+#define CARRIER_LOCK_THRESHOLD 0.85
+
+
+using google::LogMessage;
+
+galileo_e1_prs_de_tracking_cc_sptr
+galileo_e1_prs_de_make_tracking_cc(
+ long if_freq,
+ long fs_in,
+ unsigned int vector_length,
+ boost::shared_ptr queue,
+ bool dump,
+ std::string dump_filename,
+ float pll_bw_hz,
+ float dll_bw_hz,
+ float sll_bw_hz,
+ float early_late_code_space_chips,
+ float early_late_subcarrier_space_cycles,
+ bool aid_subcarrier_with_carrier,
+ bool aid_code_with_subcarrier,
+ LongCodeInterface_sptr prs_code_gen)
+{
+ return galileo_e1_prs_de_tracking_cc_sptr(new galileo_e1_prs_de_tracking_cc(if_freq,
+ fs_in, vector_length, queue, dump, dump_filename, pll_bw_hz, dll_bw_hz,
+ sll_bw_hz, early_late_code_space_chips, early_late_subcarrier_space_cycles,
+ aid_subcarrier_with_carrier, aid_code_with_subcarrier, prs_code_gen));
+}
+
+
+void galileo_e1_prs_de_tracking_cc::forecast (int noutput_items,
+ gr_vector_int &ninput_items_required)
+{
+ ninput_items_required[0] = static_cast(d_vector_length) * 2; //set the required available samples in each call
+}
+
+
+galileo_e1_prs_de_tracking_cc::galileo_e1_prs_de_tracking_cc(
+ long if_freq,
+ long fs_in,
+ unsigned int vector_length,
+ boost::shared_ptr queue,
+ bool dump,
+ std::string dump_filename,
+ float pll_bw_hz,
+ float dll_bw_hz,
+ float sll_bw_hz,
+ float early_late_code_space_chips,
+ float early_late_subcarrier_space_cycles,
+ bool aid_subcarrier_with_carrier,
+ bool aid_code_with_subcarrier,
+ LongCodeInterface_sptr prs_code_gen):
+ gr::block("galileo_e1_prs_de_tracking_cc", gr::io_signature::make(1, 1, sizeof(gr_complex)),
+ gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)))
+{
+ // Create the gnss_message input port
+ message_port_register_in( GNSS_MESSAGE_PORT_ID );
+ set_msg_handler( GNSS_MESSAGE_PORT_ID,
+ boost::bind( &galileo_e1_prs_de_tracking_cc::handle_gnss_message, this, _1 ) );
+
+ d_prs_code_gen = prs_code_gen;
+
+ this->set_relative_rate(1.0/vector_length);
+ // initialize internal vars
+ d_queue = queue;
+ d_dump = dump;
+ d_if_freq = if_freq;
+ d_fs_in = fs_in;
+ d_vector_length = vector_length;
+ d_dump_filename = dump_filename;
+ d_code_loop_filter = Tracking_loop_filter(Galileo_E1_CODE_PERIOD, dll_bw_hz, 1, false);
+ d_subcarrier_loop_filter = Tracking_loop_filter(Galileo_E1_CODE_PERIOD, sll_bw_hz, 1, false);
+ d_carrier_loop_filter = Tracking_loop_filter(Galileo_E1_CODE_PERIOD, pll_bw_hz, 3, false);
+ d_aid_subcarrier_with_carrier = aid_subcarrier_with_carrier;
+ d_aid_code_with_subcarrier = aid_code_with_subcarrier;
+
+ // Initialize tracking ==========================================
+
+
+ // Correlator spacing
+ d_early_late_code_spc_chips = early_late_code_space_chips; // Define early-late offset (in chips)
+ d_early_late_subcarrier_spc_cycles = early_late_subcarrier_space_cycles; // Define very-early-late offset (in chips)
+
+ // Initialization of local code replica
+ // Get space for a vector with the code replica sampled 1x/chip
+ d_e1b_code = static_cast(volk_malloc((Galileo_E1_B_CODE_LENGTH_CHIPS + 2) * sizeof(gr_complex), volk_get_alignment()));
+
+ // for the prs:
+ // Store about 400 ms worth of chips:
+ d_size_prs_code = static_cast< unsigned int>( std::ceil( 0.4 * Galileo_E1_A_CODE_CHIP_RATE_HZ ) );
+ d_prs_code = static_cast< gr_complex*>(volk_malloc( d_size_prs_code*sizeof( gr_complex ), volk_get_alignment() ) );
+ d_start_index_prs_code = 0;
+
+ d_early_code= static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_prompt_code = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_late_code = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_early_subcarrier = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_prompt_subcarrier = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_late_subcarrier = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_carr_sign = static_cast(volk_malloc(2*d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+
+ d_early_code_prs= static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_prompt_code_prs = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_late_code_prs = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_early_subcarrier_prs = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_prompt_subcarrier_prs = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_late_subcarrier_prs = static_cast(volk_malloc(2 * d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+ d_carr_sign = static_cast(volk_malloc(2*d_vector_length * sizeof(gr_complex), volk_get_alignment()));
+
+ // correlator outputs (scalar)
+ d_Prompt_Subcarrier_Early_Code = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Subcarrier_Prompt_Code = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Subcarrier_Late_Code = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Code_Early_Subcarrier = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Code_Late_Subcarrier = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+
+ // correlator outputs (scalar)
+ d_Prompt_Subcarrier_Early_Code_prs = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Subcarrier_Prompt_Code_prs = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Subcarrier_Late_Code_prs = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Code_Early_Subcarrier_prs = static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+ d_Prompt_Code_Late_Subcarrier_prs= static_cast(volk_malloc(sizeof(gr_complex), volk_get_alignment()));
+
+ //--- Initializations ------------------------------
+ // Initial code frequency basis of NCO
+ d_code_freq_chips = static_cast(Galileo_E1_CODE_CHIP_RATE_HZ);
+ d_subcarrier_freq_cycles = static_cast(Galileo_E1_CODE_CHIP_RATE_HZ);
+
+ d_code_freq_chips_prs = static_cast(Galileo_E1_A_CODE_CHIP_RATE_HZ);
+ d_subcarrier_freq_cycles_prs = static_cast(Galileo_E1_A_SUB_CARRIER_RATE_HZ);
+ // Residual code phase (in chips)
+ d_rem_code_phase_samples = 0.0;
+ d_rem_subcarrier_phase_samples = 0.0;
+ d_code_phase_chips = 0.0;
+ d_subcarrier_phase_halfcycles = 0.0;
+
+ d_rem_code_phase_samples_prs = 0.0;
+ d_rem_subcarrier_phase_samples_prs = 0.0;
+ d_code_phase_chips_prs = 0.0;
+ d_subcarrier_phase_halfcycles_prs = 0.0;
+
+ // Residual carrier phase
+ d_rem_carr_phase_rad = 0.0;
+ d_rem_carr_phase_rad_prs = 0.0;
+
+ // sample synchronization
+ d_sample_counter = 0;
+ //d_sample_counter_seconds = 0;
+ d_acq_sample_stamp = 0;
+
+ d_enable_tracking = false;
+ d_pull_in = false;
+ d_last_seg = 0;
+ d_prs_tracking_enabled = false;
+ d_prs_code_initialized = false;
+
+ d_current_prn_length_samples = static_cast(d_vector_length);
+
+ // CN0 estimation and lock detector buffers
+ d_cn0_estimation_counter = 0;
+ d_Prompt_buffer = new gr_complex[CN0_ESTIMATION_SAMPLES];
+ d_carrier_lock_test = 1;
+ d_CN0_SNV_dB_Hz = 0;
+ d_carrier_lock_fail_counter = 0;
+ d_carrier_lock_threshold = CARRIER_LOCK_THRESHOLD;
+
+ systemName["E"] = std::string("Galileo");
+ *d_Prompt_Subcarrier_Early_Code = gr_complex(0,0);
+ *d_Prompt_Subcarrier_Prompt_Code = gr_complex(0,0);
+ *d_Prompt_Subcarrier_Late_Code = gr_complex(0,0);
+ *d_Prompt_Code_Early_Subcarrier = gr_complex(0,0);
+ *d_Prompt_Code_Late_Subcarrier = gr_complex(0,0);
+
+ *d_Prompt_Subcarrier_Early_Code_prs = gr_complex(0,0);
+ *d_Prompt_Subcarrier_Prompt_Code_prs = gr_complex(0,0);
+ *d_Prompt_Subcarrier_Late_Code_prs = gr_complex(0,0);
+ *d_Prompt_Code_Early_Subcarrier_prs = gr_complex(0,0);
+ *d_Prompt_Code_Late_Subcarrier_prs = gr_complex(0,0);
+
+ d_channel_internal_queue = 0;
+ d_acquisition_gnss_synchro = 0;
+ d_channel = 0;
+ d_acq_code_phase_samples = 0.0;
+ d_acq_carrier_doppler_hz = 0.0;
+ d_carrier_doppler_hz = 0.0;
+ d_acc_carrier_phase_rad = 0.0;
+ d_acc_code_phase_secs = 0.0;
+}
+
+void galileo_e1_prs_de_tracking_cc::start_tracking()
+{
+ d_acq_code_phase_samples = d_acquisition_gnss_synchro->Acq_delay_samples;
+ d_acq_carrier_doppler_hz = d_acquisition_gnss_synchro->Acq_doppler_hz;
+ d_acq_sample_stamp = d_acquisition_gnss_synchro->Acq_samplestamp_samples;
+
+ // DLL/PLL filter initialization
+ d_carrier_loop_filter.initialize(d_acq_carrier_doppler_hz); // initialize the carrier filter
+ float code_doppler_chips = d_acq_carrier_doppler_hz *( Galileo_E1_CODE_CHIP_RATE_HZ) / Galileo_E1_FREQ_HZ;
+
+ float init_freq = ( d_aid_subcarrier_with_carrier ? 0.0 : code_doppler_chips );
+ d_subcarrier_loop_filter.initialize(init_freq); // initialize the carrier filter
+ init_freq = ( d_aid_code_with_subcarrier ? 0.0 : code_doppler_chips );
+ d_code_loop_filter.initialize(init_freq); // initialize the code filter
+
+ // generate local reference ALWAYS starting at chip 1 (1 samples per chip)
+ galileo_e1_prn_gen_complex_sampled(&d_e1b_code[1],
+ d_acquisition_gnss_synchro->Signal,
+ d_acquisition_gnss_synchro->PRN,
+ Galileo_E1_CODE_CHIP_RATE_HZ,
+ 0);
+ // Fill head and tail
+ d_e1b_code[0] = d_e1b_code[static_cast(Galileo_E1_B_CODE_LENGTH_CHIPS+1)];
+ d_e1b_code[static_cast(Galileo_E1_B_CODE_LENGTH_CHIPS + 2)] = d_e1b_code[1];
+
+ d_carrier_lock_fail_counter = 0;
+ d_rem_code_phase_samples = 0.0;
+ d_rem_subcarrier_phase_samples = 0.0;
+ d_rem_carr_phase_rad = 0;
+ d_acc_carrier_phase_rad = 0;
+
+ d_acc_code_phase_secs = 0;
+ d_carrier_doppler_hz = d_acq_carrier_doppler_hz;
+ d_current_prn_length_samples = d_vector_length;
+
+ std::string sys_ = &d_acquisition_gnss_synchro->System;
+ sys = sys_.substr(0, 1);
+
+ // DEBUG OUTPUT
+ std::cout << "Tracking start on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << std::endl;
+ LOG(INFO) << "Starting tracking of satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel;
+
+ // enable tracking
+ d_pull_in = true;
+ d_enable_tracking = true;
+
+ LOG(INFO) << "PULL-IN Doppler [Hz]=" << d_carrier_doppler_hz
+ << " PULL-IN Code Phase [samples]=" << d_acq_code_phase_samples;
+}
+
+
+void galileo_e1_prs_de_tracking_cc::update_local_code()
+{
+ double tcode_chips;
+ double tsubcarrier_phase_halfcyles;
+ float rem_code_phase_chips;
+ int associated_chip_index;
+ int associated_subcarrier_index;
+ int code_length_chips = static_cast(Galileo_E1_B_CODE_LENGTH_CHIPS);
+ double code_phase_step_chips;
+ double subcarrier_phase_step_halfcycles;
+ double early_late_subcarrier_spc_halfcycles;
+ double subcarrier_freq_halfcycles;
+
+ double chips_to_halfcycles = Galileo_E1_SUB_CARRIER_A_RATE_HZ /
+ Galileo_E1_CODE_CHIP_RATE_HZ * 2.0;
+
+
+ subcarrier_freq_halfcycles = d_subcarrier_freq_cycles * chips_to_halfcycles;
+
+ code_phase_step_chips = (static_cast(d_code_freq_chips)) / (static_cast(d_fs_in));
+ subcarrier_phase_step_halfcycles = subcarrier_freq_halfcycles/ (static_cast(d_fs_in));
+
+ rem_code_phase_chips = d_rem_code_phase_samples * (d_code_freq_chips / d_fs_in);
+ tcode_chips = - static_cast(rem_code_phase_chips) + 1.0;
+
+
+ tsubcarrier_phase_halfcyles = static_cast(d_subcarrier_phase_halfcycles);
+
+ early_late_subcarrier_spc_halfcycles = d_early_late_subcarrier_spc_cycles * chips_to_halfcycles;
+
+ int64_t early_code_phase_fxp = double_to_fxpt64( tcode_chips + d_early_late_code_spc_chips );
+ int64_t prompt_code_phase_fxp = double_to_fxpt64( tcode_chips );
+ int64_t late_code_phase_fxp = double_to_fxpt64( tcode_chips - d_early_late_code_spc_chips);
+
+ int64_t early_subcarrier_phase_fxp = double_to_fxpt64(
+ tsubcarrier_phase_halfcyles + early_late_subcarrier_spc_halfcycles );
+ int64_t prompt_subcarrier_phase_fxp = double_to_fxpt64(
+ tsubcarrier_phase_halfcyles );
+ int64_t late_subcarrier_phase_fxp = double_to_fxpt64(
+ tsubcarrier_phase_halfcyles - early_late_subcarrier_spc_halfcycles );
+
+ int64_t code_phase_step_fxp = double_to_fxpt64( code_phase_step_chips );
+ int64_t subcarrier_phase_step_fxp = double_to_fxpt64( subcarrier_phase_step_halfcycles );
+
+ for (int i = 0; i < d_current_prn_length_samples; i++)
+ {
+ d_early_code[i] = d_e1b_code[ (early_code_phase_fxp >> 32 )];
+ d_prompt_code[i] = d_e1b_code[ (prompt_code_phase_fxp >> 32 )];
+ d_late_code[i] = d_e1b_code[ (late_code_phase_fxp >> 32 )];
+
+ d_early_subcarrier[i] = (1.0 - 2.0*( (early_subcarrier_phase_fxp>>32)&0x01 ) );
+ d_prompt_subcarrier[i] = (1.0 - 2.0*( (prompt_subcarrier_phase_fxp>>32)&0x01 ) );
+ d_late_subcarrier[i] = (1.0 - 2.0*( (late_subcarrier_phase_fxp>>32)&0x01 ) );
+
+ early_code_phase_fxp += code_phase_step_fxp;
+ prompt_code_phase_fxp += code_phase_step_fxp;
+ late_code_phase_fxp += code_phase_step_fxp;
+
+ early_subcarrier_phase_fxp += subcarrier_phase_step_fxp;
+ prompt_subcarrier_phase_fxp += subcarrier_phase_step_fxp;
+ late_subcarrier_phase_fxp += subcarrier_phase_step_fxp;
+
+ }
+}
+
+
+void galileo_e1_prs_de_tracking_cc::update_local_code_prs()
+{
+ double tcode_chips;
+ double tsubcarrier_phase_halfcyles;
+ float rem_code_phase_chips;
+ int associated_chip_index;
+ int associated_subcarrier_index;
+ int code_length_chips = static_cast(Galileo_E1_B_CODE_LENGTH_CHIPS);
+ double code_phase_step_chips;
+ double subcarrier_phase_step_halfcycles;
+ double early_late_subcarrier_spc_halfcycles;
+ double subcarrier_freq_halfcycles;
+
+
+ double chips_to_halfcycles = Galileo_E1_A_SUB_CARRIER_RATE_HZ /
+ Galileo_E1_A_CODE_CHIP_RATE_HZ * 2.0;
+
+
+ subcarrier_freq_halfcycles = d_subcarrier_freq_cycles_prs * 2.0;
+
+ code_phase_step_chips = (static_cast(d_code_freq_chips_prs)) / (static_cast(d_fs_in));
+ subcarrier_phase_step_halfcycles = subcarrier_freq_halfcycles/ (static_cast(d_fs_in));
+
+ // Update the local PRS code if necessary:
+ uint64_t last_code_phase_store = d_start_index_prs_code + d_size_prs_code;
+
+ uint64_t last_code_phase_required = static_cast< uint64_t >(
+ d_code_phase_chips_prs + code_phase_step_chips*d_current_prn_length_samples );
+
+ if( !d_prs_code_initialized || ( last_code_phase_required > last_code_phase_store - 2 ) )
+ {
+ // Make sure we go back at least 2 chips:
+ d_start_index_prs_code = ( d_code_phase_chips_prs < 2.0 ?
+ static_cast( std::floor( d_code_phase_chips_prs ) ) + d_prs_code_gen->get_code_length() - 2 :
+ static_cast( std::floor( d_code_phase_chips_prs) ) - 2 );
+
+ DLOG(INFO) << "Updating the PRS code: starting chip: " << d_start_index_prs_code
+ << " for code phase: " << std::fixed << d_code_phase_chips_prs
+ << " given code length: " << d_prs_code_gen->get_code_length()
+ << " Code freq: " << d_code_freq_chips_prs
+ << " Size prs code: " << d_size_prs_code
+ << " Timestamp: " << static_cast< double >( d_sample_counter) / static_cast( d_fs_in );
+ d_prs_code_gen->get_chips(d_start_index_prs_code, d_size_prs_code, d_prs_code_shorts );
+
+ for( unsigned int ii = 0; ii < d_size_prs_code; ++ii )
+ {
+ d_prs_code[ii] = gr_complex( 1.0-2.0*static_cast( d_prs_code_shorts[ii] ), 0.0f );
+ }
+
+ d_prs_code_initialized = true;
+
+ std::cout << "PRS (" << d_acquisition_gnss_synchro->PRN << ")"
+ << " Start index: " << d_start_index_prs_code
+ << " First 12 chips:";
+ for( unsigned int ii = 0; ii < 12; ++ii )
+ {
+ std::cout << " " << d_prs_code[ii];
+ }
+ std::cout << std::endl;
+ }
+
+ uint64_t int_code_phase = static_cast< uint64_t >( std::floor( d_code_phase_chips_prs ) );
+ double frac_code_phase = std::fmod( d_code_phase_chips_prs, 1.0 );
+ tcode_chips = frac_code_phase + static_cast< double >( int_code_phase - d_start_index_prs_code );
+ //tcode_chips = d_code_phase_chips_prs - static_cast< double >( d_start_index_prs_code );
+
+ // Add 1/4 of a cyle here to account for cosine phasing:
+ tsubcarrier_phase_halfcyles = static_cast(d_subcarrier_phase_halfcycles_prs) + 0.5;
+
+ early_late_subcarrier_spc_halfcycles = d_early_late_subcarrier_spc_cycles * 2.0;
+
+ int64_t early_code_phase_fxp = double_to_fxpt64( tcode_chips + d_early_late_code_spc_chips );
+ int64_t prompt_code_phase_fxp = double_to_fxpt64( tcode_chips );
+ int64_t late_code_phase_fxp = double_to_fxpt64( tcode_chips - d_early_late_code_spc_chips);
+
+ int64_t early_subcarrier_phase_fxp = double_to_fxpt64(
+ tsubcarrier_phase_halfcyles + early_late_subcarrier_spc_halfcycles );
+ int64_t prompt_subcarrier_phase_fxp = double_to_fxpt64(
+ tsubcarrier_phase_halfcyles );
+ int64_t late_subcarrier_phase_fxp = double_to_fxpt64(
+ tsubcarrier_phase_halfcyles - early_late_subcarrier_spc_halfcycles );
+
+ int64_t code_phase_step_fxp = double_to_fxpt64( code_phase_step_chips );
+ int64_t subcarrier_phase_step_fxp = double_to_fxpt64( subcarrier_phase_step_halfcycles );
+
+ for (int i = 0; i < d_current_prn_length_samples; i++)
+ {
+ d_early_code_prs[i] = d_prs_code[ (early_code_phase_fxp >> 32 )];
+ d_prompt_code_prs[i] = d_prs_code[ (prompt_code_phase_fxp >> 32 )];
+ d_late_code_prs[i] = d_prs_code[ (late_code_phase_fxp >> 32 )];
+
+ d_early_subcarrier_prs[i] = (1.0 - 2.0*( (early_subcarrier_phase_fxp>>32)&0x01 ) );
+ d_prompt_subcarrier_prs[i] = (1.0 - 2.0*( (prompt_subcarrier_phase_fxp>>32)&0x01 ) );
+ d_late_subcarrier_prs[i] = (1.0 - 2.0*( (late_subcarrier_phase_fxp>>32)&0x01 ) );
+
+ early_code_phase_fxp += code_phase_step_fxp;
+ prompt_code_phase_fxp += code_phase_step_fxp;
+ late_code_phase_fxp += code_phase_step_fxp;
+
+ early_subcarrier_phase_fxp += subcarrier_phase_step_fxp;
+ prompt_subcarrier_phase_fxp += subcarrier_phase_step_fxp;
+ late_subcarrier_phase_fxp += subcarrier_phase_step_fxp;
+
+ }
+
+ // Check for propagation:
+ //double code_phase_at_end = d_code_phase_chips_prs + d_current_prn_length_samples*code_phase_step_chips;
+
+ //double fxp_code_phase_at_end = static_cast< double >( prompt_code_phase_fxp ) *
+ //std::pow( 2, -32 );
+
+ //std::cerr << "PRN: " << d_acquisition_gnss_synchro->PRN
+ //<< "Timestamp : " <<
+}
+void galileo_e1_prs_de_tracking_cc::update_local_carrier()
+{
+ float sin_f, cos_f;
+ float phase_step_rad = static_cast(2 * GALILEO_PI) * ( d_if_freq + d_carrier_doppler_hz ) / static_cast(d_fs_in);
+ int phase_step_rad_i = gr::fxpt::float_to_fixed(phase_step_rad);
+ int phase_rad_i = gr::fxpt::float_to_fixed(d_rem_carr_phase_rad);
+
+ for(int i = 0; i < d_current_prn_length_samples; i++)
+ {
+ gr::fxpt::sincos(phase_rad_i, &sin_f, &cos_f);
+ d_carr_sign[i] = std::complex(cos_f, -sin_f);
+ phase_rad_i += phase_step_rad_i;
+ }
+}
+
+galileo_e1_prs_de_tracking_cc::~galileo_e1_prs_de_tracking_cc()
+{
+ d_dump_file.close();
+
+ volk_free(d_early_code);
+ volk_free(d_prompt_code);
+ volk_free(d_late_code);
+ volk_free(d_early_subcarrier);
+ volk_free(d_prompt_subcarrier);
+ volk_free(d_late_subcarrier);
+ volk_free(d_carr_sign);
+ volk_free(d_Prompt_Subcarrier_Early_Code);
+ volk_free(d_Prompt_Subcarrier_Prompt_Code);
+ volk_free(d_Prompt_Subcarrier_Late_Code);
+ volk_free(d_Prompt_Code_Early_Subcarrier);
+ volk_free(d_Prompt_Code_Late_Subcarrier);
+ volk_free(d_e1b_code);
+
+ volk_free(d_early_code_prs);
+ volk_free(d_prompt_code_prs);
+ volk_free(d_late_code_prs);
+ volk_free(d_early_subcarrier_prs);
+ volk_free(d_prompt_subcarrier_prs);
+ volk_free(d_late_subcarrier_prs);
+ volk_free(d_Prompt_Subcarrier_Early_Code_prs);
+ volk_free(d_Prompt_Subcarrier_Prompt_Code_prs);
+ volk_free(d_Prompt_Subcarrier_Late_Code_prs);
+ volk_free(d_Prompt_Code_Early_Subcarrier_prs);
+ volk_free(d_Prompt_Code_Late_Subcarrier_prs);
+ volk_free(d_prs_code);
+ delete[] d_Prompt_buffer;
+}
+
+
+
+int galileo_e1_prs_de_tracking_cc::general_work (int noutput_items,gr_vector_int &ninput_items,
+ gr_vector_const_void_star &input_items, gr_vector_void_star &output_items)
+{
+ float carr_error_hz = 0.0;
+ float carr_error_filt_hz = 0.0;
+ float code_error_chips = 0.0;
+ float subcarrier_error_cycles = 0.0;
+ float code_error_filt_chips = 0.0;
+ float subcarrier_error_filt_cycles = 0.0;
+ double integer_subcarrier_periods = 0.0;
+ float carr_error_hz_prs = 0.0;
+ float carr_error_filt_hz_prs = 0.0;
+ float code_error_chips_prs = 0.0;
+ float subcarrier_error_cycles_prs = 0.0;
+ float code_error_filt_chips_prs = 0.0;
+ float subcarrier_error_filt_cycles_prs = 0.0;
+
+ // Block input data and block output stream pointers
+ const gr_complex* in = (gr_complex*) input_items[0];
+ Gnss_Synchro **out = (Gnss_Synchro **) &output_items[0];
+
+ // GNSS_SYNCHRO OBJECT to interchange data between tracking->telemetry_decoder
+ Gnss_Synchro current_synchro_data;
+
+ int next_prn_length_samples = d_current_prn_length_samples;
+ if (d_enable_tracking == true)
+ {
+ if (d_pull_in == true)
+ {
+ /*
+ * Signal alignment (skip samples until the incoming signal is aligned with local replica)
+ */
+ int samples_offset;
+ float acq_trk_shif_correction_samples;
+ int acq_to_trk_delay_samples;
+ acq_to_trk_delay_samples = d_sample_counter - d_acq_sample_stamp;
+ acq_trk_shif_correction_samples = d_current_prn_length_samples - fmod(static_cast(acq_to_trk_delay_samples), static_cast(d_current_prn_length_samples));
+ samples_offset = round(d_acq_code_phase_samples + acq_trk_shif_correction_samples);
+ d_sample_counter = d_sample_counter + samples_offset; //count for the processed samples
+ d_pull_in = false;
+ // Now update the code and carrier phase estimates:
+ d_code_phase_chips = 0.0;
+ d_rem_code_phase_samples = 0.0;
+ d_subcarrier_phase_halfcycles = 0.0;
+
+ //std::cout<<" samples_offset="<(d_sample_counter) + static_cast(d_rem_code_phase_samples)) / static_cast(d_fs_in);
+
+ // Generate local code and carrier replicas (using \hat{f}_d(k-1))
+ update_local_code();
+ //update_local_carrier();
+
+ gr_complex phase_as_complex( std::cos( d_rem_carr_phase_rad ),
+ -std::sin( d_rem_carr_phase_rad ) );
+
+ double carrier_doppler_inc_rad = 2.0*M_PI*(d_if_freq + d_carrier_doppler_hz )/d_fs_in;
+
+ gr_complex phase_inc_as_complex( std::cos( carrier_doppler_inc_rad ),
+ -std::sin( carrier_doppler_inc_rad ) );
+
+
+ // perform carrier wipe-off and compute Very Early, Early, Prompt, Late and Very Late correlation
+ d_correlator.Carrier_rotate_and_DE_volk(d_current_prn_length_samples,
+ in,
+ &phase_as_complex,
+ phase_inc_as_complex,
+ d_early_code,
+ d_prompt_code,
+ d_late_code,
+ d_early_subcarrier,
+ d_prompt_subcarrier,
+ d_late_subcarrier,
+ d_Prompt_Subcarrier_Early_Code,
+ d_Prompt_Subcarrier_Prompt_Code,
+ d_Prompt_Subcarrier_Late_Code,
+ d_Prompt_Code_Early_Subcarrier,
+ d_Prompt_Code_Late_Subcarrier );
+
+ // Now update the code and carrier phase estimates:
+ double chips_to_halfcycles = Galileo_E1_SUB_CARRIER_A_RATE_HZ /
+ Galileo_E1_CODE_CHIP_RATE_HZ * 2.0;
+ double T = static_cast( d_current_prn_length_samples ) / static_cast( d_fs_in );
+ d_code_phase_chips += T*d_code_freq_chips;
+ d_code_phase_chips = std::fmod( d_code_phase_chips, Galileo_E1_B_CODE_LENGTH_CHIPS );
+ d_carrier_phase_rad += T*2.0*M_PI*d_carrier_doppler_hz;
+ //int64_t subcarrier_inc_halfcycles_fxp = double_to_fxpt64(
+ //d_subcarrier_freq_cycles*chips_to_halfcycles/d_fs_in, 48 );
+
+ //int64_t subcarrier_delta_halfcycles_fxp = subcarrier_inc_halfcycles_fxp * d_current_prn_length_samples;
+ //// take out the integer part:
+ //subcarrier_delta_halfcycles_fxp &=0xFFFFFFFFFFFF; // 48 ones in LSB
+
+ //d_subcarrier_phase_halfcycles += static_cast< double >( subcarrier_delta_halfcycles_fxp )*std::pow(2.0,-48.0);
+ d_subcarrier_phase_halfcycles += T*d_subcarrier_freq_cycles*chips_to_halfcycles;
+ integer_subcarrier_periods = std::floor( d_subcarrier_phase_halfcycles );
+ d_subcarrier_phase_halfcycles = std::fmod( d_subcarrier_phase_halfcycles, 2.0 );
+ double rem_subcarrier_phase_cycles = 1.0 - d_subcarrier_phase_halfcycles/2.0;
+
+ if( rem_subcarrier_phase_cycles > 0.5 ){
+ rem_subcarrier_phase_cycles -= 1.0;
+ }
+
+ d_rem_subcarrier_phase_samples = rem_subcarrier_phase_cycles*
+ static_cast(d_fs_in)/Galileo_E1_SUB_CARRIER_A_RATE_HZ;
+
+ double rem_code_phase_chips = Galileo_E1_B_CODE_LENGTH_CHIPS - d_code_phase_chips;
+ if( rem_code_phase_chips > Galileo_E1_B_CODE_LENGTH_CHIPS / 2.0 )
+ {
+ rem_code_phase_chips = ( rem_code_phase_chips - Galileo_E1_B_CODE_LENGTH_CHIPS );
+ }
+
+ d_rem_code_phase_samples = rem_code_phase_chips * d_fs_in/Galileo_E1_CODE_CHIP_RATE_HZ;
+
+ // PRS tracking
+ if( d_prs_tracking_enabled ){
+ // Generate local code and carrier replicas (using \hat{f}_d(k-1))
+ update_local_code_prs();
+ //update_local_carrier();
+
+ phase_as_complex = gr_complex( std::cos( d_rem_carr_phase_rad_prs ),
+ -std::sin( d_rem_carr_phase_rad_prs ) );
+
+ carrier_doppler_inc_rad = 2.0*M_PI*(d_if_freq + d_carrier_doppler_hz_prs )/d_fs_in;
+
+ phase_inc_as_complex = gr_complex( std::cos( carrier_doppler_inc_rad ),
+ -std::sin( carrier_doppler_inc_rad ) );
+
+
+ // perform carrier wipe-off and compute Very Early, Early, Prompt, Late and Very Late correlation
+ d_correlator.Carrier_rotate_and_DE_volk(d_current_prn_length_samples,
+ in,
+ &phase_as_complex,
+ phase_inc_as_complex,
+ d_early_code_prs,
+ d_prompt_code_prs,
+ d_late_code_prs,
+ d_early_subcarrier_prs,
+ d_prompt_subcarrier_prs,
+ d_late_subcarrier_prs,
+ d_Prompt_Subcarrier_Early_Code_prs,
+ d_Prompt_Subcarrier_Prompt_Code_prs,
+ d_Prompt_Subcarrier_Late_Code_prs,
+ d_Prompt_Code_Early_Subcarrier_prs,
+ d_Prompt_Code_Late_Subcarrier_prs );
+
+ // Now update the code and carrier phase estimates:
+ double chips_to_halfcycles_prs = Galileo_E1_A_SUB_CARRIER_RATE_HZ /
+ Galileo_E1_A_CODE_CHIP_RATE_HZ * 2.0;
+ d_code_phase_chips_prs += T*d_code_freq_chips_prs;
+ d_code_phase_chips_prs = std::fmod( d_code_phase_chips_prs, d_prs_code_gen->get_code_length() );
+ d_carrier_phase_rad_prs += T*2.0*M_PI*d_carrier_doppler_hz_prs;
+
+ d_subcarrier_phase_halfcycles_prs += T*d_subcarrier_freq_cycles_prs*2.0;
+ d_subcarrier_phase_halfcycles_prs = std::fmod( d_subcarrier_phase_halfcycles_prs, 2.0 );
+ double rem_subcarrier_phase_cycles_prs = 1.0 - d_subcarrier_phase_halfcycles_prs/2.0;
+
+ if( rem_subcarrier_phase_cycles_prs > 0.5 ){
+ rem_subcarrier_phase_cycles_prs -= 1.0;
+ }
+
+ d_rem_subcarrier_phase_samples_prs = rem_subcarrier_phase_cycles_prs*
+ static_cast(d_fs_in)/Galileo_E1_A_SUB_CARRIER_RATE_HZ;
+
+ }
+
+ // check for samples consistency (this should be done before in the receiver / here only if the source is a file)
+ if (std::isnan((*d_Prompt_Subcarrier_Prompt_Code).real()) == true or
+ std::isnan((*d_Prompt_Subcarrier_Prompt_Code).imag()) == true ) // or std::isinf(in[i].real())==true or std::isinf(in[i].imag())==true)
+ {
+ const int samples_available = ninput_items[0];
+ d_sample_counter = d_sample_counter + samples_available;
+ LOG(WARNING) << "Detected NaN samples at sample number " << d_sample_counter;
+ consume_each(samples_available);
+
+ // make an output to not stop the rest of the processing blocks
+ current_synchro_data.Prompt_I = 0.0;
+ current_synchro_data.Prompt_Q = 0.0;
+ current_synchro_data.Tracking_timestamp_secs = static_cast(d_sample_counter) / static_cast(d_fs_in);
+ current_synchro_data.Carrier_phase_rads = 0.0;
+ current_synchro_data.Code_phase_secs = 0.0;
+ current_synchro_data.CN0_dB_hz = 0.0;
+ current_synchro_data.Flag_valid_tracking = false;
+ current_synchro_data.Flag_valid_pseudorange = false;
+
+ *out[0] = current_synchro_data;
+ return 1;
+ }
+
+ // consume the input samples:
+ d_sample_counter += d_current_prn_length_samples;
+
+ // ################## PLL ##########################################################
+ // PLL discriminator
+ carr_error_hz = pll_cloop_two_quadrant_atan(*d_Prompt_Subcarrier_Prompt_Code) / static_cast(GPS_TWO_PI);
+ // Carrier discriminator filter
+ carr_error_filt_hz = d_carrier_loop_filter.apply(carr_error_hz);
+ // New carrier Doppler frequency estimation
+ d_carrier_doppler_hz = carr_error_filt_hz;
+
+ float code_doppler_chips = ((d_carrier_doppler_hz * Galileo_E1_CODE_CHIP_RATE_HZ) / Galileo_E1_FREQ_HZ);
+
+ // New subcarrier Doppler frequency estimation: carrier
+ // aiding of the subcarrier:
+ if( d_aid_subcarrier_with_carrier )
+ {
+ d_subcarrier_freq_cycles = Galileo_E1_CODE_CHIP_RATE_HZ + code_doppler_chips;
+ }
+ else
+ {
+ d_subcarrier_freq_cycles = Galileo_E1_CODE_CHIP_RATE_HZ;
+ }
+ //carrier phase accumulator for (K) Doppler estimation
+ d_acc_carrier_phase_rad = d_acc_carrier_phase_rad + GPS_TWO_PI * d_carrier_doppler_hz * Galileo_E1_CODE_PERIOD;
+ //remnant carrier phase to prevent overflow in the code NCO
+ d_rem_carr_phase_rad = d_rem_carr_phase_rad + GPS_TWO_PI * d_carrier_doppler_hz * Galileo_E1_CODE_PERIOD;
+ d_rem_carr_phase_rad = fmod(d_rem_carr_phase_rad, GPS_TWO_PI);
+
+ // ################## SLL ##########################################################
+ // SLL discriminator
+ subcarrier_error_cycles = dll_nc_e_minus_l_normalized(
+ *d_Prompt_Code_Early_Subcarrier,
+ *d_Prompt_Code_Late_Subcarrier); //[chips/Ti]
+ // normalise the SLL discriminator by the slope of the
+ // BOC(1,1) at the origin:
+ float corr_slope = 2.0;
+ subcarrier_error_cycles *= ( 1 - corr_slope*d_early_late_subcarrier_spc_cycles) / corr_slope;
+ // Subcarrier discriminator filter
+ subcarrier_error_filt_cycles = d_subcarrier_loop_filter.apply(subcarrier_error_cycles); //[chips/second]
+ d_subcarrier_freq_cycles += subcarrier_error_filt_cycles;
+ // Aiding the code tracking with the subcarrier:
+ if( d_aid_code_with_subcarrier )
+ {
+ d_code_freq_chips = d_subcarrier_freq_cycles;
+ }
+ else if( d_aid_subcarrier_with_carrier )
+ {
+ d_code_freq_chips = Galileo_E1_CODE_CHIP_RATE_HZ + code_doppler_chips;
+ }
+ else
+ {
+ d_code_freq_chips = Galileo_E1_CODE_CHIP_RATE_HZ;
+ }
+
+ //Subcarrier phase accumulator
+ float subcarrier_error_filt_secs;
+ subcarrier_error_filt_secs = (Galileo_E1_CODE_PERIOD * subcarrier_error_filt_cycles) / Galileo_E1_CODE_CHIP_RATE_HZ; //[seconds]
+ //code_error_filt_secs=T_prn_seconds*code_error_filt_chips*T_chip_seconds*static_cast(d_fs_in); //[seconds]
+
+ // ################## DLL ##########################################################
+ // DLL discriminator
+ code_error_chips = dll_nc_e_minus_l_normalized(
+ *d_Prompt_Subcarrier_Early_Code,
+ *d_Prompt_Subcarrier_Late_Code); //[chips/Ti]
+ //Normalise the code phase error:
+ corr_slope = 1.0;
+ code_error_chips *= ( 1 - corr_slope*d_early_late_code_spc_chips) / corr_slope;
+ // Code discriminator filter
+ code_error_filt_chips = d_code_loop_filter.apply(code_error_chips); //[chips/second]
+ //Code phase accumulator
+ d_code_freq_chips += code_error_filt_chips;
+ float code_error_filt_secs;
+ code_error_filt_secs = (Galileo_E1_CODE_PERIOD * code_error_filt_chips) / Galileo_E1_CODE_CHIP_RATE_HZ; //[seconds]
+ //code_error_filt_secs=T_prn_seconds*code_error_filt_chips*T_chip_seconds*static_cast(d_fs_in); //[seconds]
+ d_acc_code_phase_secs = d_acc_code_phase_secs + code_error_filt_secs;
+
+ // ################## PRS ##########################################################
+ // ################## PLL ##########################################################
+ // PLL discriminator
+ carr_error_hz_prs = pll_cloop_two_quadrant_atan(*d_Prompt_Subcarrier_Prompt_Code_prs) / static_cast(GPS_TWO_PI);
+
+ // FOR NOW : Use E1b value
+ d_carrier_doppler_hz_prs = d_carrier_doppler_hz;
+
+
+ // ################## SLL ##########################################################
+ // SLL discriminator
+ subcarrier_error_cycles_prs = dll_nc_e_minus_l_normalized(
+ *d_Prompt_Code_Early_Subcarrier_prs,
+ *d_Prompt_Code_Late_Subcarrier_prs); //[chips/Ti]
+ // normalise the SLL discriminator by the slope of the
+ // BOC(1,1) at the origin:
+ corr_slope = 2.0;
+ subcarrier_error_cycles_prs *= ( 1 - corr_slope*d_early_late_subcarrier_spc_cycles) / corr_slope;
+
+ // For now use the E1b values
+ d_subcarrier_freq_cycles_prs = d_subcarrier_freq_cycles
+ * Galileo_E1_A_SUB_CARRIER_RATE_HZ / Galileo_E1_SUB_CARRIER_A_RATE_HZ;
+
+ // ################## DLL ##########################################################
+ // DLL discriminator
+ code_error_chips_prs = dll_nc_e_minus_l_normalized(
+ *d_Prompt_Subcarrier_Early_Code_prs,
+ *d_Prompt_Subcarrier_Late_Code_prs); //[chips/Ti]
+ //Normalise the code phase error:
+ corr_slope = 1.0;
+ code_error_chips_prs *= ( 1 - corr_slope*d_early_late_code_spc_chips) / corr_slope;
+
+ // For now use the E1 values:
+ d_code_freq_chips_prs = d_code_freq_chips * Galileo_E1_A_CODE_CHIP_RATE_HZ /
+ Galileo_E1_CODE_CHIP_RATE_HZ;
+
+ // ################## CARRIER AND CODE NCO BUFFER ALIGNEMENT #######################
+ // keep alignment parameters for the next input buffer
+ double T_chip_seconds;
+ double T_prn_seconds;
+ double T_prn_samples;
+ double K_blk_samples;
+ double T_sc_seconds;
+ double T_sc_prn_seconds;
+ double T_sc_prn_samples;
+ double K_sc_samples;
+ // Compute the next buffer lenght based in the new period of the PRN sequence and the code phase error estimation
+ T_chip_seconds = 1 / static_cast(d_code_freq_chips);
+ T_prn_seconds = T_chip_seconds * Galileo_E1_B_CODE_LENGTH_CHIPS;
+ T_prn_samples = T_prn_seconds * static_cast(d_fs_in);
+ K_blk_samples = T_prn_samples + d_rem_code_phase_samples; // + code_error_filt_secs * static_cast(d_fs_in);
+
+ T_sc_seconds = 1 / static_cast(d_subcarrier_freq_cycles);
+ // THere is one subcarrier period per code chip:
+ T_sc_prn_seconds = T_sc_seconds * Galileo_E1_B_CODE_LENGTH_CHIPS;
+ T_sc_prn_samples = T_sc_prn_seconds * static_cast(d_fs_in);
+ K_sc_samples = T_sc_prn_samples + d_rem_subcarrier_phase_samples;
+
+ next_prn_length_samples = round(K_blk_samples); //round to a discrete samples
+ //d_rem_code_phase_samples = K_blk_samples - d_current_prn_length_samples; //rounding error < 1 sample
+
+ // ####### CN0 ESTIMATION AND LOCK DETECTORS ######
+ if (d_cn0_estimation_counter < CN0_ESTIMATION_SAMPLES)
+ {
+ // fill buffer with prompt correlator output values
+ d_Prompt_buffer[d_cn0_estimation_counter] = *d_Prompt_Subcarrier_Prompt_Code;
+ d_cn0_estimation_counter++;
+ }
+ else
+ {
+ d_cn0_estimation_counter = 0;
+
+ // Code lock indicator
+ d_CN0_SNV_dB_Hz = cn0_svn_estimator(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES, d_fs_in, Galileo_E1_B_CODE_LENGTH_CHIPS);
+
+ // Carrier lock indicator
+ d_carrier_lock_test = carrier_lock_detector(d_Prompt_buffer, CN0_ESTIMATION_SAMPLES);
+
+ // Loss of lock detection
+ if (d_carrier_lock_test < d_carrier_lock_threshold or d_CN0_SNV_dB_Hz < MINIMUM_VALID_CN0)
+ {
+ d_carrier_lock_fail_counter++;
+ }
+ else
+ {
+ if (d_carrier_lock_fail_counter > 0) d_carrier_lock_fail_counter--;
+ }
+ if (d_carrier_lock_fail_counter > MAXIMUM_LOCK_FAIL_COUNTER)
+ {
+ std::cout << "Loss of lock in channel " << d_channel << "!" << std::endl;
+ LOG(INFO) << "Loss of lock in channel " << d_channel << "!";
+ std::unique_ptr cmf(new ControlMessageFactory());
+ if (d_queue != gr::msg_queue::sptr())
+ {
+ d_queue->handle(cmf->GetQueueMessage(d_channel, 2));
+ }
+ d_carrier_lock_fail_counter = 0;
+ d_enable_tracking = false; // TODO: check if disabling tracking is consistent with the channel state machine
+ }
+ }
+
+ // ########### Output the tracking results to Telemetry block ##########
+
+ current_synchro_data.Prompt_I = static_cast((*d_Prompt_Subcarrier_Prompt_Code).real());
+ current_synchro_data.Prompt_Q = static_cast((*d_Prompt_Subcarrier_Prompt_Code).imag());
+
+ // Tracking_timestamp_secs is aligned with the NEXT PRN start sample (Hybridization problem!)
+ //compute remnant code phase samples BEFORE the Tracking timestamp
+ //d_rem_code_phase_samples = K_blk_samples - d_current_prn_length_samples; //rounding error < 1 sample
+ //current_synchro_data.Tracking_timestamp_secs = ((double)d_sample_counter +
+ // (double)d_current_prn_length_samples + (double)d_rem_code_phase_samples) / static_cast(d_fs_in);
+
+ // Tracking_timestamp_secs is aligned with the CURRENT PRN start sample (Hybridization OK!, but some glitches??)
+ //current_synchro_data.Tracking_timestamp_secs = (static_cast(d_sample_counter) + static_cast(d_rem_code_phase_samples)) / static_cast(d_fs_in);
+ //compute remnant code phase samples AFTER the Tracking timestamp
+ //d_rem_code_phase_samples = K_blk_samples - d_current_prn_length_samples; //rounding error < 1 sample
+
+ //d_rem_subcarrier_phase_samples = K_sc_samples - d_current_prn_length_samples; //rounding error < 1 sample
+ // This tracking block aligns the Tracking_timestamp_secs with the start sample of the PRN, thus, Code_phase_secs=0
+ current_synchro_data.Code_phase_secs = 0;
+ current_synchro_data.Carrier_phase_rads = static_cast(d_acc_carrier_phase_rad);
+ current_synchro_data.Carrier_Doppler_hz = static_cast(d_carrier_doppler_hz);
+ current_synchro_data.CN0_dB_hz = static_cast(d_CN0_SNV_dB_Hz);
+ current_synchro_data.Flag_valid_pseudorange = false;
+ *out[0] = current_synchro_data;
+
+ // ########## DEBUG OUTPUT
+ /*!
+ * \todo The stop timer has to be moved to the signal source!
+ */
+ // stream to collect cout calls to improve thread safety
+ std::stringstream tmp_str_stream;
+ if (floor(d_sample_counter / d_fs_in) != d_last_seg)
+ {
+ d_last_seg = floor(d_sample_counter / d_fs_in);
+
+ if (d_channel == 0)
+ {
+ // debug: Second counter in channel 0
+ tmp_str_stream << "Current input signal time = " << d_last_seg << " [s]" << std::endl << std::flush;
+ std::cout << tmp_str_stream.rdbuf() << std::flush;
+ }
+
+ tmp_str_stream << "Tracking CH " << d_channel << ": Satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN)
+ << ", Doppler=" << d_carrier_doppler_hz << " [Hz] CN0 = " << d_CN0_SNV_dB_Hz << " [dB-Hz]" << std::endl;
+ LOG(INFO) << tmp_str_stream.rdbuf() << std::flush;
+ //if (d_channel == 0 || d_last_seg==5) d_carrier_lock_fail_counter=500; //DEBUG: force unlock!
+ }
+ }
+ else
+ {
+ // ########## DEBUG OUTPUT (TIME ONLY for channel 0 when tracking is disabled)
+ /*!
+ * \todo The stop timer has to be moved to the signal source!
+ */
+ // stream to collect cout calls to improve thread safety
+ std::stringstream tmp_str_stream;
+ if (floor(d_sample_counter / d_fs_in) != d_last_seg)
+ {
+ d_last_seg = floor(d_sample_counter / d_fs_in);
+
+ if (d_channel == 0)
+ {
+ // debug: Second counter in channel 0
+ tmp_str_stream << "Current input signal time = " << d_last_seg << " [s]" << std::endl << std::flush;
+ std::cout << tmp_str_stream.rdbuf() << std::flush;
+ }
+ }
+ *d_Prompt_Subcarrier_Early_Code = gr_complex(0,0);
+ *d_Prompt_Subcarrier_Prompt_Code = gr_complex(0,0);
+ *d_Prompt_Subcarrier_Late_Code = gr_complex(0,0);
+ *d_Prompt_Code_Early_Subcarrier = gr_complex(0,0);
+ *d_Prompt_Code_Late_Subcarrier = gr_complex(0,0);
+ Gnss_Synchro **out = (Gnss_Synchro **) &output_items[0]; //block output stream pointer
+ // GNSS_SYNCHRO OBJECT to interchange data between tracking->telemetry_decoder
+ d_acquisition_gnss_synchro->Flag_valid_pseudorange = false;
+ *out[0] = *d_acquisition_gnss_synchro;
+ d_sample_counter += d_current_prn_length_samples;
+ }
+
+ if(d_dump)
+ {
+ // Dump results to file
+ float prompt_I;
+ float prompt_Q;
+ float tmp_VE, tmp_E, tmp_P, tmp_L, tmp_VL;
+ float tmp_float;
+ double tmp_double;
+ prompt_I = (*d_Prompt_Subcarrier_Prompt_Code).real();
+ prompt_Q = (*d_Prompt_Subcarrier_Prompt_Code).imag();
+ tmp_VE = std::abs(*d_Prompt_Code_Early_Subcarrier);
+ tmp_E = std::abs(*d_Prompt_Subcarrier_Early_Code);
+ tmp_P = std::abs(*d_Prompt_Subcarrier_Prompt_Code);
+ tmp_L = std::abs(*d_Prompt_Subcarrier_Late_Code);
+ tmp_VL = std::abs(*d_Prompt_Code_Late_Subcarrier);
+
+ try
+ {
+ // Dump correlators output
+ d_dump_file.write(reinterpret_cast(&tmp_VE), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_E), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_P), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_L), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_VL), sizeof(float));
+ // PROMPT I and Q (to analyze navigation symbols)
+ d_dump_file.write(reinterpret_cast(&prompt_I), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&prompt_Q), sizeof(float));
+ // PRN start sample stamp
+ d_dump_file.write(reinterpret_cast(&d_sample_counter), sizeof(unsigned long int));
+ // accumulated carrier phase
+ tmp_float = static_cast(d_acc_carrier_phase_rad);
+ d_dump_file.write(reinterpret_cast(&tmp_float), sizeof(float));
+ // carrier and code frequency
+ d_dump_file.write(reinterpret_cast(&d_carrier_doppler_hz), sizeof(float));
+ tmp_float = static_cast( d_code_freq_chips );
+ d_dump_file.write(reinterpret_cast(&tmp_float), sizeof(float));
+ //PLL commands
+ d_dump_file.write(reinterpret_cast(&carr_error_hz), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&carr_error_filt_hz), sizeof(float));
+ //DLL commands
+ d_dump_file.write(reinterpret_cast(&code_error_chips), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&code_error_filt_chips), sizeof(float));
+ // SLL commands
+ d_dump_file.write(reinterpret_cast(&subcarrier_error_cycles), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&subcarrier_error_filt_cycles), sizeof(float));
+ // CN0 and carrier lock test
+ d_dump_file.write(reinterpret_cast(&d_CN0_SNV_dB_Hz), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&d_carrier_lock_test), sizeof(float));
+ // AUX vars (for debug purposes)
+ //tmp_float = d_rem_code_phase_samples/static_cast< float >( d_fs_in )*Galileo_E1_CODE_CHIP_RATE_HZ;
+ tmp_float = d_code_phase_chips;
+ d_dump_file.write(reinterpret_cast(&tmp_float), sizeof(float));
+ //tmp_double = static_cast(d_sample_counter + d_current_prn_length_samples);
+ tmp_double = integer_subcarrier_periods;
+ d_dump_file.write(reinterpret_cast(&tmp_double), sizeof(double));
+ //tmp_float = d_rem_subcarrier_phase_samples/static_cast( d_fs_in ) * Galileo_E1_CODE_CHIP_RATE_HZ;
+ tmp_float = d_subcarrier_phase_halfcycles/2.0;
+ d_dump_file.write(reinterpret_cast(&tmp_float), sizeof(float));
+
+
+ // ****************************************************************************
+ // PRS Variables:
+ prompt_I = (*d_Prompt_Subcarrier_Prompt_Code_prs).real();
+ prompt_Q = (*d_Prompt_Subcarrier_Prompt_Code_prs).imag();
+ tmp_VE = std::abs(*d_Prompt_Code_Early_Subcarrier_prs);
+ tmp_E = std::abs(*d_Prompt_Subcarrier_Early_Code_prs);
+ tmp_P = std::abs(*d_Prompt_Subcarrier_Prompt_Code_prs);
+ tmp_L = std::abs(*d_Prompt_Subcarrier_Late_Code_prs);
+ tmp_VL = std::abs(*d_Prompt_Code_Late_Subcarrier_prs);
+ // Dump correlators output
+ d_dump_file.write(reinterpret_cast(&tmp_VE), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_E), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_P), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_L), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&tmp_VL), sizeof(float));
+ // PROMPT I and Q (to analyze navigation symbols)
+ d_dump_file.write(reinterpret_cast(&prompt_I), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&prompt_Q), sizeof(float));
+ // carrier and code frequency
+ d_dump_file.write(reinterpret_cast(&d_carrier_doppler_hz_prs), sizeof(float));
+ tmp_float = static_cast(d_code_freq_chips_prs);
+ d_dump_file.write(reinterpret_cast(&tmp_float), sizeof(float));
+ tmp_float = static_cast(d_subcarrier_freq_cycles_prs);
+ d_dump_file.write(reinterpret_cast(&tmp_float), sizeof(float));
+ //PLL commands
+ d_dump_file.write(reinterpret_cast(&carr_error_hz_prs), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&carr_error_filt_hz_prs), sizeof(float));
+ //DLL commands
+ d_dump_file.write(reinterpret_cast(&code_error_chips_prs), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&code_error_filt_chips_prs), sizeof(float));
+ // SLL commands
+ d_dump_file.write(reinterpret_cast(&subcarrier_error_cycles_prs), sizeof(float));
+ d_dump_file.write(reinterpret_cast(&subcarrier_error_filt_cycles_prs), sizeof(float));
+
+ d_dump_file.write(reinterpret_cast(&d_code_phase_chips_prs), sizeof(double));
+ tmp_float = d_subcarrier_phase_halfcycles_prs/2.0;
+ d_dump_file.write(reinterpret_cast(&tmp_float), sizeof(float));
+ }
+ catch (std::ifstream::failure e)
+ {
+ LOG(WARNING) << "Exception writing trk dump file " << e.what() << std::endl;
+ }
+ }
+ consume_each(d_current_prn_length_samples); // this is required for gr_block derivates
+ //d_sample_counter += d_current_prn_length_samples; //count for the processed samples
+ d_current_prn_length_samples = next_prn_length_samples;
+ //std::cout<<"Galileo tracking output at sample "<(d_channel));
+ d_dump_filename.append(".dat");
+ d_dump_file.exceptions (std::ifstream::failbit | std::ifstream::badbit);
+ d_dump_file.open(d_dump_filename.c_str(), std::ios::out | std::ios::binary);
+ LOG(INFO) << "Tracking dump enabled on channel " << d_channel << " Log file: " << d_dump_filename.c_str();
+ }
+ catch (std::ifstream::failure e)
+ {
+ LOG(WARNING) << "channel " << d_channel << " Exception opening trk dump file " << e.what() << std::endl;
+ }
+ }
+ }
+}
+
+
+
+void galileo_e1_prs_de_tracking_cc::set_channel_queue(concurrent_queue *channel_internal_queue)
+{
+ d_channel_internal_queue = channel_internal_queue;
+}
+
+
+
+void galileo_e1_prs_de_tracking_cc::set_gnss_synchro(Gnss_Synchro* p_gnss_synchro)
+{
+ d_acquisition_gnss_synchro = p_gnss_synchro;
+ // Gnss_Satellite(satellite.get_system(), satellite.get_PRN());
+ //DLOG(INFO) << "Tracking code phase set to " << d_acq_code_phase_samples;
+ //DLOG(INFO) << "Tracking carrier doppler set to " << d_acq_carrier_doppler_hz;
+ //DLOG(INFO) << "Tracking Satellite set to " << d_satellite;
+}
+
+void galileo_e1_prs_de_tracking_cc::start_tracking_prs()
+{
+
+ // Initialise the code/phase and subcarrier estimates:
+ double time_since_tow = static_cast< double >( d_sample_counter ) /
+ static_cast( d_fs_in ) - d_timestamp_last_tow;
+
+ double code_periods_since_tow = std::floor( time_since_tow / Galileo_E1_CODE_PERIOD + 0.5);
+
+ double curr_tow = d_last_tow + code_periods_since_tow*Galileo_E1_CODE_PERIOD +
+ //std::fmod( d_code_phase_chips, Galileo_E1_B_CODE_LENGTH_CHIPS ) / Galileo_E1_CODE_CHIP_RATE_HZ;
+ d_rem_code_phase_samples / static_cast( d_fs_in );
+
+ // Handle week rollover:
+ if( curr_tow > 604800.0 ){
+ curr_tow -= 604800.0;
+ }
+
+ d_code_phase_chips_prs = std::fmod( curr_tow * Galileo_E1_A_CODE_CHIP_RATE_HZ,
+ d_prs_code_gen->get_code_length() );
+
+
+ d_subcarrier_phase_halfcycles_prs = std::fmod( curr_tow,
+ 1.0/Galileo_E1_A_SUB_CARRIER_RATE_HZ ) * 2.0 * Galileo_E1_A_SUB_CARRIER_RATE_HZ;
+
+ d_rem_carr_phase_rad_prs = d_rem_carr_phase_rad + M_PI/2.0;
+
+ d_code_freq_chips_prs = d_code_freq_chips * Galileo_E1_A_CODE_CHIP_RATE_HZ /
+ Galileo_E1_CODE_CHIP_RATE_HZ;
+
+ d_subcarrier_freq_cycles_prs = d_subcarrier_freq_cycles * Galileo_E1_A_SUB_CARRIER_RATE_HZ /
+ Galileo_E1_SUB_CARRIER_A_RATE_HZ;
+
+ d_carrier_doppler_hz_prs = d_carrier_doppler_hz;
+
+
+ // Initialise the filters:
+ // TODO:
+
+
+ std::string sys_ = &d_acquisition_gnss_synchro->System;
+ sys = sys_.substr(0, 1);
+
+ // DEBUG OUTPUT
+ std::cout << "PRS tracking start on channel " << d_channel << " for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << std::endl;
+ LOG(INFO) << "Starting tracking of PRS for satellite " << Gnss_Satellite(systemName[sys], d_acquisition_gnss_synchro->PRN) << " on channel " << d_channel;
+
+ DLOG(INFO) << "Starting params: current TOW estimate: " << curr_tow
+ << " Code phase " << d_code_phase_chips_prs << " chips."
+ << " Subcarrier Phase " << ( d_subcarrier_phase_halfcycles_prs*2.0 ) << " cycles"
+ << " Last TOW: " << d_last_tow << " @ " << d_timestamp_last_tow
+ << " Correction: " << (curr_tow - d_last_tow);
+ // enable tracking
+ d_prs_tracking_enabled = true;
+ d_prs_code_gen->set_prn( d_acquisition_gnss_synchro->PRN );
+
+
+ LOG(INFO) << "PULL-IN Doppler [Hz]=" << d_carrier_doppler_hz_prs
+ << " PULL-IN Code Phase [samples]=" << d_code_phase_chips_prs;
+}
+
+void galileo_e1_prs_de_tracking_cc::handle_gnss_message( pmt::pmt_t msg )
+{
+ std::string telem_msg = gnss_message::get_message( msg );
+
+ std::stringstream log_str("");
+
+ log_str << "Received message " << telem_msg
+ << " with timestamp: " << gnss_message::get_timestamp( msg );
+
+ pmt::pmt_t not_found;
+
+ if( gnss_message::get_message( msg ) == "TOW_ACQUIRED" ){
+ d_tow_received = true;
+ d_last_tow = pmt::to_double( pmt::dict_ref( msg, pmt::mp( "TOW" ), not_found ) ) ;
+ log_str << ". TOW: " << d_last_tow;
+ d_timestamp_last_tow = gnss_message::get_timestamp( msg );
+
+ if( !d_prs_tracking_enabled )
+ {
+ log_str << ". Enabling PRS tracking.";
+ start_tracking_prs();
+ }
+ }
+
+ LOG(INFO) << log_str.str();
+
+
+}
diff --git a/src/algorithms/tracking/gnuradio_blocks/galileo_e1_prs_de_tracking_cc.h b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_prs_de_tracking_cc.h
new file mode 100644
index 000000000..2279595e6
--- /dev/null
+++ b/src/algorithms/tracking/gnuradio_blocks/galileo_e1_prs_de_tracking_cc.h
@@ -0,0 +1,268 @@
+/*!
+ * \file galileo_e1_prs_de_tracking_cc.h
+ * \brief Implementation of Double Estimator tracking for Galileo E1 PRS
+ * \author Cillian O'Driscoll, 2015. cillian.odriscoll(at)gmail.com
+ *
+ * -------------------------------------------------------------------------
+ *
+ * Copyright (C) 2010-2015 (see AUTHORS file for a list of contributors)
+ *
+ * GNSS-SDR is a software defined Global Navigation
+ * Satellite Systems receiver
+ *
+ * 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 GNSS_SDR_GALILEO_E1_PRS_DE_TRACKING_CC_H
+#define GNSS_SDR_GALILEO_E1_PRS_DE_TRACKING_CC_H
+
+#include
+#include
+#include
+#include