Commit cbc826f8469c2aa0da90cb4ab7fe3b73a7d957a7

Authored by jason
1 parent 8225514b

feat:remove sync status lock

HDFwear/Home/HomeViewController.swift
... ... @@ -707,7 +707,7 @@ extension HomeViewController: XMLParserDelegate {
707 707 isFirstSync = true
708 708 queryArray = CurDevice.queryArray
709 709 print("开始同步数据 Home")
710   - BluetoothManager.shared.syncBug()
  710 +// BluetoothManager.shared.syncBug()
711 711 syncStep(.today)
712 712 }
713 713  
... ... @@ -826,11 +826,11 @@ extension HomeViewController: XMLParserDelegate {
826 826 self?.queryArray.remove(at: index)
827 827 // isFirstSync = false
828 828 self?.queryFirmwareVersion()
829   - self?.syncFinish()
  829 +// self?.syncFinish()
830 830 }
831 831 } else {
832 832 queryFirmwareVersion()
833   - syncFinish()
  833 +// syncFinish()
834 834 }
835 835 }
836 836  
... ... @@ -856,28 +856,28 @@ extension HomeViewController: XMLParserDelegate {
856 856 }
857 857  
858 858  
859   - func syncFinish() {
860   - print("\(queryArray)---同步完成!!!---")
861   - collectionView.reloadData()
862   - queryArray = CurDevice.queryArray
863   - updateStepView()
864   - isFirstSync = false
865   - // if DailSyncBug {
866   - // GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "DailSyncBug", timeInterval: 5, queue: .main, repeats: false) {
867   - // self.dailSyncBug()
868   - // }
869   - // }
870   -
871   - scrollView.mj_header?.endRefreshing()
872   - scrollView.mj_header?.isHidden = false
873   - }
  859 +// func syncFinish() {
  860 +// print("\(queryArray)---同步完成!!!---")
  861 +// collectionView.reloadData()
  862 +// queryArray = CurDevice.queryArray
  863 +// updateStepView()
  864 +// isFirstSync = false
  865 +// // if DailSyncBug {
  866 +// // GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "DailSyncBug", timeInterval: 5, queue: .main, repeats: false) {
  867 +// // self.dailSyncBug()
  868 +// // }
  869 +// // }
  870 +//
  871 +// scrollView.mj_header?.endRefreshing()
  872 +// scrollView.mj_header?.isHidden = false
  873 +// }
874 874 // func dailSyncBug() {
875 875 // DailSyncBug = false
876 876 // }
877 877  
878   - func syncBug() {
879   - // if !isFirstSync {
880   - syncFinish()
881   - // }
882   - }
  878 +// func syncBug() {
  879 +// // if !isFirstSync {
  880 +// syncFinish()
  881 +// // }
  882 +// }
