feat: 支持获取 maximumWrtieLength (#14)
This commit is contained in:
@ -254,6 +254,7 @@ protocol MyCentralControllerHostApi {
|
||||
func stopDiscovery() throws
|
||||
func connect(myPeripheralKey: Int64, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func disconnect(myPeripheralKey: Int64, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func getMaximumWriteLength(myPeripheralKey: Int64, myTypeNumber: Int64) throws -> Int64
|
||||
func discoverGATT(myPeripheralKey: Int64, completion: @escaping (Result<Void, Error>) -> Void)
|
||||
func getServices(myPeripheralKey: Int64) throws -> [MyGattServiceArgs]
|
||||
func getCharacteristics(myServiceKey: Int64) throws -> [MyGattCharacteristicArgs]
|
||||
@ -359,6 +360,22 @@ class MyCentralControllerHostApiSetup {
|
||||
} else {
|
||||
disconnectChannel.setMessageHandler(nil)
|
||||
}
|
||||
let getMaximumWriteLengthChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.bluetooth_low_energy_darwin.MyCentralControllerHostApi.getMaximumWriteLength", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
getMaximumWriteLengthChannel.setMessageHandler { message, reply in
|
||||
let args = message as! [Any?]
|
||||
let myPeripheralKeyArg = args[0] is Int64 ? args[0] as! Int64 : Int64(args[0] as! Int32)
|
||||
let myTypeNumberArg = args[1] is Int64 ? args[1] as! Int64 : Int64(args[1] as! Int32)
|
||||
do {
|
||||
let result = try api.getMaximumWriteLength(myPeripheralKey: myPeripheralKeyArg, myTypeNumber: myTypeNumberArg)
|
||||
reply(wrapResult(result))
|
||||
} catch {
|
||||
reply(wrapError(error))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
getMaximumWriteLengthChannel.setMessageHandler(nil)
|
||||
}
|
||||
let discoverGATTChannel = FlutterBasicMessageChannel(name: "dev.flutter.pigeon.bluetooth_low_energy_darwin.MyCentralControllerHostApi.discoverGATT", binaryMessenger: binaryMessenger, codec: codec)
|
||||
if let api = api {
|
||||
discoverGATTChannel.setMessageHandler { message, reply in
|
||||
|
@ -122,6 +122,21 @@ class MyCentralController: MyCentralControllerHostApi {
|
||||
}
|
||||
}
|
||||
|
||||
func getMaximumWriteLength(myPeripheralKey: Int64, myTypeNumber: Int64) throws -> Int64 {
|
||||
let peripheralKey = Int(myPeripheralKey)
|
||||
guard let peripheral = cachedPeripherals[peripheralKey] else {
|
||||
throw MyError.illegalArgument
|
||||
}
|
||||
let myTypeRawValue = Int(myTypeNumber)
|
||||
guard let myTypeArgs = MyGattCharacteristicWriteTypeArgs(rawValue: myTypeRawValue) else {
|
||||
throw MyError.illegalArgument
|
||||
}
|
||||
let type = myTypeArgs.toType()
|
||||
let maximumWriteLength32 = peripheral.maximumWriteValueLength(for: type)
|
||||
let maximumWriteLength = Int64(maximumWriteLength32)
|
||||
return maximumWriteLength
|
||||
}
|
||||
|
||||
func discoverGATT(myPeripheralKey: Int64, completion: @escaping (Result<Void, Error>) -> Void) {
|
||||
do {
|
||||
let peripheralKey = Int(myPeripheralKey)
|
||||
|
Reference in New Issue
Block a user