From b7b3e92bed9c4553e30e2901a1877f088a5f8823 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期一, 04 十一月 2019 17:20:52 +0800
Subject: [PATCH] 2019.11.4

---
 ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs |  207 ++++++++++-----------------------------------------
 1 files changed, 41 insertions(+), 166 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs
index bb3cf89..c1bc636 100755
--- a/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs
+++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs
@@ -1,6 +1,5 @@
 锘縰sing System;
 using System.Collections.Generic;
-using System.Text;
 using System.Threading.Tasks;
 using Newtonsoft.Json;
 using Newtonsoft.Json.Linq;
@@ -28,32 +27,8 @@
         public List<Shared.Phone.UserCenter.MemberInfoRes> localAllAccountList = new List<Shared.Phone.UserCenter.MemberInfoRes> { };
         public static int RemoteUnlockCount = 3;//杩滅▼寮�閿佹鏁伴檺鍒�
         public static string RemoteUnlockPassword = string.Empty;//杩滅▼寮�閿佸瘑鐮�
-        public static string LocalTempPassword = string.Empty;//鏈湴鐢熸垚鐨勪复鏃跺瘑鐮�
         public static DateTime maxValue = DateTime.MaxValue;
         public static DateTime minValue = DateTime.MinValue;
-
-
-        #region 涓存椂瀵嗙爜淇℃伅
-        /// <summary>
-        /// 涓存椂瀵嗙爜鏈湴瀛樺偍瀵硅薄
-        /// </summary>
-        public TempPasswordObj tempPasswordObj = new TempPasswordObj();
-        /// <summary>
-        /// 涓存椂瀵嗙爜鏈湴瀵硅薄
-        /// </summary>
-        [System.Serializable]
-        public class TempPasswordObj
-        {
-            /// <summary>
-            /// 闂ㄩ攣鏈夋晥鏃堕棿
-            /// </summary>
-            public int validTime;
-            /// <summary>
-            /// 闂ㄩ攣鏃堕棿
-            /// </summary>
-            public int times;
-        }
-        #endregion
 
         /// <summary>
         /// 闂ㄩ攣缂栫▼浜嬩欢閫氱煡
@@ -395,7 +370,6 @@
         }
         #endregion
 
-        #region  涓庣綉鍏抽�氳鎺ュ彛
         #region 闂ㄩ攣鎿嶄綔浜嬩欢閫氱煡
         /// <summary>
         /// 闂ㄩ攣鎿嶄綔浜嬩欢閫氱煡
@@ -697,137 +671,29 @@
         }
         #endregion
 
-        #region 鐭闂ㄩ攣鏃堕棿
+        #region 涓存椂瀵嗙爜淇℃伅
         /// <summary>
-        /// 鐭闂ㄩ攣鏃堕棿
+        /// 涓存椂瀵嗙爜鏈湴瀛樺偍瀵硅薄
         /// </summary>
-        /// <returns>The writable value async.</returns>  
-        /// <param name="timestamp">鐭闂ㄩ攣鐨勬椂闂�</param>
-        public async System.Threading.Tasks.Task<SetWritableValueResponAllData> RectifyDoorLockTimeAsync(int timestamp)
-        {
-            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 };
-                            DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_{ topic}");
-                        }
-                    }
-                };
-                Gateway.Actions += action;
-                DebugPrintLog("SetWritableValue_Actions 鍚姩" + "_" + System.DateTime.Now.ToString());
-
-                try
-                {
-                    var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 10 }, { "Command", 120 } };
-                    var data = new JObject { { "Undivided", 0 }, { "AttributeId", 0 }, { "AttributeDataType", 226 }, { "AttributeData", timestamp } };
-                    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;
-                DebugPrintLog("SetWritableValue_Actions 閫�鍑�" + System.DateTime.Now.ToString());
-
-                return d;
-            });
-        }
-
+        public TempPasswordObj tempPasswordObj = new TempPasswordObj();
         /// <summary>
-        /// 缃戝叧鐗堟湰淇℃伅,缃戝叧鍙嶉淇℃伅
-        /// </summary>
-        public SetWritableValueResponAllData setWritableValueResponAllData;
-        /// <summary>
-        /// 缃戝叧鐗堟湰淇℃伅,缃戝叧鍙嶉淇℃伅
+        /// 涓存椂瀵嗙爜鏈湴瀵硅薄
         /// </summary>
         [System.Serializable]
-        public class SetWritableValueResponAllData
+        public class TempPasswordObj
         {
             /// <summary>
-            /// 閿欒淇℃伅
+            /// 闂ㄩ攣鏈夋晥鏃堕棿
             /// </summary>
-            public string errorMessageBase;
+            public int validTime;
             /// <summary>
-            /// 缃戝叧淇℃伅閿欒鍙嶉
-            /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para>
+            /// 闂ㄩ攣鏃堕棿
             /// </summary>
-            public ErrorResponData errorResponData;
-            /// <summary>
-            /// 缃戝叧鐗堟湰淇℃伅
-            /// </summary>
-            public SetWritableValueResponData setWritableValueResponData;
-        }
-
-        /// <summary>
-        /// 璁剧疆鍙啓灞炴�х殑鍊肩殑鏁版嵁
-        /// </summary>
-        [System.Serializable]
-        public class SetWritableValueResponData
-        {
-            /// <summary>
-            /// 閰嶇疆灞炴�ф墍鍦ㄧ殑cluster
-            /// </summary>
-            public int Cluster;
-            /// <summary>
-            /// 0锛氶厤缃垚鍔燂紙鑻ラ厤缃垚鍔燂紝涓嬮潰鐨凙ttributeId瀛楁涓嶅瓨鍦級
-            ///<para>134锛氫笉鏀寔璇ュ睘鎬�</para>
-            ///<para>135锛氭棤鏁堢殑灞炴�у��</para>
-            ///<para>141锛氭棤鏁堢殑鏁版嵁绫诲瀷</para>
-            /// </summary>
-            public int Status;
-
+            public int times;
         }
         #endregion
