]> git.mxchange.org Git - flightgear.git/commitdiff
Wendell Turner writes:
authorehofman <ehofman>
Tue, 22 Apr 2003 09:21:17 +0000 (09:21 +0000)
committerehofman <ehofman>
Tue, 22 Apr 2003 09:21:17 +0000 (09:21 +0000)
I modified the files in src/Autopilot to add waypoint capabilities to the telnet port.

'set waypoint <WPT>' will set the next waypoint.
'get waypoint' returns one string which is the list of waypoints.
'set waypoint 0' will delete the next waypoint.

src/Autopilot/auto_gui.cxx
src/Autopilot/auto_gui.hxx
src/Autopilot/newauto.cxx
src/Autopilot/newauto.hxx

index 1af3e523438866936722c10886f581bf76e53e68..191f03cf04c06a83313279d54ce12ceb78fe569c 100644 (file)
@@ -608,59 +608,85 @@ void TgtAptDialog_OK (puObject *)
     TgtAptDialogInput->getValue(&s);
 
     string tmp = s;
-    double alt = 0.0;
     unsigned int pos = tmp.find( "@" );
     if ( pos != string::npos ) {
        TgtAptId = tmp.substr( 0, pos );
-       string alt_str = tmp.substr( pos + 1 );
-       alt = atof( alt_str.c_str() );
-       if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
-           alt *= SG_FEET_TO_METER;
-       }
     } else {
        TgtAptId = tmp;
     }
 
     TgtAptDialog_Cancel( NULL );
     
-    FGAirport a;
-    FGFix f;
-    double t1, t2;
-    if ( fgFindAirportID( TgtAptId, &a ) ) {
+    /* s = input string, either 'FIX' or FIX@4000' */
+    /* TgtAptId is name of fix only; may get appended to below */
 
-        SG_LOG( SG_GENERAL, SG_INFO,
-                "Adding waypoint (airport) = " << TgtAptId );
-        
-        sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+    if ( NewWaypoint( TgtAptId ) == 0)
+    {
+        TgtAptId  += " not in database.";
+        mkDialog(TgtAptId.c_str());
+    }
+}
+
+/* add new waypoint (either from above popup window 'ok button or telnet session) */
+
+int NewWaypoint( string Tgt_Alt )
+{
+  string TgtAptId;
+  FGAirport a;
+  FGFix f;
+
+  double alt = 0.0;
+  unsigned int pos = Tgt_Alt.find( "@" );
+  if ( pos != string::npos ) {
+    TgtAptId = Tgt_Alt.substr( 0, pos );
+    string alt_str = Tgt_Alt.substr( pos + 1 );
+    alt = atof( alt_str.c_str() );
+    if ( !strcmp(fgGetString("/sim/startup/units"), "feet") ) {
+      alt *= SG_FEET_TO_METER;
+    }
+  } else {
+    TgtAptId = Tgt_Alt;
+  }
+
+  if ( fgFindAirportID( TgtAptId, &a ) ) {
+
+    SG_LOG( SG_GENERAL, SG_INFO,
+                 "Adding waypoint (airport) = " << TgtAptId );
 
-        SGWayPoint wp( a.longitude, a.latitude, alt,
-                       SGWayPoint::WGS84, TgtAptId );
-        globals->get_route()->add_waypoint( wp );
+    sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+
+    SGWayPoint wp( a.longitude, a.latitude, alt,
+                        SGWayPoint::WGS84, TgtAptId );
+    globals->get_route()->add_waypoint( wp );
 
          /* and turn on the autopilot */
-         globals->get_autopilot()->set_HeadingEnabled( true );
-         globals->get_autopilot()->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
+    globals->get_autopilot()->set_HeadingEnabled( true );
+    globals->get_autopilot()->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT
+);
 
-    } else if ( current_fixlist->query( TgtAptId, &f ) )
-    {
-        SG_LOG( SG_GENERAL, SG_INFO,
-                "Adding waypoint (fix) = " << TgtAptId );
-        
-        sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
+    return 1;
+
+  } else if ( current_fixlist->query( TgtAptId, &f ) )
+  {
+   SG_LOG( SG_GENERAL, SG_INFO,
+                 "Adding waypoint (fix) = " << TgtAptId );
+
+    sprintf( NewTgtAirportId, "%s", TgtAptId.c_str() );
 
-        SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
-                       SGWayPoint::WGS84, TgtAptId );
-        globals->get_route()->add_waypoint( wp );
+    SGWayPoint wp( f.get_lon(), f.get_lat(), alt,
+                        SGWayPoint::WGS84, TgtAptId );
+    globals->get_route()->add_waypoint( wp );
 
          /* and turn on the autopilot */
