]> git.mxchange.org Git - flightgear.git/commitdiff
Exposed the fg_commands though the httpd interface.
authorcurt <curt>
Sat, 30 Nov 2002 20:10:16 +0000 (20:10 +0000)
committercurt <curt>
Sat, 30 Nov 2002 20:10:16 +0000 (20:10 +0000)
Added a built in command to preset to what ever values are in /sim/presets/
Twiddling with preset code.

src/GUI/preset_dlg.cxx
src/Main/fg_commands.cxx
src/Main/fg_init.cxx
src/Network/httpd.cxx

index 32a6ed61c94ede0c0c52746d8470fa93b1411edc..91481716cfb2c477c34d3cbae27d0f388112a583 100644 (file)
 #  include <windows.h>
 #endif
 
-// #include <stdlib.h>
-
-// #include <simgear/constants.h>
-// #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/commands.hxx>
 #include <simgear/misc/sg_path.hxx>
 
-// #include <Include/general.hxx>
-
-// #include <GL/glut.h>
-// #include <GL/gl.h>
-
-#include <Airports/simple.hxx>
-#include <FDM/flight.hxx>
-#include <Main/fg_init.hxx>
 #include <Main/fg_props.hxx>
-#include <Scenery/tilemgr.hxx>
 
 #include "gui.h"
 #include "preset_dlg.hxx"
@@ -239,52 +227,10 @@ void fgPresetAirspeed(puObject *cb)
 
 void fgPresetCommit(puObject *)
 {
-    static const SGPropertyNode *longitude
-       = fgGetNode("/sim/presets/longitude-deg");
-    static const SGPropertyNode *latitude
-       = fgGetNode("/sim/presets/latitude-deg");
-    static const SGPropertyNode *master_freeze
-       = fgGetNode("/sim/freeze/master");
-
-    SGPath path( globals->get_fg_root() );
-    path.append( "Airports" );
-    path.append( "simple.mk4" );
-    FGAirports airports( path.c_str() );
-
-    FGAirport a;
-
-    bool freeze = master_freeze->getBoolValue();
-    if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", true);
-    }
-
-    // unbind the current fdm state so property changes
-    // don't get lost when we subsequently delete this fdm
-    // and create a new one.
-    cur_fdm_state->unbind();
-        
-    // invalidate lon/lat if an airport is specified in the presets
-    string apt = fgGetString("/sim/presets/airport-id");
-    if ( !apt.empty() ) {
-        fgSetDouble("/sim/presets/longitude-deg", -9999.0 );
-        fgSetDouble("/sim/presets/latitude-deg", -9999.0 );
-    }
-
-    // set position from presets
-    fgInitPosition();
-
-    // BusyCursor(0);
-    fgReInitSubsystems();
-
-    cout << "before tile_mgr init " << longitude->getDoubleValue() << " "
-         << latitude->getDoubleValue() << endl;
-
-    double visibility_meters = fgGetDouble("/environment/visibility-m");
-    global_tile_mgr.update( visibility_meters );
-    // BusyCursor(1);
-
-    if ( !freeze ) {
-        fgSetBool("/sim/freeze/master", false);
+    SGPropertyNode args;
+    if ( !globals->get_commands()->execute("presets_commit", &args) )
+    {
+        SG_LOG( SG_GENERAL, SG_ALERT, "Command: presets_commit failed.");
     }
 }
 
index f408f06d6eec08f7f029b850fd65dd1ee8692543..bb5368183d934d88ab4ba85e6000c484b2c9a49e 100644 (file)
 #include <simgear/misc/commands.hxx>
 #include <simgear/misc/props.hxx>
 
-#include <GUI/gui.h>
-#include <GUI/new_gui.hxx>
 #include <Cockpit/panel.hxx>
 #include <Cockpit/panel_io.hxx>
+#include <FDM/flight.hxx>
+#include <GUI/gui.h>
+#include <GUI/new_gui.hxx>
 #include <Scenery/tilemgr.hxx>
 #include <Time/tmp.hxx>
 
+#include "fg_init.hxx"
 #include "fg_commands.hxx"
 
 SG_USING_STD(string);
@@ -588,6 +590,34 @@ do_gui (const SGPropertyNode * arg)
 }
 
 
+/**
+ * Built-in command: commit presets (read from in /sim/presets/)
+ */
+static bool
+do_presets_commit (const SGPropertyNode * arg)
+{
+    // unbind the current fdm state so property changes
+    // don't get lost when we subsequently delete this fdm
+    // and create a new one.
+    cur_fdm_state->unbind();
+        
+    // set position from presets
+    fgInitPosition();
+
+    // BusyCursor(0);
+    fgReInitSubsystems();
+
+    global_tile_mgr.update( fgGetDouble("/environment/visibility-m") );
+
+    if ( ! fgGetBool("/sim/presets/onground") ) {
+        fgSetBool( "/sim/freeze/master", true );
+        fgSetBool( "/sim/freeze/clock", true );
+    }
+
+    return true;
+}
+
+
 \f
 ////////////////////////////////////////////////////////////////////////
 // Command setup.
@@ -622,6 +652,7 @@ static struct {
     { "property-swap", do_property_swap },
     { "property-scale", do_property_scale },
     { "gui", do_gui },
+    { "presets_commit", do_presets_commit },
     { 0, 0 }                   // zero-terminated
 };
 
