2 #include <Main/fg_init.hxx>
3 #include <Main/globals.hxx>
4 #include <Main/fg_props.hxx>
6 #include <Instrumentation/gps.hxx>
7 #include <Autopilot/route_mgr.hxx>
8 #include <Environment/environment_mgr.hxx>
12 char *homedir = ::getenv( "HOME" );
13 char *hostname = ::getenv( "HOSTNAME" );
14 bool free_hostname = false;
16 void testSetPosition(const SGGeod& aPos)
18 fgSetDouble("/position/longitude-deg", aPos.getLongitudeDeg());
19 fgSetDouble("/position/latitude-deg", aPos.getLatitudeDeg());
20 fgSetDouble("/position/altitude-ft", aPos.getElevationFt());
23 void printScratch(SGPropertyNode* scratch)
25 if (!scratch->getBoolValue("valid", false)) {
26 SG_LOG(SG_GENERAL, SG_ALERT, "Scratch is invalid.");
30 SG_LOG(SG_GENERAL, SG_ALERT, "Scratch:" <<
31 scratch->getStringValue("ident") << "/" << scratch->getStringValue("name"));
33 SG_LOG(SG_GENERAL, SG_ALERT, "\t" << scratch->getDoubleValue("longitude-deg")
34 << " " << scratch->getDoubleValue("latitude-deg") << " @ " << scratch->getDoubleValue("altitude-ft"));
36 SG_LOG(SG_GENERAL, SG_ALERT, "\t" << scratch->getDoubleValue("true-bearing-deg") <<
37 " (" << scratch->getDoubleValue("mag-bearing-deg") << " magnetic) " << scratch->getDoubleValue("distance-nm"));
39 if (scratch->hasChild("result-index")) {
40 SG_LOG(SG_GENERAL, SG_ALERT, "\tresult-index:" << scratch->getIntValue("result-index"));
43 if (scratch->hasChild("route-index")) {
44 SG_LOG(SG_GENERAL, SG_ALERT, "\troute-index:" << scratch->getIntValue("route-index"));
48 void createDummyRoute(FGRouteMgr* rm)
50 SGPropertyNode* rmInput = fgGetNode("/autopilot/route-manager/input", true);
51 rmInput->setStringValue("UW");
52 rmInput->setStringValue("TLA/347/13");
53 rmInput->setStringValue("TLA");
54 rmInput->setStringValue("HAVEN");
55 rmInput->setStringValue("NEW/305/29");
56 rmInput->setStringValue("NEW");
57 rmInput->setStringValue("OTR");
60 int main(int argc, char* argv[])
62 globals = new FGGlobals;
64 fgInitFGRoot(argc, argv);
65 if (!fgInitConfig(argc, argv) ) {
66 SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed" );
73 SG_LOG(SG_GENERAL, SG_ALERT, "hello world!");
75 const FGAirport* egph = fgFindAirportID("EGPH");
76 SG_LOG(SG_GENERAL, SG_ALERT, "egph: cart location:" << egph->cart());
78 FGAirport::AirportFilter af;
79 FGPositioned::List l = FGPositioned::findClosestN(egph->geod(), 20, 2000.0, &af);
80 for (unsigned int i=0; i<l.size(); ++i) {
81 SG_LOG(SG_GENERAL, SG_ALERT, "\t" << l[i]->ident() << "/" << l[i]->name());
84 //l = FGPositioned::findWithinRange(egph->geod(), 500.0, &af);
85 //for (unsigned int i=0; i<l.size(); ++i) {
86 // SG_LOG(SG_GENERAL, SG_ALERT, "\t" << l[i]->ident() << "/" << l[i]->name());
90 FGRouteMgr* rm = new FGRouteMgr;
91 globals->add_subsystem( "route-manager", rm );
93 // FGEnvironmentMgr* envMgr = new FGEnvironmentMgr;
94 // globals->add_subsystem("environment", envMgr);
98 SGPropertyNode* nd = fgGetNode("/instrumentation/gps", true);
99 GPS* gps = new GPS(nd);
100 globals->add_subsystem("gps", gps);
103 testSetPosition(egph->geod());
105 // startup the route manager
108 nd->setBoolValue("serviceable", true);
109 fgSetBool("/systems/electrical/outputs/gps", true);
112 SGPropertyNode* scratch = nd->getChild("scratch", 0, true);
113 SGPropertyNode* wp = nd->getChild("wp", 0, true);
114 SGPropertyNode* wp1 = wp->getChild("wp", 1, true);
116 // update a few times
120 scratch->setStringValue("query", "TL");
121 scratch->setStringValue("type", "Vor");
122 scratch->setBoolValue("exact", false);
123 nd->setStringValue("command", "search");
124 printScratch(scratch);
126 nd->setStringValue("command", "next");
127 printScratch(scratch);
129 nd->setStringValue("command", "next");
130 printScratch(scratch);
132 // alphanumeric sort, partial matching
133 nd->setDoubleValue("config/min-runway-length-ft", 5000.0);
134 scratch->setBoolValue("exact", false);
135 scratch->setBoolValue("order-by-distance", false);
136 scratch->setStringValue("query", "KS");
137 scratch->setStringValue("type", "apt");
139 nd->setStringValue("command", "search");
140 printScratch(scratch);
142 nd->setStringValue("command", "next");
143 printScratch(scratch);
145 nd->setStringValue("command", "next");
146 printScratch(scratch);
148 // alphanumeric sort, explicit matching
149 scratch->setBoolValue("exact", true);
150 scratch->setBoolValue("order-by-distance", true);
151 scratch->setStringValue("type", "vor");
152 scratch->setStringValue("query", "DCS");
154 nd->setStringValue("command", "search");
155 printScratch(scratch);
157 nd->setStringValue("command", "next");
158 printScratch(scratch);
160 // search on totally missing
161 scratch->setBoolValue("exact", true);
162 scratch->setBoolValue("order-by-distance", true);
163 scratch->setStringValue("query", "FOFOFOFOF");
164 nd->setStringValue("command", "search");
165 printScratch(scratch);
168 scratch->setStringValue("type", "apt");
169 scratch->setIntValue("max-results", 10);
170 nd->setStringValue("command", "nearest");
171 printScratch(scratch);
173 nd->setStringValue("command", "next");
174 printScratch(scratch);
176 nd->setStringValue("command", "next");
177 printScratch(scratch);
180 nd->setStringValue("command", "direct");
181 SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t"
182 << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg")
183 << " " << wp1->getDoubleValue("latitude-deg"));
186 scratch->setStringValue("query", "UW");
187 scratch->setBoolValue("order-by-distance", true);
188 nd->setStringValue("command", "search");
189 printScratch(scratch);
191 nd->setStringValue("command", "obs");
192 SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t"
193 << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg")
194 << " " << wp1->getDoubleValue("latitude-deg"));
196 // load route waypoints
197 createDummyRoute(rm);
199 scratch->setIntValue("route-index", 5);
200 nd->setStringValue("command", "load-route-wpt");
201 printScratch(scratch);
203 nd->setStringValue("command", "next");
204 printScratch(scratch);
206 nd->setStringValue("command", "next");
207 printScratch(scratch);
209 scratch->setIntValue("route-index", 2);
210 nd->setStringValue("command", "load-route-wpt");
211 nd->setStringValue("command", "direct");
212 SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t"
213 << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg")
214 << " " << wp1->getDoubleValue("latitude-deg"));
217 SGGeod pos = egph->geod();
218 scratch->setStringValue("ident", "FOOBAR");
219 scratch->setDoubleValue("longitude-deg", pos.getLongitudeDeg());
220 scratch->setDoubleValue("latitude-deg", pos.getLatitudeDeg());
221 nd->setStringValue("command", "define-user-wpt");
222 printScratch(scratch);