iOS 平台实现 (#2)

* 修复 UUID 创建失败的问题

* 移除 scanning 属性

* 临时提交

* CentralManager 开发 & 示例项目开发

* CentralManager 开发 & 示例项目开发

* android 插件生命周期监听

* 修改 API

* 示例程序开发

* 修改字体,添加 API,解决后台问题

* Central#connect API

* 蓝牙连接部分开发

* 蓝牙连接部分开发

* 解决一些问题

* 解决一些问题

* Connect API 优化

* 添加 API

* example 开发

* API 基本完成

* 消息重命名

* API 修改,Android 实现

* 删除多余代码

* 删除多余文件

* 解决 descriptor 自动生成报错的问题

* 还原 Kotlin 版本,广播处理代码迁移至 dart 端

* Kotlin 版本升至 1.5.20

* 解决特征值通知没有在主线程触发的问题,优化代码

* 引入哈希值,避免对象销毁后继续使用

* 使用下拉刷新代替搜索按钮

* 解决由于热重载和蓝牙关闭产生的问题

* 更新插件信息

* 更新 README 和 CHANGELOG

* 更新许可证

* 添加注释

* 添加注释,central 拆分

* dartfmt -w .

* flutter build ios --no-codesign

* API 重构

* 添加 connectable 属性

* Android 8.0 之前无法获取 connectable 属性

* 解决合并错误

* 解决连接时可能引发异常的一个问题,iOS 开发

* API 修改,TODO: iOS 哈希值为 64 位无法用 Int32 表示

* iOS 开发

* iOS 开发完成,使用 UUID 实现对象映射

* 更新版本记录和文档
This commit is contained in:
iAMD
2021-07-15 20:18:49 +08:00
committed by GitHub
parent aaed38e1eb
commit fc35f74488
63 changed files with 10278 additions and 5267 deletions

View File

@ -2,7 +2,7 @@ group 'dev.yanshouwang.bluetooth_low_energy'
version '1.0-SNAPSHOT'
buildscript {
ext.kotlin_version = '1.5.20'
ext.kotlin_version = '1.5.21'
repositories {
google()
mavenCentral()

View File

@ -42,16 +42,6 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
private const val CLIENT_CHARACTERISTIC_CONFIG = "00002902-0000-1000-8000-00805f9b34fb"
private const val BLUETOOTH_ADAPTER_STATE_UNKNOWN = -1
private const val NO_ERROR = 0
private const val INVALID_REQUEST = 1
private const val REQUEST_PERMISSION_FAILED = 2
private const val REQUEST_MTU_FAILED = 3
private const val DISCOVER_SERVICES_FAILED = 4
private const val READ_CHARACTERISTIC_FAILED = 5
private const val WRITE_CHARACTERISTIC_FAILED = 6
private const val NOTIFY_CHARACTERISTIC_FAILED = 7
private const val READ_DESCRIPTOR_FAILED = 8
private const val WRITE_DESCRIPTOR_FAILED = 9
private const val BLUETOOTH_ADAPTER_CLOSED = 10
private const val REQUEST_CODE = 443
}
@ -60,28 +50,32 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
private lateinit var context: Context
private var binding: ActivityPluginBinding? = null
private var sink: EventSink? = null
private var events: EventSink? = null
private val bluetoothAvailable by lazy { context.packageManager.hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE) }
private val bluetoothManager by lazy { context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager }
private val bluetoothAdapter by lazy { bluetoothManager.adapter }
private val handler by lazy { Handler(context.mainLooper) }
private val bluetoothState: BluetoothState
get() {
return if (bluetoothAvailable) bluetoothAdapter.state.messageState
else BluetoothState.UNSUPPORTED
}
private val bluetoothStateReceiver by lazy {
object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val oldState = intent!!.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, BLUETOOTH_ADAPTER_STATE_UNKNOWN).opened
val newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BLUETOOTH_ADAPTER_STATE_UNKNOWN).opened
// TODO: clear status when bluetooth closed.
val oldState = intent!!.getIntExtra(BluetoothAdapter.EXTRA_PREVIOUS_STATE, BLUETOOTH_ADAPTER_STATE_UNKNOWN).messageState
val newState = intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, BLUETOOTH_ADAPTER_STATE_UNKNOWN).messageState
if (newState == oldState) return
val closed = !newState
if (closed && scanning) scanning = false
if (newState != BluetoothState.POWERED_ON && scanning) scanning = false
val event = Message.newBuilder()
.setCategory(BLUETOOTH_STATE)
.setState(newState)
.build()
.toByteArray()
sink?.success(event)
events?.success(event)
}
}
}
@ -93,6 +87,7 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
private var scanCode = NO_ERROR
private var scanning = false
private val scanCallback by lazy {
object : ScanCallback() {
override fun onScanFailed(errorCode: Int) {
@ -103,122 +98,129 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
override fun onScanResult(callbackType: Int, result: ScanResult?) {
super.onScanResult(callbackType, result)
if (result == null) return
val address = result.device.address
val rssi = result.rssi
val record = result.scanRecord
val advertisements =
if (record == null) ByteString.EMPTY
else ByteString.copyFrom(record.bytes)
// TODO: We can't get connectable value before Android 8.0, here we just return true
// remove this useless code after the minSdkVersion set to 26 or later.
val connectable =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) result.isConnectable
else true
val builder = Discovery.newBuilder()
.setAddress(address)
.setRssi(rssi)
.setUuid(result.device.uuid)
.setRssi(result.rssi)
.setAdvertisements(advertisements)
.setConnectable(connectable)
val discovery = builder.build()
val event = Message.newBuilder()
.setCategory(CENTRAL_DISCOVERED)
.setDiscovery(discovery)
.build()
.toByteArray()
sink?.success(event)
events?.success(event)
}
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
super.onBatchScanResults(results)
if (results == null) return
for (result in results) {
val address = result.device.address
val rssi = result.rssi
val record = result.scanRecord
val advertisements =
if (record == null) ByteString.EMPTY
else ByteString.copyFrom(record.bytes)
// TODO: We can't get connectable value before Android 8.0, here we just return true
// remove this useless code after the minSdkVersion set to 26 or later.
val connectable =
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) result.isConnectable
else true
val builder = Discovery.newBuilder()
.setAddress(address)
.setRssi(rssi)
.setUuid(result.device.uuid)
.setRssi(result.rssi)
.setAdvertisements(advertisements)
.setConnectable(connectable)
val discovery = builder.build()
val event = Message.newBuilder()
.setCategory(CENTRAL_DISCOVERED)
.setDiscovery(discovery)
.build()
.toByteArray()
sink?.success(event)
events?.success(event)
}
}
}
}
private val gatts by lazy { mutableMapOf<String, BluetoothGatt>() }
private val connects by lazy { mutableMapOf<String, Result>() }
private val mtus by lazy { mutableMapOf<String, Int>() }
private val disconnects by lazy { mutableMapOf<String, Result>() }
private val characteristicReads by lazy { mutableMapOf<Int, Result>() }
private val characteristicWrites by lazy { mutableMapOf<Int, Result>() }
private val descriptorReads by lazy { mutableMapOf<Int, Result>() }
private val descriptorWrites by lazy { mutableMapOf<Int, Result>() }
private val nativeGATTs by lazy { mutableMapOf<String, NativeGATT>() }
private val connects by lazy { mutableMapOf<BluetoothGatt, Result>() }
private val maximumWriteLengths by lazy { mutableMapOf<BluetoothGatt, Int>() }
private val disconnects by lazy { mutableMapOf<BluetoothGatt, Result>() }
private val characteristicReads by lazy { mutableMapOf<BluetoothGattCharacteristic, Result>() }
private val characteristicWrites by lazy { mutableMapOf<BluetoothGattCharacteristic, Result>() }
private val descriptorReads by lazy { mutableMapOf<BluetoothGattDescriptor, Result>() }
private val descriptorWrites by lazy { mutableMapOf<BluetoothGattDescriptor, Result>() }
private val bluetoothGattCallback by lazy {
object : BluetoothGattCallback() {
override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
super.onConnectionStateChange(gatt, status, newState)
val address = gatt!!.device.address
when (status) {
BluetoothGatt.GATT_SUCCESS -> {
when (newState) {
BluetoothProfile.STATE_DISCONNECTED -> {
// Maybe disconnect succeed, connect failed, or connection lost when an adaptor closed event triggered.
gatts.remove(address)!!.close()
val disconnect = disconnects.remove(address)
if (disconnect != null) handler.post { disconnect.success() }
gatt!!.close()
val connect = connects.remove(gatt)
if (connect != null) handler.post { connect.error("GATT error with status: $status.", null, null) }
else {
val connect = connects.remove(address)
if (connect != null) handler.post { connect.error(BLUETOOTH_ADAPTER_CLOSED) }
val nativeGATT = nativeGATTs.entries.first { entry -> entry.value.value === gatt }
nativeGATTs.remove(nativeGATT.key)
val disconnect = disconnects.remove(gatt)
if (disconnect != null) handler.post { disconnect.success() }
else {
val id = gatt.hashCode()
val connectionLost = ConnectionLost.newBuilder()
.setId(id)
.setErrorCode(BLUETOOTH_ADAPTER_CLOSED)
val connectionLost = GattConnectionLost.newBuilder()
.setKey(nativeGATT.key)
.setError("GATT error with status: $status")
.build()
val event = Message.newBuilder()
.setCategory(GATT_CONNECTION_LOST)
.setConnectionLost(connectionLost)
.build()
.toByteArray()
handler.post { sink?.success(event) }
handler.post { events?.success(event) }
}
}
}
BluetoothProfile.STATE_CONNECTED -> {
// Must be connect succeed.
val requested = gatt.requestMtu(512)
if (!requested) {
gatts.remove(address)!!.close()
val connect = connects.remove(address)!!
handler.post { connect.error(REQUEST_MTU_FAILED) }
}
val requested = gatt!!.requestMtu(512)
if (!requested) gatt.disconnect()
}
else -> throw NotImplementedError() // should never be called.
}
}
else -> {
// Maybe connect failed, disconnect failed or connection lost when an adaptor closed event triggered.
gatts.remove(address)!!.close()
val connect = connects.remove(address)
if (connect != null) handler.post { connect.error(status) }
// Maybe connect failed, disconnect failed or connection lost.
gatt!!.close()
val connect = connects.remove(gatt)
if (connect != null) handler.post { connect.error("GATT error with status: $status", null, null) }
else {
val disconnect = disconnects.remove(address)
if (disconnect != null) handler.post { disconnect.error(status) }
val nativeGATT = nativeGATTs.entries.first { entry -> entry.value.value === gatt }
nativeGATTs.remove(nativeGATT.key)
val disconnect = disconnects.remove(gatt)
if (disconnect != null) handler.post { disconnect.error("GATT error with status: $status", null, null) }
else {
val id = gatt.hashCode()
val connectionLost = ConnectionLost.newBuilder()
.setId(id)
.setErrorCode(status)
val connectionLost = GattConnectionLost.newBuilder()
.setKey(nativeGATT.key)
.setError("GATT error with status: $status")
.build()
val event = Message.newBuilder()
.setCategory(GATT_CONNECTION_LOST)
.setConnectionLost(connectionLost)
.build()
.toByteArray()
handler.post { sink?.success(event) }
handler.post { events?.success(event) }
}
}
}
@ -227,107 +229,118 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
override fun onMtuChanged(gatt: BluetoothGatt?, mtu: Int, status: Int) {
super.onMtuChanged(gatt, mtu, status)
val address = gatt!!.device.address
val code = when (status) {
when (status) {
BluetoothGatt.GATT_SUCCESS -> {
val discovered = gatt.discoverServices()
if (discovered) {
mtus[address] = mtu
NO_ERROR
} else DISCOVER_SERVICES_FAILED
val discovered = gatt!!.discoverServices()
if (discovered) maximumWriteLengths[gatt] = mtu - 3
else gatt.disconnect()
}
else -> status
}
if (code != NO_ERROR) {
gatts.remove(address)!!.close()
val connect = connects.remove(address)!!
handler.post { connect.error(code) }
else -> gatt!!.disconnect()
}
}
override fun onServicesDiscovered(gatt: BluetoothGatt?, status: Int) {
super.onServicesDiscovered(gatt, status)
val address = gatt!!.device.address
val connect = connects.remove(address)!!
val mtu = mtus.remove(address)!!
val maximumWriteLength = maximumWriteLengths.remove(gatt)!!
when (status) {
BluetoothGatt.GATT_SUCCESS -> {
val id = gatt.hashCode()
val services = gatt.services.map { service ->
val serviceId = service.hashCode()
val serviceUUID = service.uuid.toString()
val characteristics = service.characteristics.map { characteristic ->
val characteristicId = characteristic.hashCode()
val characteristicUUID = characteristic.uuid.toString()
val properties = characteristic.properties
val canRead = properties and BluetoothGattCharacteristic.PROPERTY_READ != 0
val canWrite = properties and BluetoothGattCharacteristic.PROPERTY_WRITE != 0
val canWriteWithoutResponse = properties and BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE != 0
val canNotify = properties and BluetoothGattCharacteristic.PROPERTY_NOTIFY != 0
val descriptors = characteristic.descriptors.map { descriptor ->
val descriptorId = descriptor.hashCode()
val nativeServices = mutableMapOf<String, NativeGattService>()
val messageServices = mutableListOf<GattService>()
for (service in gatt!!.services) {
val nativeCharacteristics = mutableMapOf<String, NativeGattCharacteristic>()
val messageCharacteristics = mutableListOf<GattCharacteristic>()
for (characteristic in service.characteristics) {
val nativeDescriptors = mutableMapOf<String, NativeGattDescriptor>()
val messageDescriptors = mutableListOf<GattDescriptor>()
for (descriptor in characteristic.descriptors) {
// Add native descriptor.
val nativeDescriptor = NativeGattDescriptor(descriptor)
nativeDescriptors[nativeDescriptor.key] = nativeDescriptor
// Add message descriptor.
val descriptorUUID = descriptor.uuid.toString()
GattDescriptor.newBuilder()
.setId(descriptorId)
val messageDescriptor = GattDescriptor.newBuilder()
.setKey(nativeDescriptor.key)
.setUuid(descriptorUUID)
.build()
messageDescriptors.add(messageDescriptor)
}
GattCharacteristic.newBuilder()
.setId(characteristicId)
// Add native characteristic.
val nativeCharacteristic = NativeGattCharacteristic(characteristic, nativeDescriptors)
nativeCharacteristics[nativeCharacteristic.key] = nativeCharacteristic
// Add message characteristic.
val characteristicUUID = characteristic.uuid.toString()
val canRead = characteristic.properties and BluetoothGattCharacteristic.PROPERTY_READ != 0
val canWrite = characteristic.properties and BluetoothGattCharacteristic.PROPERTY_WRITE != 0
val canWriteWithoutResponse = characteristic.properties and BluetoothGattCharacteristic.PROPERTY_WRITE_NO_RESPONSE != 0
val canNotify = characteristic.properties and BluetoothGattCharacteristic.PROPERTY_NOTIFY != 0
val messageCharacteristic = GattCharacteristic.newBuilder()
.setKey(nativeCharacteristic.key)
.setUuid(characteristicUUID)
.setCanRead(canRead)
.setCanWrite(canWrite)
.setCanWriteWithoutResponse(canWriteWithoutResponse)
.setCanNotify(canNotify)
.addAllDescriptors(descriptors)
.addAllDescriptors(messageDescriptors)
.build()
messageCharacteristics.add(messageCharacteristic)
}
GattService.newBuilder()
.setId(serviceId)
// Add native service.
val nativeService = NativeGattService(service, nativeCharacteristics)
nativeServices[nativeService.key] = nativeService
// Add message service.
val serviceUUID = service.uuid.toString()
val messageService = GattService.newBuilder()
.setKey(nativeService.key)
.setUuid(serviceUUID)
.addAllCharacteristics(characteristics).build()
.addAllCharacteristics(messageCharacteristics)
.build()
messageServices.add(messageService)
}
// Add native gatt.
val nativeGATT = NativeGATT(gatt, nativeServices)
nativeGATTs[nativeGATT.key] = nativeGATT
// Add message gatt.
val reply = GATT.newBuilder()
.setId(id)
.setMtu(mtu)
.addAllServices(services)
.setKey(nativeGATT.key)
.setMaximumWriteLength(maximumWriteLength)
.addAllServices(messageServices)
.build()
.toByteArray()
val connect = connects.remove(gatt)!!
handler.post { connect.success(reply) }
}
else -> {
gatts.remove(address)!!.close()
handler.post { connect.error(status) }
}
else -> gatt!!.disconnect()
}
}
override fun onCharacteristicRead(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?, status: Int) {
super.onCharacteristicRead(gatt, characteristic, status)
val key = characteristic!!.hashCode()
val read = characteristicReads.remove(key)!!
val read = characteristicReads.remove(characteristic)!!
when (status) {
BluetoothGatt.GATT_SUCCESS -> handler.post { read.success(characteristic.value) }
else -> handler.post { read.error(status) }
BluetoothGatt.GATT_SUCCESS -> handler.post { read.success(characteristic!!.value) }
else -> handler.post { read.error("GATT error with status: $status", null, null) }
}
}
override fun onCharacteristicWrite(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?, status: Int) {
super.onCharacteristicWrite(gatt, characteristic, status)
val key = characteristic!!.hashCode()
val write = characteristicWrites.remove(key)!!
val write = characteristicWrites.remove(characteristic)!!
when (status) {
BluetoothGatt.GATT_SUCCESS -> handler.post { write.success() }
else -> handler.post { write.error(status) }
else -> handler.post { write.error("GATT error with status: $status", null, null) }
}
}
override fun onCharacteristicChanged(gatt: BluetoothGatt?, characteristic: BluetoothGattCharacteristic?) {
super.onCharacteristicChanged(gatt, characteristic)
val id = characteristic!!.hashCode()
val value = ByteString.copyFrom(characteristic.value)
val nativeGATT = nativeGATTs.values.first { entry -> entry.value === gatt }
val nativeService = nativeGATT.services.values.first { entry -> entry.value === characteristic!!.service }
val nativeCharacteristic = nativeService.characteristics.values.first { entry -> entry.value === characteristic }
val value = ByteString.copyFrom(characteristic!!.value)
val characteristicValue = GattCharacteristicValue.newBuilder()
.setId(id)
.setGattKey(nativeGATT.key)
.setServiceKey(nativeService.key)
.setKey(nativeCharacteristic.key)
.setValue(value)
.build()
val event = Message.newBuilder()
@ -335,26 +348,24 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
.setCharacteristicValue(characteristicValue)
.build()
.toByteArray()
handler.post { sink?.success(event) }
handler.post { events?.success(event) }
}
override fun onDescriptorRead(gatt: BluetoothGatt?, descriptor: BluetoothGattDescriptor?, status: Int) {
super.onDescriptorRead(gatt, descriptor, status)
val key = descriptor!!.hashCode()
val read = descriptorReads.remove(key)!!
val read = descriptorReads.remove(descriptor)!!
when (status) {
BluetoothGatt.GATT_SUCCESS -> handler.post { read.success(descriptor.value) }
else -> handler.post { read.error(status) }
BluetoothGatt.GATT_SUCCESS -> handler.post { read.success(descriptor!!.value) }
else -> handler.post { read.error("GATT error with status: $status", null, null) }
}
}
override fun onDescriptorWrite(gatt: BluetoothGatt?, descriptor: BluetoothGattDescriptor?, status: Int) {
super.onDescriptorWrite(gatt, descriptor, status)
val key = descriptor!!.hashCode()
val write = descriptorWrites.remove(key)!!
val write = descriptorWrites.remove(descriptor)!!
when (status) {
BluetoothGatt.GATT_SUCCESS -> handler.post { write.success() }
else -> handler.post { write.error(status) }
else -> handler.post { write.error("GATT error with status: $status", null, null) }
}
}
}
@ -400,8 +411,7 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
override fun onDetachedFromEngine(@NonNull binding: FlutterPlugin.FlutterPluginBinding) {
// Clear connections.
for (gatt in gatts.values) gatt.close()
gatts.clear()
for (nativeGATT in nativeGATTs.values) nativeGATT.value.disconnect()
// Stop scan.
if (scanning) stopScan()
// Unregister bluetooth adapter state receiver.
@ -411,37 +421,30 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
}
override fun onMethodCall(@NonNull call: MethodCall, @NonNull result: Result) {
val category = call.category
if (category != BLUETOOTH_AVAILABLE && category != BLUETOOTH_STATE && !bluetoothAdapter.state.opened) result.error(BLUETOOTH_ADAPTER_CLOSED)
else when (category) {
BLUETOOTH_AVAILABLE -> result.success(bluetoothAvailable)
BLUETOOTH_STATE -> result.success(bluetoothAdapter.state.opened)
val data = call.arguments<ByteArray>()
val command = Message.parseFrom(data)
when (command.category!!) {
BLUETOOTH_STATE -> result.success(bluetoothState.number)
CENTRAL_START_DISCOVERY -> {
val startDiscovery = Runnable {
val services = command.startDiscoveryArguments.servicesList
val startScanHandler: StartScanHandler = { code ->
when (code) {
NO_ERROR -> result.success()
else -> result.error("Discovery start failed with code: $code", null, null)
}
}
startScan(services, startScanHandler)
}
when {
requestPermissionsHandler != null -> result.error(INVALID_REQUEST)
hasPermission -> startDiscovery.run()
else -> {
val startDiscovery = Runnable {
val data = call.arguments<ByteArray>()
val arguments = StartDiscoveryArguments.parseFrom(data)
val startScanHandler: StartScanHandler = { code ->
when (code) {
NO_ERROR -> result.success()
else -> result.error(code)
}
}
startScan(arguments.servicesList, startScanHandler)
}
when {
hasPermission -> startDiscovery.run()
else -> {
requestPermissionsHandler = { granted ->
if (granted) startDiscovery.run()
else result.error(REQUEST_PERMISSION_FAILED)
}
val permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
ActivityCompat.requestPermissions(binding!!.activity, permissions, REQUEST_CODE)
}
requestPermissionsHandler = { granted ->
if (granted) startDiscovery.run()
else result.error("Discovery start failed because `ACCESS_FINE_LOCATION` was denied by user.", null, null)
}
val permissions = arrayOf(Manifest.permission.ACCESS_FINE_LOCATION)
ActivityCompat.requestPermissions(binding!!.activity, permissions, REQUEST_CODE)
}
}
}
@ -449,176 +452,92 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
stopScan()
result.success()
}
CENTRAL_DISCOVERED -> result.notImplemented()
CENTRAL_CONNECT -> {
val data = call.arguments<ByteArray>()
val arguments = ConnectArguments.parseFrom(data)
val address = arguments.address
val connect = connects[address]
var gatt = gatts[address]
if (connect != null || gatt != null) {
result.error(INVALID_REQUEST)
} else {
val device = bluetoothAdapter.getRemoteDevice(address)
gatt = when {
// Use TRANSPORT_LE to avoid none flag device on Android 23 or later.
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> device.connectGatt(context, false, bluetoothGattCallback, BluetoothDevice.TRANSPORT_LE)
else -> device.connectGatt(context, false, bluetoothGattCallback)
}
connects[address] = result
gatts[address] = gatt
val device = bluetoothAdapter.getRemoteDevice(command.connectArguments.uuid.address)
val gatt = when {
// Use TRANSPORT_LE to avoid none flag device on Android 23 or later.
Build.VERSION.SDK_INT >= Build.VERSION_CODES.M -> device.connectGatt(context, false, bluetoothGattCallback, BluetoothDevice.TRANSPORT_LE)
else -> device.connectGatt(context, false, bluetoothGattCallback)
}
connects[gatt] = result
}
GATT_DISCONNECT -> {
val data = call.arguments<ByteArray>()
val arguments = GattDisconnectArguments.parseFrom(data)
val address = arguments.address
val disconnect = disconnects[address]
val gatt = gatts[address]
if (disconnect != null || gatt == null || gatt.hashCode() != arguments.id) {
result.error(INVALID_REQUEST)
} else {
disconnects[address] = result
gatt.disconnect()
}
val nativeGATT = nativeGATTs[command.disconnectArguments.key]!!
disconnects[nativeGATT.value] = result
nativeGATT.value.disconnect()
}
GATT_CONNECTION_LOST -> result.notImplemented()
GATT_CHARACTERISTIC_READ -> {
val data = call.arguments<ByteArray>()
val arguments = GattCharacteristicReadArguments.parseFrom(data)
val gatt = gatts[arguments.address]
if (gatt == null) result.error(INVALID_REQUEST)
else {
val serviceUUID = UUID.fromString(arguments.serviceUuid)
val service = gatt.getService(serviceUUID)
val uuid = UUID.fromString(arguments.uuid)
val characteristic = service.getCharacteristic(uuid)
val id = characteristic.hashCode()
val characteristicRead = characteristicReads[id]
if (characteristicRead != null || id != arguments.id) result.error(INVALID_REQUEST)
else {
val failed = !gatt.readCharacteristic(characteristic)
if (failed) result.error(READ_CHARACTERISTIC_FAILED)
else characteristicReads[id] = result
}
}
val nativeGATT = nativeGATTs[command.characteristicReadArguments.gattKey]!!
val nativeService = nativeGATT.services[command.characteristicReadArguments.serviceKey]!!
val nativeCharacteristic = nativeService.characteristics[command.characteristicReadArguments.key]!!
val read = nativeGATT.value.readCharacteristic(nativeCharacteristic.value)
if (read) characteristicReads[nativeCharacteristic.value] = result
else result.error("Characteristic read failed.", null, null)
}
GATT_CHARACTERISTIC_WRITE -> {
val data = call.arguments<ByteArray>()
val arguments = GattCharacteristicWriteArguments.parseFrom(data)
val gatt = gatts[arguments.address]
if (gatt == null) result.error(INVALID_REQUEST)
else {
val serviceUUID = UUID.fromString(arguments.serviceUuid)
val service = gatt.getService(serviceUUID)
val uuid = UUID.fromString(arguments.uuid)
val characteristic = service.getCharacteristic(uuid)
val id = characteristic.hashCode()
val characteristicWrite = characteristicWrites[id]
if (characteristicWrite != null || id != arguments.id) result.error(INVALID_REQUEST)
else {
characteristic.value = arguments.value.toByteArray()
characteristic.writeType =
if (arguments.withoutResponse) BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
else BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
val failed = !gatt.writeCharacteristic(characteristic)
if (failed) result.error(WRITE_CHARACTERISTIC_FAILED)
else characteristicWrites[id] = result
}
}
val nativeGATT = nativeGATTs[command.characteristicWriteArguments.gattKey]!!
val nativeService = nativeGATT.services[command.characteristicWriteArguments.serviceKey]!!
val nativeCharacteristic = nativeService.characteristics[command.characteristicWriteArguments.key]!!
nativeCharacteristic.value.writeType =
if (command.characteristicWriteArguments.withoutResponse) BluetoothGattCharacteristic.WRITE_TYPE_NO_RESPONSE
else BluetoothGattCharacteristic.WRITE_TYPE_DEFAULT
nativeCharacteristic.value.value = command.characteristicWriteArguments.value.toByteArray()
val written = nativeGATT.value.writeCharacteristic(nativeCharacteristic.value)
if (written) characteristicWrites[nativeCharacteristic.value] = result
else result.error("Characteristic write failed.", null, null)
}
GATT_CHARACTERISTIC_NOTIFY -> {
val data = call.arguments<ByteArray>()
val arguments = GattCharacteristicNotifyArguments.parseFrom(data)
val gatt = gatts[arguments.address]
if (gatt == null) result.error(INVALID_REQUEST)
else {
val serviceUUID = UUID.fromString(arguments.serviceUuid)
val service = gatt.getService(serviceUUID)
val uuid = UUID.fromString(arguments.uuid)
val characteristic = service.getCharacteristic(uuid)
val id = characteristic.hashCode()
val descriptorUUID = UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG)
val descriptor = characteristic.getDescriptor(descriptorUUID)
val descriptorId = descriptor.hashCode()
val descriptorWrite = descriptorWrites[descriptorId]
if (descriptorWrite != null || id != arguments.id) result.error(INVALID_REQUEST)
else {
var failed = !gatt.setCharacteristicNotification(characteristic, arguments.state)
if (failed) result.error(NOTIFY_CHARACTERISTIC_FAILED)
else {
descriptor.value =
if (arguments.state) BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
else BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE
failed = !gatt.writeDescriptor(descriptor)
if (failed) result.error(WRITE_DESCRIPTOR_FAILED)
else descriptorWrites[descriptorId] = result
}
}
}
val nativeGATT = nativeGATTs[command.characteristicNotifyArguments.gattKey]!!
val nativeService = nativeGATT.services[command.characteristicNotifyArguments.serviceKey]!!
val nativeCharacteristic = nativeService.characteristics[command.characteristicNotifyArguments.key]!!
val descriptorUUID = UUID.fromString(CLIENT_CHARACTERISTIC_CONFIG)
val descriptor = nativeCharacteristic.value.getDescriptor(descriptorUUID)
val notified = nativeGATT.value.setCharacteristicNotification(nativeCharacteristic.value, command.characteristicNotifyArguments.state)
if (notified) {
descriptor.value =
if (command.characteristicNotifyArguments.state) BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
else BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE
val written = nativeGATT.value.writeDescriptor(descriptor)
if (written) descriptorWrites[descriptor] = result
else result.error("Client characteristic config descriptor write failed.", null, null)
} else result.error("Characteristic Notify failed.", null, null)
}
GATT_DESCRIPTOR_READ -> {
val data = call.arguments<ByteArray>()
val arguments = GattDescriptorReadArguments.parseFrom(data)
val gatt = gatts[arguments.address]
if (gatt == null) result.error(INVALID_REQUEST)
else {
val serviceUUID = UUID.fromString(arguments.serviceUuid)
val service = gatt.getService(serviceUUID)
val characteristicUUID = UUID.fromString(arguments.characteristicUuid)
val characteristic = service.getCharacteristic(characteristicUUID)
val uuid = UUID.fromString(arguments.uuid)
val descriptor = characteristic.getDescriptor(uuid)
val id = descriptor.hashCode()
val descriptorRead = descriptorReads[id]
if (descriptorRead != null || id != arguments.id) result.error(INVALID_REQUEST)
else {
val failed = !gatt.readDescriptor(descriptor)
if (failed) result.error(READ_DESCRIPTOR_FAILED)
else descriptorReads[id] = result
}
}
val nativeGATT = nativeGATTs[command.descriptorReadArguments.gattKey]!!
val nativeService = nativeGATT.services[command.descriptorReadArguments.serviceKey]!!
val nativeCharacteristic = nativeService.characteristics[command.descriptorReadArguments.characteristicKey]!!
val nativeDescriptor = nativeCharacteristic.descriptors[command.descriptorReadArguments.key]!!
val read = nativeGATT.value.readDescriptor(nativeDescriptor.value)
if (read) descriptorReads[nativeDescriptor.value] = result
else result.error("Descriptor read failed.", null, null)
}
GATT_DESCRIPTOR_WRITE -> {
val data = call.arguments<ByteArray>()
val arguments = GattDescriptorWriteArguments.parseFrom(data)
val gatt = gatts[arguments.address]
if (gatt == null) result.error(INVALID_REQUEST)
else {
val serviceUUID = UUID.fromString(arguments.serviceUuid)
val service = gatt.getService(serviceUUID)
val characteristicUUID = UUID.fromString(arguments.characteristicUuid)
val characteristic = service.getCharacteristic(characteristicUUID)
val uuid = UUID.fromString(arguments.uuid)
val descriptor = characteristic.getDescriptor(uuid)
val id = descriptor.hashCode()
val descriptorWrite = descriptorWrites[id]
if (descriptorWrite != null || id != arguments.id) result.error(INVALID_REQUEST)
else {
val failed = !gatt.writeDescriptor(descriptor)
if (failed) result.error(WRITE_DESCRIPTOR_FAILED)
else descriptorWrites[id] = result
}
}
val nativeGATT = nativeGATTs[command.descriptorWriteArguments.gattKey]!!
val nativeService = nativeGATT.services[command.descriptorWriteArguments.serviceKey]!!
val nativeCharacteristic = nativeService.characteristics[command.descriptorWriteArguments.characteristicKey]!!
val nativeDescriptor = nativeCharacteristic.descriptors[command.descriptorWriteArguments.key]!!
nativeDescriptor.value.value = command.descriptorWriteArguments.value.toByteArray()
val written = nativeGATT.value.writeDescriptor(nativeDescriptor.value)
if (written) descriptorWrites[nativeDescriptor.value] = result
else result.error("Descriptor write failed.", null, null)
}
UNRECOGNIZED -> result.notImplemented()
else -> result.notImplemented()
}
}
override fun onListen(arguments: Any?, sink: EventSink?) {
override fun onListen(arguments: Any?, events: EventSink?) {
Log.d(TAG, "onListen")
this.sink = sink
this.events = events
}
override fun onCancel(arguments: Any?) {
Log.d(TAG, "onCancel")
// This must be a hot reload for now, clear all status here.
// Clear connections.
for (gatt in gatts.values) gatt.close()
gatts.clear()
for (nativeGATT in nativeGATTs.values) nativeGATT.value.disconnect()
// Stop scan.
if (scanning) stopScan()
sink = null
events = null
}
override fun onAttachedToActivity(binding: ActivityPluginBinding) {
@ -639,11 +558,7 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
onDetachedFromActivity()
}
override fun onRequestPermissionsResult(
requestCode: Int,
permissions: Array<out String>?,
grantResults: IntArray?
): Boolean {
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>?, grantResults: IntArray?): Boolean {
return when {
requestCode != REQUEST_CODE || requestPermissionsHandler == null -> false
else -> {
@ -657,25 +572,28 @@ class BluetoothLowEnergyPlugin : FlutterPlugin, MethodCallHandler, StreamHandler
}
}
val Any.TAG: String
get() = this::class.java.simpleName
fun Result.success() {
success(null)
}
fun Result.error(code: Int, message: String? = null, details: String? = null) {
error("$code", message, details)
}
val Any.TAG: String
get() = this::class.java.simpleName
val MethodCall.category: MessageCategory
get() = valueOf(method)
val Int.opened: Boolean
val Int.messageState: BluetoothState
get() = when (this) {
BluetoothAdapter.STATE_OFF -> false
BluetoothAdapter.STATE_TURNING_ON -> false
BluetoothAdapter.STATE_ON -> true
BluetoothAdapter.STATE_TURNING_OFF -> true
else -> false
}
BluetoothAdapter.STATE_OFF -> BluetoothState.POWERED_OFF
BluetoothAdapter.STATE_TURNING_ON -> BluetoothState.POWERED_OFF
BluetoothAdapter.STATE_ON -> BluetoothState.POWERED_ON
BluetoothAdapter.STATE_TURNING_OFF -> BluetoothState.POWERED_ON
else -> BluetoothState.UNRECOGNIZED
}
val BluetoothDevice.uuid: String
get() {
val node = address.filter { char -> char != ':' }.lowercase()
// We don't known the timestamp of the bluetooth device, use nil UUID as prefix.
return "00000000-0000-0000-0000-$node"
}
val String.address: String
get() = takeLast(12).chunked(2).joinToString(":").uppercase()

View File

@ -23,20 +23,20 @@ object ConnectArgumentsKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectArguments = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string uuid = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var uuid: kotlin.String
@JvmName("getUuid")
get() = _builder.getUuid()
@JvmName("setUuid")
set(value) {
_builder.setAddress(value)
_builder.setUuid(value)
}
/**
* <code>string address = 1;</code>
* <code>string uuid = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
fun clearUuid() {
_builder.clearUuid()
}
}
}

View File

@ -1,62 +0,0 @@
//Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package dev.yanshouwang.bluetooth_low_energy;
@kotlin.jvm.JvmSynthetic
inline fun connectionLost(block: dev.yanshouwang.bluetooth_low_energy.ConnectionLostKt.Dsl.() -> Unit): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost =
dev.yanshouwang.bluetooth_low_energy.ConnectionLostKt.Dsl._create(dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost.newBuilder()).apply { block() }._build()
object ConnectionLostKt {
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
@com.google.protobuf.kotlin.ProtoDslMarker
class Dsl private constructor(
@kotlin.jvm.JvmField private val _builder: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost.Builder
) {
companion object {
@kotlin.jvm.JvmSynthetic
@kotlin.PublishedApi
internal fun _create(builder: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost.Builder): Dsl = Dsl(builder)
}
@kotlin.jvm.JvmSynthetic
@kotlin.PublishedApi
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost = _builder.build()
/**
* <code>int32 id = 1;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
set(value) {
_builder.setId(value)
}
/**
* <code>int32 id = 1;</code>
*/
fun clearId() {
_builder.clearId()
}
/**
* <code>int32 error_code = 2;</code>
*/
var errorCode: kotlin.Int
@JvmName("getErrorCode")
get() = _builder.getErrorCode()
@JvmName("setErrorCode")
set(value) {
_builder.setErrorCode(value)
}
/**
* <code>int32 error_code = 2;</code>
*/
fun clearErrorCode() {
_builder.clearErrorCode()
}
}
}
@kotlin.jvm.JvmSynthetic
inline fun dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost.copy(block: dev.yanshouwang.bluetooth_low_energy.ConnectionLostKt.Dsl.() -> Unit): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost =
dev.yanshouwang.bluetooth_low_energy.ConnectionLostKt.Dsl._create(this.toBuilder()).apply { block() }._build()

View File

@ -23,20 +23,20 @@ object DiscoveryKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.Discovery = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string uuid = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var uuid: kotlin.String
@JvmName("getUuid")
get() = _builder.getUuid()
@JvmName("setUuid")
set(value) {
_builder.setAddress(value)
_builder.setUuid(value)
}
/**
* <code>string address = 1;</code>
* <code>string uuid = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
fun clearUuid() {
_builder.clearUuid()
}
/**
@ -72,6 +72,23 @@ object DiscoveryKt {
fun clearAdvertisements() {
_builder.clearAdvertisements()
}
/**
* <code>bool connectable = 4;</code>
*/
var connectable: kotlin.Boolean
@JvmName("getConnectable")
get() = _builder.getConnectable()
@JvmName("setConnectable")
set(value) {
_builder.setConnectable(value)
}
/**
* <code>bool connectable = 4;</code>
*/
fun clearConnectable() {
_builder.clearConnectable()
}
}
}
@kotlin.jvm.JvmSynthetic

View File

@ -23,37 +23,37 @@ object GATTKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GATT = _builder.build()
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setId(value)
_builder.setKey(value)
}
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
fun clearId() {
_builder.clearId()
fun clearKey() {
_builder.clearKey()
}
/**
* <code>int32 mtu = 2;</code>
* <code>int32 maximumWriteLength = 2;</code>
*/
var mtu: kotlin.Int
@JvmName("getMtu")
get() = _builder.getMtu()
@JvmName("setMtu")
var maximumWriteLength: kotlin.Int
@JvmName("getMaximumWriteLength")
get() = _builder.getMaximumWriteLength()
@JvmName("setMaximumWriteLength")
set(value) {
_builder.setMtu(value)
_builder.setMaximumWriteLength(value)
}
/**
* <code>int32 mtu = 2;</code>
* <code>int32 maximumWriteLength = 2;</code>
*/
fun clearMtu() {
_builder.clearMtu()
fun clearMaximumWriteLength() {
_builder.clearMaximumWriteLength()
}
/**

View File

@ -23,20 +23,20 @@ object GattCharacteristicKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristic = _builder.build()
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setId(value)
_builder.setKey(value)
}
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
fun clearId() {
_builder.clearId()
fun clearKey() {
_builder.clearKey()
}
/**
@ -57,70 +57,7 @@ object GattCharacteristicKt {
}
/**
* An uninstantiable, behaviorless type to represent the field in
* generics.
*/
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
class DescriptorsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 3;</code>
*/
val descriptors: com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>
@kotlin.jvm.JvmSynthetic
get() = com.google.protobuf.kotlin.DslList(
_builder.getDescriptorsList()
)
/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 3;</code>
* @param value The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("addDescriptors")
fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.add(value: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor) {
_builder.addDescriptors(value)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 3;</code>
* @param value The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("plusAssignDescriptors")
inline operator fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.plusAssign(value: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor) {
add(value)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 3;</code>
* @param values The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("addAllDescriptors")
fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.addAll(values: kotlin.collections.Iterable<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor>) {
_builder.addAllDescriptors(values)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 3;</code>
* @param values The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("plusAssignAllDescriptors")
inline operator fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.plusAssign(values: kotlin.collections.Iterable<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor>) {
addAll(values)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 3;</code>
* @param index The index to set the value at.
* @param value The descriptors to set.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("setDescriptors")
operator fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.set(index: kotlin.Int, value: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor) {
_builder.setDescriptors(index, value)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 3;</code>
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("clearDescriptors")
fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.clear() {
_builder.clearDescriptors()
}
/**
* <code>bool canRead = 4;</code>
* <code>bool canRead = 3;</code>
*/
var canRead: kotlin.Boolean
@JvmName("getCanRead")
@ -130,14 +67,14 @@ object GattCharacteristicKt {
_builder.setCanRead(value)
}
/**
* <code>bool canRead = 4;</code>
* <code>bool canRead = 3;</code>
*/
fun clearCanRead() {
_builder.clearCanRead()
}
/**
* <code>bool canWrite = 5;</code>
* <code>bool canWrite = 4;</code>
*/
var canWrite: kotlin.Boolean
@JvmName("getCanWrite")
@ -147,14 +84,14 @@ object GattCharacteristicKt {
_builder.setCanWrite(value)
}
/**
* <code>bool canWrite = 5;</code>
* <code>bool canWrite = 4;</code>
*/
fun clearCanWrite() {
_builder.clearCanWrite()
}
/**
* <code>bool canWriteWithoutResponse = 6;</code>
* <code>bool canWriteWithoutResponse = 5;</code>
*/
var canWriteWithoutResponse: kotlin.Boolean
@JvmName("getCanWriteWithoutResponse")
@ -164,14 +101,14 @@ object GattCharacteristicKt {
_builder.setCanWriteWithoutResponse(value)
}
/**
* <code>bool canWriteWithoutResponse = 6;</code>
* <code>bool canWriteWithoutResponse = 5;</code>
*/
fun clearCanWriteWithoutResponse() {
_builder.clearCanWriteWithoutResponse()
}
/**
* <code>bool canNotify = 7;</code>
* <code>bool canNotify = 6;</code>
*/
var canNotify: kotlin.Boolean
@JvmName("getCanNotify")
@ -181,12 +118,75 @@ object GattCharacteristicKt {
_builder.setCanNotify(value)
}
/**
* <code>bool canNotify = 7;</code>
* <code>bool canNotify = 6;</code>
*/
fun clearCanNotify() {
_builder.clearCanNotify()
}
}
/**
* An uninstantiable, behaviorless type to represent the field in
* generics.
*/
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
class DescriptorsProxy private constructor() : com.google.protobuf.kotlin.DslProxy()
/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 7;</code>
*/
val descriptors: com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>
@kotlin.jvm.JvmSynthetic
get() = com.google.protobuf.kotlin.DslList(
_builder.getDescriptorsList()
)
/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 7;</code>
* @param value The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("addDescriptors")
fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.add(value: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor) {
_builder.addDescriptors(value)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 7;</code>
* @param value The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("plusAssignDescriptors")
inline operator fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.plusAssign(value: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor) {
add(value)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 7;</code>
* @param values The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("addAllDescriptors")
fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.addAll(values: kotlin.collections.Iterable<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor>) {
_builder.addAllDescriptors(values)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 7;</code>
* @param values The descriptors to add.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("plusAssignAllDescriptors")
inline operator fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.plusAssign(values: kotlin.collections.Iterable<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor>) {
addAll(values)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 7;</code>
* @param index The index to set the value at.
* @param value The descriptors to set.
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("setDescriptors")
operator fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.set(index: kotlin.Int, value: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor) {
_builder.setDescriptors(index, value)
}/**
* <code>repeated .dev.yanshouwang.bluetooth_low_energy.GattDescriptor descriptors = 7;</code>
*/
@kotlin.jvm.JvmSynthetic
@kotlin.jvm.JvmName("clearDescriptors")
fun com.google.protobuf.kotlin.DslList<dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor, DescriptorsProxy>.clear() {
_builder.clearDescriptors()
}}
}
@kotlin.jvm.JvmSynthetic
inline fun dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristic.copy(block: dev.yanshouwang.bluetooth_low_energy.GattCharacteristicKt.Dsl.() -> Unit): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristic =

View File

@ -23,75 +23,58 @@ object GattCharacteristicNotifyArgumentsKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicNotifyArguments = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var gattKey: kotlin.String
@JvmName("getGattKey")
get() = _builder.getGattKey()
@JvmName("setGattKey")
set(value) {
_builder.setAddress(value)
_builder.setGattKey(value)
}
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
fun clearGattKey() {
_builder.clearGattKey()
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
var serviceUuid: kotlin.String
@JvmName("getServiceUuid")
get() = _builder.getServiceUuid()
@JvmName("setServiceUuid")
var serviceKey: kotlin.String
@JvmName("getServiceKey")
get() = _builder.getServiceKey()
@JvmName("setServiceKey")
set(value) {
_builder.setServiceUuid(value)
_builder.setServiceKey(value)
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
fun clearServiceUuid() {
_builder.clearServiceUuid()
fun clearServiceKey() {
_builder.clearServiceKey()
}
/**
* <code>string uuid = 3;</code>
* <code>string key = 3;</code>
*/
var uuid: kotlin.String
@JvmName("getUuid")
get() = _builder.getUuid()
@JvmName("setUuid")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setUuid(value)
_builder.setKey(value)
}
/**
* <code>string uuid = 3;</code>
* <code>string key = 3;</code>
*/
fun clearUuid() {
_builder.clearUuid()
fun clearKey() {
_builder.clearKey()
}
/**
* <code>int32 id = 4;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
set(value) {
_builder.setId(value)
}
/**
* <code>int32 id = 4;</code>
*/
fun clearId() {
_builder.clearId()
}
/**
* <code>bool state = 5;</code>
* <code>bool state = 4;</code>
*/
var state: kotlin.Boolean
@JvmName("getState")
@ -101,7 +84,7 @@ object GattCharacteristicNotifyArgumentsKt {
_builder.setState(value)
}
/**
* <code>bool state = 5;</code>
* <code>bool state = 4;</code>
*/
fun clearState() {
_builder.clearState()

View File

@ -23,71 +23,54 @@ object GattCharacteristicReadArgumentsKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicReadArguments = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var gattKey: kotlin.String
@JvmName("getGattKey")
get() = _builder.getGattKey()
@JvmName("setGattKey")
set(value) {
_builder.setAddress(value)
_builder.setGattKey(value)
}
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
fun clearGattKey() {
_builder.clearGattKey()
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
var serviceUuid: kotlin.String
@JvmName("getServiceUuid")
get() = _builder.getServiceUuid()
@JvmName("setServiceUuid")
var serviceKey: kotlin.String
@JvmName("getServiceKey")
get() = _builder.getServiceKey()
@JvmName("setServiceKey")
set(value) {
_builder.setServiceUuid(value)
_builder.setServiceKey(value)
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
fun clearServiceUuid() {
_builder.clearServiceUuid()
fun clearServiceKey() {
_builder.clearServiceKey()
}
/**
* <code>string uuid = 3;</code>
* <code>string key = 3;</code>
*/
var uuid: kotlin.String
@JvmName("getUuid")
get() = _builder.getUuid()
@JvmName("setUuid")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setUuid(value)
_builder.setKey(value)
}
/**
* <code>string uuid = 3;</code>
* <code>string key = 3;</code>
*/
fun clearUuid() {
_builder.clearUuid()
}
/**
* <code>int32 id = 4;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
set(value) {
_builder.setId(value)
}
/**
* <code>int32 id = 4;</code>
*/
fun clearId() {
_builder.clearId()
fun clearKey() {
_builder.clearKey()
}
}
}

View File

@ -23,20 +23,54 @@ object GattCharacteristicValueKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicValue = _builder.build()
/**
* <code>int32 id = 3;</code>
* <code>string gatt_key = 1;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
var gattKey: kotlin.String
@JvmName("getGattKey")
get() = _builder.getGattKey()
@JvmName("setGattKey")
set(value) {
_builder.setId(value)
_builder.setGattKey(value)
}
/**
* <code>int32 id = 3;</code>
* <code>string gatt_key = 1;</code>
*/
fun clearId() {
_builder.clearId()
fun clearGattKey() {
_builder.clearGattKey()
}
/**
* <code>string service_key = 2;</code>
*/
var serviceKey: kotlin.String
@JvmName("getServiceKey")
get() = _builder.getServiceKey()
@JvmName("setServiceKey")
set(value) {
_builder.setServiceKey(value)
}
/**
* <code>string service_key = 2;</code>
*/
fun clearServiceKey() {
_builder.clearServiceKey()
}
/**
* <code>string key = 3;</code>
*/
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setKey(value)
}
/**
* <code>string key = 3;</code>
*/
fun clearKey() {
_builder.clearKey()
}
/**

View File

@ -23,75 +23,58 @@ object GattCharacteristicWriteArgumentsKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicWriteArguments = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var gattKey: kotlin.String
@JvmName("getGattKey")
get() = _builder.getGattKey()
@JvmName("setGattKey")
set(value) {
_builder.setAddress(value)
_builder.setGattKey(value)
}
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
fun clearGattKey() {
_builder.clearGattKey()
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
var serviceUuid: kotlin.String
@JvmName("getServiceUuid")
get() = _builder.getServiceUuid()
@JvmName("setServiceUuid")
var serviceKey: kotlin.String
@JvmName("getServiceKey")
get() = _builder.getServiceKey()
@JvmName("setServiceKey")
set(value) {
_builder.setServiceUuid(value)
_builder.setServiceKey(value)
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
fun clearServiceUuid() {
_builder.clearServiceUuid()
fun clearServiceKey() {
_builder.clearServiceKey()
}
/**
* <code>string uuid = 3;</code>
* <code>string key = 3;</code>
*/
var uuid: kotlin.String
@JvmName("getUuid")
get() = _builder.getUuid()
@JvmName("setUuid")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setUuid(value)
_builder.setKey(value)
}
/**
* <code>string uuid = 3;</code>
* <code>string key = 3;</code>
*/
fun clearUuid() {
_builder.clearUuid()
fun clearKey() {
_builder.clearKey()
}
/**
* <code>int32 id = 4;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
set(value) {
_builder.setId(value)
}
/**
* <code>int32 id = 4;</code>
*/
fun clearId() {
_builder.clearId()
}
/**
* <code>bytes value = 5;</code>
* <code>bytes value = 4;</code>
*/
var value: com.google.protobuf.ByteString
@JvmName("getValue")
@ -101,14 +84,14 @@ object GattCharacteristicWriteArgumentsKt {
_builder.setValue(value)
}
/**
* <code>bytes value = 5;</code>
* <code>bytes value = 4;</code>
*/
fun clearValue() {
_builder.clearValue()
}
/**
* <code>bool withoutResponse = 6;</code>
* <code>bool withoutResponse = 5;</code>
*/
var withoutResponse: kotlin.Boolean
@JvmName("getWithoutResponse")
@ -118,7 +101,7 @@ object GattCharacteristicWriteArgumentsKt {
_builder.setWithoutResponse(value)
}
/**
* <code>bool withoutResponse = 6;</code>
* <code>bool withoutResponse = 5;</code>
*/
fun clearWithoutResponse() {
_builder.clearWithoutResponse()

View File

@ -0,0 +1,62 @@
//Generated by the protocol buffer compiler. DO NOT EDIT!
// source: message.proto
package dev.yanshouwang.bluetooth_low_energy;
@kotlin.jvm.JvmSynthetic
inline fun gattConnectionLost(block: dev.yanshouwang.bluetooth_low_energy.GattConnectionLostKt.Dsl.() -> Unit): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost =
dev.yanshouwang.bluetooth_low_energy.GattConnectionLostKt.Dsl._create(dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost.newBuilder()).apply { block() }._build()
object GattConnectionLostKt {
@kotlin.OptIn(com.google.protobuf.kotlin.OnlyForUseByGeneratedProtoCode::class)
@com.google.protobuf.kotlin.ProtoDslMarker
class Dsl private constructor(
@kotlin.jvm.JvmField private val _builder: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost.Builder
) {
companion object {
@kotlin.jvm.JvmSynthetic
@kotlin.PublishedApi
internal fun _create(builder: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost.Builder): Dsl = Dsl(builder)
}
@kotlin.jvm.JvmSynthetic
@kotlin.PublishedApi
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost = _builder.build()
/**
* <code>string key = 1;</code>
*/
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setKey(value)
}
/**
* <code>string key = 1;</code>
*/
fun clearKey() {
_builder.clearKey()
}
/**
* <code>string error = 2;</code>
*/
var error: kotlin.String
@JvmName("getError")
get() = _builder.getError()
@JvmName("setError")
set(value) {
_builder.setError(value)
}
/**
* <code>string error = 2;</code>
*/
fun clearError() {
_builder.clearError()
}
}
}
@kotlin.jvm.JvmSynthetic
inline fun dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost.copy(block: dev.yanshouwang.bluetooth_low_energy.GattConnectionLostKt.Dsl.() -> Unit): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost =
dev.yanshouwang.bluetooth_low_energy.GattConnectionLostKt.Dsl._create(this.toBuilder()).apply { block() }._build()

View File

@ -23,20 +23,20 @@ object GattDescriptorKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptor = _builder.build()
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setId(value)
_builder.setKey(value)
}
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
fun clearId() {
_builder.clearId()
fun clearKey() {
_builder.clearKey()
}
/**

View File

@ -23,88 +23,71 @@ object GattDescriptorReadArgumentsKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptorReadArguments = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var gattKey: kotlin.String
@JvmName("getGattKey")
get() = _builder.getGattKey()
@JvmName("setGattKey")
set(value) {
_builder.setAddress(value)
_builder.setGattKey(value)
}
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
fun clearGattKey() {
_builder.clearGattKey()
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
var serviceUuid: kotlin.String
@JvmName("getServiceUuid")
get() = _builder.getServiceUuid()
@JvmName("setServiceUuid")
var serviceKey: kotlin.String
@JvmName("getServiceKey")
get() = _builder.getServiceKey()
@JvmName("setServiceKey")
set(value) {
_builder.setServiceUuid(value)
_builder.setServiceKey(value)
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
fun clearServiceUuid() {
_builder.clearServiceUuid()
fun clearServiceKey() {
_builder.clearServiceKey()
}
/**
* <code>string characteristic_uuid = 3;</code>
* <code>string characteristic_key = 3;</code>
*/
var characteristicUuid: kotlin.String
@JvmName("getCharacteristicUuid")
get() = _builder.getCharacteristicUuid()
@JvmName("setCharacteristicUuid")
var characteristicKey: kotlin.String
@JvmName("getCharacteristicKey")
get() = _builder.getCharacteristicKey()
@JvmName("setCharacteristicKey")
set(value) {
_builder.setCharacteristicUuid(value)
_builder.setCharacteristicKey(value)
}
/**
* <code>string characteristic_uuid = 3;</code>
* <code>string characteristic_key = 3;</code>
*/
fun clearCharacteristicUuid() {
_builder.clearCharacteristicUuid()
fun clearCharacteristicKey() {
_builder.clearCharacteristicKey()
}
/**
* <code>string uuid = 4;</code>
* <code>string key = 4;</code>
*/
var uuid: kotlin.String
@JvmName("getUuid")
get() = _builder.getUuid()
@JvmName("setUuid")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setUuid(value)
_builder.setKey(value)
}
/**
* <code>string uuid = 4;</code>
* <code>string key = 4;</code>
*/
fun clearUuid() {
_builder.clearUuid()
}
/**
* <code>int32 id = 5;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
set(value) {
_builder.setId(value)
}
/**
* <code>int32 id = 5;</code>
*/
fun clearId() {
_builder.clearId()
fun clearKey() {
_builder.clearKey()
}
}
}

View File

@ -23,92 +23,75 @@ object GattDescriptorWriteArgumentsKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptorWriteArguments = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var gattKey: kotlin.String
@JvmName("getGattKey")
get() = _builder.getGattKey()
@JvmName("setGattKey")
set(value) {
_builder.setAddress(value)
_builder.setGattKey(value)
}
/**
* <code>string address = 1;</code>
* <code>string gatt_key = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
fun clearGattKey() {
_builder.clearGattKey()
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
var serviceUuid: kotlin.String
@JvmName("getServiceUuid")
get() = _builder.getServiceUuid()
@JvmName("setServiceUuid")
var serviceKey: kotlin.String
@JvmName("getServiceKey")
get() = _builder.getServiceKey()
@JvmName("setServiceKey")
set(value) {
_builder.setServiceUuid(value)
_builder.setServiceKey(value)
}
/**
* <code>string service_uuid = 2;</code>
* <code>string service_key = 2;</code>
*/
fun clearServiceUuid() {
_builder.clearServiceUuid()
fun clearServiceKey() {
_builder.clearServiceKey()
}
/**
* <code>string characteristic_uuid = 3;</code>
* <code>string characteristic_key = 3;</code>
*/
var characteristicUuid: kotlin.String
@JvmName("getCharacteristicUuid")
get() = _builder.getCharacteristicUuid()
@JvmName("setCharacteristicUuid")
var characteristicKey: kotlin.String
@JvmName("getCharacteristicKey")
get() = _builder.getCharacteristicKey()
@JvmName("setCharacteristicKey")
set(value) {
_builder.setCharacteristicUuid(value)
_builder.setCharacteristicKey(value)
}
/**
* <code>string characteristic_uuid = 3;</code>
* <code>string characteristic_key = 3;</code>
*/
fun clearCharacteristicUuid() {
_builder.clearCharacteristicUuid()
fun clearCharacteristicKey() {
_builder.clearCharacteristicKey()
}
/**
* <code>string uuid = 4;</code>
* <code>string key = 4;</code>
*/
var uuid: kotlin.String
@JvmName("getUuid")
get() = _builder.getUuid()
@JvmName("setUuid")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setUuid(value)
_builder.setKey(value)
}
/**
* <code>string uuid = 4;</code>
* <code>string key = 4;</code>
*/
fun clearUuid() {
_builder.clearUuid()
fun clearKey() {
_builder.clearKey()
}
/**
* <code>int32 id = 5;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
set(value) {
_builder.setId(value)
}
/**
* <code>int32 id = 5;</code>
*/
fun clearId() {
_builder.clearId()
}
/**
* <code>bytes value = 6;</code>
* <code>bytes value = 5;</code>
*/
var value: com.google.protobuf.ByteString
@JvmName("getValue")
@ -118,7 +101,7 @@ object GattDescriptorWriteArgumentsKt {
_builder.setValue(value)
}
/**
* <code>bytes value = 6;</code>
* <code>bytes value = 5;</code>
*/
fun clearValue() {
_builder.clearValue()

View File

@ -23,37 +23,20 @@ object GattDisconnectArgumentsKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDisconnectArguments = _builder.build()
/**
* <code>string address = 1;</code>
* <code>string key = 1;</code>
*/
var address: kotlin.String
@JvmName("getAddress")
get() = _builder.getAddress()
@JvmName("setAddress")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setAddress(value)
_builder.setKey(value)
}
/**
* <code>string address = 1;</code>
* <code>string key = 1;</code>
*/
fun clearAddress() {
_builder.clearAddress()
}
/**
* <code>int32 id = 2;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
set(value) {
_builder.setId(value)
}
/**
* <code>int32 id = 2;</code>
*/
fun clearId() {
_builder.clearId()
fun clearKey() {
_builder.clearKey()
}
}
}

View File

@ -23,20 +23,20 @@ object GattServiceKt {
internal fun _build(): dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattService = _builder.build()
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
var id: kotlin.Int
@JvmName("getId")
get() = _builder.getId()
@JvmName("setId")
var key: kotlin.String
@JvmName("getKey")
get() = _builder.getKey()
@JvmName("setKey")
set(value) {
_builder.setId(value)
_builder.setKey(value)
}
/**
* <code>int32 id = 1;</code>
* <code>string key = 1;</code>
*/
fun clearId() {
_builder.clearId()
fun clearKey() {
_builder.clearKey()
}
/**

View File

@ -40,9 +40,9 @@ object MessageKt {
}
/**
* <code>bool state = 2;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.BluetoothState state = 2;</code>
*/
var state: kotlin.Boolean
var state: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.BluetoothState
@JvmName("getState")
get() = _builder.getState()
@JvmName("setState")
@ -50,13 +50,13 @@ object MessageKt {
_builder.setState(value)
}
/**
* <code>bool state = 2;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.BluetoothState state = 2;</code>
*/
fun clearState() {
_builder.clearState()
}
/**
* <code>bool state = 2;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.BluetoothState state = 2;</code>
* @return Whether the state field is set.
*/
fun hasState(): kotlin.Boolean {
@ -64,7 +64,31 @@ object MessageKt {
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.Discovery discovery = 3;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.StartDiscoveryArguments startDiscoveryArguments = 3;</code>
*/
var startDiscoveryArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.StartDiscoveryArguments
@JvmName("getStartDiscoveryArguments")
get() = _builder.getStartDiscoveryArguments()
@JvmName("setStartDiscoveryArguments")
set(value) {
_builder.setStartDiscoveryArguments(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.StartDiscoveryArguments startDiscoveryArguments = 3;</code>
*/
fun clearStartDiscoveryArguments() {
_builder.clearStartDiscoveryArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.StartDiscoveryArguments startDiscoveryArguments = 3;</code>
* @return Whether the startDiscoveryArguments field is set.
*/
fun hasStartDiscoveryArguments(): kotlin.Boolean {
return _builder.hasStartDiscoveryArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.Discovery discovery = 4;</code>
*/
var discovery: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.Discovery
@JvmName("getDiscovery")
@ -74,13 +98,13 @@ object MessageKt {
_builder.setDiscovery(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.Discovery discovery = 3;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.Discovery discovery = 4;</code>
*/
fun clearDiscovery() {
_builder.clearDiscovery()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.Discovery discovery = 3;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.Discovery discovery = 4;</code>
* @return Whether the discovery field is set.
*/
fun hasDiscovery(): kotlin.Boolean {
@ -88,33 +112,57 @@ object MessageKt {
}
/**
* <code>bool scanning = 4;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.ConnectArguments connectArguments = 5;</code>
*/
var scanning: kotlin.Boolean
@JvmName("getScanning")
get() = _builder.getScanning()
@JvmName("setScanning")
var connectArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectArguments
@JvmName("getConnectArguments")
get() = _builder.getConnectArguments()
@JvmName("setConnectArguments")
set(value) {
_builder.setScanning(value)
_builder.setConnectArguments(value)
}
/**
* <code>bool scanning = 4;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.ConnectArguments connectArguments = 5;</code>
*/
fun clearScanning() {
_builder.clearScanning()
fun clearConnectArguments() {
_builder.clearConnectArguments()
}
/**
* <code>bool scanning = 4;</code>
* @return Whether the scanning field is set.
* <code>.dev.yanshouwang.bluetooth_low_energy.ConnectArguments connectArguments = 5;</code>
* @return Whether the connectArguments field is set.
*/
fun hasScanning(): kotlin.Boolean {
return _builder.hasScanning()
fun hasConnectArguments(): kotlin.Boolean {
return _builder.hasConnectArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.ConnectionLost connectionLost = 5;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDisconnectArguments disconnectArguments = 6;</code>
*/
var connectionLost: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.ConnectionLost
var disconnectArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDisconnectArguments
@JvmName("getDisconnectArguments")
get() = _builder.getDisconnectArguments()
@JvmName("setDisconnectArguments")
set(value) {
_builder.setDisconnectArguments(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDisconnectArguments disconnectArguments = 6;</code>
*/
fun clearDisconnectArguments() {
_builder.clearDisconnectArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDisconnectArguments disconnectArguments = 6;</code>
* @return Whether the disconnectArguments field is set.
*/
fun hasDisconnectArguments(): kotlin.Boolean {
return _builder.hasDisconnectArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattConnectionLost connectionLost = 7;</code>
*/
var connectionLost: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattConnectionLost
@JvmName("getConnectionLost")
get() = _builder.getConnectionLost()
@JvmName("setConnectionLost")
@ -122,13 +170,13 @@ object MessageKt {
_builder.setConnectionLost(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.ConnectionLost connectionLost = 5;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.GattConnectionLost connectionLost = 7;</code>
*/
fun clearConnectionLost() {
_builder.clearConnectionLost()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.ConnectionLost connectionLost = 5;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.GattConnectionLost connectionLost = 7;</code>
* @return Whether the connectionLost field is set.
*/
fun hasConnectionLost(): kotlin.Boolean {
@ -136,7 +184,79 @@ object MessageKt {
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicValue characteristicValue = 6;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicReadArguments characteristicReadArguments = 8;</code>
*/
var characteristicReadArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicReadArguments
@JvmName("getCharacteristicReadArguments")
get() = _builder.getCharacteristicReadArguments()
@JvmName("setCharacteristicReadArguments")
set(value) {
_builder.setCharacteristicReadArguments(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicReadArguments characteristicReadArguments = 8;</code>
*/
fun clearCharacteristicReadArguments() {
_builder.clearCharacteristicReadArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicReadArguments characteristicReadArguments = 8;</code>
* @return Whether the characteristicReadArguments field is set.
*/
fun hasCharacteristicReadArguments(): kotlin.Boolean {
return _builder.hasCharacteristicReadArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicWriteArguments characteristicWriteArguments = 9;</code>
*/
var characteristicWriteArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicWriteArguments
@JvmName("getCharacteristicWriteArguments")
get() = _builder.getCharacteristicWriteArguments()
@JvmName("setCharacteristicWriteArguments")
set(value) {
_builder.setCharacteristicWriteArguments(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicWriteArguments characteristicWriteArguments = 9;</code>
*/
fun clearCharacteristicWriteArguments() {
_builder.clearCharacteristicWriteArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicWriteArguments characteristicWriteArguments = 9;</code>
* @return Whether the characteristicWriteArguments field is set.
*/
fun hasCharacteristicWriteArguments(): kotlin.Boolean {
return _builder.hasCharacteristicWriteArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicNotifyArguments characteristicNotifyArguments = 10;</code>
*/
var characteristicNotifyArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicNotifyArguments
@JvmName("getCharacteristicNotifyArguments")
get() = _builder.getCharacteristicNotifyArguments()
@JvmName("setCharacteristicNotifyArguments")
set(value) {
_builder.setCharacteristicNotifyArguments(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicNotifyArguments characteristicNotifyArguments = 10;</code>
*/
fun clearCharacteristicNotifyArguments() {
_builder.clearCharacteristicNotifyArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicNotifyArguments characteristicNotifyArguments = 10;</code>
* @return Whether the characteristicNotifyArguments field is set.
*/
fun hasCharacteristicNotifyArguments(): kotlin.Boolean {
return _builder.hasCharacteristicNotifyArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicValue characteristicValue = 11;</code>
*/
var characteristicValue: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattCharacteristicValue
@JvmName("getCharacteristicValue")
@ -146,18 +266,66 @@ object MessageKt {
_builder.setCharacteristicValue(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicValue characteristicValue = 6;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicValue characteristicValue = 11;</code>
*/
fun clearCharacteristicValue() {
_builder.clearCharacteristicValue()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicValue characteristicValue = 6;</code>
* <code>.dev.yanshouwang.bluetooth_low_energy.GattCharacteristicValue characteristicValue = 11;</code>
* @return Whether the characteristicValue field is set.
*/
fun hasCharacteristicValue(): kotlin.Boolean {
return _builder.hasCharacteristicValue()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDescriptorReadArguments descriptorReadArguments = 12;</code>
*/
var descriptorReadArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptorReadArguments
@JvmName("getDescriptorReadArguments")
get() = _builder.getDescriptorReadArguments()
@JvmName("setDescriptorReadArguments")
set(value) {
_builder.setDescriptorReadArguments(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDescriptorReadArguments descriptorReadArguments = 12;</code>
*/
fun clearDescriptorReadArguments() {
_builder.clearDescriptorReadArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDescriptorReadArguments descriptorReadArguments = 12;</code>
* @return Whether the descriptorReadArguments field is set.
*/
fun hasDescriptorReadArguments(): kotlin.Boolean {
return _builder.hasDescriptorReadArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDescriptorWriteArguments descriptorWriteArguments = 13;</code>
*/
var descriptorWriteArguments: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.GattDescriptorWriteArguments
@JvmName("getDescriptorWriteArguments")
get() = _builder.getDescriptorWriteArguments()
@JvmName("setDescriptorWriteArguments")
set(value) {
_builder.setDescriptorWriteArguments(value)
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDescriptorWriteArguments descriptorWriteArguments = 13;</code>
*/
fun clearDescriptorWriteArguments() {
_builder.clearDescriptorWriteArguments()
}
/**
* <code>.dev.yanshouwang.bluetooth_low_energy.GattDescriptorWriteArguments descriptorWriteArguments = 13;</code>
* @return Whether the descriptorWriteArguments field is set.
*/
fun hasDescriptorWriteArguments(): kotlin.Boolean {
return _builder.hasDescriptorWriteArguments()
}
val valueCase: dev.yanshouwang.bluetooth_low_energy.MessageOuterClass.Message.ValueCase
@JvmName("getValueCase")
get() = _builder.getValueCase()

View File

@ -0,0 +1,5 @@
package dev.yanshouwang.bluetooth_low_energy
import android.bluetooth.BluetoothGatt
class NativeGATT(value: BluetoothGatt, val services: Map<String, NativeGattService>) : NativeValue<BluetoothGatt>(value)

View File

@ -0,0 +1,5 @@
package dev.yanshouwang.bluetooth_low_energy
import android.bluetooth.BluetoothGattCharacteristic
class NativeGattCharacteristic(value: BluetoothGattCharacteristic, val descriptors: Map<String, NativeGattDescriptor>) : NativeValue<BluetoothGattCharacteristic>(value)

View File

@ -0,0 +1,5 @@
package dev.yanshouwang.bluetooth_low_energy
import android.bluetooth.BluetoothGattDescriptor
class NativeGattDescriptor(value: BluetoothGattDescriptor) : NativeValue<BluetoothGattDescriptor>(value)

View File

@ -0,0 +1,5 @@
package dev.yanshouwang.bluetooth_low_energy
import android.bluetooth.BluetoothGattService
class NativeGattService(value: BluetoothGattService, val characteristics: Map<String, NativeGattCharacteristic>) : NativeValue<BluetoothGattService>(value)

View File

@ -0,0 +1,7 @@
package dev.yanshouwang.bluetooth_low_energy
import java.util.*
open class NativeValue<T>(val value: T) {
public val key = UUID.randomUUID().toString()
}