Kaynağa Gözat

CRC32 추가 , Download File Make 기능 추가

PYJ 5 yıl önce
ebeveyn
işleme
cb02edba7d

BIN
.vs/Jdas_Mbic/v15/.suo


BIN
.vs/Jdas_Mbic/v15/Server/sqlite3/storage.ide


BIN
.vs/Jdas_Mbic/v15/Server/sqlite3/storage.ide-shm


BIN
.vs/Jdas_Mbic/v15/Server/sqlite3/storage.ide-wal


+ 13 - 0
Jdas_Mbic/Main.Designer.cs

@@ -269,6 +269,7 @@
269 269
             this.label44 = new System.Windows.Forms.Label();
270 270
             this.pictureBox_ULShutdown_Alarm_ON = new System.Windows.Forms.PictureBox();
271 271
             this.pictureBox_ULShutdown_Alarm_OFF = new System.Windows.Forms.PictureBox();
272
+            this.button_Test = new System.Windows.Forms.Button();
272 273
             ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
273 274
             this.Mbic_Setting.SuspendLayout();
274 275
             this.tabPage_Main.SuspendLayout();
@@ -412,6 +413,7 @@
412 413
             // 
413 414
             // tabPage_Main
414 415
             // 
416
+            this.tabPage_Main.Controls.Add(this.button_Test);
415 417
             this.tabPage_Main.Controls.Add(this.button_Reset);
416 418
             this.tabPage_Main.Controls.Add(this.button_Save);
417 419
             this.tabPage_Main.Controls.Add(this.label62);
@@ -3510,6 +3512,16 @@
3510 3512
             this.pictureBox_ULShutdown_Alarm_OFF.TabStop = false;
3511 3513
             this.pictureBox_ULShutdown_Alarm_OFF.Tag = "2";
3512 3514
             // 
3515
+            // button_Test
3516
+            // 
3517
+            this.button_Test.Location = new System.Drawing.Point(81, 682);
3518
+            this.button_Test.Name = "button_Test";
3519
+            this.button_Test.Size = new System.Drawing.Size(128, 23);
3520
+            this.button_Test.TabIndex = 149;
3521
+            this.button_Test.Text = "MBIC Down";
3522
+            this.button_Test.UseVisualStyleBackColor = true;
3523
+            this.button_Test.Click += new System.EventHandler(this.button_Test_Click);
3524
+            // 
3513 3525
             // JdasMbic
3514 3526
             // 
3515 3527
             this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
@@ -3935,6 +3947,7 @@
3935 3947
         private System.Windows.Forms.Label label44;
3936 3948
         public System.Windows.Forms.PictureBox pictureBox_ULShutdown_Alarm_ON;
3937 3949
         public System.Windows.Forms.PictureBox pictureBox_ULShutdown_Alarm_OFF;
3950
+        private System.Windows.Forms.Button button_Test;
3938 3951
     }
3939 3952
 }
3940 3953
 

+ 181 - 0
Jdas_Mbic/Main.cs

@@ -17,6 +17,7 @@ using System.Reflection;
17 17
 using Excel = Microsoft.Office.Interop.Excel;
18 18
 using static Jdas_Mbic.Bluecell_BootProtocol;
19 19
 using System.Threading;
20
+using System.IO;
20 21
 
21 22
 namespace Jdas_Mbic
22 23
 {
@@ -2699,6 +2700,186 @@ namespace Jdas_Mbic
2699 2700
             temp_buf[(int)Bluecell_ProtIndex_p.Bluecell_data + 2] = 1; //CRC
2700 2701
             serial.Serial_DataSend(temp_buf, temp_buf.Length);
2701 2702
         }
