黄学彪
2020-09-01 dee21bf452a8979d0515d13e534fbb69ed9715dd
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlDeviceUpdateLogic.cs
@@ -8,7 +8,7 @@
    /// <summary>
    /// HDL设备升级的逻辑
    /// </summary>
    public class HdlDeviceUpdateLogic
    public class HdlDeviceUpdateLogic : HdlDeviceUpdateCommonLogic
    {
        #region ■ 变量声明___________________________
@@ -27,17 +27,10 @@
        /// </summary>
        public Action<decimal> ProgressEvent = null;
        /// <summary>
        /// 当前执行的状态
        /// </summary>
        public UpdateStatuMode UpdateStatu = UpdateStatuMode.None;
        /// <summary>
        /// 设备新版本的固件信息(多个设备升级时,应该会需要公开这个对象)
        /// </summary>
        public FirmwareVersionInfo deviceFirmware = null;
        /// <summary>
        /// 升级是否完成(出现错误时,它也会变成true)
        /// </summary>
        public bool IsFinishUpdate = true;
        /// <summary>
        /// 网关
        /// </summary>
@@ -65,6 +58,7 @@
        /// <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;
@@ -89,9 +83,9 @@
            if (this.UpdateStatu == UpdateStatuMode.Wait)
            {
                //如果是等待模式,再次点击时,移除列表
                if (FirmwareUpdateResourse.dicDeviceUpdateList.ContainsKey(otaDevice.DeviceAddr) == true)
                if (FirmwareUpdateResourse.dicUpdateList.ContainsKey(otaDevice.DeviceAddr) == true)
                {
                    FirmwareUpdateResourse.dicDeviceUpdateList.Remove(otaDevice.DeviceAddr);
                    FirmwareUpdateResourse.dicUpdateList.Remove(otaDevice.DeviceAddr);
                }
                //取消
                this.UpdateStatu = UpdateStatuMode.None;
@@ -107,7 +101,7 @@
            //进入等待模式
            this.UpdateStatu = UpdateStatuMode.Wait;
            FirmwareUpdateResourse.dicDeviceUpdateList[otaDevice.DeviceAddr] = this;
            FirmwareUpdateResourse.dicUpdateList[otaDevice.DeviceAddr] = this;
            //等待中…
            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uWaitting));
@@ -117,9 +111,9 @@
        }
        /// <summary>
        /// 开始执行更新操作
        /// 开始执行更新操作(FirmwareUpdateLogic调用)
        /// </summary>
        public void DoStartUpdate()
        public override void DoStartUpdate()
        {
            //状态变更
            this.IsFinishUpdate = false;
@@ -210,7 +204,7 @@
                return;
            }
            var tempZb = (ZbGateway)objValue;
            if (tempZb.CurrentGateWayId != HdlGatewayLogic.Current.GetGatewayId(this.zbGateway))
            if (tempZb.GwId != this.zbGateway.GwId)
            {
                //不是自己的网关推送,则不处理
                return;
@@ -369,7 +363,7 @@
                return;
            }
            var tempZb = (ZbGateway)objValue;
            if (tempZb.CurrentGateWayId != HdlGatewayLogic.Current.GetGatewayId(this.zbGateway))
            if (tempZb.GwId != this.zbGateway.GwId)
            {
                //不是自己的网关推送,则不处理
                return;
@@ -418,7 +412,7 @@
        /// </summary>
        /// <param name="statusData"></param>
        /// <returns></returns>
        private bool CheckStatusCode(ZbGatewayData.OTAScheduleResponData statusData)
        private bool CheckStatusCode(CommonDevice.OTAScheduleResponData statusData)
        {
            if (statusData == null)
            {
@@ -505,7 +499,7 @@
            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uDeviceUpdating));
            this.SetProgressValue(0);
            FirmwareUpdateResourse.dicDeviceUpdateList[otaDevice.DeviceAddr] = this;
            FirmwareUpdateResourse.dicUpdateList[otaDevice.DeviceAddr] = this;
            //同步进度
            this.zbGateway.ReportAction += UpdateDeviceProgress;
        }
@@ -562,11 +556,22 @@
            {
                System.Threading.Thread.Sleep(3000);
                //重新刷新缓存
                HdlDeviceImageInfoLogic.Current.SetAllImageInfoToOtaDevice(otaDevice, (device, reportData) =>
                {
                    this.IsFinishUpdate = true;
                });
                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;
@@ -578,22 +583,19 @@
                    count--;
                }
                //移除事件
                HdlDeviceImageInfoLogic.Current.RemoveDeviceFirmwareVersionThread(otaDevice);
                HdlGatewayReceiveLogic.Current.RemoveEvent("HdlDeviceUpdate");
                Application.RunOnMainThread(() =>
                {
                    //设置进度值直接为100%
                    this.ProgressEvent?.Invoke(100);
                    //状态变更
                    this.IsFinishUpdate = true;
                    //升级完成
                    this.UpdateStatu = UpdateStatuMode.UpdateFinish;
                //设置进度值直接为100%
                this.ProgressEvent?.Invoke(100);
                //状态变更
                this.IsFinishUpdate = true;
                //升级完成
                this.UpdateStatu = UpdateStatuMode.UpdateFinish;
                    HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
                HdlFirmwareUpdateLogic.DoUpdateNextFirmware();
                    //设备升级成功!
                    this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uDeviceUpdateSuccess));
                });
                //设备升级成功!
                this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uDeviceUpdateSuccess));
            });
        }
@@ -737,7 +739,7 @@
        /// <summary>
        /// 释放缓存
        /// </summary>
        public void Dispose()
        public override void Dispose()
        {
            this.ProgressEvent = null;
            this.UpdateStatuChangedEvent = null;