コード例 #1
0
ファイル: MainV2.cs プロジェクト: Event38/MissionPlanner
        private void MenuConnect_Click(object sender, EventArgs e)
        {
            comPort.giveComport = false;

            log.Info("MenuConnect Start");

            // sanity check
            if (comPort.BaseStream.IsOpen && MainV2.comPort.MAV.cs.groundspeed > 4)
            {
                if (DialogResult.No == CustomMessageBox.Show(Strings.Stillmoving, Strings.Disconnect, MessageBoxButtons.YesNo))
                {
                    return;
                }
            }

            try
            {
                log.Info("Cleanup last logfiles");
                // cleanup from any previous sessions
                if (comPort.logfile != null)
                    comPort.logfile.Close();

                if (comPort.rawlogfile != null)
                    comPort.rawlogfile.Close();
            }
            catch (Exception ex)
            {
                CustomMessageBox.Show(Strings.ErrorClosingLogFile + ex.Message, Strings.ERROR);
            }

            comPort.logfile = null;
            comPort.rawlogfile = null;

            // decide if this is a connect or disconnect
            if (comPort.BaseStream.IsOpen)
            {
                //fix for not recognizing when USB is pulled out - D Cironi
                if (MenuConnect.Text == "DISCONNECT")
                {
                    comPort.Close();
                }

                log.Info("We are disconnecting");
                try
                {
                    if (speechEngine != null) // cancel all pending speech
                        speechEngine.SpeakAsyncCancelAll();

                    comPort.BaseStream.DtrEnable = false;
                    comPort.Close();
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                }

                // now that we have closed the connection, cancel the connection stats
                // so that the 'time connected' etc does not grow, but the user can still
                // look at the now frozen stats on the still open form
                try
                {
                    // if terminal is used, then closed using this button.... exception
                    if (this.connectionStatsForm != null)
                        ((ConnectionStats)this.connectionStatsForm.Controls[0]).StopUpdates();
                }
                catch { }

                // refresh config window if needed
                if (MyView.current != null)
                {
                    if (MyView.current.Name == "HWConfig")
                        MyView.ShowScreen("HWConfig");
                    if (MyView.current.Name == "SWConfig")
                        MyView.ShowScreen("SWConfig");
                }

                try
                {
                    System.Threading.ThreadPool.QueueUserWorkItem((WaitCallback)delegate
                    {
                        try
                        {
                            MissionPlanner.Log.LogSort.SortLogs(Directory.GetFiles(MainV2.LogDir, "*.tlog"));
                        }
                        catch { }
                    }
                    );
                }
                catch { }

                this.MenuConnect.Image = global::MissionPlanner.Properties.Resources.light_connect_icon;
            }
            else
            {
                log.Info("We are connecting");
                switch (_connectionControl.CMB_serialport.Text)
                {
                    case "TCP":
                        comPort.BaseStream = new TcpSerial();
                        break;
                    case "UDP":
                        comPort.BaseStream = new UdpSerial();
                        break;
                    case "AUTO":
                    default:
                        comPort.BaseStream = new SerialPort();
                        break;
                }

                // Tell the connection UI that we are now connected.
                _connectionControl.IsConnected(true);

                // Here we want to reset the connection stats counter etc.
                this.ResetConnectionStats();

                MainV2.comPort.MAV.cs.ResetInternals();

                //cleanup any log being played
                comPort.logreadmode = false;
                if (comPort.logplaybackfile != null)
                    comPort.logplaybackfile.Close();
                comPort.logplaybackfile = null;

                try
                {
                    // do autoscan
                    if (_connectionControl.CMB_serialport.Text == "AUTO")
                    {
                        Comms.CommsSerialScan.Scan(false);

                        DateTime deadline = DateTime.Now.AddSeconds(50);

                        while (Comms.CommsSerialScan.foundport == false)
                        {
                            System.Threading.Thread.Sleep(100);

                            if (DateTime.Now > deadline)
                            {
                                CustomMessageBox.Show(Strings.Timeout);
                                _connectionControl.IsConnected(false);
                                return;
                            }
                        }

                        _connectionControl.CMB_serialport.Text = Comms.CommsSerialScan.portinterface.PortName;
                        _connectionControl.CMB_baudrate.Text = Comms.CommsSerialScan.portinterface.BaudRate.ToString();
                    }

                    log.Info("Set Portname");
                    // set port, then options
                    comPort.BaseStream.PortName = _connectionControl.CMB_serialport.Text;

                    log.Info("Set Baudrate");
                    try
                    {
                        comPort.BaseStream.BaudRate = int.Parse(_connectionControl.CMB_baudrate.Text);
                    }
                    catch (Exception exp)
                    {
                        log.Error(exp);
                    }

                    // prevent serialreader from doing anything
                    comPort.giveComport = true;

                    log.Info("About to do dtr if needed");
                    // reset on connect logic.
                    if (config["CHK_resetapmonconnect"] == null || bool.Parse(config["CHK_resetapmonconnect"].ToString()) == true)
                    {
                        log.Info("set dtr rts to false");
                        comPort.BaseStream.DtrEnable = false;
                        comPort.BaseStream.RtsEnable = false;

                        comPort.BaseStream.toggleDTR();
                    }

                    comPort.giveComport = false;

                    // setup to record new logs
                    try
                    {
                        Directory.CreateDirectory(MainV2.LogDir);
                        comPort.logfile = new BufferedStream(File.Open(MainV2.LogDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".tlog", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None));

                        comPort.rawlogfile = new BufferedStream(File.Open(MainV2.LogDir + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".rlog", FileMode.CreateNew, FileAccess.ReadWrite, FileShare.None));

                        log.Info("creating logfile " + DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".tlog");
                    }
                    catch (Exception exp2) { log.Error(exp2); CustomMessageBox.Show(Strings.Failclog); } // soft fail

                    // reset connect time - for timeout functions
                    connecttime = DateTime.Now;

                    // do the connect
                    comPort.Open(false);

                    if (!comPort.BaseStream.IsOpen)
                    {
                        log.Info("comport is closed. existing connect");
                        try
                        {
                            _connectionControl.IsConnected(false);
                            UpdateConnectIcon();
                            comPort.Close();
                        }
                        catch { }
                        return;
                    }

                    // 3dr radio is hidden as no hb packet is ever emitted
                    if (comPort.sysidseen.Count > 1)
                    {
                        // we have more than one mav
                        // user selection of sysid
                        MissionPlanner.Controls.SysidSelector id = new SysidSelector();

                        id.ShowDialog();
                    }

                    comPort.getParamList();
                    
                    //set hatch servo values based on parameter file -D Cironi 2015-03-02
                    if (comPort.MAV.cs.connected)
                    {
                        FlightData.servoOptions3.TXT_pwm_high.Text = comPort.GetParam("RC7_MAX").ToString();

                        FlightData.servoOptions3.TXT_pwm_low.Text = comPort.GetParam("RC7_MIN").ToString();
                    }
                    float i;
                    i = comPort.GetParam("SYSID_SW_TYPE");

                    // detect firmware we are conected to.
                    if (comPort.GetParam("SYSID_SW_TYPE") == 10)
                    {
                        _connectionControl.TOOL_APMFirmware.SelectedIndex = 2;
                     
                        CurrentUAV = UAVStats.setStats("IRIS+");
                    }

                        //!=any of our mavs 
                    else if (comPort.GetParam("SYSID_SW_TYPE") != 10 && comPort.GetParam("SYSID_SW_TYPE") != 2 && comPort.GetParam("SYSID_SW_TYPE") != 1 && comPort.GetParam("SYSID_SW_TYPE") != 0)
                    {
                        _connectionControl.TOOL_APMFirmware.SelectedIndex = 4;

                        CurrentUAV = UAVStats.setStats("E384");
                    }
                    else if (comPort.GetParam("SYSID_SW_TYPE") == 0)
                    {         
                        _connectionControl.TOOL_APMFirmware.SelectedIndex = 0;
                        CurrentUAV = UAVStats.setStats("E384");
                    }
                    else if (comPort.GetParam("SYSID_SW_TYPE") == 1)
                    {        
                        _connectionControl.TOOL_APMFirmware.SelectedIndex = 1;
                        CurrentUAV = UAVStats.setStats("E386");
                    }
                    else if (comPort.GetParam("SYSID_SW_TYPE") == 2)
                    {        
                        _connectionControl.TOOL_APMFirmware.SelectedIndex = 3;
                        CurrentUAV = UAVStats.setStats("Scout");
                    }
                    MainV2.config["CMB_Model"] = MainV2._connectionControl.TOOL_APMFirmware.SelectedIndex;
                    // check for newer firmware -Don't do this in our version -D Cironi 2015-05-13
                    //var softwares = Firmware.LoadSoftwares();

                    //if (softwares.Count > 0)
                    //{
                    //    try
                    //    {
                    //        string[] fields1 = comPort.MAV.VersionString.Split(' ');

                    //        foreach (Firmware.software item in softwares)
                    //        {
                    //            string[] fields2 = item.name.Split(' ');

                    //            // check primare firmware type. ie arudplane, arducopter
                    //            if (fields1[0] == fields2[0])
                    //            {
                    //                Version ver1 = VersionDetection.GetVersion(comPort.MAV.VersionString);
                    //                Version ver2 = VersionDetection.GetVersion(item.name);

                    //                if (ver2 > ver1)
                    //                {
                    //                    Common.MessageShowAgain(Strings.NewFirmware, Strings.NewFirmwareA + item.name + Strings.Pleaseup);
                    //                    break;
                    //                }

                    //                // check the first hit only
                    //                break;
                    //            }
                    //        }
                    //    }
                    //    catch (Exception ex) { log.Error(ex); }
                    //}

                    FlightData.CheckBatteryShow();
                    MissionPlanner.Utilities.Tracking.AddEvent("Connect", "Connect", comPort.MAV.cs.firmware.ToString(), comPort.MAV.param.Count.ToString());
                    MissionPlanner.Utilities.Tracking.AddTiming("Connect", "Connect Time", (DateTime.Now - connecttime).TotalMilliseconds, "");

                    MissionPlanner.Utilities.Tracking.AddEvent("Connect", "Baud", comPort.BaseStream.BaudRate.ToString(), "");

                    // save the baudrate for this port
                    config[_connectionControl.CMB_serialport.Text + "_BAUD"] = _connectionControl.CMB_baudrate.Text;

                    this.Text = titlebar + " " + comPort.MAV.VersionString;

                    // refresh config window if needed
                    if (MyView.current != null)
                    {
                        if (MyView.current.Name == "HWConfig")
                            MyView.ShowScreen("HWConfig");
                        if (MyView.current.Name == "SWConfig")
                            MyView.ShowScreen("SWConfig");
                    }


                    // load wps on connect option.
                    if (config["loadwpsonconnect"] != null && bool.Parse(config["loadwpsonconnect"].ToString()) == true)
                    {
                        // only do it if we are connected.
                        if (comPort.BaseStream.IsOpen)
                        {
                            MenuFlightPlanner_Click(null, null);
                            FlightPlanner.BUT_read_Click(null, null);
                        }
                    }

                    // set connected icon
                    this.MenuConnect.Image = displayicons.disconnect;
                }
                catch (Exception ex)
                {
                    log.Warn(ex);
                    try
                    {
                        _connectionControl.IsConnected(false);
                        UpdateConnectIcon();
                        comPort.Close();
                    }
                    catch { }
                    CustomMessageBox.Show("Can not establish a connection\n\n" + ex.Message);
                    return;
                }
            }
        }
