]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_io.cxx
Added code to put aircraft at the end of the runway closest to the desired
[flightgear.git] / src / Main / fg_io.cxx
index 8e9f40e99dc40a2c05cba6fee3d225ebf0bd7b61..24383e7a1b20d5dfacab786d3d1153398108dff2 100644 (file)
 // $Id$
 
 
-#include <Include/compiler.h>
+#include <simgear/compiler.h>
 
 #include STL_STRING
 
-#include <Debug/logstream.hxx>
-#include <Include/fg_types.hxx>
-#include <Main/options.hxx>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/io/iochannel.hxx>
+#include <simgear/io/sg_file.hxx>
+#include <simgear/io/sg_serial.hxx>
+#include <simgear/io/sg_socket.hxx>
+
+#include <simgear/math/fg_types.hxx>
 
-#include <Network/iochannel.hxx>
-#include <Network/fg_file.hxx>
-#include <Network/fg_serial.hxx>
-#include <Network/fg_socket.hxx>
+#include <Main/options.hxx>
 
 #include <Network/protocol.hxx>
+#include <Network/native.hxx>
 #include <Network/garmin.hxx>
 #include <Network/nmea.hxx>
 #include <Network/pve.hxx>
+#include <Network/ray.hxx>
 #include <Network/rul.hxx>
+#include <Network/joyclient.hxx>
 
 #include <Time/timestamp.hxx>
 
@@ -69,7 +73,10 @@ static FGProtocol *parse_port_config( const string& config )
     FG_LOG( FG_IO, FG_INFO, "  protocol = " << protocol );
 
     FGProtocol *io;
-    if ( protocol == "garmin" ) {
+    if ( protocol == "native" ) {
+       FGNative *native = new FGNative;
+       io = native;
+    } else if ( protocol == "garmin" ) {
        FGGarmin *garmin = new FGGarmin;
        io = garmin;
     } else if ( protocol == "nmea" ) {
@@ -78,9 +85,15 @@ static FGProtocol *parse_port_config( const string& config )
     } else if ( protocol == "pve" ) {
        FGPVE *pve = new FGPVE;
        io = pve;
+    } else if ( protocol == "ray" ) {
+       FGRAY *ray = new FGRAY;
+       io = ray;
     } else if ( protocol == "rul" ) {
        FGRUL *rul = new FGRUL;
        io = rul;
+    } else if ( protocol == "joyclient" ) {
+       FGJoyClient *joyclient = new FGJoyClient;
+       io = joyclient;
     } else {
        return NULL;
     }
@@ -119,49 +132,56 @@ static FGProtocol *parse_port_config( const string& config )
     FG_LOG( FG_IO, FG_INFO, "  hertz = " << hertz );
 
     if ( medium == "serial" ) {
-       FGSerial *ch = new FGSerial;
-       io->set_io_channel( ch );
-
        // device name
        end = config.find(",", begin);
        if ( end == string::npos ) {
            return NULL;
        }
     
-       ch->set_device( config.substr(begin, end - begin) );
+       string device = config.substr(begin, end - begin);
        begin = end + 1;
-       FG_LOG( FG_IO, FG_INFO, "  device = " << ch->get_device() );
+       FG_LOG( FG_IO, FG_INFO, "  device = " << device );
 
        // baud
-       ch->set_baud( config.substr(begin) );
-       FG_LOG( FG_IO, FG_INFO, "  baud = " << ch->get_baud() );
+       string baud = config.substr(begin);
+       FG_LOG( FG_IO, FG_INFO, "  baud = " << baud );
 
+       SGSerial *ch = new SGSerial( device, baud );
        io->set_io_channel( ch );
     } else if ( medium == "file" ) {
-       FGFile *ch = new FGFile;
-       io->set_io_channel( ch );
-
        // file name
-       ch->set_file_name( config.substr(begin) );
-       FG_LOG( FG_IO, FG_INFO, "  file name = " << ch->get_file_name() );
-    } else if ( medium == "socket" ) {
-       FGSocket *ch = new FGSocket;
-       io->set_io_channel( ch );
+       string file = config.substr(begin);
+       FG_LOG( FG_IO, FG_INFO, "  file name = " << file );
 
+       SGFile *ch = new SGFile( file );
+       io->set_io_channel( ch );
+    } else if ( medium == "socket" ) {
        // hostname
        end = config.find(",", begin);
        if ( end == string::npos ) {
            return NULL;
        }
     
-       ch->set_hostname( config.substr(begin, end - begin) );
+       string hostname = config.substr(begin, end - begin);
        begin = end + 1;
-       FG_LOG( FG_IO, FG_INFO, "  hostname = " << ch->get_hostname() );
+       FG_LOG( FG_IO, FG_INFO, "  hostname = " << hostname );
 
-       // port
-       ch->set_port_str( config.substr(begin) );
-       FG_LOG( FG_IO, FG_INFO, "  port string = " << ch->get_port_str() );
+       // port string
+       end = config.find(",", begin);
+       if ( end == string::npos ) {
+           return NULL;
+       }
+    
+       string port = config.substr(begin, end - begin);
+       begin = end + 1;
+       FG_LOG( FG_IO, FG_INFO, "  port string = " << port );
 
+       // socket style
+       string style_str = config.substr(begin);
+       FG_LOG( FG_IO, FG_INFO, "  style string = " << style_str );
+       
+       SGSocket *ch = new SGSocket( hostname, port, style_str );
+       io->set_io_channel( ch );
     }
 
     return io;
@@ -223,9 +243,9 @@ void fgIOProcess() {
 
        if ( p->is_enabled() ) {
            p->dec_count_down( interval );
-           if ( p->get_count_down() < 0 ) {
+           while ( p->get_count_down() < 0 ) {
                p->process();
-               p->set_count_down( 1000000.0 / p->get_hz() );
+               p->dec_count_down( -1000000.0 / p->get_hz() );
            }
        }
     }