]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/atlas.cxx
Removes some references (in comments / disabled code) to Point3D
[flightgear.git] / src / Network / atlas.cxx
index 3d15edb947d799da945446a757d15504d223b96d..4a2cd9d64911be983546731be43460db784e7d11 100644 (file)
@@ -2,7 +2,7 @@
 //
 // Written by Curtis Olson, started November 1999.
 //
-// Copyright (C) 1999  Curtis L. Olson - curt@flightgear.org
+// Copyright (C) 1999  Curtis L. Olson - http://www.flightgear.org/~curt
 //
 // This program is free software; you can redistribute it and/or
 // modify it under the terms of the GNU General Public License as
 //
 // You should have received a copy of the GNU General Public License
 // along with this program; if not, write to the Free Software
-// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
+#include <cstring>
 
 #include <simgear/debug/logstream.hxx>
 #include <simgear/math/sg_geodesy.hxx>
 #include <simgear/io/iochannel.hxx>
+#include <simgear/timing/sg_time.hxx>
 
-#include <Cockpit/radiostack.hxx>
-#include <FDM/flight.hxx>
+#include <FDM/flightProperties.hxx>
 #include <Main/globals.hxx>
+#include <Main/fg_props.hxx>
+#include <Main/fg_init.hxx>
 
 #include "atlas.hxx"
 
 
 FGAtlas::FGAtlas() {
+  fdm = new FlightProperties;
 }
 
 FGAtlas::~FGAtlas() {
+  delete fdm;
 }
 
 
@@ -58,13 +67,20 @@ static char calc_atlas_cksum(char *sentence) {
     return sum;
 }
 
