Search in sources :

Example 1 with BleReadCharacteristicOperation

use of com.afunx.ble.blelitelib.operation.BleReadCharacteristicOperation in project BleLiteLib4android by afunx.

the class BleGattClientProxyImpl method __readCharacteristic.

private byte[] __readCharacteristic(BluetoothGattCharacteristic gattCharacteristic, long timeout) {
    final BluetoothGatt bluetoothGatt = getBluetoothGatt();
    if (bluetoothGatt == null) {
        BleLiteLog.w(TAG, "__readCharacteristic() fail for bluetoothGatt is null");
        return null;
    }
    // create operation
    final BleReadCharacteristicOperation readCharacteristicOperation = BleReadCharacteristicOperation.createInstance(bluetoothGatt, gattCharacteristic);
    // register
    register(readCharacteristicOperation);
    // execute operation
    long startTimestamp = System.currentTimeMillis();
    readCharacteristicOperation.doRunnableSelfAsync(false);
    readCharacteristicOperation.waitLock(timeout);
    long consume = System.currentTimeMillis() - startTimestamp;
    final byte[] msg = readCharacteristicOperation.isNotified() ? readCharacteristicOperation.getResult() : null;
    BleLiteLog.i(TAG, "__readCharacteristic() gattCharacteristic's uuid: " + gattCharacteristic.getUuid() + ", consume: " + consume + " ms" + ", msg: " + Arrays.toString(msg));
    return msg;
}
Also used : BleReadCharacteristicOperation(com.afunx.ble.blelitelib.operation.BleReadCharacteristicOperation) BluetoothGatt(android.bluetooth.BluetoothGatt)

Aggregations

BluetoothGatt (android.bluetooth.BluetoothGatt)1 BleReadCharacteristicOperation (com.afunx.ble.blelitelib.operation.BleReadCharacteristicOperation)1