package com.hdl.sdk.ttl.HDLAppliances.HDLDoorMachine.Parser;
|
|
|
import android.util.Log;
|
|
import com.hdl.sdk.ttl.Config.Configuration;
|
import com.hdl.sdk.ttl.HDLAppliances.Config.HDLApConfig;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo;
|
import com.hdl.sdk.ttl.HDLDeviceManger.Core.HDLDeviceManager;
|
import com.hdl.sdk.ttl.Utils.HDLUtlis.AesUtil;
|
import com.hdl.sdk.ttl.Utils.HDLUtlis.CommonHelper;
|
|
import org.json.JSONObject;
|
|
import java.util.ArrayList;
|
import java.util.Arrays;
|
import java.util.List;
|
|
/**
|
* Created by panlili on 2023/8/22
|
*/
|
public class DoorMachineParser {
|
// 附加数据: 回路号,备注,状态
|
public static final int fail = 0;
|
|
public static final int doorNum = 0;
|
|
public static final int doorStatus = 1;//门锁状态
|
public static final int doorStatusClose = 0;//关
|
public static final int doorStatusOpen = 1;//开
|
public static final int doorStatusNormallyOpen = 2;//常开
|
|
public static final int normalOpenMode = 2;//常开模式
|
public static final int normalOpenModeClose = 0;//关闭
|
public static final int normalOpenModeOpen = 1;//打开
|
|
public static final int doorVolume = 3;//音量
|
|
public static final int doorElectricity = 4;//电池百分比
|
|
public static byte[] getDoorMachineAddByte(AppliancesInfo appliancesInfo, byte[] secretBytes, String password, int doorStatus) {
|
try {
|
AppliancesInfo newInfo = null;
|
byte[] doorMachineBytes = null;
|
|
outter:
|
for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
|
if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID()
|
&& appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID()) {
|
for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
|
if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.DOOR_MACHINE_BIG_TYPE
|
&& HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_DOOR_MACHINE
|
&& appliancesInfo.getChannelNum() == HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getChannelNum()) {
|
newInfo = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j);
|
if (newInfo.getArrCurState() == null) {
|
newInfo.setArrCurState(new byte[9]);
|
}
|
doorMachineBytes = newInfo.getArrCurState();
|
break outter;
|
}
|
|
}
|
}
|
}
|
|
byte[] passwordBytes = new byte[6];
|
byte[] dataBytes = new byte[32];
|
|
if (doorMachineBytes != null && doorMachineBytes.length >= 9) {
|
//开锁密码6byte
|
if (password != null && password.length() == 6) {
|
for (int i = 0; i < password.length(); i++) {
|
String s = String.valueOf(password.charAt(i));
|
passwordBytes[i] = Byte.parseByte(s);
|
}
|
}
|
dataBytes = lockControlEncrypt(secretBytes, passwordBytes, doorStatus);
|
} else {
|
|
}
|
|
return dataBytes;
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new byte[]{fail};
|
}
|
|
}
|
|
public static byte[] getDoorMachineSettingPwdByte(AppliancesInfo appliancesInfo, String tempPassword, String startTime, String endTime) {
|
try {
|
byte[] addBytes = new byte[15];
|
addBytes[0] = (byte) appliancesInfo.getChannelNum();
|
|
//开锁密码6byte
|
if (tempPassword != null && tempPassword.length() == 6) {
|
for (int i = 0; i < tempPassword.length(); i++) {
|
String s = String.valueOf(tempPassword.charAt(i));
|
addBytes[i] = Byte.parseByte(s);
|
}
|
}
|
|
//开始时间戳4byte
|
long st = Long.parseLong(startTime);
|
addBytes[7] = (byte) (st / 255 / 255 / 255);
|
addBytes[8] = (byte) (st / 255 / 255);
|
addBytes[9] = (byte) (st / 255);
|
addBytes[10] = (byte) (st % 255);
|
|
//结束时间戳4byte
|
long et = Long.parseLong(endTime);
|
addBytes[11] = (byte) (et / 255 / 255 / 255);
|
addBytes[12] = (byte) (et / 255 / 255);
|
addBytes[13] = (byte) (et / 255);
|
addBytes[14] = (byte) (et % 255);
|
|
return addBytes;
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new byte[]{fail};
|
}
|
|
}
|
|
public static byte[] lockControlEncrypt(byte[] usefulBytes, byte[] passwordBytes, int doorStatus) {
|
byte[] sendBytes = new byte[32];
|
int loopID = usefulBytes[0] & 0xFF;
|
|
byte[] randomBytes = Arrays.copyOfRange(usefulBytes, 1, 9);
|
|
byte[] passwordArray = new byte[6];
|
passwordArray[0] = Byte.parseByte("1");
|
passwordArray[1] = Byte.parseByte("2");
|
passwordArray[2] = Byte.parseByte("3");
|
passwordArray[3] = Byte.parseByte("1");
|
passwordArray[4] = Byte.parseByte("2");
|
passwordArray[5] = Byte.parseByte("3");
|
|
try {
|
//备注20位
|
byte[] deviceBytes = "HDL ON".getBytes("GB2312");
|
|
/*if (loopID > 0) {
|
loopID -= 1;
|
}*/
|
byte[] inpuptBytes = new byte[]{(byte) 0xE4, (byte) 0xF0, (byte) loopID, (byte) doorStatus};
|
byte[] allAddBytes = new byte[4 + 6 + 2 + 20];
|
System.arraycopy(inpuptBytes, 0, allAddBytes, 0, 4);
|
System.arraycopy(passwordBytes, 0, allAddBytes, 4, 6);
|
System.arraycopy(deviceBytes, 0, allAddBytes, 4 + 6 + 2, deviceBytes.length);
|
|
sendBytes = CommonHelper.Encryption(randomBytes, allAddBytes);
|
return sendBytes;
|
|
} catch (Exception exception) {
|
exception.printStackTrace();
|
}
|
return sendBytes;
|
}
|
|
}
|