From bba578c2f0acf2eca747edcb69426771e0cadd32 Mon Sep 17 00:00:00 2001 From: WJC <wjc@hdlchina.com.cn> Date: 星期一, 23 三月 2020 18:20:50 +0800 Subject: [PATCH] 2020-03-23-3 --- ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs | 597 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 594 insertions(+), 3 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs index 0dd69e0..1fc9f8f 100755 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs @@ -1401,8 +1401,8 @@ /// <summary> /// 鐘舵�佸�� /// <para>榛樿鍝嶅簲缁撴灉锛� - ///<para>0 鍒犻櫎鎴愬姛</para> - ///<para>1 鍒犻櫎澶辫触</para> + ///<para>0 鎴愬姛</para> + ///<para>1 澶辫触</para> ///<para>2 鐢ㄦ埛涓嶅瓨鍦�</para> ///<para>32 鍐荤粨鎴愬姛</para> ///<para>34 鍐荤粨澶辫触</para> @@ -1789,7 +1789,7 @@ #region 涓存椂瀵嗙爜鍙戦�佹暟鎹� ///<summary > - ///杩滅▼寮�閿� + ///涓存椂瀵嗙爜 ///<para>inputPassword: 杈撳叆瀵嗙爜/para> /// </summary> public async System.Threading.Tasks.Task<TempPasswordResponseAllData> TempPasswordAsync(string inputPassword, System.DateTime startTime, System.DateTime endTime, string fixedPassword = "190605") @@ -2340,6 +2340,597 @@ } #endregion + #region 闊抽噺 + ///<summary > + ///鑾峰彇闊抽噺 + /// </summary> + public async System.Threading.Tasks.Task<VolumeResponseAllData> GetVolumeAsync() + { + VolumeResponseAllData result = null; + if (Gateway == null) + { + result = new VolumeResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" }; + return result; + } + return await System.Threading.Tasks.Task.Run(async () => + { + 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) + { + result = new VolumeResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + } + + else + { + result = new VolumeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; + } + } + if (topic == gatewayID + "/" + "ZbDataPassthrough") + { + var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; + gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); + + if (gatewayTemp.clientDataPassthroughResponseData == null) + { + result = new VolumeResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + } + else + { + if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) + { + var data = gatewayTemp.clientDataPassthroughResponseData.PassData; + if (data.Length == 14) + { + var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); + if (command == "0456") + { + var tempD = new VolumeResponseData(); + tempD.command = data[10].ToString() + data[11].ToString(); + tempD.value = Convert.ToInt32(data[13].ToString(), 16); + result = new VolumeResponseAllData { volumeResponseData = tempD }; + DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0456_{ topic}"); + } + } + } + } + } + }; + + Gateway.Actions += action; + DebugPrintLog("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString()); + + try + { + var passData = VolumeData(-1); + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; + var data = new JObject { { "PassData", passData } }; + jObject.Add("Data", data); + Gateway.Send(("ClientDataPassthrough"), jObject.ToString()); + } + catch { } + + var dateTime = DateTime.Now; + while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime) + { + await System.Threading.Tasks.Task.Delay(10); + if (result != null && result.volumeResponseData != null) + { + break; + } + } + if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) + { + result = new VolumeResponseAllData + { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + } + Gateway.Actions -= action; + DebugPrintLog("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + return result; + }); + } + + ///<summary > + ///闊抽噺 + ///<para>鍛戒护鍊�: comandValue</para> + ///<para>comandValue: 0 闈欓煶</para> + ///<para>comandValue:1 鏈�灏忛煶閲�</para> + ///<para>comandValue:2~13 闊抽噺 </para> + ///<para>comandValue:14 鏈�澶ч煶閲�</para> + /// </summary> + public async System.Threading.Tasks.Task<DefaultControlResponseAllData> SetVolumeAsync(int comandValue) + { + DefaultControlResponseAllData result = null; + if (Gateway == null) + { + result = new DefaultControlResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" }; + return result; + } + return await System.Threading.Tasks.Task.Run(async () => + { + 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) + { + result = new DefaultControlResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + } + + else + { + result = new DefaultControlResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; + } + } + if (topic == gatewayID + "/" + "ZbDataPassthrough") + { + var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; + gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); + + if (gatewayTemp.clientDataPassthroughResponseData == null) + { + result = new DefaultControlResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + } + else + { + if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) + { + var data = gatewayTemp.clientDataPassthroughResponseData.PassData; + if (data.Length == 16) + { + var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); + if (command == "0002") + { + var tempD = new DefaultControlResponseData(); + tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString(); + tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16); + if (tempD.command == "0455") + { + result = new DefaultControlResponseAllData { defaultControlResponseData = tempD }; + DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0456_{ topic}"); + } + } + } + } + } + } + }; + + Gateway.Actions += action; + DebugPrintLog("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString()); + + try + { + var passData = VolumeData(comandValue); + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; + var data = new JObject { { "PassData", passData } }; + jObject.Add("Data", data); + Gateway.Send(("ClientDataPassthrough"), jObject.ToString()); + } + catch { } + + var dateTime = DateTime.Now; + while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime) + { + await System.Threading.Tasks.Task.Delay(10); + if (result != null && result.defaultControlResponseData != null) + { + break; + } + } + if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) + { + result = new DefaultControlResponseAllData + { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + } + Gateway.Actions -= action; + DebugPrintLog("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + return result; + }); + } + + /// <summary> + /// 闊抽噺鍙戦�佹暟鎹� + ///<para>comandValue: 0 闈欓煶</para> + ///<para>comandValue:1 鏈�灏忛煶閲�</para> + ///<para>comandValue:2~13 闊抽噺 </para> + ///<para>comandValue:14 鏈�澶ч煶閲�</para> + /// </summary> + public string VolumeData(int comandValue) + { + string data = ""; + string dataLength = "05"; + string dataComand1 = "55"; + string dataComand2 = "04"; + string dataSerialNum = "01"; + string addDataLength = "01"; + string cValue = ""; + try + { + if (comandValue >= 1) + { + //comandValue = comandValue * 100; + //float v = (float)100 / 15; + //int vv = Convert.ToInt32(v * 100); + //var comandValueTemp = comandValue / vv; + //if (comandValueTemp == 0) + //{ + // comandValueTemp = 1; + //} + cValue = Convert.ToString(comandValue, 16).ToUpper(); + cValue = "F" + cValue; + } + else + { + switch (comandValue) + { + case -1: + cValue = "AA"; + break; + case 0: + cValue = "EB"; + break; + } + } + data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + + cValue; + } + catch (Exception ex) + { + var mess = ex.Message; + }; + return data; + } + + /// <summary> + /// 闊抽噺鍥炲鏁版嵁 + /// </summary> + public VolumeResponseAllData volumeResponseAllData; + [System.Serializable] + public class VolumeResponseAllData + { + /// <summary> + /// 閿欒淇℃伅 + /// </summary> + public string errorMessageBase; + /// <summary> + /// 缃戝叧淇℃伅閿欒鍙嶉 + /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> + /// </summary> + public ErrorResponData errorResponData; + /// <summary> + /// 闊抽噺鍥炲鏁版嵁 + /// </summary> + public VolumeResponseData volumeResponseData; + } + + /// <summary> + /// 闊抽噺鍥炲鏁版嵁 + /// </summary> + [System.Serializable] + public class VolumeResponseData + { + /// <summary> + ///鍛戒护 + ///<para>0x00 鎺ユ敹鎴愬姛</para> + ///<para>0xea 璇煶妯″紡</para> + ///<para>0xeb 闈欓煶妯″紡</para> + /// </summary> + public string command = ""; + /// <summary> + /// 闊抽噺鍊� + /// <para>0xf1~0xfe 1-14闊抽噺</para> + /// <para>0 鏃犻煶閲忓��</para> + /// </summary> + public int value = -1; + } + #endregion + + #region 甯稿紑妯″紡聽聽聽 聽聽聽聽聽 + /// <summary> + /// 璇诲彇甯稿紑妯″紡 + /// </summary> + /// <returns></returns> + public async System.Threading.Tasks.Task<OpenModeResponseAllData> ReadNormallyOpenModeFuncAsync() + { + OpenModeResponseAllData result = null; + if (Gateway == null) + { + result = new OpenModeResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" }; + return result; + } + return await System.Threading.Tasks.Task.Run(async () => + { + 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) + { + result = new OpenModeResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + } + + else + { + result = new OpenModeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; + } + } + if (topic == gatewayID + "/" + "ZbDataPassthrough") + { + var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; + gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); + + if (gatewayTemp.clientDataPassthroughResponseData == null) + { + result = new OpenModeResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + } + else + { + if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) + { + var data = gatewayTemp.clientDataPassthroughResponseData.PassData; + if (data.Length == 12) + { + var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); + if (command == "0458") + { + result = new OpenModeResponseAllData(); + result.command = data[10].ToString() + data[11].ToString(); + DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0457_{ topic}"); + } + } + } + } + } + }; + + Gateway.Actions += action; + DebugPrintLog("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString()); + + try + { + var passData = OpenModeData(SwitchMode.Obtain); + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; + var data = new JObject { { "PassData", passData } }; + jObject.Add("Data", data); + Gateway.Send(("ClientDataPassthrough"), jObject.ToString()); + } + catch { } + + var dateTime = DateTime.Now; + while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime) + { + await System.Threading.Tasks.Task.Delay(10); + if (result != null) + { + break; + } + } + if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) + { + result = new OpenModeResponseAllData + { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + } + Gateway.Actions -= action; + DebugPrintLog("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + return result; + }); + } + + /// <summary> + /// 璁剧疆甯稿紑妯″紡 + /// </summary> + /// <param name="IsNormallyOpenMode">鏄惁鎵撳紑甯稿紑妯″紡锛歵rue锛氭墦寮� false锛氬叧闂�</param> + /// <returns></returns> + public async System.Threading.Tasks.Task<DefaultControlResponseAllData> SetNormallyOpenModeFuncAsync(bool IsNormallyOpenMode) + { + DefaultControlResponseAllData result = null; + if (Gateway == null) + { + result = new DefaultControlResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" }; + return result; + } + return await System.Threading.Tasks.Task.Run(async () => + { + 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) + { + result = new DefaultControlResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + } + + else + { + result = new DefaultControlResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; + } + } + if (topic == gatewayID + "/" + "ZbDataPassthrough") + { + var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; + gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); + + if (gatewayTemp.clientDataPassthroughResponseData == null) + { + result = new DefaultControlResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + } + else + { + if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) + { + var data = gatewayTemp.clientDataPassthroughResponseData.PassData; + if (data.Length == 16) + { + var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); + if (command == "0002") + { + var tempD = new DefaultControlResponseData(); + tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString(); + tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16); + if (tempD.command == "0457") + { + result = new DefaultControlResponseAllData { defaultControlResponseData = tempD }; + DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0457_{ topic}"); + } + } + } + } + } + } + }; + + Gateway.Actions += action; + DebugPrintLog("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString()); + + try + { + var passData = ""; + if (IsNormallyOpenMode) + { + passData = OpenModeData(SwitchMode.NormallyOpen); + } + else + { + passData = OpenModeData(SwitchMode.NormallyClose); + } + var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; + var data = new JObject { { "PassData", passData } }; + jObject.Add("Data", data); + Gateway.Send(("ClientDataPassthrough"), jObject.ToString()); + } + catch { } + + var dateTime = DateTime.Now; + while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime) + { + await System.Threading.Tasks.Task.Delay(10); + if (result != null && result.defaultControlResponseData != null) + { + break; + } + } + if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) + { + result = new DefaultControlResponseAllData + { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + } + Gateway.Actions -= action; + DebugPrintLog("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + return result; + }); + } + + /// <summary> + /// 甯稿紑妯″紡聽鍙戦�佹暟鎹� + /// </summary> + public string OpenModeData(SwitchMode switchMode) + { + string data = ""; + string dataLength = "05"; + string dataComand1 = "57"; + string dataComand2 = "04"; + string dataSerialNum = "01"; + string addDataLength = "01"; + string cValue = ""; + try + { + switch (switchMode) + { + case SwitchMode.Obtain: + cValue = "10"; + break; + case SwitchMode.NormallyOpen: + cValue = "12"; + break; + case SwitchMode.NormallyClose: + cValue = "13"; + break; + } + data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + + cValue; + } + catch (Exception ex) + { + var mess = ex.Message; + }; + return data; + } + + /// <summary> + /// 甯稿紑妯″紡聽鍥炲鏁版嵁 + /// </summary> + public OpenModeResponseAllData openModeResponseAllData; + [System.Serializable] + public class OpenModeResponseAllData + { + /// <summary> + /// 閿欒淇℃伅 + /// </summary> + public string errorMessageBase; + /// <summary> + /// 缃戝叧淇℃伅閿欒鍙嶉 + /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> + /// </summary> + public ErrorResponData errorResponData; + /// <summary> + /// 0x10 甯稿紑宸插紑鍚� + /// <para>0x11 甯稿紑宸插叧闂�</para> + /// </summary> + public string command; + } + + + /// <summary> + /// 寮�鍏虫ā寮� + /// </summary> + public enum SwitchMode + { + /// <summary> + /// 0x10 鏌ヨ甯稿紑鐘舵�� + /// </summary> + Obtain = 0x10, + /// <summary> + /// 0x12 寮�鍚父寮� + /// </summary> + NormallyOpen = 0x12, + /// <summary> + /// 0x13 鍏抽棴甯稿紑 + /// </summary> + NormallyClose = 0x13 + } + #endregion + #endregion } } -- Gitblit v1.8.0