1 #include "test_debug.hpp"
2 #include "harness_aircraft.hpp"
3 #include "TaskEventsPrint.hpp"
4 #include "Replay/IgcReplay.hpp"
5 #include "Task/TaskManager.hpp"
6 #include "Engine/Navigation/Aircraft.hpp"
7 #include "Engine/Task/Ordered/OrderedTask.hpp"
8 #include "Computer/FlyingComputer.hpp"
9 #include "NMEA/FlyingState.hpp"
10 #include "OS/ConvertPathName.hpp"
11 #include "OS/FileUtil.hpp"
12 #include "IO/FileLineReader.hpp"
13 #include "Task/Deserialiser.hpp"
14 #include "XML/DataNodeXML.hpp"
15 #include "NMEA/Info.hpp"
16 #include "Engine/Waypoint/Waypoints.hpp"
20 static OrderedTask
* task_load(OrderedTask
* task
) {
21 PathName
szFilename(task_file
.c_str());
22 DataNode
*root
= DataNodeXML::Load(szFilename
);
26 Deserialiser
des(*root
);
27 des
.Deserialise(*task
);
28 if (task
->CheckTask()) {
37 class ReplayLoggerSim
: public IgcReplay
40 ReplayLoggerSim(NLineReader
*reader
)
46 void print(std::ostream
&f
) {
47 f
<< (double)state
.time
<< " "
48 << (double)state
.location
.longitude
.Degrees() << " "
49 << (double)state
.location
.latitude
.Degrees() << " "
50 << (double)state
.altitude
<< "\n";
55 virtual void OnReset() {}
56 virtual void OnStop() {}
58 void OnAdvance(const GeoPoint
&loc
,
59 const fixed speed
, const Angle bearing
,
60 const fixed alt
, const fixed baroalt
, const fixed t
) {
63 state
.ground_speed
= speed
;
64 state
.track
= bearing
;
76 Directory::Create(_T("output/results"));
77 std::ofstream
f("output/results/res-sample.txt");
79 GlidePolar
glide_polar(fixed(4.0));
81 AircraftState state_last
;
83 TaskBehaviour task_behaviour
;
84 task_behaviour
.SetDefaults();
85 task_behaviour
.auto_mc
= true;
86 task_behaviour
.enable_trace
= false;
88 TaskManager
task_manager(task_behaviour
, waypoints
);
90 TaskEventsPrint
default_events(verbose
);
91 task_manager
.SetTaskEvents(default_events
);
93 glide_polar
.SetBallast(fixed(1.0));
95 task_manager
.SetGlidePolar(glide_polar
);
97 OrderedTask
* blank
= new OrderedTask(task_manager
.GetTaskBehaviour());
99 OrderedTask
* t
= task_load(blank
);
101 task_manager
.Commit(*t
);
102 task_manager
.Resume();
107 // task_manager.get_task_advance().get_advance_state() = TaskAdvance::AUTO;
109 FileLineReaderA
*reader
= new FileLineReaderA(replay_file
.c_str());
110 if (reader
->error()) {
115 ReplayLoggerSim
sim(reader
);
116 sim
.state
.netto_vario
= fixed(0);
118 bool do_print
= verbose
;
119 unsigned print_counter
=0;
124 while (sim
.Update(basic
) && !sim
.started
) {
126 state_last
= sim
.state
;
128 sim
.state
.wind
.norm
= fixed(7);
129 sim
.state
.wind
.bearing
= Angle::Degrees(330);
131 fixed time_last
= sim
.state
.time
;
133 // uncomment this to manually go to first tp
134 // task_manager.incrementActiveTaskPoint(1);
136 FlyingComputer flying_computer
;
137 flying_computer
.Reset();
139 FlyingState flying_state
;
140 flying_state
.Reset();
142 while (sim
.Update(basic
)) {
143 if (sim
.state
.time
>time_last
) {
147 flying_computer
.Compute(glide_polar
.GetVTakeoff(),
148 sim
.state
, sim
.state
.time
- time_last
,
150 sim
.state
.flying
= flying_state
.flying
;
152 task_manager
.Update(sim
.state
, state_last
);
153 task_manager
.UpdateIdle(sim
.state
);
154 task_manager
.UpdateAutoMC(sim
.state
, fixed(0));
155 task_manager
.SetTaskAdvance().SetArmed(true);
157 state_last
= sim
.state
;
164 PrintHelper::taskmanager_print(task_manager
, sim
.state
);
166 do_print
= (++print_counter
% output_skip
==0) && verbose
;
168 time_last
= sim
.state
.time
;
172 PrintDistanceCounts();
173 printf("# task elapsed %d (s)\n", (int)task_manager
.GetStats().total
.time_elapsed
);
174 printf("# task speed %3.1f (kph)\n", (int)task_manager
.GetStats().total
.travelled
.GetSpeed()*3.6);
175 printf("# travelled distance %4.1f (km)\n",
176 (double)task_manager
.GetStats().total
.travelled
.GetDistance()/1000.0);
177 printf("# scored distance %4.1f (km)\n",
178 (double)task_manager
.GetStats().distance_scored
/1000.0);
179 if (positive(task_manager
.GetStats().total
.time_elapsed
)) {
180 printf("# scored speed %3.1f (kph)\n",
181 (double)task_manager
.GetStats().distance_scored
/(double)task_manager
.GetStats().total
.time_elapsed
*3.6);
188 int main(int argc
, char** argv
)
192 replay_file
= "test/data/apf-bug554.igc";
193 task_file
= "test/data/apf-bug554.tsk";
195 if (!ParseArgs(argc
,argv
)) {
201 ok(test_replay(),"replay task",0);
203 return exit_status();