示例#1
0
        internal void Firmware_Load(object sender, EventArgs e)
        {
            ProgressReporterDialogue pdr = new ArdupilotMega.Controls.ProgressReporterDialogue();

            pdr.DoWork += pdr_DoWork;

            pdr.UpdateProgressAndStatus(-1, "Getting Firmware List");

            ThemeManager.ApplyThemeTo(pdr);

            pdr.RunBackgroundOperationAsync();
        }
示例#2
0
        public void StartCalibration()
        {
            ArdupilotMega.Controls.ProgressReporterDialogue prd = new ArdupilotMega.Controls.ProgressReporterDialogue()
            {
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                Text          = "Compass Mot"
            };

            prd.DoWork += DoCalibration;

            prd.RunBackgroundOperationAsync();
        }
示例#3
0
        internal void Firmware_Load(object sender, EventArgs e)
        {
            pdr = new ProgressReporterDialogue();

            pdr.DoWork -= pdr_DoWork;

            pdr.DoWork += pdr_DoWork;

            ThemeManager.ApplyThemeTo(pdr);

            pdr.RunBackgroundOperationAsync();
        }
示例#4
0
        public void StartCalibration()
        {
            ArdupilotMega.Controls.ProgressReporterDialogue prd = new ArdupilotMega.Controls.ProgressReporterDialogue()
            {
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                Text = "Compass Mot"
            };

            prd.DoWork += DoCalibration;

            prd.RunBackgroundOperationAsync();
        }
示例#5
0
        private void BUT_MagCalibration_Click(object sender, EventArgs e)
        {
            CustomMessageBox.Show("Data will be collected for 60 seconds, Please click ok and move the apm around all axises");

            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            Utilities.ThemeManager.ApplyThemeTo(prd);

            prd.DoWork += prd_DoWork;

            prd.RunBackgroundOperationAsync();
        }
示例#6
0
        public int WizardValidate()
        {
            comport = CMB_port.Text;

            pdr = new ProgressReporterDialogue();

            pdr.DoWork -= pdr_DoWork;

            pdr.DoWork += pdr_DoWork;

            ThemeManager.ApplyThemeTo(pdr);

            pdr.RunBackgroundOperationAsync();

            MainV2.comPort.BaseStream.BaudRate = 115200;
            MainV2.comPort.BaseStream.PortName = comport;

            MainV2.comPort.Open(true);

            if (!MainV2.comPort.BaseStream.IsOpen)
                return 0;

            if (string.IsNullOrEmpty(pdr.doWorkArgs.ErrorMessage))
            {
                if (Wizard.config["fwtype"].ToString() == "copter")
                    // check if its a quad, and show the frame type screen
                    return 1;
                else
                    // skip the frame type screen as its not valid for anythine else
                    return 2;
            }

            return 0;
        }
示例#7
0
        internal void Firmware_Load(object sender, EventArgs e)
        {
            ProgressReporterDialogue pdr = new ArdupilotMega.Controls.ProgressReporterDialogue();

            pdr.DoWork += pdr_DoWork;

            pdr.UpdateProgressAndStatus(-1,"Getting Firmware List");

            ThemeManager.ApplyThemeTo(pdr);

            pdr.RunBackgroundOperationAsync();
        }
