2016-09-29 16:31:22 +00:00
|
|
|
/*!
|
2018-05-28 13:42:44 +00:00
|
|
|
* \file ttff.cc
|
2016-09-29 16:31:22 +00:00
|
|
|
* \brief This class implements a test for measuring
|
|
|
|
* the Time-To-First-Fix
|
|
|
|
* \author Carles Fernandez-Prades, 2016. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
2018-05-13 20:49:11 +00:00
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
2016-09-29 16:31:22 +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/>.
|
2016-09-29 16:31:22 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
2018-02-26 02:15:53 +00:00
|
|
|
#include "concurrent_map.h"
|
|
|
|
#include "concurrent_queue.h"
|
|
|
|
#include "control_thread.h"
|
|
|
|
#include "file_configuration.h"
|
|
|
|
#include "gnss_flowgraph.h"
|
|
|
|
#include "gps_acq_assist.h"
|
2018-12-09 21:00:09 +00:00
|
|
|
#include "in_memory_configuration.h"
|
2018-02-26 02:15:53 +00:00
|
|
|
#include <boost/date_time/posix_time/posix_time.hpp>
|
|
|
|
#include <gflags/gflags.h>
|
|
|
|
#include <glog/logging.h>
|
|
|
|
#include <gtest/gtest.h>
|
2016-10-03 16:34:53 +00:00
|
|
|
#include <cerrno>
|
2016-09-29 17:06:17 +00:00
|
|
|
#include <chrono>
|
2016-10-03 16:34:53 +00:00
|
|
|
#include <cmath>
|
|
|
|
#include <limits>
|
2016-10-01 09:26:59 +00:00
|
|
|
#include <numeric>
|
2017-06-07 15:28:11 +00:00
|
|
|
#include <random>
|
2016-09-29 16:31:22 +00:00
|
|
|
#include <string>
|
2016-10-01 10:41:39 +00:00
|
|
|
#include <sys/ipc.h>
|
|
|
|
#include <sys/msg.h>
|
2018-12-09 21:00:09 +00:00
|
|
|
#include <sys/types.h>
|
2016-09-29 17:06:17 +00:00
|
|
|
#include <thread>
|
2016-09-29 17:46:27 +00:00
|
|
|
|
|
|
|
|
2016-10-10 17:23:54 +00:00
|
|
|
DEFINE_int32(fs_in, 4000000, "Sampling rate, in Samples/s");
|
2016-09-29 18:15:50 +00:00
|
|
|
DEFINE_int32(max_measurement_duration, 90, "Maximum time waiting for a position fix, in seconds");
|
|
|
|
DEFINE_int32(num_measurements, 2, "Number of measurements");
|
2016-09-29 17:46:27 +00:00
|
|
|
DEFINE_string(device_address, "192.168.40.2", "USRP device IP address");
|
2016-10-02 09:43:51 +00:00
|
|
|
DEFINE_string(subdevice, "A:0", "USRP subdevice");
|
2016-10-10 09:02:39 +00:00
|
|
|
DEFINE_string(config_file_ttff, std::string(""), "File containing the configuration parameters for the TTFF test.");
|
2016-09-29 16:31:22 +00:00
|
|
|
|
|
|
|
// For GPS NAVIGATION (L1)
|
|
|
|
concurrent_queue<Gps_Acq_Assist> global_gps_acq_assist_queue;
|
|
|
|
concurrent_map<Gps_Acq_Assist> global_gps_acq_assist_map;
|
|
|
|
|
2016-10-01 09:26:59 +00:00
|
|
|
std::vector<double> TTFF_v;
|
2016-10-01 08:25:29 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
long mtype; // required by SysV message
|
2016-10-01 09:03:40 +00:00
|
|
|
double ttff;
|
|
|
|
} ttff_msgbuf;
|
2016-10-01 08:25:29 +00:00
|
|
|
|
|
|
|
|
2018-05-28 13:42:44 +00:00
|
|
|
class TtffTest : public ::testing::Test
|
2016-10-01 09:58:15 +00:00
|
|
|
{
|
2016-10-02 10:48:12 +00:00
|
|
|
public:
|
|
|
|
void config_1();
|
|
|
|
void config_2();
|
2019-02-11 20:13:02 +00:00
|
|
|
void print_TTFF_report(const std::vector<double> &ttff_v, const std::shared_ptr<ConfigurationInterface> &config_);
|
2016-10-02 11:45:23 +00:00
|
|
|
|
2016-10-02 09:43:51 +00:00
|
|
|
std::shared_ptr<InMemoryConfiguration> config;
|
|
|
|
std::shared_ptr<FileConfiguration> config2;
|
2016-09-29 16:31:22 +00:00
|
|
|
|
2016-10-02 10:48:12 +00:00
|
|
|
const double central_freq = 1575420000.0;
|
|
|
|
const double gain_dB = 40.0;
|
|
|
|
|
|
|
|
const int number_of_taps = 11;
|
|
|
|
const int number_of_bands = 2;
|
|
|
|
const float band1_begin = 0.0;
|
|
|
|
const float band1_end = 0.48;
|
|
|
|
const float band2_begin = 0.52;
|
|
|
|
const float band2_end = 1.0;
|
|
|
|
const float ampl1_begin = 1.0;
|
|
|
|
const float ampl1_end = 1.0;
|
|
|
|
const float ampl2_begin = 0.0;
|
|
|
|
const float ampl2_end = 0.0;
|
|
|
|
const float band1_error = 1.0;
|
|
|
|
const float band2_error = 1.0;
|
|
|
|
const int grid_density = 16;
|
|
|
|
const float zero = 0.0;
|
|
|
|
const int number_of_channels = 8;
|
|
|
|
const int in_acquisition = 1;
|
|
|
|
|
|
|
|
const float threshold = 0.01;
|
|
|
|
const float doppler_max = 8000.0;
|
|
|
|
const float doppler_step = 500.0;
|
|
|
|
const int max_dwells = 1;
|
|
|
|
const int tong_init_val = 2;
|
|
|
|
const int tong_max_val = 10;
|
|
|
|
const int tong_max_dwells = 30;
|
|
|
|
const int coherent_integration_time_ms = 1;
|
|
|
|
|
|
|
|
const float pll_bw_hz = 30.0;
|
|
|
|
const float dll_bw_hz = 4.0;
|
|
|
|
const float early_late_space_chips = 0.5;
|
|
|
|
|
|
|
|
const int display_rate_ms = 500;
|
2016-10-02 11:45:23 +00:00
|
|
|
const int output_rate_ms = 100;
|
|
|
|
const int averaging_depth = 10;
|
2016-10-02 10:48:12 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2018-05-28 13:42:44 +00:00
|
|
|
void TtffTest::config_1()
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
|
|
|
config = std::make_shared<InMemoryConfiguration>();
|
2016-10-02 19:41:37 +00:00
|
|
|
|
2017-09-02 09:24:44 +00:00
|
|
|
config->set_property("GNSS-SDR.internal_fs_sps", std::to_string(FLAGS_fs_in));
|
2016-10-02 19:41:37 +00:00
|
|
|
|
2016-10-02 20:09:23 +00:00
|
|
|
// Set the assistance system parameters
|
2016-10-02 19:41:37 +00:00
|
|
|
config->set_property("GNSS-SDR.SUPL_gps_ephemeris_server", "supl.google.com");
|
|
|
|
config->set_property("GNSS-SDR.SUPL_gps_ephemeris_port", std::to_string(7275));
|
|
|
|
config->set_property("GNSS-SDR.SUPL_gps_acquisition_server", "supl.google.com");
|
|
|
|
config->set_property("GNSS-SDR.SUPL_gps_acquisition_port", std::to_string(7275));
|
|
|
|
config->set_property("GNSS-SDR.SUPL_MCC", std::to_string(244));
|
2018-10-22 22:16:36 +00:00
|
|
|
config->set_property("GNSS-SDR.SUPL_MNC", std::to_string(5));
|
2016-10-02 19:41:37 +00:00
|
|
|
config->set_property("GNSS-SDR.SUPL_LAC", "0x59e2");
|
|
|
|
config->set_property("GNSS-SDR.SUPL_CI", "0x31b0");
|
|
|
|
|
|
|
|
// Set the Signal Source
|
2016-09-29 17:06:17 +00:00
|
|
|
config->set_property("SignalSource.item_type", "cshort");
|
2016-09-29 16:31:22 +00:00
|
|
|
config->set_property("SignalSource.implementation", "UHD_Signal_Source");
|
2016-10-01 10:41:39 +00:00
|
|
|
config->set_property("SignalSource.freq", std::to_string(central_freq));
|
2016-09-29 20:28:22 +00:00
|
|
|
config->set_property("SignalSource.sampling_frequency", std::to_string(FLAGS_fs_in));
|
2016-10-01 10:41:39 +00:00
|
|
|
config->set_property("SignalSource.gain", std::to_string(gain_dB));
|
2016-09-29 17:46:27 +00:00
|
|
|
config->set_property("SignalSource.subdevice", FLAGS_subdevice);
|
2016-09-29 18:15:50 +00:00
|
|
|
config->set_property("SignalSource.samples", std::to_string(FLAGS_fs_in * FLAGS_max_measurement_duration));
|
2016-09-29 17:46:27 +00:00
|
|
|
config->set_property("SignalSource.device_address", FLAGS_device_address);
|
2016-09-29 16:31:22 +00:00
|
|
|
|
|
|
|
// Set the Signal Conditioner
|
|
|
|
config->set_property("SignalConditioner.implementation", "Signal_Conditioner");
|
|
|
|
config->set_property("DataTypeAdapter.implementation", "Pass_Through");
|
|
|
|
config->set_property("DataTypeAdapter.item_type", "cshort");
|
|
|
|
config->set_property("InputFilter.implementation", "Fir_Filter");
|
|
|
|
config->set_property("InputFilter.dump", "false");
|
|
|
|
config->set_property("InputFilter.input_item_type", "cshort");
|
|
|
|
config->set_property("InputFilter.output_item_type", "gr_complex");
|
|
|
|
config->set_property("InputFilter.taps_item_type", "float");
|
2016-10-01 15:42:47 +00:00
|
|
|
config->set_property("InputFilter.number_of_taps", std::to_string(number_of_taps));
|
|
|
|
config->set_property("InputFilter.number_of_bands", std::to_string(number_of_bands));
|
2016-10-01 17:09:55 +00:00
|
|
|
config->set_property("InputFilter.band1_begin", std::to_string(band1_begin));
|
|
|
|
config->set_property("InputFilter.band1_end", std::to_string(band1_end));
|
|
|
|
config->set_property("InputFilter.band2_begin", std::to_string(band2_begin));
|
|
|
|
config->set_property("InputFilter.band2_end", std::to_string(band2_end));
|
|
|
|
config->set_property("InputFilter.ampl1_begin", std::to_string(ampl1_begin));
|
|
|
|
config->set_property("InputFilter.ampl1_end", std::to_string(ampl1_end));
|
|
|
|
config->set_property("InputFilter.ampl2_begin", std::to_string(ampl2_begin));
|
|
|
|
config->set_property("InputFilter.ampl2_end", std::to_string(ampl2_end));
|
|
|
|
config->set_property("InputFilter.band1_error", std::to_string(band1_error));
|
|
|
|
config->set_property("InputFilter.band2_error", std::to_string(band2_error));
|
2016-09-29 16:31:22 +00:00
|
|
|
config->set_property("InputFilter.filter_type", "bandpass");
|
2016-10-01 17:09:55 +00:00
|
|
|
config->set_property("InputFilter.grid_density", std::to_string(grid_density));
|
2016-10-01 09:03:40 +00:00
|
|
|
config->set_property("InputFilter.sampling_frequency", std::to_string(FLAGS_fs_in));
|
2016-10-01 17:09:55 +00:00
|
|
|
config->set_property("InputFilter.IF", std::to_string(zero));
|
2016-09-29 16:31:22 +00:00
|
|
|
config->set_property("Resampler.implementation", "Pass_Through");
|
|
|
|
config->set_property("Resampler.dump", "false");
|
|
|
|
config->set_property("Resampler.item_type", "gr_complex");
|
2016-10-01 09:03:40 +00:00
|
|
|
config->set_property("Resampler.sample_freq_in", std::to_string(FLAGS_fs_in));
|
|
|
|
config->set_property("Resampler.sample_freq_out", std::to_string(FLAGS_fs_in));
|
2016-09-29 16:31:22 +00:00
|
|
|
|
|
|
|
// Set the number of Channels
|
2016-10-01 17:09:55 +00:00
|
|
|
config->set_property("Channels_1C.count", std::to_string(number_of_channels));
|
|
|
|
config->set_property("Channels.in_acquisition", std::to_string(in_acquisition));
|
2016-09-29 16:31:22 +00:00
|
|
|
config->set_property("Channel.signal", "1C");
|
|
|
|
|
|
|
|
// Set Acquisition
|
2016-09-29 20:18:21 +00:00
|
|
|
config->set_property("Acquisition_1C.implementation", "GPS_L1_CA_PCPS_Tong_Acquisition");
|
2016-09-29 16:31:22 +00:00
|
|
|
config->set_property("Acquisition_1C.item_type", "gr_complex");
|
2016-10-02 09:43:51 +00:00
|
|
|
config->set_property("Acquisition_1C.coherent_integration_time_ms", std::to_string(coherent_integration_time_ms));
|
2016-10-01 17:09:55 +00:00
|
|
|
config->set_property("Acquisition_1C.threshold", std::to_string(threshold));
|
|
|
|
config->set_property("Acquisition_1C.doppler_max", std::to_string(doppler_max));
|
|
|
|
config->set_property("Acquisition_1C.doppler_step", std::to_string(doppler_step));
|
2016-09-29 20:28:22 +00:00
|
|
|
config->set_property("Acquisition_1C.bit_transition_flag", "false");
|
2016-10-02 00:02:42 +00:00
|
|
|
config->set_property("Acquisition_1C.max_dwells", std::to_string(max_dwells));
|
|
|
|
config->set_property("Acquisition_1C.tong_init_val", std::to_string(tong_init_val));
|
|
|
|
config->set_property("Acquisition_1C.tong_max_val", std::to_string(tong_max_val));
|
|
|
|
config->set_property("Acquisition_1C.tong_max_dwells", std::to_string(tong_max_dwells));
|
2016-09-29 16:31:22 +00:00
|
|
|
|
|
|
|
// Set Tracking
|
|
|
|
config->set_property("Tracking_1C.implementation", "GPS_L1_CA_DLL_PLL_Tracking");
|
|
|
|
config->set_property("Tracking_1C.item_type", "gr_complex");
|
|
|
|
config->set_property("Tracking_1C.dump", "false");
|
|
|
|
config->set_property("Tracking_1C.dump_filename", "./tracking_ch_");
|
2016-10-02 10:48:12 +00:00
|
|
|
config->set_property("Tracking_1C.pll_bw_hz", std::to_string(pll_bw_hz));
|
|
|
|
config->set_property("Tracking_1C.dll_bw_hz", std::to_string(dll_bw_hz));
|
|
|
|
config->set_property("Tracking_1C.early_late_space_chips", std::to_string(early_late_space_chips));
|
2016-09-29 16:31:22 +00:00
|
|
|
|
|
|
|
// Set Telemetry
|
|
|
|
config->set_property("TelemetryDecoder_1C.implementation", "GPS_L1_CA_Telemetry_Decoder");
|
|
|
|
config->set_property("TelemetryDecoder_1C.dump", "false");
|
|
|
|
|
|
|
|
// Set Observables
|
2017-04-12 15:04:51 +00:00
|
|
|
config->set_property("Observables.implementation", "Hybrid_Observables");
|
2016-09-29 16:31:22 +00:00
|
|
|
config->set_property("Observables.dump", "false");
|
|
|
|
config->set_property("Observables.dump_filename", "./observables.dat");
|
|
|
|
|
|
|
|
// Set PVT
|
2017-04-29 21:14:36 +00:00
|
|
|
config->set_property("PVT.implementation", "RTKLIB_PVT");
|
2018-06-06 09:09:40 +00:00
|
|
|
config->set_property("PVT.positioning_mode", "Single");
|
2016-10-02 11:45:23 +00:00
|
|
|
config->set_property("PVT.output_rate_ms", std::to_string(output_rate_ms));
|
2016-10-02 10:48:12 +00:00
|
|
|
config->set_property("PVT.display_rate_ms", std::to_string(display_rate_ms));
|
2016-09-29 16:31:22 +00:00
|
|
|
config->set_property("PVT.dump_filename", "./PVT");
|
|
|
|
config->set_property("PVT.nmea_dump_filename", "./gnss_sdr_pvt.nmea");
|
|
|
|
config->set_property("PVT.flag_nmea_tty_port", "false");
|
|
|
|
config->set_property("PVT.nmea_dump_devname", "/dev/pts/4");
|
|
|
|
config->set_property("PVT.flag_rtcm_server", "false");
|
|
|
|
config->set_property("PVT.flag_rtcm_tty_port", "false");
|
|
|
|
config->set_property("PVT.rtcm_dump_devname", "/dev/pts/1");
|
|
|
|
config->set_property("PVT.dump", "false");
|
2016-10-02 10:48:12 +00:00
|
|
|
}
|
2016-09-29 16:31:22 +00:00
|
|
|
|
|
|
|
|
2018-05-28 13:42:44 +00:00
|
|
|
void TtffTest::config_2()
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
2018-03-03 01:03:39 +00:00
|
|
|
if (FLAGS_config_file_ttff.empty())
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
std::string path = std::string(TEST_PATH);
|
|
|
|
std::string filename = path + "../../conf/gnss-sdr_GPS_L1_USRP_X300_realtime.conf";
|
|
|
|
config2 = std::make_shared<FileConfiguration>(filename);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
config2 = std::make_shared<FileConfiguration>(FLAGS_config_file_ttff);
|
|
|
|
}
|
|
|
|
|
|
|
|
int d_sampling_rate;
|
2017-09-02 09:24:44 +00:00
|
|
|
d_sampling_rate = config2->property("GNSS-SDR.internal_fs_sps", FLAGS_fs_in);
|
2016-10-10 17:23:54 +00:00
|
|
|
config2->set_property("SignalSource.samples", std::to_string(d_sampling_rate * FLAGS_max_measurement_duration));
|
2016-10-02 10:48:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void receive_msg()
|
|
|
|
{
|
|
|
|
ttff_msgbuf msg;
|
|
|
|
ttff_msgbuf msg_stop;
|
|
|
|
msg_stop.mtype = 1;
|
2016-10-03 11:43:20 +00:00
|
|
|
msg_stop.ttff = -200.0;
|
2016-10-02 10:48:12 +00:00
|
|
|
double ttff_msg = 0.0;
|
|
|
|
int msgrcv_size = sizeof(msg.ttff);
|
|
|
|
int msqid;
|
2016-10-03 09:42:54 +00:00
|
|
|
int msqid_stop = -1;
|
2016-10-02 10:48:12 +00:00
|
|
|
key_t key = 1101;
|
|
|
|
key_t key_stop = 1102;
|
2016-10-03 15:43:06 +00:00
|
|
|
bool leave = false;
|
2016-10-02 10:48:12 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
while (!leave)
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
2016-10-03 15:43:06 +00:00
|
|
|
// wait for the queue to be created
|
2018-03-03 01:03:39 +00:00
|
|
|
while ((msqid = msgget(key, 0644)) == -1)
|
|
|
|
{
|
|
|
|
}
|
2016-10-02 10:48:12 +00:00
|
|
|
|
2016-10-03 15:43:06 +00:00
|
|
|
if (msgrcv(msqid, &msg, msgrcv_size, 1, 0) != -1)
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
2016-10-03 15:43:06 +00:00
|
|
|
ttff_msg = msg.ttff;
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((ttff_msg != 0) && (ttff_msg != -1))
|
2016-10-03 15:43:06 +00:00
|
|
|
{
|
2017-04-29 17:14:59 +00:00
|
|
|
TTFF_v.push_back(ttff_msg);
|
|
|
|
LOG(INFO) << "Valid Time-To-First-Fix: " << ttff_msg << "[s]";
|
2016-10-03 15:43:06 +00:00
|
|
|
// Stop the receiver
|
2018-03-03 01:03:39 +00:00
|
|
|
while (((msqid_stop = msgget(key_stop, 0644))) == -1)
|
|
|
|
{
|
|
|
|
}
|
2016-10-03 15:43:06 +00:00
|
|
|
double msgsend_size = sizeof(msg_stop.ttff);
|
|
|
|
msgsnd(msqid_stop, &msg_stop, msgsend_size, IPC_NOWAIT);
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (std::abs(ttff_msg - (-1.0)) < 10 * std::numeric_limits<double>::epsilon())
|
2016-10-03 15:43:06 +00:00
|
|
|
{
|
|
|
|
leave = true;
|
|
|
|
}
|
2016-10-02 10:48:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-11 20:13:02 +00:00
|
|
|
void TtffTest::print_TTFF_report(const std::vector<double> &ttff_v, const std::shared_ptr<ConfigurationInterface> &config_)
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
2016-10-03 10:48:02 +00:00
|
|
|
std::ofstream ttff_report_file;
|
|
|
|
std::string filename = "ttff_report";
|
|
|
|
std::string filename_;
|
|
|
|
|
2017-08-11 11:11:38 +00:00
|
|
|
boost::posix_time::ptime pt = boost::posix_time::second_clock::local_time();
|
|
|
|
tm timeinfo = boost::posix_time::to_tm(pt);
|
2016-10-03 10:48:02 +00:00
|
|
|
|
2016-10-13 08:06:53 +00:00
|
|
|
std::stringstream strm0;
|
2017-08-11 11:11:38 +00:00
|
|
|
const int year = timeinfo.tm_year - 100;
|
2016-10-13 08:06:53 +00:00
|
|
|
strm0 << year;
|
2017-08-11 11:11:38 +00:00
|
|
|
const int month = timeinfo.tm_mon + 1;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (month < 10)
|
2016-10-03 10:48:02 +00:00
|
|
|
{
|
2016-10-13 08:06:53 +00:00
|
|
|
strm0 << "0";
|
|
|
|
}
|
|
|
|
strm0 << month;
|
2017-08-11 11:11:38 +00:00
|
|
|
const int day = timeinfo.tm_mday;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (day < 10)
|
2016-10-13 08:06:53 +00:00
|
|
|
{
|
|
|
|
strm0 << "0";
|
|
|
|
}
|
|
|
|
strm0 << day << "_";
|
2017-08-11 11:11:38 +00:00
|
|
|
const int hour = timeinfo.tm_hour;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (hour < 10)
|
|
|
|
{
|
2016-10-13 08:06:53 +00:00
|
|
|
strm0 << "0";
|
|
|
|
}
|
|
|
|
strm0 << hour;
|
2017-08-11 11:11:38 +00:00
|
|
|
const int min = timeinfo.tm_min;
|
2016-10-03 10:48:02 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
if (min < 10)
|
2016-10-13 08:06:53 +00:00
|
|
|
{
|
|
|
|
strm0 << "0";
|
2016-10-03 10:48:02 +00:00
|
|
|
}
|
2016-10-13 08:06:53 +00:00
|
|
|
strm0 << min;
|
2017-08-11 11:11:38 +00:00
|
|
|
const int sec = timeinfo.tm_sec;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (sec < 10)
|
2016-10-03 10:48:02 +00:00
|
|
|
{
|
2016-10-13 08:06:53 +00:00
|
|
|
strm0 << "0";
|
2016-10-03 10:48:02 +00:00
|
|
|
}
|
2016-10-13 08:06:53 +00:00
|
|
|
strm0 << sec;
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
filename_ = filename + "_" + strm0.str() + ".txt";
|
2016-10-03 10:48:02 +00:00
|
|
|
|
|
|
|
ttff_report_file.open(filename_.c_str());
|
|
|
|
|
2016-10-02 10:48:12 +00:00
|
|
|
std::vector<double> ttff = ttff_v;
|
2016-10-02 19:14:58 +00:00
|
|
|
bool read_ephemeris;
|
2016-10-13 10:48:05 +00:00
|
|
|
bool false_bool = false;
|
|
|
|
read_ephemeris = config_->property("GNSS-SDR.SUPL_read_gps_assistance_xml", false_bool);
|
2016-10-02 19:14:58 +00:00
|
|
|
bool agnss;
|
2016-10-13 10:48:05 +00:00
|
|
|
agnss = config_->property("GNSS-SDR.SUPL_gps_enabled", false_bool);
|
2016-10-02 10:48:12 +00:00
|
|
|
double sum = std::accumulate(ttff.begin(), ttff.end(), 0.0);
|
|
|
|
double mean = sum / ttff.size();
|
|
|
|
double sq_sum = std::inner_product(ttff.begin(), ttff.end(), ttff.begin(), 0.0);
|
|
|
|
double stdev = std::sqrt(sq_sum / ttff.size() - mean * mean);
|
|
|
|
auto max_ttff = std::max_element(std::begin(ttff), std::end(ttff));
|
|
|
|
auto min_ttff = std::min_element(std::begin(ttff), std::end(ttff));
|
2016-10-03 10:48:02 +00:00
|
|
|
std::string source;
|
|
|
|
std::string default_str = "default";
|
|
|
|
source = config_->property("SignalSource.implementation", default_str);
|
|
|
|
|
2017-11-10 09:46:53 +00:00
|
|
|
std::stringstream stm;
|
2016-10-03 10:48:02 +00:00
|
|
|
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "---------------------------" << std::endl;
|
|
|
|
stm << " Time-To-First-Fix Report" << std::endl;
|
2018-03-03 01:03:39 +00:00
|
|
|
stm << "---------------------------" << std::endl;
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Initial receiver status: ";
|
2016-10-02 19:14:58 +00:00
|
|
|
if (read_ephemeris)
|
|
|
|
{
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Hot start." << std::endl;
|
2016-10-02 19:14:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Cold start." << std::endl;
|
2016-10-02 19:14:58 +00:00
|
|
|
}
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "A-GNSS: ";
|
2016-10-02 19:14:58 +00:00
|
|
|
if (agnss && read_ephemeris)
|
|
|
|
{
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Enabled." << std::endl;
|
2016-10-02 19:14:58 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Disabled." << std::endl;
|
2016-10-02 19:14:58 +00:00
|
|
|
}
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Valid measurements (" << ttff.size() << "/" << FLAGS_num_measurements << "): ";
|
2019-02-11 20:13:02 +00:00
|
|
|
for (double ttff_ : ttff)
|
|
|
|
{
|
|
|
|
stm << ttff_ << " ";
|
|
|
|
}
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << std::endl;
|
|
|
|
stm << "TTFF mean: " << mean << " [s]" << std::endl;
|
2019-02-05 00:31:09 +00:00
|
|
|
if (!ttff.empty())
|
2016-09-29 17:06:17 +00:00
|
|
|
{
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "TTFF max: " << *max_ttff << " [s]" << std::endl;
|
|
|
|
stm << "TTFF min: " << *min_ttff << " [s]" << std::endl;
|
2016-10-02 10:48:12 +00:00
|
|
|
}
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "TTFF stdev: " << stdev << " [s]" << std::endl;
|
|
|
|
stm << "Operating System: " << std::string(HOST_SYSTEM) << std::endl;
|
2018-03-03 01:03:39 +00:00
|
|
|
stm << "Navigation mode: "
|
|
|
|
<< "3D" << std::endl;
|
2016-10-03 10:48:02 +00:00
|
|
|
|
2018-12-08 19:09:25 +00:00
|
|
|
if (source != "UHD_Signal_Source")
|
2016-10-03 09:42:54 +00:00
|
|
|
{
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Source: File" << std::endl;
|
2016-10-03 09:42:54 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-11-10 09:46:53 +00:00
|
|
|
stm << "Source: Live" << std::endl;
|
|
|
|
}
|
|
|
|
stm << "---------------------------" << std::endl;
|
|
|
|
|
|
|
|
std::cout << stm.rdbuf();
|
|
|
|
if (ttff_report_file.is_open())
|
|
|
|
{
|
|
|
|
ttff_report_file << stm.str();
|
|
|
|
ttff_report_file.close();
|
2016-10-03 09:42:54 +00:00
|
|
|
}
|
2016-10-02 10:48:12 +00:00
|
|
|
}
|
|
|
|
|
2016-09-29 17:06:17 +00:00
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
TEST_F(TtffTest /*unused*/, ColdStart /*unused*/)
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
|
|
|
unsigned int num_measurements = 0;
|
|
|
|
|
|
|
|
config_1();
|
|
|
|
// Ensure Cold Start
|
|
|
|
config->set_property("GNSS-SDR.SUPL_gps_enabled", "false");
|
|
|
|
config->set_property("GNSS-SDR.SUPL_read_gps_assistance_xml", "false");
|
|
|
|
|
|
|
|
config_2();
|
|
|
|
// Ensure Cold Start
|
2016-10-02 19:14:58 +00:00
|
|
|
config2->set_property("GNSS-SDR.SUPL_gps_enabled", "false");
|
2016-10-02 10:48:12 +00:00
|
|
|
config2->set_property("GNSS-SDR.SUPL_read_gps_assistance_xml", "false");
|
|
|
|
config2->set_property("PVT.flag_rtcm_server", "false");
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int n = 0; n < FLAGS_num_measurements; n++)
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
|
|
|
// Create a new ControlThread object with a smart pointer
|
2016-10-10 13:22:42 +00:00
|
|
|
std::shared_ptr<ControlThread> control_thread;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (FLAGS_config_file_ttff.empty())
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
control_thread = std::make_shared<ControlThread>(config);
|
|
|
|
}
|
2016-10-10 09:02:39 +00:00
|
|
|
else
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
control_thread = std::make_shared<ControlThread>(config2);
|
|
|
|
}
|
2016-10-10 13:22:42 +00:00
|
|
|
|
2016-09-29 18:15:50 +00:00
|
|
|
// record startup time
|
2016-10-02 11:45:23 +00:00
|
|
|
std::cout << "Starting measurement " << num_measurements + 1 << " / " << FLAGS_num_measurements << std::endl;
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2016-10-01 10:41:39 +00:00
|
|
|
// start receiver
|
2016-09-29 17:06:17 +00:00
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2016-09-29 17:06:17 +00:00
|
|
|
control_thread->run();
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const boost::exception &e)
|
|
|
|
{
|
2016-09-29 17:06:17 +00:00
|
|
|
std::cout << "Boost exception: " << boost::diagnostic_information(e);
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception &ex)
|
|
|
|
{
|
|
|
|
std::cout << "STD exception: " << ex.what();
|
|
|
|
}
|
2016-09-29 17:06:17 +00:00
|
|
|
|
2016-10-01 10:41:39 +00:00
|
|
|
// stop clock
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
|
|
|
double ttff = elapsed_seconds.count();
|
2016-09-29 18:15:50 +00:00
|
|
|
|
|
|
|
std::shared_ptr<GNSSFlowgraph> flowgraph = control_thread->flowgraph();
|
|
|
|
EXPECT_FALSE(flowgraph->running());
|
2016-10-01 08:25:29 +00:00
|
|
|
|
2016-09-29 17:06:17 +00:00
|
|
|
num_measurements = num_measurements + 1;
|
2016-10-02 10:48:12 +00:00
|
|
|
std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (n < FLAGS_num_measurements - 1)
|
2016-10-02 10:48:12 +00:00
|
|
|
{
|
2017-06-07 15:28:11 +00:00
|
|
|
std::random_device r;
|
|
|
|
std::default_random_engine e1(r());
|
|
|
|
std::uniform_real_distribution<float> uniform_dist(0, 1);
|
|
|
|
float random_variable_0_1 = uniform_dist(e1);
|
2016-10-02 10:48:12 +00:00
|
|
|
int random_delay_s = static_cast<int>(random_variable_0_1 * 25.0);
|
2016-10-03 10:20:46 +00:00
|
|
|
std::cout << "Waiting a random amount of time (from 5 to 30 s) to start a new measurement... " << std::endl;
|
2018-03-03 01:03:39 +00:00
|
|
|
std::cout << "This time will wait " << random_delay_s + 5 << " s." << std::endl
|
|
|
|
<< std::endl;
|
2016-10-02 11:45:23 +00:00
|
|
|
std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::seconds(5) + std::chrono::seconds(random_delay_s));
|
2016-10-02 10:48:12 +00:00
|
|
|
}
|
2016-09-29 17:06:17 +00:00
|
|
|
}
|
2016-10-01 09:58:15 +00:00
|
|
|
|
2016-09-29 17:06:17 +00:00
|
|
|
// Print TTFF report
|
2018-03-03 01:03:39 +00:00
|
|
|
if (FLAGS_config_file_ttff.empty())
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
print_TTFF_report(TTFF_v, config);
|
|
|
|
}
|
2016-10-10 09:02:39 +00:00
|
|
|
else
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
print_TTFF_report(TTFF_v, config2);
|
|
|
|
}
|
2018-03-03 01:03:39 +00:00
|
|
|
std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::seconds(5)); //let the USRP some time to rest before the next test
|
2016-09-29 16:31:22 +00:00
|
|
|
}
|
2016-09-29 20:04:53 +00:00
|
|
|
|
|
|
|
|
2018-12-08 17:49:31 +00:00
|
|
|
TEST_F(TtffTest /*unused*/, HotStart /*unused*/)
|
2016-10-02 19:24:46 +00:00
|
|
|
{
|
|
|
|
unsigned int num_measurements = 0;
|
|
|
|
TTFF_v.clear();
|
|
|
|
|
2016-10-02 19:41:37 +00:00
|
|
|
config_1();
|
2016-10-02 19:24:46 +00:00
|
|
|
// Ensure Hot Start
|
2016-10-02 19:41:37 +00:00
|
|
|
config->set_property("GNSS-SDR.SUPL_gps_enabled", "true");
|
|
|
|
config->set_property("GNSS-SDR.SUPL_read_gps_assistance_xml", "true");
|
2016-10-02 19:24:46 +00:00
|
|
|
|
2016-10-10 09:02:39 +00:00
|
|
|
config_2();
|
|
|
|
// Ensure Hot Start
|
|
|
|
config2->set_property("GNSS-SDR.SUPL_gps_enabled", "true");
|
|
|
|
config2->set_property("GNSS-SDR.SUPL_read_gps_assistance_xml", "true");
|
|
|
|
config2->set_property("PVT.flag_rtcm_server", "false");
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
for (int n = 0; n < FLAGS_num_measurements; n++)
|
2016-10-02 19:24:46 +00:00
|
|
|
{
|
|
|
|
// Create a new ControlThread object with a smart pointer
|
2016-10-10 13:22:42 +00:00
|
|
|
std::shared_ptr<ControlThread> control_thread;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (FLAGS_config_file_ttff.empty())
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
control_thread = std::make_shared<ControlThread>(config);
|
|
|
|
}
|
2016-10-10 09:02:39 +00:00
|
|
|
else
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
control_thread = std::make_shared<ControlThread>(config2);
|
|
|
|
}
|
2016-10-02 19:24:46 +00:00
|
|
|
// record startup time
|
|
|
|
std::cout << "Starting measurement " << num_measurements + 1 << " / " << FLAGS_num_measurements << std::endl;
|
2017-08-11 03:18:38 +00:00
|
|
|
std::chrono::time_point<std::chrono::system_clock> start, end;
|
|
|
|
start = std::chrono::system_clock::now();
|
2016-10-02 19:24:46 +00:00
|
|
|
|
|
|
|
// start receiver
|
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2016-10-02 19:24:46 +00:00
|
|
|
control_thread->run();
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const boost::exception &e)
|
|
|
|
{
|
2016-10-02 19:24:46 +00:00
|
|
|
std::cout << "Boost exception: " << boost::diagnostic_information(e);
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (const std::exception &ex)
|
|
|
|
{
|
|
|
|
std::cout << "STD exception: " << ex.what();
|
|
|
|
}
|
2016-10-02 19:24:46 +00:00
|
|
|
|
|
|
|
// stop clock
|
2017-08-11 03:18:38 +00:00
|
|
|
end = std::chrono::system_clock::now();
|
|
|
|
std::chrono::duration<double> elapsed_seconds = end - start;
|
|
|
|
double ttff = elapsed_seconds.count();
|
2016-10-02 19:24:46 +00:00
|
|
|
|
|
|
|
std::shared_ptr<GNSSFlowgraph> flowgraph = control_thread->flowgraph();
|
|
|
|
EXPECT_FALSE(flowgraph->running());
|
|
|
|
|
|
|
|
num_measurements = num_measurements + 1;
|
|
|
|
std::cout << "Just finished measurement " << num_measurements << ", which took " << ttff << " seconds." << std::endl;
|
2018-03-03 01:03:39 +00:00
|
|
|
if (n < FLAGS_num_measurements - 1)
|
2016-10-02 19:24:46 +00:00
|
|
|
{
|
2017-06-07 15:28:11 +00:00
|
|
|
std::random_device r;
|
|
|
|
std::default_random_engine e1(r());
|
|
|
|
std::uniform_real_distribution<float> uniform_dist(0, 1);
|
|
|
|
float random_variable_0_1 = uniform_dist(e1);
|
2016-10-02 19:24:46 +00:00
|
|
|
int random_delay_s = static_cast<int>(random_variable_0_1 * 25.0);
|
|
|
|
std::cout << "Waiting a random amount of time (from 5 to 30 s) to start new measurement... " << std::endl;
|
2018-03-03 01:03:39 +00:00
|
|
|
std::cout << "This time will wait " << random_delay_s + 5 << " s." << std::endl
|
|
|
|
<< std::endl;
|
2016-10-02 19:24:46 +00:00
|
|
|
std::this_thread::sleep_until(std::chrono::system_clock::now() + std::chrono::seconds(5) + std::chrono::seconds(random_delay_s));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Print TTFF report
|
2018-03-03 01:03:39 +00:00
|
|
|
if (FLAGS_config_file_ttff.empty())
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
print_TTFF_report(TTFF_v, config);
|
|
|
|
}
|
2016-10-10 09:02:39 +00:00
|
|
|
else
|
2016-10-10 17:23:54 +00:00
|
|
|
{
|
|
|
|
print_TTFF_report(TTFF_v, config2);
|
|
|
|
}
|
2016-10-02 19:24:46 +00:00
|
|
|
}
|
|
|
|
|
2016-10-01 09:58:15 +00:00
|
|
|
|
2016-09-29 20:04:53 +00:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
|
|
|
std::cout << "Running Time-To-First-Fix test..." << std::endl;
|
|
|
|
int res = 0;
|
2016-10-01 09:26:59 +00:00
|
|
|
TTFF_v.clear();
|
2016-10-13 22:26:05 +00:00
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2016-10-13 22:26:05 +00:00
|
|
|
testing::InitGoogleTest(&argc, argv);
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
|
|
|
} // catch the "testing::internal::<unnamed>::ClassUniqueToAlwaysTrue" from gtest
|
2016-10-13 22:26:05 +00:00
|
|
|
|
2016-09-29 20:04:53 +00:00
|
|
|
google::ParseCommandLineFlags(&argc, &argv, true);
|
|
|
|
google::InitGoogleLogging(argv[0]);
|
2016-10-01 10:41:39 +00:00
|
|
|
|
|
|
|
// Start queue thread
|
2016-10-01 08:25:29 +00:00
|
|
|
std::thread receive_msg_thread(receive_msg);
|
2016-10-01 10:41:39 +00:00
|
|
|
|
|
|
|
// Run the Tests
|
2016-09-29 20:04:53 +00:00
|
|
|
try
|
2018-03-03 01:03:39 +00:00
|
|
|
{
|
2016-09-29 20:04:53 +00:00
|
|
|
res = RUN_ALL_TESTS();
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2016-09-29 20:04:53 +00:00
|
|
|
LOG(WARNING) << "Unexpected catch";
|
2018-03-03 01:03:39 +00:00
|
|
|
}
|
2016-10-01 10:41:39 +00:00
|
|
|
|
|
|
|
// Terminate the queue thread
|
2016-10-03 15:43:06 +00:00
|
|
|
key_t sysv_msg_key;
|
|
|
|
int sysv_msqid;
|
|
|
|
sysv_msg_key = 1101;
|
|
|
|
int msgflg = IPC_CREAT | 0666;
|
2018-03-03 01:03:39 +00:00
|
|
|
if ((sysv_msqid = msgget(sysv_msg_key, msgflg)) == -1)
|
|
|
|
{
|
|
|
|
std::cout << "GNSS-SDR can not create message queues!" << std::endl;
|
|
|
|
return 1;
|
|
|
|
}
|
2016-10-01 08:25:29 +00:00
|
|
|
ttff_msgbuf msg;
|
|
|
|
msg.mtype = 1;
|
2016-10-01 09:44:38 +00:00
|
|
|
msg.ttff = -1;
|
2016-10-01 08:25:29 +00:00
|
|
|
int msgsend_size;
|
2016-10-01 09:26:59 +00:00
|
|
|
msgsend_size = sizeof(msg.ttff);
|
2016-10-01 08:25:29 +00:00
|
|
|
msgsnd(sysv_msqid, &msg, msgsend_size, IPC_NOWAIT);
|
|
|
|
receive_msg_thread.join();
|
2019-02-05 00:31:09 +00:00
|
|
|
msgctl(sysv_msqid, IPC_RMID, nullptr);
|
2016-10-03 15:43:06 +00:00
|
|
|
|
2016-09-29 20:04:53 +00:00
|
|
|
google::ShutDownCommandLineFlags();
|
|
|
|
return res;
|
|
|
|
}
|