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 "Device/Driver.hpp"
25 #include "Device/Register.hpp"
26 #include "Device/Parser.hpp"
27 #include "Device/Port/Port.hpp"
28 #include "Device/Port/ConfiguredPort.hpp"
29 #include "DebugPort.hpp"
30 #include "Engine/Waypoint/Waypoints.hpp"
31 #include "OS/ConvertPathName.hpp"
32 #include "Operation/ConsoleOperationEnvironment.hpp"
33 #include "Profile/DeviceConfig.hpp"
34 #include "OS/Args.hpp"
35 #include "IO/Async/GlobalIOThread.hpp"
36 #include "Util/ConvertString.hpp"
41 NMEAParser::ReadGeoPoint(NMEAInputLine
&line
, GeoPoint
&value_r
)
47 NMEAParser::ReadDate(NMEAInputLine
&line
, BrokenDate
&date
)
53 NMEAParser::TimeHasAdvanced(fixed this_time
, fixed
&last_time
, NMEAInfo
&info
)
59 NMEAParser::TimeModify(fixed fix_time
, BrokenDateTime
&date_time
,
66 PrintFlightList(const RecordedFlightList
&flight_list
)
68 for (auto i
= flight_list
.begin(); i
!= flight_list
.end(); ++i
) {
69 const RecordedFlightInfo
&flight
= *i
;
70 printf("%04u/%02u/%02u %02u:%02u-%02u:%02u\n",
71 flight
.date
.year
, flight
.date
.month
, flight
.date
.day
,
72 flight
.start_time
.hour
, flight
.start_time
.minute
,
73 flight
.end_time
.hour
, flight
.end_time
.minute
);
77 int main(int argc
, char **argv
)
79 NarrowString
<1024> usage
;
80 usage
= "DRIVER PORT BAUD FILE.igc [FLIGHT NR]\n\n"
81 "Where DRIVER is one of:";
83 const DeviceRegister
*driver
;
84 for (unsigned i
= 0; (driver
= GetDriverByIndex(i
)) != NULL
; ++i
) {
85 if (driver
->IsLogger()) {
86 WideToUTF8Converter
driver_name(driver
->name
);
87 usage
.AppendFormat("\n\t%s", (const char *)driver_name
);
92 Args
args(argc
, argv
, usage
);
93 tstring driver_name
= args
.ExpectNextT();
94 const DeviceConfig config
= ParsePortArgs(args
);
96 PathName
path(args
.ExpectNext());
98 unsigned flight_id
= args
.IsEmpty() ? 0 : atoi(args
.GetNext());
101 InitialiseIOThread();
103 Port
*port
= OpenPort(config
, *(DataHandler
*)NULL
);
105 fprintf(stderr
, "Failed to open COM port\n");
109 ConsoleOperationEnvironment env
;
110 const struct DeviceRegister
*driver
= FindDriverByName(driver_name
.c_str());
111 if (driver
== NULL
) {
112 fprintf(stderr
, "No such driver: %s\n", argv
[1]);
116 if (!driver
->IsLogger()) {
117 fprintf(stderr
, "Not a logger driver: %s\n", argv
[1]);
121 assert(driver
->CreateOnPort
!= NULL
);
122 Device
*device
= driver
->CreateOnPort(config
, *port
);
123 assert(device
!= NULL
);
125 RecordedFlightList flight_list
;
126 if (!device
->ReadFlightList(flight_list
, env
)) {
129 fprintf(stderr
, "Failed to download flight list\n");
133 if (flight_list
.empty()) {
136 fprintf(stderr
, "Logger is empty\n");
140 PrintFlightList(flight_list
);
142 if (flight_id
>= flight_list
.size()) {
145 fprintf(stderr
, "Flight id not found\n");
149 if (!device
->DownloadFlight(flight_list
[flight_id
], path
, env
)) {
152 fprintf(stderr
, "Failed to download flight\n");
158 DeinitialiseIOThread();
160 printf("Flight downloaded successfully\n");