package com.hdl.sdk.ttl.HDLDeviceManger.Bean; import java.util.ArrayList; import java.util.Calendar; import com.hdl.sdk.ttl.Config.Global; import com.hdl.sdk.ttl.HDLDeviceManger.Core.Crc; import java.net.InetAddress; public class SendDatas { // finish public static final int FINISH = 10; public static final int SEND_ONLY_ONCE = 0; public static final int SEND_MAX = 3; /** * 重发列表 */ private static ArrayList RetransmissionDateList = new ArrayList(); /** * 只发送一次,发送完就移除 */ public static ArrayList sendDataArrayList = new ArrayList(100); // 已经发送出去的次数 public int SendCount = 0; public Calendar StartCalendar =null; // 子网号 public int DesSubnetID; // 设备号 public int DesDeviceID; // 发送出去的附加数据 public byte[] AddBytes = new byte[]{}; // 获取发送出去的数据,每调用这个方法的时候,数据都会重新排列一下,得到真实的数据 public InetAddress InetAddress; public int Port; public InetAddress TargetAddress; /** * 设备协议类型 */ public int protocolType; public byte[] GetSendBytes() { // 要计算CRC的数据和CRC两个字节 byte[] crcBytes = new byte[9 + this.AddBytes.length + 2]; // 发送出去的数据 byte[] sendBytes = new byte[16 + crcBytes.length]; /*String[] ip = Net.CurrentNet.getPsdnIp().split("\\."); // IP地址 sendBytes[0] = (byte) GetStringToInteger(ip[0]); sendBytes[1] = (byte) GetStringToInteger(ip[1]); sendBytes[2] = (byte) GetStringToInteger(ip[2]); sendBytes[3] = (byte) GetStringToInteger(ip[3]);*/ // HDL--HOTEL if (this.Port == 6006) { sendBytes[4] = (byte) 0x48; sendBytes[5] = (byte) 0x44; sendBytes[6] = (byte) 0x4c; sendBytes[7] = (byte) 0x4d; sendBytes[8] = (byte) 0x49; sendBytes[9] = (byte) 0x52; sendBytes[10] = (byte) 0x41; sendBytes[11] = (byte) 0x43; sendBytes[12] = (byte) 0x4c; sendBytes[13] = (byte) 0x45; } else { // HDLMIRACLE sendBytes[4] = (byte) 0x48; sendBytes[5] = (byte) 0x44; sendBytes[6] = (byte) 0x4c; sendBytes[7] = (byte) 0x4d; sendBytes[8] = (byte) 0x49; sendBytes[9] = (byte) 0x52; sendBytes[10] = (byte) 0x41; sendBytes[11] = (byte) 0x43; sendBytes[12] = (byte) 0x4c; sendBytes[13] = (byte) 0x45; } // 引导码 sendBytes[14] = (byte) 0xAA; sendBytes[15] = (byte) 0xAA; // 16 数据包长度 11-78 crcBytes[0] = (byte) crcBytes.length; // 17 源子网地址 0-254 crcBytes[1] = (byte) Global.subnetID; // 18 源设备地址 0-254 crcBytes[2] = (byte) Global.deviceID; // 19 源设备类型高位 crcBytes[3] = (byte) (Global.DeviceType / 256); // 20 源设备类型低位 crcBytes[4] = (byte) (Global.DeviceType % 256); // 21 操作码高位 crcBytes[5] = (byte) (this.Command / 256); // 22 操作码低位 crcBytes[6] = (byte) (this.Command % 256); // 23 目标子网地址 0-254 crcBytes[7] = (byte) this.DesSubnetID; // 24 目标设备地址 0-254 crcBytes[8] = (byte) this.DesDeviceID; // 25~n附加数据 System.arraycopy(this.AddBytes, 0, crcBytes, 9, this.AddBytes.length); // CRC校验 Crc.ConCRC(crcBytes, crcBytes.length - 2); // 复制CRC数据到发送数据里面 System.arraycopy(crcBytes, 0, sendBytes, 16, crcBytes.length); /* * int sss[] = new int[sendBytes.length]; for(int i * =0;i GetSendDataList() { return RetransmissionDateList; } /** * 字符串转换为整数 * * @param s * @return */ public static int GetStringToInteger(String s) { try { return Integer.parseInt(s); } catch (Exception e) { return 0; } } }