Преглед на файлове

CRC8 추가 / BootLoader Seq 추가 / Bootloader Progressbar 추가 /

YJ преди 6 години
родител
ревизия
1596bd0d26

+ 21 - 2
Basic_Terminal/Func/Crc16.cs

@@ -87,7 +87,7 @@ namespace Basic_Terminal
87 87
             return (crc16);
88 88
         }
89 89
 
90
-        EtError CRC16_Check(byte[] buf_ptr, int len, ushort checksum)
90
+        public EtError CRC16_Check(byte[] buf_ptr, int len, ushort checksum)
91 91
         {
92 92
             byte dt = 0;
93 93
             ushort crc16 = 0;
@@ -121,8 +121,27 @@ namespace Basic_Terminal
121 121
             }
122 122
             return (crc16 == checksum ? EtError.CHECKSUM_ERROR : EtError.NO_ERROR);
123 123
         }
124
+        public byte STH30_CheckCrc(byte[] data, byte nbrOfBytes, byte checksum)
125
+        {
126
+            byte bit;        // bit mask
127
+            int crc = 0xFF; // calculated checksum
128
+            byte byteCtr;    // byte counter
129
+            byte index = 1;
124 130
 
125
-        byte STH30_CreateCrc(byte[] data, byte nbrOfBytes)
131
+            // calculates 8-Bit checksum with given polynomial
132
+            for (byteCtr = 0; byteCtr < nbrOfBytes; byteCtr++)
133
+            {
134
+                crc ^= (data[index++]);
135
+                for (bit = 8; bit > 0; --bit)
136
+                {
137
+                    if (Convert.ToBoolean(crc & 0x80)) { crc = (crc << 1) ^ POLYNOMIAL; }
138
+                    else crc = (crc << 1);
139
+                }
140
+            }
141
+            if (crc != checksum) return 0;
142
+            else return 1;
143
+        }
144
+        public byte STH30_CreateCrc(byte[] data, byte nbrOfBytes)
126 145
         {
127 146
             byte bit;        // bit mask
128 147
             int crc = 0xFF; // calculated checksum

+ 53 - 27
Basic_Terminal/Func/Data_Handler.cs

@@ -10,51 +10,77 @@ namespace Basic_Terminal
10 10
     {
11 11
         //FileDownload fileDownload;
12 12
         Update_Serial fileDownload;
13
-        
13
+        const byte Terminal_Controller_Update_Ack = 0x11;
14
+        const byte Terminal_Controller_Update_Nak = 0x22;
15
+        const byte Terminal_Controller_FirmwareUpdateLen = 250;
16
+        const byte Terminal_Reset = 0x0A;
17
+        const byte Terminal_BootStart = 0x0B;
18
+
19
+
20
+        private Boolean HeaderCheck(byte[] data)
21
+        {
22
+            Boolean ret = false;
23
+
24
+            if(data[0] == 0xbe)
25
+            {
26
+                ret = true;
27
+            }
28
+            return ret;
29
+        }
30
+        private byte CrcCheck(byte[] data)
31
+        {
32
+            byte ret = 0;
33
+            Crc16 crc = new Crc16();
34
+            byte length,crcindex;
35
+            length = data[2];
36
+            crcindex = (byte)(length + 1);
37
+            ret = crc.STH30_CheckCrc(data,length,data[crcindex]);
38
+
39
+
40
+            return ret;
41
+        }
14 42
         public void Recv_dataCheck(object fileDownload, byte[] data)
15 43
         {
16
-            Boolean HeaderCheck;
17
-            byte seq = data[1];
44
+            Boolean Header_Check;
45
+            byte Crc_Check,seq = data[1];
18 46
             if (fileDownload != null)
19 47
             {
20
-              // this.fileDownload = (FileDownload)fileDownload;
21 48
                 this.fileDownload = (Update_Serial)fileDownload;
22 49
             }
23 50
             else
24 51
             {
25
-            //    this.fileDownload = new FileDownload();
26 52
                 this.fileDownload = new Update_Serial();
27 53
             }
28 54
             if (this.fileDownload.Update_ready == true)
29 55
             {
30
-                
31
-               /* HeaderCheck = this.fileDownload.Serial_HeaderCheck(data);
32
-
33
-
34
-
35
-                if (HeaderCheck == false)
56
+                Header_Check = HeaderCheck(data);
57
+                if (Header_Check == false)
36 58
                 {
37 59
                     return;
38 60
                 }
39
-                else*/
61
+                Crc_Check = CrcCheck(data);
62
+                if(Crc_Check == 0)
40 63
                 {
64
+                    return;
65
+                }
66
+
41 67
 
42
-                    switch (seq)
43
-                    {
44
-                        case 0x0a:
45
-                        case 0x0b:
46
-                        case 0x11:
47
-                        case 0x22:
48
-                            //int DataAckcnt = data[(int)Bluepro_t.bluecell_type + 1];
49
-                            //this.fileDownload.UpdateFileSend(data, DataAckcnt);
50
-                            this.fileDownload.Termianl__Operate(data);
51
-                            break;
52
-                        case 3:
53
-                            break;
54
-                        default:
55
-                            break;
56
-                    }
68
+                switch (seq)
69
+                {
70
+                    case Terminal_Reset:
71
+                    case Terminal_BootStart:
72
+                    case Terminal_Controller_Update_Ack:
73
+                    case Terminal_Controller_Update_Nak:
74
+                        //int DataAckcnt = data[(int)Bluepro_t.bluecell_type + 1];
75
+                        //this.fileDownload.UpdateFileSend(data, DataAckcnt);
76
+                        this.fileDownload.Termianl__Operate(data);
77
+                        break;
78
+                    case 3:
79
+                        break;
80
+                    default:
81
+                        break;
57 82
                 }
83
+                
58 84
             }
59 85
         }
60 86
     }

+ 16 - 16
Basic_Terminal/Func/Update_Serial.cs

@@ -5,9 +5,9 @@ using System.Linq;
5 5
 using System.Text;
6 6
 using System.Threading.Tasks;
7 7
 
8
-
9 8
 using System.Windows.Forms;
10 9
 
10
+
11 11
 namespace Basic_Terminal
12 12
 {
13 13
     class Update_Serial
@@ -30,8 +30,8 @@ namespace Basic_Terminal
30 30
         const int POLYNOMIAL = 0x131; // P(x) = x^8 + x^5 + x^4 + 1 = 100110001
31 31
         Bluecell_BootProtocol Bluecell_BootProtocol = new Bluecell_BootProtocol();
32 32
         Download_bar download_Bar = new Download_bar();
33
-
34
-
33
+        private delegate void StringSend(string Text);
34
+        private delegate void VoidSend();
35 35
         OpenFileDialog ofd;
36 36
         Serial serial;
37 37
 
@@ -84,7 +84,6 @@ namespace Basic_Terminal
84 84
 
85 85
                 Firmware_byte_load = File.ReadAllBytes(this.ofd.FileName);
86 86
                 FirmTotalcnt = Firmware_byte_load.Length / Termianl_Controller_FirmwareUpdateLen;
87
-                // for (int i = 0; i < Termianl_Controller_FirmwareUpdateLen; i++)
88 87
 
89 88
                 FirmCurrcnt = 0;
90 89
                 PreFirmSendingcnt = 0;
@@ -95,18 +94,14 @@ namespace Basic_Terminal
95 94
                 tempdata[2] = 0x02;
96 95
                 tempdata[3] = STH30_CreateCrc(tempdata, tempdata[2]);
97 96
                 tempdata[4] = 0xeb;
98
-                /*try
99
-                {
100
-                    serialPort1.Write(tempdata, 0, 5);
101
-                }
102
-                catch { MessageBox.Show("Port Open Failed!!!"); }*/
97
+               
103 98
                 this.serial.Serial_DataSend(tempdata, 5);
104 99
                 try
105 100
                 {
106 101
                    // Controller_Debug.Controller_TX_TextLoad(tempdata);
107 102
                 }
108 103
                 catch { }
109
-                //download_Bar.ShowDialog();
104
+                download_Bar.ShowDialog();
110 105
                 /*Update_label.Visible = true;
111 106
                 progressBar1.Visible = true;*/
112 107
                 return fileFullName;
@@ -159,9 +154,12 @@ namespace Basic_Terminal
159 154
                     }
160 155
                     temp_data[temp_data[2] + 1] = STH30_CreateCrc(temp_data, temp_data[2]);
161 156
                     temp_data[temp_data[2] + 2] = blucell_etx;
162
-                    /*ownload_Bar.ShowDialog();
163
-                    download_Bar.Progressbar("0 %");
164
-                    download_Bar.Close();*/
157
+                    /*ownload_Bar.ShowDialog();*/
158
+                    this.download_Bar.Invoke(new StringSend(this.download_Bar.Progressbar), "0 %");
159
+                    //download_Bar.Progressbar("0 %");
160
+
161
+                    this.download_Bar.FormClosed(this.download_Bar);
162
+                   
165 163
                     /*Update_label.Text = "0%";
166 164
                     Update_label.Visible = false;
167 165
                     progressBar1.Visible = false;
@@ -204,13 +202,15 @@ namespace Basic_Terminal
204 202
             int tempupdateret = Firmware_byte_load.Length / 100;
205 203
             tempupdateret = FirmSendingcnt / tempupdateret;
206 204
             //CheckForIllegalCrossThreadCalls = false;
207
-            //Update_label.Text = Convert.ToString(tempupdateret) + "%";
205
+            this.download_Bar.Update_Percent(Convert.ToString(tempupdateret));
208 206
             if (pretempupdateret != tempupdateret)
209 207
             {
210 208
 
211
-                for (int i = 0; i < tempupdateret - pretempupdateret; i++)
209
+                for (int i = 0; i <= tempupdateret - this.download_Bar.Update_get(); i++)
212 210
                 {
213
-                   // progressBar1.PerformStep();
211
+                    this.download_Bar.PerformStepup(this.download_Bar);
212
+                    //this.download_Bar.PerformStepinc(tempupdateret);
213
+                    // progressBar1.PerformStep();
214 214
                 }
215 215
 
216 216
                 pretempupdateret = tempupdateret;

+ 10 - 10
Basic_Terminal/Wnd/Download_bar.Designer.cs

@@ -28,20 +28,20 @@
28 28
         /// </summary>
29 29
         private void InitializeComponent()
30 30
         {
31
-            this.progressBar1 = new System.Windows.Forms.ProgressBar();
31
+            this.Firm_Progressbar = new System.Windows.Forms.ProgressBar();
32 32
             this.Update_label = new System.Windows.Forms.Label();
33 33
             this.SuspendLayout();
34 34
             // 
35
-            // progressBar1
35
+            // Firm_Progressbar
36 36
             // 
37
-            this.progressBar1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
37
+            this.Firm_Progressbar.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
38 38
             | System.Windows.Forms.AnchorStyles.Left) 
39 39
             | System.Windows.Forms.AnchorStyles.Right)));
40
-            this.progressBar1.Location = new System.Drawing.Point(52, 24);
41
-            this.progressBar1.Name = "progressBar1";
42
-            this.progressBar1.Size = new System.Drawing.Size(398, 46);
43
-            this.progressBar1.Step = 1;
44
-            this.progressBar1.TabIndex = 133;
40
+            this.Firm_Progressbar.Location = new System.Drawing.Point(12, 24);
41
+            this.Firm_Progressbar.Name = "Firm_Progressbar";
42
+            this.Firm_Progressbar.Size = new System.Drawing.Size(478, 46);
43
+            this.Firm_Progressbar.Step = 1;
44
+            this.Firm_Progressbar.TabIndex = 133;
45 45
             // 
46 46
             // Update_label
47 47
             // 
@@ -64,7 +64,7 @@
64 64
             this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
65 65
             this.ClientSize = new System.Drawing.Size(502, 94);
66 66
             this.Controls.Add(this.Update_label);
67
-            this.Controls.Add(this.progressBar1);
67
+            this.Controls.Add(this.Firm_Progressbar);
68 68
             this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None;
69 69
             this.Name = "Download_bar";
70 70
             this.Text = "Download_bar";
@@ -75,7 +75,7 @@
75 75
 
76 76
         #endregion
77 77
 
78
-        private System.Windows.Forms.ProgressBar progressBar1;
78
+        private System.Windows.Forms.ProgressBar Firm_Progressbar;
79 79
         public System.Windows.Forms.Label Update_label;
80 80
     }
81 81
 }

+ 29 - 0
Basic_Terminal/Wnd/Download_bar.cs

@@ -20,5 +20,34 @@ namespace Basic_Terminal
20 20
         {
21 21
             Update_label.Text = val;
22 22
         }
23
+        public new void FormClosed(object form)
24
+        {
25
+            Download_bar download_Bar = (Download_bar)form;
26
+            CheckForIllegalCrossThreadCalls = false;
27
+            download_Bar.Close();
28
+        }
29
+        public void PerformStepup(object form)
30
+        {
31
+            Download_bar download_Bar = (Download_bar)form;
32
+            CheckForIllegalCrossThreadCalls = false;
33
+            Firm_Progressbar.PerformStep();
34
+        }
35
+        public void PerformStepinc(int val)
36
+        {
37
+            //Download_bar download_Bar = (Download_bar)form;
38
+            CheckForIllegalCrossThreadCalls = false;
39
+            Firm_Progressbar.Increment(val);
40
+        }
41
+        public void Update_Percent(String val)
42
+        {
43
+            CheckForIllegalCrossThreadCalls = false;
44
+            Firm_Progressbar.PerformStep();
45
+            Update_label.Text = val + "%";
46
+        }
47
+        public int Update_get()
48
+        {
49
+            return Firm_Progressbar.Value;
50
+        }
51
+
23 52
     }
24 53
 }