From 9b1c370b8864bf46382c68bd1c43fbd72a878f34 Mon Sep 17 00:00:00 2001 From: jason Date: Mon, 20 Nov 2023 19:16:54 +0800 Subject: [PATCH] feat:beidou --- HDFwear.xcodeproj/project.pbxproj | 4 ++++ HDFwear/20231111ReadMe.md | 14 ++++++++++++++ HDFwear/Home/Model/NewBeiDouContactModel.swift | 17 +++++++++++++++++ HDFwear/Mine/MineViewController.swift | 27 +++++++++++++++++++++++++++ HDFwear/Tools/BleMessage+Function.swift | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- HDFwear/Tools/Bluetooth+Types.swift | 5 ++--- HDFwear/Tools/BluetoothManager+Function.swift | 16 ++++++++++++++++ 7 files changed, 139 insertions(+), 4 deletions(-) diff --git a/HDFwear.xcodeproj/project.pbxproj b/HDFwear.xcodeproj/project.pbxproj index 37c479c..a547b7f 100644 --- a/HDFwear.xcodeproj/project.pbxproj +++ b/HDFwear.xcodeproj/project.pbxproj @@ -283,6 +283,7 @@ 6CFEEBC22773354500621863 /* HRReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC12773354500621863 /* HRReferenceVC.swift */; }; 6CFEEBC42773355700621863 /* SleepReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */; }; 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; }; + 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */; }; B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; }; B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; }; B23AA1032A1879E200BB3902 /* SortPageSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1022A1879E200BB3902 /* SortPageSectionHeader.xib */; }; @@ -659,6 +660,7 @@ 6CFEEBC12773354500621863 /* HRReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HRReferenceVC.swift; sourceTree = ""; }; 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepReferenceVC.swift; sourceTree = ""; }; 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = ""; }; + 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewBeiDouContactModel.swift; sourceTree = ""; }; 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = ""; }; B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; }; B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = ""; }; @@ -1272,6 +1274,7 @@ 6C6F40942743933100F9473C /* HealthModel.swift */, 6C6051BD2760C0CB00286B37 /* WeatherModel.swift */, 847482752B03793C0004F0C2 /* NewWeatherModel.swift */, + 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */, ); path = Model; sourceTree = ""; @@ -1754,6 +1757,7 @@ 6C1B7EA027B7976600DB9D1C /* NFCModifyCardVC.swift in Sources */, 6C6505A92798FAD90043DB7A /* CustomDialViewController.swift in Sources */, 6CBB0CAC27B7B89C009B27C1 /* NFCMessageVC.swift in Sources */, + 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */, 6C6505C12798FB030043DB7A /* LTCollectionFlowLayout.swift in Sources */, 6C04E8B527898883002C2D8E /* TemperatureView.swift in Sources */, 6C6505C52798FB030043DB7A /* UIView+LTExtension.swift in Sources */, diff --git a/HDFwear/20231111ReadMe.md b/HDFwear/20231111ReadMe.md index e91b428..f92eebe 100644 --- a/HDFwear/20231111ReadMe.md +++ b/HDFwear/20231111ReadMe.md @@ -41,3 +41,17 @@ BluetoothManager+Function 发送: [237, 126, 0, 1, 0, 49, 0, 1, 0, 34, 101, 86, 25, 192, 15, 10, 20, 2, 4, 3, 6, 4, 1, 11, 21, 1, 12, 22, 1, 13, 23, 1, 14, 24, 1, 15, 25, 6, 233, 149, 191, 230, 178, 153, 198, 52] 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 0, 192, 215] 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 14, 33, 25] + + +设置北斗联系人 + func newSetBeiDouContact(contacts: [NewBeiDouContactModel], completion: @escaping(_ error: Int?) -> ()) { +发送 拼: [237, 126, 0, 1, 0, 41, 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, 90, 161] +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 41, 0, 74, 13] +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 41, 14, 171, 195] + +设置北斗快捷回复 + func newSetBeiDouQuickAnswer(answers: [String], completion: @escaping(_ error: Int?) -> ()) { +发送 拼: [237, 126, 0, 1, 0, 48, 0, 1, 0, 13, 1, 6, 229, 140, 151, 230, 150, 151, 4, 177, 177, 182, 183, 141, 19] +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 48, 0, 243, 230] +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 48, 14, 18, 40] + diff --git a/HDFwear/Home/Model/NewBeiDouContactModel.swift b/HDFwear/Home/Model/NewBeiDouContactModel.swift index ab05207..b93459d 100644 --- a/HDFwear/Home/Model/NewBeiDouContactModel.swift +++ b/HDFwear/Home/Model/NewBeiDouContactModel.swift @@ -6,7 +6,24 @@ // import UIKit +import HandyJSON +import SwiftDate + +enum NewBeiDouContactType: Int, HandyJSONEnum { + case emergency = 1 + case general = 2 +} class NewBeiDouContactModel: NSObject { + required override init() { } + + var name: String = "" + var phone: String = "" + var type: NewBeiDouContactType = .general + init(name: String, phone: String, type: NewBeiDouContactType) { + self.name = name + self.phone = phone + self.type = type + } } diff --git a/HDFwear/Mine/MineViewController.swift b/HDFwear/Mine/MineViewController.swift index 9682185..a214d83 100644 --- a/HDFwear/Mine/MineViewController.swift +++ b/HDFwear/Mine/MineViewController.swift @@ -378,6 +378,30 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { } } + let archiveAction20 = UIAlertAction(title: "newSetBeiDouContact", style: .default) { action in + let contacts = [NewBeiDouContactModel(name: "周杰伦", phone: "18974960001", type: .emergency), + NewBeiDouContactModel(name: "梁朝伟", phone: "18974960002", type: .general), + NewBeiDouContactModel(name: "吴彦祖", phone: "18974960003", type: .emergency), + NewBeiDouContactModel(name: "成龙", phone: "18974960004", type: .general)] + BluetoothManager.shared.newSetBeiDouContact(contacts: contacts) { error in + if error != nil { + print("newSetBeiDouContact" + (error?.description ?? "")) + }else { + print("newSetBeiDouContact success") + } + } + } + + let archiveAction21 = UIAlertAction(title: "newSetBeiDouQuickAnswer", style: .default) { action in + BluetoothManager.shared.newSetBeiDouQuickAnswer(answers: ["北斗"]) { error in + if error != nil { + print("newSetBeiDouQuickAnswer" + (error?.description ?? "")) + }else { + print("newSetBeiDouQuickAnswer success") + } + } + } + alert.addAction(archiveAction1) alert.addAction(archiveAction2) alert.addAction(archiveAction3) @@ -397,6 +421,9 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { alert.addAction(archiveAction17) alert.addAction(archiveAction18) alert.addAction(archiveAction19) + alert.addAction(archiveAction20) + alert.addAction(archiveAction21) + present(alert, animated: true, completion: nil) case "我的数据": let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthDataVC") diff --git a/HDFwear/Tools/BleMessage+Function.swift b/HDFwear/Tools/BleMessage+Function.swift index f731242..c2662cb 100644 --- a/HDFwear/Tools/BleMessage+Function.swift +++ b/HDFwear/Tools/BleMessage+Function.swift @@ -139,9 +139,67 @@ extension BleMessage { let utf8Array = Array(utf8Data) bytes += [UInt8(utf8Array.count)] + utf8Array } else { - // jtd! + bytes += [UInt8(1), UInt8(0)] print("转换失败") } return createDataPacket(key: .setWeather, bytes: bytes) } + + func getNewBeiDouContactCmd(_ contacts: [NewBeiDouContactModel]) -> Data { + // 如果超过10个元素,截断数组 + var truncatedContacts = contacts + if truncatedContacts.count > 10 { + truncatedContacts.removeSubrange(10.. Data { + let answersCount = answers.count + var bytes: [UInt8] = [UInt8(answersCount)] + for ans in answers { + // utf8 + if let utf8Data = ans.data(using: .utf8) { + let utf8Array = Array(utf8Data) + bytes += [UInt8(utf8Array.count)] + utf8Array + }else { + bytes += [UInt8(1), UInt8(0)] + print("转换失败") + } + // gbk + let cfEncoding = CFStringEncodings.GB_18030_2000 + let encoding = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(cfEncoding.rawValue)) + let fullStr = ans.toFullWidth()// 半角->全角 + if let gbkData = fullStr.data(using: String.Encoding(rawValue: encoding)) { + let gbkArray = Array(gbkData) + bytes += [UInt8(gbkArray.count)] + gbkArray + }else { + bytes += [UInt8(1), UInt8(0)] + print("转换失败") + } + } + return createDataPacket(key: .setBeiDouQuickAnswer, bytes: bytes) + } } diff --git a/HDFwear/Tools/Bluetooth+Types.swift b/HDFwear/Tools/Bluetooth+Types.swift index b9a5e3e..72cf839 100644 --- a/HDFwear/Tools/Bluetooth+Types.swift +++ b/HDFwear/Tools/Bluetooth+Types.swift @@ -139,9 +139,8 @@ enum NewCmd: UInt8 { case setNoDisturb = 0x0027 case setSynWatch = 0x0028 case setWeather = 0x0031 - //jtd! -// case setBeiDouContact = 0x0029 -// case setBeiDouQuickAnswer = 0x0030 + case setBeiDouContact = 0x0029 + case setBeiDouQuickAnswer = 0x0030 } diff --git a/HDFwear/Tools/BluetoothManager+Function.swift b/HDFwear/Tools/BluetoothManager+Function.swift index 19c6b89..c51b1c0 100644 --- a/HDFwear/Tools/BluetoothManager+Function.swift +++ b/HDFwear/Tools/BluetoothManager+Function.swift @@ -160,6 +160,22 @@ extension BluetoothManager { sendData(data) } + // 设置北斗联系人 + // + func newSetBeiDouContact(contacts: [NewBeiDouContactModel], completion: @escaping(_ error: Int?) -> ()) { + let data = BleMessage.shared.getNewBeiDouContactCmd(contacts) + self.setCmdClosure = completion + sendData(data) + } + + // 设置北斗快捷回复 + // + func newSetBeiDouQuickAnswer(answers: [String], completion: @escaping(_ error: Int?) -> ()) { + let data = BleMessage.shared.getNewBeiDouQuickAnswerCmd(answers) + self.setCmdClosure = completion + sendData(data) + } + //MARK: - 同步健康数据 // 拉取睡眠数据 func getSleepHistoryData( closure: SleepClosure? = nil) { -- libgit2 0.21.4