2018-08-29 16:53:03 +00:00
|
|
|
/*!
|
|
|
|
* \file spirent_motion_csv_dump_reader.cc
|
|
|
|
* \brief Helper file for unit testing
|
|
|
|
* \author Javier Arribas, 2017. jarribas(at)cttc.es
|
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2018-08-29 16:53:03 +00:00
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
|
2018-08-29 16:53:03 +00:00
|
|
|
* This file is part of GNSS-SDR.
|
|
|
|
*
|
2020-12-30 12:35:06 +00:00
|
|
|
* Copyright (C) 2010-2020 (see AUTHORS file for a list of contributors)
|
2020-02-08 00:20:02 +00:00
|
|
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
2018-08-29 16:53:03 +00:00
|
|
|
*
|
2020-07-28 14:57:15 +00:00
|
|
|
* -----------------------------------------------------------------------------
|
2018-08-29 16:53:03 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "spirent_motion_csv_dump_reader.h"
|
2018-09-04 13:51:45 +00:00
|
|
|
#include <boost/tokenizer.hpp>
|
2019-02-10 20:55:51 +00:00
|
|
|
#include <exception>
|
2018-08-29 16:53:03 +00:00
|
|
|
#include <iostream>
|
2018-12-03 18:01:47 +00:00
|
|
|
#include <utility>
|
2018-08-29 16:53:03 +00:00
|
|
|
|
2018-08-30 17:40:17 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
Spirent_Motion_Csv_Dump_Reader::Spirent_Motion_Csv_Dump_Reader()
|
2021-12-17 16:40:17 +00:00
|
|
|
: header_lines(2),
|
|
|
|
TOW_ms(0.0),
|
|
|
|
Pos_X(0.0),
|
|
|
|
Pos_Y(0.0),
|
|
|
|
Pos_Z(0.0),
|
|
|
|
Vel_X(0.0),
|
|
|
|
Vel_Y(0.0),
|
|
|
|
Vel_Z(0.0),
|
|
|
|
Acc_X(0.0),
|
|
|
|
Acc_Y(0.0),
|
|
|
|
Acc_Z(0.0),
|
|
|
|
Jerk_X(0.0),
|
|
|
|
Jerk_Y(0.0),
|
|
|
|
Jerk_Z(0.0),
|
|
|
|
Lat(0.0),
|
|
|
|
Long(0.0),
|
|
|
|
Height(0.0),
|
|
|
|
Heading(0.0),
|
|
|
|
Elevation(0.0),
|
|
|
|
Bank(0.0),
|
|
|
|
Ang_vel_X(0.0),
|
|
|
|
Ang_vel_Y(0.0),
|
|
|
|
Ang_vel_Z(0.0),
|
|
|
|
Ang_acc_X(0.0),
|
|
|
|
Ang_acc_Y(0.0),
|
|
|
|
Ang_acc_Z(0.0),
|
|
|
|
Ant1_Pos_X(0.0),
|
|
|
|
Ant1_Pos_Y(0.0),
|
|
|
|
Ant1_Pos_Z(0.0),
|
|
|
|
Ant1_Vel_X(0.0),
|
|
|
|
Ant1_Vel_Y(0.0),
|
|
|
|
Ant1_Vel_Z(0.0),
|
|
|
|
Ant1_Acc_X(0.0),
|
|
|
|
Ant1_Acc_Y(0.0),
|
|
|
|
Ant1_Acc_Z(0.0),
|
|
|
|
Ant1_Lat(0.0),
|
|
|
|
Ant1_Long(0.0),
|
|
|
|
Ant1_Height(0.0),
|
|
|
|
Ant1_DOP(0.0)
|
2018-08-30 17:40:17 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
Spirent_Motion_Csv_Dump_Reader::~Spirent_Motion_Csv_Dump_Reader()
|
2018-08-30 17:40:17 +00:00
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
try
|
2018-08-30 17:40:17 +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 Spirent CSV dump Log file: " << d_dump_filename << '\n';
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
|
|
|
{
|
|
|
|
std::cerr << e.what() << '\n';
|
2018-08-30 17:40:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
bool Spirent_Motion_Csv_Dump_Reader::read_csv_obs()
|
2018-08-29 16:53:03 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
std::vector<double> vec;
|
|
|
|
std::string line;
|
|
|
|
if (getline(d_dump_file, line))
|
|
|
|
{
|
|
|
|
boost::tokenizer<boost::escaped_list_separator<char>> tk(
|
|
|
|
line, boost::escaped_list_separator<char>('\\', ',', '\"'));
|
|
|
|
for (boost::tokenizer<boost::escaped_list_separator<char>>::iterator i(
|
|
|
|
tk.begin());
|
|
|
|
i != tk.end(); ++i)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
vec.push_back(std::stod(*i));
|
|
|
|
}
|
|
|
|
catch (const std::exception &ex)
|
|
|
|
{
|
|
|
|
vec.push_back(0.0);
|
|
|
|
}
|
|
|
|
}
|
2018-08-30 12:34:05 +00:00
|
|
|
parse_vector(vec);
|
2018-08-29 16:53:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-08-30 17:24:28 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
bool Spirent_Motion_Csv_Dump_Reader::parse_vector(std::vector<double> &vec)
|
2018-08-29 16:53:03 +00:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
TOW_ms = vec.at(n++);
|
|
|
|
Pos_X = vec.at(n++);
|
|
|
|
Pos_Y = vec.at(n++);
|
|
|
|
Pos_Z = vec.at(n++);
|
|
|
|
Vel_X = vec.at(n++);
|
|
|
|
Vel_Y = vec.at(n++);
|
|
|
|
Vel_Z = vec.at(n++);
|
|
|
|
Acc_X = vec.at(n++);
|
|
|
|
Acc_Y = vec.at(n++);
|
|
|
|
Acc_Z = vec.at(n++);
|
|
|
|
Jerk_X = vec.at(n++);
|
|
|
|
Jerk_Y = vec.at(n++);
|
|
|
|
Jerk_Z = vec.at(n++);
|
|
|
|
Lat = vec.at(n++);
|
|
|
|
Long = vec.at(n++);
|
|
|
|
Height = vec.at(n++);
|
|
|
|
Heading = vec.at(n++);
|
|
|
|
Elevation = vec.at(n++);
|
|
|
|
Bank = vec.at(n++);
|
|
|
|
Ang_vel_X = vec.at(n++);
|
|
|
|
Ang_vel_Y = vec.at(n++);
|
|
|
|
Ang_vel_Z = vec.at(n++);
|
|
|
|
Ang_acc_X = vec.at(n++);
|
|
|
|
Ang_acc_Y = vec.at(n++);
|
|
|
|
Ang_acc_Z = vec.at(n++);
|
|
|
|
Ant1_Pos_X = vec.at(n++);
|
|
|
|
Ant1_Pos_Y = vec.at(n++);
|
|
|
|
Ant1_Pos_Z = vec.at(n++);
|
|
|
|
Ant1_Vel_X = vec.at(n++);
|
|
|
|
Ant1_Vel_Y = vec.at(n++);
|
|
|
|
Ant1_Vel_Z = vec.at(n++);
|
|
|
|
Ant1_Acc_X = vec.at(n++);
|
|
|
|
Ant1_Acc_Y = vec.at(n++);
|
|
|
|
Ant1_Acc_Z = vec.at(n++);
|
|
|
|
Ant1_Lat = vec.at(n++);
|
|
|
|
Ant1_Long = vec.at(n++);
|
|
|
|
Ant1_Height = vec.at(n++);
|
|
|
|
Ant1_DOP = vec.at(n++);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (const std::exception &ex)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
2018-08-30 17:24:28 +00:00
|
|
|
|
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
bool Spirent_Motion_Csv_Dump_Reader::restart()
|
2018-08-29 16:53:03 +00:00
|
|
|
{
|
|
|
|
if (d_dump_file.is_open())
|
|
|
|
{
|
|
|
|
d_dump_file.clear();
|
|
|
|
d_dump_file.seekg(0, std::ios::beg);
|
|
|
|
std::string line;
|
|
|
|
for (int n = 0; n < header_lines; n++)
|
|
|
|
{
|
|
|
|
getline(d_dump_file, line);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
return false;
|
2018-08-29 16:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
int64_t Spirent_Motion_Csv_Dump_Reader::num_epochs()
|
2018-08-29 16:53:03 +00:00
|
|
|
{
|
2018-08-30 17:24:28 +00:00
|
|
|
int64_t nepoch = 0LL;
|
2018-08-29 16:53:03 +00:00
|
|
|
std::string line;
|
2018-08-30 12:34:05 +00:00
|
|
|
std::ifstream tmpfile(d_dump_filename.c_str());
|
2018-08-29 16:53:03 +00:00
|
|
|
if (tmpfile.is_open())
|
|
|
|
{
|
|
|
|
while (std::getline(tmpfile, line))
|
2018-08-30 12:34:05 +00:00
|
|
|
{
|
|
|
|
++nepoch;
|
|
|
|
}
|
2018-08-29 16:53:03 +00:00
|
|
|
return nepoch - header_lines;
|
|
|
|
}
|
2018-12-03 21:08:19 +00:00
|
|
|
return 0;
|
2018-08-29 16:53:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
bool Spirent_Motion_Csv_Dump_Reader::open_obs_file(std::string out_file)
|
2018-08-29 16:53:03 +00:00
|
|
|
{
|
|
|
|
if (d_dump_file.is_open() == false)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2018-12-03 18:01:47 +00:00
|
|
|
d_dump_filename = std::move(out_file);
|
2018-08-29 16:53:03 +00:00
|
|
|
d_dump_file.exceptions(std::ifstream::failbit | std::ifstream::badbit);
|
|
|
|
d_dump_file.open(d_dump_filename.c_str());
|
|
|
|
std::string line;
|
|
|
|
for (int n = 0; n < header_lines; n++)
|
|
|
|
{
|
|
|
|
getline(d_dump_file, line);
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
2020-07-07 16:53:50 +00:00
|
|
|
std::cout << "Problem opening Spirent CSV dump Log file: " << d_dump_filename << '\n';
|
2018-08-29 16:53:03 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 17:24:28 +00:00
|
|
|
|
2019-02-22 09:47:24 +00:00
|
|
|
void Spirent_Motion_Csv_Dump_Reader::close_obs_file()
|
2018-08-29 16:53:03 +00:00
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (d_dump_file.is_open() == true)
|
|
|
|
{
|
|
|
|
d_dump_file.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (const std::ifstream::failure &e)
|
|
|
|
{
|
|
|
|
std::cerr << "Problem closing Spirent CSV dump Log file: " << d_dump_filename << '\n';
|
|
|
|
}
|
|
|
|
catch (const std::exception &e)
|
2018-08-29 16:53:03 +00:00
|
|
|
{
|
2019-02-10 20:55:51 +00:00
|
|
|
std::cerr << e.what() << '\n';
|
2018-08-29 16:53:03 +00:00
|
|
|
}
|
|
|
|
}
|