TaskManager: remove GetStartState() and GetFinishState()
[xcsoar.git] / test / src / FlightPath.cpp
blob59006769fc11f46b7b9eedc01b5ecac84b43411b
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2013 The XCSoar Project
6 A detailed list of copyright holders can be found in the file "AUTHORS".
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 #include "OS/Args.hpp"
25 #include "DebugReplay.hpp"
26 #include "Engine/Trace/Trace.hpp"
28 int main(int argc, char **argv)
30 int start = -1, end = -1;
31 unsigned max_points = 1000;
33 Args args(argc, argv,
34 "[options] DRIVER FILE\n"
35 "Options:\n"
36 " --start=5000 Begin flight path at 5000 sec after UTC midnight,\n"
37 " if not defined takeoff time is used\n"
38 " --end=15000 End flight path at 15000 sec after UTC midnight,\n"
39 " if not defined the last timestamp in the file is used\n"
40 " --max-points=1000 Maximum number of trace points in output (default = 1000)");
42 const char *arg;
43 while ((arg = args.PeekNext()) != nullptr && *arg == '-') {
44 args.Skip();
46 const char *value;
47 if ((value = StringAfterPrefix(arg, "--max-points=")) != nullptr) {
48 unsigned _max_points = strtol(value, NULL, 10);
49 if (_max_points > 0)
50 max_points = _max_points;
51 } else if ((value = StringAfterPrefix(arg, "--start=")) != nullptr) {
52 char *endptr;
53 start = strtol(value, &endptr, 10);
54 if (endptr == value || *endptr != '\0' || start < 0) {
55 fputs("The start parameter could not be parsed correctly.\n", stderr);
56 args.UsageError();
58 } else if ((value = StringAfterPrefix(arg, "--end=")) != nullptr) {
59 char *endptr;
60 end = strtol(value, &endptr, 10);
61 if (endptr == value || *endptr != '\0' || end < 0) {
62 fputs("The end parameter could not be parsed correctly.\n", stderr);
63 args.UsageError();
65 } else {
66 args.UsageError();
70 if (start >= 0 && end >= 0 && start >= end) {
71 fputs("The start parameter has to be smaller than the end parameter.\n", stderr);
72 args.UsageError();
75 DebugReplay *replay = CreateDebugReplay(args);
76 if (replay == nullptr)
77 return EXIT_FAILURE;
79 args.ExpectEnd();
81 Trace trace(0, Trace::null_time, max_points);
83 bool takeoff = false;
85 while (replay->Next()) {
86 const MoreData &basic = replay->Basic();
87 const DerivedInfo &calculated = replay->Calculated();
89 if (!basic.time_available || !basic.location_available ||
90 !basic.NavAltitudeAvailable())
91 continue;
93 if (start >= 0 && (int)basic.time < start)
94 continue;
96 if (end >= 0 && (int)basic.time > end)
97 break;
99 trace.push_back(TracePoint(basic));
101 if (start < 0 && calculated.flight.flying && !takeoff) {
102 takeoff = true;
103 trace.EraseEarlierThan(calculated.flight.takeoff_time);
107 delete replay;
109 for (auto i = trace.begin(), end = trace.end(); i != end; ++i) {
110 const TracePoint &point = *i;
111 printf("%u %f %f %d %u\n",
112 point.GetTime(),
113 (double)point.GetLocation().latitude.Degrees(),
114 (double)point.GetLocation().longitude.Degrees(),
115 point.GetIntegerAltitude(),
116 point.GetEngineNoiseLevel());