| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Threading.Tasks; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | | using Shared; |
| | | using Shared.Common; |
| | | using Shared.Common.ResponseEntity; |
| | | using Shared.Phone.UserCenter; |
| | | |
| | | namespace ZigBee.Device |
| | |
| | | this.Type = DeviceType.DoorLock; |
| | | } |
| | | |
| | | #region 门锁本地变量 |
| | | /// <summary> |
| | | /// 门锁本地用户列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Dictionary<int, LocaDoorLockObj> localDoorLockUserList = new Dictionary<int, 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 static DateTime maxValue = DateTime.MaxValue; |
| | | public static DateTime minValue = DateTime.MinValue; |
| | | |
| | | /// <summary> |
| | | /// 门锁编程事件通知 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class LocaDoorLockObj |
| | | { |
| | | /// <summary> |
| | | /// 用户id |
| | | ///门锁本地录入的密码、指纹、感应卡都有唯一对应的用户Id |
| | | /// </summary> |
| | | public int UserID; |
| | | /// <summary> |
| | | /// 开锁类型 |
| | | /// 常用: |
| | | /// 0:Keypad(键盘/密码);3:RFID(射频卡);15:指纹 |
| | | ///不常用: |
| | | /// 1:RF(Zigbee无线);2:Manual(手动);255:Indeterminate(不确定) |
| | | /// </summary> |
| | | public int UnlockType; |
| | | /// <summary> |
| | | /// 关联账户的ID |
| | | /// </summary> |
| | | public string ConnectedAccount = string.Empty; |
| | | /// <summary> |
| | | /// 门锁用户名 |
| | | /// </summary> |
| | | public string UserName = string.Empty; |
| | | /// <summary> |
| | | /// 门锁录入的时 |
| | | /// </summary> |
| | | public DateTime EntryTime = System.DateTime.MinValue; |
| | | /// <summary> |
| | | /// PrimaryId 门锁云端主 键(非更新字段,以下均为更新字段) -->键名 : PrimaryId默认值: null |
| | | /// </summary> |
| | | public string PrimaryId = ""; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 与云端通讯接口 |
| | | #region 门锁服务器发送基本信息 |
| | | /// <summary> |
| | | /// 添加门锁 |
| | | /// </summary> |
| | | public class AddDoorLockData |
| | | public class BaseDoorLockServerData |
| | | { |
| | | /// <summary> |
| | | /// RequestVersion |
| | |
| | | /// <summary> |
| | | /// 住宅Id -->键名 : HomeId |
| | | /// </summary> |
| | | public string HomeId = ""; |
| | | /// <summary> |
| | | /// 云端帐号Id -->键名 : CloudAccountId |
| | | /// </summary> |
| | | public string CloudAccountId = ""; |
| | | public string HomeId = Shared.Common.Config.Instance.HomeId; |
| | | /// <summary> |
| | | /// 门锁Id -->键名 : DoorLockId |
| | | /// </summary> |
| | | public string DoorLockId = ""; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选) |
| | | /// </summary> |
| | | public int OpenLockMode = 0; |
| | | /// <summary> |
| | | /// 门锁本地用户Id -->键名 : DoorLockLocalUserId |
| | | /// </summary> |
| | | public string DoorLockLocalUserId = ""; |
| | | } |
| | | #endregion |
| | | |
| | | #region 添加门锁 |
| | | /// <summary> |
| | | /// 添加门锁 |
| | | /// </summary> |
| | | public class AddDoorLockData : BaseDoorLockServerData |
| | | { |
| | | /// <summary> |
| | | /// 云端帐号Id -->键名 : CloudAccountId |
| | | /// </summary> |
| | | public string CloudAccountId = ""; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选) |
| | | /// </summary> |
| | | public int OpenLockMode = 0; |
| | | /// <summary> |
| | | /// Data 相关内容(如:密码、指纹、IC卡 的二进制) -->键名 : Data (可选) |
| | | public byte[] Data = null; |
| | |
| | | /// <summary> |
| | | /// EntryTime 录入时间 -->键名 : EntryTime(可选) |
| | | /// </summary> |
| | | public DateTime EntryTime = System.DateTime.Now; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加门锁结果 |
| | | /// </summary> |
| | | public class AddDoorLockDataRes |
| | | { |
| | | /// <summary> |
| | | /// 响应的版本号,一般请求什么版本号,这里与之请求相同 |
| | | /// </summary> |
| | | public string ResponseVersion = string.Empty; |
| | | /// <summary> |
| | | /// 响应状态码: |
| | | ///<para>(1)Success 则[调用此接口操作成功], ResponseData则为null</para> |
| | | ///<para>(2)ParameterOrEmpty,则响应字段中[ErrorInfo] 为错误信息, ResponseData则为null</para> |
| | | ///(<para>3)NoLogin,则响应字段中[ErrorInfo] 为错误信息为[无效登录Token!]</para> |
| | | ///<para>(4)NoRecord,则响应字段中[ErrorInfo] 为错误信息为[当前提交DoorLockId值在云端不存在,请确认值是否正确!]</para> |
| | | ///<para>(5)DoorLockIdNoIsYou,则响应字段中[ErrorInfo] 为错误信息为[当前提交DoorLockId并不属于你当前帐号的,请确认值是否正确!]</para> |
| | | /// </summary> |
| | | public string StateCode = string.Empty; |
| | | } |
| | | #endregion |
| | | |
| | | #region 更新门锁 |
| | | /// <summary> |
| | | /// 更新门锁 |
| | | /// </summary> |
| | | public class RefreshDoorLockData : BaseDoorLockServerData |
| | | { |
| | | /// <summary> |
| | | /// PrimaryId 门锁云端主 键(非更新字段,以下均为更新字段) -->键名 : PrimaryId默认值: null |
| | | /// </summary> |
| | | public string PrimaryId = ""; |
| | | /// <summary> |
| | | /// 云端帐号Id -->键名 : CloudAccountId |
| | | /// </summary> |
| | | public string CloudAccountId = ""; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选) |
| | | /// </summary> |
| | | public int OpenLockMode = 0; |
| | | |
| | | /// <summary> |
| | | /// 住宅Id (可选) |
| | | /// </summary> |
| | | public byte[] Data; |
| | | /// <summary> |
| | | /// 用户Id备注 |
| | | /// </summary> |
| | | public string UserIdRemarks = ""; |
| | | /// <summary> |
| | | /// 是否为管理员门锁 |
| | | /// </summary> |
| | | public bool IsFreezeUser; |
| | | /// <summary> |
| | | /// 是否为管理员门锁 |
| | | /// </summary> |
| | | public bool IsTempUnlockAuthority; |
| | | } |
| | | #endregion |
| | | |
| | | #region 删除门锁 |
| | | /// <summary> |
| | | /// 删除门锁 |
| | | /// </summary> |
| | | public class DeleteDoorLockData : BaseDoorLockServerData |
| | | { |
| | | /// <summary> |
| | | /// PrimaryId 门锁云端主 键(非更新字段,以下均为更新字段) -->键名 : PrimaryId默认值: null |
| | | /// </summary> |
| | | public string PrimaryId = ""; |
| | | /// <summary> |
| | | /// 门锁Id -->键名 : DoorLockId (可选) |
| | | /// </summary> |
| | | public int DelDoorLockDelType; |
| | | } |
| | | #endregion |
| | | |
| | | #region 获取门锁 |
| | | /// <summary> |
| | | /// 获取门锁 |
| | | /// </summary> |
| | | public class GetDoorLockData : BaseDoorLockServerData |
| | | { |
| | | /// <summary> |
| | | /// 云端帐号Id -->键名 : CloudAccountId (可选) |
| | | /// </summary> |
| | | public string CloudAccountId = ""; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选) |
| | | /// </summary> |
| | | //public int OpenLockMode = 0; |
| | | } |
| | | |
| | | [Serializable] |
| | | public class GetDoorLockDataRes |
| | | { |
| | | public List<CloudDoorLockObj> PageData = new List<CloudDoorLockObj>(); |
| | | public int PageIndex; |
| | | public int PageSize; |
| | | public int TotalCount; |
| | | public int TotalPages; |
| | | public bool HasPreviousPage; |
| | | public bool HasNextPage; |
| | | } |
| | | [Serializable] |
| | | public class CloudDoorLockObj |
| | | { |
| | | /// <summary> |
| | | /// 门锁Id |
| | | /// </summary> |
| | | public string DoorLockId; |
| | | /// <summary> |
| | | /// 云端帐号Id |
| | | /// </summary> |
| | | public string CloudAccountId; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) |
| | | /// </summary> |
| | | public int OpenLockMode; |
| | | /// <summary> |
| | | /// 门锁本地用户Id |
| | | /// </summary> |
| | | public string DoorLockLocalUserId; |
| | | /// <summary> |
| | | /// 住宅Id |
| | | /// </summary> |
| | | public byte[] Data; |
| | | /// <summary> |
| | | /// 用户Id备注 |
| | | /// </summary> |
| | | public string UserIdRemarks; |
| | | /// <summary> |
| | | /// 是否为管理员门锁 |
| | | /// </summary> |
| | | public bool IsAdminDoorLock; |
| | | /// <summary> |
| | | /// 是否为管理员门锁 |
| | | /// </summary> |
| | | public bool IsFreezeUser; |
| | | /// <summary> |
| | | /// 是否为管理员门锁 |
| | | /// </summary> |
| | | public bool IsTempUnlockAuthority; |
| | | /// <summary> |
| | | /// 录入时间 |
| | | /// </summary> |
| | | public DateTime EntryTime; |
| | | /// <summary> |
| | | /// 最后更新时间 |
| | | /// </summary> |
| | | public string LastChangeTime; |
| | | /// <summary> |
| | | /// 【门锁云端主键】,用于【添加门锁历史】接口中的DoorLockId参数及【删除门锁】接口中的PrimaryId参数,注意不是网关中的【门锁Id |
| | | /// </summary> |
| | | public string Id; |
| | | /// <summary> |
| | | /// 创建时间 |
| | | /// </summary> |
| | | public DateTime CreatedOnUtc; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取门锁给云服务器 |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<GetDoorLockDataRes> GetDoorLockInfoFromServer(string RequestName, GetDoorLockData getDoorLockData) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<GetDoorLockDataRes>>)(async () => |
| | | { |
| | | GetDoorLockDataRes listInfo = null; |
| | | var revertObj = await SendDoorLockToServer(RequestName, getDoorLockData); |
| | | if (revertObj != null && revertObj.ResponseData != null) |
| | | { |
| | | var result = revertObj.ResponseData.ToString(); |
| | | if (result != null) |
| | | { |
| | | listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDoorLockDataRes>(result); |
| | | int i = 0; |
| | | } |
| | | } |
| | | return listInfo; |
| | | })); |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 发送门锁数据到服务器,只回复状态,没有数据处理 |
| | | /// </summary> |
| | | /// <returns>获取从接口那里取到的ResponsePack</returns> |
| | | /// <param name="RequestName">访问地址</param> |
| | | /// <param name="obj">一个类</param> |
| | | public static async Task<ResponsePack> SendDoorLockToServer(string RequestName, object obj) |
| | | { |
| | | try |
| | | { |
| | | //序列化对象 |
| | | var requestJson = JsonConvert.SerializeObject(obj); |
| | | //访问接口 |
| | | var result = await CommonPage.Instance.RequestHttpsZigbeeAsync(RequestName, System.Text.Encoding.UTF8.GetBytes(requestJson)); |
| | | |
| | | return result; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine(ex.Message); |
| | | return null; |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | 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", true, pra); |
| | | string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra); |
| | | var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Shared.Phone.UserCenter.MemberInfoRes>>(result); |
| | | return listInfo; |
| | | })); |
| | |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region 门锁本地变量 |
| | | /// <summary> |
| | | /// 门锁本地用户列表 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Dictionary<int, DoorLockProgrammingEventNotificationCommand> localDoorLockUserList = new Dictionary<int, DoorLockProgrammingEventNotificationCommand>(); |
| | | public string currentUserDisplayMethod = string.Empty; |
| | | |
| | | #endregion |
| | | |
| | | public async System.Threading.Tasks.Task GetDoorLockAllInfo() |
| | | { |
| | | FingerprintInfo fingerprint = await GetFingerprintAsync(); |
| | | var password = GetPasswordAsync(); |
| | | var proximity = GetProximityAsync(); |
| | | } |
| | | |
| | | #region 门锁操作事件通知 |
| | | /// <summary> |
| | |
| | | } |
| | | #endregion |
| | | |
| | | /* |
| | | #region 获取门锁本地log记录 |
| | | ///<summary > |
| | | ///获取门锁本地log记录 |
| | | ///<para>若命令中的PIN/RFID Code与门锁中的PIN/RFID Code相匹配,则将门锁上锁</para> |
| | | ///<para>command :门锁设备记录的索引号;取值范围:</para> |
| | | ///<para>1~“Number of Log Records Supported attribute”;</para> |
| | | ///<para>值为0表示获取设备最近的记录数据。</para> |
| | | ///</summary> |
| | | public async System.Threading.Tasks.Task<LogRecordResponAllData> LogRecordAsync(int logIndex) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | LogRecordResponAllData dataRes = 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) |
| | | { |
| | | dataRes = new LogRecordResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | dataRes = new LogRecordResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "DoorLock/DoorLockGetLogRecordResponseCommand") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<LogRecordResData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | | { |
| | | dataRes = new LogRecordResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | dataRes = new LogRecordResponAllData { logRecordResData = tempData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("DoorLock/DoorLockGetLogRecordResponseCommand_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 257 }, { "Command", 4 }, { "SendMode", 2 } }; |
| | | var data = new JObject { { "LogIndex", logIndex } }; |
| | | jObject.Add("Data", data);
|
| | | Gateway.Send("DoorLock/test", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (dataRes != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | dataRes = new LogRecordResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("DoorLock/DoorLockGetLogRecordResponseCommand_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return dataRes; |
| | | }); |
| | | } |
| | | |
| | | ///<summary > |
| | | ///获取门锁本地log记录 |
| | | /// </summary> |
| | | public class LogRecordResponAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 获取门锁本地log记录 |
| | | /// </summary> |
| | | public LogRecordResData logRecordResData; |
| | | } |
| | | |
| | | ///<summary > |
| | | ///获取门锁本地log记录 |
| | | /// </summary> |
| | | public class LogRecordResData |
| | | { |
| | | /// <summary> |
| | | /// 事件触发 |
| | | /// </summary> |
| | | public int OperationEventSoure; |
| | | /// <summary> |
| | | /// 事件 |
| | | /// </summary> |
| | | public int OperationEventCode; |
| | | /// <summary> |
| | | /// 设备当前时间的时间戳 |
| | | /// </summary> |
| | | public int ZigbeeLocalTime; |
| | | } |
| | | #endregion |
| | | */ |
| | | |
| | | /* 获取网关门锁信息,暂不支持 |
| | | #region 获取所有门锁所有用户信息 |
| | | ///<summary > |
| | | ///获取所有门锁所有用户信息 |
| | | ///</summary> |
| | | public async System.Threading.Tasks.Task<AlldoorlockUserInfoResponAllData> GetAlldoorlockUserInfoRspAsync() |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | AlldoorlockUserInfoResponAllData dataRes = 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) |
| | | { |
| | | dataRes = new AlldoorlockUserInfoResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | dataRes = new AlldoorlockUserInfoResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Doorlock/GetAlldoorlockUserInfoRsp") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<AlldoorlockUserInfoResData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | | { |
| | | dataRes = new AlldoorlockUserInfoResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | dataRes = new AlldoorlockUserInfoResponAllData { alldoorlockUserInfoResData = tempData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("门锁Doorlock/GetAlldoorlockUserInfoRsp_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 6100 } };
|
| | | Gateway.Send("DoorLock/test", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (dataRes != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | dataRes = new AlldoorlockUserInfoResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("门锁Doorlock/GetAlldoorlockUserInfoRsp_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return dataRes; |
| | | }); |
| | | } |
| | | |
| | | ///<summary > |
| | | ///获取所有门锁所有用户信息 |
| | | /// </summary> |
| | | public class AlldoorlockUserInfoResponAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 获取所有门锁所有用户信息 |
| | | /// </summary> |
| | | public AlldoorlockUserInfoResData alldoorlockUserInfoResData; |
| | | } |
| | | |
| | | ///<summary > |
| | | ///获取所有门锁所有用户信息 |
| | | /// </summary> |
| | | public class AlldoorlockUserInfoResData |
| | | { |
| | | /// <summary> |
| | | /// 事件触发 |
| | | /// </summary> |
| | | public int doorlockUserInfoRecordSum; |
| | | /// <summary> |
| | | /// 事件 |
| | | /// </summary> |
| | | public int OperationEventCode; |
| | | /// <summary> |
| | | /// 设备当前时间的时间戳 |
| | | /// </summary> |
| | | public int ZigbeeLocalTime; |
| | | } |
| | | #endregion |
| | | |
| | | #region 获取单个门锁单个用户信息 |
| | | ///<summary > |
| | | ///获取单个门锁单个用户信息 |
| | | ///<para>userId:门锁本地用户Id</para> |
| | | ///</summary> |
| | | public async System.Threading.Tasks.Task<UserInfoByMACEPUserIdResponAllData> GetdoorlockUserInfoByMACEPUserIdAsync(int userId) |
| | | { |
| | | if (Gateway == null) |
| | | { |
| | | return null; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | UserInfoByMACEPUserIdResponAllData dataRes = 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) |
| | | { |
| | | dataRes = new UserInfoByMACEPUserIdResponAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | dataRes = new UserInfoByMACEPUserIdResponAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Doorlock/GetdoorlockUserInfoByMACEPUserIdRsp") |
| | | { |
| | | var gatewayTemp = new ZbGateway() { DeviceID = jobject.Value<int>("Device_ID"), DeviceAddr = jobject.Value<string>("DeviceAddr"), DeviceEpoint = jobject.Value<int>("Epoint"), CurrentGateWayId = Gateway.getGatewayBaseInfo.gwID }; |
| | | var tempData = Newtonsoft.Json.JsonConvert.DeserializeObject<UserInfoByMACEPUserIdRspResData>(jobject["Data"].ToString()); |
| | | |
| | | if (tempData == null) |
| | | { |
| | | dataRes = new UserInfoByMACEPUserIdResponAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | dataRes = new UserInfoByMACEPUserIdResponAllData { userInfoByMACEPUserIdRspResData = tempData }; |
| | | DebugPrintLog($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("门锁Doorlock/GetdoorlockUserInfoByMACEPUserIdRsp 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", DeviceEpoint }, { "Cluster_ID", 0 }, { "Command", 6102 } }; |
| | | var data = new JObject { { "UserId", userId } }; |
| | | jObject.Add("Data", data); |
| | | Gateway.Send("DoorLock/test", jObject.ToString()); |
| | | } |
| | | catch { } |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (dataRes != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | dataRes = new UserInfoByMACEPUserIdResponAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("门锁Doorlock/GetdoorlockUserInfoByMACEPUserIdRsp 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return dataRes; |
| | | }); |
| | | } |
| | | |
| | | ///<summary > |
| | | ///获取单个门锁单个用户信息 |
| | | /// </summary> |
| | | public class UserInfoByMACEPUserIdResponAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 获取单个门锁单个用户信息 |
| | | /// </summary> |
| | | public UserInfoByMACEPUserIdRspResData userInfoByMACEPUserIdRspResData; |
| | | } |
| | | |
| | | ///<summary > |
| | | ///获取所有门锁所有用户信息 |
| | | /// </summary> |
| | | public class UserInfoByMACEPUserIdRspResData |
| | | { |
| | | /// <summary> |
| | | /// 事件触发 |
| | | /// </summary> |
| | | public int OperationEventSoure; |
| | | /// <summary> |
| | | /// 事件 |
| | | /// </summary> |
| | | public int OperationEventCode; |
| | | /// <summary> |
| | | /// 设备当前时间的时间戳 |
| | | /// </summary> |
| | | public int ZigbeeLocalTime; |
| | | } |
| | | #endregion |
| | | */ |
| | | |
| | | #region 临时密码信息 |
| | | /// <summary> |
| | | /// 临时密码本地存储对象 |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 指纹信息 |
| | | public async System.Threading.Tasks.Task<FingerprintInfo> GetFingerprintAsync() |
| | | { |
| | | FingerprintInfo result = null; |
| | | return result; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 用户指纹列表 |
| | | /// </summary> |
| | | public List<FingerprintInfo> fingerprintList = new List<FingerprintInfo>(); |
| | | |
| | | /// <summary> |
| | | /// 用户指纹列表信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class FingerprintInfo |
| | | { |
| | | /// <summary> |
| | | /// 指纹备注 |
| | | /// </summary> |
| | | public string fingerprintRemark = string.Empty; |
| | | /// <summary> |
| | | /// 指纹图片 |
| | | /// </summary> |
| | | public string fingerprintImage = string.Empty; |
| | | /// <summary> |
| | | /// 指纹ID |
| | | /// </summary> |
| | | public int userFingerprintID; |
| | | /// <summary> |
| | | /// 指纹目标列表 |
| | | /// </summary> |
| | | public readonly List<string> sceneFingerprintTargetList = new List<string>(); |
| | | } |
| | | #endregion |
| | | |
| | | #region 密码信息 |
| | | public PasswordInfo GetPasswordAsync() |
| | | { |
| | | return null; |
| | | } |
| | | /// <summary> |
| | | /// 用户密码列表 |
| | | /// </summary> |
| | | public List<PasswordInfo> passwordList = new List<PasswordInfo>(); |
| | | |
| | | /// <summary> |
| | | /// 用户密码列表信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class PasswordInfo |
| | | { |
| | | /// <summary> |
| | | /// 密码备注 |
| | | /// </summary> |
| | | public string passwordRemark = string.Empty; |
| | | /// <summary> |
| | | /// 密码图片 |
| | | /// </summary> |
| | | public string passwordImage = string.Empty; |
| | | /// <summary> |
| | | /// 密码ID |
| | | /// </summary> |
| | | public int userPasswordID; |
| | | /// <summary> |
| | | /// 密码目标列表 |
| | | /// </summary> |
| | | public readonly List<string> scenePasswordTargetList = new List<string>(); |
| | | } |
| | | #endregion |
| | | |
| | | #region 感应卡信息 |
| | | public ProximityInfo GetProximityAsync() |
| | | { |
| | | return null; |
| | | } |
| | | /// <summary> |
| | | /// 用户感应卡列表 |
| | | /// </summary> |
| | | public List<ProximityInfo> proximityList = new List<ProximityInfo>(); |
| | | |
| | | /// <summary> |
| | | /// 用户感应卡列表信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ProximityInfo |
| | | { |
| | | /// <summary> |
| | | /// 感应卡备注 |
| | | /// </summary> |
| | | public string proximityRemark = string.Empty; |
| | | /// <summary> |
| | | /// 感应卡图片 |
| | | /// </summary> |
| | | public string proximityImage = string.Empty; |
| | | /// <summary> |
| | | /// 感应卡ID |
| | | /// </summary> |
| | | public int userProximityID; |
| | | /// <summary> |
| | | /// 感应卡目标列表 |
| | | /// </summary> |
| | | public readonly List<string> sceneProximityTargetList = new List<string>(); |
| | | } |
| | | #endregion |
| | | |
| | | #region 历史记录 |
| | | /// <summary> |
| | | /// 历史记录列表 |
| | | /// </summary> |
| | | public List<HistoryRecord> historyRecordList = new List<HistoryRecord> { }; |
| | | /// <summary> |
| | | /// 门锁状态和报警信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class HistoryRecord |
| | | { |
| | | /// <summary> |
| | | /// 门锁开锁类型对应1 2 3 6 |
| | | /// </summary> |
| | | public byte type; |
| | | |
| | | /// <summary> |
| | | /// 门锁开锁用户ID |
| | | /// </summary> |
| | | public int userID; |
| | | |
| | | /// <summary> |
| | | /// 年 |
| | | /// </summary> |
| | | public string year; |
| | | |
| | | /// <summary> |
| | | /// 月 |
| | | /// </summary> |
| | | public string month; |
| | | |
| | | /// <summary> |
| | | /// 日 |
| | | /// </summary> |
| | | public string day; |
| | | |
| | | /// <summary> |
| | | /// 时 |
| | | /// </summary> |
| | | public string hour; |
| | | |
| | | /// <summary> |
| | | /// 分 |
| | | /// </summary> |
| | | public string minute; |
| | | |
| | | /// <summary> |
| | | /// 秒 |
| | | /// </summary> |
| | | public string second; |
| | | } |
| | | #endregion |
| | | |
| | | #region 私有命令 |
| | | #region 回复默认响应的控制 |
| | | |
| | | #region 用户管理控制 |
| | | ///<summary > |
| | | ///默认响应控制 |
| | | ///用户管理控制 |
| | | /// <para>passData:透传数据</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<ResponseAllData> DefaultControlAsync(string passData) |
| | | public async System.Threading.Tasks.Task<DefaultControlResponseAllData> DefaultControlAsync(string passData) |
| | | { |
| | | ResponseAllData result = null; |
| | | DefaultControlResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = "当前没有网关" }; |
| | | result = new DefaultControlResponseAllData { errorMessageBase = "当前没有网关" }; |
| | | return result; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | |
| | | |
| | | if (temp == null) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | result = new DefaultControlResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new ResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | result = new DefaultControlResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | |
| | | |
| | | if (gatewayTemp.clientDataPassthroughResponseData == null) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | result = new DefaultControlResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | {
|
| | |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | if (command == "0002") |
| | | { |
| | | var tempD = new ResponseData(); |
| | | var tempD = new DefaultControlResponseData(); |
| | | 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 }; |
| | | result = new DefaultControlResponseAllData { defaultControlResponseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0402_{ topic}"); |
| | | } |
| | | } |
| | |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | result = new DefaultControlResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | |
| | | return result; |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region 用户管理发送数据 |
| | | /// <summary> |
| | | /// 用户管理发送数据 |
| | | /// </summary> |
| | |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 用户管理发送数据回复 |
| | | /// </summary> |
| | | public DefaultControlResponseAllData defaultControlResponseAllData; |
| | | [System.Serializable] |
| | | public class DefaultControlResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 用户管理数据回复 |
| | | /// </summary> |
| | | public DefaultControlResponseData defaultControlResponseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 用户管理数据回复 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DefaultControlResponseData |
| | | { |
| | | /// <summary> |
| | | ///响应操作码(0-ffff) |
| | | /// </summary> |
| | | public int command = -1; |
| | | /// <summary> |
| | | /// 状态值 |
| | | /// <para>默认响应结果: |
| | | ///<para>0 删除成功</para> |
| | | ///<para>1 删除失败</para> |
| | | ///<para>2 用户不存在</para> |
| | | ///<para>32 冻结成功</para> |
| | | ///<para>34 冻结失败</para> |
| | | ///<para>33 解冻成功</para> |
| | | ///<para>35 解冻失败</para> |
| | | /// </summary> |
| | | public int status = -1; |
| | | } |
| | | |
| | | public enum AccessType |
| | | { |
| | | /// <summary> |
| | | /// 0x00 删除全部单次用户 |
| | | /// </summary> |
| | | DelAllUsers = 0, |
| | | /// <summary> |
| | | /// 0x01 删除指定用户(按编号) |
| | | /// </summary> |
| | | DelCurrentUser = 1, |
| | | /// <summary> |
| | | /// 0x20 冻结指定用户 |
| | | /// </summary> |
| | | DisEnable = 2, |
| | | /// <summary> |
| | | /// 0x21 解冻指定用户 |
| | | /// </summary> |
| | | Enable = 3, |
| | | } |
| | | #endregion |
| | | |
| | | #region 远程发送数据 |
| | | #region 验证门锁密码 |
| | | ///<summary > |
| | | ///验证门锁密码 |
| | | ///<para>inputPassword:输入的门锁密码</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<VerifyPasswordResponseAllData> VerifyPasswordAsync(string inputPassword) |
| | | { |
| | | VerifyPasswordResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new VerifyPasswordResponseAllData { 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 VerifyPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new VerifyPasswordResponseAllData { 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 VerifyPasswordResponseAllData { 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 == "0454") |
| | | { |
| | | var result1 = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16); |
| | | result = new VerifyPasswordResponseAllData { result = result1 }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0402_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var getPw = await GetkeyPassword(); |
| | | var passData = VerifyPasswordData(inputPassword, getPw); |
| | | 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 > WaitReceiveDataTime) |
| | | { |
| | | result = new VerifyPasswordResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 验证门锁密码 |
| | | /// </summary> |
| | | public string VerifyPasswordData(string keyPassword, int password, int fixedPassword = 0x190605) |
| | | { |
| | | string data = ""; |
| | | string dataLength = "08"; |
| | | string dataComand1 = "53"; |
| | | string dataComand2 = "04"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = "04"; |
| | | string passwordStr = ""; |
| | | try |
| | | { |
| | | int keyPasswordInt = System.Convert.ToInt32(keyPassword, 16); |
| | | var pawStr = System.Convert.ToString((keyPasswordInt ^ password) + fixedPassword, 16); |
| | | pawStr = pawStr.PadLeft(8, '0'); |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | | passwordStr += pawStr.Substring(i, 2); |
| | | } |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | passwordStr; |
| | | } |
| | | catch { }; |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 用户管理发送数据回复 |
| | | /// </summary> |
| | | public VerifyPasswordResponseAllData verifyPasswordResponseAllData; |
| | | [System.Serializable] |
| | | public class VerifyPasswordResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 用户管理数据回复 |
| | | /// <para>0:成功</para> |
| | | ///<para>1:失败</para> |
| | | /// </summary> |
| | | public int result = -1; |
| | | } |
| | | #endregion |
| | | |
| | | #region 远程开锁 |
| | | ///<summary > |
| | | ///远程开锁 |
| | | ///<para>inputPassword: 输入密码/para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<ResponseAllData> RemoteControlAsync(string inputPassword) |
| | | { |
| | | 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 |
| | | { |
| | | 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 ResponseData(); |
| | | 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 }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_command:0400_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var getPw = await GetkeyPassword(); |
| | | var passData = RemoteData(inputPassword, getPw); |
| | | 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 > WaitReceiveDataTime) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 远程发送数据 |
| | | /// </summary> |
| | | public string RemoteData(string keyPassword, string password, string fixedPassword = "190605") |
| | | string RemoteData(string keyPassword, int password, int fixedPassword = 0x190605) |
| | | { |
| | | string data = ""; |
| | | string dataLength = "09"; |
| | | string dataLength = "08"; |
| | | string dataComand1 = "62"; |
| | | string dataComand2 = "04"; |
| | | string dataSerialNum = "01"; |
| | |
| | | try |
| | | { |
| | | int keyPasswordInt = System.Convert.ToInt32(keyPassword, 16); |
| | | int passwordInt = System.Convert.ToInt32(password, 16); |
| | | var fixedPasswordInt = System.Convert.ToInt32(fixedPassword, 16); |
| | | var pawStr = System.Convert.ToString((keyPasswordInt ^ passwordInt) + fixedPasswordInt, 16); |
| | | var pawStr = System.Convert.ToString((keyPasswordInt ^ password) + fixedPassword, 16); |
| | | pawStr = pawStr.PadLeft(8, '0'); |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | | passwordStr += passwordStr.Substring(i, 2); |
| | | passwordStr += pawStr.Substring(i, 2); |
| | | } |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | passwordStr; |
| | |
| | | #endregion |
| | | |
| | | #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") |
| | | { |
| | | TempPasswordResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new TempPasswordResponseAllData { 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 TempPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new TempPasswordResponseAllData { 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 TempPasswordResponseAllData { 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 TempPasswordResponseData(); |
| | | 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 }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_command:0400_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var getPw = await GetkeyPassword(); |
| | | var passData = TempPasswordData(inputPassword, getPw, startTime, endTime); |
| | | 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 > WaitReceiveDataTime) |
| | | { |
| | | result = new TempPasswordResponseAllData |
| | | { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 临时密码发送数据 |
| | | /// </summary> |
| | | public string TempPasswordData(string keyPassword, string password, System.DateTime startTime, System.DateTime endTime, string fixedPassword = "190605") |
| | | public string TempPasswordData(string keyPassword, int password, System.DateTime startTime, System.DateTime endTime) |
| | | { |
| | | string data = ""; |
| | | string dataLength = "14";//十进制是19 |
| | | string dataLength = "10"; |
| | | string dataComand1 = "63"; |
| | | string dataComand2 = "04"; |
| | | string dataSerialNum = "01"; |
| | |
| | | try |
| | | { |
| | | int keyPasswordInt = System.Convert.ToInt32(keyPassword, 16); |
| | | int passwordInt = System.Convert.ToInt32(password, 16); |
| | | var fixedPasswordInt = System.Convert.ToInt32(fixedPassword, 16); |
| | | var pawStr = System.Convert.ToString((keyPasswordInt ^ passwordInt) + fixedPasswordInt, 16); |
| | | var pawStr = System.Convert.ToString((keyPasswordInt ^ password) + 0x190605, 16); |
| | | pawStr = pawStr.PadLeft(8, '0'); |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | |
| | | } |
| | | var startTimeStr = System.Convert.ToString(GetUnixTimeStamp(startTime, false), 16); |
| | | var endTimeStr = System.Convert.ToString(GetUnixTimeStamp(endTime, false), 16); |
| | | |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | | vaildTimeStr += startTimeStr.Substring(i, 2); |
| | |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 临时密码回复数据 |
| | | /// </summary> |
| | | public TempPasswordResponseAllData keyColorDataResponseAllData; |
| | | [System.Serializable] |
| | | public class TempPasswordResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 临时密码回复数据 |
| | | /// </summary> |
| | | public TempPasswordResponseData responseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 临时密码回复数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class TempPasswordResponseData |
| | | { |
| | | /// <summary> |
| | | ///响应操作码(0-ffff) |
| | | /// </summary> |
| | | public int command = -1; |
| | | /// <summary> |
| | | /// 状态值 |
| | | /// <para>0--注册成功</para> |
| | | /// <para>1--注册失败</para> |
| | | /// <para>2--用户已存在(重复密码)</para> |
| | | /// <para>3-- 用户已满(+已满类型回复)</para> |
| | | /// <para>4--有效时间重叠</para> |
| | | /// </summary> |
| | | public int status = -1; |
| | | } |
| | | #endregion |
| | | |
| | | #region 获取门锁密钥 |
| | |
| | | /// <para>获取加密的随机密钥,返回的密钥经过一个简单的加法加密加上0x190605,因此获取的密钥需要减上0x190605</para> |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | async System.Threading.Tasks.Task<string> GetkeyPassword() |
| | | async System.Threading.Tasks.Task<int> GetkeyPassword() |
| | | { |
| | | string passwordStr = ""; |
| | | var result = await GetKeyPassworAsync(); |
| | | //返回小端 |
| | | if (result == null || result.keyPassword == null) |
| | | { |
| | | return ""; |
| | | return 0; |
| | | } |
| | | return result.keyPassword; |
| | | |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | | passwordStr += result.keyPassword.Substring(i, 2); |
| | | } |
| | | var keyPasswordInt = System.Convert.ToInt32(passwordStr, 16); |
| | | return keyPasswordInt - 0x190605; |
| | | } |
| | | |
| | | ///<summary > |
| | | ///获取门锁密钥 |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<KeyPasswordInfo> GetKeyPassworAsync(int keyType = 0) |
| | | async System.Threading.Tasks.Task<KeyPasswordInfo> GetKeyPassworAsync(int keyType = 0) |
| | | { |
| | | KeyPasswordInfo result = null; |
| | | if (Gateway == null) |
| | |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | if (data.Length == 14) |
| | | if (data.Length == 20) |
| | | { |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | |
| | |
| | | var kType = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16); |
| | | var keyPassword = data[12].ToString() + data[13].ToString() + data[14].ToString() + data[15].ToString() + data[16].ToString() + data[17].ToString() + data[18].ToString() + data[19].ToString(); |
| | | result = new KeyPasswordInfo { keyType = kType, keyPassword = keyPassword }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_command:0406_{ topic}"); |
| | | DebugPrintLog($"UI收到通知后的主题_command:0460_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | |
| | | result = new KeyPasswordInfo { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | |
| | | ///<summary > |
| | | ///读取锁上信息 |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<DoorlockUserInfo> GetDoorlockUserInfoAsync(int keyType = 0) |
| | | public async System.Threading.Tasks.Task<DoorlockUserInfo> GetDoorlockUserInfoAsync() |
| | | { |
| | | DoorlockUserInfo result = null; |
| | | DoorLockUserDetailData doorLockUserDetailData = new DoorLockUserDetailData { }; |
| | | if (Gateway == null) |
| | | { |
| | | result = new DoorlockUserInfo { errorMessageBase = "当前没有网关" }; |
| | |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | var dateTime = DateTime.Now; |
| | | 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 DoorlockUserInfo { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new DoorlockUserInfo { 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()); |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.clientDataPassthroughResponseData == null) |
| | | if (clientDataPassthroughResponseData != null) |
| | | { |
| | | result = new DoorlockUserInfo { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | if (clientDataPassthroughResponseData.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | if (data.Length == 14) |
| | | var data = clientDataPassthroughResponseData.PassData; |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | if (command == "0452") |
| | | { |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | |
| | | if (command == "0452") |
| | | dateTime = DateTime.Now; |
| | | int returnAllLength = 2 + 2 * Convert.ToInt32(data[0].ToString() + data[1].ToString(), 16); |
| | | int usefulLength = (returnAllLength - 16); |
| | | int tempCount = 0; |
| | | var listData = new List<string>(); |
| | | while (tempCount < usefulLength) |
| | | { |
| | | //var kType = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16); |
| | | //var keyPassword = data[12].ToString() + data[13].ToString() + data[14].ToString() + data[15].ToString() + data[16].ToString() + data[17].ToString() + data[18].ToString() + data[19].ToString(); |
| | | //result = new DoorlockUserInfo { keyType = kType, keyPassword = keyPassword }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_command:0451_{ topic}"); |
| | | listData.Add(data[16 + tempCount].ToString()); |
| | | tempCount++; |
| | | } |
| | | for (int j = 0; j < listData.Count / 4; j++) |
| | | { |
| | | int curIndex = 4 * j; |
| | | var userInfo = new UserObj(); |
| | | userInfo.UserType = Convert.ToInt32(listData[curIndex + 2].ToString(), 16); |
| | | userInfo.UserId = Convert.ToInt32(listData[curIndex + 3].ToString() + listData[curIndex].ToString() + listData[curIndex + 1].ToString(), 16); |
| | | doorLockUserDetailData.UserObjList.Add(userInfo); |
| | | } |
| | | 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); |
| | | result = new DoorlockUserInfo { doorLockUserDetailData = doorLockUserDetailData }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0451_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = KeyPasswordData(keyType); |
| | | var passData = DoorlockUserData(); |
| | | var jObject = new JObject { { "DeviceAddr", DeviceAddr }, { "Epoint", 200 }, { "Cluster_ID", 64513 }, { "Command", 0 } }; |
| | | var data = new JObject { { "PassData", passData } }; |
| | | jObject.Add("Data", data); |
| | |
| | | } |
| | | catch { } |
| | | |
| | | var dateTime = DateTime.Now; |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)//WaitReceiveDataTime) |
| | | //接收一个包最多等5秒,没有收到就退出 |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 5000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (result != null) |
| | | { |
| | | break; |
| | | } |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | { |
| | | result = new DoorlockUserInfo { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | |
| | | Gateway.Actions -= action; |
| | | System.Console.WriteLine("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | |
| | | /// <summary> |
| | | /// 读取锁上信息 |
| | | /// </summary> |
| | | string DoorlockUserData(int userType) |
| | | string DoorlockUserData() |
| | | { |
| | | string data = ""; |
| | | string dataLength = "05"; |
| | |
| | | string dataComand2 = "04"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = "01"; |
| | | string keyTypeData = ""; |
| | | string keyTypeData = "01"; |
| | | |
| | | try |
| | | { |
| | | var tempTypeString = new System.Text.StringBuilder(); |
| | | var temp = Convert.ToString(userType, 16); |
| | | switch (temp.Length) |
| | | { |
| | | case 1: |
| | | keyTypeData = "0" + temp; |
| | | break; |
| | | case 2: |
| | | keyTypeData = temp; |
| | | break; |
| | | } |
| | | tempTypeString.Append(keyTypeData.ToString().ToUpper()); |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | tempTypeString; |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + keyTypeData; |
| | | } |
| | | catch { }; |
| | | |
| | |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 门锁设备返回信息 |
| | | /// </summary> |
| | | public DoorLockUserDetailData doorLockUserDetailData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 门锁设备返回信息 |
| | | /// </summary> |
| | | public class DoorLockUserDetailData |
| | | { |
| | | /// <summary> |
| | |
| | | /// 数据包序号 |
| | | /// </summary> |
| | | public int currentNum; |
| | | /// <summary> |
| | | /// 用户数据 |
| | | /// </summary> |
| | | public byte userData; |
| | | } |
| | | #endregion |
| | | |
| | | public enum AccessType |
| | | /// <summary> |
| | | /// 虚拟驱动信息 |
| | | /// </summary> |
| | | public List<UserObj> UserObjList = new List<UserObj>(); |
| | | } |
| | | |
| | | public class UserObj |
| | | { |
| | | /// <summary> |
| | | /// 0x00 删除全部单次用户 |
| | | /// 门锁用户类型 |
| | | /// </summary> |
| | | DelAllUsers = 0, |
| | | public int UserType; |
| | | |
| | | /// <summary> |
| | | /// 0x01 删除指定用户(按编号) |
| | | /// 门锁用户Id号 |
| | | /// </summary> |
| | | DelCurrentUser = 1, |
| | | /// <summary> |
| | | /// 0x20 冻结指定用户 |
| | | /// </summary> |
| | | DisEnable = 2, |
| | | /// <summary> |
| | | /// 0x21 解冻指定用户 |
| | | /// </summary> |
| | | Enable = 3, |
| | | public int UserId; |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 获取从格林威治时间到当前某一时刻的总毫秒数 |
| | |
| | | /// <param name="unixTimeStamp">时间戳</param> |
| | | /// <param name="accurateToMilliseconds">精确到毫秒,佛为秒</param> |
| | | /// <returns></returns> |
| | | public static DateTime GetLocalTime(long unixTimeStamp, bool accurateToMilliseconds) |
| | | 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(); |