コード例 #1
0
ファイル: RunWindEKF.cpp プロジェクト: davidswelt/XCSoar
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  printf("# time quality wind_bearing (deg) wind_speed (m/s) grndspeed (m/s) tas (m/s) bearing (deg)\n");

  WindEKFGlue wind_ekf;
  wind_ekf.Reset();

  while (replay->Next()) {
    const MoreData &data = replay->Basic();

    WindEKFGlue::Result result =
      wind_ekf.Update(data, replay->Calculated());
    if (result.quality > 0)
      printf("%d %d %d %g %g %g %d\n", (int)data.time, result.quality,
             (int)result.wind.bearing.Degrees(),
             (double)result.wind.norm,
             (double)data.ground_speed,
             (double)data.true_airspeed,
             (int)data.track.Degrees());
  }

  delete replay;
}
コード例 #2
0
ファイル: DumpVario.cpp プロジェクト: MindMil/XCSoar
int
main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  const unsigned sample_rate = 44100;

  VarioSynthesiser synthesiser;

  while (replay->Next()) {
    fixed vario = replay->Basic().brutto_vario;
    synthesiser.SetVario(sample_rate, vario);

    static int16_t buffer[sample_rate];
    synthesiser.Synthesise(buffer, ARRAY_SIZE(buffer));

    if (write(1, buffer, sizeof(buffer)) < 0) {
      perror("write");
      return EXIT_FAILURE;
    }
  }

  return EXIT_SUCCESS;
}
コード例 #3
0
ファイル: Flight.hpp プロジェクト: CnZoom/XcSoarWork
  /**
   * Return a DebugReplay, either direct from file or from memory,
   * depending on the keep_flight flag. Don't forget to delete
   * the replay after use.
   */
  DebugReplay *Replay() {
    DebugReplay *replay;

    if (keep_flight) replay = DebugReplayVector::Create(*fixes);
    else replay = DebugReplayIGC::Create(flight_file);

    if (qnh_available)
      replay->SetQNH(qnh);

    return replay;
  };
