Kaynağa Gözat

MBIC Merge 함수 추가 /CRC16추가 /

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

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


+ 102 - 1
Jdas_Mbic/Func/Bluecell_BootProtocol.cs

@@ -120,7 +120,38 @@ namespace Jdas_Mbic
120 120
         byte ATT_ALC4_L;
121 121
         byte bluecell_crc;        
122 122
     };
123
+    enum MBICProt_st
124
+    {
125
+        MBIC_PREAMBLE_0 = 0,
126
+        MBIC_PREAMBLE_1,
127
+        MBIC_PREAMBLE_2,
128
+        MBIC_PREAMBLE_3,
129
+        MBIC_SUBUID_0,
130
+        MBIC_SUBUID_1,
131
+        MBIC_RCODE_0,
132
+        MBIC_TRID_0,
133
+        MBIC_TRID_1,
134
+        MBIC_SEQSUM_0, // 9Index
135
+
136
+        MBIC_TTL_0, //10 INDEX
137
+        MBIC_TIME_0,
138
+        MBIC_TIME_1,
139
+        MBIC_TIME_2,
140
+        MBIC_TIME_3,
141
+        MBIC_TIME_4,
142
+        MBIC_TIME_5,
143
+        MBIC_ERRRESPONSE_0,
144
+        MBIC_CMD_0,
145
+
146
+        MBIC_LENGTH_0, // 19INDEX
147
+        MBIC_LENGTH_1, // 20
123 148
 
149
+        MBIC_HEADERCHECKSUM_0,
150
+        MBIC_PAYLOADSTART,
151
+        /*
152
+         * PayLoadSTART
153
+         */
154
+    };
124 155
     class Bluecell_BootProtocol
