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 FGRouteMgr* rm = new FGRouteMgr;
76 globals->add_subsystem( "route-manager", rm );
78 // FGEnvironmentMgr* envMgr = new FGEnvironmentMgr;
79 // globals->add_subsystem("environment", envMgr);
83 SGPropertyNode* nd = fgGetNode("/instrumentation/gps", true);
84 GPS* gps = new GPS(nd);
85 globals->add_subsystem("gps", gps);
87 const FGAirport* egph = fgFindAirportID("EGPH");
88 testSetPosition(egph->geod());
90 // startup the route manager
93 nd->setBoolValue("serviceable", true);
94 fgSetBool("/systems/electrical/outputs/gps", true);
97 SGPropertyNode* scratch = nd->getChild("scratch", 0, true);
98 SGPropertyNode* wp = nd->getChild("wp", 0, true);
99 SGPropertyNode* wp1 = wp->getChild("wp", 1, true);
101 // update a few times
105 scratch->setStringValue("ident", "TL");
106 scratch->setStringValue("type", "Vor");
107 scratch->setBoolValue("exact", false);
108 nd->setStringValue("command", "search");
109 printScratch(scratch);
111 nd->setStringValue("command", "next");
112 printScratch(scratch);
114 nd->setStringValue("command", "next");
115 printScratch(scratch);
117 // alphanumeric sort, partial matching
118 nd->setDoubleValue("config/min-runway-length-ft", 5000.0);
119 scratch->setBoolValue("exact", false);
120 scratch->setBoolValue("order-by-distance", false);
121 scratch->setStringValue("ident", "KS");
122 scratch->setStringValue("type", "apt");
124 nd->setStringValue("command", "search");
125 printScratch(scratch);
127 nd->setStringValue("command", "next");
128 printScratch(scratch);
130 nd->setStringValue("command", "next");
131 printScratch(scratch);
133 // alphanumeric sort, explicit matching
134 scratch->setBoolValue("exact", true);
135 scratch->setBoolValue("order-by-distance", true);
136 scratch->setStringValue("type", "vor");
137 scratch->setStringValue("ident", "DCS");
139 nd->setStringValue("command", "search");
140 printScratch(scratch);
142 nd->setStringValue("command", "next");
143 printScratch(scratch);
145 // search on totally missing
146 scratch->setBoolValue("exact", true);
147 scratch->setBoolValue("order-by-distance", true);
148 scratch->setStringValue("ident", "FOFOFOFOF");
149 nd->setStringValue("command", "search");
150 printScratch(scratch);
153 scratch->setStringValue("type", "apt");
154 scratch->setIntValue("max-results", 10);
155 nd->setStringValue("command", "nearest");
156 printScratch(scratch);
158 nd->setStringValue("command", "next");
159 printScratch(scratch);
161 nd->setStringValue("command", "next");
162 printScratch(scratch);
165 nd->setStringValue("command", "direct");
166 SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t"
167 << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg")
168 << " " << wp1->getDoubleValue("latitude-deg"));
171 scratch->setStringValue("ident", "UW");
172 scratch->setBoolValue("order-by-distance", true);
173 nd->setStringValue("command", "search");
174 printScratch(scratch);
176 nd->setStringValue("command", "obs");
177 SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t"
178 << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg")
179 << " " << wp1->getDoubleValue("latitude-deg"));
181 // load route waypoints
182 createDummyRoute(rm);
184 scratch->setIntValue("route-index", 5);
185 nd->setStringValue("command", "load-route-wpt");
186 printScratch(scratch);
188 nd->setStringValue("command", "next");
189 printScratch(scratch);
191 nd->setStringValue("command", "next");
192 printScratch(scratch);
194 scratch->setIntValue("route-index", 2);
195 nd->setStringValue("command", "load-route-wpt");
196 nd->setStringValue("command", "direct");
197 SG_LOG(SG_GENERAL, SG_ALERT, "mode:" << nd->getStringValue("mode") << "\n\t"
198 << wp1->getStringValue("ID") << " " << wp1->getDoubleValue("longitude-deg")
199 << " " << wp1->getDoubleValue("latitude-deg"));
202 SGGeod pos = egph->geod();
203 scratch->setStringValue("ident", "FOOBAR");
204 scratch->setDoubleValue("longitude-deg", pos.getLongitudeDeg());
205 scratch->setDoubleValue("latitude-deg", pos.getLatitudeDeg());
206 nd->setStringValue("command", "define-user-wpt");
207 printScratch(scratch);