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.Config.ZigbeeDeviceID;
|
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.Bean.ZigbeeBean.ZigbeeDeviceSaveBean;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.ZigbeeBean.ZigbeeSceneSaveBean;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.ZigbeeBean.gatewaybeans.StatusReadBackBean;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Bean.ZigbeeBean.gatewaybeans.StatusThermostatReadBean;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Callback.StateEvent;
|
import com.hdl.sdk.hdl_core.HDLDeviceManger.Callback.StateListener;
|
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.HDLDeviceManger.EventBusEvent.ZigbeeDeviceInfoEvent;
|
import com.hdl.sdk.hdl_core.Util.LogUtil.HDLLog;
|
import com.hdl.sdk.hdl_core.Util.NetUtil.NetWorkUtil;
|
import com.hdl.sdk.hdl_core.Util.SPUtil.SPUtils;
|
import com.hdl.sdk.hdl_core.Util.TransformUtil.HDLUtlis;
|
import com.hdl.sdk.hdl_core.Util.TransformUtil.JsonUtil;
|
|
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.Subscribe;
|
import org.greenrobot.eventbus.ThreadMode;
|
|
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
|
|
private static List<ZigbeeDeviceSaveBean> zigbeeDeviceDatas;//zigbee映射数据回调
|
private static List<ZigbeeSceneSaveBean> zigbeeSceneDatas;//zigbeeScene映射数据回调
|
private static StatusReadBackBean statusReadBackBean;//状态回调
|
private static StatusThermostatReadBean thermostatReadBean;//恒温器状态回调
|
private static ZigbeeDeviceSaveBean zigbeeDeviceBean;//设备数据
|
private static ZigbeeSceneSaveBean zigbeeSceneBean;//设备场景数据
|
private static int type = 0;
|
|
|
/**
|
* 初始化
|
*
|
* @param context
|
*/
|
public static void init(Context context) {
|
HDLDeviceManager.init(context);
|
}
|
|
|
// /**
|
// * 获取本地广播IP
|
// * @return
|
// */
|
// public static String getLocalBroadCastIp(){
|
// return NetWorkUtil.getLocalBroadCast();
|
// }
|
|
/**
|
* 获取本地广播IP
|
*
|
* @return
|
*/
|
public static String getLocalBroadCastIp() {
|
return NetWorkUtil.getLocalBroadCast();
|
}
|
|
/**
|
* 是否开启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, Boolean isZigbee) {
|
HandleSearch.getHomeDevices(context, isZigbee);
|
}
|
|
// 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, boolean isZigbee) {
|
if (isZigbee) {
|
if (statusReadBackBean != null) {
|
if (info.getBigType() == Configuration.LIGTH_BIG_TYPE && info.getLittleType() == 1) {//继电器 开关
|
if (statusReadBackBean.getValue() == Configuration.RELAY_ON) {
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.OnOffOutput, Configuration.RELAY_OFF);
|
} else {
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.OnOffOutput, Configuration.RELAY_ON);
|
}
|
}
|
if (info.getBigType() == Configuration.LIGTH_BIG_TYPE && info.getLittleType() == 0) {//调光器 开到固定的值或者开到0
|
int value = (int) (state * 2.55);
|
if (statusReadBackBean.getValue() != 0) {
|
//lightStatus = 0;
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.DimmableLight, 0);
|
} else {
|
//lightStatus = value;
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.DimmableLight, value);
|
}
|
}
|
} else {
|
HDLLog.info("为获取到设备状态");
|
}
|
|
} else {
|
// HDLDeviceManager.isLightCtrlSuccess = false;
|
HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, 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.getDeviceCtrlSuccessStateWithInfo(info)) {
|
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, boolean isZigbee) {
|
if (isZigbee) {
|
switch (state) {
|
case CurtainCtrlParser.curtainOn:
|
HDLCommandText.sendCurtainStatus(zigbeeDeviceBean, ZigbeeDeviceID.WindowCoveringDevice, 0, 0);//value = 0为开,tag = 0为标记控制
|
break;
|
case CurtainCtrlParser.curtainOff:
|
HDLCommandText.sendCurtainStatus(zigbeeDeviceBean, ZigbeeDeviceID.WindowCoveringDevice, 1, 0);//value = 1为关,tag = 0为标记控制
|
break;
|
case CurtainCtrlParser.curtainPause:
|
HDLCommandText.sendCurtainStatus(zigbeeDeviceBean, ZigbeeDeviceID.WindowCoveringDevice, 2, 0);//value = 2为暂停,tag = 0为标记控制
|
break;
|
default:
|
HDLCommandText.sendCurtainStatus(zigbeeDeviceBean, ZigbeeDeviceID.WindowCoveringDevice, state, 1);//value = state为调整数值,tag = 1为标记数值控制
|
break;
|
}
|
} else {
|
HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, 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.getDeviceCtrlSuccessStateWithInfo(info)) {
|
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, boolean isZigbee) {
|
if (isZigbee) {
|
switch (type) {
|
case AirCtrlParser.airSwich:
|
//开关选择
|
switch (state) {
|
case AirCtrlParser.airOn://空调开
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 1, 0, 0);//value = 1为空调开 tag = 0为标志为开关控制 mode忽略
|
break;
|
case AirCtrlParser.airOff://空调关
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 0, 0, 0);//value = 0为空调开 tag = 0为标志为开关控制 mode忽略
|
break;
|
}
|
break;
|
case AirCtrlParser.airMode:
|
//恒温器模式选择
|
switch (state) {
|
case AirCtrlParser.airModeHeatTem://空调模式制热
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 4, 1, 0);//value = 4为恒温器制热 tag = 1为标志为恒温器控制 mode忽略
|
break;
|
case AirCtrlParser.airModeVen://空调模式通风
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 7, 1, 0);//value = 7为恒温器通风 tag = 1为标志为恒温器控制 mode忽略
|
break;
|
case AirCtrlParser.airModeAuto://空调模式自动
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 1, 1, 0);//value = 1为恒温器自动 tag = 1为标志为恒温器控制 mode忽略
|
break;
|
case AirCtrlParser.airModeDehum://空调模式抽湿
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 8, 1, 0);//value = 8为恒温器抽湿 tag = 1为标志为恒温器控制 mode忽略
|
break;
|
case AirCtrlParser.airModeRefTem://空调模式制冷
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 3, 1, 0);//value = 3为恒温器制冷 tag = 1为标志为恒温器控制 mode忽略
|
break;
|
}
|
break;
|
case AirCtrlParser.airSpeed:
|
//风速模式选择
|
switch (state) {
|
case AirCtrlParser.airSpeedHigh://风速高风
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 3, 2, 0);//value = 3为风速高风 tag = 2为标志为风速控制 mode忽略
|
break;
|
case AirCtrlParser.airSpeedMid://风速中风
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 2, 2, 0);//value = 2为风速中风 tag = 2为标志为风速控制 mode忽略
|
break;
|
case AirCtrlParser.airSpeedLow://风速低风
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 1, 2, 0);//value = 1为风速低风 tag = 2为标志为风速控制 mode忽略
|
break;
|
case AirCtrlParser.airSpeedAuto://风速自动
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, 5, 2, 0);//value = 5为风速自动 tag = 2为标志为风速控制 mode忽略
|
break;
|
}
|
break;
|
case AirCtrlParser.dehumTem://当前空调模式为抽湿
|
case AirCtrlParser.refTem: //当前空调模式为制冷
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, state, 3, 1);//value = state为温度值 tag = 3为标志为温度控制 mode = 1为制冷
|
break;
|
case AirCtrlParser.heatTem://当前空调模式为制热
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, state, 3, 0);//value = state为温度值 tag = 3为标志为温度控制 mode = 0为制热
|
break;
|
case AirCtrlParser.autoTem://当前空调模式为自动
|
HDLCommandText.sendAirStatus(zigbeeDeviceBean, ZigbeeDeviceID.Thermostat, state, 3, 2);//value = state为温度值 tag = 3为标志为温度控制 mode = 2为自动
|
break;
|
}
|
} else {
|
// HDLDeviceManager.isACCtrlSuccess = false;
|
HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, 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.getDeviceCtrlSuccessStateWithInfo(info)) {
|
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
|
* @param type
|
* @param state 2019-07-09
|
*/
|
public static void freshAirCtrl(final AppliancesInfo info, int type, int state, boolean isZigbee) {
|
if (isZigbee) {
|
switch (type) {
|
case FreshAirParser.freshAirSwich:
|
switch (state) {
|
case FreshAirParser.freshAirOn:
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.AirPanel, 1);//value = 1为新风开
|
break;
|
case FreshAirParser.freshAirOff:
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.AirPanel, 0);//value = 0为新风关
|
break;
|
}
|
break;
|
case FreshAirParser.freshAirSpeed://高风、低风
|
switch (state) {
|
case FreshAirParser.freshAirSpeedMid://控制成高风
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.AirPanel, 3);//value = 3为新风高风
|
break;
|
case FreshAirParser.freshAirSpeedLow://控制成低速
|
case FreshAirParser.freshAirSpeedOff:
|
HDLCommandText.sendStatus(zigbeeDeviceBean, ZigbeeDeviceID.AirPanel, 1);//value = 1为新风低风
|
break;
|
}
|
break;
|
}
|
} else {
|
// HDLDeviceManager.isFreshAirCtrlSuccess = false;
|
HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, 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.getDeviceCtrlSuccessStateWithInfo(info)) {
|
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
|
*/
|
public static void logicCtrl(final AppliancesInfo info, final boolean isZigbee) {
|
if (isZigbee) {
|
HDLCommandText.sendSceneStatus(zigbeeSceneBean.getScenesId(), 0);//控制场景的id,延时时间为0
|
} else {
|
// HDLDeviceManager.isSceneCtrlSuccess = false;
|
HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, 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.getDeviceCtrlSuccessStateWithInfo(info)) {
|
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 tempInt 2020-03-15
|
*/
|
public static void geothermalCtrlTemp(final AppliancesInfo info, int tempInt) {
|
// HDLDeviceManager.isGeothermalCtrlSuccess = false;
|
HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false);
|
if (geothermalCtrlFailTimer != null) {
|
geothermalCtrlFailTimer.cancel();
|
geothermalCtrlFailTimer = null;
|
}
|
if (info.getBigType() == Configuration.GEOTHERMAL_BIG_TYPE) {
|
byte[] sendbytes = GeothermalParser.getGeothermalAddByteTemp(info, tempInt);
|
addSendData(info, sendbytes, Configuration.CONTROL);
|
|
geothermalCtrlFailTimer = new Timer();
|
geothermalCtrlFailTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) {
|
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()
|
);
|
}
|
}
|
|
/**
|
* 控制地热模块
|
*
|
* @param info
|
* @param type
|
* @param state 2019-07-10
|
*/
|
public static void geothermalCtrl(final AppliancesInfo info, int type, int state) {
|
// HDLDeviceManager.isGeothermalCtrlSuccess = false;
|
HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, 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.getDeviceCtrlSuccessStateWithInfo(info)) {
|
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);
|
//
|
// }
|
|
/**
|
* 获取单一设备状态
|
*/
|
public static void getDeviceState(Context context, final AppliancesInfo appliancesInfo, boolean isZigbee) {
|
if (isZigbee) {
|
zigbeeDeviceDatas = SPUtils.getZigbeeDeviceSaveBean(context, SPUtils.KEY_ZIGBEE_IP);
|
zigbeeSceneDatas = SPUtils.getZigbeeSceneSaveBean(context, SPUtils.KEY_ZIGBEE_SCENE_IP);
|
HDLCommandText hdlCommandText = new HDLCommandText();
|
for (ZigbeeDeviceSaveBean zigbeeDeviceSaveBean : zigbeeDeviceDatas) {
|
if (appliancesInfo.getBigType() == Configuration.LIGTH_BIG_TYPE && appliancesInfo.getLittleType() == 1) {
|
//继电器
|
type = ZigbeeDeviceID.OnOffOutput;
|
if (zigbeeDeviceSaveBean.getmSubnetID() == appliancesInfo.getDeviceSubnetID() &&
|
zigbeeDeviceSaveBean.getEpoint() == appliancesInfo.getChannelNum() &&
|
zigbeeDeviceSaveBean.getDeviceMark() == appliancesInfo.getDeviceDeviceID())//判断bus数据对应的zigbee数据
|
{
|
HDLLog.info("继电器匹配成功");
|
zigbeeDeviceBean = zigbeeDeviceSaveBean;
|
hdlCommandText.setIpAddr(zigbeeDeviceSaveBean.getIpAddress());
|
HDLCommandText.initStatus(zigbeeDeviceSaveBean, ZigbeeDeviceID.OnOffOutput);
|
}
|
}
|
|
if (appliancesInfo.getBigType() == Configuration.LIGTH_BIG_TYPE && appliancesInfo.getLittleType() == 0) {
|
//调光器
|
type = ZigbeeDeviceID.DimmableLight;
|
if (zigbeeDeviceSaveBean.getmSubnetID() == appliancesInfo.getDeviceSubnetID() &&
|
zigbeeDeviceSaveBean.getEpoint() == appliancesInfo.getChannelNum() &&
|
zigbeeDeviceSaveBean.getDeviceMark() == appliancesInfo.getDeviceDeviceID())//判断bus数据对应的zigbee数据
|
{
|
HDLLog.info("调光器匹配成功");
|
zigbeeDeviceBean = zigbeeDeviceSaveBean;
|
hdlCommandText.setIpAddr(zigbeeDeviceSaveBean.getIpAddress());
|
HDLCommandText.initStatus(zigbeeDeviceSaveBean, ZigbeeDeviceID.DimmableLight);
|
}
|
}
|
if (appliancesInfo.getBigType() == Configuration.CURTAIN_BIG_TYPE && appliancesInfo.getLittleType() == 0) {
|
//窗帘
|
type = ZigbeeDeviceID.WindowCoveringDevice;
|
if (zigbeeDeviceSaveBean.getmSubnetID() == appliancesInfo.getDeviceSubnetID() &&
|
zigbeeDeviceSaveBean.getEpoint() == appliancesInfo.getChannelNum() &&
|
zigbeeDeviceSaveBean.getDeviceMark() == appliancesInfo.getDeviceDeviceID())//判断bus数据对应的zigbee数据
|
{
|
HDLLog.info("窗帘匹配成功");
|
zigbeeDeviceBean = zigbeeDeviceSaveBean;
|
hdlCommandText.setIpAddr(zigbeeDeviceSaveBean.getIpAddress());
|
HDLCommandText.initStatus(zigbeeDeviceSaveBean, ZigbeeDeviceID.WindowCoveringDevice);
|
}
|
}
|
if (appliancesInfo.getBigType() == Configuration.AIR_BIG_TYPE && appliancesInfo.getLittleType() == 0) {
|
//空调
|
type = ZigbeeDeviceID.Thermostat;
|
if (zigbeeDeviceSaveBean.getmSubnetID() == appliancesInfo.getDeviceSubnetID() &&
|
zigbeeDeviceSaveBean.getEpoint() == appliancesInfo.getChannelNum() &&
|
zigbeeDeviceSaveBean.getDeviceMark() == appliancesInfo.getDeviceDeviceID())//判断bus数据对应的zigbee数据
|
{
|
HDLLog.info("空调匹配成功");
|
zigbeeDeviceBean = zigbeeDeviceSaveBean;
|
hdlCommandText.setIpAddr(zigbeeDeviceSaveBean.getIpAddress());
|
HDLCommandText.initStatus(zigbeeDeviceSaveBean, ZigbeeDeviceID.Thermostat);
|
}
|
}
|
if (appliancesInfo.getBigType() == Configuration.FRESH_AIR_BIG_TYPE && appliancesInfo.getLittleType() == 0) {
|
//新风
|
type = ZigbeeDeviceID.AirPanel;
|
if (zigbeeDeviceSaveBean.getmSubnetID() == appliancesInfo.getDeviceSubnetID() &&
|
zigbeeDeviceSaveBean.getEpoint() == appliancesInfo.getChannelNum() &&
|
zigbeeDeviceSaveBean.getDeviceMark() == appliancesInfo.getDeviceDeviceID())//判断bus数据对应的zigbee数据
|
{
|
HDLLog.info("新风匹配成功");
|
zigbeeDeviceBean = zigbeeDeviceSaveBean;
|
hdlCommandText.setIpAddr(zigbeeDeviceSaveBean.getIpAddress());
|
HDLCommandText.initStatus(zigbeeDeviceSaveBean, ZigbeeDeviceID.AirPanel);
|
}
|
}
|
}
|
for (ZigbeeSceneSaveBean zigbeeSceneSaveBean : zigbeeSceneDatas) {
|
if (appliancesInfo.getBigType() == Configuration.GLOBAL_LOGIC_BIG_TYPE && appliancesInfo.getLittleType() == 0) {
|
//场景
|
type = ZigbeeDeviceID.SceneMark;
|
if (zigbeeSceneSaveBean.getSubnetId() == appliancesInfo.getDeviceSubnetID() &&
|
zigbeeSceneSaveBean.getDeviceid() == appliancesInfo.getDeviceDeviceID())//判断bus数据对应的zigbee数据
|
{
|
HDLLog.info("场景匹配成功");
|
zigbeeSceneBean = zigbeeSceneSaveBean;
|
hdlCommandText.setIpAddr(zigbeeSceneSaveBean.getIpAddr());
|
}
|
}
|
}
|
Log.d("11113", "type: " + type);
|
//读写状态信息回调
|
HDLCommandText.setStateListener(new StateListener() {
|
@Override
|
public void onData(final StateEvent event) {
|
//上报zigbee回馈信息
|
Log.d("11113", "zigbee 回馈json:" + event.getJson());
|
switch (type) {
|
case ZigbeeDeviceID.OnOffOutput:
|
//继电器设备回调
|
statusReadBackBean = JsonUtil.parseJsonWithGson(event.getJson(), StatusReadBackBean.class);
|
if (statusReadBackBean.getValue() == Configuration.RELAY_ON) {
|
//继电器关
|
appliancesInfo.setCurState(0);
|
EventBus.getDefault().post(new DeviceStateEvent(appliancesInfo, true));
|
} else {
|
//继电器开
|
appliancesInfo.setCurState(100);
|
EventBus.getDefault().post(new DeviceStateEvent(appliancesInfo, true));
|
}
|
break;
|
case ZigbeeDeviceID.WindowCoveringDevice:
|
//窗帘设备回调
|
statusReadBackBean = JsonUtil.parseJsonWithGson(event.getJson(), StatusReadBackBean.class);
|
appliancesInfo.setCurState(statusReadBackBean.getValue());
|
EventBus.getDefault().post(new DeviceStateEvent(appliancesInfo, true));
|
break;
|
case ZigbeeDeviceID.DimmableLight:
|
//调光器设备
|
statusReadBackBean = JsonUtil.parseJsonWithGson(event.getJson(), StatusReadBackBean.class);
|
Log.d("2222", "回调数据: " + statusReadBackBean.getValue());
|
appliancesInfo.setCurState(statusReadBackBean.getValue());
|
EventBus.getDefault().post(new DeviceStateEvent(appliancesInfo, true));
|
break;
|
case ZigbeeDeviceID.Thermostat:
|
//温度设备
|
thermostatReadBean = JsonUtil.parseJsonWithGson(event.getJson(), StatusThermostatReadBean.class);
|
int fanMode = thermostatReadBean.getFanmode(); //新风模式 0:Off、1:Low、2:Medium、3:High、4:On、5:Auto、6:Smart
|
int thermostatMode = thermostatReadBean.getThermostatmode();//恒温模式 0:Off、1:Auto、3:Cool、4:Heat、5:Emergency heating、6:Precooling、7:Fan only、8:Dry、9:Sleep;
|
int coolingSetpoint = thermostatReadBean.getCoolingSetpoint();//制冷温度
|
int heatingSetpoint = thermostatReadBean.getHeatingSetpoint();//制热温度
|
int tag = thermostatReadBean.getTag();
|
switch (tag) {
|
case 0://开关模式返回
|
if (fanMode == 0 && thermostatMode == 0) {
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSwich, AirCtrlParser.airOff)); //空调关
|
} else {
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSwich, AirCtrlParser.airOn));//空调开
|
}
|
break;
|
case 1://恒温器模式返回
|
if (fanMode == 0 && thermostatMode == 0) {
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSwich, AirCtrlParser.airOff));//空调关
|
} else {
|
switch (thermostatMode) {
|
case 1://自动模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airMode, AirCtrlParser.airModeAuto));
|
break;
|
case 3://制冷模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airMode, AirCtrlParser.airModeRefTem));
|
break;
|
case 4://制热模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airMode, AirCtrlParser.airModeHeatTem));
|
break;
|
case 7://通风模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airMode, AirCtrlParser.airModeVen));
|
break;
|
case 8://抽湿模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airMode, AirCtrlParser.airModeDehum));
|
break;
|
}
|
}
|
|
break;
|
case 2://通风器模式返回
|
if (fanMode == 0 && thermostatMode == 0) {
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSwich, AirCtrlParser.airOff)); //空调关
|
} else {
|
switch (fanMode) {
|
case 1://低风
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSpeed, AirCtrlParser.airSpeedLow));
|
break;
|
case 2://中风
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSpeed, AirCtrlParser.airSpeedMid));
|
break;
|
case 3://高风
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSpeed, AirCtrlParser.airSpeedHigh));
|
break;
|
case 5://自动
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSpeed, AirCtrlParser.airSpeedAuto));
|
break;
|
}
|
}
|
break;
|
case 3://设置温度模式返回
|
if (fanMode == 0 && thermostatMode == 0) {
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.airSwich, AirCtrlParser.airOff)); //空调关
|
} else {
|
switch (thermostatMode) {
|
case 1://TODO 自动模式温度返回需要协议上的
|
if (coolingSetpoint != 0 && heatingSetpoint == 0) {
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.autoTem, coolingSetpoint));
|
} else {
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.autoTem, heatingSetpoint));
|
}
|
break;
|
case 3://制冷模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.refTem, coolingSetpoint));
|
break;
|
case 4://制热模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.heatTem, heatingSetpoint));
|
break;
|
case 8://抽湿模式
|
appliancesInfo.setArrCurState(AirCtrlParser.getAirPanelAddByte(AirCtrlParser.dehumTem, coolingSetpoint));
|
break;
|
}
|
}
|
break;
|
}
|
EventBus.getDefault().post(new DeviceStateEvent(appliancesInfo, true));
|
break;
|
case ZigbeeDeviceID.AirPanel:
|
//新风设备回调
|
statusReadBackBean = JsonUtil.parseJsonWithGson(event.getJson(), StatusReadBackBean.class);
|
FreshAirBackInfo freshAirBackInfo = new FreshAirBackInfo();
|
freshAirBackInfo.setAppliancesInfo(appliancesInfo);
|
switch (statusReadBackBean.getValue()) {
|
case 0://风扇关
|
freshAirBackInfo.setIsOn(0);
|
freshAirBackInfo.setFreshAirSpeed(0);
|
break;
|
case 1://低风
|
freshAirBackInfo.setIsOn(1);
|
freshAirBackInfo.setFreshAirSpeed(1);
|
break;
|
case 3://高风
|
freshAirBackInfo.setIsOn(1);
|
freshAirBackInfo.setFreshAirSpeed(3);
|
break;
|
case 255:
|
break;
|
}
|
EventBus.getDefault().post(new FreshAirFeedBackEvent(freshAirBackInfo, true));
|
break;
|
case ZigbeeDeviceID.SceneMark:
|
//场景回调
|
statusReadBackBean = JsonUtil.parseJsonWithGson(event.getJson(), StatusReadBackBean.class);
|
if (statusReadBackBean.getValue() == 1) {
|
LogicCtrlBackInfo logicCtrlBackInfo = new LogicCtrlBackInfo();
|
logicCtrlBackInfo.setAppliancesInfo(appliancesInfo);
|
EventBus.getDefault().post(new LogicFeedBackEvent(logicCtrlBackInfo, true));
|
}
|
break;
|
}
|
}
|
});
|
} else {
|
if (appliancesInfo == null) {
|
return;
|
}
|
HDLDeviceManager.isGetDeviceStateSuccess = false;
|
switch (appliancesInfo.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 = appliancesInfo;
|
int lightState = getLightState(appliancesInfo);
|
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 = appliancesInfo;
|
int curtainState = getCurtainState(appliancesInfo);
|
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(appliancesInfo).length >= 4) {
|
AppliancesInfo acInfo = appliancesInfo;
|
byte[] acState = getACState(appliancesInfo);
|
|
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(appliancesInfo, new byte[]{(byte) appliancesInfo.getBigType(), (byte) appliancesInfo.getLittleType(), (byte) appliancesInfo.getChannelNum()}, Configuration.STATE);
|
break;
|
case HDLApConfig.TYPE_GEOTHERMAL_MODULE: //20190710 新增
|
//发送获取地热模块所有数据
|
addSendData(appliancesInfo, new byte[]{(byte) appliancesInfo.getChannelNum()}, Configuration.STATE);
|
break;
|
case HDLApConfig.TYPE_FRESH_AIR: //20190710 新增
|
//发送获取新风系统所有数据
|
addSendData(appliancesInfo, new byte[]{(byte) appliancesInfo.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(30);
|
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).getCurStateObject());
|
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).getCurStateObject());
|
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(), getLocalBroadCastIp());
|
}
|
|
}
|
|
/**
|
* 背景音乐控制
|
*
|
* @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(), getLocalBroadCastIp());
|
}
|
}
|
|
/**
|
* @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(), getLocalBroadCastIp());
|
}
|
|
}
|
|
|
/**
|
* 提供第三方调用设置本地子网号、设备号
|
*
|
* @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(), getLocalBroadCastIp());
|
sendDatas.count = 0;
|
|
|
final Timer sendCycleTimer = new Timer();
|
sendCycleTimer.schedule(new TimerTask() {
|
@Override
|
public void run() {
|
if (sendDatas.count >= 4) {
|
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();
|
HDLLog.info("getDeviceKey: " + info.getDeviceKey());
|
sendDatas.isCtrlSuccess = HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info);
|
|
// 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(), getLocalBroadCastIp());
|
} else {
|
// HDLLog.info("控制已成功,停止");
|
sendCycleTimer.cancel();
|
}
|
}
|
}
|
}, 1, 500); //2019-07-23 发一次补发3次,间隔500ms
|
|
|
}
|
|
|
/**
|
* 发送广播或点对点命令
|
*
|
* @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);
|
}
|
|
}
|