-         globals->get_autopilot()->set_HeadingEnabled( true );
-         globals->get_autopilot()->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
-    } else {
-       TgtAptId  += " not in database.";
-       mkDialog(TgtAptId.c_str());
-    }
+   globals->get_autopilot()->set_HeadingEnabled( true );
+   globals->get_autopilot()->set_HeadingMode( FGAutopilot::FG_HEADING_WAYPOINT );
+   return 2;
+
+  }
+  else return 0;
 }
 
+
 void TgtAptDialog_Reset(puObject *)
 {
     sprintf( NewTgtAirportId, "%s", fgGetString("/sim/presets/airport-id") );
index e3e1e53bdc8e2aee2690ec8eb0a258b10324094a..44db9965c581afbcf23c9ed5aca9331b17ca5124 100644 (file)
@@ -43,5 +43,7 @@ void fgAPAdjustInit() ;
 void NewHeadingInit();
 void NewAltitudeInit();
 
+int NewWaypoint( string Tgt_Alt );
+
 
 #endif // _AUTO_GUI_HXX
index 315852d6f775ae27339dbabf023751cdfa0fb75a..6762c0a30d8e5ef987cedd0d4be4f193d4211e07 100644 (file)
@@ -5,6 +5,7 @@
 // Contributions by Jeff Goeke-Smith <jgoeke@voyager.net>
 //                  Norman Vine <nhv@cape.com>
 //                  Curtis Olson <curt@flightgear.org>
+//                  Wendell Turner <wendell@adsi-m4.com>
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
@@ -44,6 +45,7 @@
 #include <Scenery/scenery.hxx>
 
 #include "newauto.hxx"
+#include "auto_gui.hxx"
 
 
 /// These statics will eventually go into the class
@@ -343,10 +345,17 @@ FGAutopilot::bind ()
     fgTie("/autopilot/locks/heading", this,
          &FGAutopilot::getAPHeadingLock, &FGAutopilot::setAPHeadingLock);
     fgSetArchivable("/autopilot/locks/heading");
+
     fgTie("/autopilot/settings/heading-bug-deg", this,
          &FGAutopilot::getAPHeadingBug, &FGAutopilot::setAPHeadingBug);
     fgSetArchivable("/autopilot/settings/heading-bug-deg");
     fgSetDouble("/autopilot/settings/heading-bug-deg", 0.0f);
+
+    fgTie("/autopilot/settings/waypoint", this,
+         &FGAutopilot::getAPwaypoint, &FGAutopilot::setAPwaypoint);
+    fgSetArchivable("/autopilot/settings/waypoint");
+    fgSetString("/autopilot/settings/waypoint", "");
+
     fgTie("/autopilot/locks/wing-leveler", this,
          &FGAutopilot::getAPWingLeveler, &FGAutopilot::setAPWingLeveler);
     fgSetArchivable("/autopilot/locks/wing-leveler");
@@ -1273,6 +1282,54 @@ FGAutopilot::setAPHeadingBug (double heading)
 }
 
 
+/**
+ * return blank-separated string of waypoints
+ */
+const char *
+FGAutopilot::getAPwaypoint () const
+{
+  static char wplist[500];
+  char *p = wplist;
+  int   WPListsize, i;
+
+  // FIXME: This can cause a possible buffer overflow, EMH
+  if ( globals->get_route()->size() > 0 ) { 
+      WPListsize = globals->get_route()->size(); 
+
+      for (i = 0; i < globals->get_route()->size(); i++ ) {
+         p += sprintf(p, "%5s ",
+               globals->get_route()->get_waypoint(i).get_id().c_str() );
+      }
+      return wplist;
+
+  } else {
+    return "none specified";
+  }    
+}
+
+
+/**
+ * set next waypoint (if str='0', then delete next(first) waypoint)
+ */
+void
+FGAutopilot::setAPwaypoint (const char * apt)
+{
+  if (strcmp(apt, "0")==0)
+  {
+    SG_LOG( SG_AUTOPILOT, SG_INFO, "delete of first wp" );
+    if ( globals->get_route()->size() )
+                   globals->get_route()->delete_first();
+    return;
+  }
+
+  if ( NewWaypoint( apt ) == 0)
+    SG_LOG( SG_AUTOPILOT, SG_INFO, "Waypoint " << apt <<  "not in d.b."  );
+  else
+  {
+    /* SG_LOG( SG_AUTOPILOT, SG_INFO, "GOOD!" ); */
+  }
+}
+
 /**
  * Get the autopilot wing leveler lock (true=on).
  */
index 7fe263f0b9e7b3899829bc0d93379a8b4a23c3a6..37dd3dd944dcadf2154f6c2a815b52440384bca4 100644 (file)
@@ -272,6 +272,8 @@ private:
     void setAPHeadingLock (bool lock);
     double getAPHeadingBug () const;
     void setAPHeadingBug (double heading);
+    const char * getAPwaypoint () const;
+    void setAPwaypoint (const char * apt);
     bool getAPWingLeveler () const;
     void setAPWingLeveler (bool lock);
     bool getAPNAV1Lock () const;