125 156
     {
126 157
         public enum DATATYPE
@@ -209,7 +240,77 @@ namespace Jdas_Mbic
209 240
         public const byte BLUECELL_TAILER = 0xEB;
210 241
         const byte BLUECELL_RESET_LENGTH = 6;
211 242
         const byte BLUECELL_FIX_DATA_LENGTH = 3;
212
-        
243
+
244
+        const byte MBIC_HEADER_SIZE = 22;
245
+        const byte MBIC_PREAMBLE0 = 0x16;
246
+        const byte MBIC_PREAMBLE1 = 0x16;
247
+        const byte MBIC_PREAMBLE2 = 0x16;
248
+        const byte MBIC_PREAMBLE3 = 0x16;
249
+        const byte MBIC_SUBUID0 = 0x00;
250
+        const byte MBIC_SUBUID1 = 0xF1;
251
+        const byte MBIC_RCODE = 0x00;
252
+        const byte MBIC_TRID = 0x00;
253
+        const byte MBIC_SEQNUM = 0x00;
254
+        const byte MBIC_TTL = 0x00;
255
+        const byte MBIC_TIME = 0x00;
256
+        const byte MBIC_ERRRESPONSE = 0x00;
257
+        const byte MBIC_CMD = 0x00;
258
+        const byte MBIC_LENGTH = 0x00;
259
+        const byte MBIC_CHECKSHUM_INDEX = MBIC_HEADER_SIZE - 1; //CheckSUM REMOVE INDEX
260
+        const byte MBIC_ETX = 0x03;
261
+        const byte MBIC_NODE_MU = 0x80;
262
+        const byte MBIC_CPUVERSION = 0x000000;
263
+        public byte[] MBIC_HeaderMergeFunction(byte[] data, int Length)
264
+        {
265
+            byte[] ret = new byte[data.Length + 22 + 3];
266
+            UInt16 CRCData = crc16.CRC16_Generate(data, data.Length);
267
+            /*
268
+             TAIL
269
+             */
270
+            ret[(int)MBICProt_st.MBIC_PAYLOADSTART + Length + 0] = Convert.ToByte((CRCData & 0xFF00) >> 8);
271
+            ret[(int)MBICProt_st.MBIC_PAYLOADSTART + Length + 1] = Convert.ToByte((CRCData & 0x00FF));
272
+            ret[(int)MBICProt_st.MBIC_PAYLOADSTART + Length + 2] = 0x03;
273
+            /*
274
+             Header
275
+             */
276
+            ret[(int)MBICProt_st.MBIC_PREAMBLE_0] = MBIC_PREAMBLE0;
277
+            ret[(int)MBICProt_st.MBIC_PREAMBLE_1] = MBIC_PREAMBLE1;
278
+            ret[(int)MBICProt_st.MBIC_PREAMBLE_2] = MBIC_PREAMBLE2;
279
+            ret[(int)MBICProt_st.MBIC_PREAMBLE_3] = MBIC_PREAMBLE3;
280
+
281
+            ret[(int)MBICProt_st.MBIC_SUBUID_0] = MBIC_SUBUID0;
282
+            ret[(int)MBICProt_st.MBIC_SUBUID_1] = MBIC_SUBUID1;
283
+
284
+            ret[(int)MBICProt_st.MBIC_RCODE_0] = 0;
285
+
286
+            ret[(int)MBICProt_st.MBIC_TRID_0] = 0;
287
+            ret[(int)MBICProt_st.MBIC_TRID_1] = 0;
288
+
289
+            ret[(int)MBICProt_st.MBIC_SEQSUM_0] = 0;
290
+
291
+            ret[(int)MBICProt_st.MBIC_TTL_0] = 0;
292
+
293
+            ret[(int)MBICProt_st.MBIC_TIME_0] = 0;
294
+            ret[(int)MBICProt_st.MBIC_TIME_1] = 0;
295
+            ret[(int)MBICProt_st.MBIC_TIME_2] = 0;
296
+            ret[(int)MBICProt_st.MBIC_TIME_3] = 0;
297
+            ret[(int)MBICProt_st.MBIC_TIME_4] = 0;
298
+            ret[(int)MBICProt_st.MBIC_TIME_5] = 0;
299
+            ret[(int)MBICProt_st.MBIC_ERRRESPONSE_0] = MBIC_ERRRESPONSE;
300
+
301
+            ret[(int)MBICProt_st.MBIC_CMD_0] = MBIC_ERRRESPONSE;
302
+
303
+            ret[(int)MBICProt_st.MBIC_LENGTH_0] = MBIC_ERRRESPONSE;
304
+            ret[(int)MBICProt_st.MBIC_LENGTH_1] = MBIC_ERRRESPONSE;
305
+
306
+
307
+
308
+            for (int i = 0; i < data.Length; i++)
309
+                ret[(int)MBICProt_st.MBIC_PAYLOADSTART + i] = data[i];
310
+
311
+            return ret;
312
+        }
313
+
213 314
         public void Bluecell_Reset(object serial)
214 315
         {
215 316
             this.serial = (Serial)serial;

+ 80 - 10
Jdas_Mbic/Func/Crc16.cs

@@ -60,24 +60,94 @@ namespace Jdas_Mbic
60 60
                 crc = (crc << 8) ^ Table_CRC16[(((crc >> 8) ^ crcdata[counter]) & 0x00FF)];
61 61
             return crc;
62 62
         }*/
63
-    
64 63
 
65
-        public bool CRC16_Check(byte[] buf_ptr, int len,ushort checksum)
64
+        UInt16[] crc16_tab = {
65
+            0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50a5, 0x60c6, 0x70e7,
66
+            0x8108, 0x9129, 0xa14a, 0xb16b, 0xc18c, 0xd1ad, 0xe1ce, 0xf1ef,
67
+            0x1231, 0x0210, 0x3273, 0x2252, 0x52b5, 0x4294, 0x72f7, 0x62d6,
68
+            0x9339, 0x8318, 0xb37b, 0xa35a, 0xd3bd, 0xc39c, 0xf3ff, 0xe3de,
69
+            0x2462, 0x3443, 0x0420,  0x1401, 0x64e6, 0x74c7, 0x44a4, 0x5485,
70
+            0xa56a, 0xb54b, 0x8528, 0x9509, 0xe5ee, 0xf5cf, 0xc5ac, 0xd58d,
71
+            0x3653, 0x2672, 0x1611, 0x0630, 0x76d7, 0x66f6, 0x5695, 0x46b4,
72
+            0xb75b, 0xa77a, 0x9719, 0x8738, 0xf7df, 0xe7fe, 0xd79d, 0xc7bc,
73
+            0x48c4, 0x58e5, 0x6886, 0x78a7, 0x0840, 0x1861, 0x2802, 0x3823,
74
+            0xc9cc, 0xd9ed, 0xe98e, 0xf9af, 0x8948, 0x9969, 0xa90a, 0xb92b,
75
+            0x5af5, 0x4ad4, 0x7ab7, 0x6a96, 0x1a71, 0x0a50, 0x3a33, 0x2a12,
76
+            0xdbfd, 0xcbdc, 0xfbbf, 0xeb9e, 0x9b79, 0x8b58, 0xbb3b, 0xab1a,
77
+            0x6ca6, 0x7c87, 0x4ce4, 0x5cc5, 0x2c22, 0x3c03, 0x0c60, 0x1c41,
78
+            0xedae, 0xfd8f, 0xcdec, 0xddcd, 0xad2a, 0xbd0b, 0x8d68, 0x9d49,
79
+            0x7e97, 0x6eb6, 0x5ed5, 0x4ef4, 0x3e13, 0x2e32, 0x1e51, 0x0e70,
80
+            0xff9f, 0xefbe, 0xdfdd, 0xcffc, 0xbf1b, 0xaf3a, 0x9f59, 0x8f78,
81
+            0x9188, 0x81a9, 0xb1ca, 0xa1eb, 0xd10c, 0xc12d, 0xf14e, 0xe16f,
82
+            0x1080, 0x00a1, 0x30c2, 0x20e3, 0x5004, 0x4025, 0x7046, 0x6067,
83
+            0x83b9, 0x9398, 0xa3fb, 0xb3da, 0xc33d, 0xd31c, 0xe37f, 0xf35e,
84
+            0x02b1, 0x1290, 0x22f3, 0x32d2, 0x4235, 0x5214, 0x6277, 0x7256,
85
+            0xb5ea, 0xa5cb, 0x95a8, 0x8589, 0xf56e, 0xe54f, 0xd52c, 0xc50d,
86
+            0x34e2, 0x24c3, 0x14a0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
87
+            0xa7db, 0xb7fa, 0x8799, 0x97b8, 0xe75f, 0xf77e, 0xc71d, 0xd73c,
88
+            0x26d3, 0x36f2, 0x0691, 0x16b0, 0x6657, 0x7676, 0x4615, 0x5634,
89
+            0xd94c, 0xc96d, 0xf90e, 0xe92f, 0x99c8, 0x89e9, 0xb98a, 0xa9ab,
90
+            0x5844, 0x4865, 0x7806, 0x6827, 0x18c0, 0x08e1, 0x3882, 0x28a3,
91
+            0xcb7d, 0xdb5c, 0xeb3f, 0xfb1e, 0x8bf9, 0x9bd8, 0xabbb, 0xbb9a,
92
+            0x4a75, 0x5a54, 0x6a37, 0x7a16, 0x0af1, 0x1ad0, 0x2ab3, 0x3a92,
93
+            0xfd2e, 0xed0f, 0xdd6c, 0xcd4d, 0xbdaa, 0xad8b, 0x9de8, 0x8dc9,
94
+            0x7c26, 0x6c07, 0x5c64, 0x4c45, 0x3ca2, 0x2c83, 0x1ce0, 0x0cc1,
95
+            0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
96
+            0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
97
+        };
98
+
99
+        public enum etError
66 100
         {
67
-            ushort crc = 0;
68
-            for (int counter = 0; counter < len; counter++)
69
-                crc = (ushort)((crc << 8) ^ Table_CRC16[(int)(((crc >> 8) ^ buf_ptr[counter]) & 0x00FF)]);
101
+            CHECKSUM_ERROR = 0,
102
+            NO_ERROR
103
+        };
104
+        public bool Chksum_Check(byte[] data, UInt32 leng, byte chkdata)
105
+        {
106
+            byte dataret = 0;
107
+            bool ret = false;
108
+            for (int i = (int)MBICProt_st.MBIC_SUBUID_0; i < (int)MBICProt_st.MBIC_HEADERCHECKSUM_0; i++)
109
+            {
110
+                dataret += data[i];
111
+            }
112
+            if (dataret == chkdata)
113
+            {
114
+                ret = true;
115
+            }
116
+            //    printf("dataret : %x   chkdata : %x \r\n",dataret,chkdata);
117
+            return ret;
118
+        }
119
+        public byte Chksum_Create(byte[] data)
120
+        {
121
+            byte dataret = 0;
70 122
 
71
-            return (crc == checksum ? false : true);
123
+            for (int i = (int)MBICProt_st.MBIC_SUBUID_0; i < (int)MBICProt_st.MBIC_HEADERCHECKSUM_0; i++)
124
+            {
125
+                dataret += data[i];
126
+                //        printf("dataret : %x data[%d] : %x \r\n",dataret,i,data[i]);
127
+            }
128
+            //    printf("dataret : %x \r\n",dataret);
129
+            return dataret;
72 130
         }
73
-        public ushort CRC16_Generate(byte[] buf_ptr, int len)
131
+
132
+
133
+        public bool CRC16_Check(byte[] buf_ptr, int len, UInt16 checksum)
74 134
         {
75
-            ushort crc = 0;
76
-            for (int counter = 0; counter < len; counter++)
77
-                crc = (ushort)((crc << 8) ^ Table_CRC16[(int)(((crc >> 8) ^ buf_ptr[counter]) & 0x00FF)]);
135
+            UInt16 crc = 0;
136
+            for (UInt32 counter = 0; counter < len; counter++)
137
+                crc = (UInt16)((crc << 8) ^ crc16_tab[(UInt32)(((crc >> 8) ^ buf_ptr[counter]) & 0x00FF)]);
78 138
 
139
+            return (crc == checksum ? false : true);
140
+        }
141
+        public UInt16 CRC16_Generate(byte[] buf_ptr, int len)
142
+        {
143
+            UInt16 crc = 0;
144
+            for (UInt32 counter = 0; counter < len; counter++)
145
+                crc = (UInt16)((crc << 8) ^ crc16_tab[(UInt32)(((crc >> 8) ^ buf_ptr[counter]) & 0x00FF)]);
146
+            //    printf("len : %d \r\n",len);
79 147
             return crc;
80 148
         }
149
+
150
+
81 151
         
82 152
         public bool STH30_CheckCrc(byte[] data, byte nbrOfBytes, byte checksum)
83 153
         {

+ 120 - 2
Jdas_Mbic/Func/Data_Handler.cs

@@ -16,7 +16,22 @@ namespace Jdas_Mbic
16 16
         const byte Terminal_Controller_FirmwareUpdateLen = 250;
17 17
         const byte Terminal_Reset = 0x0A;
18 18
         const byte Terminal_BootStart = 0x0B;
19
-
19
+        public enum MBIC_Download_Req_L
20
+        {
21
+            MBIC_Notice_REQ = 0x10,
22
+            MBIC_Download_DATA_REQ,
23
+            MBIC_Download_Confirm_REQ,
24
+            MBIC_Complete_Notice_REQ_REQ,
25
+            MBIC_Reboot_Notice_REQ,
26
+        };
27
+        public enum MBIC_Download_Rsp_L
28
+        {
29
+            MBIC_Notice_RSP = 0x90,
30
+            MBIC_Download_DATA_RSP,
31
+            MBIC_Download_Confirm_RSP,
32
+            MBIC_Complete_Notice_RSP,
33
+            MBIC_Reboot_Notice_RSP,
34
+        };
20 35
 
21 36
         public Boolean HeaderCheck(byte[] data)
22 37
         {
@@ -28,6 +43,20 @@ namespace Jdas_Mbic
28 43
             }
29 44
             return ret;
30 45
         }
46
+
47
+        public Boolean MBIC_HeaderCheck(byte[] data)
48
+        {
49
+            Boolean ret = false;
50
+
51
+            if (data[0] == 0x16
52
+                && data[1] == 0x16
53
+                && data[2] == 0x16
54
+                && data[3] == 0x16)
55
+            {
56
+                ret = true;
57
+            }
58
+            return ret;
59
+        }
31 60
         public bool CrcCheck(byte[] data)
32 61
         {
33 62
             bool ret = false;
@@ -52,6 +81,30 @@ namespace Jdas_Mbic
52 81
             }
53 82
             return ret;
54 83
         }
