黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
using System;
using System.Collections.Generic;
using System.Text;
using ZigBee.Device;
 
namespace Shared.Phone
{
    /// <summary>
    /// HDL设备升级的逻辑
    /// </summary>
    public class HdlDeviceUpdateLogic : DeviceUpdateCommon
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// <para>更新状态变化的事件</para>
        /// <para>第一个参数为:</para>
        /// <para>-1:更新异常,后面的值为异常信息的翻译文本</para>
        /// <para> 0:更新状态正常变化,后面的值为状态变更的文本翻译</para>
        /// <para> 1:升级成功</para>
        /// <para> 2:主动终止升级</para>
        /// <para> 3:从等待中取消(目前还没有用)</para>
        /// </summary>
        public Action<int, string> UpdateStatuChangedEvent = null;
        /// <summary>
        /// 进度值事件
        /// </summary>
        public Action<decimal> ProgressEvent = null;
        /// <summary>
        /// 设备新版本的固件信息(多个设备升级时,应该会需要公开这个对象)
        /// </summary>
        public FirmwareVersionInfo deviceFirmware = null;
 
        /// <summary>
        /// 网关
        /// </summary>
        private ZbGateway zbGateway = null;
        /// <summary>
        /// 升级的设备
        /// </summary>
        private OTADevice otaDevice = null;
        /// <summary>
        /// 前一次的最终状态
        /// </summary>
        private UpdateStatuMode oldUpdateStatu = UpdateStatuMode.None;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// <para>HDL设备升级,以下为两个重要事件</para>
        /// <para>UpdateStatuChangedEvent:更新状态变化的事件</para>
        /// <para>ProgressEvent:进度值事件</para>
        /// <para>StartUpdateReady():设备开始执行升级的函数(再次调用,内部条件达成时,可以选择终止升级),在调用这个之前,请先实现上面两个方法</para>
        /// </summary>
        /// <param name="i_otaDevice">设备</param>
        /// <param name="i_deviceFirmware">设备的固件信息</param>
        public HdlDeviceUpdateLogic(OTADevice i_otaDevice, FirmwareVersionInfo i_deviceFirmware)
        {
            this.ClassDiv = 2;
            this.otaDevice = i_otaDevice;
            this.deviceFirmware = i_deviceFirmware;
            this.zbGateway = i_otaDevice.Gateway;
        }
 
        #endregion
 
        #region ■ 开始更新___________________________
 
