Revert "Device/Driver/LX: Add small delay after baud rate change"
[xcsoar.git] / test / src / RunDownloadFlight.cpp
blob0c0253a59a9cefc0a2697c67e97dee1ef88e7c90
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 "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"
38 #include <stdio.h>
40 bool
41 NMEAParser::ReadGeoPoint(NMEAInputLine &line, GeoPoint &value_r)
43 return false;
46 bool
47 NMEAParser::ReadDate(NMEAInputLine &line, BrokenDate &date)
49 return false;
52 bool
53 NMEAParser::TimeHasAdvanced(fixed this_time, fixed &last_time, NMEAInfo &info)
55 return false;
58 fixed
59 NMEAParser::TimeModify(fixed fix_time, BrokenDateTime &date_time,
60 bool date_available)
62 return fixed(0);
65 static void
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());
99 args.ExpectEnd();
101 InitialiseIOThread();
103 Port *port = OpenPort(config, *(DataHandler *)NULL);
104 if (port == NULL) {
105 fprintf(stderr, "Failed to open COM port\n");
106 return EXIT_FAILURE;
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]);
113 args.UsageError();
116 if (!driver->IsLogger()) {
117 fprintf(stderr, "Not a logger driver: %s\n", argv[1]);
118 args.UsageError();
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)) {
127 delete device;
128 delete port;
129 fprintf(stderr, "Failed to download flight list\n");
130 return EXIT_FAILURE;
133 if (flight_list.empty()) {
134 delete device;
135 delete port;
136 fprintf(stderr, "Logger is empty\n");
137 return EXIT_FAILURE;
140 PrintFlightList(flight_list);
142 if (flight_id >= flight_list.size()) {
143 delete device;
144 delete port;
145 fprintf(stderr, "Flight id not found\n");
146 return EXIT_FAILURE;
149 if (!device->DownloadFlight(flight_list[flight_id], path, env)) {
150 delete device;
151 delete port;
152 fprintf(stderr, "Failed to download flight\n");
153 return EXIT_FAILURE;
156 delete device;
157 delete port;
158 DeinitialiseIOThread();
160 printf("Flight downloaded successfully\n");
162 return EXIT_SUCCESS;