84
+        public bool MBIC_CrcCheck(byte[] data)
85
+        {
86
+            bool ret = false;
87
+            Crc16 crc = new Crc16();
88
+            byte length, crcindex;
89
+            try
90
+            {
91
+                length = data[2];
92
+            }
93
+            catch
94
+            {
95
+                return ret;
96
+            }
97
+            crcindex = (byte)(length + 1);
98
+            try
99
+            {
100
+                ret = crc.CRC16_Check(data, length, data[crcindex]);
101
+            }
102
+            catch (Exception e)
103
+            {
104
+                return ret;
105
+            }
106
+            return ret;
107
+        }
55 108
         // 바이트 배열을 String으로 변환 
56 109
         private string ByteToString(byte[] strByte)
57 110
         {
@@ -66,16 +119,26 @@ namespace Jdas_Mbic
66 119
         }
67 120
         JdasMbic main_Form; //= new Main_Form();
68 121
         Serial serial;
122
+        
69 123
         public void Recv_dataCheck(object serial,object main_form, object fileDownload, byte[] data)
70 124
         {
125
+            Crc16 crc = new Crc16();
71 126
             Boolean DataCheck;
72 127
             Bluecell_BootProtocol bluecell_BootProtocol = new Bluecell_BootProtocol();
128
+
73 129
             this.serial = (Serial)serial;
74 130
             this.main_Form = (JdasMbic)main_form;
75
-            byte seq;
131
+            byte seq,cmd;
132
+            
133
+            int Length = 0;
134
+            int LastFrame = 0;
135
+            ushort  crcret = 0;
136
+            byte[] datatmp = new byte[100];
137
+            DataCheck = MBIC_HeaderCheck(data); // MBIC Header Check
76 138
             try
77 139
             {
78 140
                 seq = data[1];
141
+                
79 142
             }
80 143
             catch {
81 144
                 return;
@@ -119,6 +182,60 @@ namespace Jdas_Mbic
119 182
                 }
120 183
                 
121 184
             }
