Revert "Device/Driver/LX: Add small delay after baud rate change"
[xcsoar.git] / test / src / RunTask.cpp
bloba1143034fbb5c604db71f0c140c73642ad6cd4fb
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 "Task/TaskFile.hpp"
27 #include "Engine/Navigation/Aircraft.hpp"
28 #include "Engine/Waypoint/Waypoints.hpp"
29 #include "Engine/Task/TaskManager.hpp"
30 #include "Engine/Task/Ordered/OrderedTask.hpp"
31 #include "NMEA/Aircraft.hpp"
32 #include "Formatter/TimeFormatter.hpp"
34 #include <stdio.h>
35 #include <stdlib.h>
37 static void
38 Run(DebugReplay &replay, TaskManager &task_manager)
40 if (!replay.Next())
41 return;
43 MoreData last_basic;
44 last_basic = replay.Basic();
46 DerivedInfo last_calculated;
47 last_calculated = replay.Calculated();
49 unsigned active_taskpoint_index(-1);
51 char time_buffer[32];
53 while (replay.Next()) {
54 const MoreData &basic = replay.Basic();
55 const DerivedInfo &calculated = replay.Calculated();
57 if (!basic.HasTimeAdvancedSince(last_basic) ||
58 !basic.location_available)
59 continue;
61 const AircraftState current_as = ToAircraftState(basic, calculated);
62 const AircraftState last_as = ToAircraftState(last_basic,
63 last_calculated);
64 task_manager.Update(current_as, last_as);
65 task_manager.UpdateIdle(current_as);
66 task_manager.SetTaskAdvance().SetArmed(true);
68 const CommonStats &common_stats = task_manager.GetCommonStats();
69 if (common_stats.active_taskpoint_index != active_taskpoint_index) {
70 active_taskpoint_index = common_stats.active_taskpoint_index;
72 FormatISO8601(time_buffer, basic.date_time_utc);
73 printf("%s active_taskpoint_index=%u\n",
74 time_buffer, active_taskpoint_index);
77 last_basic = basic;
78 last_calculated = calculated;
81 const TaskStats &task_stats = task_manager.GetOrderedTask().GetStats();
83 printf("task_started=%d task_finished=%d\n",
84 task_stats.start.task_started,
85 task_stats.task_finished);
87 printf("task elapsed %ds\n", (int)task_stats.total.time_elapsed);
88 printf("task speed %1.1f kph\n",
89 double(task_stats.total.travelled.GetSpeed() * fixed(3.6)));
90 printf("travelled distance %1.1f km\n",
91 double(task_stats.total.travelled.GetDistance() / 1000));
92 printf("scored distance %1.1f km\n",
93 double(task_stats.distance_scored / 1000));
94 if (positive(task_stats.total.time_elapsed))
95 printf("scored speed %1.1f kph\n",
96 double(task_stats.distance_scored
97 / task_stats.total.time_elapsed * fixed(3.6)));
100 int main(int argc, char **argv)
102 Args args(argc, argv, "TASKFILE REPLAYFILE");
103 tstring task_path = args.ExpectNextT();
104 DebugReplay *replay = CreateDebugReplay(args);
105 if (replay == NULL)
106 return EXIT_FAILURE;
108 args.ExpectEnd();
110 Waypoints way_points;
112 TaskBehaviour task_behaviour;
113 task_behaviour.SetDefaults();
115 OrderedTask *task = TaskFile::GetTask(task_path.c_str(), task_behaviour,
116 NULL, 0);
117 if (task == NULL) {
118 fprintf(stderr, "Failed to load task\n");
119 return EXIT_FAILURE;
122 TaskManager task_manager(task_behaviour, way_points);
123 task_manager.SetGlidePolar(GlidePolar(fixed(1)));
125 if (!task_manager.Commit(*task)) {
126 fprintf(stderr, "Failed to commit task\n");
127 return EXIT_FAILURE;
130 delete task;
132 Run(*replay, task_manager);
133 delete replay;
135 return EXIT_SUCCESS;