]> git.mxchange.org Git - flightgear.git/commitdiff
Added a get_type() to the iochannel class so the protocol code can optionally
authorcurt <curt>
Thu, 1 Jun 2000 21:13:26 +0000 (21:13 +0000)
committercurt <curt>
Thu, 1 Jun 2000 21:13:26 +0000 (21:13 +0000)
impliment different behavior depending on the channel that's being used.

src/Network/fg_file.cxx
src/Network/fg_serial.cxx
src/Network/fg_socket.cxx
src/Network/iochannel.hxx
src/Network/joyclient.cxx
src/Network/native.cxx

index e73179eb88bcdb6a43a11b2ceda708db0ef2ca77..e8e0f36429f1901a7f4ab1f03e1205ce014ccd5b 100644 (file)
@@ -37,6 +37,7 @@ FG_USING_STD(string);
 
 
 FGFile::FGFile() {
+    set_type( fgFileType );
 }
 
 
index e1897b59c8920a7417e357325ca478cca798f0b6..6fae04c8cd1ce5bfa5e4cb4325ca59b02a988cbf 100644 (file)
@@ -38,6 +38,7 @@ FG_USING_STD(string);
 FGSerial::FGSerial() :
     save_len(0)
 {
+    set_type( fgSerialType );
 }
 
 
index 711899131b49cd76047c24cd125206395d8ea178..e57b09ad0241ba1683fc1ad55506b706899f1429 100644 (file)
@@ -54,6 +54,7 @@ FG_USING_STD(string);
 FGSocket::FGSocket() :
     save_len(0)
 {
+    set_type( fgSocketType );
 }
 
 
index 5830f6e2af29c8a595fa5fa751ac4166ad9b2bef..0793ef7fc0010a4a5e480f5039e6a1049c910a7d 100644 (file)
@@ -40,8 +40,16 @@ FG_USING_STD(string);
 class FGProtocol;
 
 
+enum FGChannelType {
+    fgFileType = 0,
+    fgSerialType = 1,
+    fgSocketType = 2
+};
+
 class FGIOChannel {
 
+    FGChannelType type;
+
 public:
 
     FGIOChannel();
@@ -53,6 +61,9 @@ public:
     virtual int write( char *buf, int length );
     virtual int writestring( char *str );
     virtual bool close();
+
+    virtual void set_type( FGChannelType t ) { type = t; }
+    virtual FGChannelType get_type() const { return type; }
 };
 
 
index bf546544bf34b38dc1605568fd711d0ebfd9835d..2d05092fccbb33b7de36bc92e52041a4de1ca027 100644 (file)
@@ -67,21 +67,42 @@ bool FGJoyClient::process() {
        return false;
     } else if ( get_direction() == in ) {
        FG_LOG( FG_IO, FG_DEBUG, "Searching for data." );
-       while ( io->read( (char *)(& buf), length ) == length ) {
-           FG_LOG( FG_IO, FG_DEBUG, "Success reading data." );
-           int *msg;
-           msg = (int *)buf;
-           FG_LOG( FG_IO, FG_DEBUG, "X = " << msg[0] << " Y = " << msg[1] );
-           double aileron = ((double)msg[0] / 2048.0) - 1.0;
-           double elevator = ((double)msg[1] / 2048.0) - 1.0;
-           if ( fabs(aileron) < 0.05 ) {
-               aileron = 0.0;
+       if ( io->get_type() == fgFileType ) {
+           if ( io->read( (char *)(& buf), length ) == length ) {
+               FG_LOG( FG_IO, FG_DEBUG, "Success reading data." );
+               int *msg;
+               msg = (int *)buf;
+               FG_LOG( FG_IO, FG_DEBUG, "X = " << msg[0] << " Y = "
+                       << msg[1] );
+               double aileron = ((double)msg[0] / 2048.0) - 1.0;
+               double elevator = ((double)msg[1] / 2048.0) - 1.0;
+               if ( fabs(aileron) < 0.05 ) {
+                   aileron = 0.0;
+               }
+               if ( fabs(elevator) < 0.05 ) {
+                   elevator = 0.0;
+               }
+               controls.set_aileron( aileron );
+               controls.set_elevator( -elevator );
            }
-           if ( fabs(elevator) < 0.05 ) {
-               elevator = 0.0;
+       } else {
+           while ( io->read( (char *)(& buf), length ) == length ) {
+               FG_LOG( FG_IO, FG_DEBUG, "Success reading data." );
+               int *msg;
+               msg = (int *)buf;
+               FG_LOG( FG_IO, FG_DEBUG, "X = " << msg[0] << " Y = "
+                       << msg[1] );
+               double aileron = ((double)msg[0] / 2048.0) - 1.0;
+               double elevator = ((double)msg[1] / 2048.0) - 1.0;
+               if ( fabs(aileron) < 0.05 ) {
+                   aileron = 0.0;
+               }
+               if ( fabs(elevator) < 0.05 ) {
+                   elevator = 0.0;
+               }
+               controls.set_aileron( aileron );
+               controls.set_elevator( -elevator );
            }
-           controls.set_aileron( aileron );
-           controls.set_elevator( -elevator );
        }
     }
 
index b66d33b7a83d6a8c0ea21a69a57c880ee20532d3..75b8d2b56b22c039a5800b97c978862076dba3aa 100644 (file)
@@ -71,9 +71,16 @@ bool FGNative::process() {
            return false;
        }
     } else if ( get_direction() == in ) {
-       while ( io->read( (char *)(& buf), length ) == length ) {
-           FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
-           *cur_fdm_state = buf;
+       if ( io->get_type() == fgFileType ) {
+           if ( io->read( (char *)(& buf), length ) == length ) {
+               FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
+               *cur_fdm_state = buf;
+           }
+       } else {
+           while ( io->read( (char *)(& buf), length ) == length ) {
+               FG_LOG( FG_IO, FG_ALERT, "Success reading data." );
+               *cur_fdm_state = buf;
+           }
        }
     }