2017-02-09 12 views
0

私はカスタムBLEセンサーボードと通信するAndroid電話でBLEアプリケーションを使用しています。ボードには加速度と加速度の2つの特性があります。電話側では、センサーボードから2つの特性の通知を受け取りたいと思います。通知を設定するコード:Bluetooth LEが複数の特性通知を聞きます

mGatt.setCharacteristicNotification(ecgChar, true); 
      BluetoothGattDescriptor descriptor = ecgChar.getDescriptor(
        UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); 
      descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 
      mGatt.writeDescriptor(descriptor); 
      mGatt.setCharacteristicNotification(accelChar, true); 
      descriptor = ecgChar.getDescriptor(
        UUID.fromString("00002902-0000-1000-8000-00805f9b34fb")); 
      descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 
      mGatt.writeDescriptor(descriptor); 

ただし、最初の特性の通知のみを受信できます。 1つの特性の通知のみ登録するとうまくいきました。 ECGと加速度のサンプリング周波数は100Hzです。では、両方の特性からどのように通知を受け取ることができますか?ありがとう。

答えて

2

一度に1つのgatt操作しか実行できません。この場合、最初の完了まで待機する前に2つのwriteDescriptor呼び出しを行います。あなたは次のものを送ることができるまでhttps://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int)を待たなければなりません。

+0

実際、gattの操作はシリアル化されているので、2つの書き込みの間に遅延を追加しようとしましたが、動作しませんでした。今私は正しい方法であるシリアル化を処理するコールバックを使用し、それはうまく動作します!ありがとう! – Sentimental

関連する問題