From 071a8328823a2861f93ce556a4da3e4119cab1a3 Mon Sep 17 00:00:00 2001 From: panlili2024 <14743743+panlili2024@user.noreply.gitee.com> Date: 星期四, 19 九月 2024 16:24:28 +0800 Subject: [PATCH] 完成金茂定制功能 --- HDL_TTLSDK485/src/main/java/com/hdl/sdk/ttl/HDLDeviceManger/Core/HDLCommand.java | 248 ++++++++++++++++++++++++++++++------------------- 1 files changed, 153 insertions(+), 95 deletions(-) diff --git a/HDL_TTLSDK485/src/main/java/com/hdl/sdk/ttl/HDLDeviceManger/Core/HDLCommand.java b/HDL_TTLSDK485/src/main/java/com/hdl/sdk/ttl/HDLDeviceManger/Core/HDLCommand.java index 302b167..bbe4f12 100644 --- a/HDL_TTLSDK485/src/main/java/com/hdl/sdk/ttl/HDLDeviceManger/Core/HDLCommand.java +++ b/HDL_TTLSDK485/src/main/java/com/hdl/sdk/ttl/HDLDeviceManger/Core/HDLCommand.java @@ -24,10 +24,13 @@ import com.hdl.sdk.ttl.HDLAppliances.HDLLight.LightCtrlBackInfo; import com.hdl.sdk.ttl.HDLAppliances.HDLLight.Parser.LightCtrlParser; import com.hdl.sdk.ttl.HDLAppliances.HDLLogic.LogicCtrlBackInfo; +import com.hdl.sdk.ttl.HDLAppliances.HDLLogic.SceneCtrlBackInfo; import com.hdl.sdk.ttl.HDLAppliances.HDLSecurity.Parser.SecurityParser; import com.hdl.sdk.ttl.HDLDeviceManger.Bean.AppliancesInfo; import com.hdl.sdk.ttl.HDLDeviceManger.Bean.DeviceStateBean; import com.hdl.sdk.ttl.HDLDeviceManger.Bean.MCUDataBean; +import com.hdl.sdk.ttl.HDLDeviceManger.Bean.ScenesData; +import com.hdl.sdk.ttl.HDLDeviceManger.Bean.SendDatas; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.AirFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.ColourLightFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.CommonSwitchCtrlBackEvent; @@ -41,6 +44,7 @@ import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LightFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.LogicFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.MCUFeedBackEvent; +import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.SceneFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.SecurityArmingFeedBackEvent; import com.hdl.sdk.ttl.HDLDeviceManger.EventBusEvent.UpdateRemarkFeedBackEvent; import com.hdl.sdk.ttl.Utils.HDLUtlis.HDLUtlis; @@ -61,6 +65,7 @@ public class HDLCommand { public static int mRequestTimeout = 5000;//榛樿璇锋眰瓒呮椂鏃堕棿 + public static int mRequestCurtainTimeout = 8000;//榛樿璇锋眰瓒呮椂鏃堕棿 private static Timer getStateFailTimer = null;//鑾峰彇璁惧鐘舵�佸け璐imer private static Timer lightCtrlFailTimer = null;//鎺у埗鐏厜澶辫触Timer private static Timer curtainCtrlFailTimer = null;//鎺у埗绐楀笜澶辫触Timer @@ -101,13 +106,27 @@ // HDLDeviceManager.release(); // } + + /** + * 鎼滅储缃戝叧 + */ + public static void seachGateway() { + HandleSearch.seachGateway(); + } + /** * 鑾峰彇瀹跺眳璁惧 */ - public static void getHomeDevices() { - HandleSearch.getHomeDevices(); + public static void getHomeDevices(int subnetID, int deviceID) { + HandleSearch.getHomeDevices(subnetID, deviceID); } + /** + * 鑾峰彇瀹跺眳鍦烘櫙 + */ + public static void getHomeScenes(int subnetID, int deviceID) { + HandleSearch.seachHomeScenes(subnetID, deviceID); + } /** * 鑾峰彇瀹跺眳璁惧澶囨敞 @@ -119,8 +138,8 @@ /** * 鍙戠幇鏂拌澶囨悳绱�,涓嶄細娓呯┖鍘熻澶囧垪琛ㄦ暟鎹� */ - public static void getNewHomeDevices() { - HandleSearch.getNewHomeDevices(); + public static void getNewHomeDevices(int subnetID, int deviceID) { + HandleSearch.getNewHomeDevices(subnetID, deviceID); } /** @@ -301,8 +320,7 @@ * @param info * @param state */ - public static void curtainCtrl(final AppliancesInfo info, int state) { -// HDLDeviceManager.isCurtainCtrlSuccess = false; + public static void curtainCtrl(final AppliancesInfo info, int state, int type) { HDLDeviceManager.setDeviceCtrlSuccessStateWithInfo(info, false); if (curtainCtrlFailTimer != null) { curtainCtrlFailTimer.cancel(); @@ -310,19 +328,23 @@ } byte[] bytes; if (info.getBigType() == Configuration.CURTAIN_BIG_TYPE) { - if (info.getLittleType() == 1 || info.getLittleType() == 0) { - //杩欓噷鏄垽鏂嵎甯樼數鏈哄拰寮�鍚堝笜鐢垫満 + if (info.getLittleType() == 1 || info.getLittleType() == 0 || info.getLittleType() == 3) {//鍒ゆ柇鍗峰笜鐢垫満/寮�鍚堝笜鐢垫満/棣欐牸閲屾媺甯樼數鏈� int newChannelNum; - if (state == CurtainCtrlParser.curtainOff - || state == CurtainCtrlParser.curtainOn - || state == CurtainCtrlParser.curtainPause) { - newChannelNum = info.getChannelNum(); + if (type == 0) { + if (state == CurtainCtrlParser.curtainOff + || state == CurtainCtrlParser.curtainOn + || state == CurtainCtrlParser.curtainPause) { + newChannelNum = info.getChannelNum(); + } else { + newChannelNum = info.getChannelNum() + 16; + } } else { - newChannelNum = info.getChannelNum() + 16; + newChannelNum = info.getChannelNum(); } - bytes = CurtainCtrlParser.getCurtainAddByte(newChannelNum, state); + + bytes = CurtainCtrlParser.getCurtainAddByte(newChannelNum, state, type); } else { - bytes = CurtainCtrlParser.getCurtainAddByte(info.getChannelNum(), state); + bytes = CurtainCtrlParser.getCurtainAddByte(info.getChannelNum(), state, type); } addSendData(info, bytes, Configuration.CONTROL); @@ -336,11 +358,11 @@ CurtainCtrlBackInfo curtainCtrlBackInfo = new CurtainCtrlBackInfo(); curtainCtrlBackInfo.setAppliancesInfo(info); curtainCtrlBackInfo.setNum(info.getChannelNum()); + EventBus.getDefault().post(new CurtainFeedBackEvent(curtainCtrlBackInfo, false)); } } - }, mRequestTimeout); - + }, mRequestCurtainTimeout); } else { HDLLog.I("djlCtrl; 涓嶆槸绐楀笜璁惧" @@ -369,7 +391,7 @@ if (info.getBigType() == Configuration.AIR_BIG_TYPE) { if (info.getDeviceType() == HDLApConfig.TYPE_AC_PANEL) { addSendData(info, AirCtrlParser.getAirPanelAddByte(type, state), Configuration.CONTROL); - } else if (info.getDeviceType() == HDLApConfig.TYPE_AC_TECHSYS) { + } else if (info.getDeviceType() == HDLApConfig.TYPE_AC_TECHSYS || info.getDeviceType() == HDLApConfig.TYPE_AC_KNXTECHSYS) { byte[] airbytes = AirCtrlParser.getAirTechAddByte(info, type, state); if (airbytes != null) { addSendData(info, airbytes, Configuration.CONTROL); @@ -553,56 +575,42 @@ } }, mRequestTimeout); } else { - HDLLog.I("djlCtrl: 閫昏緫妯″潡璁惧鎺у埗涓嶅湪鑼冨洿鍐�" + HDLLog.I("閫昏緫妯″潡璁惧鎺у埗涓嶅湪鑼冨洿鍐�" + " LittleType = " + info.getLittleType() + " BigType = " + info.getBigType() ); } } - // 鑾峰彇鍗曚竴鍥炶矾璁惧鐘舵�� - // 璇诲彇璁惧鐘舵�� -// public static void getDeviceState(final AppliancesInfo I) { -// HDLDeviceManager.isGetDeviceStateSuccess = false; -// switch (I.getBigType()) { -// case Configuration.LIGTH_BIG_TYPE: -// addSendData(I, new byte[]{}, Configuration.STATE); -// break; -// case Configuration.CURTAIN_BIG_TYPE: -// if (I.getDeviceType() == HDLApConfig.TYPE_CURTAIN_MODULE) { -// addSendData(I, new byte[]{(byte) I.getChannelNum()}, Configuration.STATE); -// } else { -// addSendData(I, new byte[]{(byte) (I.getChannelNum() + 16)}, Configuration.STATE); -// } -// break; -// case Configuration.AIR_BIG_TYPE: -// addSendData(I, new byte[]{AirCtrlParser.airSwich}, Configuration.STATE); -//// addSendData(I,new byte[]{AirCtrlParser.refTem},Configuration.STATE); -// addSendData(I, new byte[]{AirCtrlParser.airSpeed}, Configuration.STATE); -// addSendData(I, new byte[]{AirCtrlParser.airMode}, Configuration.STATE); -//// addSendData(I,new byte[]{AirCtrlParser.heatTem},Configuration.STATE); -//// addSendData(I,new byte[]{AirCtrlParser.autoTem},Configuration.STATE); -// break; -// } -// -// if (I.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(I, false)); -// } -// } -// }, mRequestTimeout); -// -// } + /** + * 鍦烘櫙鎺у埗 + * + * @param scenesData + */ + public static void sceneCtrl(final ScenesData scenesData) { + cusSendCommand(Configuration.LOGIC_CTRL_COMMAND, scenesData.getSourceSubnetID(), scenesData.getSourceDeviceID(), new byte[]{ + (byte) (scenesData.getAreaCodeID()), + (byte) (scenesData.getSceneID()) + }); + + if (sceneCtrlFailTimer != null) { + sceneCtrlFailTimer.cancel(); + sceneCtrlFailTimer = null; + } + sceneCtrlFailTimer = new Timer(); + sceneCtrlFailTimer.schedule(new TimerTask() { + @Override + public void run() { + if (!HDLDeviceManager.isSceneCtrlSuccess()) { + HDLLog.I("鍦烘櫙鎺у埗澶辫触"); + SceneCtrlBackInfo sceneCtrlBackInfo = new SceneCtrlBackInfo(); + sceneCtrlBackInfo.setAreaCodeID(scenesData.getAreaCodeID()); + sceneCtrlBackInfo.setSceneID(scenesData.getSceneID()); + EventBus.getDefault().post(new SceneFeedBackEvent(sceneCtrlBackInfo, false)); + } + } + }, mRequestTimeout); + } /** * 鎺у埗绐楀笜 @@ -690,10 +698,14 @@ } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { + case HDLApConfig.TYPE_CURTAIN_MODULE: + addSendData(info, new byte[]{(byte) info.getChannelNum(), 0, 1}, Configuration.STATE); + break; case HDLApConfig.TYPE_CURTAIN_GLYSTRO: case HDLApConfig.TYPE_CURTAIN_ROLLER: - case HDLApConfig.TYPE_CURTAIN_MODULE: - addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); + case HDLApConfig.TYPE_CURTAIN_SHANGRILA: + //鍙鍙栫櫨鍒嗘瘮锛屼笉璇诲彇寮�鍏冲仠 + addSendData(info, new byte[]{(byte) info.getChannelNum(), 0, 2}, Configuration.STATE); break; default: HDLLog.I("涓嶆槸绐楀笜璁惧"); @@ -717,7 +729,8 @@ case HDLApConfig.TYPE_LIGHT_MIX_DIMMER: case HDLApConfig.TYPE_LIGHT_MIX_RELAY: //鍙戦�佽幏鍙栫伅鍏夌姸鎬佹暟鎹� - addSendData(info, new byte[0], Configuration.STATE); + byte[] sendbytes = new byte[]{(byte) info.getChannelNum()}; + addSendData(info, sendbytes, Configuration.STATE); break; default: HDLLog.I("涓嶆槸鐏厜璁惧"); @@ -805,34 +818,11 @@ } HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { - 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: - case HDLApConfig.TYPE_SENSOR_FLOODING: - case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET: - case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON: + case HDLApConfig.TYPE_SENSOR_PM_10: //鍙戦�佽幏浼犳劅鍣ㄦā鍧楃姸鎬佹暟鎹� byte[] sendDatabyte = new byte[]{ (byte) info.getBigType(), @@ -887,6 +877,7 @@ case HDLApConfig.TYPE_SENSOR_FLOODING: case HDLApConfig.TYPE_SENSOR_DOOR_MAGNET: case HDLApConfig.TYPE_SENSOR_EMERGENCY_BUTTON: + case HDLApConfig.TYPE_SENSOR_PM_10: //鍙戦�佽幏浼犳劅鍣ㄦā鍧楃姸鎬佹暟鎹� byte[] sendDatabyte = new byte[]{ (byte) 1, @@ -936,8 +927,35 @@ HDLDeviceManager.isGetDeviceStateSuccess = false; switch (info.getDeviceType()) { case HDLApConfig.TYPE_AC_TECHSYS: + case HDLApConfig.TYPE_AC_KNXTECHSYS: //鍙戦�佺鎶�绯荤粺鐘舵�佹暟鎹� addSendData(info, new byte[]{(byte) info.getChannelNum()}, Configuration.STATE); + break; + default: + HDLLog.I("涓嶆槸绉戞妧绯荤粺璁惧"); + break; + } + } + + /** + * 鑾峰彇绉戞妧绯荤粺瀹ゅ唴婀垮害鐘舵�� + * + * @param info + */ + public static void getTechSysDeviceHumidityFromNetwork(final AppliancesInfo info) { + if (info == null) { + return; + } + info.setGetDeviceStateSuccess(false); + switch (info.getDeviceType()) { + case HDLApConfig.TYPE_AC_KNXTECHSYS: + //鍙戦�佺鎶�绯荤粺鐘舵�佹暟鎹� + byte[] sendDatabyte = new byte[]{ + (byte) info.getBigType(), + (byte) info.getLittleType(), + (byte) info.getChannelNum() + }; + addCommandSendData(info, sendDatabyte, Configuration.SENSOR_STATE_COMMAND); break; default: HDLLog.I("涓嶆槸绉戞妧绯荤粺璁惧"); @@ -970,6 +988,7 @@ case HDLApConfig.TYPE_CURTAIN_GLYSTRO: case HDLApConfig.TYPE_CURTAIN_ROLLER: case HDLApConfig.TYPE_CURTAIN_MODULE: + case HDLApConfig.TYPE_CURTAIN_SHANGRILA: int curtainState = getCurtainState(info); info.setCurState(curtainState); EventBus.getDefault().post(new DeviceStateEvent(info, true)); @@ -980,6 +999,7 @@ case HDLApConfig.TYPE_AC_INFRARED: case HDLApConfig.TYPE_AC_PANEL: case HDLApConfig.TYPE_AC_TECHSYS: + case HDLApConfig.TYPE_AC_KNXTECHSYS: //2019-8-21 澧炲姞鍒ょ┖ byte[] acState = getACState(info); if (acState != null && acState.length >= 4) { @@ -1205,6 +1225,7 @@ case HDLApConfig.TYPE_AC_HVAC: case HDLApConfig.TYPE_AC_PANEL: case HDLApConfig.TYPE_AC_TECHSYS: + case HDLApConfig.TYPE_AC_KNXTECHSYS: curState = infos.get(j).getArrCurState(); break; default: @@ -1780,7 +1801,7 @@ @Override public void run() { //2019-07 鎺у埗鍙戦�佹鏁� - if (sendDatas.count >= 4) { + if (sendDatas.count >= 3) { sendCycleTimer.cancel(); } else { sendDatas.count++; @@ -1807,10 +1828,44 @@ } }, 1, 500); - - } + /** + * 鍗曡澶囧彂閫佸懡浠� + * 鐩墠鎺у埗鍙戦�佹鏁颁负3娆� + * 鍙戜竴鏉�,琛ュ彂3鏉★紝闂撮殧500ms + * + * @param info + * @param addBytes + */ + private static void addCommandSendData(final AppliancesInfo info, byte[] addBytes, final int command) { + + final Crc sendDatas = new Crc(info.getStateCommand(), info.getDeviceSubnetID(), info.getDeviceDeviceID(), addBytes); + sendDatas.count = 0; + + final Timer sendCycleTimer = new Timer(); + sendCycleTimer.schedule(new TimerTask() { + @Override + public void run() { + //2019-07 鎺у埗鍙戦�佹鏁� + if (sendDatas.count >= 3) { + sendCycleTimer.cancel(); + } else { + sendDatas.count++; + sendDatas.command = command; + HDLLog.I("---getDevice锛� " + info.getDeviceKey() + " ---command锛� " + Integer.toHexString(command));//2019-8-2 + sendDatas.isCtrlSuccess = info.isGetDeviceStateSuccess(); + + if (!sendDatas.isCtrlSuccess) { + HDLLog.I("璇诲彇鍙戦�佺" + sendDatas.count + "娆�"); + cusSendCommand(sendDatas.command, info.getDeviceSubnetID(), info.getDeviceDeviceID(), sendDatas.addBytes); + } else { + sendCycleTimer.cancel(); + } + } + } + }, 1, 500); + } /** * 鍙戦�佸箍鎾垨鐐瑰鐐瑰懡浠� @@ -1821,9 +1876,12 @@ * @param addBytes 闄勫姞鏁版嵁 */ public static void cusSendCommand(int command, int subnetID, int deviceID, byte[] addBytes) { - Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes); - HDLSerialPortCore.sendData(sendDatas); - + if (HDLSerialPortCore.getIsModule()) { + Crc sendDatas = new Crc(command, subnetID, deviceID, addBytes); + HDLSerialPortCore.sendData(sendDatas); + } else { + SendDatas.AddSendData(command, subnetID, deviceID, addBytes); + } } /** -- Gitblit v1.8.0