size check for message queue

This commit is contained in:
Robin Müller 2020-06-22 15:34:35 +02:00
parent 45a55044dd
commit 109fdad8b3
2 changed files with 10 additions and 2 deletions

View File

@ -7,7 +7,8 @@
// As a first step towards this, introduces system context variable which needs
// to be switched manually
// Haven't found function to find system context.
MessageQueue::MessageQueue(size_t messageDepth, size_t maxMessageSize) {
MessageQueue::MessageQueue(size_t messageDepth, size_t maxMessageSize):
maxMessageSize(maxMessageSize) {
handle = xQueueCreate(messageDepth, maxMessageSize);
if (handle == NULL) {
sif::error << "MessageQueue: Creation failed" << std::endl;
@ -124,6 +125,12 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
bool ignoreFault, CallContext callContext) {
message->setSender(sentFrom);
BaseType_t result;
if(message->getMaximumMessageSize() > maxMessageSize) {
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message size"
"too large for queue!" << std::endl;
return HasReturnvaluesIF::RETURN_FAILED;
}
if(callContext == CallContext::TASK) {
result = xQueueSendToBack(reinterpret_cast<QueueHandle_t>(sendTo),
static_cast<const void*>(message->getBuffer()), 0);

View File

@ -204,6 +204,7 @@ private:
QueueHandle_t handle;
MessageQueueId_t defaultDestination = 0;
MessageQueueId_t lastPartner = 0;
const size_t maxMessageSize;
//!< Stores the current system context
CallContext callContext = CallContext::TASK;
};