private static Simulation GetSimulator(ConfigFile config, Output output, TrajectorySource trajectorySource) { if (!File.Exists(config.NmeaFile)) { throw new ArgumentException("NMEA file does not exist"); } GnssTime gnssTime = GnssTime.FromUtc(config.Date); ILiveOutput liveOutput = output as ILiveOutput; if (liveOutput != null && liveOutput.IsTrueTime) { gnssTime = liveOutput.StartTime - GnssTimeSpan.FromSeconds(1); GnssTime startTime = liveOutput.StartTime; } else { gnssTime = GnssTime.FromUtc(config.Date); } Trajectory trajectory = (trajectorySource != TrajectorySource.Joystick) ? new NmeaFileTrajectory(gnssTime, config.NmeaFile, config.GravitationalModel) : new JoystickTrajectory(throttleSlider: Key.Z.IsDownAsync() ? JoystickSlider.ZAxis : (Key.D2.IsDownAsync() ? JoystickSlider.Slider2 : JoystickSlider.Slider1), startTime: gnssTime, nmeaFileName: config.NmeaFile, gravitationalModel: config.GravitationalModel); Range <GnssTime, GnssTimeSpan> interval = trajectory.Interval; if (interval.Width.Seconds < 1.0) { string text = trajectory.ErrorMessage; if (string.IsNullOrWhiteSpace(text)) { text = "Trajectory is shorter than one second"; } RLLogger.GetLogger().LogMessage(text); MessageBox.Show(Application.Current.MainWindow, text, "SatGen error", MessageBoxButton.OK, MessageBoxImage.Hand); return(null); } IReadOnlyList <ConstellationBase> readOnlyList = ConstellationBase.Create(config.SignalTypes, output); foreach (ConstellationBase item in readOnlyList) { string almanacPath = GetAlmanacPath(item.ConstellationType, config); item.LoadAlmanac(almanacPath, gnssTime); AlmanacBase almanac = item.Almanac; if (almanac == null || !almanac.BaselineSatellites.Any()) { string text2 = "Invalid " + item.ConstellationType.ToLongName() + " almanac file \"" + Path.GetFileName(almanacPath) + "\""; RLLogger.GetLogger().LogMessage(text2); MessageBox.Show(Application.Current.MainWindow, text2, "SatGen error", MessageBoxButton.OK, MessageBoxImage.Hand); return(null); } AlmanacBase almanac2 = item.Almanac; GnssTime simulationTime = interval.Start; almanac2.UpdateAlmanacForTime(simulationTime); } return(new DoubleBufferSimulation(new SimulationParams((IReadOnlyList <SignalType>)config.SignalTypes, trajectory, interval, output, readOnlyList, config.Mask, (IDictionary <ConstellationType, double>)config.CN0s, SignalLevelMode.None))); }
private async void OnBufferUnderrun(object sender, EventArgs e) { if (!firstFewSeconds && bufferUnderrunSemaphore.Wait(0)) { ConnectionStatus = ConnectionStatus.BufferUnderrun; BufferUnderrunCount++; await Task.Delay(2000); ILiveOutput liveOutput = simulation?.SimulationParameters.Output as ILiveOutput; if (liveOutput != null) { ConnectionStatus = ((!liveOutput.IsAlive) ? ConnectionStatus.Connected : ConnectionStatus.Transmitting); } else { ConnectionStatus = ConnectionStatus.None; } bufferUnderrunSemaphore?.Release(); } }
public MainWindow() { InitializeComponent(); AppDomain.CurrentDomain.UnhandledException += OnCurrentDomainUnhandledException; TaskScheduler.UnobservedTaskException += OnUnobservedTaskException; Application.Current.SessionEnding += OnSessionEnding; string[] commandLineArgs = Environment.GetCommandLineArgs(); if (commandLineArgs.Length != 2) { Environment.Exit(-1); } if (!File.Exists(commandLineArgs[1])) { Environment.Exit(-1); } ConfigFile config = ConfigFile.Read(commandLineArgs[1]); TrajectorySource trajectorySource = Key.LeftShift.IsDownAsync() ? TrajectorySource.Joystick : TrajectorySource.NmeaFile; Output output = null; try { output = GetOutput(config); } catch (LabSatException ex) { MessageBox.Show(this, ex.Message, "Error"); Application.Current.Shutdown(); return; } output.Error += OnOutputError; liveOutput = (output as ILiveOutput); if (liveOutput != null) { Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; } simulation = GetSimulator(config, output, trajectorySource); if (simulation == null) { Environment.Exit(-1); return; } viewModel = new SimulationViewModel(simulation); base.DataContext = viewModel; Control control = (Control)((liveOutput == null) ? ((object)new DefaultView(viewModel)) : ((object)new RealTimeView(viewModel))); control.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); preferredViewSize = control.DesiredSize; if (preferredViewSize.Width < control.MinWidth) { preferredViewSize.Width = control.MinWidth; } if (preferredViewSize.Height < control.MinHeight) { preferredViewSize.Height = control.MinHeight; } base.MinWidth = control.MinWidth + 20.0; base.MinHeight = control.MinHeight + 38.0; base.Width = preferredViewSize.Width + 20.0; base.Height = preferredViewSize.Height + 38.0; MainGrid.Children.Add(control); SystemUtils.SetThreadExecutionMode(ThreadExecutionModes.KeepSystemAwake); simulation.Completed += OnSimulationCompleted; base.Loaded += OnLoaded; }
public SimulationViewModel(Simulation simulation) { this.simulation = simulation; simulation.SimulationParameters.Output.PropertyChanged += OnOutputPropertyChanged; liveOutput = simulation.SimulationParameters.LiveOutput; if (liveOutput != null) { liveOutput.BufferUnderrun += OnBufferUnderrun; ConnectionStatus = ConnectionStatus.Connected; SatCountLimitMode = (SatCountLimitMode)Settings.Default.LiveSatCountLimitMode; AutomaticSatCountLimit = Settings.Default.LiveAutomaticSatCountLimit; GpsSatCountLimit = Settings.Default.LiveGpsSatCountLimit; GlonassSatCountLimit = Settings.Default.LiveGlonassSatCountLimit; BeiDouSatCountLimit = Settings.Default.LiveBeiDouSatCountLimit; GalileoSatCountLimit = Settings.Default.LiveGalileoSatCountLimit; attenuationsLinked = Settings.Default.LiveAttenuationsLinked; } else { SatCountLimitMode = SatCountLimitMode.Manual; AutomaticSatCountLimit = int.MaxValue; GpsSatCountLimit = int.MaxValue; GlonassSatCountLimit = int.MaxValue; BeiDouSatCountLimit = int.MaxValue; GalileoSatCountLimit = int.MaxValue; } simulation.ProgressChanged += OnProgressChanged; simulation.Completed += OnSimulationCompleted; simulation.SimulationParameters.PropertyChanged += OnSimulationParametersPropertyChanged; List <SatelliteGroup> list = new List <SatelliteGroup>(); ConstellationBase constellationBase = simulation.SimulationParameters.Constellations.FirstOrDefault((ConstellationBase c) => c.ConstellationType == ConstellationType.Gps); if (constellationBase != null) { list.Add(new SatelliteGroup(simulation, constellationBase)); } ConstellationBase constellationBase2 = simulation.SimulationParameters.Constellations.FirstOrDefault((ConstellationBase c) => c.ConstellationType == ConstellationType.Galileo); if (constellationBase2 != null) { list.Add(new SatelliteGroup(simulation, constellationBase2)); } ConstellationBase constellationBase3 = simulation.SimulationParameters.Constellations.FirstOrDefault((ConstellationBase c) => c.ConstellationType == ConstellationType.Glonass); if (constellationBase3 != null) { list.Add(new SatelliteGroup(simulation, constellationBase3)); } ConstellationBase constellationBase4 = simulation.SimulationParameters.Constellations.FirstOrDefault((ConstellationBase c) => c.ConstellationType == ConstellationType.BeiDou); if (constellationBase4 != null) { list.Add(new SatelliteGroup(simulation, constellationBase4)); } visibleSatellites = list.ToArray(); SatelliteGroup[] array = visibleSatellites; for (int i = 0; i < array.Length; i++) { array[i].PropertyChanged += OnSatelliteGroupPropertyChanged; } attenuationsLinked = !attenuationsLinked; AttenuationsLinked = !attenuationsLinked; resetSatCountLimitCommand = new RelayCommand(delegate { AutomaticSatCountLimit = 99; BufferUnderrunCount = 0; }, (object p) => SatCountLimitMode == SatCountLimitMode.Automatic); }