util::json::Array MakeWaypoints(const std::vector<PhantomNodes> &segment_end_coordinates) const { BOOST_ASSERT(parameters.coordinates.size() > 0); BOOST_ASSERT(parameters.coordinates.size() == segment_end_coordinates.size() + 1); util::json::Array waypoints; waypoints.values.resize(parameters.coordinates.size()); waypoints.values[0] = MakeWaypoint(segment_end_coordinates.front().source_phantom); auto out_iter = std::next(waypoints.values.begin()); boost::range::transform(segment_end_coordinates, out_iter, [this](const PhantomNodes &phantom_pair) { return MakeWaypoint(phantom_pair.target_phantom); }); return waypoints; }
static void TestHighTPFinal() { const fixed width(1); OrderedTask task(task_behaviour); const StartPoint tp1(new LineSectorZone(wp1.location, width), wp1, task_behaviour, ordered_task_settings.start_constraints); task.Append(tp1); const Waypoint wp3b = MakeWaypoint(wp3, 1500); const ASTPoint tp2(new LineSectorZone(wp3b.location, width), wp3b, task_behaviour); task.Append(tp2); const Waypoint wp5b = MakeWaypoint(wp5, 200); const FinishPoint tp3(new LineSectorZone(wp5b.location, width), wp5b, task_behaviour, ordered_task_settings.finish_constraints, false); task.Append(tp3); task.SetActiveTaskPoint(1); task.UpdateGeometry(); ok1(task.CheckTask()); AircraftState aircraft; aircraft.Reset(); aircraft.location = wp1.location; aircraft.altitude = fixed(1200); task.Update(aircraft, aircraft, glide_polar); const TaskStats &stats = task.GetStats(); ok1(stats.task_valid); ok1(!stats.start.task_started); ok1(!stats.task_finished); ok1(!stats.flight_mode_final_glide); CheckLeg(tp2, aircraft, stats); CheckTotal(aircraft, stats, tp1, tp2, tp3); }
void MakeResponse(const std::vector<std::vector<PhantomNodeWithDistance>> &phantom_nodes, util::json::Object &response) const { BOOST_ASSERT(phantom_nodes.size() == 1); BOOST_ASSERT(parameters.coordinates.size() == 1); util::json::Array waypoints; waypoints.values.resize(phantom_nodes.front().size()); std::transform(phantom_nodes.front().begin(), phantom_nodes.front().end(), waypoints.values.begin(), [this](const PhantomNodeWithDistance &phantom_with_distance) { auto waypoint = MakeWaypoint(phantom_with_distance.phantom_node); waypoint.values["distance"] = phantom_with_distance.distance; return waypoint; }); response.values["code"] = "Ok"; response.values["waypoints"] = std::move(waypoints); }
static Waypoint MakeWaypoint(double longitude, double latitude, double altitude) { return MakeWaypoint(Waypoint(MakeGeoPoint(longitude, latitude)), altitude); }
} static Waypoint MakeWaypoint(Waypoint wp, double altitude) { wp.elevation = fixed(altitude); return wp; } static Waypoint MakeWaypoint(double longitude, double latitude, double altitude) { return MakeWaypoint(Waypoint(MakeGeoPoint(longitude, latitude)), altitude); } static const Waypoint wp1 = MakeWaypoint(0, 45, 50); static const Waypoint wp2 = MakeWaypoint(0, 45.3, 50); static const Waypoint wp3 = MakeWaypoint(0, 46, 50); static const Waypoint wp4 = MakeWaypoint(1, 46, 50); static const Waypoint wp5 = MakeWaypoint(0.3, 46, 50); static fixed GetSafetyHeight(const TaskPoint &tp) { return task_behaviour.safety_height_arrival; } static void CheckLeg(const TaskWaypoint &tp, const AircraftState &aircraft, const TaskStats &stats) {
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; }
static WaypointPtr MakeWaypointPtr(Args&&... args) { return WaypointPtr(new Waypoint(MakeWaypoint(std::forward<Args>(args)...))); }