implemented mq properly

This commit is contained in:
Robin Müller 2021-04-08 20:53:54 +02:00
parent 9e881b6a16
commit 2b84ab018c
2 changed files with 7 additions and 19 deletions

View File

@ -64,9 +64,8 @@ ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessageIF* message) {
return MessageQueueIF::EMPTY; return MessageQueueIF::EMPTY;
} }
MutexGuard mutexLock(queueLock, MutexIF::TimeoutType::WAITING, 20); MutexGuard mutexLock(queueLock, MutexIF::TimeoutType::WAITING, 20);
MessageQueueMessage* currentMessage = &messageQueue.front(); std::copy(messageQueue.front().data(), messageQueue.front().data() + messageSize,
std::copy(currentMessage->getBuffer(), message->getBuffer());
currentMessage->getBuffer() + messageSize, message->getBuffer());
messageQueue.pop(); messageQueue.pop();
// The last partner is the first uint32_t field in the message // The last partner is the first uint32_t field in the message
this->lastPartner = message->getSender(); this->lastPartner = message->getSender();
@ -80,7 +79,7 @@ MessageQueueId_t MessageQueue::getLastPartner() const {
ReturnValue_t MessageQueue::flush(uint32_t* count) { ReturnValue_t MessageQueue::flush(uint32_t* count) {
*count = messageQueue.size(); *count = messageQueue.size();
// Clears the queue. // Clears the queue.
messageQueue = std::queue<MessageQueueMessage>(); messageQueue = std::queue<std::vector<uint8_t>>();
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
@ -132,20 +131,9 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo,
} }
if(targetQueue->messageQueue.size() < targetQueue->messageDepth) { if(targetQueue->messageQueue.size() < targetQueue->messageDepth) {
MutexGuard mutexLock(targetQueue->queueLock, MutexIF::TimeoutType::WAITING, 20); MutexGuard mutexLock(targetQueue->queueLock, MutexIF::TimeoutType::WAITING, 20);
// TODO: Would be nice to support other message types, but this would require targetQueue->messageQueue.push(std::vector<uint8_t>(message->getMaximumMessageSize()));
// create the message on the heap from an upper layer and simply storing memcpy(targetQueue->messageQueue.back().data(), message->getBuffer(),
// MessageQueueMessageIF pointers in the queue. message->getMaximumMessageSize());
MessageQueueMessage* mqmMessage = dynamic_cast<MessageQueueMessage*>(message);
if(mqmMessage != nullptr) {
targetQueue->messageQueue.push(*mqmMessage);
}
else {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "MessageQueue::sendMessageFromMessageQueue: Message"
"is not MessageQueueMessage!" << std::endl;
#endif
}
} }
else { else {
return MessageQueueIF::FULL; return MessageQueueIF::FULL;

View File

@ -212,7 +212,7 @@ protected:
//static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); //static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault);
private: private:
std::queue<MessageQueueMessage> messageQueue; std::queue<std::vector<uint8_t>> messageQueue;
/** /**
* @brief The class stores the queue id it got assigned. * @brief The class stores the queue id it got assigned.
* If initialization fails, the queue id is set to zero. * If initialization fails, the queue id is set to zero.