getting wrong values from xQueueReceive

User avatar
arunbm123
Posts: 96
Joined: Fri Feb 23, 2018 5:36 am

getting wrong values from xQueueReceive

Postby arunbm123 » Tue Mar 19, 2019 7:19 am

hello All,

Please find my Code below.
I am sending ibeacon data in queue using struct.
I have a field int rssi in struct
i am assigning rssi =scan_result->scan_rst.rssi;
After sending a struct in Queue I am able to get correct rssi
but After poping out the same struct...I am not getting correct rssi.
Other parameters like major and Minor are correct.
What could be error?

Code: Select all

struct AMessage {
	uint16_t major;
	uint16_t minor;
	int  rssi;
	uint16_t slno;
}xMessage;

xMessage.major	=major;
xMessage.minor	=minor;
xMessage.rssi    	=scan_result->scan_rst.rssi;
xMessage.slno		= i;

if (xQueueSendToFront(xQueue1, (void * ) &xMessage,  (TickType_t ) 0)) {
	ESP_LOGI(TAG, "RSSI of packet:%d dbm",	scan_result->scan_rst.rssi);
	ESP_LOGI(TAG,	"rssi=(%d)" , xMessage.rssi);

	struct AMessage pxMessage1;
	if (xQueueReceive( xQueue1, &pxMessage1, 0)){
		ESP_LOGI(TAG, "==pxMessage.rssi =%d : " ,  pxMessage1.rssi);
	}

}


jcsbanks
Posts: 305
Joined: Tue Mar 28, 2017 8:03 pm

Re: getting wrong values from xQueueReceive

Postby jcsbanks » Tue Mar 19, 2019 7:51 am

Are the send and receive in the same scope?

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: getting wrong values from xQueueReceive

Postby ESP_Sprite » Tue Mar 19, 2019 8:01 am

What code do you use to create your queue? Perhaps the item size there is too small.

User avatar
arunbm123
Posts: 96
Joined: Fri Feb 23, 2018 5:36 am

Re: getting wrong values from xQueueReceive

Postby arunbm123 » Tue Mar 19, 2019 8:05 am

hi
@ESP_Sprite
queue Creation code

Code: Select all

 xQueue1 = xQueueCreate(1000, sizeof(struct AMessage *) );
@jcsbanks
I didnt get what you meant scope ?
If you mean Scope Rules in C Programming , In my real application there are in different scope.

Since I was getting wrong values I thought of testing by placing the receiving code in same scope immediately after Sending to Queue
Only The rssi value I am getting wrong.

chegewara
Posts: 2364
Joined: Wed Jun 14, 2017 9:00 pm

Re: getting wrong values from xQueueReceive

Postby chegewara » Tue Mar 19, 2019 9:56 am

You are using example from freertos docs, but you have made one mistake.
Here you see that passed is reference to pxMessage, but pxMessage is type of pointer to struct:

Code: Select all

struct AMessage *pxMessage;
xQueueSendToFront( xQueue2, ( void * ) &pxMessage, ( TickType_t ) 0 );
In your code you are passing reference to structure, not to pointer, but you are creating queue with size of pointer:
xQueue1 = xQueueCreate(1000, sizeof(struct AMessage *) );
Try this (i may be wrong):
xQueue1 = xQueueCreate(1000, sizeof(struct AMessage ) );

User avatar
arunbm123
Posts: 96
Joined: Fri Feb 23, 2018 5:36 am

Re: getting wrong values from xQueueReceive

Postby arunbm123 » Tue Mar 19, 2019 10:24 am

hi chegewara,

I am following example given in esp doc

https://docs.espressif.com/projects/esp ... eueReceive

ESP_Sprite
Posts: 9730
Joined: Thu Nov 26, 2015 4:08 am

Re: getting wrong values from xQueueReceive

Postby ESP_Sprite » Tue Mar 19, 2019 12:37 pm

Chegewara is right here. The example pushes pointers into the queue, you are trying to push the entire structure into the queue. Your approach will work, but you should size the queue item size accordingly, as Chegewara indicated.

User avatar
arunbm123
Posts: 96
Joined: Fri Feb 23, 2018 5:36 am

Re: getting wrong values from xQueueReceive

Postby arunbm123 » Tue Mar 19, 2019 1:32 pm

Thanks folks

resolved Now !!!

Who is online

Users browsing this forum: aliarifat794, Bing [Bot] and 114 guests