index 00208a8627aefd80aec90d268248393fb08c525f..ec7e640e12191ba1fba5018d89d01a23a411bb02 100644 (file)
@@ -576,6 +576,22 @@ bool fgFindAirportID( const string& id, FGAirport *a ) {
 }
 
 
+// get airport elevation
+static double fgGetAirportElev( const string& id ) {
+    FGAirport a;
+    // double lon, lat;
+
+    SG_LOG( SG_GENERAL, SG_INFO,
+            "Finding elevation for airport: " << id );
+
+    if ( fgFindAirportID( id, &a ) ) {
+        return a.elevation;
+    } else {
+        return -9999.0;
+    }
+}
+
+
 // Preset lon/lat given an airport id
 static bool fgSetPosFromAirportID( const string& id ) {
     FGAirport a;
@@ -602,11 +618,9 @@ static bool fgSetPosFromAirportID( const string& id ) {
     } else {
         return false;
     }
-
 }
 
 
-
 // Set current tower position lon/lat given an airport id
 static bool fgSetTowerPosFromAirportID( const string& id, double hdg ) {
     FGAirport a;
@@ -895,21 +909,32 @@ static bool fgSetPosFromAirportIDandRwy( const string& id, const string& rwy ) {
 
 
 static void fgSetDistOrAltFromGlideSlope() {
+    string apt_id = fgGetString("/sim/presets/airport-id");
     double gs = fgGetDouble("/sim/presets/glideslope-deg")
         * SG_DEGREES_TO_RADIANS ;
     double od = fgGetDouble("/sim/presets/offset-distance");
     double alt = fgGetDouble("/sim/presets/altitude-ft");
-    
+
+    double apt_elev = 0.0;
+    if ( ! apt_id.empty() ) {
+        apt_elev = fgGetAirportElev( apt_id );
+        if ( apt_elev < -9990.0 ) {
+            apt_elev = 0.0;
+        }
+    } else {
+        apt_elev = 0.0;
+    }
+
     if( fabs(gs) > 0.01 && fabs(od) > 0.1 && alt < -9990 ) {
         // set altitude from glideslope and offset-distance
         od *= SG_NM_TO_METER * SG_METER_TO_FEET;
-        alt = fabs(od*tan(gs));
+        alt = fabs(od*tan(gs)) + apt_elev;
         fgSetDouble("/sim/presets/altitude-ft", alt);
         fgSetBool("/sim/presets/onground", false);
         SG_LOG(SG_GENERAL,SG_INFO, "Calculated altitude as: " << alt  << " ft");
     } else if( fabs(gs) > 0.01 && alt > 0 && fabs(od) < 0.1) {
         // set offset-distance from glideslope and altitude
-        od  = alt/tan(gs);
+        od  = (alt - apt_elev) / tan(gs);
         od *= -1*SG_FEET_TO_METER * SG_METER_TO_NM;
         fgSetDouble("/sim/presets/offset-distance", od);
         SG_LOG(SG_GENERAL, SG_INFO, "Calculated offset distance as: " 
@@ -919,6 +944,7 @@ static void fgSetDistOrAltFromGlideSlope() {
                 "Glideslope given but not altitude or offset-distance." );
         SG_LOG( SG_GENERAL, SG_ALERT, "Resetting glideslope to zero" );
         fgSetDouble("/sim/presets/glideslope-deg", 0);
+        fgSetBool("/sim/presets/onground", true);
     }                              
 }                       
 
index 1c01ac7eb6f7a042c8a5fb1cd5a289903370472f..f89f147300d064e9193aaae2296f02a8243de4ab 100644 (file)
@@ -39,6 +39,7 @@
 #include <simgear/debug/logstream.hxx>
 #include <simgear/io/iochannel.hxx>
 #include <simgear/math/sg_types.hxx>
+#include <simgear/misc/commands.hxx>
 #include <simgear/misc/props.hxx>
 
 #include <Main/fg_props.hxx>
@@ -62,7 +63,7 @@ bool FGHttpd::open() {
 
     server = new HttpdServer( port );
     
-    set_hz( 5 );                // default to processing requests @ 5Hz
+    set_hz( 15 );                // default to processing requests @ 15Hz
     set_enabled( true );
 
     return true;
@@ -132,9 +133,26 @@ void HttpdChannel::foundTerminator (void) {
                     string a = arg.substr( 0, apos );
                     string b = arg.substr( apos + 1 );
                     printf("    a = %s  b = %s\n", a.c_str(), b.c_str() );
-                    if ( a == "value" ) {
-                        fgSetString( request.c_str(), urlDecode(b).c_str() );
-                    } 
+                    if ( request == "/run.cgi" ) {
+                        // execute a command
+                        if ( a == "value" ) {
+                            SGPropertyNode args;
+                            if ( !globals->get_commands()
+                                 ->execute(urlDecode(b).c_str(), &args) )
+                            {
+                                SG_LOG( SG_GENERAL, SG_ALERT,
+                                        "Command " << urlDecode(b)
+                                        << " failed.");
+                            }
+
+                        }
+                    } else {
+                        if ( a == "value" ) {
+                            // update a property value
+                            fgSetString( request.c_str(),
+                                         urlDecode(b).c_str() );
+                        }
+                    }
                 }
             }
         } else {