This is a silly comment only for updating the official documentation. While xQueueSend() returns errQUEUE_FULL if the queue was full, the function xQueueReceive() returns pdFALSE:
Returns:
pdTRUE if an item was successfully received from the queue, otherwise pdFALSE.
Yes, errQUEUE_EMPTY and errQUEUE_FULL have the same value. My point is to be consistent all along the code: while in some places one tests against errQUEUE_FULL, in others one tests against pdFALSE. That’s weird and inconsistent.
Any reason to use pdFALSE instead of errQUEUE_EMPTY. A workaround is to test always against pdTRUE and all problems are gone.
I think the idea is that for a xQueueReceive() you could check for a ‘generic’ failure with pdFAIL, or check for the type of error that would actual occur with errQUEUE_EMPTY to document what the error was. And for a send, the actual error would be errQUEUE_FULL
If you see that, both defines using for error detection, in this case, if you want to receive something from queue, but it’s EMPTY you can’t get any of data → so it’s error (0).
If you want to write into the queue and it’s full, it’s FULL so you can’t write any data → so it’s error (0).
There is no sense to know queue is full when you want to read, because it’s can’t cause any of errors.
If you want to get number of items, you could use functions like: uxQueueMessagesWaiting().
Regards.
I mean detecting an error without implying the type (which will only be the queue was empty/full).
You can read and test for ‘any error’ or you can read and test if you got a ‘queue empty’ error. They both are the same error code as that is the only error there is.
Yes, I already know that. My point here is TO BE CONSISTENT! For Richard Barry the naming is very important (although the prefix ‘x’ is meaningless in so many situations). If I test against errQUEUE_FULL when using xQueueSend(), then it would be logical to test against errQUEUE_EMPTY when using xQueueReceive(), THAT’S CONSISTENCY!
What is the error code when you pass the wrong handler?
if( xQueueReceive( handler, &data, ( TickType_t ) 10 ) == pdFALSE)
{
// Are we here for a timeout or for something else?
// How do you know what is that "something else"?
}
else
{
// process the incoming data
}
Yes, consistancy would be to use pdFAIL everywhere or errQUEUE_FULL / errQUEUE_EMPTY. My guess is that the documentation is old (but still accurate) and some has been updated to more current practices.
That question of my own was following this comment:
You can’t set the same value to different errors; an empty queue is one thing, and passing the wrong handler is other thing, so you can’t use the value 0 for both. That’s what I wanted to point out. By the way the wrong handler former can’t be catched by configAssert() if the handler is assigned to a very different object (like a semaphore or timer) but it’s not NULL.