Sending large amount of data to queue very fast

zazas321
Posts: 231
Joined: Mon Feb 01, 2021 9:41 am

Sending large amount of data to queue very fast

Postby zazas321 » Fri Nov 12, 2021 7:59 am

Hello. I have a problem when I try to send a lot of data to the FreeRTOS queue. My functions:

Code: Select all


static void BLE_parser_task(void *argument)
{
    ble_message_s data_received;
    for(;;)
    {   
        if (xQueueReceive(ble_parser_queue, &data_received, 0) == pdTRUE) {
            esp_ble_gatts_send_indicate(data_received.gatt_if, data_received.conn_id, heart_rate_handle_table[HRS_IDX_HR_CTNL_PT_VAL],data_received.length, data_received.payload, false);
            free(data_received.payload);
        }
        vTaskDelay(10/portTICK_PERIOD_MS);
    }
}






void BLE_send_many_packets(void* param){
ble_message_s message = *(ble_message_s*)param;
printf("conn id  after creating a task = %u \n",message.conn_id);
    for(;;)
    {   
        for(int i = 0; i<100; i++){
            printf("packet = %u\n",i);
            uint8_t* ptr;
            ptr = (uint8_t*)malloc((2)* sizeof(uint8_t));
            ptr[0] = i >>8;
            ptr[1] = i & 0x00FF;
            message.payload = ptr;
            message.length = 2;
            if (xQueueSend(ble_parser_queue,&message, 10) != pdTRUE) {
                printf("ERROR: Could not put item on delay queue.");
            }
            vTaskDelay(10/portTICK_PERIOD_MS);
        }
        printf("all data has been sent to queue \n");
        vTaskDelete(0);
    }
}


BLE_parser_task is running in the background and waiting for data to be sent to the queue.


BLE_send_many_packets task is a oneshot task that is created when BLE write event is triggered. After this event is triggered I send 100 BLE packets.


I think the issue is that I am sending faster than I am reading the data and sometimes I read the same value more than once. For example last 4 packets should be 0x60, 0x61, 0x62, 0x63 but instead it is 0x60, 0x63,0x63,0x63.
https://ibb.co/dtzvQ7t

Please could someone suggest me how can I fix this problem?

Who is online

Users browsing this forum: No registered users and 101 guests