package com.hdl.sdk.hdl_core.HDLDeviceManger.Core;
|
|
import android.content.Context;
|
import android.util.Log;
|
|
import com.hdl.sdk.hdl_core.Config.Configuration;
|
import com.hdl.sdk.hdl_core.HDLAppliances.Config.HDLApConfig;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.AirCtrlBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLAirCondition.Parser.AirCtrlParser;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLAudio.HDLAudio;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLCurtain.CurtainCtrlBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLCurtain.Parser.CurtainCtrlParser;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLFreshAir.FreshAirBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLFreshAir.Parser.FreshAirParser;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.GeothermalBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLGeothermal.Parser.GeothermalParser;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLight.LightCtrlBackInfo;
|
import com.hdl.sdk.hdl_core.HDLAppliances.HDLLogic.LogicCtrlBackInfo;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.AppliancesInfo;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.DeviceStateBean;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.AirFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.CurtainFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.DeviceStateEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.EventCode;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.FreshAirFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.GeothermalFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LightFeedBackEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent;
|
import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog;
|
import com.hdl.sdk.hdl_core.Util.SPUtil.SPUtils;
|
import com.hdl.sdk.hdl_core.Util.TransformUtil.HDLUtlis;
|
|
import org.greenrobot.eventbus.EventBus;
|
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Timer;
|
import java.util.TimerTask;
|
|
|
/**
|
* Created by djl on 2017/3/17.
|
*/
|
|
public class HDLCommand {
|
|
private static Timer getStateFailTimer = null;//获取设备状态失败Timer
|
|
private static Timer lightCtrlFailTimer = null;//控制灯光失败Timer
|
private static Timer curtainCtrlFailTimer = null;//控制窗帘失败Timer
|
private static Timer acCtrlFailTimer = null;//控制空调失败Timer
|
private static Timer sceneCtrlFailTimer = null;//控制场景失败Timer
|
private static Timer freshAirCtrlFailTimer = null;//控制新风失败Timer 2019-07-09
|
private static Timer geothermalCtrlFailTimer = null;//控制地热失败Timer 2019-07-10
|
|
|
/**
|
* 初始化
|
*
|
* @param context
|
*/
|
public static void init(Context context) {
|
HDLDeviceManager.init(context);
|
}
|
|
|
/**
|
* 是否开启SDK日志打印
|
* 2019-07-10新增
|
* @param bOpen
|
*/
|
public static void setHDLLogOpen(boolean bOpen) {
|
HDLLog.setHDLLogOpen(bOpen);
|
}
|
|
/**
|
* 释放资源
|
*/
|
public static void release() {
|
HDLDeviceManager.release();
|
}
|
|
|
// private static void devicesSearch() {
|
// HandleSearch.getRcuIp();
|
// }
|
|
|
|
/**
|
* 获取RCU模块的设备
|
*
|
* @param context
|
* @param rcuIp
|
*/
|
public static void getRcuDevices(Context context, String rcuIp) {
|
if (rcuIp == null) {
|
return;
|
}
|
HandleSearch.getRcuDevices(context, rcuIp);
|
}
|
|
/**
|
* 获取家居设备
|
*
|
* @param context
|
*/
|
public static void getHomeDevices(Context context) {
|
HandleSearch.getHomeDevices(context);
|
}
|
|
// public static void cancelSearching(){
|
// HandleSearch.isSearching = false;
|
// if (HandleSearch.searchTimer != null) {
|
// HandleSearch.searchTimer.cancel();
|
// HandleSearch.searchTimer = null;
|
// }
|
//
|
// if (HandleSearch.searchTwiceTimer != null) {
|
// HandleSearch.searchTwiceTimer.cancel();
|
// HandleSearch.searchTwiceTimer = null;
|
// }
|
//
|
// if (HandleSearch.searchFailTimer != null) {
|
// HandleSearch.searchFailTimer.cancel();
|
// HandleSearch.searchFailTimer = null;
|
// }
|
// }
|
|
|
/**
|
* 控制灯光
|
*
|
* @param info
|
* @param state
|
*/
|
public static void lightCtrl(final AppliancesInfo info, int state) {
|
HDLDeviceManager.isLightCtrlSuccess = false;
|
if (lightCtrlFailTimer != null) {
|
lightCtrlFailTimer.cancel();
|
lightCtrlFailTimer = null;
|
}
|
if ((!(state >= 0 && state <= 100))
|
|| (info.getBigType() != Configuration.LIGTH_BIG_TYPE)
|
|| info.getChannelNum() == 0
|
) {
|
Log.d("djlCtrl", "灯光设备控制不在范围内或不是灯光设备"
|
+ " \nstate = " + state
|
+ " \nLittleType = " + info.getLittleType()
|
+ " \nBigType = " + info.getBigType()
|
);
|
return;
|
}
|
|
byte[] bytes;
|
switch (info.getLittleType()) {
|
case 0:
|
case 1:
|
//可能有区别
|
bytes = new byte[]{(byte) info.getChannelNum(), (byte) state, 0, 0};
|
break;
|
case 9:
|
bytes = new byte[]{(byte) info.getPhysicsChannelNum(), (byte) state, 0, 0};
|
break;
|
case 10:
|
bytes = new byte[]{(byte) info.getPhysicsChannelNum(), (byte) state, 0, 0};
|
break;
|
default:
|
bytes = new byte[]{0};
|
break;
|
}
|
//酒店的是物理回路号,需要测试。可能会出现问题
|
// HDLDeviceManager.curCtrlLightType = info.getDeviceType();
|
// byte[] bytes = new byte[]{(byte) info.getChannelNum(), (byte) state, 0, 0};
|
addSendData(info, bytes, Configuration.CONTROL);
|
|
lightCtrlFailTimer = new Timer();
|
|
lightCtrlFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (!HDLDeviceManager.isLightCtrlSuccess) {
|
LightCtrlBackInfo lightCtrlBackInfo = new LightCtrlBackInfo();
|
lightCtrlBackInfo.setAppliancesInfo(info);
|
lightCtrlBackInfo.setChannelNum(info.getChannelNum());
|
EventBus.getDefault().post(new LightFeedBackEvent(lightCtrlBackInfo, false));
|
}
|
}
|
}, 5000);
|
}
|
|
|
/**
|
* 控制窗帘
|
*
|
* @param info
|
* @param state
|
*/
|
public static void curtainCtrl(final AppliancesInfo info, int state) {
|
HDLDeviceManager.isCurtainCtrlSuccess = false;
|
if (curtainCtrlFailTimer != null) {
|
curtainCtrlFailTimer.cancel();
|
curtainCtrlFailTimer = null;
|
}
|
byte[] bytes;
|
if (info.getBigType() == Configuration.CURTAIN_BIG_TYPE) {
|
if (info.getLittleType() == 1 || info.getLittleType() == 0) {
|
//这里是判断卷帘电机和开合帘电机
|
int newChannelNum;
|
if (state == CurtainCtrlParser.curtainOff
|
|| state == CurtainCtrlParser.curtainOn
|
|| state == CurtainCtrlParser.curtainPause) {
|
newChannelNum = info.getChannelNum();
|
} else {
|
newChannelNum = info.getChannelNum() + 16;
|
}
|
bytes = CurtainCtrlParser.getCurtainAddByte(newChannelNum, state);
|
} else {
|
bytes = CurtainCtrlParser.getCurtainAddByte(info.getChannelNum(), state);
|
}
|
|
addSendData(info, bytes, Configuration.CONTROL);
|
|
|
curtainCtrlFailTimer = new Timer();
|
|
curtainCtrlFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (!HDLDeviceManager.isCurtainCtrlSuccess) {
|
CurtainCtrlBackInfo curtainCtrlBackInfo = new CurtainCtrlBackInfo();
|
curtainCtrlBackInfo.setAppliancesInfo(info);
|
curtainCtrlBackInfo.setNum(info.getChannelNum());
|
EventBus.getDefault().post(new CurtainFeedBackEvent(curtainCtrlBackInfo, false));
|
}
|
}
|
}, 5000);
|
|
|
} else {
|
Log.d("djlCtrl", "不是窗帘设备"
|
+ " \nstate = " + state
|
+ " \nLittleType = " + info.getLittleType()
|
+ " \nBigType = " + info.getBigType()
|
);
|
}
|
}
|
|
|
/**
|
* 控制空调
|
*
|
* @param info
|
* @param type
|
* @param state
|
*/
|
public static void airCtrl(final AppliancesInfo info, int type, int state) {
|
HDLDeviceManager.isACCtrlSuccess = false;
|
if (acCtrlFailTimer != null) {
|
acCtrlFailTimer.cancel();
|
acCtrlFailTimer = null;
|
}
|
if (info.getBigType() == Configuration.AIR_BIG_TYPE) {
|
if (info.getDeviceType() == HDLApConfig.TYPE_AC_PANEL) {
|
addSendData(info, AirCtrlParser.getAirPanelAddByte(type, state), Configuration.CONTROL);
|
} else {
|
if (AirCtrlParser.getAcAddByte(info, type, state) != null) {
|
byte[] airbytes = AirCtrlParser.getAcAddByte(info, type, state);
|
// String airString = "发送的HVAC bytes:";
|
// for(int i = 0;i<airbytes.length;i++){
|
// airString += (airbytes[i] & 0xff) +",";
|
// }
|
// HDLLog.info(airString);
|
addSendData(info, airbytes, Configuration.CONTROL);
|
}
|
}
|
|
|
acCtrlFailTimer = new Timer();
|
acCtrlFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (!HDLDeviceManager.isACCtrlSuccess) {
|
AirCtrlBackInfo airCtrlBackInfo = new AirCtrlBackInfo();
|
airCtrlBackInfo.setAppliancesInfo(info);
|
EventBus.getDefault().post(new AirFeedBackEvent(airCtrlBackInfo, false));
|
}
|
}
|
}, 5000);
|
|
|
} else {
|
HDLLog.info("空调设备控制不在范围内"
|
+ " LittleType = " + info.getLittleType()
|
+ " BigType = " + info.getBigType()
|
);
|
}
|
}
|
|
|
/**
|
* 控制逻辑模块
|
*
|
* @param info
|
*/
|
public static void logicCtrl(final AppliancesInfo info) {
|
HDLDeviceManager.isSceneCtrlSuccess = false;
|
if (info.getBigType() == Configuration.LOGIC_BIG_TYPE
|
|| info.getBigType() == Configuration.GLOBAL_LOGIC_BIG_TYPE) {
|
if (info.getLogicMode() == null) {
|
// HDLUdpCore.sendTestCMD(HDLTest.CODE_LOGIC_MODE_NULL, HDLTest.EXCEPTION_TEST_PORT);
|
return;
|
} else {
|
addSendData(info, new byte[]{(byte) info.getLogicMode().getAreaNum(),
|
(byte) info.getLogicMode().getAreaSceneNum()}, Configuration.CONTROL);
|
}
|
|
|
if (sceneCtrlFailTimer != null) {
|
sceneCtrlFailTimer.cancel();
|
sceneCtrlFailTimer = null;
|
}
|
sceneCtrlFailTimer = new Timer();
|
sceneCtrlFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (!HDLDeviceManager.isSceneCtrlSuccess) {
|
HDLLog.info("逻辑控制失败");
|
LogicCtrlBackInfo logicCtrlBackInfo = new LogicCtrlBackInfo();
|
logicCtrlBackInfo.setAppliancesInfo(info);
|
EventBus.getDefault().post(new LogicFeedBackEvent(logicCtrlBackInfo, false));
|
}
|
}
|
}, 5000);
|
} else {
|
Log.d("djlCtrl", "逻辑模块设备控制不在范围内"
|
+ " LittleType = " + info.getLittleType()
|
+ " BigType = " + info.getBigType()
|
);
|
}
|
}
|
|
/**
|
* 控制新风系统
|
*
|
* @param info
|
* @param type
|
* @param state 2019-07-09
|
*/
|
public static void freshAirCtrl(final AppliancesInfo info, int type, int state) {
|
HDLDeviceManager.isFreshAirCtrlSuccess = false;
|
if (freshAirCtrlFailTimer != null) {
|
freshAirCtrlFailTimer.cancel();
|
freshAirCtrlFailTimer = null;
|
}
|
if (info.getBigType() == Configuration.FRESH_AIR_BIG_TYPE) {
|
byte[] freshAirbytes = FreshAirParser.getFreshAirAddByte(info, type, state);
|
addSendData(info, freshAirbytes, Configuration.CONTROL);
|
freshAirCtrlFailTimer = new Timer();
|
freshAirCtrlFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (!HDLDeviceManager.isFreshAirCtrlSuccess) {
|
FreshAirBackInfo mFreshAirBackInfo = new FreshAirBackInfo();
|
mFreshAirBackInfo.setAppliancesInfo(info);
|
EventBus.getDefault().post(new FreshAirFeedBackEvent(mFreshAirBackInfo, false));
|
}
|
}
|
}, 5000);
|
|
|
} else {
|
HDLLog.info("新风设备控制不在范围内"
|
+ " LittleType = " + info.getLittleType()
|
+ " BigType = " + info.getBigType()
|
);
|
}
|
}
|
|
/**
|
* 控制地热模块
|
*
|
* @param info
|
* @param type
|
* @param state 2019-07-10
|
*/
|
public static void geothermalCtrl(final AppliancesInfo info, int type, int state) {
|
HDLDeviceManager.isGeothermalCtrlSuccess = false;
|
if (geothermalCtrlFailTimer != null) {
|
geothermalCtrlFailTimer.cancel();
|
geothermalCtrlFailTimer = null;
|
}
|
if (info.getBigType() == Configuration.GEOTHERMAL_BIG_TYPE) {
|
byte[] sendbytes = GeothermalParser.getGeothermalAddByte(info, type, state);
|
addSendData(info, sendbytes, Configuration.CONTROL);
|
|
geothermalCtrlFailTimer = new Timer();
|
geothermalCtrlFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (!HDLDeviceManager.isGeothermalCtrlSuccess) {
|
GeothermalBackInfo mGeothermalBackInfo = new GeothermalBackInfo();
|
mGeothermalBackInfo.setAppliancesInfo(info);
|
EventBus.getDefault().post(new GeothermalFeedBackEvent(mGeothermalBackInfo, EventCode.FAILURE));
|
}
|
}
|
}, 5000);
|
|
|
} else {
|
HDLLog.info("地热模块控制不在范围内"
|
+ " LittleType = " + info.getLittleType()
|
+ " BigType = " + info.getBigType()
|
);
|
}
|
}
|
|
// 获取单一回路设备状态
|
// 读取设备状态
|
// public static void getDeviceState(final AppliancesInfo info) {
|
// HDLDeviceManager.isGetDeviceStateSuccess = false;
|
// switch (info.getBigType()) {
|
// case Configuration.LIGTH_BIG_TYPE:
|
// addSendData(info, new byte[]{}, Configuration.STATE);
|
// break;
|
// case Configuration.CURTAIN_BIG_TYPE:
|
// if (info.getDeviceType() == HDLApConfig.TYPE_CURTAIN_MODULE) {
|
// addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
|
// } else {
|
// addSendData(info, new byte[]{(byte) (info.getChannelNum() + 16)}, Configuration.STATE);
|
// }
|
// break;
|
// case Configuration.AIR_BIG_TYPE:
|
// addSendData(info, new byte[]{AirCtrlParser.airSwich}, Configuration.STATE);
|
//// addSendData(info,new byte[]{AirCtrlParser.refTem},Configuration.STATE);
|
// addSendData(info, new byte[]{AirCtrlParser.airSpeed}, Configuration.STATE);
|
// addSendData(info, new byte[]{AirCtrlParser.airMode}, Configuration.STATE);
|
//// addSendData(info,new byte[]{AirCtrlParser.heatTem},Configuration.STATE);
|
//// addSendData(info,new byte[]{AirCtrlParser.autoTem},Configuration.STATE);
|
// break;
|
// }
|
//
|
// if (info.getBigType() == Configuration.AIR_BIG_TYPE) {
|
// return;
|
// }
|
// if (getStateFailTimer != null) {
|
// getStateFailTimer.cancel();
|
// getStateFailTimer = null;
|
// }
|
// getStateFailTimer = new Timer();
|
// getStateFailTimer.schedule(new TimerTask() {
|
// @Override
|
// public void run() {
|
// if (!HDLDeviceManager.isGetDeviceStateSuccess) {
|
// EventBus.getDefault().post(new DeviceStateEvent(info, false));
|
// }
|
// }
|
// }, 5000);
|
//
|
// }
|
|
|
/**
|
* 获取单一设备状态
|
*
|
* @param info
|
*/
|
public static void getDeviceState(final AppliancesInfo info) {
|
if (info == null) {
|
return;
|
}
|
HDLDeviceManager.isGetDeviceStateSuccess = false;
|
switch (info.getDeviceType()) {
|
case HDLApConfig.TYPE_LIGHT_DIMMER:
|
case HDLApConfig.TYPE_LIGHT_RELAY:
|
case HDLApConfig.TYPE_LIGHT_MIX_DIMMER:
|
case HDLApConfig.TYPE_LIGHT_MIX_RELAY:
|
AppliancesInfo lightInfo = info;
|
int lightState = getLightState(info);
|
lightInfo.setCurState(lightState);
|
EventBus.getDefault().post(new DeviceStateEvent(lightInfo, true));
|
break;
|
|
case HDLApConfig.TYPE_CURTAIN_GLYSTRO:
|
case HDLApConfig.TYPE_CURTAIN_ROLLER:
|
case HDLApConfig.TYPE_CURTAIN_MODULE:
|
AppliancesInfo curtainInfo = info;
|
int curtainState = getCurtainState(info);
|
curtainInfo.setCurState(curtainState);
|
EventBus.getDefault().post(new DeviceStateEvent(curtainInfo, true));
|
break;
|
|
case HDLApConfig.TYPE_AC_HVAC:
|
case HDLApConfig.TYPE_AC_COOLMASTER:
|
case HDLApConfig.TYPE_AC_INFRARED:
|
case HDLApConfig.TYPE_AC_PANEL:
|
if (getACState(info).length >= 4) {
|
AppliancesInfo acInfo = info;
|
byte[] acState = getACState(info);
|
|
acInfo.setArrCurState(new byte[]{AirCtrlParser.airSwich, acState[0]});
|
EventBus.getDefault().post(new DeviceStateEvent(acInfo, true));
|
|
acInfo.setArrCurState(new byte[]{AirCtrlParser.airMode, acState[1]});
|
EventBus.getDefault().post(new DeviceStateEvent(acInfo, true));
|
|
switch (acState[1] & 0xff) {
|
case AirCtrlParser.airModeRefTem:
|
acInfo.setArrCurState(new byte[]{AirCtrlParser.refTem, acState[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(acInfo, true));
|
break;
|
case AirCtrlParser.airModeHeatTem:
|
acInfo.setArrCurState(new byte[]{AirCtrlParser.heatTem, acState[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(acInfo, true));
|
break;
|
case AirCtrlParser.airModeAuto:
|
acInfo.setArrCurState(new byte[]{AirCtrlParser.autoTem, acState[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(acInfo, true));
|
break;
|
case AirCtrlParser.airModeDehum:
|
acInfo.setArrCurState(new byte[]{AirCtrlParser.autoTem, acState[2]});
|
EventBus.getDefault().post(new DeviceStateEvent(acInfo, true));
|
break;
|
default:
|
break;
|
}
|
|
if ((acState[1] & 0xff) != AirCtrlParser.airModeDehum) {
|
acInfo.setArrCurState(new byte[]{AirCtrlParser.airSpeed, acState[3]});
|
EventBus.getDefault().post(new DeviceStateEvent(acInfo, true));
|
}
|
}
|
break;
|
|
case HDLApConfig.TYPE_SENSOR_DRY_CONTACT:
|
case HDLApConfig.TYPE_SENSOR_MOVEMENT_DETECTOR:
|
case HDLApConfig.TYPE_SENSOR_TEMP:
|
case HDLApConfig.TYPE_SENSOR_HUMIDITY:
|
case HDLApConfig.TYPE_SENSOR_ILLUMINACE:
|
case HDLApConfig.TYPE_SENSOR_VOC:
|
case HDLApConfig.TYPE_SENSOR_PM_2_POINT_5:
|
case HDLApConfig.TYPE_SENSOR_C02:
|
case HDLApConfig.TYPE_SENSOR_LPG:
|
case HDLApConfig.TYPE_SENSOR_CO_H2:
|
case HDLApConfig.TYPE_SENSOR_CH4:
|
case HDLApConfig.TYPE_SENSOR_SMOG:
|
case HDLApConfig.TYPE_SENSOR_WIND_SPEED:
|
case HDLApConfig.TYPE_SENSOR_WIND_PRESSURE:
|
case HDLApConfig.TYPE_SENSOR_LIQUID_FLOW:
|
case HDLApConfig.TYPE_SENSOR_LIQUID_PRESSURE:
|
case HDLApConfig.TYPE_SENSOR_LIQUID_DEPTH:
|
case HDLApConfig.TYPE_SENSOR_RAIN_FALL:
|
case HDLApConfig.TYPE_SENSOR_WEIGHT:
|
case HDLApConfig.TYPE_SENSOR_HEIGHT_LENGTH:
|
case HDLApConfig.TYPE_SENSOR_OBJECT_SPEED:
|
case HDLApConfig.TYPE_SENSOR_SHAKE:
|
case HDLApConfig.TYPE_SENSOR_VOLTAGE:
|
case HDLApConfig.TYPE_SENSOR_ELECTRICITY:
|
case HDLApConfig.TYPE_SENSOR_POWER:
|
//发送获取传感器所有数据
|
addSendData(info, new byte[]{(byte) info.getBigType(), (byte) info.getLittleType(), (byte) info.getChannelNum()}, Configuration.STATE);
|
break;
|
case HDLApConfig.TYPE_GEOTHERMAL_MODULE: //20190710 新增
|
//发送获取地热模块所有数据
|
addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
|
break;
|
case HDLApConfig.TYPE_FRESH_AIR: //20190710 新增
|
//发送获取新风系统所有数据
|
addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE);
|
break;
|
default:
|
break;
|
|
}
|
}
|
|
/**
|
* 获取所有设备状态
|
*
|
* @return
|
*/
|
public static List<DeviceStateBean> getAllDevicesState() {
|
List<DeviceStateBean> deviceStateBeanList = new ArrayList<>();
|
|
|
for (int i = 0; i < HDLDeviceManager.devicesDataList.size(); i++) {
|
List<AppliancesInfo> appliancesInfos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
|
for (int j = 0; j < appliancesInfos.size(); j++) {
|
if (appliancesInfos.get(j).getBigType() == Configuration.LIGTH_BIG_TYPE
|
|| appliancesInfos.get(j).getBigType() == Configuration.CURTAIN_BIG_TYPE
|
|| appliancesInfos.get(j).getBigType() == Configuration.AIR_BIG_TYPE
|
) {
|
DeviceStateBean deviceStateBean = new DeviceStateBean();
|
deviceStateBean.setDeviceSubnetID(appliancesInfos.get(j).getDeviceSubnetID());
|
deviceStateBean.setDeviceDeviceID(appliancesInfos.get(j).getDeviceDeviceID());
|
deviceStateBean.setBigType(appliancesInfos.get(j).getBigType());
|
deviceStateBean.setLittleType(appliancesInfos.get(j).getLittleType());
|
deviceStateBean.setDeviceType(appliancesInfos.get(j).getDeviceType());
|
deviceStateBean.setChannelNum(appliancesInfos.get(j).getChannelNum());
|
if (deviceStateBean.getBigType() == Configuration.AIR_BIG_TYPE) {
|
if (appliancesInfos.get(j).getArrCurState() != null) {
|
deviceStateBean.setArrCurState(appliancesInfos.get(j).getArrCurState());
|
}
|
|
} else {
|
deviceStateBean.setCurState(appliancesInfos.get(j).getIntCurState());
|
|
}
|
deviceStateBeanList.add(deviceStateBean);
|
}
|
|
}
|
}
|
//更新所有设备状态
|
HandleSearch.refreshAllDevicesState();
|
if (!deviceStateBeanList.isEmpty()) {
|
return deviceStateBeanList;
|
} else {
|
return null;
|
}
|
|
|
}
|
|
|
/**
|
* 获取灯光状态
|
*
|
* @param info
|
* @return
|
*/
|
private static int getLightState(final AppliancesInfo info) {
|
int curState = 0;
|
outter:
|
for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) {
|
if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID()
|
&& HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID()
|
) {
|
List<AppliancesInfo> infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
|
for (int j = 0, len2 = infos.size(); j < len2; j++) {
|
if (info.getBigType() == infos.get(j).getBigType()
|
&& info.getLittleType() == infos.get(j).getLittleType()
|
&& info.getChannelNum() == infos.get(j).getChannelNum()
|
) {
|
// curState = (int) infos.get(j).getCurState();//旧
|
//20190712解决强制转换int类型闪退
|
curState = HDLUtlis.getIntegerByObject(infos.get(j).getCurState());
|
break outter;
|
}
|
|
}
|
}
|
}
|
return curState;
|
}
|
|
/**
|
* 获取窗帘状态
|
*
|
* @param info
|
* @return
|
*/
|
private static int getCurtainState(final AppliancesInfo info) {
|
int curState = 0;
|
outter:
|
for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) {
|
if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID()
|
&& HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID()
|
) {
|
List<AppliancesInfo> infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
|
for (int j = 0, len2 = infos.size(); j < len2; j++) {
|
if (info.getBigType() == infos.get(j).getBigType()
|
&& info.getLittleType() == infos.get(j).getLittleType()
|
&& info.getChannelNum() == infos.get(j).getChannelNum()
|
) {
|
//这里应该是要修复的,暂时未找到。
|
//20190712解决强制转换int类型闪退
|
int state = HDLUtlis.getIntegerByObject(infos.get(j).getCurState());
|
switch (state) {
|
case -1:
|
curState = 0;
|
break;
|
case -2:
|
curState = 1;
|
break;
|
case -3:
|
curState = 2;
|
break;
|
default:
|
// curState = (int) infos.get(j).getCurState();
|
curState = state;
|
break;
|
|
}
|
|
break outter;
|
}
|
|
}
|
}
|
}
|
return curState;
|
}
|
|
/**
|
* 获取空调状态
|
*
|
* @param info
|
* @return
|
*/
|
private static byte[] getACState(final AppliancesInfo info) {
|
byte[] curState = new byte[]{};
|
outter:
|
for (int i = 0, len = HDLDeviceManager.devicesDataList.size(); i < len; i++) {
|
if (HDLDeviceManager.devicesDataList.get(i).getSourceSubnetID() == info.getDeviceSubnetID()
|
&& HDLDeviceManager.devicesDataList.get(i).getSourceDeviceID() == info.getDeviceDeviceID()
|
) {
|
List<AppliancesInfo> infos = HDLDeviceManager.devicesDataList.get(i).getAppliancesInfoList();
|
for (int j = 0, len2 = infos.size(); j < len2; j++) {
|
if (info.getBigType() == infos.get(j).getBigType()
|
&& info.getLittleType() == infos.get(j).getLittleType()
|
&& info.getChannelNum() == infos.get(j).getChannelNum()
|
) {
|
switch (info.getDeviceType()) {
|
case HDLApConfig.TYPE_AC_HVAC:
|
case HDLApConfig.TYPE_AC_PANEL:
|
curState = infos.get(j).getArrCurState();
|
break;
|
default:
|
break;
|
}
|
break outter;
|
}
|
|
}
|
}
|
}
|
return curState;
|
}
|
|
|
/**
|
* 背景音乐控制
|
*
|
* @param info
|
* @param type
|
*/
|
public static void audioCtrl(AppliancesInfo info, int type) {
|
byte[] musicBytes;
|
int command;
|
switch (type) {
|
case HDLAudio.SET_AUDIO_PLAYSTOP:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x53, 0x54, 0x4F, 0x50, 0x0D};
|
break;
|
case HDLAudio.SET_AUDIO_PLAYPAUSE:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{42, 83, 49, 80, 76, 65, 89, 80, 65, 85, 83, 69, 0x0D};
|
break;
|
case HDLAudio.SET_NEXT_SONG:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x0D};
|
break;
|
case HDLAudio.SET_PRE_SONG:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x0D};
|
break;
|
case HDLAudio.GET_AUDIO_MODE:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x4C, 0x41, 0x59, 0x4D, 0x4F, 0x44, 0x45, 0x3F, 0x0D};
|
break;
|
case HDLAudio.SET_AUDIO_MODE_UP:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2B, 0x0D};
|
break;
|
case HDLAudio.SET_AUDIO_MODE_DOWN:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4D, 0x4F, 0x44, 0x45, 0x2D, 0x0D};
|
break;
|
case HDLAudio.GET_AUDIO_CURRRENT_INFO:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
//*Z1STAUS?归为键
|
musicBytes = new byte[]{0x2A, 0x5A, 0x31, 0x53, 0x54, 0x41, 0x54, 0x55, 0x53, 0x3F, 0x0D};
|
break;
|
case HDLAudio.SET_PRE_LIST:
|
HDLAudio.isSetPreNextList = true;
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x50, 0x52, 0x45, 0x56, 0x4C, 0x49, 0x53, 0x54, 0x0D};
|
break;
|
case HDLAudio.SET_NEXT_LIST:
|
HDLAudio.isSetPreNextList = true;
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x53, 0x31, 0x4E, 0x45, 0x58, 0x54, 0x4C, 0x49, 0x53, 0x54, 0x0D};
|
break;
|
case HDLAudio.TEXT:
|
command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND;
|
musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x4C, 0x49, 0x53, 0x54, 0x30, 0x30, 0x31, 0x30, 0x30, 0x32, 0x31, 0x0D};
|
break;
|
default:
|
command = 0;
|
musicBytes = null;
|
break;
|
}
|
if (musicBytes != null) {
|
// String sendData = "";
|
// for(int i = 0,len = musicBytes.length;i<len;i++){
|
// sendData += musicBytes[i]+",";
|
// }
|
// sendData = StringUtil.asciiToString(sendData);
|
// HDLLog.info("发出数据:"+sendData+"子网id:"+info.getDeviceSubnetID()+" 设备id:"+info.getDeviceDeviceID());
|
cusSendCommand(command,
|
info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes,
|
info.getPort(), info.getIpAddress());
|
}
|
|
}
|
|
/**
|
* 背景音乐控制
|
*
|
* @param info
|
* @param type
|
* @param value
|
*/
|
public static void audioCtrl(AppliancesInfo info, int type, int value) {
|
byte[] musicBytes;
|
int command;
|
switch (type) {
|
case HDLAudio.GET_AUDIO_LIST:
|
HDLAudio.numStr.clear();
|
HDLAudio.songNameList.clear();
|
HDLAudio.curListNum = value;
|
command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND;
|
//*Z011TYPE0011归位键
|
musicBytes = new byte[]{0x2A, 0x5A, 0x30, 0x31, 0x31, 0x54, 0x59, 0x50, 0x45, 0x30, 0x30, 0x31, 0x31, 0x0D};
|
break;
|
case HDLAudio.SET_AUDIO_VOL:
|
command = Configuration.AUDIO_CTRL_READ_COMMAND;
|
musicBytes = HDLAudio.audioVolparse(value);
|
break;
|
default:
|
command = 0;
|
musicBytes = null;
|
break;
|
}
|
if (musicBytes != null) {
|
// String sendData = "";
|
// for(int i = 0,len = musicBytes.length;i<len;i++){
|
// sendData += musicBytes[i]+",";
|
// }
|
// sendData = StringUtil.asciiToString(sendData);
|
// HDLLog.info("发出数据:"+sendData+"子网id:"+info.getDeviceSubnetID()+" 设备id:"+info.getDeviceDeviceID());
|
cusSendCommand(command,
|
info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes,
|
info.getPort(), info.getIpAddress());
|
}
|
}
|
|
/**
|
* @param info
|
* @param type
|
* @param listId 列表号
|
* @param songId 歌曲号
|
*/
|
public static void audioCtrl(AppliancesInfo info, int type, int listId, int songId) {
|
byte[] musicBytes;
|
int command;
|
switch (type) {
|
|
case HDLAudio.SET_CHOOSE_PLAY_SONG:
|
command = Configuration.AUDIO_MenuPlay_INSTRUCTION_COMMAND;
|
musicBytes = HDLAudio.audioChooseSongParse(listId, songId);
|
break;
|
default:
|
command = 0;
|
musicBytes = null;
|
break;
|
}
|
|
if (musicBytes != null) {
|
// String sendData = "";
|
// for(int i = 0,len = musicBytes.length;i<len;i++){
|
// sendData += musicBytes[i]+",";
|
// }
|
// sendData = StringUtil.asciiToString(sendData);
|
// HDLLog.info("发出数据:"+sendData+"子网id:"+info.getDeviceSubnetID()+" 设备id:"+info.getDeviceDeviceID());
|
cusSendCommand(command,
|
info.getDeviceSubnetID(), info.getDeviceDeviceID(), musicBytes,
|
info.getPort(), info.getIpAddress());
|
}
|
|
}
|
|
|
/**
|
* 提供第三方调用设置本地子网号、设备号
|
*
|
* @param context
|
* @param subId
|
* @param deviceId
|
*/
|
public static void setLocalId(Context context, int subId, int deviceId) {
|
Crc.localDeviceID = deviceId;
|
Crc.localSubnetID = subId;
|
SPUtils.setParam(context, SPUtils.KEY_SUB_ID_, subId);
|
SPUtils.setParam(context, SPUtils.KEY_DEVICE_ID, deviceId);
|
}
|
|
/**
|
* 单设备发送命令
|
*
|
* @param info
|
* @param addBytes
|
* @param type
|
*/
|
private static void addSendData(final AppliancesInfo info, byte[] addBytes, final int type) {
|
|
final Crc sendDatas = new Crc(info.getStateCommand(), info.getDeviceSubnetID(), info.getDeviceDeviceID(), addBytes, info.getPort(), info.getIpAddress());
|
sendDatas.count = 0;
|
|
|
final Timer sendCycleTimer = new Timer();
|
sendCycleTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (sendDatas.count >= 3) {
|
sendCycleTimer.cancel();
|
} else {
|
// HDLLog.info("控制发送第"+sendDatas.count+ "次");
|
sendDatas.count++;
|
if (type == Configuration.STATE) {
|
sendDatas.command = info.getStateCommand();
|
sendDatas.isCtrlSuccess = HDLDeviceManager.isGetDeviceStateSuccess;
|
} else if (type == Configuration.CONTROL) {
|
sendDatas.command = info.getCtrlCommand();
|
switch (info.getBigType()) {
|
case Configuration.LIGTH_BIG_TYPE:
|
sendDatas.isCtrlSuccess = HDLDeviceManager.isLightCtrlSuccess;
|
break;
|
case Configuration.CURTAIN_BIG_TYPE:
|
sendDatas.isCtrlSuccess = HDLDeviceManager.isCurtainCtrlSuccess;
|
break;
|
case Configuration.AIR_BIG_TYPE:
|
sendDatas.isCtrlSuccess = HDLDeviceManager.isACCtrlSuccess;
|
break;
|
case Configuration.LOGIC_BIG_TYPE:
|
sendDatas.isCtrlSuccess = HDLDeviceManager.isSceneCtrlSuccess;
|
break;
|
case Configuration.GEOTHERMAL_BIG_TYPE://20190710新增
|
sendDatas.isCtrlSuccess = HDLDeviceManager.isGeothermalCtrlSuccess;
|
break;
|
case Configuration.FRESH_AIR_BIG_TYPE://20190710新增
|
sendDatas.isCtrlSuccess = HDLDeviceManager.isFreshAirCtrlSuccess;
|
break;
|
|
default:
|
sendDatas.isCtrlSuccess = false;
|
}
|
}
|
if (!sendDatas.isCtrlSuccess) {
|
cusSendCommand(sendDatas.command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendDatas.addBytes, info.getPort(), info.getIpAddress());
|
} else {
|
// HDLLog.info("控制已成功,停止");
|
sendCycleTimer.cancel();
|
}
|
}
|
|
}
|
}, 1, 200);
|
|
|
}
|
|
|
/**
|
* 发送广播或点对点命令
|
*
|
* @param command 操作码
|
* @param subnetID 子网号
|
* @param deviceID 设备号
|
* @param addBytes 附加数据
|
* @param port 端口号
|
* @param ipAddress ip地址
|
*/
|
public static void cusSendCommand(int command, int subnetID, int deviceID, byte[] addBytes, int port, String ipAddress) {
|
Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes, port, ipAddress);
|
|
HDLUdpCore.sendData(sendDatas);
|
}
|
|
|
/**
|
* 发送组播命令
|
* 这个方法目前仅用在拿到Rcu ip地址
|
*
|
* @param command 操作码
|
* @param subnetID 子网号
|
* @param deviceID 设备号
|
* @param addBytes 附加数据
|
* @param port 端口号
|
*/
|
public static void cusSendMulticastCommand(int command, int subnetID, int deviceID, byte[] addBytes, int port) {
|
|
Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes, port, Configuration.RCU_MULTI_IP);
|
HDLUdpCore.sendMulticastData(sendDatas);
|
}
|
|
|
}
|