enhance indicat API() to wait for confirm or timeout from peer.

This commit is contained in:
hathach committed 2018-01-30 14:27:38 +07:00
1 parent fc2e3603c8
commit 9e0a6ff775
4 files changed
+68 -43

No files matched your search

@@ -619,7 +619,9 @@ bool BLECharacteristic::indicate(const void* data, uint16_t len)
if ( indicateEnabled() )
{
uint16_t const max_payload = Bluefruit.Gap.getMTU( Bluefruit.connHandle() ) - 3;
uint16_t conn_hdl = Bluefruit.connHandle();
uint16_t const max_payload = Bluefruit.Gap.getMTU( conn_hdl ) - 3;
const uint8_t* u8data = (const uint8_t*) data;
while ( remaining )
@@ -636,16 +638,10 @@ bool BLECharacteristic::indicate(const void* data, uint16_t len)
};
LOG_LV2("CHR", "Indicate %d bytes", packet_len);
err_t err;
// If previous indicate is still in progress, wait for a while and try again
while ( NRF_ERROR_BUSY == (err = sd_ble_gatts_hvx(Bluefruit.connHandle(), &hvx_params)) )
{
// TODO should wait for BLE_GATTS_EVT_HVC event
delay( Bluefruit.connInterval() );
}
VERIFY_STATUS( err, false );
// Blocking wait until receiving confirmation from peer
VERIFY_STATUS( sd_ble_gatts_hvx( conn_hdl, &hvx_params), false );
VERIFY ( Bluefruit.Gatt.waitForIndicateConfirm(conn_hdl) );
remaining -= packet_len;
u8data += packet_len;