I'm working on a program which sends 20 kb of data (sending 16 byte at a time) with one condition which is that indication should be enabled first. the first function checks if indication is enabled on characteristic before starting transfer. when when the transfer is on progress and I disable indication the whole system hang
what could be the issue.
1 : is it because im trying to disable / enable indication when sending is on progress
2 : is the function (1 one)which checks if indication is enabled incorrectly programmed)
3 :my function for waiting for indication answer is it correct???
4 : is there any way to activate indication manually (send command and run indication disable manually within my peripheral code)
I shouldn't lost any data so I'm using indication instead of notification.
static bool is_flash_data_indication_enabled(uint16_t conn_handle)
{
uint32_t err_code;
uint8_t cccd_value_buf[BLE_CCCD_VALUE_LEN];
ble_gatts_value_t value;
value.len = BLE_CCCD_VALUE_LEN;
value.offset = 0;
value.p_value = cccd_value_buf;
err_code = sd_ble_gatts_value_get(conn_handle, m.flash_data_char_handles.cccd_handle, &value);
if (err_code != NRF_SUCCESS) {
return false;
}
uint16_t cccd_value = uint16_decode(cccd_value_buf);
return (bool)((cccd_value & BLE_GATT_HVX_INDICATION) != 0);
}
if ((m.conn_handle != BLE_CONN_HANDLE_INVALID) && (is_flash_data_indication_enabled(m.conn_handle))) {
// send data
indication_pending = true;
do {
// send a buffer of 16 byte
err_code = ble_param_update(&m, FLASH_DATA, NULL, steps_store_characteristic_value);//update data on BLE
} while (err_code == BLE_ERROR_NO_TX_BUFFERS);
indication_timeout = 0;
while (indication_pending) {
app_sched_execute();
nrf_delay_ms(25);
if ((indication_timeout >= 80) || (err_code == NRF_ERROR_INVALID_STATE)) {
disconnected = true;
break;
}
}
}
static void on_ble_evt(ble_evt_t * p_ble_evt)
{
...
// indication
case BLE_GATTS_EVT_HVC:
indication_pending = false;
break;
....
}