diff --git a/docs-mini/README.IO b/docs-mini/README.IO index 9388fcbba..3321adef4 100644 --- a/docs-mini/README.IO +++ b/docs-mini/README.IO @@ -29,7 +29,7 @@ Generic Communication: params can be: serial port communication: serial,dir,hz,device,baud,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. @@ -90,6 +90,9 @@ File I/O: --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: diff --git a/src/AIModel/AIBase.cxx b/src/AIModel/AIBase.cxx index 69c69d890..45e2e1e20 100644 --- a/src/AIModel/AIBase.cxx +++ b/src/AIModel/AIBase.cxx @@ -70,7 +70,8 @@ FGAIBase::FGAIBase(object_type ot) : _impact_speed(0), _refID( _newAIModelID() ), - _otype(ot) + _otype(ot), + _initialized(false) { tgt_heading = hdg = tgt_altitude_ft = tgt_speed = 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); - if (model.valid()) { + if (model.valid() && _initialized == false) { model->setNodeMask(model->getNodeMask() & ~SG_NODEMASK_TERRAIN_BIT); aip.init( model.get() ); aip.setVisible(true); invisible = false; globals->get_scenery()->get_scene_graph()->addChild(aip.getSceneGraph()); + _initialized = true; } else if (!model_path.empty()) { SG_LOG(SG_INPUT, SG_WARN, "AIBase: Could not load model " << model_path); diff --git a/src/AIModel/AIBase.hxx b/src/AIModel/AIBase.hxx index 7f0284236..b67c92878 100644 --- a/src/AIModel/AIBase.hxx +++ b/src/AIModel/AIBase.hxx @@ -192,6 +192,7 @@ protected: private: int _refID; object_type _otype; + bool _initialized; public: object_type getType(); diff --git a/src/Main/fg_io.cxx b/src/Main/fg_io.cxx index e0e2a5c24..2ca273f1d 100644 --- a/src/Main/fg_io.cxx +++ b/src/Main/fg_io.cxx @@ -26,7 +26,7 @@ #include -#include // atoi() +#include // atoi() #include @@ -67,6 +67,7 @@ #include "globals.hxx" #include "fg_io.hxx" +using std::atoi; using std::string; @@ -242,6 +243,7 @@ FGIO::parse_port_config( const string& config ) string baud = tokens[5]; SG_LOG( SG_IO, SG_INFO, " baud = " << baud ); + SGSerial *ch = new SGSerial( device, baud ); io->set_io_channel( ch ); } else if ( medium == "file" ) { @@ -253,9 +255,17 @@ FGIO::parse_port_config( const string& config ) string file = tokens[4]; SG_LOG( SG_IO, SG_INFO, " file name = " << file ); - bool repeat = false; - if (tokens.size() >= 7 && tokens[6] == "repeat") - repeat = true; + int repeat = 1; + if (tokens.size() >= 7 && tokens[6] == "repeat") { + if (tokens.size() >= 8) { + repeat = atoi(tokens[7].c_str()); + FGGeneric* generic = dynamic_cast(io); + if (generic) + generic->setExitOnError(true); + } else { + repeat = -1; + } + } SGFile *ch = new SGFile( file, repeat ); io->set_io_channel( ch ); } else if ( medium == "socket" ) { diff --git a/src/Main/fg_io.hxx b/src/Main/fg_io.hxx index b470aa59e..ca6f0f78b 100644 --- a/src/Main/fg_io.hxx +++ b/src/Main/fg_io.hxx @@ -31,9 +31,6 @@ #include #include -using std::vector; -using std::string; - class FGProtocol; class FGIO : public SGSubsystem @@ -51,13 +48,13 @@ public: private: - FGProtocol* parse_port_config( const string& cfgstr ); + FGProtocol* parse_port_config( const std::string& cfgstr ); private: // define the global I/O channel list //io_container global_io_list; - vector< FGProtocol* > io_channels; + std::vector< FGProtocol* > io_channels; }; diff --git a/src/Network/generic.cxx b/src/Network/generic.cxx index f74c954fe..8058ed29c 100644 --- a/src/Network/generic.cxx +++ b/src/Network/generic.cxx @@ -43,7 +43,8 @@ -FGGeneric::FGGeneric(string& config) { +FGGeneric::FGGeneric(string& config) : exitOnError(false) +{ string file = config+".xml"; @@ -256,18 +257,22 @@ bool FGGeneric::process() { gen_message(); if ( ! io->write( buf, length ) ) { SG_LOG( SG_IO, SG_WARN, "Error writing data." ); - return false; + goto error_out; } } else if ( get_direction() == SG_IO_IN ) { if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) { parse_message(); } else { SG_LOG( SG_IO, SG_ALERT, "Error reading data." ); - return false; + goto error_out; } } - return true; +error_out: + if (exitOnError) + fgExit(1); + else + return false; } diff --git a/src/Network/generic.hxx b/src/Network/generic.hxx index b2d0df18e..1d07b1265 100644 --- a/src/Network/generic.hxx +++ b/src/Network/generic.hxx @@ -53,6 +53,8 @@ public: // close the channel bool close(); + void setExitOnError(bool val) { exitOnError = val; } + bool getExitOnError() { return exitOnError; } protected: enum e_type { FG_BOOL=0, FG_INT, FG_DOUBLE, FG_STRING }; @@ -85,7 +87,7 @@ private: int binary_footer_value; void read_config(SGPropertyNode *root, vector<_serial_prot> &msg); - + bool exitOnError; };