public async Task SignInAsync() { if (!_settings.CheckEnableAltitudeAngel) { return; } try { // Load the user's profile, will trigger auth CurrentUser = await _client.GetUserProfile(); IsSignedIn.Value = true; await UpdateMapData(_missionPlanner.FlightDataMap, CancellationToken.None); await UpdateMapData(_missionPlanner.FlightPlanningMap, CancellationToken.None); } catch (Exception) { await _messagesService.AddMessageAsync("There was a problem signing you in."); } }
private async Task StartTelemetryFlight(FlightPlan flightPlan) { if (flightPlan == null) { return; } if (_settings.CurrentFlightId != null) { // Complete flight if starting one before the previous ends. await CompleteFlight(); } // TODO somehow prevent Arming of UAV until the following try statement has been completed, so telemetry isnt sent late. PBI 8490 try { CurrentUser = await _client.GetUserProfile(); Guid?flightPlanId; if (_settings.UseExistingFlightPlanId) { flightPlanId = _settings.ExistingFlightPlanId; } else { await _messagesService.AddMessageAsync(new Message("Creating flight plan...") { TimeToLive = TimeSpan.FromSeconds(10) }); var createPlanResponse = await _client.CreateFlightPlan(flightPlan, CurrentUser); if (createPlanResponse.Outcome == StrategicSeverity.DirectConflict) { await _messagesService.AddMessageAsync(new Message("Conflict detected; flight cancelled.") { TimeToLive = TimeSpan.FromSeconds(10) }); await _missionPlanner.Disarm(); return; } flightPlanId = createPlanResponse.FlightPlanId; } // Check flight plan id is valid if (flightPlanId == null || flightPlanId == Guid.Empty) { await _messagesService.AddMessageAsync(new Message("Flight plan not available; flight cancelled.") { TimeToLive = TimeSpan.FromSeconds(10) }); await _missionPlanner.Disarm(); return; } _settings.CurrentFlightReportId = flightPlanId.ToString(); await _messagesService.AddMessageAsync(new Message($"Flight plan {flightPlanId} in use.") { TimeToLive = TimeSpan.FromSeconds(10) }); // Flight being rejected will throw, and cause a disarm await _messagesService.AddMessageAsync(new Message("Starting flight...") { TimeToLive = TimeSpan.FromSeconds(10) }); var startFlightResponse = await _client.StartFlight(flightPlanId.Value.ToString("D")); _settings.CurrentFlightId = startFlightResponse.Id; var tacticalSettings = startFlightResponse.ServiceResponses.First(); var notificationSettings = (WebsocketNotificationProtocolConfiguration)tacticalSettings.Properties.NotificationProtocols.First(); _settings.OutboundNotifsEndpointUrl = notificationSettings.Properties.Endpoints.First(); var telemetrySettings = (UdpTelemetryProtocolConfiguration)tacticalSettings.Properties.TelemetryProtocols.First(); _settings.CurrentTelemetryId = telemetrySettings.Id; _settings.EncryptionKey = telemetrySettings.Properties.EncryptionKey; var telemetryEndPoint = telemetrySettings.Properties.Endpoints.First(); _settings.TelemetryHostName = telemetryEndPoint.Split(':')[0]; _settings.TelemetryPortNumber = int.Parse(telemetryEndPoint.Split(':')[1]); _settings.TransmissionRateInMilliseconds = telemetrySettings.Properties.TransmissionRateInMilliseconds; var task = _notificationsService.StartWebSocket(); await _messagesService.AddMessageAsync(new Message($"Flight {startFlightResponse.Id} approved and underway.") { TimeToLive = TimeSpan.FromSeconds(10) }); await task; } catch (Exception) { await _missionPlanner.Disarm(); await _messagesService.AddMessageAsync(new Message($"Flight create failed.")); } }