Commit 9b1c370b8864bf46382c68bd1c43fbd72a878f34

Authored by jason
1 parent ba0a04ea

feat:beidou

HDFwear.xcodeproj/project.pbxproj
@@ -283,6 +283,7 @@ @@ -283,6 +283,7 @@
283 6CFEEBC22773354500621863 /* HRReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC12773354500621863 /* HRReferenceVC.swift */; }; 283 6CFEEBC22773354500621863 /* HRReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC12773354500621863 /* HRReferenceVC.swift */; };
284 6CFEEBC42773355700621863 /* SleepReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */; }; 284 6CFEEBC42773355700621863 /* SleepReferenceVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */; };
285 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; }; 285 847482762B03793C0004F0C2 /* NewWeatherModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847482752B03793C0004F0C2 /* NewWeatherModel.swift */; };
  286 + 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */; };
286 B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; }; 287 B212F1FD2A14CE0400781D59 /* LaunchSetting.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = B212F1FF2A14CE0400781D59 /* LaunchSetting.storyboard */; };
287 B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; }; 288 B212F2052A14D28E00781D59 /* LaunchMyBodySettingVC.swift in Sources */ = {isa = PBXBuildFile; fileRef = B212F2042A14D28E00781D59 /* LaunchMyBodySettingVC.swift */; };
288 B23AA1032A1879E200BB3902 /* SortPageSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1022A1879E200BB3902 /* SortPageSectionHeader.xib */; }; 289 B23AA1032A1879E200BB3902 /* SortPageSectionHeader.xib in Resources */ = {isa = PBXBuildFile; fileRef = B23AA1022A1879E200BB3902 /* SortPageSectionHeader.xib */; };
@@ -659,6 +660,7 @@ @@ -659,6 +660,7 @@
659 6CFEEBC12773354500621863 /* HRReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HRReferenceVC.swift; sourceTree = "<group>"; }; 660 6CFEEBC12773354500621863 /* HRReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HRReferenceVC.swift; sourceTree = "<group>"; };
660 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepReferenceVC.swift; sourceTree = "<group>"; }; 661 6CFEEBC32773355700621863 /* SleepReferenceVC.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SleepReferenceVC.swift; sourceTree = "<group>"; };
661 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = "<group>"; }; 662 847482752B03793C0004F0C2 /* NewWeatherModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewWeatherModel.swift; sourceTree = "<group>"; };
  663 + 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NewBeiDouContactModel.swift; sourceTree = "<group>"; };
662 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = "<group>"; }; 664 847D1C4A2B009FAC0097A96E /* 20231111ReadMe.md */ = {isa = PBXFileReference; lastKnownFileType = net.daringfireball.markdown; path = 20231111ReadMe.md; sourceTree = "<group>"; };
663 B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 665 B0BDC40FAF3CBA7B780ED655 /* Pods_HDFwear.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_HDFwear.framework; sourceTree = BUILT_PRODUCTS_DIR; };
664 B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = "<group>"; }; 666 B212F1FE2A14CE0400781D59 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchSetting.storyboard; sourceTree = "<group>"; };
@@ -1272,6 +1274,7 @@ @@ -1272,6 +1274,7 @@
1272 6C6F40942743933100F9473C /* HealthModel.swift */, 1274 6C6F40942743933100F9473C /* HealthModel.swift */,
1273 6C6051BD2760C0CB00286B37 /* WeatherModel.swift */, 1275 6C6051BD2760C0CB00286B37 /* WeatherModel.swift */,
1274 847482752B03793C0004F0C2 /* NewWeatherModel.swift */, 1276 847482752B03793C0004F0C2 /* NewWeatherModel.swift */,
  1277 + 847672B72B074E43007DC2DE /* NewBeiDouContactModel.swift */,
