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() {
set_type( fgFileType );
}

View file

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

View file

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

View 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; }
};

View file

@ -67,11 +67,13 @@ 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 ) {
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] );
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 ) {
@ -83,6 +85,25 @@ bool FGJoyClient::process() {
controls.set_aileron( aileron );
controls.set_elevator( -elevator );
}
} 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 );
}
}
}
return true;

View file

@ -71,11 +71,18 @@ bool FGNative::process() {
return false;
}
} else if ( get_direction() == in ) {
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;
}
}
}
return true;
}