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/HdlACZbGatewayUpdateLogic.cs | 1042 +++++++++++++++++++++++++++++----------------------------
 1 files changed, 525 insertions(+), 517 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlACZbGatewayUpdateLogic.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlACZbGatewayUpdateLogic.cs
old mode 100755
new mode 100644
index d243082..f349f83
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlACZbGatewayUpdateLogic.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlACZbGatewayUpdateLogic.cs
@@ -1,517 +1,525 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Text;
-using ZigBee.Device;
-
-namespace Shared.Phone.UserCenter
-{
-    /// <summary>
-    /// 涓ぎ绌鸿皟鐨勫崌绾ч�昏緫
-    /// </summary>
-    public class HdlACZbGatewayUpdateLogic : 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>
-        /// 璁惧鏂扮増鏈殑鍥轰欢淇℃伅(澶氫釜璁惧鍗囩骇鏃�,搴旇浼氶渶瑕佸叕寮�杩欎釜瀵硅薄)
-        /// </summary>
-        public FirmwareVersionInfo deviceFirmware = null;
-        /// <summary>
-        /// 缃戝叧
-        /// </summary>
-        private ZbGateway zbGateway = null;
-        /// <summary>
-        /// 鍗囩骇鐨勮澶�
-        /// </summary>
-        private OTADevice otaDevice = null;
-        /// <summary>
-        /// 璁惧瀵硅薄
-        /// </summary>
-        private AC deviceAc = null;
-        /// <summary>
-        /// 鍓嶄竴娆$殑鏈�缁堢姸鎬�
-        /// </summary>
-        private UpdateStatuMode oldUpdateStatu = UpdateStatuMode.None;
-        /// <summary>
-        /// 鍥轰欢鐨刡yte鏁扮粍
-        /// </summary>
-        private byte[] deviceFirmwareByte = null;
-
-        #endregion
-
-        #region 鈻� 鍒濆鍖朹____________________________
-
-        /// <summary>
-        /// <para>HDL璁惧鍗囩骇,浠ヤ笅涓轰袱涓噸瑕佷簨浠�</para>
-        /// <para>UpdateStatuChangedEvent:鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢</para>
-        /// <para>ProgressEvent:杩涘害鍊间簨浠�</para>
-        /// <para>StartUpdateReady():璁惧寮�濮嬫墽琛屽崌绾х殑鍑芥暟,鍦ㄨ皟鐢ㄨ繖涓箣鍓�,璇峰厛瀹炵幇涓婇潰涓や釜鏂规硶</para>
-        /// </summary>
-        /// <param name="i_deviceAc">璁惧</param>
-        /// <param name="i_deviceFirmware">璁惧鐨勫浐浠朵俊鎭�</param>
-        public HdlACZbGatewayUpdateLogic(AC i_deviceAc, FirmwareVersionInfo i_deviceFirmware)
-        {
-            this.ClassDiv = 2;
-            this.deviceAc = i_deviceAc;
-            this.otaDevice = Common.LocalDevice.Current.GetOTADevice(i_deviceAc.DeviceAddr);
-            this.deviceFirmware = i_deviceFirmware;
-            this.zbGateway = i_deviceAc.Gateway;
-        }
-
-        #endregion
-
-        #region 鈻� 寮�濮嬫洿鏂癬__________________________
-
-        /// <summary>
-        /// 杩涘叆鎵ц鏇存柊鎿嶄綔鍑嗗闃舵
-        /// </summary>
-        public void StartUpdateReady()
-        {
-            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>
-        /// 寮�濮嬫墽琛屾洿鏂版搷浣�
-        /// </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.DoCheckVersion();
-            }
-            //璁惧涓嬭浇澶辫触
-            else if (this.oldUpdateStatu == UpdateStatuMode.DeviceDownLoadFail)
-            {
-                //鎵ц鏍¢獙鐗堟湰
-                this.DoCheckVersion();
-            }
-            //璁惧鍗囩骇澶辫触
-            else if (this.oldUpdateStatu == UpdateStatuMode.DeviceUpdateFail)
-            {
-                //鎵ц鏍¢獙鐗堟湰
-                this.DoCheckVersion();
-            }
-            else
-            {
-                //閲嶆柊鍐嶆潵
-                this.DoCheckVersion();
-            }
-        }
-
-        #endregion
-
-        #region 鈻� 鏍¢獙鐗堟湰___________________________
-
-        /// <summary>
-        /// 鏍¢獙鐗堟湰
-        /// </summary>
-        private async void DoCheckVersion()
-        {
-            this.UpdateStatu = UpdateStatuMode.DeviceUpdateReady;
-            //妫�娴嬭澶囩増鏈�
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uCheckDeviceVersion));
-            //璁剧疆鍒濆鍊�
-            this.SetProgressValue(0, 100);
-
-            await System.Threading.Tasks.Task.Delay(1000);
-
-            //涓嬭浇鍥轰欢璧勬簮
-            var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = this.deviceFirmware.DistributedMark };
-            this.deviceFirmwareByte = await Common.CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("FirmwareMana/DownloadPlatformUploadFirmware", Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(pra)));
-            if (this.deviceFirmwareByte == null)
-            {
-                //璁惧鍥轰欢璧勬簮涓嬭浇澶辫触
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDeviceFirmwareDownLoadFail));
-
-                //鏄剧ず閲嶆柊涓嬭浇妯″紡
-                this.ShowReDownLoadMode();
-
-                this.UpdateStatu = UpdateStatuMode.DeviceDownLoadFail;
-                return;
-            }
-
-            //鏁版嵁鍋忕Щ閲忥紝姣忎釜鍒嗗寘鍋忕Щ閲�+锛�1-43锛�
-            string offset = string.Empty;
-            //涓�娆″彂閫佺殑鏁版嵁闀垮害
-            int dataLength = -1;
-            //鎺ユ敹缃戝叧鐨勯�忎紶鏁版嵁
-            Action<string, object> receiveAction = (comand, pushData) =>
-            {
-                string receiveData = ((CommonDevice.ClientDataPassthroughResponseData)pushData).PassData;
-                if (receiveData.Length < 6)
-                {
-                    return;
-                }
-                try
-                {
-                    var command = receiveData[4].ToString() + receiveData[5].ToString() + receiveData[2].ToString() + receiveData[3].ToString();
-                    if (command == "025c")
-                    {
-                        offset = receiveData.Substring(10, 8);
-                        dataLength = Convert.ToInt32(receiveData.Substring(18, 2), 16);
-                    }
-                }
-                catch { }
-            };
-            this.zbGateway.ReportAction += receiveAction;
-
-            //璇诲彇绌鸿皟妯″潡鐗堟湰
-            var result = await HdlDeviceAirConditionerLogic.Current.ReadACFirewareVersionAsync(deviceAc);
-            if (result == null || result.readACFirewareVersionResponData == null || result.readACFirewareVersionResponData.Status != 0)
-            {
-                //鑾峰彇绌鸿皟妯″潡鐗堟湰澶辫触
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGetAirConditionerModelVersionFail));
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
-                this.zbGateway.ReportAction -= receiveAction;
-                //鍙戦�佸け璐ョ粰璁惧
-                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
-                return;
-            }
-            //鍙戦�佸崌绾ч�氱煡
-            var result2 = await HdlDeviceAirConditionerLogic.Current.UpggradeACNotificationAsync(deviceAc, result.readACFirewareVersionResponData.FirewareVersion, this.deviceFirmwareByte.Length);
-            if (result2.responseData == null)
-            {
-                //鍙戦�佸崌绾у懡浠ゅけ璐�
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uSendUpdateComandFail));
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
-                this.zbGateway.ReportAction -= receiveAction;
-                //鍙戦�佸け璐ョ粰璁惧
-                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
-                return;
-            }
-            else if (result2.responseData.status == 1)
-            {
-                //鐗堟湰鍙风浉鍚�,鍗囩骇澶辫触
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uVersionIsEqualAndUpdateFail));
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
-                this.zbGateway.ReportAction -= receiveAction;
-                //鍙戦�佸け璐ョ粰璁惧
-                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
-                return;
-            }
-            else if (result2.responseData.status != 0)
-            {
-                //鏍¢獙鐗堟湰鍙峰け璐�
-                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uCheckVersionFail));
-                //鏄剧ず閲嶆柊瀹夎
-                this.ShowReSetupMsg();
-                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
-                this.zbGateway.ReportAction -= receiveAction;
-                //鍙戦�佸け璐ョ粰璁惧
-                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
-                return;
-            }
-
-            int timeOut = 0;
-            //绛夊緟鎺ユ敹鍋忕Щ閲�
-            while (dataLength == -1)
-            {
-                timeOut++;
-                if (timeOut >= 30)
-                {
-                    //鍝嶅簲瓒呮椂,妫�娴嬭澶囩増鏈け璐�
-                    this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndCheckDeviceVersionFail));
-                    //鏄剧ず閲嶆柊瀹夎
-                    this.ShowReSetupMsg();
-                    this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
-                    this.zbGateway.ReportAction -= receiveAction;
-                    //鍙戦�佸け璐ョ粰璁惧
-                    HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
-                    return;
-                }
-                await System.Threading.Tasks.Task.Delay(1000);
-                //璁剧疆杩涘害鍊�
-                this.SetProgressValue(timeOut, 30);
-            }
-            this.zbGateway.ReportAction -= receiveAction;
-
-            //鎵ц璁惧鍗囩骇鎿嶄綔
-            this.DoSetUpdateDevice(offset, dataLength);
-        }
-
-        #endregion
-
-        #region 鈻� 璁惧鍗囩骇___________________________
-
-        /// <summary>
-        /// 鎵ц璁惧鍗囩骇鎿嶄綔
-        /// </summary>
-        private async void DoSetUpdateDevice(string i_offset, int i_dataLength)
-        {
-            this.UpdateStatu = UpdateStatuMode.DeviceUpdateReady;
-            //璁惧姝e湪鍗囩骇鈥�
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceUpdating));
-            //璁剧疆鍒濆鍊�
-            this.SetProgressValue(0, 100);
-
-            await System.Threading.Tasks.Task.Delay(1000);
-
-            //鍙戦�佹暟鎹殑绱㈠紩
-            int startIndex = 0;
-            int allDataLength = this.deviceFirmwareByte.Length;
-            int timeOut = 0;
-            //鏄惁鎺ユ敹鍒版垚鍔熷懡浠�
-            bool receiveSuccess = false;
-
-            //鎺ユ敹缃戝叧鐨勯�忎紶鏁版嵁
-            bool hadReceive = true;
-            Action<string, object> receiveAction = (comand, pushData) =>
-            {
-                if (comand != "DeviceRequestAcUpdateData")
-                {
-                    return;
-                }
-                string receiveData = ((CommonDevice.ClientDataPassthroughResponseData)pushData).PassData;
-                if (receiveData.Length < 6)
-                {
-                    return;
-                }
-                try
-                {
-                    var command = receiveData[4].ToString() + receiveData[5].ToString() + receiveData[2].ToString() + receiveData[3].ToString();
-                    if (command == "025c")
-                    {
-                        i_offset = receiveData.Substring(10, 8);
-                        i_dataLength = Convert.ToInt32(receiveData.Substring(18, 2), 16);
-                        hadReceive = true;
-                        timeOut = 0;
-                        //璁剧疆杩涘害鍊�
-                        this.SetProgressValue(startIndex, allDataLength);
-                    }
-                    else if (command == "025e")
-                    {
-                        //鎴愬姛  璁剧疆杩涘害鍊肩洿鎺�100%
-                        this.SetProgressValue(allDataLength, allDataLength);
-                        receiveSuccess = true;
-                        timeOut = 0;
-                    }
-                }
-                catch { }
-            };
-            this.zbGateway.ReportAction += receiveAction;
-
-            //鏈�鍚庝竴娆¢渶瑕佺瓑寰呭洖澶嶇粨鏋滄墠寰�涓嬭蛋
-            while (startIndex < allDataLength)
-            {
-                if (receiveSuccess == true)
-                {
-                    //宸茬粡鎺ユ敹鍒版垚鍔熺殑鍛戒护
-                    break;
-                }
-                if (hadReceive == false)
-                {
-                    timeOut++;
-                    if (timeOut >= 1500)
-                    {
-                        //鍝嶅簲瓒呮椂,鍗囩骇澶辫触
-                        this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail));
-                        //鏄剧ず閲嶆柊瀹夎
-                        this.ShowReSetupMsg();
-                        this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
-                        this.zbGateway.ReportAction -= receiveAction;
-                        //鍙戦�佸け璐ョ粰璁惧
-                        HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
-                        return;
-                    }
-                    await System.Threading.Tasks.Task.Delay(50);
-                    continue;
-                }
-                hadReceive = false;
-                //鍥犱负鍋忕Щ閲忔槸楂樹綅鍦ㄥ墠锛屾墍浠ュ�掕繃鏉�
-                string Myoffset = string.Empty;
-                for (int i = 6; i >= 0; i = i - 2)
-                {
-                    Myoffset += i_offset.Substring(i, 2);
-                }
-                startIndex = Convert.ToInt32(Myoffset, 16) - i_dataLength;
-
-                //鑾峰彇涓�娆¤兘澶熷彂閫佺殑byte
-                var listData = new List<byte>();
-                for (; startIndex < allDataLength; startIndex++)
-                {
-                    listData.Add(this.deviceFirmwareByte[startIndex]);
-                    if (listData.Count == i_dataLength)
-                    {
-                        break;
-                    }
-                }
-                //鍙戦�侀�忎紶鏁版嵁
-                var sendData = new HdlDeviceAirConditionerLogic.SendUpgradeData() { dataLength = i_dataLength, offset = i_offset };
-                sendData.databytes = listData.ToArray();
-                HdlDeviceAirConditionerLogic.Current.UpgradeAsync(deviceAc, sendData);
-            }
-            this.zbGateway.ReportAction -= receiveAction;
-
-            //鍙戦�佺粨鏉熷懡浠�
-            this.DoSendFinishComand();
-        }
-
-        #endregion
-
-        #region 鈻� 鍒嗗寘缁撴潫___________________________
-
-        /// <summary>
-        /// 鍙戦�佺粨鏉熷懡浠�
-        /// </summary>
-        private async void DoSendFinishComand()
-        {
-            //姝e湪鍙戦�佸崌绾у畬鎴愮殑鍛戒护
-            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uSendingFinishUpdateComand));
-
-            //鍙戦�佹垚鍔熷懡浠ょ粰璁惧
-            HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 0);
-
-            //绛変釜涓ょ閽熷惂
-            await System.Threading.Tasks.Task.Delay(2000);
-
-            //鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
-            this.ShowFinishMsg();
-        }
-
-        #endregion
-
-        #region 鈻� 璁剧疆杩涘害___________________________
-
-        /// <summary>
-        /// 璁惧畾杩涘害鍊�
-        /// </summary>
-        /// <param name="value">杩涘害鍊�</param>
-        /// <param name="maxValue">maxValue</param>
-        private void SetProgressValue(decimal value, decimal maxValue)
-        {
-            this.ProgressEvent?.Invoke(value / maxValue);
-        }
-
-        /// <summary>
-        /// 璁剧疆閿欒淇℃伅
-        /// </summary>
-        /// <param name="value"></param>
-        private void ShowErrorMsg(string value)
-        {
-            this.UpdateStatuChangedEvent?.Invoke(-1, value);
-        }
-
-        #endregion
-
-        #region 鈻� 鍗囩骇瀹屾垚鎻愮ず_______________________
-
-        /// <summary>
-        /// 鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
-        /// </summary>
-        private void ShowFinishMsg()
-        {
-            //鐘舵�佸彉鏇�
-            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>
-        public override void Dispose()
-        {
-            this.ProgressEvent = null;
-            this.UpdateStatuChangedEvent = null;
-        }
-
-        #endregion
-    }
-}
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter
+{
+    /// <summary>
+    /// 涓ぎ绌鸿皟鐨勫崌绾ч�昏緫
+    /// </summary>
+    public class HdlACZbGatewayUpdateLogic : 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>
+        /// 璁惧鏂扮増鏈殑鍥轰欢淇℃伅(澶氫釜璁惧鍗囩骇鏃�,搴旇浼氶渶瑕佸叕寮�杩欎釜瀵硅薄)
+        /// </summary>
+        public FirmwareVersionInfo deviceFirmware = null;
+        /// <summary>
+        /// 缃戝叧
+        /// </summary>
+        private ZbGateway zbGateway = null;
+        /// <summary>
+        /// 鍗囩骇鐨勮澶�
+        /// </summary>
+        private OTADevice otaDevice = null;
+        /// <summary>
+        /// 璁惧瀵硅薄
+        /// </summary>
+        private CommonDevice deviceAc = null;
+        /// <summary>
+        /// 鍓嶄竴娆$殑鏈�缁堢姸鎬�
+        /// </summary>
+        private UpdateStatuMode oldUpdateStatu = UpdateStatuMode.None;
+        /// <summary>
+        /// 鍥轰欢鐨刡yte鏁扮粍
+        /// </summary>
+        private byte[] deviceFirmwareByte = null;
+
+        #endregion
+
+        #region 鈻� 鍒濆鍖朹____________________________
+
+        /// <summary>
+        /// <para>HDL璁惧鍗囩骇,浠ヤ笅涓轰袱涓噸瑕佷簨浠�</para>
+        /// <para>UpdateStatuChangedEvent:鏇存柊鐘舵�佸彉鍖栫殑浜嬩欢</para>
+        /// <para>ProgressEvent:杩涘害鍊间簨浠�</para>
+        /// <para>StartUpdateReady():璁惧寮�濮嬫墽琛屽崌绾х殑鍑芥暟,鍦ㄨ皟鐢ㄨ繖涓箣鍓�,璇峰厛瀹炵幇涓婇潰涓や釜鏂规硶</para>
+        /// </summary>
+        /// <param name="i_deviceAc">璁惧</param>
+        /// <param name="i_deviceFirmware">璁惧鐨勫浐浠朵俊鎭�</param>
+        public HdlACZbGatewayUpdateLogic(CommonDevice i_deviceAc, FirmwareVersionInfo i_deviceFirmware)
+        {
+            this.ClassDiv = 2;
+            this.deviceAc = i_deviceAc;
+            this.otaDevice = Common.LocalDevice.Current.GetOTADevice(i_deviceAc.DeviceAddr);
+            this.deviceFirmware = i_deviceFirmware;
+            this.zbGateway = i_deviceAc.Gateway;
+        }
+
+        #endregion
+
+        #region 鈻� 寮�濮嬫洿鏂癬__________________________
+
+        /// <summary>
+        /// 杩涘叆鎵ц鏇存柊鎿嶄綔鍑嗗闃舵
+        /// </summary>
+        public void StartUpdateReady()
+        {
+            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>
+        /// 寮�濮嬫墽琛屾洿鏂版搷浣�
+        /// </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.DoCheckVersion();
+            }
+            //璁惧涓嬭浇澶辫触
+            else if (this.oldUpdateStatu == UpdateStatuMode.DeviceDownLoadFail)
+            {
+                //鎵ц鏍¢獙鐗堟湰
+                this.DoCheckVersion();
+            }
+            //璁惧鍗囩骇澶辫触
+            else if (this.oldUpdateStatu == UpdateStatuMode.DeviceUpdateFail)
+            {
+                //鎵ц鏍¢獙鐗堟湰
+                this.DoCheckVersion();
+            }
+            else
+            {
+                //閲嶆柊鍐嶆潵
+                this.DoCheckVersion();
+            }
+        }
+
+        #endregion
+
+        #region 鈻� 鏍¢獙鐗堟湰___________________________
+
+        /// <summary>
+        /// 鏍¢獙鐗堟湰
+        /// </summary>
+        private async void DoCheckVersion()
+        {
+            this.UpdateStatu = UpdateStatuMode.DeviceUpdateReady;
+            //妫�娴嬭澶囩増鏈�
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uCheckDeviceVersion));
+            //璁剧疆鍒濆鍊�
+            this.SetProgressValue(0, 100);
+
+            await System.Threading.Tasks.Task.Delay(1000);
+
+            //涓嬭浇鍥轰欢璧勬簮
+            if (this.deviceFirmware.ImagType != "-100")
+            {
+                var pra = new { RequestVersion = Common.CommonPage.RequestVersion, DistributedMark = this.deviceFirmware.DistributedMark };
+                this.deviceFirmwareByte = Common.CommonPage.Instance.RequestHttpsZigbeeBytesResultAsync("FirmwareMana/DownloadPlatformUploadFirmware", Encoding.UTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(pra)));
+            }
+            else
+            {
+                //鍙栨湰鍦版ā鏉�
+                this.deviceFirmwareByte = HdlFileLogic.Current.ReadFileByteContent(this.deviceFirmware.Name);
+            }
+            if (this.deviceFirmwareByte == null)
+            {
+                //璁惧鍥轰欢璧勬簮涓嬭浇澶辫触
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uDeviceFirmwareDownLoadFail));
+
+                //鏄剧ず閲嶆柊涓嬭浇妯″紡
+                this.ShowReDownLoadMode();
+
+                this.UpdateStatu = UpdateStatuMode.DeviceDownLoadFail;
+                return;
+            }
+
+            //鏁版嵁鍋忕Щ閲忥紝姣忎釜鍒嗗寘鍋忕Щ閲�+锛�1-43锛�
+            string offset = string.Empty;
+            //涓�娆″彂閫佺殑鏁版嵁闀垮害
+            int dataLength = -1;
+            //鎺ユ敹缃戝叧鐨勯�忎紶鏁版嵁
+            Action<string, object> receiveAction = (comand, pushData) =>
+            {
+                string receiveData = ((CommonDevice.ClientDataPassthroughResponseData)pushData).PassData;
+                if (receiveData.Length < 6)
+                {
+                    return;
+                }
+                try
+                {
+                    var command = receiveData[4].ToString() + receiveData[5].ToString() + receiveData[2].ToString() + receiveData[3].ToString();
+                    if (command == "025c")
+                    {
+                        offset = receiveData.Substring(10, 8);
+                        dataLength = Convert.ToInt32(receiveData.Substring(18, 2), 16);
+                    }
+                }
+                catch { }
+            };
+            this.zbGateway.ReportAction += receiveAction;
+
+            //璇诲彇绌鸿皟妯″潡鐗堟湰
+            var result = await HdlDeviceAirConditionerLogic.Current.ReadACFirewareVersionAsync(deviceAc);
+            if (result == null || result.readACFirewareVersionResponData == null || result.readACFirewareVersionResponData.Status != 0)
+            {
+                //鑾峰彇绌鸿皟妯″潡鐗堟湰澶辫触
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uGetAirConditionerModelVersionFail));
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
+                this.zbGateway.ReportAction -= receiveAction;
+                //鍙戦�佸け璐ョ粰璁惧
+                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
+                return;
+            }
+            //鍙戦�佸崌绾ч�氱煡
+            var result2 = await HdlDeviceAirConditionerLogic.Current.UpggradeACNotificationAsync(deviceAc, result.readACFirewareVersionResponData.FirewareVersion, this.deviceFirmwareByte.Length);
+            if (result2.responseData == null)
+            {
+                //鍙戦�佸崌绾у懡浠ゅけ璐�
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uSendUpdateComandFail));
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
+                this.zbGateway.ReportAction -= receiveAction;
+                //鍙戦�佸け璐ョ粰璁惧
+                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
+                return;
+            }
+            else if (result2.responseData.status == 1)
+            {
+                //鐗堟湰鍙风浉鍚�,鍗囩骇澶辫触
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uVersionIsEqualAndUpdateFail));
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
+                this.zbGateway.ReportAction -= receiveAction;
+                //鍙戦�佸け璐ョ粰璁惧
+                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
+                return;
+            }
+            else if (result2.responseData.status != 0)
+            {
+                //鏍¢獙鐗堟湰鍙峰け璐�
+                this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uCheckVersionFail));
+                //鏄剧ず閲嶆柊瀹夎
+                this.ShowReSetupMsg();
+                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
+                this.zbGateway.ReportAction -= receiveAction;
+                //鍙戦�佸け璐ョ粰璁惧
+                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
+                return;
+            }
+
+            int timeOut = 0;
+            //绛夊緟鎺ユ敹鍋忕Щ閲�
+            while (dataLength == -1)
+            {
+                timeOut++;
+                if (timeOut >= 30)
+                {
+                    //鍝嶅簲瓒呮椂,妫�娴嬭澶囩増鏈け璐�
+                    this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndCheckDeviceVersionFail));
+                    //鏄剧ず閲嶆柊瀹夎
+                    this.ShowReSetupMsg();
+                    this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
+                    this.zbGateway.ReportAction -= receiveAction;
+                    //鍙戦�佸け璐ョ粰璁惧
+                    HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
+                    return;
+                }
+                await System.Threading.Tasks.Task.Delay(1000);
+                //璁剧疆杩涘害鍊�
+                this.SetProgressValue(timeOut, 30);
+            }
+            this.zbGateway.ReportAction -= receiveAction;
+
+            //鎵ц璁惧鍗囩骇鎿嶄綔
+            this.DoSetUpdateDevice(offset, dataLength);
+        }
+
+        #endregion
+
+        #region 鈻� 璁惧鍗囩骇___________________________
+
+        /// <summary>
+        /// 鎵ц璁惧鍗囩骇鎿嶄綔
+        /// </summary>
+        private async void DoSetUpdateDevice(string i_offset, int i_dataLength)
+        {
+            this.UpdateStatu = UpdateStatuMode.DeviceUpdateReady;
+            //璁惧姝e湪鍗囩骇鈥�
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceUpdating));
+            //璁剧疆鍒濆鍊�
+            this.SetProgressValue(0, 100);
+
+            await System.Threading.Tasks.Task.Delay(1000);
+
+            //鍙戦�佹暟鎹殑绱㈠紩
+            int startIndex = 0;
+            int allDataLength = this.deviceFirmwareByte.Length;
+            int timeOut = 0;
+            //鏄惁鎺ユ敹鍒版垚鍔熷懡浠�
+            bool receiveSuccess = false;
+
+            //鎺ユ敹缃戝叧鐨勯�忎紶鏁版嵁
+            bool hadReceive = true;
+            Action<string, object> receiveAction = (comand, pushData) =>
+            {
+                if (comand != "DeviceRequestAcUpdateData")
+                {
+                    return;
+                }
+                string receiveData = ((CommonDevice.ClientDataPassthroughResponseData)pushData).PassData;
+                if (receiveData.Length < 6)
+                {
+                    return;
+                }
+                try
+                {
+                    var command = receiveData[4].ToString() + receiveData[5].ToString() + receiveData[2].ToString() + receiveData[3].ToString();
+                    if (command == "025c")
+                    {
+                        i_offset = receiveData.Substring(10, 8);
+                        i_dataLength = Convert.ToInt32(receiveData.Substring(18, 2), 16);
+                        hadReceive = true;
+                        timeOut = 0;
+                        //璁剧疆杩涘害鍊�
+                        this.SetProgressValue(startIndex, allDataLength);
+                    }
+                    else if (command == "025e")
+                    {
+                        //鎴愬姛  璁剧疆杩涘害鍊肩洿鎺�100%
+                        this.SetProgressValue(allDataLength, allDataLength);
+                        receiveSuccess = true;
+                        timeOut = 0;
+                    }
+                }
+                catch { }
+            };
+            this.zbGateway.ReportAction += receiveAction;
+
+            //鏈�鍚庝竴娆¢渶瑕佺瓑寰呭洖澶嶇粨鏋滄墠寰�涓嬭蛋
+            while (startIndex < allDataLength)
+            {
+                if (receiveSuccess == true)
+                {
+                    //宸茬粡鎺ユ敹鍒版垚鍔熺殑鍛戒护
+                    break;
+                }
+                if (hadReceive == false)
+                {
+                    timeOut++;
+                    if (timeOut >= 1500)
+                    {
+                        //鍝嶅簲瓒呮椂,鍗囩骇澶辫触
+                        this.ShowErrorMsg(Language.StringByID(R.MyInternationalizationString.uResponseTimeoutsAndUpdateFail));
+                        //鏄剧ず閲嶆柊瀹夎
+                        this.ShowReSetupMsg();
+                        this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
+                        this.zbGateway.ReportAction -= receiveAction;
+                        //鍙戦�佸け璐ョ粰璁惧
+                        HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
+                        return;
+                    }
+                    await System.Threading.Tasks.Task.Delay(50);
+                    continue;
+                }
+                hadReceive = false;
+                //鍥犱负鍋忕Щ閲忔槸楂樹綅鍦ㄥ墠锛屾墍浠ュ�掕繃鏉�
+                string Myoffset = string.Empty;
+                for (int i = 6; i >= 0; i = i - 2)
+                {
+                    Myoffset += i_offset.Substring(i, 2);
+                }
+                startIndex = Convert.ToInt32(Myoffset, 16) - i_dataLength;
+
+                //鑾峰彇涓�娆¤兘澶熷彂閫佺殑byte
+                var listData = new List<byte>();
+                for (; startIndex < allDataLength; startIndex++)
+                {
+                    listData.Add(this.deviceFirmwareByte[startIndex]);
+                    if (listData.Count == i_dataLength)
+                    {
+                        break;
+                    }
+                }
+                //鍙戦�侀�忎紶鏁版嵁
+                var sendData = new HdlDeviceAirConditionerLogic.SendUpgradeData() { dataLength = i_dataLength, offset = i_offset };
+                sendData.databytes = listData.ToArray();
+                HdlDeviceAirConditionerLogic.Current.UpgradeAsync(deviceAc, sendData);
+            }
+            this.zbGateway.ReportAction -= receiveAction;
+
+            //鍙戦�佺粨鏉熷懡浠�
+            this.DoSendFinishComand();
+        }
+
+        #endregion
+
+        #region 鈻� 鍒嗗寘缁撴潫___________________________
+
+        /// <summary>
+        /// 鍙戦�佺粨鏉熷懡浠�
+        /// </summary>
+        private async void DoSendFinishComand()
+        {
+            //姝e湪鍙戦�佸崌绾у畬鎴愮殑鍛戒护
+            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uSendingFinishUpdateComand));
+
+            //鍙戦�佹垚鍔熷懡浠ょ粰璁惧
+            HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 0);
+
+            //绛変釜涓ょ閽熷惂
+            await System.Threading.Tasks.Task.Delay(2000);
+
+            //鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
+            this.ShowFinishMsg();
+        }
+
+        #endregion
+
+        #region 鈻� 璁剧疆杩涘害___________________________
+
+        /// <summary>
+        /// 璁惧畾杩涘害鍊�
+        /// </summary>
+        /// <param name="value">杩涘害鍊�</param>
+        /// <param name="maxValue">maxValue</param>
+        private void SetProgressValue(decimal value, decimal maxValue)
+        {
+            this.ProgressEvent?.Invoke(value / maxValue);
+        }
+
+        /// <summary>
+        /// 璁剧疆閿欒淇℃伅
+        /// </summary>
+        /// <param name="value"></param>
+        private void ShowErrorMsg(string value)
+        {
+            this.UpdateStatuChangedEvent?.Invoke(-1, value);
+        }
+
+        #endregion
+
+        #region 鈻� 鍗囩骇瀹屾垚鎻愮ず_______________________
+
+        /// <summary>
+        /// 鏄剧ず鍗囩骇瀹屾垚鐨勪俊鎭�
+        /// </summary>
+        private void ShowFinishMsg()
+        {
+            //鐘舵�佸彉鏇�
+            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>
+        public override void Dispose()
+        {
+            this.ProgressEvent = null;
+            this.UpdateStatuChangedEvent = null;
+        }
+
+        #endregion
+    }
+}

--
Gitblit v1.8.0