Set the wait timeout for missing indication acknowledgment#825
Merged
Conversation
hathach
approved these changes
May 6, 2026
Member
hathach
left a comment
There was a problem hiding this comment.
look good, thank you. I slightly rename it to make it more consistent.
Contributor
There was a problem hiding this comment.
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) inwaitForIndicateConfirm()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); |
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); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.