1
0
mirror of https://github.com/gnss-sdr/gnss-sdr synced 2024-12-16 05:00:35 +00:00
gnss-sdr/src/tests/unit-tests/signal-processing-blocks/libs/tlm_dump_reader.cc

123 lines
3.6 KiB
C++
Raw Normal View History

2017-02-02 19:05:15 +00:00
/*!
* \file tlm_dump_reader.cc
* \brief Helper file for unit testing
* \author Javier Arribas, 2017. jarribas(at)cttc.es
*
* -------------------------------------------------------------------------
*
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
2017-02-02 19:05:15 +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
* along with GNSS-SDR. If not, see <https://www.gnu.org/licenses/>.
2017-02-02 19:05:15 +00:00
*
* -------------------------------------------------------------------------
*/
#include "tlm_dump_reader.h"
#include <exception>
#include <iostream>
#include <utility>
bool tlm_dump_reader::read_binary_obs()
2017-02-02 19:05:15 +00:00
{
try
{
2017-08-19 10:45:19 +00:00
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));
2017-08-19 10:45:19 +00:00
d_dump_file.read(reinterpret_cast<char *>(&d_TOW_at_Preamble), sizeof(double));
}
2017-02-02 19:05:15 +00:00
catch (const std::ifstream::failure &e)
{
return false;
}
2017-02-02 19:05:15 +00:00
return true;
}
2017-08-19 10:45:19 +00:00
2017-02-02 19:05:15 +00:00
bool tlm_dump_reader::restart()
{
if (d_dump_file.is_open())
2017-02-02 19:05:15 +00:00
{
d_dump_file.clear();
d_dump_file.seekg(0, std::ios::beg);
return true;
}
return false;
}
2017-08-19 10:45:19 +00:00
int64_t tlm_dump_reader::num_epochs()
{
std::ifstream::pos_type size;
2017-07-12 19:54:47 +00:00
int number_of_vars_in_epoch = 2;
int epoch_size_bytes = sizeof(double) * number_of_vars_in_epoch + sizeof(uint64_t);
std::ifstream tmpfile(d_dump_filename.c_str(), std::ios::binary | std::ios::ate);
if (tmpfile.is_open())
{
size = tmpfile.tellg();
int64_t nepoch = size / epoch_size_bytes;
return nepoch;
2017-02-02 19:05:15 +00:00
}
return 0;
}
2017-08-19 10:45:19 +00:00
2017-02-02 19:05:15 +00:00
bool tlm_dump_reader::open_obs_file(std::string out_file)
{
if (d_dump_file.is_open() == false)
{
2017-02-02 19:05:15 +00:00
try
{
d_dump_filename = std::move(out_file);
d_dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
2017-02-02 19:05:15 +00:00
d_dump_file.open(d_dump_filename.c_str(), std::ios::in | std::ios::binary);
std::cout << "TLM dump enabled, Log file: " << d_dump_filename.c_str() << std::endl;
2017-02-02 19:05:15 +00:00
return true;
}
catch (const std::ifstream::failure &e)
{
std::cout << "Problem opening TLM dump Log file: " << d_dump_filename << std::endl;
2017-02-02 19:05:15 +00:00
return false;
}
}
2017-02-02 19:05:15 +00:00
else
{
return false;
}
}
2017-08-19 10:45:19 +00:00
2017-02-02 19:05:15 +00:00
tlm_dump_reader::~tlm_dump_reader()
{
try
{
if (d_dump_file.is_open() == true)
{
d_dump_file.close();
}
}
catch (const std::ifstream::failure &e)
{
std::cerr << "Problem closing TLM dump Log file: " << d_dump_filename << '\n';
}
catch (const std::exception &e)
2017-02-02 19:05:15 +00:00
{
std::cerr << e.what() << '\n';
2017-02-02 19:05:15 +00:00
}
}