wxr
2020-01-18 4cc04639fbadde3a7f3b9875353df0d90fc09043
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.Entity;
 
namespace HDL_ON
{
    /// <summary>
    /// ¿ØÖÆÄ¿±êÊý¾Ý
    /// </summary>
    public class Target
    {
        /// <summary>
        /// ·¢Ë͵ÄÄ¿±ê
        /// </summary>
        public System.Net.IPEndPoint IPEndPoint;
 
        public Target()
        { }
 
        public Target(System.Net.IPEndPoint ipEndPoint)
        {
            this.IPEndPoint = ipEndPoint;
        }
 
        /// <summary>
        /// ¸½¼ÓÊý¾Ý
        /// </summary>
        public byte[] AddData;
 
        /// <summary>
        /// Ä¿±ê×ÓÍøºÅ
        /// </summary>
        public byte SubnetID;
 
        /// <summary>
        /// Ä¿±êÉ豸ºÅ
        /// </summary>
        public byte DeviceID;
 
        /// <summary>
        /// ·¢ËÍÊý¾Ý»º³åÇø
        /// </summary>
        public byte [] SendBytes {
            get {
 
                if (2 + 9 + AddData.Length + 2 <= 81&&Command!=Command.SuperGatewayAgent) {
                    byte [] bytes = new byte [16 + 9 + AddData.Length + 2];
 
                    string [] ipAddress = "192.168.1.20".Split ('.');//new Net.NetWiFi().IpAddress.ToString().Split('.');
 
                    bytes [0] = byte.Parse (ipAddress [0]);
                    bytes [1] = byte.Parse (ipAddress [1]);
                    bytes [2] = byte.Parse (ipAddress [2]);
                    bytes [3] = byte.Parse (ipAddress [3]);
 
                    bytes [4] = (byte)'H';//H
                    bytes [5] = (byte)'D';//D
                    bytes [6] = (byte)'L';//L
                    bytes [7] = (byte)'M';//M
                    bytes [8] = (byte)'I';//I
                    bytes [9] = (byte)'R';//R
                    bytes [10] = (byte)'A';//A
                    bytes [11] = (byte)'C';//C
                    bytes [12] = (byte)'L';//L
                    bytes [13] = (byte)'E';//E
                                           //Òýµ¼Âë2λ,0xAAAA¹Ì¶¨
                    bytes [14] = 0xAA;
                    bytes [15] = 0xAA;
 
                    bytes [16] = (byte)(11 + AddData.Length);//Êý¾Ý°ü³¤¶È
                    bytes [17] = 252; //Ô´×ÓÍøµØÖ· 0-254
                    bytes [18] = 252;//Ô´É豸µØÖ· 0-254
                                                      //Ô´É豸ÀàÐÍ2λ
                    bytes [19] = (byte)(0xFF);
                    bytes [20] = (byte)(0xFC);
                    //²Ù×÷Âë
                    bytes [21] = (byte)((int)this.Command / 256);
                    bytes [22] = (byte)((int)this.Command % 256);
                    //Ä¿±ê×ÓÍøµØÖ· 0-254
                    bytes [23] = this.SubnetID;
                    //Ä¿±êÉ豸µØÖ· 0-254
                    bytes [24] = this.DeviceID;
 
                    Array.Copy (AddData, 0, bytes, 25, AddData.Length);
 
                    //CRCУÑéλ
                    bytes [bytes.Length - 2] = 0;
                    bytes [bytes.Length - 1] = 0;
 
 
                    CRC.ConCRC (ref bytes, 16, bytes.Length - 2);
 
                    return bytes;
                } else {
                    byte [] bytes = new byte [16 + 9 + 2 + AddData.Length];
 
                    string [] ipAddress = "192.168.1.20".Split ('.');//new Net.NetWiFi().IpAddress.ToString().Split('.');
 
                    bytes [0] = byte.Parse (ipAddress [0]);
                    bytes [1] = byte.Parse (ipAddress [1]);
                    bytes [2] = byte.Parse (ipAddress [2]);
                    bytes [3] = byte.Parse (ipAddress [3]);
 
                    bytes [4] = (byte)'H';//H
                    bytes [5] = (byte)'D';//D
                    bytes [6] = (byte)'L';//L
                    bytes [7] = (byte)'M';//M
                    bytes [8] = (byte)'I';//I
                    bytes [9] = (byte)'R';//R
                    bytes [10] = (byte)'A';//A
                    bytes [11] = (byte)'C';//C
                    bytes [12] = (byte)'L';//L
                    bytes [13] = (byte)'E';//E
                                           //Òýµ¼Âë2λ,0xAAAA¹Ì¶¨
                    bytes [14] = 0xAA;
                    bytes [15] = 0xAA;
 
                    bytes [16] = 0xFF;//Êý¾Ý°ü³¤¶È
                    bytes [17] = 252; //Ô´×ÓÍøµØÖ· 0-254
                    bytes [18] = 252;//Ô´É豸µØÖ· 0-254
                                                      //Ô´É豸ÀàÐÍ2λ
                    bytes [19] = (byte)(0xFF);
                    bytes [20] = (byte)(0xFC);
                    //²Ù×÷Âë
                    bytes [21] = (byte)((int)this.Command / 256);
                    bytes [22] = (byte)((int)this.Command % 256);
                    //Ä¿±ê×ÓÍøµØÖ· 0-254
                    bytes [23] = this.SubnetID;
                    //Ä¿±êÉ豸µØÖ· 0-254
                    bytes [24] = this.DeviceID;
 
                    //
                    bytes [25] = (byte)(AddData.Length / 256);
                    //             
                    bytes [26] = (byte)(AddData.Length % 256);
 
                    Array.Copy (AddData, 0, bytes, 27, AddData.Length);
 
                    return bytes;
                }
            }
        }
 
        /// <summary>
        /// ²Ù×÷Âë
        /// </summary>
        public Command Command;
 
    }
}