示例#8
0
        static void GetNewFile(ProgressReporterDialogue frmProgressReporter, string baseurl, string subdir, string file)
        {
            // create dest dir
            string dir = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir;
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            // get dest path
            string path = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir + file;

            Exception fail = null;
            int attempt = 0;

            // attempt to get file
            while (attempt < 2)
            {
                // check if user canceled
                if (frmProgressReporter.doWorkArgs.CancelRequested)
                {
                    frmProgressReporter.doWorkArgs.CancelAcknowledged = true;
                    throw new Exception("Cancel");
                }

                try
                {

                    // Create a request using a URL that can receive a post.
                    WebRequest request = WebRequest.Create(baseurl + file);
                    log.Info("get "+baseurl + file + " ");
                    // Set the Method property of the request to GET.
                    request.Method = "GET";
                    // Allow compressed content
                    ((HttpWebRequest)request).AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
                    // tell server we allow compress content
                    request.Headers.Add("Accept-Encoding", "gzip,deflate");
                    // Get the response.
                    WebResponse response = request.GetResponse();
                    // Display the status.
                    log.Info(((HttpWebResponse)response).StatusDescription);
                    // Get the stream containing content returned by the server.
                    Stream dataStream = response.GetResponseStream();

                    // update status
                    if (frmProgressReporter != null)
                        frmProgressReporter.UpdateProgressAndStatus(-1, "Getting " + file);

                    // from head
                    long bytes = response.ContentLength;

                    long contlen = bytes;

                    byte[] buf1 = new byte[4096];

                    using (FileStream fs = new FileStream(path + ".new", FileMode.Create))
                    {

                        DateTime dt = DateTime.Now;

                        while (dataStream.CanRead)
                        {
                            try
                            {
                                if (dt.Second != DateTime.Now.Second)
                                {
                                    if (frmProgressReporter != null)
                                        frmProgressReporter.UpdateProgressAndStatus((int)(((double)(contlen - bytes) / (double)contlen) * 100), "Getting " + file + ": " + (((double)(contlen - bytes) / (double)contlen) * 100).ToString("0.0") + "%"); //+ Math.Abs(bytes) + " bytes");
                                    dt = DateTime.Now;
                                }
                            }
                            catch { }
                            log.Debug(file + " " + bytes);
                            int len = dataStream.Read(buf1, 0, buf1.Length);
                            if (len == 0)
                                break;
                            bytes -= len;
                            fs.Write(buf1, 0, len);
                        }
                        fs.Close();
                    }

                    response.Close();

                }
                catch (Exception ex) { fail = ex; attempt++; continue; }

                // break if we have no exception
                break;
            }

            if (attempt == 2)
            {
                throw fail;
            }
        }
示例#9
0
        static void CheckMD5(ProgressReporterDialogue frmProgressReporter, string url)
        {
            var baseurl = ConfigurationManager.AppSettings["UpdateLocation"];

            WebRequest request = WebRequest.Create(url);
            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();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();

            Regex regex = new Regex(@"([^\s]+)\s+upgrade/(.*)", RegexOptions.IgnoreCase);

            if (regex.IsMatch(responseFromServer))
            {
                MatchCollection matchs = regex.Matches(responseFromServer);
                for (int i = 0; i < matchs.Count; i++)
                {
                    string hash = matchs[i].Groups[1].Value.ToString();
                    string file = matchs[i].Groups[2].Value.ToString();

                    if (file.ToLower().EndsWith(".etag"))
                        continue;

                    if (!MD5File(file, hash))
                    {
                        log.Info("Newer File " + file);

                        if (frmProgressReporter != null)
                            frmProgressReporter.UpdateProgressAndStatus(-1, "Getting " + file);

                        string subdir = Path.GetDirectoryName(file) + Path.DirectorySeparatorChar;

                        GetNewFile(frmProgressReporter, baseurl + subdir.Replace('\\','/'), subdir, Path.GetFileName(file));
                    }
                    else
                    {
                        log.Info("Same File " + file);

                        if (frmProgressReporter != null)
                            frmProgressReporter.UpdateProgressAndStatus(-1, "Checking " + file);
                    }
                }
            }
        }
示例#10
0
        public static void updateCheckMain(ProgressReporterDialogue frmProgressReporter)
        {
            try
            {
                CheckMD5(frmProgressReporter, ConfigurationManager.AppSettings["UpdateLocationMD5"].ToString());

                var process = new Process();
                string exePath = Path.GetDirectoryName(Application.ExecutablePath);
                if (MONO)
                {
                    process.StartInfo.FileName = "mono";
                    process.StartInfo.Arguments = " \"" + exePath + Path.DirectorySeparatorChar + "Updater.exe\"" + "  \"" + Application.ExecutablePath + "\"";
                }
                else
                {
                    process.StartInfo.FileName = exePath + Path.DirectorySeparatorChar + "Updater.exe";
                    process.StartInfo.Arguments = Application.ExecutablePath;
                }

                try
                {
                    foreach (string newupdater in Directory.GetFiles(exePath, "Updater.exe*.new"))
                    {
                        File.Copy(newupdater, newupdater.Remove(newupdater.Length - 4), true);
                        File.Delete(newupdater);
                    }
                }
                catch (Exception ex)
                {
                    log.Error("Exception during update", ex);
                }
                if (frmProgressReporter != null)
                    frmProgressReporter.UpdateProgressAndStatus(-1, "Starting Updater");
                log.Info("Starting new process: " + process.StartInfo.FileName + " with " + process.StartInfo.Arguments);
                process.Start();
                log.Info("Quitting existing process");
                try
                {
                    // clean close
                    MainV2.instance.BeginInvoke((MethodInvoker)delegate()
                    {
                        MainV2.instance.Close();
                    });
                }
                catch (Exception ex)
                {
                    log.Error(ex);
                    Application.Exit();
                }
            }
            catch (Exception ex)
            {
                log.Error("Update Failed", ex);
                CustomMessageBox.Show("Update Failed " + ex.Message);
            }
        }
