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; }
int main(int argc, char **argv) { Args args(argc, argv, "[--through DRIVER0] DRIVER PORT BAUD"); tstring _through_name; const TCHAR *through_name = NULL; const char *a; while ((a = args.PeekNext()) != NULL && *a == '-') { a = args.ExpectNext(); if (strcmp(a, "--through") == 0) { _through_name = args.ExpectNextT(); through_name = _through_name.c_str(); } else args.UsageError(); } 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; } ConsoleOperationEnvironment env; if (!port->WaitConnected(env)) { delete port; DeinitialiseIOThread(); fprintf(stderr, "Failed to connect the port\n"); return EXIT_FAILURE; } 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); declaration.Append(MakeWaypoint(_T("Bergneustadt"), 488, 7.7061111111111114, 51.051944444444445)); declaration.Append(MakeWaypoint(_T("Foo"), 488, 8, 52)); declaration.Append(MakeWaypoint(_T("Bar"), 488, 7.5, 50)); declaration.Append(MakeWaypoint(_T("Bergneustadt"), 488, 7.7061111111111114, 51.051944444444445)); Device *through_device = NULL; if (through_name != NULL) { const struct DeviceRegister *through_driver = FindDriverByName(through_name); if (through_driver == NULL) { _ftprintf(stderr, _T("No such driver: %s\n"), through_name); return EXIT_FAILURE; } if (!through_driver->HasPassThrough()) { _ftprintf(stderr, _T("Not a pass-through driver: %s\n"), through_name); return EXIT_FAILURE; } assert(through_driver->CreateOnPort != NULL); through_device = through_driver->CreateOnPort(config, *port); assert(through_device != NULL); } const struct DeviceRegister *driver = FindDriverByName(driver_name); if (driver == NULL) { _ftprintf(stderr, _T("No such driver: %s\n"), driver_name); return EXIT_FAILURE; } if (!driver->CanDeclare()) { _ftprintf(stderr, _T("Not a logger driver: %s\n"), driver_name); return EXIT_FAILURE; } assert(driver->CreateOnPort != NULL); Device *device = driver->CreateOnPort(config, *port); assert(device != NULL); if (through_device != NULL && !through_device->EnablePassThrough(env)) { _ftprintf(stderr, _T("Failed to enable pass-through mode: %s\n"), through_name); return EXIT_FAILURE; } if (device->Declare(declaration, NULL, env)) fprintf(stderr, "Declaration ok\n"); else fprintf(stderr, "Declaration failed\n"); delete through_device; delete device; delete port; DeinitialiseIOThread(); return EXIT_SUCCESS; }