WJC
2020-03-23 bba578c2f0acf2eca747edcb69426771e0cadd32
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceSearchForm.cs
@@ -60,6 +60,10 @@
        /// 进度值的显示文本
        /// </summary>
        private NormalViewControl btnProgressView = null;
        /// <summary>
        /// 网关是否允许入网的标识
        /// </summary>
        private bool gatewayCanAddDevice = false;
        #endregion
@@ -138,20 +142,8 @@
            btnProgressView.Text = "0%";
            frameProgress.AddChidren(btnProgressView);
            HdlThreadLogic.Current.RunThread(() =>
            {
                //蓝才刚说有时候网关会收不到入网的命令,所以发三次
                for (int i = 0; i < 3; i++)
                {
                    if (this.Parent == null)
                    {
                        return;
                    }
                    //让网关允许入网
                    this.realGateway.AddNewDeviceToGateway(180);
                    System.Threading.Thread.Sleep(1000);
                }
            });
            //允许设备入网
            this.StartDeviceCanAddToGateway(false);
            //添加监视设备新上报的事件
            this.realGateway.GwResDataAction += this.AdjustGatewayResultData;
@@ -343,12 +335,18 @@
                while (this.Parent != null)
                {
                    System.Threading.Thread.Sleep(500);
                    timeCount++;
                    if (timeCount >= 240)
                    //网关允许设备入网后才开始计时
                    if (this.gatewayCanAddDevice == true)
                    {
                        //120秒后,再次发送网关设备入网命令
                        this.realGateway.AddNewDeviceToGateway(180);
                        timeCount++;
                        if (timeCount >= 360)
                        {
                            this.gatewayCanAddDevice = false;
                            //再次发送允许设备入网
                            this.StartDeviceCanAddToGateway(true);
                        timeCount = 0;
                        }
                    }
                    Application.RunOnMainThread(() =>
                    {
@@ -378,15 +376,34 @@
        /// <returns></returns>
        private int CheckIsDeviceComming(string topic, string resultData)
        {
            if (topic == gatewayId + "/Device/DeviceAnnounce_Respon")
            if (topic == gatewayId + "/Device/SearchNewDevice")
            {
                //网关回复设备已经可以入网
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<SearchNewDeviceResult>(jobject["Data"].ToString());
                if (info.time > 0)
                {
                    this.gatewayCanAddDevice = true;
                }
                return 0;
            }
            else if (topic == gatewayId + "/Device/DeviceAnnounce_Respon")
            {
                this.topTimeOut = topMaxTime;
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceAnnounceInfo>(jobject["Data"].ToString());
                if (info.IsNew == 6 || info.IsNew == 7)
                {
                    return 0;
                }
                //网关告知客户端有设备声明
                this.SetDeviceProgressValue(1);
                return 2;
            }
            else if (topic == gatewayId + "/Device/DeviceGetActiveEP_Respon")
            {
                this.topTimeOut = topMaxTime;
                //网关告知客户端获取设备活动端点信息
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
@@ -397,13 +414,13 @@
                    HdlLogLogic.Current.WriteLog(-1, resultData);
                    return 2;
                }
                this.topTimeOut = topMaxTime;
                //设置进度值
                this.SetDeviceProgressValue(2);
                return 2;
            }
            else if (topic == gatewayId + "/Device/DeviceGetActiveEPSimpleDesc_Respon")
            {
                this.topTimeOut = topMaxTime;
                //网关告知客户端获取设备所有活动端点简单描述符信息
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
@@ -414,13 +431,13 @@
                    HdlLogLogic.Current.WriteLog(-1, resultData);
                    return 2;
                }
                this.topTimeOut = topMaxTime;
                //设置进度值
                this.SetDeviceProgressValue(3);
                return 2;
            }
            else if (topic == gatewayId + "/Device/DeviceGetDefaultBind_Respon")
            {
                this.topTimeOut = topMaxTime;
                //网关告知客户端获取设备默认绑定表信息
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
@@ -431,13 +448,13 @@
                    HdlLogLogic.Current.WriteLog(-1, resultData);
                    return 2;
                }
                this.topTimeOut = topMaxTime;
                //设置进度值
                this.SetDeviceProgressValue(4);
                return 2;
            }
            else if (topic == gatewayId + "/Device/DeviceAutoBindZBCoord_Respon")
            {
                this.topTimeOut = topMaxTime;
                //网关告知客户端设备自动绑定协调器信息
                var jobject = Newtonsoft.Json.Linq.JObject.Parse(resultData);
                var info = Newtonsoft.Json.JsonConvert.DeserializeObject<DeviceResultInfo>(jobject["Data"].ToString());
@@ -448,7 +465,6 @@
                    HdlLogLogic.Current.WriteLog(-1, resultData);
                    return 2;
                }
                this.topTimeOut = topMaxTime;
                //设置进度值
                this.SetDeviceProgressValue(5);
                return 2;
@@ -521,6 +537,33 @@
        #endregion
        #region ■ 允许设备入网_______________________
        /// <summary>
        /// 允许设备入网
        /// </summary>
        /// <param name="close"></param>
        private void StartDeviceCanAddToGateway(bool close)
        {
            HdlThreadLogic.Current.RunThread(() =>
            {
                if (close == true)
                {
                    //关闭入网模式
                    this.realGateway.AddNewDeviceToGateway(0);
                    System.Threading.Thread.Sleep(2000);
                }
                while (gatewayCanAddDevice == false && this.Parent != null)
                {
                    //让网关允许入网
                    this.realGateway.AddNewDeviceToGateway(180);
                    System.Threading.Thread.Sleep(6000);
                }
            });
        }
        #endregion
        #region ■ 画面关闭___________________________
        /// <summary>
@@ -555,6 +598,28 @@
            public int Result = -1;
        }
        /// <summary>
        /// 网关告知客户端有设备声明
        /// </summary>
        private class DeviceAnnounceInfo
        {
            /// <summary>
            /// 蓝才刚说 6和7 这两个是设备重启上报的,目前暂时不能显示到入网步骤那里的
            /// </summary>
            public int IsNew = -1;
        }
        /// <summary>
        /// 网关回复允许设备入网
        /// </summary>
        private class SearchNewDeviceResult
        {
            /// <summary>
            /// 允许设备入网的时间
            /// </summary>
            public int time = 0;
        }
        #endregion
    }
}