using System;
using System.Collections.Generic;
using System.Text;
namespace Shared
{
///
/// ����Ŀ������
///
public class Target
{
///
/// ���͵�Ŀ��
///
public System.Net.IPEndPoint IPEndPoint;
public Target()
{ }
public Target(System.Net.IPEndPoint ipEndPoint)
{
this.IPEndPoint = ipEndPoint;
}
///
/// ��������
///
public byte[] AddData;
///
/// Ŀ��������
///
public byte SubnetID;
///
/// Ŀ���豸��
///
public byte DeviceID;
///
/// �������ݻ�����
///
public byte [] SendBytes {
get {
if (2 + 9 + AddData.Length + 2 <= 81&&Command!=Command.SuperGatewayAgent && Command != Command.enjoyUpgrade2
&& Command != Command.WriteHomeId) {
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] = Global.LocalSubnetID; //Դ������ַ 0-254
bytes [18] = Global.LocalDeviceID;//Դ�豸��ַ 0-254
//Դ�豸����2λ
bytes [19] = (byte)(Global.DeviceType / 256);
bytes [20] = (byte)(Global.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;
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] = Global.LocalSubnetID; //Դ������ַ 0-254
bytes [18] = Global.LocalDeviceID;//Դ�豸��ַ 0-254
//Դ�豸����2λ
bytes [19] = (byte)(Global.DeviceType / 256);
bytes [20] = (byte)(Global.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 [25] = (byte)(AddData.Length / 256);
//
bytes [26] = (byte)(AddData.Length % 256);
Array.Copy (AddData, 0, bytes, 27, AddData.Length);
return bytes;
}
}
}
///
/// ������
///
public Command Command;
}
}