diff --git a/HDFwear/Home/HomeViewController.swift b/HDFwear/Home/HomeViewController.swift index f2c6fbf..b84b0a3 100644 --- a/HDFwear/Home/HomeViewController.swift +++ b/HDFwear/Home/HomeViewController.swift @@ -707,7 +707,7 @@ extension HomeViewController: XMLParserDelegate { isFirstSync = true queryArray = CurDevice.queryArray print("开始同步数据 Home") - BluetoothManager.shared.syncBug() +// BluetoothManager.shared.syncBug() syncStep(.today) } @@ -826,11 +826,11 @@ extension HomeViewController: XMLParserDelegate { self?.queryArray.remove(at: index) // isFirstSync = false self?.queryFirmwareVersion() - self?.syncFinish() +// self?.syncFinish() } } else { queryFirmwareVersion() - syncFinish() +// syncFinish() } } @@ -856,28 +856,28 @@ extension HomeViewController: XMLParserDelegate { } - func syncFinish() { - print("\(queryArray)---同步完成!!!---") - collectionView.reloadData() - queryArray = CurDevice.queryArray - updateStepView() - isFirstSync = false - // if DailSyncBug { - // GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "DailSyncBug", timeInterval: 5, queue: .main, repeats: false) { - // self.dailSyncBug() - // } - // } - - scrollView.mj_header?.endRefreshing() - scrollView.mj_header?.isHidden = false - } +// func syncFinish() { +// print("\(queryArray)---同步完成!!!---") +// collectionView.reloadData() +// queryArray = CurDevice.queryArray +// updateStepView() +// isFirstSync = false +// // if DailSyncBug { +// // GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "DailSyncBug", timeInterval: 5, queue: .main, repeats: false) { +// // self.dailSyncBug() +// // } +// // } +// +// scrollView.mj_header?.endRefreshing() +// scrollView.mj_header?.isHidden = false +// } // func dailSyncBug() { // DailSyncBug = false // } - func syncBug() { - // if !isFirstSync { - syncFinish() - // } - } +// func syncBug() { +// // if !isFirstSync { +// syncFinish() +// // } +// } } diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index 8f4abf9..9031a87 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -304,93 +304,93 @@ extension BluetoothManager { // 同步数据 func newStartSyncHealthData(closure: Any?, data: Data, synType: SyncType) { - if !isSync { +// if !isSync { GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncInterval", timeInterval: 0.1, queue: .main, repeats: false) { self.clearClosures(closure: closure) - self.startSyncTimer() - self.isNextSync = false - self.isSync = true - self.isSyncType = synType +// self.startSyncTimer() +// self.isNextSync = false +// self.isSync = true +// self.isSyncType = synType self.sendData(data) } - } else { - switch closure { - case is BloodPressureClosure: - if bloodPressureClosure == nil { - bloodPressureClosure = closure as? BloodPressureClosure - bloodPressureClosure?([], -1002) - bloodPressureClosure = nil - } - case is HeartRateClosure: - if heartRateClosure == nil { - heartRateClosure = closure as? HeartRateClosure - heartRateClosure?([], -1002) - heartRateClosure = nil - } - case is BloodOxygenClosure: - if bloodOxygenClosure == nil { - bloodOxygenClosure = closure as? BloodOxygenClosure - bloodOxygenClosure?([], -1002) - bloodOxygenClosure = nil - } - case is SleepClosure: - if sleepClosure == nil { - sleepClosure = closure as? SleepClosure - sleepClosure?(nil, -1002) - sleepClosure = nil - } - case is StepClosure: - if stepClosure == nil { - stepClosure = closure as? StepClosure - stepClosure?([], -1002) - stepClosure = nil - } - case is ExerciseClosure: - if exerciseClosure == nil { - exerciseClosure = closure as? ExerciseClosure - exerciseClosure?(nil, -1002) - exerciseClosure = nil - } - case is PressureClosure: - if pressureClosure == nil { - pressureClosure = closure as? PressureClosure - pressureClosure?([], -1002) - pressureClosure = nil - } - case is MettClosure: - if mettClosure == nil { - mettClosure = closure as? MettClosure - mettClosure?([], -1002) - mettClosure = nil - } - case is GpsClosure: - if gpsClosure == nil { - gpsClosure = closure as? GpsClosure - gpsClosure?(nil, -1002) - gpsClosure = nil - } - case is IntensiveTimeClosure: - if intensiveTimeClosure == nil { - intensiveTimeClosure = closure as? IntensiveTimeClosure - intensiveTimeClosure?(nil, -1002) - intensiveTimeClosure = nil - } - case is BeidouCardClosure: - if beidouCardClosure == nil { - beidouCardClosure = closure as? BeidouCardClosure - beidouCardClosure?(nil, -1002) - beidouCardClosure = nil - } - case is FirmwareVersionClosure: - if firmwareVersionClosure == nil { - firmwareVersionClosure = closure as? FirmwareVersionClosure - firmwareVersionClosure?(nil, nil, -1002) - firmwareVersionClosure = nil - } - default: - break - } - } +// } else { +// switch closure { +// case is BloodPressureClosure: +// if bloodPressureClosure == nil { +// bloodPressureClosure = closure as? BloodPressureClosure +// bloodPressureClosure?([], -1002) +// bloodPressureClosure = nil +// } +// case is HeartRateClosure: +// if heartRateClosure == nil { +// heartRateClosure = closure as? HeartRateClosure +// heartRateClosure?([], -1002) +// heartRateClosure = nil +// } +// case is BloodOxygenClosure: +// if bloodOxygenClosure == nil { +// bloodOxygenClosure = closure as? BloodOxygenClosure +// bloodOxygenClosure?([], -1002) +// bloodOxygenClosure = nil +// } +// case is SleepClosure: +// if sleepClosure == nil { +// sleepClosure = closure as? SleepClosure +// sleepClosure?(nil, -1002) +// sleepClosure = nil +// } +// case is StepClosure: +// if stepClosure == nil { +// stepClosure = closure as? StepClosure +// stepClosure?([], -1002) +// stepClosure = nil +// } +// case is ExerciseClosure: +// if exerciseClosure == nil { +// exerciseClosure = closure as? ExerciseClosure +// exerciseClosure?(nil, -1002) +// exerciseClosure = nil +// } +// case is PressureClosure: +// if pressureClosure == nil { +// pressureClosure = closure as? PressureClosure +// pressureClosure?([], -1002) +// pressureClosure = nil +// } +// case is MettClosure: +// if mettClosure == nil { +// mettClosure = closure as? MettClosure +// mettClosure?([], -1002) +// mettClosure = nil +// } +// case is GpsClosure: +// if gpsClosure == nil { +// gpsClosure = closure as? GpsClosure +// gpsClosure?(nil, -1002) +// gpsClosure = nil +// } +// case is IntensiveTimeClosure: +// if intensiveTimeClosure == nil { +// intensiveTimeClosure = closure as? IntensiveTimeClosure +// intensiveTimeClosure?(nil, -1002) +// intensiveTimeClosure = nil +// } +// case is BeidouCardClosure: +// if beidouCardClosure == nil { +// beidouCardClosure = closure as? BeidouCardClosure +// beidouCardClosure?(nil, -1002) +// beidouCardClosure = nil +// } +// case is FirmwareVersionClosure: +// if firmwareVersionClosure == nil { +// firmwareVersionClosure = closure as? FirmwareVersionClosure +// firmwareVersionClosure?(nil, nil, -1002) +// firmwareVersionClosure = nil +// } +// default: +// break +// } +// } } //MARK: - 发送数据 func sendData(_ data: Data) { @@ -455,11 +455,11 @@ extension BluetoothManager { } //MARK: - 解析数据 func parseData(_ bytes: [UInt8]) { - stopSyncTimer(BLEConfig.SyncHealthTimer) - if !isNextSync { - isSync = false - isSyncType = .other - } +// stopSyncTimer(BLEConfig.SyncHealthTimer) +// if !isNextSync { +// isSync = false +// isSyncType = .other +// } // debug // 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] totalLength = 0 diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index 6400468..7f7b3f7 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -34,7 +34,7 @@ protocol BluetoothSyncDelegate { func didReceiveSettingData() func didReceiveStep() func firstSync() - func syncBug() +// func syncBug() // adapted func didReceiveBattery(value: Int) func didReceiveFindPhoneCommand(value: Int) @@ -54,7 +54,7 @@ extension BluetoothSyncDelegate { func didReceiveSettingData() { } func didReceiveStep() { } func firstSync() {} - func syncBug() {} +// func syncBug() {} // adapted func didReceiveBattery(value: Int) { } func didReceiveFindPhoneCommand(value: Int) { } @@ -159,10 +159,10 @@ class BluetoothManager: NSObject { var mergeLength: Int = 0 //sync - var isSyncReceived: Bool = false //是否收到同步data - var isSync: Bool = false //是否在同步中 - var isSyncType: SyncType = .other //正在同步的指令 - var isNextSync: Bool = false //是否有下一个同步包 +// var isSyncReceived: Bool = false //是否收到同步data +// var isSync: Bool = false //是否在同步中 +// var isSyncType: SyncType = .other //正在同步的指令 +// var isNextSync: Bool = false //是否有下一个同步包 // private var // 任务执行管理 @@ -705,18 +705,18 @@ class BluetoothManager: NSObject { - func syncBug() { -// if GCDTimer.s - GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "syncBug", timeInterval: 25, queue: .main, repeats: false) { - print("同步超时") - self.isSync = false - self.isSyncType = .other - self.isSyncReceived = false - for delegate in self.syncDelegateList { - delegate.syncBug() - } - } - } +// func syncBug() { +//// if GCDTimer.s +// GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "syncBug", timeInterval: 25, queue: .main, repeats: false) { +// print("同步超时") +// self.isSync = false +// self.isSyncType = .other +// self.isSyncReceived = false +// for delegate in self.syncDelegateList { +// delegate.syncBug() +// } +// } +// } //MARK: - 解析数据- deprecatd //MARK: - @@ -1280,46 +1280,46 @@ class BluetoothManager: NSObject { //MARK: - 同步计时器 - func startSyncTimer() { - stopSyncTimer(BLEConfig.SyncHealthTimer) - - GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: BLEConfig.SyncHealthTimer, timeInterval: 3, queue: .main, repeats: false) {[weak self] in - print("同步记时完毕") - if !(self?.isSyncReceived ?? true) { - self?.syncReceiveFail() - } - } - print("开始同步计时") - - -// if GCDTimer.shared.isExistTimer(WithTimerName: BLEConfig.SyncHealthTimer) { -// -// } - - } +// func startSyncTimer() { +// stopSyncTimer(BLEConfig.SyncHealthTimer) +// +// GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: BLEConfig.SyncHealthTimer, timeInterval: 3, queue: .main, repeats: false) {[weak self] in +// print("同步记时完毕") +// if !(self?.isSyncReceived ?? true) { +// self?.syncReceiveFail() +// } +// } +// print("开始同步计时") +// +// +//// if GCDTimer.shared.isExistTimer(WithTimerName: BLEConfig.SyncHealthTimer) { +//// +//// } +// +// } - func stopSyncTimer(_ name: String) { - isSyncReceived = false - if GCDTimer.shared.isExistTimer(WithTimerName: name) { - GCDTimer.shared.cancleTimer(WithTimerName: name) - print("停止同步计时") - } - } +// func stopSyncTimer(_ name: String) { +// isSyncReceived = false +// if GCDTimer.shared.isExistTimer(WithTimerName: name) { +// GCDTimer.shared.cancleTimer(WithTimerName: name) +// print("停止同步计时") +// } +// } - func syncReceiveFail() { - print("同步失败") -// stopSyncTimer(BLEConfig.SyncHealthTimer) - isSync = false - isSyncType = .other - heartRateClosure?([], -1001) - bloodPressureClosure?([], -1001) - bloodOxygenClosure?([], -1001) - sleepClosure?(nil, -1001) - stepClosure?([], -1001) - exerciseClosure?(nil, -1001) - pressureClosure?([], -1001) - mettClosure?([], -1001) - } +// func syncReceiveFail() { +// print("同步失败") +//// stopSyncTimer(BLEConfig.SyncHealthTimer) +// isSync = false +// isSyncType = .other +// heartRateClosure?([], -1001) +// bloodPressureClosure?([], -1001) +// bloodOxygenClosure?([], -1001) +// sleepClosure?(nil, -1001) +// stepClosure?([], -1001) +// exerciseClosure?(nil, -1001) +// pressureClosure?([], -1001) +// mettClosure?([], -1001) +// } func clearClosures(closure: Any?) { heartRateClosure = nil @@ -1851,7 +1851,7 @@ extension BluetoothManager: CBPeripheralDelegate { func mergeData(_ data: Data) { let bytes = [UInt8](data) // print(bytes) - isSyncReceived = true +// isSyncReceived = true if bytes[0] == 0xED && bytes[1] == 0x7E { // if bytes.count > 10, BleCmd(rawValue: bytes[8]) == .sync { // if isSync { @@ -1874,12 +1874,12 @@ extension BluetoothManager: CBPeripheralDelegate { mergeLength = bytes.count } } else { - if isSync { - if isSyncReceived { - startSyncTimer() - isSyncReceived = true - } - } +// if isSync { +// if isSyncReceived { +// startSyncTimer() +// isSyncReceived = true +// } +// } totalBytes.append(contentsOf: bytes) mergeLength += bytes.count if mergeLength == totalLength { @@ -1993,16 +1993,16 @@ extension BluetoothManager: XMLParserDelegate { } extension BluetoothManager { - private func startSync828(_ delayTime: Double) { - self.syncBug() - isFirstSync = true - GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncTime", timeInterval: delayTime, queue: .main, repeats: false) { - self.syncUserInfo() - } +// private func startSync828(_ delayTime: Double) { +// self.syncBug() +// isFirstSync = true // GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncTime", timeInterval: delayTime, queue: .main, repeats: false) { -// self.syncDeviceTime() +// self.syncUserInfo() // } - } +//// GCDTimer.shared.scheduledDispatchTimerNotNow(WithTimerName: "SyncTime", timeInterval: delayTime, queue: .main, repeats: false) { +//// self.syncDeviceTime() +//// } +// } //828: 用户信息 --- 单位 --- 抬腕亮屏 --- 整点测量 --- 闹钟 --- 喝水 --- 久坐 --- 时间 --- 消息通知 --- 月经