예제 #1
0
파일: Form1.cs 프로젝트: yucnet/navxmxp
        private void button1_Click(object sender, EventArgs e)
        {
            if (!firmware_update_registered)
            {
                firmwareUpdate.OnFirmwareUpdateProgress += new FirmwareUpdateProgressEventHandler(firmwareUpdate_OnFirmwareUpdateProgress);
                firmware_update_registered = true;
            }
            FirmwareUpdateProgressEventArgs fupea;

            progressBar1.Maximum = 100;
            progressBar1.Step    = 1;
            progressBar1.Value   = 0;

            statusText = "";
            statusTextbox.Clear();
            progressBar1.Visible = true;
            Application.DoEvents();
            fupea = new FirmwareUpdateProgressEventArgs(0, "Detecting DFU Interface...", false);
            firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);

            if (port.IsOpen)
            {
                close_port();
            }

            bool is_dfu_available = false;

            Cursor.Current = Cursors.WaitCursor;
            Application.DoEvents();
            try
            {
                is_dfu_available = firmwareUpdate.IsDFUDeviceFound();
            }
            catch (Exception ex)
            {
                fupea = new FirmwareUpdateProgressEventArgs(0, ex.Message, true);
                firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);
            }
            if (!is_dfu_available)
            {
                Cursor.Current       = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                dialog_in_progress = true;
                MessageBox.Show("To update navX-Model Firmware, ensure the device is in Firmware Update Mode.\n\n" +
                                "1. Disconnect the device from the PC USB port.\n" +
                                "2. Ensure the device has completely powered down (the RED 3.3V LED must be off).\n" +
                                "3. While holding down the 'CAL' button, re-connect the device to the PC USB port.\n\n" +
                                "4. After the device has powered up, release the 'CAL' button.\n" +
                                "When in DFU mode, only the RED power LED will be ON.",
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);
                dialog_in_progress = false;
                return;
            }
            String dfu_file_name = Path.GetTempPath() + "navx.dfu";
            bool   converted     = hex2dfu.ConvertHexToDFU(full_path_to_hex_file,
                                                           dfu_file_name,
                                                           theVid,
                                                           thePid,
                                                           theBcd);

            if (!converted)
            {
                Cursor.Current       = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                dialog_in_progress = true;
                MessageBox.Show("Error converting " + navXHexFilePath.Text + " to DFU format.",
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                dialog_in_progress = false;
                return;
            }

            UInt16 VID;
            UInt16 PID;
            UInt16 Version;

            try
            {
                firmwareUpdate.ParseDFU_File(dfu_file_name, out VID, out PID, out Version);
            }
            catch (Exception ex)
            {
                Cursor.Current       = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                fupea = new FirmwareUpdateProgressEventArgs(0, "Error parsing DFU file. " + ex.Message, false);
                firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);
                dialog_in_progress = true;
                MessageBox.Show("Error parsing DFU file. " + ex.Message,
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                dialog_in_progress = false;
                return;
            }

            fupea = new FirmwareUpdateProgressEventArgs(0, ("Found VID: " + VID.ToString("X4") + " PID: " + PID.ToString("X4") + " Version: " + Version.ToString("X4")), false);
            firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);

            try
            {
                bool eraseEveything = false;
                bool exitDFUMode    = true;

                firmwareUpdate.UpdateFirmware(dfu_file_name, eraseEveything, exitDFUMode);
            }
            catch (Exception ex)
            {
                Cursor.Current       = Cursors.Default;
                progressBar1.Visible = false;
                Application.DoEvents();
                fupea = new FirmwareUpdateProgressEventArgs(0, "Error deploying DFU file. " + ex.Message, true);
                firmwareUpdate_OnFirmwareUpdateProgress(this, fupea);
                dialog_in_progress = true;
                MessageBox.Show("Error deploying DFU file. " + ex.Message,
                                "navX-Model Firmware Update",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
                dialog_in_progress = false;
                return;
            }
            progressBar1.Visible = false;
            Cursor.Current       = Cursors.Default;
        }
예제 #2
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Error processing request.");
                Console.WriteLine("");
                Console.WriteLine("Syntax:");
                Console.WriteLine("DFUDeploy [file] [options]");
                Console.WriteLine("");
                Console.WriteLine("Options:");
                Console.WriteLine("\t/c");
                Console.WriteLine("\tClears all memory.  By default only the bootloader memory is erased.");
                Console.WriteLine("\tWith this option your NETMF runtime and deployment will also be erased.");
                Console.WriteLine("");
                Console.WriteLine("\t/x");
                Console.WriteLine("\tExits DFU mode after updating the bootloader.");
                Console.WriteLine("");
                Console.WriteLine("\t/?");
                Console.WriteLine("\tLists devices memory map.");
                Console.WriteLine("");
                Console.WriteLine("WARNING: This tool will deploy to the first USB device found in DFU mode.");
                Console.WriteLine("");
                return;
            }

            try
            {
                if (!firmwareUpdate.IsDFUDeviceFound())
                {
                    throw new Exception("No devices in DFU mode were found.");
                }

                if (args.Contains("/c") || args.Contains("/C"))
                {
                    firmwareUpdate.OnFirmwareUpdateProgress += new FirmwareUpdateProgressEventHandler(firmwareUpdate_OnFirmwareUpdateProgress);

                    UInt16 VID;
                    UInt16 PID;
                    UInt16 Version;

                    try
                    {
                        firmwareUpdate.ParseDFU_File(args[0], out VID, out PID, out Version);
                    }
                    catch (Exception ex)
                    {
                        throw new Exception("Error parsing DFU file. " + ex.Message, ex);
                    }

                    Console.WriteLine("Found VID: " + VID.ToString("X4") + " PID: " + PID.ToString("X4") + " Version: " + Version.ToString("X4"));
                }

                try
                {
                    bool eraseEveything = false;
                    bool exitDFUMode    = false;

                    //The cC switch erases everything from the chip
                    if (args.Contains("/c") || args.Contains("/C"))
                    {
                        eraseEveything = true;
                    }

                    //The xX switch exits the device from DFU mode
                    if (args.Contains("/x") || args.Contains("/X"))
                    {
                        exitDFUMode = true;
                    }

                    firmwareUpdate.UpdateFirmware(args[0], eraseEveything, exitDFUMode);
                }
                catch (Exception ex)
                {
                    throw new Exception("Error deploying DFU file. " + ex.Message, ex);
                }

                Console.WriteLine("Done.");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error: " + ex.Message);
            }
        }