New file |
| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Text; |
| | | using Newtonsoft.Json.Linq; |
| | | |
| | | namespace ZigBee.Device |
| | | { |
| | | [System.Serializable] |
| | | public class Scene |
| | | { |
| | | /// <summary> |
| | | /// 当前主网关的ID |
| | | /// </summary> |
| | | public string GateWayId; |
| | | |
| | | /// <summary> |
| | | /// 网关返回场景的命令标识 |
| | | /// </summary> |
| | | public int DataID; |
| | | |
| | | /// <summary> |
| | | /// 网关反馈的时间戳 |
| | | /// </summary> |
| | | public int Time; |
| | | |
| | | /// <summary> |
| | | /// 当前场景的ID |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneBase |
| | | { |
| | | /// <summary> |
| | | /// 场景的I |
| | | /// </summary> |
| | | public int SceneId; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关中场景设备列表 |
| | | /// </summary> |
| | | //[Newtonsoft.Json.JsonIgnore] |
| | | //public List<GetSceneDeviceListInfo> SceneDeviceList = new List<GetSceneDeviceListInfo>(); |
| | | |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | ErrorResponData errResponData; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ErrorResponData |
| | | { |
| | | /// <summary> |
| | | /// Error参数含义 |
| | | ///<para>1:网关无法解析命令数据。</para> |
| | | ///<para>2:协调器正在升级或备份/恢复数据 |
| | | ///<para>3:操作设备/组/场景不存在</para> |
| | | ///<para>4:其他错误</para> |
| | | ///<para>5:数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)</para> |
| | | /// </summary> |
| | | public int Error; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 等待从网关接收数据的时间 |
| | | /// </summary> |
| | | /// <value>The wait receive data time.</value> |
| | | public static int WaitReceiveDataTime |
| | | { |
| | | get |
| | | { |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | return 3000; |
| | | } |
| | | else if (mainGateway.IsVirtual) |
| | | { |
| | | return 6000; |
| | | } |
| | | else |
| | | { |
| | | return 3000; |
| | | } |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 网关信息错误反馈的内容 |
| | | /// </summary> |
| | | static string ErrorMess(int err) |
| | | { |
| | | string message = ""; |
| | | switch (err) |
| | | { |
| | | case 1: |
| | | message = " 网关无法解析命令数据。"; |
| | | break; |
| | | case 2: |
| | | message = " 协调器正在升级或备份 / 恢复数据。"; |
| | | break; |
| | | case 3: |
| | | message = "操作设备 / 组 / 场景不存在"; |
| | | break; |
| | | case 4: |
| | | message = " 其他错误"; |
| | | break; |
| | | case 5: |
| | | message = " 数据传输错误(在某次客户端向网关发送数据的过程中,网关在合理时间范围内接收客户端数据不完整导致该错误发生。如客户端向网关一次发送100个字节的数据,但网关等待接收了一秒只接收了80个字节。发生该错误,网关将主动关闭客户端连接)"; |
| | | break; |
| | | default: |
| | | break; |
| | | } |
| | | return message; |
| | | } |
| | | |
| | | #region 在从网关中发场景的命令的反馈 |
| | | /// <summary> |
| | | ///在从网关中发场景的命令的反馈 |
| | | /// </summary> |
| | | public SceneErrorRespon sceneErrorRespon; |
| | | /// <summary> |
| | | ///在从网关中发场景的命令的反馈 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneErrorRespon |
| | | { |
| | | /// <summary> |
| | | /// 非主网关不能使用场景指令。 |
| | | /// </summary> |
| | | public int Data_ID; |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region 创建一个空场景 |
| | | ///<summary > |
| | | /// 创建一个空场景.(仅用于主网关接口) |
| | | /// <para>sceneName:取该场景的名字</para> |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<GetSceneIdAllData> GetSceneNewIdAsync(string sceneName) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | GetSceneIdAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new GetSceneIdAllData {errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new GetSceneIdAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GetSceneIdAllData { errorResponData = temp , errorMessageBase = ErrorMess(temp.Error)}; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/GetNewId_Respon") |
| | | { |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.getSceneIdData = Newtonsoft.Json.JsonConvert.DeserializeObject<Scene.GetSceneIdData>(jobject["Data"].ToString()); |
| | | if (scene.getSceneIdData == null) |
| | | { |
| | | d = new GetSceneIdAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | GetSceneAllInfoAsync(); |
| | | d = new GetSceneIdAllData { getSceneIdData = scene.getSceneIdData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/GetNewId_Actions 启动" + System.DateTime.Now.ToString()); |
| | | try{ |
| | | var bytes = new byte[32]; |
| | | var reamarkGwBytes = System.Text.Encoding.UTF8.GetBytes(sceneName); |
| | | System.Array.Copy(reamarkGwBytes, 0, bytes, 0, 32 < reamarkGwBytes.Length ? 32 : reamarkGwBytes.Length); |
| | | sceneName = System.Text.Encoding.UTF8.GetString(bytes); |
| | | |
| | | var jObject = new Newtonsoft.Json.Linq.JObject() { |
| | | { "Cluster_ID", 0 }, |
| | | { "Command", 800 } |
| | | }; |
| | | var data = new JObject { { "ScenesName", sceneName } }; |
| | | jObject.Add("Data", data); |
| | | mainGateway.Send("Scene/GetNewId", 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 GetSceneIdAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | |
| | | } |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/GetNewId_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建一个空场景返回的数据,网关反馈信息 |
| | | /// </summary> |
| | | public GetSceneIdAllData getSceneIdAllData; |
| | | /// <summary> |
| | | /// 创建一个空场景返回的数据,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetSceneIdAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 创建一个空场景返回的数据 |
| | | /// </summary> |
| | | public GetSceneIdData getSceneIdData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 创建一个空场景返回的数据 |
| | | /// </summary> |
| | | public GetSceneIdData getSceneIdData; |
| | | /// <summary> |
| | | /// 创建一个空场景返回的数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetSceneIdData |
| | | { |
| | | /// <summary> |
| | | /// 新的场景id |
| | | /// </summary> |
| | | public int NewScenesId; |
| | | /// <summary> |
| | | /// 场景名称 ,不大于32个字节。 |
| | | /// </summary> |
| | | public string ScenesName; |
| | | } |
| | | #endregion |
| | | |
| | | #region 获取一个场景的所有信息 |
| | | ///<summary > |
| | | ///获取一个场景的所有信息 . |
| | | ///</summary> |
| | | public static async System.Threading.Tasks.Task<GetSceneAllData> GetSceneAllInfoAsync() |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => { |
| | | GetSceneAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new GetSceneAllData { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | ZbGateway.AllSceneList.Clear(); |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new GetSceneAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GetSceneAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error)}; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/GetAllInfo_Respon") |
| | | { |
| | | dateTime = DateTime.Now; |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.sceneGetAllInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetSceneAllInfo>(jobject["Data"].ToString()); |
| | | |
| | | if (scene.sceneGetAllInfo == null) |
| | | { |
| | | d = new GetSceneAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | var info = ZbGateway.AllSceneList.Find(obj => obj.ScenesId == scene.sceneGetAllInfo.ScenesId); |
| | | if (info == null) |
| | | { |
| | | ZbGateway.AllSceneList.Add(scene.sceneGetAllInfo); |
| | | } |
| | | else |
| | | { |
| | | info.DeviceList = scene.sceneGetAllInfo.DeviceList; |
| | | info.DeviceSum = scene.sceneGetAllInfo.DeviceSum; |
| | | info.IsOpen = scene.sceneGetAllInfo.IsOpen; |
| | | info.ScenesId = scene.sceneGetAllInfo.ScenesId; |
| | | info.ScenesName = scene.sceneGetAllInfo.ScenesName; |
| | | info.ScenesNum = scene.sceneGetAllInfo.ScenesNum; |
| | | info.ScenesSum = scene.sceneGetAllInfo.ScenesSum; |
| | | } |
| | | d = new GetSceneAllData { getSceneAllInfo = scene.sceneGetAllInfo }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/GetAllInfo_Actions 启动" + System.DateTime.Now.ToString()); |
| | | try{ |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 807 } }; |
| | | mainGateway.Send(("Scene/GetAllInfo"), jObject.ToString()); |
| | | } |
| | | catch {} |
| | | |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(100); |
| | | } |
| | | |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/GetAllInfo_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 获取所有场景的所有信息,网关反馈信息 |
| | | /// </summary> |
| | | public GetSceneAllData getSceneAllData; |
| | | /// <summary> |
| | | /// 获取所有场景的所有信息,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetSceneAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 获取所有场景的所有信息 |
| | | /// </summary> |
| | | public GetSceneAllInfo getSceneAllInfo; |
| | | } |
| | | /// <summary> |
| | | /// 获取所有场景的所有信息 |
| | | /// </summary> |
| | | public GetSceneAllInfo sceneGetAllInfo; |
| | | /// <summary> |
| | | /// 获取所有场景的所有信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetSceneAllInfo:CommonDevice |
| | | { |
| | | /// <summary> |
| | | ///场景总数 |
| | | /// </summary> |
| | | public int ScenesSum; |
| | | |
| | | /// <summary> |
| | | ///表示当前发送的是第几个场景信息。ScenesNum从0开始,每发送一个场景信息将自加1,当ScenesNum等于ScenesSum时,表示所有信息发送完毕。 |
| | | /// </summary> |
| | | public int ScenesNum; |
| | | |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | /// 场景是否处于开启状态 |
| | | /// <para>0:场景没有开启</para> |
| | | ///<para>1:场景处于开启状态</para> |
| | | /// </summary> |
| | | public int IsOpen; |
| | | |
| | | /// <summary> |
| | | /// 场景名称 |
| | | /// </summary> |
| | | public string ScenesName; |
| | | |
| | | /// <summary> |
| | | /// 当前场景的设备数量 |
| | | /// </summary> |
| | | public int DeviceSum; |
| | | |
| | | /// <summary> |
| | | /// 场景列表 |
| | | /// </summary> |
| | | public List<DeviceListData> DeviceList = new List<DeviceListData>(); |
| | | } |
| | | /// <summary> |
| | | /// 场景列表数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DeviceListData |
| | | { |
| | | /// <summary> |
| | | /// 成员类型 |
| | | ///<para>0:设备成员</para> |
| | | ///<para>1:场景成员</para> |
| | | ///<para>2:延时成员</para> |
| | | /// </summary> |
| | | public int Type; |
| | | |
| | | /// <summary> |
| | | /// 设备mac地址 , |
| | | ///<para>当Type=0时存在。</para> |
| | | /// </summary> |
| | | public string DeviceAddr; |
| | | /// <summary> |
| | | /// 设备端口号 |
| | | ///<para>当Type=0时存在。</para> |
| | | /// </summary> |
| | | public int Epoint; |
| | | /// <summary> |
| | | /// 设备名称 |
| | | /// </summary> |
| | | public string DeviceName; |
| | | /// <summary> |
| | | /// 设备列表 |
| | | /// 当Type=0时存在 |
| | | /// </summary> |
| | | public List<Safeguard.TaskListInfo> TaskList = new List<Safeguard.TaskListInfo>(); |
| | | |
| | | /// <summary> |
| | | /// 场景成员的场景id |
| | | /// <para>当Type=1时存在</para> |
| | | /// </summary> |
| | | public int ElseScenesId; |
| | | |
| | | /// <summary> |
| | | ///延时执行时间,单位秒。 |
| | | /// </summary> |
| | | public int DelayTime; |
| | | /// <summary> |
| | | /// 场景动作序号,表示第几个动作 |
| | | /// </summary> |
| | | public int MemberNumber; |
| | | } |
| | | |
| | | #endregion |
| | | |
| | | #region 获取场景列表 |
| | | ///<summary > |
| | | ///获取场景列表 |
| | | ///</summary> |
| | | public static async System.Threading.Tasks.Task<List<GetSceneAllInfo>> GetSceneListAsync() |
| | | { |
| | | ZbGateway.AllSceneList.Clear(); |
| | | return await System.Threading.Tasks.Task.Run(async () => { |
| | | var dateTime = DateTime.Now; |
| | | GetSceneAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new GetSceneAllData { errorMessageBase = "当前没有主网关" }; |
| | | return null; |
| | | } |
| | | Action<string, string> action = (topic, message) => |
| | | { |
| | | var gatewayID = topic.Split('/')[0]; |
| | | var jobject = Newtonsoft.Json.Linq.JObject.Parse(message); |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/GetAllInfo_Respon") |
| | | { |
| | | dateTime = DateTime.Now; |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.sceneGetAllInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetSceneAllInfo>(jobject["Data"].ToString()); |
| | | |
| | | var info = ZbGateway.AllSceneList.Find(obj => obj.ScenesId == scene.sceneGetAllInfo.ScenesId); |
| | | if (info == null) |
| | | { |
| | | ZbGateway.AllSceneList.Add(scene.sceneGetAllInfo); |
| | | } |
| | | else |
| | | { |
| | | info.DeviceList = scene.sceneGetAllInfo.DeviceList; |
| | | info.DeviceSum = scene.sceneGetAllInfo.DeviceSum; |
| | | info.IsOpen = scene.sceneGetAllInfo.IsOpen; |
| | | info.ScenesId = scene.sceneGetAllInfo.ScenesId; |
| | | info.ScenesName = scene.sceneGetAllInfo.ScenesName; |
| | | info.ScenesNum = scene.sceneGetAllInfo.ScenesNum; |
| | | info.ScenesSum = scene.sceneGetAllInfo.ScenesSum; |
| | | } |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/GetAllInfo_Actions 启动" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 807 } }; |
| | | mainGateway.Send(("Scene/GetAllInfo"),System.Text.Encoding.UTF8.GetBytes(jObject.ToString())); |
| | | } |
| | | catch { } |
| | | |
| | | while ((DateTime.Now - dateTime).TotalMilliseconds < 1000) |
| | | { |
| | | await System.Threading.Tasks.Task.Delay(10); |
| | | } |
| | | |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/GetAllInfo_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return ZbGateway.AllSceneList; |
| | | }); |
| | | } |
| | | #endregion |
| | | |
| | | #region 只能获取场景信息,没有场景中的设备信息 |
| | | /// <summary> |
| | | /// 只能获取场景信息,没有场景中的设备信息 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | //static async System.Threading.Tasks.Task<GetOnlySceneAllData> GetSceneInfoAsync() |
| | | //{ |
| | | //if (ZbGateway.MainGateWay == null) |
| | | //{ |
| | | // return null; |
| | | //} |
| | | //return await System.Threading.Tasks.Task.Run(async () => |
| | | //{ |
| | | //var d = new GetOnlySceneAllData { }; |
| | | //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 = ZbGateway.MainGateWay.getGatewayBaseInfo.gwID }; |
| | | // var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | // if (temp == null) |
| | | // { |
| | | // d.errorMessageBase = "网关错误回复,且数据是空"; |
| | | // } |
| | | // else |
| | | // { |
| | | // d.errorResponData = temp; |
| | | // d.errorMessageBase = ErrorMess(temp.Error); |
| | | // } |
| | | //} |
| | | |
| | | //if (topic == gatewayID + "/" + "Scene/GetInfo_Respon") |
| | | //{ |
| | | //var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = ZbGateway.MainGateWay?.CurrentGateWayId }; |
| | | //scene.sceneGetInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<GetSceneInfo>(jobject["Data"].ToString()); |
| | | |
| | | //if (scene.sceneGetInfo == null) |
| | | //{ |
| | | // d.errorMessageBase = "网关返回的数据为空"; |
| | | //} |
| | | //else |
| | | //{ |
| | | //if (ZbGateway.MainGateWay?.SceneList.Count == 0) |
| | | //{ |
| | | // ZbGateway.MainGateWay.SceneList.Add(scene.sceneGetInfo); |
| | | //} |
| | | //else |
| | | //{ |
| | | // foreach (var a in ZbGateway.MainGateWay.SceneList) |
| | | // { |
| | | // a.ScenesList = scene.sceneGetInfo.ScenesList; |
| | | // } |
| | | //} |
| | | //d.getSceneInfo = scene.sceneGetInfo; |
| | | // } |
| | | // } |
| | | //}; |
| | | //ZbGateway.MainGateWay.Actions += action; |
| | | //System.Console.WriteLine("Scene/GetInfo_Actions 启动" + System.DateTime.Now.ToString()); |
| | | |
| | | //var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 805 } }; |
| | | //ZbGateway.MainGateWay?.Send(("Scene/GetInfo"),System.Text.Encoding.UTF8.GetBytes(jObject.ToString())); |
| | | |
| | | //var dateTime = DateTime.Now; |
| | | //while ((DateTime.Now - dateTime).TotalMilliseconds < 1000) |
| | | //{ |
| | | // await System.Threading.Tasks.Task.Delay(10); |
| | | // if (d.getSceneInfo != null) |
| | | // { |
| | | // break; |
| | | // } |
| | | //} |
| | | //if ((DateTime.Now - dateTime).TotalMilliseconds > 10000) |
| | | //{ |
| | | // d.errorMessageBase = " 回复超时,请重新操作"; |
| | | //} |
| | | //ZbGateway.MainGateWay.Actions -= action; |
| | | //System.Console.WriteLine("Scene/GetInfo_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | //return d; |
| | | //}); |
| | | // } |
| | | |
| | | /// <summary> |
| | | ///获取场景信息,网关反馈信息 |
| | | /// </summary> |
| | | GetOnlySceneAllData getOnlySceneAllData; |
| | | /// <summary> |
| | | ///获取场景信息,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | class GetOnlySceneAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 获取场景信息 |
| | | /// </summary> |
| | | public GetSceneInfo getSceneInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取场景信息 |
| | | /// </summary> |
| | | public GetSceneInfo sceneGetInfo; |
| | | /// <summary> |
| | | /// 获取场景信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetSceneInfo |
| | | { |
| | | /// <summary> |
| | | ///场景总数 |
| | | /// </summary> |
| | | public int ScenesSum; |
| | | |
| | | /// <summary> |
| | | /// 场景列表 |
| | | /// </summary> |
| | | public List<ScenesListInfo> ScenesList = new List<ScenesListInfo>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 场景列表中的具体信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class ScenesListInfo:CommonDevice |
| | | { |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | /// 名称 |
| | | /// </summary> |
| | | public string ScenesName; |
| | | |
| | | /// <summary> |
| | | /// 是否处于开启状态 |
| | | ///0:场景没有被开启 |
| | | ///1:场景处于开启状态 |
| | | /// </summary> |
| | | public int IsOpen; |
| | | } |
| | | #endregion |
| | | |
| | | #region 获取当前场景中的设备列表信息 |
| | | ///<summary > |
| | | ///获取当前场景中的设备列表信息 |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<GetSceneDeviceListAllInfo> GetSceneDeviceListAsync(int scenesId) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | GetSceneDeviceListAllInfo d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new GetSceneDeviceListAllInfo { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new GetSceneDeviceListAllInfo { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new GetSceneDeviceListAllInfo { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/GetDeviceList_Respon") |
| | | { |
| | | var sceneTemp = new Scene() { Time = jobject.Value<int>("Time"), DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.getGatewayBaseInfo.gwID }; |
| | | sceneTemp.sceneGetDeviceListObj = Newtonsoft.Json.JsonConvert.DeserializeObject<GetSceneDeviceListInfo>(jobject["Data"].ToString()); |
| | | |
| | | if (sceneTemp.sceneGetDeviceListObj == null) |
| | | { |
| | | d = new GetSceneDeviceListAllInfo { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | var sDev = mainGateway.SceneDeviceList.Find(obj => obj.ScenesId == sceneTemp.sceneGetDeviceListObj.ScenesId); |
| | | if (sDev == null) |
| | | { |
| | | ZbGateway.MainGateWay.SceneDeviceList.Add(sceneTemp.sceneGetDeviceListObj); |
| | | } |
| | | else |
| | | { |
| | | sDev.DeviceList = sceneTemp.sceneGetDeviceListObj.DeviceList; |
| | | } |
| | | |
| | | d = new GetSceneDeviceListAllInfo { getSceneDeviceListInfo = sceneTemp.sceneGetDeviceListObj }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/GetDeviceList_Actions 启动" + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 806 } }; |
| | | var data = new JObject { { "ScenesId", scenesId } }; |
| | | jObject.Add("Data", data); |
| | | mainGateway.Send(("Scene/GetDeviceList"),System.Text.Encoding.UTF8.GetBytes(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 GetSceneDeviceListAllInfo { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/GetDeviceList_Actions退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | ///获取场景的设备列表信息,网关反馈信息 |
| | | /// </summary> |
| | | public GetSceneDeviceListAllInfo getSceneDeviceListAllInfo; |
| | | /// <summary> |
| | | ///获取场景的设备列表信息,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetSceneDeviceListAllInfo |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 获取场景的设备列表信息 |
| | | /// </summary> |
| | | public GetSceneDeviceListInfo getSceneDeviceListInfo; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取场景的设备列表信息 |
| | | /// </summary> |
| | | public GetSceneDeviceListInfo sceneGetDeviceListObj; |
| | | /// <summary> |
| | | /// 获取场景的设备列表信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class GetSceneDeviceListInfo |
| | | { |
| | | /// <summary> |
| | | ///场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | ///场景是否处于开启状态 |
| | | ///0:场景没有开启 |
| | | ///1:场景处于开启状态 |
| | | /// </summary> |
| | | public int IsOpen; |
| | | |
| | | /// <summary> |
| | | ///场景的设备数量 |
| | | /// </summary> |
| | | public int DeviceSum; |
| | | |
| | | /// <summary> |
| | | /// 设备列表 |
| | | /// </summary> |
| | | public List<DeviceListData> DeviceList = new List<DeviceListData>(); |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region 场景中添加的成员 |
| | | /// <summary> |
| | | /// 添加目标到网关到场景中。 |
| | | /// <para>返回结果Result 1 加入成功</para> |
| | | /// <para>返回结果Result 0 加入失败</para> |
| | | /// </summary> |
| | | /// <returns>The scene member.</returns> |
| | | /// <param name="scenesId">Scenes identifier.</param> |
| | | public static async System.Threading.Tasks.Task<AddSceneMemberResponseAllData> AddSceneMemberAsync(AddSceneMemberData sceneMemberData) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | AddSceneMemberResponseAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new AddSceneMemberResponseAllData { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new AddSceneMemberResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new AddSceneMemberResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/AddMember_Respon") |
| | | { |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.addSceneMemberData = Newtonsoft.Json.JsonConvert.DeserializeObject<AddSceneMemberResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (scene.addSceneMemberData == null) |
| | | { |
| | | d = new AddSceneMemberResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new AddSceneMemberResponseAllData { addSceneMemberResponseData = scene.addSceneMemberData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/AddMember_Actions 启动" + System.DateTime.Now.ToString()); |
| | | try{ |
| | | if (sceneMemberData != null) |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 820 } }; |
| | | var data = new JObject { }; |
| | | if (sceneMemberData.Type == 0) |
| | | { |
| | | var taskList = new JArray { }; |
| | | foreach (var taskInfo in sceneMemberData.TaskList) |
| | | { |
| | | var tInfo = new JObject{ |
| | | { "TaskType", taskInfo.TaskType}, |
| | | { "Data1", taskInfo.Data1}, |
| | | { "Data2",taskInfo.Data2} |
| | | }; |
| | | taskList.Add(tInfo); |
| | | } |
| | | |
| | | data = new JObject { |
| | | { "ScenesId",sceneMemberData.ScenesId}, |
| | | { "Type", sceneMemberData.Type} , |
| | | { "DeviceAddr",sceneMemberData.DeviceAddr} , |
| | | { "Epoint", sceneMemberData.Epoint} , |
| | | { "TaskList", taskList }, |
| | | { "DelayTime", sceneMemberData.DelayTime} , |
| | | { "MemberNumber",sceneMemberData.MemberNumber}, |
| | | }; |
| | | } |
| | | else if (sceneMemberData.Type == 1) |
| | | { |
| | | data = new JObject { |
| | | { "ScenesId",sceneMemberData.ScenesId}, |
| | | { "Type", sceneMemberData.Type} , |
| | | { "ElseScenesId", sceneMemberData.ElseScenesId }, |
| | | { "DelayTime", sceneMemberData.DelayTime} , |
| | | { "MemberNumber",sceneMemberData.MemberNumber}, |
| | | }; |
| | | } |
| | | else if (sceneMemberData.Type == 2) |
| | | { |
| | | data = new JObject { |
| | | { "Type", sceneMemberData.Type} , |
| | | { "ScenesId",sceneMemberData.ScenesId}, |
| | | { "DelayTime", sceneMemberData.DelayTime} , |
| | | { "MemberNumber",sceneMemberData.MemberNumber}, |
| | | }; |
| | | } |
| | | |
| | | jObject.Add("Data", data); |
| | | mainGateway.Send(("Scene/AddMember"),System.Text.Encoding.UTF8.GetBytes(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 AddSceneMemberResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/AddMember_Actions 退出" + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | |
| | | /// <summary> |
| | | /// 获取场景中添加的成员,网关反馈信息 |
| | | /// </summary> |
| | | public AddSceneMemberResponseAllData addSceneMemberResponseAllData; |
| | | /// <summary> |
| | | /// 获取场景中添加的成员,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class AddSceneMemberResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 获取场景中添加的成员 |
| | | /// </summary> |
| | | public AddSceneMemberResponseData addSceneMemberResponseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 获取场景中添加的成员 |
| | | /// </summary> |
| | | public AddSceneMemberResponseData addSceneMemberData; |
| | | /// <summary> |
| | | /// 获取添加成员到场景或更新场景 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class AddSceneMemberResponseData |
| | | { |
| | | /// <summary> |
| | | /// 1 加入成功 |
| | | /// <para>0 加入失败</para> |
| | | /// </summary> |
| | | public int Result; |
| | | |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | /// 延时执行时间,单位秒 |
| | | /// </summary> |
| | | public int DelayTime; |
| | | |
| | | /// <summary> |
| | | /// 0:加入成员为节点设备 |
| | | /// <para>1:加入成员为其他场景</para> |
| | | /// </summary> |
| | | public int Type; |
| | | |
| | | /// <summary> |
| | | /// 其他场景id |
| | | /// <para>当Type=1时,该字段存在</para> |
| | | /// </summary> |
| | | public int ElseScenesId; |
| | | |
| | | /// <summary> |
| | | /// 设备mac地址 |
| | | /// </summary> |
| | | public string DeviceAddr; |
| | | |
| | | /// <summary> |
| | | /// 设备端口号 |
| | | /// </summary> |
| | | public int Epoint; |
| | | |
| | | /// <summary> |
| | | /// 设备名称 ,当Type=0时,该字段存在 |
| | | /// </summary> |
| | | public string DeviceName; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 添加成员到场景或更新场景 |
| | | /// </summary> |
| | | public AddSceneMemberData setAddMember; |
| | | /// <summary> |
| | | /// 添加成员到场景或更新场景 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class AddSceneMemberData |
| | | { |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// <para>0:新增场景,网关将自动为该场景分配一个未被使用的场景id。</para> |
| | | /// <para>其他:设备要加入的场景。如果场景id不存在,则网关新建一个场景并用该字段值作为场景id。</para> |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | /// 添加成员类型 |
| | | ///<para>0:节点设备</para> |
| | | ///<para>1:其他场景</para> |
| | | ///<para>2:延时类型</para> |
| | | /// </summary> |
| | | public int Type; |
| | | |
| | | /// <summary> |
| | | /// 延时执行时间,单位秒 |
| | | /// 当Type=2时存在 |
| | | /// </summary> |
| | | public int DelayTime; |
| | | /// <summary> |
| | | /// 延时执行序号,表示延时索引 |
| | | ///当Type=2时存在 |
| | | /// </summary> |
| | | public int MemberNumber; |
| | | |
| | | /// <summary> |
| | | /// 作为成员的其他场景id。 |
| | | ///<para>当Type=1时,该字段才存在。</para> |
| | | /// </summary> |
| | | public int ElseScenesId; |
| | | |
| | | /// <summary> |
| | | /// 设备mac地址 |
| | | /// <para>Type=0时存在</para> |
| | | /// </summary> |
| | | public string DeviceAddr; |
| | | /// <summary> |
| | | /// 设备端口号 |
| | | /// <para>Type=0时存在</para> |
| | | /// </summary> |
| | | public int Epoint; |
| | | /// <summary> |
| | | /// 设备列表 |
| | | /// <para>Type=0时存在</para> |
| | | /// </summary> |
| | | public List<Safeguard.TaskListInfo> TaskList = new List<Safeguard.TaskListInfo>(); |
| | | } |
| | | #endregion |
| | | |
| | | #region 从网关的场景中移除设备 |
| | | /// <summary> |
| | | /// 从网关的场景中移除设备. |
| | | /// <para>返回结果Result/RemoveResult 1:移除失败,成员不存在场景中</para> |
| | | /// <para>返回结果Result/RemoveResult 0:移除成功败</para> |
| | | /// </summary> |
| | | /// <returns>The scene member.</returns> |
| | | /// <param name="scenesId">Scenes identifier.</param> |
| | | public static async System.Threading.Tasks.Task<RemoveSceneMemberResponseAllData> RemoveSceneMemberAsync(SceneRemoveMemberData sceneRemoveMemberData) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | RemoveSceneMemberResponseAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new RemoveSceneMemberResponseAllData { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new RemoveSceneMemberResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RemoveSceneMemberResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "Scene/RemoveMember_Respon") |
| | | { |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.removeSceneMemberResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveSceneMemberResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (scene.removeSceneMemberResponseData == null) |
| | | { |
| | | d = new RemoveSceneMemberResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RemoveSceneMemberResponseAllData { removeSceneMemberResponseData = scene.removeSceneMemberResponseData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/RemoveMember_Actions 启动" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | |
| | | try{ |
| | | if (sceneRemoveMemberData != null) |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 802 } }; |
| | | var deviceList = new JArray { }; |
| | | foreach (var deviceInfo in sceneRemoveMemberData.DeviceList) |
| | | { |
| | | if (deviceInfo.Type == 0) |
| | | { |
| | | var dInfo = new JObject{ |
| | | { "Type", deviceInfo.Type}, |
| | | { "DeviceAddr",deviceInfo.DeviceAddr}, |
| | | { "Epoint",deviceInfo.Epoint}, |
| | | { "DelayTime", deviceInfo.DelayTime} , |
| | | { "MemberNumber",deviceInfo.MemberNumber}, |
| | | }; |
| | | deviceList.Add(dInfo); |
| | | } |
| | | else if (deviceInfo.Type == 1) |
| | | { |
| | | var dInfo = new JObject{ |
| | | { "Type", deviceInfo.Type}, |
| | | { "ElseScenesId",deviceInfo.ElseScenesId}, |
| | | { "DelayTime", deviceInfo.DelayTime} , |
| | | { "MemberNumber",deviceInfo.MemberNumber}, |
| | | }; |
| | | deviceList.Add(dInfo); |
| | | } |
| | | else if (deviceInfo.Type == 2) |
| | | { |
| | | var dInfo = new JObject{ |
| | | { "Type", deviceInfo.Type}, |
| | | { "DelayTime", deviceInfo.DelayTime} , |
| | | { "MemberNumber",deviceInfo.MemberNumber}, |
| | | }; |
| | | deviceList.Add(dInfo); |
| | | } |
| | | |
| | | } |
| | | |
| | | var data = new JObject { |
| | | {"ScenesId",sceneRemoveMemberData.ScenesId}, |
| | | { "DeviceList", deviceList } |
| | | }; |
| | | jObject.Add("Data", data); |
| | | mainGateway.Send(("Scene/RemoveMember"),System.Text.Encoding.UTF8.GetBytes(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 RemoveSceneMemberResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/RemoveMember_Actions 退出" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 从场景中移除成员 |
| | | /// </summary> |
| | | public SceneRemoveMemberData sceneRemoveMemberData; |
| | | /// <summary> |
| | | /// 从场景中移除成员 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneRemoveMemberData |
| | | { |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | /// 设备列表 ,要移除的设备 |
| | | /// </summary> |
| | | public List<RemoveSceneDeviceListInfo> DeviceList = new List<RemoveSceneDeviceListInfo>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除场景成员信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveSceneDeviceListInfo |
| | | { |
| | | /// <summary> |
| | | /// 移除成员类型 |
| | | ///<para >0:设备成员</para> |
| | | ///<para >1:场景成员</para> |
| | | ///<para >2:延时类型</para> |
| | | /// </summary> |
| | | public int Type; |
| | | |
| | | /// <summary> |
| | | /// 设备mac地址 |
| | | /// <para>当Type=0时存在</para> |
| | | /// </summary> |
| | | public string DeviceAddr; |
| | | |
| | | /// <summary> |
| | | /// 设备端口号 |
| | | /// 当Type=0时存在 |
| | | /// </summary> |
| | | public int Epoint; |
| | | |
| | | /// <summary> |
| | | /// 场景成员id |
| | | /// 当Type=1时存在 |
| | | /// </summary> |
| | | public int ElseScenesId; |
| | | |
| | | /// <summary> |
| | | /// 延时执行时间,单位秒 |
| | | /// 当Type=2时存在 |
| | | /// </summary> |
| | | public int DelayTime; |
| | | /// <summary> |
| | | /// 延时执行序号,表示延时索引 |
| | | ///当Type=2时存在 |
| | | /// </summary> |
| | | public int MemberNumber; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除场景成员信息反馈,网关反馈信息 |
| | | /// </summary> |
| | | public RemoveSceneMemberResponseAllData removeSceneMemberResponseAllData; |
| | | /// <summary> |
| | | /// 移除场景成员信息反馈,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveSceneMemberResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 移除场景成员信息反馈 |
| | | /// </summary> |
| | | public RemoveSceneMemberResponseData removeSceneMemberResponseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除场景成员信息反馈 |
| | | /// </summary> |
| | | public RemoveSceneMemberResponseData removeSceneMemberResponseData; |
| | | /// <summary> |
| | | /// 移除场景成员信息反馈 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveSceneMemberResponseData |
| | | { |
| | | /// <summary> |
| | | /// 0 移除成功 |
| | | ///<para>1 场景ID不存在</para> |
| | | /// </summary> |
| | | public int Result = 2; |
| | | |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | /// <summary> |
| | | /// 移除设备列表 ,Result=0时存在。 |
| | | /// </summary> |
| | | public List<RemoveSceneDeviceListResponseInfo> RemoveList = new List<RemoveSceneDeviceListResponseInfo>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除场景成员信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveSceneDeviceListResponseInfo |
| | | { |
| | | /// <summary> |
| | | /// 0:移除成功 |
| | | ///<para >1:移除失败,成员不存在场景中</para> |
| | | /// </summary> |
| | | public int RemoveResult = 999; |
| | | /// <summary> |
| | | /// 移除成员类型 |
| | | ///<para >0:设备成员</para> |
| | | ///<para >1:其他场景</para> |
| | | /// </summary> |
| | | public int Type; |
| | | |
| | | /// <summary> |
| | | /// 设备mac地址 |
| | | /// <para>当Type=0时存在</para> |
| | | /// </summary> |
| | | public string DeviceAddr; |
| | | |
| | | /// <summary> |
| | | /// 设备端口号 当Type=0时存在 |
| | | /// </summary> |
| | | public int Epoint; |
| | | |
| | | /// <summary> |
| | | /// 场景成员id,当Type=1时存在 |
| | | /// </summary> |
| | | public int ElseScenesId; |
| | | } |
| | | #endregion |
| | | |
| | | #region 修改场景名称 |
| | | ///<summary > |
| | | /// 修改场景名称. |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<SceneRenameResponseAllData> RenameSceneAsync(int scenesId, string scenesName) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | SceneRenameResponseAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new SceneRenameResponseAllData { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new SceneRenameResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SceneRenameResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/Rename_Respon") |
| | | { |
| | | var scene = new Scene() { DataID = jobject.Value<int>("DataID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.sceneRenameResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneRenameResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (scene.sceneRenameResponseData == null) |
| | | { |
| | | d = new SceneRenameResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SceneRenameResponseAllData { sceneRenameResponseData = scene.sceneRenameResponseData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/Rename_Actions 启动" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | try{ |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 804 } }; |
| | | var data = new JObject { { "ScenesId", scenesId }, { "ScenesName", scenesName } }; |
| | | jObject.Add("Data", data); |
| | | mainGateway.Send(("Scene/Rename"),System.Text.Encoding.UTF8.GetBytes(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 SceneRenameResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/Rename_Actions 退出" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 修改场景名称,网关反馈信息 |
| | | /// </summary> |
| | | public SceneRenameResponseAllData sceneRenameResponseAllData; |
| | | ///<summary > |
| | | /// 修改场景名称 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneRenameResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 修改场景名称 |
| | | /// </summary> |
| | | public SceneRenameResponseData sceneRenameResponseData; |
| | | } |
| | | |
| | | ///<summary > |
| | | /// 修改场景名称 |
| | | /// </summary> |
| | | public SceneRenameResponseData sceneRenameResponseData; |
| | | ///<summary > |
| | | /// 修改场景名称 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneRenameResponseData |
| | | { |
| | | /// <summary> |
| | | ///结果 |
| | | ///<para>0 修改失败</para> |
| | | ///<para>1 修改成功</para> |
| | | ///<para>2 没有在该场景</para> |
| | | /// </summary> |
| | | public int Result=999; |
| | | |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | /// 场景名称 |
| | | /// </summary> |
| | | public string ScenesName; |
| | | } |
| | | #endregion |
| | | |
| | | #region 删除场景 |
| | | ///<summary > |
| | | /// 删除场景 |
| | | /// <para>返回结果 0 移除失败</para> |
| | | ///<para>返回结果 1 移除成功</para> |
| | | ///<para>返回结果 2 没有该场景</para> |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<RemoveSceneAllData> DeleteSceneAsync(int scenesId) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | RemoveSceneAllData d =null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new RemoveSceneAllData { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new RemoveSceneAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new RemoveSceneAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/Remove_Respon") |
| | | { |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.removeSceneData = Newtonsoft.Json.JsonConvert.DeserializeObject<RemoveSceneData>(jobject["Data"].ToString()); |
| | | if (scene.removeSceneData == null) |
| | | { |
| | | d = new RemoveSceneAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | return; |
| | | } |
| | | else |
| | | { |
| | | for (int listCount = 0; listCount < ZigBee.Device.ZbGateway.AllSceneList.Count; listCount++) |
| | | { |
| | | var sc = ZbGateway.AllSceneList[listCount]; |
| | | |
| | | if (scene.removeSceneData.ScenesId == sc.ScenesId) |
| | | { |
| | | ZigBee.Device.ZbGateway.AllSceneList.RemoveAt(listCount); |
| | | listCount--; |
| | | } |
| | | } |
| | | d = new RemoveSceneAllData { removeSceneData = scene.removeSceneData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/Remove_Actions 启动" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | try{ |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 803 } }; |
| | | var data = new JObject { { "ScenesId", scenesId } }; |
| | | jObject.Add("Data", data); |
| | | mainGateway.Send(("Scene/Remove"),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 RemoveSceneAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/Remove_Actions 退出" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除场景,网关反馈信息 |
| | | /// </summary> |
| | | public RemoveSceneAllData removeSceneAllData; |
| | | /// <summary> |
| | | /// 移除场景,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveSceneAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 移除场景 |
| | | /// </summary> |
| | | public RemoveSceneData removeSceneData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 移除场景数据 |
| | | /// </summary> |
| | | public RemoveSceneData removeSceneData; |
| | | /// <summary> |
| | | /// 移除场景数据 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class RemoveSceneData |
| | | { |
| | | /// <summary> |
| | | ///0 移除失败 |
| | | ///<para>1 移除成功</para> |
| | | ///<para>2 没有该场景</para> |
| | | /// </summary> |
| | | public int Result=999; |
| | | |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | } |
| | | #endregion |
| | | |
| | | #region 调用场景 |
| | | ///<summary > |
| | | ///调用场景 |
| | | /// <para>DelayTime:延时执行时间,单位秒</para> |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<SceneOpenAllData> ControlSceneAsync(int ScenesId,int delayTime) |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | SceneOpenAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new SceneOpenAllData { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new SceneOpenAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SceneOpenAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | |
| | | if (topic == gatewayID + "/" + "Scene/Open_Respon") |
| | | { |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.sceneOpen = Newtonsoft.Json.JsonConvert.DeserializeObject<SceneOpenData>(jobject["Data"].ToString()); |
| | | if (scene.sceneOpen == null) |
| | | { |
| | | d = new SceneOpenAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new SceneOpenAllData { sceneOpenData = scene.sceneOpen }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/Open_Actions 启动" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | try{ |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 821 } }; |
| | | var data = new JObject { { "ScenesId", ScenesId }, { "DelayTime", delayTime } }; |
| | | jObject.Add("Data", data); |
| | | mainGateway.Send(("Scene/Open"),System.Text.Encoding.UTF8.GetBytes(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 SceneOpenAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/Open_Actions退出" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 调用场景,网关反馈信息 |
| | | /// <para>返回Result 0:调用失败</para> |
| | | ///<para>Result 1:调用成功<para> |
| | | /// </summary> |
| | | public SceneOpenAllData sceneOpenAllData; |
| | | /// <summary> |
| | | /// 调用场景,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneOpenAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 调用场景 |
| | | /// </summary> |
| | | public SceneOpenData sceneOpenData; |
| | | } |
| | | |
| | | ///<summary > |
| | | /// 调用场景 |
| | | /// </summary> |
| | | public SceneOpenData sceneOpen; |
| | | ///<summary > |
| | | /// 调用场景 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneOpenData |
| | | { |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | /// <summary> |
| | | ///结果 |
| | | ///<para>Result 0:调用失败</para> |
| | | ///<para>Result 1:调用成功<para> |
| | | /// </summary> |
| | | public int Result=999; |
| | | |
| | | /// <summary> |
| | | /// 延时时间 |
| | | /// </summary> |
| | | public int DelayTime; |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | #region 查看正在延时的场景 |
| | | /// <summary> |
| | | /// 查看正在延时的场景. |
| | | /// </summary> |
| | | public static async System.Threading.Tasks.Task<CatDelaySceneResponseAllData> CatDelaySceneAsync() |
| | | { |
| | | return await System.Threading.Tasks.Task.Run(async () => |
| | | { |
| | | CatDelaySceneResponseAllData d = null; |
| | | var mainGateway = ZbGateway.MainGateWay; |
| | | if (mainGateway == null) |
| | | { |
| | | d = new CatDelaySceneResponseAllData { errorMessageBase = "当前没有主网关" }; |
| | | return d; |
| | | } |
| | | 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 = mainGateway.getGatewayBaseInfo.gwID }; |
| | | var temp = Newtonsoft.Json.JsonConvert.DeserializeObject<ErrorResponData>(jobject["Data"].ToString()); |
| | | |
| | | if (temp == null) |
| | | { |
| | | d = new CatDelaySceneResponseAllData { errorMessageBase = "网关错误回复,且数据是空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new CatDelaySceneResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) }; |
| | | } |
| | | } |
| | | if (topic == gatewayID + "/" + "Scene/CatDelayScene_Respon") |
| | | { |
| | | var scene = new Scene() { DataID = jobject.Value<int>("Data_ID"), GateWayId = mainGateway.CurrentGateWayId }; |
| | | scene.catDelaySceneResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<CatDelaySceneResponseData>(jobject["Data"].ToString()); |
| | | |
| | | if (scene.catDelaySceneResponseData == null) |
| | | { |
| | | d = new CatDelaySceneResponseAllData { errorMessageBase = "网关返回的数据为空" }; |
| | | } |
| | | else |
| | | { |
| | | d = new CatDelaySceneResponseAllData { catDelaySceneResponseData = scene.catDelaySceneResponseData }; |
| | | System.Console.WriteLine($"UI收到通知后的主题_{ topic}"); |
| | | } |
| | | } |
| | | }; |
| | | mainGateway.Actions += action; |
| | | System.Console.WriteLine("Scene/CatDelayScene_Actions 启动" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | try |
| | | { |
| | | var jObject = new JObject { { "Cluster_ID", 0 }, { "Command", 811 } }; |
| | | mainGateway.Send(("Scene/CatDelayScene"),System.Text.Encoding.UTF8.GetBytes(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 CatDelaySceneResponseAllData { errorMessageBase = " 回复超时,请重新操作" }; |
| | | } |
| | | mainGateway.Actions -= action; |
| | | System.Console.WriteLine("Scene/CatDelayScene_Actions 退出" + "_" + mainGateway.getGatewayBaseInfo.gwID + System.DateTime.Now.ToString()); |
| | | |
| | | return d; |
| | | }); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查看正在延时的场景信息信息反馈,网关反馈信息 |
| | | /// </summary> |
| | | public CatDelaySceneResponseAllData catDelaySceneResponseAllData; |
| | | /// <summary> |
| | | /// 查看正在延时的场景信息反馈,网关反馈信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class CatDelaySceneResponseAllData |
| | | { |
| | | /// <summary> |
| | | /// 错误信息 |
| | | /// </summary> |
| | | public string errorMessageBase; |
| | | /// <summary> |
| | | /// 网关信息错误反馈 |
| | | /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para> |
| | | /// </summary> |
| | | public ErrorResponData errorResponData; |
| | | /// <summary> |
| | | /// 查看正在延时的场景信息信息反馈 |
| | | /// </summary> |
| | | public CatDelaySceneResponseData catDelaySceneResponseData; |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 查看正在延时的场景信息反馈 |
| | | /// </summary> |
| | | public CatDelaySceneResponseData catDelaySceneResponseData; |
| | | /// <summary> |
| | | /// 查看正在延时的场景信息反馈 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class CatDelaySceneResponseData |
| | | { |
| | | /// <summary> |
| | | /// 正在延时执行的场景 |
| | | /// </summary> |
| | | public List<DelayScenesListResponseInfo> DelayScenesList = new List<DelayScenesListResponseInfo>(); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 正在延时执行的场景信息 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class DelayScenesListResponseInfo |
| | | { |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId ; |
| | | /// <summary> |
| | | /// 延时时间 |
| | | /// </summary> |
| | | public int DelayTime; |
| | | |
| | | /// <summary> |
| | | /// 剩余触发时间,单位秒 |
| | | /// </summary> |
| | | public int RemainTime; |
| | | } |
| | | #endregion |
| | | |
| | | ///<summary > |
| | | /// 场景被破坏反馈 |
| | | /// </summary> |
| | | public SceneBreak sceneBreak; |
| | | ///<summary > |
| | | /// 场景被破坏反馈 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneBreak |
| | | { |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | } |
| | | |
| | | ///<summary > |
| | | /// 场景动作被执行通知 |
| | | /// </summary> |
| | | public SceneExecRespon sceneExecRespon; |
| | | ///<summary > |
| | | /// 场景动作被执行通知 |
| | | /// </summary> |
| | | [System.Serializable] |
| | | public class SceneExecRespon |
| | | { |
| | | /// <summary> |
| | | /// 场景ID |
| | | /// </summary> |
| | | public int ScenesId; |
| | | |
| | | } |
| | | |
| | | //public static string SceneFilePath = "SceneFile"; |
| | | |
| | | //static Scene() |
| | | //{ |
| | | // if (null == Newtonsoft.Json.JsonConvert.DeserializeObject<List<string>>(Encoding.UTF8.GetString(Shared.IO.FileUtils.ReadFile(SceneFilePath)))) |
| | | // { |
| | | // //初始化场景列表 |
| | | // Shared.IO.FileUtils.WriteFileByBytes(SceneFilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(new List<string>()))); |
| | | // } |
| | | //} |
| | | |
| | | ///// <summary> |
| | | ///// 保存当前场景 |
| | | ///// </summary> |
| | | ///// <param name="scenceFilePath">Scence file path.</param> |
| | | //public void Save(string scenceFilePath) |
| | | //{ |
| | | // Shared.IO.FileUtils.WriteFileByBytes(scenceFilePath, System.Text.Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this))); |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 根据场景路径恢复场景对象 |
| | | /// </summary> |
| | | /// <returns>The by file path.</returns> |
| | | /// <param name="sceneFilePath">Room file path.</param> |
| | | //public static Scene GetSceneByFilePath(string sceneFilePath) |
| | | //{ |
| | | // try |
| | | // { |
| | | // return Newtonsoft.Json.JsonConvert.DeserializeObject<Scene>(System.Text.Encoding.UTF8.GetString(Shared.IO.FileUtils.ReadFile(sceneFilePath))); |
| | | // } |
| | | // catch |
| | | // { |
| | | // return new Scene(); |
| | | // } |
| | | //} |
| | | |
| | | /// <summary> |
| | | /// 场景标识 |
| | | /// </summary> |
| | | //public bool SceneLabel = false; |
| | | |
| | | /// <summary> |
| | | /// 控制目标的文件路径,格式如:RoomScene_+DeviceID_Mac_Epoint |
| | | /// </summary> |
| | | //public readonly List<string> DeviceFilePathList = new List<string>(); |
| | | |
| | | /// <summary> |
| | | /// 场景的背景图 |
| | | /// </summary> |
| | | //public string BackgroundImagePath = "Scene/s1.png"; |
| | | |
| | | /// <summary> |
| | | /// 场景中的设备列表 |
| | | /// </summary> |
| | | //[Newtonsoft.Json.JsonIgnore] |
| | | //public List<Scene> sceneDeviceList = new List<Scene>(); |
| | | |
| | | //[Newtonsoft.Json.JsonIgnore] |
| | | //public List<Scene> LocalSceneList = new List<Scene>(); |
| | | |
| | | //public SceneId SceneID; |
| | | |
| | | ///<summary > |
| | | /// 从网关的场景中移除设备 |
| | | /// </summary> |
| | | //public static void SceneRemoveMember1(ZigBee.Device.ZbGateway gateway, int ScenesId, string DeviceAddr, int Epoint) |
| | | //{ |
| | | // var jobject = new JObject { { "Cluster_ID", 0 }, { "Command", 802 } }; |
| | | // var DeviceList = new JArray |
| | | // { |
| | | // new JObject { |
| | | // { "Type", 0}, |
| | | // { "DeviceAddr",DeviceAddr}, |
| | | // { "Epoint",Epoint} |
| | | // } |
| | | // }; |
| | | // var data = new JObject { |
| | | // {"ScenesId",ScenesId}, |
| | | // { "DeviceList", DeviceList } |
| | | // }; |
| | | // jobject.Add("Data", data); |
| | | // gateway.Send(("Scene/RemoveMember"), Common.SecuritySet.Encryption((jobject.ToString()))); |
| | | |
| | | //} |
| | | |
| | | ///<summary > |
| | | /// 删除场景 |
| | | /// </summary> |
| | | //public static void SceneRemove1(ZigBee.Device.ZbGateway gateway, int scenesId) |
| | | //{ |
| | | // var jobject = new JObject { { "Cluster_ID", 0 }, { "Command", 803 } }; |
| | | // var data = new JObject { { "ScenesId", scenesId } }; |
| | | // jobject.Add("Data", data); |
| | | // gateway.Send(("Scene/Remove"), Common.SecuritySet.Encryption((jobject.ToString()))); |
| | | //} |
| | | |
| | | ///<summary > |
| | | /// 修改场景名称 |
| | | /// </summary> |
| | | //public static void SceneRename1(ZigBee.Device.ZbGateway gateway, int scenesId, string scenesName) |
| | | //{ |
| | | // var jobject = new JObject { { "Cluster_ID", 0 }, { "Command", 804 } }; |
| | | // var data = new JObject { { "ScenesId", scenesId }, { "ScenesName", scenesName } }; |
| | | // jobject.Add("Data", data); |
| | | // gateway.Send(("Scene/Rename"), Common.SecuritySet.Encryption((jobject.ToString()))); |
| | | //} |
| | | |
| | | ///<summary > |
| | | /// 获取网关中场景信息 |
| | | /// </summary> |
| | | //public static void SceneGetInfo1(ZigBee.Device.ZbGateway gateway) |
| | | //{ |
| | | // var jobject = new JObject { { "Cluster_ID", 0 }, { "Command", 805 } }; |
| | | // gateway.Send(("Scene/GetInfo"), Common.SecuritySet.Encryption((jobject.ToString()))); |
| | | //} |
| | | |
| | | ///<summary > |
| | | ///获取网关中场景的设备列表 |
| | | /// </summary> |
| | | //public static void SceneGetDeviceList1(ZigBee.Device.ZbGateway gateway, int ScenesId) |
| | | //{ |
| | | // var jobject = new JObject { { "Cluster_ID", 0 }, { "Command", 806 } }; |
| | | // var data = new JObject { { "ScenesId", ScenesId } }; |
| | | // jobject.Add("Data", data); |
| | | // gateway.Send(("Scene/GetDeviceList"), Common.SecuritySet.Encryption((jobject.ToString()))); |
| | | //} |
| | | |
| | | ///<summary > |
| | | /// 获取所有场景信息(包括场景设备列表) |
| | | /// </summary> |
| | | //public static void SceneGetAllInfo1(ZigBee.Device.ZbGateway gateway) |
| | | //{ |
| | | // var jobject = new JObject { { "Cluster_ID", 0 }, { "Command", 807 } }; |
| | | // gateway.Send(("Scene/GetAllInfo"), Common.SecuritySet.Encryption((jobject.ToString()))); |
| | | //} |
| | | |
| | | ///<summary > |
| | | ///调用场景 |
| | | /// </summary> |
| | | //public static void SceneOpen1(ZigBee.Device.ZbGateway gateway, int ScenesId) |
| | | //{ |
| | | // var jobject = new JObject { { "Cluster_ID", 0 }, { "Command", 808 } }; |
| | | // var data = new JObject { { "ScenesId", ScenesId } }; |
| | | // jobject.Add("Data", data); |
| | | // gateway.Send(("Scene/Open"), Common.SecuritySet.Encryption((jobject.ToString()))); |
| | | //} |
| | | } |
| | | } |