GNSS-SDR 0.0.21
An Open Source GNSS Software Defined Receiver
Loading...
Searching...
No Matches
gnss_sdr_flags.h
Go to the documentation of this file.
1/*!
2 * \file gnss_sdr_flags.h
3 * \brief Helper file for gnss-sdr commandline flags
4 * \author Carles Fernandez-Prades, 2018-2024. cfernandez(at)cttc.es
5 *
6 *
7 * -----------------------------------------------------------------------------
8 *
9 * GNSS-SDR is a Global Navigation Satellite System software-defined receiver.
10 * This file is part of GNSS-SDR.
11 *
12 * Copyright (C) 2010-2024 (see AUTHORS file for a list of contributors)
13 * SPDX-License-Identifier: GPL-3.0-or-later
14 *
15 * -----------------------------------------------------------------------------
16 */
17
18#ifndef GNSS_SDR_GNSS_SDR_FLAGS_H
19#define GNSS_SDR_GNSS_SDR_FLAGS_H
20
21#include <cstdint>
22#include <string>
23
24#if USE_GLOG_AND_GFLAGS
25#include <gflags/gflags.h>
26#else
27#include <absl/flags/declare.h>
28#include <absl/flags/flag.h>
29#include <cstdlib>
30#include <iostream>
31#include <sys/stat.h>
32#include <vector>
33#endif
34
35
36/** \addtogroup Algorithms_Library
37 * \{ */
38/** \addtogroup Gflags gnss_sdr_flags
39 * Library for command-line handling.
40 * \{ */
41
42#if USE_GLOG_AND_GFLAGS
43DECLARE_string(c); //!< Path to the configuration file.
44DECLARE_string(config_file); //!< Path to the configuration file.
45
46DECLARE_string(log_dir); //!< Path to the folder in which logging will be stored.
47
48// Declare flags for signal sources
49DECLARE_string(s); //!< Path to the file containing the signal samples.
50DECLARE_string(signal_source); //!< Path to the file containing the signal samples.
51DECLARE_string(timestamp_source); //!< Path to the file containing the signal samples.
52DECLARE_bool(rf_shutdown); //!< Shutdown RF when program exits.
53
54// Declare flags for acquisition blocks
55DECLARE_int32(doppler_max); //!< If defined, maximum Doppler value in the search grid, in Hz (overrides the configuration file).
56DECLARE_int32(doppler_step); //!< If defined, sets the frequency step in the search grid, in Hz, in Hz (overrides the configuration file).
57
58// Declare flags for tracking blocks
59DECLARE_int32(cn0_samples); //!< Number of correlator outputs used for CN0 estimation.
60DECLARE_int32(cn0_min); //!< Minimum valid CN0 (in dB-Hz).
61DECLARE_int32(max_lock_fail); //!< Maximum number of code lock failures before dropping a satellite.
62DECLARE_int32(max_carrier_lock_fail); //!< Maximum number of carrier lock failures before dropping a satellite.
63DECLARE_double(carrier_lock_th); //!< Carrier lock threshold (in rad).
64DECLARE_double(dll_bw_hz); //!< Bandwidth of the DLL low pass filter, in Hz (overrides the configuration file).
65DECLARE_double(pll_bw_hz); //!< Bandwidth of the PLL low pass filter, in Hz (overrides the configuration file).
66
67// Declare flags for observables block
68DECLARE_int32(carrier_smoothing_factor); //!< Sets carrier smoothing factor M (overrides the configuration file).
69const int32_t DEFAULT_CARRIER_SMOOTHING_FACTOR = 200;
70
71// Declare flags for PVT
72DECLARE_string(RINEX_version); //!< If defined, specifies the RINEX version (2.11 or 3.02). Overrides the configuration file.
73DECLARE_string(RINEX_name); //!< If defined, specifies the RINEX files base name
74DECLARE_bool(keyboard); //!< If set to false, disables the keyboard listener. Only for debug purposes (e.g. ASAN mode termination)
75
76#else
77ABSL_DECLARE_FLAG(std::string, c); //!< Path to the configuration file.
78ABSL_DECLARE_FLAG(std::string, config_file); //!< Path to the configuration file.
79
80ABSL_DECLARE_FLAG(std::string, log_dir); //!< Path to the folder in which logging will be stored.
81
82// Declare flags for signal sources
83ABSL_DECLARE_FLAG(std::string, s); //!< Path to the file containing the signal samples.
84ABSL_DECLARE_FLAG(std::string, signal_source); //!< Path to the file containing the signal samples.
85ABSL_DECLARE_FLAG(std::string, timestamp_source); //!< Path to the file containing the signal samples.
86ABSL_DECLARE_FLAG(bool, rf_shutdown); //!< Shutdown RF when program exits.
87
88// Declare flags for acquisition blocks
89ABSL_DECLARE_FLAG(int32_t, doppler_max); //!< If defined, maximum Doppler value in the search grid, in Hz (overrides the configuration file).
90ABSL_DECLARE_FLAG(int32_t, doppler_step); //!< If defined, sets the frequency step in the search grid, in Hz, in Hz (overrides the configuration file).
91
92// Declare flags for tracking blocks
93ABSL_DECLARE_FLAG(int32_t, cn0_samples); //!< Number of correlator outputs used for CN0 estimation.
94ABSL_DECLARE_FLAG(int32_t, cn0_min); //!< Minimum valid CN0 (in dB-Hz).
95ABSL_DECLARE_FLAG(int32_t, max_lock_fail); //!< Maximum number of code lock failures before dropping a satellite.
96ABSL_DECLARE_FLAG(int32_t, max_carrier_lock_fail); //!< Maximum number of carrier lock failures before dropping a satellite.
97ABSL_DECLARE_FLAG(double, carrier_lock_th); //!< Carrier lock threshold (in rad).
98ABSL_DECLARE_FLAG(double, dll_bw_hz); //!< Bandwidth of the DLL low pass filter, in Hz (overrides the configuration file).
99ABSL_DECLARE_FLAG(double, pll_bw_hz); //!< Bandwidth of the PLL low pass filter, in Hz (overrides the configuration file).
100
101// Declare flags for observables block
102ABSL_DECLARE_FLAG(int32_t, carrier_smoothing_factor); //!< Sets carrier smoothing factor M (overrides the configuration file).
103const int32_t DEFAULT_CARRIER_SMOOTHING_FACTOR = 200;
104
105// Declare flags for PVT
106ABSL_DECLARE_FLAG(std::string, RINEX_version); //!< If defined, specifies the RINEX version (2.11 or 3.02). Overrides the configuration file.
107ABSL_DECLARE_FLAG(std::string, RINEX_name); //!< If defined, specifies the RINEX files base name
108ABSL_DECLARE_FLAG(bool, keyboard); //!< If set to false, disables the keyboard listener. Only for debug purposes (e.g. ASAN mode termination)
109
110static inline void GetTempDirectories(std::vector<std::string>& list)
111{
112 list.clear();
113 // Directories, in order of preference. If we find a dir that
114 // exists, we stop adding other less-preferred dirs
115 const char* candidates[] = {
116 // Non-null only during unittest/regtest
117 std::getenv("TEST_TMPDIR"),
118
119 // Explicitly-supplied temp dirs
120 std::getenv("TMPDIR"),
121 std::getenv("TMP"),
122
123 // If all else fails
124 "/tmp",
125 };
126 for (auto d : candidates)
127 {
128 if (!d) continue; // Empty env var
129
130 // Make sure we don't surprise anyone who's expecting a '/'
131 std::string dstr = d;
132 if (dstr[dstr.size() - 1] != '/')
133 {
134 dstr += "/";
135 }
136 list.push_back(dstr);
137
138 struct stat statbuf;
139 if (!stat(d, &statbuf) && S_ISDIR(statbuf.st_mode))
140 {
141 // We found a dir that exists - we're done.
142 return;
143 }
144 }
145}
146
147
148static inline void GetExistingTempDirectories(std::vector<std::string>& list)
149{
150 GetTempDirectories(list);
151 auto i_dir = list.begin();
152 while (i_dir != list.end())
153 {
154 if (access(i_dir->c_str(), 0))
155 {
156 i_dir = list.erase(i_dir);
157 }
158 else
159 {
160 ++i_dir;
161 }
162 };
163}
164
165
166static inline std::string GetTempDir()
167{
168 std::vector<std::string> temp_directories_list;
169 GetExistingTempDirectories(temp_directories_list);
170
171 if (temp_directories_list.empty())
172 {
173 std::cerr << "No temporary directory found\n";
174 exit(EXIT_FAILURE);
175 }
176
177 // Use first directory from list of existing temporary directories.
178 return temp_directories_list.front();
179}
180
181bool ValidateFlags();
182
183#endif
184
185/** \} */
186/** \} */
187#endif // GNSS_SDR_GNSS_SDR_FLAGS_H
ABSL_DECLARE_FLAG(std::string, c)
Path to the configuration file.