Page 1 of 1

getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 7:19 am
by arunbm123
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);
	}

}


Re: getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 7:51 am
by jcsbanks
Are the send and receive in the same scope?

Re: getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 8:01 am
by ESP_Sprite
What code do you use to create your queue? Perhaps the item size there is too small.

Re: getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 8:05 am
by arunbm123
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.

Re: getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 9:56 am
by chegewara
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 ) );

Re: getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 10:24 am
by arunbm123
hi chegewara,

I am following example given in esp doc

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

Re: getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 12:37 pm
by ESP_Sprite
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.

Re: getting wrong values from xQueueReceive

Posted: Tue Mar 19, 2019 1:32 pm
by arunbm123
Thanks folks

resolved Now !!!