android/GlueIOIOPort: fix spurious errors after IOIO baud rate change
[xcsoar.git] / test / src / FlightPhaseDetector.hpp
blob448c81600b9604fb698eee66ee26b9c46f7e2343
1 /* Copyright_License {
3 XCSoar Glide Computer - http://www.xcsoar.org/
4 Copyright (C) 2000-2013 The XCSoar Project
5 A detailed list of copyright holders can be found in the file "AUTHORS".
7 This program is free software; you can redistribute it and/or
8 modify it under the terms of the GNU General Public License
9 as published by the Free Software Foundation; either version 2
10 of the License, or (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #ifndef XCSOAR_FLIGHT_PHASE_DETECTOR_HPP
23 #define XCSOAR_FLIGHT_PHASE_DETECTOR_HPP
25 #include <list>
27 #include "Math/fixed.hpp"
28 #include "Geo/GeoPoint.hpp"
29 #include "Time/BrokenDateTime.hpp"
31 struct MoreData;
32 struct DerivedInfo;
33 enum class CirclingMode : uint8_t;
35 /**
36 * Phase of the flight.
38 * May represent both single phase and totals for a set of phases.
40 struct Phase {
42 enum Type : uint8_t {
43 NO_PHASE,
44 CRUISE,
45 CIRCLING,
46 POWERED
49 enum CirclingDirection : uint8_t {
50 NO_DIRECTION,
51 LEFT,
52 RIGHT,
53 MIXED
56 /** Type of the phase */
57 Type phase_type;
58 /** Date and time in UTC when the phase started */
59 BrokenDateTime start_datetime;
60 /** Date and time in UTC when the phase ended */
61 BrokenDateTime end_datetime;
62 /** Seconds from midnight UTC when the phase started */
63 fixed start_time;
64 /** Seconds from midnight UTC when the phase ended */
65 fixed end_time;
66 /** Direction of circling (or NO_DIRECTION when not circling) */
67 CirclingDirection circling_direction;
68 /** Starting altitude of the phase */
69 fixed start_alt;
70 /** Ending altitude of the phase */
71 fixed end_alt;
72 /** Starting location of the phase */
73 GeoPoint start_loc;
74 /** Ending location of the phase */
75 GeoPoint end_loc;
76 /** Duration of the phase in seconds */
77 fixed duration;
78 /** Fraction of the phase duration compared to total flight time. */
79 fixed fraction;
80 /** Altitude difference between start_alt and end_alt */
81 fixed alt_diff;
82 /** Distance travelled during the phase, i.e. sum of distances between fixes. */
83 fixed distance;
84 /** Number of the phases of the same type, combined into this phase. */
85 unsigned int merges;
87 /** Average ground speed during the phase */
88 fixed GetSpeed() const;
89 /** Average vertical speed during the phase */
90 fixed GetVario() const;
91 /** Average glide rate during the phase */
92 fixed GetGlideRate() const;
94 /**
95 * Reinitialize phase
97 void Clear() {
98 phase_type = NO_PHASE;
99 start_datetime.Clear();
100 end_datetime.Clear();
101 start_time = fixed(0);
102 end_time = fixed(0);
103 duration = fixed(0);
104 fraction = fixed(0);
105 circling_direction = NO_DIRECTION;
106 alt_diff = fixed(0);
107 distance = fixed(0);
108 merges = 0;
112 typedef std::list<Phase> PhaseList;
116 * Combined statistics for each phase type
118 struct PhaseTotals {
119 Phase total_circstats,
120 left_circstats,
121 right_circstats,
122 mixed_circstats,
123 total_cruisestats;
125 PhaseTotals() {
126 total_circstats.Clear();
127 left_circstats.Clear();
128 right_circstats.Clear();
129 mixed_circstats.Clear();
130 total_cruisestats.Clear();
136 * Detect flight phases
138 * Divide flight into circling/cruise phases and calculate basic statistics for
139 * each.
141 * Dependencies: #CirclingComputer.
143 class FlightPhaseDetector {
144 private:
145 Phase previous_phase;
146 Phase current_phase;
147 int phase_count;
148 CirclingMode last_turn_mode;
150 PhaseList phases;
151 PhaseTotals totals;
153 void PushPhase();
155 public:
156 FlightPhaseDetector();
159 * Split track to circling/cruise phases and calculate basic statistics for
160 * each.
162 * Actual circling detection is done by #CirclingComputer. We aggregate its
163 * data to a list of Phases by grouping set of samples with the same
164 * CirclingInfo.turn_mode value.
166 * If turn_mode is uncertain for given group (POSSIBLE_CLIMB or
167 * POSSIBLE_CRUISE), actual phase type is determined by subsequent group
168 * and two groups are combined into single phase. If phase is shorter than
169 * certain threshold (MIN_PHASE_TIME), it is not considered as a separate
170 * phase and combined with previous one.
172 * @param basic Basic flight information for the iteration
173 * @param calculated Calculated flight data for the iteration
175 void Update(const MoreData &basic, const DerivedInfo &calculated);
178 * Complete phase calculation and calculate overall flight statistics.
180 * Called at the end of the flight when no flight data is pending.
183 void Finish();
186 * Return detected phases
188 * Available after Finish() is called.
190 const PhaseList &GetPhases() const {
191 return phases;
195 * Return calculated totals
197 * Available after Finish() is called.
199 const PhaseTotals &GetTotals() const {
200 return totals;
204 #endif