コード例 #2
0
        public static UAVStats setStats(string uav)
        {
            UAVStats stats = new UAVStats();

            if (uav == "E384")
            {
                stats.batteryHigh              = 16.8;
                stats.batteryLow               = 14.2;
                stats.flightSpeedM             = 13;
                stats.flightSpeedF             = 42.65;
                stats.amphour                  = 134.4;
                stats.landwp                   = 6;
                stats.firmware                 = "E384";
                stats.flighttime               = 60;
                stats.resumealt                = 80;
                stats.gpslanding               = true;
                stats.autoland                 = false;
                stats.resumeMission            = false;
                stats.runway                   = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane;
            }
            else if (uav == "IRIS+")
            {
                stats.batteryHigh              = 12.6;
                stats.batteryLow               = 11.2;
                stats.flightSpeedM             = 5;
                stats.flightSpeedF             = 16.4;
                stats.landwp                   = 1;
                stats.firmware                 = "Iris";
                stats.flighttime               = 15;
                stats.resumealt                = 60;
                stats.gpslanding               = true;
                stats.autoland                 = true;
                stats.resumeMission            = true;
                stats.amphour                  = 5100;
                stats.runway                   = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduCopter2;
            }
            else if (uav == "E386")
            {
                stats.batteryHigh              = 16.8;
                stats.batteryLow               = 14.2;
                stats.flightSpeedM             = 13;
                stats.flightSpeedF             = 42.65;
                stats.landwp                   = 5;
                stats.firmware                 = "E386";
                stats.flighttime               = 60;
                stats.resumealt                = 80;
                stats.amphour                  = 134.4;
                stats.gpslanding               = true;
                stats.autoland                 = true;
                stats.resumeMission            = true;
                stats.runway                   = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane;
            }
            else if (uav == "Scout")
            {
                stats.batteryHigh              = 12.6;
                stats.batteryLow               = 11.2;
                stats.flightSpeedM             = 13;
                stats.flightSpeedF             = 42.65;
                stats.landwp                   = 5;
                stats.firmware                 = "Scout";
                stats.flighttime               = 30;
                stats.resumealt                = 80;
                stats.amphour                  = 56.61;
                stats.gpslanding               = true;
                stats.autoland                 = true;
                stats.resumeMission            = true;
                stats.runway                   = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane;
            }
            else if (uav == "Other")
            {
                stats.batteryHigh   = 0;
                stats.batteryLow    = 0;
                stats.flightSpeedM  = 0;
                stats.flightSpeedF  = 0;
                stats.resumealt     = 0;
                stats.firmware      = "ArduRover";
                stats.flighttime    = 0;
                stats.amphour       = 0;
                stats.gpslanding    = false;
                stats.autoland      = false;
                stats.resumeMission = false;
                stats.runway        = false;
            }


            return(stats);
        }
