Beispiel #1
0
static void
CheckGRecord(const TCHAR *path)
{
  GRecord grecord;
  grecord.Initialize();
  ok1(grecord.VerifyGRecordInFile(Path(path), IgnoreError()));
}
Beispiel #2
0
int
main(int argc, char **argv)
{
  Args args(argc, argv, "FILE.igc");
  const auto path = args.ExpectNextPath();
  args.ExpectEnd();

  GRecord g;
  g.Initialize();

  Error error;
  if (!g.LoadFileToBuffer(path, error)) {
    fprintf(stderr, "%s\n", error.GetMessage());
    return 2;
  }

  g.FinalizeBuffer();

  if (!g.AppendGRecordToFile(path)) {
    fprintf(stderr, "Failed to write file\n");
    return 2;
  }

  return 0;
}
Beispiel #3
0
int
main(int argc, char **argv)
{
  if (argc != 2) {
    fprintf(stderr, "Usage: %s FILE.igc\n", argv[0]);
    return 1;
  }

#ifdef _UNICODE
  TCHAR path[PATH_MAX];
  int length = ::MultiByteToWideChar(CP_ACP, 0, argv[1], -1, path, PATH_MAX);
  if (length == 0)
    return 2;
#else
  const char *path = argv[1];
#endif

  GRecord g;
  g.Init();
  g.SetFileName(path);

  char data[1024];
  if (!g.ReadGRecordFromFile(data, ARRAY_SIZE(data))) {
    fprintf(stderr, "Error\n");
    return 2;
  }

  puts(data);
  return 0;
}
Beispiel #4
0
int main(int argc, char **argv)
{
  const TCHAR *path = _T("output/test/test.igc");
  File::Delete(path);

  static const GeoPoint home(Angle::degrees(fixed(7.7061111111111114)),
                             Angle::degrees(fixed(51.051944444444445)));
  static const GeoPoint tp(Angle::degrees(fixed(10.726111111111111)),
                           Angle::degrees(fixed(50.632222222222225)));

  static NMEA_INFO i;
  i.DateTime.year = 2010;
  i.DateTime.month = 9;
  i.DateTime.day = 4;
  i.DateTime.hour = 11;
  i.DateTime.minute = 22;
  i.DateTime.second = 33;
  i.Location = home;
  i.GPSAltitude = fixed(487);
  i.BaroAltitude = fixed(490);

  IGCWriter writer(path, i);

  writer.header(i.DateTime, _T("Pilot Name"), _T("ASK-21"), _T("D-1234"),
                _T("foo"), _T("bar"));
  writer.StartDeclaration(i.DateTime, 3);
  writer.AddDeclaration(home, _T("Bergneustadt"));
  writer.AddDeclaration(tp, _T("Suhl"));
  writer.AddDeclaration(home, _T("Bergneustadt"));
  writer.EndDeclaration();

  i.DateTime.second += 5;
  writer.LogPoint(i);
  i.DateTime.second += 5;
  writer.LogEvent(i, "my_event");
  i.DateTime.second += 5;
  writer.LoggerNote(_T("my_note"));

  i.DateTime.second += 5;
  i.Location = GeoPoint(Angle::degrees(fixed(-7.7061111111111114)),
                        Angle::degrees(fixed(-51.051944444444445)));
  writer.LogPoint(i);

  writer.finish(i);
  writer.sign();

  CheckTextFile(path, expect);

  GRecord grecord;
  grecord.Init();
  grecord.SetFileName(path);
  assert(grecord.VerifyGRecordInFile());

  return 0;
}
Beispiel #5
0
int main(int argc, char **argv)
{
  plan_tests(51);

  const TCHAR *path = _T("output/test/test.igc");
  File::Delete(path);

  Run(path);

  CheckTextFile(path, expect);

  GRecord grecord;
  grecord.Initialize();
  ok1(grecord.VerifyGRecordInFile(path));

  return exit_status();
}
Beispiel #6
0
int
main(int argc, char **argv)
try {
  Args args(argc, argv, "FILE.igc");
  const auto path = args.ExpectNextPath();
  args.ExpectEnd();

  GRecord g;
  g.Initialize();

  g.VerifyGRecordInFile(path);
  fprintf(stderr, "G record is ok\n");
  return EXIT_SUCCESS;
} catch (const std::runtime_error &e) {
  PrintException(e);
  return EXIT_FAILURE;
}
Beispiel #7
0
int
main(int argc, char **argv)
{
  Args args(argc, argv, "FILE.igc");
  tstring path = args.ExpectNextT();
  args.ExpectEnd();

  GRecord g;
  g.Initialize();

  if (g.VerifyGRecordInFile(path.c_str())) {
    fprintf(stderr, "G record is ok\n");
    return 0;
  } else {
    fprintf(stderr, "G record is NOT ok\n");
    return 2;
  }
}
Beispiel #8
0
int
main(int argc, char **argv)
{
  Args args(argc, argv, "FILE.igc");
  const auto path = args.ExpectNextPath();
  args.ExpectEnd();

  {
    GRecord grecord;
    grecord.Initialize();

    Error error;
    if (!grecord.VerifyGRecordInFile(path, error)) {
      fprintf(stderr, "%s\n", error.GetMessage());
      return EXIT_FAILURE;
    }
  }

  printf("Valid G record found\n");

  FileTransaction transaction(path);

  {
    Error error;
    FileLineReaderA reader(path, error);
    if (reader.error()) {
      fprintf(stderr, "%s\n", error.GetMessage());
      return EXIT_FAILURE;
    }

    if (!FixGRecord(reader, transaction.GetTemporaryPath())) {
      fprintf(stderr, "Failed to write output file\n");
      return EXIT_FAILURE;
    }
  }

  if (!transaction.Commit()) {
    fprintf(stderr, "Failed to commit output file\n");
    return EXIT_FAILURE;
  }

  printf("New G record written\n");
  return EXIT_SUCCESS;
}
Beispiel #9
0
static STATUS_t
ValidateXCS(const TCHAR *FileName, GRecord &oGRecord)
{
  STATUS_t eStatus = eValidationFileNotFound;

  FILE *inFile = nullptr;
  inFile = _tfopen(FileName, _T("r"));
  if (inFile == nullptr)
    return eStatus;

  fclose(inFile);

  eStatus = eValidationFailed;

  oGRecord.Initialize();
  if (oGRecord.VerifyGRecordInFile(FileName))
    eStatus = eValidationPassed;

  return eStatus;
}
Beispiel #10
0
bool GRecord::canCompare(IGCMPObject* pOther)
{
    //表能比较,记录就能比较
    bool bRet = false;
    if (pOther != nullptr)
    {
        if (pOther->type() == gotRecord)
        {
            GRecord* pOtherRecord = dynamic_cast<GRecord*>(pOther);
            if (pOtherRecord)
            {
                if (this->getTable()->canCompare(pOtherRecord->getTable()))
                {
                    bRet = true;
                }
            }
        }
    }
    return bRet;
}
Beispiel #11
0
int
main(int argc, char **argv)
{
  if (argc != 2) {
    fprintf(stderr, "Usage: %s FILE.igc\n", argv[0]);
    return 1;
  }

#ifdef _UNICODE
  TCHAR path[PATH_MAX];
  int length = ::MultiByteToWideChar(CP_ACP, 0, argv[1], -1, path, PATH_MAX);
  if (length == 0)
    return 2;
#else
  const char *path = argv[1];
#endif

  GRecord g;
  g.Init();
  g.SetFileName(path);

  if (!g.LoadFileToBuffer()) {
    fprintf(stderr, "Failed to read file\n");
    return 2;
  }

  g.FinalizeBuffer();

  if (!g.AppendGRecordToFile(true)) {
    fprintf(stderr, "Failed to write file\n");
    return 2;
  }

  return 0;
}
Beispiel #12
0
int
main(int argc, char **argv)
{
  Args args(argc, argv, "FILE.igc");
  tstring path = args.ExpectNextT();
  args.ExpectEnd();

  GRecord g;
  g.Initialize();

  if (!g.LoadFileToBuffer(path.c_str())) {
    fprintf(stderr, "Failed to read file\n");
    return 2;
  }

  g.FinalizeBuffer();

  if (!g.AppendGRecordToFile(path.c_str())) {
    fprintf(stderr, "Failed to write file\n");
    return 2;
  }

  return 0;
}
Beispiel #13
0
static bool
FixGRecord(NLineReader &reader, TextWriter &writer)
{
  GRecord grecord;
  grecord.Initialize();

  char digest[GRecord::DIGEST_LENGTH + 1];
  grecord.GetDigest(digest);

  char *line;
  while ((line = reader.ReadLine()) != nullptr) {
    if (line[0] == 'G')
      break;

    if (memcmp(line, "HFFTYFRTYPE:XCSOAR,XCSOAR ", 26) == 0) {
      char *v = strstr(line + 25, " 6.5 ");
      if (v != nullptr) {
        static char buffer[1024], *p = buffer;

        size_t n = v + 4 - line;
        memcpy(p, line, n);
        p += n;

        memcpy(p, "fix", 3);
        p += 3;

        strcpy(p, v + 4);

        line = buffer;
      }
    }

    grecord.AppendRecordToBuffer(line);

    if (!writer.WriteLine(line))
      return false;
  }

  grecord.FinalizeBuffer();
  grecord.WriteTo(writer);
  return true;
}
Beispiel #14
0
int main(int argc, char **argv)
{
  plan_tests(47);

  const TCHAR *path = _T("output/test/test.igc");
  File::Delete(path);

  static const GeoPoint home(Angle::Degrees(fixed(7.7061111111111114)),
                             Angle::Degrees(fixed(51.051944444444445)));
  static const GeoPoint tp(Angle::Degrees(fixed(10.726111111111111)),
                           Angle::Degrees(fixed(50.6322)));

  static NMEAInfo i;
  i.clock = fixed_one;
  i.time = fixed(1);
  i.time_available.Update(i.clock);
  i.date_time_utc.year = 2010;
  i.date_time_utc.month = 9;
  i.date_time_utc.day = 4;
  i.date_time_utc.hour = 11;
  i.date_time_utc.minute = 22;
  i.date_time_utc.second = 33;
  i.location = home;
  i.location_available.Update(i.clock);
  i.gps_altitude = fixed(487);
  i.gps_altitude_available.Update(i.clock);
  i.ProvideBaroAltitudeTrue(fixed(490));

  IGCWriter writer(path, i);

  writer.WriteHeader(i.date_time_utc, _T("Pilot Name"), _T("ASK-21"),
                     _T("D-1234"), _T("34"), "FOO", _T("bar"));
  writer.StartDeclaration(i.date_time_utc, 3);
  writer.AddDeclaration(home, _T("Bergneustadt"));
  writer.AddDeclaration(tp, _T("Suhl"));
  writer.AddDeclaration(home, _T("Bergneustadt"));
  writer.EndDeclaration();

  i.date_time_utc.second += 5;
  writer.LogPoint(i);
  i.date_time_utc.second += 5;
  writer.LogEvent(i, "my_event");
  i.date_time_utc.second += 5;
  writer.LoggerNote(_T("my_note"));

  i.date_time_utc.second += 5;
  i.location = GeoPoint(Angle::Degrees(fixed(-7.7061111111111114)),
                        Angle::Degrees(fixed(-51.051944444444445)));
  writer.LogPoint(i);

  writer.Finish(i);
  writer.Sign();

  CheckTextFile(path, expect);

  GRecord grecord;
  grecord.Initialize();
  grecord.SetFileName(path);
  ok1(grecord.VerifyGRecordInFile());

  return exit_status();
}