From 66a9965c44ecc32a6696abca876ab9d1cd091584 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期五, 28 二月 2020 15:25:13 +0800 Subject: [PATCH] 2020.2.28 --- ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs | 294 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 1 files changed, 256 insertions(+), 38 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs b/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs old mode 100755 new mode 100644 index 599c3a1..4379054 --- a/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs +++ b/ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs @@ -20,17 +20,31 @@ #region 闂ㄩ攣鏈湴鍙橀噺 /// <summary> - /// 闂ㄩ攣鏈湴鐢ㄦ埛鍒楄〃 + /// 鏈湴闂ㄩ攣鐢ㄦ埛鍜岃处鎴峰垪琛� + /// key:闂ㄩ攣鐢ㄦ埛ID /// </summary> /// <returns></returns> public Dictionary<int, LocaDoorLockObj> localDoorLockUserList = new Dictionary<int, LocaDoorLockObj>(); - public string currentUserDisplayMethod = string.Empty; + /// <summary> + /// 鏈湴闂ㄨ处鎴峰垪琛� + /// key:璐︽埛ID锛堜富璐︽埛鏄疓UID锛屽瓙璐︽埛鏄垎浜繃鏉ョ殑璐︽埛ID锛� + /// </summary> + /// <returns></returns> + public Dictionary<string, LocaDoorLockObj> localDoorLockAccountList = new Dictionary<string, LocaDoorLockObj>(); + + public string currentUserDisplayMethod = string.Empty;//褰撳墠鐢ㄦ埛鏄剧ず鏂瑰紡 + //鏈湴鎵�鏈夎处鎴峰垪琛� 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 string LocalTempPassword = string.Empty;//鏈湴鐢熸垚鐨勪复鏃跺瘑鐮� + public Dictionary<string, bool> IsFreezeAccount = new Dictionary<string, bool> { };//鏄惁鍐荤粨瀛愯处鎴� + public Dictionary<string, bool> HasRemoteUnlockAccess = new Dictionary<string, bool> { };//鏄惁缁欏瓙璐︽埛鎷ユ湁杩滅▼寮�閿佺殑鏉′欢 + public Dictionary<string, bool> IsFailedToGetDoorLockInfo = new Dictionary<string, bool> { };//鏄惁鑾峰彇闂ㄩ攣鏁版嵁澶辫触 + public string RemoteUnlockPassword = string.Empty;//杩滅▼寮�閿佸瘑鐮� + + public static int RemoteUnlockCount = 5;//杩滅▼寮�閿佹鏁伴檺鍒� + public static int failedCount = 3;//杩滅▼寮�閿佸け璐ユ鏁� public static DateTime maxValue = DateTime.MaxValue; public static DateTime minValue = DateTime.MinValue; - public string LocalTempPassword = string.Empty;//鏈湴鐢熸垚鐨勪复鏃跺瘑鐮� #region 涓存椂瀵嗙爜淇℃伅 /// <summary> @@ -170,10 +184,6 @@ /// </summary> public string PrimaryId = ""; /// <summary> - /// 浜戠甯愬彿Id -->閿悕 : CloudAccountId - /// </summary> - public string CloudAccountId = ""; - /// <summary> /// OpenLockMode 寮�閿佹柟寮�(瀵嗙爜銆佹寚绾广�両C鍗�) -->閿悕 : OpenLockMode (鍙��) /// </summary> public int OpenLockMode = 0; @@ -209,6 +219,7 @@ public string PrimaryId = ""; /// <summary> /// 闂ㄩ攣Id -->閿悕 : DoorLockId (鍙��) + /// DelDoorLockDelType 闂ㄩ攣鍒犻櫎绫诲瀷(0: 鏍规闂ㄩ攣涓婚敭(浜戠涓婚敭)鍒犻櫎(鍗曟潯鍒犻櫎)銆�1:鏍规闂ㄩ攣Id鎵归噺鍒犻櫎(鍑℃槸涓庨棬閿両d鐩稿悓閮戒細鍒犻櫎)銆�2锛氭牴妞愰棬閿両d鍙婇棬閿佹湰鍦扮敤鎴稩d鎵归噺鍒犻櫎(杩欎釜闂ㄩ攣Id杩欎釜闂ㄩ攣鏈湴鐢ㄦ埛Id鍧囦細琚垹闄�)) -->閿悕 : DelDoorLockDelType 榛樿鍊�: 0 /// </summary> public int DelDoorLockDelType; } @@ -481,6 +492,25 @@ /// 浜戠甯愬彿Id -->閿悕 : CloudAccountId (鍙��) /// </summary> public string CloudAccountId = ""; + /// <summary> + /// 绗嚑椤� + /// </summary> + public PageSetting pageSetting = new PageSetting(); + } + + /// <summary> + /// 鑾峰彇闂ㄩ攣 + /// </summary> + public class PageSetting + { + /// <summary> + /// 绗嚑椤� + /// </summary> + public int Page = 1; + /// <summary> + /// 绗嚑椤� + /// </summary> + public int PageSize = 10; } [Serializable] @@ -622,12 +652,12 @@ { DoorLockAccountList.Clear(); return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<List<Shared.Phone.UserCenter.MemberInfoRes>>>)(async () => - { - var pra = new Shared.Phone.UserCenter.MemberListInfoPra(); - string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra); - var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Shared.Phone.UserCenter.MemberInfoRes>>(result); - return listInfo; - })); + { + var pra = new Shared.Phone.UserCenter.MemberListInfoPra(); + string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra); + var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Shared.Phone.UserCenter.MemberInfoRes>>(result); + return listInfo; + })); } /// <summary> @@ -667,7 +697,7 @@ ///涓嶅父鐢細 /// 1:RF(Zigbee鏃犵嚎)锛�2:Manual(鎵嬪姩)锛�255:Indeterminate(涓嶇‘瀹�) /// </summary> - public int OperationEventSource; + public int OperationEventSoure; /// <summary> /// 浜嬩欢鐮� /// 甯哥敤锛� @@ -1122,7 +1152,7 @@ result = new DefaultControlResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; } else - { + { if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) { var data = gatewayTemp.clientDataPassthroughResponseData.PassData; @@ -1173,6 +1203,109 @@ return result; }); + } + + /// <summary> + /// 鐢ㄦ埛绠$悊鍙戦�佹暟鎹� + /// userIdList:涓暟涓嶈兘瓒呰繃10涓� + /// </summary> + public string FreezeAccountData(List<int> userIdList, AccessType accessType) + { + string data = ""; + string dataLength = ""; + string dataComand1 = "50"; + string dataComand2 = "04"; + string dataSerialNum = "01"; + string addDataLength = ""; + string delUserTypeStr = ""; + string userIdStr = ""; + try + { + if (userIdList.Count == 0) + { + return null; + } + if (userIdList.Count > 9) + { + return null; + } + var tempLength = 5 + userIdList.Count * 2; + string tempLength1 = Convert.ToString(tempLength, 16); + switch (tempLength1.Length) + { + case 1: + dataLength = "0" + tempLength1.ToUpper(); + break; + case 2: + dataLength = tempLength1.ToUpper(); + break; + } + + var tempAddDataLength = 1 + userIdList.Count * 2; + string tempAddDataLength1 = Convert.ToString(tempAddDataLength, 16); + switch (tempAddDataLength1.Length) + { + case 1: + addDataLength = "0" + tempAddDataLength1.ToUpper(); + break; + case 2: + addDataLength = tempAddDataLength1.ToUpper(); + break; + } + + switch ((int)accessType) + { + case 0: + delUserTypeStr = "00"; + break; + case 1: + delUserTypeStr = "01"; + break; + case 2: + delUserTypeStr = "20"; + break; + case 3: + delUserTypeStr = "21"; + break; + case 4: + delUserTypeStr = "10"; + break; + case 5: + delUserTypeStr = "30"; + break; + case 6: + delUserTypeStr = "31"; + break; + } + + var sbString = new System.Text.StringBuilder(); + foreach (var userId in userIdList) + { + string temp = Convert.ToString(userId, 16); + switch (temp.Length) + { + case 1: + userIdStr = "0" + temp + "00"; + break; + case 2: + userIdStr = temp + "00"; + break; + case 3: + var thirdBit = temp.Substring(temp.Length - 2, 1); + userIdStr = temp + "0" + thirdBit; + break; + case 4: + userIdStr = temp; + break; + } + sbString.Append(userIdStr.ToString().ToUpper()); + } + data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + + delUserTypeStr + sbString; + } + catch { }; + + return data; } /// <summary> @@ -1282,7 +1415,7 @@ public enum AccessType { /// <summary> - /// 0x00 鍒犻櫎鍏ㄩ儴鍗曟鐢ㄦ埛 + /// 0x00 鍒犻櫎鍏ㄩ儴涓存椂鐢ㄦ埛 /// </summary> DelAllUsers = 0, /// <summary> @@ -1297,6 +1430,18 @@ /// 0x21 瑙e喕鎸囧畾鐢ㄦ埛 /// </summary> Enable = 3, + /// <summary> + /// 0x10 澶氫釜鎸囧畾鐢ㄦ埛鍒犻櫎 + /// </summary> + DelMoreUsers = 4, + /// <summary> + /// 0x30 澶氫釜鎸囧畾鐢ㄦ埛鍐荤粨 + /// </summary> + DisEnableMoreUsers = 5, + /// <summary> + /// 0x31 澶氫釜鎸囧畾鐢ㄦ埛瑙e喕 + /// </summary> + EnableMoreUsers = 6, } #endregion @@ -1455,12 +1600,12 @@ ///杩滅▼寮�閿� ///<para>inputPassword: 杈撳叆瀵嗙爜/para> /// </summary> - public async System.Threading.Tasks.Task<TempPasswordResponseAllData> RemoteControlAsync(string inputPassword) + public async System.Threading.Tasks.Task<RemoteResponseAllData> RemoteControlAsync(string inputPassword) { - TempPasswordResponseAllData result = null; + RemoteResponseAllData result = null; if (Gateway == null) { - result = new TempPasswordResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" }; + result = new RemoteResponseAllData { errorMessageBase = "褰撳墠娌℃湁缃戝叧" }; return result; } return await System.Threading.Tasks.Task.Run(async () => @@ -1477,22 +1622,33 @@ if (temp == null) { - result = new TempPasswordResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; + result = new RemoteResponseAllData { errorMessageBase = "缃戝叧閿欒鍥炲锛屼笖鏁版嵁鏄┖" }; } else { - result = new TempPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; + result = new RemoteResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; } } - if (topic == gatewayID + "/" + "ZbDataPassthrough") + else if (topic == $"{gatewayID}/DoorLock/DoorLockOperatingEventNotificationCommand") + { + var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString()); + if (OperatingEventNotificationDatad != null) + { + if (OperatingEventNotificationDatad.OperationEventSoure == 1 && OperatingEventNotificationDatad.OperationEventCode == 5) + { + result = new RemoteResponseAllData { IsPawDispear = true }; + } + } + } + else 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 TempPasswordResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; + result = new RemoteResponseAllData { errorMessageBase = "缃戝叧杩斿洖鐨勬暟鎹负绌�" }; } else { @@ -1504,10 +1660,10 @@ var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); if (command == "0002") { - var tempD = new TempPasswordResponseData(); + var tempD = new RemoteResponseData(); 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); - result = new TempPasswordResponseAllData { responseData = tempD }; + result = new RemoteResponseAllData { responseData = tempD }; DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0462_{ topic}"); } } @@ -1515,7 +1671,6 @@ } } }; - Gateway.Actions += action; DebugPrintLog("ClientDataPassthrough_Actions 鍚姩" + System.DateTime.Now.ToString()); @@ -1531,18 +1686,25 @@ catch { } var dateTime = DateTime.Now; - while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime) + while ((DateTime.Now - dateTime).TotalMilliseconds < 5000)// WaitReceiveDataTime) { await System.Threading.Tasks.Task.Delay(10); - if (result != null && result.responseData != null && result.responseData.command == "0462") + if (result == null) + { + continue; + } + if (result.responseData != null && result.responseData.command == "0462") + { + break; + } + if (result.IsPawDispear == true) { break; } } if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) { - result = new TempPasswordResponseAllData - { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + result = new RemoteResponseAllData { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; } Gateway.Actions -= action; DebugPrintLog("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); @@ -1577,6 +1739,51 @@ catch { }; return data; + } + + /// <summary> + /// 杩滅▼鍥炲鏁版嵁 + /// </summary> + public RemoteResponseAllData remoteResponseAllData; + [System.Serializable] + public class RemoteResponseAllData + { + /// <summary> + /// 閿欒淇℃伅 + /// </summary> + public string errorMessageBase; + /// <summary> + /// 缃戝叧淇℃伅閿欒鍙嶉 + /// <para>褰撶綉鍏虫帴鏀跺埌瀹㈡埛绔俊鎭悗锛屽嚭鐜颁互涓嬪紓甯告儏鍐靛皢鍙嶉閿欒銆�</para> + /// </summary> + public ErrorResponData errorResponData; + /// <summary> + /// 涓存椂瀵嗙爜鍥炲鏁版嵁 + /// </summary> + public RemoteResponseData responseData; + /// <summary> + /// 鏄惁瀵嗙爜琚垹闄� + /// </summary> + public bool IsPawDispear = false; + } + + /// <summary> + /// 鐢ㄦ埛绠$悊鏁版嵁鍥炲 + /// </summary> + [System.Serializable] + public class RemoteResponseData + { + /// <summary> + ///鍝嶅簲鎿嶄綔鐮侊紙0-ffff锛� + /// </summary> + public string command = ""; + /// <summary> + /// 鐘舵�佸�� + /// <para>榛樿鍝嶅簲缁撴灉锛� + ///<para>0 鎴愬姛</para> + ///<para>1 澶辫触</para> + /// </summary> + public int status = -1; } #endregion @@ -1727,13 +1934,13 @@ /// <summary> /// 涓存椂瀵嗙爜鍥炲鏁版嵁 /// </summary> - public TempPasswordResponseAllData keyColorDataResponseAllData; + public TempPasswordResponseAllData tempPasswordResponseAllData; [System.Serializable] public class TempPasswordResponseAllData { /// <summary> /// 閿欒淇℃伅 - /// </summary> + /// </summary> public string errorMessageBase; /// <summary> /// 缃戝叧淇℃伅閿欒鍙嶉 @@ -1960,6 +2167,8 @@ public async System.Threading.Tasks.Task<DoorlockUserInfo> GetDoorlockUserInfoAsync() { DoorlockUserInfo result = null; + int totalNum = 0; + int currentNum = -1; DoorLockUserDetailData doorLockUserDetailData = new DoorLockUserDetailData { }; if (Gateway == null) { @@ -2007,6 +2216,8 @@ doorLockUserDetailData.userType = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16); doorLockUserDetailData.totalNum = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16); doorLockUserDetailData.currentNum = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16); + totalNum = doorLockUserDetailData.totalNum; + currentNum = doorLockUserDetailData.currentNum; result = new DoorlockUserInfo { doorLockUserDetailData = doorLockUserDetailData }; DebugPrintLog($"UI鏀跺埌閫氱煡鍚庣殑涓婚_command:0451_{ topic}"); } @@ -2028,12 +2239,19 @@ } catch { } - //鎺ユ敹涓�涓寘鏈�澶氱瓑5绉掞紝娌℃湁鏀跺埌灏遍��鍑� - while ((DateTime.Now - dateTime).TotalMilliseconds < 5000) + //鎺ユ敹涓�涓寘鏈�澶氱瓑3绉掞紝娌℃湁鏀跺埌灏遍��鍑�,鍗曟鏁版嵁鍖呬笉瓒呰繃30涓敤鎴� + while ((DateTime.Now - dateTime).TotalMilliseconds < 3000) { await System.Threading.Tasks.Task.Delay(100); + if (totalNum == currentNum) + { + break; + } } - + //if ((DateTime.Now - dateTime).TotalMilliseconds > 3000) + //{ + // result = new DoorlockUserInfo { errorMessageBase = " 鍥炲瓒呮椂锛岃閲嶆柊鎿嶄綔" }; + //} Gateway.Actions -= action; DebugPrintLog("ClientDataPassthrough_Actions 閫�鍑�" + System.DateTime.Now.ToString()); @@ -2124,4 +2342,4 @@ #endregion } -} +} \ No newline at end of file -- Gitblit v1.8.0