]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/testgps.cxx
Merge branch 'jmt/gps'
[flightgear.git] / src / Instrumentation / testgps.cxx
1
2 #include <Main/fg_init.hxx>
3 #include <Main/globals.hxx>
4 #include <Main/fg_props.hxx>
5
6 #include <Instrumentation/gps.hxx>
7 #include <Autopilot/route_mgr.hxx>
8 #include <Environment/environment_mgr.hxx>
9
10 using std::string;
11
12 char *homedir = ::getenv( "HOME" );
13 char *hostname = ::getenv( "HOSTNAME" );
14 bool free_hostname = false;
15
16 void testSetPosition(const SGGeod& aPos)
17 {
18   fgSetDouble("/position/longitude-deg", aPos.getLongitudeDeg());
19   fgSetDouble("/position/latitude-deg", aPos.getLatitudeDeg());
20   fgSetDouble("/position/altitude-ft", aPos.getElevationFt());
21 }
22
23 void printScratch(SGPropertyNode* scratch)
24 {
25   if (!scratch->getBoolValue("valid", false)) {
26     SG_LOG(SG_GENERAL, SG_ALERT, "Scratch is invalid."); 
27     return;
28   }
29
30   SG_LOG(SG_GENERAL, SG_ALERT, "Scratch:" <<
31     scratch->getStringValue("ident") << "/" << scratch->getStringValue("name"));
32   
33   SG_LOG(SG_GENERAL, SG_ALERT, "\t" << scratch->getDoubleValue("longitude-deg")
34     << " " << scratch->getDoubleValue("latitude-deg") << " @ " << scratch->getDoubleValue("altitude-ft"));
35     
36   SG_LOG(SG_GENERAL, SG_ALERT, "\t" << scratch->getDoubleValue("true-bearing-deg") <<
37     " (" << scratch->getDoubleValue("mag-bearing-deg") << " magnetic) " << scratch->getDoubleValue("distance-nm"));
38   
39   if (scratch->hasChild("result-index")) {
40     SG_LOG(SG_GENERAL, SG_ALERT, "\tresult-index:" << scratch->getIntValue("result-index"));
41   } 
42   
43   if (scratch->hasChild("route-index")) {
44     SG_LOG(SG_GENERAL, SG_ALERT, "\troute-index:" << scratch->getIntValue("route-index"));
45   }
46 }
47
48 void createDummyRoute(FGRouteMgr* rm)
49 {
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");
58 }
59
60 int main(int argc, char* argv[])
61 {
62   globals = new FGGlobals;
63     
64   fgInitFGRoot(argc, argv);
65   if (!fgInitConfig(argc, argv) ) {
66     SG_LOG( SG_GENERAL, SG_ALERT, "Config option parsing failed" );
67     exit(-1);
68   }
69   
70   
71   fgInitNav();
72   
73   SG_LOG(SG_GENERAL, SG_ALERT, "hello world!");
74   
75   FGRouteMgr* rm = new FGRouteMgr;
76   globals->add_subsystem( "route-manager", rm );
77   
78  // FGEnvironmentMgr* envMgr = new FGEnvironmentMgr;
79  // globals->add_subsystem("environment", envMgr);
80  // envMgr->init();
81   
82   
83   SGPropertyNode* nd = fgGetNode("/instrumentation/gps", true);
84   GPS* gps = new GPS(nd);
85   globals->add_subsystem("gps", gps);
86   
87   const FGAirport* egph = fgFindAirportID("EGPH");
88   testSetPosition(egph->geod());
89   
90   // startup the route manager
91   rm->init();
92   
93   nd->setBoolValue("serviceable", true);
94   fgSetBool("/systems/electrical/outputs/gps", true);
95   
96   gps->init();
97   SGPropertyNode* scratch  = nd->getChild("scratch", 0, true);
98   SGPropertyNode* wp = nd->getChild("wp", 0, true);
99   SGPropertyNode* wp1 = wp->getChild("wp", 1, true);
100   
101   // update a few times
102   gps->update(0.05);
103   gps->update(0.05);
104   
105   scratch->setStringValue("query", "TL");
106   scratch->setStringValue("type", "Vor");
107   scratch->setBoolValue("exact", false);
108   nd->setStringValue("command", "search");
109   printScratch(scratch);
110   
111   nd->setStringValue("command", "next");
112   printScratch(scratch);
113   
114   nd->setStringValue("command", "next");
115   printScratch(scratch);
116   
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("query", "KS");
122   scratch->setStringValue("type", "apt");
123   
124   nd->setStringValue("command", "search");
125   printScratch(scratch);
126   
127   nd->setStringValue("command", "next");
128   printScratch(scratch);
129   
130   nd->setStringValue("command", "next");
131   printScratch(scratch);
132   
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("query", "DCS");
138   
139   nd->setStringValue("command", "search");
140   printScratch(scratch);
141   
142   nd->setStringValue("command", "next");
143   printScratch(scratch);
144   
145 // search on totally missing
146   scratch->setBoolValue("exact", true);
147   scratch->setBoolValue("order-by-distance", true);
148   scratch->setStringValue("query", "FOFOFOFOF");
149   nd->setStringValue("command", "search");
150   printScratch(scratch);
151   
152 // nearest
153   scratch->setStringValue("type", "apt");
154   scratch->setIntValue("max-results", 10);
155   nd->setStringValue("command", "nearest");
156   printScratch(scratch);
157   
158   nd->setStringValue("command", "next");
159   printScratch(scratch);
160   
161   nd->setStringValue("command", "next");
162   printScratch(scratch);
163   
164 // direct to
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"));
169
170 // OBS mode
171   scratch->setStringValue("query", "UW");
172   scratch->setBoolValue("order-by-distance", true);
173   nd->setStringValue("command", "search");
174   printScratch(scratch);
175   
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"));
180   
181 // load route waypoints
182   createDummyRoute(rm);
183
184   scratch->setIntValue("route-index", 5);
185   nd->setStringValue("command", "load-route-wpt");
186   printScratch(scratch);
187   
188   nd->setStringValue("command", "next");
189   printScratch(scratch);
190   
191   nd->setStringValue("command", "next");
192   printScratch(scratch);
193   
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"));
200   
201 // route editing
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);
208   
209   
210   
211   return EXIT_SUCCESS;
212 }