        /// <summary>
        /// 进入执行更新操作准备阶段(再次调用,内部条件达成时,可以选择终止升级)
        /// </summary>
        public void StartUpdateReady()
        {
            if (this.UpdateStatu == UpdateStatuMode.DeviceUpdateReady || this.UpdateStatu == UpdateStatuMode.DeviceUpdating)
            {
                //终止升级
                this.StopUpdate();
                return;
            }
 
            if (this.UpdateStatu == UpdateStatuMode.Wait)
            {
                //如果是等待模式,再次点击时,移除列表
                if (HdlFirmwareUpdateResourse.dicUpdateList.ContainsKey(otaDevice.DeviceAddr) == true)
                {
                    HdlFirmwareUpdateResourse.dicUpdateList.Remove(otaDevice.DeviceAddr);
                }
                //取消
                this.UpdateStatu = UpdateStatuMode.None;
                this.UpdateStatuChangedEvent?.Invoke(3, "");
                return;
            }
            //如果它有状态,则表示之前它被什么错误中断了
            if (this.UpdateStatu != UpdateStatuMode.None)
            {
                //保存起来,后面有用处
                this.oldUpdateStatu = this.UpdateStatu;
            }
 
            //进入等待模式
            this.UpdateStatu = UpdateStatuMode.Wait;
            HdlFirmwareUpdateResourse.dicUpdateList[otaDevice.DeviceAddr] = this;
 
            //等待中…
            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uWaitting));
 
            //执行下一个可更新的固件的更新操作
            HdlFirmwareUpdateLogic.Current.DoUpdateNextFirmware();
        }
 
        /// <summary>
        /// 开始执行更新操作(FirmwareUpdateLogic调用)
        /// </summary>
        public override void DoStartUpdate()
        {
            //状态变更
            this.IsFinishUpdate = false;
            this.UpdateStatu = UpdateStatuMode.Action;
            //根据状态执行操作
            this.DoAdjustByStatuMode();
        }
 
        /// <summary>
        /// 根据状态执行操作
        /// </summary>
        private void DoAdjustByStatuMode()
        {
            //首发时,从开始执行
            if (this.oldUpdateStatu == UpdateStatuMode.None)
            {
                //下载设备文件
                this.DownLoadDeviceFile();
            }
            //设备下载失败
            else if (this.oldUpdateStatu == UpdateStatuMode.DeviceDownLoadFail)
            {
                //下载设备文件
                this.DownLoadDeviceFile();
            }
            //设备升级失败
            else if (this.oldUpdateStatu == UpdateStatuMode.DeviceUpdateFail)
            {
                //执行设置设备升级程序的文件
                this.DoSetUpdateDeviceFile();
            }
            else
            {
                //重新再来
                this.DownLoadDeviceFile();
            }
        }
 
        #endregion
 
        #region ■ 设备下载___________________________
 
        /// <summary>
        /// 下载设备文件
        /// </summary>
        private async void DownLoadDeviceFile()
        {
            this.UpdateStatu = UpdateStatuMode.DeviceDownLoad;
 
            //设备固件正在下载…
            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceFirmwareDownLoading));
            //设置初始值
            this.SetProgressValue(0);
            //开启设备下载超时线程
            this.StartDownLoadTimeOutThread();
 
            //下载设备文件的进度
            zbGateway.ReportAction += this.DownLoadDeviceFileProgress;
            await System.Threading.Tasks.Task.Delay(1000);
 
            //下载设备文件
            var result = await this.otaDevice.DownloadFileAsync(zbGateway, this.deviceFirmware.DistributedMark, this.deviceFirmware.Name);
            if (string.IsNullOrEmpty(result.errorMessageBase) == false)
            {
                //设备固件资源下载失败
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDeviceFirmwareDownLoadFail));
 
                //显示重新下载模式
                this.ShowReDownLoadMode();
 
                zbGateway.ReportAction -= this.DownLoadDeviceFileProgress;
 
                this.UpdateStatu = UpdateStatuMode.DeviceDownLoadFail;
 
                return;
            }
        }
 
        /// <summary>
        /// 下载设备文件的进度
        /// </summary>
        /// <param name="CommadDiv"></param>
        /// <param name="objValue"></param>
        private void DownLoadDeviceFileProgress(string CommadDiv, object objValue)
        {
            if (CommadDiv != "DownloadFileProgress" || objValue == null)
            {
                return;
            }
            var tempZb = (ZbGateway)objValue;
            if (tempZb.GwId != this.zbGateway.GwId)
            {
                //不是自己的网关推送,则不处理
                return;
            }
            //刷新超时时间
            this.DownLoadTimeOutRefresh();
 
            var responData = tempZb.downloadFileProgressResponData;
            if (responData.Status == 2)
            {
                //设备固件资源下载失败
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDeviceFirmwareDownLoadFail));
                //显示重新下载模式
                this.ShowReDownLoadMode();
 
                zbGateway.ReportAction -= this.DownLoadDeviceFileProgress;
 
                this.UpdateStatu = UpdateStatuMode.DeviceDownLoadFail;
                return;
            }
            else if (responData.Status == 0)
            {
                zbGateway.ReportAction -= this.DownLoadDeviceFileProgress;
 
                //显示执行更新模式
                this.DoSetUpdateDeviceFile();
                return;
            }
 
            //设置进度
            this.SetProgressValue(responData.DownloadPercent);
        }
 
        #endregion
 
        #region ■ 设备升级___________________________
 
        /// <summary>
        /// 设置设备升级程序的文件
        /// </summary>
        private async void DoSetUpdateDeviceFile()
        {
            this.UpdateStatu = UpdateStatuMode.DeviceUpdateReady;
            //设备正在升级…
            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceUpdating));
            //设置初始值
            this.SetProgressValue(0);
 
            await System.Threading.Tasks.Task.Delay(1000);
 
            //首先指定设备升级的固件
            var result = await this.otaDevice.UpgradeDeviceAsync(this.zbGateway, this.deviceFirmware.Name);
            if (result.otaSetImageData != null && result.otaSetImageData.Result == 1)
            {
                //升级文件丢失!请重新下载!
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uLostUpdateFileAndReDownLoad));
 
                //显示重新下载模式
                this.ShowReDownLoadMode();
 
                this.UpdateStatu = UpdateStatuMode.DeviceDownLoadFail;
 
                return;
            }
            else if (result.otaSetImageData != null && result.otaSetImageData.Result == 2)
            {
                this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
 
                //判断当前设备是不是在升级中 
                string nowMainkeys = this.otaDevice.DeviceAddr;
                foreach (var devi in result.otaSetImageData.DeviceList)
                {
                    string mainkeys = devi.MacAddr;
                    if (mainkeys == nowMainkeys)
                    {
                        //它自己就在升级中 ,直接同步
                        this.SynchronizeDeviceProgress();
                        return;
                    }
                }
 
                //当前有节点设备正在升级中,请稍后再试
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uHadDeviceUpdatingAndDoAgain));
                //显示重新安装
                this.ShowReSetupMsg();
 
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
 
                return;
            }
            else if (string.IsNullOrEmpty(result.errorMessageBase) == false)
            {
                //设备升级失败
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDeviceUpdatingFail));
 
                //显示重新安装
                this.ShowReSetupMsg();
 
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
 
                return;
            }
            //执行设备升级程序
            this.DoUpdateDevice();
        }
 
        /// <summary>
        /// 执行设备升级程序
        /// </summary>
        private async void DoUpdateDevice()
        {
            //执行升级
            var updateData = new CommonDevice.StartUpdateData();
            var deviceInfo = new CommonDevice.OTADeviceList();
            deviceInfo.MacAddr = this.otaDevice.DeviceAddr;
            //控制面板的时候,固定200端口
            updateData.DeviceList.Add(deviceInfo);
 
            this.zbGateway.ReportAction += this.UpdateDeviceProgress;
 
            //执行升级
            var upResult = await this.otaDevice.StartDeviceUpdateAsync(this.zbGateway, updateData);
            //设备升级中
            this.UpdateStatu = UpdateStatuMode.DeviceUpdating;
            //开启设备升级超时线程
            this.StartUpdateTimeOutThread();
 
            //别的错误
            if (upResult.startUpdateDeviceData == null || upResult.startUpdateDeviceData.Result == 1)
            {
                //设备升级失败
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDeviceUpdatingFail));
 
                //显示重新安装
                this.ShowReSetupMsg();
 
                this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
 
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
 
                //终止升级
                await this.otaDevice.KillUpdateAsync(this.zbGateway, 200);
                return;
            }
        }
 
        /// <summary>
        /// 升级设备的进度
        /// </summary>
        /// <param name="CommadDiv"></param>
        /// <param name="objValue"></param>
        private void UpdateDeviceProgress(string CommadDiv, object objValue)
        {
            if (CommadDiv != "DeviceUpgradePercent" || objValue == null)
            {
                return;
            }
            var tempZb = (ZbGateway)objValue;
            if (tempZb.GwId != this.zbGateway.GwId)
            {
                //不是自己的网关推送,则不处理
                return;
            }
            //刷新超时时间
            this.UpdateTimeOutRefresh();
 
            //设置进度
            var responData = tempZb.oTAScheduleResponData;
 
            //检测状态码
            if (this.CheckStatusCode(responData) == false)
            {
                this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
 
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    //终止升级
                    await this.otaDevice.KillUpdateAsync(this.zbGateway, 200);
                });
 
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
                return;
            }
 
            if (responData.Status == 2)
            {
                this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
 
                //显示升级完成的信息
                this.ShowFinishMsg();
                return;
            }
            if (responData.Status == 0)
            {
                //没什么意义
                return;
            }
 
            //设置进度值
            this.SetProgressValue(responData.Percent);
        }
 
        /// <summary>
        /// 检测状态码
        /// </summary>
        /// <param name="statusData"></param>
        /// <returns></returns>
        private bool CheckStatusCode(CommonDevice.OTAScheduleResponData statusData)
        {
            if (statusData == null)
            {
                return true;
            }
            if (statusData.Status == 3)
            {
                //响应超时,升级失败
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail));
                //显示重新安装
                this.ShowReSetupMsg();
 
                return false;
            }
            else if (statusData.Status == 150)
            {
                //无效的升级固件
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uErrorUpdateFirmwareFile));
                //显示重新安装
                this.ShowReSetupMsg();
 
                return false;
            }
            else if (statusData.Status == 153)
            {
                //升级固件不足
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uUpdateFirmwareFileNotEnough));
                //显示重新安装
                this.ShowReSetupMsg();
                return false;
            }
            else if (statusData.Status == 149)
            {
                //升级操作被终止
                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uUpdatedWasStoped));
                //显示重新安装
                this.ShowReSetupMsg();
                return false;
            }
 
            return true;
        }
 
        #endregion
 
        #region ■ 设置进度___________________________
 
        /// <summary>
        /// 设定进度值
        /// </summary>
        /// <param name="value">进度值</param>
        private void SetProgressValue(decimal value)
        {
            if (value > 100)
            {
                //有时候会瞎发什么鬼过来
                return;
            }
            this.ProgressEvent?.Invoke(value);
        }
 
        /// <summary>
        /// 设置错误信息
        /// </summary>
        /// <param name="value"></param>
        private void ShowErrorMsg(string value)
        {
            this.UpdateStatuChangedEvent?.Invoke(-1, value);
        }
 
        #endregion
 
        #region ■ 同步进度___________________________
 
        /// <summary>
        /// 同步进度
        /// </summary>
        private void SynchronizeDeviceProgress()
        {
            this.UpdateStatu = UpdateStatuMode.DeviceUpdating;
            this.IsFinishUpdate = false;
 
            //设备正在升级…
            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceUpdating));
            this.SetProgressValue(0);
 
            HdlFirmwareUpdateResourse.dicUpdateList[otaDevice.DeviceAddr] = this;
            //同步进度
            this.zbGateway.ReportAction += UpdateDeviceProgress;
        }
 
        #endregion
 
        #region ■ 终止升级___________________________
 
        /// <summary>
        /// 终止升级
        /// </summary>
        private void StopUpdate()
        {
            //确认是否要停止升级?
            string msg = Language.StringByID(R.MyInternationalizationString.uConfirmWantToStopUpdate);
            var contr = new ShowMsgControl(ShowMsgType.Confirm, msg);
            contr.ConfirmClickEvent += async () =>
            {
                if (this.UpdateStatu != UpdateStatuMode.DeviceUpdateReady && this.UpdateStatu != UpdateStatuMode.DeviceUpdating)
                {
                    return;
                }
 
                this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
 
                //终止升级
                var myResult = await this.otaDevice.KillUpdateAsync(this.zbGateway, 200);
 
                //状态变更
                this.IsFinishUpdate = true;
                this.oldUpdateStatu = UpdateStatuMode.None;
                this.UpdateStatu = UpdateStatuMode.None;
 
                //执行下一个可更新的固件的更新操作
                HdlFirmwareUpdateLogic.Current.DoUpdateNextFirmware();
                this.UpdateStatuChangedEvent?.Invoke(2, "");
            };
            contr.Show();
        }
 
        #endregion
 
        #region ■ 升级完成提示_______________________
 
        /// <summary>
        /// 显示升级完成的信息
        /// </summary>
        private void ShowFinishMsg()
        {
            //升级成功
            this.UpdateStatu = UpdateStatuMode.UpdateSuccess;
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                System.Threading.Thread.Sleep(3000);
 
                string checkKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(otaDevice.DeviceAddr, otaDevice.DeviceEpoint);
                HdlGatewayReceiveLogic.Current.AddAttributeEvent("HdlDeviceUpdate" + otaDevice.DeviceAddr, ReceiveComandDiv.A设备属性上报, (report) =>
                 {
                     if (report.DeviceStatusReport.CluterID == (int)Cluster_ID.Ota)
                     {
                         string mainKey = HdlDeviceCommonLogic.Current.GetDeviceMainKeys(report.DeviceAddr, report.DeviceEpoint);
                         if (checkKey == mainKey)
                         {
                            //已经接收得到
                            this.IsFinishUpdate = true;
                         }
                     }
                 });
 
                //发送命令
                HdlDeviceAttributeLogic.Current.ReadDeviceFirmwareVersion(otaDevice);
 
                System.Threading.Thread.Sleep(1500);
                int count = 12;
                while (this.IsFinishUpdate == false && count > 0)
                {
                    HdlDeviceAttributeLogic.Current.ReadDeviceFirmwareVersion(otaDevice);
                    //等待一下设备信息的反馈
                    System.Threading.Thread.Sleep(2000);
                    count--;
                }
                //移除事件
                HdlGatewayReceiveLogic.Current.RemoveEvent("HdlDeviceUpdate");
 
                //设置进度值直接为100%
                this.ProgressEvent?.Invoke(100);
                //状态变更
                this.IsFinishUpdate = true;
                //升级完成
                this.UpdateStatu = UpdateStatuMode.UpdateFinish;
 
                HdlFirmwareUpdateLogic.Current.DoUpdateNextFirmware();
 
                //设备升级成功!
                this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uDeviceUpdateSuccess));
            });
        }
 
        #endregion
 
        #region ■ 处理结果提示_______________________
 
        /// <summary>
        /// 显示重新安装的信息
        /// </summary>
        private void ShowReSetupMsg()
        {
            //状态变更
            this.IsFinishUpdate = true;
            //执行下一个升级
            HdlFirmwareUpdateLogic.Current.DoUpdateNextFirmware();
        }
 
        /// <summary>
        /// 显示重新下载模式
        /// </summary>
        private void ShowReDownLoadMode()
        {
            //状态变更
            this.IsFinishUpdate = true;
            //执行下一个升级
            HdlFirmwareUpdateLogic.Current.DoUpdateNextFirmware();
        }
 
        #endregion
 
        #region ■ 设备下载超时线程___________________
 
        /// <summary>
        /// 超时时间设置
        /// </summary>
        private int downLoadTimeOutCount = 30;
        /// <summary>
        /// 开启设备下载超时线程
        /// </summary>
        private void StartDownLoadTimeOutThread()
        {
            this.downLoadTimeOutCount = 30;
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (true)
                {
                    var value = this.UpdateStatu.ToString();
                    if (value.EndsWith("DownLoad") == false)
                    {
                        //执行完成下载操作
                        break;
                    }
                    System.Threading.Thread.Sleep(1000);
                    this.downLoadTimeOutCount--;
                    if (this.downLoadTimeOutCount < 0)
                    {
                        this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
 
                        Application.RunOnMainThread(() =>
                        {
                            //从头再来
                            this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
                            //显示重新下载模式
                            this.ShowReDownLoadMode();
                            //响应超时,升级失败
                            string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail);
                            this.ShowErrorMsg(msg);
                        });
                        break;
                    }
                }
            });
        }
 
        /// <summary>
        /// 超时时间刷新
        /// </summary>
        private void DownLoadTimeOutRefresh()
        {
            this.downLoadTimeOutCount = 30;
        }
 
        #endregion
 
        #region ■ 设备升级超时线程___________________
 
        /// <summary>
        /// 升级超时时间设置
        /// </summary>
        private int UpdateTimeOutCount = 60;
        /// <summary>
        /// 开启设备升级超时线程
        /// </summary>
        private void StartUpdateTimeOutThread()
        {
            this.UpdateTimeOutCount = 60;
            HdlThreadLogic.Current.RunThread(() =>
            {
                while (true)
                {
                    var value = this.UpdateStatu.ToString();
                    if (this.UpdateStatu != UpdateStatuMode.DeviceUpdateReady || this.UpdateStatu != UpdateStatuMode.DeviceUpdating)
                    {
                        //执行完成升级操作
                        break;
                    }
                    System.Threading.Thread.Sleep(1000);
                    this.UpdateTimeOutCount--;
                    if (this.UpdateTimeOutCount < 0)
                    {
                        this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
                        Application.RunOnMainThread(() =>
                        {
                            //从头再来
                            this.UpdateStatu = UpdateStatuMode.GatewayDownLoadFail;
                            //显示重新下载模式
                            this.ShowReDownLoadMode();
                            //响应超时,升级失败
                            string msg = Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail);
                            this.ShowErrorMsg(msg);
                        });
                        break;
                    }
                }
            });
        }
 
        /// <summary>
        /// 升级超时时间刷新
        /// </summary>
        private void UpdateTimeOutRefresh()
        {
            this.UpdateTimeOutCount = 60;
        }
 
        #endregion
 
        #region ■ 释放缓存___________________________
 
        /// <summary>
        /// 释放缓存
        /// </summary>
        public override void Dispose()
        {
            this.ProgressEvent = null;
            this.UpdateStatuChangedEvent = null;
        }
 
        #endregion
    }
}