Hi
I am using ble_app_uart code from ble_peripheral folder and nrf_connect app to receive/send data.
I have interfaced external sensor with UART pins and receiving data from it over nrf_connect app too.
Now,when I am sending different commands from mobile(mobile->command->ble->pca10040->uart) I expect ack for that command from from my sensor (sensor->ack->uart->pca10040->ble->mobile).
I receive ack of 1 byte ,sometimes 4 bytes or 6 bytes from sensor.
Hence if I set (index >= 1)) I only receive 1st byte of 4 bytes ack. or when I set (index >= 6) I don't receive any bytes of 4 bytes ack because I have set limit of 6.
How can I generalize this condition so that even I get ack of 1 byte or 6 bytes or whatever size I should able to read it over mobile./ or print it on terminal
Below is my code.
Thanks in advance
.void uart_event_handle(app_uart_evt_t * p_event)
{
static uint8_t data_array[BLE_NUS_MAX_DATA_LEN];
static uint8_t index = 0;
uint32_t err_code;
char temp_str[40];
switch (p_event->evt_type)
{
case APP_UART_DATA_READY:
UNUSED_VARIABLE(app_uart_get(&data_array[index]));
index++;
if ((data_array[index - 1] == '\n') ||
(data_array[index - 1] == '\r') ||
(index >= 6))
{
if (index > 0)
{
NRF_LOG_INFO("Ready to send data over BLE NUS");
// NRF_LOG_DEBUG("Ready to send data over BLE NUS");
NRF_LOG_HEXDUMP_DEBUG(data_array, index);
do
{
uint16_t length = (uint16_t)index;
err_code = ble_nus_data_send(&m_nus, data_array, &length, m_conn_handle);
if ((err_code != NRF_ERROR_INVALID_STATE) &&
(err_code != NRF_ERROR_RESOURCES) &&
(err_code != NRF_ERROR_NOT_FOUND))
{
APP_ERROR_CHECK(err_code);
}
} while (err_code == NRF_ERROR_RESOURCES);
}
index = 0;
}
break;