| | |
| | | /// </summary>
|
| | | private bool newGatewayGetting = false;
|
| | | /// <summary>
|
| | | /// 网关检测中
|
| | | /// 网关搜索中
|
| | | /// </summary>
|
| | | private string isGatewayChecking = "0";
|
| | | private bool isGatewaySearching = true;
|
| | |
|
| | | #endregion
|
| | |
|
| | |
| | |
|
| | | //初始化连接的假想动画效果
|
| | | this.InitConcetionAnimete();
|
| | | //开启网关检测的线程
|
| | | this.StartCheckGatewayThread();
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | btnReDo.Gravity = Gravity.CenterHorizontal;
|
| | | btnReDo.TextAlignment = TextAlignment.Center;
|
| | | btnReDo.TextID = R.MyInternationalizationString.uReDoAgain;
|
| | | frameback.AddChidren(btnReDo, ChidrenBindMode.BindEventOnly);
|
| | | frameback.AddChidren(btnReDo, ChidrenBindMode.BindEvent);
|
| | | frameback.ButtonClickEvent += (sender, e) =>
|
| | | {
|
| | | //初始化初始中部控件
|
| | |
| | | string strMsg = btnMsg.Text;
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | //清空全部列表
|
| | | HdlGatewayLogic.Current.ClearAllRealGateway();
|
| | | ZigBee.Common.Application.IsSearchingGateway = true;
|
| | |
|
| | | int index = 1;
|
| | | //计时时间
|
| | | int timeCount = 0;
|
| | |
| | | //5秒后清空网关列表
|
| | | HdlGatewayLogic.Current.ClearAllRealGateway();
|
| | | ZigBee.Common.Application.IsSearchingGateway = true;
|
| | | }
|
| | | if (timeCount % 4 == 0 && timeCount >= 10)
|
| | | {
|
| | | lock (isGatewayChecking)
|
| | | {
|
| | | if (isGatewayChecking != "1")
|
| | | {
|
| | | isGatewayChecking = "1";
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | //每2秒检测搜索到的网关
|
| | | await this.CheckZbGatewayAndSetRow();
|
| | | lock (isGatewayChecking)
|
| | | {
|
| | | isGatewayChecking = "0";
|
| | | }
|
| | | });
|
| | | }
|
| | | }
|
| | | }
|
| | | if (timeCount % 2 == 0)
|
| | | {
|
| | |
| | |
|
| | | System.Threading.Thread.Sleep(500);
|
| | | }
|
| | | //搜索结束
|
| | | this.isGatewaySearching = false;
|
| | |
|
| | | if (timeOut <= 0)
|
| | | {
|
| | | HdlThreadLogic.Current.RunMain(() =>
|
| | |
| | | #region ■ 网关检测___________________________
|
| | |
|
| | | /// <summary>
|
| | | /// 开启网关检测的线程
|
| | | /// </summary>
|
| | | private void StartCheckGatewayThread()
|
| | | {
|
| | | this.isGatewaySearching = true;
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | int count = 0;
|
| | | while (this.Parent != null && this.isGatewaySearching == true)
|
| | | {
|
| | | //每2秒检测搜索到的网关
|
| | | System.Threading.Thread.Sleep(500);
|
| | | count++;
|
| | | if (count < 4)
|
| | | {
|
| | | //主要为了快一点能够中断这个线程
|
| | | continue;
|
| | | }
|
| | | count = 0;
|
| | |
|
| | | await this.CheckZbGatewayAndSetRow();
|
| | |
|
| | | if (this.newGatewayGetting == true)
|
| | | {
|
| | | //获取得到新网关,则中断线程
|
| | | break;
|
| | | }
|
| | | }
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 检测搜索到的网关
|
| | | /// </summary>
|
| | | private async Task<bool> CheckZbGatewayAndSetRow()
|
| | | {
|
| | | var listCheck = new HashSet<string>();
|
| | | for (int i = 0; i < ZbGateway.GateWayList.Count; i++)
|
| | | {
|
| | | var way = ZbGateway.GateWayList[i];
|
| | | var wayId = HdlGatewayLogic.Current.GetGatewayId(way);
|
| | | var wayId = way.GwId;
|
| | | if (dicZbGatewayDiv.ContainsKey(wayId) == true)
|
| | | {
|
| | | //已经处理了
|
| | |
| | | GatewayBindMode mode = GatewayBindMode.BindAgain;
|
| | | //如果是第一次绑定,或者是以前已经绑定过了的
|
| | | if (HdlGatewayLogic.Current.HomeIdIsEmpty(way) == true
|
| | | || way.getGatewayBaseInfo.HomeId == Common.Config.Instance.HomeId)
|
| | | || way.HomeId == Common.Config.Instance.HomeId)
|
| | | {
|
| | | if (way.getGatewayBaseInfo.HomeId != Common.Config.Instance.HomeId)
|
| | | if (way.HomeId != Common.Config.Instance.HomeId)
|
| | | {
|
| | | //第一次绑定,也就是网关住宅ID为空
|
| | | mode = GatewayBindMode.First;
|
| | |
| | | this.newGatewayGetting = true;
|
| | | }
|
| | |
|
| | | if (mode == GatewayBindMode.First)
|
| | | if (mode == GatewayBindMode.First || mode == GatewayBindMode.Binded)
|
| | | {
|
| | | //我觉得这里需要获取一下新网关的设备列表
|
| | | Common.LocalDevice.Current.SetDeviceToMemmoryByGateway(way);
|