Пример #1
0
        protected override void OnLoad(EventArgs e)
        {
            //MyView.AddScreen(new MainSwitcher.Screen("FlightData", FlightData, true));
            FlightData          = new GCSViews.FlightData();
            FlightData.TopLevel = false;
            FlightData.Show();
            this.splitContainer1.Panel1.Controls.Clear();
            this.splitContainer1.Panel1.Controls.Add(FlightData);

            // for long running tasks using own threads.
            // for short use threadpool
            this.splitContainer1.Panel1.Resize += new EventHandler(splitContainer1_Panel1_Resize);
            this.SuspendLayout();
            //if (Program.Logo != null && Program.name == "VVVVZ")
            //{
            //    this.PerformLayout();
            //    MenuFlightPlanner_Click(this, e);
            //    MainMenu_ItemClicked(this, new ToolStripItemClickedEventArgs(MenuFlightPlanner));
            //}
            //else
            //{
            //    this.PerformLayout();
            //    log.Info("show FlightData");
            //    MenuFlightData_Click(this, e);
            //    log.Info("show FlightData... Done");
            //    MainMenu_ItemClicked(this, new ToolStripItemClickedEventArgs(MenuFlightData));
            //}

            // for long running tasks using own threads.
            // for short use threadpool

            //this.SuspendLayout();

            // setup http server
            try
            {
                log.Info("start http");
                httpthread = new Thread(new httpserver().listernforclients)
                {
                    Name         = "tcp connect station",
                    IsBackground = true
                };
                httpthread.Start();
            }
            catch (Exception ex)
            {
                log.Error("Error starting TCP listener thread: ", ex);
                CustomMessageBox.Show(ex.ToString());
            }

            log.Info("start serialreader");
            // setup main serial reader
            serialreaderthread = new Thread(SerialReader)
            {
                IsBackground = true,
                Name         = "Main Serial reader",
                Priority     = ThreadPriority.AboveNormal
            };
            serialreaderthread.Start();

            //ThreadPool.QueueUserWorkItem(BGLoadAirports);

            //ThreadPool.QueueUserWorkItem(BGCreateMaps);

            //ThreadPool.QueueUserWorkItem(BGGetAlmanac);

            ThreadPool.QueueUserWorkItem(BGgetTFR);
            //数据解析线程
            //myThreadDataParser = new Thread(new ThreadStart(UartDataParser));//数据解析程序
            //myThreadDataParser.IsBackground = true;
            //myThreadDataParser.Priority = ThreadPriority.Highest;
            //myThreadDataParser.Start();

            //GPS数据解析线程

            //if (UDPserverStart == false)
            //{
            //    StartReceiveUDP_GPS();
            //    if (GPSsaveFileFs == null)
            //    {
            //        //OpenSaveGpsFile();
            //    }

            //    //UDPserverStart = true;
            //}

            // myThreadGPSDataParser = new Thread(new ThreadStart(UartGPSDataParser));//GPS数据解析程序
            // myThreadGPSDataParser.IsBackground = true;
            // myThreadGPSDataParser.Start();

            //自动打开两个串口
            //ConPort();
            //绘图设置
            //dataviewReset();
            //computer.Open();
            //开始更新时间和日期标签
            updateDateTimer.Start();
            this.updateDateTimer.Enabled = true;
        }
