From 4f0ab0ad21ce450b7856d50f98322a7899361386 Mon Sep 17 00:00:00 2001
From: 黄学彪 <hxb@hdlchina.com.cn>
Date: 星期二, 22 九月 2020 10:30:01 +0800
Subject: [PATCH] 不要下载这个备份
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs | 234 +++++++++++++++++++++++++++++++++++++++++++++-------------
1 files changed, 182 insertions(+), 52 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceCurtainLogic.cs
index 9801090..a3af533 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.TemplateData;
+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);
+ //娣诲姞缂撳瓨
+ TemplateDeviceDataLogic.Current.SetCurtainHandPullControl(device, bolStatu, null);
+ 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,36 @@
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);
+ //娣诲姞缂撳瓨
+ TemplateDeviceDataLogic.Current.SetCurtainHandPullControl(device, bolStatu, result.JsonData[0]);
+
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 +114,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 +140,127 @@
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 TemplateDeviceDataLogic.Current.SetCurtainDirection(device, isDirectionReversed, null);
+ }
+ //鑾峰彇缂栬緫绐楀笜鏂瑰悜鐨勫懡浠ゅ瓧绗�
+ 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;
+ }
+
+ //娣诲姞缂撳瓨
+ TemplateDeviceDataLogic.Current.SetCurtainDirection(device, isDirectionReversed, result.JsonData[0]);
+
+ 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 TemplateData.TemplateDeviceDataLogic.Current.SetCurtainLimitPoint(rollershade, upLimit, downLimit, curtainLength, null);
+ }
+ //鑾峰彇缂栬緫寮�鍚堝笜闄愪綅鐨勫懡浠ゅ瓧绗�
+ 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;
+ }
+
+ //娣诲姞缂撳瓨
+ TemplateDeviceDataLogic.Current.SetCurtainLimitPoint(rollershade, upLimit, downLimit, curtainLength, result.JsonData[0]);
+
+ 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
@@ -136,12 +272,31 @@
/// </summary>
/// <param name="rollershade">绐楀笜瀵硅薄</param>
/// <param name="limiType">纭鍙婅鐩栦笂闄愪綅杩樻槸涓嬮檺浣�</param>
- /// <param name="upLimit">涓婇檺浣嶇殑鍊�,鐧惧垎姣�(澶囦唤鐢�)</param>
- /// <param name="downLimit">涓嬮檺浣嶇殑鍊�,鐧惧垎姣�(澶囦唤鐢�)</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)
{
- var result = await rollershade.SetCurtainInstalledLimitAsync(limiType);
+ 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)
@@ -164,12 +319,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;
@@ -208,25 +357,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