黄学彪
2020-07-13 23420922845c9e77019a55c3b3e3271eb1ec261e
ZigbeeApp/Shared/Phone/ZigBee/Device/CommonDevice.cs
@@ -850,6 +850,109 @@
        }
        #endregion
        #region 一键更新四寸屏按键属性
        /// <summary>
        /// 同步设备功能
        /// </summary>
        /// <returns></returns>
        public async System.Threading.Tasks.Task<SynchronizationDeviceResponseAllData> SyncMsgToBindSource(string deviceAddr, int deviceEpoint)
        {
            if (Gateway == null)
            {
                return null;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
            {
                SynchronizationDeviceResponseAllData resContent = 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)
                        {
                            resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            resContent = new SynchronizationDeviceResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "Bind/SyncMsgToBindSourceRespon")
                    {
                        var res = Newtonsoft.Json.JsonConvert.DeserializeObject<int>(jobject["Data"]["Result"].ToString());
                        if (res == null)
                        {
                            resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                            resContent = new SynchronizationDeviceResponseAllData { result = res };
                            System.Console.WriteLine($"UI收到通知后的主题_{ topic}");
                        }
                    }
                };
                Gateway.Actions = action;
                DebugPrintLog("Bind/SyncMsgToBindSourceRespon_Actions 启动" + "_" + System.DateTime.Now.ToString());
                try
                {
                    var jObject = new JObject { { "DeviceAddr", deviceAddr }, { "Epoint", deviceEpoint }, { "Cluster_ID", 0 }, { "Command", 5010 } };
                    Gateway.Send("Bind/SyncMsgToBindSource", jObject.ToString());
                }
                catch { }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (resContent != null)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    resContent = new SynchronizationDeviceResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("Bind/SyncMsgToBindSource_Actions 退出" + System.DateTime.Now.ToString());
                return resContent;
            });
        }
        /// <summary>
        /// 同步设备,网关反馈具体信息
        /// </summary>
        [System.Serializable]
        public class SynchronizationDeviceResponseAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 同步结果
            /// 0:成功:网关内部自动写入设备目标名字、设备目标功能类型、场景目标名字、utc时间写入4寸屏
            /// 1:失败
            /// </summary>
            public int result;
        }
        #endregion
        #region 删除设备(使设备离网)
        /// <summary>
        /// 删除设备(使设备离网)
@@ -900,7 +1003,7 @@
                    }
                };
                Gateway.Actions += action;
                System.Console.WriteLine("RemoveDevice_Actions 启动" + "_" + System.DateTime.Now.ToString());
                DebugPrintLog("RemoveDevice_Actions 启动" + "_" + System.DateTime.Now.ToString());
                try
                {
@@ -938,7 +1041,7 @@
                    d = new RemoveDeviceResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                System.Console.WriteLine("RemoveDevice_Actions 退出" + System.DateTime.Now.ToString());
                DebugPrintLog("RemoveDevice_Actions 退出" + System.DateTime.Now.ToString());
                return d;
            });