Skip to content

Set the wait timeout for missing indication acknowledgment#825

Merged
hathach merged 7 commits into
adafruit:masterfrom
AndreasLamparter:master
May 6, 2026
Merged

Set the wait timeout for missing indication acknowledgment#825
hathach merged 7 commits into
adafruit:masterfrom
AndreasLamparter:master

Conversation

@AndreasLamparter
Copy link
Copy Markdown
Contributor

The wait timeout for indication acknowledgment is infinite.

With this, you can set a defined wait timeout on each connection for missing acknowledgment packages.

This resolves #772, which caused freezing on BLE indication when going out of range during transmission.

Copilot AI review requested due to automatic review settings May 6, 2026 08:29
Copy link
Copy Markdown
Member

@hathach hathach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

look good, thank you. I slightly rename it to make it more consistent.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a per-connection timeout for waiting on BLE indication confirmations (HVC), addressing freezes when the peer goes out of range mid-transmission (issue #772).

Changes:

  • Add a configurable indication-confirm (HVC) wait timeout to BLEConnection.
  • Replace the previously-infinite wait (portMAX_DELAY) in waitForIndicateConfirm() with the configured timeout.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
libraries/Bluefruit52Lib/src/BLEConnection.h Adds a new per-connection timeout member and public setter declaration.
libraries/Bluefruit52Lib/src/BLEConnection.cpp Initializes the timeout, implements the setter, and uses the timeout in waitForIndicateConfirm().

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 295 to 304
bool BLEConnection::waitForIndicateConfirm(void)
{
// on the fly semaphore
_hvc_sem = xSemaphoreCreateBinary();

_hvc_received = false;
xSemaphoreTake(_hvc_sem, portMAX_DELAY);
xSemaphoreTake(_hvc_sem, _indicate_confirm_timeout);

vSemaphoreDelete(_hvc_sem);
_hvc_sem = NULL;

void BLEConnection::setIndicateConfirmTimeout(uint32_t timeout_ms)
{
_indicate_confirm_timeout = pdMS_TO_TICKS(timeout_ms);
Comment on lines 297 to 303
// on the fly semaphore
_hvc_sem = xSemaphoreCreateBinary();

_hvc_received = false;
xSemaphoreTake(_hvc_sem, portMAX_DELAY);
xSemaphoreTake(_hvc_sem, _indicate_confirm_timeout);

vSemaphoreDelete(_hvc_sem);
bool saveCccd(void);
bool loadCccd(void);

bool loadCccd(void);
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

Comment on lines 297 to 310
// Lazy-allocate once per connection and reuse. Avoids a create/delete race
// with the BLE event handler that may give the semaphore on HVC/timeout.
if (_hvc_sem == NULL)
{
_hvc_sem = xSemaphoreCreateBinary();
if (_hvc_sem == NULL) return false;
}

_hvc_received = false;
xSemaphoreTake(_hvc_sem, portMAX_DELAY);
// Drain any stale signal left from a previous call (e.g. late HVC after timeout)
xSemaphoreTake(_hvc_sem, 0);

vSemaphoreDelete(_hvc_sem);
_hvc_sem = NULL;
_hvc_received = false;
xSemaphoreTake(_hvc_sem, _indicate_confirm_timeout);

Comment on lines +290 to +293
void BLEConnection::setIndicateConfirmTimeout(uint32_t timeout_ms)
{
_indicate_confirm_timeout = (timeout_ms == portMAX_DELAY) ? portMAX_DELAY : pdMS_TO_TICKS(timeout_ms);
}
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

Comment thread libraries/Bluefruit52Lib/src/BLEConnection.cpp
Comment thread libraries/Bluefruit52Lib/src/BLEConnection.h
Comment thread libraries/Bluefruit52Lib/src/BLEConnection.h
Comment thread libraries/Bluefruit52Lib/src/BLEConnection.cpp
@hathach hathach merged commit a0aad47 into adafruit:master May 6, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Freezing on BLE indicate when goes out of range when transmitting

3 participants