Commit 35756df091d371aab50d8ed237161d33f30963ab

Authored by jason
1 parent e3bf0573

feat:0301 part1

HDFwear.xcodeproj/project.pbxproj
... ... @@ -297,6 +297,7 @@
297 297 847B88EF2B5780CA00851EE7 /* NewIntensiveTimeModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847B88EE2B5780CA00851EE7 /* NewIntensiveTimeModel.swift */; };
298 298 847CA80F2B6147680051AEAF /* OTAUpdateViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 847CA80D2B6147680051AEAF /* OTAUpdateViewController.m */; };
299 299 847CA8102B6147680051AEAF /* OTAUpdateViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 847CA80E2B6147680051AEAF /* OTAUpdateViewController.xib */; };
  300 + 848387332B93560300E94A9A /* 20240301ReadMe.md in Resources */ = {isa = PBXBuildFile; fileRef = 848387322B93560300E94A9A /* 20240301ReadMe.md */; };
300 301 84DA399D2B4D3A5B008D34A9 /* NewGpsModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */; };
301 302 B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; };
302 303 B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; };
... ... @@ -695,6 +696,7 @@
695 696 847CA80E2B6147680051AEAF /* OTAUpdateViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = OTAUpdateViewController.xib; sourceTree = "<group>"; };
696 697 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = "<group>"; };
697 698 847D2DE42B3D575F001BA7EF /* 20240110ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20240110ReadMe.md; sourceTree = "<group>"; };
  699 + 848387322B93560300E94A9A /* 20240301ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20240301ReadMe.md; sourceTree = "<group>"; };
698 700 84DA399C2B4D3A5B008D34A9 /* NewGpsModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewGpsModel.swift; sourceTree = "<group>"; };
699 701 B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; };
700 702 B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = "<group>"; };
... ... @@ -1110,6 +1112,7 @@
1110 1112 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */,
1111 1113 847D2DE42B3D575F001BA7EF /* 20240110ReadMe.md */,
1112 1114 845ADE9F2B5507FA00C3AD73 /* 20240126ReadMe.md */,
  1115 + 848387322B93560300E94A9A /* 20240301ReadMe.md */,
1113 1116 );
1114 1117 path = HDFwear;
1115 1118 sourceTree = "<group>";
... ... @@ -1531,6 +1534,7 @@
1531 1534 6C5B546027759D6B007F7901 /* SettingCell3.xib in Resources */,
1532 1535 6C0AE826279162FE0064D377 /* AppVersionView.xib in Resources */,
1533 1536 6CEA284B27EB0A82006A44AB /* MedalHeaderView.xib in Resources */,
  1537 + 848387332B93560300E94A9A /* 20240301ReadMe.md in Resources */,
1534 1538 6CA8623F2747473900139069 /* StepProgressView.xib in Resources */,
1535 1539 6C28F54527901A8D00E74EA5 /* StepReportCell.xib in Resources */,
1536 1540 );
... ...
HDFwear.xcodeproj/xcshareddata/xcschemes/HDFwear.xcscheme
... ... @@ -74,7 +74,7 @@
74 74 <EnvironmentVariable
75 75 key = "OS_ACTIVITY_MODE"
76 76 value = "disable"
77   - isEnabled = "YES">
  77 + isEnabled = "NO">
