]> git.mxchange.org Git - flightgear.git/blobdiff - src/Instrumentation/dme.cxx
better use unset() for unsetting ...
[flightgear.git] / src / Instrumentation / dme.cxx
index 6c4d08d713c0696057b641fe37478df11d6f26a1..f12b4f80e6938ea39670c2cc0b61d5123a35ce95 100644 (file)
@@ -3,6 +3,10 @@
 //
 // This file is in the Public Domain and comes with no warranty.
 
+#ifdef HAVE_CONFIG_H
+#  include <config.h>
+#endif
+
 #include <simgear/compiler.h>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/math/sg_random.h>
@@ -44,35 +48,8 @@ DME::DME ( SGPropertyNode *node )
       _transmitter_elevation_ft(0),
       _transmitter_range_nm(0),
       _transmitter_bias(0.0),
-      name("dme"),
-      num(0)
-{
-    int i;
-    for ( i = 0; i < node->nChildren(); ++i ) {
-        SGPropertyNode *child = node->getChild(i);
-        string cname = child->getName();
-        string cval = child->getStringValue();
-        if ( cname == "name" ) {
-            name = cval;
-        } else if ( cname == "number" ) {
-            num = child->getIntValue();
-        } else {
-            SG_LOG( SG_INSTR, SG_WARN, "Error in dme config logic" );
-            if ( name.length() ) {
-                SG_LOG( SG_INSTR, SG_WARN, "Section = " << name );
-            }
-        }
-    }
-}
-
-DME::DME ()
-    : _last_distance_nm(0),
-      _last_frequency_mhz(-1),
-      _time_before_search_sec(0),
-      _transmitter_valid(false),
-      _transmitter_elevation_ft(0),
-      _transmitter_range_nm(0),
-      _transmitter_bias(0.0)
+      _name(node->getStringValue("name", "dme")),
+      _num(node->getIntValue("number", 0))
 {
 }
 
@@ -84,9 +61,9 @@ void
 DME::init ()
 {
     string branch;
-    branch = "/instrumentation/" + name;
+    branch = "/instrumentation/" + _name;
 
-    SGPropertyNode *node = fgGetNode(branch.c_str(), num, true );
+    SGPropertyNode *node = fgGetNode(branch.c_str(), _num, true );
 
     _longitude_node = fgGetNode("/position/longitude-deg", true);
     _latitude_node = fgGetNode("/position/latitude-deg", true);
@@ -100,8 +77,6 @@ DME::init ()
     _distance_node = node->getChild("indicated-distance-nm", 0, true);
     _speed_node = node->getChild("indicated-ground-speed-kt", 0, true);
     _time_node = node->getChild("indicated-time-min", 0, true);
-
-    _serviceable_node->setBoolValue(true);
 }
 
 void
@@ -111,7 +86,7 @@ DME::update (double delta_time_sec)
     const char * source = _source_node->getStringValue();
     if (source[0] == '\0') {
         string branch;
-        branch = "/instrumentation/" + name + "/frequencies/selected-mhz";
+        branch = "/instrumentation/" + _name + "/frequencies/selected-mhz";
         _source_node->setStringValue(branch.c_str());
         source = _source_node->getStringValue();
     }
@@ -150,9 +125,10 @@ DME::update (double delta_time_sec)
     }
 
                                 // Calculate the distance to the transmitter
-    Point3D location =
-        sgGeodToCart(Point3D(longitude_rad, latitude_rad, altitude_m));
-    double distance_nm = _transmitter.distance3D(location) * SG_METER_TO_NM;
+    SGGeod geod = SGGeod::fromRadM(longitude_rad, latitude_rad, altitude_m);
+    SGVec3d location = SGVec3d::fromGeod(geod);
+    
+    double distance_nm = dist(_transmitter, location) * SG_METER_TO_NM;
 
     double range_nm = adjust_range(_transmitter_elevation_ft,
                                    altitude_m * SG_METER_TO_FEET,
@@ -196,7 +172,7 @@ DME::search (double frequency_mhz, double longitude_rad,
     _transmitter_valid = (dme != NULL);
 
     if ( _transmitter_valid ) {
-        _transmitter = Point3D(dme->get_x(), dme->get_y(), dme->get_z());
+        _transmitter = dme->get_cart();
         _transmitter_elevation_ft = dme->get_elev_ft();
         _transmitter_range_nm = dme->get_range();
         _transmitter_bias = dme->get_multiuse();