コード例 #3
0
ファイル: MainV2.cs プロジェクト: Event38/MissionPlanner
 private void TOOL_APMFirmware_SelectedIndexChanged(object sender, EventArgs e)
 { 
         MainV2.CurrentUAV = UAVStats.setStats(_connectionControl.TOOL_APMFirmware.SelectedItem.ToString());
         MainV2.config["CMB_Model"] = MainV2._connectionControl.TOOL_APMFirmware.SelectedIndex;
     }
コード例 #4
0
ファイル: UAVStats.cs プロジェクト: Event38/MissionPlanner
        public static UAVStats setStats(string uav)
        {
            UAVStats stats = new UAVStats();
            if (uav == "E384")
            {
                stats.batteryHigh = 16.8;
                stats.batteryLow = 14.2;
                stats.flightSpeedM = 13;
                stats.flightSpeedF = 42.65;
                stats.amphour = 134.4;
                stats.landwp = 6;
                stats.firmware = "E384";
                stats.flighttime = 60;
                stats.resumealt = 80;
                stats.gpslanding = true;
                stats.autoland = false;
                stats.resumeMission = false;
                stats.runway = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane;               
            }
            else if (uav == "IRIS+")
            {
                stats.batteryHigh = 12.6;
                stats.batteryLow = 11.2;
                stats.flightSpeedM = 5;
                stats.flightSpeedF = 16.4;
                stats.landwp = 1;
                stats.firmware = "Iris";
                stats.flighttime = 15;
                stats.resumealt = 60;
                stats.gpslanding = true;
                stats.autoland = true;
                stats.resumeMission = true;
                stats.amphour = 5100;
                stats.runway = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduCopter2;               

            }
            else if (uav == "E386")
            {
                stats.batteryHigh = 16.8;
                stats.batteryLow = 14.2;
                stats.flightSpeedM = 13;
                stats.flightSpeedF = 42.65;
                stats.landwp = 5;
                stats.firmware = "E386";
                stats.flighttime = 60;
                stats.resumealt = 80;
                stats.amphour = 134.4;
                stats.gpslanding = true;
                stats.autoland = true;
                stats.resumeMission = true;
                stats.runway = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane;               
            }
            else if (uav == "Scout")
            {
                stats.batteryHigh = 12.6;
                stats.batteryLow = 11.2;
                stats.flightSpeedM = 13;
                stats.flightSpeedF = 42.65;
                stats.landwp = 5;
                stats.firmware = "Scout";
                stats.flighttime = 30;
                stats.resumealt = 80;
                stats.amphour = 56.61;
                stats.gpslanding = true;
                stats.autoland = true;
                stats.resumeMission = true;
                stats.runway = true;
                MainV2.comPort.MAV.cs.firmware = MainV2.Firmwares.ArduPlane;               
            }
            else if (uav == "Other")
            {
                stats.batteryHigh = 0;
                stats.batteryLow = 0;
                stats.flightSpeedM = 0;
                stats.flightSpeedF = 0;
                stats.resumealt = 0;
                stats.firmware = "ArduRover";
                stats.flighttime = 0;
                stats.amphour = 0;
                stats.gpslanding = false;
                stats.autoland = false;
                stats.resumeMission = false;
                stats.runway = false;
            }
         

            return stats;
        }