From dc0309e64f02227d8e1468b7326c07955f804612 Mon Sep 17 00:00:00 2001
From: chenqiyang <1406175257@qq.com>
Date: 星期三, 22 六月 2022 11:22:18 +0800
Subject: [PATCH] 修改引用路径

---
 ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs | 1482 +++++++++++++++++++++++++++++-----------------------------
 1 files changed, 741 insertions(+), 741 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs
old mode 100755
new mode 100644
index a76bb38..566d567
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs
@@ -1,750 +1,750 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Text;
-using ZigBee.Device;
-
-namespace Shared.Phone.UserCenter
-{
-    /// <summary>
-    /// HDL璁惧鍗囩骇鐨勯�昏緫
-    /// </summary>
-    public class HdlDeviceUpdateLogic : HdlDeviceUpdateCommonLogic
-    {
-        #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>
-        /// 璁惧鏂扮増鏈殑鍥轰欢淇℃伅(澶氫釜璁惧鍗囩骇鏃�,搴旇浼氶渶瑕佸叕寮�杩欎釜瀵硅薄)
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// HDL璁惧鍗囩骇鐨勯�昏緫
+    /// </summary>
+    public class HdlDeviceUpdateLogic : HdlDeviceUpdateCommonLogic
+    {
+        #region 鈻� 鍙橀噺澹版槑___________________________
+
+        /// <summary>
+        /// <para>鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢</para>
+        /// <para>绗竴涓弬鏁颁负:</para>
+        /// <para>-1:鏇存柊寮傚父,鍚庨潰鐨勫�间负寮傚父淇℃伅鐨勭炕璇戞枃鏈�</para>
+        /// <para> 0:鏇存柊鐘舵�佹甯稿彉鍖�,鍚庨潰鐨勫�间负鐘舵�佸彉鏇寸殑鏂囨湰缈昏瘧</para>
+        /// <para> 1:鍗囩骇鎴愬姛</para>
+        /// <para> 2:涓诲姩缁堟鍗囩骇</para>
+        /// <para> 3:浠庣瓑寰呬腑鍙栨秷(鐩墠杩樻病鏈夌敤)</para>
         /// </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 (FirmwareUpdateResourse.dicUpdateList.ContainsKey(otaDevice.DeviceAddr) == true)
-                {
-                    FirmwareUpdateResourse.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;
-            FirmwareUpdateResourse.dicUpdateList[otaDevice.DeviceAddr] = this;
-
-            //绛夊緟涓��
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uWaitting));
-
-            //鎵ц涓嬩竴涓彲鏇存柊鐨勫浐浠剁殑鏇存柊鎿嶄綔
-            HdlFirmwareUpdateLogic.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;
-
-            //璁惧鍥轰欢姝e湪涓嬭浇鈥�
-            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;
-            //璁惧姝e湪鍗囩骇鈥�
-            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 鈻� 璁剧疆杩涘害___________________________
-
+        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 (FirmwareUpdateResourse.dicUpdateList.ContainsKey(otaDevice.DeviceAddr) == true)
+                {
+                    FirmwareUpdateResourse.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;
+            FirmwareUpdateResourse.dicUpdateList[otaDevice.DeviceAddr] = this;
+
+            //绛夊緟涓��
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uWaitting));
+
+            //鎵ц涓嬩竴涓彲鏇存柊鐨勫浐浠剁殑鏇存柊鎿嶄綔
+            HdlFirmwareUpdateLogic.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;
+
+            //璁惧鍥轰欢姝e湪涓嬭浇鈥�
+            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;
+            //璁惧姝e湪鍗囩骇鈥�
+            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;
+            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;
-
-            //璁惧姝e湪鍗囩骇鈥�
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceUpdating));
-            this.SetProgressValue(0);
-
-            FirmwareUpdateResourse.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.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 = Common.LocalDevice.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 = Common.LocalDevice.Current.GetDeviceMainKeys(report.DeviceAddr, report.DeviceEpoint);
-                         if (checkKey == mainKey)
-                         {
-                            //宸茬粡鎺ユ敹寰楀埌
-                            this.IsFinishUpdate = true;
-                         }
-                     }
-                 });
-
-                //鍙戦�佸懡浠�
-                HdlDeviceImageInfoLogic.Current.SetFirmwareVersionComand(otaDevice);
-
-                System.Threading.Thread.Sleep(1500);
-                int count = 12;
-                while (this.IsFinishUpdate == false && count > 0)
-                {
-                    HdlDeviceImageInfoLogic.Current.SetFirmwareVersionComand(otaDevice);
-                    //绛夊緟涓�涓嬭澶囦俊鎭殑鍙嶉
-                    System.Threading.Thread.Sleep(2000);
-                    count--;
-                }
-                //绉婚櫎浜嬩欢
-                HdlGatewayReceiveLogic.Current.RemoveEvent("HdlDeviceUpdate");
-
-                //璁剧疆杩涘害鍊肩洿鎺ヤ负100%
-                this.ProgressEvent?.Invoke(100);
-                //鐘舵�佸彉鏇�
-                this.IsFinishUpdate = true;
-                //鍗囩骇瀹屾垚
-                this.UpdateStatu = UpdateStatuMode.UpdateFinish;
-
-                HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
-
-                //璁惧鍗囩骇鎴愬姛!
-                this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uDeviceUpdateSuccess));
-            });
-        }
-
-        #endregion
-
-        #region 鈻� 澶勭悊缁撴灉鎻愮ず_______________________
-
-        /// <summary>
-        /// 鏄剧ず閲嶆柊瀹夎鐨勪俊鎭�
-        /// </summary>
-        private void ShowReSetupMsg()
-        {
-            //鐘舵�佸彉鏇�
-            this.IsFinishUpdate = true;
-            //鎵ц涓嬩竴涓崌绾�
-            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
-        }
-
-        /// <summary>
-        /// 鏄剧ず閲嶆柊涓嬭浇妯″紡
-        /// </summary>
-        private void ShowReDownLoadMode()
-        {
-            //鐘舵�佸彉鏇�
-            this.IsFinishUpdate = true;
-            //鎵ц涓嬩竴涓崌绾�
-            HdlFirmwareUpdateLogic.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
-    }
-}
+        }
+
+        /// <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;
+
+            //璁惧姝e湪鍗囩骇鈥�
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceUpdating));
+            this.SetProgressValue(0);
+
+            FirmwareUpdateResourse.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.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 = Common.LocalDevice.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 = Common.LocalDevice.Current.GetDeviceMainKeys(report.DeviceAddr, report.DeviceEpoint);
+                         if (checkKey == mainKey)
+                         {
+                            //宸茬粡鎺ユ敹寰楀埌
+                            this.IsFinishUpdate = true;
+                         }
+                     }
+                 });
+
+                //鍙戦�佸懡浠�
+                HdlDeviceImageInfoLogic.Current.SetFirmwareVersionComand(otaDevice);
+
+                System.Threading.Thread.Sleep(1500);
+                int count = 12;
+                while (this.IsFinishUpdate == false && count > 0)
+                {
+                    HdlDeviceImageInfoLogic.Current.SetFirmwareVersionComand(otaDevice);
+                    //绛夊緟涓�涓嬭澶囦俊鎭殑鍙嶉
+                    System.Threading.Thread.Sleep(2000);
+                    count--;
+                }
+                //绉婚櫎浜嬩欢
+                HdlGatewayReceiveLogic.Current.RemoveEvent("HdlDeviceUpdate");
+
+                //璁剧疆杩涘害鍊肩洿鎺ヤ负100%
+                this.ProgressEvent?.Invoke(100);
+                //鐘舵�佸彉鏇�
+                this.IsFinishUpdate = true;
+                //鍗囩骇瀹屾垚
+                this.UpdateStatu = UpdateStatuMode.UpdateFinish;
+
+                HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
+
+                //璁惧鍗囩骇鎴愬姛!
+                this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uDeviceUpdateSuccess));
+            });
+        }
+
+        #endregion
+
+        #region 鈻� 澶勭悊缁撴灉鎻愮ず_______________________
+
+        /// <summary>
+        /// 鏄剧ず閲嶆柊瀹夎鐨勪俊鎭�
+        /// </summary>
+        private void ShowReSetupMsg()
+        {
+            //鐘舵�佸彉鏇�
+            this.IsFinishUpdate = true;
+            //鎵ц涓嬩竴涓崌绾�
+            HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
+        }
+
+        /// <summary>
+        /// 鏄剧ず閲嶆柊涓嬭浇妯″紡
+        /// </summary>
+        private void ShowReDownLoadMode()
+        {
+            //鐘舵�佸彉鏇�
+            this.IsFinishUpdate = true;
+            //鎵ц涓嬩竴涓崌绾�
+            HdlFirmwareUpdateLogic.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
+    }
+}

--
Gitblit v1.8.0