Android OnCharacteristicChanged - Continuous stream of bytes from Bluetooth Stethoscope

29 views Asked by At

I'm working on integration of a Bluetooth enabled Litmann Stethoscope with an Android app. I'm able to pair with the Stethoscope and enable Characteristic notifications. Once notification is enabled I'm getting continuous stream of data from the Stethoscope at the rate of hundreds of Characteristic changed notifications per second. I guessed this is because the Stethoscope is streaming the audio from its sensor. Need help to understand what is the audio format I'm receiving and how can I play this audio in the app. Below is the sample of the bytes received on each characteristic changed notification.

enter image description here

Below is a sample of the code I wrote in getting the characteristics.

public static final UUID stethoscopeServiceUuid = UUID.fromString("##respectiveUUID##");
public static final UUID stethoscopeCharacteristicUuid = UUID.fromString("##respectiveUUID##");
public static final UUID generalDescriptorUuid = UUID.fromString("00002902-0000-1000-8000-00805f9b34fb");
ByteArrayOutputStream stethescopeStream = new ByteArrayOutputStream();

private void handleConnectionStateChange(BluetoothGatt gatt, int newState) {
    if (newState == BluetoothProfile.STATE_CONNECTED) {
        gatt.discoverServices();
    }
}

private void handleServicesDiscovered(BluetoothGatt gatt, int status) {
    if (status == BluetoothGatt.GATT_SUCCESS) {
        BluetoothGattCharacteristic stethoscopeCharacteristic = gatt.getService(stethoscopeServiceUuid).getCharacteristic(stethoscopeCharacteristicUuid);
        gatt.setCharacteristicNotification(stethoscopeCharacteristic, true);
        BluetoothGattDescriptor descriptor = stethoscopeCharacteristic.getDescriptor(generalDescriptorUuid);
        descriptor.setValue(BluetoothGattDescriptor
            .ENABLE_NOTIFICATION_VALUE);
        gatt.writeDescriptor(descriptor);
    }
}

private void handleCharacteristicChanged(BluetoothGatt gatt, BluetoothGattCharacteristic characteristic, byte[] value){
    handleStethoscopeValueReceived(gatt.getDevice().getName(),characteristic, value);
}

private void handleStethoscopeValueReceived(String deviceName, BluetoothGattCharacteristic characteristic, byte[] value) {
    //value
    //00 42 11 89 99 BB CA AA AA 80 0A 99 9E BB CD CA A9
    //01 99 90 08 A9 8A CB A9 10 11 02 20 11 03 53 35 42
    //02 32 42 21 43 53 23 34 33 34 33 53 35 43 34 34 33
    //03 34 32 34 42 23 34 32 22 32 21 08 91 90 90 90 99
    //04 9B BB BD DA BB EB BB BC BB AB CB BC BD BA BB BB
    //05 CB BC BA CB AB CB AA 9B B9 BB 9A BB BB AB 99 11
    //06 BA 01 BB 91 B0 91 90 BB BA 99 99 A9 99 BA BB A9
    //....

    stethescopeStream.write(Arrays.copyOfRange(value, 0, value.length));
}
0

There are 0 answers