2017-02-09 1 views
0

사용자 BLE 센서 보드와 통신하는 Android 전화에서 BLE 애플리케이션을 사용하고 있습니다. 보드가 제공하는 두 가지 특성 인 가속과 심의가 있습니다. 전화 측에서는 센서 보드에서 두 가지 특성에 대한 알림을 받고 싶습니다. 알림을 설정하는 코드 :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); 

그러나 첫 번째 특성에 대한 알림 만 수신 할 수 있습니다. 하나의 특성에 대한 알림 만 등록하면 잘 작동합니다. 샘플링 주파수는 심전도와 가속 모두 100Hz입니다. 그렇다면 두 특성 모두에서 알림을 수신하려면 어떻게해야합니까? 감사.

답변

2

한 번에 하나의 뛰어난 gatt 작업 만있을 수 있습니다. 이 경우 첫 번째 작업이 완료 될 때까지 기다리기 전에 두 개의 writeDescriptor 호출을 수행합니다. 다음 번에 보낼 수있을 때까지 https://developer.android.com/reference/android/bluetooth/BluetoothGattCallback.html#onDescriptorWrite(android.bluetooth.BluetoothGatt, android.bluetooth.BluetoothGattDescriptor, int)을 기다려야합니다.

+0

실제로 gatt 작업이 serialize 된 것을 알고 있으므로 두 번의 쓰기 사이에 지연을 추가하려고했지만 작동하지 않았습니다. 이제 콜백을 사용하여 올바른 방법 인 직렬화를 처리하고 잘 작동합니다! 감사! – Sentimental

관련 문제