1275 ); 1278 );
1276 path = Model; 1279 path = Model;
1277 sourceTree = "<group>"; 1280 sourceTree = "<group>";
@@ -1754,6 +1757,7 @@ @@ -1754,6 +1757,7 @@
1754 6C1B7EA027B7976600DB9D1C /* NFCModifyCardVC.swift in Sources */, 1757 6C1B7EA027B7976600DB9D1C /* NFCModifyCardVC.swift in Sources */,
1755 6C6505A92798FAD90043DB7A /* CustomDialViewController.swift in Sources */, 1758 6C6505A92798FAD90043DB7A /* CustomDialViewController.swift in Sources */,
1756 6CBB0CAC27B7B89C009B27C1 /* NFCMessageVC.swift in Sources */, 1759 6CBB0CAC27B7B89C009B27C1 /* NFCMessageVC.swift in Sources */,
  1760 + 847672B82B074E43007DC2DE /* NewBeiDouContactModel.swift in Sources */,
1757 6C6505C12798FB030043DB7A /* LTCollectionFlowLayout.swift in Sources */, 1761 6C6505C12798FB030043DB7A /* LTCollectionFlowLayout.swift in Sources */,
1758 6C04E8B527898883002C2D8E /* TemperatureView.swift in Sources */, 1762 6C04E8B527898883002C2D8E /* TemperatureView.swift in Sources */,
1759 6C6505C52798FB030043DB7A /* UIView+LTExtension.swift in Sources */, 1763 6C6505C52798FB030043DB7A /* UIView+LTExtension.swift in Sources */,
HDFwear/20231111ReadMe.md
@@ -41,3 +41,17 @@ BluetoothManager+Function @@ -41,3 +41,17 @@ BluetoothManager+Function
41 发送: [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] 41 发送: [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]
42 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 0, 192, 215] 42 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 0, 192, 215]
43 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 14, 33, 25] 43 接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 49, 14, 33, 25]
  44 +
  45 +
  46 +设置北斗联系人
  47 + func newSetBeiDouContact(contacts: [NewBeiDouContactModel], completion: @escaping(_ error: Int?) -> ()) {
  48 +发送 拼: [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]
  49 +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 41, 0, 74, 13]
  50 +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 41, 14, 171, 195]
  51 +
  52 +设置北斗快捷回复
  53 + func newSetBeiDouQuickAnswer(answers: [String], completion: @escaping(_ error: Int?) -> ()) {
  54 +发送 拼: [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]
  55 +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 48, 0, 243, 230]
  56 +接收: [237, 126, 0, 1, 128, 1, 0, 1, 0, 5, 0, 1, 0, 48, 14, 18, 40]
  57 +
HDFwear/Home/Model/NewBeiDouContactModel.swift
@@ -6,7 +6,24 @@ @@ -6,7 +6,24 @@
6 // 6 //
7 7
8 import UIKit 8 import UIKit
  9 +import HandyJSON
  10 +import SwiftDate
  11 +
  12 +enum NewBeiDouContactType: Int, HandyJSONEnum {
  13 + case emergency = 1
  14 + case general = 2
  15 +}
