From: liangzhenying <867174124@qq.com> Date: Fri, 17 Jan 2025 06:11:31 +0000 (+0800) Subject: 新增SOS指令 X-Git-Url: http://git.snicker.com.cn/sitemap.xml?a=commitdiff_plain;h=5c19005ee2c10abecfacd48659939de4ce029d71;p=mirrors%2FIOTBluetooth-iOS.git 新增SOS指令 --- diff --git a/IOTBluetooth/IOTBluetooth/Example/Datas.swift b/IOTBluetooth/IOTBluetooth/Example/Datas.swift index 867831f..ca97cac 100644 --- a/IOTBluetooth/IOTBluetooth/Example/Datas.swift +++ b/IOTBluetooth/IOTBluetooth/Example/Datas.swift @@ -11,6 +11,8 @@ import IOTBluetooth let datas: [(ability: IBAbility, label: String, parameters: [IBParameter])] = [ + (.getSosContact,"获取OS紧急联系人",[]), + (.setSosContact,"设置SOS紧急联系人",[.setSosContact([IBContact()])]), (.getPushConfig,"获取推送配置",[]), (.setPushConfig,"设置推送",[.setPush(IBPush.all)]), diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj index 8f5c54e..1e45d64 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.pbxproj @@ -63,6 +63,7 @@ 3F6A07C52D2D06D600F4122A /* MixTools.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 3F6A07C42D2D06D600F4122A /* MixTools.framework */; }; 3F6A07CC2D2D2C3F00F4122A /* IBPassword.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */; }; 3F9355B72D38FF2100C54DAB /* IBPush.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3F9355B62D38FF1900C54DAB /* IBPush.swift */; }; + 3FFAE0552D3A042900325873 /* IBContact.swift in Sources */ = {isa = PBXBuildFile; fileRef = 3FFAE0542D3A03EF00325873 /* IBContact.swift */; }; 8A0A39BF2B980BEF006A3B18 /* IOTBluetooth.h in Headers */ = {isa = PBXBuildFile; fileRef = 8A0A39BE2B980BEF006A3B18 /* IOTBluetooth.h */; settings = {ATTRIBUTES = (Public, ); }; }; 8A0A39C62B980C88006A3B18 /* IBluetooth.swift in Sources */ = {isa = PBXBuildFile; fileRef = 8A0A39C52B980C88006A3B18 /* IBluetooth.swift */; }; 8A0A39C92B980CC2006A3B18 /* CoreBluetooth.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 8A0A39C82B980CC2006A3B18 /* CoreBluetooth.framework */; }; @@ -185,6 +186,7 @@ 3F6A07C42D2D06D600F4122A /* MixTools.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = MixTools.framework; sourceTree = ""; }; 3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPassword.swift; sourceTree = ""; }; 3F9355B62D38FF1900C54DAB /* IBPush.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBPush.swift; sourceTree = ""; }; + 3FFAE0542D3A03EF00325873 /* IBContact.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IBContact.swift; sourceTree = ""; }; 8A0A39BB2B980BEF006A3B18 /* IOTBluetooth.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = IOTBluetooth.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 8A0A39BE2B980BEF006A3B18 /* IOTBluetooth.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = IOTBluetooth.h; sourceTree = ""; }; 8A0A39C52B980C88006A3B18 /* IBluetooth.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = IBluetooth.swift; sourceTree = ""; }; @@ -408,6 +410,7 @@ 182DDFD32C5CE68900D44D37 /* IBAiValid.swift */, 3F6A07CB2D2D2C3F00F4122A /* IBPassword.swift */, 3F9355B62D38FF1900C54DAB /* IBPush.swift */, + 3FFAE0542D3A03EF00325873 /* IBContact.swift */, ); path = Models; sourceTree = ""; @@ -569,6 +572,7 @@ 8A5822CF2BA1A67700590AB6 /* IBAbility.swift in Sources */, 8A65F9652BAC271B005C1EA4 /* IBScreen.swift in Sources */, 1859DFA02BFF5A2700112E8C /* IBSendTime.swift in Sources */, + 3FFAE0552D3A042900325873 /* IBContact.swift in Sources */, 18EF69792C47A86D00AA0A36 /* IBTools.swift in Sources */, 8A65F9632BAC1018005C1EA4 /* IBTargetStep.swift in Sources */, 181441D32C115AC500CCDD46 /* IBFileSender.swift in Sources */, diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate index f2903ef..3c632fc 100644 Binary files a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate and b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/project.xcworkspace/xcuserdata/yaozuopan.xcuserdatad/UserInterfaceState.xcuserstate differ diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist index b77e291..295d9b7 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth.xcodeproj/xcuserdata/yaozuopan.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist @@ -3,4 +3,22 @@ uuid = "2CC27BE0-931D-4412-B83C-49E80F4BA55C" type = "1" version = "2.0"> + + + + + + diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift index cd782cc..292bfb6 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBAbility.swift @@ -97,7 +97,19 @@ public extension IBAbility { /// 设置消息推送 /// - Parameter setPush: see ``[IBPush]`` - static let setPushConfig = IBAbility.long.id(0x1e).parser(IBGeneralParser.self).checker(IBPUshChecker.self) + static let setPushConfig = IBAbility.long.id(0x1e).parser(IBGeneralParser.self).checker(IBPushChecker.self) + + /// 获取SOS紧急联系人 + /// - Returns: ``[IBContact]`` \ + /// Read from ``IBResponse``.value + static let getSosContact = IBAbility.short.id(0x36).parser(IBGetSosParser.self) + + /// 设置SOS紧急联系人 + /// - Parameter setSosContact: see ``[IBContact]`` + static let setSosContact = IBAbility.long.id(0x25).parser(IBGeneralParser.self).checker(IBSetSosChecker.self) + + + /// 设置用户数据 /// - Parameter userInfo: see ``IBUserInfo`` diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift index 93e6c3c..20f1890 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBChecker.swift @@ -294,7 +294,7 @@ struct IBUserInfoChecker: IBChecker { return data } } -struct IBPUshChecker: IBChecker { +struct IBPushChecker: IBChecker { static func check(_ parameters: [IBParameter]) -> [UInt8] { guard case let .setPush(value) = parameters[.setPush] else { fatalError("缺少参数: setpush") } Logger.log(value.description) @@ -312,6 +312,26 @@ struct IBPUshChecker: IBChecker { return data } } +struct IBSetSosChecker: IBChecker { + static func check(_ parameters: [IBParameter]) -> [UInt8] { + guard case let .setSosContact(value) = parameters[.setSosContact] else { fatalError("缺少参数: setpush") } + Logger.log(value.description) + var data = [UInt8]() + data += [value.count.byte] + for item in value { + data += [item.gender.byte] + if let value = item.name.data(using: .utf8),!value.isEmpty { + data += [value.count.byte] + data += value.bytes + } + if let value = item.tel.data(using: .utf8),!value.isEmpty { + data += [value.count.byte] + data += value.bytes + } + } + return data + } +} struct IBClockChecker: IBChecker { diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift index e01be3f..04d3a82 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParameter.swift @@ -42,6 +42,7 @@ enum IBKey: String { case setPassword = "setPassword" case setPush = "setPushConfig" + case setSosContact = "setSosContact" } /// 参数 @@ -110,8 +111,10 @@ public enum IBParameter { case aiResponse(IBAiResponse) /// 设置密码 case setPassword(IBPassword) - /// 设置密码 + /// 设置消息推送 case setPush([IBPush]) + /// 设置SOS紧急联系人 + case setSosContact([IBContact]) var key: IBKey { switch self { @@ -148,6 +151,7 @@ public enum IBParameter { case .aiResponse(_): return .aiResponse case .setPassword(_): return .setPassword case .setPush(_): return .setPush + case .setSosContact(_): return .setSosContact } } } diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift index 55b0414..96ba4a5 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/IBParser.swift @@ -97,6 +97,31 @@ struct IBGetPushParser: IBParser { return .response.code(.success).value(list) } } +/// 获取SOS紧急联系人 +struct IBGetSosParser: IBParser { + static func parse(_ data: Data) -> IBResponse { + let datas = dataPacket(data) + let num = datas[0].int + var list = [IBContact]() + var index = 1 + for _ in 0 ..< num { + let value = IBContact() + value.gender = datas[index].int + index = index + 1 + let nameLen = datas[index].int + index = index + 1 + value.name = String.init(data: Data(datas[index.. IBResponse { let code = dataPacket(data).int diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBContact.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBContact.swift new file mode 100644 index 0000000..c20764e --- /dev/null +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBContact.swift @@ -0,0 +1,26 @@ +// +// IBContact.swift +// IOTBluetooth +// +// Created by liangshi on 2025/1/17. +// + +import Foundation +/// 联系人 +public class IBContact { + /// 性别 0:男性 1:女性 + public var gender: Int = 0 + /// 名称 + public var name:String = "广州" + /// 电话 + public var tel:String = "13480000000" + + public init() { } + + + var description: String { + let str = "IBContact(gender: \(gender),name:\(name),tel:\(tel))" + return str + } + +} diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPassword.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPassword.swift index 651b4e8..aec3ef2 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPassword.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPassword.swift @@ -7,7 +7,7 @@ import Foundation -/// 关于本机模型 +/// 密码模型 public class IBPassword:Codable { /// 0不启用,1启用 public var type: Int = 0 diff --git a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPush.swift b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPush.swift index 04fde22..ec29b93 100644 --- a/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPush.swift +++ b/IOTBluetooth/IOTBluetooth/IOTBluetooth/Models/IBPush.swift @@ -6,7 +6,7 @@ // import Foundation -/// 关于本机模型 +/// 消息推送 public class IBPush { /// 类型 public var type: IBPushType = .tel @@ -36,7 +36,7 @@ public class IBPush { } } -/// 推送配置 +/// 推送类型 public enum IBPushType: Int { case tel = 0 case sms = 1