public frmUploadFirmware() { this.InitializeComponent(); this.txtFileToUpload.Text = ""; this.lblStatus.Text = ""; this.Status = UpGradeStatus.STATUS_NONE; this.OnlyVerify = false; }
private void btnVerify_Click(object sender, EventArgs e) { this.OnlyVerify = true; this.TimeOutPhase = DateTime.Now; this.progressBar1.Value = 0; this.lblStatus.Text = "Initializing..."; if (STDFU_EX_Wrapper.STDFU_EX_Init(this.txtFileToUpload.Text) == STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { this.Status = UpGradeStatus.STATUS_VERIFY; } else { this.Status = UpGradeStatus.STATUS_ERROR; } this.timer1.Enabled = true; this.btnBrowse.Enabled = false; this.btnClose.Enabled = false; this.btnCloseLeave.Enabled = false; this.btnUpload.Enabled = false; this.btnVerify.Enabled = false; if (this.OnMessageToLogSettings != null) { this.OnMessageToLogSettings("Start firmware verify..."); } }
private void timer1_Tick(object sender, EventArgs e) { TimeSpan span = DateTime.Now.TimeOfDay - this.TimeOutPhase.TimeOfDay; if (span.TotalSeconds > 30.0) { this.lblStatus.Text = this.lblStatus.Text + " (Time out)"; this.Status = UpGradeStatus.STATUS_ERROR; } switch (this.Status) { case UpGradeStatus.STATUS_NONE: this.Status = UpGradeStatus.STATUS_INIT; return; case UpGradeStatus.STATUS_INIT: this.TimeOutPhase = DateTime.Now; this.lblStatus.Text = "Initializing..."; this.progressBar1.Value = 0; if (STDFU_EX_Wrapper.STDFU_EX_Init(this.txtFileToUpload.Text) != STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { this.Status = UpGradeStatus.STATUS_ERROR; return; } this.Status = UpGradeStatus.STATUS_ERASE; return; case UpGradeStatus.STATUS_ERASE: this.TimeOutPhase = DateTime.Now; this.lblStatus.Text = "Erasing..."; if (STDFU_EX_Wrapper.STDFU_EX_Erase() != STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { this.Status = UpGradeStatus.STATUS_ERROR; return; } this.Status = UpGradeStatus.STATUS_ERASE_ING; return; case UpGradeStatus.STATUS_ERASE_ING: { int status = 0; double percent = 0.0; STDFU_EX_Wrapper.STDFU_EX_Error error = STDFU_EX_Wrapper.STDFU_EX_GetStatus(ref status, ref percent); this.progressBar1.Value = (int) percent; if (error == STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { if (percent != 100.0) { break; } this.Status = UpGradeStatus.STATUS_UPGRADE; return; } this.Status = UpGradeStatus.STATUS_ERROR; return; } case UpGradeStatus.STATUS_UPGRADE: this.TimeOutPhase = DateTime.Now; this.lblStatus.Text = "Flashing..."; if (STDFU_EX_Wrapper.STDFU_EX_FlashDevice() != STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { this.Status = UpGradeStatus.STATUS_ERROR; return; } this.Status = UpGradeStatus.STATUS_UPGRADE_ING; return; case UpGradeStatus.STATUS_UPGRADE_ING: { int num3 = 0; double num4 = 0.0; STDFU_EX_Wrapper.STDFU_EX_Error error2 = STDFU_EX_Wrapper.STDFU_EX_GetStatus(ref num3, ref num4); this.progressBar1.Value = (int) num4; if (error2 == STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { if (num4 != 100.0) { break; } this.Status = UpGradeStatus.STATUS_VERIFY; return; } this.Status = UpGradeStatus.STATUS_ERROR; return; } case UpGradeStatus.STATUS_VERIFY: this.TimeOutPhase = DateTime.Now; this.lblStatus.Text = "Verifing..."; if (STDFU_EX_Wrapper.STDFU_EX_Verify() != STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { this.Status = UpGradeStatus.STATUS_ERROR; return; } this.Status = UpGradeStatus.STATUS_VERIFY_ING; return; case UpGradeStatus.STATUS_VERIFY_ING: { int num5 = 0; double num6 = 0.0; STDFU_EX_Wrapper.STDFU_EX_Error error3 = STDFU_EX_Wrapper.STDFU_EX_GetStatus(ref num5, ref num6); this.progressBar1.Value = (int) num6; if (error3 == STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { if (num6 != 100.0) { break; } this.Status = UpGradeStatus.STATUS_RUN_APP; return; } this.Status = UpGradeStatus.STATUS_ERROR; return; } case UpGradeStatus.STATUS_RUN_APP: this.TimeOutPhase = DateTime.Now; this.lblStatus.Text = "Detaching..."; if (STDFU_EX_Wrapper.STDFU_EX_RunApplication() != STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { this.Status = UpGradeStatus.STATUS_ERROR; return; } this.Status = UpGradeStatus.STATUS_RUN_APP_ING; return; case UpGradeStatus.STATUS_RUN_APP_ING: { int num7 = 0; double num8 = 0.0; STDFU_EX_Wrapper.STDFU_EX_Error error4 = STDFU_EX_Wrapper.STDFU_EX_GetStatus(ref num7, ref num8); this.progressBar1.Value = (int) num8; if (error4 == STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { if (num8 != 100.0) { break; } this.Status = UpGradeStatus.STATUS_COMPLETED; return; } this.Status = UpGradeStatus.STATUS_ERROR; return; } case UpGradeStatus.STATUS_COMPLETED: { this.timer1.Enabled = false; this.btnBrowse.Enabled = true; this.btnClose.Enabled = true; this.btnCloseLeave.Enabled = true; this.btnUpload.Enabled = true; this.btnVerify.Enabled = true; STDFU_EX_Wrapper.STDFU_EX_Release(); this.lblStatus.Text = "Done!"; string strMessage = "Firmware upgrade completed successfully"; string caption = "Firmware upgrade"; if (this.OnlyVerify) { strMessage = "Firmware verify completed successfully"; caption = "Firmware verify"; } strMessage = strMessage + " \nDevice is in application mode."; if (this.OnMessageToLogSettings != null) { this.OnMessageToLogSettings(strMessage); } MessageBox.Show(strMessage, caption, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); base.Close(); return; } case UpGradeStatus.STATUS_ERROR: this.lblStatus.Text = "Error on " + this.lblStatus.Text; if (STDFU_EX_Wrapper.STDFU_EX_Release() == STDFU_EX_Wrapper.STDFU_EX_Error.STDFU_EX_ERROR_NONE) { this.timer1.Enabled = false; this.btnBrowse.Enabled = true; this.btnClose.Enabled = true; this.btnClose.Enabled = true; this.btnUpload.Enabled = true; this.btnVerify.Enabled = true; this.Status = UpGradeStatus.STATUS_NONE; if (this.OnMessageToLogSettings != null) { this.OnMessageToLogSettings(this.lblStatus.Text); } } break; default: return; } }
private void btnUpload_Click(object sender, EventArgs e) { this.Status = UpGradeStatus.STATUS_NONE; this.timer1.Enabled = true; this.btnBrowse.Enabled = false; this.btnClose.Enabled = false; this.btnCloseLeave.Enabled = false; this.btnUpload.Enabled = false; this.btnVerify.Enabled = false; this.TimeOutPhase = DateTime.Now; this.OnlyVerify = false; if (this.OnMessageToLogSettings != null) { this.OnMessageToLogSettings("Start firmware upgrading..."); } }