strings in queue
Posted: Mon Oct 15, 2018 6:42 am
Hi,
I want to send and recieve multiple strings to/from queue.
but as I send strings in queue one by one in one task and receive in other task, on recieve task it is only receiving first string that is sent on queue. I am not getting what is the problem. please help me out for this problem.
below is my code.
I want to send and recieve multiple strings to/from queue.
but as I send strings in queue one by one in one task and receive in other task, on recieve task it is only receiving first string that is sent on queue. I am not getting what is the problem. please help me out for this problem.
below is my code.
Code: Select all
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "freertos/queue.h"
#include "string.h"
#define BUF 1024
xQueueHandle xQueue;
void consumer_task(void *pvParameter)
{
char* rxmesage;
while(1){
if( xQueue != 0 ) {
if( (xQueuePeek( xQueue, &( rxmesage ), ( portTickType ) 10 )) == pdTRUE)
{
printf("value received on queue: %s \n",rxmesage);
vTaskDelay(1500/portTICK_PERIOD_MS); //wait for 500 ms
}
}
}
}
void producer_task(void *pvParameter){
char *mydata="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *repl_data="";
int count=0;
while(1){
asprintf(&repl_data,"%d %s",count,mydata);
printf("value sent on queue: %s \n",repl_data);
xQueueSend(xQueue,(void *)&repl_data,(TickType_t )0); // add the counter value to the queue
vTaskDelay(500/portTICK_PERIOD_MS); //wait for a second
count++;
}
}
void app_main()
{
uint8_t* dataSerial = (uint8_t*) malloc(BUF);
xQueue = xQueueCreate( 1, sizeof(dataSerial));
if(xQueue != NULL){
printf("Queue is created\n");
vTaskDelay(1000/portTICK_PERIOD_MS); //wait for a second
xTaskCreate(&producer_task,"producer_task",1024*4,NULL,5,NULL);
printf("producer task started\n");
xTaskCreate(&consumer_task,"consumer_task",1024*4,NULL,5,NULL);
printf("consumer task started\n");
}else{
printf("Queue creation failed");
}
}