From 36b76cd7949818ee2bde712d8c48ad97333b8894 Mon Sep 17 00:00:00 2001 From: jason Date: Wed, 17 Jan 2024 12:11:24 +0800 Subject: [PATCH] feat:intensive time now & history data --- HDFwear.xcodeproj/project.pbxproj | 4 ++++ HDFwear/20240126ReadMe.md | 15 ++++++++++++--- HDFwear/Home/Model/NewIntensiveTimeModel.swift | 46 ++++++++++++++++++++++++++++++++++++++++++++++ HDFwear/Mine/MineViewController.swift | 23 +++++++++++++++++++++++ HDFwear/Tools/Bluetooth+Types.swift | 2 ++ HDFwear/Tools/BluetoothManager+Function.swift | 33 +++++++++++++++++++++++++++++++++ HDFwear/Tools/BluetoothManager.swift | 6 ++++++ 7 files changed, 126 insertions(+), 3 deletions(-) create mode 100644 HDFwear/Home/Model/NewIntensiveTimeModel.swift diff --git a/HDFwear.xcodeproj/project.pbxproj b/HDFwear.xcodeproj/project.pbxproj index 48399a1..db9040b 100644 --- a/HDFwear.xcodeproj/project.pbxproj +++ b/HDFwear.xcodeproj/project.pbxproj @@ -286,6 +286,7 @@ 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; }; 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */; }; 847AF36E2B4CF35F00E3456E /* NewSleepModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */; }; + 847B88EF2B5780CA00851EE7 /* NewIntensiveTimeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847B88EE2B5780CA00851EE7 /* NewIntensiveTimeModel.swift */; }; 84DA399D2B4D3A5B008D34A9 /* NewGpsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */; }; B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; }; B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; }; @@ -666,6 +667,7 @@ 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = ""; }; 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewBeiDouContactModel.swift; sourceTree = ""; }; 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewSleepModel.swift; sourceTree = ""; }; + 847B88EE2B5780CA00851EE7 /* NewIntensiveTimeModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewIntensiveTimeModel.swift; sourceTree = ""; }; 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = ""; }; 847D2DE42B3D575F001BA7EF /* 20240110ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20240110ReadMe.md; sourceTree = ""; }; 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGpsModel.swift; sourceTree = ""; }; @@ -1287,6 +1289,7 @@ 847AF36D2B4CF35F00E3456E /* NewSleepModel.swift */, 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */, 845ADEA02B551C8E00C3AD73 /* NewStepModel.swift */, + 847B88EE2B5780CA00851EE7 /* NewIntensiveTimeModel.swift */, ); path = Model; sourceTree = ""; @@ -1713,6 +1716,7 @@ 6C1B7EA427B7976600DB9D1C /* NFCDetailVC.swift in Sources */, 6CD70CFE27D5AAEB00687095 /* PayProcessVC.swift in Sources */, 6C411EE5275DFF37009B2E02 /* Bluetooth+Types.swift in Sources */, + 847B88EF2B5780CA00851EE7 /* NewIntensiveTimeModel.swift in Sources */, 6C0AE825279151260064D377 /* AppVersionView.swift in Sources */, 6C2EE98E2780265B0051413A /* SleepReportCell.swift in Sources */, 6C1B7EA127B7976600DB9D1C /* NFCProblemsVC.swift in Sources */, diff --git a/HDFwear/20240126ReadMe.md b/HDFwear/20240126ReadMe.md index 2c08bba..d15ac31 100644 --- a/HDFwear/20240126ReadMe.md +++ b/HDFwear/20240126ReadMe.md @@ -88,8 +88,17 @@ BluetoothManager+Function 接收: [237, 126, 0, 1, 128, 37, 0, 1, 0, 169, 1, 101, 133, 64, 133, 0, 0, 0, 20, 13, 84, 138, 254, 0, 1, 134, 160, 67, 167, 168, 250, 0, 1, 134, 160, 13, 84, 142, 230, 0, 1, 134, 160, 67, 167, 172, 226, 0, 1, 134, 160, 13, 84, 146, 206, 0, 1, 134, 160, 67, 167, 176, 202, 0, 1, 134, 160, 13, 84, 142, 230, 0, 1, 134, 160, 67, 167, 172, 226, 0, 1, 134, 160, 13, 84, 138, 254, 0, 1, 134, 160, 67, 167, 168, 250, 0, 1, 134, 160, 13, 84, 135, 22, 0, 1, 134, 160, 67, 167, 161, 42, 0, 1, 134, 160, 13, 84, 131, 46, 0, 1, 134, 160, 67, 167, 157, 66, 0, 1, 134, 160, 13, 84, 123, 94, 0, 1, 134, 160, 67, 167, 153, 90, 0, 1, 134, 160, 13, 84, 119, 118, 0, 1, 134, 160, 67, 167, 149, 114, 0, 1, 134, 160, 13, 84, 115, 142, 0, 1, 134, 160, 67, 167, 141, 162, 0, 1, 134, 160, 68, 78] 接收: [237, 126, 0, 1, 128, 37, 0, 1, 0, 1, 255, 107, 166] - - - +拉取中高强度时长数据 + func newGetIntensiveTimeData(option: SyncOption = .now, closure: IntensiveTimeClosure? = nil) + 当前 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 11, 1, 250, 50] + 接收: [237, 126, 0, 1, 128, 40, 0, 1, 0, 28, 7, 232, 1, 9, 0, 0, 0, 0, 0, 0, 10, 10, 10, 20, 30, 52, 0, 24, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 38, 123] + 接收: [237, 126, 0, 1, 128, 40, 0, 1, 0, 1, 255, 37, 229] + 历史 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 11, 2, 202, 81] + 接收: [237, 126, 0, 1, 128, 40, 0, 2, 0, 28, 7, 232, 1, 8, 0, 0, 0, 0, 0, 0, 10, 10, 10, 20, 30, 52, 0, 24, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 149] + 接收: [237, 126, 0, 1, 128, 40, 0, 2, 0, 28, 7, 232, 1, 8, 0, 0, 0, 0, 0, 0, 10, 10, 10, 20, 30, 52, 0, 24, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 225, 149] + 接收: [237, 126, 0, 1, 128, 40, 0, 2, 0, 28, 7, 232, 1, 9, 0, 0, 0, 0, 0, 0, 10, 10, 10, 20, 30, 52, 0, 24, 43, 0, 0, 0, 0, 0, 0, 0, 0, 0, 164, 33] + 接收: [237, 126, 0, 1, 128, 40, 0, 2, 0, 1, 255, 190, 57] 接受数据类 diff --git a/HDFwear/Home/Model/NewIntensiveTimeModel.swift b/HDFwear/Home/Model/NewIntensiveTimeModel.swift new file mode 100644 index 0000000..b1cbe75 --- /dev/null +++ b/HDFwear/Home/Model/NewIntensiveTimeModel.swift @@ -0,0 +1,46 @@ +// +// NewIntensiveTimeModel.swift +// HDFwear +// +// Created by admin on 2024/1/17. +// + +import Foundation +import UIKit +import HandyJSON +import SwiftDate + +class NewIntensiveTimeModel: NSObject { + required override init() { } + + var year: UInt32 = 0 + var month: UInt32 = 0 + var day: UInt32 = 0 + var intensiveFragments : [UInt8] = [] + + + override var description: String { + let dateFormatter = DateFormatter() + dateFormatter.dateFormat = "yyyy-MM-dd" + let dateString = dateFormatter.string(from: DateComponents(calendar: Calendar.current, year: Int(year), month: Int(month), day: Int(day)).date!) + + let fragmentsString = intensiveFragments.map { String(format: "%d", $0) }.joined(separator: " ") + + return "NewIntensiveTimeModel\n" + + "Date: \(dateString)\n" + + "Intensive Fragments: \(fragmentsString)" + } + + class func toIntensiveTimeModel(_ data: [UInt8]) -> NewIntensiveTimeModel { + let s = NewIntensiveTimeModel() + guard data.count >= 28 else { + return s + } + + s.year = data[0..<2].reduce(0) { ($0 << 8) + UInt32($1) } + s.month = data[2..<3].reduce(0) { ($0 << 8) + UInt32($1) } + s.day = data[3..<4].reduce(0) { ($0 << 8) + UInt32($1) } + s.intensiveFragments = Array(data[4..<28]) + return s; + } +} diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index 15508c7..f31269d 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -590,6 +590,27 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } + let archiveAction102a = UIAlertAction(title: "newGetIntensiveTimeData now", style: .default) {[weak self] action in + BluetoothManager.shared.newGetIntensiveTimeData(option: .now) {intensiveTimeModel, error in + if error != nil { + print("newGetIntensiveTimeData" + (error?.description ?? "")) + }else { + self?.showDetailAlert(msg: intensiveTimeModel?.description) + print("newGetIntensiveTimeData success") + } + } + } + let archiveAction102b = UIAlertAction(title: "newGetIntensiveTimeData history", style: .default) {[weak self] action in + BluetoothManager.shared.newGetIntensiveTimeData(option: .history) {intensiveTimeModel, error in + if error != nil { + print("newGetIntensiveTimeData" + (error?.description ?? "")) + }else { + self?.showDetailAlert(msg: intensiveTimeModel?.description) + print("newGetIntensiveTimeData success") + } + } + } + alert.addAction(archiveAction9a) alert.addAction(archiveAction9b) @@ -605,6 +626,8 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction22) alert.addAction(archiveAction101a) alert.addAction(archiveAction101b) + alert.addAction(archiveAction102a) + alert.addAction(archiveAction102b) alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil)) present(alert, animated: true, completion: nil) diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index 6f7a7b2..83c1989 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -176,6 +176,8 @@ enum SyncType: UInt8 { case step = 0x08 case battery = 0x09 case gps = 0x0A + case intensiveTime = 0x0B + case beidouCard = 0x0C case other = 0xff } diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index b4abe13..7f7cdf7 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -238,6 +238,12 @@ extension BluetoothManager { newStartSyncHealthData(closure: closure, data: data, synType: .gps) } + // 拉取中高强度时长 + func newGetIntensiveTimeData(option: SyncOption = .now, closure: IntensiveTimeClosure? = nil) { + let data = BleMessage.shared.getSyncCmd(.intensiveTime, option) + newStartSyncHealthData(closure: closure, data: data, synType: .intensiveTime) + } + //MARK: - old code // 拉取睡眠数据 func getSleepData(option: SyncOption = .now, closure: SleepClosure? = nil) { @@ -342,6 +348,12 @@ extension BluetoothManager { gpsClosure?(nil, -1002) gpsClosure = nil } + case is IntensiveTimeClosure: + if intensiveTimeClosure == nil { + intensiveTimeClosure = closure as? IntensiveTimeClosure + intensiveTimeClosure?(nil, -1002) + intensiveTimeClosure = nil + } default: break } @@ -534,6 +546,16 @@ extension BluetoothManager { }else { parseGpsData(content) } + case 0x8028://中高强度时长 + print("中高强度时长") + let content = parseContentFromBytes(bytes) + if (content.count == 1 && content.first == 0xff) { + for delegate in syncDelegateList { + delegate.didReceiveFinishCommand(0x8028) + } + }else { + parseIntensiveTimeData(content) + } default: break } @@ -718,4 +740,15 @@ extension BluetoothManager { let gpsModel = NewGpsModel.toGpsModel(content) gpsClosure?(gpsModel, nil) } + + // 中高强度时长数据 + func parseIntensiveTimeData(_ content: [UInt8]) { + guard content.count > 0 else { + print("无有效的信息") + intensiveTimeClosure?(nil, nil) + return + } + let gpsModel = NewIntensiveTimeModel.toIntensiveTimeModel(content) + intensiveTimeClosure?(gpsModel, nil) + } } diff --git a/HDFwear/Tools/BluetoothManager.swift b/HDFwear/Tools/BluetoothManager.swift index 65bc7e5..287f1c0 100644 --- a/HDFwear/Tools/BluetoothManager.swift +++ b/HDFwear/Tools/BluetoothManager.swift @@ -95,6 +95,8 @@ class BluetoothManager: NSObject { var mettClosure: MettClosure? typealias GpsClosure = (_ gps: NewGpsModel?, _ error: Int?) -> Void var gpsClosure: GpsClosure? + typealias IntensiveTimeClosure = (_ intensiveTime:NewIntensiveTimeModel?, _ error: Int?) -> Void + var intensiveTimeClosure: IntensiveTimeClosure? typealias DialProgressClosure = (_ progress: Int) -> Void var dialProgressClosure: DialProgressClosure? @@ -1291,6 +1293,8 @@ class BluetoothManager: NSObject { trainClosure = nil pressureClosure = nil mettClosure = nil + gpsClosure = nil + intensiveTimeClosure = nil switch closure { case is BloodPressureClosure: bloodPressureClosure = closure as? BloodPressureClosure @@ -1310,6 +1314,8 @@ class BluetoothManager: NSObject { mettClosure = closure as? MettClosure case is GpsClosure: gpsClosure = closure as? GpsClosure + case is IntensiveTimeClosure: + intensiveTimeClosure = closure as? IntensiveTimeClosure default: break } -- libgit2 0.21.4