-        #endregion
 
-        #region 涓庤澶囬�氳鎺ュ彛锛堢鏈夊懡浠わ級
+        #region 绉佹湁鍛戒护
 
         #region 鐢ㄦ埛绠$悊鎺у埗
         ///<summary >
@@ -1260,7 +1126,7 @@
                                         tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
                                         tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                         result = new ResponseAllData { responseData = tempD };
-                                        DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0400_{ topic}");
+                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0400_{ topic}");
                                     }
                                 }
                             }
@@ -1389,7 +1255,7 @@
                                         tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16);
                                         tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                         result = new TempPasswordResponseAllData { responseData = tempD };
-                                        DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0400_{ topic}");
+                                        System.Console.WriteLine($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0400_{ topic}");
                                     }
                                 }
                             }
@@ -1452,35 +1318,20 @@
                 pawStr = pawStr.PadLeft(8, '0');
                 for (int i = 6; i >= 0; i = i - 2)
                 {
-                    passwordStr += pawStr.Substring(i, 2);
+                    passwordStr += passwordStr.Substring(i, 2);
                 }
+                var startTimeStr = System.Convert.ToString(GetUnixTimeStamp(startTime, false), 16);
+                var endTimeStr = System.Convert.ToString(GetUnixTimeStamp(endTime, false), 16);
 
-                double dStartTimeStr = startTime.ToOADate();
-                Byte[] bStartTimeStr = BitConverter.GetBytes(dStartTimeStr);
-                StringBuilder sb = new StringBuilder();
-                Array.Reverse(bStartTimeStr);
-                foreach (byte b in bStartTimeStr)
-                    sb.AppendFormat("{0:x2}", b);
-                var startTimeStr = sb.ToString();
                 for (int i = 6; i >= 0; i = i - 2)
                 {
                     vaildTimeStr += startTimeStr.Substring(i, 2);
-                    //invalidTimeStr += endTimeStr.Substring(i, 2);
+                    invalidTimeStr += endTimeStr.Substring(i, 2);
                 }
-
-                //var startTimeStr = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetUnixTimeStamp(startTime);
-                //var endTimeStr = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetUnixTimeStamp(startTime);
-                //var startTimeInt = System.Convert.ToInt64(startTimeStr, 16).ToString();
-                //var endTimeInt = System.Convert.ToInt64(endTimeStr, 16).ToString();
-
-
                 data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                    passwordStr + vaildTimeStr + vaildTimeStr;
             }
-            catch (Exception ex)
-            {
-                var mess = ex.Message;
-            };
+            catch { };
 
             return data;
         }
@@ -1883,6 +1734,30 @@
         }
         #endregion
 
+        /// <summary>
+        /// 鑾峰彇浠庢牸鏋楀▉娌绘椂闂村埌褰撳墠鏌愪竴鏃跺埢鐨勬�绘绉掓暟
+        /// </summary>
+        /// <param name="dateTime">鍖椾含鏃堕棿</param>
+        /// <param name="accurateToMilliseconds">绮剧‘鍒版绉掞紝鍚﹀埌绉�</param>
+        /// <returns>杩斿洖涓�涓暱鏁存暟鏃堕棿鎴�</returns>
+        public static long GetUnixTimeStamp(DateTime dateTime, bool accurateToMilliseconds)
+        {
+            DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));//鍖椾含鎵�鍦ㄤ笢鍏尯
+            DateTime endTime = TimeZoneInfo.ConvertTimeToUtc(dateTime);
+            return (long)(accurateToMilliseconds ? (endTime - startTime).TotalMilliseconds : (endTime - startTime).TotalSeconds);
+        }
+
+        /// <summary>
+        /// 灏哢NIX鏃堕棿鎴宠浆涓哄寳浜椂闂�        
+        /// </summary>
+        /// <param name="unixTimeStamp">鏃堕棿鎴�</param>
+        /// <param name="accurateToMilliseconds">绮剧‘鍒版绉�,浣涗负绉�</param>
+        /// <returns></returns>
+        public static DateTime GetLocalTime(int unixTimeStamp, bool accurateToMilliseconds)
+        {
+            DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));//鍖椾含鎵�鍦ㄤ笢鍏尯
+            return (accurateToMilliseconds ? startTime.AddMilliseconds(unixTimeStamp) : startTime.AddSeconds(unixTimeStamp)).ToLocalTime();
+        }
         #endregion
     }
 }

--
Gitblit v1.8.0