Beispiel #1
0
// scan the base path for fltNNNN directories.  Return the biggest
// flight number
int max_flight_num() {
    int max = -1;

    DIR *d = opendir( log_path.c_str() );
    if ( d == NULL ) {
        printf( "Cannot open %s for log writing\n", log_path.c_str() );
        return max;
    }

    struct dirent *file;
    while ( ( file = readdir(d) ) != NULL  ) {
        if ( strncmp( file->d_name, "flt", 3 ) == 0 ) {
            int num;
            sscanf( file->d_name, "flt%d", &num );
            if ( num > max ) {
                max = num;
            }
            printf("file = %s  num = %d  max = %d\n", file->d_name, num, max);
        }
    }

    if ( closedir( d ) != 0 ) {
        printf("Error: cannot close log directory\n");
        return -1;
    }

    return max;
}
Beispiel #2
0
SGPath FGFCS::FindFullPathName(const SGPath& path) const
{
  SGPath name = FGModel::FindFullPathName(path);
  if (systype != stSystem || !name.isNull()) return name;

  name = CheckPathName(FDMExec->GetFullAircraftPath()/string("Systems"), path);
  if (!name.isNull()) return name;

  return CheckPathName(FDMExec->GetSystemsPath(), path);
}
Beispiel #3
0
bool options(int count, char **arg)
{
  int i;
  bool result = true;

  if (count == 1) {
    PrintHelp();
    exit(0);
  }

  cout.setf(ios_base::fixed);

  for (i=1; i<count; i++) {
    string argument = string(arg[i]);
    string keyword(argument);
    string value("");
    string::size_type n=argument.find("=");

    if (n != string::npos && n > 0) {
      keyword = argument.substr(0, n);
      value = argument.substr(n+1);
    }

    if (keyword == "--help") {
      PrintHelp();
      exit(0);
    } else if (keyword == "--version") {
      cout << endl << "  JSBSim Version: " << FDMExec->GetVersion() << endl << endl;
      exit (0);
    } else if (keyword == "--realtime") {
      realtime = true;
    } else if (keyword == "--nice") {
      play_nice = true;
      if (n != string::npos) {
        try {
          sleep_period = atof( value.c_str() );
        } catch (...) {
          cerr << endl << "  Invalid sleep period given!" << endl << endl;
          result = false;
        }
      } else {
        sleep_period = 0.01;
      }
    } else if (keyword == "--suspend") {
      suspend = true;
    } else if (keyword == "--nohighlight") {
        nohighlight = true;
    } else if (keyword == "--outputlogfile") {
      if (n != string::npos) {
        LogOutputName.push_back(value);
      }
    } else if (keyword == "--logdirectivefile") {
      if (n != string::npos) {
        LogDirectiveName.push_back(SGPath::fromLocal8Bit(value.c_str()));
      } else {
        gripe;
        exit(1);
      }
    } else if (keyword == "--root") {
      if (n != string::npos) {
        RootDir = SGPath::fromLocal8Bit(value.c_str());
      } else {
        gripe;
        exit(1);
      }
    } else if (keyword == "--aircraft") {
      if (n != string::npos) {
        AircraftName = value;
      } else {
        gripe;
        exit(1);
      }
    } else if (keyword == "--script") {
      if (n != string::npos) {
        ScriptName = SGPath::fromLocal8Bit(value.c_str());
      } else {
        gripe;
        exit(1);
      }
    } else if (keyword == "--initfile") {
      if (n != string::npos) {
        ResetName = SGPath::fromLocal8Bit(value.c_str());
      } else {
        gripe;
        exit(1);
      }

    } else if (keyword == "--property") {
      if (n != string::npos) {
         string propName = value.substr(0,value.find("="));
         string propValueString = value.substr(value.find("=")+1);
         double propValue = atof(propValueString.c_str());
         CommandLineProperties.push_back(propName);
         CommandLinePropertyValues.push_back(propValue);
      } else {
        gripe;
        exit(1);
      }

    } else if (keyword.substr(0,5) == "--end") {
      if (n != string::npos) {
        try {
        end_time = atof( value.c_str() );
        } catch (...) {
          cerr << endl << "  Invalid end time given!" << endl << endl;
          result = false;
        }
      } else {
        gripe;
        exit(1);
      }

    } else if (keyword == "--simulation-rate") {
      if (n != string::npos) {
        try {
          simulation_rate = atof( value.c_str() );
          override_sim_rate = true;
        } catch (...) {
          cerr << endl << "  Invalid simulation rate given!" << endl << endl;
          result = false;
        }
      } else {
        gripe;
        exit(1);
      }

    } else if (keyword == "--catalog") {
        catalog = true;
        if (value.size() > 0) AircraftName=value;
    } else if (keyword.substr(0,2) != "--" && value.empty() ) {
      // See what kind of files we are specifying on the command line

      XMLFile xmlFile;
      SGPath path = SGPath::fromLocal8Bit(keyword.c_str());
      
      if (xmlFile.IsScriptFile(path)) ScriptName = path;
      else if (xmlFile.IsLogDirectiveFile(path))  LogDirectiveName.push_back(path);
      else if (xmlFile.IsAircraftFile(SGPath("aircraft")/keyword/keyword)) AircraftName = keyword;
      else if (xmlFile.IsInitFile(path)) ResetName = path;
      else if (xmlFile.IsInitFile(SGPath("aircraft")/AircraftName/keyword)) ResetName = SGPath("aircraft")/AircraftName/keyword;
      else {
        cerr << "The argument \"" << keyword << "\" cannot be interpreted as a file name or option." << endl;
        exit(1);
      }

    }
    else //Unknown keyword so print the help file, the bad keyword and abort
    {
          PrintHelp();
          cerr << "The argument \"" << keyword << "\" cannot be interpreted as a file name or option." << endl;
          exit(1);
    }

  }

  // Post-processing for script options. check for incompatible options.

  if (catalog && !ScriptName.isNull()) {
    cerr << "Cannot specify catalog with script option" << endl << endl;
    result = false;
  }
  if (!AircraftName.empty() && ResetName.isNull() && !catalog) {
    cerr << "You must specify an initialization file with the aircraft name." << endl << endl;
    result = false;
  }
  if (!ScriptName.isNull() && !AircraftName.empty()) {
    cerr << "You cannot specify an aircraft file with a script." << endl;
    result = false;
  }

  return result;

}
Beispiel #4
0
bool logging_init() {
    // find the biggest flight number logged so far
    int max = max_flight_num();
    printf("Max log dir is flt%05d\n", max);


    // make the new logging directory
    char new_dir[256];
    snprintf( new_dir, 256, "%s/flt%05d", log_path.c_str(), max+1 );
    printf("Creating log dir: %s\n", new_dir);
    int result = mkdir( new_dir, 01777 );
    if ( result != 0 ) {
        printf("Error: creating %s\n", new_dir);
    }

    // open all the logging files

    SGPath file;

    file = new_dir; file.append( "imu.dat.gz" );
    if ( (fimu = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannont open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "gps.dat.gz" );
    if ( (fgps = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannont open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "nav.dat.gz" );
    if ( (fnav = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannont open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "servo.dat.gz" );
    if ( (fservo = gzopen( file.c_str(),"w+b" )) == NULL ) {
        printf("Cannont open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "health.dat.gz" );
    if ( (fhealth = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannont open %s\n", file.c_str());
        return false;
    }

    return true;
}
Beispiel #5
0
bool logging_init() {
    // find the biggest flight number logged so far
    int max = max_flight_num();
    printf("Max log dir is flt%05d\n", max);

    // make the new logging directory
    char new_dir[256];
    snprintf( new_dir, 256, "%s/flt%05d", log_path.c_str(), max+1 );
    printf("Creating log dir: %s\n", new_dir);
    int result = mkdir( new_dir, 01777 );
    if ( result != 0 ) {
        printf("Error: creating %s\n", new_dir);
    }

    // open all the logging files

    SGPath file;

    file = new_dir; file.append( "imu.dat.gz" );
    if ( (fimu = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannot open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "gps.dat.gz" );
    if ( (fgps = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannot open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "air.dat.gz" );
    if ( (fair = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannot open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "filter.dat.gz" );
    if ( (ffilter = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannot open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "actuator.dat.gz" );
    if ( (fact = gzopen( file.c_str(),"w+b" )) == NULL ) {
        printf("Cannot open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "pilot.dat.gz" );
    if ( (fpilot = gzopen( file.c_str(),"w+b" )) == NULL ) {
        printf("Cannot open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "ap.dat.gz" );
    if ( (fap = gzopen( file.c_str(), "w+b" )) == NULL ) {
        printf("Cannot open %s\n", file.c_str());
        return false;
    }

    file = new_dir; file.append( "events.dat" );
    if ( (fevent = fopen( file.c_str(), "w" )) == NULL ) {
	printf("Cannot open %s\n", file.c_str());
	return false;
    }

    return true;
}