Skip to content

Commit

Permalink
fix(java): fix waiter released to early
Browse files Browse the repository at this point in the history
Signed-off-by: Sacha Froment <sfroment42@gmail.com>
  • Loading branch information
sfroment committed Nov 13, 2018
1 parent ae39d8d commit 9972621
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Expand Up @@ -43,7 +43,7 @@ public BertyDevice(BluetoothDevice device, BluetoothGatt gatt, String address) {
this.addr = address;
this.device = device;
this.isWaiting = new Semaphore(1);
waitReady = new CountDownLatch(2);
waitReady = new CountDownLatch(8);
this.toSend = new ArrayList<>();
new Thread(new Runnable() {
@Override
Expand Down
Expand Up @@ -565,22 +565,30 @@ public void onServicesDiscovered(BluetoothGatt gatt, int status) {
todo.add(new PopulateCharacteristic(IS_READY_UUID, bDevice));
todo.add(new PopulateCharacteristic(ACCEPT_UUID, bDevice));

Log.e(TAG, "START DISCO CHAR");

try {
List<Future<BluetoothGattCharacteristic>> answers = es.invokeAll(todo);
for (Future<BluetoothGattCharacteristic> future:answers) {
BluetoothGattCharacteristic c = future.get();
if (c.getUuid().equals(MA_UUID)) {
bDevice.maCharacteristic = c;
bDevice.waitReady.countDown();
} else if (c.getUuid().equals(PEER_ID_UUID)) {
bDevice.peerIDCharacteristic = c;
bDevice.waitReady.countDown();
} else if (c.getUuid().equals(CLOSER_UUID)) {
bDevice.closerCharacteristic = c;
bDevice.waitReady.countDown();
} else if (c.getUuid().equals(WRITER_UUID)) {
bDevice.writerCharacteristic = c;
bDevice.waitReady.countDown();
} else if (c.getUuid().equals(IS_READY_UUID)) {
bDevice.isRdyCharacteristic = c;
bDevice.waitReady.countDown();
} else if (c.getUuid().equals(ACCEPT_UUID)) {
bDevice.acceptCharacteristic = c;
bDevice.waitReady.countDown();
} else {
Log.e(TAG, "UNKNOW CHARACT");
}
Expand Down

0 comments on commit 9972621

Please sign in to comment.