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/ZigBee/Device/Rollershade.cs | 318 +++++++---------------------------------------------
1 files changed, 47 insertions(+), 271 deletions(-)
diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs
index 7c6d30a..8b2603c 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs
@@ -16,81 +16,44 @@
/// WcdType=4锛氬紑鍚堝笜
/// WcdType=0锛氬嵎甯�
/// </summary>
- public int WcdType = 0;
-
- /// <summary>
- ///绐楀笜褰撳墠楂樺害锛屽崟浣嶏細cm.
- /// </summary>
- public int WcdCurrentPositionLift = 0;
-
+ public int WcdType = -1;
/// <summary>
/// 褰撳墠绐楀笜鎵�鍦ㄧ殑浣嶇疆(鐧惧垎姣�).
/// </summary>
+ [Newtonsoft.Json.JsonIgnore]
public int WcdCurrentPositionLiftPercentage = 0;
- //{
- // get
- // {
- // if (DeviceStatusReport.CluterID == 258)
- // {
- // var attriButeList = DeviceStatusReport.AttriBute;
- // foreach (var attriBute in attriButeList)
- // {
- // if (attriBute.AttributeId == 8)
- // {
- // return attriBute.AttriButeData;
- // }
- // }
- // }
- // return 0;
- // }
- //}
-
- /// <summary>
- /// 绐楀笜鍏ㄥ紑鎵�鍦ㄧ殑瑙掑害锛屽崟浣嶏細0.1掳
- /// </summary>
- public int WcdInstalledOpenLimitTilt = 0;
-
- /// <summary>
- /// 绐楀笜鍏ㄥ叧鎵�鍦ㄧ殑瑙掑害锛屽崟浣嶏細0.1掳
- /// </summary>
- public int WcdInstalledClosedLimitTilt = 0;
-
- /// <summary>
- /// 褰撳墠寮�鍚堝笜鐢垫満鏂瑰悜
- /// <para> (false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜锛�)</para> .
- /// </summary>
- public bool WcdCurrentDirection = false;
-
- /// <summary>
- /// 褰撳墠寮�鍚堝笜缁存姢妯″紡
- /// <para>fasle:鐢垫満杩愯浆姝e父锛泃rue:鐢垫満鍦ㄧ淮淇ā寮忎笅杩愯锛�</para>
- /// </summary>
- public bool WcdCurrentMaintenance = false;
-
- /// <summary>
- /// 褰撳墠绐楀笜寮�鍚堝笜闄愪綅寮�锛堜笂锛夐檺浣�
- /// 娉ㄦ剰杩欓噷鍊兼槸缃戝叧杩斿洖鐨勫疄闄呭�硷紝UI涓婃樉绀虹殑鍊艰瀹為檯澶勭悊
- /// </summary>
- public int WcdCurrentWcdInstalOpenLimit = 0;
-
- /// <summary>
- /// 褰撳墠寮�鍚堝笜闄愪綅鍏筹紙涓嬶級闄愪綅
- /// 娉ㄦ剰杩欓噷鍊兼槸缃戝叧杩斿洖鐨勫疄闄呭�硷紝UI涓婃樉绀虹殑鍊艰瀹為檯澶勭悊
- /// </summary>
- public int WcdCurrentInstalCloseLimit = 0;
-
- /// <summary>
- /// 褰撳墠寮�鍚堝笜鎬荤殑闀垮害
- /// </summary>
- public int WcdCurrentLength = 0;
/// <summary>
/// 璇诲彇褰撳墠绐楀笜鐨勬ā寮�
/// <para>AttriButeId=0 (鍏堣皟鐢ㄥ彂鐜板睘鎬ф帴鍙o紝鏌ョ湅璁惧鏄惁鏀寔璇ユ帴鍙g殑灞炴�э級</para>
/// </summary>
- public void ReadWcdType()
+ public new void ReadWcdType()
{
ReadAttri(Device.Cluster_ID.WindowCovering, AttriButeId.WindowCoveringType);
+ }
+
+ /// <summary>
+ /// 璇诲彇褰撳墠绐楀笜妯″紡
+ /// </summary>
+ /// <param name="commonDevice"></param>
+ /// <param name="action"></param>
+ public static void ReadWcdTypeAction(CommonDevice commonDevice, Action action)
+ {
+ new System.Threading.Thread(() =>
+ {
+ (commonDevice as Rollershade).ReadWcdType();
+ var dateTime = DateTime.Now;
+ while ((DateTime.Now - dateTime).TotalSeconds < 10)
+ {
+ System.Threading.Thread.Sleep(100);
+ if ((commonDevice as Rollershade).WcdType != -1)
+ {
+ break;
+ }
+ }
+ action?.Invoke();
+ })
+ { IsBackground = true }.Start();
}
/// <summary>
@@ -209,7 +172,7 @@
var data = new JObject {
{ "Value", value }
};
- jObject.Add("Data", data);
+ jObject.Add("Data", data);
Gateway?.Send("DeviceControl", jObject.ToString());
}
@@ -231,7 +194,7 @@
var data = new JObject {
{ "Value", value }
};
- jObject.Add("Data", data);
+ jObject.Add("Data", data);
Gateway?.Send("DeviceControl", jObject.ToString());
}
@@ -253,7 +216,7 @@
var data = new JObject {
{ "Value", value }
};
- jObject.Add("Data", data);
+ jObject.Add("Data", data);
Gateway?.Send("DeviceControl", jObject.ToString());
}
@@ -276,190 +239,9 @@
var data = new JObject {
{ "Value", value }
};
- jObject.Add("Data", data);
+ jObject.Add("Data", data);
Gateway?.Send("DeviceControl", jObject.ToString());
}
-
- #region 璁剧疆寮�鍚堝笜鐢垫満鏂瑰悜.
- /// <summary>
- /// 璁剧疆寮�鍚堝笜鐢垫満鏂瑰悜
- /// <para>isDirectionReversed (false:鐢垫満鏂瑰悜姝e悜锛泃rue:鐢垫満鏂瑰悜鍙嶅悜锛�)</para> .
- /// </summary>
- public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetCurtainDirectionAsync(bool isDirectionReversed)
- {
- if (Gateway == null)
- {
- return null;
- }
- return await System.Threading.Tasks.Task.Run(async () =>
- {
- SetWritableValueResponAllData d = null;
- Action<string, string> action = (topic, message) =>
- {
- var gatewayID = topic.Split('/')[0];
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
- if (topic == gatewayID + "/" + "Error_Respon")
- {
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
-
- if (temp == null)
- {
- d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
- }
- else
- {
- d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
- }
- }
-
- if (topic == gatewayID + "/" + "SetWritableValue_Respon")
- {
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
-
- if (tempData == null)
- {
- d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
- }
- else
- {
- d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
- System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
- }
- }
- };
- Gateway.Actions += action;
- System.Console.WriteLine("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
-
- try
- {
- int attributeData = 0;
- int bit0 = 0;
- if (isDirectionReversed)
- {
- bit0 = 1;
- }
- 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);
- Gateway.Send("SetWritableValue", jObject.ToString());
- }
- catch { }
-
- var dateTime = DateTime.Now;
- while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
- {
- await System.Threading.Tasks.Task.Delay(10);
- if (d != null)
- {
- break;
- }
- }
- if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
- {
- d = new SetWritableValueResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
- }
- Gateway.Actions -= action;
- System.Console.WriteLine("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString());
-
- return d;
- });
- }
- #endregion
-
- #region 璁剧疆寮�鍚堝笜缁存姢妯″紡
- /// <summary>
- /// 璁剧疆寮�鍚堝笜缁存姢妯″紡
- /// <para>isMotorMaintenance (fasle:鐢垫満杩愯浆姝e父锛泃rue:鐢垫満鍦ㄧ淮淇ā寮忎笅杩愯锛�)</para>
- /// </summary>
- public async System.Threading.Tasks.Task<SetWritableValueResponAllData> SetCurtianMaintenanceAsync(bool isMotorMaintenance)
- {
- if (Gateway == null)
- {
- return null;
- }
- return await System.Threading.Tasks.Task.Run(async () =>
- {
- SetWritableValueResponAllData d = null;
- Action<string, string> action = (topic, message) =>
- {
- var gatewayID = topic.Split('/')[0];
- var jobject = Newtonsoft.Json.Linq.JObject.Parse(message);
-
- if (topic == gatewayID + "/" + "Error_Respon")
- {
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
-
- if (temp == null)
- {
- d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" };
- }
- else
- {
- d = new SetWritableValueResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
- }
- }
-
- if (topic == gatewayID + "/" + "SetWritableValue_Respon")
- {
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
-
- if (tempData == null)
- {
- d = new SetWritableValueResponAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" };
- }
- else
- {
- d = new SetWritableValueResponAllData { setWritableValueResponData = tempData };
- System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
- }
- }
- };
- Gateway.Actions += action;
- System.Console.WriteLine("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
-
- try
- {
- int attributeData = 0;
- int bit2 = 0;
-
- if (isMotorMaintenance)
- {
- bit2 = 1;
- }
- 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);
- Gateway.Send("SetWritableValue", jObject.ToString());
- }
- catch { }
-
- var dateTime = DateTime.Now;
- while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
- {
- await System.Threading.Tasks.Task.Delay(10);
- if (d != null)
- {
- break;
- }
- }
- if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
- {
- d = new SetWritableValueResponAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" };
- }
- Gateway.Actions -= action;
- System.Console.WriteLine("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString());
-
- return d;
- });
- }
- #endregion
#region 璁剧疆寮�鍚堝笜闄愪綅鍙傛暟.
/// <summary>
@@ -481,8 +263,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -496,7 +277,6 @@
if (topic == gatewayID + "/" + "SetWritableValue_Respon")
{
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
if (tempData == null)
@@ -519,15 +299,15 @@
switch (installedLimit)
{
case CurtainPrivateInstalledLimi.UpLimit:
- tempLimit = 1;
+ tempLimit = 2;
break;
case CurtainPrivateInstalledLimi.DownLimit:
- tempLimit = 2;
+ tempLimit = 1;
break;
}
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
var data = new JObject { { "Undivided", 0 }, { "AttributeId", 0xea01 }, { "AttributeDataType", 32 }, { "AttributeData", tempLimit } };
- jObject.Add("Data", data);
+ jObject.Add("Data", data);
Gateway.Send("SetWritableValue", jObject.ToString());
}
catch { }
@@ -560,11 +340,11 @@
/// <summary>
/// 绐楀笜鍏ㄥ紑鎵�鍦ㄧ殑浣嶇疆(涓婇檺浣�)
/// </summary>
- UpLimit = 1,
+ UpLimit = 2,
/// <summary>
/// 绐楀笜鍏ㄥ叧鎵�鍦ㄧ殑浣嶇疆(涓嬮檺浣�)
/// </summary>
- DownLimit = 2,
+ DownLimit = 1,
}
#endregion
@@ -589,8 +369,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -604,7 +383,6 @@
if (topic == gatewayID + "/" + "SetWritableValue_Respon")
{
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
if (tempData == null)
@@ -622,11 +400,11 @@
System.Console.WriteLine("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
try
- {
-
+ {
+
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
var data = new JObject { { "Undivided", 0 }, { "AttributeId", 0xea02 }, { "AttributeDataType", 32 }, { "AttributeData", 1 } };
- jObject.Add("Data", data);
+ jObject.Add("Data", data);
Gateway.Send("SetWritableValue", jObject.ToString());
}
catch { }
@@ -688,8 +466,7 @@
if (topic == gatewayID + "/" + "Error_Respon")
{
- var gatewayTemp = new ZbGateway() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
- var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ZbGateway.ErrorResponData>(jobject["Data"].ToString());
+ var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString());
if (temp == null)
{
@@ -703,7 +480,6 @@
if (topic == gatewayID + "/" + "SetWritableValue_Respon")
{
- var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), DataID = jobject.Value<int>("Data_ID"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID };
var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<SetWritableValueResponData>(jobject["Data"].ToString());
if (tempData == null)
@@ -726,10 +502,10 @@
switch (limiType)
{
case LimiType.DownLimit:
- tempLimit = 8;
+ tempLimit = 2;
break;
case LimiType.UpLimit:
- tempLimit = 2;
+ tempLimit = 8;
break;
}
var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 258 }, { "Command", 120 } };
@@ -767,13 +543,13 @@
/// <summary>
/// 鍒犻櫎绐楀笜涓婇檺浣�
/// </summary>
- UpLimit = 0x02,
+ UpLimit = 0x08,
/// <summary>
/// 鍒犻櫎绐楀笜涓嬮檺浣�
/// </summary>
- DownLimit = 0x08,
+ DownLimit = 0x02,
- }
+ }
#endregion
}
}
--
Gitblit v1.8.0