package com.hdl.sdk.ttl.HDLAppliances.HDLAirCondition.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;
|
|
/**
|
* Created by Tommy on 2017/7/20.
|
*/
|
|
public class AirCtrlParser {
|
public static final int fail = 0;
|
public static final int infrared = 1;
|
public static final int panelLock = 2;
|
|
public static final int airSwich = 3;
|
public static final int airOn = 1;//空调开
|
public static final int airOff = 0;//空调关
|
|
public static final int refTem = 4;//制冷温度
|
|
public static final int airSpeed = 5;//风速
|
public static final int airSpeedAuto = 0;//风速自动
|
public static final int airSpeedHigh = 1;//风速高风
|
public static final int airSpeedMid = 2;//风速中风
|
public static final int airSpeedLow = 3;//风速低风
|
|
public static final int airMode = 6;//空调模式
|
public static final int airModeRefTem = 0;//空调模式制冷
|
public static final int airModeHeatTem = 1;//空调模式制热
|
public static final int airModeVen = 2;//空调模式通风
|
public static final int airModeAuto = 3;//空调模式自动
|
public static final int airModeDehum = 4;//空调模式抽湿
|
|
public static final int heatTem = 7;//制热温度
|
public static final int autoTem = 8;//自动温度
|
public static final int upTem = 9;//上升温度
|
public static final int downTem = 10;//下降温度
|
|
public static final int dehumTem = 19;//抽湿温度
|
|
|
public static byte[] getAirPanelAddByte(int type, int arg2) {
|
byte[] addBytes;
|
switch (type) {
|
case airSwich:
|
if (arg2 == airOff) {
|
addBytes = new byte[]{airSwich, (byte) arg2};
|
} else if (arg2 == airOn) {
|
addBytes = new byte[]{airSwich, (byte) arg2};
|
} else {
|
addBytes = new byte[]{fail};
|
}
|
break;
|
case refTem:
|
addBytes = new byte[]{refTem, (byte) arg2};
|
break;
|
case airSpeed:
|
switch (arg2) {
|
case airSpeedAuto:
|
addBytes = new byte[]{airSpeed, airSpeedAuto};
|
break;
|
case airSpeedHigh:
|
addBytes = new byte[]{airSpeed, airSpeedHigh};
|
break;
|
case airSpeedMid:
|
addBytes = new byte[]{airSpeed, airSpeedMid};
|
break;
|
case airSpeedLow:
|
addBytes = new byte[]{airSpeed, airSpeedLow};
|
break;
|
default:
|
addBytes = new byte[]{fail};
|
break;
|
}
|
break;
|
case airMode:
|
switch (arg2) {
|
case airModeRefTem:
|
addBytes = new byte[]{airMode, airModeRefTem};
|
break;
|
case airModeHeatTem:
|
addBytes = new byte[]{airMode, airModeHeatTem};
|
break;
|
case airModeVen:
|
addBytes = new byte[]{airMode, airModeVen};
|
break;
|
case airModeAuto:
|
addBytes = new byte[]{airMode, airModeAuto};
|
break;
|
case airModeDehum:
|
addBytes = new byte[]{airMode, airModeDehum};
|
break;
|
default:
|
addBytes = new byte[]{fail};
|
break;
|
}
|
break;
|
case heatTem:
|
addBytes = new byte[]{heatTem, (byte) arg2};
|
break;
|
case autoTem:
|
addBytes = new byte[]{autoTem, (byte) arg2};
|
break;
|
case dehumTem:
|
addBytes = new byte[]{dehumTem, (byte) arg2};
|
break;
|
case upTem:
|
addBytes = new byte[]{upTem, (byte) arg2};
|
break;
|
case downTem:
|
addBytes = new byte[]{downTem, (byte) arg2};
|
break;
|
default:
|
addBytes = new byte[]{fail};
|
break;
|
}
|
return addBytes;
|
}
|
|
public static byte[] getAcAddByte(AppliancesInfo appliancesInfo, int type, int state) {
|
|
try {
|
AppliancesInfo newInfo = null;
|
byte[] airBytes = null;
|
outter:
|
for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
|
if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getDeviceSubnetID()
|
&& appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getDeviceDeviceID()) {
|
for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
|
if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.AIR_BIG_TYPE
|
&& HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() != HDLApConfig.TYPE_AC_PANEL
|
&& 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[19]);
|
}
|
airBytes = newInfo.getArrCurState();
|
break outter;
|
}
|
|
}
|
}
|
}
|
byte[] addBytes = new byte[19];
|
if (airBytes != null && airBytes.length >= 19) {
|
System.arraycopy(airBytes, 0, addBytes, 0, airBytes.length);
|
addBytes[0] = (byte) newInfo.getChannelNum();
|
|
switch (type) {
|
case airSwich://设置开关状态
|
if (state == airOff) {
|
addBytes[8] = 0;
|
} else {
|
addBytes[8] = 1;
|
}
|
break;
|
case refTem:
|
case heatTem:
|
case autoTem:
|
case dehumTem://设置温度
|
addBytes[8] = 1;
|
addBytes[3] = (byte) state;
|
addBytes[4] = (byte) state;
|
addBytes[5] = (byte) state;
|
addBytes[6] = (byte) state;
|
addBytes[11] = (byte) state;
|
break;
|
case upTem://升温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[4] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[5] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[6] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[11] = (byte) ((airBytes[2] & 0xff) + state);
|
break;
|
case downTem://降温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[4] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[5] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[6] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[11] = (byte) ((airBytes[2] & 0xff) - state);
|
break;
|
case airMode://设置空调模式
|
addBytes[8] = 1;
|
addBytes[7] = (byte) (state * 16 + (airBytes[3] & 0xff));
|
addBytes[9] = (byte) state;
|
break;
|
case airSpeed://设置风速
|
addBytes[8] = 1;
|
addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + state);
|
addBytes[10] = (byte) state;
|
break;
|
}
|
} else {
|
addBytes[0] = (byte) newInfo.getChannelNum();
|
addBytes[1] = 0;
|
addBytes[2] = (byte) 28;
|
addBytes[3] = (byte) 28;
|
addBytes[4] = (byte) 28;
|
addBytes[5] = (byte) 28;
|
addBytes[6] = (byte) 28;
|
addBytes[7] = 0;
|
addBytes[8] = 1;
|
addBytes[9] = 0;
|
addBytes[10] = 0;
|
addBytes[11] = (byte) 28;
|
addBytes[12] = 0;
|
switch (type) {
|
case airSwich://设置开关状态
|
if (state == airOff) {
|
addBytes[8] = 0;
|
} else {
|
addBytes[8] = 1;
|
}
|
break;
|
case refTem:
|
case heatTem:
|
case autoTem:
|
case dehumTem://设置温度
|
addBytes[8] = 1;
|
addBytes[3] = (byte) state;
|
addBytes[4] = (byte) state;
|
addBytes[5] = (byte) state;
|
addBytes[6] = (byte) state;
|
addBytes[11] = (byte) state;
|
break;
|
case upTem://升温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) (28 + state);
|
addBytes[4] = (byte) (28 + state);
|
addBytes[5] = (byte) (28 + state);
|
addBytes[6] = (byte) (28 + state);
|
addBytes[11] = (byte) (28 + state);
|
break;
|
case downTem://降温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) (28 - state);
|
addBytes[4] = (byte) (28 - state);
|
addBytes[5] = (byte) (28 - state);
|
addBytes[6] = (byte) (28 - state);
|
addBytes[11] = (byte) (28 - state);
|
break;
|
case airMode://设置空调模式
|
addBytes[8] = 1;
|
addBytes[7] = (byte) (state * 16);
|
addBytes[9] = (byte) state;
|
break;
|
case airSpeed://设置风速
|
addBytes[8] = 1;
|
addBytes[7] = (byte) (state);
|
addBytes[10] = (byte) state;
|
break;
|
}
|
}
|
|
|
return addBytes;
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new byte[]{fail};
|
}
|
|
}
|
|
public static byte[] getAirTechAddByte(AppliancesInfo appliancesInfo, int type, int state) {
|
|
try {
|
AppliancesInfo newInfo = null;
|
byte[] airBytes = null;
|
outter:
|
for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
|
if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getDeviceSubnetID()
|
&& appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getDeviceDeviceID()) {
|
for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
|
if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.AIR_BIG_TYPE
|
&& (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_AC_TECHSYS
|
|| HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_AC_KNXTECHSYS)
|
&& 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[19]);
|
}
|
airBytes = newInfo.getArrCurState();
|
break outter;
|
}
|
|
}
|
}
|
}
|
byte[] addBytes = new byte[19];
|
if (airBytes != null && airBytes.length >= 19) {
|
System.arraycopy(airBytes, 0, addBytes, 0, airBytes.length);
|
addBytes[0] = (byte) newInfo.getChannelNum();
|
|
switch (type) {
|
case airSwich://设置开关状态
|
if (state == airOff) {
|
addBytes[8] = 0;
|
} else {
|
addBytes[8] = 1;
|
}
|
break;
|
case refTem:
|
case heatTem:
|
case autoTem:
|
case dehumTem://设置温度
|
addBytes[8] = 1;
|
addBytes[3] = (byte) state;
|
addBytes[4] = (byte) state;
|
addBytes[5] = (byte) state;
|
addBytes[6] = (byte) state;
|
addBytes[11] = (byte) state;
|
break;
|
case upTem://升温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[4] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[5] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[6] = (byte) ((airBytes[2] & 0xff) + state);
|
addBytes[11] = (byte) ((airBytes[2] & 0xff) + state);
|
break;
|
case downTem://降温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[4] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[5] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[6] = (byte) ((airBytes[2] & 0xff) - state);
|
addBytes[11] = (byte) ((airBytes[2] & 0xff) - state);
|
break;
|
case airMode://设置空调模式
|
addBytes[8] = 1;
|
addBytes[7] = (byte) (state * 16 + (airBytes[3] & 0xff));
|
addBytes[9] = (byte) state;
|
break;
|
case airSpeed://设置风速
|
addBytes[8] = 1;
|
addBytes[7] = (byte) ((airBytes[1] & 0xff) * 16 + state);
|
addBytes[10] = (byte) state;
|
break;
|
}
|
} else {
|
addBytes[0] = (byte) newInfo.getChannelNum();
|
addBytes[1] = 0;
|
addBytes[2] = (byte) 28;
|
addBytes[3] = (byte) 28;
|
addBytes[4] = (byte) 28;
|
addBytes[5] = (byte) 28;
|
addBytes[6] = (byte) 28;
|
addBytes[7] = 0;
|
addBytes[8] = 1;
|
addBytes[9] = 0;
|
addBytes[10] = 0;
|
addBytes[11] = (byte) 28;
|
addBytes[12] = 0;
|
switch (type) {
|
case airSwich://设置开关状态
|
if (state == airOff) {
|
addBytes[8] = 0;
|
} else {
|
addBytes[8] = 1;
|
}
|
break;
|
case refTem:
|
case heatTem:
|
case autoTem:
|
case dehumTem://设置温度
|
addBytes[8] = 1;
|
addBytes[3] = (byte) state;
|
addBytes[4] = (byte) state;
|
addBytes[5] = (byte) state;
|
addBytes[6] = (byte) state;
|
addBytes[11] = (byte) state;
|
break;
|
case upTem://升温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) (28 + state);
|
addBytes[4] = (byte) (28 + state);
|
addBytes[5] = (byte) (28 + state);
|
addBytes[6] = (byte) (28 + state);
|
addBytes[11] = (byte) (28 + state);
|
break;
|
case downTem://降温
|
addBytes[8] = 1;
|
addBytes[3] = (byte) (28 - state);
|
addBytes[4] = (byte) (28 - state);
|
addBytes[5] = (byte) (28 - state);
|
addBytes[6] = (byte) (28 - state);
|
addBytes[11] = (byte) (28 - state);
|
break;
|
case airMode://设置空调模式
|
addBytes[8] = 1;
|
addBytes[7] = (byte) (state * 16);
|
addBytes[9] = (byte) state;
|
break;
|
case airSpeed://设置风速
|
addBytes[8] = 1;
|
addBytes[7] = (byte) (state);
|
addBytes[10] = (byte) state;
|
break;
|
}
|
}
|
|
return addBytes;
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new byte[]{fail};
|
}
|
|
}
|
|
public static byte[] getAirKNXTechAddByte(AppliancesInfo appliancesInfo, int type, float temp) {
|
|
try {
|
AppliancesInfo newInfo = null;
|
byte[] airBytes = null;
|
outter:
|
for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
|
if (appliancesInfo.getDeviceSubnetID() == HDLDeviceManager.devicesDataList.get(i).getDeviceSubnetID()
|
&& appliancesInfo.getDeviceDeviceID() == HDLDeviceManager.devicesDataList.get(i).getDeviceDeviceID()) {
|
for (int j = 0; j < HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().size(); j++) {
|
if (HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getBigType() == Configuration.AIR_BIG_TYPE
|
&& HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList().get(j).getDeviceType() == HDLApConfig.TYPE_AC_KNXTECHSYS
|
&& 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[19]);
|
}
|
airBytes = newInfo.getArrCurState();
|
break outter;
|
}
|
}
|
}
|
}
|
byte[] addBytes = new byte[19];
|
if (airBytes != null && airBytes.length >= 19) {
|
System.arraycopy(airBytes, 0, addBytes, 0, airBytes.length);
|
addBytes[0] = (byte) newInfo.getChannelNum();
|
|
Log.d("panlili", "---temp=" + temp);
|
String tempStr = String.valueOf(temp).trim();
|
String[] strByte = tempStr.split("\\.");
|
int tempInt = Integer.parseInt(strByte[0]);
|
int tempFloat = Integer.parseInt(strByte[1]);
|
|
switch (type) {
|
case refTem:
|
case heatTem:
|
case autoTem:
|
case dehumTem://设置温度
|
addBytes[8] = 1;
|
|
addBytes[3] = (byte) tempInt;
|
addBytes[4] = (byte) tempInt;
|
addBytes[5] = (byte) tempInt;
|
addBytes[6] = (byte) tempInt;
|
addBytes[11] = (byte) tempInt;
|
|
addBytes[14] = (byte) tempFloat;
|
addBytes[15] = (byte) tempFloat;
|
addBytes[16] = (byte) tempFloat;
|
addBytes[17] = (byte) tempFloat;
|
addBytes[18] = (byte) tempFloat;
|
|
break;
|
}
|
}
|
|
return addBytes;
|
} catch (Exception e) {
|
e.printStackTrace();
|
return new byte[]{fail};
|
}
|
|
}
|
}
|