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))); }
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; }