package com.hdl.sdk.ttl_sdk.bean;
|
|
import com.hdl.sdk.ttl.HDLDeviceManger.Core.Crc;
|
|
/**
|
* Created by JLChen on 2019/9/27
|
*/
|
public class ZigBeeCommand {
|
|
public static final int COMMAND_HEARTBEAT_SEND = 0x2000;
|
public static final int COMMAND_BACK_OPEN_RECEIVING_MODE = 0x2002;//代表有缓存数据
|
public static final int COMMAND_BACK_CLOSE_RECEIVING_MODE = 0x2001;//代表没缓存数据
|
public static final int COMMAND_SEND_DATA = 0x1002;//发送数据 (魔镜->STM32)
|
public static final int COMMAND_SEND_DATA_BACK = 0x2003;//发送数据回复 1byte0XF8成功 0XF5失败
|
|
public static final int COMMAND_RECEIVE_DATA = 0x1001;//(STM32->魔镜)
|
public static final int COMMAND_RECEIVE_DATA_BACK = 0x2003;//发送数据 1byte0XF8成功 0XF5失败
|
|
|
private static int DeviceType = 0x6666;
|
// private int Command1002 = 0x1002;
|
// private int CommandHeartbeat = 0x2000;
|
// private int DeviceID = 0x01;
|
// private static int sendCount = 0;//发送序列号
|
|
/**
|
* @return
|
*/
|
public static byte[] GetHeartbeatBytes(int sendCount) {
|
byte[] crcBytes = new byte[13];
|
byte[] sendBytes = new byte[2 + crcBytes.length];
|
//Boot code
|
sendBytes[0] = (byte) 0xAA;
|
sendBytes[1] = (byte) 0xAA;
|
crcBytes[0] = (byte) (crcBytes.length / 256);
|
crcBytes[1] = (byte) (crcBytes.length % 256);
|
crcBytes[2] = (byte) 0x01;
|
crcBytes[3] = (byte) 0x01;
|
crcBytes[4] = (byte) (DeviceType / 256);
|
crcBytes[5] = (byte) (DeviceType % 256);
|
crcBytes[6] = (byte) (COMMAND_HEARTBEAT_SEND / 256);
|
crcBytes[7] = (byte) (COMMAND_HEARTBEAT_SEND % 256);
|
crcBytes[8] = (byte) 0x02;
|
crcBytes[9] = (byte) 0x02;
|
crcBytes[10] = (byte) sendCount;
|
|
Crc.ConCRC(crcBytes, crcBytes.length - 2);
|
System.arraycopy(crcBytes, 0, sendBytes, 2, crcBytes.length);
|
return sendBytes;
|
}
|
|
/**
|
* @return
|
*/
|
public static byte[] GetSendBytes(byte[] addBytes, int mCommand, int sendCount) {
|
|
byte[] crcBytes = new byte[15 + addBytes.length];
|
byte[] sendBytes = new byte[2 + crcBytes.length];
|
//Boot code
|
sendBytes[0] = (byte) 0xAA;
|
sendBytes[1] = (byte) 0xAA;
|
crcBytes[0] = (byte) (crcBytes.length / 256);
|
crcBytes[1] = (byte) (crcBytes.length % 256);
|
crcBytes[2] = (byte) 0x01;
|
crcBytes[3] = (byte) 0x01;
|
crcBytes[4] = (byte) (DeviceType / 256);
|
crcBytes[5] = (byte) (DeviceType % 256);
|
crcBytes[6] = (byte) (mCommand / 256);
|
crcBytes[7] = (byte) (mCommand % 256);
|
crcBytes[8] = (byte) 0x02;
|
crcBytes[9] = (byte) 0x02;
|
crcBytes[10] = (byte) sendCount;
|
crcBytes[11] = (byte) (addBytes.length / 256);
|
crcBytes[12] = (byte) (addBytes.length % 256);
|
System.arraycopy(addBytes, 0, crcBytes, 13, addBytes.length);
|
Crc.ConCRC(crcBytes, crcBytes.length - 2);
|
System.arraycopy(crcBytes, 0, sendBytes, 2, crcBytes.length);
|
return sendBytes;
|
}
|
|
|
/**
|
* @return
|
* COMMAND_RECEIVE_DATA_BACK
|
*/
|
public static byte[] GetReplyBytes(int sendCount, boolean bSuccess) {
|
byte[] crcBytes = new byte[14];
|
byte[] sendBytes = new byte[2 + crcBytes.length];
|
//Boot code
|
sendBytes[0] = (byte) 0xAA;
|
sendBytes[1] = (byte) 0xAA;
|
crcBytes[0] = (byte) (crcBytes.length / 256);
|
crcBytes[1] = (byte) (crcBytes.length % 256);
|
crcBytes[2] = (byte) 0x01;
|
crcBytes[3] = (byte) 0x01;
|
crcBytes[4] = (byte) (DeviceType / 256);
|
crcBytes[5] = (byte) (DeviceType % 256);
|
crcBytes[6] = (byte) (COMMAND_RECEIVE_DATA_BACK / 256);
|
crcBytes[7] = (byte) (COMMAND_RECEIVE_DATA_BACK % 256);
|
crcBytes[8] = (byte) 0x02;
|
crcBytes[9] = (byte) 0x02;
|
crcBytes[10] = (byte) sendCount;
|
crcBytes[11] = bSuccess ? (byte) 0xF8 : (byte) 0xF5;
|
Crc.ConCRC(crcBytes, crcBytes.length - 2);
|
System.arraycopy(crcBytes, 0, sendBytes, 2, crcBytes.length);
|
return sendBytes;
|
}
|
|
}
|