无法阅读Android BLE上的葡萄糖测量特征

时间:2017-10-27 16:37:44

标签: android bluetooth-lowenergy bluetooth-gatt

我正在开发一个应用程序来读取具有葡萄糖服务启用的BLE设备的葡萄糖测量值。但是,我无法读取已经采取的测量值,因此永远不会调用on onCharacteristicChanged回调。我的代码段如下:

 @Override
 public void onServicesDiscovered(BluetoothGatt gatt, int status) {
        super.onServicesDiscovered(gatt, status);
        if (status == BluetoothGatt.GATT_SUCCESS) {
          mGlucoseService = 
          gatt.getService(BluetoothUUIDS.GLUCOSE_MEASUREMENT_SERVICE_UUID);
          mGlucoseCharacteristic = 
          mGlucoseService.getCharacteristic(BluetoothUUIDS
                    .GLUCOSE_MEASUREMENT_CHARACTERISTIC_UUID);
            gatt.setCharacteristicNotification(mGlucoseCharacteristic, true);
            BluetoothGattDescriptor descMeasurement = mGlucoseCharacteristic.getDescriptor(BluetoothUUIDS
                    .CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
            descMeasurement.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descMeasurement);

            mGlucoseContextCharacteristic = mGlucoseService.getCharacteristic(BluetoothUUIDS
                    .GLUCOSE_MEASUREMENT_CONTEXT_CHARACTERISTIC_UUID);
            gatt.setCharacteristicNotification(mGlucoseContextCharacteristic, true);
            BluetoothGattDescriptor descContext = mGlucoseCharacteristic.getDescriptor(BluetoothUUIDS
                    .CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
            descContext.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE);
            gatt.writeDescriptor(descContext);

            mRecordAccessCharacteristic = mGlucoseService.getCharacteristic(BluetoothUUIDS
                    .GLUCOSE_RECORD_ACCESS_CHARACTERISTIC_UUID);
            gatt.setCharacteristicNotification(mRecordAccessCharacteristic, true);
            mRecordAccessConfigurationDescriptor = mRecordAccessCharacteristic.getDescriptor(BluetoothUUIDS
                    .CLIENT_CHARACTERISTIC_CONFIG_DESCRIPTOR_UUID);
            if (mRecordAccessConfigurationDescriptor != null) {
                mRecordAccessConfigurationDescriptor.setValue(BluetoothGattDescriptor.ENABLE_INDICATION_VALUE);

                new Thread(new Runnable() {
                    public void run() {
                        boolean success = false;
                        while (!success) {
                            if (mGatt.writeDescriptor(mRecordAccessConfigurationDescriptor)){
                                success = true;
                            }
                        }
                    }
                }).start();

获取我正在使用的记录:

mRecordAccessCharacteristic.setValue(new byte[2]);
mRecordAccessCharacteristic.setValue(OPCODE_REPORT_NUMBER_OF_RECORDS, BluetoothGattCharacteristic
            .FORMAT_UINT8, 0);
    mRecordAccessCharacteristic.setValue(OPERATOR_ALL_RECORDS, BluetoothGattCharacteristic.FORMAT_UINT8, 1);
    mGattDevice.writeCharacteristic(mRecordAccessCharacteristic);

OR

    byte[] data = new byte[2];
    data[0] = 0x01; // Report Stored records
    data[1] = 0x01; // All records
    mRecordAccessCharacteristic.setValue(data);
    mGattDevice.writeCharacteristic(mRecordAccessCharacteristic);

两种方式都不起作用。请,任何帮助将不胜感激!

0 个答案:

没有答案