protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
        {
            if (keyData == (Keys.Control | Keys.B))
            {
                findfirmware("AP-trunk");
                return(true);
            }
            if (keyData == (Keys.Control | Keys.A))
            {
                findfirmware("AC2-QUADHIL");
                return(true);
            }

            if (keyData == (Keys.Control | Keys.C))
            {
                OpenFileDialog fd = new OpenFileDialog();
                fd.Filter = "Firmware (*.hex)|*.hex";
                fd.ShowDialog();
                if (File.Exists(fd.FileName))
                {
                    UploadFlash(fd.FileName, ArduinoDetect.DetectBoard(MainV2.comportname));
                }
                return(true);
            }
            return(base.ProcessCmdKey(ref msg, keyData));
        }
        //Load custom firmware (old CTRL+C shortcut)
        private void Custom_firmware_label_Click(object sender, EventArgs e)
        {
            var fd = new OpenFileDialog {
                Filter = "Firmware (*.hex;*.px4)|*.hex;*.px4"
            };

            fd.ShowDialog();
            if (File.Exists(fd.FileName))
            {
                fw.Progress -= fw_Progress;
                fw.Progress += fw_Progress1;

                string boardtype = "";
                try
                {
                    boardtype = ArduinoDetect.DetectBoard(MainV2.comPortName);
                }
                catch
                {
                    CustomMessageBox.Show("Can not connect to com port and detect board type", "Error");
                    return;
                }

                fw.UploadFlash(MainV2.comPortName, fd.FileName, boardtype);
            }
        }
Exemple #3
0
        //Load custom firmware (old CTRL+C shortcut)
        private void Custom_firmware_label_Click(object sender, EventArgs e)
        {
            var fd = new OpenFileDialog {
                Filter = "Firmware (*.hex)|*.hex"
            };

            fd.ShowDialog();
            if (File.Exists(fd.FileName))
            {
                UploadFlash(fd.FileName, ArduinoDetect.DetectBoard(MainV2.comPortName));
            }
        }
Exemple #4
0
 protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
 {
     if (keyData == (Keys.Control | Keys.C))
     {
         var fd = new OpenFileDialog {
             Filter = "Firmware (*.hex)|*.hex"
         };
         fd.ShowDialog();
         if (File.Exists(fd.FileName))
         {
             UploadFlash(fd.FileName, ArduinoDetect.DetectBoard(MainV2.comPortName));
         }
         return(true);
     }
     return(base.ProcessCmdKey(ref msg, keyData));
 }
Exemple #5
0
        /// <summary>
        /// Do full update - get firmware from internet
        /// </summary>
        /// <param name="temp"></param>
        /// <param name="historyhash"></param>
        public bool update(string comport, software temp)
        {
            string board = "";

            try
            {
                updateProgress(-1, "Detecting APM Version");

                board = ArduinoDetect.DetectBoard(comport);

                if (board == "")
                {
                    CustomMessageBox.Show("Cant detect your APM version. Please check your cabling");
                    return(false);
                }

                int apmformat_version = -1; // fail continue

                if (board != "px4")
                {
                    try
                    {
                        apmformat_version = ArduinoDetect.decodeApVar(comport, board);
                    }
                    catch { }

                    if (apmformat_version != -1 && apmformat_version != temp.k_format_version)
                    {
                        if (DialogResult.No == CustomMessageBox.Show("Epprom changed, all your setting will be lost during the update,\nDo you wish to continue?", "Epprom format changed (" + apmformat_version + " vs " + temp.k_format_version + ")", MessageBoxButtons.YesNo))
                        {
                            CustomMessageBox.Show("Please connect and backup your config in the configuration tab.");
                            return(false);
                        }
                    }
                }


                log.Info("Detected a " + board);

                updateProgress(-1, "Detected a " + board);

                string baseurl = "";
                if (board == "2560")
                {
                    baseurl = temp.url2560.ToString();
                }
                else if (board == "1280")
                {
                    baseurl = temp.url.ToString();
                }
                else if (board == "2560-2")
                {
                    baseurl = temp.url2560_2.ToString();
                }
                else if (board == "px4")
                {
                    baseurl = temp.urlpx4.ToString();
                }
                else
                {
                    CustomMessageBox.Show("Invalid Board Type");
                    return(false);
                }

                log.Info("Using " + baseurl);

                // Create a request using a URL that can receive a post.
                WebRequest request = WebRequest.Create(baseurl);
                request.Timeout = 10000;
                // Set the Method property of the request to POST.
                request.Method = "GET";
                // Get the request stream.
                Stream dataStream; //= request.GetRequestStream();
                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                log.Info(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();

                long bytes   = response.ContentLength;
                long contlen = bytes;

                byte[] buf1 = new byte[1024];

                FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create);

                updateProgress(0, "Downloading from Internet");

                dataStream.ReadTimeout = 30000;

                while (dataStream.CanRead)
                {
                    try
                    {
                        updateProgress(50, "Downloading from Internet");
                    }
                    catch { }
                    int len = dataStream.Read(buf1, 0, 1024);
                    if (len == 0)
                    {
                        break;
                    }
                    bytes -= len;
                    fs.Write(buf1, 0, len);
                }

                fs.Close();
                dataStream.Close();
                response.Close();

                updateProgress(100, "Downloaded from Internet");
                log.Info("Downloaded");
            }
            catch (Exception ex) { updateProgress(50, "Failed download"); CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return(false); }

            System.Threading.ThreadPool.QueueUserWorkItem(apmtype, temp.name + "!" + board);

            MissionPlanner.Utilities.Tracking.AddFW(temp.name, board);

            return(UploadFlash(comport, Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board));
        }
