diff --git a/HDFwear/20240110ReadMe.md b/HDFwear/20240110ReadMe.md index 9e824b7..320843c 100644 --- a/HDFwear/20240110ReadMe.md +++ b/HDFwear/20240110ReadMe.md @@ -82,3 +82,15 @@ BluetoothManager+Function 0x8022 接收: [237, 126, 0, 1, 128, 34, 0, 1, 0, 1, 0, 189, 23] 接收: [237, 126, 0, 1, 128, 34, 0, 1, 0, 1, 1, 173, 54] + +心跳数据 + func parseHeartRateData (_ content: [UInt8]) + 接收: [237, 126, 0, 1, 128, 22, 0, 1, 0, 0, 109, 26] + +血氧数据 + func parseBlooodOxygenData (_ content: [UInt8]) + 接收: [237, 126, 0, 1, 128, 23, 0, 1, 0, 0, 199, 75] + +压力数据 + func parsePressureData (_ content: [UInt8]) + 接收: [237, 126, 0, 1, 128, 32, 0, 1, 0, 0, 172, 113] diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index 2933d20..22e65c4 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -189,6 +189,11 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { // let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "AboutAppVC") // navigationController?.pushViewController(vc, animated: true) let alert = UIAlertController(title: "plz select", message: nil, preferredStyle: .actionSheet) + + let archiveAction0 = UIAlertAction(title: "Fetch Date", style: .default) { action in + self.fetchDataAlert() + } + let archiveAction1 = UIAlertAction(title: "newSetTouchSense", style: .default) { action in BluetoothManager.shared.newSetTouchSense(bool: true) { error in if error != nil { @@ -261,25 +266,6 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } } - let archiveAction9 = UIAlertAction(title: "getSleepHistoryData", style: .default) { action in - BluetoothManager.shared.getSleepHistoryData() { sleepArray, error in - if error != nil { - print("getSleepHistoryData" + (error?.description ?? "")) - }else { - print("getSleepHistoryData success") - SleepModel.addArray(sleepArray) - } - } - } - let archiveAction10 = UIAlertAction(title: "getBloodOxygenHistoryData", style: .default) { action in - BluetoothManager.shared.getBloodOxygenHistoryData() { boArray, error in - if error != nil { - print("getBloodOxygenHistoryData" + (error?.description ?? "")) - }else { - print("getBloodOxygenHistoryData success") - } - } - } let archiveAction11 = UIAlertAction(title: "queryDeviceInfo", style: .default) { action in BluetoothManager.shared.queryDeviceInfo(queryItems: [0x02,0x03]) { error in @@ -311,46 +297,6 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } - let archiveAction14 = UIAlertAction(title: "getHeartRateHistoryData", style: .default) { action in - BluetoothManager.shared.getHeartRateHistoryData() { boArray, error in - if error != nil { - print("getHeartRateHistoryData" + (error?.description ?? "")) - }else { - print("getHeartRateHistoryData success") - } - } - } - - let archiveAction15 = UIAlertAction(title: "getStepHistoryData", style: .default) { action in - BluetoothManager.shared.getStepHistoryData() { boArray, error in - if error != nil { - print("getStepHistoryData" + (error?.description ?? "")) - }else { - print("getStepHistoryData success") - } - } - } - - let archiveAction16 = UIAlertAction(title: "getTrainHistoryData", style: .default) { action in - BluetoothManager.shared.getTrainHistoryData() { boArray, error in - if error != nil { - print("getTrainHistoryData" + (error?.description ?? "")) - }else { - print("getTrainHistoryData success") - } - } - } - - let archiveAction17 = UIAlertAction(title: "getPressureHistoryData", style: .default) { action in - BluetoothManager.shared.getPressureHistoryData() { boArray, error in - if error != nil { - print("getPressureHistoryData" + (error?.description ?? "")) - }else { - print("getPressureHistoryData success") - } - } - } - let archiveAction18 = UIAlertAction(title: "newSetTime", style: .default) { action in BluetoothManager.shared.newSetTime { error in if error != nil { @@ -402,16 +348,6 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } - let archiveAction22 = UIAlertAction(title: "newGetBatteryData", style: .default) { action in - BluetoothManager.shared.newGetBatteryData { error in - if error != nil { - print("newGetBatteryData" + (error?.description ?? "")) - }else { - print("newGetBatteryData success") - } - } - } - let archiveAction23 = UIAlertAction(title: "newSetRestHeartRateRemind", style: .default) { action in BluetoothManager.shared.newSetRestHeartRateRemind(bool: true, minHr: 60, maxHr: 90) { error in if error != nil { @@ -453,7 +389,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } - + alert.addAction(archiveAction0) alert.addAction(archiveAction1) alert.addAction(archiveAction2) alert.addAction(archiveAction3) @@ -462,20 +398,16 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction6) alert.addAction(archiveAction7) alert.addAction(archiveAction8) - alert.addAction(archiveAction9) - alert.addAction(archiveAction10) + alert.addAction(archiveAction11) alert.addAction(archiveAction12) alert.addAction(archiveAction13) - alert.addAction(archiveAction14) - alert.addAction(archiveAction15) - alert.addAction(archiveAction16) - alert.addAction(archiveAction17) + alert.addAction(archiveAction18) alert.addAction(archiveAction19) alert.addAction(archiveAction20) alert.addAction(archiveAction21) - alert.addAction(archiveAction22) + alert.addAction(archiveAction23) alert.addAction(archiveAction24) alert.addAction(archiveAction25) @@ -498,4 +430,101 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } + func fetchDataAlert () { + let alert = UIAlertController(title: "plz select fetch type", message: nil, preferredStyle: .actionSheet) + + let archiveAction9 = UIAlertAction(title: "getSleepHistoryData", style: .default) { action in + BluetoothManager.shared.getSleepHistoryData() { sleepArray, error in + if error != nil { + print("getSleepHistoryData" + (error?.description ?? "")) + }else { + print("getSleepHistoryData success") + SleepModel.addArray(sleepArray) + } + } + } + let archiveAction10 = UIAlertAction(title: "getBloodOxygenHistoryData", style: .default) { action in + BluetoothManager.shared.getBloodOxygenHistoryData() { boArray, error in + if error != nil { + print("getBloodOxygenHistoryData" + (error?.description ?? "")) + }else { + print("getBloodOxygenHistoryData success") + } + } + } + + let archiveAction14 = UIAlertAction(title: "getHeartRateHistoryData", style: .default) { action in + BluetoothManager.shared.getHeartRateHistoryData() { boArray, error in + if error != nil { + print("getHeartRateHistoryData" + (error?.description ?? "")) + }else { + print("getHeartRateHistoryData success") + } + } + } + + let archiveAction15 = UIAlertAction(title: "getStepHistoryData", style: .default) { action in + BluetoothManager.shared.getStepHistoryData() { boArray, error in + if error != nil { + print("getStepHistoryData" + (error?.description ?? "")) + }else { + print("getStepHistoryData success") + } + } + } + + let archiveAction16 = UIAlertAction(title: "getTrainHistoryData", style: .default) { action in + BluetoothManager.shared.getTrainHistoryData() { boArray, error in + if error != nil { + print("getTrainHistoryData" + (error?.description ?? "")) + }else { + print("getTrainHistoryData success") + } + } + } + + let archiveAction17 = UIAlertAction(title: "getPressureHistoryData", style: .default) { action in + BluetoothManager.shared.getPressureHistoryData() { boArray, error in + if error != nil { + print("getPressureHistoryData" + (error?.description ?? "")) + }else { + print("getPressureHistoryData success") + } + } + } + + let archiveAction22 = UIAlertAction(title: "newGetBatteryData", style: .default) { action in + BluetoothManager.shared.newGetBatteryData { error in + if error != nil { + print("newGetBatteryData" + (error?.description ?? "")) + }else { + print("newGetBatteryData success") + } + } + } + + let archiveAction101 = UIAlertAction(title: "newGetGpsData", style: .default) { action in + BluetoothManager.shared.newGetGpsData() {error in + if error != nil { + print("newGetGpsData" + (error?.description ?? "")) + }else { + print("newGetGpsData success") + } + } + } + + + alert.addAction(archiveAction9) + alert.addAction(archiveAction10) + alert.addAction(archiveAction14) + alert.addAction(archiveAction15) + alert.addAction(archiveAction16) + alert.addAction(archiveAction17) + alert.addAction(archiveAction22) + alert.addAction(archiveAction101) + + alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil)) + present(alert, animated: true, completion: nil) + } + } diff --git a/HDFwear/ReadMe.txt b/HDFwear/ReadMe.txt index a96c8f9..b647c19 100644 --- a/HDFwear/ReadMe.txt +++ b/HDFwear/ReadMe.txt @@ -75,19 +75,9 @@ BluetoothManager+Function 2. 设备信息数据 private func parseDeviceInfoData (_ content:[UInt8]) -3. 心跳数据 - func parseHeartRateData (_ content: [UInt8]) - 接收: [237, 126, 0, 1, 128, 22, 0, 7, 0, 200, 100, 157, 163, 180, 112, 100, 157, 170, 188, 247, 100, 157, 177, 196, 6, 100, 157, 184, 204, 0, 100, 157, 191, 212, 22, 100, 157, 198, 220, 249, 100, 157, 205, 228, 6, 100, 157, 212, 236, 0, 100, 157, 219, 244, 0, 100, 157, 226, 252, 251, 100, 157, 234, 4, 6, 100, 157, 241, 12, 0, 100, 157, 248, 20, 229, 100, 157, 255, 28, 253, 100, 158, 6, 36, 6, 100, 158, 13, 44, 0, 100, 158, 20, 52, 197, 100, 158, 27, 60, 255, 100, 158, 34, 68, 6, 100, 158, 41, 76, 0, 100, 158, 48, 84, 180, 100, 158, 55, 92, 1, 100, 158, 62, 100, 7, 100, 158, 69, 108, 0, 100, 158, 76, 116, 158, 100, 158, 83, 124, 2, 100, 158, 90, 132, 7, 100, 158, 97, 140, 0, 100, 158, 104, 148, 131, 100, 158, 111, 156, 4, 100, 158, 118, 164, 7, 100, 158, 125, 172, 0, 100, 158, 132, 180, 114, 100, 158, 139, 188, 6, 100, 158, 146, 196, 7, 100, 158, 153, 204, 0, 100, 158, 160, 212, 87, 100, 158, 167, 220, 8, 100, 158, 174, 228, 7, 100, 158, 181, 236, 20, 23, 62] - -4. 血氧数据 - func parseBlooodOxygenData (_ content: [UInt8]) - 5. 体温数据 func parseTemperaturData (_ content: [UInt8]) -6. 压力数据 - func parsePressureData (_ content: [UInt8]) - 7. 计步数据 func parseStepData (_ content: [UInt8]) diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index e1d8b7d..baf9147 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -176,7 +176,7 @@ enum SyncType: UInt8 { case train = 0x07 // case 0x08 case battery = 0x09 -// case gps = 0x0A + case gps = 0x0A case other = 0xff } diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index cd8705d..e954d38 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -195,13 +195,6 @@ extension BluetoothManager { sendData(data) } - // 拉取电量数据 - func newGetBatteryData( completion: ((_ error: Int?) -> ())? = nil) { - let data = BleMessage.shared.getSyncCmd(.battery) - self.setCmdClosure = completion - sendData(data) - } - // 心率测量间隔设置 func newSetHeartRateDetectInterval(bool: Bool, interval: UInt8, completion: @escaping(_ error: Int?) -> ()) { let data = BleMessage.shared.getHeartRateDetectIntervalCmd(bool: bool, interval: interval) @@ -218,6 +211,25 @@ extension BluetoothManager { } //MARK: - 同步健康数据 + //拉取数据 + func newGetData(type:SyncType, completion: ((_ error: Int?) -> ())? = nil) { + let data = BleMessage.shared.getSyncCmd(type) + self.setCmdClosure = completion + sendData(data) + } + + // 拉取电量数据 + func newGetBatteryData( completion: ((_ error: Int?) -> ())? = nil) { + newGetData(type: .battery, completion: completion) + } + + // 拉取GPS轨迹数据 + //jtd! 需要使用特定的回调,这样才能够直接把数据回调出来 + func newGetGpsData( completion: ((_ error: Int?) -> ())? = nil) { + newGetData(type: .gps, completion: completion) + } + + //MARK: - history // 拉取睡眠数据 func getSleepHistoryData( closure: SleepClosure? = nil) { let data = BleMessage.shared.getSyncCmd(.sleep) @@ -615,4 +627,17 @@ extension BluetoothManager { } stepClosure?([step], nil) } + + // GPS数据 + func parseGPSData (_ content: [UInt8]) { + //jtd! parse gps data +// guard content.count > 0 else { +// print("无有效的信息") +// heartRateClosure?([], nil) +// return +// } +// let hrArray = HeartRateModel.toHeartRateArray(content) +// HeartRateModel.addArray(hrArray)// 加入数据库 +// heartRateClosure?(hrArray, nil) + } }