From 79a1562ade8ad648e670e910fb8297fec1386884 Mon Sep 17 00:00:00 2001 From: jason Date: Fri, 29 Dec 2023 20:34:37 +0800 Subject: [PATCH] feat:remove ota --- HDFwear/Setting/DailSyncSubVC.swift | 24 ++++++++++++------------ HDFwear/Setting/DailSyncViewController.swift | 120 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------ HDFwear/Setting/DialSyncLocalVC.swift | 34 +++++++++++++++++----------------- HDFwear/Setting/FirmwareUpdateVC.swift | 38 +++++++++++++++++++------------------- HDFwear/Tools/BluetoothManager.swift | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------- 5 files changed, 200 insertions(+), 200 deletions(-) diff --git a/HDFwear/Setting/DailSyncSubVC.swift b/HDFwear/Setting/DailSyncSubVC.swift index 9029c99..576ac4c 100644 --- a/HDFwear/Setting/DailSyncSubVC.swift +++ b/HDFwear/Setting/DailSyncSubVC.swift @@ -100,18 +100,18 @@ class DailSyncSubVC: UIViewController { return } let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell - BluetoothManager.shared.syncFileWith(path: path) { progress in - cell.updateProgressView(Int(Double(progress)*0.95)+5) - } completion: {[weak self] error in - self?.updateUserInteraction(false) - if error == nil { - self?.syncComplete(indexPath: indexPath) - cell.syncComplete() - } else { - cell.initProgressView() - self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) - } - } +// BluetoothManager.shared.syncFileWith(path: path) { progress in +// cell.updateProgressView(Int(Double(progress)*0.95)+5) +// } completion: {[weak self] error in +// self?.updateUserInteraction(false) +// if error == nil { +// self?.syncComplete(indexPath: indexPath) +// cell.syncComplete() +// } else { +// cell.initProgressView() +// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) +// } +// } } diff --git a/HDFwear/Setting/DailSyncViewController.swift b/HDFwear/Setting/DailSyncViewController.swift index 05f8ce3..e7435f3 100644 --- a/HDFwear/Setting/DailSyncViewController.swift +++ b/HDFwear/Setting/DailSyncViewController.swift @@ -203,7 +203,7 @@ class DailSyncViewController: UIViewController, XMLParserDelegate { cell.updateProgressView(Int(progress.fractionCompleted*5), isDownload: true) }.responseData {[weak self] response in if let _ = response.value { - self?.syncDail(indexPath, cell: cell, path: response.destinationURL!.path) +// self?.syncDail(indexPath, cell: cell, path: response.destinationURL!.path) } else { cell.initProgressView() self?.updateUserInteraction(false) @@ -212,66 +212,66 @@ class DailSyncViewController: UIViewController, XMLParserDelegate { } } - private func syncDail(_ indexPath: IndexPath, cell: DailCell, path: String = "") { - if showAlert() { return } - if platform == ._828 { - if !FileManager.default.fileExists(atPath: path) { - updateUserInteraction(false) - showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) - return - } -// let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell - BluetoothManager.shared.syncFileWith(path: path) { progress in - cell.updateProgressView(Int(Double(progress)*0.95)+5) - } completion: {[weak self] error in - self?.updateUserInteraction(false) - if error == nil { - self?.syncCompleteOnline(indexPath: indexPath) - cell.syncComplete() - } else { - cell.initProgressView() - self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) - } - } - } else { - if IsDailSyncing { return } - let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell - if cell.progressView.label.text == LocString("已安装") { return } - updateUserInteraction(true) - cell.updateProgressView(0) -// switch platform { -// case ._816: -// BluetoothManager.shared.syncDialWith(path: "\(Bundle.main.resourcePath!)/dial/Dialdata280/\(indexPath.row)") { progress in -// cell.updateProgressView(progress) -// } completion: {[weak self] error in -// self?.updateUserInteraction(false) -// if error == nil { -// cell.syncComplete() -// } else { -// cell.initProgressView() -// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) -// } -// } -// -// case ._818: -// BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataRtk/\(indexPath.row)/dial.bin") { progress in -// cell.updateProgressView(progress) -// } completion: {[weak self] error in -// self?.updateUserInteraction(false) -// if error == nil { -// self?.syncComplete(index: indexPath.row) -// cell.syncComplete() -// } else { -// cell.initProgressView() -// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) -// } +// private func syncDail(_ indexPath: IndexPath, cell: DailCell, path: String = "") { +// if showAlert() { return } +// if platform == ._828 { +// if !FileManager.default.fileExists(atPath: path) { +// updateUserInteraction(false) +// showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) +// return +// } +//// let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell +// BluetoothManager.shared.syncFileWith(path: path) { progress in +// cell.updateProgressView(Int(Double(progress)*0.95)+5) +// } completion: {[weak self] error in +// self?.updateUserInteraction(false) +// if error == nil { +// self?.syncCompleteOnline(indexPath: indexPath) +// cell.syncComplete() +// } else { +// cell.initProgressView() +// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) // } -// -// default: -// break // } - } - } +// } else { +// if IsDailSyncing { return } +// let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell +// if cell.progressView.label.text == LocString("已安装") { return } +// updateUserInteraction(true) +// cell.updateProgressView(0) +//// switch platform { +//// case ._816: +//// BluetoothManager.shared.syncDialWith(path: "\(Bundle.main.resourcePath!)/dial/Dialdata280/\(indexPath.row)") { progress in +//// cell.updateProgressView(progress) +//// } completion: {[weak self] error in +//// self?.updateUserInteraction(false) +//// if error == nil { +//// cell.syncComplete() +//// } else { +//// cell.initProgressView() +//// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) +//// } +//// } +//// +//// case ._818: +//// BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataRtk/\(indexPath.row)/dial.bin") { progress in +//// cell.updateProgressView(progress) +//// } completion: {[weak self] error in +//// self?.updateUserInteraction(false) +//// if error == nil { +//// self?.syncComplete(index: indexPath.row) +//// cell.syncComplete() +//// } else { +//// cell.initProgressView() +//// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) +//// } +//// } +//// +//// default: +//// break +//// } +// } +// } func syncComplete(index: Int) { user.dailIndex = index @@ -382,7 +382,7 @@ extension DailSyncViewController: UICollectionViewDelegate, UICollectionViewData if self?.platform == ._828 { self?.downloadDailFile(indexPath) } else { - self?.syncDail(indexPath, cell: cell) +// self?.syncDail(indexPath, cell: cell) } } diff --git a/HDFwear/Setting/DialSyncLocalVC.swift b/HDFwear/Setting/DialSyncLocalVC.swift index b8a1468..29998b9 100644 --- a/HDFwear/Setting/DialSyncLocalVC.swift +++ b/HDFwear/Setting/DialSyncLocalVC.swift @@ -47,23 +47,23 @@ class DialSyncLocalVC: UIViewController { if cell.progressView.label.text == LocString("已安装") { return } updateUserInteraction(true) cell.updateProgressView(0) - switch CurDevice.platform { - case ._828: - BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataHQ7/\(indexPath.row)/dial.bin") { progress in - cell.updateProgressView(progress) - } completion: {[weak self] error in - self?.updateUserInteraction(false) - if error == nil { - self?.syncComplete(index: indexPath.row) - cell.syncComplete() - } else { - cell.initProgressView() - self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) - } - } - default: - break - } +// switch CurDevice.platform { +// case ._828: +// BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataHQ7/\(indexPath.row)/dial.bin") { progress in +// cell.updateProgressView(progress) +// } completion: {[weak self] error in +// self?.updateUserInteraction(false) +// if error == nil { +// self?.syncComplete(index: indexPath.row) +// cell.syncComplete() +// } else { +// cell.initProgressView() +// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil) +// } +// } +// default: +// break +// } } func syncComplete(index: Int) { diff --git a/HDFwear/Setting/FirmwareUpdateVC.swift b/HDFwear/Setting/FirmwareUpdateVC.swift index 53d8e75..3b18da7 100644 --- a/HDFwear/Setting/FirmwareUpdateVC.swift +++ b/HDFwear/Setting/FirmwareUpdateVC.swift @@ -206,25 +206,25 @@ class FirmwareUpdateVC: UIViewController, XMLParserDelegate { // return updateUserInteraction(true) updateLabel.text = LocString("正在升级中...") - BluetoothManager.shared.syncFileWith(path: path, isFirmware: true) {[weak self] progress in - let n = progress/2 * 2 - self?.updateImageView.image = UIImage(named: "update_\(n)") - self?.progressLabel.text = "\(progress)%" - } completion: {[weak self] error in - self?.updateUserInteraction(false) - if error == nil { - self?.updateLabel.text = LocString("升级完成") - self?.updateBtn.setTitle(LocString("升级完成"), for: .normal) - self?.updateImageView.image = UIImage(named: "update_100") - let str1 = LocString("当前已是最新版本") - let string = NSMutableAttributedString(string: "\(str1)\nv \((self?.latestVersion)!)") - string.addAttributes([.foregroundColor: UIColor.rgbColorFromHex(0x00993E)], range: NSMakeRange(str1.count, string.string.count-str1.count)) - self?.versionLabel.attributedText = string - - } else { - self?.showAlert(title: LocString("提示"), message: LocString("升级失败,请重试"), cancelText: nil) - } - } +// BluetoothManager.shared.syncFileWith(path: path, isFirmware: true) {[weak self] progress in +// let n = progress/2 * 2 +// self?.updateImageView.image = UIImage(named: "update_\(n)") +// self?.progressLabel.text = "\(progress)%" +// } completion: {[weak self] error in +// self?.updateUserInteraction(false) +// if error == nil { +// self?.updateLabel.text = LocString("升级完成") +// self?.updateBtn.setTitle(LocString("升级完成"), for: .normal) +// self?.updateImageView.image = UIImage(named: "update_100") +// let str1 = LocString("当前已是最新版本") +// let string = NSMutableAttributedString(string: "\(str1)\nv \((self?.latestVersion)!)") +// string.addAttributes([.foregroundColor: UIColor.rgbColorFromHex(0x00993E)], range: NSMakeRange(str1.count, string.string.count-str1.count)) +// self?.versionLabel.attributedText = string +// +// } else { +// self?.showAlert(title: LocString("提示"), message: LocString("升级失败,请重试"), cancelText: nil) +// } +// } } // func parseXML(_ data: Data) { diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index 37eb365..3547a57 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -248,7 +248,7 @@ class BluetoothManager: NSObject { // MTKBleManager.sharedInstance() = nil manger = MTKBleManager.sharedInstance() as? MTKBleManager - OTAPeripheral = nil +// OTAPeripheral = nil peripheral = nil let device = DeviceModel() // device.menstrual = menstrual @@ -437,65 +437,65 @@ class BluetoothManager: NSObject { - var OTAProfile: RTKOTAProfile? = nil - var OTAPeripheral: RTKOTAPeripheral? = nil - var DFUPeripheral: RTKMultiDFUPeripheral? = nil - var upgradeBins: [RTKOTAUpgradeBin] = [] - var isFirmwareUpdate: Bool = false +// var OTAProfile: RTKOTAProfile? = nil +// var OTAPeripheral: RTKOTAPeripheral? = nil +// var DFUPeripheral: RTKMultiDFUPeripheral? = nil +// var upgradeBins: [RTKOTAUpgradeBin] = [] +// var isFirmwareUpdate: Bool = false - func syncFileWith(path: String, isFirmware: Bool = false, progress: @escaping SyncRTKProgressClosure, completion: @escaping SyncRTKClosure) { - isFirmwareUpdate = isFirmware - if OTAPeripheral == nil { - return - } - startSyncDial() - syncRTKProgressClosure = progress - syncRTKClosure = completion - - do { - upgradeBins = try RTKOTAUpgradeBin.imagesExtracted(fromMPPackFilePath: path) - } catch { - print("fail") - return - } - - if upgradeBins.count == 1 { - if !(upgradeBins.last!.icDetermined) { - upgradeBins.last?.assertAvailable(for: OTAPeripheral!) - } - } - if OTAPeripheral!.canUpgradeSliently && !OTAPeripheral!.isRWS { - let peripheral = OTAProfile!.dfuPeripheral(of: OTAPeripheral!) - DFUPeripheral = peripheral as? RTKMultiDFUPeripheral - DFUPeripheral!.delegate = self - OTAProfile?.connect(to: DFUPeripheral!) - } - - } +// func syncFileWith(path: String, isFirmware: Bool = false, progress: @escaping SyncRTKProgressClosure, completion: @escaping SyncRTKClosure) { +// isFirmwareUpdate = isFirmware +// if OTAPeripheral == nil { +// return +// } +// startSyncDial() +// syncRTKProgressClosure = progress +// syncRTKClosure = completion +// +// do { +// upgradeBins = try RTKOTAUpgradeBin.imagesExtracted(fromMPPackFilePath: path) +// } catch { +// print("fail") +// return +// } +// +// if upgradeBins.count == 1 { +// if !(upgradeBins.last!.icDetermined) { +// upgradeBins.last?.assertAvailable(for: OTAPeripheral!) +// } +// } +// if OTAPeripheral!.canUpgradeSliently && !OTAPeripheral!.isRWS { +// let peripheral = OTAProfile!.dfuPeripheral(of: OTAPeripheral!) +// DFUPeripheral = peripheral as? RTKMultiDFUPeripheral +// DFUPeripheral!.delegate = self +// OTAProfile?.connect(to: DFUPeripheral!) +// } +// +// } - func toUpgradeImages() -> [RTKOTAUpgradeBin] { - if OTAPeripheral == nil { - return [] - } - switch OTAPeripheral?.activeBank.rawValue { - case 0: - let imagesForBank1: [RTKOTAUpgradeBin] = self.upgradeBins.filter{$0.upgradeBank == .bank1} - if imagesForBank1.count > 0 { - return [] - } else { - return self.upgradeBins - } - case 1: - return self.upgradeBins.filter{$0.upgradeBank == .bank1 || $0.upgradeBank == .unknown} - case 2: - return self.upgradeBins.filter{$0.upgradeBank == .singleOrBank0 || $0.upgradeBank == .unknown} - default: - return self.upgradeBins - } - } +// func toUpgradeImages() -> [RTKOTAUpgradeBin] { +// if OTAPeripheral == nil { +// return [] +// } +// switch OTAPeripheral?.activeBank.rawValue { +// case 0: +// let imagesForBank1: [RTKOTAUpgradeBin] = self.upgradeBins.filter{$0.upgradeBank == .bank1} +// if imagesForBank1.count > 0 { +// return [] +// } else { +// return self.upgradeBins +// } +// case 1: +// return self.upgradeBins.filter{$0.upgradeBank == .bank1 || $0.upgradeBank == .unknown} +// case 2: +// return self.upgradeBins.filter{$0.upgradeBank == .singleOrBank0 || $0.upgradeBank == .unknown} +// default: +// return self.upgradeBins +// } +// } @@ -1388,7 +1388,7 @@ extension BluetoothManager: ClientProfileDelegate { if platform == ._828 { print("828连接") - OTAProfile = RTKOTAProfile(delegate: self) +// OTAProfile = RTKOTAProfile(delegate: self) startSync828(delayTime) } @@ -1600,43 +1600,43 @@ extension BluetoothManager: CBCentralManagerDelegate { } -extension BluetoothManager: RTKMultiDFUPeripheralDelegate, RTKLEProfileDelegate { - func profileManagerDidUpdateState(_ profile: RTKLEProfile) { - if profile.centralManager.state == .poweredOn && self.peripheral != nil { -// print("RTK??????????????") - OTAPeripheral = OTAProfile?.instantiatePeripheral(with: self.peripheral!) as? RTKOTAPeripheral - OTAProfile?.connect(to: OTAPeripheral!) - } - } - - func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didSend length: UInt, totalToSend totalLength: UInt) { - print("\(length) ---- \(totalLength)") - startSyncDial() - syncRTKProgressClosure?(Int(Float(length)/Float(totalLength)*100)) - } - - func profile(_ profile: RTKLEProfile, didConnect peripheral: RTKLEPeripheral) { - if peripheral == self.DFUPeripheral { - DFUPeripheral?.upgradeImages(self.toUpgradeImages(), inOTAMode: false) - } - } - - func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didFinishWithError err: Error?) { -// if err != nil { - print("dfuPeripheral \\ \(err)") - isSyncDial = false - if GCDTimer.shared.isExistTimer(WithTimerName: "SyncDial") { - GCDTimer.shared.cancleTimer(WithTimerName: "SyncDial") - } - syncRTKClosure?(err) +//extension BluetoothManager: RTKMultiDFUPeripheralDelegate, RTKLEProfileDelegate { +// func profileManagerDidUpdateState(_ profile: RTKLEProfile) { +// if profile.centralManager.state == .poweredOn && self.peripheral != nil { +//// print("RTK??????????????") +// OTAPeripheral = OTAProfile?.instantiatePeripheral(with: self.peripheral!) as? RTKOTAPeripheral +// OTAProfile?.connect(to: OTAPeripheral!) // } - } - - func dfuPeripheral(_ peripheral: RTKDFUPeripheral, shouldWaitForDisconnectionOnCompleteSend image: RTKOTAUpgradeBin) -> Bool { - return isFirmwareUpdate - } - -} +// } +// +// func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didSend length: UInt, totalToSend totalLength: UInt) { +// print("\(length) ---- \(totalLength)") +// startSyncDial() +// syncRTKProgressClosure?(Int(Float(length)/Float(totalLength)*100)) +// } +// +// func profile(_ profile: RTKLEProfile, didConnect peripheral: RTKLEPeripheral) { +// if peripheral == self.DFUPeripheral { +// DFUPeripheral?.upgradeImages(self.toUpgradeImages(), inOTAMode: false) +// } +// } +// +// func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didFinishWithError err: Error?) { +//// if err != nil { +// print("dfuPeripheral \\ \(err)") +// isSyncDial = false +// if GCDTimer.shared.isExistTimer(WithTimerName: "SyncDial") { +// GCDTimer.shared.cancleTimer(WithTimerName: "SyncDial") +// } +// syncRTKClosure?(err) +//// } +// } +// +// func dfuPeripheral(_ peripheral: RTKDFUPeripheral, shouldWaitForDisconnectionOnCompleteSend image: RTKOTAUpgradeBin) -> Bool { +// return isFirmwareUpdate +// } +// +//} extension BluetoothManager: XMLParserDelegate { private func queryLatestVersion(version: String, type: String) { -- libgit2 0.21.4