samsung ble api ไม่สามารถรับการแจ้งเตือนจากคุณสมบัติ GATT หลาย ๆ อย่าง

ฉันกำลังพัฒนาแอปบน Samsung ACE3 เพื่อเชื่อมต่ออุปกรณ์ Bluetooth Low Energy เนื่องจาก Samsung ไม่ต้องการให้ ACE3 อัปเกรดเป็น Android 4.3 ฉันจึงต้องใช้ Samsung ble api ในปัจจุบัน การเชื่อมต่อ การอ่านข้อมูล การส่งข้อมูล และรับการแจ้งเตือนจากคุณลักษณะหนึ่งๆ ถือว่าใช้ได้ทั้งหมด แต่เมื่อฉันเปิดใช้งานการแจ้งเตือนสำหรับคุณสมบัติหลายรายการ เฉพาะคุณสมบัติแรกที่เปิดใช้งานเท่านั้นที่สามารถรับการแจ้งเตือนได้ ใครมีปัญหาเดียวกันบ้างไหม? ขอบคุณที่คุณช่วย!

รหัสต่อไปนี้เปิดใช้งานการแจ้งเตือนเกี่ยวกับการเชื่อมต่อ

 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);
    }

ต่อไปนี้เป็นวิธีการเปิดใช้งานการแจ้งเตือน:

    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);
}

person skyin    schedule 13.11.2013    source แหล่งที่มา


คำตอบ (1)


เพิ่งรู้ว่าคำถามได้รับการแก้ไขในคำตอบที่สองโดย miznick ในโพสต์นี้. สาเหตุหลักมาจาก Samsung BLE Api ทำงานพร้อมกัน โดยพื้นฐานแล้ว API สามารถประมวลผลคำสั่ง Gatt ได้เพียง 1 คำสั่งเท่านั้น เช่น คุณลักษณะการเขียน/การอ่าน ตัวอธิบายที่มี r และอื่นๆ ในแต่ละครั้ง ด้วยการเรียกเมธอด w/r GATT ก็เหมือนกับการผนวกคำสั่ง Gatt เข้ากับระบบที่รอการดำเนินการ หลังจากดำเนินการแล้ว ระบบจะเรียกใช้วิธีการโทรกลับที่เกี่ยวข้อง เช่น onCharacterWrite, OnDescriptorWrite และอื่นๆ เฉพาะในหรือหลังจุดนี้เท่านั้น เราควรเรียกเมธอด Gatt w/r อื่น รหัสอยู่ในโพสต์ของ miznick

โพสต์นี้ยังมีประโยชน์ในการทำความเข้าใจอีกด้วย พฤติกรรมของ Samsung Ble api ดูคำแนะนำและคำแนะนำในเว็บไซต์อย่างเป็นทางการของ Samsung BLE

person skyin    schedule 14.11.2013