diff --git a/src/Network/fg_file.cxx b/src/Network/fg_file.cxx index e73179eb8..e8e0f3642 100644 --- a/src/Network/fg_file.cxx +++ b/src/Network/fg_file.cxx @@ -37,6 +37,7 @@ FG_USING_STD(string); FGFile::FGFile() { + set_type( fgFileType ); } diff --git a/src/Network/fg_serial.cxx b/src/Network/fg_serial.cxx index e1897b59c..6fae04c8c 100644 --- a/src/Network/fg_serial.cxx +++ b/src/Network/fg_serial.cxx @@ -38,6 +38,7 @@ FG_USING_STD(string); FGSerial::FGSerial() : save_len(0) { + set_type( fgSerialType ); } diff --git a/src/Network/fg_socket.cxx b/src/Network/fg_socket.cxx index 711899131..e57b09ad0 100644 --- a/src/Network/fg_socket.cxx +++ b/src/Network/fg_socket.cxx @@ -54,6 +54,7 @@ FG_USING_STD(string); FGSocket::FGSocket() : save_len(0) { + set_type( fgSocketType ); } diff --git a/src/Network/iochannel.hxx b/src/Network/iochannel.hxx index 5830f6e2a..0793ef7fc 100644 --- a/src/Network/iochannel.hxx +++ b/src/Network/iochannel.hxx @@ -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; } }; diff --git a/src/Network/joyclient.cxx b/src/Network/joyclient.cxx index bf546544b..2d05092fc 100644 --- a/src/Network/joyclient.cxx +++ b/src/Network/joyclient.cxx @@ -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 ); } } diff --git a/src/Network/native.cxx b/src/Network/native.cxx index b66d33b7a..75b8d2b56 100644 --- a/src/Network/native.cxx +++ b/src/Network/native.cxx @@ -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; + } } }