|
|
@@ -20,7 +20,13 @@ namespace Basic_Terminal
|
|
20
|
20
|
bluecell_data,
|
|
21
|
21
|
|
|
22
|
22
|
};
|
|
23
|
|
-
|
|
|
23
|
+ enum Updateseq
|
|
|
24
|
+ {
|
|
|
25
|
+ Bluecell_Reset = 0,
|
|
|
26
|
+ Bluecell_Firmupdate_start,
|
|
|
27
|
+ Bluecell_Firmupdate_sending,
|
|
|
28
|
+ Bluecell_Firmupdate_end,
|
|
|
29
|
+ };
|
|
24
|
30
|
class Bluecell_BootProtocol
|
|
25
|
31
|
{
|
|
26
|
32
|
Serial serial;
|
|
|
@@ -30,87 +36,80 @@ namespace Basic_Terminal
|
|
30
|
36
|
public const byte Bluecell_Header2 = 0x55;//ASCII : U
|
|
31
|
37
|
public const byte Bluecell_Header3 = 0x45;//ASCII : E
|
|
32
|
38
|
/*bluecell type*/
|
|
33
|
|
- public const byte Bluecell_Reset = 0x52;//ASCII : R
|
|
34
|
|
- public const byte Bluecell_Firmupdate_start = 0x55;//ASCII : U
|
|
35
|
|
- public const byte Bluecell_Firmupdate_sending = 0x53;//ASCII : S
|
|
36
|
|
- public const byte Bluecell_Firmupdate_end = 0x65;//ASCII : e
|
|
|
39
|
+
|
|
37
|
40
|
|
|
38
|
41
|
public const int bluecell_Firmupdate_sendlength = 1024;
|
|
|
42
|
+ public const byte bluecell_header = 4;
|
|
|
43
|
+ public const byte bluecell_type = 1;
|
|
|
44
|
+ public const byte bluecell_length = 2;
|
|
|
45
|
+ public const byte bluecell_updatecnt = 2;
|
|
|
46
|
+ public const byte bluecell_crc16 = 2;
|
|
|
47
|
+ public const byte bluecell_nessarybyte = bluecell_header + bluecell_type + bluecell_length + bluecell_updatecnt + bluecell_crc16;
|
|
39
|
48
|
Crc16 crc16 = new Crc16();
|
|
40
|
49
|
|
|
41
|
50
|
public int Bluecell_Firmupdate_sendlength() {
|
|
42
|
51
|
return bluecell_Firmupdate_sendlength;
|
|
43
|
52
|
}
|
|
44
|
|
-
|
|
45
|
|
- public byte[] Boot_Reset(object serial)
|
|
|
53
|
+ private void BootHeaderput(ref byte[] fix_data)
|
|
46
|
54
|
{
|
|
47
|
|
- this.serial = (Serial)serial;
|
|
48
|
|
- byte[] fix_data = new byte[11];
|
|
49
|
|
- //Array.Clear(data, 0, data.Length);
|
|
50
|
55
|
fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
|
|
51
|
56
|
fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
|
|
52
|
57
|
fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
|
|
53
|
58
|
fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
|
|
54
|
|
- fix_data[(int)Bluepro_t.bluecell_type] = Bluecell_Reset;
|
|
|
59
|
+ }
|
|
|
60
|
+
|
|
|
61
|
+ public byte[] Boot_Reset(object serial,byte[] Updatedata)
|
|
|
62
|
+ {
|
|
|
63
|
+ this.serial = (Serial)serial;
|
|
|
64
|
+ byte[] fix_data = new byte[11];
|
|
|
65
|
+ //Array.Clear(data, 0, data.Length);
|
|
|
66
|
+ BootHeaderput(ref fix_data);
|
|
|
67
|
+ fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Reset;
|
|
55
|
68
|
fix_data[(int)Bluepro_t.bluecell_length_h] = 0;
|
|
56
|
69
|
fix_data[(int)Bluepro_t.bluecell_length_l] = 5;
|
|
57
|
|
- fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = 0;
|
|
58
|
|
- fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = 0;
|
|
|
70
|
+ fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((Updatedata.Length & 0xFF00) >> 8);
|
|
|
71
|
+ fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((Updatedata.Length & 0x00FF));
|
|
59
|
72
|
|
|
60
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0xFF00) >> 8);
|
|
61
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0x00FF));
|
|
|
73
|
+ fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0xFF00) >> 8);
|
|
|
74
|
+ fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length - 4) & 0x00FF));
|
|
62
|
75
|
this.serial.Serial_DataSend(fix_data, fix_data.Length);
|
|
63
|
76
|
return fix_data;
|
|
64
|
77
|
}
|
|
65
|
|
- public byte[] Boot_DataStart()
|
|
|
78
|
+
|
|
|
79
|
+ public byte[] Boot_DataSending(byte[] update_data,UInt16 length, UInt16 updatacnt)
|
|
66
|
80
|
{
|
|
67
|
81
|
//Array.Clear(data, 0, data.Length);
|
|
68
|
|
- byte[] fix_data = new byte[11];
|
|
69
|
|
- fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
|
|
70
|
|
- fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
|
|
71
|
|
- fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
|
|
72
|
|
- fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
|
|
73
|
|
- fix_data[(int)Bluepro_t.bluecell_type] = Bluecell_Firmupdate_start;
|
|
74
|
|
- fix_data[(int)Bluepro_t.bluecell_length_h] = 0;
|
|
75
|
|
- fix_data[(int)Bluepro_t.bluecell_length_l] = 3;
|
|
76
|
|
- fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = 0;
|
|
77
|
|
- fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = 0;
|
|
78
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0xFF00) >> 8);
|
|
79
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((crc16.CRC16_Generate(fix_data, fix_data.Length) & 0x00FF));
|
|
|
82
|
+ byte[] fix_data = new byte[bluecell_Firmupdate_sendlength];
|
|
|
83
|
+ //BootHeaderput(ref fix_data);
|
|
|
84
|
+ //length += 5;
|
|
|
85
|
+ Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
|
|
|
86
|
+ BootHeaderput(ref fix_data);
|
|
|
87
|
+ fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_sending;
|
|
|
88
|
+ fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
|
|
|
89
|
+ fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
|
|
|
90
|
+ fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = Convert.ToByte((updatacnt & 0xFF00) >> 8);
|
|
|
91
|
+ fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = Convert.ToByte((updatacnt & 0x00FF));
|
|
|
92
|
+
|
|
|
93
|
+ //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
|
|
|
94
|
+ fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
|
|
|
95
|
+ fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
|
|
80
|
96
|
return fix_data;
|
|
81
|
97
|
}
|
|
82
|
|
- public byte[] Boot_DataSending(byte[] data,int length)
|
|
83
|
|
- {
|
|
84
|
|
- //Array.Clear(data, 0, data.Length);
|
|
85
|
|
- byte[] fix_data = new byte[5];
|
|
86
|
|
- fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
|
|
87
|
|
- fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
|
|
88
|
|
- fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
|
|
89
|
|
- fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
|
|
90
|
|
- fix_data[(int)Bluepro_t.bluecell_type] = Bluecell_Firmupdate_sending;
|
|
91
|
|
- fix_data[(int)Bluepro_t.bluecell_length_h] = 0;
|
|
92
|
|
- fix_data[(int)Bluepro_t.bluecell_length_l] = 3;
|
|
93
|
|
- fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = 0;
|
|
94
|
|
- fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = 0;
|
|
95
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((length & 0xFF00) >> 8);
|
|
96
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((length & 0x00FF));
|
|
97
|
|
- return data;
|
|
98
|
|
- }
|
|
99
|
|
- public byte[] Boot_DataEnd(byte[] data,int length)
|
|
|
98
|
+ public byte[] Boot_DataEnd(byte[] update_data, int length)
|
|
100
|
99
|
{
|
|
101
|
100
|
//Array.Clear(data, 0, data.Length);
|
|
102
|
101
|
byte[] fix_data = new byte[11];
|
|
103
|
|
- fix_data[(int)Bluepro_t.bluecell_header0] = Bluecell_Header0;
|
|
104
|
|
- fix_data[(int)Bluepro_t.bluecell_header1] = Bluecell_Header1;
|
|
105
|
|
- fix_data[(int)Bluepro_t.bluecell_header2] = Bluecell_Header2;
|
|
106
|
|
- fix_data[(int)Bluepro_t.bluecell_header3] = Bluecell_Header3;
|
|
107
|
|
- fix_data[(int)Bluepro_t.bluecell_type] = Bluecell_Firmupdate_end;
|
|
108
|
|
- fix_data[(int)Bluepro_t.bluecell_length_h] = 0;
|
|
109
|
|
- fix_data[(int)Bluepro_t.bluecell_length_l] = 3;
|
|
|
102
|
+ Array.Copy(update_data, (int)Bluepro_t.bluecell_data, fix_data, (int)Bluepro_t.bluecell_data, length);
|
|
|
103
|
+ BootHeaderput(ref fix_data);
|
|
|
104
|
+ fix_data[(int)Bluepro_t.bluecell_type] = (byte)Updateseq.Bluecell_Firmupdate_end;
|
|
|
105
|
+ fix_data[(int)Bluepro_t.bluecell_length_h] = Convert.ToByte((length & 0xFF00) >> 8);
|
|
|
106
|
+ fix_data[(int)Bluepro_t.bluecell_length_l] = Convert.ToByte((length & 0x00FF));
|
|
110
|
107
|
fix_data[(int)Bluepro_t.bluecell_updatecnt_h] = 0;
|
|
111
|
108
|
fix_data[(int)Bluepro_t.bluecell_updatecnt_l] = 0;
|
|
112
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 0] = Convert.ToByte((length & 0xFF00) >> 8);
|
|
113
|
|
- fix_data[(int)Bluepro_t.bluecell_data + 1] = Convert.ToByte((length & 0x00FF));
|
|
|
109
|
+
|
|
|
110
|
+ //Array.Copy(update_data, 0, fix_data, (int)Bluepro_t.bluecell_data, length-3);
|
|
|
111
|
+ fix_data[length + 9] = Convert.ToByte((crc16.CRC16_Generate(fix_data, length + 5) & 0xFF00) >> 8);
|
|
|
112
|
+ fix_data[length + 10] = Convert.ToByte(crc16.CRC16_Generate(fix_data, length + 5) & 0x00FF);
|
|
114
|
113
|
return fix_data;
|
|
115
|
114
|
}
|
|
116
|
115
|
}
|