From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期一, 14 十二月 2020 09:59:01 +0800 Subject: [PATCH] 请合并代码,完成晾衣架最终功能。 --- ZigbeeApp/Shared/Phone/ZigBee/Device/PIRSensor.cs | 406 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 406 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/PIRSensor.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/PIRSensor.cs new file mode 100755 index 0000000..d7c9124 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/PIRSensor.cs @@ -0,0 +1,406 @@ +锘縰sing System; +using System.Collections.Generic; +using Newtonsoft.Json.Linq; + +namespace ZigBee.Device +{ + public class PIRSensor: BindObj + { + public PIRSensor() + { + this.Type = DeviceType.IASZone; + } + + //#region PIR浼犳劅鍣ㄥ弬鏁伴厤缃� + /////<summary > + /////PIR浼犳劅鍣ㄥ弬鏁伴厤缃� + ///// </summary> + //public async System.Threading.Tasks.Task<ResponseAllData> SetPIRSensorParamateAsync(ConfigureParamates configureParamates) + //{ + // ResponseAllData result = null; + // if (Gateway == null) + // { + // result = new ResponseAllData { 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 ResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + // } + + // else + // { + // result = new ResponseAllData { 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 ResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + // } + // else + // { + // result = new ResponseAllData { }; + // if (clientDataPassthroughResponseData?.PassData != null) + // { + // var data = clientDataPassthroughResponseData.PassData; + // if (data.Length == 14) + // { + // result.responseData.command = int.Parse(data[10].ToString() + data[11].ToString()+ data[12].ToString() + data[13].ToString()); + // result.responseData.status = int.Parse(data[14].ToString() + data[15].ToString()); + // } + // } + // System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); + // } + // } + // }; + + // try + // { + // var passData = SetPIRSensorData(configureParamates); + // var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; + // var data = new JObject { { "PassData", passData } }; + // jObject.Add("Data", data); + // CurrentGateWayId = Gateway.getGatewayBaseInfo?.gwID; + // Gateway.Send(("ClientDataPassthrough"), Common.SecuritySet.Encryption((jObject.ToString()))); + // } + // catch { } + + // var dateTime = DateTime.Now; + // while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) + // { + // await System.Threading.Tasks.Task.Delay(10); + // if (result != null) + // { + // break; + // } + // } + // if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) + // { + // result = new ResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + // } + // Gateway.Actions -= action; + // System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + // return result; + // }); + //} + + ///// <summary> + ///// PIR閰嶇疆鍙傛暟鍥炲 + ///// </summary> + //public ParamatesInfo paramatesInfo; + //[System.Serializable] + //public class ParamatesInfo + //{ + // /// <summary> + // /// 閿欒淇℃伅 + // /// </summary> + // public string errorMessageBase; + // /// <summary> + // /// 缃戝叧淇℃伅閿欒鍙嶉 + // /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> + // /// </summary> + // public ErrorResponData errorResponData; + // /// <summary> + // /// PIR閰嶇疆鍙傛暟 + // /// </summary> + // public ConfigureParamates configureParamates ; + //} + + ///// <summary> + ///// PIR閰嶇疆鍙傛暟 + ///// </summary> + //[System.Serializable] + //public class ConfigureParamates + //{ + // /// <summary> + // ///浜害锛堝厜鐓у害锛変娇鑳� + // ///<para> false:涓嶄娇鑳�</para> + // /// <para>true:浣胯兘</para> + // /// </summary> + // public bool levelEnable; + // /// <summary> + // /// 鍏夌収搴︾瓑绾� + // /// </summary> + // public LevelSize levelSize = new LevelSize{}; + // /// <summary> + // ///浜害锛堝厜鐓у害锛変娇鑳� + // ///<para> false:涓嶄娇鑳�</para> + // /// <para>true:浣胯兘</para> + // /// </summary> + // public bool controlDevEnable; + // /// <summary> + // /// 瑙﹀彂寮�鐏埌瑙﹀彂鍏崇伅鐨勬椂闂撮棿闅旓紝锛堟敞鎰忥細璇ュ弬鏁颁负16杩涘埗锛� + // /// <para>0-ffff 鍗曚綅绉�</para> + // /// </summary> + // public int transitionTime; + + // } + + ///// <summary> + ///// 鎸夐敭鎸囩ず鐏鑹蹭俊鎭搴旈『搴忓彿 + ///// </summary> + //public enum LevelSize + //{ + // /// <summary> + // /// 鐧藉ぉ + // /// </summary> + // Daytime = 1, + // /// <summary> + // /// 鏄忔殫 + // /// </summary> + // Dusky = 2, + // /// <summary> + // /// 榛戝 + // /// </summary> + // Night = 3, + //} + + ///// <summary> + ///// 閰嶇疆PIR閰嶇疆鍙傛暟 + ///// <para>鍙戦厤缃寜閿寚绀虹伅棰滆壊鍛戒护鏃讹紝姝ゆ椂涓哄彂閫佸埌缃戝叧鐨勯�忎紶鏁版嵁</para> + ///// </summary> + //string SetPIRSensorData(ConfigureParamates configureParamates) + //{ + // string data = ""; + // string dataLength = "09"; + // string dataComand1 = "00"; + // string dataComand2 = "03"; + // string dataSerialNum = "01"; + // string addDataLength = "05"; + // string levelEnable = ""; + // string levelSize = ""; + // string controlDevEnable = ""; + // string transitionTime = ""; + // try + // { + // if (configureParamates != null) + // { + // if (configureParamates.levelEnable) + // { + // levelEnable = "00"; + // } + // else + // { + // levelEnable = "01"; + // } + // switch (configureParamates.levelSize) + // { + // case LevelSize.Daytime: + // levelSize = "01"; + // break; + // case LevelSize.Dusky: + // levelSize = "02"; + // break; + // case LevelSize.Night: + // levelSize = "03"; + // break; + // } + // if (configureParamates.controlDevEnable) + // { + // controlDevEnable = "00"; + // } + // else + // { + // controlDevEnable = "01"; + // } + + // var time = configureParamates.transitionTime.ToString(); + // var sbString = new System.Text.StringBuilder(); + // switch (time.Length) + // { + // case 1: + // transitionTime = "000"+ time; + // break; + // case 2: + // transitionTime = "00" + time; + // break; + // case 3: + // transitionTime = "0" + time; + // break; + // case 4: + // transitionTime = time; + // break; + // } + // sbString.Append(transitionTime.ToUpper()); + // } + + // data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + + // levelEnable + levelSize + controlDevEnable + transitionTime; + // } + // catch { }; + + // return data; + //} + //#endregion + + //#region 鑾峰彇PIR閰嶇疆鏁版嵁 + /////<summary > + /////PIR浼犳劅鍣ㄥ弬鏁伴厤缃� + ///// <para>reserve:0-ff</para> + ///// </summary> + //public async System.Threading.Tasks.Task<ParamatesInfo> GetPIRSensorParamateAsync(string reserve="01") + //{ + // ParamatesInfo result = null; + // if (Gateway == null) + // { + // result = new ParamatesInfo { 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 ParamatesInfo { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + // } + + // else + // { + // result = new ParamatesInfo { 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 ParamatesInfo { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + // } + // else + // { + // result = new ParamatesInfo { }; + // if (clientDataPassthroughResponseData?.PassData != null) + // { + // var data = clientDataPassthroughResponseData.PassData; + // if (data.Length == 18) + // { + // var le = data[8].ToString() + data[9].ToString(); + // if (le == "01") + // { + // result.configureParamates.levelEnable = true; + // } + // else + // { + // result.configureParamates.levelEnable = false; + // } + + // var size = data[10].ToString() + data[11].ToString(); + // switch (size) + // { + // case "01": + // result.configureParamates.levelSize = LevelSize.Daytime; + // break; + // case "02": + // result.configureParamates.levelSize = LevelSize.Dusky; + // break; + // case "03": + // result.configureParamates.levelSize = LevelSize.Night; + // break; + // } + + // var cdl = data[12].ToString() + data[13].ToString(); + // if (cdl == "01") + // { + // result.configureParamates.controlDevEnable = true; + // } + // else + // { + // result.configureParamates.controlDevEnable = false; + // } + + // result.configureParamates.transitionTime = int.Parse(data[14].ToString() + data[15].ToString() + data[16].ToString() + data[17].ToString()); + // } + // } + // System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}"); + // } + // } + // }; + + // try + // { + // var passData = GetPIRSensorData(reserve); + // var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; + // var data = new JObject { { "PassData", passData } }; + // jObject.Add("Data", data); + // CurrentGateWayId = Gateway.getGatewayBaseInfo?.gwID; + // Gateway.Send(("ClientDataPassthrough"), Common.SecuritySet.Encryption((jObject.ToString()))); + // } + // catch { } + + // var dateTime = DateTime.Now; + // while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) + // { + // await System.Threading.Tasks.Task.Delay(10); + // if (result != null) + // { + // break; + // } + // } + // if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) + // { + // result = new ParamatesInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + // } + // Gateway.Actions -= action; + // System.Console.WriteLine("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); + + // return result; + // }); + //} + + ///// <summary> + ///// 閰嶇疆PIR閰嶇疆鍙傛暟 + ///// <para>鍙戦厤缃寜閿寚绀虹伅棰滆壊鍛戒护鏃讹紝姝ゆ椂涓哄彂閫佸埌缃戝叧鐨勯�忎紶鏁版嵁</para> + ///// </summary> + //string GetPIRSensorData(string reserve) + //{ + // string data = ""; + // string dataLength = "05"; + // string dataComand1 = "01"; + // string dataComand2 = "03"; + // string dataSerialNum = "01"; + // string addDataLength = "01"; + // string reserveData = reserve; + + // try + // { + // data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + + // reserveData; + // } + // catch { }; + + // return data; + //} + //#endregion + } +} -- Gitblit v1.8.0