185
+            else if (DataCheck == true)/*Header Check*/
186
+            {
187
+                //(int)MBICProt_st.MBIC_PAYLOADSTART
188
+                DataCheck = MBIC_CrcCheck(data);
189
+                if(DataCheck == true)
190
+                {
191
+                    cmd = data[(int)MBICProt_st.MBIC_CMD_0];
192
+                    switch (cmd)
193
+                    {
194
+                        case (byte)MBIC_Download_Rsp_L.MBIC_Notice_RSP:
195
+                        
196
+                        case (byte)MBIC_Download_Rsp_L.MBIC_Download_DATA_RSP:
197
+                            Length = (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 0] << 24)
198
+                                    | (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 1] << 16)
199
+                                    | (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 2] << 8)
200
+                                    | (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 3]);
201
+                            LastFrame = (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 4] << 24)
202
+                                       | (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 5] << 16)
203
+                                       | (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 6] << 8)
204
+                                       | (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 7]);
205
+                            if (LastFrame != Length)
206
+                            {
207
+                                if (Length == this.main_Form.MBIC_BootLoader_DataArray.Length)
208
+                                    this.fileDownload.MBIC_FirmwareUpdateSend(ref this.serial, this.main_Form.MBIC_BootLoader_DataArray);
209
+                            }
210
+                            else
211
+                            {
212
+                                crcret = crc.CRC16_Generate(this.main_Form.MBIC_BootLoader_DataArray, this.main_Form.MBIC_BootLoader_DataArray.Length);
213
+                                datatmp[0] = (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 0]);
214
+                                datatmp[1] =  (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 1]);
215
+                                datatmp[2] =  (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 2]);
216
+                                datatmp[3] =  (data[(int)MBICProt_st.MBIC_PAYLOADSTART + 3]);
217
+                                datatmp[4] = Convert.ToByte(crcret & 0xFF00 >> 8);
218
+                                datatmp[5] = Convert.ToByte(crcret & 0xFF00 >> 8);
219
+                                datatmp[6] = Convert.ToByte(crcret & 0xFF00 >> 8);
220
+                                datatmp[7] = Convert.ToByte(crcret & 0xFF00 >> 8);
221
+                                datatmp[8] = Convert.ToByte(crcret & 0xFF00 >> 8);
222
+                                datatmp[9] = Convert.ToByte(crcret & 0xFF00 >> 8);
223
+                                datatmp[10] = Convert.ToByte(crcret & 0xFF00 >> 8);
224
+                                datatmp[11] = Convert.ToByte(crcret & 0xFF00 >> 8);
225
+
226
+                                datatmp = bluecell_BootProtocol.MBIC_HeaderMergeFunction(datatmp, 12);
227
+                                this.serial.Serial_DataSend(datatmp, 22 + 12 + 3);
228
+                            }
229
+                            
230
+                            break;
231
+                        case (byte)MBIC_Download_Rsp_L.MBIC_Download_Confirm_RSP:
232
+                            break;
233
+                        case (byte)MBIC_Download_Rsp_L.MBIC_Reboot_Notice_RSP:
234
+                            
235
+                            break;
236
+                    }
237
+                }
238
+            }
122 239
             else/* * * * * * * * * * * * * *API RECV 부분 * * * * * * * * * * * * *  */
