]> git.mxchange.org Git - flightgear.git/blobdiff - src/Network/garmin.cxx
SG_ namespace
[flightgear.git] / src / Network / garmin.cxx
index 6a0814b72c0124549e6bae27dc7199c3b899d911..00a266f47f6496daa6f924f2268372e31ee2ec1c 100644 (file)
 // $Id$
 
 
-#include <Debug/logstream.hxx>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/math/sg_geodesy.hxx>
+#include <simgear/io/iochannel.hxx>
+
 #include <FDM/flight.hxx>
-#include <Math/fg_geodesy.hxx>
-#include <Time/fg_time.hxx>
+#include <Main/globals.hxx>
 
-#include "iochannel.hxx"
 #include "garmin.hxx"
 
 
@@ -66,14 +67,14 @@ bool FGGarmin::gen_message() {
     int deg;
     double min;
 
-    FGTime *t = FGTime::cur_time_params;
+    SGTime *t = globals->get_time_params();
 
     char utc[10];
     sprintf( utc, "%02d%02d%02d", 
             t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
 
     char lat[20];
-    double latd = cur_fdm_state->get_Latitude() * RAD_TO_DEG;
+    double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
     if ( latd < 0.0 ) {
        latd *= -1.0;
        dir = 'S';
@@ -85,7 +86,7 @@ bool FGGarmin::gen_message() {
     sprintf( lat, "%02d%06.3f,%c", abs(deg), min, dir);
 
     char lon[20];
-    double lond = cur_fdm_state->get_Longitude() * RAD_TO_DEG;
+    double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
     if ( lond < 0.0 ) {
        lond *= -1.0;
        dir = 'W';
@@ -100,7 +101,7 @@ bool FGGarmin::gen_message() {
     sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
 
     char heading[10];
-    sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * RAD_TO_DEG );
+    sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
 
     char altitude_m[10];
     sprintf( altitude_m, "%02d", 
@@ -235,7 +236,7 @@ bool FGGarmin::parse_message() {
                lat *= -1;
            }
 
-           cur_fdm_state->set_Latitude( lat * DEG_TO_RAD );
+           cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
            FG_LOG( FG_IO, FG_INFO, "  lat = " << lat );
 
            // lon val
@@ -264,16 +265,18 @@ bool FGGarmin::parse_message() {
                lon *= -1;
            }
 
-           cur_fdm_state->set_Longitude( lon * DEG_TO_RAD );
+           cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
            FG_LOG( FG_IO, FG_INFO, "  lon = " << lon );
 
+#if 0
            double sl_radius, lat_geoc;
-           fgGeodToGeoc( cur_fdm_state->get_Latitude(), 
+           sgGeodToGeoc( cur_fdm_state->get_Latitude(), 
                          cur_fdm_state->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() );
+#endif
 
            // speed
            end = msg.find(",", begin);
@@ -284,8 +287,8 @@ bool FGGarmin::parse_message() {
            string speed_str = msg.substr(begin, end - begin);
            begin = end + 1;
            speed = atof( speed_str.c_str() );
-           cur_fdm_state->set_V_equiv_kts( speed );
-           cur_fdm_state->set_V_ground_speed( speed );
+           cur_fdm_state->set_V_calibrated_kts( speed );
+           // cur_fdm_state->set_V_ground_speed( speed );
            FG_LOG( FG_IO, FG_INFO, "  speed = " << speed );
 
            // heading
@@ -299,7 +302,7 @@ bool FGGarmin::parse_message() {
            heading = atof( hdg_str.c_str() );
            cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(), 
                                             cur_fdm_state->get_Theta(), 
-                                            heading * DEG_TO_RAD );
+                                            heading * SGD_DEGREES_TO_RADIANS );
            FG_LOG( FG_IO, FG_INFO, "  heading = " << heading );
        } else if ( sentence == "PGRMZ" ) {
            // altitude
@@ -349,7 +352,7 @@ bool FGGarmin::open() {
        return false;
     }
 
-    FGIOChannel *io = get_io_channel();
+    SGIOChannel *io = get_io_channel();
 
     if ( ! io->open( get_direction() ) ) {
        FG_LOG( FG_IO, FG_ALERT, "Error opening channel communication layer." );
@@ -364,16 +367,16 @@ bool FGGarmin::open() {
 
 // process work for this port
 bool FGGarmin::process() {
-    FGIOChannel *io = get_io_channel();
+    SGIOChannel *io = get_io_channel();
 
-    if ( get_direction() == out ) {
+    if ( get_direction() == SG_IO_OUT ) {
        gen_message();
        if ( ! io->write( buf, length ) ) {
            FG_LOG( FG_IO, FG_ALERT, "Error writing data." );
            return false;
        }
-    } else if ( get_direction() == in ) {
-       if ( length = io->readline( buf, FG_MAX_MSG_SIZE ) ) {
+    } else if ( get_direction() == SG_IO_IN ) {
+       if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
            FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
            if ( parse_message() ) {
                FG_LOG( FG_IO, FG_ALERT, "Success parsing data." );
@@ -384,7 +387,7 @@ bool FGGarmin::process() {
            FG_LOG( FG_IO, FG_ALERT, "Error reading data." );
            return false;
        }
-       if ( length = io->readline( buf, FG_MAX_MSG_SIZE ) ) {
+       if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
            FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
            if ( parse_message() ) {
                FG_LOG( FG_IO, FG_ALERT, "Success parsing data." );
@@ -403,7 +406,7 @@ bool FGGarmin::process() {
 
 // close the channel
 bool FGGarmin::close() {
-    FGIOChannel *io = get_io_channel();
+    SGIOChannel *io = get_io_channel();
 
     set_enabled( false );