weliem / blessed-android

BLESSED, a Bluetooth Low Energy (BLE) library for Android
MIT License
556 stars 120 forks source link

Retry mechanism isn't working correctly #32

Closed mvdhorst closed 4 years ago

mvdhorst commented 4 years ago

I haven't used the pull requests yet, so that's why i'm posting it here. The retry mechanism starts a nextCommand, but nextCommand sets the retry count to 0, this should only set the retry count to 0 when it's not a retry message.

/**
 * Execute the next command in the subscribe queue.
 * A queue is used because the calls have to be executed sequentially.
 * If the read or write fails, the next command in the queue is executed.
 */
private void nextCommand() {
    // Make sure only one thread can execute this method
    synchronized (this) {
        // If there is still a command being executed then bail out
        if (commandQueueBusy) {
            return;
        }

        // Check if we still have a valid gatt object
        if (bluetoothGatt == null) {
            Timber.e("gatt is 'null' for peripheral '%s', clearing command queue", getAddress());
            commandQueue.clear();
            commandQueueBusy = false;
            return;
        }

        // Execute the next command in the queue
        final Runnable bluetoothCommand = commandQueue.peek();
        if (bluetoothCommand != null) {
            commandQueueBusy = true;

if(!isRetrying) nrTries = 0;

weliem commented 4 years ago

You are absolutely right! Fixed in 73d7281