Renderer, ...: use PixelRect::GetCenter()
[xcsoar.git] / test / src / DebugReplayIGC.cpp
blobdbe1851597501d4d937c0d09b2e460b811b89ea0
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 "DebugReplayIGC.hpp"
25 #include "IO/FileLineReader.hpp"
26 #include "IGC/IGCParser.hpp"
27 #include "IGC/IGCFix.hpp"
28 #include "Units/System.hpp"
30 bool
31 DebugReplayIGC::Next()
33 last_basic = computed_basic;
35 const char *line;
36 while ((line = reader->ReadLine()) != NULL) {
37 if (line[0] == 'B') {
38 IGCFix fix;
39 if (IGCParseFix(line, extensions, fix)) {
40 CopyFromFix(fix);
42 Compute();
43 return true;
45 } else if (line[0] == 'H') {
46 BrokenDate date;
47 if (memcmp(line, "HFDTE", 5) == 0 &&
48 IGCParseDateRecord(line, date)) {
49 (BrokenDate &)raw_basic.date_time_utc = date;
50 raw_basic.date_available = true;
51 raw_basic.time_available.Clear();
53 } else if (line[0] == 'I') {
54 IGCParseExtensions(line, extensions);
58 if (computed_basic.time_available)
59 flying_computer.Finish(calculated.flight, computed_basic.time);
61 return false;
64 void
65 DebugReplayIGC::CopyFromFix(const IGCFix &fix)
67 NMEAInfo &basic = raw_basic;
69 if (basic.time_available && basic.date_time_utc.hour >= 23 &&
70 fix.time.hour == 0) {
71 /* midnight roll-over */
72 ++day;
73 raw_basic.date_time_utc.IncrementDay();
76 basic.clock = basic.time =
77 fixed(day * 24 * 3600 + fix.time.GetSecondOfDay());
78 basic.time_available.Update(basic.clock);
79 basic.date_time_utc.hour = fix.time.hour;
80 basic.date_time_utc.minute = fix.time.minute;
81 basic.date_time_utc.second = fix.time.second;
82 basic.alive.Update(basic.clock);
83 basic.location = fix.location;
85 if (fix.gps_valid)
86 basic.location_available.Update(basic.clock);
87 else
88 basic.location_available.Clear();
90 if (fix.gps_altitude != 0) {
91 basic.gps_altitude = fixed(fix.gps_altitude);
93 if (fix.gps_valid)
94 basic.gps_altitude_available.Update(basic.clock);
95 else
96 basic.gps_altitude_available.Clear();
97 } else
98 basic.gps_altitude_available.Clear();
100 if (fix.pressure_altitude != 0) {
101 basic.pressure_altitude = basic.baro_altitude = fixed(fix.pressure_altitude);
102 basic.pressure_altitude_available.Update(basic.clock);
103 basic.baro_altitude_available.Update(basic.clock);
106 if (fix.enl >= 0) {
107 basic.engine_noise_level = fix.enl;
108 basic.engine_noise_level_available.Update(basic.clock);
111 if (fix.trt >= 0) {
112 basic.track = Angle::Degrees(fixed(fix.trt));
113 basic.track_available.Update(basic.clock);
116 if (fix.gsp >= 0) {
117 basic.ground_speed = Units::ToSysUnit(fixed(fix.gsp),
118 Unit::KILOMETER_PER_HOUR);
119 basic.ground_speed_available.Update(basic.clock);
122 if (fix.ias >= 0) {
123 fixed ias = Units::ToSysUnit(fixed(fix.ias), Unit::KILOMETER_PER_HOUR);
124 if (fix.tas >= 0)
125 basic.ProvideBothAirspeeds(ias,
126 Units::ToSysUnit(fixed(fix.tas),
127 Unit::KILOMETER_PER_HOUR));
128 else
129 basic.ProvideIndicatedAirspeedWithAltitude(ias, basic.pressure_altitude);
130 } else if (fix.tas >= 0)
131 basic.ProvideTrueAirspeed(Units::ToSysUnit(fixed(fix.tas),
132 Unit::KILOMETER_PER_HOUR));
134 if (fix.siu >= 0) {
135 basic.gps.satellites_used = fix.siu;
136 basic.gps.satellites_used_available.Update(basic.clock);