bool DeviceDescriptor::DownloadFlight(const RecordedFlightInfo &flight, Path path, OperationEnvironment &env) { assert(borrowed); assert(port != nullptr); assert(driver != nullptr); assert(device != nullptr); if (port == nullptr || driver == nullptr || device == nullptr) return false; StaticString<60> text; if (driver->HasPassThrough() && (second_device != nullptr)) { text.Format(_T("%s: %s."), _("Downloading flight log"), second_driver->display_name); env.SetText(text); device->EnablePassThrough(env); return second_device->DownloadFlight(flight, path, env); } else { text.Format(_T("%s: %s."), _("Downloading flight log"), driver->display_name); env.SetText(text); return device->DownloadFlight(flight, path, env); } }
bool DeviceDescriptor::Declare(const struct Declaration &declaration, const Waypoint *home, OperationEnvironment &env) { if (port == NULL) return false; SetBusy(true); StaticString<60> text; text.Format(_T("%s: %s."), _("Sending declaration"), driver->display_name); env.SetText(text); port->StopRxThread(); bool result = device != NULL && device->Declare(declaration, home, env); if (device_blackboard->IsFLARM(index) && !IsDriver(_T("FLARM"))) { text.Format(_T("%s: FLARM."), _("Sending declaration")); env.SetText(text); FlarmDevice flarm(*port); result = flarm.Declare(declaration, home, env) || result; } port->StartRxThread(); SetBusy(false); return result; }
bool DeviceDescriptor::ReadFlightList(RecordedFlightList &flight_list, OperationEnvironment &env) { assert(borrowed); assert(port != nullptr); assert(driver != nullptr); assert(device != nullptr); StaticString<60> text; if (driver->HasPassThrough() && second_device != nullptr) { text.Format(_T("%s: %s."), _("Reading flight list"), second_driver->display_name); env.SetText(text); device->EnablePassThrough(env); return second_device->ReadFlightList(flight_list, env); } else { text.Format(_T("%s: %s."), _("Reading flight list"), driver->display_name); env.SetText(text); return device->ReadFlightList(flight_list, env); } }
void CAI302WaypointUploader::Run(OperationEnvironment &env) { Waypoints waypoints; env.SetText(_("Loading Waypoints...")); if (!reader.Parse(waypoints, env)) { env.SetErrorMessage(_("Failed to load file.")); return; } if (waypoints.size() > 9999) { env.SetErrorMessage(_("Too many waypoints.")); return; } env.SetText(_("Uploading Waypoints")); env.SetProgressRange(waypoints.size() + 1); env.SetProgressPosition(0); if (!device.ClearPoints(env)) { if (!env.IsCancelled()) env.SetErrorMessage(_("Failed to erase waypoints.")); return; } if (!device.EnableBulkMode(env)) { if (!env.IsCancelled()) env.SetErrorMessage(_("Failed to switch baud rate.")); return; } unsigned id = 1; for (auto i = waypoints.begin(), end = waypoints.end(); i != end; ++i, ++id) { if (env.IsCancelled()) break; env.SetProgressPosition(id); if (!device.WriteNavpoint(id, *i, env)) { if (!env.IsCancelled()) env.SetErrorMessage(_("Failed to write waypoint.")); break; } } device.DisableBulkMode(env); }
bool WaypointGlue::LoadWaypoints(Waypoints &way_points, const RasterTerrain *terrain, OperationEnvironment &operation) { LogStartUp(_T("ReadWaypoints")); operation.SetText(_("Loading Waypoints...")); bool found = false; // Delete old waypoints way_points.Clear(); // ### FIRST FILE ### found |= LoadWaypointFile(1, way_points, terrain, operation); // ### SECOND FILE ### found |= LoadWaypointFile(2, way_points, terrain, operation); // ### WATCHED WAYPOINT/THIRD FILE ### found |= LoadWaypointFile(3, way_points, terrain, operation); // ### MAP/FOURTH FILE ### // If no waypoint file found yet if (!found) found = LoadMapFileWaypoints(0, szProfileMapFile, way_points, terrain, operation); // Optimise the waypoint list after attaching new waypoints way_points.Optimise(); // Return whether waypoints have been loaded into the waypoint list return found; }
bool WaypointGlue::LoadWaypoints(Waypoints &way_points, const RasterTerrain *terrain, OperationEnvironment &operation) { LogFormat("ReadWaypoints"); operation.SetText(_("Loading Waypoints...")); bool found = false; // Delete old waypoints way_points.Clear(); TCHAR path[MAX_PATH]; LoadWaypointFile(way_points, LocalPath(path, _T("user.cup")), WaypointFileType::SEEYOU, WaypointOrigin::USER, terrain, operation); // ### FIRST FILE ### if (Profile::GetPath(ProfileKeys::WaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::PRIMARY, terrain, operation); // ### SECOND FILE ### if (Profile::GetPath(ProfileKeys::AdditionalWaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::ADDITIONAL, terrain, operation); // ### WATCHED WAYPOINT/THIRD FILE ### if (Profile::GetPath(ProfileKeys::WatchedWaypointFile, path)) found |= LoadWaypointFile(way_points, path, WaypointOrigin::WATCHED, terrain, operation); // ### MAP/FOURTH FILE ### // If no waypoint file found yet if (!found) { auto dir = OpenMapFile(); if (dir != nullptr) { found |= LoadWaypointFile(way_points, dir, "waypoints.xcw", WaypointFileType::WINPILOT, WaypointOrigin::MAP, terrain, operation); found |= LoadWaypointFile(way_points, dir, "waypoints.cup", WaypointFileType::SEEYOU, WaypointOrigin::MAP, terrain, operation); zzip_dir_close(dir); } } // Optimise the waypoint list after attaching new waypoints way_points.Optimise(); // Return whether waypoints have been loaded into the waypoint list return found; }
/** * Opens the airfield details file and parses it */ void WaypointDetails::ReadFile(TLineReader &reader, Waypoints &way_points, OperationEnvironment &operation) { operation.SetText(_("Loading Airfield Details File...")); ParseAirfieldDetails(way_points, reader, operation); }
bool VolksloggerDevice::Declare(const Declaration &declaration, const Waypoint *home, OperationEnvironment &env) { if (declaration.Size() < 2) return false; env.SetText(_T("Comms with Volkslogger")); port.SetRxTimeout(500); // change to IO mode baud rate unsigned lLastBaudrate = port.SetBaudrate(9600L); VLAPI vl(port, env); bool success = DeclareInner(vl, declaration, home); vl.close(1); port.SetBaudrate(lLastBaudrate); // restore baudrate return success; }
virtual void Run(OperationEnvironment &env) { env.SetText(_T("Working...")); env.SetProgressRange(30); for (unsigned i = 0; i < 30 && !env.IsCancelled(); ++i) { env.SetProgressPosition(i); env.Sleep(500); } }
bool LoadConfiguredTopography(TopographyStore &store, OperationEnvironment &operation) { LogFormat("Loading Topography File..."); operation.SetText(_("Loading Topography File...")); return LoadConfiguredTopographyZip(store, operation); }
static bool DoDeclare(const struct Declaration &declaration, Port &port, const DeviceRegister &driver, Device *device, bool flarm, const Waypoint *home, OperationEnvironment &env) { StaticString<60> text; text.Format(_T("%s: %s."), _("Sending declaration"), driver.display_name); env.SetText(text); bool result = device != nullptr && device->Declare(declaration, home, env); if (flarm) { text.Format(_T("%s: FLARM."), _("Sending declaration")); env.SetText(text); result |= DeclareToFLARM(declaration, port, driver, device, home, env); } return result; }
bool DeviceDescriptor::ReadFlightList(RecordedFlightList &flight_list, OperationEnvironment &env) { assert(borrowed); assert(port != nullptr); assert(driver != nullptr); assert(device != nullptr); StaticString<60> text; text.Format(_T("%s: %s."), _("Reading flight list"), driver->display_name); env.SetText(text); return device->ReadFlightList(flight_list, env); }
bool DeviceDescriptor::ReadFlightList(RecordedFlightList &flight_list, OperationEnvironment &env) { if (port == NULL || driver == NULL || device == NULL) return false; StaticString<60> text; text.Format(_T("%s: %s."), _("Reading flight list"), driver->display_name); env.SetText(text); port->StopRxThread(); bool result = device->ReadFlightList(flight_list, env); port->StartRxThread(); return result; }
bool WaypointGlue::LoadWaypoints(Waypoints &way_points, const RasterTerrain *terrain, OperationEnvironment &operation) { LogFormat("ReadWaypoints"); operation.SetText(_("Loading Waypoints...")); bool found = false; // Delete old waypoints way_points.Clear(); TCHAR path[MAX_PATH]; // ### FIRST FILE ### if (Profile::GetPath(ProfileKeys::WaypointFile, path)) found |= LoadWaypointFile(way_points, path, 1, terrain, operation); // ### SECOND FILE ### if (Profile::GetPath(ProfileKeys::AdditionalWaypointFile, path)) found |= LoadWaypointFile(way_points, path, 2, terrain, operation); // ### WATCHED WAYPOINT/THIRD FILE ### if (Profile::GetPath(ProfileKeys::WatchedWaypointFile, path)) found |= LoadWaypointFile(way_points, path, 3, terrain, operation); // ### MAP/FOURTH FILE ### // If no waypoint file found yet if (!found && Profile::GetPath(ProfileKeys::MapFile, path)) { TCHAR *tail = path + _tcslen(path); _tcscpy(tail, _T("/waypoints.xcw")); found |= LoadWaypointFile(way_points, path, 0, terrain, operation); _tcscpy(tail, _T("/waypoints.cup")); found |= LoadWaypointFile(way_points, path, 0, terrain, operation); } // Optimise the waypoint list after attaching new waypoints way_points.Optimise(); // Return whether waypoints have been loaded into the waypoint list return found; }
bool DeviceDescriptor::DownloadFlight(const RecordedFlightInfo &flight, const TCHAR *path, OperationEnvironment &env) { if (port == NULL || driver == NULL || device == NULL) return false; StaticString<60> text; text.Format(_T("%s: %s."), _("Downloading flight log"), driver->display_name); env.SetText(text); port->StopRxThread(); bool result = device->DownloadFlight(flight, path, env); port->StartRxThread(); return result; }
bool DeviceDescriptor::DownloadFlight(const RecordedFlightInfo &flight, const TCHAR *path, OperationEnvironment &env) { assert(borrowed); assert(port != nullptr); assert(driver != nullptr); assert(device != nullptr); if (port == nullptr || driver == nullptr || device == nullptr) return false; StaticString<60> text; text.Format(_T("%s: %s."), _("Downloading flight log"), driver->display_name); env.SetText(text); return device->DownloadFlight(flight, path, env); }
void ReadAirspace(Airspaces &airspaces, RasterTerrain *terrain, const AtmosphericPressure &press, OperationEnvironment &operation) { LogStartUp(_T("ReadAirspace")); operation.SetText(_("Loading Airspace File...")); bool airspace_ok = false; // Read the airspace filenames from the registry TLineReader *reader = OpenConfiguredTextFile(szProfileAirspaceFile, _T("airspace.txt")); if (reader != NULL) { if (!ReadAirspace(airspaces, *reader, operation)) LogStartUp(_T("No airspace file 1")); else airspace_ok = true; delete reader; } reader = OpenConfiguredTextFile(szProfileAdditionalAirspaceFile); if (reader != NULL) { if (!ReadAirspace(airspaces, *reader, operation)) LogStartUp(_T("No airspace file 2")); else airspace_ok = true; delete reader; } if (airspace_ok) { airspaces.optimise(); airspaces.set_flight_levels(press); if (terrain != NULL) airspaces.set_ground_levels(*terrain); } else // there was a problem airspaces.clear(); }
void ReadAirspace(Airspaces &airspaces, RasterTerrain *terrain, const AtmosphericPressure &press, OperationEnvironment &operation) { LogFormat("ReadAirspace"); operation.SetText(_("Loading Airspace File...")); bool airspace_ok = false; AirspaceParser parser(airspaces); // Read the airspace filenames from the registry auto path = Profile::GetPath(ProfileKeys::AirspaceFile); if (!path.IsNull()) airspace_ok |= ParseAirspaceFile(parser, path, operation); path = Profile::GetPath(ProfileKeys::AdditionalAirspaceFile); if (!path.IsNull()) airspace_ok |= ParseAirspaceFile(parser, path, operation); auto archive = OpenMapFile(); if (archive) airspace_ok |= ParseAirspaceFile(parser, archive->get(), "airspace.txt", operation); if (airspace_ok) { airspaces.Optimise(); airspaces.SetFlightLevels(press); if (terrain != NULL) airspaces.SetGroundLevels(*terrain); } else // there was a problem airspaces.Clear(); }
void RasterWeatherStore::ScanAll(const GeoPoint &location, OperationEnvironment &operation) { /* not holding the lock here, because this method is only called during startup, when the other threads aren't running yet */ operation.SetText(_("Scanning weather forecast")); ZZIP_DIR *dir = OpenArchive(); if (dir == nullptr) return; operation.SetProgressRange(MAX_WEATHER_TIMES); maps.clear(); std::set<tstring> names; for (const auto &i : WeatherDescriptors) { if (i.name == nullptr) { /* special case: 0 = terrain */ assert(maps.empty()); auto &m = maps.append(); m.name.clear(); m.label = i.label; m.help = i.help; } else { if (maps.full()) break; MapItem item(i.name); item.label = i.label; item.help = i.help; if (ScanMapItem(dir, item)) maps.push_back(item); names.insert(i.name); } } ZZIP_DIRENT e; while (zzip_dir_read(dir, &e)) { if (maps.full()) break; const char *filename = e.d_name; if (!StringEndsWith(filename, ".jp2")) continue; MapItem item(_T("")); const char *dot = strchr(filename, '.'); if (dot == nullptr || dot == filename || size_t(dot - filename) >= item.name.capacity()) continue; item.name.SetASCII(filename, dot); item.label = nullptr; item.help = nullptr; if (!names.insert(item.name.c_str()).second) continue; if (ScanMapItem(dir, item)) maps.push_back(item); } // TODO: scan the rest zzip_dir_close(dir); }