strings in queue

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

strings in queue

Postby burkulesomesh43 » 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.

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");
    }
}
--
Somesh Burkule

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: strings in queue

Postby WiFive » Mon Oct 15, 2018 7:07 am

Receive an item from a queue without removing the item from the queue.
https://www.freertos.org/xQueuePeek.html

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: strings in queue

Postby burkulesomesh43 » Mon Oct 15, 2018 7:11 am

WiFive wrote:
Receive an item from a queue without removing the item from the queue.
https://www.freertos.org/xQueuePeek.html
Ok. I got the point.
Is there any other method to receive an string from queue with removing string from queue?
--
Somesh Burkule

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: strings in queue

Postby WiFive » Mon Oct 15, 2018 7:15 am

XQueueReceive

You also have to free the allocated string

User avatar
loboris
Posts: 514
Joined: Wed Dec 21, 2016 7:40 pm

Re: strings in queue

Postby loboris » Mon Oct 15, 2018 7:21 am

Queue API is quite well documented.

sam@logic
Posts: 3
Joined: Thu Sep 27, 2018 6:01 am

Re: strings in queue

Postby sam@logic » Mon Oct 15, 2018 7:33 am

WiFive wrote:XQueueReceive

You also have to free the allocated string
its working now. thank you for your quick response.
I have one question now.
I am using queue length of 100 now as shown in below..
uint8_t* dataSerial = (uint8_t*) malloc(BUF);
xQueue = xQueueCreate( 100, sizeof(dataSerial));

so queue has to be full after sending 100 strings in queue. but it is not getting full.
see my output below..

value sent on queue: 367 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 368 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 369 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 123 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 370 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 371 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 372 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 124 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 373 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 374 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 375 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 125 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 376 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 377 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 378 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 126 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 379 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 380 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 381 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 127 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 382 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 383 ABCDEFGHIJKLMNOPQRSTUVWXYZ


Now how it is going to work.. I am not getting..
Last edited by sam@logic on Thu Nov 01, 2018 5:50 am, edited 1 time in total.

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: strings in queue

Postby burkulesomesh43 » Mon Oct 15, 2018 7:33 am

WiFive wrote:XQueueReceive

You also have to free the allocated string
its working now. thank you for your quick response.
I have one question now.
I am using queue length of 100 now as shown in below..
uint8_t* dataSerial = (uint8_t*) malloc(BUF);
xQueue = xQueueCreate( 100, sizeof(dataSerial));

so queue has to be full after sending 100 strings in queue. but it is not getting full.
see my output below..

value sent on queue: 367 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 368 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 369 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 123 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 370 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 371 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 372 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 124 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 373 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 374 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 375 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 125 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 376 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 377 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 378 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 126 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 379 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 380 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 381 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value received on queue: 127 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 382 ABCDEFGHIJKLMNOPQRSTUVWXYZ
value sent on queue: 383 ABCDEFGHIJKLMNOPQRSTUVWXYZ


Now how it is going to work.. I am not getting..
--
Somesh Burkule

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: strings in queue

Postby burkulesomesh43 » Mon Oct 15, 2018 7:35 am

loboris wrote:Queue API is quite well documented.
thanks.
--
Somesh Burkule

WiFive
Posts: 3529
Joined: Tue Dec 01, 2015 7:35 am

Re: strings in queue

Postby WiFive » Mon Oct 15, 2018 7:59 am

How would you know whether it is full if you don't check return code of xQueueSend

If you send 3 items for every 1 receive then it should be full after 150

burkulesomesh43
Posts: 132
Joined: Tue Aug 14, 2018 6:21 am
Location: India

Re: strings in queue

Postby burkulesomesh43 » Mon Oct 15, 2018 9:03 am

WiFive wrote:How would you know whether it is full if you don't check return code of xQueueSend

If you send 3 items for every 1 receive then it should be full after 150
Ok. got it.
what is maximum length of queue we can use.
is there any memory problem if we use maximum queue length or poblem on running tasks?
--
Somesh Burkule

Who is online

Users browsing this forum: bfredo123, Bing [Bot] and 57 guests