How to send more than 20 bytes from central to peripheral ?
How to send more than 20 bytes from central to peripheral ?
Solution is long write and this is example of necessary part:
void on_ble_evt(ble_evt_t * p_ble_evt)
{
case BLE_EVT_USER_MEM_REQUEST:
mem_block.len = QUEUED_WRITE_BUFFER_SIZE;
mem_block.p_mem = &queued_write_buffer[0];
err_code = sd_ble_user_mem_reply(m_deufol.conn_handle, &mem_block);
//simple_uart_putstring("User mem request \r\n");
break;
case BLE_EVT_USER_MEM_RELEASE:
if ((p_ble_evt->evt.common_evt.params.user_mem_release.mem_block.p_mem == mem_block.p_mem)&&(p_ble_evt->evt.common_evt.params.user_mem_release.mem_block.len == mem_block.len))
{
//memory released do nothing.
//simple_uart_putstring("User mem released \r\n");
}
break;
case BLE_GATTC_EVT_WRITE_RSP:
if(m_deufol.conn_handle != BLE_CONN_HANDLE_INVALID)
{
uint8_t temp_data[BYTE_NUMBER];
if(p_ble_evt->evt.gattc_evt.params.write_rsp.handle == m_deufol.char_identification.handle
&& m_deufol.char_identification.uuid.uuid == BLE_DEUFOL_COMMON_CHAR_UUID)
{
if(p_ble_evt->evt.gattc_evt.gatt_status == BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL)
{
ble_gattc_write_params_t write_params;
write_params.handle = m_deufol.common_handles.value_handle;
write_params.len = 0;
write_params.write_op = BLE_GATT_OP_EXEC_WRITE_REQ;
write_params.offset = 0;
write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
write_params.p_value = NULL;
err_code = sd_ble_gattc_write(m_deufol.conn_handle, &write_params);
rsp_counter = 0;
}
else
{
if(p_ble_evt->evt.gattc_evt.params.write_rsp.write_op == BLE_GATT_OP_PREP_WRITE_REQ)
{
rsp_counter++;
if(p_ble_evt->evt.gattc_evt.gatt_status != BLE_GATT_STATUS_ATTERR_PREPARE_QUEUE_FULL)
{
ble_gattc_write_params_t write_params;
write_params.handle = m_deufol.common_handles.value_handle;
write_params.len = BYTE_NUMBER;
write_params.write_op = BLE_GATT_OP_PREP_WRITE_REQ;
write_params.offset = rsp_counter * BYTE_NUMBER;
write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
for(uint8_t index = 0;index < BYTE_NUMBER;index++)
temp_data[index] = write_array[rsp_counter * BYTE_NUMBER + index];
write_params.p_value = temp_data;
err_code = sd_ble_gattc_write(m_deufol.conn_handle, &write_params);
}
}
}
}
}
break;
}
call this function first:
uint32_t send_data(ble_deufol_t * p_deufol,uint16_t length,uint8_t * write_array)
{
uint8_t temp_data[BYTE_NUMBER];
for(uint8_t a = 0;a<BYTE_NUMBER;a++)
temp_data[a] = write_array[a];
ble_gattc_write_params_t write_params;
write_params.handle = p_deufol->common_handles.value_handle;
write_params.len = length;
write_params.write_op = BLE_GATT_OP_PREP_WRITE_REQ;
write_params.offset = 0;
write_params.flags = BLE_GATT_EXEC_WRITE_FLAG_PREPARED_WRITE;
write_params.p_value = data;
err_code = sd_ble_gattc_write(p_deufol->conn_handle, &write_params);
return err_code;
}
Count of sending data is depend on QUEUED_WRITE_BUFFER_SIZE. This value has to be larger than sending data. BYTE_NUMBER = 18