| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using Newtonsoft.Json; |
| | | using Newtonsoft.Json.Linq; |
| | |
| | | |
| | | namespace ZigBee.Device |
| | | { |
| | | public class DoorLock : CommonDevice |
| | | public class DoorLock : Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo |
| | | { |
| | | public DoorLock() |
| | | { |
| | |
| | | |
| | | #region 门锁本地变量 |
| | | /// <summary> |
| | | /// 门锁本地用户列表 |
| | | /// 本地门锁用户和账户列表 |
| | | /// key:门锁用户ID |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Dictionary<int, LocaDoorLockObj> localDoorLockUserList = new Dictionary<int, LocaDoorLockObj>(); |
| | | public string currentUserDisplayMethod = string.Empty; |
| | | /// <summary> |
| | | /// 本地门账户列表 |
| | | /// key:账户ID(主账户是GUID,子账户是分享过来的账户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 static DateTime maxValue = DateTime.MaxValue; |
| | | public static DateTime minValue = DateTime.MinValue; |
| | | |
| | | /// <summary> |
| | | /// 门锁编程事件通知 |
| | | /// 是否常开模式 |
| | | /// ture:常开; false:关闭 |
| | | /// </summary> |
| | | public bool IsDoorLockNormallyMode = false; |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | 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> { };//是否获取门锁数据失败 |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public string RemoteUnlockPassword = string.Empty;//远程开锁密码 |
| | | |
| | | public static int RemoteUnlockCount = 5;//远程开锁次数限制 |
| | | public static int failedCount = 3;//远程开锁失败次数 |
| | | public static DateTime minValue = DateTime.MinValue; |
| | | |
| | | #region 临时密码信息 |
| | | /// <summary> |
| | | /// 用户管理发送数据回复 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public TempPasswordObject tempPasswordObject; |
| | | /// <summary> |
| | | /// 临时密码本地对象 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class LocaDoorLockObj |
| | | public class TempPasswordObject |
| | | { |
| | | /// <summary> |
| | | /// 用户id |
| | | ///门锁本地录入的密码、指纹、感应卡都有唯一对应的用户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; |
| | | public int UserId; |
| | | /// <summary> |
| | | /// PrimaryId 门锁云端主 键(非更新字段,以下均为更新字段) -->键名 : PrimaryId默认值: null |
| | | /// </summary> |
| | | public string PrimaryId = ""; |
| | | //public string PrimaryId; |
| | | /// <summary> |
| | | /// 6位有动态临时密码 |
| | | /// </summary> |
| | | public string TempPassword; |
| | | /// <summary> |
| | | /// 门锁有效时间 |
| | | /// </summary> |
| | | public DateTime ValidTime; |
| | | /// <summary> |
| | | /// 门锁失效时间 |
| | | /// </summary> |
| | | public DateTime InValidTime; |
| | | } |
| | | #endregion |
| | | |
| | | #endregion |
| | | |
| | |
| | | /// 门锁本地用户Id -->键名 : DoorLockLocalUserId |
| | | /// </summary> |
| | | public string DoorLockLocalUserId = ""; |
| | | |
| | | /// <summary> |
| | | /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl |
| | | /// </summary> |
| | | public bool IsOtherAccountCtrl = false; |
| | | } |
| | | #endregion |
| | | |
| | |
| | | /// </summary> |
| | | public string PrimaryId = ""; |
| | | /// <summary> |
| | | /// 云端帐号Id -->键名 : CloudAccountId |
| | | /// </summary> |
| | | public string CloudAccountId = ""; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选) |
| | | /// </summary> |
| | | public int OpenLockMode = 0; |
| | |
| | | public string PrimaryId = ""; |
| | | /// <summary> |
| | | /// 门锁Id -->键名 : DoorLockId (可选) |
| | | /// DelDoorLockDelType 门锁删除类型(0: 根椐门锁主键(云端主键)删除(单条删除)、1:根椐门锁Id批量删除(凡是与门锁Id相同都会删除)、2:根椐门锁Id及门锁本地用户Id批量删除(这个门锁Id这个门锁本地用户Id均会被删除)) -->键名 : DelDoorLockDelType 默认值: 0 |
| | | /// </summary> |
| | | public int DelDoorLockDelType; |
| | | } |
| | | #endregion |
| | | |
| | | #region 添加门锁临时密码 |
| | | /// <summary> |
| | | /// 添加门锁 |
| | | /// </summary> |
| | | public class AddDoorLockTempPasswordData |
| | | { |
| | | /// <summary> |
| | | /// RequestVersion |
| | | /// </summary> |
| | | public string RequestVersion = Shared.Common.CommonPage.RequestVersion; |
| | | /// <summary> |
| | | /// LoginAccessToken |
| | | /// </summary> |
| | | public string LoginAccessToken = Shared.Common.Config.Instance.Token; |
| | | /// <summary> |
| | | /// 住宅Id -->键名 : HomeId |
| | | /// </summary> |
| | | public string HomeId = Shared.Common.Config.Instance.HomeId; |
| | | /// <summary> |
| | | /// 门锁Id -->键名 : DoorLockId |
| | | /// </summary> |
| | | public string LocalDoorLockId = ""; |
| | | /// <summary> |
| | | /// 临时密码Id -->键名 : TempPwdId |
| | | /// </summary> |
| | | public string TempPwdId = ""; |
| | | /// <summary> |
| | | /// 临时密码 -->键名 : TempPwd |
| | | /// </summary> |
| | | public string TempPwd = ""; |
| | | /// <summary> |
| | | /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime 默认值: 0001/1/1 |
| | | /// </summary> |
| | | public DateTime ValidBeginTime; |
| | | /// <summary> |
| | | /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime |
| | | /// </summary> |
| | | public DateTime ValidEndTime; |
| | | /// <summary> |
| | | /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl |
| | | /// </summary> |
| | | public bool IsOtherAccountCtrl = false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加门锁结果 |
| | | /// </summary> |
| | | public class AddDoorLockTempPasswordDataRes : AddDoorLockDataRes |
| | | { |
| | | } |
| | | #endregion |
| | | |
| | | #region 删除门锁临时密码 |
| | | /// <summary> |
| | | /// 删除门锁 |
| | | /// </summary> |
| | | public class DelDoorLockTempPasswordData |
| | | { |
| | | /// <summary> |
| | | /// RequestVersion |
| | | /// </summary> |
| | | public string RequestVersion = Shared.Common.CommonPage.RequestVersion; |
| | | /// <summary> |
| | | /// LoginAccessToken |
| | | /// </summary> |
| | | public string LoginAccessToken = Shared.Common.Config.Instance.Token; |
| | | /// <summary> |
| | | /// 住宅Id -->键名 : HomeId |
| | | /// </summary> |
| | | public string HomeId = Shared.Common.Config.Instance.HomeId; |
| | | /// <summary> |
| | | /// LocalDoorLockId 搜索本地门锁Id -->键名 : LocalDoorLockId 默认值: null |
| | | /// </summary> |
| | | public string LocalDoorLockId = ""; |
| | | /// <summary> |
| | | /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl |
| | | /// </summary> |
| | | public bool IsOtherAccountCtrl = false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除门锁结果 |
| | | /// </summary> |
| | | public class DelDoorLockTempPasswordDataRes : AddDoorLockDataRes |
| | | { |
| | | } |
| | | #endregion |
| | | |
| | | #region 更新门锁临时密码 |
| | | /// <summary> |
| | | /// 更新门锁 |
| | | /// </summary> |
| | | public class ModifyDoorLockTempPasswordData |
| | | { |
| | | /// <summary> |
| | | /// RequestVersion |
| | | /// </summary> |
| | | public string RequestVersion = Shared.Common.CommonPage.RequestVersion; |
| | | /// <summary> |
| | | /// LoginAccessToken |
| | | /// </summary> |
| | | public string LoginAccessToken = Shared.Common.Config.Instance.Token; |
| | | /// <summary> |
| | | /// 住宅Id -->键名 : HomeId |
| | | /// </summary> |
| | | public string HomeId = Shared.Common.Config.Instance.HomeId; |
| | | /// <summary> |
| | | /// 门锁密码主键(获取门锁密码分页中的Id) -->键名 : DoorLockPwdId |
| | | /// </summary> |
| | | public string DoorLockPwdId = ""; |
| | | /// <summary> |
| | | /// 门锁Id -->键名 : DoorLockId |
| | | /// </summary> |
| | | public string LocalDoorLockId = ""; |
| | | /// <summary> |
| | | /// 临时密码Id -->键名 : TempPwdId |
| | | /// </summary> |
| | | public string TempPwdId = ""; |
| | | /// <summary> |
| | | /// 临时密码 -->键名 : TempPwd |
| | | /// </summary> |
| | | public string TempPwd = ""; |
| | | /// <summary> |
| | | /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime 默认值: 0001/1/1 |
| | | /// </summary> |
| | | public DateTime ValidBeginTime; |
| | | /// <summary> |
| | | /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime |
| | | /// </summary> |
| | | public DateTime ValidEndTime; |
| | | /// <summary> |
| | | /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl |
| | | /// </summary> |
| | | public bool IsOtherAccountCtrl = false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加门锁结果 |
| | | /// </summary> |
| | | public class ModigDoorLockTempPasswordDataRes : AddDoorLockDataRes |
| | | { |
| | | } |
| | | #endregion |
| | | |
| | | #region 获取门锁临时密码 |
| | | /// <summary> |
| | | /// 获取门锁 |
| | | /// </summary> |
| | | public class GetDoorLockTempPasswordData |
| | | { |
| | | /// <summary> |
| | | /// RequestVersion |
| | | /// </summary> |
| | | public string RequestVersion = Shared.Common.CommonPage.RequestVersion; |
| | | /// <summary> |
| | | /// LoginAccessToken |
| | | /// </summary> |
| | | public string LoginAccessToken = Shared.Common.Config.Instance.Token; |
| | | /// <summary> |
| | | /// 住宅Id -->键名 : HomeId |
| | | /// </summary> |
| | | public string HomeId = Shared.Common.Config.Instance.HomeId; |
| | | /// <summary> |
| | | /// 门锁Id -->键名 : DoorLockId |
| | | /// </summary> |
| | | public string LocalDoorLockId = ""; |
| | | /// <summary> |
| | | /// 临时密码Id -->键名 : TempPwdId |
| | | /// </summary> |
| | | public string TempPwdId = ""; |
| | | /// <summary> |
| | | /// 临时密码 -->键名 : TempPwd |
| | | /// </summary> |
| | | public string TempPwd = ""; |
| | | /// <summary> |
| | | /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime 默认值: 0001/1/1 |
| | | /// </summary> |
| | | public DateTime? ValidBeginTime; |
| | | /// <summary> |
| | | /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime |
| | | /// </summary> |
| | | public DateTime? ValidEndTime; |
| | | /// <summary> |
| | | /// IsOtherAccountCtrl 是否为子帐号控制过来 -->键名 : IsOtherAccountCtrl |
| | | /// </summary> |
| | | public bool IsOtherAccountCtrl = false; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取门锁临时密码结果 |
| | | /// </summary> |
| | | [Serializable] |
| | | public class GetDoorLockTempPasswordDataRes |
| | | { |
| | | public List<CloudDoorLockTempPasswordObj> PageData = new List<CloudDoorLockTempPasswordObj>(); |
| | | public int PageIndex; |
| | | public int PageSize; |
| | | public int TotalCount; |
| | | public int TotalPages; |
| | | public bool HasPreviousPage; |
| | | public bool HasNextPage; |
| | | } |
| | | [Serializable] |
| | | public class CloudDoorLockTempPasswordObj |
| | | { |
| | | /// <summary> |
| | | /// 门锁Id -->键名 : DoorLockId |
| | | /// </summary> |
| | | public string LocalDoorLockId = ""; |
| | | /// <summary> |
| | | /// 临时密码Id -->键名 : TempPwdId |
| | | /// </summary> |
| | | public string TempPwdId = ""; |
| | | /// <summary> |
| | | /// 临时密码 -->键名 : TempPwd |
| | | /// </summary> |
| | | public string TempPwd = ""; |
| | | /// <summary> |
| | | /// 0:00:00] ValidBeginTime 有效开始时间 -->键名 : ValidBeginTime 默认值: 0001/1/1 |
| | | /// </summary> |
| | | public DateTime ValidBeginTime; |
| | | /// <summary> |
| | | /// 0:00:00] ValidEndTime 有效结束时间 -->键名 : ValidEndTime |
| | | /// </summary> |
| | | public DateTime ValidEndTime; |
| | | /// <summary> |
| | | /// 【门锁云端主键】,用于【添加门锁历史】接口中的DoorLockId参数及【删除门锁】接口中的PrimaryId参数,注意不是网关中的【门锁Id |
| | | /// </summary> |
| | | public string Id; |
| | | /// <summary> |
| | | /// 创建时间 |
| | | /// </summary> |
| | | public DateTime CreatedOnUtc; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 从云服务器中获取门锁临时密码 |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<GetDoorLockTempPasswordDataRes> GetDoorLockTempPasswordFromServer(string RequestName, GetDoorLockTempPasswordData getDoorLockTempPasswordData) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<GetDoorLockTempPasswordDataRes>>)(async () => |
| | | { |
| | | GetDoorLockTempPasswordDataRes listInfo = null; |
| | | var revertObj = await SendDoorLockToServer(RequestName, getDoorLockTempPasswordData); |
| | | if (revertObj != null && revertObj.ResponseData != null) |
| | | { |
| | | var result = revertObj.ResponseData.ToString(); |
| | | if (result != null) |
| | | { |
| | | listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDoorLockTempPasswordDataRes>(result); |
| | | } |
| | | } |
| | | return listInfo; |
| | | })); |
| | | } |
| | | #endregion |
| | | |
| | |
| | | /// </summary> |
| | | public string CloudAccountId = ""; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选) |
| | | /// 第几页 |
| | | /// </summary> |
| | | //public int OpenLockMode = 0; |
| | | public PageSetting pageSetting = new PageSetting(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取门锁 |
| | | /// </summary> |
| | | public class PageSetting |
| | | { |
| | | /// <summary> |
| | | /// 第几页 |
| | | /// </summary> |
| | | public int Page = 1; |
| | | /// <summary> |
| | | /// 第几页 |
| | | /// </summary> |
| | | public int PageSize = 10; |
| | | } |
| | | |
| | | [Serializable] |
| | |
| | | public class CloudDoorLockObj |
| | | { |
| | | /// <summary> |
| | | /// 门锁Id |
| | | /// 门锁Id |
| | | /// </summary> |
| | | public string DoorLockId; |
| | | /// <summary> |
| | | /// 云端帐号Id |
| | | /// 云端帐号Id |
| | | /// </summary> |
| | | public string CloudAccountId; |
| | | /// <summary> |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) |
| | | /// OpenLockMode 开锁方式(密码、指纹、IC卡) |
| | | /// </summary> |
| | | public int OpenLockMode; |
| | | /// <summary> |
| | | /// 门锁本地用户Id |
| | | /// 门锁本地用户Id |
| | | /// </summary> |
| | | public string DoorLockLocalUserId; |
| | | /// <summary> |
| | | /// 住宅Id |
| | | /// 住宅Id |
| | | /// </summary> |
| | | public byte[] Data; |
| | | /// <summary> |
| | |
| | | /// </summary> |
| | | public bool IsTempUnlockAuthority; |
| | | /// <summary> |
| | | /// 录入时间 |
| | | /// 录入时间 |
| | | /// </summary> |
| | | public DateTime EntryTime; |
| | | /// <summary> |
| | | /// 最后更新时间 |
| | | /// 最后更新时间 |
| | | /// </summary> |
| | | public string LastChangeTime; |
| | | /// <summary> |
| | |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取门锁给云服务器 |
| | | /// </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 () => |
| | |
| | | if (result != null) |
| | | { |
| | | listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetDoorLockDataRes>(result); |
| | | int i = 0; |
| | | } |
| | | } |
| | | return listInfo; |
| | |
| | | { |
| | | //序列化对象 |
| | | var requestJson = JsonConvert.SerializeObject(obj); |
| | | var byteData = System.Text.Encoding.UTF8.GetBytes(requestJson); |
| | | byte[] result1 = null; |
| | | //访问接口 |
| | | var result = await CommonPage.Instance.RequestHttpsZigbeeAsync(RequestName, System.Text.Encoding.UTF8.GetBytes(requestJson)); |
| | | |
| | | return result; |
| | | if (UserCenterResourse.UserInfo.AuthorityNo == 1) |
| | | { |
| | | result1 = await CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync(RequestName, byteData); |
| | | } |
| | | else |
| | | { |
| | | result1 = await CommonPage.Instance.RequestZigbeeHttpsByAdmin(RequestName, byteData); |
| | | } |
| | | if (result1 != null) |
| | | { |
| | | var result2 = Encoding.UTF8.GetString(result1); |
| | | if (result2 != null) |
| | | { |
| | | var result = Newtonsoft.Json.JsonConvert.DeserializeObject<Shared.Common.ResponseEntity.ResponsePack>(result2); |
| | | return result; |
| | | } |
| | | } |
| | | return null; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | |
| | | /// <summary> |
| | | /// 获取子账户信息 |
| | | /// </summary> |
| | | /// </summary> |
| | | static List<Shared.Phone.UserCenter.MemberInfoRes> DoorLockAccountList = new List<Shared.Phone.UserCenter.MemberInfoRes> { }; |
| | | public static async System.Threading.Tasks.Task<List<Shared.Phone.UserCenter.MemberInfoRes>> GetSubAccountByDistributedMark() |
| | | { |
| | |
| | | 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); |
| | | string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra);
|
| | | if (result == null)
|
| | | {
|
| | | return null;
|
| | | } |
| | | var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Shared.Phone.UserCenter.MemberInfoRes>>(result); |
| | | return listInfo; |
| | | })); |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 与网关通讯接口 |
| | | #region 门锁操作事件通知 |
| | | /// <summary> |
| | | /// 门锁操作事件通知 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DoorLockOperatingEventNotificationCommand doorLockOperatingEventNotificationCommand; |
| | | /// <summary> |
| | | /// 门锁操作事件通知 |
| | |
| | | ///不常用: |
| | | /// 1:RF(Zigbee无线);2:Manual(手动);255:Indeterminate(不确定) |
| | | /// </summary> |
| | | public int OperationEventSource; |
| | | public int OperationEventSoure; |
| | | /// <summary> |
| | | /// 事件码 |
| | | /// 常用: |
| | |
| | | /// Unlock命令:error,invalid schedule事件 |
| | | /// </summary> |
| | | UnlockInvalidScheduleEvent = 6, |
| | | } |
| | | }
|
| | | #endregion |
| | | |
| | |
|
| | | #region 门锁编程事件通知 |
| | | /// <summary> |
| | | /// 门锁编程事件通知 |
| | | /// </summary> |
| | | [Newtonsoft.Json.JsonIgnore] |
| | | public DoorLockProgrammingEventNotificationCommand doorLockProgrammingEventNotificationCommand; |
| | | /// <summary> |
| | | /// 门锁编程事件通知 |
| | |
| | | /// 保留 |
| | | /// </summary> |
| | | public int UserStatus; |
| | | /// <summary> |
| | | /// <summary> |
| | | /// 编程事件触发源 |
| | | /// 常用: |
| | | /// 0:Keypad(键盘/密码);3:RFID(射频卡);15:指纹 |
| | |
| | | /// 常用: |
| | | /// 键盘/密码,指纹、感应卡:1:Lock命令成功事件;2:Unlock命令成功事件 |
| | | ///不常用: |
| | | /// 请查看枚举 |
| | | /// 请查看枚举 |
| | | /// </summary> |
| | | public int ProgramEventCode; |
| | | /// <summary> |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 临时密码信息 |
| | | #region 矫正门锁时间 |
| | | /// <summary> |
| | | /// 临时密码本地存储对象 |
| | | /// 矫正门锁时间 |
| | | /// </summary> |
| | | public TempPasswordObj tempPasswordObj = new TempPasswordObj(); |
| | | /// <summary> |
| | | /// 临时密码本地对象 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class TempPasswordObj |
| | | /// <param name="timestamp"></param> |
| | | /// <returns></returns> |
| | | public async System.Threading.Tasks.Task<SetWritableValueResponAllData> RectifyDoorLockTimeAsync(int timestamp) |
| | | { |
| | | /// <summary> |
| | | /// 门锁有效时间 |
| | | /// </summary> |
| | | public int validTime; |
| | | /// <summary> |
| | | /// 门锁时间 |
| | | /// </summary> |
| | | public int times; |
| | | 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.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 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; |
| | | }); |
| | | } |
| | | |
| | | #endregion |
| | | #endregion |
| | | |
| | | #region 私有命令 |
| | | #region 与设备通讯接口(私有命令) |
| | | |
| | | #region 用户管理控制 |
| | | ///<summary > |
| | |
| | | |
| | | 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()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | 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 DefaultControlResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | {
|
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | var data = 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 DefaultControlResponseData(); |
| | | tempD.command = Convert.ToInt32(data[10].ToString() + data[11].ToString() + data[12].ToString() + data[13].ToString(), 16); |
| | | 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 DefaultControlResponseAllData { defaultControlResponseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0402_{ topic}"); |
| | | if (tempD.command == "0450") |
| | | { |
| | | result = new DefaultControlResponseAllData { defaultControlResponseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0450_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) |
| | | { |
| | | result = new DefaultControlResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | |
| | | |
| | | 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> |
| | |
| | | /// <summary> |
| | | /// 用户管理发送数据回复 |
| | | /// </summary> |
| | | public DefaultControlResponseAllData defaultControlResponseAllData; |
| | | [System.Serializable] |
| | | public class DefaultControlResponseAllData |
| | | { |
| | |
| | | /// <summary> |
| | | ///响应操作码(0-ffff) |
| | | /// </summary> |
| | | public int command = -1; |
| | | public string command = ""; |
| | | /// <summary> |
| | | /// 状态值 |
| | | /// <para>默认响应结果: |
| | | ///<para>0 删除成功</para> |
| | | ///<para>1 删除失败</para> |
| | | ///<para>0 成功</para> |
| | | ///<para>1 失败</para> |
| | | ///<para>2 用户不存在</para> |
| | | ///<para>32 冻结成功</para> |
| | | ///<para>34 冻结失败</para> |
| | | ///<para>33 解冻成功</para> |
| | | ///<para>35 解冻失败</para> |
| | | ///<para>35 解冻失败</para> |
| | | /// </summary> |
| | | public int status = -1; |
| | | } |
| | |
| | | public enum AccessType |
| | | { |
| | | /// <summary> |
| | | /// 0x00 删除全部单次用户 |
| | | /// 0x00 删除全部临时用户 |
| | | /// </summary> |
| | | DelAllUsers = 0, |
| | | /// <summary> |
| | |
| | | /// 0x21 解冻指定用户 |
| | | /// </summary> |
| | | Enable = 3, |
| | | /// <summary> |
| | | /// 0x10 多个指定用户删除 |
| | | /// </summary> |
| | | DelMoreUsers = 4, |
| | | /// <summary> |
| | | /// 0x30 多个指定用户冻结 |
| | | /// </summary> |
| | | DisEnableMoreUsers = 5, |
| | | /// <summary> |
| | | /// 0x31 多个指定用户解冻 |
| | | /// </summary> |
| | | EnableMoreUsers = 6, |
| | | } |
| | | #endregion |
| | | |
| | | #region 验证门锁密码 |
| | | ///<summary > |
| | | ///验证门锁密码 |
| | | ///<para>inputPassword:输入的门锁密码</para> |
| | | ///<para>inputPassword:输入的门锁密码</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<VerifyPasswordResponseAllData> VerifyPasswordAsync(string inputPassword) |
| | | { |
| | |
| | | |
| | | 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()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | 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 VerifyPasswordResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | var data = clientDataPassthroughResponseData.PassData; |
| | | if (data.Length == 12) |
| | | { |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | |
| | | { |
| | | var result1 = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16); |
| | | result = new VerifyPasswordResponseAllData { result = result1 }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0402_{ topic}"); |
| | | DebugPrintLog($"UI收到通知后的主题_command:0454_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (result != null) |
| | | if (result != null && result.result == 0) |
| | | { |
| | | break; |
| | | } |
| | |
| | | /// <summary> |
| | | /// 用户管理发送数据回复 |
| | | /// </summary> |
| | | public VerifyPasswordResponseAllData verifyPasswordResponseAllData; |
| | | [System.Serializable] |
| | | public class VerifyPasswordResponseAllData |
| | | { |
| | |
| | | } |
| | | #endregion |
| | | |
| | | #region 远程开锁 |
| | | #region 远程开锁 |
| | | ///<summary > |
| | | ///远程开锁 |
| | | ///<para>inputPassword: 输入密码/para> |
| | | ///远程开锁 |
| | | ///<para>inputPassword: 输入密码/para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<ResponseAllData> RemoteControlAsync(string inputPassword) |
| | | public async System.Threading.Tasks.Task<RemoteResponseAllData> RemoteControlAsync(string inputPassword) |
| | | { |
| | | ResponseAllData result = null; |
| | | RemoteResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = "当前没有网关" }; |
| | | result = new RemoteResponseAllData { errorMessageBase = "当前没有网关" }; |
| | | return result; |
| | | } |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | |
| | | |
| | | 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()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | result = new RemoteResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new ResponseAllData { 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 gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") }; |
| | | gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (gatewayTemp.clientDataPassthroughResponseData == null) |
| | | var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString()); |
| | | if (OperatingEventNotificationDatad != null) |
| | | { |
| | | result = new ResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | if (OperatingEventNotificationDatad.OperationEventSoure == 1 && OperatingEventNotificationDatad.OperationEventCode == 5) |
| | | { |
| | | result = new RemoteResponseAllData { IsPawDispear = true }; |
| | | } |
| | | } |
| | | } |
| | | else if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (clientDataPassthroughResponseData == null) |
| | | { |
| | | result = new RemoteResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | var data = 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); |
| | | 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 ResponseAllData { responseData = tempD }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_command:0400_{ topic}"); |
| | | if (tempD.command == "0462") |
| | | { |
| | | result = new RemoteResponseAllData { responseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0462_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | |
| | | 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) |
| | | 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 ResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | result = new RemoteResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | |
| | | |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 远程回复数据 |
| | | /// </summary> |
| | | [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 |
| | | |
| | | #region 临时密码发送数据 |
| | | ///<summary > |
| | | ///远程开锁 |
| | | ///<para>inputPassword: 输入密码/para> |
| | | ///临时密码 |
| | | ///<para>inputPassword: 输入密码/para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<TempPasswordResponseAllData> TempPasswordAsync(string inputPassword, System.DateTime startTime, System.DateTime endTime, string fixedPassword = "190605") |
| | | { |
| | |
| | | |
| | | 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()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | } |
| | | 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 TempPasswordResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | var data = 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.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 }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_command:0400_{ topic}"); |
| | | if (tempD.command == "0463") |
| | | { |
| | | result = new TempPasswordResponseAllData { responseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0463_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | if (result != null) |
| | | if (result != null && result.responseData != null && result.responseData.command == "0463") |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime) |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) |
| | | { |
| | | result = new TempPasswordResponseAllData |
| | | { errorMessageBase = " 回复超时,请重新操作" }; |
| | |
| | | pawStr = pawStr.PadLeft(8, '0'); |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | | passwordStr += passwordStr.Substring(i, 2); |
| | | passwordStr += pawStr.Substring(i, 2); |
| | | } |
| | | var startTimeStr = System.Convert.ToString(GetUnixTimeStamp(startTime, false), 16); |
| | | var endTimeStr = System.Convert.ToString(GetUnixTimeStamp(endTime, false), 16); |
| | | |
| | | var startTimeStr = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetUnixTimeStamp(startTime); |
| | | var endTimeStr = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetUnixTimeStamp(endTime); |
| | | startTimeStr = string.Format("{0:X}", System.Convert.ToInt64(startTimeStr)); |
| | | endTimeStr = string.Format("{0:X}", System.Convert.ToInt64(endTimeStr)); |
| | | for (int i = 6; i >= 0; i = i - 2) |
| | | { |
| | | vaildTimeStr += startTimeStr.Substring(i, 2); |
| | | invalidTimeStr += endTimeStr.Substring(i, 2); |
| | | } |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | passwordStr + vaildTimeStr + vaildTimeStr; |
| | | } |
| | | catch { }; |
| | | |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | passwordStr + vaildTimeStr + invalidTimeStr; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | var mess = ex.Message; |
| | | }; |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 临时密码回复数据 |
| | | /// </summary> |
| | | public TempPasswordResponseAllData keyColorDataResponseAllData; |
| | | [System.Serializable] |
| | | public class TempPasswordResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | |
| | | /// <summary> |
| | | ///响应操作码(0-ffff) |
| | | /// </summary> |
| | | public int command = -1; |
| | | public string command = ""; |
| | | /// <summary> |
| | | /// 状态值 |
| | | /// <para>0--注册成功</para> |
| | |
| | | { |
| | | string passwordStr = ""; |
| | | var result = await GetKeyPassworAsync(); |
| | | //返回小端 |
| | | //返回小端 |
| | | if (result == null || result.keyPassword == null) |
| | | { |
| | | return 0; |
| | |
| | | |
| | | 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()); |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | |
| | | |
| | | 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 KeyPasswordInfo { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null) |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = gatewayTemp.clientDataPassthroughResponseData.PassData; |
| | | var data = clientDataPassthroughResponseData.PassData; |
| | | if (data.Length == 20) |
| | | { |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | |
| | | public async System.Threading.Tasks.Task<DoorlockUserInfo> GetDoorlockUserInfoAsync() |
| | | { |
| | | DoorlockUserInfo result = null; |
| | | int totalNum = 0; |
| | | int currentNum = -1; |
| | | DoorLockUserDetailData doorLockUserDetailData = new DoorLockUserDetailData { }; |
| | | if (Gateway == null) |
| | | { |
| | |
| | | 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}"); |
| | | } |
| | |
| | | } |
| | | 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()); |
| | | |
| | |
| | | public class DoorLockUserDetailData |
| | | { |
| | | /// <summary> |
| | | /// 类型 |
| | | /// 类型(读取锁上已有用户) |
| | | /// </summary> |
| | | public int userType; |
| | | /// <summary> |
| | |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 获取从格林威治时间到当前某一时刻的总毫秒数 |
| | | #region 音量 |
| | | ///<summary > |
| | | ///获取音量 |
| | | /// </summary> |
| | | /// <param name="dateTime">北京时间</param> |
| | | /// <param name="accurateToMilliseconds">精确到毫秒,否到秒</param> |
| | | /// <returns>返回一个长整数时间戳</returns> |
| | | public static long GetUnixTimeStamp(DateTime dateTime, bool accurateToMilliseconds) |
| | | public async System.Threading.Tasks.Task<VolumeResponseAllData> GetVolumeAsync() |
| | | { |
| | | 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); |
| | | VolumeResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new VolumeResponseAllData { 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | result = new VolumeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new VolumeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (clientDataPassthroughResponseData == null) |
| | | { |
| | | result = new VolumeResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = clientDataPassthroughResponseData.PassData; |
| | | if (data.Length == 14) |
| | | { |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | if (command == "0456") |
| | | { |
| | | var tempD = new VolumeResponseData(); |
| | | tempD.command = data[10].ToString() + data[11].ToString(); |
| | | tempD.value = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16); |
| | | result = new VolumeResponseAllData { volumeResponseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0456_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = VolumeData(-1); |
| | | 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 && result.volumeResponseData != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) |
| | | { |
| | | result = new VolumeResponseAllData |
| | | { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | |
| | | ///<summary > |
| | | ///音量 |
| | | ///<para>命令值: comandValue</para> |
| | | ///<para>comandValue: 0-0x64 音量</para> |
| | | /// </summary> |
| | | public async System.Threading.Tasks.Task<DefaultControlResponseAllData> SetVolumeAsync(int comandValue) |
| | | { |
| | | DefaultControlResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new DefaultControlResponseAllData { 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | result = new DefaultControlResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new DefaultControlResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (clientDataPassthroughResponseData == null) |
| | | { |
| | | result = new DefaultControlResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = 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 DefaultControlResponseData(); |
| | | 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); |
| | | if (tempD.command == "0455") |
| | | { |
| | | result = new DefaultControlResponseAllData { defaultControlResponseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0455_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = VolumeData(comandValue); |
| | | 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 && result.defaultControlResponseData != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) |
| | | { |
| | | result = new DefaultControlResponseAllData |
| | | { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 将UNIX时间戳转为北京时间 |
| | | /// 音量发送数据 |
| | | ///<para>comandValue: 0-100 音量</para> |
| | | /// </summary> |
| | | /// <param name="unixTimeStamp">时间戳</param> |
| | | /// <param name="accurateToMilliseconds">精确到毫秒,佛为秒</param> |
| | | /// <returns></returns> |
| | | public static DateTime GetLocalTime(int unixTimeStamp, bool accurateToMilliseconds) |
| | | public string VolumeData(int comandValue) |
| | | { |
| | | DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(1970, 1, 1, 8, 0, 0));//北京所在东八区 |
| | | return (accurateToMilliseconds ? startTime.AddMilliseconds(unixTimeStamp) : startTime.AddSeconds(unixTimeStamp)).ToLocalTime(); |
| | | string data = ""; |
| | | string dataLength = "05"; |
| | | string dataComand1 = "55"; |
| | | string dataComand2 = "04"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = "01"; |
| | | string cValue = ""; |
| | | try |
| | | { |
| | | if (comandValue >= 1) |
| | | { |
| | | cValue = Convert.ToString(comandValue, 16).ToUpper(); |
| | | if (cValue.Length == 1) |
| | | { |
| | | cValue = "0" + cValue; |
| | | } |
| | | else |
| | | { |
| | | cValue = cValue; |
| | | } |
| | | |
| | | } |
| | | else |
| | | { |
| | | switch (comandValue) |
| | | { |
| | | case -1: |
| | | cValue = "AA"; |
| | | break; |
| | | case 0: |
| | | cValue = "EB"; |
| | | break; |
| | | } |
| | | } |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | cValue; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | var mess = ex.Message; |
| | | }; |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 音量回复数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class VolumeResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 音量回复数据 |
| | | /// </summary> |
| | | public VolumeResponseData volumeResponseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 音量回复数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class VolumeResponseData |
| | | { |
| | | /// <summary> |
| | | ///命令 |
| | | ///<para>0x00 接收成功</para> |
| | | ///<para>0xea 语音模式</para> |
| | | ///<para>0xeb 静音模式</para> |
| | | /// </summary> |
| | | public string command = ""; |
| | | /// <summary> |
| | | /// 音量值 |
| | | /// <para>0xf1~0xfe 1-14音量</para> |
| | | /// <para>0 无音量值</para> |
| | | /// </summary> |
| | | public int value = -1; |
| | | } |
| | | #endregion |
| | | |
| | | #region 常开模式 |
| | | /// <summary> |
| | | /// 读取常开模式 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public async System.Threading.Tasks.Task<OpenModeResponseAllData> ReadNormallyOpenModeFuncAsync() |
| | | { |
| | | OpenModeResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new OpenModeResponseAllData { 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | result = new OpenModeResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new OpenModeResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (clientDataPassthroughResponseData == null) |
| | | { |
| | | result = new OpenModeResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = clientDataPassthroughResponseData.PassData; |
| | | if (data.Length == 12) |
| | | { |
| | | var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString(); |
| | | if (command == "0458") |
| | | { |
| | | result = new OpenModeResponseAllData(); |
| | | result.command = data[10].ToString() + data[11].ToString(); |
| | | DebugPrintLog($"UI收到通知后的主题_command:0457_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = OpenModeData(SwitchMode.Obtain); |
| | | 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 > 9000) |
| | | { |
| | | result = new OpenModeResponseAllData |
| | | { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 设置常开模式 |
| | | /// </summary> |
| | | /// <param name="IsNormallyOpenMode">是否打开常开模式:true:打开 false:关闭</param> |
| | | /// <returns></returns> |
| | | public async System.Threading.Tasks.Task<DefaultControlResponseAllData> SetNormallyOpenModeFuncAsync(bool IsNormallyOpenMode) |
| | | { |
| | | DefaultControlResponseAllData result = null; |
| | | if (Gateway == null) |
| | | { |
| | | result = new DefaultControlResponseAllData { 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 temp = Newtonsoft.Json.JsonConvert.DeserializeObject<CommonDevice.ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | result = new DefaultControlResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | |
| | | else |
| | | { |
| | | result = new DefaultControlResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "ZbDataPassthrough") |
| | | { |
| | | var clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (clientDataPassthroughResponseData == null) |
| | | { |
| | | result = new DefaultControlResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | if (clientDataPassthroughResponseData?.PassData != null) |
| | | { |
| | | var data = 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 DefaultControlResponseData(); |
| | | 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); |
| | | if (tempD.command == "0457") |
| | | { |
| | | result = new DefaultControlResponseAllData { defaultControlResponseData = tempD }; |
| | | DebugPrintLog($"UI收到通知后的主题_command:0457_{ topic}"); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Gateway.Actions += action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | try |
| | | { |
| | | var passData = ""; |
| | | if (IsNormallyOpenMode) |
| | | { |
| | | passData = OpenModeData(SwitchMode.NormallyOpen); |
| | | } |
| | | else |
| | | { |
| | | passData = OpenModeData(SwitchMode.NormallyClose); |
| | | } |
| | | 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 && result.defaultControlResponseData != null) |
| | | { |
| | | break; |
| | | } |
| | | } |
| | | if ((DateTime.Now - dateTime).TotalMilliseconds > 9000) |
| | | { |
| | | result = new DefaultControlResponseAllData |
| | | { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | Gateway.Actions -= action; |
| | | DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return result; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 常开模式 发送数据 |
| | | /// </summary> |
| | | public string OpenModeData(SwitchMode switchMode) |
| | | { |
| | | string data = ""; |
| | | string dataLength = "05"; |
| | | string dataComand1 = "57"; |
| | | string dataComand2 = "04"; |
| | | string dataSerialNum = "01"; |
| | | string addDataLength = "01"; |
| | | string cValue = ""; |
| | | try |
| | | { |
| | | switch (switchMode) |
| | | { |
| | | case SwitchMode.Obtain: |
| | | cValue = "10"; |
| | | break; |
| | | case SwitchMode.NormallyOpen: |
| | | cValue = "12"; |
| | | break; |
| | | case SwitchMode.NormallyClose: |
| | | cValue = "13"; |
| | | break; |
| | | } |
| | | data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength + |
| | | cValue; |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | var mess = ex.Message; |
| | | }; |
| | | return data; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 常开模式 回复数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class OpenModeResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 0x10 常开已开启 |
| | | /// <para>0x11 常开已关闭</para> |
| | | /// </summary> |
| | | public string command; |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 开关模式 |
| | | /// </summary> |
| | | public enum SwitchMode |
| | | { |
| | | /// <summary> |
| | | /// 0x10 查询常开状态 |
| | | /// </summary> |
| | | Obtain = 0x10, |
| | | /// <summary> |
| | | /// 0x12 开启常开 |
| | | /// </summary> |
| | | NormallyOpen = 0x12, |
| | | /// <summary> |
| | | /// 0x13 关闭常开 |
| | | /// </summary> |
| | | NormallyClose = 0x13 |
| | | } |
| | | #endregion |
| | | |
| | | #endregion |
| | | } |
| | | } |