Example #1
0
int main(int argc, char **argv)
{
    Args args(argc, argv, "DRIVER PORT BAUD");

    tstring _driver_name = args.ExpectNextT();
    const TCHAR *driver_name = _driver_name.c_str();
    const DeviceConfig config = ParsePortArgs(args);
    args.ExpectEnd();

    InitialiseIOThread();

    Port *port = OpenPort(config, *(DataHandler *)NULL);
    if (port == NULL) {
        fprintf(stderr, "Failed to open COM port\n");
        return EXIT_FAILURE;
    }

    const struct DeviceRegister *driver = FindDriverByName(driver_name);
    if (driver == NULL) {
        _ftprintf(stderr, _T("No such driver: %s\n"), driver_name);
        return EXIT_FAILURE;
    }

    ConsoleOperationEnvironment env;

    if (!port->WaitConnected(env)) {
        delete port;
        DeinitialiseIOThread();
        fprintf(stderr, "Failed to connect the port\n");
        return EXIT_FAILURE;
    }

    assert(driver->CreateOnPort != NULL);
    Device *device = driver->CreateOnPort(config, *port);
    assert(device != NULL);

    device->EnableNMEA(env);

    delete device;
    delete port;
    DeinitialiseIOThread();

    return EXIT_SUCCESS;
}
Example #2
0
static void
TestDeclare(const struct DeviceRegister &driver)
{
  FaultInjectionPort port(*(DataHandler *)NULL);
  Device *device = driver.CreateOnPort(dummy_config, port);
  ok1(device != NULL);

  LoggerSettings logger_settings;
  logger_settings.pilot_name = _T("Foo Bar");
  Plane plane;
  plane.registration = _T("D-3003");
  plane.competition_id = _T("33");
  plane.type = _T("Cirrus");

  Declaration declaration(logger_settings, plane, NULL);
  const GeoPoint gp(Angle::Degrees(7.7061111111111114),
                    Angle::Degrees(51.051944444444445));
  Waypoint wp(gp);
  wp.name = _T("Foo");
  wp.elevation = fixed(123);
  declaration.Append(wp);
  declaration.Append(wp);
  declaration.Append(wp);
  declaration.Append(wp);

  NullOperationEnvironment env;

  for (unsigned i = 0; i < 1024; ++i) {
    inject_port_fault = i;
    bool success = device->Declare(declaration, NULL, env);
    if (success || !port.running ||
        port.baud_rate != FaultInjectionPort::DEFAULT_BAUD_RATE)
      break;
  }

  device->EnableNMEA(env);

  ok1(port.baud_rate == FaultInjectionPort::DEFAULT_BAUD_RATE);

  delete device;
}
Example #3
0
int main(int argc, char **argv)
try {
  Args args(argc, argv, "DRIVER PORT BAUD");

  tstring _driver_name = args.ExpectNextT();
  const TCHAR *driver_name = _driver_name.c_str();
  DebugPort debug_port(args);
  args.ExpectEnd();

  ScopeGlobalAsioThread global_asio_thread;

  auto port = debug_port.Open(*asio_thread, *(DataHandler *)nullptr);

  const struct DeviceRegister *driver = FindDriverByName(driver_name);
  if (driver == NULL) {
    _ftprintf(stderr, _T("No such driver: %s\n"), driver_name);
    return EXIT_FAILURE;
  }

  ConsoleOperationEnvironment env;

  if (!port->WaitConnected(env)) {
    fprintf(stderr, "Failed to connect the port\n");
    return EXIT_FAILURE;
  }

  assert(driver->CreateOnPort != NULL);
  Device *device = driver->CreateOnPort(debug_port.GetConfig(), *port);
  assert(device != NULL);

  device->EnableNMEA(env);

  delete device;

  return EXIT_SUCCESS;
} catch (const std::exception &exception) {
  PrintException(exception);
  return EXIT_FAILURE;
}
Example #4
0
static void
TestFlightList(const struct DeviceRegister &driver)
{
  FaultInjectionPort port(*(DataHandler *)NULL);
  Device *device = driver.CreateOnPort(dummy_config, port);
  ok1(device != NULL);

  NullOperationEnvironment env;

  for (unsigned i = 0; i < 1024; ++i) {
    inject_port_fault = i;
    RecordedFlightList flight_list;
    bool success = device->ReadFlightList(flight_list, env);
    if (success || !port.running ||
        port.baud_rate != FaultInjectionPort::DEFAULT_BAUD_RATE)
      break;
  }

  device->EnableNMEA(env);

  ok1(port.baud_rate == FaultInjectionPort::DEFAULT_BAUD_RATE);

  delete device;
}