Exemplo n.º 1
0
void
IGCFileVisitor::Visit(Path path, Path filename)
{
  Error error;
  FileLineReaderA reader(path, error);
  if (reader.error()) {
    fprintf(stderr, "%s\n", error.GetMessage());
    return;
  }

  IGCExtensions extensions;
  extensions.clear();

  FlightCheck flight(filename.c_str());
  char *line;
  while ((line = reader.ReadLine()) != NULL) {
    unsigned day, month, year;

    IGCFix fix;
    if (IGCParseFix(line, extensions, fix))
      flight.fix(fix);
    else if (sscanf(line, "HFDTE%02u%02u%02u", &day, &month, &year)) {
      /* damn you, Y2K bug! */
      if (year > 80)
        year += 1900;
      else
        year += 2000;

      flight.date(year, month, day);
    }
  }

  flight.finish();
}
Exemplo n.º 2
0
void
IGCFileVisitor::Visit(const TCHAR *path, const TCHAR *filename)
{
  FileLineReaderA reader(path);
  if (reader.error()) {
    _ftprintf(stderr, _T("Failed to open %s\n"), path);
    return;
  }

  IGCExtensions extensions;
  extensions.clear();

  FlightCheck flight(filename);
  char *line;
  while ((line = reader.ReadLine()) != NULL) {
    unsigned day, month, year;

    IGCFix fix;
    if (IGCParseFix(line, extensions, fix))
      flight.fix(fix);
    else if (sscanf(line, "HFDTE%02u%02u%02u", &day, &month, &year)) {
      /* damn you, Y2K bug! */
      if (year > 80)
        year += 1900;
      else
        year += 2000;

      flight.date(year, month, day);
    }
  }

  flight.finish();
}
Exemplo n.º 3
0
static bool
TestTrace(Path filename, unsigned ntrace, bool output=false)
{
  FileLineReaderA reader(filename);

  printf("# %d", ntrace);  
  Trace trace(1000, ntrace);

  IGCExtensions extensions;
  extensions.clear();

  char *line;
  int i = 0;
  for (; (line = reader.ReadLine()) != NULL; i++) {
    if (output && (i % 500 == 0)) {
      putchar('.');
      fflush(stdout);
    }

    IGCFix fix;
    if (!IGCParseFix(line, extensions, fix) || !fix.gps_valid)
      continue;

    OnAdvance(trace,
               fix.location,
               fix.gps_altitude,
               fix.time.GetSecondOfDay());
  }
  putchar('\n');
  printf("# samples %d\n", i);
  return true;
}
Exemplo n.º 4
0
static void
TestFix()
{
  IGCExtensions extensions;
  extensions.clear();

  IGCFix fix;
  ok1(!IGCParseFix("", extensions, fix));
  ok1(!IGCParseFix("B1122385103117N00742367EA", extensions, fix));

  ok1(!IGCParseFix("B1122385103117X00742367EA0049000487", extensions, fix));
  ok1(!IGCParseFix("B1122385103117N00742367XA0049000487", extensions, fix));
  ok1(!IGCParseFix("B1122389003117N00742367EA0049000487", extensions, fix));
  ok1(!IGCParseFix("B1122385103117N18042367EA0049000487", extensions, fix));
  ok1(!IGCParseFix("B1122385163117N00742367EA0049000487", extensions, fix));
  ok1(!IGCParseFix("B1122385103117N00762367EA0049000487", extensions, fix));

  ok1(IGCParseFix("B1122385103117N00742367EA0049000487", extensions, fix));
  ok1(fix.time == BrokenTime(11, 22, 38));
  ok1(equals(fix.location, 51.05195, 7.70611667));
  ok1(fix.gps_valid);
  ok1(fix.pressure_altitude == 490);
  ok1(fix.gps_altitude == 487);

  ok1(IGCParseFix("B1122385103117N00742367EV0049000487", extensions, fix));
  ok1(fix.time == BrokenTime(11, 22, 38));
  ok1(equals(fix.location, 51.05195, 7.70611667));
  ok1(!fix.gps_valid);
  ok1(fix.pressure_altitude == 490);
  ok1(fix.gps_altitude == 487);

  ok1(!IGCParseFix("B1122385103117N00742367EX0049000487", extensions, fix));

  ok1(IGCParseFix("B1122435103117N00742367EA004900000000000",
                  extensions, fix));
  ok1(fix.time == BrokenTime(11, 22, 43));
  ok1(fix.gps_valid);
  ok1(fix.pressure_altitude == 490);
  ok1(fix.gps_altitude == 0);

  ok1(IGCParseFix("B1122535103117S00742367WA104900000700000",
                  extensions, fix));
  ok1(fix.time == BrokenTime(11, 22, 53));
  ok1(fix.gps_valid);
  ok1(equals(fix.location, -51.05195, -7.70611667));
  ok1(fix.pressure_altitude == 10490);
  ok1(fix.gps_altitude == 7);
}
Exemplo n.º 5
0
bool
IGCParseExtensions(const char *buffer, IGCExtensions &extensions)
{
  if (*buffer++ != 'I')
    return false;

  int count = ParseTwoDigits(buffer);
  if (count < 0)
    return false;

  buffer += 2;

  extensions.clear();

  while (count-- > 0) {
    const int start = ParseTwoDigits(buffer);
    if (start < 8)
      return false;

    buffer += 2;

    const int finish = ParseTwoDigits(buffer);
    if (finish < start)
      return false;

    buffer += 2;

    if (!CheckThreeAlphaNumeric(buffer))
      return false;

    IGCExtension &x = extensions.append();
    x.start = start;
    x.finish = finish;
    memcpy(x.code, buffer, 3);
    x.code[3] = 0;

    buffer += 3;
  }

  return true;
}
Exemplo n.º 6
0
static void
TestExtensions()
{
  IGCExtensions extensions;
  ok1(!IGCParseExtensions("", extensions));
  ok1(!IGCParseExtensions("B1122385103117N00742367EA004900048700000", extensions));
  ok1(!IGCParseExtensions("AXYZAA", extensions));

  ok1(IGCParseExtensions("I043638FXA3941ENL4246GSP4749TRT", extensions));
  ok1(extensions.size() == 4);
  ok1(extensions[0].start == 36);
  ok1(extensions[0].finish == 38);
  ok1(strcmp(extensions[0].code, "FXA") == 0);
  ok1(extensions[1].start == 39);
  ok1(extensions[1].finish == 41);
  ok1(strcmp(extensions[1].code, "ENL") == 0);
  ok1(extensions[2].start == 42);
  ok1(extensions[2].finish == 46);
  ok1(strcmp(extensions[2].code, "GSP") == 0);
  ok1(extensions[3].start == 47);
  ok1(extensions[3].finish == 49);
  ok1(strcmp(extensions[3].code, "TRT") == 0);
}
Exemplo n.º 7
0
bool
IGCParseFix(const char *buffer, const IGCExtensions &extensions, IGCFix &fix)
{
  if (*buffer != 'B')
    return false;

  BrokenTime time;
  if (!IGCParseTime(buffer + 1, time))
    return false;

  char valid_char;
  int gps_altitude, pressure_altitude;

  if (sscanf(buffer + 24, "%c%05d%05d",
             &valid_char, &pressure_altitude, &gps_altitude) != 3)
    return false;

  if (valid_char == 'A')
    fix.gps_valid = true;
  else if (valid_char == 'V')
    fix.gps_valid = false;
  else
    return false;

  fix.gps_altitude = gps_altitude;
  fix.pressure_altitude = pressure_altitude;

  if (!IGCParseLocation(buffer + 7, fix.location))
    return false;

  fix.time = time;

  fix.ClearExtensions();

  const size_t line_length = strlen(buffer);
  for (auto i = extensions.begin(), end = extensions.end(); i != end; ++i) {
    const IGCExtension &extension = *i;
    assert(extension.start > 0);
    assert(extension.finish >= extension.start);

    if (extension.finish > line_length)
      /* exceeds the input line length */
      continue;

    const char *start = buffer + extension.start - 1;
    const char *finish = buffer + extension.finish;

    if (StringIsEqual(extension.code, "ENL"))
      ParseExtensionValue(start, finish, fix.enl);
    else if (StringIsEqual(extension.code, "RPM"))
      ParseExtensionValue(start, finish, fix.rpm);
    else if (StringIsEqual(extension.code, "HDM"))
      ParseExtensionValue(start, finish, fix.hdm);
    else if (StringIsEqual(extension.code, "HDT"))
      ParseExtensionValue(start, finish, fix.hdt);
    else if (StringIsEqual(extension.code, "TRM"))
      ParseExtensionValue(start, finish, fix.trm);
    else if (StringIsEqual(extension.code, "TRT"))
      ParseExtensionValue(start, finish, fix.trt);
    else if (StringIsEqual(extension.code, "GSP"))
      ParseExtensionValueN(start, finish, 3, fix.gsp);
    else if (StringIsEqual(extension.code, "IAS"))
      ParseExtensionValueN(start, finish, 3, fix.ias);
    else if (StringIsEqual(extension.code, "TAS"))
      ParseExtensionValueN(start, finish, 3, fix.tas);
    else if (StringIsEqual(extension.code, "SIU"))
      ParseExtensionValue(start, finish, fix.siu);
  }

  return true;
}
Exemplo n.º 8
0
 DebugReplayIGC(FileLineReaderA *_reader)
   : DebugReplayFile(_reader) {
   extensions.clear();
 }
Exemplo n.º 9
0
 DebugReplayIGC(NLineReader *reader)
   :DebugReplay(reader), day(0) {
   extensions.clear();
 }