]> git.mxchange.org Git - flightgear.git/blobdiff - src/Main/fg_io.cxx
Added static port system and a new altimeter model connected to it.
[flightgear.git] / src / Main / fg_io.cxx
index e6352f0c581638e6f4c4395df7f885e629d10f15..0e80419d714c0268d481c9dc9b13d66b3fcafe37 100644 (file)
 #include <Network/opengc.hxx>
 #include <Network/nmea.hxx>
 #include <Network/props.hxx>
-#include <Network/telnet.hxx>
 #include <Network/pve.hxx>
 #include <Network/ray.hxx>
 #include <Network/rul.hxx>
 
 #include "globals.hxx"
+#include "fg_io.hxx"
 
-SG_USING_NAMESPACE(std);
 SG_USING_STD(string);
 
 
-// define the global I/O channel list
-io_container global_io_list;
+FGIO::FGIO()
+{
+}
+
+#include STL_ALGORITHM
+SG_USING_STD(for_each);
+
+static void delete_ptr( FGProtocol* p ) { delete p; }
+
+FGIO::~FGIO()
+{
+    shutdown_all();
+    for_each( io_channels.begin(), io_channels.end(), delete_ptr );
+}
 
 
 // configure a port based on the config string
-static FGProtocol *parse_port_config( const string& config )
+FGProtocol*
+FGIO::parse_port_config( const string& config )
 {
     SG_LOG( SG_IO, SG_INFO, "Parse I/O channel request: " << config );
 
@@ -88,7 +100,9 @@ static FGProtocol *parse_port_config( const string& config )
     try
     {
        if ( protocol == "atc610x" ) {
-           return new FGATC610x;
+            FGATC610x *atc610x = new FGATC610x;
+           atc610x->set_hz( 30 );
+           return atc610x;
        } else if ( protocol == "atlas" ) {
            FGAtlas *atlas = new FGAtlas;
            io = atlas;
@@ -125,10 +139,8 @@ static FGProtocol *parse_port_config( const string& config )
        } else if ( protocol == "nmea" ) {
            FGNMEA *nmea = new FGNMEA;
            io = nmea;
-       } else if ( protocol == "props" ) {
-           io = new FGProps();
-       } else if ( protocol == "telnet" ) {
-           io = new FGTelnet( tokens );
+       } else if ( protocol == "props" || protocol == "telnet" ) {
+           io = new FGProps( tokens );
            return io;
        } else if ( protocol == "pve" ) {
            FGPVE *pve = new FGPVE;
@@ -198,12 +210,13 @@ static FGProtocol *parse_port_config( const string& config )
 
 // step through the port config streams (from fgOPTIONS) and setup
 // serial port channels for each
-void fgIOInit() {
+void
+FGIO::init()
+{
     // SG_LOG( SG_IO, SG_INFO, "I/O Channel initialization, " << 
     //         globals->get_channel_options_list()->size() << " requests." );
 
     FGProtocol *p;
-    string_list *channel_options_list = globals->get_channel_options_list();
 
     // we could almost do this in a single step except pushing a valid
     // port onto the port list copies the structure and destroys the
@@ -211,11 +224,15 @@ void fgIOInit() {
 
     // parse the configuration strings and store the results in the
     // appropriate FGIOChannel structures
-    for ( int i = 0; i < (int)channel_options_list->size(); ++i ) {
-       p = parse_port_config( (*channel_options_list)[i] );
+    typedef vector<string> container;
+    container::iterator i = globals->get_channel_options_list()->begin();
+    container::iterator end = globals->get_channel_options_list()->end();
+    for (; i != end; ++i )
+    {
+       p = parse_port_config( *i );
        if ( p != NULL ) {
            p->open();
-           global_io_list.push_back( p );
+           io_channels.push_back( p );
            if ( !p->is_enabled() ) {
                SG_LOG( SG_IO, SG_ALERT, "I/O Channel config failed." );
                exit(-1);
@@ -228,7 +245,9 @@ void fgIOInit() {
 
 
 // process any serial port work
-void fgIOProcess() {
+void
+FGIO::update( double delta_time_sec )
+{
     // cout << "processing I/O channels" << endl;
 
     static int inited = 0;
@@ -246,9 +265,12 @@ void fgIOProcess() {
        last = current;
     }
 
-    for ( unsigned int i = 0; i < global_io_list.size(); ++i ) {
-       // cout << "  channel = " << i << endl;
-       FGProtocol* p = global_io_list[i];
+    typedef vector< FGProtocol* > container;
+    container::iterator i = io_channels.begin();
+    container::iterator end = io_channels.end();
+    for (; i != end; ++i )
+    {
+       FGProtocol* p = *i;
 
        if ( p->is_enabled() ) {
            p->dec_count_down( interval );
@@ -261,18 +283,32 @@ void fgIOProcess() {
 }
 
 
-// shutdown all I/O connections
-void fgIOShutdownAll() {
+void
+FGIO::shutdown_all() {
     FGProtocol *p;
 
     // cout << "processing I/O channels" << endl;
 
-    for ( int i = 0; i < (int)global_io_list.size(); ++i ) {
-       // cout << "  channel = " << i << endl;
-       p = global_io_list[i];
+    typedef vector< FGProtocol* > container;
+    container::iterator i = io_channels.begin();
+    container::iterator end = io_channels.end();
+    for (; i != end; ++i )
+    {
+       p = *i;
 
        if ( p->is_enabled() ) {
            p->close();
        }
     }
 }
+
+void
+FGIO::bind()
+{
+}
+
+void
+FGIO::unbind()
+{
+}
+