Exemple #6
0
        private void update(software temp)
        {
            string board = "";

            MainV2.comPort.BaseStream.DtrEnable = false;
            MainV2.comPort.Close();
            System.Threading.Thread.Sleep(100);
            MainV2.comPort.giveComport = true;

            try
            {
                if (softwares.Count == 0)
                {
                    CustomMessageBox.Show("No valid options");
                    return;
                }

                lbl_status.Text = "Detecting APM Version";

                this.Refresh();
                Application.DoEvents();

                /*
                 * ArdupilotMega.Controls.Firmware_Board fwb = new ArdupilotMega.Controls.Firmware_Board();
                 * fwb.ShowDialog();
                 *
                 * var boardname = ArdupilotMega.Controls.Firmware_Board.fw;
                 *
                 * switch (boardname)
                 * {
                 *  case ArdupilotMega.Controls.Firmware_Board.Firmware.apm1:
                 *      board = "2560";
                 *      break;
                 *  case ArdupilotMega.Controls.Firmware_Board.Firmware.apm2:
                 *      board = "2560-2";
                 *      break;
                 *  case ArdupilotMega.Controls.Firmware_Board.Firmware.apm2_5:
                 *      board = "2560-2";
                 *      break;
                 *  case ArdupilotMega.Controls.Firmware_Board.Firmware.px4:
                 *      board = "px4";
                 *      break;
                 * }
                 */
                board = ArduinoDetect.DetectBoard(MainV2.comPortName);

                if (board == "")
                {
                    CustomMessageBox.Show("Cant detect your APM version. Please check your cabling");
                    return;
                }

                int apmformat_version = -1; // fail continue

                if (board != "px4")
                {
                    try
                    {
                        apmformat_version = ArduinoDetect.decodeApVar(MainV2.comPortName, board);
                    }
                    catch { }

                    if (apmformat_version != -1 && apmformat_version != temp.k_format_version)
                    {
                        if (DialogResult.No == CustomMessageBox.Show("Epprom changed, all your setting will be lost during the update,\nDo you wish to continue?", "Epprom format changed (" + apmformat_version + " vs " + temp.k_format_version + ")", MessageBoxButtons.YesNo))
                        {
                            CustomMessageBox.Show("Please connect and backup your config in the configuration tab.");
                            return;
                        }
                    }
                }


                log.Info("Detected a " + board);

                string baseurl = "";
                if (board == "2560")
                {
                    baseurl = temp.url2560.ToString();
                }
                else if (board == "1280")
                {
                    baseurl = temp.url.ToString();
                }
                else if (board == "2560-2")
                {
                    baseurl = temp.url2560_2.ToString();
                }
                else if (board == "px4")
                {
                    baseurl = temp.urlpx4.ToString();
                }
                else
                {
                    CustomMessageBox.Show("Invalid Board Type");
                    return;
                }

                // use the git-history url
                if (CMB_history.Visible == true)
                {
                    baseurl = getUrl(CMB_history.Text, baseurl);
                }

                log.Info("Using " + baseurl);

                // Create a request using a URL that can receive a post.
                WebRequest request = WebRequest.Create(baseurl);
                request.Timeout = 10000;
                // Set the Method property of the request to POST.
                request.Method = "GET";
                // Get the request stream.
                Stream dataStream; //= request.GetRequestStream();
                // Get the response.
                WebResponse response = request.GetResponse();
                // Display the status.
                log.Info(((HttpWebResponse)response).StatusDescription);
                // Get the stream containing content returned by the server.
                dataStream = response.GetResponseStream();

                long bytes   = response.ContentLength;
                long contlen = bytes;

                byte[] buf1 = new byte[1024];

                FileStream fs = new FileStream(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", FileMode.Create);

                lbl_status.Text = "Downloading from Internet";

                this.Refresh();
                Application.DoEvents();

                dataStream.ReadTimeout = 30000;

                while (dataStream.CanRead)
                {
                    try
                    {
                        progress.Value = 50;// (int)(((float)(response.ContentLength - bytes) / (float)response.ContentLength) * 100);
                        this.progress.Refresh();
                    }
                    catch { }
                    int len = dataStream.Read(buf1, 0, 1024);
                    if (len == 0)
                    {
                        break;
                    }
                    bytes -= len;
                    fs.Write(buf1, 0, len);
                }

                fs.Close();
                dataStream.Close();
                response.Close();

                progress.Value = 100;
                this.Refresh();
                Application.DoEvents();
                log.Info("Downloaded");
            }
            catch (Exception ex) { lbl_status.Text = "Failed download"; CustomMessageBox.Show("Failed to download new firmware : " + ex.ToString()); return; }

            System.Threading.ThreadPool.QueueUserWorkItem(apmtype, temp.name + "!" + board);

            UploadFlash(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + @"firmware.hex", board);
        }