| | |
| | | /// <summary>
|
| | | /// HDL设备升级的逻辑
|
| | | /// </summary>
|
| | | public class HdlDeviceUpdateLogic
|
| | | public class HdlDeviceUpdateLogic : HdlDeviceUpdateCommonLogic
|
| | | {
|
| | | #region ■ 变量声明___________________________
|
| | |
|
| | |
| | | /// <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 UpdateStatuMode UpdateStatu = UpdateStatuMode.None;
|
| | | /// <summary>
|
| | | /// 设备新版本的固件信息(多个设备升级时,应该会需要公开这个对象)
|
| | | /// </summary> |
| | | public FirmwareVersionInfo deviceFirmware = null;
|
| | | /// <summary>
|
| | | /// 升级是否完成(出现错误时,它也会变成true)
|
| | | /// </summary>
|
| | | public bool IsFinishUpdate = true;
|
| | |
|
| | | /// <summary>
|
| | | /// 网关
|
| | | /// </summary>
|
| | |
| | | /// <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;
|
| | |
| | | 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;
|
| | | this.UpdateStatuChangedEvent?.Invoke(3, "");
|
| | | return;
|
| | | }
|
| | | //如果它有状态,则表示之前它被什么错误中断了
|
| | |
| | |
|
| | | //进入等待模式
|
| | | this.UpdateStatu = UpdateStatuMode.Wait;
|
| | | FirmwareUpdateResourse.dicDeviceUpdateList[otaDevice.DeviceAddr] = this;
|
| | | FirmwareUpdateResourse.dicUpdateList[otaDevice.DeviceAddr] = this;
|
| | |
|
| | | //等待中…
|
| | | this.UpdateStatuChangedEvent?.Invoke(0, Language.StringByID(R.MyInternationalizationString.uWaitting));
|
| | |
| | | }
|
| | |
|
| | | /// <summary>
|
| | | /// 开始执行更新操作
|
| | | /// 开始执行更新操作(FirmwareUpdateLogic调用)
|
| | | /// </summary>
|
| | | public void DoStartUpdate()
|
| | | public override void DoStartUpdate()
|
| | | {
|
| | | //状态变更
|
| | | this.IsFinishUpdate = false;
|
| | |
| | | return;
|
| | | }
|
| | | var tempZb = (ZbGateway)objValue;
|
| | | if (tempZb.CurrentGateWayId != HdlGatewayLogic.Current.GetGatewayId(this.zbGateway))
|
| | | if (tempZb.GwId != this.zbGateway.GwId)
|
| | | {
|
| | | //不是自己的网关推送,则不处理
|
| | | return;
|
| | |
| | | return;
|
| | | }
|
| | | var tempZb = (ZbGateway)objValue;
|
| | | if (tempZb.CurrentGateWayId != HdlGatewayLogic.Current.GetGatewayId(this.zbGateway))
|
| | | if (tempZb.GwId != this.zbGateway.GwId)
|
| | | {
|
| | | //不是自己的网关推送,则不处理
|
| | | return;
|
| | |
| | | {
|
| | | this.zbGateway.ReportAction -= this.UpdateDeviceProgress;
|
| | |
|
| | | new System.Threading.Thread(async () =>
|
| | | HdlThreadLogic.Current.RunThread(async () =>
|
| | | {
|
| | | //终止升级
|
| | | await this.otaDevice.KillUpdateAsync(this.zbGateway, 200);
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | });
|
| | |
|
| | | this.UpdateStatu = UpdateStatuMode.DeviceUpdateFail;
|
| | | return;
|
| | |
| | | /// </summary>
|
| | | /// <param name="statusData"></param>
|
| | | /// <returns></returns>
|
| | | private bool CheckStatusCode(ZbGatewayData.OTAScheduleResponData statusData)
|
| | | private bool CheckStatusCode(CommonDevice.OTAScheduleResponData statusData)
|
| | | {
|
| | | if (statusData == null)
|
| | | {
|
| | |
| | | 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;
|
| | | }
|
| | |
| | | //升级成功
|
| | | this.UpdateStatu = UpdateStatuMode.UpdateSuccess;
|
| | |
|
| | | new System.Threading.Thread(() =>
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | System.Threading.Thread.Sleep(3000);
|
| | |
|
| | |
| | | //移除事件
|
| | | HdlDeviceImageInfoLogic.Current.RemoveDeviceFirmwareVersionThread(otaDevice);
|
| | |
|
| | | 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));
|
| | | });
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | //设备升级成功!
|
| | | this.UpdateStatuChangedEvent?.Invoke(1, Language.StringByID(R.MyInternationalizationString.uDeviceUpdateSuccess));
|
| | | });
|
| | | }
|
| | |
|
| | | #endregion
|
| | |
| | | private void StartDownLoadTimeOutThread()
|
| | | {
|
| | | this.downLoadTimeOutCount = 30;
|
| | | new System.Threading.Thread(() =>
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | while (true)
|
| | | {
|
| | |
| | | break;
|
| | | }
|
| | | }
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | private void StartUpdateTimeOutThread()
|
| | | {
|
| | | this.UpdateTimeOutCount = 60;
|
| | | new System.Threading.Thread(() =>
|
| | | HdlThreadLogic.Current.RunThread(() =>
|
| | | {
|
| | | while (true)
|
| | | {
|
| | |
| | | break;
|
| | | }
|
| | | }
|
| | | })
|
| | | { IsBackground = true }.Start();
|
| | | });
|
| | | }
|
| | |
|
| | | /// <summary>
|
| | |
| | | /// <summary>
|
| | | /// 释放缓存
|
| | | /// </summary>
|
| | | public void Dispose()
|
| | | public override void Dispose()
|
| | | {
|
| | | this.ProgressEvent = null;
|
| | | this.UpdateStatuChangedEvent = null;
|