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.
23 #include "IGC/IGCParser.hpp"
24 #include "IGC/IGCFix.hpp"
25 #include "IO/FileLineReader.hpp"
26 #include "OS/FileUtil.hpp"
27 #include "Util/StaticString.hpp"
33 StaticString
<64> name
;
35 unsigned year
, month
, day
;
37 IGCFix previous
, slow
, fast
, takeoff
, landing
;
38 bool previous_valid
, takeoff_valid
, landing_valid
;
39 unsigned slow_count
, fast_count
;
42 FlightCheck(const TCHAR
*_name
)
44 year(0), month(0), day(0),
45 previous_valid(false), takeoff_valid(false),
46 slow_count(0), fast_count(0) {}
48 void date(unsigned _year
, unsigned _month
, unsigned _day
) {
55 _tprintf(_T("%s,%04u-%02u-%02u,%02u:%02u,%02u:%02u\n"), name
.c_str(),
57 takeoff
.time
.hour
, takeoff
.time
.minute
,
58 landing
.time
.hour
, landing
.time
.minute
);
61 void fix(const IGCFix
&fix
);
66 FlightCheck::fix(const IGCFix
&fix
)
71 if (previous_valid
&& fix
.time
> previous
.time
) {
72 fixed distance
= fix
.location
.Distance(previous
.location
);
73 fixed speed
= distance
/ (fix
.time
.GetSecondOfDay() - previous
.time
.GetSecondOfDay());
74 if (speed
> fixed(15)) {
82 if (speed
< fixed(5)) {
90 if (slow_count
> 10) {
95 takeoff_valid
= landing_valid
= false;
98 if (fast_count
> 10) {
100 takeoff_valid
= true;
106 previous_valid
= true;
110 FlightCheck::finish()
114 landing_valid
= true;
120 class IGCFileVisitor
: public File::Visitor
{
121 virtual void Visit(const TCHAR
*path
, const TCHAR
*filename
);
125 IGCFileVisitor::Visit(const TCHAR
*path
, const TCHAR
*filename
)
127 FileLineReaderA
reader(path
);
128 if (reader
.error()) {
129 _ftprintf(stderr
, _T("Failed to open %s\n"), path
);
133 FlightCheck
flight(filename
);
135 while ((line
= reader
.ReadLine()) != NULL
) {
136 unsigned day
, month
, year
;
139 if (IGCParseFix(line
, fix
))
141 else if (sscanf(line
, "HFDTE%02u%02u%02u", &day
, &month
, &year
)) {
142 /* damn you, Y2K bug! */
148 flight
.date(year
, month
, day
);
155 int main(gcc_unused
int argc
, gcc_unused
char **argv
)
157 IGCFileVisitor visitor
;
158 Directory::VisitSpecificFiles(_T("."), _T("*.igc"), visitor
);