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/Driver/FLARM/Device.hpp"
26 #include "Device/Register.hpp"
27 #include "Device/Parser.hpp"
28 #include "Device/device.hpp"
29 #include "Logger/Settings.hpp"
30 #include "Plane/Plane.hpp"
31 #include "Engine/Waypoint/Waypoints.hpp"
32 #include "Operation/ConsoleOperationEnvironment.hpp"
33 #include "Profile/DeviceConfig.hpp"
34 #include "Device/Port/Port.hpp"
35 #include "Device/Port/ConfiguredPort.hpp"
36 #include "Device/Declaration.hpp"
37 #include "DebugPort.hpp"
38 #include "IO/Async/GlobalIOThread.hpp"
41 #include "OS/Args.hpp"
48 fputs("Where DRIVER0 is one of:\n", stderr
);
50 const struct DeviceRegister
*driver
;
51 for (unsigned i
= 0; (driver
= GetDriverByIndex(i
)) != NULL
; ++i
)
52 if (driver
->HasPassThrough())
53 _ftprintf(stderr
, _T("\t%s\n"), driver
->name
);
55 fputs("Where DRIVER is one of:\n", stderr
);
57 for (unsigned i
= 0; (driver
= GetDriverByIndex(i
)) != NULL
; ++i
)
58 if (driver
->CanDeclare())
59 _ftprintf(stderr
, _T("\t%s\n"), driver
->name
);
63 NMEAParser::ReadGeoPoint(NMEAInputLine
&line
, GeoPoint
&value_r
)
69 NMEAParser::ReadDate(NMEAInputLine
&line
, BrokenDate
&date
)
75 NMEAParser::TimeHasAdvanced(fixed this_time
, fixed
&last_time
, NMEAInfo
&info
)
81 NMEAParser::TimeModify(fixed fix_time
, BrokenDateTime
&date_time
,
88 MakeWaypoint(const TCHAR
*name
, int altitude
,
89 double longitude
, double latitude
)
91 Waypoint
wp(GeoPoint(Angle::Degrees(longitude
),
92 Angle::Degrees(latitude
)));
94 wp
.elevation
= fixed(altitude
);
98 int main(int argc
, char **argv
)
100 Args
args(argc
, argv
, "[--through DRIVER0] DRIVER PORT BAUD");
102 tstring _through_name
;
103 const TCHAR
*through_name
= NULL
;
106 while ((a
= args
.PeekNext()) != NULL
&& *a
== '-') {
107 a
= args
.ExpectNext();
108 if (strcmp(a
, "--through") == 0) {
109 _through_name
= args
.ExpectNextT();
110 through_name
= _through_name
.c_str();
115 tstring _driver_name
= args
.ExpectNextT();
116 const TCHAR
*driver_name
= _driver_name
.c_str();
117 const DeviceConfig config
= ParsePortArgs(args
);
120 InitialiseIOThread();
122 Port
*port
= OpenPort(config
, *(DataHandler
*)NULL
);
124 fprintf(stderr
, "Failed to open COM port\n");
128 LoggerSettings logger_settings
;
129 logger_settings
.pilot_name
= _T("Foo Bar");
131 plane
.registration
= _T("D-3003");
132 plane
.competition_id
= _T("33");
133 plane
.type
= _T("Cirrus");
135 Declaration
declaration(logger_settings
, plane
, NULL
);
137 declaration
.Append(MakeWaypoint(_T("Bergneustadt"), 488,
138 7.7061111111111114, 51.051944444444445));
139 declaration
.Append(MakeWaypoint(_T("Foo"), 488, 8, 52));
140 declaration
.Append(MakeWaypoint(_T("Bar"), 488, 7.5, 50));
141 declaration
.Append(MakeWaypoint(_T("Bergneustadt"), 488,
142 7.7061111111111114, 51.051944444444445));
144 Device
*through_device
= NULL
;
145 if (through_name
!= NULL
) {
146 const struct DeviceRegister
*through_driver
=
147 FindDriverByName(through_name
);
148 if (through_driver
== NULL
) {
149 _ftprintf(stderr
, _T("No such driver: %s\n"), through_name
);
153 if (!through_driver
->HasPassThrough()) {
154 _ftprintf(stderr
, _T("Not a pass-through driver: %s\n"), through_name
);
158 assert(through_driver
->CreateOnPort
!= NULL
);
159 through_device
= through_driver
->CreateOnPort(config
, *port
);
160 assert(through_device
!= NULL
);
163 const struct DeviceRegister
*driver
= FindDriverByName(driver_name
);
164 if (driver
== NULL
) {
165 _ftprintf(stderr
, _T("No such driver: %s\n"), driver_name
);
169 if (!driver
->CanDeclare()) {
170 _ftprintf(stderr
, _T("Not a logger driver: %s\n"), driver_name
);
174 assert(driver
->CreateOnPort
!= NULL
);
175 Device
*device
= driver
->CreateOnPort(config
, *port
);
176 assert(device
!= NULL
);
178 ConsoleOperationEnvironment env
;
180 if (through_device
!= NULL
&& !through_device
->EnablePassThrough(env
)) {
181 _ftprintf(stderr
, _T("Failed to enable pass-through mode: %s\n"),
186 if (device
->Declare(declaration
, NULL
, env
))
187 fprintf(stderr
, "Declaration ok\n");
189 fprintf(stderr
, "Declaration failed\n");
191 delete through_device
;
194 DeinitialiseIOThread();