コード例 #4
0
int main(int argc, char **argv)
{
    Args args(argc, argv, "DRIVER INFILE OUTFILE");
    DebugReplay *replay = CreateDebugReplay(args);
    if (replay == NULL)
        return EXIT_FAILURE;

    const char *output_file = args.ExpectNext();
    args.ExpectEnd();

    while (!replay->Basic().time_available)
        if (!replay->Next())
            return 0;

    const TCHAR *driver_name = _T("Unknown");

    PathName igc_path(output_file);
    IGCWriter writer(igc_path, replay->Basic());
    writer.WriteHeader(replay->Basic().date_time_utc, _T("Manfred Mustermann"),
                       _T("Ventus"), _T("D-1234"),
                       _T("MM"), _T("Foo"), driver_name);

    GPSClock log_clock(fixed(1));
    while (replay->Next())
        if (log_clock.check_advance(replay->Basic().time))
            writer.LogPoint(replay->Basic());

    writer.Flush();

    return EXIT_SUCCESS;
}
コード例 #5
0
ファイル: RunWaveComputer.cpp プロジェクト: ahsparrow/xcsoar
int main(int argc, char **argv)
{
    Args args(argc, argv, "DRIVER FILE");
    DebugReplay *replay = CreateDebugReplay(args);
    if (replay == NULL)
        return EXIT_FAILURE;

    args.ExpectEnd();

    WaveSettings settings;
    settings.SetDefaults();
    settings.enabled = true;

    WaveComputer wave;
    wave.Reset();

    WaveResult result;
    result.Clear();

    while (replay->Next()) {
        const MoreData &basic = replay->Basic();
        const DerivedInfo &calculated = replay->Calculated();

        wave.Compute(basic, calculated.flight, result, settings);
    }

    delete replay;

    for (const auto &w : result.waves) {
        TCHAR time_buffer[32];
        if (w.time >= 0)
            FormatTime(time_buffer, w.time);
        else
            _tcscpy(time_buffer, _T("?"));

        _tprintf(_T("wave: t=%s location=%f,%f a=%f,%f b=%f,%f location=%s normal=%f\n"),
                 time_buffer,
                 (double)w.location.longitude.Degrees(),
                 (double)w.location.latitude.Degrees(),
                 (double)w.a.longitude.Degrees(),
                 (double)w.a.latitude.Degrees(),
                 (double)w.b.longitude.Degrees(),
                 (double)w.b.latitude.Degrees(),
                 FormatGeoPoint(w.location, CoordinateFormat::DDMMSS).c_str(),
                 (double)w.normal.Degrees());
    }

    return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: TestOLC.cpp プロジェクト: macsux/XCSoar
static int
TestOLC(DebugReplay &replay)
{
  for (int i = 1; replay.Next(); i++) {
    if (i % 500 == 0) {
      putchar('.');
      fflush(stdout);
    }

    const AircraftState state =
      ToAircraftState(replay.Basic(), replay.Calculated());
    full_trace.append(state);
    sprint_trace.append(state);

    full_trace.optimise_if_old();
    sprint_trace.optimise_if_old();

    olc_sprint.UpdateIdle();
  }

  olc_classic.SolveExhaustive();
  olc_fai.SolveExhaustive();
  olc_league.SolveExhaustive();
  olc_plus.SolveExhaustive();

  putchar('\n');

  std::cout << "classic\n";
  PrintHelper::print(olc_classic.GetStats().get_contest_result());
  std::cout << "league\n";
  PrintHelper::print(olc_league.GetStats().get_contest_result());
  std::cout << "fai\n";
  PrintHelper::print(olc_fai.GetStats().get_contest_result());
  std::cout << "sprint\n";
  PrintHelper::print(olc_sprint.GetStats().get_contest_result());
  std::cout << "plus\n";
  PrintHelper::print(olc_plus.GetStats().get_contest_result());

  olc_classic.Reset();
  olc_fai.Reset();
  olc_sprint.Reset();
  olc_league.Reset();
  olc_plus.Reset();
  full_trace.clear();
  sprint_trace.clear();

  return 0;
}
コード例 #7
0
ファイル: RunWindComputer.cpp プロジェクト: CnZoom/XcSoarPull
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  printf("# time wind_bearing (deg) wind_speed (m/s)\n");

  GlidePolar glide_polar(fixed(0));

  CirclingSettings circling_settings;

  WindSettings wind_settings;
  wind_settings.SetDefaults();

  CirclingComputer circling_computer;
  circling_computer.Reset();

  WindComputer wind_computer;
  wind_computer.Reset();

  Validity last;
  last.Clear();

  while (replay->Next()) {
    const MoreData &basic = replay->Basic();
    const DerivedInfo &calculated = replay->Calculated();

    circling_computer.TurnRate(replay->SetCalculated(),
                               basic, calculated.flight);
    circling_computer.Turning(replay->SetCalculated(),
                              basic,
                              calculated.flight,
                              circling_settings);

    wind_computer.Compute(wind_settings, glide_polar, basic,
                          replay->SetCalculated());

    if (calculated.estimated_wind_available.Modified(last)) {
      TCHAR time_buffer[32];
      FormatTime(time_buffer, replay->Basic().time);

      _tprintf(_T("%s %d %g\n"),
               time_buffer, (int)calculated.estimated_wind.bearing.Degrees(),
               (double)calculated.estimated_wind.norm);
    }

    last = calculated.estimated_wind_available;
  }

  delete replay;
}
コード例 #8
0
ファイル: RunFlightLogger.cpp プロジェクト: Advi42/XCSoar
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE OUTFILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  const auto path = args.ExpectNextPath();
  args.ExpectEnd();

  FlightLogger logger;
  logger.SetPath(path);
  logger.Reset();

  while (replay->Next())
    logger.Tick(replay->Basic(), replay->Calculated());

  delete replay;
}
コード例 #9
0
ファイル: RunTrace.cpp プロジェクト: davidswelt/XCSoar
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  Trace trace;

  while (replay->Next()) {
    const AircraftState state =
      ToAircraftState(replay->Basic(), replay->Calculated());
    trace.append(state);
  }

  delete replay;
}
コード例 #10
0
ファイル: Flight.cpp プロジェクト: CnZoom/XcSoarWork
void Flight::ReadFlight() {
  fixes = new std::vector<IGCFixEnhanced>;

  DebugReplay *replay = DebugReplayIGC::Create(flight_file);

  if (replay) {
    if (qnh_available)
      replay->SetQNH(qnh);

    while (replay->Next()) {
      IGCFixEnhanced fix;
      fix.Clear();
      if (fix.Apply(replay->Basic(), replay->Calculated())) {
        fixes->push_back(fix);
      }
    }

    delete replay;
  }
}
コード例 #11
0
ファイル: RunTrace.cpp プロジェクト: Adrien81/XCSoar
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  Trace trace;

  while (replay->Next()) {
    const MoreData &basic = replay->Basic();
    if (basic.time_available && basic.location_available &&
        basic.NavAltitudeAvailable())
      trace.push_back(TracePoint(basic));
  }

  delete replay;
}
コード例 #12
0
ファイル: AnalyseFlight.cpp プロジェクト: MindMil/XCSoar
static void
ComputeCircling(DebugReplay &replay, const CirclingSettings &circling_settings)
{
  circling_computer.TurnRate(replay.SetCalculated(),
                             replay.Basic(),
                             replay.Calculated().flight);
  circling_computer.Turning(replay.SetCalculated(),
                            replay.Basic(),
                            replay.Calculated().flight,
                            circling_settings);
}
コード例 #13
0
ファイル: RunWindEKF.cpp プロジェクト: Advi42/XCSoar
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  printf("# time wind_bearing (deg) wind_speed (m/s) grndspeed (m/s) tas (m/s) bearing (deg)\n");

  CirclingSettings circling_settings;
  circling_settings.SetDefaults();

  CirclingComputer circling_computer;
  circling_computer.Reset();

  WindEKFGlue wind_ekf;
  wind_ekf.Reset();

  while (replay->Next()) {
    const MoreData &data = replay->Basic();
    const DerivedInfo &calculated = replay->Calculated();

    circling_computer.TurnRate(replay->SetCalculated(),
                               data, calculated.flight);

    WindEKFGlue::Result result =
      wind_ekf.Update(data, replay->Calculated());
    if (result.quality > 0) {
      TCHAR time_buffer[32];
      FormatTime(time_buffer, data.time);

      _tprintf(_T("%s %d %g %g %g %d\n"), time_buffer,
               (int)result.wind.bearing.Degrees(),
               (double)result.wind.norm,
               (double)data.ground_speed,
               (double)data.true_airspeed,
               (int)data.track.Degrees());
    }
  }

  delete replay;
}
コード例 #14
0
ファイル: RunTask.cpp プロジェクト: Advi42/XCSoar
static void
Run(DebugReplay &replay, OrderedTask &task, const GlidePolar &glide_polar)
{
  Validity last_location_available;
  last_location_available.Clear();

  AircraftState last_as;
  bool last_as_valid = false;
  bool task_finished = false;

  unsigned active_taskpoint_index(-1);

  char time_buffer[32];

  while (replay.Next()) {
    const MoreData &basic = replay.Basic();
    const DerivedInfo &calculated = replay.Calculated();

    if (!basic.location_available) {
      last_location_available.Clear();
      continue;
    }

    const AircraftState current_as = ToAircraftState(basic, calculated);

    if (!last_location_available) {
      last_as = current_as;
      last_as_valid = true;
      last_location_available = basic.location_available;
      continue;
    }

    if (!basic.location_available.Modified(last_location_available))
      continue;

    if (!last_as_valid) {
      last_as = current_as;
      last_as_valid = true;
      last_location_available = basic.location_available;
      continue;
    }

    task.Update(current_as, last_as, glide_polar);
    task.UpdateIdle(current_as, glide_polar);
    task.SetTaskAdvance().SetArmed(true);

    if (task.GetActiveIndex() != active_taskpoint_index) {
      active_taskpoint_index = task.GetActiveIndex();

      FormatISO8601(time_buffer, basic.date_time_utc);
      printf("%s active_taskpoint_index=%u\n",
             time_buffer, active_taskpoint_index);
    }

    const TaskStats &task_stats = task.GetStats();
    if (task_finished != task_stats.task_finished) {
      task_finished = true;
      FormatISO8601(time_buffer, basic.date_time_utc);
      printf("%s task finished\n", time_buffer);
    }

    last_as = current_as;
    last_as_valid = true;
  }

  const TaskStats &task_stats = task.GetStats();

  printf("task_started=%d task_finished=%d\n",
         task_stats.start.task_started,
         task_stats.task_finished);

  printf("task elapsed %ds\n", (int)task_stats.total.time_elapsed);
  printf("task speed %1.2f kph\n",
         double(task_stats.total.travelled.GetSpeed() * 3.6));
  printf("travelled distance %1.3f km\n",
         double(task_stats.total.travelled.GetDistance() / 1000));
  printf("scored distance %1.3f km\n",
         double(task_stats.distance_scored / 1000));
  if (task_stats.total.time_elapsed > 0)
    printf("scored speed %1.2f kph\n",
           double(task_stats.distance_scored
                  / task_stats.total.time_elapsed * 3.6));
}
コード例 #15
0
static bool
TestTracking(int argc, char *argv[])
{
  Args args(argc, argv, "[DRIVER] FILE [USERNAME [PASSWORD]]");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return false;

  bool has_user_id;
  UserID user_id;
  tstring username, password;
  if (args.IsEmpty()) {
    username = _T("");
    password = _T("");
    has_user_id = false;
  } else {
    username = args.ExpectNextT();
    password = args.IsEmpty() ? _T("") : args.ExpectNextT();

    user_id = LiveTrack24::GetUserID(username.c_str(), password.c_str());
    has_user_id = (user_id != 0);
  }

  SessionID session = has_user_id ?
                      GenerateSessionID(user_id) : GenerateSessionID();
  printf("Generated session id: %u\n", session);


  printf("Starting tracking ... ");
  bool result = StartTracking(session, username.c_str(), password.c_str(), 10,
                              VehicleType::GLIDER, _T("Hornet"));
  printf(result ? "done\n" : "failed\n");
  if (!result)
    return false;

  BrokenDate now = BrokenDateTime::NowUTC();

  printf("Sending positions ");
  unsigned package_id = 2;
  while (replay->Next()) {
    if (package_id % 10 == 0) {
      putchar('.');
      fflush(stdout);
    }
    const MoreData &basic = replay->Basic();

    const BrokenTime time = basic.date_time_utc;
    BrokenDateTime datetime(now.year, now.month, now.day, time.hour,
                            time.minute, time.second);

    result = SendPosition(
        session, package_id, basic.location, (unsigned)basic.nav_altitude,
        (unsigned)Units::ToUserUnit(basic.ground_speed, unKiloMeterPerHour),
        basic.track, datetime.ToUnixTimeUTC());

    if (!result)
      break;

    package_id++;
  }
  printf(result ? "done\n" : "failed\n");

  printf("Stopping tracking ... ");
  result = EndTracking(session, package_id);
  printf(result ? "done\n" : "failed\n");

  return true;
}
コード例 #16
0
ファイル: AnalyseFlight.cpp プロジェクト: ahsparrow/xcsoar
void
Run(DebugReplay &replay, FlightPhaseDetector &flight_phase_detector,
    WindList &wind_list,
    const BrokenDateTime &takeoff_time,
    const BrokenDateTime &scoring_start_time,
    const BrokenDateTime &scoring_end_time,
    const BrokenDateTime &landing_time,
    Trace &full_trace, Trace &triangle_trace, Trace &sprint_trace,
    ComputerSettings &computer_settings)
{
    GeoPoint last_location = GeoPoint::Invalid();
    constexpr Angle max_longitude_change = Angle::Degrees(30);
    constexpr Angle max_latitude_change = Angle::Degrees(1);

    CirclingSettings circling_settings;
    circling_settings.SetDefaults();
    CirclingComputer circling_computer;
    circling_computer.Reset();

    GlidePolar glide_polar(0);

    WindSettings wind_settings;
    wind_settings.SetDefaults();

    WindComputer wind_computer;
    wind_computer.Reset();

    Validity last_wind;
    last_wind.Clear();

    const Waypoints waypoints;
    AutoQNH auto_qnh(5);
    auto_qnh.Reset();

    const int64_t takeoff_unix = takeoff_time.ToUnixTimeUTC();
    const int64_t landing_unix = landing_time.ToUnixTimeUTC();


    int64_t scoring_start_unix, scoring_end_unix;

    if (scoring_start_time.IsPlausible())
        scoring_start_unix = scoring_start_time.ToUnixTimeUTC();
    else
        scoring_start_unix = std::numeric_limits<int64_t>::max();

    if (scoring_end_time.IsPlausible())
        scoring_end_unix = scoring_end_time.ToUnixTimeUTC();
    else
        scoring_end_unix = 0;


    while (replay.Next()) {
        const MoreData &basic = replay.Basic();
        const int64_t date_time_utc = basic.date_time_utc.ToUnixTimeUTC();

        if (date_time_utc < takeoff_unix)
            continue;

        if (date_time_utc > landing_unix)
            break;

        circling_computer.TurnRate(replay.SetCalculated(),
                                   replay.Basic(),
                                   replay.Calculated().flight);
        circling_computer.Turning(replay.SetCalculated(),
                                  replay.Basic(),
                                  replay.Calculated().flight,
                                  circling_settings);

        flight_phase_detector.Update(replay.Basic(), replay.Calculated());

        wind_computer.Compute(wind_settings, glide_polar, basic,
                              replay.SetCalculated());

        if (replay.Calculated().estimated_wind_available.Modified(last_wind)) {
            wind_list.push_back(WindListItem(basic.date_time_utc, basic.gps_altitude,
                                             replay.Calculated().estimated_wind));
        }

        last_wind = replay.Calculated().estimated_wind_available;

        auto_qnh.Process(basic, replay.SetCalculated(), computer_settings, waypoints);

        if (!computer_settings.pressure_available && replay.Calculated().pressure_available) {
            computer_settings.pressure = replay.Calculated().pressure;
            computer_settings.pressure_available = replay.Calculated().pressure_available;
        }

        if (!basic.time_available || !basic.location_available ||
                !basic.NavAltitudeAvailable())
            continue;

        if (last_location.IsValid() &&
                ((last_location.latitude - basic.location.latitude).Absolute() > max_latitude_change ||
                 (last_location.longitude - basic.location.longitude).Absolute() > max_longitude_change))
            /* there was an implausible warp, which is usually triggered by
               an invalid point declared "valid" by a bugged logger; if that
               happens, we stop the analysis, because the IGC file is
               obviously broken */
            break;

        last_location = basic.location;

        if (date_time_utc >= scoring_start_unix && date_time_utc <= scoring_end_unix) {
            const TracePoint point(basic);
            full_trace.push_back(point);
            triangle_trace.push_back(point);
            sprint_trace.push_back(point);
        }
    }

    flight_phase_detector.Finish();
}
コード例 #17
0
ファイル: FlightPath.cpp プロジェクト: CnZoom/XcSoarPull
int main(int argc, char **argv)
{
  int start = -1, end = -1;
  unsigned max_points = 1000;

  Args args(argc, argv,
            "[options] DRIVER FILE\n"
            "Options:\n"
            "  --start=5000             Begin flight path at 5000 sec after UTC midnight,\n"
            "                           if not defined takeoff time is used\n"
            "  --end=15000              End flight path at 15000 sec after UTC midnight,\n"
            "                           if not defined the last timestamp in the file is used\n"
            "  --max-points=1000        Maximum number of trace points in output (default = 1000)");

  const char *arg;
  while ((arg = args.PeekNext()) != nullptr && *arg == '-') {
    args.Skip();

    const char *value;
    if ((value = StringAfterPrefix(arg, "--max-points=")) != nullptr) {
      unsigned _max_points = strtol(value, NULL, 10);
      if (_max_points > 0)
        max_points = _max_points;
    } else if ((value = StringAfterPrefix(arg, "--start=")) != nullptr) {
      char *endptr;
      start = strtol(value, &endptr, 10);
      if (endptr == value || *endptr != '\0' || start < 0) {
        fputs("The start parameter could not be parsed correctly.\n", stderr);
        args.UsageError();
      }
    } else if ((value = StringAfterPrefix(arg, "--end=")) != nullptr) {
      char *endptr;
      end = strtol(value, &endptr, 10);
      if (endptr == value || *endptr != '\0' || end < 0) {
        fputs("The end parameter could not be parsed correctly.\n", stderr);
        args.UsageError();
      }
    } else {
      args.UsageError();
    }
  }

  if (start >= 0 && end >= 0 && start >= end) {
    fputs("The start parameter has to be smaller than the end parameter.\n", stderr);
    args.UsageError();
  }

  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == nullptr)
    return EXIT_FAILURE;

  args.ExpectEnd();

  Trace trace(0, Trace::null_time, max_points);

  bool takeoff = false;

  while (replay->Next()) {
    const MoreData &basic = replay->Basic();
    const DerivedInfo &calculated = replay->Calculated();

    if (!basic.time_available || !basic.location_available ||
        !basic.NavAltitudeAvailable())
      continue;

    if (start >= 0 && (int)basic.time < start)
      continue;

    if (end >= 0 && (int)basic.time > end)
      break;

    trace.push_back(TracePoint(basic));

    if (start < 0 && calculated.flight.flying && !takeoff) {
      takeoff = true;
      trace.EraseEarlierThan(calculated.flight.takeoff_time);
    }
  }

  delete replay;

  for (auto i = trace.begin(), end = trace.end(); i != end; ++i) {
    const TracePoint &point = *i;
    printf("%u %f %f %d %u\n",
           point.GetTime(),
           (double)point.GetLocation().latitude.Degrees(),
           (double)point.GetLocation().longitude.Degrees(),
           point.GetIntegerAltitude(),
           point.GetEngineNoiseLevel());
  }
}
コード例 #18
0
ファイル: AnalyseFlight.cpp プロジェクト: MindMil/XCSoar
static void
Run(DebugReplay &replay, Result &result,
    Trace &full_trace, Trace &triangle_trace, Trace &sprint_trace)
{
  CirclingSettings circling_settings;
  circling_settings.SetDefaults();

  bool released = false;

  GeoPoint last_location = GeoPoint::Invalid();
  constexpr Angle max_longitude_change = Angle::Degrees(30);
  constexpr Angle max_latitude_change = Angle::Degrees(1);

  while (replay.Next()) {
    ComputeCircling(replay, circling_settings);

    const MoreData &basic = replay.Basic();

    Update(basic, replay.Calculated(), result);
    flight_phase_detector.Update(replay.Basic(), replay.Calculated());

    if (!basic.time_available || !basic.location_available ||
        !basic.NavAltitudeAvailable())
      continue;

    if (last_location.IsValid() &&
        ((last_location.latitude - basic.location.latitude).Absolute() > max_latitude_change ||
         (last_location.longitude - basic.location.longitude).Absolute() > max_longitude_change))
      /* there was an implausible warp, which is usually triggered by
         an invalid point declared "valid" by a bugged logger; if that
         happens, we stop the analysis, because the IGC file is
         obviously broken */
      break;

    last_location = basic.location;

    if (!released && !negative(replay.Calculated().flight.release_time)) {
      released = true;

      full_trace.EraseEarlierThan(replay.Calculated().flight.release_time);
      triangle_trace.EraseEarlierThan(replay.Calculated().flight.release_time);
      sprint_trace.EraseEarlierThan(replay.Calculated().flight.release_time);
    }

    if (released && !replay.Calculated().flight.flying)
      /* the aircraft has landed, stop here */
      /* TODO: at some point, we might want to emit the analysis of
         all flights in this IGC file */
      break;

    const TracePoint point(basic);
    full_trace.push_back(point);
    triangle_trace.push_back(point);
    sprint_trace.push_back(point);
  }

  Update(replay.Basic(), replay.Calculated(), result);
  Finish(replay.Basic(), replay.Calculated(), result);
  flight_phase_detector.Finish();
}
コード例 #19
0
ファイル: Airspaces.cpp プロジェクト: CnZoom/XcSoarWork
PyObject* xcsoar_Airspaces_findIntrusions(Pyxcsoar_Airspaces *self, PyObject *args) {
  PyObject *py_flight = nullptr;

  if (!PyArg_ParseTuple(args, "O", &py_flight)) {
    PyErr_SetString(PyExc_AttributeError, "Can't parse argument.");
    return nullptr;
  }

  DebugReplay *replay = ((Pyxcsoar_Flight*)py_flight)->flight->Replay();

  if (replay == nullptr) {
    PyErr_SetString(PyExc_IOError, "Can't start replay - file not found.");
    return nullptr;
  }

  PyObject *py_result = PyDict_New();
  Airspaces::AirspaceVector last_airspaces;

  while (replay->Next()) {
    const MoreData &basic = replay->Basic();

    if (!basic.time_available || !basic.location_available ||
        !basic.NavAltitudeAvailable())
      continue;

    Airspaces::AirspaceVector airspaces = self->airspace_database->FindInside(
      ToAircraftState(basic, replay->Calculated())
    );

    for (auto it = airspaces.begin(); it != airspaces.end(); it++) {
      PyObject *py_name = PyString_FromString((*it).GetAirspace().GetName());
      PyObject *py_airspace = nullptr,
               *py_period = nullptr;

      if (PyDict_Contains(py_result, py_name) == 0) {
        // this is the first fix inside this airspace
        py_airspace = PyList_New(0);
        PyDict_SetItem(py_result, py_name, py_airspace);

        py_period = PyList_New(0);
        PyList_Append(py_airspace, py_period);
        Py_DECREF(py_period);

      } else {
        // this airspace was hit some time before...
        py_airspace = PyDict_GetItem(py_result, py_name);

        // check if the last fix was already inside this airspace
        auto in_last = std::find(last_airspaces.begin(), last_airspaces.end(), *it);

        if (in_last == last_airspaces.end()) {
          // create a new period
          py_period = PyList_New(0);
          PyList_Append(py_airspace, py_period);
          Py_DECREF(py_period);
        } else {
          py_period = PyList_GET_ITEM(py_airspace, PyList_GET_SIZE(py_airspace) - 1);
        }
      }

      PyList_Append(py_period, Py_BuildValue("{s:N,s:N}",
        "time", Python::BrokenDateTimeToPy(basic.date_time_utc),
        "location", Python::WriteLonLat(basic.location)));
    }

    last_airspaces.swap(airspaces);
  }

  delete replay;

  return py_result;
}
コード例 #20
0
ファイル: FlightTimes.cpp プロジェクト: Adrien81/XCSoar
bool
Run(DebugReplay &replay, FlightTimeResult &result)
{
  bool released = false;
  bool powered = false;

  GeoPoint last_location = GeoPoint::Invalid();
  constexpr Angle max_longitude_change = Angle::Degrees(30);
  constexpr Angle max_latitude_change = Angle::Degrees(1);

  replay.SetCalculated().Reset();
  replay.SetFlyingComputer().Reset();

  while (replay.Next()) {
    const MoreData &basic = replay.Basic();

    Update(basic, replay.Calculated(), result);

    if (!basic.time_available || !basic.location_available ||
        !basic.NavAltitudeAvailable())
      continue;

    if (last_location.IsValid() &&
        ((last_location.latitude - basic.location.latitude).Absolute() > max_latitude_change ||
         (last_location.longitude - basic.location.longitude).Absolute() > max_longitude_change))
      /* there was an implausible warp, which is usually triggered by
         an invalid point declared "valid" by a bugged logger; if that
         happens, we stop the analysis, because the IGC file is
         obviously broken */
      break;

    last_location = basic.location;

    if (!released && !negative(replay.Calculated().flight.release_time)) {
      released = true;
    }

    if (replay.Calculated().flight.powered != powered) {
      powered = replay.Calculated().flight.powered;
      PowerState power_state;

      if (powered) {
        power_state.time = basic.GetDateTimeAt(replay.Calculated().flight.power_on_time);
        power_state.location = replay.Calculated().flight.power_on_location;
        power_state.state = PowerState::ON;
      } else {
        power_state.time = basic.GetDateTimeAt(replay.Calculated().flight.power_off_time);
        power_state.location = replay.Calculated().flight.power_off_location;
        power_state.state = PowerState::OFF;
      }

      result.power_states.push_back(power_state);
    }

    if (released && !replay.Calculated().flight.flying)
      /* the aircraft has landed, stop here */
      /* TODO: at some point, we might want to emit the analysis of
         all flights in this IGC file */
      break;
  }

  Update(replay.Basic(), replay.Calculated(), result);
  Finish(replay.Basic(), replay.Calculated(), result);

  // landing detected or eof?
  if (replay.Tell() != replay.Size())
    return false;
  else
    return true;
}
コード例 #21
0
ファイル: RunOLCAnalysis.cpp プロジェクト: CnZoom/XcSoarPull
static int
TestOLC(DebugReplay &replay)
{
  bool released = false;

  for (int i = 1; replay.Next(); i++) {
    if (i % 500 == 0) {
      putchar('.');
      fflush(stdout);
    }

    const MoreData &basic = replay.Basic();
    if (!basic.time_available || !basic.location_available ||
        !basic.NavAltitudeAvailable())
      continue;

    if (!released && !negative(replay.Calculated().flight.release_time)) {
      released = true;

      triangle_trace.EraseEarlierThan(replay.Calculated().flight.release_time);
      full_trace.EraseEarlierThan(replay.Calculated().flight.release_time);
      sprint_trace.EraseEarlierThan(replay.Calculated().flight.release_time);
    }

    const TracePoint point(basic);
    triangle_trace.push_back(point);
    full_trace.push_back(point);
    sprint_trace.push_back(point);

    olc_sprint.UpdateIdle();
    olc_league.UpdateIdle();
  }

  olc_classic.SolveExhaustive();
  olc_fai.SolveExhaustive();
  olc_league.SolveExhaustive();
  olc_plus.SolveExhaustive();
  dmst.SolveExhaustive();
  xcontest.SolveExhaustive();
  sis_at.SolveExhaustive();
  olc_netcoupe.SolveExhaustive();

  putchar('\n');

  std::cout << "classic\n";
  PrintHelper::print(olc_classic.GetStats().GetResult());
  std::cout << "league\n";
  std::cout << "# league\n";
  PrintHelper::print(olc_league.GetStats().GetResult(0));
  std::cout << "# classic\n";
  PrintHelper::print(olc_league.GetStats().GetResult(1));
  std::cout << "fai\n";
  PrintHelper::print(olc_fai.GetStats().GetResult());
  std::cout << "sprint\n";
  PrintHelper::print(olc_sprint.GetStats().GetResult());
  std::cout << "plus\n";
  std::cout << "# classic\n";
  PrintHelper::print(olc_plus.GetStats().GetResult(0));
  std::cout << "# triangle\n";
  PrintHelper::print(olc_plus.GetStats().GetResult(1));
  std::cout << "# plus\n";
  PrintHelper::print(olc_plus.GetStats().GetResult(2));

  std::cout << "dmst\n";
  PrintHelper::print(dmst.GetStats().GetResult());

  std::cout << "xcontest\n";
  std::cout << "# free\n";
  PrintHelper::print(xcontest.GetStats().GetResult(0));
  std::cout << "# triangle\n";
  PrintHelper::print(xcontest.GetStats().GetResult(1));

  std::cout << "sis_at\n";
  PrintHelper::print(sis_at.GetStats().GetResult(0));

  std::cout << "netcoupe\n";
  PrintHelper::print(olc_netcoupe.GetStats().GetResult());

  olc_classic.Reset();
  olc_fai.Reset();
  olc_sprint.Reset();
  olc_league.Reset();
  olc_plus.Reset();
  dmst.Reset();
  olc_netcoupe.Reset();
  full_trace.clear();
  sprint_trace.clear();

  return 0;
}
コード例 #22
0
int
main(int argc, char *argv[])
{
  Args args(argc, argv, "HOST KEY");
  const char *host = args.ExpectNext();
  const char *key = args.ExpectNext();

  SocketAddress address;
  if (!address.Lookup(host, "5597", SOCK_DGRAM)) {
    fprintf(stderr, "Failed to look up: %s\n", host);
    return EXIT_FAILURE;
  }

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
  InitialiseIOThread();
#endif

  SkyLinesTracking::Client client;

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
  client.SetIOThread(io_thread);

  Handler handler;
  client.SetHandler(&handler);
#endif

  client.SetKey(ParseUint64(key, NULL, 16));
  if (!client.Open(address)) {
    fprintf(stderr, "Failed to create client\n");
    return EXIT_FAILURE;
  }

  if (args.IsEmpty() || StringIsEqual(args.PeekNext(), "fix")) {
    NMEAInfo basic;
    basic.Reset();
    basic.UpdateClock();
    basic.time = fixed(1);
    basic.time_available.Update(basic.clock);

    return client.SendFix(basic) ? EXIT_SUCCESS : EXIT_FAILURE;
  } else if (StringIsEqual(args.PeekNext(), "ping")) {
    client.SendPing(1);

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
    handler.Wait();
#endif
  } else if (StringIsEqual(args.PeekNext(), "traffic")) {
    client.SendTrafficRequest(true, true);

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
    handler.Wait();
#endif
  } else {
    DebugReplay *replay = CreateDebugReplay(args);
    if (replay == NULL)
      return EXIT_FAILURE;

    while (replay->Next()) {
      client.SendFix(replay->Basic());
      usleep(100000);
    }
  }

#ifdef HAVE_SKYLINES_TRACKING_HANDLER
  client.Close();
  DeinitialiseIOThread();
#endif

  return EXIT_SUCCESS;
}
コード例 #23
0
ファイル: RunCirclingWind.cpp プロジェクト: macsux/XCSoar
int main(int argc, char **argv)
{
  Args args(argc, argv, "DRIVER FILE");
  DebugReplay *replay = CreateDebugReplay(args);
  if (replay == NULL)
    return EXIT_FAILURE;

  args.ExpectEnd();

  printf("# time quality wind_bearing (deg) wind_speed (m/s)\n");

  CirclingComputer circling_computer;
  CirclingWind circling_wind;

  while (replay->Next()) {
    circling_computer.TurnRate(replay->SetCalculated(),
                               replay->Basic(), replay->LastBasic(),
                               replay->Calculated(), replay->LastCalculated());
    circling_computer.Turning(replay->SetCalculated(),
                              replay->Basic(), replay->LastBasic(),
                              replay->Calculated(), replay->LastCalculated(),
                              replay->SettingsComputer());

    if ((replay->LastCalculated().turn_mode == WAITCLIMB &&
         replay->Calculated().turn_mode == CLIMB) ||
        (replay->LastCalculated().turn_mode == WAITCRUISE &&
         replay->Calculated().turn_mode == CRUISE))
      circling_wind.slot_newFlightMode(replay->Calculated(),
                                       negative(replay->Calculated().turn_rate_smoothed),
                                       0);

    CirclingWind::Result result = circling_wind.NewSample(replay->Basic());
    if (result.quality > 0) {
      fixed mag = hypot(result.wind.x, result.wind.y);

      Angle bearing;
      if (result.wind.y == fixed_zero && result.wind.x == fixed_zero)
        bearing = Angle::zero();
      else
        bearing = Angle::radians(atan2(result.wind.y, result.wind.x)).as_bearing();

      printf("%d %d %d %g\n",
             (int)replay->Basic().time,
             result.quality, (int)bearing.value_degrees(), (double)mag);
    }
  }

  delete replay;
}