From 6fa9d69da922c8049f5acfcbb9ce9fd26811024c Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 16 四月 2020 17:10:57 +0800 Subject: [PATCH] 请合并代码 --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs | 366 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 366 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs new file mode 100755 index 0000000..2f7a1b2 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs @@ -0,0 +1,366 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter +{ + /// <summary> + /// 绐楀笜鐨勯�昏緫 + /// </summary> + public class HdlDeviceCurtainLogic + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 绐楀笜鐨勯�昏緫 + /// </summary> + private static HdlDeviceCurtainLogic m_Current = null; + /// <summary> + /// 绐楀笜鐨勯�昏緫 + /// </summary> + public static HdlDeviceCurtainLogic Current + { + get + { + if (m_Current == null) + { + m_Current = new HdlDeviceCurtainLogic(); + } + return m_Current; + } + } + + #endregion + + #region 鈻� 鎵嬫媺鎺у埗___________________________ + + /// <summary> + /// 璁剧疆鎵嬫媺鎺у埗鐘舵�佸�� + /// </summary> + /// <param name="rollershade">绐楀笜瀵硅薄</param> + /// <param name="bolStatu">鎵嬫媺鎺у埗鐘舵�佸��</param> + /// <returns></returns> + public async Task<bool> SetHandPullControl(Rollershade rollershade, bool bolStatu) + { + var result = await rollershade.SetCurtianMaintenanceAsync(bolStatu); + //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 + string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); + if (error != null) + { + this.ShowTipMsg(error); + return false; + } + if (result == null || result.setWritableValueResponData == null) + { + //鍒囨崲鎵嬫媺鎺у埗澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + this.ShowTipMsg(msg); + return false; + } + if (result.setWritableValueResponData.Status != 0) + { + //鍒囨崲鎵嬫媺鎺у埗澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uChangeHandPullControlFail); + this.ShowTipMsg(msg); + return false; + } + //澶囦唤灞炴�� + await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜鎵嬫媺鎺у埗, bolStatu); + return true; + } + + #endregion + + #region 鈻� 绐楀笜鏂瑰悜閰嶇疆_______________________ + + /// <summary> + /// 閰嶇疆绐楀笜鐨勬柟鍚� + /// </summary> + /// <param name="rollershade">绐楀笜瀵硅薄</param> + /// <param name="bolStatu">false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜</param> + /// <returns></returns> + public async Task<bool> SetCurtainDirection(Rollershade rollershade, bool bolStatu) + { + var result = await rollershade.SetCurtainDirectionAsync(bolStatu); + //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 + string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); + if (error != null) + { + this.ShowTipMsg(error); + return false; + } + if (result == null || result.setWritableValueResponData == null) + { + //绐楀笜鏂瑰悜璁剧疆澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + this.ShowTipMsg(msg); + return false; + } + if (result.setWritableValueResponData.Status != 0) + { + //绐楀笜鏂瑰悜璁剧疆澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uSetCurtainDirectionFail); + this.ShowTipMsg(msg); + return false; + } + //澶囦唤璁惧 + await this.BackupCurtainDirection(rollershade, bolStatu); + + return true; + } + + /// <summary> + /// 澶囦唤绐楀笜鏂瑰悜 + /// </summary> + /// <param name="rollershade">绐楀笜瀵硅薄</param> + /// <param name="bolStatu">false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜</param> + /// <returns></returns> + public async Task<bool> BackupCurtainDirection(Rollershade rollershade, bool bolStatu) + { + //澶囦唤璁惧 + return await HdlGatewayLogic.Current.UpLoadDeviceBackupDataToGateway(rollershade, GatewayBackupEnum.A绐楀笜鏂瑰悜, bolStatu); + } + + #endregion + + #region 鈻� 绐楀笜闄愪綅閰嶇疆_______________________ + + /// <summary> + /// 鎵ц纭鍙婅鐩栫獥甯橀檺浣嶇偣 + /// </summary> + /// <param name="rollershade">绐楀笜瀵硅薄</param> + /// <param name="limiType">纭鍙婅鐩栦笂闄愪綅杩樻槸涓嬮檺浣�</param> + /// <param name="upLimit">涓婇檺浣嶇殑鍊�(闀垮害鍊�,涓嶆槸鐧惧垎姣�)</param> + /// <param name="downLimit">涓嬮檺浣嶇殑鍊�(闀垮害鍊�,涓嶆槸鐧惧垎姣�)</param> + /// <returns></returns> + public async Task<bool> CommitCurtainLimitPoint(Rollershade rollershade, Rollershade.CurtainPrivateInstalledLimi limiType, int upLimit, int downLimit) + { + CommonDevice.SetWritableValueResponAllData result = null; + if (upLimit == -1 && downLimit == -1) + { + //杩欎釜鏄嵎甯� + result = await rollershade.SetCurtainInstalledLimitAsync(limiType); + } + else + { + //杩欎釜鏄紑鍚堝笜 "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'); + } + result = await HdlDeviceAttributeLogic.Current.WriteDeviceAttribute(rollershade, 258, 24, 65, sendData); + } + //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 + string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); + if (error != null) + { + this.ShowTipMsg(error); + return false; + } + if (result == null || result.setWritableValueResponData == null) + { + //璁剧疆绐楀笜闄愪綅鐐瑰け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uCommitCurtainLimitFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + this.ShowTipMsg(msg); + return false; + } + if (result.setWritableValueResponData.Status != 0) + { + //璁剧疆绐楀笜闄愪綅鐐瑰け璐� + 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; + } + + /// <summary> + /// 鍒犻櫎闄愪綅鐐� + /// </summary> + /// <param name="rollershade">绐楀笜瀵硅薄</param> + /// <param name="limiType">鍒犻櫎涓婇檺浣嶈繕鏄垹闄や笅闄愪綅</param> + /// <returns></returns> + public async Task<bool> DeleteCurtainLimitPoint(Rollershade rollershade, Rollershade.LimiType limiType) + { + var result = await rollershade.DeleteCurtainLimitsAsync(limiType); + //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 + string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); + if (error != null) + { + this.ShowTipMsg(error); + return false; + } + if (result == null || result.setWritableValueResponData == null) + { + //閲嶇疆绐楀笜闄愪綅鐐瑰け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + this.ShowTipMsg(msg); + return false; + } + if (result.setWritableValueResponData.Status != 0) + { + //閲嶇疆绐楀笜闄愪綅鐐瑰け璐� + string msg = Language.StringByID(R.MyInternationalizationString.uDeleteCurtainLimitFail); + this.ShowTipMsg(msg); + 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 + + #region 鈻� 鑾峰彇绐楀笜闄愪綅閰嶇疆___________________ + + /// <summary> + /// 鍙戦�佽幏鍙栫獥甯橀檺浣嶉厤缃殑鍛戒护 + /// </summary> + /// <param name="rollershade">绐楀笜瀵硅薄</param> + public void SetGetCurtainLimitSettionComand(Rollershade rollershade) + { + var jObject = new Newtonsoft.Json.Linq.JObject + { + { "DeviceAddr",rollershade.DeviceAddr }, + { "Epoint", rollershade.DeviceEpoint }, + { "Cluster_ID", (int)Cluster_ID.WindowCovering }, + { "Command", 108 } + }; + var attriBute = new Newtonsoft.Json.Linq.JArray + { + new Newtonsoft.Json.Linq.JObject + { + //寮�鍚堝笜鏂瑰悜 + { "AttriButeId", (int)AttriButeId.WindowCoveringMode} + }, + new Newtonsoft.Json.Linq.JObject + { + //寮�鍚堝笜鎬婚暱 + { "AttriButeId", (int)AttriButeId.WindowCoveringLength} + }, + new Newtonsoft.Json.Linq.JObject + { + //寮�闄愪綅 + { "AttriButeId", (int)AttriButeId.InstalledOpenLimitLift} + }, + new Newtonsoft.Json.Linq.JObject + { + //鍚堥檺浣� + { "AttriButeId", (int)AttriButeId.InstalledClosedLimitLift} + } + }; + var data = new Newtonsoft.Json.Linq.JObject { { "AttriBute", attriBute } }; + jObject.Add("Data", data); + rollershade.Gateway?.Send(("GetDeviceStatus"), jObject.ToString()); + } + + #endregion + + #region 鈻� 閲嶇疆绐楀笜___________________________ + + /// <summary> + /// 閲嶇疆绐楀笜 + /// </summary> + /// <param name="rollershade">绐楀笜瀵硅薄</param> + /// <returns></returns> + public async Task<bool> RestoreCurtain(Rollershade rollershade) + { + var result = await rollershade.RestoreCurtainLimitAsync(); + //妫�娴嬬綉鍏宠繑鍥炵殑鍏遍�氶敊璇姸鎬佺爜 + string error = HdlCheckLogic.Current.CheckCommonErrorCode(result); + if (error != null) + { + this.ShowTipMsg(error); + return false; + } + if (result == null || result.setWritableValueResponData == null) + { + //閲嶇疆绐楀笜澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail); + //鎷兼帴涓娿�愮綉鍏冲洖澶嶈秴鏃躲�戠殑Msg + msg = UserCenterLogic.CombineGatewayTimeOutMsg(msg, result); + this.ShowTipMsg(msg); + return false; + } + if (result.setWritableValueResponData.Status != 0) + { + //閲嶇疆绐楀笜澶辫触 + string msg = Language.StringByID(R.MyInternationalizationString.uRestoreCurtainFail); + this.ShowTipMsg(msg); + return false; + } + return true; + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鏄剧ず閿欒淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowErrorMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Error, msg); + contr.Show(); + }); + } + + /// <summary> + /// 鏄剧ずTip淇℃伅绐楀彛 + /// </summary> + /// <param name="msg"></param> + private void ShowTipMsg(string msg) + { + Application.RunOnMainThread(() => + { + var contr = new ShowMsgControl(ShowMsgType.Tip, msg); + contr.Show(); + }); + } + + #endregion + } +} -- Gitblit v1.8.0