2018-02-18 11:23:55 +00:00
|
|
|
/*!
|
|
|
|
* \file gnss_sdr_flags.cc
|
|
|
|
* \brief Helper file for gnss-sdr commandline flags
|
|
|
|
* \author Carles Fernandez-Prades, 2018. cfernandez(at)cttc.es
|
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010-2018 (see AUTHORS file for a list of contributors)
|
|
|
|
*
|
|
|
|
* 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/>.
|
2018-02-18 11:23:55 +00:00
|
|
|
*
|
|
|
|
* -------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2018-02-26 02:15:53 +00:00
|
|
|
#include "gnss_sdr_flags.h"
|
2019-06-10 19:41:13 +00:00
|
|
|
#if HAS_STD_FILESYSTEM
|
|
|
|
#include <filesystem>
|
|
|
|
#else
|
2018-03-03 01:03:39 +00:00
|
|
|
#include <boost/filesystem/operations.hpp> // for exists
|
2019-06-10 19:41:13 +00:00
|
|
|
#endif
|
2018-02-18 20:58:23 +00:00
|
|
|
#include <cstdint>
|
2018-02-18 19:50:16 +00:00
|
|
|
#include <iostream>
|
2018-02-26 20:37:53 +00:00
|
|
|
#include <string>
|
2018-02-18 19:50:16 +00:00
|
|
|
|
2019-06-10 19:41:13 +00:00
|
|
|
#if HAS_STD_FILESYSTEM
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
#else
|
|
|
|
namespace fs = boost::filesystem;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_string(c, "-", "Path to the configuration file (if set, overrides --config_file).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-26 20:37:53 +00:00
|
|
|
DEFINE_string(config_file, std::string(GNSSSDR_INSTALL_DIR "/share/gnss-sdr/conf/default.conf"),
|
2018-03-03 01:03:39 +00:00
|
|
|
"Path to the configuration file.");
|
2018-02-26 20:37:53 +00:00
|
|
|
|
2018-02-18 21:48:47 +00:00
|
|
|
DEFINE_string(s, "-",
|
2018-03-03 01:03:39 +00:00
|
|
|
"If defined, path to the file containing the signal samples (overrides the configuration file and --signal_source).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
|
|
|
DEFINE_string(signal_source, "-",
|
2018-03-03 01:03:39 +00:00
|
|
|
"If defined, path to the file containing the signal samples (overrides the configuration file).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_int32(doppler_max, 0, "If defined, sets the maximum Doppler value in the search grid, in Hz (overrides the configuration file).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_int32(doppler_step, 0, "If defined, sets the frequency step in the search grid, in Hz (overrides the configuration file).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_int32(cn0_samples, 20, "Number of correlator outputs used for CN0 estimation.");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_int32(cn0_min, 25, "Minimum valid CN0 (in dB-Hz).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-04-28 10:33:46 +00:00
|
|
|
DEFINE_int32(max_lock_fail, 50, "Maximum number of lock failures before dropping a satellite.");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_double(carrier_lock_th, 0.85, "Carrier lock threshold (in rad).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_string(RINEX_version, "-", "If defined, specifies the RINEX version (2.11 or 3.02). Overrides the configuration file.");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_double(dll_bw_hz, 0.0, "If defined, bandwidth of the DLL low pass filter, in Hz (overrides the configuration file).");
|
|
|
|
|
|
|
|
DEFINE_double(pll_bw_hz, 0.0, "If defined, bandwidth of the PLL low pass filter, in Hz (overrides the configuration file).");
|
2018-02-18 21:48:47 +00:00
|
|
|
|
|
|
|
|
|
|
|
#if GFLAGS_GREATER_2_0
|
2018-02-18 20:58:23 +00:00
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
static bool ValidateC(const char* flagname, const std::string& value)
|
2018-02-26 20:37:53 +00:00
|
|
|
{
|
2019-06-10 19:41:13 +00:00
|
|
|
if (fs::exists(value) or value == "-")
|
2019-02-11 20:13:02 +00:00
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ". The file '" << value << "' does not exist." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
static bool ValidateConfigFile(const char* flagname, const std::string& value)
|
2018-02-26 20:37:53 +00:00
|
|
|
{
|
2019-06-10 19:41:13 +00:00
|
|
|
if (fs::exists(value) or value == std::string(GNSSSDR_INSTALL_DIR "/share/gnss-sdr/conf/default.conf"))
|
2019-02-11 20:13:02 +00:00
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ". The file '" << value << "' does not exist." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
static bool ValidateS(const char* flagname, const std::string& value)
|
2018-02-26 20:37:53 +00:00
|
|
|
{
|
2019-06-10 19:41:13 +00:00
|
|
|
if (fs::exists(value) or value == "-")
|
2019-02-11 20:13:02 +00:00
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ". The file '" << value << "' does not exist." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-03-03 01:03:39 +00:00
|
|
|
static bool ValidateSignalSource(const char* flagname, const std::string& value)
|
2018-02-26 20:37:53 +00:00
|
|
|
{
|
2019-06-10 19:41:13 +00:00
|
|
|
if (fs::exists(value) or value == "-")
|
2019-02-11 20:13:02 +00:00
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ". The file '" << value << "' does not exist." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-18 20:58:23 +00:00
|
|
|
static bool ValidateDopplerMax(const char* flagname, int32_t value)
|
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const int32_t max_value = 1000000;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value >= 0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " Hz." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-18 20:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-25 00:00:17 +00:00
|
|
|
static bool ValidateDopplerStep(const char* flagname, int32_t value)
|
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const int32_t max_value = 10000;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value >= 0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " Hz." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-25 00:00:17 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-02-18 20:58:23 +00:00
|
|
|
static bool ValidateCn0Samples(const char* flagname, int32_t value)
|
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const int32_t max_value = 10000;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value > 0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " samples." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-18 20:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ValidateCn0Min(const char* flagname, int32_t value)
|
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const int32_t max_value = 100;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value > 0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " dB-Hz." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-18 20:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ValidateMaxLockFail(const char* flagname, int32_t value)
|
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const int32_t max_value = 10000;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value > 0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " fails." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-18 20:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ValidateCarrierLockTh(const char* flagname, double value)
|
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const double max_value = 1.508;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value > 0.0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " rad." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-18 20:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ValidateDllBw(const char* flagname, double value)
|
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const double max_value = 10000.0;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value >= 0.0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " Hz." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-18 20:58:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool ValidatePllBw(const char* flagname, double value)
|
2018-02-18 19:50:16 +00:00
|
|
|
{
|
2018-02-26 20:37:53 +00:00
|
|
|
const double max_value = 10000.0;
|
2019-02-11 20:13:02 +00:00
|
|
|
if (value >= 0.0 && value < max_value)
|
|
|
|
{ // value is ok
|
|
|
|
return true;
|
|
|
|
}
|
2018-02-26 20:37:53 +00:00
|
|
|
std::cout << "Invalid value for flag -" << flagname << ": " << value << ". Allowed range is 0 < " << flagname << " < " << max_value << " Hz." << std::endl;
|
|
|
|
std::cout << "GNSS-SDR program ended." << std::endl;
|
2018-02-18 19:50:16 +00:00
|
|
|
return false;
|
|
|
|
}
|
2018-02-18 11:23:55 +00:00
|
|
|
|
2018-02-26 20:37:53 +00:00
|
|
|
DEFINE_validator(c, &ValidateC);
|
|
|
|
DEFINE_validator(config_file, &ValidateConfigFile);
|
|
|
|
DEFINE_validator(s, &ValidateS);
|
|
|
|
DEFINE_validator(signal_source, &ValidateSignalSource);
|
2018-02-18 19:50:16 +00:00
|
|
|
DEFINE_validator(doppler_max, &ValidateDopplerMax);
|
2018-02-25 00:00:17 +00:00
|
|
|
DEFINE_validator(doppler_step, &ValidateDopplerStep);
|
2018-02-18 20:58:23 +00:00
|
|
|
DEFINE_validator(cn0_samples, &ValidateCn0Samples);
|
|
|
|
DEFINE_validator(cn0_min, &ValidateCn0Min);
|
|
|
|
DEFINE_validator(max_lock_fail, &ValidateMaxLockFail);
|
|
|
|
DEFINE_validator(carrier_lock_th, &ValidateCarrierLockTh);
|
2018-02-18 21:48:47 +00:00
|
|
|
DEFINE_validator(dll_bw_hz, &ValidateDllBw);
|
|
|
|
DEFINE_validator(pll_bw_hz, &ValidatePllBw);
|
2018-02-18 12:55:04 +00:00
|
|
|
|
|
|
|
|
2018-02-18 21:48:47 +00:00
|
|
|
#endif
|