From da3b2b2500592047335c689d8f7d9b9b15f60a86 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 25 Aug 2020 18:09:05 +0200 Subject: [PATCH] form improvements --- ipc/CommandMessage.cpp | 4 +- ipc/CommandMessage.h | 12 ++-- ipc/CommandMessageIF.h | 10 +-- ipc/MessageQueueIF.h | 111 ++++++++++++++++++++------------ ipc/MessageQueueMessage.cpp | 2 +- ipc/MessageQueueMessage.h | 6 +- ipc/MessageQueueMessageIF.h | 6 +- ipc/MutexHelper.h | 6 +- ipc/QueueFactory.h | 2 +- osal/FreeRTOS/MessageQueue.cpp | 10 +-- osal/FreeRTOS/MessageQueue.h | 113 ++++++++------------------------- 11 files changed, 125 insertions(+), 157 deletions(-) diff --git a/ipc/CommandMessage.cpp b/ipc/CommandMessage.cpp index 6934e6ce8..16293608d 100644 --- a/ipc/CommandMessage.cpp +++ b/ipc/CommandMessage.cpp @@ -1,5 +1,5 @@ -#include "../ipc/CommandMessage.h" -#include "../ipc/CommandMessageCleaner.h" +#include "CommandMessage.h" +#include "CommandMessageCleaner.h" #include CommandMessage::CommandMessage() { diff --git a/ipc/CommandMessage.h b/ipc/CommandMessage.h index 73b73dc91..3be9a1205 100644 --- a/ipc/CommandMessage.h +++ b/ipc/CommandMessage.h @@ -1,9 +1,9 @@ -#ifndef FRAMEWORK_IPC_COMMANDMESSAGE_H_ -#define FRAMEWORK_IPC_COMMANDMESSAGE_H_ +#ifndef FSFW_IPC_COMMANDMESSAGE_H_ +#define FSFW_IPC_COMMANDMESSAGE_H_ -#include "../ipc/CommandMessageIF.h" -#include "../ipc/MessageQueueMessage.h" -#include "../ipc/FwMessageTypes.h" +#include "CommandMessageIF.h" +#include "MessageQueueMessage.h" +#include "FwMessageTypes.h" /** * @brief Default command message used to pass command messages between tasks. @@ -126,4 +126,4 @@ public: size_t getMinimumMessageSize() const override; }; -#endif /* COMMANDMESSAGE_H_ */ +#endif /* FSFW_IPC_COMMANDMESSAGE_H_ */ diff --git a/ipc/CommandMessageIF.h b/ipc/CommandMessageIF.h index e5f962aec..68a8d9564 100644 --- a/ipc/CommandMessageIF.h +++ b/ipc/CommandMessageIF.h @@ -1,8 +1,8 @@ -#ifndef FRAMEWORK_IPC_COMMANDMESSAGEIF_H_ -#define FRAMEWORK_IPC_COMMANDMESSAGEIF_H_ +#ifndef FSFW_IPC_COMMANDMESSAGEIF_H_ +#define FSFW_IPC_COMMANDMESSAGEIF_H_ -#include "../ipc/MessageQueueMessageIF.h" -#include "../ipc/FwMessageTypes.h" +#include "MessageQueueMessageIF.h" +#include "FwMessageTypes.h" #include "../returnvalues/HasReturnvaluesIF.h" #define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number)) @@ -70,4 +70,4 @@ public: }; -#endif /* FRAMEWORK_IPC_COMMANDMESSAGEIF_H_ */ +#endif /* FSFW_IPC_COMMANDMESSAGEIF_H_ */ diff --git a/ipc/MessageQueueIF.h b/ipc/MessageQueueIF.h index 6ae852eae..1e80f7bd5 100644 --- a/ipc/MessageQueueIF.h +++ b/ipc/MessageQueueIF.h @@ -1,5 +1,5 @@ -#ifndef FRAMEWORK_IPC_MESSAGEQUEUEIF_H_ -#define FRAMEWORK_IPC_MESSAGEQUEUEIF_H_ +#ifndef FSFW_IPC_MESSAGEQUEUEIF_H_ +#define FSFW_IPC_MESSAGEQUEUEIF_H_ // COULDDO: We could support blocking calls // semaphores are being implemented, which makes this idea even more iteresting. @@ -30,21 +30,28 @@ public: virtual ~MessageQueueIF() {} /** * @brief This operation sends a message to the last communication partner. - * @details This operation simplifies answering an incoming message by using the stored - * lastParnter information as destination. If there was no message received yet - * (i.e. lastPartner is zero), an error code is returned. - * @param message A pointer to a previously created message, which is sent. - * @return RETURN_OK if ok - * @return NO_REPLY_PARTNER Should return NO_REPLY_PARTNER if partner was found + * @details + * This operation simplifies answering an incoming message by using the + * stored lastParnter information as destination. If there was no message + * received yet (i.e. lastPartner is zero), an error code is returned. + * @param message + * A pointer to a previously created message, which is sent. + * @return + * -@c RETURN_OK if ok + * -@c NO_REPLY_PARTNER Should return NO_REPLY_PARTNER if partner was found. */ - virtual ReturnValue_t reply( MessageQueueMessageIF* message ) = 0; + virtual ReturnValue_t reply(MessageQueueMessageIF* message) = 0; /** - * @brief This function reads available messages from the message queue and returns the sender. - * @details It works identically to the other receiveMessage call, but in addition returns the - * sender's queue id. - * @param message A pointer to a message in which the received data is stored. - * @param receivedFrom A pointer to a queue id in which the sender's id is stored. + * @brief This function reads available messages from the message queue + * and returns the sender. + * @details + * It works identically to the other receiveMessage call, but in addition + * returns the sender's queue id. + * @param message + * A pointer to a message in which the received data is stored. + * @param receivedFrom + * A pointer to a queue id in which the sender's id is stored. */ virtual ReturnValue_t receiveMessage(MessageQueueMessageIF* message, MessageQueueId_t *receivedFrom) = 0; @@ -57,7 +64,8 @@ public: * information is stored in theblastPartner attribute. Else, the lastPartner * information remains untouched, the message's content is cleared and the * function returns immediately. - * @param message A pointer to a message in which the received data is stored. + * @param message + * A pointer to a message in which the received data is stored. * @return -@c RETURN_OK on success * -@c MessageQueueIF::EMPTY if queue is empty */ @@ -69,24 +77,33 @@ public: */ virtual ReturnValue_t flush(uint32_t* count) = 0; /** - * @brief This method returns the message queue id of the last communication partner. + * @brief This method returns the message queue + * id of the last communication partner. */ virtual MessageQueueId_t getLastPartner() const = 0; /** - * @brief This method returns the message queue id of this class's message queue. + * @brief This method returns the message queue + * id of this class's message queue. */ virtual MessageQueueId_t getId() const = 0; /** - * @brief With the sendMessage call, a queue message is sent to a receiving queue. - * @details This method takes the message provided, adds the sentFrom information and passes - * it on to the destination provided with an operating system call. The OS's return - * value is returned. - * @param sendTo This parameter specifies the message queue id to send the message to. - * @param message This is a pointer to a previously created message, which is sent. - * @param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. - * This variable is set to zero by default. - * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full (if implemented). + * @brief With the sendMessage call, a queue message + * is sent to a receiving queue. + * @details + * This method takes the message provided, adds the sentFrom information + * and passes it on to the destination provided with an operating system + * call. The OS's returnvalue is returned. + * @param sendTo + * This parameter specifies the message queue id to send the message to. + * @param message + * This is a pointer to a previously created message, which is sent. + * @param sentFrom + * The sentFrom information can be set to inject the sender's queue id + * into the message. This variable is set to zero by default. + * @param ignoreFault + * If set to true, the internal software fault counter is not incremented + * if queue is full (if implemented). * @return -@c RETURN_OK on success * -@c MessageQueueIF::FULL if queue is full */ @@ -96,21 +113,31 @@ public: /** * @brief This operation sends a message to the given destination. - * @details It directly uses the sendMessage call of the MessageQueueSender parent, but passes its - * queue id as "sentFrom" parameter. - * @param sendTo This parameter specifies the message queue id of the destination message queue. - * @param message A pointer to a previously created message, which is sent. - * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. + * @details + * It directly uses the sendMessage call of the MessageQueueSender parent, + * but passes its queue id as "sentFrom" parameter. + * @param sendTo + * This parameter specifies the message queue id of the destination + * message queue. + * @param message + * A pointer to a previously created message, which is sent. + * @param ignoreFault + * If set to true, the internal software fault counter is not incremented + * if queue is full. */ virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessageIF* message, bool ignoreFault = false ) = 0; /** - * @brief The sendToDefaultFrom method sends a queue message to the default destination. - * @details In all other aspects, it works identical to the sendMessage method. - * @param message This is a pointer to a previously created message, which is sent. - * @param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. - * This variable is set to zero by default. + * @brief The sendToDefaultFrom method sends a queue message + * to the default destination. + * @details + * In all other aspects, it works identical to the sendMessage method. + * @param message + * This is a pointer to a previously created message, which is sent. + * @param sentFrom + * The sentFrom information can be set to inject the sender's queue id + * into the message. This variable is set to zero by default. * @return -@c RETURN_OK on success * -@c MessageQueueIF::FULL if queue is full */ @@ -118,19 +145,21 @@ public: MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0; /** * @brief This operation sends a message to the default destination. - * @details As in the sendMessage method, this function uses the sendToDefault call of the - * Implementation class and adds its queue id as "sentFrom" information. + * @details + * As in the sendMessage method, this function uses the sendToDefault + * call of the Implementation class and adds its queue id as + * "sentFrom" information. * @param message A pointer to a previously created message, which is sent. * @return -@c RETURN_OK on success * -@c MessageQueueIF::FULL if queue is full */ virtual ReturnValue_t sendToDefault( MessageQueueMessageIF* message ) = 0; /** - * \brief This method is a simple setter for the default destination. + * @brief This method is a simple setter for the default destination. */ virtual void setDefaultDestination(MessageQueueId_t defaultDestination) = 0; /** - * \brief This method is a simple getter for the default destination. + * @brief This method is a simple getter for the default destination. */ virtual MessageQueueId_t getDefaultDestination() const = 0; @@ -139,4 +168,4 @@ public: -#endif /* FRAMEWORK_IPC_MESSAGEQUEUEIF_H_ */ +#endif /* FSFW_IPC_MESSAGEQUEUEIF_H_ */ diff --git a/ipc/MessageQueueMessage.cpp b/ipc/MessageQueueMessage.cpp index d00321297..2f79cb3b9 100644 --- a/ipc/MessageQueueMessage.cpp +++ b/ipc/MessageQueueMessage.cpp @@ -1,4 +1,4 @@ -#include "../ipc/MessageQueueMessage.h" +#include "MessageQueueMessage.h" #include "../serviceinterface/ServiceInterfaceStream.h" #include "../globalfunctions/arrayprinter.h" #include diff --git a/ipc/MessageQueueMessage.h b/ipc/MessageQueueMessage.h index cf06fde62..da5c78cb8 100644 --- a/ipc/MessageQueueMessage.h +++ b/ipc/MessageQueueMessage.h @@ -1,5 +1,5 @@ -#ifndef FRAMEWORK_IPC_MESSAGEQUEUEMESSAGE_H_ -#define FRAMEWORK_IPC_MESSAGEQUEUEMESSAGE_H_ +#ifndef FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ +#define FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ #include "../ipc/MessageQueueMessageIF.h" #include "../ipc/MessageQueueSenderIF.h" @@ -147,4 +147,4 @@ public: void print(bool printWholeMessage); }; -#endif /* MESSAGEQUEUEMESSAGE_H_ */ +#endif /* FSFW_IPC_MESSAGEQUEUEMESSAGE_H_ */ diff --git a/ipc/MessageQueueMessageIF.h b/ipc/MessageQueueMessageIF.h index c6c677c1e..91753ced9 100644 --- a/ipc/MessageQueueMessageIF.h +++ b/ipc/MessageQueueMessageIF.h @@ -29,8 +29,10 @@ public: /** * @brief With this method, the whole content and the message - * size is set to zero. Implementations should also take care - * to clear data which is stored indirectly (e.g. storage data). + * size is set to zero. + * @details + * Implementations should also take care to clear data which is stored + * indirectly (e.g. storage data). */ virtual void clear() = 0; diff --git a/ipc/MutexHelper.h b/ipc/MutexHelper.h index 31d8d9ecb..97e280072 100644 --- a/ipc/MutexHelper.h +++ b/ipc/MutexHelper.h @@ -1,7 +1,7 @@ #ifndef FRAMEWORK_IPC_MUTEXHELPER_H_ #define FRAMEWORK_IPC_MUTEXHELPER_H_ -#include "../ipc/MutexFactory.h" +#include "MutexFactory.h" #include "../serviceinterface/ServiceInterfaceStream.h" class MutexHelper { @@ -16,8 +16,8 @@ public: << timeoutMs << " milliseconds!" << std::endl; } else if(status != HasReturnvaluesIF::RETURN_OK){ - sif::error << "MutexHelper: Lock of Mutex failed with code " << - status << std::endl; + sif::error << "MutexHelper: Lock of Mutex failed with code " + << status << std::endl; } } diff --git a/ipc/QueueFactory.h b/ipc/QueueFactory.h index 8141a3cf2..e98919877 100644 --- a/ipc/QueueFactory.h +++ b/ipc/QueueFactory.h @@ -1,7 +1,7 @@ #ifndef FRAMEWORK_IPC_QUEUEFACTORY_H_ #define FRAMEWORK_IPC_QUEUEFACTORY_H_ -#include "../ipc/MessageQueueIF.h" +#include "MessageQueueIF.h" #include /** * Creates message queues. diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 933689e83..e3e0ef1c1 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -1,4 +1,4 @@ -#include "../../osal/FreeRTOS/MessageQueue.h" +#include "MessageQueue.h" #include "../../serviceinterface/ServiceInterfaceStream.h" @@ -10,13 +10,13 @@ MessageQueue::MessageQueue(size_t messageDepth, size_t maxMessageSize): maxMessageSize(maxMessageSize) { handle = xQueueCreate(messageDepth, maxMessageSize); - if (handle == NULL) { - sif::error << "MessageQueue: Creation failed" << std::endl; + if (handle == nullptr) { + sif::error << "MessageQueue::MessageQueue Creation failed" << std::endl; } } MessageQueue::~MessageQueue() { - if (handle != NULL) { + if (handle != nullptr) { vQueueDelete(handle); } } @@ -126,7 +126,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, BaseType_t result = pdFALSE; QueueHandle_t destination = nullptr; - if(sendTo == MessageQueueIF::NO_QUEUE) { + if(sendTo == MessageQueueIF::NO_QUEUE or sendTo == 0x00) { return MessageQueueIF::DESTINVATION_INVALID; } else { diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index 48a5ab6a6..11986751e 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -1,5 +1,5 @@ -#ifndef MESSAGEQUEUE_H_ -#define MESSAGEQUEUE_H_ +#ifndef FSFW_OSAL_FREERTOS_MESSAGEQUEUE_H_ +#define FSFW_OSAL_FREERTOS_MESSAGEQUEUE_H_ #include "../../internalError/InternalErrorReporterIF.h" #include "../../ipc/MessageQueueIF.h" @@ -43,11 +43,12 @@ public: /** * @brief The constructor initializes and configures the message queue. * @details - * By making use of the according operating system call, a message queue is created - * and initialized. The message depth - the maximum number of messages to be - * buffered - may be set with the help of a parameter, whereas the message size is - * automatically set to the maximum message queue message size. The operating system - * sets the message queue id, or i case of failure, it is set to zero. + * By making use of the according operating system call, a message queue + * is created and initialized. The message depth - the maximum number of + * messages to be buffered - may be set with the help of a parameter, + * whereas the message size is automatically set to the maximum message + * queue message size. The operating system sets the message queue id, or + * in case of failure, it is set to zero. * @param message_depth * The number of messages to be buffered before passing an error to the * sender. Default is three. @@ -76,103 +77,39 @@ public: */ void switchSystemContext(CallContext callContext); - /** - * @brief This operation sends a message to the given destination. - * @details It directly uses the sendMessage call of the MessageQueueSender parent, but passes its - * queue id as "sentFrom" parameter. - * @param sendTo This parameter specifies the message queue id of the destination message queue. - * @param message A pointer to a previously created message, which is sent. - * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. - */ + /** MessageQueueIF implementation */ ReturnValue_t sendMessage(MessageQueueId_t sendTo, MessageQueueMessageIF* message, bool ignoreFault = false) override; - /** - * @brief This operation sends a message to the default destination. - * @details As in the sendMessage method, this function uses the sendToDefault call of the - * MessageQueueSender parent class and adds its queue id as "sentFrom" information. - * @param message A pointer to a previously created message, which is sent. - */ - ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override; - /** - * @brief This operation sends a message to the last communication partner. - * @details This operation simplifies answering an incoming message by using the stored - * lastParnter information as destination. If there was no message received yet - * (i.e. lastPartner is zero), an error code is returned. - * @param message A pointer to a previously created message, which is sent. - */ - ReturnValue_t reply(MessageQueueMessageIF* message) override; - /** - * @brief With the sendMessage call, a queue message is sent to a receiving queue. - * @details This method takes the message provided, adds the sentFrom information and passes - * it on to the destination provided with an operating system call. The OS's return - * value is returned. - * @param sendTo This parameter specifies the message queue id to send the message to. - * @param message This is a pointer to a previously created message, which is sent. - * @param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. - * This variable is set to zero by default. - * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. - */ + ReturnValue_t sendToDefault(MessageQueueMessageIF* message) override; + + ReturnValue_t reply(MessageQueueMessageIF* message) override; virtual ReturnValue_t sendMessageFrom(MessageQueueId_t sendTo, MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false) override; - /** - * @brief The sendToDefault method sends a queue message to the default destination. - * @details In all other aspects, it works identical to the sendMessage method. - * @param message This is a pointer to a previously created message, which is sent. - * @param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. - * This variable is set to zero by default. - */ virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessageIF* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false) override; - /** - * @brief This function reads available messages from the message queue and returns the sender. - * @details It works identically to the other receiveMessage call, but in addition returns the - * sender's queue id. - * @param message A pointer to a message in which the received data is stored. - * @param receivedFrom A pointer to a queue id in which the sender's id is stored. - */ ReturnValue_t receiveMessage(MessageQueueMessageIF* message, MessageQueueId_t *receivedFrom) override; - /** - * @brief This function reads available messages from the message queue. - * @details If data is available it is stored in the passed message pointer. The message's - * original content is overwritten and the sendFrom information is stored in the - * lastPartner attribute. Else, the lastPartner information remains untouched, the - * message's content is cleared and the function returns immediately. - * @param message A pointer to a message in which the received data is stored. - */ ReturnValue_t receiveMessage(MessageQueueMessageIF* message) override; - /** - * Deletes all pending messages in the queue. - * @param count The number of flushed messages. - * @return RETURN_OK on success. - */ - ReturnValue_t flush(uint32_t* count); - /** - * @brief This method returns the message queue id of the last communication partner. - */ - MessageQueueId_t getLastPartner() const; - /** - * @brief This method returns the message queue id of this class's message queue. - */ - MessageQueueId_t getId() const; - /** - * @brief This method is a simple setter for the default destination. - */ - void setDefaultDestination(MessageQueueId_t defaultDestination); - /** - * @brief This method is a simple getter for the default destination. - */ - MessageQueueId_t getDefaultDestination() const; + ReturnValue_t flush(uint32_t* count) override; + + MessageQueueId_t getLastPartner() const override; + + MessageQueueId_t getId() const override; + + void setDefaultDestination(MessageQueueId_t defaultDestination) override; + + MessageQueueId_t getDefaultDestination() const override; + + bool isDefaultDestinationSet() const override; - bool isDefaultDestinationSet() const; protected: /** * @brief Implementation to be called from any send Call within @@ -205,8 +142,8 @@ private: MessageQueueId_t defaultDestination = 0; MessageQueueId_t lastPartner = 0; const size_t maxMessageSize; - //!< Stores the current system context + //! Stores the current system context CallContext callContext = CallContext::TASK; }; -#endif /* MESSAGEQUEUE_H_ */ +#endif /* FSFW_OSAL_FREERTOS_MESSAGEQUEUE_H_ */