123 240
             {
124 241
                 if(ByteToString(data).Contains("Build at") == true)
@@ -142,5 +259,6 @@ namespace Jdas_Mbic
142 259
                 bluecell_BootProtocol.Bluecell_RF_Status_Get(this.serial,this.main_Form, data);
143 260
             }
144 261
         }
262
+
145 263
     }
146 264
 }

+ 70 - 0
Jdas_Mbic/Func/Update_Serial.cs

@@ -233,6 +233,7 @@ namespace Jdas_Mbic
233 233
             catch { }
234 234
         }
235 235
 
236
+
236 237
         public void Termianl__Operate(byte[] Text)
237 238
         {
238 239
             byte Type = 0;
@@ -252,7 +253,76 @@ namespace Jdas_Mbic
252 253
                     break;
253 254
             }
254 255
         }
256
+       // private JdasMbic JdasMbic = new JdasMbic();    // Teminal Text Wnd Open
257
+       
258
+        Crc16 crc = new Crc16();
259
+        static public int MBIC_SendingCnt = 0;
260
+        static int MBIC_SendingIndex = 0;
261
+        public void MBIC_FirmwareUpdateSend(ref Serial serial,byte[] data)
262
+        {
263
+            int Length = data.Length;// + 128;
264
+            int cnt = data.Length / 1024;
265
+            int reminder = data.Length % 1024;
266
+            
267
+            byte[] SendArray = new byte[1061];//1024 + 22 + 3 + 12
268
+            MBIC_SendingCnt++;
269
+
270
+            //if (MBIC_SendingCnt <= cnt)
271
+            if (Length - MBIC_SendingIndex >= 1024)
272
+            {
273
+                Array.Copy(data, MBIC_SendingIndex, SendArray, 12, 1024);
274
+                MBIC_SendingIndex = MBIC_SendingCnt * 1024 ;
275
+                //SendArray = 
276
+                SendArray[0] = Convert.ToByte((Length & 0xFF000000) >> 24);
277
+                SendArray[1] = Convert.ToByte((Length & 0x00FF0000) >> 16);
278
+                SendArray[2] = Convert.ToByte((Length & 0x0000FF00) >> 8);
279
+                SendArray[3] = Convert.ToByte((Length & 0x000000FF));
280
+
281
+
282
+               
283
+                SendArray[4] = Convert.ToByte((MBIC_SendingIndex& 0xFF000000) >> 24);
284
+                SendArray[5] = Convert.ToByte((MBIC_SendingIndex& 0x00FF0000) >> 16);
285
+                SendArray[6] = Convert.ToByte((MBIC_SendingIndex& 0x0000FF00) >> 8);
286
+                SendArray[7] = Convert.ToByte((MBIC_SendingIndex& 0x000000FF));
287
+
288
+
289
+                SendArray = Bluecell_BootProtocol.MBIC_HeaderMergeFunction(SendArray, SendArray.Length);
290
+                SendArray[(int)MBICProt_st.MBIC_CMD_0] = 0x11;
291
+                SendArray[(int)MBICProt_st.MBIC_HEADERCHECKSUM_0] = crc.Chksum_Create(SendArray);
292
+                serial.Serial_DataSend(SendArray, 1024 + 22 + 12 + 3);
293
+                /*
294
+                 * 1024byte : data ,
295
+                 * 22byte : Header  
296
+                 * 12byte : Subdata Header , 
297
+                 * 3byte : Tail
298
+                 */
299
+            }
300
+            else
301
+            {
302
+                Array.Copy(data, MBIC_SendingIndex, SendArray, 12, reminder);
303
+                MBIC_SendingIndex += reminder;
304
+                //SendArray = 
305
+                SendArray[0] = Convert.ToByte((Length & 0xFF000000) >> 24);
306
+                SendArray[1] = Convert.ToByte((Length & 0x00FF0000) >> 16);
307
+                SendArray[2] = Convert.ToByte((Length & 0x0000FF00) >> 8);
308
+                SendArray[3] = Convert.ToByte((Length & 0x000000FF));
309
+
310
+
311
+                SendArray[4] = Convert.ToByte((MBIC_SendingIndex& 0xFF000000) >> 24);
312
+                SendArray[5] = Convert.ToByte((MBIC_SendingIndex& 0x00FF0000) >> 16);
313
+                SendArray[6] = Convert.ToByte((MBIC_SendingIndex& 0x0000FF00) >> 8);
314
+                SendArray[7] = Convert.ToByte((MBIC_SendingIndex& 0x000000FF));
255 315
 
316
+
317
+                SendArray = Bluecell_BootProtocol.MBIC_HeaderMergeFunction(SendArray, SendArray.Length);
318
+                SendArray[(int)MBICProt_st.MBIC_CMD_0] = 0x11;
319
+                SendArray[(int)MBICProt_st.MBIC_HEADERCHECKSUM_0] = crc.Chksum_Create(SendArray);
320
+
321
+                serial.Serial_DataSend(SendArray, reminder + 22 + 12 + 3);
322
+                MBIC_SendingCnt = 0;
323
+                MBIC_SendingIndex = 0;
324
+            }
325
+        }
256 326
         byte STH30_CreateCrc(byte[] data, byte nbrOfBytes)