883 883 }
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -304,93 +304,93 @@ extension BluetoothManager {
304 304  
305 305 // 同步数据
306 306 func newStartSyncHealthData(closure: Any?, data: Data, synType: SyncType) {
307   - if !isSync {
  307 +// if !isSync {
308 308 GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncInterval", timeInterval: 0.1, queue: .main, repeats: false) {
309 309 self.clearClosures(closure: closure)
310   - self.startSyncTimer()
311   - self.isNextSync = false
312   - self.isSync = true
313   - self.isSyncType = synType
  310 +// self.startSyncTimer()
  311 +// self.isNextSync = false
  312 +// self.isSync = true
  313 +// self.isSyncType = synType
314 314 self.sendData(data)
315 315 }
316   - } else {
317   - switch closure {
318   - case is BloodPressureClosure:
319   - if bloodPressureClosure == nil {
320   - bloodPressureClosure = closure as? BloodPressureClosure
321   - bloodPressureClosure?([], -1002)
322   - bloodPressureClosure = nil
323   - }
324   - case is HeartRateClosure:
325   - if heartRateClosure == nil {
326   - heartRateClosure = closure as? HeartRateClosure
327   - heartRateClosure?([], -1002)
328   - heartRateClosure = nil
329   - }
330   - case is BloodOxygenClosure:
331   - if bloodOxygenClosure == nil {
332   - bloodOxygenClosure = closure as? BloodOxygenClosure
333   - bloodOxygenClosure?([], -1002)
334   - bloodOxygenClosure = nil
335   - }
336   - case is SleepClosure:
337   - if sleepClosure == nil {
338   - sleepClosure = closure as? SleepClosure
339   - sleepClosure?(nil, -1002)
340   - sleepClosure = nil
341   - }
342   - case is StepClosure:
343   - if stepClosure == nil {
344   - stepClosure = closure as? StepClosure
345   - stepClosure?([], -1002)
346   - stepClosure = nil
347   - }
348   - case is ExerciseClosure:
349   - if exerciseClosure == nil {
350   - exerciseClosure = closure as? ExerciseClosure
351   - exerciseClosure?(nil, -1002)
352   - exerciseClosure = nil
353   - }
354   - case is PressureClosure:
355   - if pressureClosure == nil {
356   - pressureClosure = closure as? PressureClosure
357   - pressureClosure?([], -1002)
358   - pressureClosure = nil
359   - }
360   - case is MettClosure:
361   - if mettClosure == nil {
362   - mettClosure = closure as? MettClosure
363   - mettClosure?([], -1002)
364   - mettClosure = nil
365   - }
366   - case is GpsClosure:
367   - if gpsClosure == nil {
368   - gpsClosure = closure as? GpsClosure
369   - gpsClosure?(nil, -1002)
370   - gpsClosure = nil
371   - }
372   - case is IntensiveTimeClosure:
373   - if intensiveTimeClosure == nil {
374   - intensiveTimeClosure = closure as? IntensiveTimeClosure
375   - intensiveTimeClosure?(nil, -1002)
376   - intensiveTimeClosure = nil
377   - }
378   - case is BeidouCardClosure:
379   - if beidouCardClosure == nil {
380   - beidouCardClosure = closure as? BeidouCardClosure
381   - beidouCardClosure?(nil, -1002)
382   - beidouCardClosure = nil
383   - }
384   - case is FirmwareVersionClosure:
385   - if firmwareVersionClosure == nil {
386   - firmwareVersionClosure = closure as? FirmwareVersionClosure
387   - firmwareVersionClosure?(nil, nil, -1002)
388   - firmwareVersionClosure = nil
389   - }
390   - default:
391   - break
392   - }
393   - }
  316 +// } else {
  317 +// switch closure {
  318 +// case is BloodPressureClosure:
  319 +// if bloodPressureClosure == nil {
  320 +// bloodPressureClosure = closure as? BloodPressureClosure
  321 +// bloodPressureClosure?([], -1002)
  322 +// bloodPressureClosure = nil
  323 +// }
  324 +// case is HeartRateClosure:
  325 +// if heartRateClosure == nil {
  326 +// heartRateClosure = closure as? HeartRateClosure
  327 +// heartRateClosure?([], -1002)
  328 +// heartRateClosure = nil
  329 +// }
  330 +// case is BloodOxygenClosure:
  331 +// if bloodOxygenClosure == nil {
  332 +// bloodOxygenClosure = closure as? BloodOxygenClosure
  333 +// bloodOxygenClosure?([], -1002)
  334 +// bloodOxygenClosure = nil
  335 +// }
  336 +// case is SleepClosure:
  337 +// if sleepClosure == nil {
  338 +// sleepClosure = closure as? SleepClosure
  339 +// sleepClosure?(nil, -1002)
  340 +// sleepClosure = nil
  341 +// }
  342 +// case is StepClosure:
  343 +// if stepClosure == nil {
  344 +// stepClosure = closure as? StepClosure
  345 +// stepClosure?([], -1002)
  346 +// stepClosure = nil
  347 +// }
  348 +// case is ExerciseClosure:
  349 +// if exerciseClosure == nil {
  350 +// exerciseClosure = closure as? ExerciseClosure
  351 +// exerciseClosure?(nil, -1002)
  352 +// exerciseClosure = nil
  353 +// }
  354 +// case is PressureClosure:
  355 +// if pressureClosure == nil {
  356 +// pressureClosure = closure as? PressureClosure
  357 +// pressureClosure?([], -1002)
  358 +// pressureClosure = nil
  359 +// }
  360 +// case is MettClosure:
  361 +// if mettClosure == nil {
  362 +// mettClosure = closure as? MettClosure
  363 +// mettClosure?([], -1002)
  364 +// mettClosure = nil
  365 +// }
  366 +// case is GpsClosure:
  367 +// if gpsClosure == nil {
  368 +// gpsClosure = closure as? GpsClosure
  369 +// gpsClosure?(nil, -1002)
  370 +// gpsClosure = nil
  371 +// }
  372 +// case is IntensiveTimeClosure:
  373 +// if intensiveTimeClosure == nil {
  374 +// intensiveTimeClosure = closure as? IntensiveTimeClosure
  375 +// intensiveTimeClosure?(nil, -1002)
  376 +// intensiveTimeClosure = nil
  377 +// }
  378 +// case is BeidouCardClosure:
  379 +// if beidouCardClosure == nil {
  380 +// beidouCardClosure = closure as? BeidouCardClosure
  381 +// beidouCardClosure?(nil, -1002)
  382 +// beidouCardClosure = nil
  383 +// }
  384 +// case is FirmwareVersionClosure:
  385 +// if firmwareVersionClosure == nil {
  386 +// firmwareVersionClosure = closure as? FirmwareVersionClosure
  387 +// firmwareVersionClosure?(nil, nil, -1002)
  388 +// firmwareVersionClosure = nil
  389 +// }
  390 +// default:
  391 +// break
  392 +// }
  393 +// }
394 394 }
395 395 //MARK: - 发送数据
396 396 func sendData(_ data: Data) {
... ... @@ -455,11 +455,11 @@ extension BluetoothManager {
455 455 }
456 456 //MARK: - 解析数据
457 457 func parseData(_ bytes: [UInt8]) {
458   - stopSyncTimer(BLEConfig.SyncHealthTimer)
459   - if !isNextSync {
460   - isSync = false
461   - isSyncType = .other
462   - }
  458 +// stopSyncTimer(BLEConfig.SyncHealthTimer)
  459 +// if !isNextSync {
  460 +// isSync = false
  461 +// isSyncType = .other
  462 +// }
463 463 // debug
464 464 // let bytes: [UInt8] = [0xED, 0x7E, 0x00, 0x01, 0x80, 0x16, 0x00, 0x07, 0x00, 0xC8, 0x64, 0x9D, 0xA3, 0xB4, 0x70, 0x64, 0x9D, 0xAA, 0xBC, 0xF7, 0x64, 0x9D, 0xB1, 0xC4, 0x06, 0x64, 0x9D, 0xB8, 0xCC, 0x00, 0x64, 0x9D, 0xBF, 0xD4, 0x16, 0x64, 0x9D, 0xC6, 0xDC, 0xF9, 0x64, 0x9D, 0xCD, 0xE4, 0x06, 0x64, 0x9D, 0xD4, 0xEC, 0x00, 0x64, 0x9D, 0xDB, 0xF4, 0x00, 0x64, 0x9D, 0xE2, 0xFC, 0xFB, 0x64, 0x9D, 0xEA, 0x04, 0x06, 0x64, 0x9D, 0xF1, 0x0C, 0x00, 0x64, 0x9D, 0xF8, 0x14, 0xE5, 0x64, 0x9D, 0xFF, 0x1C, 0xFD, 0x64, 0x9E, 0x06, 0x24, 0x06, 0x64, 0x9E, 0x0D, 0x2C, 0x00, 0x64, 0x9E, 0x14, 0x34, 0xC5, 0x64, 0x9E, 0x1B, 0x3C, 0xFF, 0x64, 0x9E, 0x22, 0x44, 0x06, 0x64, 0x9E, 0x29, 0x4C, 0x00, 0x64, 0x9E, 0x30, 0x54, 0xB4, 0x64, 0x9E, 0x37, 0x5C, 0x01, 0x64, 0x9E, 0x3E, 0x64, 0x07, 0x64, 0x9E, 0x45, 0x6C, 0x00, 0x64, 0x9E, 0x4C, 0x74, 0x9E, 0x64, 0x9E, 0x53, 0x7C, 0x02, 0x64, 0x9E, 0x5A, 0x84, 0x07, 0x64, 0x9E, 0x61, 0x8C, 0x00, 0x64, 0x9E, 0x68, 0x94, 0x83, 0x64, 0x9E, 0x6F, 0x9C, 0x04, 0x64, 0x9E, 0x76, 0xA4, 0x07, 0x64, 0x9E, 0x7D, 0xAC, 0x00, 0x64, 0x9E, 0x84, 0xB4, 0x72, 0x64, 0x9E, 0x8B, 0xBC, 0x06, 0x64, 0x9E, 0x92, 0xC4, 0x07, 0x64, 0x9E, 0x99, 0xCC, 0x00, 0x64, 0x9E, 0xA0, 0xD4, 0x57, 0x64, 0x9E, 0xA7, 0xDC, 0x08, 0x64, 0x9E, 0xAE, 0xE4, 0x07, 0x64, 0x9E, 0xB5, 0xEC, 0x14, 0x17, 0x3E]
465 465 totalLength = 0
... ...
HDFwear/Tools/BluetoothManager.swift
... ... @@ -34,7 +34,7 @@ protocol BluetoothSyncDelegate {
34 34 func didReceiveSettingData()
35 35 func didReceiveStep()
36 36 func firstSync()
37   - func syncBug()
  37 +// func syncBug()
38 38 // adapted
39 39 func didReceiveBattery(value: Int)
40 40 func didReceiveFindPhoneCommand(value: Int)
... ... @@ -54,7 +54,7 @@ extension BluetoothSyncDelegate {
54 54 func didReceiveSettingData() { }
55 55 func didReceiveStep() { }
56 56 func firstSync() {}
57   - func syncBug() {}
  57 +// func syncBug() {}
58 58 // adapted
59 59 func didReceiveBattery(value: Int) { }
60 60 func didReceiveFindPhoneCommand(value: Int) { }
... ... @@ -159,10 +159,10 @@ class BluetoothManager: NSObject {
159 159 var mergeLength: Int = 0
160 160  
161 161 //sync
162   - var isSyncReceived: Bool = false //是否收到同步data
163   - var isSync: Bool = false //是否在同步中
164   - var isSyncType: SyncType = .other //正在同步的指令
165   - var isNextSync: Bool = false //是否有下一个同步包
  162 +// var isSyncReceived: Bool = false //是否收到同步data
  163 +// var isSync: Bool = false //是否在同步中
  164 +// var isSyncType: SyncType = .other //正在同步的指令
  165 +// var isNextSync: Bool = false //是否有下一个同步包
166 166 // private var
167 167  
168 168 // 任务执行管理
... ... @@ -705,18 +705,18 @@ class BluetoothManager: NSObject {
705 705  
706 706  
707 707  
708   - func syncBug() {
709   -// if GCDTimer.s
710   - GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "syncBug", timeInterval: 25, queue: .main, repeats: false) {
711   - print("同步超时")
712   - self.isSync = false
713   - self.isSyncType = .other
714   - self.isSyncReceived = false
715   - for delegate in self.syncDelegateList {
716   - delegate.syncBug()
717   - }
718   - }
719   - }
  708 +// func syncBug() {
  709 +//// if GCDTimer.s
  710 +// GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "syncBug", timeInterval: 25, queue: .main, repeats: false) {
  711 +// print("同步超时")
  712 +// self.isSync = false
  713 +// self.isSyncType = .other
  714 +// self.isSyncReceived = false
  715 +// for delegate in self.syncDelegateList {
  716 +// delegate.syncBug()
  717 +// }
  718 +// }
  719 +// }
720 720  
721 721 //MARK: - 解析数据- deprecatd
722 722 //MARK: -
... ... @@ -1280,46 +1280,46 @@ class BluetoothManager: NSObject {
1280 1280  
1281 1281  
1282 1282 //MARK: - 同步计时器
1283   - func startSyncTimer() {
1284   - stopSyncTimer(BLEConfig.SyncHealthTimer)
1285   -
1286   - GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: BLEConfig.SyncHealthTimer, timeInterval: 3, queue: .main, repeats: false) {[weak self] in
1287   - print("同步记时完毕")
1288   - if !(self?.isSyncReceived ?? true) {
1289   - self?.syncReceiveFail()
1290   - }
1291   - }
1292   - print("开始同步计时")
1293   -
1294   -
1295   -// if GCDTimer.shared.isExistTimer(WithTimerName: BLEConfig.SyncHealthTimer) {
1296   -//
1297   -// }
1298   -
1299   - }
  1283 +// func startSyncTimer() {
  1284 +// stopSyncTimer(BLEConfig.SyncHealthTimer)
  1285 +//
  1286 +// GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: BLEConfig.SyncHealthTimer, timeInterval: 3, queue: .main, repeats: false) {[weak self] in
  1287 +// print("同步记时完毕")
  1288 +// if !(self?.isSyncReceived ?? true) {
  1289 +// self?.syncReceiveFail()
  1290 +// }
  1291 +// }
  1292 +// print("开始同步计时")
  1293 +//
  1294 +//
  1295 +//// if GCDTimer.shared.isExistTimer(WithTimerName: BLEConfig.SyncHealthTimer) {
  1296 +////
  1297 +//// }
  1298 +//
  1299 +// }
1300 1300  
1301   - func stopSyncTimer(_ name: String) {
1302   - isSyncReceived = false
1303   - if GCDTimer.shared.isExistTimer(WithTimerName: name) {
1304   - GCDTimer.shared.cancleTimer(WithTimerName: name)
1305   - print("停止同步计时")
1306   - }
1307   - }
  1301 +// func stopSyncTimer(_ name: String) {
  1302 +// isSyncReceived = false
  1303 +// if GCDTimer.shared.isExistTimer(WithTimerName: name) {
  1304 +// GCDTimer.shared.cancleTimer(WithTimerName: name)
  1305 +// print("停止同步计时")
  1306 +// }
  1307 +// }
1308 1308  
1309   - func syncReceiveFail() {
1310   - print("同步失败")
1311   -// stopSyncTimer(BLEConfig.SyncHealthTimer)
1312   - isSync = false
1313   - isSyncType = .other
1314   - heartRateClosure?([], -1001)
1315   - bloodPressureClosure?([], -1001)
1316   - bloodOxygenClosure?([], -1001)
1317   - sleepClosure?(nil, -1001)
1318   - stepClosure?([], -1001)
1319   - exerciseClosure?(nil, -1001)
1320   - pressureClosure?([], -1001)
1321   - mettClosure?([], -1001)
1322   - }
  1309 +// func syncReceiveFail() {
  1310 +// print("同步失败")
  1311 +//// stopSyncTimer(BLEConfig.SyncHealthTimer)
  1312 +// isSync = false
  1313 +// isSyncType = .other
  1314 +// heartRateClosure?([], -1001)
  1315 +// bloodPressureClosure?([], -1001)
  1316 +// bloodOxygenClosure?([], -1001)
  1317 +// sleepClosure?(nil, -1001)
  1318 +// stepClosure?([], -1001)
  1319 +// exerciseClosure?(nil, -1001)
  1320 +// pressureClosure?([], -1001)
  1321 +// mettClosure?([], -1001)
  1322 +// }
1323 1323  
1324 1324 func clearClosures(closure: Any?) {
1325 1325 heartRateClosure = nil
... ... @@ -1851,7 +1851,7 @@ extension BluetoothManager: CBPeripheralDelegate {
1851 1851 func mergeData(_ data: Data) {
1852 1852 let bytes = [UInt8](data)
1853 1853 // print(bytes)
1854   - isSyncReceived = true
  1854 +// isSyncReceived = true
1855 1855 if bytes[0] == 0xED && bytes[1] == 0x7E {
1856 1856 // if bytes.count > 10, BleCmd(rawValue: bytes[8]) == .sync {
1857 1857 // if isSync {
... ... @@ -1874,12 +1874,12 @@ extension BluetoothManager: CBPeripheralDelegate {
1874 1874 mergeLength = bytes.count
1875 1875 }
1876 1876 } else {
1877   - if isSync {
1878   - if isSyncReceived {
1879   - startSyncTimer()
1880   - isSyncReceived = true
1881   - }
1882   - }
  1877 +// if isSync {
  1878 +// if isSyncReceived {
  1879 +// startSyncTimer()
  1880 +// isSyncReceived = true
  1881 +// }
  1882 +// }
1883 1883 totalBytes.append(contentsOf: bytes)
1884 1884 mergeLength += bytes.count
1885 1885 if mergeLength == totalLength {
... ... @@ -1993,16 +1993,16 @@ extension BluetoothManager: XMLParserDelegate {
1993 1993 }
1994 1994  
1995 1995 extension BluetoothManager {
1996   - private func startSync828(_ delayTime: Double) {
1997   - self.syncBug()
1998   - isFirstSync = true
1999   - GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncTime", timeInterval: delayTime, queue: .main, repeats: false) {
2000   - self.syncUserInfo()
2001   - }
  1996 +// private func startSync828(_ delayTime: Double) {
  1997 +// self.syncBug()
  1998 +// isFirstSync = true
2002 1999 // GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncTime", timeInterval: delayTime, queue: .main, repeats: false) {
2003   -// self.syncDeviceTime()
  2000 +// self.syncUserInfo()
2004 2001 // }
2005   - }
  2002 +//// GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncTime", timeInterval: delayTime, queue: .main, repeats: false) {
  2003 +//// self.syncDeviceTime()
  2004 +//// }
  2005 +// }
2006 2006  
2007 2007 //828: 用户信息 --- 单位 --- 抬腕亮屏 --- 整点测量 --- 闹钟 --- 喝水 --- 久坐 --- 时间 --- 消息通知 --- 月经
2008 2008  
... ...