1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-15 12:40:35 +00:00

Replace deque by faster boost::circular_buffer

This commit is contained in:
Carles Fernandez 2019-02-28 13:40:09 +01:00
parent abd91e0825
commit ccc9222ebe
12 changed files with 71 additions and 87 deletions

View File

@ -50,13 +50,13 @@ add_library(telemetry_decoder_gr_blocks
target_link_libraries(telemetry_decoder_gr_blocks
PUBLIC
Gnuradio::runtime
Volkgnsssdr::volkgnsssdr
telemetry_decoder_libswiftcnav
telemetry_decoder_libs
core_system_parameters
PRIVATE
Gnuradio::runtime
Volkgnsssdr::volkgnsssdr
Boost::boost
PRIVATE
Gflags::gflags
Glog::glog
)

View File

@ -117,6 +117,7 @@ beidou_b1i_telemetry_decoder_cc::beidou_b1i_telemetry_decoder_cc(
d_subframe_symbols = static_cast<double *>(volk_gnsssdr_malloc(BEIDOU_DNAV_PREAMBLE_PERIOD_SYMBOLS * sizeof(double), volk_gnsssdr_get_alignment()));
d_required_symbols = BEIDOU_DNAV_SUBFRAME_SYMBOLS * d_samples_per_symbol + d_samples_per_preamble;
d_symbol_history.set_capacity(d_required_symbols + 1);
// Generic settings
d_sample_counter = 0;
d_stat = 0;
@ -316,12 +317,8 @@ void beidou_b1i_telemetry_decoder_cc::set_satellite(const Gnss_Satellite &satell
volk_gnsssdr_free(d_secondary_code_symbols);
volk_gnsssdr_free(d_subframe_symbols);
d_samples_per_symbol = (BEIDOU_B1I_CODE_RATE_HZ / BEIDOU_B1I_CODE_LENGTH_CHIPS) / BEIDOU_D2NAV_SYMBOL_RATE_SPS;
d_symbols_per_preamble = BEIDOU_DNAV_PREAMBLE_LENGTH_SYMBOLS;
d_samples_per_preamble = BEIDOU_DNAV_PREAMBLE_LENGTH_SYMBOLS * d_samples_per_symbol;
d_secondary_code_symbols = nullptr;
d_preamble_samples = static_cast<int32_t *>(volk_gnsssdr_malloc(d_samples_per_preamble * sizeof(int32_t), volk_gnsssdr_get_alignment()));
d_preamble_period_samples = BEIDOU_DNAV_PREAMBLE_PERIOD_SYMBOLS * d_samples_per_symbol;
// Setting samples of preamble code
int32_t n = 0;
@ -401,7 +398,7 @@ int beidou_b1i_telemetry_decoder_cc::general_work(int noutput_items __attribute_
//******* preamble correlation ********
for (int32_t i = 0; i < d_samples_per_preamble; i++)
{
if (d_symbol_history.at(i) < 0) // symbols clipping
if (d_symbol_history[i] < 0) // symbols clipping
{
corr_value -= d_preamble_samples[i];
}
@ -579,11 +576,6 @@ int beidou_b1i_telemetry_decoder_cc::general_work(int noutput_items __attribute_
}
}
// remove used symbols from history
if (d_symbol_history.size() > d_required_symbols)
{
d_symbol_history.pop_front();
}
// 3. Make the output (copy the object contents to the GNURadio reserved memory)
*out[0] = current_symbol;

View File

@ -42,6 +42,7 @@
#include "beidou_dnav_utc_model.h"
#include "gnss_satellite.h"
#include "gnss_synchro.h"
#include <boost/circular_buffer.hpp>
#include <gnuradio/block.h>
#include <fstream>
#include <string>
@ -94,7 +95,7 @@ private:
uint32_t d_required_symbols;
// Storage for incoming data
std::deque<float> d_symbol_history;
boost::circular_buffer<float> d_symbol_history;
// Variables for internal functionality
uint64_t d_sample_counter; // Sample counter as an index (1,2,3,..etc) indicating number of samples processed

View File

@ -52,25 +52,6 @@ galileo_make_telemetry_decoder_cc(const Gnss_Satellite &satellite, int frame_typ
}
void galileo_telemetry_decoder_cc::viterbi_decoder(double *page_part_symbols, int32_t *page_part_bits)
{
Viterbi(page_part_bits, out0, state0, out1, state1,
page_part_symbols, KK, nn, DataLength);
}
void galileo_telemetry_decoder_cc::deinterleaver(int32_t rows, int32_t cols, const double *in, double *out)
{
for (int32_t r = 0; r < rows; r++)
{
for (int32_t c = 0; c < cols; c++)
{
out[c * rows + r] = in[r * cols + c];
}
}
}
galileo_telemetry_decoder_cc::galileo_telemetry_decoder_cc(
const Gnss_Satellite &satellite, int frame_type,
bool dump) : gr::block("galileo_telemetry_decoder_cc", gr::io_signature::make(1, 1, sizeof(Gnss_Synchro)),
@ -216,6 +197,8 @@ galileo_telemetry_decoder_cc::galileo_telemetry_decoder_cc(
d_channel = 0;
flag_TOW_set = false;
d_symbol_history.set_capacity(d_required_symbols + 1);
// vars for Viterbi decoder
int32_t max_states = 1 << mm; // 2^mm
g_encoder[0] = 121; // Polynomial G1
@ -256,6 +239,25 @@ galileo_telemetry_decoder_cc::~galileo_telemetry_decoder_cc()
}
void galileo_telemetry_decoder_cc::viterbi_decoder(double *page_part_symbols, int32_t *page_part_bits)
{
Viterbi(page_part_bits, out0, state0, out1, state1,
page_part_symbols, KK, nn, DataLength);
}
void galileo_telemetry_decoder_cc::deinterleaver(int32_t rows, int32_t cols, const double *in, double *out)
{
for (int32_t r = 0; r < rows; r++)
{
for (int32_t c = 0; c < cols; c++)
{
out[c * rows + r] = in[r * cols + c];
}
}
}
void galileo_telemetry_decoder_cc::decode_INAV_word(double *page_part_symbols, int32_t frame_length)
{
// 1. De-interleave
@ -473,11 +475,10 @@ int galileo_telemetry_decoder_cc::general_work(int noutput_items __attribute__((
if (d_symbol_history.size() > d_required_symbols)
{
// TODO Optimize me!
// ******* preamble correlation ********
for (int32_t i = 0; i < d_samples_per_preamble; i++)
{
if (d_symbol_history.at(i) < 0.0) // symbols clipping
if (d_symbol_history[i] < 0.0) // symbols clipping
{
corr_value -= d_preamble_samples[i];
}
@ -524,7 +525,7 @@ int galileo_telemetry_decoder_cc::general_work(int noutput_items __attribute__((
}
break;
}
case 2: //preamble acquired
case 2: // preamble acquired
{
if (d_sample_counter == d_preamble_index + static_cast<uint64_t>(d_preamble_period_symbols))
{
@ -534,14 +535,14 @@ int galileo_telemetry_decoder_cc::general_work(int noutput_items __attribute__((
case 1: // INAV
// NEW Galileo page part is received
// 0. fetch the symbols into an array
if (corr_value > 0) //normal PLL lock
if (corr_value > 0) // normal PLL lock
{
for (uint32_t i = 0; i < d_frame_length_symbols; i++)
{
d_page_part_symbols[i] = d_symbol_history.at(i + d_samples_per_preamble); // because last symbol of the preamble is just received now!
}
}
else //180 deg. inverted carrier phase PLL lock
else // 180 deg. inverted carrier phase PLL lock
{
for (uint32_t i = 0; i < d_frame_length_symbols; i++)
{
@ -553,7 +554,7 @@ int galileo_telemetry_decoder_cc::general_work(int noutput_items __attribute__((
case 2: // FNAV
// NEW Galileo page part is received
// 0. fetch the symbols into an array
if (corr_value > 0) //normal PLL lock
if (corr_value > 0) // normal PLL lock
{
int k = 0;
for (uint32_t i = 0; i < d_frame_length_symbols; i++)
@ -567,13 +568,13 @@ int galileo_telemetry_decoder_cc::general_work(int noutput_items __attribute__((
}
}
}
else //180 deg. inverted carrier phase PLL lock
else // 180 deg. inverted carrier phase PLL lock
{
int k = 0;
for (uint32_t i = 0; i < d_frame_length_symbols; i++)
{
d_page_part_symbols[i] = 0;
for (uint32_t m = 0; m < d_samples_per_symbol; m++) //integrate samples into symbols
for (uint32_t m = 0; m < d_samples_per_symbol; m++) // integrate samples into symbols
{
d_page_part_symbols[i] -= static_cast<float>(d_secondary_code_samples[k]) * d_symbol_history.at(i * d_samples_per_symbol + d_samples_per_preamble + m); // because last symbol of the preamble is just received now!
k++;
@ -717,13 +718,6 @@ int galileo_telemetry_decoder_cc::general_work(int noutput_items __attribute__((
}
}
// remove used symbols from history
// todo: Use circular buffer here
if (d_symbol_history.size() > d_required_symbols)
{
d_symbol_history.pop_front();
}
switch (d_frame_type)
{
case 1: // INAV

View File

@ -43,11 +43,11 @@
#include "galileo_utc_model.h"
#include "gnss_satellite.h"
#include "gnss_synchro.h"
#include <boost/circular_buffer.hpp>
#include <gnuradio/block.h>
#include <fstream>
#include <string>
class galileo_telemetry_decoder_cc;
using galileo_telemetry_decoder_cc_sptr = boost::shared_ptr<galileo_telemetry_decoder_cc>;
@ -95,7 +95,7 @@ private:
uint32_t d_frame_length_symbols;
double *d_page_part_symbols;
std::deque<float> d_symbol_history;
boost::circular_buffer<float> d_symbol_history;
uint64_t d_sample_counter;
uint64_t d_preamble_index;

View File

@ -89,6 +89,8 @@ glonass_l1_ca_telemetry_decoder_cc::glonass_l1_ca_telemetry_decoder_cc(
n++;
}
}
d_symbol_history.set_capacity(GLONASS_GNAV_PREAMBLE_LENGTH_SYMBOLS);
d_sample_counter = 0ULL;
d_stat = 0;
d_preamble_index = 0ULL;
@ -276,14 +278,14 @@ int glonass_l1_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
consume_each(1);
d_flag_preamble = false;
uint32_t required_symbols = GLONASS_GNAV_STRING_SYMBOLS;
if (d_symbol_history.size() > required_symbols)
if (d_symbol_history.size() == d_symbols_per_preamble)
{
// ******* preamble correlation ********
for (int32_t i = 0; i < d_symbols_per_preamble; i++)
int i = 0;
for (const auto &iter : d_symbol_history)
{
if (d_symbol_history.at(i).Prompt_I < 0) // symbols clipping
if (iter.Prompt_I < 0.0) // symbols clipping
{
corr_value -= d_preambles_symbols[i];
}
@ -291,6 +293,7 @@ int glonass_l1_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
{
corr_value += d_preambles_symbols[i];
}
i++;
}
}
@ -304,7 +307,7 @@ int glonass_l1_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
LOG(INFO) << "Preamble detection for GLONASS L1 C/A SAT " << this->d_satellite;
// Enter into frame pre-detection status
d_stat = 1;
d_preamble_time_samples = d_symbol_history.at(0).Tracking_sample_counter; // record the preamble sample stamp
d_preamble_time_samples = d_symbol_history[0].Tracking_sample_counter; // record the preamble sample stamp
}
}
else if (d_stat == 1) // possible preamble lock
@ -314,7 +317,7 @@ int glonass_l1_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
// check preamble separation
preamble_diff = static_cast<int32_t>(d_sample_counter - d_preamble_index);
// Record the PRN start sample index associated to the preamble
d_preamble_time_samples = static_cast<double>(d_symbol_history.at(0).Tracking_sample_counter);
d_preamble_time_samples = static_cast<double>(d_symbol_history[0].Tracking_sample_counter);
if (abs(preamble_diff - GLONASS_GNAV_PREAMBLE_PERIOD_SYMBOLS) == 0)
{
// try to decode frame
@ -366,7 +369,7 @@ int glonass_l1_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
{
d_flag_frame_sync = true;
DLOG(INFO) << " Frame sync SAT " << this->d_satellite << " with preamble start at "
<< d_symbol_history.at(0).Tracking_sample_counter << " [samples]";
<< d_symbol_history[0].Tracking_sample_counter << " [samples]";
}
}
else
@ -437,11 +440,6 @@ int glonass_l1_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
}
}
// remove used symbols from history
if (d_symbol_history.size() > required_symbols)
{
d_symbol_history.pop_front();
}
// 3. Make the output (copy the object contents to the GNURadio reserved memory)
*out[0] = current_symbol;

View File

@ -41,6 +41,7 @@
#include "glonass_gnav_utc_model.h"
#include "gnss_satellite.h"
#include "gnss_synchro.h"
#include <boost/circular_buffer.hpp>
#include <gnuradio/block.h>
#include <fstream>
#include <string>
@ -88,7 +89,7 @@ private:
int32_t d_symbols_per_preamble;
//!< Storage for incoming data
std::deque<Gnss_Synchro> d_symbol_history;
boost::circular_buffer<Gnss_Synchro> d_symbol_history;
//!< Variables for internal functionality
uint64_t d_sample_counter; //!< Sample counter as an index (1,2,3,..etc) indicating number of samples processed

View File

@ -89,6 +89,8 @@ glonass_l2_ca_telemetry_decoder_cc::glonass_l2_ca_telemetry_decoder_cc(
n++;
}
}
d_symbol_history.set_capacity(GLONASS_GNAV_PREAMBLE_PERIOD_SYMBOLS);
d_sample_counter = 0ULL;
d_stat = 0;
d_preamble_index = 0ULL;
@ -276,14 +278,14 @@ int glonass_l2_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
consume_each(1);
d_flag_preamble = false;
uint32_t required_symbols = GLONASS_GNAV_STRING_SYMBOLS;
if (d_symbol_history.size() > required_symbols)
if (d_symbol_history.size() == GLONASS_GNAV_PREAMBLE_PERIOD_SYMBOLS)
{
// ******* preamble correlation ********
for (int32_t i = 0; i < d_symbols_per_preamble; i++)
int i = 0;
for (const auto &iter : d_symbol_history)
{
if (d_symbol_history.at(i).Prompt_I < 0) // symbols clipping
if (iter.Prompt_I < 0.0) // symbols clipping
{
corr_value -= d_preambles_symbols[i];
}
@ -291,6 +293,7 @@ int glonass_l2_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
{
corr_value += d_preambles_symbols[i];
}
i++;
}
}
@ -304,7 +307,7 @@ int glonass_l2_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
LOG(INFO) << "Preamble detection for GLONASS L2 C/A SAT " << this->d_satellite;
// Enter into frame pre-detection status
d_stat = 1;
d_preamble_time_samples = d_symbol_history.at(0).Tracking_sample_counter; // record the preamble sample stamp
d_preamble_time_samples = d_symbol_history[0].Tracking_sample_counter; // record the preamble sample stamp
}
}
else if (d_stat == 1) // possible preamble lock
@ -314,7 +317,7 @@ int glonass_l2_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
// check preamble separation
preamble_diff = static_cast<int32_t>(d_sample_counter - d_preamble_index);
// Record the PRN start sample index associated to the preamble
d_preamble_time_samples = static_cast<double>(d_symbol_history.at(0).Tracking_sample_counter);
d_preamble_time_samples = static_cast<double>(d_symbol_history[0].Tracking_sample_counter);
if (abs(preamble_diff - GLONASS_GNAV_PREAMBLE_PERIOD_SYMBOLS) == 0)
{
// try to decode frame
@ -366,7 +369,7 @@ int glonass_l2_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
{
d_flag_frame_sync = true;
DLOG(INFO) << " Frame sync SAT " << this->d_satellite << " with preamble start at "
<< d_symbol_history.at(0).Tracking_sample_counter << " [samples]";
<< d_symbol_history[0].Tracking_sample_counter << " [samples]";
}
}
else
@ -437,11 +440,6 @@ int glonass_l2_ca_telemetry_decoder_cc::general_work(int noutput_items __attribu
}
}
// remove used symbols from history
if (d_symbol_history.size() > required_symbols)
{
d_symbol_history.pop_front();
}
// 3. Make the output (copy the object contents to the GNURadio reserved memory)
*out[0] = current_symbol;

View File

@ -40,6 +40,7 @@
#include "glonass_gnav_utc_model.h"
#include "gnss_satellite.h"
#include "gnss_synchro.h"
#include <boost/circular_buffer.hpp>
#include <gnuradio/block.h>
#include <fstream>
#include <string>
@ -86,7 +87,7 @@ private:
int32_t d_symbols_per_preamble;
//!< Storage for incoming data
std::deque<Gnss_Synchro> d_symbol_history;
boost::circular_buffer<Gnss_Synchro> d_symbol_history;
//!< Variables for internal functionality
uint64_t d_sample_counter; //!< Sample counter as an index (1,2,3,..etc) indicating number of samples processed

View File

@ -32,6 +32,7 @@
#define GNSS_SDR_GPS_L2C_TELEMETRY_DECODER_CC_H
#include "GPS_L2C.h"
#include "gnss_satellite.h"
#include "gps_cnav_ephemeris.h"
#include "gps_cnav_iono.h"
@ -39,13 +40,11 @@
#include <gnuradio/block.h>
#include <algorithm> // for copy
#include <cstdint>
#include <deque>
#include <fstream>
#include <string>
#include <utility> // for pair
#include <vector>
extern "C"
{
#include "bits.h"
@ -53,7 +52,6 @@ extern "C"
#include "edc.h"
}
#include "GPS_L2C.h"
class gps_l2c_telemetry_decoder_cc;

View File

@ -66,6 +66,8 @@ gps_l5_telemetry_decoder_cc::gps_l5_telemetry_decoder_cc(
d_flag_valid_word = false;
d_TOW_at_current_symbol_ms = 0U;
d_TOW_at_Preamble_ms = 0U;
sym_hist.set_capacity(GPS_L5I_NH_CODE_LENGTH);
// initialize the CNAV frame decoder (libswiftcnav)
cnav_msg_decoder_init(&d_cnav_decoder);
for (int32_t aux = 0; aux < GPS_L5I_NH_CODE_LENGTH; aux++)
@ -145,10 +147,10 @@ int gps_l5_telemetry_decoder_cc::general_work(int noutput_items __attribute__((u
const auto *in = reinterpret_cast<const Gnss_Synchro *>(input_items[0]); // Get the input buffer pointer
// UPDATE GNSS SYNCHRO DATA
Gnss_Synchro current_synchro_data{}; //structure to save the synchronization information and send the output object to the next block
Gnss_Synchro current_synchro_data{}; // structure to save the synchronization information and send the output object to the next block
// 1. Copy the current tracking output
current_synchro_data = in[0];
consume_each(1); //one by one
consume_each(1); // one by one
sym_hist.push_back(in[0].Prompt_I);
int32_t corr_NH = 0;
int32_t symbol_value = 0;
@ -158,7 +160,7 @@ int gps_l5_telemetry_decoder_cc::general_work(int noutput_items __attribute__((u
{
for (int32_t i = 0; i < GPS_L5I_NH_CODE_LENGTH; i++)
{
if ((bits_NH[i] * sym_hist.at(i)) > 0.0)
if ((bits_NH[i] * sym_hist[i]) > 0.0)
{
corr_NH += 1;
}
@ -183,7 +185,6 @@ int gps_l5_telemetry_decoder_cc::general_work(int noutput_items __attribute__((u
}
else
{
sym_hist.pop_front();
sync_NH = false;
new_sym = false;
}

View File

@ -31,12 +31,13 @@
#define GNSS_SDR_GPS_L5_TELEMETRY_DECODER_CC_H
#include "GPS_L5.h"
#include "gnss_satellite.h"
#include "gps_cnav_navigation_message.h"
#include <boost/circular_buffer.hpp>
#include <gnuradio/block.h>
#include <algorithm>
#include <cstdint>
#include <deque>
#include <fstream>
#include <string>
#include <utility>
@ -49,7 +50,6 @@ extern "C"
#include "edc.h"
}
#include "GPS_L5.h"
class gps_l5_telemetry_decoder_cc;
@ -90,8 +90,8 @@ private:
bool d_flag_valid_word;
Gps_CNAV_Navigation_Message d_CNAV_Message;
double bits_NH[GPS_L5I_NH_CODE_LENGTH]{};
std::deque<double> sym_hist;
float bits_NH[GPS_L5I_NH_CODE_LENGTH]{};
boost::circular_buffer<float> sym_hist;
bool sync_NH;
bool new_sym;
};