257 327
         {
258 328
             byte bit;        // bit mask

+ 41 - 15
Jdas_Mbic/Main.cs

@@ -2759,7 +2759,7 @@ namespace Jdas_Mbic
2759 2759
             return crc ^ ~0U;					
2760 2760
         }
2761 2761
 
2762
-        byte[] MBIC_BootLoader_DataArray;
2762
+        public byte[] MBIC_BootLoader_DataArray;
2763 2763
         byte[] MBIC_Add_BootLoader_DataArray = new byte[128];
2764 2764
         const string MBIC_HeaderName = "JT-NRDAS ";
2765 2765
         const string MBIC_HeaderFileName = "jhfs-mbic-nrdas-v00.00.01.mbc";
@@ -2777,13 +2777,19 @@ namespace Jdas_Mbic
2777 2777
 
2778 2778
             return ret;
2779 2779
         }
2780
+
2781
+
2782
+        Crc16 crc = new Crc16();
2783
+
2784
+        byte[] MBIC_BootLoaderData;
2780 2785
         private void button_Test_Click(object sender, EventArgs e)
2781 2786
         {
2782 2787
             char[] tempchardata;
2783 2788
             OpenFileDialog Mbic_ofd = new OpenFileDialog();
2784 2789
             UInt32 Crcret = 0;
2785 2790
             byte[] tempdata = new byte[1027];
2786
-            
2791
+            int i = 0;
2792
+            timer_JdasMbic.Stop(); //타이머를 멈춘다.
2787 2793
             //파일오픈창 생성 및 설정
2788 2794
             Mbic_ofd.Title = "업데이터 파일 탐색기";
2789 2795
             Mbic_ofd.FileName = "*.bin";
@@ -2815,7 +2821,7 @@ namespace Jdas_Mbic
2815 2821
                 //JT-NRDAS 
2816 2822
 
2817 2823
                 tempchardata = MBIC_HeaderName.ToCharArray();
2818
-                for(int i = 0; i < tempchardata.Length; i++)
2824
+                for(i = 0; i < tempchardata.Length; i++)
2819 2825
                 {
2820 2826
                     MBIC_Add_BootLoader_DataArray[i] = Convert.ToByte(tempchardata[i]);
2821 2827
                 }
@@ -2826,7 +2832,7 @@ namespace Jdas_Mbic
2826 2832
                 MBIC_Add_BootLoader_DataArray[13] = 0x01;//version
2827 2833
 
2828 2834
                 tempchardata = MBIC_HeaderFileName.ToCharArray();
2829
-                for (int i = 14; i < 14 + tempchardata.Length + 12; i++) // Total 41byte Filename
2835
+                for (i = 14; i < 14 + tempchardata.Length + 12; i++) // Total 41byte Filename
2830 2836
                 {
2831 2837
                     try
2832 2838
                     {
@@ -2839,32 +2845,52 @@ namespace Jdas_Mbic
2839 2845
                 }
2840 2846
                 
2841 2847
                 tempchardata = s3.ToCharArray();
2842
-                for (int i = 55; i < 54 + tempchardata.Length / 2; i++)
2848
+                for (i = 55; i < 54 + tempchardata.Length / 2 + 1; i++)
2843 2849
                 {
2844 2850
                     MBIC_Add_BootLoader_DataArray[i] = DataToConvertHex(s3)[i - 55];
2845 2851
                 }
2846 2852
 
2847 2853
                 MBIC_BootLoader_DataArray = File.ReadAllBytes(Mbic_ofd.FileName);
2848
-                MBIC_Add_BootLoader_DataArray[60] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0xFF00) >> 8);
2849
-                MBIC_Add_BootLoader_DataArray[61] = Convert.ToByte((MBIC_BootLoader_DataArray.Length & 0x00FF));
2854
+                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0xFF00) >> 8);
2855
+                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128)& 0x00FF));
2850 2856
 
