]> git.mxchange.org Git - flightgear.git/blobdiff - src/Navaids/ils.hxx
Changes to keep the various autopilot properties from stepping on each
[flightgear.git] / src / Navaids / ils.hxx
index e4cde79c2839a9df08912b81b7a33705f9e672e2..b97b2882e9a560199274c23b017b18909efc0d75 100644 (file)
 
 
 #include <simgear/compiler.h>
-#include <simgear/math/fg_geodesy.hxx>
-#include <simgear/misc/fgstream.hxx>
+#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/misc/sgstream.hxx>
 
-#ifdef FG_HAVE_STD_INCLUDES
+#ifdef SG_HAVE_STD_INCLUDES
 #  include <istream>
-#elif defined( FG_HAVE_NATIVE_SGI_COMPILERS )
+#elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
 #  include <iostream.h>
 #elif defined( __BORLANDC__ )
 #  include <iostream>
 #  include <istream.h>
 #endif
 
-#if ! defined( FG_HAVE_NATIVE_SGI_COMPILERS )
-FG_USING_STD(istream);
+#if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
+SG_USING_STD(istream);
 #endif
 
 
-#define FG_ILS_DEFAULT_RANGE 30
+#define FG_ILS_DEFAULT_RANGE 18
 
 class FGILS {
 
@@ -53,15 +53,18 @@ class FGILS {
     char aptcode[5];
     char rwyno[4];
     int  locfreq;
-    char locident[5];
+    char locident[5];          // official ident
     double locheading;
     double loclat;
     double loclon;
+    double x, y, z;
+    bool has_gs;
     double gselev;
     double gsangle;
     double gslat;
     double gslon;
     double gs_x, gs_y, gs_z;
+    bool has_dme;
     double dmelat;
     double dmelon;
     double dme_x, dme_y, dme_z;
@@ -72,6 +75,12 @@ class FGILS {
     double imlat;
     double imlon;
 
+    // for failure modeling
+    string trans_ident;                // transmitted ident
+    bool loc_failed;           // localizer failed?
+    bool gs_failed;            // glide slope failed?
+    bool dme_failed;           // dme failed?
+
 public:
 
     inline FGILS(void) {}
@@ -83,9 +92,14 @@ public:
     inline char *get_rwyno() { return rwyno; }
     inline int get_locfreq() const { return locfreq; }
     inline char *get_locident() { return locident; }
+    inline string get_trans_ident() { return trans_ident; }
     inline double get_locheading() const { return locheading; }
     inline double get_loclat() const { return loclat; }
     inline double get_loclon() const { return loclon; }
+    inline double get_x() const { return x; }
+    inline double get_y() const { return y; }
+    inline double get_z() const { return z; }
+    inline bool get_has_gs() const { return has_gs; }
     inline double get_gselev() const { return gselev; }
     inline double get_gsangle() const { return gsangle; }
     inline double get_gslat() const { return gslat; }
@@ -93,6 +107,7 @@ public:
     inline double get_gs_x() const { return gs_x; }
     inline double get_gs_y() const { return gs_y; }
     inline double get_gs_z() const { return gs_z; }
+    inline bool get_has_dme() const { return has_dme; }
     inline double get_dmelat() const { return dmelat; }
     inline double get_dmelon() const { return dmelon; }
     inline double get_dme_x() const { return dme_x; }
@@ -113,7 +128,12 @@ inline istream&
 operator >> ( istream& in, FGILS& i )
 {
     double f;
-    in >> i.ilstype >> i.ilstypename >> i.aptcode >> i.rwyno 
+    in >> i.ilstype;
+    
+    if ( i.ilstype == '[' )
+          return in;
+
+    in >> i.ilstypename >> i.aptcode >> i.rwyno 
        >> f >> i.locident >> i.locheading >> i.loclat >> i.loclon
        >> i.gselev >> i.gsangle >> i.gslat >> i.gslon
        >> i.dmelat >> i.dmelon
@@ -127,31 +147,43 @@ operator >> ( istream& in, FGILS& i )
     // generate cartesian coordinates
     Point3D geod, cart;
 
-    if ( i.gslon < FG_EPSILON && i.gslat < FG_EPSILON ) {
-       i.gslon = i.loclon;
-       i.gslat = i.loclat;
+    geod = Point3D( i.loclon * SGD_DEGREES_TO_RADIANS, i.loclat * SGD_DEGREES_TO_RADIANS, i.gselev );
+    cart = sgGeodToCart( geod );
+    i.x = cart.x();
+    i.y = cart.y();
+    i.z = cart.z();
+
+    if ( i.gslon < SG_EPSILON && i.gslat < SG_EPSILON ) {
+       i.has_gs = false;
+    } else {
+       i.has_gs = true;
+
+       geod = Point3D( i.gslon * SGD_DEGREES_TO_RADIANS, i.gslat * SGD_DEGREES_TO_RADIANS, i.gselev );
+       cart = sgGeodToCart( geod );
+       i.gs_x = cart.x();
+       i.gs_y = cart.y();
+       i.gs_z = cart.z();
+       // cout << "gs = " << cart << endl;
     }
 
-    if ( i.dmelon < FG_EPSILON && i.dmelat < FG_EPSILON ) {
-       i.dmelon = i.gslon;
-       i.dmelat = i.gslat;
+    if ( i.dmelon < SG_EPSILON && i.dmelat < SG_EPSILON ) {
+       i.has_dme = false;
+    } else {
+       i.has_dme = true;
+
+       geod = Point3D( i.dmelon * SGD_DEGREES_TO_RADIANS, i.dmelat * SGD_DEGREES_TO_RADIANS, i.gselev);
+       cart = sgGeodToCart( geod );
+       i.dme_x = cart.x();
+       i.dme_y = cart.y();
+       i.dme_z = cart.z();
+       // cout << "dme = " << cart << endl;
     }
 
-    geod = Point3D( i.gslon * DEG_TO_RAD, i.gslat * DEG_TO_RAD, i.gselev );
-    cart = fgGeodToCart( geod );
-    i.gs_x = cart.x();
-    i.gs_y = cart.y();
-    i.gs_z = cart.z();
-    // cout << "gs = " << cart << endl;
-
-    geod = Point3D( i.dmelon * DEG_TO_RAD, i.dmelat * DEG_TO_RAD, i.gselev );
-    cart = fgGeodToCart( geod );
-    i.dme_x = cart.x();
-    i.dme_y = cart.y();
-    i.dme_z = cart.z();
-    // cout << "dme = " << cart << endl;
-
-     // return in >> skipeol;
+    i.trans_ident = "I";
+    i.trans_ident += i.locident;
+    i.loc_failed = i.gs_failed = i.dme_failed = false;
+   
+    // return in >> skipeol;
     return in;
 }