Search in sources :

Example 1 with BleRequestMtuOperation

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

the class BleGattClientProxyImpl method __requestMtu.

private boolean __requestMtu(final int mtu, final long timeout) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        BleLiteLog.w(TAG, "__requestMtu() fail for android version is to low(lower than 5.0 LOLLIPOP)");
        return false;
    }
    final BluetoothGatt bluetoothGatt = getBluetoothGatt();
    if (bluetoothGatt == null) {
        BleLiteLog.w(TAG, "__requestMtu() fail for bluetoothGatt is null");
        return false;
    }
    // create operation
    final BleRequestMtuOperation requestMtuOperation = BleRequestMtuOperation.createInstance(bluetoothGatt, mtu);
    // register
    register(requestMtuOperation);
    // execute operation
    long startTimestamp = System.currentTimeMillis();
    requestMtuOperation.doRunnableSelfAsync(false);
    requestMtuOperation.waitLock(timeout);
    long consume = System.currentTimeMillis() - startTimestamp;
    boolean isRequestMtuSuc = requestMtuOperation.isNotified();
    BleLiteLog.i(TAG, "__requestMtu() mtu: " + mtu + " suc: " + isRequestMtuSuc + ", consume: " + consume + " ms");
    return isRequestMtuSuc;
}
Also used : BluetoothGatt(android.bluetooth.BluetoothGatt) BleRequestMtuOperation(com.afunx.ble.blelitelib.operation.BleRequestMtuOperation)

Aggregations

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