2851 2857
                 Crcret = crc32(0, MBIC_BootLoader_DataArray, Convert.ToUInt32(MBIC_BootLoader_DataArray.Length));
2852
-                MBIC_Add_BootLoader_DataArray[62] = Convert.ToByte((Crcret & 0xFF000000) >> (8 * 3));
2853
-                MBIC_Add_BootLoader_DataArray[63] = Convert.ToByte((Crcret & 0x00FF0000) >> (8 * 2));
2854
-                MBIC_Add_BootLoader_DataArray[64] = Convert.ToByte((Crcret & 0x0000FF00) >> (8 * 1));
2855
-                MBIC_Add_BootLoader_DataArray[65] = Convert.ToByte((Crcret & 0x000000FF) >> (8 * 0));
2858
+                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0xFF000000) >> (8 * 3));
2859
+                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x00FF0000) >> (8 * 2));
2860
+                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x0000FF00) >> (8 * 1));
2861
+                MBIC_Add_BootLoader_DataArray[i++] = Convert.ToByte((Crcret & 0x000000FF) >> (8 * 0));
2856 2862
 
2857
-                for (int i = 0; i < 62; i++)
2863
+                for (i = 0; i < 62; i++)
2858 2864
                     MBIC_Add_BootLoader_DataArray[66 + i] = 0x00;
