DeviceBlackboard.cpp: Refactoring of Heading()
[xcsoar.git] / test / src / RunDeclare.cpp
blobb14d405f5157ed6b6300d56760ae8d6ae7b6488e
1 /*
2 Copyright_License {
4 XCSoar Glide Computer - http://www.xcsoar.org/
5 Copyright (C) 2000-2010 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/Descriptor.hpp"
28 #include "Device/device.hpp"
29 #include "Device/Geoid.h"
30 #include "Engine/Navigation/GeoPoint.hpp"
31 #include "Engine/Waypoint/Waypoints.hpp"
32 #include "InputEvents.hpp"
33 #include "Thread/Trigger.hpp"
34 #include "DeviceBlackboard.hpp"
35 #include "OS/PathName.hpp"
36 #include "Protection.hpp"
38 #ifdef HAVE_POSIX
39 #include "Device/TTYPort.hpp"
40 #else
41 #include "Device/SerialPort.hpp"
42 #endif
44 #include <stdio.h>
46 Waypoints way_points;
48 DeviceBlackboard device_blackboard;
50 static DeviceDescriptor device;
53 * Fake Protection.cpp
56 Mutex mutexBlackboard;
58 void TriggerGPSUpdate() {}
59 void TriggerVarioUpdate() {}
62 * Fake Device/device.cpp
65 bool
66 devHasBaroSource()
68 return device.IsBaroSource();
71 bool
72 HaveCondorDevice()
74 return device.IsCondor();
78 * Fake Device/Geoid.cpp
81 fixed
82 LookupGeoidSeparation(const GeoPoint pt)
84 return fixed_zero;
88 * Fake InputEvents.cpp
91 bool
92 InputEvents::processGlideComputer(unsigned gce_id)
94 return true;
97 bool
98 InputEvents::processNmea(unsigned key)
100 return true;
104 * Fake Settings*Blackboard.cpp
107 SettingsComputerBlackboard::SettingsComputerBlackboard() {}
108 SettingsMapBlackboard::SettingsMapBlackboard() {}
111 * The actual code.
114 static Waypoint
115 MakeWaypoint(const TCHAR *name, int altitude,
116 double longitude, double latitude)
118 const GeoPoint gp(Angle::degrees(fixed(7.7061111111111114)),
119 Angle::degrees(fixed(51.051944444444445)));
120 Waypoint wp(GeoPoint(Angle::degrees(fixed(longitude)),
121 Angle::degrees(fixed(latitude))));
122 wp.Name = name;
123 wp.Altitude = fixed(altitude);
124 return wp;
127 int main(int argc, char **argv)
129 if (argc != 4) {
130 fprintf(stderr, "Usage: %s DRIVER PORT BAUD\n"
131 "Where DRIVER is one of:\n", argv[0]);
133 const TCHAR *name;
134 for (unsigned i = 0; (name = devRegisterGetName(i)) != NULL; ++i)
135 _ftprintf(stderr, _T("\t%s\n"), name);
137 return EXIT_FAILURE;
140 PathName driver_name(argv[1]);
141 PathName port_name(argv[2]);
142 int baud = atoi(argv[3]);
144 device.Driver = devGetDriver(driver_name);
145 if (device.Driver == NULL) {
146 fprintf(stderr, "No such driver: %s\n", argv[1]);
147 return EXIT_FAILURE;
150 if ((device.Driver->Flags & drfLogger) == 0) {
151 fprintf(stderr, "Not a logger driver: %s\n", argv[1]);
152 return EXIT_FAILURE;
155 #ifdef HAVE_POSIX
156 TTYPort *port = new TTYPort(port_name, baud, *(Port::Handler *)NULL);
157 #else
158 SerialPort *port = new SerialPort(port_name, baud, *(Port::Handler *)NULL);
159 #endif
160 device.Com = port;
161 if (!port->Open()) {
162 delete port;
163 fprintf(stderr, "Failed to open COM port\n");
164 return EXIT_FAILURE;
167 if (!device.Open()) {
168 delete device.Com;
169 fprintf(stderr, "Failed to open driver: %s\n", argv[1]);
170 return EXIT_FAILURE;
173 Declaration declaration(NULL);
174 declaration.PilotName = _T("Foo Bar");
175 declaration.AircraftType = _T("Cirrus");
176 declaration.AircraftRego = _T("D-3003");
178 declaration.append(MakeWaypoint(_T("Bergneustadt"), 488,
179 7.7061111111111114, 51.051944444444445));
180 declaration.append(MakeWaypoint(_T("Foo"), 488, 8, 52));
181 declaration.append(MakeWaypoint(_T("Bar"), 488, 7.5, 50));
182 declaration.append(MakeWaypoint(_T("Bergneustadt"), 488,
183 7.7061111111111114, 51.051944444444445));
185 if (device.Declare(&declaration))
186 fprintf(stderr, "Declaration ok\n");
187 else
188 fprintf(stderr, "Declaration failed\n");
190 device.Close();