示例#11
0
        public static void DoUpdate()
        {
            ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue()
            {
                Text = "Check for Updates",
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
            };

            ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.DoWork += new Controls.ProgressReporterDialogue.DoWorkEventHandler(DoUpdateWorker_DoWork);

            frmProgressReporter.UpdateProgressAndStatus(-1, "Checking for Updates");

            frmProgressReporter.RunBackgroundOperationAsync();
        }
示例#12
0
        public void Open(bool getparams)
        {
            if (BaseStream.IsOpen)
                return;

            frmProgressReporter = new ProgressReporterDialogue
                                      {
                                          StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                                          Text = "Hubungkan dengan satelit"
                                      };

            if (getparams)
            {
                frmProgressReporter.DoWork += FrmProgressReporterDoWorkAndParams;
            }
            else
            {
                frmProgressReporter.DoWork += FrmProgressReporterDoWorkNOParams;
            }
            frmProgressReporter.UpdateProgressAndStatus(-1, "Terhubung dengan satelit...");
            ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.RunBackgroundOperationAsync();

            if (ParamListChanged != null)
            {
                ParamListChanged(this,null);
            }
        }
示例#13
0
        /*
        public Bitmap getImage()
        {
            MemoryStream ms = new MemoryStream();

        }
        */
        public void getParamList()
        {
            frmProgressReporter = new ProgressReporterDialogue
            {
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                Text = "Getting Params"
            };

            frmProgressReporter.DoWork += FrmProgressReporterGetParams;
            frmProgressReporter.UpdateProgressAndStatus(-1, "Getting Params...");
            ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.RunBackgroundOperationAsync();

            if (ParamListChanged != null)
            {
                ParamListChanged(this, null);
            }
        }
示例#14
0
        public void Open(bool getparams)
        {
            if (BaseStream.IsOpen)
                return;

            frmProgressReporter = new ProgressReporterDialogue
                                      {
                                          StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                                          Text = "Connecting Mavlink"
                                      };

            if (getparams)
            {
                frmProgressReporter.DoWork += FrmProgressReporterDoWorkAndParams;
            }
            else
            {
                frmProgressReporter.DoWork += FrmProgressReporterDoWorkNOParams;
            }
            frmProgressReporter.UpdateProgressAndStatus(-1, "Mavlink Connecting...");
            ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.RunBackgroundOperationAsync();
        }
示例#15
0
        private void BUT_MagCalibration_Click(object sender, EventArgs e)
        {
            MainV2.comPort.MAV.cs.ratesensors = 2;

            MainV2.comPort.requestDatastream(ArdupilotMega.MAVLink.MAV_DATA_STREAM.EXTRA3, MainV2.comPort.MAV.cs.ratesensors);
            MainV2.comPort.requestDatastream(ArdupilotMega.MAVLink.MAV_DATA_STREAM.RAW_SENSORS, MainV2.comPort.MAV.cs.ratesensors);

            MainV2.comPort.setParam("MAG_ENABLE", 1);

            CustomMessageBox.Show("Data will be collected for 60 seconds, Please click ok and move the apm around all axises");

            ProgressReporterDialogue prd = new ProgressReporterDialogue();

            Utilities.ThemeManager.ApplyThemeTo(prd);

            prd.DoWork += prd_DoWork;

            prd.RunBackgroundOperationAsync();
        }
