Search in sources :

Example 1 with BleWriteCharacteristicOperation

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

the class BleGattClientProxyImpl method __writeCharacteristic.

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

Aggregations

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