public byte[] Load_Image(string args) { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; //Image// string file_path = args; byte[] Image_data = new byte[0]; char[] File_spliter = new char[] { '.' }; string[] subcommand = file_path.Split(File_spliter); string file_posfix = subcommand[subcommand.Length - 1]; if (file_posfix == "s19") { SREC_file srec = new SREC_file(file_path); Image_data = srec.ivt_boot_image.Data; File_Support = true; } else if (file_posfix == "bin") { FileStream fileStream = new FileStream(file_path, FileMode.Open, FileAccess.Read); Image_data = new byte[fileStream.Length]; fileStream.Read(Image_data, 0, Image_data.Length); File_Support = true; } else { Invoke(UpdateLog, new Object[] { "File Format Doesn't Supported Now...", true }); File_Support = false; } return(Image_data); }
public void Setup_BootLoader() { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; int count = 0; byte[] Filedata = new byte[1024]; ivt_BootLoader BL = new ivt_BootLoader(); Sdp_Handler.WriteCommand(4, 539001344, Convert.ToInt32(BL.BootLoader.Length)); while (count < BL.BootLoader.Length) { if (count + Filedata.Length > BL.BootLoader.Length) { byte[] partdata = new byte[BL.BootLoader.Length - count]; Array.Copy(BL.BootLoader, count, partdata, 0, partdata.Length); Sdp_Handler.WriteData(partdata); count += partdata.Length; } else { Array.Copy(BL.BootLoader, count, Filedata, 0, Filedata.Length); Sdp_Handler.WriteData(Filedata); count += Filedata.Length; } } Sdp_Handler.WriteCommand(11, 539001344, 0); System.Threading.Thread.Sleep(1000); Invoke(UpdateLog, new Object[] { "Recovery Success, Reinitializing FW Upgrade Menager...", true }); }
public void PushReceiveData(byte[] datas) { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Viewer.UpadateDataMapInvoke UpdateDataMap = Data_Process; if (datas.Length > 0) { Invoke(UpdateLog, "Data Received", true); Invoke(UpdateDataMap, BitConverter.ToString(datas, 0).Replace("-", " ")); } }
public void Check_Recipe() { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Invoke(UpdateLog, new Object[] { "Start Upgrading FW... ", true }); CommandList.RemoveRange(0, CommandList.Count); using (StreamReader update_flow = new StreamReader("Auto_Recipe.txt")) { string templine; byte[] rawbyte; while ((templine = update_flow.ReadLine()) != null) { Command readin_command = new Command(); char[] spliter = { '\t' }; string[] data_split = templine.Split(spliter); for (int i = 0; i < data_split.Length; i++) { rawbyte = System.Text.Encoding.Default.GetBytes(data_split[i]); byte[] change_record = new byte[rawbyte.Length / 2]; for (int c = 0; c < rawbyte.Length; c++) { rawbyte[c] = Convert.ToByte((rawbyte[c] > 57) ? rawbyte[c] - 55 : rawbyte[c] - 48);; } for (int c = 0; c < change_record.Length; c++) { change_record[c] = BitConverter.GetBytes(rawbyte[2 * c] * 16 + rawbyte[2 * c + 1])[0]; } switch (i) { case 0: readin_command.command_type = change_record; break; case 1: for (int j = 0; j < change_record.Length; j++) { readin_command.Para_1[j] = change_record[j]; } break; case 2: for (int j = 0; j < change_record.Length; j++) { readin_command.Para_2[j] = change_record[j]; } break; } } CommandList.Add(readin_command); } update_flow.Close(); } }
private void Save_Image(object image) { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; string save_path = "Saved_Image_" + DateTime.Now.ToString("ddMMyy_HHmmss_fff") + ".bmp"; Viewer.sSavePath = new FileStream(Viewer.PathofExe + save_path, FileMode.Create); lock (image) { ((Bitmap)image).Save(Viewer.sSavePath, ImageFormat.Bmp); } Viewer.sSavePath.Close(); SSL_Save_Status.Text = "File Save at " + Viewer.PathofExe + save_path; Invoke(UpdateLog, new Object[] { "File Save at " + Viewer.PathofExe + save_path, true }); GC.Collect(); }
public void CheckBmp(object Checkmap) { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Invoke(UpdateLog, new Object[] { "Start Check :" + Viewer.frameCount, true }); for (int c = 0; c < ((byte[])Checkmap).Length; c++) { if (((byte[])Checkmap)[c] != 255) { Invoke(UpdateLog, new Object[] { "Failed position count : " + c + "Value : " + ((byte[])Checkmap)[c], true }); } } //Invoke(UpdateLog, new Object[] { "End Check :" + Viewer.Backup_frame, true }); Viewer._Buffer3 = false; }
private void btn_onekeyupdate_Click(object sender, EventArgs e) { btn_onekeyupdate.Enabled = false; bool BL_connect = false; Viewer.UpdateProgressBarCallback UpdateProgressBar = Assign_ProgressBar; Viewer.UpadateLogInvoke UpdateLog = LogUpdate; if (Viewer.fingerPrint == null) { Viewer.fingerPrint = new FingerPrint_API.FingerPrint(); Viewer.fingerPrint.AutoConnect_Interval = 5000; } if (!Viewer.fingerPrint.IsConnected) { InitialDvice(true); } bool force_try = false; if (!Viewer._Initial) { DialogResult dr = MessageBox.Show("Can't Find Appropriate Device, Try Recovery?", "Connect Failed", MessageBoxButtons.YesNo); force_try = (dr == DialogResult.Yes) ? true : false; } if (Viewer._Initial || force_try) { int BLtry_count = 0; Invoke(UpdateLog, new Object[] { "Initializing FW Update Menager...", true }); Invoke(UpdateLog, new Object[] { "Please Waiting...", false }); while (Bl_Handler == null && BLtry_count < 5) { Invoke(UpdateLog, new Object[] { "...", false }); System.Threading.Thread.Sleep(1000); Bl_Handler = BL_Handler.Enumerate(0x15A2, new[] { 0x0073 }).FirstOrDefault(); BLtry_count++; } Invoke(UpdateLog, new Object[] { " ", true }); if (Bl_Handler != null) { Bl_Handler.LogUpdate += UpdateLogFromHandler; Bl_Handler.DataRecieved += ReceiveDataFlag; Bl_Handler.StartListen(); BL_connect = true; Invoke(UpdateLog, new Object[] { "Initializing FW Update Menager Success...", true }); } else { Invoke(UpdateLog, new Object[] { "Initializing Failed, Recovery Function Start...", true }); Sdp_Handler = SDP_Handler.Enumerate(0x1FC9, new[] { 0x0130 }).FirstOrDefault(); if (Sdp_Handler != null) { Sdp_Handler.DataRecieved += ReceiveDataFlag; Sdp_Handler.StartListen(); Setup_BootLoader(); } else { Invoke(UpdateLog, new Object[] { "Recovery Failed, Terminated...", true }); } } System.Threading.Thread.Sleep(3000); // Reconnect if (!BL_connect) { Bl_Handler = BL_Handler.Enumerate(0x15A2, new[] { 0x0073 }).FirstOrDefault(); if (Bl_Handler != null) { Bl_Handler.LogUpdate += UpdateLogFromHandler; Bl_Handler.DataRecieved += ReceiveDataFlag; Bl_Handler.StartListen(); BL_connect = true; Invoke(UpdateLog, new Object[] { "Initializing FW Update Menager Success...", true }); } else { Invoke(UpdateLog, new Object[] { "Initializing FW Upgrade Menager Fail... Terminated", true }); } } if (BL_connect) { string ImageFilePath = tb_allinone_path.Text; //Check Recipe// if (!File.Exists("Auto_Recipe.txt")) { Invoke(UpdateLog, new Object[] { "Recipe Loss, Please Contact For Support", true }); } else { Check_Recipe(); byte[] Image_data = Load_Image(ImageFilePath); if (File_Support) { Do_Command(Image_data); } Invoke(UpdateLog, new Object[] { "Process Done", true }); } } if (File_Support) { Viewer._Initial = false; int try_count = 0; Viewer.fingerPrint.Dispose(); Viewer.fingerPrint = new FingerPrint_API.FingerPrint(); rt_log.Text += "Verificating...\n"; while (!Viewer._Initial && try_count < 3) { try_count++; System.Threading.Thread.Sleep(3000); InitialDvice(false); } if (!Viewer._Initial) { Invoke(UpdateLog, new Object[] { "Updated Failed Please Check Your Image File And Restart Upgrade Program", true }); } } } btn_onekeyupdate.Enabled = true; }
public void Do_Command(byte[] Image_data) { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; byte[] image_Len = new byte[4] { 0x00, 0x00, 0x00, 0x00 }; image_Len = BitConverter.GetBytes(Image_data.Length); Array.Reverse(image_Len); byte[] Erase_Len = new byte[4]; Array.Copy(image_Len, Erase_Len, image_Len.Length); Erase_Len[3] = 0x00; Erase_Len[2] = BitConverter.GetBytes((((Erase_Len[2] / 16) + 2) * 16))[0]; /////Load in Progress Done///// Invoke(UpdateLog, new Object[] { "Load in Image Progress Done", true }); Invoke(UpdateLog, new Object[] { "Processing..., Please Waiting...", false }); foreach (Command active_command in CommandList) { //Invoke(UpdateLog, new Object[] { "...", false }); switch (BitConverter.ToString(active_command.command_type, 0)) { case "02": Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, Erase_Len, false); wait_response_lock = true; break; case "03": Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, active_command.Para_2, false); wait_response_lock = true; break; case "04": int file_pointer = 0; byte[] HID_packet = new byte[1016]; Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, image_Len, true); wait_response_lock = true; while (file_pointer < Image_data.Length) { int data_len = ((Image_data.Length - file_pointer) > HID_packet.Length) ? HID_packet.Length : (Image_data.Length - file_pointer); Array.Copy(Image_data, file_pointer, HID_packet, 0, data_len); Bl_Handler.WriteData(HID_packet); file_pointer += data_len; } wait_response_lock = true; break; case "05": Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, active_command.Para_2.Length, active_command.Para_2, false); wait_response_lock = true; break; case "07": Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, active_command.Para_2, false); wait_response_lock = true; break; case "0B": Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, active_command.Para_2, false); wait_response_lock = true; break; case "0F": Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, active_command.Para_2, false); wait_response_lock = true; break; case "11": Bl_Handler.WriteCommand(active_command.command_type, active_command.Para_1, active_command.Para_2, false); wait_response_lock = true; break; default: break; } } Invoke(UpdateLog, new Object[] { " ", true }); }
private void DeviceRemoved() { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Invoke(UpdateLog, new Object[] { "連接中斷", true }); }
private void DeviceInserted() { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Invoke(UpdateLog, new Object[] { "連接成功", true }); }
private void UpdateLogFromHandler(string log, bool newline) { Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Invoke(UpdateLog, new Object[] { log, newline }); }
private void btn_send_BL_Click(object sender, EventArgs e) { Viewer.UpadateDataMapInvoke UpdateDataMap = Data_Process; Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Viewer.UpdateProgressBarCallback UpdateProgressBar = Assign_ProgressBar; Invoke(UpdateProgressBar, 0); int para_1 = Int32.Parse(tb_BL_para1.Text, System.Globalization.NumberStyles.HexNumber); int para_2 = Convert.ToInt32(tb_BL_para2.Text); byte[] data = new byte[para_2]; int row = 0, col = 0, pcount = 0; if (cb_BL_command_type.Text == "FillMemory") { while (pcount < para_2 && dgv_datamap.Rows[row].Cells[col].Value != null) { data[pcount] = byte.Parse(dgv_datamap.Rows[row].Cells[col].Value.ToString(), System.Globalization.NumberStyles.HexNumber); pcount++; col = (col + 1 > dgv_datamap.ColumnCount - 1) ? 0 : ++col; if (col == 0) { row = (row + 1 > dgv_datamap.RowCount) ? row : ++row; } } } Invoke(UpdateDataMap, new string[] { null }); int command_type = 0; switch (cb_BL_command_type.Text) { case "FlashEraseRegion": command_type = 2; Bl_Handler.WriteCommand(command_type, para_1, para_2, false); break; case "ReadMemory": command_type = 3; Bl_Handler.WriteCommand(command_type, para_1, para_2, false); break; case "WriteMemory": Invoke(UpdateProgressBar, 20); command_type = 4; int file_pointer = 0; string file_path = tb_BL_filepath.Text; char[] spliter = new char[] { '.' }; string[] subcommand = file_path.Split(spliter); string file_posfix = subcommand[subcommand.Length - 1]; if (file_posfix == "s19") { SREC_file srec = new SREC_file(file_path); byte[] HID_packet = new byte[1016]; int datapacket_count_perstep = (srec.ivt_boot_image.Data.Length / HID_packet.Length) / 80; Bl_Handler.WriteCommand(command_type, para_1, Convert.ToInt32(srec.ivt_boot_image.Data.Length), true); int count = 0; while (file_pointer < srec.ivt_boot_image.Data.Length) { int data_len = ((srec.ivt_boot_image.Data.Length - file_pointer) > HID_packet.Length) ? HID_packet.Length : (srec.ivt_boot_image.Data.Length - file_pointer); Array.Copy(srec.ivt_boot_image.Data, file_pointer, HID_packet, 0, data_len); Debug.WriteLine("pointer : " + file_pointer + ", data len : " + data_len); Bl_Handler.WriteData(HID_packet); file_pointer += data_len; count++; if (count == datapacket_count_perstep) { count = 0; Invoke(UpdateProgressBar, 1); } } } else if (file_posfix == "bin") { int count = 0; long preposition = 0; byte[] Filedata = new byte[1016]; FileStream fileStream = new FileStream(tb_BL_filepath.Text, FileMode.Open, FileAccess.Read); Debug.WriteLine(fileStream.Length); Bl_Handler.WriteCommand(command_type, para_1, Convert.ToInt32(fileStream.Length), true); while (fileStream.Read(Filedata, 0, Filedata.Length) > 0) { Debug.WriteLine(fileStream.Position); if (fileStream.Position == fileStream.Length) { byte[] partdata = new byte[fileStream.Position - preposition]; Array.Copy(Filedata, partdata, partdata.Length); Bl_Handler.WriteData(partdata); count += partdata.Length; } else { Bl_Handler.WriteData(Filedata); count += Filedata.Length; } Debug.WriteLine("Write Count : " + count); preposition = fileStream.Position; } } break; case "FillMemory": command_type = 5; Bl_Handler.WriteCommand(command_type, para_1, para_2, data, false); break; case "GetProperty": command_type = 7; Bl_Handler.WriteCommand(command_type, para_1, para_2, false); break; case "Reset": command_type = 11; Bl_Handler.WriteCommand(command_type, para_1, para_2, false); break; case "FlashReadOnce": command_type = 15; Bl_Handler.WriteCommand(command_type, para_1, para_2, false); break; case "ConfigureQuadSPI": command_type = 17; Bl_Handler.WriteCommand(command_type, para_1, para_2, false); break; default: break; } Invoke(UpdateLog, "Command Process Done", true); Invoke(UpdateProgressBar, 100); }
private void btn_sent_SDP_Click(object sender, EventArgs e) { btn_sent_SDP.Enabled = false; Viewer.UpadateDataMapInvoke UpdateDataMap = Data_Process; Viewer.UpadateLogInvoke UpdateLog = LogUpdate; Viewer.UpdateProgressBarCallback UpdateProgressBar = Assign_ProgressBar; Invoke(UpdateProgressBar, 0); int addr_int = Int32.Parse(tb_addr.Text, System.Globalization.NumberStyles.HexNumber); int datacount = Convert.ToInt32(tb_datacount.Text); byte[] data = new byte[datacount]; int row = 0, col = 0, pcount = 0; if (cb_command_type.Text == "WRITE_REGISTER" || cb_command_type.Text == "WRITE_FILE") { while (pcount < datacount && dgv_datamap.Rows[row].Cells[col].Value != null) { data[pcount] = byte.Parse(dgv_datamap.Rows[row].Cells[col].Value.ToString(), System.Globalization.NumberStyles.HexNumber); pcount++; col = (col + 1 > dgv_datamap.ColumnCount - 1) ? 0 : col++; if (col == 0) { row = (row + 1 > dgv_datamap.RowCount) ? row : row++; } } } Invoke(UpdateDataMap, new string[] { null }); int command_type = 0; switch (cb_command_type.Text) { case "READ_REGISTER": command_type = 1; Sdp_Handler.WriteCommand(command_type, addr_int, datacount); break; case "WRITE_REGISTER": command_type = 2; Sdp_Handler.WriteCommand(command_type, addr_int, datacount, data); break; case "WRITE_FILE": command_type = 4; int count = 0; long preposition = 0; byte[] Filedata = new byte[1024]; FileStream fileStream = new FileStream(tb_filepath.Text, FileMode.Open, FileAccess.Read); Invoke(UpdateLog, "File Length : " + fileStream.Length, true); Invoke(UpdateProgressBar, 20); Invoke(UpdateLog, "Start", true); Sdp_Handler.WriteCommand(command_type, addr_int, Convert.ToInt32(fileStream.Length)); while (fileStream.Read(Filedata, 0, Filedata.Length) > 0) { if (fileStream.Position == fileStream.Length) { byte[] partdata = new byte[fileStream.Position - preposition]; Array.Copy(Filedata, partdata, partdata.Length); Sdp_Handler.WriteData(partdata); count += partdata.Length; } else { Sdp_Handler.WriteData(Filedata); count += Filedata.Length; } Debug.WriteLine("Write Count : " + count); preposition = fileStream.Position; } break; case "ERROR_STATUS": command_type = 5; Sdp_Handler.WriteCommand(command_type, 0, 0); break; case "DCD_WRITE": command_type = 10; break; case "JUMP_ADDRESS": command_type = 11; Sdp_Handler.WriteCommand(command_type, addr_int, 0); break; default: MessageBox.Show("Please Select Command Type"); break; } Invoke(UpdateLog, "Command Process Done", true); btn_sent_SDP.Enabled = true; Invoke(UpdateProgressBar, 100); }
private void Communication_PackageReceived(FingerPrint.Frame frame) { Viewer.UpdateImageCallback UpdateImage = ChangeImage; Viewer.UpdateStatusCallback UpdateStatusText = ShowStatusText; Viewer.UpdateStatusCallback UpdateTNText = ShowStatusText; Viewer.UpadateLogInvoke UpdateLog = LogUpdate; #region Debug_input #if DEBUGX if (Viewer.frameCount > 0 && Viewer.frameCount % 20 == 0) { Viewer._Buffer3 = true; int col = frame.nDataFrameNum * 16; Bitmap clo = frame.bitmap.Clone(new Rectangle(col, 0, 4, frame.bitmap.Height), PixelFormat.Format24bppRgb); BitmapData bmpData = clo.LockBits(new Rectangle(0, 0, 4, clo.Height), ImageLockMode.ReadOnly, PixelFormat.Format24bppRgb); //frame.bitmap.Height byte[] data = new byte[bmpData.Width * bmpData.Height * 3]; System.Runtime.InteropServices.Marshal.Copy(bmpData.Scan0, data, 0, data.Length); //複製記憶體區塊 clo.UnlockBits(bmpData); if (data[0] != 0) { Viewer.tArrange = new Thread(CheckBmp); Viewer.tArrange.Start(data); //new Rectangle(0, 0, 1600, 1), frame.bitmap.PixelFormat } } #endif #endregion Debug_input if (!Viewer.StreamStart) { Viewer.StreamStart = true; Invoke(UpdateLog, new Object[] { "Frist Stream In, Start Stram...", true }); } Viewer.nDataFrameNum = (uint)frame.nDataFrameNum; Viewer.FPS = frame.nFPS; Viewer.bmp_TN_Temp = frame.bitmap; switch (frame.nDataFrameNum) { case 0: Viewer._Buffer0 = false; Viewer.bmp0 = frame.bitmap; Viewer._Buffer0 = true; break; case 1: Viewer._Buffer1 = false; Viewer.bmp1 = frame.bitmap; Viewer._Buffer1 = true; break; case 2: Viewer._Buffer2 = false; Viewer.bmp2 = frame.bitmap; Viewer._Buffer2 = true; break; default: break; } if (Viewer.DisplayByGL) { Invoke(UpdateImage); } Invoke(UpdateStatusText, new Object[] { this.SSL_Framecount, "Frame count : " + Viewer.frameCount, null }); Invoke(UpdateStatusText, new Object[] { this.SSL_TN, "TN : " + Viewer.TN, null }); Viewer.frameCount++; if (Viewer.save_count > 0) { Viewer.tSaveImage = new Thread(new ParameterizedThreadStart(Save_Image)); Viewer.tSaveImage.Start(frame.bitmap); Viewer.save_count--; } GC.Collect(); }