1
0
Fork 0

Allow generic file protocol to terminate fg after a number of repetitions.

This commit is contained in:
timoore 2008-08-07 22:24:47 +00:00
parent 42e14d98f4
commit 0d0bd58268
7 changed files with 37 additions and 17 deletions

View file

@ -29,7 +29,7 @@ Generic Communication:
params can be: params can be:
serial port communication: serial,dir,hz,device,baud,protocol serial port communication: serial,dir,hz,device,baud,protocol
socket communication: socket,dir,hz,machine,port,style,protocol socket communication: socket,dir,hz,machine,port,style,protocol
i/o to a file: file,dir,hz,filename,protocol[,repeat] i/o to a file: file,dir,hz,filename,protocol[,repeat[,count]]
See README.protocol for how to define a generic protocol. See README.protocol for how to define a generic protocol.
@ -90,6 +90,9 @@ File I/O:
--generic=file,in,20,flight.out,playback,repeat --generic=file,in,20,flight.out,playback,repeat
With a numeric argument, FlightGear will exit after that number of repeats.
--generic=file,in,20,flight.out,playback,repeat,5
Moving Map Example: Moving Map Example:

View file

@ -70,7 +70,8 @@ FGAIBase::FGAIBase(object_type ot) :
_impact_speed(0), _impact_speed(0),
_refID( _newAIModelID() ), _refID( _newAIModelID() ),
_otype(ot) _otype(ot),
_initialized(false)
{ {
tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0; tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 0.0;
tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0; tgt_roll = roll = tgt_pitch = tgt_yaw = tgt_vs = vs = pitch = 0.0;
@ -174,12 +175,13 @@ bool FGAIBase::init(bool search_in_AI_path) {
model = load3DModel(f, props); model = load3DModel(f, props);
if (model.valid()) { if (model.valid() && _initialized == false) {
model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT); model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT);
aip.init( model.get() ); aip.init( model.get() );
aip.setVisible(true); aip.setVisible(true);
invisible = false; invisible = false;
globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph()); globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph());
_initialized = true;
} else if (!model_path.empty()) { } else if (!model_path.empty()) {
SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path); SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path);

View file

@ -192,6 +192,7 @@ protected:
private: private:
int _refID; int _refID;
object_type _otype; object_type _otype;
bool _initialized;
public: public:
object_type getType(); object_type getType();

View file

@ -26,7 +26,7 @@
#include <simgear/compiler.h> #include <simgear/compiler.h>
#include <stdlib.h> // atoi() #include <cstdlib> // atoi()
#include <string> #include <string>
@ -67,6 +67,7 @@
#include "globals.hxx" #include "globals.hxx"
#include "fg_io.hxx" #include "fg_io.hxx"
using std::atoi;
using std::string; using std::string;
@ -242,6 +243,7 @@ FGIO::parse_port_config( const string& config )
string baud = tokens[5]; string baud = tokens[5];
SG_LOG( SG_IO, SG_INFO, " baud = " << baud ); SG_LOG( SG_IO, SG_INFO, " baud = " << baud );
SGSerial *ch = new SGSerial( device, baud ); SGSerial *ch = new SGSerial( device, baud );
io->set_io_channel( ch ); io->set_io_channel( ch );
} else if ( medium == "file" ) { } else if ( medium == "file" ) {
@ -253,9 +255,17 @@ FGIO::parse_port_config( const string& config )
string file = tokens[4]; string file = tokens[4];
SG_LOG( SG_IO, SG_INFO, " file name = " << file ); SG_LOG( SG_IO, SG_INFO, " file name = " << file );
bool repeat = false; int repeat = 1;
if (tokens.size() >= 7 && tokens[6] == "repeat") if (tokens.size() >= 7 && tokens[6] == "repeat") {
repeat = true; if (tokens.size() >= 8) {
repeat = atoi(tokens[7].c_str());
FGGeneric* generic = dynamic_cast<FGGeneric*>(io);
if (generic)
generic->setExitOnError(true);
} else {
repeat = -1;
}
}
SGFile *ch = new SGFile( file, repeat ); SGFile *ch = new SGFile( file, repeat );
io->set_io_channel( ch ); io->set_io_channel( ch );
} else if ( medium == "socket" ) { } else if ( medium == "socket" ) {

View file

@ -31,9 +31,6 @@
#include <vector> #include <vector>
#include <string> #include <string>
using std::vector;
using std::string;
class FGProtocol; class FGProtocol;
class FGIO : public SGSubsystem class FGIO : public SGSubsystem
@ -51,13 +48,13 @@ public:
private: private:
FGProtocol* parse_port_config( const string& cfgstr ); FGProtocol* parse_port_config( const std::string& cfgstr );
private: private:
// define the global I/O channel list // define the global I/O channel list
//io_container global_io_list; //io_container global_io_list;
vector< FGProtocol* > io_channels; std::vector< FGProtocol* > io_channels;
}; };

View file

@ -43,7 +43,8 @@
FGGeneric::FGGeneric(string& config) { FGGeneric::FGGeneric(string& config) : exitOnError(false)
{
string file = config+".xml"; string file = config+".xml";
@ -256,18 +257,22 @@ bool FGGeneric::process() {
gen_message(); gen_message();
if ( ! io->write( buf, length ) ) { if ( ! io->write( buf, length ) ) {
SG_LOG( SG_IO, SG_WARN, "Error writing data." ); SG_LOG( SG_IO, SG_WARN, "Error writing data." );
return false; goto error_out;
} }
} else if ( get_direction() == SG_IO_IN ) { } else if ( get_direction() == SG_IO_IN ) {
if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) { if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
parse_message(); parse_message();
} else { } else {
SG_LOG( SG_IO, SG_ALERT, "Error reading data." ); SG_LOG( SG_IO, SG_ALERT, "Error reading data." );
return false; goto error_out;
} }
} }
return true; return true;
error_out:
if (exitOnError)
fgExit(1);
else
return false;
} }

View file

@ -53,6 +53,8 @@ public:
// close the channel // close the channel
bool close(); bool close();
void setExitOnError(bool val) { exitOnError = val; }
bool getExitOnError() { return exitOnError; }
protected: protected:
enum e_type { FG_BOOL=0, FG_INT, FG_DOUBLE, FG_STRING }; enum e_type { FG_BOOL=0, FG_INT, FG_DOUBLE, FG_STRING };
@ -85,7 +87,7 @@ private:
int binary_footer_value; int binary_footer_value;
void read_config(SGPropertyNode *root, vector<_serial_prot> &msg); void read_config(SGPropertyNode *root, vector<_serial_prot> &msg);
bool exitOnError;
}; };