예제 #1
0
        /// <summary>
        /// Selects a firmware file to flash.
        /// </summary>
        private void ButtonBrowse_Click(object sender, EventArgs e)
        {
            // Create the file open dialog
            using (OpenFileDialog openFileDialog = new OpenFileDialog())
            {
                // Title for the dialog
                openFileDialog.Title = "Choose file to flash";

                // Filter for .bin files
                openFileDialog.Filter = ".bin File|*.bin";

                if (openFileDialog.ShowDialog() == DialogResult.OK)
                {
                    // Clear the output boxes
                    this.textActivity.Clear();
                    this.textVerbose.Clear();

                    // Set the text box to the selected file name
                    this.textFileName.Text = openFileDialog.FileName;

                    // Check the file size
                    if (!FileUtils.CheckFirmwareFileSize(this.textFileName.Text))
                    {
                        return;
                    }

                    // Get the signature from the firmware file
                    FileUtils.FirmwareFile fileDetails = FileUtils.GetFirmwareSignature(this.textFileName.Text);

                    // If we got details from the signature write them to the log window
                    if (fileDetails != null)
                    {
                        this.AppendLog($"Firmware File Name:       {this.textFileName.Text.Substring(this.textFileName.Text.LastIndexOf("\\") + 1)}\r\n");
                        this.AppendLog($"Multi Firmware Version:   {fileDetails.Version} ({fileDetails.ModuleType})\r\n");
                        this.AppendLog($"Expected Channel Order:   {fileDetails.ChannelOrder}\r\n");
                        this.AppendLog($"Multi Telemetry Type:     {fileDetails.MultiTelemetryType}\r\n");
                        this.AppendLog($"Invert Telemetry Enabled: {fileDetails.InvertTelemetry}\r\n");
                        this.AppendLog($"Flash from Radio Enabled: {fileDetails.CheckForBootloader}\r\n");
                        this.AppendLog($"Bootloader Enabled:       {fileDetails.BootloaderSupport}\r\n");
                        this.AppendLog($"Serial Debug Enabled:     {fileDetails.DebugSerial}");
                    }
                    else
                    {
                        this.AppendLog($"Firmware File Name: {this.textFileName.Text.Substring(this.textFileName.Text.LastIndexOf("\\") + 1)}\r\n\r\n");
                        this.AppendLog($"Firmware signature not found in file, extended information is not available. This is normal for firmware prior to v1.2.1.79.\r\n");
                    }

                    // Check if the binary file contains USB / bootloader support
                    if (FileUtils.CheckForUsbSupport(this.textFileName.Text))
                    {
                        Debug.WriteLine("Firmware file compiled with USB support.");
                    }
                    else
                    {
                        Debug.WriteLine("Firmware file was not compiled with USB support.");
                    }
                }
            }

            // Check if the Upload button should be enabled yet
            this.CheckControls();
        }
예제 #2
0
        /// <summary>
        /// Main method where all the action happens.
        /// Called by the Upload button.
        /// </summary>
        private async void ButtonUpload_Click(object sender, EventArgs e)
        {
            // Disable the buttons until this flash attempt is complete
            Debug.WriteLine("Disabling the controls...");
            this.EnableControls(false);

            // Clear the output box
            Debug.WriteLine("Clearing the output textboxes...");
            this.textActivity.Clear();
            this.textVerbose.Clear();
            this.progressBar1.Value = 0;
            this.outputLineBuffer   = string.Empty;

            // Check if the file exists
            if (!File.Exists(this.textFileName.Text))
            {
                this.AppendLog(string.Format("File {0} does not exist", this.textFileName.Text));
                MessageBox.Show("Firmware file does not exist.", "Write Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.EnableControls(true);
                return;
            }

            // Check the file size
            if (!FileUtils.CheckFirmwareFileSize(this.textFileName.Text))
            {
                this.EnableControls(true);
                return;
            }

            // Determine if we should use Maple device
            MapleDevice mapleResult = MapleDevice.FindMaple();

            // Determine if we should use a USBasp device
            UsbAspDevice usbaspResult = UsbAspDevice.FindUsbAsp();

            // Determine if the selected file contains USB / bootloader support
            bool firmwareSupportsUsb = FileUtils.CheckForUsbSupport(this.textFileName.Text);

            // Get the signature from the firmware file
            FileUtils.FirmwareFile fileSignature = FileUtils.GetFirmwareSignature(this.textFileName.Text);

            // Error if flashing non-USB firmware via native USB port
            if (mapleResult.DeviceFound && !firmwareSupportsUsb)
            {
                string msgBoxMessage = "The selected firmware file was compiled without USB support.\r\n\r\nFlashing this firmware would prevent the Multiprotocol module from functioning correctly.\r\n\r\nPlease select a different firmware file.";
                MessageBox.Show(msgBoxMessage, "Incompatible Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error);
                this.EnableControls(true);
                return;
            }

            // Get the selected COM port
            string comPort = this.comPortSelector.SelectedValue.ToString();

            // Do the selected flash using the appropriate method
            if (mapleResult.DeviceFound == true)
            {
                Debug.WriteLine($"Maple device found in {mapleResult.Mode} mode\r\n");
                await MapleDevice.WriteFlash(this, this.textFileName.Text, comPort);
            }
            else if (usbaspResult.DeviceFound == true && comPort == "USBasp")
            {
                if (fileSignature == null)
                {
                    string msgBoxMessage = "Unable to check the specified firmware file for compatibility with this upload method.";
                    MessageBox.Show(msgBoxMessage, "Incompatible Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.EnableControls(true);
                    return;
                }

                if (fileSignature.ModuleType != "AVR")
                {
                    string msgBoxMessage = "The selected firmware file is not compatible with this upload method.";
                    MessageBox.Show(msgBoxMessage, "Incompatible Firmware", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    this.EnableControls(true);
                    return;
                }

                await UsbAspDevice.WriteFlash(this, this.textFileName.Text, fileSignature.BootloaderSupport);
            }
            else
            {
                await SerialDevice.WriteFlash(this, this.textFileName.Text, comPort, firmwareSupportsUsb);
            }
        }