4

Bluetooth Low Energy デバイスを接続するために、Samsung ACE3 でアプリを開発しています。Samsung は ACE3 を Android 4.3 にアップグレードすることを望んでいないため、Samsung ble API を使用する必要があります。現在、接続、データの読み取り、データの送信、および 1 つの特性からの通知の取得はすべて問題ありません。しかし、複数の特性の通知を有効にすると、最初に有効になった特性だけが通知を受け取ることができます。誰も同じ問題を抱えていますか?あなたの助けに感謝!

次のコードは、接続時に通知を有効にします

 if (mBluetoothGatt != null && device != null) {
        BluetoothGattService pucService = mBluetoothGatt.getService(device, PROFILE_UART_CONTROL_SERVICE);
        if (pucService == null) {
            showMessage("PUC service not found!");
            return;
        }

        BluetoothGattCharacteristic motion = pucService.getCharacteristic(MOTION_READ);
        if (motion == null) {
            showMessage("charateristic not found!");
            return;
        }
        enableNotification(true, motion);            

        BluetoothGattCharacteristic voltage = pucService.getCharacteristic(VOLTAGE_READ);
        if (voltage == null) {
            showMessage("charateristic not found!");
            return;
        }
        enableNotification(true, voltage);


        BluetoothGattCharacteristic pressure = pucService.getCharacteristic(PRESSURE_READ);
        if (pressure == null) {
            showMessage("charateristic not found!");
            return;
        }
        enableNotification(true, pressure);
    }

enableNotification メソッドは次のとおりです。

    public boolean enableNotification(boolean enable, BluetoothGattCharacteristic characteristic) {
    if (mBluetoothGatt == null)
        return false;
    if (!mBluetoothGatt.setCharacteristicNotification(characteristic, enable))
        return false;

    BluetoothGattDescriptor clientConfig = characteristic.getDescriptor(CCC);
    if (clientConfig == null)
        return false;

    if (enable) {
         Log.i(TAG,"enable notification");
        clientConfig.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
    } else {
        Log.i(TAG,"disable notification");
        clientConfig.setValue(BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE);
    }
    return mBluetoothGatt.writeDescriptor(clientConfig);
}
4

1 に答える 1

3

この投稿のmiznickによる2番目の回答で質問が対処されていることに気付きました。主に、Samsung BLE Api が同期的に動作するためです。基本的に、API は書き込み/読み取り特性、w/r 記述子など、一度に 1 つの Gatt 命令しか処理できません。w/r GATT メソッドを呼び出すことで、実行待ちのシステムに Gatt 命令を追加するようなものです。実行後、システムは onCharacterWrite、OnDescriptorWrite などの関連するコールバック メソッドを呼び出します。この時点以降にのみ、別の Gatt w/r メソッドを呼び出す必要があります。コードは miznick の投稿に記載されています。

この投稿は、Samsung Ble API の動作を理解するのにも役立ちます。Samsung BLE 公式サイトのガイドとヒントをご覧ください。

于 2013-11-14T08:10:06.463 に答える