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