从通知中获取特征 gatt



我正在使用带有 kotlin 的 RxAndroidBle。 到目前为止,我可以设置多个通知并且正在接收它们。

如何将通知映射到其特定特征?

迄今:

enter code here connectionObserver
.flatMap { rxBleConnection ->
rxBleConnection.discoverServices().flatMap { services -> services.getService(ServiceUUID).map(BluetoothGattService::getCharacteristics) }
.flatMapObservable { s -> fromIterable(s) }
.flatMap { characteristic -> rxBleConnection.setupNotification(characteristic)
.flatMap{ notificationObservable -> notificationObservable}}
}.observeOn(AndroidSchedulers.mainThread())
.subscribe{notification->notification}

谢谢

对于那些在 kotlin 和 RxAndroid 蓝牙上苦苦挣扎的人来说,经过一些工作后,我让它工作了,所以原始代码看起来像

enter code here  connectionObserver
.flatMap { rxBleConnection ->
rxBleConnection.discoverServices().flatMap { services -> services.getService(ServiceUUID).map(BluetoothGattService::getCharacteristics) }
.flatMapObservable { s -> fromIterable(s) }
.flatMap { characteristic ->
rxBleConnection.setupNotification(characteristic)
.flatMap { notificationObservable -> notificationObservable.flatMap { result -> Observable.just(result).zipWith(fromArray(getBytesFromUUID(characteristic.uuid))) } }
}
}.observeOn(AndroidSchedulers.mainThread())
.subscribe { notification -> onNotificationReceived(notification)
}

最新更新