1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-06-29 00:13:14 +00:00
gnss-sdr/src/algorithms/observables/gnuradio_blocks/hybrid_observables_cc.cc

612 lines
25 KiB
C++
Raw Normal View History

/*!
* \file hybrid_observables_cc.cc
2018-04-03 21:45:06 +00:00
* \brief Implementation of the observables computation block
* \author Javier Arribas 2017. jarribas(at)cttc.es
2018-02-20 10:28:34 +00:00
* \author Antonio Ramos 2018. antonio.ramos(at)cttc.es
*
* -------------------------------------------------------------------------
*
2018-02-20 10:28:34 +00:00
* Copyright (C) 2010-2018 (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
2015-01-08 18:49:59 +00:00
* (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 <http://www.gnu.org/licenses/>.
*
* -------------------------------------------------------------------------
*/
#include "hybrid_observables_cc.h"
2018-04-03 21:45:06 +00:00
#include "display.h"
#include "GPS_L1_CA.h"
#include <armadillo>
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
2016-01-04 17:06:54 +00:00
using google::LogMessage;
2018-02-16 17:10:48 +00:00
hybrid_observables_cc_sptr hybrid_make_observables_cc(unsigned int nchannels_in, unsigned int nchannels_out, bool dump, std::string dump_filename)
{
2018-02-16 17:10:48 +00:00
return hybrid_observables_cc_sptr(new hybrid_observables_cc(nchannels_in, nchannels_out, dump, dump_filename));
}
2018-04-03 21:45:06 +00:00
hybrid_observables_cc::hybrid_observables_cc(unsigned int nchannels_in,
unsigned int nchannels_out,
bool dump,
std::string dump_filename) : gr::block("hybrid_observables_cc",
gr::io_signature::make(nchannels_in, nchannels_in, sizeof(Gnss_Synchro)),
gr::io_signature::make(nchannels_out, nchannels_out, sizeof(Gnss_Synchro)))
{
d_dump = dump;
2018-02-13 17:16:03 +00:00
d_nchannels = nchannels_out;
d_dump_filename = dump_filename;
T_rx_s = 0.0;
2018-03-08 17:32:55 +00:00
T_rx_step_s = 0.001; // 1 ms
2018-04-11 11:35:01 +00:00
max_delta = 3.5; // 3.5 s
2018-04-11 10:49:22 +00:00
d_latency = 0.08; // 80 ms
2018-02-16 17:10:48 +00:00
valid_channels.resize(d_nchannels, false);
d_num_valid_channels = 0;
2018-04-11 11:35:01 +00:00
d_gnss_synchro_history = new Gnss_circular_deque<Gnss_Synchro>(static_cast<unsigned int>(max_delta * 1000.0), d_nchannels);
// ############# ENABLE DATA FILE LOG #################
2018-02-16 17:10:48 +00:00
if (d_dump)
{
2018-03-08 17:32:55 +00:00
if (!d_dump_file.is_open())
{
try
{
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) << "Observables dump enabled Log file: " << d_dump_filename.c_str();
}
catch (const std::ifstream::failure &e)
{
LOG(WARNING) << "Exception opening observables dump file " << e.what();
d_dump = false;
}
}
}
}
hybrid_observables_cc::~hybrid_observables_cc()
{
2018-04-09 16:02:07 +00:00
delete d_gnss_synchro_history;
2018-02-16 17:10:48 +00:00
if (d_dump_file.is_open())
2018-03-08 17:32:55 +00:00
{
try
{
d_dump_file.close();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
std::cout << "Writing observables .mat files ...";
save_matfile();
std::cout << " done." << std::endl;
}
}
int hybrid_observables_cc::save_matfile()
{
// READ DUMP FILE
std::ifstream::pos_type size;
int number_of_double_vars = 7;
int epoch_size_bytes = sizeof(double) * number_of_double_vars * d_nchannels;
std::ifstream dump_file;
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
2018-03-08 17:32:55 +00:00
try
{
dump_file.open(d_dump_filename.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << std::endl;
return 1;
}
// count number of epochs and rewind
long int num_epoch = 0;
if (dump_file.is_open())
2018-01-17 18:02:52 +00:00
{
size = dump_file.tellg();
num_epoch = static_cast<long int>(size) / static_cast<long int>(epoch_size_bytes);
dump_file.seekg(0, std::ios::beg);
}
2018-03-08 17:32:55 +00:00
else
{
return 1;
}
double **RX_time = new double *[d_nchannels];
double **TOW_at_current_symbol_s = new double *[d_nchannels];
double **Carrier_Doppler_hz = new double *[d_nchannels];
double **Carrier_phase_cycles = new double *[d_nchannels];
double **Pseudorange_m = new double *[d_nchannels];
double **PRN = new double *[d_nchannels];
double **Flag_valid_pseudorange = new double *[d_nchannels];
for (unsigned int i = 0; i < d_nchannels; i++)
2018-01-17 18:02:52 +00:00
{
RX_time[i] = new double[num_epoch];
2018-01-17 18:02:52 +00:00
TOW_at_current_symbol_s[i] = new double[num_epoch];
Carrier_Doppler_hz[i] = new double[num_epoch];
Carrier_phase_cycles[i] = new double[num_epoch];
Pseudorange_m[i] = new double[num_epoch];
PRN[i] = new double[num_epoch];
Flag_valid_pseudorange[i] = new double[num_epoch];
}
try
{
2018-01-17 18:02:52 +00:00
if (dump_file.is_open())
{
for (long int i = 0; i < num_epoch; i++)
2018-01-17 18:02:52 +00:00
{
for (unsigned int chan = 0; chan < d_nchannels; chan++)
2018-01-17 18:02:52 +00:00
{
dump_file.read(reinterpret_cast<char *>(&RX_time[chan][i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_s[chan][i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&Carrier_Doppler_hz[chan][i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&Carrier_phase_cycles[chan][i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&Pseudorange_m[chan][i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&PRN[chan][i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&Flag_valid_pseudorange[chan][i]), sizeof(double));
}
}
}
2018-01-17 18:02:52 +00:00
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << std::endl;
for (unsigned int i = 0; i < d_nchannels; i++)
2018-01-17 18:02:52 +00:00
{
delete[] RX_time[i];
delete[] TOW_at_current_symbol_s[i];
delete[] Carrier_Doppler_hz[i];
delete[] Carrier_phase_cycles[i];
delete[] Pseudorange_m[i];
delete[] PRN[i];
delete[] Flag_valid_pseudorange[i];
}
delete[] RX_time;
delete[] TOW_at_current_symbol_s;
delete[] Carrier_Doppler_hz;
delete[] Carrier_phase_cycles;
delete[] Pseudorange_m;
delete[] PRN;
delete[] Flag_valid_pseudorange;
return 1;
}
double *RX_time_aux = new double[d_nchannels * num_epoch];
double *TOW_at_current_symbol_s_aux = new double[d_nchannels * num_epoch];
double *Carrier_Doppler_hz_aux = new double[d_nchannels * num_epoch];
double *Carrier_phase_cycles_aux = new double[d_nchannels * num_epoch];
double *Pseudorange_m_aux = new double[d_nchannels * num_epoch];
double *PRN_aux = new double[d_nchannels * num_epoch];
double *Flag_valid_pseudorange_aux = new double[d_nchannels * num_epoch];
unsigned int k = 0;
for (long int j = 0; j < num_epoch; j++)
{
for (unsigned int i = 0; i < d_nchannels; i++)
2018-01-17 18:02:52 +00:00
{
RX_time_aux[k] = RX_time[i][j];
TOW_at_current_symbol_s_aux[k] = TOW_at_current_symbol_s[i][j];
Carrier_Doppler_hz_aux[k] = Carrier_Doppler_hz[i][j];
Carrier_phase_cycles_aux[k] = Carrier_phase_cycles[i][j];
Pseudorange_m_aux[k] = Pseudorange_m[i][j];
PRN_aux[k] = PRN[i][j];
Flag_valid_pseudorange_aux[k] = Flag_valid_pseudorange[i][j];
k++;
}
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = d_dump_filename;
2018-03-08 17:32:55 +00:00
if (filename.size() > 4)
{
filename.erase(filename.end() - 4, filename.end());
}
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), NULL, MAT_FT_MAT73);
if (reinterpret_cast<long *>(matfp) != NULL)
2018-01-17 18:02:52 +00:00
{
size_t dims[2] = {static_cast<size_t>(d_nchannels), static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("RX_time", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, RX_time_aux, MAT_F_DONT_COPY_DATA);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
2018-01-17 18:02:52 +00:00
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_current_symbol_s", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, TOW_at_current_symbol_s_aux, MAT_F_DONT_COPY_DATA);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
2018-01-17 18:02:52 +00:00
Mat_VarFree(matvar);
matvar = Mat_VarCreate("Carrier_Doppler_hz", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, Carrier_Doppler_hz_aux, MAT_F_DONT_COPY_DATA);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
2018-01-17 18:02:52 +00:00
Mat_VarFree(matvar);
matvar = Mat_VarCreate("Carrier_phase_cycles", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, Carrier_phase_cycles_aux, MAT_F_DONT_COPY_DATA);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
2018-01-17 18:02:52 +00:00
Mat_VarFree(matvar);
matvar = Mat_VarCreate("Pseudorange_m", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, Pseudorange_m_aux, MAT_F_DONT_COPY_DATA);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
2018-01-17 18:02:52 +00:00
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, PRN_aux, MAT_F_DONT_COPY_DATA);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
2018-01-17 18:02:52 +00:00
Mat_VarFree(matvar);
matvar = Mat_VarCreate("Flag_valid_pseudorange", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims, Flag_valid_pseudorange_aux, MAT_F_DONT_COPY_DATA);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
2018-01-17 18:02:52 +00:00
Mat_VarFree(matvar);
}
Mat_Close(matfp);
for (unsigned int i = 0; i < d_nchannels; i++)
2018-01-17 18:02:52 +00:00
{
delete[] RX_time[i];
delete[] TOW_at_current_symbol_s[i];
delete[] Carrier_Doppler_hz[i];
delete[] Carrier_phase_cycles[i];
delete[] Pseudorange_m[i];
delete[] PRN[i];
delete[] Flag_valid_pseudorange[i];
}
delete[] RX_time;
delete[] TOW_at_current_symbol_s;
delete[] Carrier_Doppler_hz;
delete[] Carrier_phase_cycles;
delete[] Pseudorange_m;
delete[] PRN;
delete[] Flag_valid_pseudorange;
delete[] RX_time_aux;
delete[] TOW_at_current_symbol_s_aux;
delete[] Carrier_Doppler_hz_aux;
delete[] Carrier_phase_cycles_aux;
delete[] Pseudorange_m_aux;
delete[] PRN_aux;
delete[] Flag_valid_pseudorange_aux;
return 0;
}
2018-04-03 21:45:06 +00:00
2018-04-11 11:35:01 +00:00
bool hybrid_observables_cc::interpolate_data(Gnss_Synchro &out, const unsigned int &ch, const double &ti)
2018-02-16 17:10:48 +00:00
{
2018-04-11 11:35:01 +00:00
if ((ti < d_gnss_synchro_history->front(ch).RX_time) or (ti > d_gnss_synchro_history->back(ch).RX_time))
2018-03-08 17:32:55 +00:00
{
return false;
}
2018-04-11 11:35:01 +00:00
std::pair<unsigned int, unsigned int> ind = find_interp_elements(ch, ti);
2018-04-11 11:35:01 +00:00
//Linear interpolation: y(t) = y(t1) + (y(t2) - y(t1)) * (t - t1) / (t2 - t1)
2018-04-10 14:05:22 +00:00
2018-04-11 11:35:01 +00:00
// CARRIER PHASE INTERPOLATION
2018-04-10 14:05:22 +00:00
2018-04-11 11:35:01 +00:00
out.Carrier_phase_rads = d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads + (d_gnss_synchro_history->at(ch, ind.second).Carrier_phase_rads - d_gnss_synchro_history->at(ch, ind.first).Carrier_phase_rads) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time);
2018-04-11 11:35:01 +00:00
// CARRIER DOPPLER INTERPOLATION
out.Carrier_Doppler_hz = d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz + (d_gnss_synchro_history->at(ch, ind.second).Carrier_Doppler_hz - d_gnss_synchro_history->at(ch, ind.first).Carrier_Doppler_hz) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time);
// TOW INTERPOLATION
out.TOW_at_current_symbol_s = d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s + (d_gnss_synchro_history->at(ch, ind.second).TOW_at_current_symbol_s - d_gnss_synchro_history->at(ch, ind.first).TOW_at_current_symbol_s) * (ti - d_gnss_synchro_history->at(ch, ind.first).RX_time) / (d_gnss_synchro_history->at(ch, ind.second).RX_time - d_gnss_synchro_history->at(ch, ind.first).RX_time);
return true;
2018-02-16 17:10:48 +00:00
}
2018-04-03 21:45:06 +00:00
2018-03-08 17:32:55 +00:00
double hybrid_observables_cc::compute_T_rx_s(const Gnss_Synchro &a)
2014-06-13 16:38:16 +00:00
{
2018-03-08 17:32:55 +00:00
if (a.Flag_valid_word)
{
return ((static_cast<double>(a.Tracking_sample_counter) + a.Code_phase_samples) / static_cast<double>(a.fs));
}
else
{
return 0.0;
}
2018-02-16 17:10:48 +00:00
}
2018-04-11 11:35:01 +00:00
std::pair<unsigned int, unsigned int> hybrid_observables_cc::find_interp_elements(const unsigned int &ch, const double &ti)
{
unsigned int closest = 0;
double dif = std::numeric_limits<double>::max();
double dt = 0.0;
for (unsigned int i = 0; i < d_gnss_synchro_history->size(ch); i++)
{
dt = ti - d_gnss_synchro_history->at(ch, i).RX_time;
if (dt < dif and dt > 0.0)
{
dif = dt;
closest = i;
}
}
unsigned int index1;
unsigned int index2;
if (closest == 0)
{
index1 = 0;
index2 = 1;
}
else if (closest == (d_gnss_synchro_history->size(ch) - 1))
{
index1 = d_gnss_synchro_history->size(ch) - 2;
index2 = d_gnss_synchro_history->size(ch) - 1;
}
else
{
index1 = closest;
index2 = closest + 1;
}
return std::pair<unsigned int, unsigned int>(index1, index2);
}
2018-02-16 17:10:48 +00:00
void hybrid_observables_cc::forecast(int noutput_items __attribute__((unused)),
2018-03-08 17:32:55 +00:00
gr_vector_int &ninput_items_required)
{
2018-03-08 17:32:55 +00:00
for (unsigned int i = 0; i < d_nchannels; i++)
{
ninput_items_required[i] = 0;
}
2018-02-19 16:20:34 +00:00
ninput_items_required[d_nchannels] = 1;
}
2018-04-03 21:45:06 +00:00
2018-04-11 11:35:01 +00:00
void hybrid_observables_cc::clean_history(unsigned int pos)
2018-02-19 16:20:34 +00:00
{
2018-04-11 11:35:01 +00:00
while (d_gnss_synchro_history->size(pos) > 0)
2018-03-08 17:32:55 +00:00
{
2018-04-11 11:35:01 +00:00
if ((T_rx_s - d_gnss_synchro_history->front(pos).RX_time) > max_delta)
2018-03-08 17:32:55 +00:00
{
2018-04-11 11:35:01 +00:00
d_gnss_synchro_history->pop_front(pos);
2018-03-08 17:32:55 +00:00
}
else
{
return;
}
}
2018-02-19 16:20:34 +00:00
}
2018-04-03 21:45:06 +00:00
2018-03-08 17:32:55 +00:00
void hybrid_observables_cc::correct_TOW_and_compute_prange(std::vector<Gnss_Synchro> &data)
2018-02-19 16:20:34 +00:00
{
std::vector<Gnss_Synchro>::iterator it;
2018-02-23 09:50:22 +00:00
/////////////////////// DEBUG //////////////////////////
2018-02-23 15:17:51 +00:00
// Logs if there is a pseudorange difference between
// signals of the same satellite higher than a threshold
////////////////////////////////////////////////////////
2018-02-23 11:00:20 +00:00
#ifndef NDEBUG
2018-02-23 09:50:22 +00:00
std::vector<Gnss_Synchro>::iterator it2;
2018-03-08 17:32:55 +00:00
double thr_ = 250.0 / SPEED_OF_LIGHT; // Maximum pseudorange difference = 250 meters
for (it = data.begin(); it != (data.end() - 1); it++)
{
for (it2 = it + 1; it2 != data.end(); it2++)
2018-02-23 09:50:22 +00:00
{
2018-03-08 17:32:55 +00:00
if (it->PRN == it2->PRN and it->System == it2->System)
{
double tow_dif_ = std::fabs(it->TOW_at_current_symbol_s - it2->TOW_at_current_symbol_s);
if (tow_dif_ > thr_)
{
DLOG(INFO) << "System " << it->System << ". Signals " << it->Signal << " and " << it2->Signal
<< ". TOW difference in PRN " << it->PRN
<< " = " << tow_dif_ * 1e3 << "[ms]. Equivalent to " << tow_dif_ * SPEED_OF_LIGHT
<< " meters in pseudorange";
std::cout << TEXT_RED << "System " << it->System << ". Signals " << it->Signal << " and " << it2->Signal
<< ". TOW difference in PRN " << it->PRN
<< " = " << tow_dif_ * 1e3 << "[ms]. Equivalent to " << tow_dif_ * SPEED_OF_LIGHT
<< " meters in pseudorange" << TEXT_RESET << std::endl;
}
}
2018-02-23 09:50:22 +00:00
}
}
2018-02-23 11:00:20 +00:00
#endif
2018-03-08 17:32:55 +00:00
///////////////////////////////////////////////////////////
2018-02-23 11:00:20 +00:00
2018-02-23 15:17:51 +00:00
double TOW_ref = std::numeric_limits<double>::lowest();
2018-03-08 17:32:55 +00:00
for (it = data.begin(); it != data.end(); it++)
{
2018-03-09 12:05:25 +00:00
if (it->TOW_at_current_symbol_s > TOW_ref)
2018-03-08 17:32:55 +00:00
{
TOW_ref = it->TOW_at_current_symbol_s;
}
}
for (it = data.begin(); it != data.end(); it++)
{
double traveltime_s = TOW_ref - it->TOW_at_current_symbol_s + GPS_STARTOFFSET_ms / 1000.0;
it->RX_time = TOW_ref + GPS_STARTOFFSET_ms / 1000.0;
it->Pseudorange_m = traveltime_s * SPEED_OF_LIGHT;
}
}
2017-05-11 04:15:06 +00:00
2018-01-17 18:02:52 +00:00
2018-02-16 17:10:48 +00:00
int hybrid_observables_cc::general_work(int noutput_items __attribute__((unused)),
2018-03-08 17:32:55 +00:00
gr_vector_int &ninput_items, gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
2018-03-08 17:32:55 +00:00
const Gnss_Synchro **in = reinterpret_cast<const Gnss_Synchro **>(&input_items[0]);
Gnss_Synchro **out = reinterpret_cast<Gnss_Synchro **>(&output_items[0]);
2018-02-16 17:10:48 +00:00
unsigned int i;
int total_input_items = 0;
2018-03-08 17:32:55 +00:00
for (i = 0; i < d_nchannels; i++)
{
total_input_items += ninput_items[i];
}
2018-02-19 16:20:34 +00:00
consume(d_nchannels, 1);
2018-02-22 10:14:57 +00:00
T_rx_s += T_rx_step_s;
2018-02-16 17:10:48 +00:00
//////////////////////////////////////////////////////////////////////////
2018-03-08 17:32:55 +00:00
if ((total_input_items == 0) and (d_num_valid_channels == 0))
{
return 0;
}
2018-02-16 17:10:48 +00:00
//////////////////////////////////////////////////////////////////////////
2018-02-16 17:10:48 +00:00
if (total_input_items > 0)
2018-03-08 17:32:55 +00:00
{
2018-04-11 11:35:01 +00:00
for (i = 0; i < d_nchannels; i++)
2018-02-19 09:29:12 +00:00
{
2018-03-08 17:32:55 +00:00
if (ninput_items[i] > 0)
2018-02-20 09:58:56 +00:00
{
2018-03-08 17:32:55 +00:00
// Add the new Gnss_Synchros to their corresponding deque
for (int aux = 0; aux < ninput_items[i]; aux++)
{
if (in[i][aux].Flag_valid_word)
{
2018-04-11 11:35:01 +00:00
d_gnss_synchro_history->push_back(i, in[i][aux]);
d_gnss_synchro_history->back(i).RX_time = compute_T_rx_s(in[i][aux]);
2018-03-08 17:32:55 +00:00
// Check if the last Gnss_Synchro comes from the same satellite as the previous ones
2018-04-11 11:35:01 +00:00
if (d_gnss_synchro_history->size(i) > 1)
2018-03-08 17:32:55 +00:00
{
2018-04-11 11:35:01 +00:00
if (d_gnss_synchro_history->front(i).PRN != d_gnss_synchro_history->back(i).PRN)
2018-03-08 17:32:55 +00:00
{
2018-04-11 11:35:01 +00:00
d_gnss_synchro_history->clear(i);
2018-03-08 17:32:55 +00:00
}
}
}
}
consume(i, ninput_items[i]);
2018-02-20 09:58:56 +00:00
}
2018-03-08 17:32:55 +00:00
}
}
for (i = 0; i < d_nchannels; i++)
{
2018-04-11 11:35:01 +00:00
if (d_gnss_synchro_history->size(i) > 2)
2018-03-08 17:32:55 +00:00
{
valid_channels[i] = true;
}
else
{
valid_channels[i] = false;
2018-02-19 09:29:12 +00:00
}
2018-02-13 17:16:03 +00:00
}
2018-02-16 17:10:48 +00:00
d_num_valid_channels = valid_channels.count();
// Check if there is any valid channel after reading the new incoming Gnss_Synchro data
2018-03-08 17:32:55 +00:00
if (d_num_valid_channels == 0)
{
return 0;
}
2018-02-16 17:10:48 +00:00
2018-03-08 17:32:55 +00:00
for (i = 0; i < d_nchannels; i++) //Discard observables with T_rx higher than the threshold
2018-02-16 17:10:48 +00:00
{
2018-03-08 17:32:55 +00:00
if (valid_channels[i])
{
2018-04-11 11:35:01 +00:00
clean_history(i);
if (d_gnss_synchro_history->size(i) < 2)
2018-03-08 17:32:55 +00:00
{
valid_channels[i] = false;
}
}
2018-02-16 17:10:48 +00:00
}
2018-02-16 17:10:48 +00:00
// Check if there is any valid channel after computing the time distance between the Gnss_Synchro data and the receiver time
2018-02-19 16:20:34 +00:00
d_num_valid_channels = valid_channels.count();
2018-04-11 10:49:22 +00:00
double T_rx_s_out = T_rx_s - d_latency;
2018-03-08 17:32:55 +00:00
if ((d_num_valid_channels == 0) or (T_rx_s_out < 0.0))
{
return 0;
}
2018-02-19 16:20:34 +00:00
std::vector<Gnss_Synchro> epoch_data;
2018-04-11 11:35:01 +00:00
for (i = 0; i < d_nchannels; i++)
2018-03-08 17:32:55 +00:00
{
if (valid_channels[i])
{
2018-04-11 11:35:01 +00:00
Gnss_Synchro interpolated_gnss_synchro = d_gnss_synchro_history->back(i);
if (interpolate_data(interpolated_gnss_synchro, i, T_rx_s_out))
2018-03-08 17:32:55 +00:00
{
epoch_data.push_back(interpolated_gnss_synchro);
}
else
{
valid_channels[i] = false;
}
}
2018-02-19 16:20:34 +00:00
}
2018-02-22 10:18:37 +00:00
d_num_valid_channels = valid_channels.count();
2018-03-08 17:32:55 +00:00
if (d_num_valid_channels == 0)
{
return 0;
}
2018-02-19 16:20:34 +00:00
correct_TOW_and_compute_prange(epoch_data);
2018-04-11 11:35:01 +00:00
std::vector<Gnss_Synchro>::iterator it = epoch_data.begin();
2018-03-08 17:32:55 +00:00
for (i = 0; i < d_nchannels; i++)
{
if (valid_channels[i])
{
2018-04-11 11:35:01 +00:00
out[i][0] = (*it);
2018-03-08 17:32:55 +00:00
out[i][0].Flag_valid_pseudorange = true;
2018-04-11 11:35:01 +00:00
it++;
2018-03-08 17:32:55 +00:00
}
else
{
out[i][0] = Gnss_Synchro();
out[i][0].Flag_valid_pseudorange = false;
}
}
if (d_dump)
{
// MULTIPLEXED FILE RECORDING - Record results to file
try
{
double tmp_double;
for (i = 0; i < d_nchannels; i++)
{
tmp_double = out[i][0].RX_time;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_double = out[i][0].TOW_at_current_symbol_s;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_double = out[i][0].Carrier_Doppler_hz;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_double = out[i][0].Carrier_phase_rads / GPS_TWO_PI;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_double = out[i][0].Pseudorange_m;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_double = static_cast<double>(out[i][0].PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_double = static_cast<double>(out[i][0].Flag_valid_pseudorange);
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
}
}
catch (const std::ifstream::failure &e)
{
LOG(WARNING) << "Exception writing observables dump file " << e.what();
d_dump = false;
}
}
2018-02-16 17:10:48 +00:00
return 1;
}