Thank you Richard Barry.
I have try your answers and many others solution but nothing seems to work…
I make another example code with 10 different messages.
First, here is the code that uses a structure pointer that contains a variable and a char array:
~~~
/*Begining of Auto generated code by Atmel studio */
include <Arduino.h>
/*End of auto generated code by Atmel studio */
include <Arduino_FreeRTOS.h>
include <queue.h>
//Beginning of Auto generated function prototypes by Atmel Studio
//End of Auto generated function prototypes by Atmel Studio
// CHAR ARRAY POINTER ————————–
struct tabData {
int messsageID = 0;
//char* pData;
char pData[10] = {0};
};
struct tabData *pDataSend;
struct tabData *pDataReceive;
QueueHandle_t queue;
void setup() {
pDataSend = (struct tabData*)malloc(sizeof(struct tabData));
//pDataSend->pData = (char*)malloc(sizeof(char)*10);
pDataReceive = (struct tabData*)malloc(sizeof(struct tabData));
//pDataReceive->pData = (char*)malloc(sizeof(char)*10);
Serial.begin(115200);
queue = xQueueCreate( 10, sizeof(tabData) );
if(queue == NULL){
Serial.println(“Error creating the queue”);
}
}
void loop() {
if(queue == NULL)return;
for(int i = 0; i<10; i++){
pDataSend->messsageID = i;
switch(i) {
case 0:
strcpy(pDataSend->pData, “abcd”);
break;
case 1:
strcpy(pDataSend->pData, “efgh”);
break;
case 2:
strcpy(pDataSend->pData, “ijkl”);
break;
case 3:
strcpy(pDataSend->pData, “mnop”);
break;
case 4:
strcpy(pDataSend->pData, “qrst”);
break;
case 5:
strcpy(pDataSend->pData, “uvwx”);
break;
case 6:
strcpy(pDataSend->pData, “yz12”);
break;
case 7:
strcpy(pDataSend->pData, “3456”);
break;
case 8:
strcpy(pDataSend->pData, “7890”);
break;
case 9:
strcpy(pDataSend->pData, “Test”);
break;
default:
break;
}
xQueueSend(queue, pDataSend, portMAX_DELAY);
}
for(int j = 0; j<10; j++){
xQueueReceive(queue, pDataReceive, portMAX_DELAY);
Serial.print(pDataReceive->messsageID);
Serial.print(” | “);
Serial.print(pDataReceive->pData);
Serial.println();
}
Serial.println();
delay(1000);
}
~~~
this version works perfectly and I have the message ID and the message on the terminal in the good order:
~~~
0 | abcd
1 | efgh
2 | ijkl
3 | mnop
4 | qrst
5 | uvwx
6 | yz12
7 | 3456
8 | 7890
9 | Test
~~~
After that, I tried to make the same program, but using a char pointer instead of the array.
~~~
/*Begining of Auto generated code by Atmel studio */
include <Arduino.h>
/*End of auto generated code by Atmel studio */
include <Arduino_FreeRTOS.h>
include <queue.h>
//Beginning of Auto generated function prototypes by Atmel Studio
//End of Auto generated function prototypes by Atmel Studio
// CHAR ARRAY POINTER ————————–
struct tabData {
int messsageID = 0;
char* pData;
//char pData[10] = {0};
};
struct tabData *pDataSend;
struct tabData *pDataReceive;
QueueHandle_t queue;
void setup() {
pDataSend = (struct tabData*)malloc(sizeof(struct tabData));
pDataSend->pData = (char*)malloc(sizeof(char)*10);
pDataReceive = (struct tabData*)malloc(sizeof(struct tabData));
pDataReceive->pData = (char*)malloc(sizeof(char)*10);
Serial.begin(115200);
queue = xQueueCreate( 10, sizeof(tabData) );
if(queue == NULL){
Serial.println(“Error creating the queue”);
}
}
void loop() {
if(queue == NULL)return;
for(int i = 0; i<10; i++){
pDataSend->messsageID = i;
switch(i) {
case 0:
strcpy(pDataSend->pData, “abcd”);
break;
case 1:
strcpy(pDataSend->pData, “efgh”);
break;
case 2:
strcpy(pDataSend->pData, “ijkl”);
break;
case 3:
strcpy(pDataSend->pData, “mnop”);
break;
case 4:
strcpy(pDataSend->pData, “qrst”);
break;
case 5:
strcpy(pDataSend->pData, “uvwx”);
break;
case 6:
strcpy(pDataSend->pData, “yz12”);
break;
case 7:
strcpy(pDataSend->pData, “3456”);
break;
case 8:
strcpy(pDataSend->pData, “7890”);
break;
case 9:
strcpy(pDataSend->pData, “Test”);
break;
default:
break;
}
xQueueSend(queue, pDataSend, portMAX_DELAY);
}
for(int j = 0; j<10; j++){
xQueueReceive(queue, pDataReceive, portMAX_DELAY);
Serial.print(pDataReceive->messsageID);
Serial.print(” | “);
Serial.print(pDataReceive->pData);
Serial.println();
}
Serial.println();
delay(1000);
}
~~~
And this time, the teminal show this…
~~~
0 | Test
1 | Test
2 | Test
3 | Test
4 | Test
5 | Test
6 | Test
7 | Test
8 | Test
9 | Test
~~~
I don’t understand why there is the good ID but the message doesn’t change.
Sorry I do not have much experience with pointers of structures with pointers.
Thank you for your help.