2017-04-12 15:04:51 +00:00
|
|
|
/*!
|
|
|
|
* \file observables_dump_reader.cc
|
|
|
|
* \brief Helper file for unit testing
|
|
|
|
* \author Javier Arribas, 2017. jarribas(at)cttc.es
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2019-07-26 10:38:20 +00:00
|
|
|
* Copyright (C) 2010-2019 (see AUTHORS file for a list of contributors)
|
2017-04-12 15:04:51 +00:00
|
|
|
*
|
|
|
|
* 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
|
2018-05-13 20:49:11 +00:00
|
|
|
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
|
2017-04-12 15:04:51 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "observables_dump_reader.h"
|
2019-02-10 20:55:51 +00:00
|
|
|
#include <exception>
|
2018-02-25 21:49:06 +00:00
|
|
|
#include <iostream>
|
2018-12-03 18:01:47 +00:00
|
|
|
#include <utility>
|
2017-04-12 15:04:51 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
bool Observables_Dump_Reader::read_binary_obs()
|
2017-04-12 15:04:51 +00:00
|
|
|
{
|
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < n_channels; i++)
|
2017-10-28 22:44:38 +00:00
|
|
|
{
|
|
|
|
d_dump_file.read(reinterpret_cast<char *>(&RX_time[i]), sizeof(double));
|
|
|
|
d_dump_file.read(reinterpret_cast<char *>(&TOW_at_current_symbol_s[i]), sizeof(double));
|
|
|
|
d_dump_file.read(reinterpret_cast<char *>(&Carrier_Doppler_hz[i]), sizeof(double));
|
|
|
|
d_dump_file.read(reinterpret_cast<char *>(&Acc_carrier_phase_hz[i]), sizeof(double));
|
|
|
|
d_dump_file.read(reinterpret_cast<char *>(&Pseudorange_m[i]), sizeof(double));
|
|
|
|
d_dump_file.read(reinterpret_cast<char *>(&PRN[i]), sizeof(double));
|
|
|
|
d_dump_file.read(reinterpret_cast<char *>(&valid[i]), sizeof(double));
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2017-04-12 15:04:51 +00:00
|
|
|
catch (const std::ifstream::failure &e)
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2017-04-12 15:04:51 +00:00
|
|
|
return false;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2017-04-12 15:04:51 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-08-19 10:45:19 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
bool Observables_Dump_Reader::restart()
|
2017-04-12 15:04:51 +00:00
|
|
|
{
|
|
|
|
if (d_dump_file.is_open())
|
|
|
|
{
|
|
|
|
d_dump_file.clear();
|
|
|
|
d_dump_file.seekg(0, std::ios::beg);
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
return false;
|
2017-04-12 15:04:51 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 10:45:19 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
int64_t Observables_Dump_Reader::num_epochs()
|
2017-04-12 15:04:51 +00:00
|
|
|
{
|
|
|
|
std::ifstream::pos_type size;
|
2017-08-19 10:45:19 +00:00
|
|
|
int number_of_vars_in_epoch = n_channels * 7;
|
2017-04-12 15:04:51 +00:00
|
|
|
int epoch_size_bytes = sizeof(double) * number_of_vars_in_epoch;
|
2018-03-03 01:03:39 +00:00
|
|
|
std::ifstream tmpfile(d_dump_filename.c_str(), std::ios::binary | std::ios::ate);
|
2017-04-12 15:04:51 +00:00
|
|
|
if (tmpfile.is_open())
|
|
|
|
{
|
|
|
|
size = tmpfile.tellg();
|
2018-08-10 19:16:10 +00:00
|
|
|
int64_t nepoch = size / epoch_size_bytes;
|
2017-04-12 15:04:51 +00:00
|
|
|
return nepoch;
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
return 0;
|
2017-04-12 15:04:51 +00:00
|
|
|
}
|
|
|
|
|
2017-08-19 10:45:19 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
bool Observables_Dump_Reader::open_obs_file(std::string out_file)
|
2017-04-12 15:04:51 +00:00
|
|
|
{
|
|
|
|
if (d_dump_file.is_open() == false)
|
|
|
|
{
|
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2018-12-03 18:01:47 +00:00
|
|
|
d_dump_filename = std::move(out_file);
|
2018-03-03 01:03:39 +00:00
|
|
|
d_dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
2017-04-12 15:04:51 +00:00
|
|
|
d_dump_file.open(d_dump_filename.c_str(), std::ios::in | std::ios::binary);
|
|
|
|
return true;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
std::cout << "Problem opening Observables dump Log file: " << d_dump_filename << std::endl;
|
2017-04-12 15:04:51 +00:00
|
|
|
return false;
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2017-04-12 15:04:51 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 20:55:51 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
void Observables_Dump_Reader::close_obs_file()
|
2018-06-19 15:51:22 +00:00
|
|
|
{
|
|
|
|
if (d_dump_file.is_open() == false)
|
|
|
|
{
|
|
|
|
d_dump_file.close();
|
|
|
|
}
|
|
|
|
}
|
2017-08-19 10:45:19 +00:00
|
|
|
|
2019-02-10 20:55:51 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
Observables_Dump_Reader::Observables_Dump_Reader(int n_channels_)
|
2017-04-12 15:04:51 +00:00
|
|
|
{
|
2017-08-19 10:45:19 +00:00
|
|
|
n_channels = n_channels_;
|
|
|
|
RX_time = new double[n_channels];
|
|
|
|
TOW_at_current_symbol_s = new double[n_channels];
|
|
|
|
Carrier_Doppler_hz = new double[n_channels];
|
|
|
|
Acc_carrier_phase_hz = new double[n_channels];
|
|
|
|
Pseudorange_m = new double[n_channels];
|
|
|
|
PRN = new double[n_channels];
|
|
|
|
valid = new double[n_channels];
|
2017-04-12 15:04:51 +00:00
|
|
|
}
|
2017-08-19 10:45:19 +00:00
|
|
|
|
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
Observables_Dump_Reader::~Observables_Dump_Reader()
|
2017-04-12 15:04:51 +00:00
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
try
|
2017-04-12 15:04:51 +00:00
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
if (d_dump_file.is_open() == true)
|
|
|
|
{
|
|
|
|
d_dump_file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
|
|
|
std::cerr << "Problem closing Observables dump Log file: " << d_dump_filename << '\n';
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << '\n';
|
2017-04-12 15:04:51 +00:00
|
|
|
}
|
|
|
|
delete[] RX_time;
|
|
|
|
delete[] TOW_at_current_symbol_s;
|
|
|
|
delete[] Carrier_Doppler_hz;
|
|
|
|
delete[] Acc_carrier_phase_hz;
|
|
|
|
delete[] Pseudorange_m;
|
|
|
|
delete[] PRN;
|
2017-07-28 16:24:36 +00:00
|
|
|
delete[] valid;
|
2017-04-12 15:04:51 +00:00
|
|
|
}
|