示例#1
0
 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("-", " "));
     }
 }
示例#2
0
        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);
        }
示例#3
0
        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);
        }