Commit 79a1562ade8ad648e670e910fb8297fec1386884

Authored by jason
1 parent 6535c9df

feat:remove ota

HDFwear/Setting/DailSyncSubVC.swift
... ... @@ -100,18 +100,18 @@ class DailSyncSubVC: UIViewController {
100 100 return
101 101 }
102 102 let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
103   - BluetoothManager.shared.syncFileWith(path: path) { progress in
104   - cell.updateProgressView(Int(Double(progress)*0.95)+5)
105   - } completion: {[weak self] error in
106   - self?.updateUserInteraction(false)
107   - if error == nil {
108   - self?.syncComplete(indexPath: indexPath)
109   - cell.syncComplete()
110   - } else {
111   - cell.initProgressView()
112   - self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
113   - }
114   - }
  103 +// BluetoothManager.shared.syncFileWith(path: path) { progress in
  104 +// cell.updateProgressView(Int(Double(progress)*0.95)+5)
  105 +// } completion: {[weak self] error in
  106 +// self?.updateUserInteraction(false)
  107 +// if error == nil {
  108 +// self?.syncComplete(indexPath: indexPath)
  109 +// cell.syncComplete()
  110 +// } else {
  111 +// cell.initProgressView()
  112 +// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
  113 +// }
  114 +// }
115 115 }
116 116  
117 117  
... ...
HDFwear/Setting/DailSyncViewController.swift
... ... @@ -203,7 +203,7 @@ class DailSyncViewController: UIViewController, XMLParserDelegate {
203 203 cell.updateProgressView(Int(progress.fractionCompleted*5), isDownload: true)
204 204 }.responseData {[weak self] response in
205 205 if let _ = response.value {
206   - self?.syncDail(indexPath, cell: cell, path: response.destinationURL!.path)
  206 +// self?.syncDail(indexPath, cell: cell, path: response.destinationURL!.path)
207 207 } else {
208 208 cell.initProgressView()
209 209 self?.updateUserInteraction(false)
... ... @@ -212,66 +212,66 @@ class DailSyncViewController: UIViewController, XMLParserDelegate {
212 212 }
213 213 }
214 214  
215   - private func syncDail(_ indexPath: IndexPath, cell: DailCell, path: String = "") {
216   - if showAlert() { return }
217   - if platform == ._828 {
218   - if !FileManager.default.fileExists(atPath: path) {
219   - updateUserInteraction(false)
220   - showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
221   - return
222   - }
223   -// let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
224   - BluetoothManager.shared.syncFileWith(path: path) { progress in
225   - cell.updateProgressView(Int(Double(progress)*0.95)+5)
226   - } completion: {[weak self] error in
227   - self?.updateUserInteraction(false)
228   - if error == nil {
229   - self?.syncCompleteOnline(indexPath: indexPath)
230   - cell.syncComplete()
231   - } else {
232   - cell.initProgressView()
233   - self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
234   - }
235   - }
236   - } else {
237   - if IsDailSyncing { return }
238   - let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
239   - if cell.progressView.label.text == LocString("已安装") { return }
240   - updateUserInteraction(true)
241   - cell.updateProgressView(0)
242   -// switch platform {
243   -// case ._816:
244   -// BluetoothManager.shared.syncDialWith(path: "\(Bundle.main.resourcePath!)/dial/Dialdata280/\(indexPath.row)") { progress in
245   -// cell.updateProgressView(progress)
246   -// } completion: {[weak self] error in
247   -// self?.updateUserInteraction(false)
248   -// if error == nil {
249   -// cell.syncComplete()
250   -// } else {
251   -// cell.initProgressView()
252   -// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
253   -// }
254   -// }
255   -//
256   -// case ._818:
257   -// BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataRtk/\(indexPath.row)/dial.bin") { progress in
258   -// cell.updateProgressView(progress)
259   -// } completion: {[weak self] error in
260   -// self?.updateUserInteraction(false)
261   -// if error == nil {
262   -// self?.syncComplete(index: indexPath.row)
263   -// cell.syncComplete()
264   -// } else {
265   -// cell.initProgressView()
266   -// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
267   -// }
  215 +// private func syncDail(_ indexPath: IndexPath, cell: DailCell, path: String = "") {
  216 +// if showAlert() { return }
  217 +// if platform == ._828 {
  218 +// if !FileManager.default.fileExists(atPath: path) {
  219 +// updateUserInteraction(false)
  220 +// showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
  221 +// return
  222 +// }
  223 +//// let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
  224 +// BluetoothManager.shared.syncFileWith(path: path) { progress in
  225 +// cell.updateProgressView(Int(Double(progress)*0.95)+5)
  226 +// } completion: {[weak self] error in
  227 +// self?.updateUserInteraction(false)
  228 +// if error == nil {
  229 +// self?.syncCompleteOnline(indexPath: indexPath)
  230 +// cell.syncComplete()
  231 +// } else {
  232 +// cell.initProgressView()
  233 +// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
268 234 // }
269   -//
270   -// default:
271   -// break
272 235 // }
273   - }
274   - }
  236 +// } else {
  237 +// if IsDailSyncing { return }
  238 +// let cell = self.collectionView.cellForItem(at: indexPath) as! DailCell
  239 +// if cell.progressView.label.text == LocString("已安装") { return }
  240 +// updateUserInteraction(true)
  241 +// cell.updateProgressView(0)
  242 +//// switch platform {
  243 +//// case ._816:
  244 +//// BluetoothManager.shared.syncDialWith(path: "\(Bundle.main.resourcePath!)/dial/Dialdata280/\(indexPath.row)") { progress in
  245 +//// cell.updateProgressView(progress)
  246 +//// } completion: {[weak self] error in
  247 +//// self?.updateUserInteraction(false)
  248 +//// if error == nil {
  249 +//// cell.syncComplete()
  250 +//// } else {
  251 +//// cell.initProgressView()
  252 +//// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
  253 +//// }
  254 +//// }
  255 +////
  256 +//// case ._818:
  257 +//// BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataRtk/\(indexPath.row)/dial.bin") { progress in
  258 +//// cell.updateProgressView(progress)
  259 +//// } completion: {[weak self] error in
  260 +//// self?.updateUserInteraction(false)
  261 +//// if error == nil {
  262 +//// self?.syncComplete(index: indexPath.row)
  263 +//// cell.syncComplete()
  264 +//// } else {
  265 +//// cell.initProgressView()
  266 +//// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
  267 +//// }
  268 +//// }
  269 +////
  270 +//// default:
  271 +//// break
  272 +//// }
  273 +// }
  274 +// }
275 275  
276 276 func syncComplete(index: Int) {
277 277 user.dailIndex = index
... ... @@ -382,7 +382,7 @@ extension DailSyncViewController: UICollectionViewDelegate, UICollectionViewData
382 382 if self?.platform == ._828 {
383 383 self?.downloadDailFile(indexPath)
384 384 } else {
385   - self?.syncDail(indexPath, cell: cell)
  385 +// self?.syncDail(indexPath, cell: cell)
386 386 }
387 387  
388 388 }
... ...
HDFwear/Setting/DialSyncLocalVC.swift
... ... @@ -47,23 +47,23 @@ class DialSyncLocalVC: UIViewController {
47 47 if cell.progressView.label.text == LocString("已安装") { return }
48 48 updateUserInteraction(true)
49 49 cell.updateProgressView(0)
50   - switch CurDevice.platform {
51   - case ._828:
52   - BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataHQ7/\(indexPath.row)/dial.bin") { progress in
53   - cell.updateProgressView(progress)
54   - } completion: {[weak self] error in
55   - self?.updateUserInteraction(false)
56   - if error == nil {
57   - self?.syncComplete(index: indexPath.row)
58   - cell.syncComplete()
59   - } else {
60   - cell.initProgressView()
61   - self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
62   - }
63   - }
64   - default:
65   - break
66   - }
  50 +// switch CurDevice.platform {
  51 +// case ._828:
  52 +// BluetoothManager.shared.syncFileWith(path: "\(Bundle.main.resourcePath!)/dial/DialDataHQ7/\(indexPath.row)/dial.bin") { progress in
  53 +// cell.updateProgressView(progress)
  54 +// } completion: {[weak self] error in
  55 +// self?.updateUserInteraction(false)
  56 +// if error == nil {
  57 +// self?.syncComplete(index: indexPath.row)
  58 +// cell.syncComplete()
  59 +// } else {
  60 +// cell.initProgressView()
  61 +// self?.showAlert(title: LocString("提示"), message: LocString("安装失败,请重试"), cancelText: nil)
  62 +// }
  63 +// }
  64 +// default:
  65 +// break
  66 +// }
67 67 }
68 68  
69 69 func syncComplete(index: Int) {
... ...
HDFwear/Setting/FirmwareUpdateVC.swift
... ... @@ -206,25 +206,25 @@ class FirmwareUpdateVC: UIViewController, XMLParserDelegate {
206 206 // return
207 207 updateUserInteraction(true)
208 208 updateLabel.text = LocString("正在升级中...")
209   - BluetoothManager.shared.syncFileWith(path: path, isFirmware: true) {[weak self] progress in
210   - let n = progress/2 * 2
211   - self?.updateImageView.image = UIImage(named: "update_\(n)")
212   - self?.progressLabel.text = "\(progress)%"
213   - } completion: {[weak self] error in
214   - self?.updateUserInteraction(false)
215   - if error == nil {
216   - self?.updateLabel.text = LocString("升级完成")
217   - self?.updateBtn.setTitle(LocString("升级完成"), for: .normal)
218   - self?.updateImageView.image = UIImage(named: "update_100")
219   - let str1 = LocString("当前已是最新版本")
220   - let string = NSMutableAttributedString(string: "\(str1)\nv \((self?.latestVersion)!)")
221   - string.addAttributes([.foregroundColor: UIColor.rgbColorFromHex(0x00993E)], range: NSMakeRange(str1.count, string.string.count-str1.count))
222   - self?.versionLabel.attributedText = string
223   -
224   - } else {
225   - self?.showAlert(title: LocString("提示"), message: LocString("升级失败,请重试"), cancelText: nil)
226   - }
227   - }
  209 +// BluetoothManager.shared.syncFileWith(path: path, isFirmware: true) {[weak self] progress in
  210 +// let n = progress/2 * 2
  211 +// self?.updateImageView.image = UIImage(named: "update_\(n)")
  212 +// self?.progressLabel.text = "\(progress)%"
  213 +// } completion: {[weak self] error in
  214 +// self?.updateUserInteraction(false)
  215 +// if error == nil {
  216 +// self?.updateLabel.text = LocString("升级完成")
  217 +// self?.updateBtn.setTitle(LocString("升级完成"), for: .normal)
  218 +// self?.updateImageView.image = UIImage(named: "update_100")
  219 +// let str1 = LocString("当前已是最新版本")
  220 +// let string = NSMutableAttributedString(string: "\(str1)\nv \((self?.latestVersion)!)")
  221 +// string.addAttributes([.foregroundColor: UIColor.rgbColorFromHex(0x00993E)], range: NSMakeRange(str1.count, string.string.count-str1.count))
  222 +// self?.versionLabel.attributedText = string
  223 +//
  224 +// } else {
  225 +// self?.showAlert(title: LocString("提示"), message: LocString("升级失败,请重试"), cancelText: nil)
  226 +// }
  227 +// }
228 228 }
229 229  
230 230 // func parseXML(_ data: Data) {
... ...
HDFwear/Tools/BluetoothManager.swift
... ... @@ -248,7 +248,7 @@ class BluetoothManager: NSObject {
248 248 // MTKBleManager.sharedInstance() = nil
249 249 manger = MTKBleManager.sharedInstance() as? MTKBleManager
250 250  
251   - OTAPeripheral = nil
  251 +// OTAPeripheral = nil
252 252 peripheral = nil
253 253 let device = DeviceModel()
254 254 // device.menstrual = menstrual
... ... @@ -437,65 +437,65 @@ class BluetoothManager: NSObject {
437 437  
438 438  
439 439  
440   - var OTAProfile: RTKOTAProfile? = nil
441   - var OTAPeripheral: RTKOTAPeripheral? = nil
442   - var DFUPeripheral: RTKMultiDFUPeripheral? = nil
443   - var upgradeBins: [RTKOTAUpgradeBin] = []
444   - var isFirmwareUpdate: Bool = false
  440 +// var OTAProfile: RTKOTAProfile? = nil
  441 +// var OTAPeripheral: RTKOTAPeripheral? = nil
  442 +// var DFUPeripheral: RTKMultiDFUPeripheral? = nil
  443 +// var upgradeBins: [RTKOTAUpgradeBin] = []
  444 +// var isFirmwareUpdate: Bool = false
445 445  
446 446  
447 447  
448   - func syncFileWith(path: String, isFirmware: Bool = false, progress: @escaping SyncRTKProgressClosure, completion: @escaping SyncRTKClosure) {
449   - isFirmwareUpdate = isFirmware
450   - if OTAPeripheral == nil {
451   - return
452   - }
453   - startSyncDial()
454   - syncRTKProgressClosure = progress
455   - syncRTKClosure = completion
456   -
457   - do {
458   - upgradeBins = try RTKOTAUpgradeBin.imagesExtracted(fromMPPackFilePath: path)
459   - } catch {
460   - print("fail")
461   - return
462   - }
463   -
464   - if upgradeBins.count == 1 {
465   - if !(upgradeBins.last!.icDetermined) {
466   - upgradeBins.last?.assertAvailable(for: OTAPeripheral!)
467   - }
468   - }
469   - if OTAPeripheral!.canUpgradeSliently && !OTAPeripheral!.isRWS {
470   - let peripheral = OTAProfile!.dfuPeripheral(of: OTAPeripheral!)
471   - DFUPeripheral = peripheral as? RTKMultiDFUPeripheral
472   - DFUPeripheral!.delegate = self
473   - OTAProfile?.connect(to: DFUPeripheral!)
474   - }
475   -
476   - }
  448 +// func syncFileWith(path: String, isFirmware: Bool = false, progress: @escaping SyncRTKProgressClosure, completion: @escaping SyncRTKClosure) {
  449 +// isFirmwareUpdate = isFirmware
  450 +// if OTAPeripheral == nil {
  451 +// return
  452 +// }
  453 +// startSyncDial()
  454 +// syncRTKProgressClosure = progress
  455 +// syncRTKClosure = completion
  456 +//
  457 +// do {
  458 +// upgradeBins = try RTKOTAUpgradeBin.imagesExtracted(fromMPPackFilePath: path)
  459 +// } catch {
  460 +// print("fail")
  461 +// return
  462 +// }
  463 +//
  464 +// if upgradeBins.count == 1 {
  465 +// if !(upgradeBins.last!.icDetermined) {
  466 +// upgradeBins.last?.assertAvailable(for: OTAPeripheral!)
  467 +// }
  468 +// }
  469 +// if OTAPeripheral!.canUpgradeSliently && !OTAPeripheral!.isRWS {
  470 +// let peripheral = OTAProfile!.dfuPeripheral(of: OTAPeripheral!)
  471 +// DFUPeripheral = peripheral as? RTKMultiDFUPeripheral
  472 +// DFUPeripheral!.delegate = self
  473 +// OTAProfile?.connect(to: DFUPeripheral!)
  474 +// }
  475 +//
  476 +// }
477 477  
478 478  
479   - func toUpgradeImages() -> [RTKOTAUpgradeBin] {
480   - if OTAPeripheral == nil {
481   - return []
482   - }
483   - switch OTAPeripheral?.activeBank.rawValue {
484   - case 0:
485   - let imagesForBank1: [RTKOTAUpgradeBin] = self.upgradeBins.filter{$0.upgradeBank == .bank1}
486   - if imagesForBank1.count > 0 {
487   - return []
488   - } else {
489   - return self.upgradeBins
490   - }
491   - case 1:
492   - return self.upgradeBins.filter{$0.upgradeBank == .bank1 || $0.upgradeBank == .unknown}
493   - case 2:
494   - return self.upgradeBins.filter{$0.upgradeBank == .singleOrBank0 || $0.upgradeBank == .unknown}
495   - default:
496   - return self.upgradeBins
497   - }
498   - }
  479 +// func toUpgradeImages() -> [RTKOTAUpgradeBin] {
  480 +// if OTAPeripheral == nil {
  481 +// return []
  482 +// }
  483 +// switch OTAPeripheral?.activeBank.rawValue {
  484 +// case 0:
  485 +// let imagesForBank1: [RTKOTAUpgradeBin] = self.upgradeBins.filter{$0.upgradeBank == .bank1}
  486 +// if imagesForBank1.count > 0 {
  487 +// return []
  488 +// } else {
  489 +// return self.upgradeBins
  490 +// }
  491 +// case 1:
  492 +// return self.upgradeBins.filter{$0.upgradeBank == .bank1 || $0.upgradeBank == .unknown}
  493 +// case 2:
  494 +// return self.upgradeBins.filter{$0.upgradeBank == .singleOrBank0 || $0.upgradeBank == .unknown}
  495 +// default:
  496 +// return self.upgradeBins
  497 +// }
  498 +// }
499 499  
500 500  
501 501  
... ... @@ -1388,7 +1388,7 @@ extension BluetoothManager: ClientProfileDelegate {
1388 1388  
1389 1389 if platform == ._828 {
1390 1390 print("828连接")
1391   - OTAProfile = RTKOTAProfile(delegate: self)
  1391 +// OTAProfile = RTKOTAProfile(delegate: self)
1392 1392 startSync828(delayTime)
1393 1393 }
1394 1394  
... ... @@ -1600,43 +1600,43 @@ extension BluetoothManager: CBCentralManagerDelegate {
1600 1600 }
1601 1601  
1602 1602  
1603   -extension BluetoothManager: RTKMultiDFUPeripheralDelegate, RTKLEProfileDelegate {
1604   - func profileManagerDidUpdateState(_ profile: RTKLEProfile) {
1605   - if profile.centralManager.state == .poweredOn && self.peripheral != nil {
1606   -// print("RTK??????????????")
1607   - OTAPeripheral = OTAProfile?.instantiatePeripheral(with: self.peripheral!) as? RTKOTAPeripheral
1608   - OTAProfile?.connect(to: OTAPeripheral!)
1609   - }
1610   - }
1611   -
1612   - func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didSend length: UInt, totalToSend totalLength: UInt) {
1613   - print("\(length) ---- \(totalLength)")
1614   - startSyncDial()
1615   - syncRTKProgressClosure?(Int(Float(length)/Float(totalLength)*100))
1616   - }
1617   -
1618   - func profile(_ profile: RTKLEProfile, didConnect peripheral: RTKLEPeripheral) {
1619   - if peripheral == self.DFUPeripheral {
1620   - DFUPeripheral?.upgradeImages(self.toUpgradeImages(), inOTAMode: false)
1621   - }
1622   - }
1623   -
1624   - func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didFinishWithError err: Error?) {
1625   -// if err != nil {
1626   - print("dfuPeripheral \\ \(err)")
1627   - isSyncDial = false
1628   - if GCDTimer.shared.isExistTimer(WithTimerName: "SyncDial") {
1629   - GCDTimer.shared.cancleTimer(WithTimerName: "SyncDial")
1630   - }
1631   - syncRTKClosure?(err)
  1603 +//extension BluetoothManager: RTKMultiDFUPeripheralDelegate, RTKLEProfileDelegate {
  1604 +// func profileManagerDidUpdateState(_ profile: RTKLEProfile) {
  1605 +// if profile.centralManager.state == .poweredOn && self.peripheral != nil {
  1606 +//// print("RTK??????????????")
  1607 +// OTAPeripheral = OTAProfile?.instantiatePeripheral(with: self.peripheral!) as? RTKOTAPeripheral
  1608 +// OTAProfile?.connect(to: OTAPeripheral!)
1632 1609 // }
1633   - }
1634   -
1635   - func dfuPeripheral(_ peripheral: RTKDFUPeripheral, shouldWaitForDisconnectionOnCompleteSend image: RTKOTAUpgradeBin) -> Bool {
1636   - return isFirmwareUpdate
1637   - }
1638   -
1639   -}
  1610 +// }
  1611 +//
  1612 +// func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didSend length: UInt, totalToSend totalLength: UInt) {
  1613 +// print("\(length) ---- \(totalLength)")
  1614 +// startSyncDial()
  1615 +// syncRTKProgressClosure?(Int(Float(length)/Float(totalLength)*100))
  1616 +// }
  1617 +//
  1618 +// func profile(_ profile: RTKLEProfile, didConnect peripheral: RTKLEPeripheral) {
  1619 +// if peripheral == self.DFUPeripheral {
  1620 +// DFUPeripheral?.upgradeImages(self.toUpgradeImages(), inOTAMode: false)
  1621 +// }
  1622 +// }
  1623 +//
  1624 +// func dfuPeripheral(_ peripheral: RTKDFUPeripheral, didFinishWithError err: Error?) {
  1625 +//// if err != nil {
  1626 +// print("dfuPeripheral \\ \(err)")
  1627 +// isSyncDial = false
  1628 +// if GCDTimer.shared.isExistTimer(WithTimerName: "SyncDial") {
  1629 +// GCDTimer.shared.cancleTimer(WithTimerName: "SyncDial")
  1630 +// }
  1631 +// syncRTKClosure?(err)
  1632 +//// }
  1633 +// }
  1634 +//
  1635 +// func dfuPeripheral(_ peripheral: RTKDFUPeripheral, shouldWaitForDisconnectionOnCompleteSend image: RTKOTAUpgradeBin) -> Bool {
  1636 +// return isFirmwareUpdate
  1637 +// }
  1638 +//
  1639 +//}
1640 1640  
1641 1641 extension BluetoothManager: XMLParserDelegate {
1642 1642 private func queryLatestVersion(version: String, type: String) {
... ...