private Lock lock = new ReentrantLock();
private Condition condition = lock.newCondition();
public void writeCharacteristic(UUID paramUUID, byte[] recvBuf, ActionCallback paramActionCallback)
{
try {
lock.lock();
writeCharacteristic(Profile.UUID_SERVICE_DRIVERMATE, paramUUID, recvBuf, paramActionCallback);
System.out.println("writeCharacteristic我在等一个新信号"+Thread.currentThread().getName());
condition.await(500, TimeUnit.MILLISECONDS);
} catch (Exception e){
} finally {
System.out.println("writeCharacteristic拿到一个信号"+Thread.currentThread().getName());
lock.unlock();
}
}
public void onCharacteristicWrite(BluetoothGatt paramBluetoothGatt, BluetoothGattCharacteristic paramBluetoothGattCharacteristic, int paramInt)
{
super.onCharacteristicWrite(paramBluetoothGatt, paramBluetoothGattCharacteristic, paramInt);
//Log.w(TAG, "onSuccess onCharacteristicWrite = " + ByteUtil.bytesToHexString(paramBluetoothGattCharacteristic.getValue()));
if (paramInt == 0) {
onSuccess(paramBluetoothGattCharacteristic);
}
else {
onFail(paramInt, "onCharacteristicWrite fail");
}
try {
lock.lock();
System.out.println("onCharacteristicWrite" + Thread.currentThread().getName());
condition.signal();
System.out.println("onCharacteristicWrite我发出了一个信号:"+Thread.currentThread().getName());
} catch (Exception e){
} finally {
lock.unlock();
}
}