wxr
2020-11-04 e6a26ee148587327478d9a82624a820c907b6e16
HDL_ON/DriverLayer/Target.cs
@@ -6,16 +6,16 @@
namespace HDL_ON
{
    /// <summary>
    /// 控制目标数据
    /// 控制数据
    /// </summary>
    public class Target
    {
        /// <summary>
        /// 发送的目标
        /// 目标端口
        /// </summary>
        public System.Net.IPEndPoint IPEndPoint;
        /// <summary>
        /// 设备类型
        /// 本机设备类型
        /// </summary>
        int deviceType = 58037;
@@ -28,32 +28,24 @@
        }
        /// <summary>
        /// 附加数据
        /// 附加数据
        /// </summary>
        public byte[] AddData;
        /// <summary>
        /// 目标子网号
        /// 目标子网号
        /// </summary>
        public byte SubnetID;
        /// <summary>
        /// 目标设备号
        /// 目标设备号
        /// </summary>
        public byte DeviceID;
        public byte[] GetGatewayIp_SendBytes;
        /// <summary>
        /// 发送数据缓冲区
        /// </summary>
        public byte [] SendBytes {
            get {
                if(GetGatewayIp_SendBytes!=null)
                {
                    byte[] bytes = GetGatewayIp_SendBytes;
                    return bytes;
                }
                if (2 + 9 + AddData.Length + 2 <= 81&&Command!=Command.SuperGatewayAgent) {
                    byte [] bytes = new byte [16 + 9 + AddData.Length + 2];
@@ -74,27 +66,22 @@
                    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 [16] = (byte)(11 + AddData.Length);
                    bytes [17] = 252; //源子网号
                    bytes [18] = 252; //源设备号
                    bytes [19] = (byte)(deviceType/256);
                    bytes [20] = (byte)(deviceType%256);
                    //操作码
                    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 [23] = this.SubnetID;//目标子网号
                    bytes [24] = this.DeviceID;//目标设备号
                    Array.Copy (AddData, 0, bytes, 25, AddData.Length);
                    //CRC校验位
                    //CRC校验位
                    bytes [bytes.Length - 2] = 0;
                    bytes [bytes.Length - 1] = 0;
@@ -122,22 +109,17 @@
                    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 [16] = 0xFF;//数据包长度
                    bytes [17] = 252;//源子网号
                    bytes [18] = 252;//源设备号
                    bytes [19] = (byte)(deviceType/256);
                    bytes [20] = (byte)(deviceType%256);
                    //操作码
                    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;
                    //
@@ -151,25 +133,9 @@
                }
            }
        }
        /// <summary>
        /// 操作码
        /// 操作码
        /// </summary>
        public Command Command;
        /// <summary>
        /// 发送数据缓冲区
        /// </summary>
        public byte[] SendBytesGetGatewayIP
        {
            get
            {
                return AddData;
            }
        }
    }
}