2859 2865
 
2860 2866
                 byte[] RetBinary = new byte[MBIC_Add_BootLoader_DataArray.Length + MBIC_BootLoader_DataArray.Length];
2861 2867
                 Array.Copy(MBIC_Add_BootLoader_DataArray, 0, RetBinary, 0, MBIC_Add_BootLoader_DataArray.Length);
2862 2868
                 Array.Copy(MBIC_BootLoader_DataArray, 0, RetBinary, MBIC_Add_BootLoader_DataArray.Length, MBIC_BootLoader_DataArray.Length);
2863 2869
 
2864
-                //System.IO.FileStream infile = new System.IO.FileStream("FileName.bin", System.IO.FileMode.Create); //파일 스트림 선언
2870
+//                System.IO.FileStream infile = new System.IO.FileStream("FileName.bin", System.IO.FileMode.Create); //파일 스트림 선언
2865 2871
                 //infile.Write(RetBinary, 0, RetBinary.Length);    //쓰기
2866
-                //infile.Close();                  //꼭 닫아 주세요. 파일 입출력엔 엄청 중요하죠.
2867
-                this.serial.Serial_DataSend(RetBinary, 128);
2872
+//                infile.Close();                  //꼭 닫아 주세요. 파일 입출력엔 엄청 중요하죠.
2873
+
2874
+                MBIC_BootLoaderData = bluecell_BootProtocol.MBIC_HeaderMergeFunction(RetBinary, RetBinary.Length);
2875
+
2876
+                /*Download Start Request*/
2877
+                /*tempdata[0] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0xFF000000) >> 24);
2878
+                tempdata[1] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0x00FF0000) >> 16);
2879
+                tempdata[2] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0x0000FF00) >> 8);
2880
+                tempdata[3] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length + 128) & 0x000000FF));*/
2881
+                tempdata[0] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length) & 0xFF000000) >> 24);
2882
+                tempdata[1] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length) & 0x00FF0000) >> 16);
2883
+                tempdata[2] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length) & 0x0000FF00) >> 8);
2884
+                tempdata[3] = Convert.ToByte(((MBIC_BootLoader_DataArray.Length) & 0x000000FF));
2885
+                tempdata[4] = 0;
2886
+                tempdata[5] = 0;
2887
+                tempdata[6] = 0;
2888
+                tempdata[7] = 0;
2889
+                tempdata = bluecell_BootProtocol.MBIC_HeaderMergeFunction(tempdata, 8);
2890
+                tempdata[(int)MBICProt_st.MBIC_CMD_0] = 0x10;
2891
+                tempdata[(int)MBICProt_st.MBIC_HEADERCHECKSUM_0] = crc.Chksum_Create(tempdata);
2892
+                this.serial.Serial_DataSend(tempdata, 8 + 22 + 3);
2893
+                //this.serial.Serial_DataSend(MBIC_BootLoaderData, 1024 + 22 + 3);
2868 2894
 
2869 2895
                 /*    
2870 2896
                     tempdata[0] = 0xbe;

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/bin/Debug/Untitled1


BIN
Jdas_Mbic/bin/Debug/Untitled1.bak


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


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.exe


BIN
Jdas_Mbic/obj/Debug/Jdas_Mbic.pdb