| | |
| | | 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.HDLCommonSwitch.CommonSwitchBackInfo; |
| | | 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.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.HDLAppliances.HDLSecurity.Parser.SecurityParser; |
| | | 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.CommonSwitchCtrlBackEvent; |
| | | 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.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.SecurityArmingFeedBackEvent; |
| | | 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; |
| | |
| | | */ |
| | | |
| | | public class HDLCommand { |
| | | |
| | | public static int mRequestTimeout = 5000;//默认请求超时时间 |
| | | private static Timer getStateFailTimer = null;//获取设备状态失败Timer |
| | | |
| | | private static Timer lightCtrlFailTimer = null;//控制灯光失败Timer |
| | |
| | | private static Timer freshAirCtrlFailTimer = null;//控制新风失败Timer 2019-07-09 |
| | | private static Timer geothermalCtrlFailTimer = null;//控制地热失败Timer 2019-07-10 |
| | | |
| | | private static Timer securityCtrlFailTimer = null;//安防模块操作失败Timer |
| | | private static Timer commonSwitchCtrlFailTimer = null;//通用开关失败Timer |
| | | |
| | | /** |
| | | * 初始化 |
| | |
| | | HDLDeviceManager.init(context); |
| | | } |
| | | |
| | | /** |
| | | * 开启bus模式 |
| | | * 启用6000端口 |
| | | * @param context |
| | | */ |
| | | public static void startHomeMode(Context context) { |
| | | SPUtils.setParam(context, SPUtils.KEY_RCU_IP_, ""); |
| | | HandleSearch.curSearchMode = HandleSearch.GET_BUS_DEVICES; |
| | | HandleSearch.rcuIp = ""; |
| | | HDLUdpCore.closeSocket6008(); |
| | | HDLUdpCore.init6000(); |
| | | } |
| | | |
| | | /** |
| | | * 开启RCU模式 |
| | | * 启用6008端口 |
| | | * @param context |
| | | * @param newRcuIp RCU的IP地址 |
| | | */ |
| | | public static void startRcuMode(Context context, String newRcuIp) { |
| | | HandleSearch.curSearchMode = HandleSearch.GET_RCU_DEVICES; |
| | | HandleSearch.rcuIp = newRcuIp; |
| | | SPUtils.setParam(context, SPUtils.KEY_RCU_IP_, newRcuIp); |
| | | HDLUdpCore.closeSocket6000(); |
| | | HDLUdpCore.init6008(); |
| | | } |
| | | |
| | | // /** |
| | | // * 获取本地广播IP |
| | |
| | | } |
| | | |
| | | |
| | | /**************************************2020-06-23新增***************************************/ |
| | | /** |
| | | * 控制通用开关 |
| | | * |
| | | * @param info |
| | | */ |
| | | public static void commonSwitchCtrl(final AppliancesInfo info, int state) { |
| | | |
| | | HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); |
| | | if (info.getBigType() == Configuration.COMMON_SWITCH_BIG_TYPE) { |
| | | |
| | | if (commonSwitchCtrlFailTimer != null) { |
| | | commonSwitchCtrlFailTimer.cancel(); |
| | | commonSwitchCtrlFailTimer = null; |
| | | } |
| | | |
| | | byte[] bytes = new byte[]{(byte) info.getChannelNum(), (byte) state}; |
| | | |
| | | addSendData(info, bytes, Configuration.CONTROL); |
| | | |
| | | commonSwitchCtrlFailTimer = new Timer(); |
| | | commonSwitchCtrlFailTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { |
| | | HDLLog.info("通用开关控制失败"); |
| | | CommonSwitchBackInfo mCommonSwitchBackInfo = new CommonSwitchBackInfo(); |
| | | mCommonSwitchBackInfo.setAppliancesInfo(info); |
| | | EventBus.getDefault().post(new CommonSwitchCtrlBackEvent(mCommonSwitchBackInfo, false)); |
| | | } |
| | | } |
| | | }, mRequestTimeout); |
| | | } else { |
| | | HDLLog.info("djlCtrl: 通用开关设备控制不在范围内" |
| | | + " LittleType = " + info.getLittleType() |
| | | + " BigType = " + info.getBigType() |
| | | ); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 获取通用开关状态 |
| | | * @param info |
| | | */ |
| | | public static void getCommonSwitchStateFromNetwork(final AppliancesInfo info) { |
| | | if (info == null) { |
| | | return; |
| | | } |
| | | HDLDeviceManager.isGetDeviceStateSuccess = false; |
| | | switch (info.getDeviceType()) { |
| | | case HDLApConfig.TYPE_COMMON_SWITCH: |
| | | addSendData(info, new byte[0], Configuration.STATE); |
| | | break; |
| | | default: |
| | | HDLLog.info("不是通用开关设备"); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取安防模块状态 |
| | | * @param info |
| | | */ |
| | | public static void getSecurityStateFromNetwork(final AppliancesInfo info) { |
| | | if (info == null) { |
| | | return; |
| | | } |
| | | HDLDeviceManager.isGetDeviceStateSuccess = false; |
| | | switch (info.getDeviceType()) { |
| | | case HDLApConfig.TYPE_SECURITY_MODULE: |
| | | //发送获安防模块状态数据 |
| | | addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); |
| | | break; |
| | | default: |
| | | HDLLog.info("不是安防模块"); |
| | | break; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 安防模块 布防设置 |
| | | * 2020-06-23 |
| | | * @param info |
| | | */ |
| | | public static void securityArmingCtrl(final AppliancesInfo info, int state) { |
| | | // HDLDeviceManager.isSecurityCtrlSuccess = false; |
| | | HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); |
| | | if (securityCtrlFailTimer != null) { |
| | | securityCtrlFailTimer.cancel(); |
| | | securityCtrlFailTimer = null; |
| | | } |
| | | if (info.getBigType() == Configuration.SECURITY_BIG_TYPE) { |
| | | byte[] sendbytes = SecurityParser.getArmingByte(info, state); |
| | | addSendData(info, sendbytes, Configuration.CONTROL); |
| | | securityCtrlFailTimer = new Timer(); |
| | | securityCtrlFailTimer.schedule(new TimerTask() { |
| | | @Override |
| | | public void run() { |
| | | if (!HDLDeviceManager.getDeviceCtrlSuccessStateWithInfo(info)) { |
| | | EventBus.getDefault().post(new SecurityArmingFeedBackEvent(info,0, false)); |
| | | } |
| | | } |
| | | }, 5000); |
| | | |
| | | } else { |
| | | HDLLog.info("安防模块不在范围内" |
| | | + " LittleType = " + info.getLittleType() |
| | | + " BigType = " + info.getBigType() |
| | | ); |
| | | } |
| | | } |
| | | |
| | | // /** |
| | | // * 安防模块 报警设置 |
| | | // * 2019-7-29 |
| | | // * @param info |
| | | // * @param state 发送的报警内容,只报警一种 |
| | | // */ |
| | | // public static void securitySendAlarm(final AppliancesInfo info, int state) { |
| | | // if (info.getBigType() == Configuration.SECURITY_BIG_TYPE) { |
| | | // byte[] sendbytes = SecurityParser.getAlarmByte(info, state); |
| | | // cusSendCommand(Configuration.SECURITY_ALARM_CTRL_COMMAND, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendbytes); |
| | | // } else { |
| | | // HDLLog.info("不是安防模块" |
| | | // + " LittleType = " + info.getLittleType() |
| | | // + " BigType = " + info.getBigType() |
| | | // ); |
| | | // } |
| | | // } |
| | | |
| | | } |