9 16
10 class NewBeiDouContactModel: NSObject { 17 class NewBeiDouContactModel: NSObject {
  18 + required override init() { }
  19 +
  20 + var name: String = ""
  21 + var phone: String = ""
  22 + var type: NewBeiDouContactType = .general
11 23
  24 + init(name: String, phone: String, type: NewBeiDouContactType) {
  25 + self.name = name
  26 + self.phone = phone
  27 + self.type = type
  28 + }
12 } 29 }
HDFwear/Mine/MineViewController.swift
@@ -378,6 +378,30 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { @@ -378,6 +378,30 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
378 } 378 }
379 } 379 }
380 380
  381 + let archiveAction20 = UIAlertAction(title: "newSetBeiDouContact", style: .default) { action in
  382 + let contacts = [NewBeiDouContactModel(name: "周杰伦", phone: "18974960001", type: .emergency),
  383 + NewBeiDouContactModel(name: "梁朝伟", phone: "18974960002", type: .general),
  384 + NewBeiDouContactModel(name: "吴彦祖", phone: "18974960003", type: .emergency),
  385 + NewBeiDouContactModel(name: "成龙", phone: "18974960004", type: .general)]
  386 + BluetoothManager.shared.newSetBeiDouContact(contacts: contacts) { error in
  387 + if error != nil {
  388 + print("newSetBeiDouContact" + (error?.description ?? ""))
  389 + }else {
  390 + print("newSetBeiDouContact success")
  391 + }
  392 + }
  393 + }
  394 +
  395 + let archiveAction21 = UIAlertAction(title: "newSetBeiDouQuickAnswer", style: .default) { action in
  396 + BluetoothManager.shared.newSetBeiDouQuickAnswer(answers: ["北斗"]) { error in
  397 + if error != nil {
  398 + print("newSetBeiDouQuickAnswer" + (error?.description ?? ""))
  399 + }else {
  400 + print("newSetBeiDouQuickAnswer success")
  401 + }
  402 + }
  403 + }
  404 +
381 alert.addAction(archiveAction1) 405 alert.addAction(archiveAction1)
382 alert.addAction(archiveAction2) 406 alert.addAction(archiveAction2)
383 alert.addAction(archiveAction3) 407 alert.addAction(archiveAction3)
@@ -397,6 +421,9 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate { @@ -397,6 +421,9 @@ extension MineViewController: UITableViewDataSource, UITableViewDelegate {
397 alert.addAction(archiveAction17) 421 alert.addAction(archiveAction17)
398 alert.addAction(archiveAction18) 422 alert.addAction(archiveAction18)
399 alert.addAction(archiveAction19) 423 alert.addAction(archiveAction19)
  424 + alert.addAction(archiveAction20)
  425 + alert.addAction(archiveAction21)
  426 +
400 present(alert, animated: true, completion: nil) 427 present(alert, animated: true, completion: nil)
401 case "我的数据": 428 case "我的数据":
402 let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthDataVC") 429 let vc = UIStoryboard.loadViewControllerIdentifier(storyboardName: "Mine", identifier: "HealthDataVC")
HDFwear/Tools/BleMessage+Function.swift
@@ -139,9 +139,67 @@ extension BleMessage { @@ -139,9 +139,67 @@ extension BleMessage {
139 let utf8Array = Array(utf8Data) 139 let utf8Array = Array(utf8Data)
140 bytes += [UInt8(utf8Array.count)] + utf8Array 140 bytes += [UInt8(utf8Array.count)] + utf8Array
141 } else { 141 } else {
142 - // jtd! 142 + bytes += [UInt8(1), UInt8(0)]
143 print("转换失败") 143 print("转换失败")
144 } 144 }
145 return createDataPacket(key: .setWeather, bytes: bytes) 145 return createDataPacket(key: .setWeather, bytes: bytes)
146 } 146 }
  147 +
  148 + func getNewBeiDouContactCmd(_ contacts: [NewBeiDouContactModel]) -> Data {
  149 + // 如果超过10个元素,截断数组
  150 + var truncatedContacts = contacts
  151 + if truncatedContacts.count > 10 {
  152 + truncatedContacts.removeSubrange(10..<truncatedContacts.count)
  153 + }
  154 + let contactsCount = truncatedContacts.count
  155 + var bytes: [UInt8] = [UInt8(contactsCount)]
  156 + for model in truncatedContacts {
  157 + // name
  158 + if let utf8Data = model.name.data(using: .utf8) {
  159 + let utf8Array = Array(utf8Data)
  160 + bytes += [UInt8(utf8Array.count)] + utf8Array
  161 + }else {
  162 + bytes += [UInt8(1), UInt8(0)]
  163 + print("转换失败")
  164 + }
  165 + // phone
  166 + if let asciiData = model.phone.data(using: .ascii) {
  167 + let asciiArray = Array(asciiData)
  168 + bytes += [UInt8(asciiArray.count)] + asciiArray
  169 + }else {
  170 + bytes += [UInt8(1), UInt8(0)]
  171 + print("转换失败")
  172 + }
  173 + // type
  174 + bytes.append(UInt8(model.type.rawValue))
  175 + }
  176 + return createDataPacket(key: .setBeiDouContact, bytes: bytes)
  177 + }
  178 +
  179 + func getNewBeiDouQuickAnswerCmd(_ answers: [String]) -> Data {
  180 + let answersCount = answers.count
  181 + var bytes: [UInt8] = [UInt8(answersCount)]
  182 + for ans in answers {
  183 + // utf8
  184 + if let utf8Data = ans.data(using: .utf8) {
  185 + let utf8Array = Array(utf8Data)
  186 + bytes += [UInt8(utf8Array.count)] + utf8Array
  187 + }else {
  188 + bytes += [UInt8(1), UInt8(0)]
  189 + print("转换失败")
  190 + }
  191 + // gbk
  192 + let cfEncoding = CFStringEncodings.GB_18030_2000
  193 + let encoding = CFStringConvertEncodingToNSStringEncoding(CFStringEncoding(cfEncoding.rawValue))
  194 + let fullStr = ans.toFullWidth()// 半角->全角
  195 + if let gbkData = fullStr.data(using: String.Encoding(rawValue: encoding)) {
  196 + let gbkArray = Array(gbkData)
  197 + bytes += [UInt8(gbkArray.count)] + gbkArray
  198 + }else {
  199 + bytes += [UInt8(1), UInt8(0)]
  200 + print("转换失败")
  201 + }
  202 + }
  203 + return createDataPacket(key: .setBeiDouQuickAnswer, bytes: bytes)
  204 + }