2703
+        UInt32[] crc32_tab = {
2704
+        0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
2705
+        0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
2706
+        0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
2707
+        0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
2708
+        0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
2709
+        0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
2710
+        0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
2711
+        0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
2712
+        0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
2713
+        0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
2714
+        0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
2715
+        0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
2716
+        0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
2717
+        0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
2718
+        0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
2719
+        0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
2720
+        0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
2721
+        0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
2722
+        0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
2723
+        0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
2724
+        0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
2725
+        0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
2726
+        0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
2727
+        0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
2728
+        0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
2729
+        0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
2730
+        0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
2731
+        0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
2732
+        0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
2733
+        0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
2734
+        0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
2735
+        0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
2736
+        0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
2737
+        0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
2738
+        0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
2739
+        0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
2740
+        0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
2741
+        0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
2742
+        0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
2743
+        0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
2744
+        0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
2745
+        0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
2746
+        0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
2747
+    };
2748
+
2749
+        UInt32 crc32(UInt32 crc, byte[] buf, UInt32 size)					
2750
+        {
2751
+            int i = 0;
2752
+            crc = crc ^ ~0U;					
2753
+					
2754
+            while (i < size) {					
2755
+                crc = crc32_tab[(crc ^ buf[i]) & 0xFF] ^ (crc >> 8);
2756
+                i++;
2757
+            }					
2758
+					
2759
+            return crc ^ ~0U;					
2760
+        }
2761
+
2762
+        byte[] MBIC_BootLoader_DataArray;
2763
+        byte[] MBIC_Add_BootLoader_DataArray = new byte[128];
2764
+        const string MBIC_HeaderName = "JT-NRDAS ";
2765
+        const string MBIC_HeaderFileName = "jhfs-mbic-nrdas-v00.00.01.mbc";
2766
+        private byte[] DataToConvertHex(string date)
2767
+        {
2768
+            char[] tmpret;
2769
+            byte[] ret = new byte[6];
2770
+            tmpret = date.ToCharArray();
2771
+
2772
+            for (int i = 0; i < date.Length/2; i++)
2773
+            {
2774
+                ret[i] = Convert.ToByte((tmpret[i * 2] & 0x0F) * 10) ;
2775
+                ret[i] += Convert.ToByte((tmpret[(i * 2) + 1] & 0x0F));
2776
+            }
2777
+
2778
+            return ret;
2779
+        }
2780
+        private void button_Test_Click(object sender, EventArgs e)
2781
+        {
2782
+            char[] tempchardata;
2783
+            OpenFileDialog Mbic_ofd = new OpenFileDialog();
2784
+            UInt32 Crcret = 0;
2785
+            byte[] tempdata = new byte[5];
2786
+            
2787
+            //파일오픈창 생성 및 설정
2788
+            Mbic_ofd.Title = "업데이터 파일 탐색기";
2789
+            Mbic_ofd.FileName = "*.bin";
2790
+            Mbic_ofd.Filter = "binary 파일 (*.binary,*.bin) | *.binary;, *.bin; | 모든 파일 (*.*) | *.*";
2791
+            string s3 = DateTime.Now.ToString("yyMMddHHmmss");
2792
+            //string s3 = DateTime.Now.ToString("yyMMdd");
2793
+
2794
+            //파일 오픈창 로드
2795
+            DialogResult dr = Mbic_ofd.ShowDialog();
2796
+
2797
+            //OK버튼 클릭시
2798
+            if (dr == DialogResult.OK)
2799
+            {
2800
+                //File명과 확장자를 가지고 온다.
2801
+                string fileName = Mbic_ofd.SafeFileName;
2802
+                //File경로와 File명을 모두 가지고 온다.
2803
+                string fileFullName = Mbic_ofd.FileName;
2804
+                //File경로만 가지고 온다.
2805
+                string filePath = fileFullName.Replace(fileName, "");
2806
+                this.serial.debug_hextoasciiConvert();
2807
+
2808
+                //출력 예제용 로직
2809
+                //  label1.Text = "File Name  : " + fileName;
2810
+                // label2.Text = "Full Name  : " + fileFullName;
2811
+                // label3.Text = "File Path  : " + filePath;`
2812
+                //File경로 + 파일명 리턴
2813
+                //JT-NRDAS 
2814
+                tempchardata = MBIC_HeaderName.ToCharArray();
2815
+                for(int i = 0; i < tempchardata.Length; i++)
2816
+                {
2817
+                    MBIC_Add_BootLoader_DataArray[i] = Convert.ToByte(tempchardata[i]);
2818
+                }
2819
+                MBIC_Add_BootLoader_DataArray[9] = 0x20; //file type : MBIC 0x20
2820
+                MBIC_Add_BootLoader_DataArray[10] = 0x00; //file type : CPU 0x00
2821
+                MBIC_Add_BootLoader_DataArray[11] = 0x00;//version
2822
+                MBIC_Add_BootLoader_DataArray[12] = 0x00;//version
2823
+                MBIC_Add_BootLoader_DataArray[13] = 0x01;//version
2824
+
2825
+                tempchardata = MBIC_HeaderFileName.ToCharArray();
2826
+                for (int i = 14; i < 14 + tempchardata.Length + 12; i++) // Total 41byte Filename
2827
+                {
2828
+                    try
2829
+                    {
2830
+                        MBIC_Add_BootLoader_DataArray[i] = Convert.ToByte(tempchardata[i - 14]);
2831
+                    }
2832
+                    catch
2833
+                    {
2834
+                        MBIC_Add_BootLoader_DataArray[i] = 0x20;
2835
+                    }
2836
+                }
2837
+                
2838
+                tempchardata = s3.ToCharArray();
2839
+                for (int i = 55; i < 54 + tempchardata.Length / 2; i++)
2840
+                {
2841
+                    MBIC_Add_BootLoader_DataArray[i] = DataToConvertHex(s3)[i - 55];
2842
+                }
2843
+                MBIC_BootLoader_DataArray = File.ReadAllBytes(Mbic_ofd.FileName);
2844
+                MBIC_Add_BootLoader_DataArray[60] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0xFF00) >> 8);
2845
+                MBIC_Add_BootLoader_DataArray[61] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0x00FF));
2846
+
2847
+                Crcret = crc32(0, MBIC_BootLoader_DataArray, Convert.ToUInt32(MBIC_BootLoader_DataArray.Length));
2848
+                MBIC_Add_BootLoader_DataArray[62] = Convert.ToByte((Crcret & 0xFF000000) >> (8 * 3));
2849
+                MBIC_Add_BootLoader_DataArray[63] = Convert.ToByte((Crcret & 0x00FF0000) >> (8 * 2));
2850
+                MBIC_Add_BootLoader_DataArray[64] = Convert.ToByte((Crcret & 0x0000FF00) >> (8 * 1));
2851
+                MBIC_Add_BootLoader_DataArray[65] = Convert.ToByte((Crcret & 0x000000FF) >> (8 * 0));
2852
+                for (int i = 0; i < 62; i++)
2853
+                    MBIC_Add_BootLoader_DataArray[66 + i] = 0x20;
2854
+
2855
+                byte[] RetBinary = new byte[MBIC_Add_BootLoader_DataArray.Length + MBIC_BootLoader_DataArray.Length];
2856
+                Array.Copy(MBIC_Add_BootLoader_DataArray, 0, RetBinary, 0, MBIC_Add_BootLoader_DataArray.Length);
2857
+                Array.Copy(MBIC_BootLoader_DataArray, 0, RetBinary, MBIC_Add_BootLoader_DataArray.Length, MBIC_BootLoader_DataArray.Length);
2858
+                System.IO.FileStream infile = new System.IO.FileStream("FileName.bin", System.IO.FileMode.Create); //파일 스트림 선언
2859
+
2860
+                infile.Write(RetBinary, 0, RetBinary.Length);    //쓰기
2861
+                infile.Close();                  //꼭 닫아 주세요. 파일 입출력엔 엄청 중요하죠.
2862
+                /*    
2863
+                    tempdata[0] = 0xbe;
2864
+                    tempdata[1] = Termianl_Reset;
2865
+                    tempdata[2] = 0x02;
2866
+                    tempdata[3] = STH30_CreateCrc(tempdata, tempdata[2]);
2867
+                    tempdata[4] = 0xeb;
2868
+
2869
+                    this.serial.Serial_DataSend(tempdata, 5);*/
2870
+                try
2871
+                {
2872
+                    // Controller_Debug.Controller_TX_TextLoad(tempdata);
2873
+                }
2874
+                catch { }
2875
+            
2876
+            }
2877
+            //취소버튼 클릭시 또는 ESC키로 파일창을 종료 했을경우
2878
+            else if (dr == DialogResult.Cancel)
2879
+            {
2880
+            }
2881
+
2882
+        }
2702 2883
     }
2703 2884
     class AutoClosingMessageBox
2704 2885
     {

BIN
Jdas_Mbic/bin/Debug/FileName.bin


BIN
Jdas_Mbic/bin/Debug/Jdas_Mbic.exe


BIN
Jdas_Mbic/bin/Debug/Jdas_Mbic.pdb


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.csproj.GenerateResource.cache


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.exe


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.pdb