From e747e6d8524e3146bb48dc304a713f309966b1c6 Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期二, 19 五月 2020 13:10:03 +0800 Subject: [PATCH] 新版本 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs | 202 ++++++++++++++++++++++++++++++++++++++------------ 1 files changed, 152 insertions(+), 50 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs index 2f7a1b2..8a29182 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs @@ -1,4 +1,7 @@ -锘縰sing System; +锘縰sing Newtonsoft.Json; +using Newtonsoft.Json.Linq; +using Shared.Phone.ModelData; +using System; using System.Collections.Generic; using System.Text; using System.Threading.Tasks; @@ -37,22 +40,30 @@ #region 鈻� 鎵嬫媺鎺у埗___________________________ /// <summary> - /// 璁剧疆鎵嬫媺鎺у埗鐘舵�佸�� + /// 璁剧疆鎵嬫媺鎺у埗鐘舵�佸�� 鈽嗏槅鈽嗏槅鈽� /// </summary> - /// <param name="rollershade">绐楀笜瀵硅薄</param> + /// <param name="device">绐楀笜瀵硅薄</param> /// <param name="bolStatu">鎵嬫媺鎺у埗鐘舵�佸��</param> /// <returns></returns> - public async Task<bool> SetHandPullControl(Rollershade rollershade, bool bolStatu) + public bool SetHandPullControl(CommonDevice device, bool bolStatu) { - var result = await rollershade.SetCurtianMaintenanceAsync(bolStatu); - //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 - string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); - if (error != null) + //濡傛灉鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) { - this.ShowTipMsg(error); + //娣诲姞缂撳瓨 + DeviceModelDataLogic.Current.SetCurtainHandPullControl(device, bolStatu, "SetWritableValue"); + return true; + } + //鑾峰彇鍙戦�佺殑鍛戒护瀛楃 + var sendData = this.GetHandPullControlText(device.DeviceAddr, device.DeviceEpoint, bolStatu); + //鍙戦�佺粰缃戝叧 + var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon"); + if (result.ErrorMsg != null) + { + this.ShowTipMsg(result.ErrorMsg); return false; } - if (result == null || result.setWritableValueResponData == null) + if (result.ErrorMsgDiv == 0) { //鍒囨崲鎵嬫媺鎺у埗澶辫触 string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail); @@ -61,16 +72,33 @@ this.ShowTipMsg(msg); return false; } - if (result.setWritableValueResponData.Status != 0) + + var data = JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData); + if (data.Status != 0) { //鍒囨崲鎵嬫媺鎺у埗澶辫触 string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail); this.ShowTipMsg(msg); return false; } - //澶囦唤灞炴�� - await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜鎵嬫媺鎺у埗, bolStatu); return true; + } + + /// <summary> + /// 鑾峰彇鏇存敼鎵嬫媺鎺у埗鐘舵�佺殑瀛楃涓插懡浠� 鈽嗏槅鈽嗏槅鈽� + /// </summary> + /// <param name="DeviceAddr">DeviceAddr</param> + /// <param name="DeviceEpoint">DeviceEpoint</param> + /// <param name="bolStatu">鎵嬫媺鎺у埗鐘舵�佸��</param> + /// <returns></returns> + public string GetHandPullControlText(string DeviceAddr, int DeviceEpoint, bool bolStatu) + { + int bit2 = bolStatu == true ? 1 : 0; + int attributeData = bit2 * 4; + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } }; + var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } }; + jObject.Add("Data", data); + return jObject.ToString(); } #endregion @@ -83,9 +111,9 @@ /// <param name="rollershade">绐楀笜瀵硅薄</param> /// <param name="bolStatu">false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜</param> /// <returns></returns> - public async Task<bool> SetCurtainDirection(Rollershade rollershade, bool bolStatu) + public bool SetCurtainDirection(CommonDevice rollershade, bool bolStatu) { - var result = await rollershade.SetCurtainDirectionAsync(bolStatu); + var result = this.SetCurtainDirectionAsync(rollershade, bolStatu); //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); if (error != null) @@ -109,22 +137,121 @@ this.ShowTipMsg(msg); return false; } - //澶囦唤璁惧 - await this.BackupCurtainDirection(rollershade, bolStatu); return true; } /// <summary> - /// 澶囦唤绐楀笜鏂瑰悜 + /// 璁剧疆寮�鍚堝笜鐢垫満鏂瑰悜 + /// <para>isDirectionReversed (false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜锛�)</para> . /// </summary> - /// <param name="rollershade">绐楀笜瀵硅薄</param> - /// <param name="bolStatu">false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜</param> - /// <returns></returns> - public async Task<bool> BackupCurtainDirection(Rollershade rollershade, bool bolStatu) + private CommonDevice.SetWritableValueResponAllData SetCurtainDirectionAsync(CommonDevice device, bool isDirectionReversed) { - //澶囦唤璁惧 - return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜鏂瑰悜, bolStatu); + //濡傛灉褰撳墠鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) + { + return ModelData.DeviceModelDataLogic.Current.SetCurtainDirection(device, isDirectionReversed, "SetWritableValue"); + } + //鑾峰彇缂栬緫绐楀笜鏂瑰悜鐨勫懡浠ゅ瓧绗� + var sendData = this.GetCurtainDirectionCommadText(device.DeviceAddr, device.DeviceEpoint, isDirectionReversed); + var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(device, "SetWritableValue", sendData, "SetWritableValue_Respon"); + if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) + { + return null; + } + + var tempData = JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData); + return new CommonDevice.SetWritableValueResponAllData { setWritableValueResponData = tempData }; + } + + /// <summary> + /// 鑾峰彇缂栬緫绐楀笜鏂瑰悜鐨勫懡浠ゅ瓧绗� + /// </summary> + /// <param name="DeviceAddr"></param> + /// <param name="DeviceEpoint"></param> + /// <param name="isDirectionReversed"></param> + /// <returns></returns> + public string GetCurtainDirectionCommadText(string DeviceAddr,int DeviceEpoint, bool isDirectionReversed) + { + int bit0 = isDirectionReversed == true ? 1 : 0; + int attributeData = bit0 * 1; + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } }; + var data = new JObject { { "Undivided", 0 }, { "AttributeId", 23 }, { "AttributeDataType", 24 }, { "AttributeData", attributeData } }; + jObject.Add("Data", data); + + return jObject.ToString(); + } + + #endregion + + #region 鈻� 寮�鍚堝笜闄愪綅閰嶇疆_____________________ + + /// <summary> + /// 璁剧疆寮�鍚堝笜闄愪綅 + /// </summary> + /// <param name="rollershade"></param> + /// <param name="upLimit">寮�闄愪綅</param> + /// <param name="downLimit">鍚堥檺浣�</param> + /// <param name="curtainLength">瀵艰建闀垮害(杩欎釜鏄粰铏氭嫙璁惧鐢ㄧ殑)</param> + /// <returns></returns> + public bool SetAutoOpenCurtainLimitPoint(CommonDevice rollershade, int upLimit, int downLimit, int curtainLength) + { + //濡傛灉褰撳墠鏄櫄鎷熶綇瀹� + if (Common.Config.Instance.Home.IsVirtually == true) + { + return ModelData.DeviceModelDataLogic.Current.SetCurtainLimitPoint(rollershade, upLimit, downLimit, curtainLength, "SetWritableValue"); + } + //鑾峰彇缂栬緫寮�鍚堝笜闄愪綅鐨勫懡浠ゅ瓧绗� + var sendData = this.GetAutoOpenCurtainLimitPointCommandText(rollershade.DeviceAddr, rollershade.DeviceEpoint, upLimit, downLimit); + var result = HdlDeviceCommonLogic.Current.SendJobjectDataToGateway(rollershade, "SetWritableValue", sendData, "SetWritableValue_Respon"); + if (result.ErrorMsg != null || result.ErrorMsgDiv == 0) + { + //璁剧疆绐楀笜闄愪綅鐐瑰け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + this.ShowTipMsg(msg); + return false; + } + var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.SetWritableValueResponData>(result.ReceiptData); + if (tempData.Status != 0) + { + //璁剧疆绐楀笜闄愪綅鐐瑰け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail); + this.ShowTipMsg(msg); + return false; + } + + return true; + } + + + /// <summary> + /// 鑾峰彇缂栬緫寮�鍚堝笜闄愪綅鐨勫懡浠ゅ瓧绗� + /// </summary> + /// <param name="DeviceAddr"></param> + /// <param name="DeviceEpoint"></param> + /// <param name="upLimit"></param> + /// <param name="downLimit"></param> + /// <returns></returns> + public string GetAutoOpenCurtainLimitPointCommandText(string DeviceAddr, int DeviceEpoint, int upLimit, int downLimit) + { + //杩欎釜鏄紑鍚堝笜 "2,0x00ff,0x00ff"鏍煎紡 鍚堥檺浣嶅湪鍓嶏紝寮�闄愪綅鍦ㄥ悗 + string convertData = "\"2,0x" + Convert.ToString(downLimit, 16).PadLeft(4, '0'); + convertData += ",0x" + Convert.ToString(upLimit, 16).PadLeft(4, '0') + "\""; + //鐒跺悗灏嗗畠浠浆涓篈SK鐮佹暟鍊�,鐒跺悗鍐嶈浆涓�16杩涘埗 + //鎬昏闀垮害涓�17(杩欓噷鏄�16杩涘埗) + string sendData = "11"; + foreach (char c in convertData) + { + sendData += Convert.ToString((int)c, 16).PadLeft(2, '0'); + } + + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } }; + var data = new JObject { { "Undivided", 0 }, { "AttributeId", 24 }, { "AttributeDataType", 65 }, { "AttributeData", sendData } }; + jObject.Add("Data", data); + + return jObject.ToString(); } #endregion @@ -159,7 +286,7 @@ { sendData += Convert.ToString((int)c, 16).PadLeft(2, '0'); } - result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(rollershade, 258, 24, 65, sendData); + //result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(rollershade, 258, 24, 65, sendData); } //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); @@ -183,12 +310,6 @@ string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail); this.ShowTipMsg(msg); return false; - } - - if (upLimit != -1 && downLimit != -1) - { - //澶囦唤璁惧 - await this.BackupCurtainLimitPoint(rollershade, upLimit, downLimit); } return true; @@ -227,25 +348,6 @@ return false; } return true; - } - - /// <summary> - /// 澶囦唤绐楀笜闄愪綅鐐� - /// </summary> - /// <param name="rollershade">绐楀笜瀵硅薄</param> - /// <param name="upLimit">涓婇檺浣嶇殑鍊�,鐧惧垎姣�(澶囦唤鐢�)</param> - /// <param name="downLimit">涓嬮檺浣嶇殑鍊�,鐧惧垎姣�(澶囦唤鐢�)</param> - /// <returns></returns> - public async Task<bool> BackupCurtainLimitPoint(Rollershade rollershade, int upLimit, int downLimit) - { - //澶囦唤璁惧 - var backData = new Newtonsoft.Json.Linq.JObject - { - { "upLimit",upLimit }, - { "downLimit", downLimit } - }; - //澶囦唤璁惧 - return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜涓婁笅闄愪綅, backData); } #endregion -- Gitblit v1.8.0