78 78 </EnvironmentVariable>
79 79 </EnvironmentVariables>
80 80 </LaunchAction>
... ...
HDFwear/20240126ReadMe.md
... ... @@ -170,16 +170,6 @@ BluetoothManager+Function
170 170 func newGetBoLowRemindData(option: SyncOption = .now, closure: BoLowRemindClosure? = nil)
171 171 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 15, 1, 54, 246]
172 172 接收: [237, 126, 0, 1, 128, 50, 0, 1, 0, 1, 80, 253, 102]
173   -
174   -拉取心率自动测量开关
175   - func newGetHrAutoDetectData(option: SyncOption = .now, closure: BoAutoDetectClosure? = nil)
176   - 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 16, 1, 37, 187]
177   - 接收: [237, 126, 0, 1, 128, 51, 0, 1, 0, 1, 1, 242, 18]
178   -
179   -拉取运动心率预警开关
180   - func newGetExerciseHrRemindData(option: SyncOption = .now, closure: ExerciseHrRemindClosure? = nil)
181   - 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 18, 1, 67, 217]
182   - 接收: [237, 126, 0, 1, 128, 53, 0, 1, 0, 1, 0, 111, 210]
183 173  
184 174 接受数据类
185 175  
... ...
HDFwear/20240301ReadMe.md 0 → 100644
  1 +接口说明:
  2 +
  3 +接口实现
  4 +BluetoothManager+Function
  5 +
  6 +发送数据类
  7 +拉取消息通知开关
  8 + func newGetMessageRemindData(option: SyncOption = .now, closure: MessageRemindClosure? = nil)
  9 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 23, 1, 188, 44]
  10 + 接收: [237, 126, 0, 1, 128, 57, 0, 1, 0, 1, 11, 213, 90]
  11 +
  12 +拉取紧急常用联系人 北斗联系人
  13 + func newGetBeiDouContactData(option: SyncOption = .now, closure: BeiDouContactClosure? = nil)
  14 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 24, 1, 172, 18]
  15 + 接收: [237, 126, 0, 1, 128, 64, 0, 1, 0, 90, 4, 9, 229, 145, 168, 230, 157, 176, 228, 188, 166, 11, 49, 56, 57, 55, 52, 57, 54, 48, 48, 48, 49, 1, 9, 230, 162, 129, 230, 156, 157, 228, 188, 159, 11, 49, 56, 57, 55, 52, 57, 54, 48, 48, 48, 50, 2, 9, 229, 144, 180, 229, 189, 166, 231, 165, 150, 11, 49, 56, 57, 55, 52, 57, 54, 48, 48, 48, 51, 1, 6, 230, 136, 144, 233, 190, 153, 11, 49, 56, 57, 55, 52, 57, 54, 48, 48, 48, 52, 2, 240, 77]
  16 +
  17 +拉取压力开关 压力检测开关
  18 + func newGetPressureAutoDetectData(option: SyncOption = .now, closure: PressureAutoDetectClosure? = nil)
  19 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 25, 1, 159, 35]
  20 + 接收: [237, 126, 0, 1, 128, 65, 0, 1, 0, 1, 1, 60, 206]
  21 +
  22 +拉取低电量提醒开关
  23 + func newGetLowPowerRemindData(option: SyncOption = .now, closure: LowPowerRemindClosure? = nil)
  24 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 26, 1, 202, 112]
  25 + 接收: [237, 126, 0, 1, 128, 66, 0, 1, 0, 1, 1, 242, 46]
  26 +
  27 +拉取北斗消息回复 北斗消息自动回复
  28 + func newGetBeiDouQuickAnswerData(option: SyncOption = .now, closure: BeiDouQuickAnswerClosure? = nil)
  29 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 27, 1, 249, 65]
  30 + 接收: [237, 126, 0, 1, 128, 67, 0, 1, 0, 15, 2, 6, 229, 140, 151, 230, 150, 151, 6, 229, 141, 151, 230, 150, 151, 124, 127]
  31 +
  32 +拉取运动心率预警开关
  33 + func newGetExerciseHrRemindData(option: SyncOption = .now, closure: ExerciseHrRemindClosure? = nil)
  34 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 28, 1, 96, 214]
  35 + 接收: [237, 126, 0, 1, 128, 68, 0, 1, 0, 3, 1, 110, 150, 22, 246]
  36 +
  37 +拉取心率自动测量开关 连续测量心率
  38 + func newGetHrAutoDetectData(option: SyncOption = .now, closure: HrAutoDetectClosure? = nil)
  39 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 29, 1, 83, 231]
  40 + 接收: [237, 126, 0, 1, 128, 69, 0, 1, 0, 3, 1, 18, 0, 255, 110]
  41 +
  42 +拉取安静心率提醒设置
  43 + func newGetRestHrRemindData(option: SyncOption = .now, closure: RestHrRemindClosure? = nil)
  44 + 发送: [237, 126, 0, 1, 0, 40, 0, 1, 0, 2, 30, 1, 6, 180]
  45 + 接收: [237, 126, 0, 1, 128, 70, 0, 1, 0, 3, 1, 60, 90, 233, 77]
