Improve dump of Telemetry blocks

This commit is contained in:
Carles Fernandez 2020-11-19 09:55:08 +01:00
parent 40e9d687dd
commit dd60970f32
No known key found for this signature in database
GPG Key ID: 4C583C52B0C3877D
21 changed files with 1017 additions and 30 deletions

View File

@ -85,6 +85,10 @@ SPDX-FileCopyrightText: 2011-2020 Carles Fernandez-Prades <carles.fernandez@cttc
Make use of MathJax for equation rendering. Added new building option
`ENABLE_EXTERNAL_MATHJAX`, set to `ON` by default. If set to `OFF`, it allows
using a local installation of MathJax 2.
- Improved dumps in Telemetry Decoding blocks. Now they include the raw
navigation message bits. If `TelemetryDecoder_XX.dump=true`, the resulting
`.dat` binary file is also delivered in `.mat` format, which is readable from
Matlab and Python.
&nbsp;

View File

@ -60,6 +60,7 @@ target_link_libraries(telemetry_decoder_gr_blocks
PRIVATE
Gflags::gflags
Glog::glog
Matio::matio
)
if(GNURADIO_USES_STD_POINTERS)

View File

@ -29,12 +29,14 @@
#include "gnss_synchro.h"
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <cstdlib> // for abs
#include <exception> // for exception
#include <iostream> // for cout
#include <memory> // for shared_ptr, make_shared
#include <vector>
#define CRC_ERROR_LIMIT 8
@ -115,6 +117,118 @@ beidou_b1i_telemetry_decoder_gs::~beidou_b1i_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t beidou_b1i_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -585,12 +699,17 @@ int beidou_b1i_telemetry_decoder_gs::general_work(int noutput_items __attribute_
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = static_cast<double>(d_TOW_at_current_symbol_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_symbol.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = static_cast<double>(d_TOW_at_Preamble_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_int = (current_symbol.Prompt_I > 0.0 ? 1 : -1);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_symbol.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -74,6 +74,8 @@ private:
beidou_b1i_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
int32_t save_matfile() const;
void decode_subframe(float *symbols);
void decode_word(int32_t word_counter, const float *enc_word_symbols, int32_t *dec_word_symbols);
void decode_bch15_11_01(const int32_t *bits, std::array<int32_t, 15> &decbits);

View File

@ -28,12 +28,14 @@
#include "gnss_synchro.h"
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <cstdlib> // for abs
#include <exception> // for exception
#include <iostream> // for cout
#include <memory> // for shared_ptr, make_shared
#include <vector>
#define CRC_ERROR_LIMIT 8
@ -115,6 +117,118 @@ beidou_b3i_telemetry_decoder_gs::~beidou_b3i_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t beidou_b3i_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -615,12 +729,17 @@ int beidou_b3i_telemetry_decoder_gs::general_work(
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = static_cast<double>(d_TOW_at_current_symbol_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_symbol.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = static_cast<double>(d_TOW_at_Preamble_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_int = (current_symbol.Prompt_I > 0.0 ? 1 : -1);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_symbol.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -72,6 +72,8 @@ private:
beidou_b3i_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
int32_t save_matfile() const;
void decode_subframe(float *symbols);
void decode_word(int32_t word_counter, const float *enc_word_symbols,
int32_t *dec_word_symbols);

View File

@ -34,6 +34,7 @@
#include "gnss_synchro.h"
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <cmath> // for fmod
@ -224,6 +225,119 @@ galileo_telemetry_decoder_gs::~galileo_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t galileo_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -907,12 +1021,31 @@ int galileo_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = static_cast<double>(d_TOW_at_current_symbol_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_symbol.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = static_cast<double>(d_TOW_at_Preamble_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
switch (d_frame_type)
{
case 1:
tmp_int = (current_symbol.Prompt_I > 0.0 ? 1 : -1);
break;
case 2:
tmp_int = (current_symbol.Prompt_Q > 0.0 ? 1 : -1);
break;
case 3:
tmp_int = (current_symbol.Prompt_I > 0.0 ? 1 : -1);
break;
default:
tmp_int = 0;
break;
}
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_symbol.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -82,6 +82,8 @@ private:
const int32_t d_nn = 2; // Coding rate 1/n
const int32_t d_KK = 7; // Constraint Length
int32_t save_matfile() const;
void viterbi_decoder(float *page_part_symbols, int32_t *page_part_bits);
void deinterleaver(int32_t rows, int32_t cols, const float *in, float *out);
void decode_INAV_word(float *page_part_symbols, int32_t frame_length);

View File

@ -25,6 +25,7 @@
#include "glonass_gnav_utc_model.h"
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <cmath> // for floor, round
@ -32,6 +33,7 @@
#include <exception> // for exception
#include <iostream> // for cout
#include <memory> // for shared_ptr, make_shared
#include <vector>
#define CRC_ERROR_LIMIT 6
@ -108,6 +110,118 @@ glonass_l1_ca_telemetry_decoder_gs::~glonass_l1_ca_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t glonass_l1_ca_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -414,12 +528,17 @@ int glonass_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribu
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = d_TOW_at_current_symbol;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_symbol.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = 0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_int = (current_symbol.Prompt_I > 0.0 ? 1 : -1);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_symbol.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -82,6 +82,8 @@ private:
const int32_t d_symbols_per_preamble = GLONASS_GNAV_PREAMBLE_LENGTH_SYMBOLS;
int32_t save_matfile() const;
void decode_string(const double *symbols, int32_t frame_length);
// Help with coherent tracking

View File

@ -25,6 +25,7 @@
#include "glonass_gnav_utc_model.h"
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <cmath> // for floor, round
@ -32,6 +33,7 @@
#include <exception> // for exception
#include <iostream> // for cout
#include <memory> // for shared_ptr, make_shared
#include <vector>
#define CRC_ERROR_LIMIT 6
@ -108,6 +110,118 @@ glonass_l2_ca_telemetry_decoder_gs::~glonass_l2_ca_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t glonass_l2_ca_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -413,12 +527,17 @@ int glonass_l2_ca_telemetry_decoder_gs::general_work(int noutput_items __attribu
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = d_TOW_at_current_symbol;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_symbol.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = 0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_int = (current_symbol.Prompt_I > 0.0 ? 1 : -1);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_symbol.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -80,6 +80,8 @@ private:
const int32_t d_symbols_per_preamble = GLONASS_GNAV_PREAMBLE_LENGTH_SYMBOLS;
int32_t save_matfile() const;
void decode_string(const double *symbols, int32_t frame_length);
// Storage for incoming data

View File

@ -24,6 +24,7 @@
#include "gps_utc_model.h" // for Gps_Utc_Model
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <cmath> // for round
@ -31,6 +32,7 @@
#include <exception> // for exception
#include <iostream> // for cout
#include <memory> // for shared_ptr
#include <vector>
#ifdef COMPILER_HAS_ROTL
@ -130,6 +132,118 @@ gps_l1_ca_telemetry_decoder_gs::~gps_l1_ca_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t gps_l1_ca_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -501,12 +615,17 @@ int gps_l1_ca_telemetry_decoder_gs::general_work(int noutput_items __attribute__
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = static_cast<double>(d_TOW_at_current_symbol_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_symbol.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = static_cast<double>(d_TOW_at_Preamble_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_int = (current_symbol.Prompt_I > 0.0 ? 1 : -1);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_symbol.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -72,6 +72,8 @@ private:
gps_l1_ca_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
int32_t save_matfile() const;
bool gps_word_parityCheck(uint32_t gpsword);
bool decode_subframe();

View File

@ -27,6 +27,7 @@
#include "gps_cnav_utc_model.h" // for Gps_CNAV_Utc_Model
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <bitset> // for bitset
@ -34,6 +35,7 @@
#include <exception> // for exception
#include <iostream> // for cout
#include <memory> // for shared_ptr, make_shared
#include <vector>
gps_l2c_telemetry_decoder_gs_sptr
@ -92,6 +94,118 @@ gps_l2c_telemetry_decoder_gs::~gps_l2c_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t gps_l2c_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -252,12 +366,17 @@ int gps_l2c_telemetry_decoder_gs::general_work(int noutput_items __attribute__((
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = d_TOW_at_current_symbol;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_synchro_data.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = d_TOW_at_Preamble;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_int = (current_synchro_data.Prompt_I > 0.0 ? 1 : -1);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_synchro_data.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -72,6 +72,8 @@ private:
gps_l2c_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
int32_t save_matfile() const;
Gnss_Satellite d_satellite;
cnav_msg_decoder_t d_cnav_decoder{};

View File

@ -26,6 +26,7 @@
#include "gps_cnav_utc_model.h" // for Gps_CNAV_Utc_Model
#include <glog/logging.h>
#include <gnuradio/io_signature.h>
#include <matio.h> // for Mat_VarCreate
#include <pmt/pmt.h> // for make_any
#include <pmt/pmt_sugar.h> // for mp
#include <bitset> // for std::bitset
@ -33,6 +34,7 @@
#include <exception> // for std::exception
#include <iostream> // for std::cout
#include <memory> // for shared_ptr, make_shared
#include <vector>
gps_l5_telemetry_decoder_gs_sptr
@ -87,6 +89,118 @@ gps_l5_telemetry_decoder_gs::~gps_l5_telemetry_decoder_gs()
LOG(WARNING) << "Exception in destructor closing the dump file " << ex.what();
}
}
if (d_dump)
{
try
{
save_matfile();
}
catch (const std::exception &ex)
{
LOG(WARNING) << "Error saving the .mat file: " << ex.what();
}
}
}
int32_t gps_l5_telemetry_decoder_gs::save_matfile() const
{
std::ifstream::pos_type size;
const int32_t number_of_double_vars = 2;
const int32_t number_of_int_vars = 2;
const int32_t epoch_size_bytes = sizeof(uint64_t) + sizeof(double) * number_of_double_vars +
sizeof(int32_t) * number_of_int_vars;
std::ifstream dump_file;
std::string dump_filename_ = d_dump_filename;
std::cout << "Generating .mat file for " << dump_filename_ << '\n';
dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
try
{
dump_file.open(dump_filename_.c_str(), std::ios::binary | std::ios::ate);
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem opening dump file:" << e.what() << '\n';
return 1;
}
// count number of epochs and rewind
int64_t num_epoch = 0;
if (dump_file.is_open())
{
size = dump_file.tellg();
num_epoch = static_cast<int64_t>(size) / static_cast<int64_t>(epoch_size_bytes);
if (num_epoch == 0LL)
{
// empty file, exit
return 1;
}
dump_file.seekg(0, std::ios::beg);
}
else
{
return 1;
}
auto TOW_at_current_symbol_ms = std::vector<double>(num_epoch);
auto tracking_sample_counter = std::vector<uint64_t>(num_epoch);
auto TOW_at_Preamble_ms = std::vector<double>(num_epoch);
auto nav_symbol = std::vector<int32_t>(num_epoch);
auto prn = std::vector<int32_t>(num_epoch);
try
{
if (dump_file.is_open())
{
for (int64_t i = 0; i < num_epoch; i++)
{
dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&tracking_sample_counter[i]), sizeof(uint64_t));
dump_file.read(reinterpret_cast<char *>(&TOW_at_Preamble_ms[i]), sizeof(double));
dump_file.read(reinterpret_cast<char *>(&nav_symbol[i]), sizeof(int32_t));
dump_file.read(reinterpret_cast<char *>(&prn[i]), sizeof(int32_t));
}
}
dump_file.close();
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem reading dump file:" << e.what() << '\n';
return 1;
}
// WRITE MAT FILE
mat_t *matfp;
matvar_t *matvar;
std::string filename = dump_filename_;
filename.erase(filename.length() - 4, 4);
filename.append(".mat");
matfp = Mat_CreateVer(filename.c_str(), nullptr, MAT_FT_MAT73);
if (reinterpret_cast<int64_t *>(matfp) != nullptr)
{
std::array<size_t, 2> dims{1, static_cast<size_t>(num_epoch)};
matvar = Mat_VarCreate("TOW_at_current_symbol_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_current_symbol_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("tracking_sample_counter", MAT_C_UINT64, MAT_T_UINT64, 2, dims.data(), tracking_sample_counter.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("TOW_at_Preamble_ms", MAT_C_DOUBLE, MAT_T_DOUBLE, 2, dims.data(), TOW_at_Preamble_ms.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("nav_symbol", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), nav_symbol.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
matvar = Mat_VarCreate("PRN", MAT_C_INT32, MAT_T_INT32, 2, dims.data(), prn.data(), 0);
Mat_VarWrite(matfp, matvar, MAT_COMPRESSION_ZLIB); // or MAT_COMPRESSION_NONE
Mat_VarFree(matvar);
}
Mat_Close(matfp);
return 0;
}
@ -263,12 +377,17 @@ int gps_l5_telemetry_decoder_gs::general_work(int noutput_items __attribute__((u
{
double tmp_double;
uint64_t tmp_ulong_int;
int32_t tmp_int;
tmp_double = static_cast<double>(d_TOW_at_current_symbol_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_ulong_int = current_synchro_data.Tracking_sample_counter;
d_dump_file.write(reinterpret_cast<char *>(&tmp_ulong_int), sizeof(uint64_t));
tmp_double = static_cast<double>(d_TOW_at_Preamble_ms) / 1000.0;
d_dump_file.write(reinterpret_cast<char *>(&tmp_double), sizeof(double));
tmp_int = (current_synchro_data.Prompt_Q > 0.0 ? 1 : -1);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
tmp_int = static_cast<int32_t>(current_synchro_data.PRN);
d_dump_file.write(reinterpret_cast<char *>(&tmp_int), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{

View File

@ -71,6 +71,8 @@ private:
gps_l5_telemetry_decoder_gs(const Gnss_Satellite &satellite, bool dump);
int32_t save_matfile() const;
cnav_msg_decoder_t d_cnav_decoder{};
Gnss_Satellite d_satellite;

View File

@ -29,6 +29,8 @@ bool Tlm_Dump_Reader::read_binary_obs()
d_dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol), sizeof(double));
d_dump_file.read(reinterpret_cast<char *>(&Tracking_sample_counter), sizeof(uint64_t));
d_dump_file.read(reinterpret_cast<char *>(&d_TOW_at_Preamble), sizeof(double));
d_dump_file.read(reinterpret_cast<char *>(&nav_symbol), sizeof(int32_t));
d_dump_file.read(reinterpret_cast<char *>(&prn), sizeof(int32_t));
}
catch (const std::ifstream::failure &e)
{
@ -53,8 +55,9 @@ bool Tlm_Dump_Reader::restart()
int64_t Tlm_Dump_Reader::num_epochs()
{
std::ifstream::pos_type size;
int number_of_vars_in_epoch = 2;
int epoch_size_bytes = sizeof(double) * number_of_vars_in_epoch + sizeof(uint64_t);
int number_of_double_vars_in_epoch = 2;
int number_of_int_vars_in_epoch = 2;
int epoch_size_bytes = sizeof(double) * number_of_double_vars_in_epoch + sizeof(uint64_t) + sizeof(int32_t) * number_of_int_vars_in_epoch;
std::ifstream tmpfile(d_dump_filename.c_str(), std::ios::binary | std::ios::ate);
if (tmpfile.is_open())
{

View File

@ -38,6 +38,8 @@ public:
double TOW_at_current_symbol;
uint64_t Tracking_sample_counter;
double d_TOW_at_Preamble;
int32_t nav_symbol;
int32_t prn;
private:
std::string d_dump_filename;

View File

@ -21,9 +21,11 @@ function [telemetry] = gps_l1_ca_read_telemetry_dump (filename, count)
%%
m = nargchk (1,2,nargin);
num_double_vars=4;
num_double_vars=3;
double_size_bytes=8;
skip_bytes_each_read=double_size_bytes*num_double_vars;
num_int_vars=2;
int_size_bytes=4;
skip_bytes_each_read=double_size_bytes*num_double_vars+num_int_vars*int_size_bytes;
bytes_shift=0;
if (m)
usage (m);
@ -32,34 +34,27 @@ end
if (nargin < 3)
count = Inf;
end
%loops_counter = fread (f, count, 'uint32',4*12);
f = fopen (filename, 'rb');
if (f < 0)
else
telemetry.tow_current_symbol_ms = fread (f, count, 'float64',skip_bytes_each_read-double_size_bytes);
bytes_shift=bytes_shift+double_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
telemetry.tracking_sample_counter = fread (f, count, 'uint64',skip_bytes_each_read-double_size_bytes);
bytes_shift=bytes_shift+double_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
telemetry.tow = fread (f, count, 'float64',skip_bytes_each_read-double_size_bytes);
bytes_shift=bytes_shift+double_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
telemetry.required_symbols = fread (f, count, 'uint64',skip_bytes_each_read-double_size_bytes);
bytes_shift=bytes_shift+double_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
[x, loops_counter] = fread (f,skip_bytes_each_read);
fseek(f,0,-1);
for i=1:min(count, loops_counter),
telemetry(i).tow_current_symbol_ms = fread (f, count, 'float64',skip_bytes_each_read-double_size_bytes);
bytes_shift=bytes_shift+double_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
telemetry(i).tracking_sample_counter = fread (f, count, 'uint64',skip_bytes_each_read-double_size_bytes);
bytes_shift=bytes_shift+double_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
telemetry(i).tow = fread (f, count, 'float64',skip_bytes_each_read-double_size_bytes);
bytes_shift=bytes_shift+double_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
telemetry(i).nav_simbols = fread (f, count, 'int32',skip_bytes_each_read-int_size_bytes);
bytes_shift=bytes_shift+int_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
telemetry(i).prn = fread (f, count, 'int32',skip_bytes_each_read-int_size_bytes);
bytes_shift=bytes_shift+int_size_bytes;
fseek(f,bytes_shift,'bof'); % move to next interleaved
end
fclose (f);
%%%%%%%% output vars %%%%%%%%
% {
% double tmp_double;
% tmp_double = current_synchro_data.Preamble_delay_ms;
% d_dump_file.write((char*)&tmp_double, sizeof(double));
% tmp_double = current_synchro_data.Prn_delay_ms;
% d_dump_file.write((char*)&tmp_double, sizeof(double));
% tmp_double = current_synchro_data.Preamble_symbol_counter;
% d_dump_file.write((char*)&tmp_double, sizeof(double));
% }
end