147 } 205 }
HDFwear/Tools/Bluetooth+Types.swift
@@ -139,9 +139,8 @@ enum NewCmd: UInt8 { @@ -139,9 +139,8 @@ enum NewCmd: UInt8 {
139 case setNoDisturb = 0x0027 139 case setNoDisturb = 0x0027
140 case setSynWatch = 0x0028 140 case setSynWatch = 0x0028
141 case setWeather = 0x0031 141 case setWeather = 0x0031
142 - //jtd!  
143 -// case setBeiDouContact = 0x0029  
144 -// case setBeiDouQuickAnswer = 0x0030 142 + case setBeiDouContact = 0x0029
  143 + case setBeiDouQuickAnswer = 0x0030
145 144
146 } 145 }
147 146
HDFwear/Tools/BluetoothManager+Function.swift
@@ -160,6 +160,22 @@ extension BluetoothManager { @@ -160,6 +160,22 @@ extension BluetoothManager {
160 sendData(data) 160 sendData(data)
161 } 161 }
162 162
  163 + // 设置北斗联系人
  164 + //
  165 + func newSetBeiDouContact(contacts: [NewBeiDouContactModel], completion: @escaping(_ error: Int?) -> ()) {
  166 + let data = BleMessage.shared.getNewBeiDouContactCmd(contacts)
  167 + self.setCmdClosure = completion
  168 + sendData(data)
  169 + }
  170 +
  171 + // 设置北斗快捷回复
  172 + //
  173 + func newSetBeiDouQuickAnswer(answers: [String], completion: @escaping(_ error: Int?) -> ()) {
  174 + let data = BleMessage.shared.getNewBeiDouQuickAnswerCmd(answers)
  175 + self.setCmdClosure = completion
  176 + sendData(data)
  177 + }
  178 +
163 //MARK: - 同步健康数据 179 //MARK: - 同步健康数据
164 // 拉取睡眠数据 180 // 拉取睡眠数据
165 func getSleepHistoryData( closure: SleepClosure? = nil) { 181 func getSleepHistoryData( closure: SleepClosure? = nil) {