Пример #2
0
        //定义当前窗体的高度
        public MainV2()
        {
            log.Info("Mainv2 create");

            // load config
            // load last saved connection settings
            //LoadConfig(configfilename);

            //ShowAirports = true;

            instance = this;

            //disable dpi scaling
            if (Font.Name != "宋体")
            {
                //Chinese displayed normally when scaling. But would be too small or large using this line of code.
                using (var g = CreateGraphics())
                {
                    Font = new Font(Font.Name, 8.25f * 96f / g.DpiX, Font.Style, Font.Unit, Font.GdiCharSet,
                                    Font.GdiVerticalFont);
                }
            }
            InitializeComponent();
            //MyView = new MainSwitcher(this);
            //View = MyView;
            x = this.Width;
            y = this.Height;
            setTag(this);

            //var t = Type.GetType("Mono.Runtime");
            //MONO = (t != null);

            //if (!MONO) // windows only
            //{
            //    if (Settings.Instance["showconsole"] != null && Settings.Instance["showconsole"].ToString() == "True")
            //    {
            //    }
            //    else
            //    {
            //        int win = NativeMethods.FindWindow("ConsoleWindowClass", null);
            //        NativeMethods.ShowWindow(win, NativeMethods.SW_HIDE); // hide window
            //    }

            //    // prevent system from sleeping while program open
            //    var previousExecutionState =
            //        NativeMethods.SetThreadExecutionState(NativeMethods.ES_CONTINUOUS | NativeMethods.ES_SYSTEM_REQUIRED);
            //}

            if (Settings.Instance["showairports"] != null)
            {
                MainV2.ShowAirports = bool.Parse(Settings.Instance["showairports"]);
            }
            try
            {
                log.Info("Create FD");
                FlightData = new GCSViews.FlightData();
                //FlightData.Parent = this;
                FlightData.TopLevel = false;
                this.splitContainer1.Panel1.Controls.Add(FlightData);

                log.Info("Create FP");
                //FlightPlanner = new GCSViews.FlightPlanner();
                //Configuration = new GCSViews.ConfigurationView.Setup();
                log.Info("Create SIM");
                //Simulation = new SITL();
                //Firmware = new GCSViews.Firmware();
                //Terminal = new GCSViews.Terminal();

                //FlightData.Width = MyView.Width;
                //FlightPlanner.Width = MyView.Width;
                //Simulation.Width = MyView.Width;
            }
            catch (ArgumentException e)
            {
                //http://www.microsoft.com/en-us/download/details.aspx?id=16083
                //System.ArgumentException: Font 'Arial' does not support style 'Regular'.

                log.Fatal(e);
                CustomMessageBox.Show(e.ToString() +
                                      "\n\n Font Issues? Please install this http://www.microsoft.com/en-us/download/details.aspx?id=16083");
                //splash.Close();
                //this.Close();
                Application.Exit();
            }
            catch (Exception e)
            {
                log.Fatal(e);
                CustomMessageBox.Show("A Major error has occured : " + e.ToString());
                Application.Exit();
            }
            //set first instance display configuration

            // load old config

            //UpdateTextHandler = new UpdateAcceptTextBoxTextHandler(UpdateText);
            try
            {
                if (!Directory.Exists(Settings.Instance.LogDir))
                {
                    Directory.CreateDirectory(Settings.Instance.LogDir);
                }
            }
            catch (Exception ex) { log.Error(ex); }

            //Microsoft.Win32.SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

            if (!MONO)
            {
                Microsoft.Win32.RegistryKey installed_versions =
                    Microsoft.Win32.Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
                string[] version_names = installed_versions.GetSubKeyNames();
                //version names start with 'v', eg, 'v3.5' which needs to be trimmed off before conversion
                double Framework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1),
                                                    CultureInfo.InvariantCulture);
                int SP =
                    Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1])
                                    .GetValue("SP", 0));

                if (Framework < 4.0)
                {
                    CustomMessageBox.Show("This program requires .NET Framework 4.0. You currently have " + Framework);
                }
            }

            Application.DoEvents();
            Application.DoEvents();

            Comports.Add(comPort);

            MainV2.comPort.MavChanged += comPort_MavChanged;

            // save config to test we have write access
            SaveConfig();
            //SaveConfig();

            //DataconnectWork.DoWork += new DoWorkEventHandler(DataconnectWork_DoWork);
            //DataconnectWork.RunWorkerCompleted +=
            //     new RunWorkerCompletedEventHandler(DataconnectWork_RunWorkerCompleted);
        }