From 2be70a32d2a8c517bd9868fb60913fcc843e66fe Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期三, 13 五月 2020 11:21:32 +0800 Subject: [PATCH] 上传代码 --- ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs | 157 ++++++++++++++++++---------------------------------- 1 files changed, 55 insertions(+), 102 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs index 7c6d30a..7a88bfd 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/Rollershade.cs @@ -16,73 +16,12 @@ /// 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> /// 璇诲彇褰撳墠绐楀笜鐨勬ā寮� @@ -91,6 +30,30 @@ public 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,7 +239,7 @@ var data = new JObject { { "Value", value } }; - jObject.Add("Data", data); + jObject.Add("Data", data); Gateway?.Send("DeviceControl", jObject.ToString()); } @@ -301,8 +264,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) { @@ -316,7 +278,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) @@ -336,15 +297,15 @@ try { int attributeData = 0; - int bit0 = 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); + jObject.Add("Data", data); Gateway.Send("SetWritableValue", jObject.ToString()); } catch { } @@ -391,8 +352,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) { @@ -406,7 +366,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) @@ -425,9 +384,9 @@ try { - int attributeData = 0; - int bit2 = 0; - + int attributeData = 0; + int bit2 = 0; + if (isMotorMaintenance) { bit2 = 1; @@ -435,7 +394,7 @@ 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); + jObject.Add("Data", data); Gateway.Send("SetWritableValue", jObject.ToString()); } catch { } @@ -481,8 +440,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 +454,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 +476,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 +517,11 @@ /// <summary> /// 绐楀笜鍏ㄥ紑鎵�鍦ㄧ殑浣嶇疆(涓婇檺浣�) /// </summary> - UpLimit = 1, + UpLimit = 2, /// <summary> /// 绐楀笜鍏ㄥ叧鎵�鍦ㄧ殑浣嶇疆(涓嬮檺浣�) /// </summary> - DownLimit = 2, + DownLimit = 1, } #endregion @@ -589,8 +546,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 +560,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 +577,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 +643,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 +657,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 +679,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 +720,13 @@ /// <summary> /// 鍒犻櫎绐楀笜涓婇檺浣� /// </summary> - UpLimit = 0x02, + UpLimit = 0x08, /// <summary> /// 鍒犻櫎绐楀笜涓嬮檺浣� /// </summary> - DownLimit = 0x08, + DownLimit = 0x02, - } + } #endregion } } -- Gitblit v1.8.0