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