You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
462 lines
19 KiB
462 lines
19 KiB
1 year ago
|
//
|
||
1 year ago
|
// FirmwareUpdateViewModels.swift
|
||
1 year ago
|
// FireBoltt
|
||
1 year ago
|
//
|
||
|
// Created by lemo. on 2020/4/17.
|
||
|
// Copyright © 2020 Sheldon. All rights reserved.
|
||
|
//
|
||
|
|
||
|
import UIKit
|
||
|
import RxSwift
|
||
|
import iOSDFULibrary
|
||
|
import RTKOTASDK
|
||
|
|
||
|
|
||
1 year ago
|
|
||
1 year ago
|
enum FirmwareOTAPlan {
|
||
|
case nordic
|
||
|
/// 富芮坤
|
||
|
case frq
|
||
|
/// 瑞昱
|
||
|
case realtek
|
||
|
/// 杰里
|
||
|
case jerry
|
||
|
|
||
|
var fileType: String {
|
||
|
switch self {
|
||
|
case .nordic, .realtek: return "zip"
|
||
|
case .frq: return "bin"
|
||
|
case .jerry: return "ufw"
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
fileprivate let rtkEncryptKey: [UInt8] = [0x1B, 0x62, 0x8E, 0x11, 0xD3, 0x4C, 0x0D, 0x96, 0x70, 0x7E, 0x7A, 0x80, 0xDF, 0x63, 0x67, 0x1F, 0xFB, 0x10, 0xF6, 0xD1, 0x0C, 0x1A, 0x97, 0x9A, 0xE2, 0x29, 0x2B, 0x09, 0xC5, 0xF8, 0x46, 0x4E].reversed()
|
||
|
fileprivate let rtkEncryptKeyData = Data(rtkEncryptKey)
|
||
|
|
||
1 year ago
|
class FirmwareUpdateViewModels: ViewModel, ViewModelType, RTKLEPeripheralDelegate{
|
||
1 year ago
|
|
||
|
|
||
|
// override init() {
|
||
|
// super.init()
|
||
|
// jerryOTASuccess()
|
||
|
// }
|
||
|
|
||
|
|
||
|
struct Input {
|
||
|
let startUpdate: Observable<Void>
|
||
|
}
|
||
|
|
||
|
struct Output {
|
||
|
let versionTip: BehaviorRelay<String>
|
||
|
let versionLogTip: BehaviorRelay<NSAttributedString>
|
||
|
}
|
||
|
|
||
1 year ago
|
func transform(input: FirmwareUpdateViewModels.Input) -> FirmwareUpdateViewModels.Output {
|
||
1 year ago
|
input.startUpdate
|
||
|
.subscribe(onNext: { [weak self] _ in
|
||
|
// 二次确认
|
||
1 year ago
|
showAlert(currentViewController()!, MultiLanguageKey_FB.updateConfirmFB.localized, cancelText: "NO", confirmText: "YES") { (result) in
|
||
1 year ago
|
if result {
|
||
|
self?.startUpdateFirmware()
|
||
|
}
|
||
|
}
|
||
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
|
||
|
let firwareModel = GlobalDeviceProfileModel.shareInstance.firwareModel ?? FirmwareModel()
|
||
|
currenVersion = firwareModel.firmwareVersion;
|
||
1 year ago
|
var versionStr = MultiLanguageKey_FB.currenVerisonFB.localized + firwareModel.firmwareVersion
|
||
1 year ago
|
let versionTip = BehaviorRelay<String>(value: versionStr)
|
||
|
let versionLogTip = BehaviorRelay<NSAttributedString>(value: NSAttributedString(string: ""))
|
||
|
// 获取当前固件信息
|
||
|
SVProgressHUD.show()
|
||
|
if isDFU == false {
|
||
1 year ago
|
ProviderRequest(.getLastAppUpgrade(packageName: "FireBoltt.\(firwareModel.adapterNumber)"))
|
||
1 year ago
|
.flatMapLatest({ [weak self] (json) -> Observable<String> in
|
||
|
guard let `self` = self else { return .just("") }
|
||
|
SVProgressHUD.dismiss()
|
||
|
var url = json["data"]["url"].stringValue
|
||
|
url += json["data"]["apkName"].stringValue
|
||
|
let version = json["data"]["version"].intValue
|
||
|
let newVersion = String(format: "%d.%d.%d", version / 1000, version / 100 % 10, version % 100)
|
||
|
self.firmwareUrl = url
|
||
|
self.newVersion = json["data"]["apkName"].stringValue
|
||
|
// 更新
|
||
1 year ago
|
versionStr += ", \(MultiLanguageKey_FB.newVerisonFB.localized)\(newVersion)"
|
||
1 year ago
|
let remarkStr = json["data"]["remark"].string ?? ""
|
||
|
var remarkStrAtt = NSMutableAttributedString(string: "")
|
||
|
do {
|
||
|
if let data = remarkStr.data(using: String.Encoding.unicode, allowLossyConversion: true) {
|
||
|
let attStr = try NSMutableAttributedString.init(data: data, options: [NSAttributedString.DocumentReadingOptionKey.documentType : NSAttributedString.DocumentType.html], documentAttributes: nil)
|
||
|
attStr.addAttribute(NSAttributedString.Key.font, value: SystemRegularFont(16), range: NSMakeRange(0, attStr.length))
|
||
|
remarkStrAtt = attStr
|
||
|
}
|
||
|
}
|
||
|
versionLogTip.accept(remarkStrAtt)
|
||
|
// 强制升级
|
||
|
let isMandatory = json["data"]["imposed"].boolValue
|
||
|
if isMandatory {
|
||
|
self.startUpdateFirmware(isMandatory: isMandatory)
|
||
|
}
|
||
|
return Observable.just(versionStr)
|
||
|
})
|
||
|
.bind(to: versionTip)
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}else {
|
||
|
// DFU设备直接获取本地数据升级
|
||
|
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
|
||
|
let filePath = "\(paths)/firmware.zip"
|
||
|
// 启动升级
|
||
|
nordicFirmWare(fileName: filePath)
|
||
|
}
|
||
|
return Output(versionTip: versionTip,
|
||
|
versionLogTip: versionLogTip)
|
||
|
}
|
||
|
|
||
|
/// 固件升级状态
|
||
|
private var isOtaUpdate: Bool = false
|
||
|
/// 固件下载地址
|
||
|
private var firmwareUrl: String?
|
||
|
/// 当前版本号
|
||
|
private var currenVersion: String = ""
|
||
|
/// 最新版本号
|
||
|
private var newVersion: String = ""
|
||
|
/// 是否进入就是DFU设备
|
||
|
private var isDFU: Bool = false
|
||
|
/// 升级完成
|
||
|
let updateComplete = PublishSubject<Void>()
|
||
|
/// OTA升级类型
|
||
|
var otaPlan: FirmwareOTAPlan = .nordic
|
||
|
|
||
|
/// FRQOTA
|
||
|
lazy var frqOTAManager: FRIUpdateOTAManager = {
|
||
|
return FRIUpdateOTAManager()
|
||
|
}()
|
||
|
/// Realtek
|
||
|
lazy var rtkOTAProfile: RTKOTAProfile = {
|
||
|
return RTKOTAProfile()
|
||
|
}()
|
||
|
|
||
|
|
||
|
var rtkOTAPeripheral: RTKOTAPeripheral?
|
||
|
var rtkDFUPeripheral: RTKMultiDFUPeripheral?
|
||
|
var rtkOTAUpgradeBins: [RTKOTAUpgradeBin] = []
|
||
|
//var jlOTARunSDK: JL_RunSDK?
|
||
|
|
||
|
init(isDFU: Bool = false) {
|
||
|
super.init()
|
||
|
self.isDFU = isDFU
|
||
|
/// OTA升级方案
|
||
1 year ago
|
if let deviceInfo = UserDefaultsManagerFrieBoltt.getDeviceInfo() {
|
||
1 year ago
|
otaPlan = deviceInfo.otaPlan
|
||
|
switch otaPlan {
|
||
|
case .frq:
|
||
|
frqOTAManager.delegate = self
|
||
|
case .realtek:
|
||
|
rtkOTAProfile.delegate = self
|
||
|
case .jerry:
|
||
|
//JL_RunSDK.sharedInstance().delegate = self
|
||
1 year ago
|
BluetoothFireBoltt.shareInstance()?.jl_delegate = self
|
||
1 year ago
|
default:
|
||
|
break
|
||
|
}
|
||
|
}
|
||
|
// nordic DFU设备自动进入升级
|
||
|
kNotificationCenter.rx.notification(Notification.Name(rawValue: BluetoothNotificationAtDFUConnectSuccess))
|
||
|
.subscribe(onNext: { [weak self] _ in
|
||
|
guard let `self` = self else { return }
|
||
|
if self.isOtaUpdate == false {
|
||
|
// DFU设备直接获取本地数据升级
|
||
|
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
|
||
|
let filePath = "\(paths)/firmware.zip"
|
||
|
// 启动升级
|
||
|
self.nordicFirmWare(fileName: filePath)
|
||
|
}
|
||
|
})
|
||
|
.disposed(by: rx.disposeBag)
|
||
|
}
|
||
|
|
||
|
// private func jerryOTASuccess() {
|
||
|
// /// 杰里OTA升级成功失败监听
|
||
|
// Observable.of(kNotificationCenter.rx.notification(Notification.Name(rawValue: "JerryOTASuccess")))
|
||
|
// .merge()
|
||
|
// .subscribe(onNext: { [weak self] notification in
|
||
|
// self!.isOtaUpdate = false
|
||
1 year ago
|
// //SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.firmwareCompleteFB.localized)
|
||
1 year ago
|
// self!.updateComplete.onNext(())
|
||
|
//
|
||
|
// })
|
||
|
// .disposed(by: rx.disposeBag)
|
||
|
// }
|
||
|
|
||
|
}
|
||
|
|
||
1 year ago
|
extension FirmwareUpdateViewModels {
|
||
1 year ago
|
|
||
|
/// 启动固件升级
|
||
|
private func startUpdateFirmware(isMandatory: Bool = false) {
|
||
|
if isMandatory {
|
||
|
// 强制升级仅判断连接状态
|
||
1 year ago
|
let isConnect = BluetoothFireBoltt.shareInstance()?.isConnected ?? false
|
||
1 year ago
|
if !isConnect {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.bleTipFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
}else {
|
||
|
// 是否已连接 && 是否正在同步数据
|
||
1 year ago
|
if !BluetoothService.shared.checkBleCmdEnable(isShow: true) {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.bleTipFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
// 电量判断
|
||
|
if BluetoothService.shared.power.value < 30 {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.lowPowerFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
}
|
||
|
// 是否获取下载地址
|
||
|
guard let firmwareUrl = firmwareUrl else {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.networkErrorFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
// 版本是否一致
|
||
|
if currenVersion == newVersion {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.latestVerisonFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
// 下载固件 & 启动升级
|
||
|
SVProgressHUD.setDefaultMaskType(.black)
|
||
1 year ago
|
ProviderRequestDownloadWithProgress(APIManagerFireBoltt.downLoad(url: firmwareUrl))
|
||
1 year ago
|
.subscribe(onNext: {
|
||
|
[weak self] (result) in
|
||
|
guard let `self` = self else {return}
|
||
|
let progress = String(format: "%.0f%%", result.progress * 100)
|
||
|
SVProgressHUD.show(withStatus: "下载中".localized + progress)
|
||
|
if result.completed {
|
||
|
// 写入OTA文件
|
||
|
let data = (result.response?.data ?? Data()) as NSData
|
||
|
let paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true).first!
|
||
|
let filePath = self.otaPlan == .jerry ? String(format: "%@/%@", paths,self.newVersion) : "\(paths)/firmware.\(self.otaPlan.fileType)"
|
||
|
if !data.write(toFile: filePath, atomically: true) {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.networkErrorFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
switch self.otaPlan {
|
||
|
case .nordic:
|
||
|
self.nordicFirmWare(fileName: filePath)
|
||
|
case .frq:
|
||
|
self.frqOTAFirmWare(data: data)
|
||
|
case .realtek:
|
||
|
self.realtekOTAFirmWare(filePath: filePath)
|
||
|
case .jerry:
|
||
|
self.JLUpdateFailure(filePath: filePath, fileData: data)
|
||
|
print("杰里SDK升级")
|
||
|
}
|
||
|
}
|
||
|
}).disposed(by: rx.disposeBag)
|
||
|
// // 测试固件地址
|
||
|
// guard let filePath = Bundle.main.path(forResource: "v1014", ofType: "bin"), let data = NSData(contentsOfFile: filePath) else { return }
|
||
|
// switch otaPlan {
|
||
|
// case .nordic:
|
||
|
// nordicFirmWare(fileName: filePath)
|
||
|
// case .frq:
|
||
|
// frqOTAFirmWare(data: data)
|
||
|
// case .realtek:
|
||
|
// realtekOTAFirmWare(filePath: filePath)
|
||
|
// }
|
||
|
}
|
||
|
|
||
|
/// 开始固件升级
|
||
|
private func nordicFirmWare(fileName: String) {
|
||
|
guard let selectedFirmware = DFUFirmware.init(urlToZipFile: URL(fileURLWithPath: fileName)) else {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.updateFirmwareFailFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
1 year ago
|
guard let peripheral = BluetoothFireBoltt.shareInstance()!.currenModel.peripheral else {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.updateFirmwareFailFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
isOtaUpdate = true
|
||
|
let centralManager = CBCentralManager()
|
||
|
let initiator = DFUServiceInitiator.init(centralManager: centralManager, target: peripheral)
|
||
|
_ = initiator.with(firmware: selectedFirmware)
|
||
|
initiator.alternativeAdvertisingNameEnabled = false
|
||
|
initiator.logger = self
|
||
|
initiator.delegate = self
|
||
|
initiator.progressDelegate = self
|
||
|
_ = initiator.start()
|
||
|
}
|
||
|
|
||
|
/// 开始FRQ固件升级
|
||
|
private func frqOTAFirmWare(data: NSData) {
|
||
1 year ago
|
guard let write = BluetoothFireBoltt.shareInstance()?.frqOTAwritecharacteristic, let blemodel = BluetoothFireBoltt.shareInstance()!.currenModel, let peripheral = blemodel.peripheral else {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.updateFirmwareFailFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
isOtaUpdate = true
|
||
|
frqOTAManager.binData = data as Data
|
||
|
frqOTAManager.updateVersion = newVersion
|
||
|
frqOTAManager.startUpdateOTA(peripheral, write: write)
|
||
|
}
|
||
|
|
||
|
/// 开始Realtek固件升级
|
||
|
private func realtekOTAFirmWare(filePath: String) {
|
||
1 year ago
|
guard let blemodel = BluetoothFireBoltt.shareInstance()!.currenModel, let peripheral = blemodel.peripheral, let otaPeripheral = self.rtkOTAProfile.instantiatePeripheral(with: peripheral) as? RTKOTAPeripheral, let rtkOTAUpgradeBins = try? RTKOTAUpgradeBin.imagesExtracted(fromMPPackFilePath: filePath) else {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.updateFirmwareFailFB.localized)
|
||
1 year ago
|
return
|
||
|
}
|
||
|
isOtaUpdate = true
|
||
|
self.rtkOTAPeripheral = otaPeripheral
|
||
|
self.rtkOTAProfile.connect(to: otaPeripheral)
|
||
|
self.rtkOTAUpgradeBins = rtkOTAUpgradeBins
|
||
|
}
|
||
|
|
||
|
private func handleUpdateFailure() {
|
||
|
if self.isOtaUpdate {
|
||
1 year ago
|
SVProgressHUD.showError(withStatus: MultiLanguageKey_FB.updateFirmwareFailFB.localized)
|
||
1 year ago
|
isOtaUpdate = false
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/// 杰里固件升级
|
||
|
private func JLUpdateFailure(filePath: String, fileData:NSData){
|
||
|
// Bluetooth.shareInstance()! .jerryOTAUpgrade(filePath,fileData: fileData as Data)
|
||
1 year ago
|
BluetoothFireBoltt.shareInstance()?.otaFunc(withFilePaths: filePath);
|
||
1 year ago
|
SVProgressHUD .dismiss()
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
// MARK:- DFUProgressDelegate, DFUServiceDelegate, LoggerDelegate
|
||
1 year ago
|
extension FirmwareUpdateViewModels: DFUProgressDelegate, DFUServiceDelegate, LoggerDelegate {
|
||
1 year ago
|
func dfuProgressDidChange(for part: Int, outOf totalParts: Int, to progress: Int, currentSpeedBytesPerSecond: Double, avgSpeedBytesPerSecond: Double) {
|
||
|
SVProgressHUD.show(withStatus: "固件升级中".localized + " \(progress)%")
|
||
|
LFLogs("固件升级进度 part: \(part) totalProgress: \(totalParts) progress: \(progress) currentSpeedBytesPerSecond: \(currentSpeedBytesPerSecond) avgSpeedBytesPerSecond: \(avgSpeedBytesPerSecond)")
|
||
|
}
|
||
|
|
||
|
func dfuStateDidChange(to state: DFUState) {
|
||
|
LFLogs("固件升级状态: \(state)")
|
||
|
if (state == .completed) {
|
||
|
isOtaUpdate = false
|
||
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.firmwareCompleteFB.localized)
|
||
1 year ago
|
updateComplete.onNext(())
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func dfuError(_ error: DFUError, didOccurWithMessage message: String) {
|
||
|
if error.rawValue != 0 {
|
||
|
handleUpdateFailure()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func logWith(_ level: LogLevel, message: String) {
|
||
|
LFLogs("logWith level: \(level) message: \(message)")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// MARK:- FRQUpdateOTAManagerDelegate
|
||
1 year ago
|
extension FirmwareUpdateViewModels: FRIUpdateOTAManagerDelegate {
|
||
1 year ago
|
|
||
|
func onOTAUpdateStatusDidChange(_ ota: FRIUpdateOTAManager, withProgress aProgress: Float) {
|
||
|
LFLogs("[FRQOTA] onOTAUpdateStatusDidChange aProgress:\(aProgress)")
|
||
|
SVProgressHUD.show(withStatus: "固件升级中".localized + " \(Int(aProgress))%")
|
||
|
}
|
||
|
|
||
|
func onOTAUpdateStatusCompletion(_ ota: FRIUpdateOTAManager) {
|
||
|
LFLogs("[FRQOTA] onOTAUpdateStatusCompletion")
|
||
|
isOtaUpdate = false
|
||
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.firmwareCompleteFB.localized)
|
||
1 year ago
|
updateComplete.onNext(())
|
||
|
}
|
||
|
|
||
|
func onOTAUpdateStart(_ ota: FRIUpdateOTAManager) {
|
||
|
LFLogs("[FRQOTA] onOTAUpdateStart")
|
||
|
}
|
||
|
|
||
|
func onOTAUpdateStatusFailure(_ ota: FRIUpdateOTAManager, error err: Error) {
|
||
|
LFLogs("[FRQOTA] onOTAUpdateStatusFailure")
|
||
|
handleUpdateFailure()
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
// MARK:- RTKLEProfileDelegate, RTKMultiDFUPeripheralDelegate
|
||
1 year ago
|
extension FirmwareUpdateViewModels: RTKLEProfileDelegate, RTKMultiDFUPeripheralDelegate {
|
||
1 year ago
|
|
||
|
func profileManagerDidUpdateState(_ profile: RTKLEProfile) {
|
||
|
}
|
||
|
|
||
|
func profile(_ profile: RTKLEProfile, didConnect peripheral: RTKLEPeripheral) {
|
||
|
if peripheral == rtkOTAPeripheral, let rtkOTAPeripheral = rtkOTAPeripheral {
|
||
|
// 转换DFU外设
|
||
|
if rtkOTAUpgradeBins.count == 1 && !(rtkOTAUpgradeBins.last?.icDetermined ?? false) {
|
||
|
rtkOTAUpgradeBins.last?.assertAvailable(for: rtkOTAPeripheral)
|
||
|
}
|
||
|
// 判断升级类型
|
||
|
if rtkOTAPeripheral.canEnterOTAMode {
|
||
|
rtkOTAProfile.translate(rtkOTAPeripheral) { [weak self] success, error, dfuPeripheral in
|
||
|
if success, let dfuPeripheral = dfuPeripheral {
|
||
|
self?.rtkDFUPeripheral = dfuPeripheral as? RTKMultiDFUPeripheral
|
||
|
self?.rtkDFUPeripheral?.delegate = self
|
||
|
self?.rtkOTAProfile.connect(to: dfuPeripheral)
|
||
|
}else {
|
||
|
self?.handleUpdateFailure()
|
||
|
}
|
||
|
}
|
||
|
return
|
||
|
}
|
||
|
handleUpdateFailure()
|
||
|
}else if peripheral == rtkDFUPeripheral {
|
||
|
// 启动升级
|
||
|
rtkDFUPeripheral?.setEncryptKey(rtkEncryptKeyData)
|
||
|
rtkDFUPeripheral?.upgradeImages(rtkOTAUpgradeBins, inOTAMode: true)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didSend length: UInt, totalToSend totalLength: UInt) {
|
||
|
let progress = CGFloat(length) / CGFloat(totalLength) * 100
|
||
|
LFLogs("[RTKOTA] dfuPeripheral progress:\(progress)")
|
||
|
SVProgressHUD.show(withStatus: "固件升级中".localized + " \(Int(progress))%")
|
||
|
}
|
||
|
|
||
|
func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didFinishWithError err: Error?) {
|
||
|
if err == nil {
|
||
|
LFLogs("[RTKOTA] dfuPeripheral Upgrade complete successfully")
|
||
|
isOtaUpdate = false
|
||
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.firmwareCompleteFB.localized)
|
||
1 year ago
|
updateComplete.onNext(())
|
||
|
}else {
|
||
|
LFLogs("[RTKOTA] dfuPeripheral Upgrade Fail")
|
||
|
handleUpdateFailure()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
1 year ago
|
extension FirmwareUpdateViewModels:JL_SDKOtaDelegate{
|
||
1 year ago
|
func otaProgress(with result: JL_OTAResult, withProgress progress: Float) {
|
||
|
isOtaUpdate = true
|
||
|
if result == .success{
|
||
|
isOtaUpdate = false
|
||
1 year ago
|
SVProgressHUD.showSuccess(withStatus: MultiLanguageKey_FB.firmwareCompleteFB.localized)
|
||
1 year ago
|
updateComplete.onNext(())
|
||
1 year ago
|
BluetoothFireBoltt.shareInstance()?.otaTimeClose()
|
||
1 year ago
|
}
|
||
|
|
||
|
if result == .fail {
|
||
|
SVProgressHUD.dismiss()
|
||
1 year ago
|
BluetoothFireBoltt.shareInstance()?.otaTimeClose()
|
||
1 year ago
|
print("---> 固件升级失败")
|
||
|
// Bluetooth.shareInstance()?.startAndStopReconnect(true)
|
||
|
handleUpdateFailure()
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|
||
|
}
|