From 52005ed57f3f7bc796fdd1a878e4f298a126f1e8 Mon Sep 17 00:00:00 2001
From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local>
Date: 星期二, 29 十月 2019 16:48:47 +0800
Subject: [PATCH] 2019.10.29-3
---
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