示例#16
0
        private static bool updateCheck(ProgressReporterDialogue frmProgressReporter, string baseurl, string subdir)
        {
            bool update = false;
            List<string> files = new List<string>();

            // Create a request using a URL that can receive a post.
            log.Info(baseurl);
            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();
            // Open the stream using a StreamReader for easy access.
            StreamReader reader = new StreamReader(dataStream);
            // Read the content.
            string responseFromServer = reader.ReadToEnd();
            // Display the content.
            Regex regex = new Regex("href=\"([^\"]+)\"", RegexOptions.IgnoreCase);

            Uri baseuri = new Uri(baseurl, UriKind.Absolute);

            if (regex.IsMatch(responseFromServer))
            {
                MatchCollection matchs = regex.Matches(responseFromServer);
                for (int i = 0; i < matchs.Count; i++)
                {
                    if (matchs[i].Groups[1].Value.ToString().Contains(".."))
                        continue;
                    if (matchs[i].Groups[1].Value.ToString().Contains("http"))
                        continue;
                    if (matchs[i].Groups[1].Value.ToString().StartsWith("?"))
                        continue;
                    if (matchs[i].Groups[1].Value.ToString().ToLower().Contains(".etag"))
                        continue;

                    //
                    {
                        string url = System.Web.HttpUtility.UrlDecode(matchs[i].Groups[1].Value.ToString());
                        Uri newuri = new Uri(baseuri, url);
                        files.Add(baseuri.MakeRelativeUri(newuri).ToString());
                    }

                    // dirs
                    if (matchs[i].Groups[1].Value.ToString().Contains("tree/master/"))
                    {
                        string url = System.Web.HttpUtility.UrlDecode(matchs[i].Groups[1].Value.ToString()) + "/";
                        Uri newuri = new Uri(baseuri, url);
                        files.Add(baseuri.MakeRelativeUri(newuri).ToString());

                    }
                    // files
                    if (matchs[i].Groups[1].Value.ToString().Contains("blob/master/"))
                    {
                        string url = System.Web.HttpUtility.UrlDecode(matchs[i].Groups[1].Value.ToString());
                        Uri newuri = new Uri(baseuri, url);
                        files.Add(System.Web.HttpUtility.UrlDecode(newuri.Segments[newuri.Segments.Length - 1]));
                    }
                }
            }

            //Console.WriteLine(responseFromServer);
            // Clean up the streams.
            reader.Close();
            dataStream.Close();
            response.Close();

            string dir = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir;
            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);
            foreach (string file in files)
            {
                if (frmProgressReporter.doWorkArgs.CancelRequested)
                {
                    frmProgressReporter.doWorkArgs.CancelAcknowledged = true;
                    throw new Exception("Cancel");
                }

                if (file.Equals("/") || file.Equals("") || file.StartsWith("../"))
                {
                    continue;
                }
                if (file.EndsWith("/"))
                {
                    update = updateCheck(frmProgressReporter, baseurl + file, subdir.Replace('/', Path.DirectorySeparatorChar) + file) && update;
                    continue;
                }
                if (frmProgressReporter != null)
                    frmProgressReporter.UpdateProgressAndStatus(-1, "Checking " + file);

                string path = Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + subdir + file;

             //   baseurl = baseurl.Replace("//github.com", "//raw.github.com");
             //   baseurl = baseurl.Replace("/tree/", "/");

                Exception fail = null;
                int attempt = 0;

                while (attempt < 2)
                {

                    try
                    {

                        // Create a request using a URL that can receive a post.
                        request = WebRequest.Create(baseurl + file);
                        log.Info(baseurl + file + " ");
                        // Set the Method property of the request to POST.
                        request.Method = "GET";

                        ((HttpWebRequest)request).AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

                        request.Headers.Add("Accept-Encoding", "gzip,deflate");

                        // Get the response.
                        response = request.GetResponse();
                        // Display the status.
                        log.Info(((HttpWebResponse)response).StatusDescription);
                        // Get the stream containing content returned by the server.
                        dataStream = response.GetResponseStream();
                        // Open the stream using a StreamReader for easy access.

                        bool updateThisFile = false;

                        if (File.Exists(path))
                        {
                            FileInfo fi = new FileInfo(path);

                            //log.Info(response.Headers[HttpResponseHeader.ETag]);
                            string CurrentEtag = "";

                            if (File.Exists(path + ".etag"))
                            {
                                using (Stream fs = File.OpenRead(path + ".etag"))
                                {
                                    using (StreamReader sr = new StreamReader(fs))
                                    {
                                        CurrentEtag = sr.ReadLine();
                                        sr.Close();
                                    }
                                    fs.Close();
                                }
                            }

                            log.Debug("New file Check: " + fi.Length + " vs " + response.ContentLength + " " + response.Headers[HttpResponseHeader.ETag] + " vs " + CurrentEtag);

                            if (fi.Length != response.ContentLength || response.Headers[HttpResponseHeader.ETag] != CurrentEtag)
                            {
                                using (StreamWriter sw = new StreamWriter(path + ".etag.new"))
                                {
                                    sw.WriteLine(response.Headers[HttpResponseHeader.ETag]);
                                    sw.Close();
                                }
                                updateThisFile = true;
                                log.Info("NEW FILE " + file);
                            }
                        }
                        else
                        {
                            updateThisFile = true;
                            log.Info("NEW FILE " + file);
                            using (StreamWriter sw = new StreamWriter(path + ".etag.new"))
                            {
                                sw.WriteLine(response.Headers[HttpResponseHeader.ETag]);
                                sw.Close();
                            }
                            // get it
                        }

                        if (updateThisFile)
                        {
                            if (!update)
                            {
                                //DialogResult dr = MessageBox.Show("Update Found\n\nDo you wish to update now?", "Update Now", MessageBoxButtons.YesNo);
                                //if (dr == DialogResult.Yes)
                                {
                                    update = true;
                                }
                                //else
                                {
                                    //    return;
                                }
                            }
                            if (frmProgressReporter != null)
                                frmProgressReporter.UpdateProgressAndStatus(-1, "Getting " + file);

                            // from head
                            long bytes = response.ContentLength;

                            long contlen = bytes;

                            byte[] buf1 = new byte[4096];

                            using (FileStream fs = new FileStream(path + ".new", FileMode.Create))
                            {

                                DateTime dt = DateTime.Now;

                                //dataStream.ReadTimeout = 30000;

                                while (dataStream.CanRead)
                                {
                                    try
                                    {
                                        if (dt.Second != DateTime.Now.Second)
                                        {
                                            if (frmProgressReporter != null)
                                                frmProgressReporter.UpdateProgressAndStatus((int)(((double)(contlen - bytes) / (double)contlen) * 100), "Getting " + file + ": " + (((double)(contlen - bytes) / (double)contlen) * 100).ToString("0.0") + "%"); //+ Math.Abs(bytes) + " bytes");
                                            dt = DateTime.Now;
                                        }
                                    }
                                    catch { }
                                    log.Debug(file + " " + bytes);
                                    int len = dataStream.Read(buf1, 0, buf1.Length);
                                    if (len == 0)
                                        break;
                                    bytes -= len;
                                    fs.Write(buf1, 0, len);
                                }
                                fs.Close();
                            }
                        }

                        reader.Close();
                        //dataStream.Close();
                        response.Close();

                    }
                    catch (Exception ex) { fail = ex; attempt++; update = false; continue; }

                    // break if we have no exception
                    break;
                }

                if (attempt == 2)
                {
                    throw fail;
                }
            }

            //P.StartInfo.CreateNoWindow = true;
            //P.StartInfo.RedirectStandardOutput = true;
            return update;
        }
        public void Open()
        {
            if (client.Client.Connected)
            {
                log.Info("udpserial socket already open");
                return;
            }

            ProgressReporterDialogue frmProgressReporter = new ProgressReporterDialogue
            {
                StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen,
                Text = "Connecting Mavlink UDP"
            };

            frmProgressReporter.DoWork += frmProgressReporter_DoWork;

            frmProgressReporter.UpdateProgressAndStatus(-1, "Connecting Mavlink UDP");

            ArdupilotMega.Utilities.ThemeManager.ApplyThemeTo(frmProgressReporter);

            frmProgressReporter.RunBackgroundOperationAsync();
        }
示例#18
0
        internal void Firmware_Load(object sender, EventArgs e)
        {
            // if (softwares.Count == 0)
            {
                ProgressReporterDialogue pdr = new ArdupilotMega.Controls.ProgressReporterDialogue();

                pdr.DoWork += pdr_DoWork;

                pdr.UpdateProgressAndStatus(-1, "Getting Firmware List");

                ThemeManager.ApplyThemeTo(pdr);

                pdr.RunBackgroundOperationAsync();
            }
              //  else
            {
              //  foreach (var temp in softwares)
              //  {
              //      updateDisplayNameInvoke(temp);
              //  }
            }
        }