]> git.mxchange.org Git - flightgear.git/commitdiff
Allow generic file protocol to terminate fg after a number of repetitions.
authortimoore <timoore>
Thu, 7 Aug 2008 22:24:47 +0000 (22:24 +0000)
committertimoore <timoore>
Thu, 7 Aug 2008 22:24:47 +0000 (22:24 +0000)
docs-mini/README.IO
src/AIModel/AIBase.cxx
src/AIModel/AIBase.hxx
src/Main/fg_io.cxx
src/Main/fg_io.hxx
src/Network/generic.cxx
src/Network/generic.hxx

index 9388fcbbaf0106e5af825be66722a12a145b4c86..3321adef42e46b0ae967911325aa0f4cb64bdc56 100644 (file)
@@ -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:
 
index 69c69d8902403de9d6524c8e7f0ae868b7bfafae..45e2e1e20e141279344631ff16223536040f0c9b 100644 (file)
@@ -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);
index 7f02842360de92ee8a58717d3a4aadcbb3e2d85e..b67c928787a686c24b301f68d2264a9050b617b3 100644 (file)
@@ -192,6 +192,7 @@ protected:
 private:
     int _refID;
     object_type _otype;
+    bool _initialized;
 
 public:
     object_type getType();
index e0e2a5c241957adab5f5061b0d8447c47bfff7f2..2ca273f1de2f10de551f747ed98fb5f1747ae028 100644 (file)
@@ -26,7 +26,7 @@
 
 #include <simgear/compiler.h>
 
-#include <stdlib.h>             // atoi()
+#include <cstdlib>             // atoi()
 
 #include <string>
 
@@ -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<FGGeneric*>(io);
+                if (generic)
+                    generic->setExitOnError(true);
+            } else {
+                repeat = -1;
+            }
+        }
        SGFile *ch = new SGFile( file, repeat );
        io->set_io_channel( ch );
     } else if ( medium == "socket" ) {
index b470aa59e0b00c2f35b367d2c3c91e62ef2cc5de..ca6f0f78bcae60be8ec0ff9b735aee116fc1f7c4 100644 (file)
@@ -31,9 +31,6 @@
 #include <vector>
 #include <string>
 
-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;
 };
 
 
index f74c954fe60d8d149f36059e8d15ff27b299da1c..8058ed29c476ce8b03dc88d4f5a8824114bab784 100644 (file)
@@ -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;
 }
 
 
index b2d0df18ef1d34d73c97a6305b6058cbe66a9ded..1d07b1265efefa034699a14767ab62e34208e060 100644 (file)
@@ -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;
 };