Example #1
0
 private void downloadBackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
 {
     if (this.highDownloadSpeed)
     {
         this.status = this.rs232comms.setVMUBaudrate(this.currentPort, 9600);
         if (this.status == COMMS_STATUS.OKAY)
         {
             this.highDownloadSpeed = false;
         }
     }
     this.toolStripProgressBar1.Value = 0;
     setProgressBarParms(ProgressBarStyle.Blocks, false);
     this.toolStripStatusLabel1.Text = "Done";
     this.listView1.Enabled          = true;
     setEnable(true);
     foreach (ListViewItem item in this.listView1.Items)
     {
         if (item.Checked)
         {
             item.Checked = false;
         }
     }
     if (e.Cancelled)
     {
         MessageBox.Show("Download Cancelled!", "", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
     else
     {
         MessageBox.Show("Download Complete", "", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
Example #2
0
        private void btnClearData_Click(object sender, EventArgs e)
        {
            DialogResult res = MessageBox.Show("All the Data will be erased!\nDo you want to proceed?", "",
                                               MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (res == DialogResult.No)
            {
                return;
            }
            if (res == DialogResult.Yes)
            {
                this.status = this.rs232comms.eraseFlash(this.currentPort);
            }
        }
Example #3
0
        private void downloadBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;
            string           path   = (string)e.Argument;
            string           fname  = "";

            if (worker.CancellationPending)
            {
                e.Cancel = true; return;
            }
            byte[] temp = new byte[this.frameSize];

            int    totalBlocks       = this.selectedBlocks.Count;
            int    totalFramesToRead = this.framesPerBlock * totalBlocks;
            double p = 0.0;

            for (int i = 0; i < totalBlocks; i++)
            {
                fname = this.vmu.vmuConst.ID.TrimEnd(new char[] { '\0' }) + getFileType(this.vmu.flashConfig[this.selectedBlocks[i]]);

                if (worker.CancellationPending)
                {
                    e.Cancel = true; return;
                }

                for (int j = 0; j < this.framesPerBlock; j++)
                {
                    if (worker.CancellationPending)
                    {
                        e.Cancel = true; return;
                    }
                    p = (((double)((i * this.framesPerBlock) + (j + 1))) / totalFramesToRead) * 100;
                    worker.ReportProgress((int)p, string.Format("Downloading Block{0:G} to {1:G}    {2:G}% Complete",
                                                                this.selectedBlocks[i], fname, (int)p));
                    this.status = this.rs232comms.getVMUFlashData(this.currentPort, this.selectedBlocks[i], j * this.frameSize, frameSize, temp);
                    if (this.status == COMMS_STATUS.OKAY)
                    {
                        Array.Copy(temp, 0, this.blockData, j * this.frameSize, this.frameSize);
                    }
                }

                FileInfo   fi = new FileInfo(path + "\\" + fname);
                FileStream fs = fi.OpenWrite();
                fs.Write(this.blockData, 0, this.blockData.Length);
                fs.Close();
            }
        }
Example #4
0
        private void btnDownload_Click(object sender, EventArgs e)
        {
            if (this.selectedBlocks.Count > 0)
            {
                DialogResult res = MessageBox.Show("Switch to Higher Download Speed", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (res == DialogResult.Yes)
                {
                    this.status = this.rs232comms.setVMUBaudrate(this.currentPort, 56000);
                    if (this.status == COMMS_STATUS.OKAY)
                    {
                        this.highDownloadSpeed = true;
                    }
                }


                this.folderBrowserDialog1.RootFolder = Environment.SpecialFolder.Desktop;

                res = this.folderBrowserDialog1.ShowDialog(this);

                if (res == DialogResult.OK)
                {
                    this.status = this.rs232comms.getVMUConstants(this.currentPort, ref this.vmu.vmuConst);
                    if (this.status == COMMS_STATUS.OKAY)
                    {
                        this.listView1.Enabled = false;
                        setEnable(false);
                        this.selectedBlocks.Sort();
                        setProgressBarParms(ProgressBarStyle.Blocks, true);
                        Settings.Default.downloadFolder = this.folderBrowserDialog1.SelectedPath;
                        Settings.Default.Save();
                        string path = Settings.Default.downloadFolder;
                        if (!this.downloadBackgroundWorker.IsBusy)
                        {
                            this.downloadBackgroundWorker.RunWorkerAsync(path);
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("Please Tick the Blocks to download from!", "",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Example #5
0
        private void flashConfigBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker worker = sender as BackgroundWorker;

            if (worker.CancellationPending)
            {
                e.Cancel = true; return;
            }

            this.vmu.flashConfig = new flashHeaderStruct[VMU.FLASH_BLOCKS];
            int    maxBlocks = VMU.FLASH_BLOCKS;
            double p;
            int    percentage;

            for (int i = 0; i < maxBlocks; i++)
            {
                if (worker.CancellationPending)
                {
                    e.Cancel = true; return;
                }

                worker.ReportProgress(this.toolStripProgressBar1.Value,
                                      string.Format("Reading Block {0:G} Configuration", i));
                this.status = this.rs232comms.getVMUFlashConfig(this.currentPort, i, ref this.vmu.flashConfig[i]);

                p          = ((double)i) / maxBlocks;
                percentage = (int)(p * 100);
                worker.ReportProgress(percentage,
                                      string.Format("Reading Block {0:G} Configuration", i));

                if (this.status == COMMS_STATUS.OKAY)
                {
                    updateListViewItems(this.listView1, this.vmu.flashConfig[i]);
                }
            }
        }
Example #6
0
        private void readFlashBackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int tripBlocks, sbsBlocks, gpsBlocks;

            tripBlocks = int.Parse(this.tripsTextBox.Text);
            sbsBlocks  = int.Parse(this.sbsTextBox.Text);
            gpsBlocks  = int.Parse(this.gpsTextBox.Text);

            DialogResult res = MessageBox.Show(string.Format(
                                                   "TRIP Blocks = {0:G}\nSBS Blocks = {1:G}\nGPS Blocks = {2:G}\n\nAll Data will be ERASED!!\n\n\nDo you wish to proceed?"
                                                   , tripBlocks, sbsBlocks, gpsBlocks)
                                               , "WARNING!"
                                               , MessageBoxButtons.YesNo, MessageBoxIcon.Warning);

            if (res == DialogResult.Yes)
            {
                for (int i = 0; i < VMU.FLASH_BLOCKS; i++)
                {
                    this.vmu.newFlashConfig[i].blockNum = i;

                    if (i < tripBlocks)
                    {
                        this.vmu.newFlashConfig[i].type       = 0x80;
                        this.vmu.newFlashConfig[i].recordSize = 0;
                    }
                    if ((i >= tripBlocks) && (i < tripBlocks + sbsBlocks))
                    {
                        this.vmu.newFlashConfig[i].type       = 0x21;
                        this.vmu.newFlashConfig[i].recordSize = 8;
                    }
                    if ((i >= tripBlocks + sbsBlocks) && (i < tripBlocks + sbsBlocks + gpsBlocks))
                    {
                        this.vmu.newFlashConfig[i].type       = 0x10;
                        this.vmu.newFlashConfig[i].recordSize = 18;
                    }
                }

                this.status = this.rs232comms.setVMUFlashConfig(this.currentPort, this.vmu.newFlashConfig, VMU.FLASH_BLOCKS);

                //this.currentPort.Close();

                if (this.status == COMMS_STATUS.OKAY)
                {
                    MessageBox.Show("Flash Memory Successfully Configured!!\nYour Device will restart shortly...", "CONFIRMATION!",
                                    MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
                //this.currentPort.Open();

                for (int i = 0; i <= 80; i++)
                {
                    Thread.Sleep(210);
                    readFlashBackgroundWorker.ReportProgress(i);

                    if (readFlashBackgroundWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        readFlashBackgroundWorker.ReportProgress(0);
                        return;
                    }
                }

                toolStripLabelRestart.Text = "Restarting Device!";

                for (int i = 81; i <= 94; i++)
                {
                    Thread.Sleep(210);
                    readFlashBackgroundWorker.ReportProgress(i);

                    if (readFlashBackgroundWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        readFlashBackgroundWorker.ReportProgress(0);
                        return;
                    }
                }

                toolStripLabelRestart.Text = "";

                for (int i = 95; i <= 100; i++)
                {
                    Thread.Sleep(210);
                    readFlashBackgroundWorker.ReportProgress(i);

                    if (readFlashBackgroundWorker.CancellationPending)
                    {
                        e.Cancel = true;
                        readFlashBackgroundWorker.ReportProgress(0);
                        return;
                    }
                }

                readFlashBackgroundWorker.ReportProgress(0);
            }
        }