I have a task running, on a dedicated core, whose sole responsibility is to monitor a queue, pull items off of the queue and act upon the instructions contained therein (it’s not important what it’s actually doing, but for the sake of completeness, let’s imagine that the instructions are for displaying messages on an OLED display)
The structure of the object going onto the queue is as follows
struct MessageInfo
{
private:
char _message[64];
public:
const TickType_t period = 0;
const line_positions position;
const display_properties properties;
const uint message_length = 0;
const char * message = nullptr;
MessageInfo() : position(NO_POSITION), properties(NO_PROPERTY) { }
MessageInfo(TickType_t period_)
: period(period_), position(NO_POSITION), properties(WAIT) { }
MessageInfo(line_positions position_, display_properties properties_, const char * message_, uint length)
: position(position_), properties(properties_), message_length(length)
{
if(length == 0) { return; }
strcpy(_message, message_);
message = &_message[0];
}
};
The API is essentially a disconnected Facade to the OLED controls and as such exposes methods for writing to the OLED display, one such method might be:
void Gsdc_SSD1306::scrollToCenter(line_positions position, String message)
{
MessageInfo info(position, SCROLL_TO_CENTER, message.c_str(), message.length());
xQueueSendToBack(_messageQueue, (void *)&info, portMAX_DELAY);
}
The point behind this is so that instructions can be sent to the OLED display which are themselves executed asynchronously so that the main program can continue with it’s processing unhindered.
The task which runs on another core thus …
xTaskCreatePinnedToCore(messageTask, "MSG_TSK", 20480, (void *)_taskServices, 2, NULL, 1);
Will then take items from the queue and process them:
void messageTask(void * parameter)
{
task_data data = *((task_data *)parameter);
for( ;; )
{
MessageInfo currentMessage;
MessageInfo peekMessage;
if(xQueueReceive(data.messageQueue, ¤tMessage, (TickType_t) 10) == pdPASS)
{
data.set_running();
Message message(¤tMessage, data.display);
while(!message.display()){ vTaskDelay(1);}
if(!xQueuePeek(data.messageQueue, &peekMessage, (TickType_t) 10))
data.set_stopped();
}
}
}
The issue that I am experiencing is that when the MessageInfo
is copied from the queue and into my currentMessage
, upon inspection the only value which is as expected is MessageInfo::message
, i.e. the values for members MessageInfo::properties
, MessageInfo::position
and MessageInfo::message_length
bear no resemblance to the values which were submitted.
I’m pretty certain that it’s something I’m doing (or not), but I am currently at a loss as to what the issue might be!