From 25429f085093d89d543a0b90e30d0d62d1b7dac9 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期二, 30 八月 2022 09:37:38 +0800
Subject: [PATCH] 合并了IOS的代码
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs | 1471 +++++++++++++++++++++++++++++-----------------------------
1 files changed, 741 insertions(+), 730 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 bfb0ab6..566d567
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs
@@ -1,739 +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 (HdlGatewayLogic.Current.GetGatewayId(tempZb) != HdlGatewayLogic.Current.GetGatewayId(this.zbGateway))
- {
- //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
- 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 (HdlGatewayLogic.Current.GetGatewayId(tempZb) != HdlGatewayLogic.Current.GetGatewayId(this.zbGateway))
- {
- //涓嶆槸鑷繁鐨勭綉鍏虫帹閫侊紝鍒欎笉澶勭悊
- 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);
-
- //閲嶆柊鍒锋柊缂撳瓨
- HdlDeviceImageInfoLogic.Current.SetAllImageInfoToOtaDevice(otaDevice, (device, reportData) =>
- {
- this.IsFinishUpdate = true;
- });
-
- System.Threading.Thread.Sleep(1500);
- int count = 12;
- while (this.IsFinishUpdate == false && count > 0)
- {
- HdlDeviceImageInfoLogic.Current.SetFirmwareVersionComand(otaDevice);
- //绛夊緟涓�涓嬭澶囦俊鎭殑鍙嶉
- System.Threading.Thread.Sleep(2000);
- count--;
- }
- //绉婚櫎浜嬩欢
- HdlDeviceImageInfoLogic.Current.RemoveDeviceFirmwareVersionThread(otaDevice);
-
- //璁剧疆杩涘害鍊肩洿鎺ヤ负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