1
0
Fork 0

Added a get_type() to the iochannel class so the protocol code can optionally

impliment different behavior depending on the channel that's being used.
This commit is contained in:
curt 2000-06-01 21:13:26 +00:00
parent 818a462a02
commit 6cb91111d8
6 changed files with 58 additions and 16 deletions

View file

@ -37,6 +37,7 @@ FG_USING_STD(string);
FGFile::FGFile() { FGFile::FGFile() {
set_type( fgFileType );
} }

View file

@ -38,6 +38,7 @@ FG_USING_STD(string);
FGSerial::FGSerial() : FGSerial::FGSerial() :
save_len(0) save_len(0)
{ {
set_type( fgSerialType );
} }

View file

@ -54,6 +54,7 @@ FG_USING_STD(string);
FGSocket::FGSocket() : FGSocket::FGSocket() :
save_len(0) save_len(0)
{ {
set_type( fgSocketType );
} }

View file

@ -40,8 +40,16 @@ FG_USING_STD(string);
class FGProtocol; class FGProtocol;
enum FGChannelType {
fgFileType = 0,
fgSerialType = 1,
fgSocketType = 2
};
class FGIOChannel { class FGIOChannel {
FGChannelType type;
public: public:
FGIOChannel(); FGIOChannel();
@ -53,6 +61,9 @@ public:
virtual int write( char *buf, int length ); virtual int write( char *buf, int length );
virtual int writestring( char *str ); virtual int writestring( char *str );
virtual bool close(); virtual bool close();
virtual void set_type( FGChannelType t ) { type = t; }
virtual FGChannelType get_type() const { return type; }
}; };

View file

@ -67,21 +67,42 @@ bool FGJoyClient::process() {
return false; return false;
} else if ( get_direction() == in ) { } else if ( get_direction() == in ) {
FG_LOG( FG_IO, FG_DEBUG, "Searching for data." ); FG_LOG( FG_IO, FG_DEBUG, "Searching for data." );
while ( io->read( (char *)(& buf), length ) == length ) { if ( io->get_type() == fgFileType ) {
FG_LOG( FG_IO, FG_DEBUG, "Success reading data." ); if ( io->read( (char *)(& buf), length ) == length ) {
int *msg; FG_LOG( FG_IO, FG_DEBUG, "Success reading data." );
msg = (int *)buf; int *msg;
FG_LOG( FG_IO, FG_DEBUG, "X = " << msg[0] << " Y = " << msg[1] ); msg = (int *)buf;
double aileron = ((double)msg[0] / 2048.0) - 1.0; FG_LOG( FG_IO, FG_DEBUG, "X = " << msg[0] << " Y = "
double elevator = ((double)msg[1] / 2048.0) - 1.0; << msg[1] );
if ( fabs(aileron) < 0.05 ) { double aileron = ((double)msg[0] / 2048.0) - 1.0;
aileron = 0.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 ) { } else {
elevator = 0.0; 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 );
} }
} }

View file

@ -71,9 +71,16 @@ bool FGNative::process() {
return false; return false;
} }
} else if ( get_direction() == in ) { } else if ( get_direction() == in ) {
while ( io->read( (char *)(& buf), length ) == length ) { if ( io->get_type() == fgFileType ) {
FG_LOG( FG_IO, FG_ALERT, "Success reading data." ); if ( io->read( (char *)(& buf), length ) == length ) {
*cur_fdm_state = buf; 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;
}
} }
} }