Fixposition SDK 0.0.0-heads/main-0-gd0a6ce2
Collection of c++ libraries and apps for use with Fixposition products
Loading...
Searching...
No Matches
fpltool_opts.hpp
Go to the documentation of this file.
1/**
2 * \verbatim
3 * ___ ___
4 * \ \ / /
5 * \ \/ / Copyright (c) Fixposition AG (www.fixposition.com) and contributors
6 * / /\ \ License: see the LICENSE file
7 * /__/ \__\
8 * \endverbatim
9 *
10 * @file
11 * @brief Fixposition SDK: fpltool args (command line arguments)
12 */
13#ifndef __FPSDK_APPS_FPLTOOL_FPLTOOL_ARGS_HPP__
14#define __FPSDK_APPS_FPLTOOL_FPLTOOL_ARGS_HPP__
15
16/* LIBC/STL */
17#include <cstdint>
18#include <string>
19#include <vector>
20
21/* EXTERNAL */
22#include <unistd.h>
23
24/* Fixposition SDK */
25#include <fpsdk_common/app.hpp>
27
28/* PACKAGE */
29
30namespace fpsdk {
31namespace apps {
32namespace fpltool {
33/* ****************************************************************************************************************** */
34
35/**
36 * @brief Program options
37 */
39{
40 public:
41 FplToolOptions() // clang-format off
42 : ProgramOptions("fpltool", {
43 { 'f', false }, { 'o', true }, { 'x', false }, { 'p', false },
44 { 'P', false }, { 'c', false }, { 'S', true }, { 'D', true } }) {}; // clang-format on
45
46 /**
47 * @brief Commands, modes of operation
48 */
49 enum class Command
50 {
51 UNSPECIFIED, //!< Bad command
52 DUMP, //!< Dump a log (for debugging)
53 META, //!< Get logfile meta data
54 ROSBAG, //!< Create ROS bag from log
55 TRIM, //!< Trim .fpl file
56 RECORD, //!< Record a log
57 EXTRACT, //!< Extract .fpl file to various (non-ROS) files
58 };
59
60 // clang-format off
61 Command command_ = Command::UNSPECIFIED; //!< Command to execute
62 std::string command_str_; //!< String of command_, for debugging
63 std::vector<std::string> inputs_; //!< List of input (files), or other positional arguments
64 std::string output_; //!< Output (file or directory, depending on command)
65 bool overwrite_ = false; //!< Overwrite existing output files
66 int extra_ = 0; //!< Enable extra output, such as hexdumps
67 int progress_ = 0; //!< Do progress reports
68 int compress_ = 0; //!< Compress output
69 uint32_t skip_ = 0; //!< Skip start [sec]
70 uint32_t duration_ = 0; //!< Duration [sec]
71 // clang-format on
72
73 void PrintHelp() final
74 {
75 // clang-format off
76 std::fputs(
77 "\n"
78 "Tool for .fpl logfiles\n"
79 "\n"
80 "Usage:\n"
81 "\n"
82 " parsertool [flags] <input> [<input> ...]\n"
83 "\n"
84 "Usage:\n"
85 "\n"
86 " fpltool [<flags>] <command> [...]\n"
87 "\n"
88 "Where (availability of flags depends on <command>, see below):\n"
89 "\n" ,stdout);
90 std::fputs(COMMON_FLAGS_HELP, stdout);
91 std::fputs(
92 " -p / -P -- Show / don't show progress (default: automatic)\n"
93 " -f -- Force overwrite output (default: refuse to overwrite existing output files)\n"
94 " -c -- Compress output (e.g. ROS bags), -c -c to compress more\n"
95 " -x -- Add extra output, multiple -x can be given\n"
96 " -o <out> -- Output to <out>\n"
97 " -S <sec> -- Skip <sec> seconds from start of log (approximate!) (default: 0, i.e. no skip)\n"
98 " -D <sec> -- Process <sec> seconds of log (approximate!) (default: everything)\n"
99 " \n"
100 "Print information about the data in a .fpl logfile, along with status and meta data\n"
101 "\n"
102 " fpltool [-vqpPx] dump <fpl-file>\n"
103 "\n"
104 "Print the meta data from a .fpl logfile (as YAML)\n"
105 "\n"
106 " fpltool [-vqpP] meta <fpl-file>\n"
107#ifdef FP_USE_ROS1
108 "\n"
109 "Generate a ROS bag from a .fpl logfile\n"
110 "\n"
111 " fpltool [-vqpPfoSD] robag <fpl-file>\n"
112#endif
113 "\n"
114 "Trim start and/or end of .fpl logfile, i.e. extract a portion of the file. Note that this process is\n"
115 "inaccurate and the effective start time and duration of the resulting file may be off by 30 to 60 seconds.\n"
116 "Therefore, both the start time (-S) and the duration (-D) must be at least 60 seconds.\n"
117 "\n"
118 " fpltool [-vqpPfo] -S <sec> -D <sec> <fpl-file>\n"
119 "\n"
120 "Extract (som) non-ROS data from the .fpl logfile\n"
121 "\n"
122 " fpltool [-vqpP] extract <fpl-file>\n"
123 "\n"
124 "Examples:\n"
125#ifdef FP_USE_ROS1
126 "\n"
127 " Create a some.bag from a some.fpl logfile:\n"
128 "\n"
129 " fpltool rosbag some.fpl\n"
130 "\n"
131 " Create a compressed another.bag with 2 minutes of data starting 60 seconds into some.fpl logfile:\n"
132 "\n"
133 " fpltool rosbag some.fpl -c -c -o another.bag -S 60 -D 120\n"
134#endif
135 "\n"
136 " Show meta data of some.fpl:\n"
137 "\n"
138 " fpltool meta some.fpl\n"
139 "\n"
140 " Trim a verylong.fpl into a shorter one:\n"
141 "\n"
142 " fpltool trim some.fpl -S 3600 -D 1800\n"
143 "\n"
144 " Extract data from some.fpl:\n"
145 "\n"
146 " fpltool extract some.fpl\n"
147 "\n"
148 " This results in various data files suitable for further processing. For example, the input/output\n"
149 " messages received/sent by the sensor can be processed by the parsertool:\n"
150 "\n"
151 " parsertool some_userio.raw\n"
152 "\n"
153 "\n", stdout);
154 // clang-format on
155 }
156
157 bool HandleOption(const Option& option, const std::string& argument) final
158 {
159 bool ok = true;
160 switch (option.flag) {
161 case 'f':
162 overwrite_ = true;
163 break;
164 case 'o':
165 output_ = argument;
166 break;
167 case 'x':
168 extra_++;
169 break;
170 case 'p':
171 progress_++;
172 progress_set_ = true;
173 break;
174 case 'P':
175 progress_ = 0;
176 progress_set_ = true;
177 break;
178 case 'c':
179 compress_++;
180 break;
181 case 'S':
183 ok = false;
184 }
185 break;
186 case 'D':
187 if (!fpsdk::common::string::StrToValue(argument, duration_) || (duration_ < 1)) {
188 ok = false;
189 }
190 break;
191 default:
192 ok = false;
193 break;
194 }
195 return ok;
196 }
197
198 bool CheckOptions(const std::vector<std::string>& args) final
199 {
200 bool ok = true;
201
202 // There must a remaining argument, which is the command
203 if (args.size() > 0) {
204 command_str_ = args[0];
205 // clang-format off
206 if (command_str_ == "meta") { command_ = Command::META; }
207 else if (command_str_ == "dump") { command_ = Command::DUMP; }
208 else if (command_str_ == "rosbag") { command_ = Command::ROSBAG; }
209 else if (command_str_ == "trim") { command_ = Command::TRIM; }
210 else if (command_str_ == "record") { command_ = Command::RECORD; }
211 else if (command_str_ == "extract") { command_ = Command::EXTRACT; }
212 // clang-format on
213 else {
214 WARNING("Unknown command '%s'", command_str_.c_str());
215 ok = false;
216 }
217 } else {
218 WARNING("Missing command or wrong arguments");
219 ok = false;
220 }
221
222 // Any further positional arguments
223 for (std::size_t ix = 1; ix < args.size(); ix++) {
224 inputs_.push_back(args[ix]);
225 }
226
227 // Default enable progress output and colours if run interactively
228 if (!progress_set_ && (isatty(fileno(stdin)) == 1)) {
229 progress_ = 1;
230 }
231
232 // Debug
233 DEBUG("command_ = '%s'", command_str_.c_str());
234 for (std::size_t ix = 0; ix < inputs_.size(); ix++) {
235 DEBUG("inputs_[%" PRIuMAX "] = '%s'", ix, inputs_[ix].c_str());
236 }
237 DEBUG("output = '%s'", output_.c_str());
238 DEBUG("overwrite = %s", overwrite_ ? "true" : "false");
239 DEBUG("extra = %d", extra_);
240 DEBUG("progress = %d", progress_);
241 DEBUG("compress = %d", compress_);
242 DEBUG("skip = %d", skip_);
243 DEBUG("duration = %d", duration_);
244
245 return ok;
246 }
247
248 private:
249 bool progress_set_ = false;
250};
251
252/* ****************************************************************************************************************** */
253} // namespace fpltool
254} // namespace apps
255} // namespace fpsdk
256#endif // __FPSDK_APPS_FPLTOOL_FPLTOOL_ARGS_HPP__
Fixposition SDK: Utilities for apps.
uint32_t duration_
Duration [sec].
void PrintHelp() final
Print the help screen and exit(0)
std::string output_
Output (file or directory, depending on command)
Command command_
Command to execute.
int progress_
Do progress reports.
Command
Commands, modes of operation.
@ EXTRACT
Extract .fpl file to various (non-ROS) files.
bool overwrite_
Overwrite existing output files.
std::string command_str_
String of command_, for debugging.
std::vector< std::string > inputs_
List of input (files), or other positional arguments.
bool HandleOption(const Option &option, const std::string &argument) final
Handle a command-line flag argument.
int extra_
Enable extra output, such as hexdumps.
uint32_t skip_
Skip start [sec].
bool CheckOptions(const std::vector< std::string > &args) final
Check options, and handle non-flag arguments.
ProgramOptions(const std::string &app_name, const std::vector< Option > &options)
Constructor.
static constexpr const char * COMMON_FLAGS_HELP
Help screen for common options.
Definition app.hpp:213
Fixposition SDK: Logging.
#define WARNING(...)
Print a warning message.
Definition logging.hpp:60
#define DEBUG(...)
Print a debug message.
Definition logging.hpp:72
bool StrToValue(const std::string &str, int8_t &value)
Convert string to value (int8_t)
Fixposition SDK.