]> git.mxchange.org Git - flightgear.git/blob - src/Instrumentation/testgps.cxx
Merge branches 'jmt/spatial', 'jmt/ref_ptr', 'jmt/navradio' and '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   const FGAirport* egph = fgFindAirportID("EGPH");
76   SG_LOG(SG_GENERAL, SG_ALERT, "egph: cart location:" << egph->cart());
77   
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());
82   }
83   
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());
87   //}
88   
89
90   FGRouteMgr* rm = new FGRouteMgr;
91   globals->add_subsystem( "route-manager", rm );
92   
93  // FGEnvironmentMgr* envMgr = new FGEnvironmentMgr;
94  // globals->add_subsystem("environment", envMgr);
95  // envMgr->init();
96   
97   
98   SGPropertyNode* nd = fgGetNode("/instrumentation/gps", true);
99   GPS* gps = new GPS(nd);
100   globals->add_subsystem("gps", gps);
101   
102   
103   testSetPosition(egph->geod());
104   
105   // startup the route manager
106   rm->init();
107   
108   nd->setBoolValue("serviceable", true);
109   fgSetBool("/systems/electrical/outputs/gps", true);
110   
111   gps->init();
112   SGPropertyNode* scratch  = nd->getChild("scratch", 0, true);
113   SGPropertyNode* wp = nd->getChild("wp", 0, true);
114   SGPropertyNode* wp1 = wp->getChild("wp", 1, true);
115   
116   // update a few times
117   gps->update(0.05);
118   gps->update(0.05);
119   
120   scratch->setStringValue("query", "TL");
121   scratch->setStringValue("type", "Vor");
122   scratch->setBoolValue("exact", false);
123   nd->setStringValue("command", "search");
124   printScratch(scratch);
125   
126   nd->setStringValue("command", "next");
127   printScratch(scratch);
128   
129   nd->setStringValue("command", "next");
130   printScratch(scratch);
131   
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");
138   
139   nd->setStringValue("command", "search");
140   printScratch(scratch);
141   
142   nd->setStringValue("command", "next");
143   printScratch(scratch);
144   
145   nd->setStringValue("command", "next");
146   printScratch(scratch);
147   
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");
153   
154   nd->setStringValue("command", "search");
155   printScratch(scratch);
156   
157   nd->setStringValue("command", "next");
158   printScratch(scratch);
159   
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);
166   
167 // nearest
168   scratch->setStringValue("type", "apt");
169   scratch->setIntValue("max-results", 10);
170   nd->setStringValue("command", "nearest");
171   printScratch(scratch);
172   
173   nd->setStringValue("command", "next");
174   printScratch(scratch);
175   
176   nd->setStringValue("command", "next");
177   printScratch(scratch);
178   
179 // direct to
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"));
184
185 // OBS mode
186   scratch->setStringValue("query", "UW");
187   scratch->setBoolValue("order-by-distance", true);
188   nd->setStringValue("command", "search");
189   printScratch(scratch);
190   
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"));
195   
196 // load route waypoints
197   createDummyRoute(rm);
198
199   scratch->setIntValue("route-index", 5);
200   nd->setStringValue("command", "load-route-wpt");
201   printScratch(scratch);
202   
203   nd->setStringValue("command", "next");
204   printScratch(scratch);
205   
206   nd->setStringValue("command", "next");
207   printScratch(scratch);
208   
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"));
215   
216 // route editing
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);
223   
224   
225   
226   return EXIT_SUCCESS;
227 }