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.
--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:
_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;
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);
private:
int _refID;
object_type _otype;
+ bool _initialized;
public:
object_type getType();
#include <simgear/compiler.h>
-#include <stdlib.h> // atoi()
+#include <cstdlib> // atoi()
#include <string>
#include "globals.hxx"
#include "fg_io.hxx"
+using std::atoi;
using std::string;
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" ) {
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" ) {
#include <vector>
#include <string>
-using std::vector;
-using std::string;
-
class FGProtocol;
class FGIO : public SGSubsystem
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;
};
-FGGeneric::FGGeneric(string& config) {
+FGGeneric::FGGeneric(string& config) : exitOnError(false)
+{
string file = config+".xml";
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;
}
// 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 };
int binary_footer_value;
void read_config(SGPropertyNode *root, vector<_serial_prot> &msg);
-
+ bool exitOnError;
};