-
 // generate Atlas message
 bool FGAtlas::gen_message() {
     // cout << "generating atlas message" << endl;
 
     static SGPropertyNode *adf_freq
-        = fgGetNode("/radios/adf/frequencies/selected-khz", true);
+        = fgGetNode("/instrumentation/adf/frequencies/selected-khz", true);
+    static SGPropertyNode *nav1_freq
+        = fgGetNode("/instrumentation/nav/frequencies/selected-mhz", true);
+    static SGPropertyNode *nav1_sel_radial
+        = fgGetNode("/instrumentation/nav/radials/selected-deg", true);
+    static SGPropertyNode *nav2_freq
+        = fgGetNode("/instrumentation/nav[1]/frequencies/selected-mhz", true);
+    static SGPropertyNode *nav2_sel_radial
+        = fgGetNode("/instrumentation/nav[1]/radials/selected-deg", true);
 
     char rmc[256], gga[256], patla[256];
     char rmc_sum[10], gga_sum[10], patla_sum[10];
@@ -79,7 +95,7 @@ bool FGAtlas::gen_message() {
             t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
 
     char lat[20];
-    double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+    double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if ( latd < 0.0 ) {
        latd *= -1.0;
        dir = 'S';
@@ -91,7 +107,7 @@ bool FGAtlas::gen_message() {
     sprintf( lat, "%02d%06.3f,%c", abs(deg), min, dir);
 
     char lon[20];
-    double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+    double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if ( lond < 0.0 ) {
        lond *= -1.0;
        dir = 'W';
@@ -103,17 +119,17 @@ bool FGAtlas::gen_message() {
     sprintf( lon, "%03d%06.3f,%c", abs(deg), min, dir);
 
     char speed[10];
-    sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
+    sprintf( speed, "%05.1f", fdm->get_V_equiv_kts() );
 
     char heading[10];
-    sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
+    sprintf( heading, "%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES );
 
     char altitude_m[10];
     sprintf( altitude_m, "%02d", 
-            (int)(cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) );
+            (int)(fdm->get_Altitude() * SG_FEET_TO_METER) );
 
     char altitude_ft[10];
-    sprintf( altitude_ft, "%02d", (int)cur_fdm_state->get_Altitude() );
+    sprintf( altitude_ft, "%02d", (int)fdm->get_Altitude() );
 
     char date[10];
     sprintf( date, "%02d%02d%02d", t->getGmt()->tm_mday, 
@@ -129,10 +145,10 @@ bool FGAtlas::gen_message() {
     sprintf( gga_sum, "%02X", calc_atlas_cksum(gga) );
 
     sprintf( patla, "PATLA,%.2f,%.1f,%.2f,%.1f,%.0f",
-            current_radiostack->get_nav1_freq(),
-            current_radiostack->get_nav1_sel_radial(),
-            current_radiostack->get_nav2_freq(),
-            current_radiostack->get_nav2_sel_radial(),
+            nav1_freq->getDoubleValue(),
+            nav1_sel_radial->getDoubleValue(),
+            nav2_freq->getDoubleValue(),
+            nav2_sel_radial->getDoubleValue(),
             adf_freq->getDoubleValue() );
     sprintf( patla_sum, "%02X", calc_atlas_cksum(patla) );
 
@@ -163,7 +179,7 @@ bool FGAtlas::gen_message() {
     atlas_sentence += patla_sum;
     atlas_sentence += "\n";
 
-    cout << atlas_sentence;
+    //    cout << atlas_sentence;
 
     length = atlas_sentence.length();
     strncpy( buf, atlas_sentence.c_str(), length );
@@ -260,7 +276,7 @@ bool FGAtlas::parse_message() {
                lat *= -1;
            }
 
-           cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -289,17 +305,17 @@ bool FGAtlas::parse_message() {
                lon *= -1;
            }
 
-           cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
 #if 0
            double sl_radius, lat_geoc;
-           sgGeodToGeoc( cur_fdm_state->get_Latitude(), 
-                         cur_fdm_state->get_Altitude(), 
+           sgGeodToGeoc( fdm->get_Latitude(), 
+                         fdm->get_Altitude(), 
                          &sl_radius, &lat_geoc );
-           cur_fdm_state->set_Geocentric_Position( lat_geoc, 
-                          cur_fdm_state->get_Longitude(), 
-                          sl_radius + cur_fdm_state->get_Altitude() );
+           fdm->set_Geocentric_Position( lat_geoc, 
+                          fdm->get_Longitude(), 
+                          sl_radius + fdm->get_Altitude() );
 #endif
 
            // speed
@@ -311,8 +327,8 @@ bool FGAtlas::parse_message() {
            string speed_str = msg.substr(begin, end - begin);
            begin = end + 1;
            speed = atof( speed_str.c_str() );
-           cur_fdm_state->set_V_calibrated_kts( speed );
-           // cur_fdm_state->set_V_ground_speed( speed );
+           fdm->set_V_calibrated_kts( speed );
+           // fdm->set_V_ground_speed( speed );
            SG_LOG( SG_IO, SG_INFO, "  speed = " << speed );
 
            // heading
@@ -324,8 +340,8 @@ bool FGAtlas::parse_message() {
            string hdg_str = msg.substr(begin, end - begin);
            begin = end + 1;
            heading = atof( hdg_str.c_str() );
-           cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(), 
-                                            cur_fdm_state->get_Theta(), 
+           fdm->set_Euler_Angles( fdm->get_Phi(), 
+                                            fdm->get_Theta(), 
                                             heading * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  heading = " << heading );
        } else if ( sentence == "GPGGA" ) {
@@ -365,7 +381,7 @@ bool FGAtlas::parse_message() {
                lat *= -1;
            }
 
-           // cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+           // fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lat = " << lat );
 
            // lon val
@@ -394,7 +410,7 @@ bool FGAtlas::parse_message() {
                lon *= -1;
            }
 
-           // cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+           // fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            SG_LOG( SG_IO, SG_INFO, "  lon = " << lon );
 
            // junk
@@ -446,11 +462,11 @@ bool FGAtlas::parse_message() {
            string alt_units = msg.substr(begin, end - begin);
            begin = end + 1;
 
-           if ( alt_units != (string)"F" ) {
+           if ( alt_units != "F" ) {
                altitude *= SG_METER_TO_FEET;
            }
 
-           cur_fdm_state->set_Altitude( altitude );
+           fdm->set_Altitude( altitude );
     
            SG_LOG( SG_IO, SG_INFO, " altitude  = " << altitude );
 
@@ -544,20 +560,20 @@ bool FGAtlas::process() {
     if ( get_direction() == SG_IO_OUT ) {
        gen_message();
        if ( ! io->write( buf, length ) ) {
-           SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
+           SG_LOG( SG_IO, SG_WARN, "Error writing data." );
            return false;
        }
     } else if ( get_direction() == SG_IO_IN ) {
        if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
            parse_message();
        } else {
-           SG_LOG( SG_IO, SG_ALERT, "Error reading data." );
+           SG_LOG( SG_IO, SG_WARN, "Error reading data." );
            return false;
        }
        if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
            parse_message();
        } else {
-           SG_LOG( SG_IO, SG_ALERT, "Error reading data." );
+           SG_LOG( SG_IO, SG_WARN, "Error reading data." );
            return false;
        }
     }
@@ -568,6 +584,7 @@ bool FGAtlas::process() {
 
 // close the channel
 bool FGAtlas::close() {
+    SG_LOG( SG_IO, SG_INFO, "closing FGAtlas" );   
     SGIOChannel *io = get_io_channel();
 
     set_enabled( false );