gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlACZbGatewayUpdateLogic.cs
@@ -212,7 +212,7 @@
            this.zbGateway.ReportAction += receiveAction;
            //读取空调模块版本
            var result = await deviceAc.ReadACFirewareVersionAsync();
            var result = await HdlDeviceAirConditionerLogic.Current.ReadACFirewareVersionAsync(deviceAc);
            if (result == null || result.readACFirewareVersionResponData == null || result.readACFirewareVersionResponData.Status != 0)
            {
                //获取空调模块版本失败
@@ -222,11 +222,11 @@
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
                this.zbGateway.ReportAction -= receiveAction;
                //发送失败给设备
                deviceAc.SendFinishAsync(1);
                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
                return;
            }
            //发送升级通知
            var result2 = await deviceAc.UpggradeACNotificationAsync(result.readACFirewareVersionResponData.FirewareVersion, this.deviceFirmwareByte.Length);
            var result2 = await HdlDeviceAirConditionerLogic.Current.UpggradeACNotificationAsync(deviceAc, result.readACFirewareVersionResponData.FirewareVersion, this.deviceFirmwareByte.Length);
            if (result2.responseData == null)
            {
                //发送升级命令失败
@@ -236,7 +236,7 @@
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
                this.zbGateway.ReportAction -= receiveAction;
                //发送失败给设备
                deviceAc.SendFinishAsync(1);
                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
                return;
            }
            else if (result2.responseData.status == 1)
@@ -248,7 +248,7 @@
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
                this.zbGateway.ReportAction -= receiveAction;
                //发送失败给设备
                deviceAc.SendFinishAsync(1);
                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
                return;
            }
            else if (result2.responseData.status != 0)
@@ -260,7 +260,7 @@
                this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
                this.zbGateway.ReportAction -= receiveAction;
                //发送失败给设备
                deviceAc.SendFinishAsync(1);
                HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
                return;
            }
@@ -278,7 +278,7 @@
                    this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
                    this.zbGateway.ReportAction -= receiveAction;
                    //发送失败给设备
                    deviceAc.SendFinishAsync(1);
                    HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 1);
                    return;
                }
                await System.Threading.Tasks.Task.Delay(1000);
@@ -298,7 +298,7 @@
        /// <summary>
        /// 执行设备升级操作
        /// </summary>
        private async void DoSetUpdateDevice(string i_offset,int i_dataLength)
        private async void DoSetUpdateDevice(string i_offset, int i_dataLength)
        {
            this.UpdateStatu = UpdateStatuMode.DeviceUpdateReady;
            //设备正在升级…
@@ -312,6 +312,8 @@
            int startIndex = 0;
            int allDataLength = this.deviceFirmwareByte.Length;
            int timeOut = 0;
            //是否接收到成功命令
            bool receiveSuccess = false;
            //接收网关的透传数据
            bool hadReceive = true;
@@ -338,14 +340,26 @@
                        //设置进度值
                        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 || hadReceive == false)
            while (startIndex < allDataLength)
            {
                if (receiveSuccess == true)
                {
                    //已经接收到成功的命令
                    break;
                }
                if (hadReceive == false)
                {
                    timeOut++;
@@ -358,13 +372,20 @@
                        this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
                        this.zbGateway.ReportAction -= receiveAction;
                        //发送失败给设备
                        deviceAc.SendFinishAsync(1);
                        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>();
@@ -373,15 +394,13 @@
                    listData.Add(this.deviceFirmwareByte[startIndex]);
                    if (listData.Count == i_dataLength)
                    {
                        //往下一位推移
                        startIndex++;
                        break;
                    }
                }
                //发送透传数据
                var sendData = new AC.SendUpgradeData() { dataLength = i_dataLength, offset = i_offset };
                var sendData = new HdlDeviceAirConditionerLogic.SendUpgradeData() { dataLength = i_dataLength, offset = i_offset };
                sendData.databytes = listData.ToArray();
                deviceAc.UpgradeAsync(sendData);
                HdlDeviceAirConditionerLogic.Current.UpgradeAsync(deviceAc, sendData);
            }
            this.zbGateway.ReportAction -= receiveAction;
@@ -402,7 +421,7 @@
            this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uSendingFinishUpdateComand));
            //发送成功命令给设备
            deviceAc.SendFinishAsync(0);
            HdlDeviceAirConditionerLogic.Current.SendFinishAsync(deviceAc, 0);
            //等个两秒钟吧
            await System.Threading.Tasks.Task.Delay(2000);