... ...
HDFwear/Home/Model/NewBeiDouContactModel.swift
... ... @@ -20,10 +20,56 @@ class NewBeiDouContactModel: NSObject {
20 20 var name: String = ""
21 21 var phone: String = ""
22 22 var type: NewBeiDouContactType = .general
  23 +
  24 + override var description: String {
  25 + return "Name: \(name), Phone: \(phone), Type: \(type.rawValue)"
  26 + }
23 27  
24 28 init(name: String, phone: String, type: NewBeiDouContactType) {
25 29 self.name = name
26 30 self.phone = phone
27 31 self.type = type
28 32 }
  33 +
  34 + class func getNewBeiDouContact(from data: [UInt8]) -> [NewBeiDouContactModel]? {
  35 + var index = 0
  36 + var contacts: [NewBeiDouContactModel] = []
  37 +
  38 + guard data.count >= 1 else { return nil }
  39 +
  40 + let contactsCount = Int(data[index])
  41 + index += 1
  42 +
  43 + for _ in 0..<contactsCount {
  44 + guard index + 2 < data.count else { return nil }
  45 +
  46 + let nameLength = Int(data[index])
  47 + index += 1
  48 +
  49 + let nameData = Array(data[index..<(index + nameLength)])
  50 + guard let name = String(bytes: nameData, encoding: .utf8) else { return nil }
  51 + index += nameLength
  52 +
  53 + let phoneLength = Int(data[index])
  54 + index += 1
  55 +
  56 + let phoneData = Array(data[index..<(index + phoneLength)])
  57 + guard let phone = String(bytes: phoneData, encoding: .ascii) else { return nil }
  58 + index += phoneLength
  59 +
  60 + let typeRawValue = data[index]
  61 + index += 1
  62 +
  63 + if let type = NewBeiDouContactType(rawValue: Int(typeRawValue)) {
  64 + let contact = NewBeiDouContactModel(name: name, phone: phone, type: type)
  65 + contacts.append(contact)
  66 + } else {
  67 + return nil
  68 + }
  69 + }
  70 +
  71 + return contacts
  72 + }
  73 +
  74 +
29 75 }
... ...
HDFwear/Mine/MineViewController.swift
... ... @@ -355,7 +355,7 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
355 355 }
356 356  
357 357 let archiveAction21 = UIAlertAction(title: "newSetBeiDouQuickAnswer", style: .default) { action in
358   - BluetoothManager.shared.newSetBeiDouQuickAnswer(answers: ["北斗"]) { error in
  358 + BluetoothManager.shared.newSetBeiDouQuickAnswer(answers: ["北斗","南斗"]) { error in
359 359 if error != nil {
360 360 print("newSetBeiDouQuickAnswer" + (error?.description ?? ""))
361 361 }else {
... ... @@ -809,27 +809,101 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
809 809 }
810 810  
811 811 let archiveAction110 = UIAlertAction(title: "newGetHrAutoDetectData", style: .default) {[weak self] action in
812   - BluetoothManager.shared.newGetHrAutoDetectData() {enable, error in
  812 + BluetoothManager.shared.newGetHrAutoDetectData() {enable, interval, error in
813 813 if error != nil {
814 814 print("newGetHrAutoDetectData" + (error?.description ?? ""))
815 815 }else {
816   - self?.showDetailAlert(msg: String(enable))
  816 + self?.showDetailAlert(msg: String("enable: \(enable), interval: \(interval)"))
817 817 print("newGetHrAutoDetectData success")
818 818 }
819 819 }
820 820 }
821 821  
822 822 let archiveAction111 = UIAlertAction(title: "newGetExerciseHrRemindData", style: .default) {[weak self] action in
823   - BluetoothManager.shared.newGetExerciseHrRemindData() {enable, error in
  823 + BluetoothManager.shared.newGetExerciseHrRemindData() {enable, min, max, error in
824 824 if error != nil {
825 825 print("newGetExerciseHrRemindData" + (error?.description ?? ""))
826 826 }else {
827   - self?.showDetailAlert(msg: String(enable))
  827 + self?.showDetailAlert(msg: String("enable: \(enable), min: \(min), max: \(max)"))
828 828 print("newGetExerciseHrRemindData success")
829 829 }
830 830 }
831 831 }
832 832  
  833 + let archiveAction111a = UIAlertAction(title: "newGetRestHrRemindData", style: .default) {[weak self] action in
  834 + BluetoothManager.shared.newGetRestHrRemindData() {enable, min, max, error in
  835 + if error != nil {
  836 + print("newGetRestHrRemindData" + (error?.description ?? ""))
  837 + }else {
  838 + self?.showDetailAlert(msg: String("enable: \(enable), min: \(min), max: \(max)"))
  839 + print("newGetRestHrRemindData success")
  840 + }
  841 + }
  842 + }
  843 +
  844 + let archiveAction112 = UIAlertAction(title: "newGetMessageRemindData", style: .default) {[weak self] action in
  845 + BluetoothManager.shared.newGetMessageRemindData() {enable, system, wechat, qq, error in
  846 + if error != nil {
  847 + print("newGetMessageRemindData" + (error?.description ?? ""))
  848 + }else {
  849 + self?.showDetailAlert(msg: String("enable: \(enable), system: \(system), wechat: \(wechat), qq: \(qq)"))
  850 + print("newGetMessageRemindData success")
  851 + }
  852 + }
  853 + }
  854 +
  855 + let archiveAction113 = UIAlertAction(title: "newGetBeiDouContactData", style: .default) {[weak self] action in
  856 + BluetoothManager.shared.newGetBeiDouContactData() {contact, error in
  857 + if error != nil {
  858 + print("newGetBeiDouContactData" + (error?.description ?? ""))
  859 + }else {
  860 + if let c = contact {
  861 + let contactsDescription = c.map { "\($0)" }.joined(separator: "\n")
  862 + self?.showDetailAlert(msg: contactsDescription)
  863 + print("newGetBeiDouContactData success")
  864 + }
  865 + }
  866 + }
  867 + }
  868 +
  869 + let archiveAction114 = UIAlertAction(title: "newGetPressureAutoDetectData", style: .default) {[weak self] action in
  870 + BluetoothManager.shared.newGetPressureAutoDetectData() {enable, error in
  871 + if error != nil {
  872 + print("newGetPressureAutoDetectData" + (error?.description ?? ""))
  873 + }else {
  874 + self?.showDetailAlert(msg: String(enable))
  875 + print("newGetPressureAutoDetectData success")
  876 + }
  877 + }
  878 + }
  879 +
  880 + let archiveAction115 = UIAlertAction(title: "newGetLowPowerRemindData", style: .default) {[weak self] action in
  881 + BluetoothManager.shared.newGetLowPowerRemindData() {enable, error in
  882 + if error != nil {
  883 + print("newGetLowPowerRemindData" + (error?.description ?? ""))
  884 + }else {
  885 + self?.showDetailAlert(msg: String(enable))
  886 + print("newGetLowPowerRemindData success")
  887 + }
  888 + }
  889 + }
  890 +
  891 + let archiveAction116 = UIAlertAction(title: "newGetBeiDouQuickAnswerData", style: .default) {[weak self] action in
  892 + BluetoothManager.shared.newGetBeiDouQuickAnswerData() {answers, error in
  893 + if error != nil {
  894 + print("newGetBeiDouQuickAnswerData" + (error?.description ?? ""))
  895 + }else {
  896 + if let a = answers {
  897 + let contactsDescription = a.map { "\($0)" }.joined(separator: "\n")
  898 + self?.showDetailAlert(msg: contactsDescription)
  899 + print("newGetBeiDouQuickAnswerData success")
  900 + }
  901 + }
  902 + }
  903 + }
  904 +
  905 +
  906 +
833 907  
834 908 alert.addAction(archiveAction9a)
835 909 alert.addAction(archiveAction9b)
... ... @@ -856,6 +930,12 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
856 930 alert.addAction(archiveAction109)
857 931 alert.addAction(archiveAction110)
858 932 alert.addAction(archiveAction111)
  933 + alert.addAction(archiveAction111a)
  934 + alert.addAction(archiveAction112)
  935 + alert.addAction(archiveAction113)
  936 + alert.addAction(archiveAction114)
  937 + alert.addAction(archiveAction115)
  938 + alert.addAction(archiveAction116)
859 939  
860 940 alert.addAction(UIAlertAction(title: "取消", style: .destructive, handler: nil))
861 941 present(alert, animated: true, completion: nil)
... ...
HDFwear/Tools/Bluetooth+Types.swift
... ... @@ -128,8 +128,8 @@ enum NewCmd: UInt8 {
128 128 case setRestore = 0x17
129 129 case setHeartRateHighRemind = 0x90// deprecated
130 130 case setHeartRateLowRemind = 0x91// deprecated
131   - case setRestHeartRateRemind = 0x18
132   - case setExerciseHeartRateRemind = 0x19
  131 + case setRestHeartRateRemind = 0x18//安静心率预警
  132 + case setExerciseHeartRateRemind = 0x19//运动心率预警
133 133 case setFindWatch = 0x0020
134 134 // case setMessage = 0x0021
135 135 // case setPhoneCall = 0x0022
... ... @@ -181,10 +181,18 @@ enum SyncType: UInt8 {
181 181 case noDisturb = 0x0D
182 182 case boAutoDetect = 0x0E
183 183 case boLowRemind = 0x0F
184   - case hrAutoDetect = 0x10
185   - case exerciseHrRemind = 0x12
  184 +// case hrAutoDetect = 0x10
  185 +// case exerciseHrRemind = 0x12
186 186 case firmwareVersion = 0x14
187 187 case wristSense = 0x15
  188 + case messageRemind = 0x0017
  189 + case beiDouContact = 0x0018
  190 + case pressureAutoDetect = 0x19
  191 + case lowPowerRemind = 0x1A
  192 + case beiDouQuickAnswer = 0x001B
  193 + case exerciseHrRemind = 0x1C//运动心率预警
  194 + case hrAutoDetect = 0x1D//心率测量间隔设置
  195 + case restHrRemind = 0x1E//安静心率预警
188 196 case other = 0xff
189 197 }
190 198  
... ...
HDFwear/Tools/BluetoothManager+Function.swift
... ... @@ -300,6 +300,42 @@ extension BluetoothManager {
300 300 newStartSyncHealthData(closure: closure, data: data, synType: .firmwareVersion)
301 301 }
302 302  
  303 + // 拉取消息通知开关
  304 + func newGetMessageRemindData(option: SyncOption = .now, closure: MessageRemindClosure? = nil) {
  305 + let data = BleMessage.shared.getSyncCmd(.messageRemind, option)
  306 + newStartSyncHealthData(closure: closure, data: data, synType: .messageRemind)
  307 + }
  308 +
  309 + // 拉取紧急常用联系人 北斗联系人
  310 + func newGetBeiDouContactData(option: SyncOption = .now, closure: BeiDouContactClosure? = nil) {
  311 + let data = BleMessage.shared.getSyncCmd(.beiDouContact, option)
  312 + newStartSyncHealthData(closure: closure, data: data, synType: .beiDouContact)
  313 + }
  314 +
  315 + // 拉取压力开关 压力检测开关
  316 + func newGetPressureAutoDetectData(option: SyncOption = .now, closure: PressureAutoDetectClosure? = nil) {
  317 + let data = BleMessage.shared.getSyncCmd(.pressureAutoDetect, option)
  318 + newStartSyncHealthData(closure: closure, data: data, synType: .pressureAutoDetect)
  319 + }
  320 +
  321 + // 拉取低电量提醒开关
  322 + func newGetLowPowerRemindData(option: SyncOption = .now, closure: LowPowerRemindClosure? = nil) {
  323 + let data = BleMessage.shared.getSyncCmd(.lowPowerRemind, option)
  324 + newStartSyncHealthData(closure: closure, data: data, synType: .lowPowerRemind)
  325 + }
  326 +
  327 + // 拉取北斗消息回复 北斗消息自动回复
  328 + func newGetBeiDouQuickAnswerData(option: SyncOption = .now, closure: BeiDouQuickAnswerClosure? = nil) {
  329 + let data = BleMessage.shared.getSyncCmd(.beiDouQuickAnswer, option)
  330 + newStartSyncHealthData(closure: closure, data: data, synType: .beiDouQuickAnswer)
  331 + }
  332 +
  333 + // 拉取安静心率提醒设置
  334 + func newGetRestHrRemindData(option: SyncOption = .now, closure: RestHrRemindClosure? = nil) {
  335 + let data = BleMessage.shared.getSyncCmd(.restHrRemind, option)
  336 + newStartSyncHealthData(closure: closure, data: data, synType: .restHrRemind)
  337 + }
  338 +
303 339 //MARK: - old code
304 340 // 拉取睡眠数据
305 341 func getSleepData(option: SyncOption = .now, closure: SleepClosure? = nil) {
... ... @@ -690,44 +726,128 @@ extension BluetoothManager {
690 726 parseBoLowRemindData(content)
691 727 }
692 728 case 0x8033://心率自动测量开关
693   - print("心率自动测量开关")
  729 + newGetHrAutoDetectData(option: .now, closure: hrAutoDetectClosure)
  730 +// print("心率自动测量开关")
  731 +// let content = parseContentFromBytes(bytes)
  732 +// if (content.count == 1 && content.first == 0xff) {
  733 +// for delegate in syncDelegateList {
  734 +// delegate.didReceiveFinishCommand(0x8033)
  735 +// }
  736 +// }else {
  737 +// parseHrAutoDetectData(content)
  738 +// }
  739 + case 0x8034://安静心率预警开关
  740 + newGetRestHrRemindData(option: .now, closure: restHrRemindClosure)
  741 + case 0x8035://运动心率预警开关
  742 + newGetExerciseHrRemindData(option: .now, closure: exerciseHrRemindClosure)
  743 +// print("运动心率预警开关")
  744 +// let content = parseContentFromBytes(bytes)
  745 +// if (content.count == 1 && content.first == 0xff) {
  746 +// for delegate in syncDelegateList {
  747 +// delegate.didReceiveFinishCommand(0x8035)
  748 +// }
  749 +// }else {
  750 +// parseExerciseHrRemindData(content)
  751 +// }
  752 + case 0x8037://固件版本号
  753 + print("固件版本号")
694 754 let content = parseContentFromBytes(bytes)
695 755 if (content.count == 1 && content.first == 0xff) {
696 756 for delegate in syncDelegateList {
697   - delegate.didReceiveFinishCommand(0x8033)
  757 + delegate.didReceiveFinishCommand(0x8037)
698 758 }
699 759 }else {
700   - parseHrAutoDetectData(content)
  760 + parseFirmwareVersionData(content)
701 761 }
702   - case 0x8035://运动心率预警开关
  762 + case 0x8038://抬腕提醒开关
  763 + print("抬腕提醒开关")
  764 + let content = parseContentFromBytes(bytes)
  765 + if (content.count == 1 && content.first == 0xff) {
  766 + for delegate in syncDelegateList {
  767 + delegate.didReceiveFinishCommand(0x8038)
  768 + }
  769 + }else {
  770 + parseWristSenseData(content)
  771 + }
  772 + case 0x8039://消息通知开关
  773 + print("消息通知开关")
  774 + let content = parseContentFromBytes(bytes)
  775 + if (content.count == 1 && content.first == 0xff) {
  776 + for delegate in syncDelegateList {
  777 + delegate.didReceiveFinishCommand(0x8039)
  778 + }
  779 + }else {
  780 + parseMessageRemindData(content)
  781 + }
  782 + case 0x8040://紧急常用联系人
  783 + print("紧急常用联系人")
  784 + let content = parseContentFromBytes(bytes)
  785 + if (content.count == 1 && content.first == 0xff) {
  786 + for delegate in syncDelegateList {
  787 + delegate.didReceiveFinishCommand(0x8040)
  788 + }
  789 + }else {
  790 + parseBeiDouContactData(content)
  791 + }
  792 + case 0x8041://压力检测开关
  793 + print("压力检测开关")
  794 + let content = parseContentFromBytes(bytes)
  795 + if (content.count == 1 && content.first == 0xff) {
  796 + for delegate in syncDelegateList {
  797 + delegate.didReceiveFinishCommand(0x8041)
  798 + }
  799 + }else {
  800 + parsePressureAutoDetectData(content)
  801 + }
  802 + case 0x8042://低电量提醒开关
  803 + print("低电量提醒开关")
  804 + let content = parseContentFromBytes(bytes)
  805 + if (content.count == 1 && content.first == 0xff) {
  806 + for delegate in syncDelegateList {
  807 + delegate.didReceiveFinishCommand(0x8042)
  808 + }
  809 + }else {
  810 + parseLowPowerRemindData(content)
  811 + }
  812 + case 0x8043://北斗消息自动回复
  813 + print("北斗消息自动回复")
  814 + let content = parseContentFromBytes(bytes)
  815 + if (content.count == 1 && content.first == 0xff) {
  816 + for delegate in syncDelegateList {
  817 + delegate.didReceiveFinishCommand(0x8043)
  818 + }
  819 + }else {
  820 + parseBeiDouQuickAnswerData(content)
  821 + }
  822 + case 0x8044://运动心率预警开关
703 823 print("运动心率预警开关")
704 824 let content = parseContentFromBytes(bytes)
705 825 if (content.count == 1 && content.first == 0xff) {
706 826 for delegate in syncDelegateList {
707   - delegate.didReceiveFinishCommand(0x8035)
  827 + delegate.didReceiveFinishCommand(0x8044)
708 828 }
709 829 }else {
710 830 parseExerciseHrRemindData(content)
711 831 }
712   - case 0x8037://固件版本号
713   - print("固件版本号")
  832 + case 0x8045://心率自动测量开关 连续测量心率
  833 + print("心率自动测量开关")
714 834 let content = parseContentFromBytes(bytes)
715 835 if (content.count == 1 && content.first == 0xff) {
716 836 for delegate in syncDelegateList {
717   - delegate.didReceiveFinishCommand(0x8037)
  837 + delegate.didReceiveFinishCommand(0x8045)
718 838 }
719 839 }else {
720   - parseFirmwareVersionData(content)
  840 + parseHrAutoDetectData(content)
721 841 }
722   - case 0x8038://抬腕提醒开关
723   - print("抬腕提醒开关")
  842 + case 0x8046://安静心率提醒设置
  843 + print("心率自动测量开关")
724 844 let content = parseContentFromBytes(bytes)
725 845 if (content.count == 1 && content.first == 0xff) {
726 846 for delegate in syncDelegateList {
727   - delegate.didReceiveFinishCommand(0x8038)
  847 + delegate.didReceiveFinishCommand(0x8046)
728 848 }
729 849 }else {
730   - parseWristSenseData(content)
  850 + parseRestHrRemindData(content)
731 851 }
732 852 default:
733 853 break
... ... @@ -980,24 +1100,40 @@ extension BluetoothManager {
980 1100  
981 1101 // 心率自动测量开关
982 1102 func parseHrAutoDetectData(_ content: [UInt8]) {
983   - guard content.count > 0 else {
  1103 + guard content.count > 1 else {
984 1104 print("无有效的信息")
985   - hrAutoDetectClosure?(false, nil)
  1105 +// hrAutoDetectClosure?(false, nil)
986 1106 return
987 1107 }
988 1108 let enable = (content[0] == 0x01)
989   - hrAutoDetectClosure?(enable, nil)
  1109 + let interval = Int(content[1])
  1110 + hrAutoDetectClosure?(enable, interval, nil)
990 1111 }
991 1112  
992 1113 // 运动心率预警开关
993 1114 func parseExerciseHrRemindData(_ content: [UInt8]) {
994   - guard content.count > 0 else {
  1115 + guard content.count > 2 else {
995 1116 print("无有效的信息")
996   - exerciseHrRemindClosure?(false, nil)
  1117 +// exerciseHrRemindClosure?(false, nil)
997 1118 return
998 1119 }
999 1120 let enable = (content[0] == 0x01)
1000   - exerciseHrRemindClosure?(enable, nil)
  1121 + let min = Int(content[1])
  1122 + let max = Int(content[2])
  1123 + exerciseHrRemindClosure?(enable, min, max, nil)
  1124 + }
  1125 +
  1126 + // 安静心率预警开关
  1127 + func parseRestHrRemindData(_ content: [UInt8]) {
  1128 + guard content.count > 2 else {
  1129 + print("无有效的信息")
  1130 +// exerciseHrRemindClosure?(false, nil)
  1131 + return
  1132 + }
  1133 + let enable = (content[0] == 0x01)
  1134 + let min = Int(content[1])
  1135 + let max = Int(content[2])
  1136 + restHrRemindClosure?(enable, min, max, nil)
1001 1137 }
1002 1138  
1003 1139 // 运动数据
... ... @@ -1037,4 +1173,97 @@ extension BluetoothManager {
1037 1173 let enable = (content[0] == 0x01)
1038 1174 wristSenseClosure?(enable, nil)
1039 1175 }
  1176 +
  1177 + // 消息通知开关
  1178 + func parseMessageRemindData(_ content: [UInt8]) {
  1179 + guard content.count > 0 else {
  1180 + print("无有效的信息")
  1181 + return
  1182 + }
  1183 + let byte = content[0] // 获取第一个字节
  1184 + let enable = byte & 0b00000001 != 0
  1185 + let system = byte & 0b00000010 != 0
  1186 + let wechat = byte & 0b00000100 != 0
  1187 + let qq = byte & 0b00001000 != 0
  1188 +
  1189 + messageRemindClosure?(enable, system, wechat, qq, nil)
  1190 + }
  1191 +
  1192 +
  1193 + // 紧急常用联系人
  1194 + func parseBeiDouContactData(_ content: [UInt8]) {
  1195 + guard content.count > 0 else {
  1196 + print("无有效的信息")
  1197 + return
  1198 + }
  1199 + let contact = NewBeiDouContactModel.getNewBeiDouContact(from: content)
  1200 + beiDouContactClosure?(contact, nil)
  1201 + }
  1202 +
  1203 + // 压力检测开关
  1204 + func parsePressureAutoDetectData(_ content: [UInt8]) {
  1205 + guard content.count > 0 else {
  1206 + print("无有效的信息")
  1207 + return
  1208 + }
  1209 + let enable = (content[0] == 0x01)
  1210 + pressureAutoDetectClosure?(enable, nil)
  1211 + }
  1212 +
  1213 + // 低电量提醒开关
  1214 + func parseLowPowerRemindData(_ content: [UInt8]) {
  1215 + guard content.count > 0 else {
  1216 + print("无有效的信息")
  1217 + return
  1218 + }
  1219 + let enable = (content[0] == 0x01)
  1220 + lowPowerRemindClosure?(enable, nil)
  1221 + }
  1222 +
  1223 + // 北斗消息自动回复
  1224 + func parseBeiDouQuickAnswerData(_ content: [UInt8]) {
  1225 + guard content.count > 0 else {
  1226 + print("无有效的信息")
  1227 + return
  1228 + }
  1229 + let answers = extractNewBeiDouQuickAnswers(from: content)
  1230 + beiDouQuickAnswerClosure?(answers, nil)
  1231 + }
  1232 +
  1233 + func extractNewBeiDouQuickAnswers(from data: [UInt8]) -> [String]? {
  1234 + var index = 0
  1235 + guard data.count >= 1 else { return nil }
  1236 +
  1237 + let answersCount = Int(data[index])
  1238 + index += 1
  1239 +
  1240 + var answers: [String] = []
  1241 +
  1242 + for _ in 0..<answersCount {
  1243 + guard index + 2 < data.count else { return nil }
  1244 +
  1245 + let utf8Length = Int(data[index])
  1246 + index += 1
  1247 +
  1248 + let utf8Data = Array(data[index..<(index + utf8Length)])
  1249 + guard let utf8String = String(bytes: utf8Data, encoding: .utf8) else { return nil }
  1250 + index += utf8Length
  1251 +
  1252 +// guard index + 2 < data.count else { return nil }
  1253 +//
  1254 +// let gbkLength = Int(data[index])
  1255 +// index += 1
  1256 +//
  1257 +// let gbkData = Array(data[index..<(index + gbkLength)])
  1258 +// let cfEncoding = CFStringEncodings(rawValue: CFStringEncodings.GB_18030_2000.rawValue)
  1259 +// let encoding = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(cfEncoding!.rawValue))
  1260 +// guard let gbkString = String(bytes: gbkData, encoding: String.Encoding(rawValue: encoding)) else { return nil }
  1261 +// index += gbkLength
  1262 +
  1263 + answers.append(utf8String)
  1264 + }
  1265 +
  1266 + return answers
  1267 + }
  1268 +
1040 1269 }
... ...
HDFwear/Tools/BluetoothManager.swift
... ... @@ -115,14 +115,28 @@ class BluetoothManager: NSObject {
115 115 var boAutoDetectClosure: BoAutoDetectClosure?
116 116 typealias BoLowRemindClosure = (_ value:Int, _ error: Int?) -> Void
117 117 var boLowRemindClosure: BoLowRemindClosure?
118   - typealias HrAutoDetectClosure = (_ enable:Bool, _ error: Int?) -> Void
  118 + typealias HrAutoDetectClosure = (_ enable:Bool, _ interval: Int, _ error: Int?) -> Void
119 119 var hrAutoDetectClosure: HrAutoDetectClosure?
120   - typealias ExerciseHrRemindClosure = (_ enable:Bool, _ error: Int?) -> Void
  120 + typealias ExerciseHrRemindClosure = (_ enable:Bool, _ min: Int, _ max: Int, _ error: Int?) -> Void
121 121 var exerciseHrRemindClosure: ExerciseHrRemindClosure?
  122 + typealias RestHrRemindClosure = (_ enable:Bool, _ min: Int, _ max: Int, _ error: Int?) -> Void
  123 + var restHrRemindClosure: RestHrRemindClosure?
122 124 typealias WristSenseClosure = (_ enable:Bool, _ error: Int?) -> Void
123 125 var wristSenseClosure: WristSenseClosure?
124 126 typealias FirmwareVersionClosure = (_ first:Int?, _ second:Int?, _ error: Int?) -> Void
125 127 var firmwareVersionClosure: FirmwareVersionClosure?
  128 + typealias MessageRemindClosure = (_ enable:Bool, _ system: Bool, _ wechat: Bool, _ qq: Bool, _ error: Int?) -> Void
  129 + var messageRemindClosure: MessageRemindClosure?
  130 + typealias BeiDouContactClosure = (_ contacts: [NewBeiDouContactModel]?, _ error: Int?) -> Void
  131 + var beiDouContactClosure: BeiDouContactClosure?
  132 + typealias PressureAutoDetectClosure = (_ enable:Bool, _ error: Int?) -> Void
  133 + var pressureAutoDetectClosure: PressureAutoDetectClosure?
  134 + typealias LowPowerRemindClosure = (_ enable:Bool, _ error: Int?) -> Void
  135 + var lowPowerRemindClosure: LowPowerRemindClosure?
  136 + typealias BeiDouQuickAnswerClosure = (_ answers:[String]?, _ error: Int?) -> Void
  137 + var beiDouQuickAnswerClosure: BeiDouQuickAnswerClosure?
  138 +
  139 +
126 140  
127 141 typealias DialProgressClosure = (_ progress: Int) -> Void
128 142 var dialProgressClosure: DialProgressClosure?
... ... @@ -1403,10 +1417,22 @@ class BluetoothManager: NSObject {
1403 1417 hrAutoDetectClosure = closure as? HrAutoDetectClosure
1404 1418 case .exerciseHrRemind:
1405 1419 exerciseHrRemindClosure = closure as? ExerciseHrRemindClosure
  1420 + case .restHrRemind:
  1421 + restHrRemindClosure = closure as? RestHrRemindClosure
1406 1422 case .wristSense:
1407 1423 wristSenseClosure = closure as? WristSenseClosure
1408 1424 case .firmwareVersion:
1409 1425 firmwareVersionClosure = closure as? FirmwareVersionClosure
  1426 + case .messageRemind:
  1427 + messageRemindClosure = closure as? MessageRemindClosure
  1428 + case .beiDouContact:
  1429 + beiDouContactClosure = closure as? BeiDouContactClosure
  1430 + case .pressureAutoDetect:
  1431 + pressureAutoDetectClosure = closure as? PressureAutoDetectClosure
  1432 + case .lowPowerRemind:
  1433 + lowPowerRemindClosure = closure as? LowPowerRemindClosure
  1434 + case .beiDouQuickAnswer:
  1435 + beiDouQuickAnswerClosure = closure as? BeiDouQuickAnswerClosure
1410 1436 default:
1411 1437 break
1412 1438 }
... ...