From 76d81b5b494686cd64378d333ce85fca50d09bd2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jan 2021 11:38:45 +0100 Subject: [PATCH 01/14] replaced tab by spaces --- action/ActionHelper.cpp | 164 ++++++++++++++-------------- action/ActionHelper.h | 176 +++++++++++++++--------------- action/ActionMessage.cpp | 86 +++++++-------- action/ActionMessage.h | 44 ++++---- action/CommandActionHelper.cpp | 188 ++++++++++++++++----------------- action/CommandActionHelper.h | 36 +++---- action/CommandsActionsIF.h | 28 ++--- action/HasActionsIF.h | 44 ++++---- action/SimpleActionHelper.cpp | 102 +++++++++--------- action/SimpleActionHelper.h | 30 +++--- 10 files changed, 449 insertions(+), 449 deletions(-) diff --git a/action/ActionHelper.cpp b/action/ActionHelper.cpp index 705b692bb..23c9d7329 100644 --- a/action/ActionHelper.cpp +++ b/action/ActionHelper.cpp @@ -6,120 +6,120 @@ ActionHelper::ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue) : - owner(setOwner), queueToUse(useThisQueue) { + owner(setOwner), queueToUse(useThisQueue) { } ActionHelper::~ActionHelper() { } ReturnValue_t ActionHelper::handleActionMessage(CommandMessage* command) { - if (command->getCommand() == ActionMessage::EXECUTE_ACTION) { - ActionId_t currentAction = ActionMessage::getActionId(command); - prepareExecution(command->getSender(), currentAction, - ActionMessage::getStoreId(command)); - return HasReturnvaluesIF::RETURN_OK; - } else { - return CommandMessage::UNKNOWN_COMMAND; - } + if (command->getCommand() == ActionMessage::EXECUTE_ACTION) { + ActionId_t currentAction = ActionMessage::getActionId(command); + prepareExecution(command->getSender(), currentAction, + ActionMessage::getStoreId(command)); + return HasReturnvaluesIF::RETURN_OK; + } else { + return CommandMessage::UNKNOWN_COMMAND; + } } ReturnValue_t ActionHelper::initialize(MessageQueueIF* queueToUse_) { - ipcStore = objectManager->get(objects::IPC_STORE); - if (ipcStore == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; - } - if(queueToUse_ != nullptr) { - setQueueToUse(queueToUse_); - } + ipcStore = objectManager->get(objects::IPC_STORE); + if (ipcStore == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + if(queueToUse_ != nullptr) { + setQueueToUse(queueToUse_); + } - return HasReturnvaluesIF::RETURN_OK; + return HasReturnvaluesIF::RETURN_OK; } void ActionHelper::step(uint8_t step, MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result) { - CommandMessage reply; - ActionMessage::setStepReply(&reply, commandId, step + STEP_OFFSET, result); - queueToUse->sendMessage(reportTo, &reply); + CommandMessage reply; + ActionMessage::setStepReply(&reply, commandId, step + STEP_OFFSET, result); + queueToUse->sendMessage(reportTo, &reply); } void ActionHelper::finish(MessageQueueId_t reportTo, ActionId_t commandId, ReturnValue_t result) { - CommandMessage reply; - ActionMessage::setCompletionReply(&reply, commandId, result); - queueToUse->sendMessage(reportTo, &reply); + CommandMessage reply; + ActionMessage::setCompletionReply(&reply, commandId, result); + queueToUse->sendMessage(reportTo, &reply); } void ActionHelper::setQueueToUse(MessageQueueIF* queue) { - queueToUse = queue; + queueToUse = queue; } void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, store_address_t dataAddress) { - const uint8_t* dataPtr = NULL; - size_t size = 0; - ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size); - if (result != HasReturnvaluesIF::RETURN_OK) { - CommandMessage reply; - ActionMessage::setStepReply(&reply, actionId, 0, result); - queueToUse->sendMessage(commandedBy, &reply); - return; - } - result = owner->executeAction(actionId, commandedBy, dataPtr, size); - ipcStore->deleteData(dataAddress); - if(result == HasActionsIF::EXECUTION_FINISHED) { - CommandMessage reply; - ActionMessage::setCompletionReply(&reply, actionId, result); - queueToUse->sendMessage(commandedBy, &reply); - } - if (result != HasReturnvaluesIF::RETURN_OK) { - CommandMessage reply; - ActionMessage::setStepReply(&reply, actionId, 0, result); - queueToUse->sendMessage(commandedBy, &reply); - return; - } + const uint8_t* dataPtr = NULL; + size_t size = 0; + ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size); + if (result != HasReturnvaluesIF::RETURN_OK) { + CommandMessage reply; + ActionMessage::setStepReply(&reply, actionId, 0, result); + queueToUse->sendMessage(commandedBy, &reply); + return; + } + result = owner->executeAction(actionId, commandedBy, dataPtr, size); + ipcStore->deleteData(dataAddress); + if(result == HasActionsIF::EXECUTION_FINISHED) { + CommandMessage reply; + ActionMessage::setCompletionReply(&reply, actionId, result); + queueToUse->sendMessage(commandedBy, &reply); + } + if (result != HasReturnvaluesIF::RETURN_OK) { + CommandMessage reply; + ActionMessage::setStepReply(&reply, actionId, 0, result); + queueToUse->sendMessage(commandedBy, &reply); + return; + } } ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, - ActionId_t replyId, SerializeIF* data, bool hideSender) { - CommandMessage reply; - store_address_t storeAddress; - uint8_t *dataPtr; - size_t maxSize = data->getSerializedSize(); - if (maxSize == 0) { - //No error, there's simply nothing to report. - return HasReturnvaluesIF::RETURN_OK; - } - size_t size = 0; - ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize, - &dataPtr); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - result = data->serialize(&dataPtr, &size, maxSize, - SerializeIF::Endianness::BIG); - if (result != HasReturnvaluesIF::RETURN_OK) { - ipcStore->deleteData(storeAddress); - return result; - } - // We don't need to report the objectId, as we receive REQUESTED data - // before the completion success message. - // True aperiodic replies need to be reported with - // another dedicated message. - ActionMessage::setDataReply(&reply, replyId, storeAddress); + ActionId_t replyId, SerializeIF* data, bool hideSender) { + CommandMessage reply; + store_address_t storeAddress; + uint8_t *dataPtr; + size_t maxSize = data->getSerializedSize(); + if (maxSize == 0) { + //No error, there's simply nothing to report. + return HasReturnvaluesIF::RETURN_OK; + } + size_t size = 0; + ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize, + &dataPtr); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + result = data->serialize(&dataPtr, &size, maxSize, + SerializeIF::Endianness::BIG); + if (result != HasReturnvaluesIF::RETURN_OK) { + ipcStore->deleteData(storeAddress); + return result; + } + // We don't need to report the objectId, as we receive REQUESTED data + // before the completion success message. + // True aperiodic replies need to be reported with + // another dedicated message. + ActionMessage::setDataReply(&reply, replyId, storeAddress); // If the sender needs to be hidden, for example to handle packet // as unrequested reply, this will be done here. - if (hideSender) { - result = MessageQueueSenderIF::sendMessage(reportTo, &reply); - } - else { - result = queueToUse->sendMessage(reportTo, &reply); - } + if (hideSender) { + result = MessageQueueSenderIF::sendMessage(reportTo, &reply); + } + else { + result = queueToUse->sendMessage(reportTo, &reply); + } - if (result != HasReturnvaluesIF::RETURN_OK){ - ipcStore->deleteData(storeAddress); - } - return result; + if (result != HasReturnvaluesIF::RETURN_OK){ + ipcStore->deleteData(storeAddress); + } + return result; } void ActionHelper::resetHelper() { diff --git a/action/ActionHelper.h b/action/ActionHelper.h index d379e7161..ae971d382 100644 --- a/action/ActionHelper.h +++ b/action/ActionHelper.h @@ -18,68 +18,68 @@ class HasActionsIF; class ActionHelper { public: - /** - * Constructor of the action helper - * @param setOwner Pointer to the owner of the interface - * @param useThisQueue messageQueue to be used, can be set during - * initialize function as well. - */ - ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue); + /** + * Constructor of the action helper + * @param setOwner Pointer to the owner of the interface + * @param useThisQueue messageQueue to be used, can be set during + * initialize function as well. + */ + ActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue); - virtual ~ActionHelper(); - /** - * Function to be called from the owner with a new command message - * - * If the message is a valid action message the helper will use the - * executeAction function from HasActionsIF. - * If the message is invalid or the callback fails a message reply will be - * send to the sender of the message automatically. - * - * @param command Pointer to a command message received by the owner - * @return HasReturnvaluesIF::RETURN_OK if the message is a action message, - * CommandMessage::UNKNOW_COMMAND if this message ID is unkown - */ - ReturnValue_t handleActionMessage(CommandMessage* command); - /** - * Helper initialize function. Must be called before use of any other - * helper function - * @param queueToUse_ Pointer to the messageQueue to be used, optional - * if queue was set in constructor - * @return Returns RETURN_OK if successful - */ - ReturnValue_t initialize(MessageQueueIF* queueToUse_ = nullptr); - /** - * Function to be called from the owner to send a step message. - * Success or failure will be determined by the result value. - * - * @param step Number of steps already done - * @param reportTo The messageQueueId to report the step message to - * @param commandId ID of the executed command - * @param result Result of the execution - */ - void step(uint8_t step, MessageQueueId_t reportTo, - ActionId_t commandId, - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); - /** - * Function to be called by the owner to send a action completion message - * - * @param reportTo MessageQueueId_t to report the action completion message to - * @param commandId ID of the executed command - * @param result Result of the execution - */ - void finish(MessageQueueId_t reportTo, ActionId_t commandId, - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); - /** - * Function to be called by the owner if an action does report data. - * Takes a SerializeIF* pointer and serializes it into the IPC store. - * @param reportTo MessageQueueId_t to report the action completion - * message to - * @param replyId ID of the executed command - * @param data Pointer to the data - * @return Returns RETURN_OK if successful, otherwise failure code - */ - ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, - SerializeIF* data, bool hideSender = false); + virtual ~ActionHelper(); + /** + * Function to be called from the owner with a new command message + * + * If the message is a valid action message the helper will use the + * executeAction function from HasActionsIF. + * If the message is invalid or the callback fails a message reply will be + * send to the sender of the message automatically. + * + * @param command Pointer to a command message received by the owner + * @return HasReturnvaluesIF::RETURN_OK if the message is a action message, + * CommandMessage::UNKNOW_COMMAND if this message ID is unkown + */ + ReturnValue_t handleActionMessage(CommandMessage* command); + /** + * Helper initialize function. Must be called before use of any other + * helper function + * @param queueToUse_ Pointer to the messageQueue to be used, optional + * if queue was set in constructor + * @return Returns RETURN_OK if successful + */ + ReturnValue_t initialize(MessageQueueIF* queueToUse_ = nullptr); + /** + * Function to be called from the owner to send a step message. + * Success or failure will be determined by the result value. + * + * @param step Number of steps already done + * @param reportTo The messageQueueId to report the step message to + * @param commandId ID of the executed command + * @param result Result of the execution + */ + void step(uint8_t step, MessageQueueId_t reportTo, + ActionId_t commandId, + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); + /** + * Function to be called by the owner to send a action completion message + * + * @param reportTo MessageQueueId_t to report the action completion message to + * @param commandId ID of the executed command + * @param result Result of the execution + */ + void finish(MessageQueueId_t reportTo, ActionId_t commandId, + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); + /** + * Function to be called by the owner if an action does report data. + * Takes a SerializeIF* pointer and serializes it into the IPC store. + * @param reportTo MessageQueueId_t to report the action completion + * message to + * @param replyId ID of the executed command + * @param data Pointer to the data + * @return Returns RETURN_OK if successful, otherwise failure code + */ + ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, + SerializeIF* data, bool hideSender = false); /** * Function to be called by the owner if an action does report data. * Takes the raw data and writes it into the IPC store. @@ -91,35 +91,35 @@ public: */ ReturnValue_t reportData(MessageQueueId_t reportTo, ActionId_t replyId, const uint8_t* data, size_t dataSize, bool hideSender = false); - /** - * Function to setup the MessageQueueIF* of the helper. Can be used to - * set the MessageQueueIF* if message queue is unavailable at construction - * and initialize but must be setup before first call of other functions. - * @param queue Queue to be used by the helper - */ - void setQueueToUse(MessageQueueIF *queue); + /** + * Function to setup the MessageQueueIF* of the helper. Can be used to + * set the MessageQueueIF* if message queue is unavailable at construction + * and initialize but must be setup before first call of other functions. + * @param queue Queue to be used by the helper + */ + void setQueueToUse(MessageQueueIF *queue); protected: - //! Increase of value of this per step - static const uint8_t STEP_OFFSET = 1; - HasActionsIF* owner;//!< Pointer to the owner - //! Queue to be used as response sender, has to be set in ctor or with - //! setQueueToUse - MessageQueueIF* queueToUse; - //! Pointer to an IPC Store, initialized during construction or - StorageManagerIF* ipcStore = nullptr; + //! Increase of value of this per step + static const uint8_t STEP_OFFSET = 1; + HasActionsIF* owner;//!< Pointer to the owner + //! Queue to be used as response sender, has to be set in ctor or with + //! setQueueToUse + MessageQueueIF* queueToUse; + //! Pointer to an IPC Store, initialized during construction or + StorageManagerIF* ipcStore = nullptr; - /** - * Internal function called by handleActionMessage - * @param commandedBy MessageQueueID of Commander - * @param actionId ID of action to be done - * @param dataAddress Address of additional data in IPC Store - */ - virtual void prepareExecution(MessageQueueId_t commandedBy, - ActionId_t actionId, store_address_t dataAddress); - /** - * @brief Default implementation is empty. - */ - virtual void resetHelper(); + /** + * Internal function called by handleActionMessage + * @param commandedBy MessageQueueID of Commander + * @param actionId ID of action to be done + * @param dataAddress Address of additional data in IPC Store + */ + virtual void prepareExecution(MessageQueueId_t commandedBy, + ActionId_t actionId, store_address_t dataAddress); + /** + * @brief Default implementation is empty. + */ + virtual void resetHelper(); }; #endif /* FSFW_ACTION_ACTIONHELPER_H_ */ diff --git a/action/ActionMessage.cpp b/action/ActionMessage.cpp index 1c00dee0f..c3eb47109 100644 --- a/action/ActionMessage.cpp +++ b/action/ActionMessage.cpp @@ -11,71 +11,71 @@ ActionMessage::~ActionMessage() { } void ActionMessage::setCommand(CommandMessage* message, ActionId_t fid, - store_address_t parameters) { - message->setCommand(EXECUTE_ACTION); - message->setParameter(fid); - message->setParameter2(parameters.raw); + store_address_t parameters) { + message->setCommand(EXECUTE_ACTION); + message->setParameter(fid); + message->setParameter2(parameters.raw); } ActionId_t ActionMessage::getActionId(const CommandMessage* message) { - return ActionId_t(message->getParameter()); + return ActionId_t(message->getParameter()); } store_address_t ActionMessage::getStoreId(const CommandMessage* message) { - store_address_t temp; - temp.raw = message->getParameter2(); - return temp; + store_address_t temp; + temp.raw = message->getParameter2(); + return temp; } void ActionMessage::setStepReply(CommandMessage* message, ActionId_t fid, uint8_t step, - ReturnValue_t result) { - if (result == HasReturnvaluesIF::RETURN_OK) { - message->setCommand(STEP_SUCCESS); - } else { - message->setCommand(STEP_FAILED); - } - message->setParameter(fid); - message->setParameter2((step << 16) + result); + ReturnValue_t result) { + if (result == HasReturnvaluesIF::RETURN_OK) { + message->setCommand(STEP_SUCCESS); + } else { + message->setCommand(STEP_FAILED); + } + message->setParameter(fid); + message->setParameter2((step << 16) + result); } uint8_t ActionMessage::getStep(const CommandMessage* message) { - return uint8_t((message->getParameter2() >> 16) & 0xFF); + return uint8_t((message->getParameter2() >> 16) & 0xFF); } ReturnValue_t ActionMessage::getReturnCode(const CommandMessage* message) { - return message->getParameter2() & 0xFFFF; + return message->getParameter2() & 0xFFFF; } void ActionMessage::setDataReply(CommandMessage* message, ActionId_t actionId, - store_address_t data) { - message->setCommand(DATA_REPLY); - message->setParameter(actionId); - message->setParameter2(data.raw); + store_address_t data) { + message->setCommand(DATA_REPLY); + message->setParameter(actionId); + message->setParameter2(data.raw); } void ActionMessage::setCompletionReply(CommandMessage* message, - ActionId_t fid, ReturnValue_t result) { - if (result == HasReturnvaluesIF::RETURN_OK or result == HasActionsIF::EXECUTION_FINISHED) { - message->setCommand(COMPLETION_SUCCESS); - } else { - message->setCommand(COMPLETION_FAILED); - } - message->setParameter(fid); - message->setParameter2(result); + ActionId_t fid, ReturnValue_t result) { + if (result == HasReturnvaluesIF::RETURN_OK or result == HasActionsIF::EXECUTION_FINISHED) { + message->setCommand(COMPLETION_SUCCESS); + } else { + message->setCommand(COMPLETION_FAILED); + } + message->setParameter(fid); + message->setParameter2(result); } void ActionMessage::clear(CommandMessage* message) { - switch(message->getCommand()) { - case EXECUTE_ACTION: - case DATA_REPLY: { - StorageManagerIF *ipcStore = objectManager->get( - objects::IPC_STORE); - if (ipcStore != NULL) { - ipcStore->deleteData(getStoreId(message)); - } - break; - } - default: - break; - } + switch(message->getCommand()) { + case EXECUTE_ACTION: + case DATA_REPLY: { + StorageManagerIF *ipcStore = objectManager->get( + objects::IPC_STORE); + if (ipcStore != NULL) { + ipcStore->deleteData(getStoreId(message)); + } + break; + } + default: + break; + } } diff --git a/action/ActionMessage.h b/action/ActionMessage.h index deb110952..246ac601d 100644 --- a/action/ActionMessage.h +++ b/action/ActionMessage.h @@ -15,29 +15,29 @@ using ActionId_t = uint32_t; */ class ActionMessage { private: - ActionMessage(); + ActionMessage(); public: - static const uint8_t MESSAGE_ID = messagetypes::ACTION; - static const Command_t EXECUTE_ACTION = MAKE_COMMAND_ID(1); - static const Command_t STEP_SUCCESS = MAKE_COMMAND_ID(2); - static const Command_t STEP_FAILED = MAKE_COMMAND_ID(3); - static const Command_t DATA_REPLY = MAKE_COMMAND_ID(4); - static const Command_t COMPLETION_SUCCESS = MAKE_COMMAND_ID(5); - static const Command_t COMPLETION_FAILED = MAKE_COMMAND_ID(6); - virtual ~ActionMessage(); - static void setCommand(CommandMessage* message, ActionId_t fid, - store_address_t parameters); - static ActionId_t getActionId(const CommandMessage* message ); - static store_address_t getStoreId(const CommandMessage* message ); - static void setStepReply(CommandMessage* message, ActionId_t fid, - uint8_t step, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); - static uint8_t getStep(const CommandMessage* message ); - static ReturnValue_t getReturnCode(const CommandMessage* message ); - static void setDataReply(CommandMessage* message, ActionId_t actionId, - store_address_t data); - static void setCompletionReply(CommandMessage* message, ActionId_t fid, - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); - static void clear(CommandMessage* message); + static const uint8_t MESSAGE_ID = messagetypes::ACTION; + static const Command_t EXECUTE_ACTION = MAKE_COMMAND_ID(1); + static const Command_t STEP_SUCCESS = MAKE_COMMAND_ID(2); + static const Command_t STEP_FAILED = MAKE_COMMAND_ID(3); + static const Command_t DATA_REPLY = MAKE_COMMAND_ID(4); + static const Command_t COMPLETION_SUCCESS = MAKE_COMMAND_ID(5); + static const Command_t COMPLETION_FAILED = MAKE_COMMAND_ID(6); + virtual ~ActionMessage(); + static void setCommand(CommandMessage* message, ActionId_t fid, + store_address_t parameters); + static ActionId_t getActionId(const CommandMessage* message ); + static store_address_t getStoreId(const CommandMessage* message ); + static void setStepReply(CommandMessage* message, ActionId_t fid, + uint8_t step, ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); + static uint8_t getStep(const CommandMessage* message ); + static ReturnValue_t getReturnCode(const CommandMessage* message ); + static void setDataReply(CommandMessage* message, ActionId_t actionId, + store_address_t data); + static void setCompletionReply(CommandMessage* message, ActionId_t fid, + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); + static void clear(CommandMessage* message); }; #endif /* FSFW_ACTION_ACTIONMESSAGE_H_ */ diff --git a/action/CommandActionHelper.cpp b/action/CommandActionHelper.cpp index 4e88f3c34..148b36575 100644 --- a/action/CommandActionHelper.cpp +++ b/action/CommandActionHelper.cpp @@ -5,123 +5,123 @@ #include "../objectmanager/ObjectManagerIF.h" CommandActionHelper::CommandActionHelper(CommandsActionsIF *setOwner) : - owner(setOwner), queueToUse(NULL), ipcStore( - NULL), commandCount(0), lastTarget(0) { + owner(setOwner), queueToUse(NULL), ipcStore( + NULL), commandCount(0), lastTarget(0) { } CommandActionHelper::~CommandActionHelper() { } ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, - ActionId_t actionId, SerializeIF *data) { - HasActionsIF *receiver = objectManager->get(commandTo); - if (receiver == NULL) { - return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS; - } - store_address_t storeId; - uint8_t *storePointer; - size_t maxSize = data->getSerializedSize(); - ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize, - &storePointer); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - size_t size = 0; - result = data->serialize(&storePointer, &size, maxSize, - SerializeIF::Endianness::BIG); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - return sendCommand(receiver->getCommandQueue(), actionId, storeId); + ActionId_t actionId, SerializeIF *data) { + HasActionsIF *receiver = objectManager->get(commandTo); + if (receiver == NULL) { + return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS; + } + store_address_t storeId; + uint8_t *storePointer; + size_t maxSize = data->getSerializedSize(); + ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize, + &storePointer); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + size_t size = 0; + result = data->serialize(&storePointer, &size, maxSize, + SerializeIF::Endianness::BIG); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return sendCommand(receiver->getCommandQueue(), actionId, storeId); } ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, - ActionId_t actionId, const uint8_t *data, uint32_t size) { -// if (commandCount != 0) { -// return CommandsFunctionsIF::ALREADY_COMMANDING; -// } - HasActionsIF *receiver = objectManager->get(commandTo); - if (receiver == NULL) { - return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS; - } - store_address_t storeId; - ReturnValue_t result = ipcStore->addData(&storeId, data, size); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - return sendCommand(receiver->getCommandQueue(), actionId, storeId); + ActionId_t actionId, const uint8_t *data, uint32_t size) { +// if (commandCount != 0) { +// return CommandsFunctionsIF::ALREADY_COMMANDING; +// } + HasActionsIF *receiver = objectManager->get(commandTo); + if (receiver == NULL) { + return CommandsActionsIF::OBJECT_HAS_NO_FUNCTIONS; + } + store_address_t storeId; + ReturnValue_t result = ipcStore->addData(&storeId, data, size); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + return sendCommand(receiver->getCommandQueue(), actionId, storeId); } ReturnValue_t CommandActionHelper::sendCommand(MessageQueueId_t queueId, - ActionId_t actionId, store_address_t storeId) { - CommandMessage command; - ActionMessage::setCommand(&command, actionId, storeId); - ReturnValue_t result = queueToUse->sendMessage(queueId, &command); - if (result != HasReturnvaluesIF::RETURN_OK) { - ipcStore->deleteData(storeId); - } - lastTarget = queueId; - commandCount++; - return result; + ActionId_t actionId, store_address_t storeId) { + CommandMessage command; + ActionMessage::setCommand(&command, actionId, storeId); + ReturnValue_t result = queueToUse->sendMessage(queueId, &command); + if (result != HasReturnvaluesIF::RETURN_OK) { + ipcStore->deleteData(storeId); + } + lastTarget = queueId; + commandCount++; + return result; } ReturnValue_t CommandActionHelper::initialize() { - ipcStore = objectManager->get(objects::IPC_STORE); - if (ipcStore == NULL) { - return HasReturnvaluesIF::RETURN_FAILED; - } + ipcStore = objectManager->get(objects::IPC_STORE); + if (ipcStore == NULL) { + return HasReturnvaluesIF::RETURN_FAILED; + } - queueToUse = owner->getCommandQueuePtr(); - if (queueToUse == NULL) { - return HasReturnvaluesIF::RETURN_FAILED; - } - return HasReturnvaluesIF::RETURN_OK; + queueToUse = owner->getCommandQueuePtr(); + if (queueToUse == NULL) { + return HasReturnvaluesIF::RETURN_FAILED; + } + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t CommandActionHelper::handleReply(CommandMessage *reply) { - if (reply->getSender() != lastTarget) { - return HasReturnvaluesIF::RETURN_FAILED; - } - switch (reply->getCommand()) { - case ActionMessage::COMPLETION_SUCCESS: - commandCount--; - owner->completionSuccessfulReceived(ActionMessage::getActionId(reply)); - return HasReturnvaluesIF::RETURN_OK; - case ActionMessage::COMPLETION_FAILED: - commandCount--; - owner->completionFailedReceived(ActionMessage::getActionId(reply), - ActionMessage::getReturnCode(reply)); - return HasReturnvaluesIF::RETURN_OK; - case ActionMessage::STEP_SUCCESS: - owner->stepSuccessfulReceived(ActionMessage::getActionId(reply), - ActionMessage::getStep(reply)); - return HasReturnvaluesIF::RETURN_OK; - case ActionMessage::STEP_FAILED: - commandCount--; - owner->stepFailedReceived(ActionMessage::getActionId(reply), - ActionMessage::getStep(reply), - ActionMessage::getReturnCode(reply)); - return HasReturnvaluesIF::RETURN_OK; - case ActionMessage::DATA_REPLY: - extractDataForOwner(ActionMessage::getActionId(reply), - ActionMessage::getStoreId(reply)); - return HasReturnvaluesIF::RETURN_OK; - default: - return HasReturnvaluesIF::RETURN_FAILED; - } + if (reply->getSender() != lastTarget) { + return HasReturnvaluesIF::RETURN_FAILED; + } + switch (reply->getCommand()) { + case ActionMessage::COMPLETION_SUCCESS: + commandCount--; + owner->completionSuccessfulReceived(ActionMessage::getActionId(reply)); + return HasReturnvaluesIF::RETURN_OK; + case ActionMessage::COMPLETION_FAILED: + commandCount--; + owner->completionFailedReceived(ActionMessage::getActionId(reply), + ActionMessage::getReturnCode(reply)); + return HasReturnvaluesIF::RETURN_OK; + case ActionMessage::STEP_SUCCESS: + owner->stepSuccessfulReceived(ActionMessage::getActionId(reply), + ActionMessage::getStep(reply)); + return HasReturnvaluesIF::RETURN_OK; + case ActionMessage::STEP_FAILED: + commandCount--; + owner->stepFailedReceived(ActionMessage::getActionId(reply), + ActionMessage::getStep(reply), + ActionMessage::getReturnCode(reply)); + return HasReturnvaluesIF::RETURN_OK; + case ActionMessage::DATA_REPLY: + extractDataForOwner(ActionMessage::getActionId(reply), + ActionMessage::getStoreId(reply)); + return HasReturnvaluesIF::RETURN_OK; + default: + return HasReturnvaluesIF::RETURN_FAILED; + } } uint8_t CommandActionHelper::getCommandCount() const { - return commandCount; + return commandCount; } void CommandActionHelper::extractDataForOwner(ActionId_t actionId, store_address_t storeId) { - const uint8_t * data = NULL; - size_t size = 0; - ReturnValue_t result = ipcStore->getData(storeId, &data, &size); - if (result != HasReturnvaluesIF::RETURN_OK) { - return; - } - owner->dataReceived(actionId, data, size); - ipcStore->deleteData(storeId); + const uint8_t * data = NULL; + size_t size = 0; + ReturnValue_t result = ipcStore->getData(storeId, &data, &size); + if (result != HasReturnvaluesIF::RETURN_OK) { + return; + } + owner->dataReceived(actionId, data, size); + ipcStore->deleteData(storeId); } diff --git a/action/CommandActionHelper.h b/action/CommandActionHelper.h index cfed8c941..96ef1763a 100644 --- a/action/CommandActionHelper.h +++ b/action/CommandActionHelper.h @@ -11,26 +11,26 @@ class CommandsActionsIF; class CommandActionHelper { - friend class CommandsActionsIF; + friend class CommandsActionsIF; public: - CommandActionHelper(CommandsActionsIF* owner); - virtual ~CommandActionHelper(); - ReturnValue_t commandAction(object_id_t commandTo, - ActionId_t actionId, const uint8_t* data, uint32_t size); - ReturnValue_t commandAction(object_id_t commandTo, - ActionId_t actionId, SerializeIF* data); - ReturnValue_t initialize(); - ReturnValue_t handleReply(CommandMessage* reply); - uint8_t getCommandCount() const; + CommandActionHelper(CommandsActionsIF* owner); + virtual ~CommandActionHelper(); + ReturnValue_t commandAction(object_id_t commandTo, + ActionId_t actionId, const uint8_t* data, uint32_t size); + ReturnValue_t commandAction(object_id_t commandTo, + ActionId_t actionId, SerializeIF* data); + ReturnValue_t initialize(); + ReturnValue_t handleReply(CommandMessage* reply); + uint8_t getCommandCount() const; private: - CommandsActionsIF* owner; - MessageQueueIF* queueToUse; - StorageManagerIF* ipcStore; - uint8_t commandCount; - MessageQueueId_t lastTarget; - void extractDataForOwner(ActionId_t actionId, store_address_t storeId); - ReturnValue_t sendCommand(MessageQueueId_t queueId, ActionId_t actionId, - store_address_t storeId); + CommandsActionsIF* owner; + MessageQueueIF* queueToUse; + StorageManagerIF* ipcStore; + uint8_t commandCount; + MessageQueueId_t lastTarget; + void extractDataForOwner(ActionId_t actionId, store_address_t storeId); + ReturnValue_t sendCommand(MessageQueueId_t queueId, ActionId_t actionId, + store_address_t storeId); }; #endif /* COMMANDACTIONHELPER_H_ */ diff --git a/action/CommandsActionsIF.h b/action/CommandsActionsIF.h index 491bfc703..fe7e856c2 100644 --- a/action/CommandsActionsIF.h +++ b/action/CommandsActionsIF.h @@ -15,22 +15,22 @@ * - replyReceived(id, step, cause) (if cause == OK, it's a success). */ class CommandsActionsIF { - friend class CommandActionHelper; + friend class CommandActionHelper; public: - static const uint8_t INTERFACE_ID = CLASS_ID::COMMANDS_ACTIONS_IF; - static const ReturnValue_t OBJECT_HAS_NO_FUNCTIONS = MAKE_RETURN_CODE(1); - static const ReturnValue_t ALREADY_COMMANDING = MAKE_RETURN_CODE(2); - virtual ~CommandsActionsIF() {} - virtual MessageQueueIF* getCommandQueuePtr() = 0; + static const uint8_t INTERFACE_ID = CLASS_ID::COMMANDS_ACTIONS_IF; + static const ReturnValue_t OBJECT_HAS_NO_FUNCTIONS = MAKE_RETURN_CODE(1); + static const ReturnValue_t ALREADY_COMMANDING = MAKE_RETURN_CODE(2); + virtual ~CommandsActionsIF() {} + virtual MessageQueueIF* getCommandQueuePtr() = 0; protected: - virtual void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) = 0; - virtual void stepFailedReceived(ActionId_t actionId, uint8_t step, - ReturnValue_t returnCode) = 0; - virtual void dataReceived(ActionId_t actionId, const uint8_t* data, - uint32_t size) = 0; - virtual void completionSuccessfulReceived(ActionId_t actionId) = 0; - virtual void completionFailedReceived(ActionId_t actionId, - ReturnValue_t returnCode) = 0; + virtual void stepSuccessfulReceived(ActionId_t actionId, uint8_t step) = 0; + virtual void stepFailedReceived(ActionId_t actionId, uint8_t step, + ReturnValue_t returnCode) = 0; + virtual void dataReceived(ActionId_t actionId, const uint8_t* data, + uint32_t size) = 0; + virtual void completionSuccessfulReceived(ActionId_t actionId) = 0; + virtual void completionFailedReceived(ActionId_t actionId, + ReturnValue_t returnCode) = 0; }; diff --git a/action/HasActionsIF.h b/action/HasActionsIF.h index 690f03698..056e674c3 100644 --- a/action/HasActionsIF.h +++ b/action/HasActionsIF.h @@ -35,28 +35,28 @@ */ class HasActionsIF { public: - static const uint8_t INTERFACE_ID = CLASS_ID::HAS_ACTIONS_IF; - static const ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1); - static const ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(2); - static const ReturnValue_t EXECUTION_FINISHED = MAKE_RETURN_CODE(3); - static const ReturnValue_t INVALID_ACTION_ID = MAKE_RETURN_CODE(4); - virtual ~HasActionsIF() { } - /** - * Function to get the MessageQueueId_t of the implementing object - * @return MessageQueueId_t of the object - */ - virtual MessageQueueId_t getCommandQueue() const = 0; - /** - * Execute or initialize the execution of a certain function. - * The ActionHelpers will execute this function and behave differently - * depending on the returnvalue. - * - * @return - * -@c EXECUTION_FINISHED Finish reply will be generated - * -@c Not RETURN_OK Step failure reply will be generated - */ - virtual ReturnValue_t executeAction(ActionId_t actionId, - MessageQueueId_t commandedBy, const uint8_t* data, size_t size) = 0; + static const uint8_t INTERFACE_ID = CLASS_ID::HAS_ACTIONS_IF; + static const ReturnValue_t IS_BUSY = MAKE_RETURN_CODE(1); + static const ReturnValue_t INVALID_PARAMETERS = MAKE_RETURN_CODE(2); + static const ReturnValue_t EXECUTION_FINISHED = MAKE_RETURN_CODE(3); + static const ReturnValue_t INVALID_ACTION_ID = MAKE_RETURN_CODE(4); + virtual ~HasActionsIF() { } + /** + * Function to get the MessageQueueId_t of the implementing object + * @return MessageQueueId_t of the object + */ + virtual MessageQueueId_t getCommandQueue() const = 0; + /** + * Execute or initialize the execution of a certain function. + * The ActionHelpers will execute this function and behave differently + * depending on the returnvalue. + * + * @return + * -@c EXECUTION_FINISHED Finish reply will be generated + * -@c Not RETURN_OK Step failure reply will be generated + */ + virtual ReturnValue_t executeAction(ActionId_t actionId, + MessageQueueId_t commandedBy, const uint8_t* data, size_t size) = 0; }; diff --git a/action/SimpleActionHelper.cpp b/action/SimpleActionHelper.cpp index af57736c8..f77d01473 100644 --- a/action/SimpleActionHelper.cpp +++ b/action/SimpleActionHelper.cpp @@ -2,74 +2,74 @@ #include "SimpleActionHelper.h" SimpleActionHelper::SimpleActionHelper(HasActionsIF* setOwner, - MessageQueueIF* useThisQueue) : - ActionHelper(setOwner, useThisQueue), isExecuting(false) { + MessageQueueIF* useThisQueue) : + ActionHelper(setOwner, useThisQueue), isExecuting(false) { } SimpleActionHelper::~SimpleActionHelper() { } void SimpleActionHelper::step(ReturnValue_t result) { - // STEP_OFFESET is subtracted to compensate for adding offset in base - // method, which is not necessary here. - ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction, - result); - if (result != HasReturnvaluesIF::RETURN_OK) { - resetHelper(); - } + // STEP_OFFESET is subtracted to compensate for adding offset in base + // method, which is not necessary here. + ActionHelper::step(stepCount - STEP_OFFSET, lastCommander, lastAction, + result); + if (result != HasReturnvaluesIF::RETURN_OK) { + resetHelper(); + } } void SimpleActionHelper::finish(ReturnValue_t result) { - ActionHelper::finish(lastCommander, lastAction, result); - resetHelper(); + ActionHelper::finish(lastCommander, lastAction, result); + resetHelper(); } ReturnValue_t SimpleActionHelper::reportData(SerializeIF* data) { - return ActionHelper::reportData(lastCommander, lastAction, data); + return ActionHelper::reportData(lastCommander, lastAction, data); } void SimpleActionHelper::resetHelper() { - stepCount = 0; - isExecuting = false; - lastAction = 0; - lastCommander = 0; + stepCount = 0; + isExecuting = false; + lastAction = 0; + lastCommander = 0; } void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy, - ActionId_t actionId, store_address_t dataAddress) { - CommandMessage reply; - if (isExecuting) { - ipcStore->deleteData(dataAddress); - ActionMessage::setStepReply(&reply, actionId, 0, - HasActionsIF::IS_BUSY); - queueToUse->sendMessage(commandedBy, &reply); - } - const uint8_t* dataPtr = NULL; - size_t size = 0; - ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size); - if (result != HasReturnvaluesIF::RETURN_OK) { - ActionMessage::setStepReply(&reply, actionId, 0, result); - queueToUse->sendMessage(commandedBy, &reply); - return; - } - lastCommander = commandedBy; - lastAction = actionId; - result = owner->executeAction(actionId, commandedBy, dataPtr, size); - ipcStore->deleteData(dataAddress); - switch (result) { - case HasReturnvaluesIF::RETURN_OK: - isExecuting = true; - stepCount++; - break; - case HasActionsIF::EXECUTION_FINISHED: - ActionMessage::setCompletionReply(&reply, actionId, - HasReturnvaluesIF::RETURN_OK); - queueToUse->sendMessage(commandedBy, &reply); - break; - default: - ActionMessage::setStepReply(&reply, actionId, 0, result); - queueToUse->sendMessage(commandedBy, &reply); - break; - } + ActionId_t actionId, store_address_t dataAddress) { + CommandMessage reply; + if (isExecuting) { + ipcStore->deleteData(dataAddress); + ActionMessage::setStepReply(&reply, actionId, 0, + HasActionsIF::IS_BUSY); + queueToUse->sendMessage(commandedBy, &reply); + } + const uint8_t* dataPtr = NULL; + size_t size = 0; + ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size); + if (result != HasReturnvaluesIF::RETURN_OK) { + ActionMessage::setStepReply(&reply, actionId, 0, result); + queueToUse->sendMessage(commandedBy, &reply); + return; + } + lastCommander = commandedBy; + lastAction = actionId; + result = owner->executeAction(actionId, commandedBy, dataPtr, size); + ipcStore->deleteData(dataAddress); + switch (result) { + case HasReturnvaluesIF::RETURN_OK: + isExecuting = true; + stepCount++; + break; + case HasActionsIF::EXECUTION_FINISHED: + ActionMessage::setCompletionReply(&reply, actionId, + HasReturnvaluesIF::RETURN_OK); + queueToUse->sendMessage(commandedBy, &reply); + break; + default: + ActionMessage::setStepReply(&reply, actionId, 0, result); + queueToUse->sendMessage(commandedBy, &reply); + break; + } } diff --git a/action/SimpleActionHelper.h b/action/SimpleActionHelper.h index 1f35d9fdf..7c6c4e00e 100644 --- a/action/SimpleActionHelper.h +++ b/action/SimpleActionHelper.h @@ -4,27 +4,27 @@ #include "ActionHelper.h" /** - * @brief This is an action helper which is only able to service one action - * at a time but remembers last commander and last action which - * simplifies usage + * @brief This is an action helper which is only able to service one action + * at a time but remembers last commander and last action which + * simplifies usage */ class SimpleActionHelper: public ActionHelper { public: - SimpleActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue); - virtual ~SimpleActionHelper(); - void step(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); - void finish(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); - ReturnValue_t reportData(SerializeIF* data); + SimpleActionHelper(HasActionsIF* setOwner, MessageQueueIF* useThisQueue); + virtual ~SimpleActionHelper(); + void step(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); + void finish(ReturnValue_t result = HasReturnvaluesIF::RETURN_OK); + ReturnValue_t reportData(SerializeIF* data); protected: - void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, - store_address_t dataAddress); - virtual void resetHelper(); + void prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, + store_address_t dataAddress); + virtual void resetHelper(); private: - bool isExecuting; - MessageQueueId_t lastCommander = MessageQueueIF::NO_QUEUE; - ActionId_t lastAction = 0; - uint8_t stepCount = 0; + bool isExecuting; + MessageQueueId_t lastCommander = MessageQueueIF::NO_QUEUE; + ActionId_t lastAction = 0; + uint8_t stepCount = 0; }; #endif /* SIMPLEACTIONHELPER_H_ */ -- 2.34.1 From 98f89302c43c990b3eeb3df21cd15029de8a697b Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jan 2021 11:44:49 +0100 Subject: [PATCH 02/14] tabs replaced by spaces --- container/ArrayList.h | 398 +++++----- container/BinaryTree.h | 234 +++--- container/DynamicFIFO.h | 64 +- container/FIFO.h | 48 +- container/FIFOBase.h | 112 +-- container/FIFOBase.tpp | 82 +- container/FixedArrayList.h | 38 +- container/FixedMap.h | 354 ++++----- container/FixedOrderedMultimap.h | 282 +++---- container/FixedOrderedMultimap.tpp | 136 ++-- container/HybridIterator.h | 124 +-- container/IndexedRingMemoryArray.h | 1178 ++++++++++++++-------------- container/PlacementFactory.h | 84 +- container/RingBufferBase.h | 166 ++-- container/SharedRingBuffer.cpp | 40 +- container/SharedRingBuffer.h | 122 +-- container/SimpleRingBuffer.cpp | 152 ++-- container/SimpleRingBuffer.h | 178 ++--- container/SinglyLinkedList.h | 176 ++--- 19 files changed, 1984 insertions(+), 1984 deletions(-) diff --git a/container/ArrayList.h b/container/ArrayList.h index 6bd5c1d5a..25e281a27 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -6,7 +6,7 @@ #include "../serialize/SerializeIF.h" /** - * @brief A List that stores its values in an array. + * @brief A List that stores its values in an array. * @details * The underlying storage is an array that can be allocated by the class * itself or supplied via ctor. @@ -15,237 +15,237 @@ */ template class ArrayList { - template friend class SerialArrayListAdapter; + template friend class SerialArrayListAdapter; public: - static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST; - static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01); + static const uint8_t INTERFACE_ID = CLASS_ID::ARRAY_LIST; + static const ReturnValue_t FULL = MAKE_RETURN_CODE(0x01); - /** - * This is the allocating constructor. - * It allocates an array of the specified size. - * @param maxSize - */ - ArrayList(count_t maxSize) : - size(0), maxSize_(maxSize), allocated(true) { - entries = new T[maxSize]; - } + /** + * This is the allocating constructor. + * It allocates an array of the specified size. + * @param maxSize + */ + ArrayList(count_t maxSize) : + size(0), maxSize_(maxSize), allocated(true) { + entries = new T[maxSize]; + } - /** - * This is the non-allocating constructor - * - * It expects a pointer to an array of a certain size and initializes - * itself to it. - * - * @param storage the array to use as backend - * @param maxSize size of storage - * @param size size of data already present in storage - */ - ArrayList(T *storage, count_t maxSize, count_t size = 0) : - size(size), entries(storage), maxSize_(maxSize), allocated(false) { - } + /** + * This is the non-allocating constructor + * + * It expects a pointer to an array of a certain size and initializes + * itself to it. + * + * @param storage the array to use as backend + * @param maxSize size of storage + * @param size size of data already present in storage + */ + ArrayList(T *storage, count_t maxSize, count_t size = 0) : + size(size), entries(storage), maxSize_(maxSize), allocated(false) { + } - /** - * Copying is forbiden by declaring copy ctor and copy assignment deleted - * It is too ambigous in this case. - * (Allocate a new backend? Use the same? What to do in an modifying call?) - */ - ArrayList(const ArrayList& other) = delete; - const ArrayList& operator=(const ArrayList& other) = delete; + /** + * Copying is forbiden by declaring copy ctor and copy assignment deleted + * It is too ambigous in this case. + * (Allocate a new backend? Use the same? What to do in an modifying call?) + */ + ArrayList(const ArrayList& other) = delete; + const ArrayList& operator=(const ArrayList& other) = delete; - /** - * Number of Elements stored in this List - */ - count_t size; + /** + * Number of Elements stored in this List + */ + count_t size; - /** - * Destructor, if the allocating constructor was used, it deletes the array. - */ - virtual ~ArrayList() { - if (allocated) { - delete[] entries; - } - } + /** + * Destructor, if the allocating constructor was used, it deletes the array. + */ + virtual ~ArrayList() { + if (allocated) { + delete[] entries; + } + } - /** - * An Iterator to go trough an ArrayList - * - * It stores a pointer to an element and increments the - * pointer when incremented itself. - */ - class Iterator { - public: - /** - * Empty ctor, points to NULL - */ - Iterator(): value(0) {} + /** + * An Iterator to go trough an ArrayList + * + * It stores a pointer to an element and increments the + * pointer when incremented itself. + */ + class Iterator { + public: + /** + * Empty ctor, points to NULL + */ + Iterator(): value(0) {} - /** - * Initializes the Iterator to point to an element - * - * @param initialize - */ - Iterator(T *initialize) { - value = initialize; - } + /** + * Initializes the Iterator to point to an element + * + * @param initialize + */ + Iterator(T *initialize) { + value = initialize; + } - /** - * The current element the iterator points to - */ - T *value; + /** + * The current element the iterator points to + */ + T *value; - Iterator& operator++() { - value++; - return *this; - } + Iterator& operator++() { + value++; + return *this; + } - Iterator operator++(int) { - Iterator tmp(*this); - operator++(); - return tmp; - } + Iterator operator++(int) { + Iterator tmp(*this); + operator++(); + return tmp; + } - Iterator& operator--() { - value--; - return *this; - } + Iterator& operator--() { + value--; + return *this; + } - Iterator operator--(int) { - Iterator tmp(*this); - operator--(); - return tmp; - } + Iterator operator--(int) { + Iterator tmp(*this); + operator--(); + return tmp; + } - T& operator*() { - return *value; - } + T& operator*() { + return *value; + } - const T& operator*() const { - return *value; - } + const T& operator*() const { + return *value; + } - T *operator->() { - return value; - } + T *operator->() { + return value; + } - const T *operator->() const { - return value; - } - }; + const T *operator->() const { + return value; + } + }; - friend bool operator==(const ArrayList::Iterator& lhs, - const ArrayList::Iterator& rhs) { - return (lhs.value == rhs.value); - } + friend bool operator==(const ArrayList::Iterator& lhs, + const ArrayList::Iterator& rhs) { + return (lhs.value == rhs.value); + } - friend bool operator!=(const ArrayList::Iterator& lhs, - const ArrayList::Iterator& rhs) { - return not (lhs.value == rhs.value); - } + friend bool operator!=(const ArrayList::Iterator& lhs, + const ArrayList::Iterator& rhs) { + return not (lhs.value == rhs.value); + } - /** - * Iterator pointing to the first stored elmement - * - * @return Iterator to the first element - */ - Iterator begin() const { - return Iterator(&entries[0]); - } + /** + * Iterator pointing to the first stored elmement + * + * @return Iterator to the first element + */ + Iterator begin() const { + return Iterator(&entries[0]); + } - /** - * returns an Iterator pointing to the element after the last stored entry - * - * @return Iterator to the element after the last entry - */ - Iterator end() const { - return Iterator(&entries[size]); - } + /** + * returns an Iterator pointing to the element after the last stored entry + * + * @return Iterator to the element after the last entry + */ + Iterator end() const { + return Iterator(&entries[size]); + } - T & operator[](count_t i) const { - return entries[i]; - } + T & operator[](count_t i) const { + return entries[i]; + } - /** - * The first element - * - * @return pointer to the first stored element - */ - T *front() { - return entries; - } + /** + * The first element + * + * @return pointer to the first stored element + */ + T *front() { + return entries; + } - /** - * The last element - * - * does not return a valid pointer if called on an empty list. - * - * @return pointer to the last stored element - */ - T *back() { - return &entries[size - 1]; - //Alternative solution - //return const_cast(static_cast(*this).back()); - } + /** + * The last element + * + * does not return a valid pointer if called on an empty list. + * + * @return pointer to the last stored element + */ + T *back() { + return &entries[size - 1]; + //Alternative solution + //return const_cast(static_cast(*this).back()); + } - const T* back() const{ - return &entries[size-1]; - } + const T* back() const{ + return &entries[size-1]; + } - /** - * The maximum number of elements this List can contain - * - * @return maximum number of elements - */ - size_t maxSize() const { - return this->maxSize_; - } + /** + * The maximum number of elements this List can contain + * + * @return maximum number of elements + */ + size_t maxSize() const { + return this->maxSize_; + } - /** - * Insert a new element into the list. - * - * The new element is inserted after the last stored element. - * - * @param entry - * @return - * -@c FULL if the List is full - * -@c RETURN_OK else - */ - ReturnValue_t insert(T entry) { - if (size >= maxSize_) { - return FULL; - } - entries[size] = entry; - ++size; - return HasReturnvaluesIF::RETURN_OK; - } + /** + * Insert a new element into the list. + * + * The new element is inserted after the last stored element. + * + * @param entry + * @return + * -@c FULL if the List is full + * -@c RETURN_OK else + */ + ReturnValue_t insert(T entry) { + if (size >= maxSize_) { + return FULL; + } + entries[size] = entry; + ++size; + return HasReturnvaluesIF::RETURN_OK; + } - /** - * clear the List - * - * This does not actually clear all entries, it only sets the size to 0. - */ - void clear() { - size = 0; - } + /** + * clear the List + * + * This does not actually clear all entries, it only sets the size to 0. + */ + void clear() { + size = 0; + } - count_t remaining() { - return (maxSize_ - size); - } + count_t remaining() { + return (maxSize_ - size); + } protected: - /** - * pointer to the array in which the entries are stored - */ - T *entries; - /** - * remembering the maximum size - */ - size_t maxSize_; + /** + * pointer to the array in which the entries are stored + */ + T *entries; + /** + * remembering the maximum size + */ + size_t maxSize_; - /** - * true if the array was allocated and needs to be deleted in the destructor. - */ - bool allocated; + /** + * true if the array was allocated and needs to be deleted in the destructor. + */ + bool allocated; }; diff --git a/container/BinaryTree.h b/container/BinaryTree.h index 73073dea3..6200cbb1f 100644 --- a/container/BinaryTree.h +++ b/container/BinaryTree.h @@ -7,65 +7,65 @@ template class BinaryNode { public: - BinaryNode(Tp* setValue) : - value(setValue), left(NULL), right(NULL), parent(NULL) { - } - Tp *value; - BinaryNode* left; - BinaryNode* right; - BinaryNode* parent; + BinaryNode(Tp* setValue) : + value(setValue), left(NULL), right(NULL), parent(NULL) { + } + Tp *value; + BinaryNode* left; + BinaryNode* right; + BinaryNode* parent; }; template class ExplicitNodeIterator { public: - typedef ExplicitNodeIterator _Self; - typedef BinaryNode _Node; - typedef Tp value_type; - typedef Tp* pointer; - typedef Tp& reference; - ExplicitNodeIterator() : - element(NULL) { - } - ExplicitNodeIterator(_Node* node) : - element(node) { - } - BinaryNode* element; - _Self up() { - return _Self(element->parent); - } - _Self left() { - if (element != NULL) { - return _Self(element->left); - } else { - return _Self(NULL); - } + typedef ExplicitNodeIterator _Self; + typedef BinaryNode _Node; + typedef Tp value_type; + typedef Tp* pointer; + typedef Tp& reference; + ExplicitNodeIterator() : + element(NULL) { + } + ExplicitNodeIterator(_Node* node) : + element(node) { + } + BinaryNode* element; + _Self up() { + return _Self(element->parent); + } + _Self left() { + if (element != NULL) { + return _Self(element->left); + } else { + return _Self(NULL); + } - } - _Self right() { - if (element != NULL) { - return _Self(element->right); - } else { - return _Self(NULL); - } + } + _Self right() { + if (element != NULL) { + return _Self(element->right); + } else { + return _Self(NULL); + } - } - bool operator==(const _Self& __x) const { - return element == __x.element; - } - bool operator!=(const _Self& __x) const { - return element != __x.element; - } + } + bool operator==(const _Self& __x) const { + return element == __x.element; + } + bool operator!=(const _Self& __x) const { + return element != __x.element; + } pointer operator->() const { - if (element != NULL) { - return element->value; - } else { - return NULL; - } + if (element != NULL) { + return element->value; + } else { + return NULL; + } } pointer operator*() const { - return this->operator->(); + return this->operator->(); } }; @@ -75,77 +75,77 @@ public: template class BinaryTree { public: - typedef ExplicitNodeIterator iterator; - typedef BinaryNode Node; - typedef std::pair children; - BinaryTree() : - rootNode(NULL) { - } - BinaryTree(Node* rootNode) : - rootNode(rootNode) { - } - iterator begin() const { - return iterator(rootNode); - } - static iterator end() { - return iterator(NULL); - } - iterator insert(bool insertLeft, iterator parentNode, Node* newNode ) { - newNode->parent = parentNode.element; - if (parentNode.element != NULL) { - if (insertLeft) { - parentNode.element->left = newNode; - } else { - parentNode.element->right = newNode; - } - } else { - //Insert first element. - rootNode = newNode; - } - return iterator(newNode); - } - //No recursion to children. Needs to be done externally. - children erase(iterator node) { - if (node.element == rootNode) { - //We're root node - rootNode = NULL; - } else { - //Delete parent's reference - if (node.up().left() == node) { - node.up().element->left = NULL; - } else { - node.up().element->right = NULL; - } - } - return children(node.element->left, node.element->right); - } - static uint32_t countLeft(iterator start) { - if (start == end()) { - return 0; - } - //We also count the start node itself. - uint32_t count = 1; - while (start.left() != end()) { - count++; - start = start.left(); - } - return count; - } - static uint32_t countRight(iterator start) { - if (start == end()) { - return 0; - } - //We also count the start node itself. - uint32_t count = 1; - while (start.right() != end()) { - count++; - start = start.right(); - } - return count; - } + typedef ExplicitNodeIterator iterator; + typedef BinaryNode Node; + typedef std::pair children; + BinaryTree() : + rootNode(NULL) { + } + BinaryTree(Node* rootNode) : + rootNode(rootNode) { + } + iterator begin() const { + return iterator(rootNode); + } + static iterator end() { + return iterator(NULL); + } + iterator insert(bool insertLeft, iterator parentNode, Node* newNode ) { + newNode->parent = parentNode.element; + if (parentNode.element != NULL) { + if (insertLeft) { + parentNode.element->left = newNode; + } else { + parentNode.element->right = newNode; + } + } else { + //Insert first element. + rootNode = newNode; + } + return iterator(newNode); + } + //No recursion to children. Needs to be done externally. + children erase(iterator node) { + if (node.element == rootNode) { + //We're root node + rootNode = NULL; + } else { + //Delete parent's reference + if (node.up().left() == node) { + node.up().element->left = NULL; + } else { + node.up().element->right = NULL; + } + } + return children(node.element->left, node.element->right); + } + static uint32_t countLeft(iterator start) { + if (start == end()) { + return 0; + } + //We also count the start node itself. + uint32_t count = 1; + while (start.left() != end()) { + count++; + start = start.left(); + } + return count; + } + static uint32_t countRight(iterator start) { + if (start == end()) { + return 0; + } + //We also count the start node itself. + uint32_t count = 1; + while (start.right() != end()) { + count++; + start = start.right(); + } + return count; + } protected: - Node* rootNode; + Node* rootNode; }; diff --git a/container/DynamicFIFO.h b/container/DynamicFIFO.h index 86d43f7d7..e1bc3ef2f 100644 --- a/container/DynamicFIFO.h +++ b/container/DynamicFIFO.h @@ -5,8 +5,8 @@ #include /** - * @brief Simple First-In-First-Out data structure. The maximum size - * can be set in the constructor. + * @brief Simple First-In-First-Out data structure. The maximum size + * can be set in the constructor. * @details * The maximum capacity can be determined at run-time, so this container * performs dynamic memory allocation! @@ -17,39 +17,39 @@ template class DynamicFIFO: public FIFOBase { public: - DynamicFIFO(size_t maxCapacity): FIFOBase(nullptr, maxCapacity), - fifoVector(maxCapacity) { - // trying to pass the pointer of the uninitialized vector - // to the FIFOBase constructor directly lead to a super evil bug. - // So we do it like this now. - this->setContainer(fifoVector.data()); - }; + DynamicFIFO(size_t maxCapacity): FIFOBase(nullptr, maxCapacity), + fifoVector(maxCapacity) { + // trying to pass the pointer of the uninitialized vector + // to the FIFOBase constructor directly lead to a super evil bug. + // So we do it like this now. + this->setContainer(fifoVector.data()); + }; - /** - * @brief Custom copy constructor which prevents setting the - * underlying pointer wrong. This function allocates memory! - * @details This is a very heavy operation so try to avoid this! - * - */ - DynamicFIFO(const DynamicFIFO& other): FIFOBase(other), - fifoVector(other.maxCapacity) { - this->fifoVector = other.fifoVector; - this->setContainer(fifoVector.data()); - } + /** + * @brief Custom copy constructor which prevents setting the + * underlying pointer wrong. This function allocates memory! + * @details This is a very heavy operation so try to avoid this! + * + */ + DynamicFIFO(const DynamicFIFO& other): FIFOBase(other), + fifoVector(other.maxCapacity) { + this->fifoVector = other.fifoVector; + this->setContainer(fifoVector.data()); + } - /** - * @brief Custom assignment operator - * @details This is a very heavy operation so try to avoid this! - * @param other DyamicFIFO to copy from - */ - DynamicFIFO& operator=(const DynamicFIFO& other){ - FIFOBase::operator=(other); - this->fifoVector = other.fifoVector; - this->setContainer(fifoVector.data()); - return *this; - } + /** + * @brief Custom assignment operator + * @details This is a very heavy operation so try to avoid this! + * @param other DyamicFIFO to copy from + */ + DynamicFIFO& operator=(const DynamicFIFO& other){ + FIFOBase::operator=(other); + this->fifoVector = other.fifoVector; + this->setContainer(fifoVector.data()); + return *this; + } private: - std::vector fifoVector; + std::vector fifoVector; }; #endif /* FSFW_CONTAINER_DYNAMICFIFO_H_ */ diff --git a/container/FIFO.h b/container/FIFO.h index 701138520..79ead3139 100644 --- a/container/FIFO.h +++ b/container/FIFO.h @@ -5,8 +5,8 @@ #include /** - * @brief Simple First-In-First-Out data structure with size fixed at - * compile time + * @brief Simple First-In-First-Out data structure with size fixed at + * compile time * @details * Performs no dynamic memory allocation. * The public interface of FIFOBase exposes the user interface for the FIFO. @@ -16,32 +16,32 @@ template class FIFO: public FIFOBase { public: - FIFO(): FIFOBase(nullptr, capacity) { - this->setContainer(fifoArray.data()); - }; + FIFO(): FIFOBase(nullptr, capacity) { + this->setContainer(fifoArray.data()); + }; - /** - * @brief Custom copy constructor to set pointer correctly. - * @param other - */ - FIFO(const FIFO& other): FIFOBase(other) { - this->fifoArray = other.fifoArray; - this->setContainer(fifoArray.data()); - } + /** + * @brief Custom copy constructor to set pointer correctly. + * @param other + */ + FIFO(const FIFO& other): FIFOBase(other) { + this->fifoArray = other.fifoArray; + this->setContainer(fifoArray.data()); + } - /** - * @brief Custom assignment operator - * @param other - */ - FIFO& operator=(const FIFO& other){ - FIFOBase::operator=(other); - this->fifoArray = other.fifoArray; - this->setContainer(fifoArray.data()); - return *this; - } + /** + * @brief Custom assignment operator + * @param other + */ + FIFO& operator=(const FIFO& other){ + FIFOBase::operator=(other); + this->fifoArray = other.fifoArray; + this->setContainer(fifoArray.data()); + return *this; + } private: - std::array fifoArray; + std::array fifoArray; }; #endif /* FSFW_CONTAINER_FIFO_H_ */ diff --git a/container/FIFOBase.h b/container/FIFOBase.h index edd66d37a..eaa80346e 100644 --- a/container/FIFOBase.h +++ b/container/FIFOBase.h @@ -8,70 +8,70 @@ template class FIFOBase { public: - static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS; - static const ReturnValue_t FULL = MAKE_RETURN_CODE(1); - static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2); + static const uint8_t INTERFACE_ID = CLASS_ID::FIFO_CLASS; + static const ReturnValue_t FULL = MAKE_RETURN_CODE(1); + static const ReturnValue_t EMPTY = MAKE_RETURN_CODE(2); - /** Default ctor, takes pointer to first entry of underlying container - * and maximum capacity */ - FIFOBase(T* values, const size_t maxCapacity); + /** Default ctor, takes pointer to first entry of underlying container + * and maximum capacity */ + FIFOBase(T* values, const size_t maxCapacity); - /** - * Insert value into FIFO - * @param value - * @return RETURN_OK on success, FULL if full - */ - ReturnValue_t insert(T value); - /** - * Retrieve item from FIFO. This removes the item from the FIFO. - * @param value Must point to a valid T - * @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed - */ - ReturnValue_t retrieve(T *value); - /** - * Retrieve item from FIFO without removing it from FIFO. - * @param value Must point to a valid T - * @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed - */ - ReturnValue_t peek(T * value); - /** - * Remove item from FIFO. - * @return RETURN_OK on success, EMPTY if empty - */ - ReturnValue_t pop(); + /** + * Insert value into FIFO + * @param value + * @return RETURN_OK on success, FULL if full + */ + ReturnValue_t insert(T value); + /** + * Retrieve item from FIFO. This removes the item from the FIFO. + * @param value Must point to a valid T + * @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed + */ + ReturnValue_t retrieve(T *value); + /** + * Retrieve item from FIFO without removing it from FIFO. + * @param value Must point to a valid T + * @return RETURN_OK on success, EMPTY if empty and FAILED if nullptr check failed + */ + ReturnValue_t peek(T * value); + /** + * Remove item from FIFO. + * @return RETURN_OK on success, EMPTY if empty + */ + ReturnValue_t pop(); - /*** - * Check if FIFO is empty - * @return True if empty, False if not - */ - bool empty(); - /*** - * Check if FIFO is Full - * @return True if full, False if not - */ - bool full(); - /*** - * Current used size (elements) used - * @return size_t in elements - */ - size_t size(); - /*** - * Get maximal capacity of fifo - * @return size_t with max capacity of this fifo - */ - size_t getMaxCapacity() const; + /*** + * Check if FIFO is empty + * @return True if empty, False if not + */ + bool empty(); + /*** + * Check if FIFO is Full + * @return True if full, False if not + */ + bool full(); + /*** + * Current used size (elements) used + * @return size_t in elements + */ + size_t size(); + /*** + * Get maximal capacity of fifo + * @return size_t with max capacity of this fifo + */ + size_t getMaxCapacity() const; protected: - void setContainer(T* data); - size_t maxCapacity = 0; + void setContainer(T* data); + size_t maxCapacity = 0; - T* values; + T* values; - size_t readIndex = 0; - size_t writeIndex = 0; - size_t currentSize = 0; + size_t readIndex = 0; + size_t writeIndex = 0; + size_t currentSize = 0; - size_t next(size_t current); + size_t next(size_t current); }; #include "FIFOBase.tpp" diff --git a/container/FIFOBase.tpp b/container/FIFOBase.tpp index 763004b6f..2e6a3829c 100644 --- a/container/FIFOBase.tpp +++ b/container/FIFOBase.tpp @@ -7,87 +7,87 @@ template inline FIFOBase::FIFOBase(T* values, const size_t maxCapacity): - maxCapacity(maxCapacity), values(values){}; + maxCapacity(maxCapacity), values(values){}; template inline ReturnValue_t FIFOBase::insert(T value) { - if (full()) { - return FULL; - } else { - values[writeIndex] = value; - writeIndex = next(writeIndex); - ++currentSize; - return HasReturnvaluesIF::RETURN_OK; - } + if (full()) { + return FULL; + } else { + values[writeIndex] = value; + writeIndex = next(writeIndex); + ++currentSize; + return HasReturnvaluesIF::RETURN_OK; + } }; template inline ReturnValue_t FIFOBase::retrieve(T* value) { - if (empty()) { - return EMPTY; - } else { - if (value == nullptr){ - return HasReturnvaluesIF::RETURN_FAILED; - } - *value = values[readIndex]; - readIndex = next(readIndex); - --currentSize; - return HasReturnvaluesIF::RETURN_OK; - } + if (empty()) { + return EMPTY; + } else { + if (value == nullptr){ + return HasReturnvaluesIF::RETURN_FAILED; + } + *value = values[readIndex]; + readIndex = next(readIndex); + --currentSize; + return HasReturnvaluesIF::RETURN_OK; + } }; template inline ReturnValue_t FIFOBase::peek(T* value) { - if(empty()) { - return EMPTY; - } else { - if (value == nullptr){ - return HasReturnvaluesIF::RETURN_FAILED; - } - *value = values[readIndex]; - return HasReturnvaluesIF::RETURN_OK; - } + if(empty()) { + return EMPTY; + } else { + if (value == nullptr){ + return HasReturnvaluesIF::RETURN_FAILED; + } + *value = values[readIndex]; + return HasReturnvaluesIF::RETURN_OK; + } }; template inline ReturnValue_t FIFOBase::pop() { - T value; - return this->retrieve(&value); + T value; + return this->retrieve(&value); }; template inline bool FIFOBase::empty() { - return (currentSize == 0); + return (currentSize == 0); }; template inline bool FIFOBase::full() { - return (currentSize == maxCapacity); + return (currentSize == maxCapacity); } template inline size_t FIFOBase::size() { - return currentSize; + return currentSize; } template inline size_t FIFOBase::next(size_t current) { - ++current; - if (current == maxCapacity) { - current = 0; - } - return current; + ++current; + if (current == maxCapacity) { + current = 0; + } + return current; } template inline size_t FIFOBase::getMaxCapacity() const { - return maxCapacity; + return maxCapacity; } template inline void FIFOBase::setContainer(T *data) { - this->values = data; + this->values = data; } #endif diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index e9e127cf0..89b76388a 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -8,30 +8,30 @@ */ template class FixedArrayList: public ArrayList { - static_assert(MAX_SIZE <= (pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE"); + static_assert(MAX_SIZE <= (pow(2,sizeof(count_t)*8)-1), "count_t is not large enough to hold MAX_SIZE"); private: - T data[MAX_SIZE]; + T data[MAX_SIZE]; public: - FixedArrayList() : - ArrayList(data, MAX_SIZE) { - } + FixedArrayList() : + ArrayList(data, MAX_SIZE) { + } - FixedArrayList(const FixedArrayList& other) : - ArrayList(data, MAX_SIZE) { - memcpy(this->data, other.data, sizeof(this->data)); - this->entries = data; - this->size = other.size; - } + FixedArrayList(const FixedArrayList& other) : + ArrayList(data, MAX_SIZE) { + memcpy(this->data, other.data, sizeof(this->data)); + this->entries = data; + this->size = other.size; + } - FixedArrayList& operator=(FixedArrayList other) { - memcpy(this->data, other.data, sizeof(this->data)); - this->entries = data; - this->size = other.size; - return *this; - } + FixedArrayList& operator=(FixedArrayList other) { + memcpy(this->data, other.data, sizeof(this->data)); + this->entries = data; + this->size = other.size; + return *this; + } - virtual ~FixedArrayList() { - } + virtual ~FixedArrayList() { + } }; diff --git a/container/FixedMap.h b/container/FixedMap.h index 7a5220faa..bd8e0f835 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -18,212 +18,212 @@ */ template class FixedMap: public SerializeIF { - static_assert (std::is_trivially_copyable::value or - std::is_base_of::value, - "Types used in FixedMap must either be trivial copy-able or a " - "derived class from SerializeIF to be serialize-able"); + static_assert (std::is_trivially_copyable::value or + std::is_base_of::value, + "Types used in FixedMap must either be trivial copy-able or a " + "derived class from SerializeIF to be serialize-able"); public: - static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; - static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); - static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x02); - static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03); + static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; + static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); + static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x02); + static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03); private: - static const key_t EMPTY_SLOT = -1; - ArrayList, uint32_t> theMap; - uint32_t _size; + static const key_t EMPTY_SLOT = -1; + ArrayList, uint32_t> theMap; + uint32_t _size; - uint32_t findIndex(key_t key) const { - if (_size == 0) { - return 1; - } - uint32_t i = 0; - for (i = 0; i < _size; ++i) { - if (theMap[i].first == key) { - return i; - } - } - return i; - } + uint32_t findIndex(key_t key) const { + if (_size == 0) { + return 1; + } + uint32_t i = 0; + for (i = 0; i < _size; ++i) { + if (theMap[i].first == key) { + return i; + } + } + return i; + } public: - FixedMap(uint32_t maxSize) : - theMap(maxSize), _size(0) { - } + FixedMap(uint32_t maxSize) : + theMap(maxSize), _size(0) { + } - class Iterator: public ArrayList, uint32_t>::Iterator { - public: - Iterator() : - ArrayList, uint32_t>::Iterator() { - } + class Iterator: public ArrayList, uint32_t>::Iterator { + public: + Iterator() : + ArrayList, uint32_t>::Iterator() { + } - Iterator(std::pair *pair) : - ArrayList, uint32_t>::Iterator(pair) { - } - }; + Iterator(std::pair *pair) : + ArrayList, uint32_t>::Iterator(pair) { + } + }; - friend bool operator==(const typename FixedMap::Iterator& lhs, - const typename FixedMap::Iterator& rhs) { - return (lhs.value == rhs.value); - } + friend bool operator==(const typename FixedMap::Iterator& lhs, + const typename FixedMap::Iterator& rhs) { + return (lhs.value == rhs.value); + } - friend bool operator!=(const typename FixedMap::Iterator& lhs, - const typename FixedMap::Iterator& rhs) { - return not (lhs.value == rhs.value); - } + friend bool operator!=(const typename FixedMap::Iterator& lhs, + const typename FixedMap::Iterator& rhs) { + return not (lhs.value == rhs.value); + } - Iterator begin() const { - return Iterator(&theMap[0]); - } + Iterator begin() const { + return Iterator(&theMap[0]); + } - Iterator end() const { - return Iterator(&theMap[_size]); - } + Iterator end() const { + return Iterator(&theMap[_size]); + } - uint32_t size() const { - return _size; - } + uint32_t size() const { + return _size; + } - ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) { - if (exists(key) == HasReturnvaluesIF::RETURN_OK) { - return KEY_ALREADY_EXISTS; - } - if (_size == theMap.maxSize()) { - return MAP_FULL; - } - theMap[_size].first = key; - theMap[_size].second = value; - if (storedValue != nullptr) { - *storedValue = Iterator(&theMap[_size]); - } - ++_size; - return HasReturnvaluesIF::RETURN_OK; - } + ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr) { + if (exists(key) == HasReturnvaluesIF::RETURN_OK) { + return KEY_ALREADY_EXISTS; + } + if (_size == theMap.maxSize()) { + return MAP_FULL; + } + theMap[_size].first = key; + theMap[_size].second = value; + if (storedValue != nullptr) { + *storedValue = Iterator(&theMap[_size]); + } + ++_size; + return HasReturnvaluesIF::RETURN_OK; + } - ReturnValue_t insert(std::pair pair) { - return insert(pair.first, pair.second); - } + ReturnValue_t insert(std::pair pair) { + return insert(pair.first, pair.second); + } - ReturnValue_t exists(key_t key) const { - ReturnValue_t result = KEY_DOES_NOT_EXIST; - if (findIndex(key) < _size) { - result = HasReturnvaluesIF::RETURN_OK; - } - return result; - } + ReturnValue_t exists(key_t key) const { + ReturnValue_t result = KEY_DOES_NOT_EXIST; + if (findIndex(key) < _size) { + result = HasReturnvaluesIF::RETURN_OK; + } + return result; + } - ReturnValue_t erase(Iterator *iter) { - uint32_t i; - if ((i = findIndex((*iter).value->first)) >= _size) { - return KEY_DOES_NOT_EXIST; - } - theMap[i] = theMap[_size - 1]; - --_size; - --((*iter).value); - return HasReturnvaluesIF::RETURN_OK; - } + ReturnValue_t erase(Iterator *iter) { + uint32_t i; + if ((i = findIndex((*iter).value->first)) >= _size) { + return KEY_DOES_NOT_EXIST; + } + theMap[i] = theMap[_size - 1]; + --_size; + --((*iter).value); + return HasReturnvaluesIF::RETURN_OK; + } - ReturnValue_t erase(key_t key) { - uint32_t i; - if ((i = findIndex(key)) >= _size) { - return KEY_DOES_NOT_EXIST; - } - theMap[i] = theMap[_size - 1]; - --_size; - return HasReturnvaluesIF::RETURN_OK; - } + ReturnValue_t erase(key_t key) { + uint32_t i; + if ((i = findIndex(key)) >= _size) { + return KEY_DOES_NOT_EXIST; + } + theMap[i] = theMap[_size - 1]; + --_size; + return HasReturnvaluesIF::RETURN_OK; + } - T *findValue(key_t key) const { - return &theMap[findIndex(key)].second; - } + T *findValue(key_t key) const { + return &theMap[findIndex(key)].second; + } - Iterator find(key_t key) const { - ReturnValue_t result = exists(key); - if (result != HasReturnvaluesIF::RETURN_OK) { - return end(); - } - return Iterator(&theMap[findIndex(key)]); - } + Iterator find(key_t key) const { + ReturnValue_t result = exists(key); + if (result != HasReturnvaluesIF::RETURN_OK) { + return end(); + } + return Iterator(&theMap[findIndex(key)]); + } - ReturnValue_t find(key_t key, T **value) const { - ReturnValue_t result = exists(key); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - *value = &theMap[findIndex(key)].second; - return HasReturnvaluesIF::RETURN_OK; - } + ReturnValue_t find(key_t key, T **value) const { + ReturnValue_t result = exists(key); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + *value = &theMap[findIndex(key)].second; + return HasReturnvaluesIF::RETURN_OK; + } - bool empty() { - if(_size == 0) { - return true; - } - else { - return false; - } - } + bool empty() { + if(_size == 0) { + return true; + } + else { + return false; + } + } - bool full() { - if(_size >= theMap.maxSize()) { - return true; - } - else { - return false; - } - } + bool full() { + if(_size >= theMap.maxSize()) { + return true; + } + else { + return false; + } + } - void clear() { - _size = 0; - } + void clear() { + _size = 0; + } - uint32_t maxSize() const { - return theMap.maxSize(); - } + uint32_t maxSize() const { + return theMap.maxSize(); + } - virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, - size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = SerializeAdapter::serialize(&this->_size, - buffer, size, maxSize, streamEndianness); - uint32_t i = 0; - while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->_size)) { - result = SerializeAdapter::serialize(&theMap[i].first, buffer, - size, maxSize, streamEndianness); - result = SerializeAdapter::serialize(&theMap[i].second, buffer, size, - maxSize, streamEndianness); - ++i; - } - return result; - } + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + size_t maxSize, Endianness streamEndianness) const { + ReturnValue_t result = SerializeAdapter::serialize(&this->_size, + buffer, size, maxSize, streamEndianness); + uint32_t i = 0; + while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->_size)) { + result = SerializeAdapter::serialize(&theMap[i].first, buffer, + size, maxSize, streamEndianness); + result = SerializeAdapter::serialize(&theMap[i].second, buffer, size, + maxSize, streamEndianness); + ++i; + } + return result; + } - virtual size_t getSerializedSize() const { - uint32_t printSize = sizeof(_size); - uint32_t i = 0; + virtual size_t getSerializedSize() const { + uint32_t printSize = sizeof(_size); + uint32_t i = 0; - for (i = 0; i < _size; ++i) { - printSize += SerializeAdapter::getSerializedSize( - &theMap[i].first); - printSize += SerializeAdapter::getSerializedSize(&theMap[i].second); - } + for (i = 0; i < _size; ++i) { + printSize += SerializeAdapter::getSerializedSize( + &theMap[i].first); + printSize += SerializeAdapter::getSerializedSize(&theMap[i].second); + } - return printSize; - } + return printSize; + } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness) { - ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size, - buffer, size, streamEndianness); - if (this->_size > theMap.maxSize()) { - return SerializeIF::TOO_MANY_ELEMENTS; - } - uint32_t i = 0; - while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->_size)) { - result = SerializeAdapter::deSerialize(&theMap[i].first, buffer, - size, streamEndianness); - result = SerializeAdapter::deSerialize(&theMap[i].second, buffer, size, - streamEndianness); - ++i; - } - return result; - } + virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness) { + ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size, + buffer, size, streamEndianness); + if (this->_size > theMap.maxSize()) { + return SerializeIF::TOO_MANY_ELEMENTS; + } + uint32_t i = 0; + while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->_size)) { + result = SerializeAdapter::deSerialize(&theMap[i].first, buffer, + size, streamEndianness); + result = SerializeAdapter::deSerialize(&theMap[i].second, buffer, size, + streamEndianness); + ++i; + } + return result; + } }; diff --git a/container/FixedOrderedMultimap.h b/container/FixedOrderedMultimap.h index acf2368af..cb8abdcaf 100644 --- a/container/FixedOrderedMultimap.h +++ b/container/FixedOrderedMultimap.h @@ -34,172 +34,172 @@ template> class FixedOrderedMultimap { public: - static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MULTIMAP; - static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x01); - static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x02); + static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MULTIMAP; + static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x01); + static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x02); - /*** - * Constructor which needs a size_t for the maximum allowed size - * - * Can not be resized during runtime - * - * Allocates memory at construction - * @param maxSize size_t of Maximum allowed size - */ + /*** + * Constructor which needs a size_t for the maximum allowed size + * + * Can not be resized during runtime + * + * Allocates memory at construction + * @param maxSize size_t of Maximum allowed size + */ FixedOrderedMultimap(size_t maxSize):theMap(maxSize), _size(0){ } - /*** - * Virtual destructor frees Memory by deleting its member - */ - virtual ~FixedOrderedMultimap() { - } + /*** + * Virtual destructor frees Memory by deleting its member + */ + virtual ~FixedOrderedMultimap() { + } - /*** - * Special iterator for FixedOrderedMultimap - */ - class Iterator: public ArrayList, size_t>::Iterator { - public: - Iterator() : - ArrayList, size_t>::Iterator() { - } + /*** + * Special iterator for FixedOrderedMultimap + */ + class Iterator: public ArrayList, size_t>::Iterator { + public: + Iterator() : + ArrayList, size_t>::Iterator() { + } - Iterator(std::pair *pair) : - ArrayList, size_t>::Iterator(pair) { - } - }; + Iterator(std::pair *pair) : + ArrayList, size_t>::Iterator(pair) { + } + }; - /*** - * Returns an iterator pointing to the first element - * @return Iterator pointing to first element - */ - Iterator begin() const { - return Iterator(&theMap[0]); - } + /*** + * Returns an iterator pointing to the first element + * @return Iterator pointing to first element + */ + Iterator begin() const { + return Iterator(&theMap[0]); + } - /** - * Returns an iterator pointing to one element past the end - * @return Iterator pointing to one element past the end - */ - Iterator end() const { - return Iterator(&theMap[_size]); - } + /** + * Returns an iterator pointing to one element past the end + * @return Iterator pointing to one element past the end + */ + Iterator end() const { + return Iterator(&theMap[_size]); + } - /*** - * Returns the current size of the map (not maximum size!) - * @return Current size - */ - size_t size() const{ - return _size; - } + /*** + * Returns the current size of the map (not maximum size!) + * @return Current size + */ + size_t size() const{ + return _size; + } - /** - * Clears the map, does not deallocate any memory - */ - void clear(){ - _size = 0; - } + /** + * Clears the map, does not deallocate any memory + */ + void clear(){ + _size = 0; + } - /** - * Returns the maximum size of the map - * @return Maximum size of the map - */ - size_t maxSize() const{ - return theMap.maxSize(); - } + /** + * Returns the maximum size of the map + * @return Maximum size of the map + */ + size_t maxSize() const{ + return theMap.maxSize(); + } - /*** - * Used to insert a key and value separately. - * - * @param[in] key Key of the new element - * @param[in] value Value of the new element - * @param[in/out] (optional) storedValue On success this points to the new value, otherwise a nullptr - * @return RETURN_OK if insert was successful, MAP_FULL if no space is available - */ - ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr); + /*** + * Used to insert a key and value separately. + * + * @param[in] key Key of the new element + * @param[in] value Value of the new element + * @param[in/out] (optional) storedValue On success this points to the new value, otherwise a nullptr + * @return RETURN_OK if insert was successful, MAP_FULL if no space is available + */ + ReturnValue_t insert(key_t key, T value, Iterator *storedValue = nullptr); - /*** - * Used to insert new pair instead of single values - * - * @param pair Pair to be inserted - * @return RETURN_OK if insert was successful, MAP_FULL if no space is available - */ - ReturnValue_t insert(std::pair pair); + /*** + * Used to insert new pair instead of single values + * + * @param pair Pair to be inserted + * @return RETURN_OK if insert was successful, MAP_FULL if no space is available + */ + ReturnValue_t insert(std::pair pair); - /*** - * Can be used to check if a certain key is in the map - * @param key Key to be checked - * @return RETURN_OK if the key exists KEY_DOES_NOT_EXIST otherwise - */ - ReturnValue_t exists(key_t key) const; + /*** + * Can be used to check if a certain key is in the map + * @param key Key to be checked + * @return RETURN_OK if the key exists KEY_DOES_NOT_EXIST otherwise + */ + ReturnValue_t exists(key_t key) const; - /*** - * Used to delete the element in the iterator - * - * The iterator will point to the element before or begin(), - * but never to one element in front of the map. - * - * @warning The iterator needs to be valid and dereferenceable - * @param[in/out] iter Pointer to iterator to the element that needs to be ereased - * @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this - */ - ReturnValue_t erase(Iterator *iter); + /*** + * Used to delete the element in the iterator + * + * The iterator will point to the element before or begin(), + * but never to one element in front of the map. + * + * @warning The iterator needs to be valid and dereferenceable + * @param[in/out] iter Pointer to iterator to the element that needs to be ereased + * @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this + */ + ReturnValue_t erase(Iterator *iter); - /*** - * Used to erase by key - * @param key Key to be erased - * @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this - */ - ReturnValue_t erase(key_t key); + /*** + * Used to erase by key + * @param key Key to be erased + * @return RETURN_OK if erased, KEY_DOES_NOT_EXIST if the there is no element like this + */ + ReturnValue_t erase(key_t key); - /*** - * Find returns the first appearance of the key - * - * If the key does not exist, it points to end() - * - * @param key Key to search for - * @return Iterator pointing to the first entry of key - */ - Iterator find(key_t key) const{ - ReturnValue_t result = exists(key); - if (result != HasReturnvaluesIF::RETURN_OK) { - return end(); - } - return Iterator(&theMap[findFirstIndex(key)]); - }; + /*** + * Find returns the first appearance of the key + * + * If the key does not exist, it points to end() + * + * @param key Key to search for + * @return Iterator pointing to the first entry of key + */ + Iterator find(key_t key) const{ + ReturnValue_t result = exists(key); + if (result != HasReturnvaluesIF::RETURN_OK) { + return end(); + } + return Iterator(&theMap[findFirstIndex(key)]); + }; - /*** - * Finds first entry of the given key and returns a - * pointer to the value - * - * @param key Key to search for - * @param value Found value - * @return RETURN_OK if it points to the value, - * KEY_DOES_NOT_EXIST if the key is not in the map - */ - ReturnValue_t find(key_t key, T **value) const; + /*** + * Finds first entry of the given key and returns a + * pointer to the value + * + * @param key Key to search for + * @param value Found value + * @return RETURN_OK if it points to the value, + * KEY_DOES_NOT_EXIST if the key is not in the map + */ + ReturnValue_t find(key_t key, T **value) const; - friend bool operator==(const typename FixedOrderedMultimap::Iterator& lhs, - const typename FixedOrderedMultimap::Iterator& rhs) { - return (lhs.value == rhs.value); - } + friend bool operator==(const typename FixedOrderedMultimap::Iterator& lhs, + const typename FixedOrderedMultimap::Iterator& rhs) { + return (lhs.value == rhs.value); + } - friend bool operator!=(const typename FixedOrderedMultimap::Iterator& lhs, - const typename FixedOrderedMultimap::Iterator& rhs) { - return not (lhs.value == rhs.value); - } + friend bool operator!=(const typename FixedOrderedMultimap::Iterator& lhs, + const typename FixedOrderedMultimap::Iterator& rhs) { + return not (lhs.value == rhs.value); + } private: - typedef KEY_COMPARE compare; - compare myComp; - ArrayList, size_t> theMap; - size_t _size; + typedef KEY_COMPARE compare; + compare myComp; + ArrayList, size_t> theMap; + size_t _size; - size_t findFirstIndex(key_t key, size_t startAt = 0) const; + size_t findFirstIndex(key_t key, size_t startAt = 0) const; - size_t findNicePlace(key_t key) const; + size_t findNicePlace(key_t key) const; - void removeFromPosition(size_t position); + void removeFromPosition(size_t position); }; #include "FixedOrderedMultimap.tpp" diff --git a/container/FixedOrderedMultimap.tpp b/container/FixedOrderedMultimap.tpp index 4aa85e974..294a161fe 100644 --- a/container/FixedOrderedMultimap.tpp +++ b/container/FixedOrderedMultimap.tpp @@ -4,105 +4,105 @@ template inline ReturnValue_t FixedOrderedMultimap::insert(key_t key, T value, Iterator *storedValue) { - if (_size == theMap.maxSize()) { - return MAP_FULL; - } - size_t position = findNicePlace(key); - memmove(static_cast(&theMap[position + 1]),static_cast(&theMap[position]), - (_size - position) * sizeof(std::pair)); - theMap[position].first = key; - theMap[position].second = value; - ++_size; - if (storedValue != nullptr) { - *storedValue = Iterator(&theMap[position]); - } - return HasReturnvaluesIF::RETURN_OK; + if (_size == theMap.maxSize()) { + return MAP_FULL; + } + size_t position = findNicePlace(key); + memmove(static_cast(&theMap[position + 1]),static_cast(&theMap[position]), + (_size - position) * sizeof(std::pair)); + theMap[position].first = key; + theMap[position].second = value; + ++_size; + if (storedValue != nullptr) { + *storedValue = Iterator(&theMap[position]); + } + return HasReturnvaluesIF::RETURN_OK; } template inline ReturnValue_t FixedOrderedMultimap::insert(std::pair pair) { - return insert(pair.first, pair.second); + return insert(pair.first, pair.second); } template inline ReturnValue_t FixedOrderedMultimap::exists(key_t key) const { - ReturnValue_t result = KEY_DOES_NOT_EXIST; - if (findFirstIndex(key) < _size) { - result = HasReturnvaluesIF::RETURN_OK; - } - return result; + ReturnValue_t result = KEY_DOES_NOT_EXIST; + if (findFirstIndex(key) < _size) { + result = HasReturnvaluesIF::RETURN_OK; + } + return result; } template inline ReturnValue_t FixedOrderedMultimap::erase(Iterator *iter) { - size_t i; - if ((i = findFirstIndex((*iter).value->first)) >= _size) { - return KEY_DOES_NOT_EXIST; - } - removeFromPosition(i); - if (*iter != begin()) { - (*iter)--; - } else { - *iter = begin(); - } - return HasReturnvaluesIF::RETURN_OK; + size_t i; + if ((i = findFirstIndex((*iter).value->first)) >= _size) { + return KEY_DOES_NOT_EXIST; + } + removeFromPosition(i); + if (*iter != begin()) { + (*iter)--; + } else { + *iter = begin(); + } + return HasReturnvaluesIF::RETURN_OK; } template inline ReturnValue_t FixedOrderedMultimap::erase(key_t key) { - size_t i; - if ((i = findFirstIndex(key)) >= _size) { - return KEY_DOES_NOT_EXIST; - } - do { - removeFromPosition(i); - i = findFirstIndex(key, i); - } while (i < _size); - return HasReturnvaluesIF::RETURN_OK; + size_t i; + if ((i = findFirstIndex(key)) >= _size) { + return KEY_DOES_NOT_EXIST; + } + do { + removeFromPosition(i); + i = findFirstIndex(key, i); + } while (i < _size); + return HasReturnvaluesIF::RETURN_OK; } template inline ReturnValue_t FixedOrderedMultimap::find(key_t key, T **value) const { - ReturnValue_t result = exists(key); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - *value = &theMap[findFirstIndex(key)].second; - return HasReturnvaluesIF::RETURN_OK; + ReturnValue_t result = exists(key); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + *value = &theMap[findFirstIndex(key)].second; + return HasReturnvaluesIF::RETURN_OK; } template inline size_t FixedOrderedMultimap::findFirstIndex(key_t key, size_t startAt) const { - if (startAt >= _size) { - return startAt + 1; - } - size_t i = startAt; - for (i = startAt; i < _size; ++i) { - if (theMap[i].first == key) { - return i; - } - } - return i; + if (startAt >= _size) { + return startAt + 1; + } + size_t i = startAt; + for (i = startAt; i < _size; ++i) { + if (theMap[i].first == key) { + return i; + } + } + return i; } template inline size_t FixedOrderedMultimap::findNicePlace(key_t key) const { - size_t i = 0; - for (i = 0; i < _size; ++i) { - if (myComp(key, theMap[i].first)) { - return i; - } - } - return i; + size_t i = 0; + for (i = 0; i < _size; ++i) { + if (myComp(key, theMap[i].first)) { + return i; + } + } + return i; } template inline void FixedOrderedMultimap::removeFromPosition(size_t position) { - if (_size <= position) { - return; - } - memmove(static_cast(&theMap[position]), static_cast(&theMap[position + 1]), - (_size - position - 1) * sizeof(std::pair)); - --_size; + if (_size <= position) { + return; + } + memmove(static_cast(&theMap[position]), static_cast(&theMap[position + 1]), + (_size - position - 1) * sizeof(std::pair)); + --_size; } diff --git a/container/HybridIterator.h b/container/HybridIterator.h index 8d020cb93..6e33e4611 100644 --- a/container/HybridIterator.h +++ b/container/HybridIterator.h @@ -6,85 +6,85 @@ template class HybridIterator: public LinkedElement::Iterator, - public ArrayList::Iterator { + public ArrayList::Iterator { public: - HybridIterator() {} + HybridIterator() {} - HybridIterator(typename LinkedElement::Iterator *iter) : - LinkedElement::Iterator(*iter), value(iter->value), - linked(true) { + HybridIterator(typename LinkedElement::Iterator *iter) : + LinkedElement::Iterator(*iter), value(iter->value), + linked(true) { - } + } - HybridIterator(LinkedElement *start) : - LinkedElement::Iterator(start), value(start->value), - linked(true) { + HybridIterator(LinkedElement *start) : + LinkedElement::Iterator(start), value(start->value), + linked(true) { - } + } - HybridIterator(typename ArrayList::Iterator start, - typename ArrayList::Iterator end) : - ArrayList::Iterator(start), value(start.value), - linked(false), end(end.value) { - if (value == this->end) { - value = NULL; - } - } + HybridIterator(typename ArrayList::Iterator start, + typename ArrayList::Iterator end) : + ArrayList::Iterator(start), value(start.value), + linked(false), end(end.value) { + if (value == this->end) { + value = NULL; + } + } - HybridIterator(T *firstElement, T *lastElement) : - ArrayList::Iterator(firstElement), value(firstElement), - linked(false), end(++lastElement) { - if (value == end) { - value = NULL; - } - } + HybridIterator(T *firstElement, T *lastElement) : + ArrayList::Iterator(firstElement), value(firstElement), + linked(false), end(++lastElement) { + if (value == end) { + value = NULL; + } + } - HybridIterator& operator++() { - if (linked) { - LinkedElement::Iterator::operator++(); - if (LinkedElement::Iterator::value != nullptr) { - value = LinkedElement::Iterator::value->value; - } else { - value = nullptr; - } - } else { - ArrayList::Iterator::operator++(); - value = ArrayList::Iterator::value; + HybridIterator& operator++() { + if (linked) { + LinkedElement::Iterator::operator++(); + if (LinkedElement::Iterator::value != nullptr) { + value = LinkedElement::Iterator::value->value; + } else { + value = nullptr; + } + } else { + ArrayList::Iterator::operator++(); + value = ArrayList::Iterator::value; - if (value == end) { - value = nullptr; - } - } - return *this; - } + if (value == end) { + value = nullptr; + } + } + return *this; + } - HybridIterator operator++(int) { - HybridIterator tmp(*this); - operator++(); - return tmp; - } + HybridIterator operator++(int) { + HybridIterator tmp(*this); + operator++(); + return tmp; + } - bool operator==(const HybridIterator& other) const { - return value == other.value; - } + bool operator==(const HybridIterator& other) const { + return value == other.value; + } - bool operator!=(const HybridIterator& other) const { - return !(*this == other); - } + bool operator!=(const HybridIterator& other) const { + return !(*this == other); + } - T operator*() { - return *value; - } + T operator*() { + return *value; + } - T *operator->() { - return value; - } + T *operator->() { + return value; + } - T* value = nullptr; + T* value = nullptr; private: - bool linked = false; - T *end = nullptr; + bool linked = false; + T *end = nullptr; }; #endif /* FRAMEWORK_CONTAINER_HYBRIDITERATOR_H_ */ diff --git a/container/IndexedRingMemoryArray.h b/container/IndexedRingMemoryArray.h index 0d85b49bc..df8980f7e 100644 --- a/container/IndexedRingMemoryArray.h +++ b/container/IndexedRingMemoryArray.h @@ -10,687 +10,687 @@ template class Index: public SerializeIF{ - /** - * Index is the Type used for the list of indices. The template parameter is the type which describes the index, it needs to be a child of SerializeIF to be able to make it persistent - */ - static_assert(std::is_base_of::value,"Wrong Type for Index, Type must implement SerializeIF"); + /** + * Index is the Type used for the list of indices. The template parameter is the type which describes the index, it needs to be a child of SerializeIF to be able to make it persistent + */ + static_assert(std::is_base_of::value,"Wrong Type for Index, Type must implement SerializeIF"); public: - Index():blockStartAddress(0),size(0),storedPackets(0){} + Index():blockStartAddress(0),size(0),storedPackets(0){} - Index(uint32_t startAddress):blockStartAddress(startAddress),size(0),storedPackets(0){ + Index(uint32_t startAddress):blockStartAddress(startAddress),size(0),storedPackets(0){ - } + } - void setBlockStartAddress(uint32_t newAddress){ - this->blockStartAddress = newAddress; - } + void setBlockStartAddress(uint32_t newAddress){ + this->blockStartAddress = newAddress; + } - uint32_t getBlockStartAddress() const { - return blockStartAddress; - } + uint32_t getBlockStartAddress() const { + return blockStartAddress; + } - const T* getIndexType() const { - return &indexType; - } + const T* getIndexType() const { + return &indexType; + } - T* modifyIndexType(){ - return &indexType; - } - /** - * Updates the index Type. Uses = operator - * @param indexType Type to copy from - */ - void setIndexType(T* indexType) { - this->indexType = *indexType; - } + T* modifyIndexType(){ + return &indexType; + } + /** + * Updates the index Type. Uses = operator + * @param indexType Type to copy from + */ + void setIndexType(T* indexType) { + this->indexType = *indexType; + } - uint32_t getSize() const { - return size; - } + uint32_t getSize() const { + return size; + } - void setSize(uint32_t size) { - this->size = size; - } + void setSize(uint32_t size) { + this->size = size; + } - void addSize(uint32_t size){ - this->size += size; - } + void addSize(uint32_t size){ + this->size += size; + } - void setStoredPackets(uint32_t newStoredPackets){ - this->storedPackets = newStoredPackets; - } + void setStoredPackets(uint32_t newStoredPackets){ + this->storedPackets = newStoredPackets; + } - void addStoredPackets(uint32_t packets){ - this->storedPackets += packets; - } + void addStoredPackets(uint32_t packets){ + this->storedPackets += packets; + } - uint32_t getStoredPackets() const{ - return this->storedPackets; - } + uint32_t getStoredPackets() const{ + return this->storedPackets; + } - ReturnValue_t serialize(uint8_t** buffer, size_t* size, - size_t maxSize, Endianness streamEndianness) const { - ReturnValue_t result = SerializeAdapter::serialize(&blockStartAddress,buffer,size,maxSize,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - result = indexType.serialize(buffer,size,maxSize,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - result = SerializeAdapter::serialize(&this->size,buffer,size,maxSize,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - result = SerializeAdapter::serialize(&this->storedPackets,buffer,size,maxSize,streamEndianness); - return result; - } + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + size_t maxSize, Endianness streamEndianness) const { + ReturnValue_t result = SerializeAdapter::serialize(&blockStartAddress,buffer,size,maxSize,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + result = indexType.serialize(buffer,size,maxSize,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + result = SerializeAdapter::serialize(&this->size,buffer,size,maxSize,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + result = SerializeAdapter::serialize(&this->storedPackets,buffer,size,maxSize,streamEndianness); + return result; + } - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness){ - ReturnValue_t result = SerializeAdapter::deSerialize(&blockStartAddress,buffer,size,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - result = indexType.deSerialize(buffer,size,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - result = SerializeAdapter::deSerialize(&this->size,buffer,size,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - result = SerializeAdapter::deSerialize(&this->storedPackets,buffer,size,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - return result; - } + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness){ + ReturnValue_t result = SerializeAdapter::deSerialize(&blockStartAddress,buffer,size,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + result = indexType.deSerialize(buffer,size,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + result = SerializeAdapter::deSerialize(&this->size,buffer,size,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + result = SerializeAdapter::deSerialize(&this->storedPackets,buffer,size,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + return result; + } - size_t getSerializedSize() const { - uint32_t size = SerializeAdapter::getSerializedSize(&blockStartAddress); - size += indexType.getSerializedSize(); - size += SerializeAdapter::getSerializedSize(&this->size); - size += SerializeAdapter::getSerializedSize(&this->storedPackets); - return size; - } + size_t getSerializedSize() const { + uint32_t size = SerializeAdapter::getSerializedSize(&blockStartAddress); + size += indexType.getSerializedSize(); + size += SerializeAdapter::getSerializedSize(&this->size); + size += SerializeAdapter::getSerializedSize(&this->storedPackets); + return size; + } - bool operator==(const Index& other){ - return ((blockStartAddress == other.getBlockStartAddress()) && (size==other.getSize())) && (indexType == *(other.getIndexType())); - } + bool operator==(const Index& other){ + return ((blockStartAddress == other.getBlockStartAddress()) && (size==other.getSize())) && (indexType == *(other.getIndexType())); + } private: - uint32_t blockStartAddress; - uint32_t size; - uint32_t storedPackets; - T indexType; + uint32_t blockStartAddress; + uint32_t size; + uint32_t storedPackets; + T indexType; }; template class IndexedRingMemoryArray: public SerializeIF, public ArrayList, uint32_t>{ - /** - * Indexed Ring Memory Array is a class for a ring memory with indices. It assumes that the newest data comes in last - * It uses the currentWriteBlock as pointer to the current writing position - * The currentReadBlock must be set manually - */ + /** + * Indexed Ring Memory Array is a class for a ring memory with indices. It assumes that the newest data comes in last + * It uses the currentWriteBlock as pointer to the current writing position + * The currentReadBlock must be set manually + */ public: - IndexedRingMemoryArray(uint32_t startAddress, uint32_t size, uint32_t bytesPerBlock, SerializeIF* additionalInfo, - bool overwriteOld) :ArrayList,uint32_t>(NULL,(uint32_t)10,(uint32_t)0),totalSize(size),indexAddress(startAddress),currentReadSize(0),currentReadBlockSizeCached(0),lastBlockToReadSize(0), additionalInfo(additionalInfo),overwriteOld(overwriteOld){ + IndexedRingMemoryArray(uint32_t startAddress, uint32_t size, uint32_t bytesPerBlock, SerializeIF* additionalInfo, + bool overwriteOld) :ArrayList,uint32_t>(NULL,(uint32_t)10,(uint32_t)0),totalSize(size),indexAddress(startAddress),currentReadSize(0),currentReadBlockSizeCached(0),lastBlockToReadSize(0), additionalInfo(additionalInfo),overwriteOld(overwriteOld){ - //Calculate the maximum number of indices needed for this blocksize - uint32_t maxNrOfIndices = floor(static_cast(size)/static_cast(bytesPerBlock)); + //Calculate the maximum number of indices needed for this blocksize + uint32_t maxNrOfIndices = floor(static_cast(size)/static_cast(bytesPerBlock)); - //Calculate the Size needeed for the index itself - uint32_t serializedSize = 0; - if(additionalInfo!=NULL){ - serializedSize += additionalInfo->getSerializedSize(); - } - //Size of current iterator type - Index tempIndex; - serializedSize += tempIndex.getSerializedSize(); + //Calculate the Size needeed for the index itself + uint32_t serializedSize = 0; + if(additionalInfo!=NULL){ + serializedSize += additionalInfo->getSerializedSize(); + } + //Size of current iterator type + Index tempIndex; + serializedSize += tempIndex.getSerializedSize(); - //Add Size of Array - serializedSize += sizeof(uint32_t); //size of array - serializedSize += (tempIndex.getSerializedSize() * maxNrOfIndices); //size of elements - serializedSize += sizeof(uint16_t); //size of crc + //Add Size of Array + serializedSize += sizeof(uint32_t); //size of array + serializedSize += (tempIndex.getSerializedSize() * maxNrOfIndices); //size of elements + serializedSize += sizeof(uint16_t); //size of crc - //Calculate new size after index - if(serializedSize > totalSize){ - error << "IndexedRingMemory: Store is too small for index" << std::endl; - } - uint32_t useableSize = totalSize - serializedSize; - //Update the totalSize for calculations - totalSize = useableSize; + //Calculate new size after index + if(serializedSize > totalSize){ + error << "IndexedRingMemory: Store is too small for index" << std::endl; + } + uint32_t useableSize = totalSize - serializedSize; + //Update the totalSize for calculations + totalSize = useableSize; - //True StartAddress - uint32_t trueStartAddress = indexAddress + serializedSize; + //True StartAddress + uint32_t trueStartAddress = indexAddress + serializedSize; - //Calculate True number of Blocks and reset size of true Number of Blocks - uint32_t trueNumberOfBlocks = floor(static_cast(totalSize) / static_cast(bytesPerBlock)); + //Calculate True number of Blocks and reset size of true Number of Blocks + uint32_t trueNumberOfBlocks = floor(static_cast(totalSize) / static_cast(bytesPerBlock)); - //allocate memory now - this->entries = new Index[trueNumberOfBlocks]; - this->size = trueNumberOfBlocks; - this->maxSize_ = trueNumberOfBlocks; - this->allocated = true; + //allocate memory now + this->entries = new Index[trueNumberOfBlocks]; + this->size = trueNumberOfBlocks; + this->maxSize_ = trueNumberOfBlocks; + this->allocated = true; - //Check trueNumberOfBlocks - if(trueNumberOfBlocks<1){ - error << "IndexedRingMemory: Invalid Number of Blocks: " << trueNumberOfBlocks; - } + //Check trueNumberOfBlocks + if(trueNumberOfBlocks<1){ + error << "IndexedRingMemory: Invalid Number of Blocks: " << trueNumberOfBlocks; + } - //Fill address into index - uint32_t address = trueStartAddress; - for (typename IndexedRingMemoryArray::Iterator it = this->begin();it!=this->end();++it) { - it->setBlockStartAddress(address); - it->setSize(0); - it->setStoredPackets(0); - address += bytesPerBlock; - } + //Fill address into index + uint32_t address = trueStartAddress; + for (typename IndexedRingMemoryArray::Iterator it = this->begin();it!=this->end();++it) { + it->setBlockStartAddress(address); + it->setSize(0); + it->setStoredPackets(0); + address += bytesPerBlock; + } - //Initialize iterators - currentWriteBlock = this->begin(); - currentReadBlock = this->begin(); - lastBlockToRead = this->begin(); + //Initialize iterators + currentWriteBlock = this->begin(); + currentReadBlock = this->begin(); + lastBlockToRead = this->begin(); - //Check last blockSize - uint32_t lastBlockSize = (trueStartAddress + useableSize) - (this->back()->getBlockStartAddress()); - if((lastBlockSizesize > 1)){ - //remove the last Block so the second last block has more size - this->size -= 1; - debug << "IndexedRingMemory: Last Block is smaller than bytesPerBlock, removed last block" << std::endl; - } - } + //Check last blockSize + uint32_t lastBlockSize = (trueStartAddress + useableSize) - (this->back()->getBlockStartAddress()); + if((lastBlockSizesize > 1)){ + //remove the last Block so the second last block has more size + this->size -= 1; + debug << "IndexedRingMemory: Last Block is smaller than bytesPerBlock, removed last block" << std::endl; + } + } - /** - * Resets the whole index, the iterators and executes the given reset function on every index type - * @param typeResetFnc static reset function which accepts a pointer to the index Type - */ - void reset(void (*typeResetFnc)(T*)){ - currentReadBlock = this->begin(); - currentWriteBlock = this->begin(); - lastBlockToRead = this->begin(); - currentReadSize = 0; - currentReadBlockSizeCached = 0; - lastBlockToReadSize = 0; - for(typename IndexedRingMemoryArray::Iterator it = this->begin();it!=this->end();++it){ - it->setSize(0); - it->setStoredPackets(0); - (*typeResetFnc)(it->modifyIndexType()); - } - } + /** + * Resets the whole index, the iterators and executes the given reset function on every index type + * @param typeResetFnc static reset function which accepts a pointer to the index Type + */ + void reset(void (*typeResetFnc)(T*)){ + currentReadBlock = this->begin(); + currentWriteBlock = this->begin(); + lastBlockToRead = this->begin(); + currentReadSize = 0; + currentReadBlockSizeCached = 0; + lastBlockToReadSize = 0; + for(typename IndexedRingMemoryArray::Iterator it = this->begin();it!=this->end();++it){ + it->setSize(0); + it->setStoredPackets(0); + (*typeResetFnc)(it->modifyIndexType()); + } + } - void resetBlock(typename IndexedRingMemoryArray::Iterator it,void (*typeResetFnc)(T*)){ - it->setSize(0); - it->setStoredPackets(0); - (*typeResetFnc)(it->modifyIndexType()); - } + void resetBlock(typename IndexedRingMemoryArray::Iterator it,void (*typeResetFnc)(T*)){ + it->setSize(0); + it->setStoredPackets(0); + (*typeResetFnc)(it->modifyIndexType()); + } - /* - * Reading - */ + /* + * Reading + */ - void setCurrentReadBlock(typename IndexedRingMemoryArray::Iterator it){ - currentReadBlock = it; - currentReadBlockSizeCached = it->getSize(); - } + void setCurrentReadBlock(typename IndexedRingMemoryArray::Iterator it){ + currentReadBlock = it; + currentReadBlockSizeCached = it->getSize(); + } - void resetRead(){ - currentReadBlock = this->begin(); - currentReadSize = 0; - currentReadBlockSizeCached = this->begin()->getSize(); - lastBlockToRead = currentWriteBlock; - lastBlockToReadSize = currentWriteBlock->getSize(); - } - /** - * Sets the last block to read to this iterator. - * Can be used to dump until block x - * @param it The iterator for the last read block - */ - void setLastBlockToRead(typename IndexedRingMemoryArray::Iterator it){ - lastBlockToRead = it; - lastBlockToReadSize = it->getSize(); - } + void resetRead(){ + currentReadBlock = this->begin(); + currentReadSize = 0; + currentReadBlockSizeCached = this->begin()->getSize(); + lastBlockToRead = currentWriteBlock; + lastBlockToReadSize = currentWriteBlock->getSize(); + } + /** + * Sets the last block to read to this iterator. + * Can be used to dump until block x + * @param it The iterator for the last read block + */ + void setLastBlockToRead(typename IndexedRingMemoryArray::Iterator it){ + lastBlockToRead = it; + lastBlockToReadSize = it->getSize(); + } - /** - * Set the read pointer to the first written Block, which is the first non empty block in front of the write block - * Can be the currentWriteBlock as well - */ - void readOldest(){ - resetRead(); - currentReadBlock = getNextNonEmptyBlock(); - currentReadBlockSizeCached = currentReadBlock->getSize(); + /** + * Set the read pointer to the first written Block, which is the first non empty block in front of the write block + * Can be the currentWriteBlock as well + */ + void readOldest(){ + resetRead(); + currentReadBlock = getNextNonEmptyBlock(); + currentReadBlockSizeCached = currentReadBlock->getSize(); - } + } - /** - * Sets the current read iterator to the next Block and resets the current read size - * The current size of the block will be cached to avoid race condition between write and read - * If the end of the ring is reached the read pointer will be set to the begin - */ - void readNext(){ - currentReadSize = 0; - if((this->size != 0) && (currentReadBlock.value ==this->back())){ - currentReadBlock = this->begin(); - }else{ - currentReadBlock++; - } + /** + * Sets the current read iterator to the next Block and resets the current read size + * The current size of the block will be cached to avoid race condition between write and read + * If the end of the ring is reached the read pointer will be set to the begin + */ + void readNext(){ + currentReadSize = 0; + if((this->size != 0) && (currentReadBlock.value ==this->back())){ + currentReadBlock = this->begin(); + }else{ + currentReadBlock++; + } - currentReadBlockSizeCached = currentReadBlock->getSize(); - } + currentReadBlockSizeCached = currentReadBlock->getSize(); + } - /** - * Returns the address which is currently read from - * @return Address to read from - */ - uint32_t getCurrentReadAddress() const { - return getAddressOfCurrentReadBlock() + currentReadSize; - } - /** - * Adds readSize to the current size and checks if the read has no more data left and advances the read block - * @param readSize The size that was read - * @return Returns true if the read can go on - */ - bool addReadSize(uint32_t readSize) { - if(currentReadBlock == lastBlockToRead){ - //The current read block is the last to read - if((currentReadSize+readSize) return true - currentReadSize += readSize; - return true; - }else{ - //Reached end of read -> return false - currentReadSize = lastBlockToReadSize; - return false; - } - }else{ - //We are not in the last Block - if((currentReadSize + readSize)::Iterator it(currentReadBlock); - //Search if any block between this and the last block is not empty - for(;it!=lastBlockToRead;++it){ - if(it == this->end()){ - //This is the end, next block is the begin - it = this->begin(); - if(it == lastBlockToRead){ - //Break if the begin is the lastBlockToRead - break; - } - } - if(it->getSize()!=0){ - //This is a non empty block. Go on reading with this block - currentReadBlock = it; - currentReadBlockSizeCached = it->getSize(); - return true; - } - } - //reached lastBlockToRead and every block was empty, check if the last block is also empty - if(lastBlockToReadSize!=0){ - //go on with last Block - currentReadBlock = lastBlockToRead; - currentReadBlockSizeCached = lastBlockToReadSize; - return true; - } - //There is no non empty block left - return false; - } - //Size is larger than 0 - return true; - } - } - } - uint32_t getRemainigSizeOfCurrentReadBlock() const{ - if(currentReadBlock == lastBlockToRead){ - return (lastBlockToReadSize - currentReadSize); - }else{ - return (currentReadBlockSizeCached - currentReadSize); - } - } + /** + * Returns the address which is currently read from + * @return Address to read from + */ + uint32_t getCurrentReadAddress() const { + return getAddressOfCurrentReadBlock() + currentReadSize; + } + /** + * Adds readSize to the current size and checks if the read has no more data left and advances the read block + * @param readSize The size that was read + * @return Returns true if the read can go on + */ + bool addReadSize(uint32_t readSize) { + if(currentReadBlock == lastBlockToRead){ + //The current read block is the last to read + if((currentReadSize+readSize) return true + currentReadSize += readSize; + return true; + }else{ + //Reached end of read -> return false + currentReadSize = lastBlockToReadSize; + return false; + } + }else{ + //We are not in the last Block + if((currentReadSize + readSize)::Iterator it(currentReadBlock); + //Search if any block between this and the last block is not empty + for(;it!=lastBlockToRead;++it){ + if(it == this->end()){ + //This is the end, next block is the begin + it = this->begin(); + if(it == lastBlockToRead){ + //Break if the begin is the lastBlockToRead + break; + } + } + if(it->getSize()!=0){ + //This is a non empty block. Go on reading with this block + currentReadBlock = it; + currentReadBlockSizeCached = it->getSize(); + return true; + } + } + //reached lastBlockToRead and every block was empty, check if the last block is also empty + if(lastBlockToReadSize!=0){ + //go on with last Block + currentReadBlock = lastBlockToRead; + currentReadBlockSizeCached = lastBlockToReadSize; + return true; + } + //There is no non empty block left + return false; + } + //Size is larger than 0 + return true; + } + } + } + uint32_t getRemainigSizeOfCurrentReadBlock() const{ + if(currentReadBlock == lastBlockToRead){ + return (lastBlockToReadSize - currentReadSize); + }else{ + return (currentReadBlockSizeCached - currentReadSize); + } + } - uint32_t getAddressOfCurrentReadBlock() const { - return currentReadBlock->getBlockStartAddress(); - } + uint32_t getAddressOfCurrentReadBlock() const { + return currentReadBlock->getBlockStartAddress(); + } - /** - * Gets the next non empty Block after the current write block, - * @return Returns the iterator to the block. If there is non, the current write block is returned - */ - typename IndexedRingMemoryArray::Iterator getNextNonEmptyBlock() const { - for(typename IndexedRingMemoryArray::Iterator it = getNextWrite();it!=currentWriteBlock;++it){ - if(it == this->end()){ - it = this->begin(); - if(it == currentWriteBlock){ - break; - } - } - if(it->getSize()!=0){ - return it; - } - } - return currentWriteBlock; - } + /** + * Gets the next non empty Block after the current write block, + * @return Returns the iterator to the block. If there is non, the current write block is returned + */ + typename IndexedRingMemoryArray::Iterator getNextNonEmptyBlock() const { + for(typename IndexedRingMemoryArray::Iterator it = getNextWrite();it!=currentWriteBlock;++it){ + if(it == this->end()){ + it = this->begin(); + if(it == currentWriteBlock){ + break; + } + } + if(it->getSize()!=0){ + return it; + } + } + return currentWriteBlock; + } - /** - * Returns a copy of the oldest Index type - * @return Type of Index - */ - T* getOldest(){ - return (getNextNonEmptyBlock()->modifyIndexType()); - } + /** + * Returns a copy of the oldest Index type + * @return Type of Index + */ + T* getOldest(){ + return (getNextNonEmptyBlock()->modifyIndexType()); + } - /* - * Writing - */ - uint32_t getAddressOfCurrentWriteBlock() const{ - return currentWriteBlock->getBlockStartAddress(); - } + /* + * Writing + */ + uint32_t getAddressOfCurrentWriteBlock() const{ + return currentWriteBlock->getBlockStartAddress(); + } - uint32_t getSizeOfCurrentWriteBlock() const{ - return currentWriteBlock->getSize(); - } + uint32_t getSizeOfCurrentWriteBlock() const{ + return currentWriteBlock->getSize(); + } - uint32_t getCurrentWriteAddress() const{ - return getAddressOfCurrentWriteBlock() + getSizeOfCurrentWriteBlock(); - } + uint32_t getCurrentWriteAddress() const{ + return getAddressOfCurrentWriteBlock() + getSizeOfCurrentWriteBlock(); + } - void clearCurrentWriteBlock(){ - currentWriteBlock->setSize(0); - currentWriteBlock->setStoredPackets(0); - } + void clearCurrentWriteBlock(){ + currentWriteBlock->setSize(0); + currentWriteBlock->setStoredPackets(0); + } - void addCurrentWriteBlock(uint32_t size, uint32_t storedPackets){ - currentWriteBlock->addSize(size); - currentWriteBlock->addStoredPackets(storedPackets); - } + void addCurrentWriteBlock(uint32_t size, uint32_t storedPackets){ + currentWriteBlock->addSize(size); + currentWriteBlock->addStoredPackets(storedPackets); + } - T* modifyCurrentWriteBlockIndexType(){ - return currentWriteBlock->modifyIndexType(); - } - void updatePreviousWriteSize(uint32_t size, uint32_t storedPackets){ - typename IndexedRingMemoryArray::Iterator it = getPreviousBlock(currentWriteBlock); - it->addSize(size); - it->addStoredPackets(storedPackets); - } + T* modifyCurrentWriteBlockIndexType(){ + return currentWriteBlock->modifyIndexType(); + } + void updatePreviousWriteSize(uint32_t size, uint32_t storedPackets){ + typename IndexedRingMemoryArray::Iterator it = getPreviousBlock(currentWriteBlock); + it->addSize(size); + it->addStoredPackets(storedPackets); + } - /** - * Checks if the block has enough space for sizeToWrite - * @param sizeToWrite The data to be written in the Block - * @return Returns true if size to write is smaller the remaining size of the block - */ - bool hasCurrentWriteBlockEnoughSpace(uint32_t sizeToWrite){ - typename IndexedRingMemoryArray::Iterator next = getNextWrite(); - uint32_t addressOfNextBlock = next->getBlockStartAddress(); - uint32_t availableSize = ((addressOfNextBlock+totalSize) - (getAddressOfCurrentWriteBlock()+getSizeOfCurrentWriteBlock()))%totalSize; - return (sizeToWrite < availableSize); - } + /** + * Checks if the block has enough space for sizeToWrite + * @param sizeToWrite The data to be written in the Block + * @return Returns true if size to write is smaller the remaining size of the block + */ + bool hasCurrentWriteBlockEnoughSpace(uint32_t sizeToWrite){ + typename IndexedRingMemoryArray::Iterator next = getNextWrite(); + uint32_t addressOfNextBlock = next->getBlockStartAddress(); + uint32_t availableSize = ((addressOfNextBlock+totalSize) - (getAddressOfCurrentWriteBlock()+getSizeOfCurrentWriteBlock()))%totalSize; + return (sizeToWrite < availableSize); + } - /** - * Checks if the store is full if overwrite old is false - * @return Returns true if it is writeable and false if not - */ - bool isNextBlockWritable(){ - //First check if this is the end of the list - typename IndexedRingMemoryArray::Iterator next; - next = getNextWrite(); - if((next->getSize()!=0) && (!overwriteOld)){ - return false; - } - return true; - } + /** + * Checks if the store is full if overwrite old is false + * @return Returns true if it is writeable and false if not + */ + bool isNextBlockWritable(){ + //First check if this is the end of the list + typename IndexedRingMemoryArray::Iterator next; + next = getNextWrite(); + if((next->getSize()!=0) && (!overwriteOld)){ + return false; + } + return true; + } - /** - * Updates current write Block Index Type - * @param infoOfNewBlock - */ - void updateCurrentBlock(T* infoOfNewBlock){ - currentWriteBlock->setIndexType(infoOfNewBlock); - } + /** + * Updates current write Block Index Type + * @param infoOfNewBlock + */ + void updateCurrentBlock(T* infoOfNewBlock){ + currentWriteBlock->setIndexType(infoOfNewBlock); + } - /** - * Succeed to next block, returns FAILED if overwrite is false and the store is full - * @return - */ - ReturnValue_t writeNext(){ - //Check Next Block - if(!isNextBlockWritable()){ - //The Index is full and does not overwrite old - return HasReturnvaluesIF::RETURN_FAILED; - } - //Next block can be written, update Metadata - currentWriteBlock = getNextWrite(); - currentWriteBlock->setSize(0); - currentWriteBlock->setStoredPackets(0); - return HasReturnvaluesIF::RETURN_OK; - } + /** + * Succeed to next block, returns FAILED if overwrite is false and the store is full + * @return + */ + ReturnValue_t writeNext(){ + //Check Next Block + if(!isNextBlockWritable()){ + //The Index is full and does not overwrite old + return HasReturnvaluesIF::RETURN_FAILED; + } + //Next block can be written, update Metadata + currentWriteBlock = getNextWrite(); + currentWriteBlock->setSize(0); + currentWriteBlock->setStoredPackets(0); + return HasReturnvaluesIF::RETURN_OK; + } - /** - * Serializes the Index and calculates the CRC. - * Parameters according to HasSerializeIF - * @param buffer - * @param size - * @param maxSize - * @param streamEndianness - * @return - */ - ReturnValue_t serialize(uint8_t** buffer, size_t* size, - size_t maxSize, Endianness streamEndianness) const{ - uint8_t* crcBuffer = *buffer; - uint32_t oldSize = *size; - if(additionalInfo!=NULL){ - additionalInfo->serialize(buffer,size,maxSize,streamEndianness); - } - ReturnValue_t result = currentWriteBlock->serialize(buffer,size,maxSize,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - result = SerializeAdapter::serialize(&this->size,buffer,size,maxSize,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } + /** + * Serializes the Index and calculates the CRC. + * Parameters according to HasSerializeIF + * @param buffer + * @param size + * @param maxSize + * @param streamEndianness + * @return + */ + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + size_t maxSize, Endianness streamEndianness) const{ + uint8_t* crcBuffer = *buffer; + uint32_t oldSize = *size; + if(additionalInfo!=NULL){ + additionalInfo->serialize(buffer,size,maxSize,streamEndianness); + } + ReturnValue_t result = currentWriteBlock->serialize(buffer,size,maxSize,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + result = SerializeAdapter::serialize(&this->size,buffer,size,maxSize,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } - uint32_t i = 0; - while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->size)) { - result = SerializeAdapter::serialize(&this->entries[i], buffer, size, - maxSize, streamEndianness); - ++i; - } - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - uint16_t crc = Calculate_CRC(crcBuffer,(*size-oldSize)); - result = SerializeAdapter::serialize(&crc,buffer,size,maxSize,streamEndianness); - return result; - } + uint32_t i = 0; + while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->size)) { + result = SerializeAdapter::serialize(&this->entries[i], buffer, size, + maxSize, streamEndianness); + ++i; + } + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + uint16_t crc = Calculate_CRC(crcBuffer,(*size-oldSize)); + result = SerializeAdapter::serialize(&crc,buffer,size,maxSize,streamEndianness); + return result; + } - /** - * Get the serialized Size of the index - * @return The serialized size of the index - */ - size_t getSerializedSize() const { + /** + * Get the serialized Size of the index + * @return The serialized size of the index + */ + size_t getSerializedSize() const { - uint32_t size = 0; - if(additionalInfo!=NULL){ - size += additionalInfo->getSerializedSize(); - } - size += currentWriteBlock->getSerializedSize(); - size += SerializeAdapter::getSerializedSize(&this->size); - size += (this->entries[0].getSerializedSize()) * this->size; - uint16_t crc = 0; - size += SerializeAdapter::getSerializedSize(&crc); - return size; - } - /** - * DeSerialize the Indexed Ring from a buffer, deSerializes the current write iterator - * CRC Has to be checked before! - * @param buffer - * @param size - * @param streamEndianness - * @return - */ + uint32_t size = 0; + if(additionalInfo!=NULL){ + size += additionalInfo->getSerializedSize(); + } + size += currentWriteBlock->getSerializedSize(); + size += SerializeAdapter::getSerializedSize(&this->size); + size += (this->entries[0].getSerializedSize()) * this->size; + uint16_t crc = 0; + size += SerializeAdapter::getSerializedSize(&crc); + return size; + } + /** + * DeSerialize the Indexed Ring from a buffer, deSerializes the current write iterator + * CRC Has to be checked before! + * @param buffer + * @param size + * @param streamEndianness + * @return + */ - ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, - Endianness streamEndianness){ + ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, + Endianness streamEndianness){ - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - if(additionalInfo!=NULL){ - result = additionalInfo->deSerialize(buffer,size,streamEndianness); - } - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + if(additionalInfo!=NULL){ + result = additionalInfo->deSerialize(buffer,size,streamEndianness); + } + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } - Index tempIndex; - result = tempIndex.deSerialize(buffer,size,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - uint32_t tempSize = 0; - result = SerializeAdapter::deSerialize(&tempSize,buffer,size,streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - if(this->size != tempSize){ - return HasReturnvaluesIF::RETURN_FAILED; - } - uint32_t i = 0; - while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->size)) { - result = SerializeAdapter::deSerialize( - &this->entries[i], buffer, size, - streamEndianness); - ++i; - } - if(result != HasReturnvaluesIF::RETURN_OK){ - return result; - } - typename IndexedRingMemoryArray::Iterator cmp(&tempIndex); - for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ - if(*(cmp.value) == *(it.value)){ - currentWriteBlock = it; - return HasReturnvaluesIF::RETURN_OK; - } - } - //Reached if current write block iterator is not found - return HasReturnvaluesIF::RETURN_FAILED; - } + Index tempIndex; + result = tempIndex.deSerialize(buffer,size,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + uint32_t tempSize = 0; + result = SerializeAdapter::deSerialize(&tempSize,buffer,size,streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + if(this->size != tempSize){ + return HasReturnvaluesIF::RETURN_FAILED; + } + uint32_t i = 0; + while ((result == HasReturnvaluesIF::RETURN_OK) && (i < this->size)) { + result = SerializeAdapter::deSerialize( + &this->entries[i], buffer, size, + streamEndianness); + ++i; + } + if(result != HasReturnvaluesIF::RETURN_OK){ + return result; + } + typename IndexedRingMemoryArray::Iterator cmp(&tempIndex); + for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ + if(*(cmp.value) == *(it.value)){ + currentWriteBlock = it; + return HasReturnvaluesIF::RETURN_OK; + } + } + //Reached if current write block iterator is not found + return HasReturnvaluesIF::RETURN_FAILED; + } - uint32_t getIndexAddress() const { - return indexAddress; - } + uint32_t getIndexAddress() const { + return indexAddress; + } - /* - * Statistics - */ - uint32_t getStoredPackets() const { - uint32_t size = 0; - for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ - size += it->getStoredPackets(); - } - return size; - } + /* + * Statistics + */ + uint32_t getStoredPackets() const { + uint32_t size = 0; + for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ + size += it->getStoredPackets(); + } + return size; + } - uint32_t getTotalSize() const { - return totalSize; - } + uint32_t getTotalSize() const { + return totalSize; + } - uint32_t getCurrentSize() const{ - uint32_t size = 0; - for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ - size += it->getSize(); - } - return size; - } + uint32_t getCurrentSize() const{ + uint32_t size = 0; + for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ + size += it->getSize(); + } + return size; + } - bool isEmpty() const{ - return getCurrentSize()==0; - } + bool isEmpty() const{ + return getCurrentSize()==0; + } - double getPercentageFilled() const{ - uint32_t filledSize = 0; - for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ - filledSize += it->getSize(); - } + double getPercentageFilled() const{ + uint32_t filledSize = 0; + for(typename IndexedRingMemoryArray::Iterator it= this->begin();it!=this->end();++it){ + filledSize += it->getSize(); + } - return (double)filledSize/(double)this->totalSize; - } + return (double)filledSize/(double)this->totalSize; + } - typename IndexedRingMemoryArray::Iterator getCurrentWriteBlock() const{ - return currentWriteBlock; - } - /** - * Get the next block of the currentWriteBlock. - * Returns the first one if currentWriteBlock is the last one - * @return Iterator pointing to the next block after currentWriteBlock - */ - typename IndexedRingMemoryArray::Iterator getNextWrite() const{ - typename IndexedRingMemoryArray::Iterator next(currentWriteBlock); - if((this->size != 0) && (currentWriteBlock.value == this->back())){ - next = this->begin(); - }else{ - ++next; - } - return next; - } - /** - * Get the block in front of the Iterator - * Returns the last block if it is the first block - * @param it iterator which you want the previous block from - * @return pointing to the block before it - */ - typename IndexedRingMemoryArray::Iterator getPreviousBlock(typename IndexedRingMemoryArray::Iterator it) { - if(this->begin() == it){ - typename IndexedRingMemoryArray::Iterator next((this->back())); - return next; - } - typename IndexedRingMemoryArray::Iterator next(it); - --next; - return next; - } + typename IndexedRingMemoryArray::Iterator getCurrentWriteBlock() const{ + return currentWriteBlock; + } + /** + * Get the next block of the currentWriteBlock. + * Returns the first one if currentWriteBlock is the last one + * @return Iterator pointing to the next block after currentWriteBlock + */ + typename IndexedRingMemoryArray::Iterator getNextWrite() const{ + typename IndexedRingMemoryArray::Iterator next(currentWriteBlock); + if((this->size != 0) && (currentWriteBlock.value == this->back())){ + next = this->begin(); + }else{ + ++next; + } + return next; + } + /** + * Get the block in front of the Iterator + * Returns the last block if it is the first block + * @param it iterator which you want the previous block from + * @return pointing to the block before it + */ + typename IndexedRingMemoryArray::Iterator getPreviousBlock(typename IndexedRingMemoryArray::Iterator it) { + if(this->begin() == it){ + typename IndexedRingMemoryArray::Iterator next((this->back())); + return next; + } + typename IndexedRingMemoryArray::Iterator next(it); + --next; + return next; + } private: - //The total size used by the blocks (without index) - uint32_t totalSize; + //The total size used by the blocks (without index) + uint32_t totalSize; - //The address of the index - const uint32_t indexAddress; + //The address of the index + const uint32_t indexAddress; - //The iterators for writing and reading - typename IndexedRingMemoryArray::Iterator currentWriteBlock; - typename IndexedRingMemoryArray::Iterator currentReadBlock; + //The iterators for writing and reading + typename IndexedRingMemoryArray::Iterator currentWriteBlock; + typename IndexedRingMemoryArray::Iterator currentReadBlock; - //How much of the current read block is read already - uint32_t currentReadSize; + //How much of the current read block is read already + uint32_t currentReadSize; - //Cached Size of current read block - uint32_t currentReadBlockSizeCached; + //Cached Size of current read block + uint32_t currentReadBlockSizeCached; - //Last block of current write (should be write block) - typename IndexedRingMemoryArray::Iterator lastBlockToRead; - //current size of last Block to read - uint32_t lastBlockToReadSize; + //Last block of current write (should be write block) + typename IndexedRingMemoryArray::Iterator lastBlockToRead; + //current size of last Block to read + uint32_t lastBlockToReadSize; - //Additional Info to be serialized with the index - SerializeIF* additionalInfo; + //Additional Info to be serialized with the index + SerializeIF* additionalInfo; - //Does it overwrite old blocks? - const bool overwriteOld; + //Does it overwrite old blocks? + const bool overwriteOld; }; diff --git a/container/PlacementFactory.h b/container/PlacementFactory.h index a0aebb7d1..94b4aeefd 100644 --- a/container/PlacementFactory.h +++ b/container/PlacementFactory.h @@ -22,50 +22,50 @@ */ class PlacementFactory { public: - PlacementFactory(StorageManagerIF* backend) : - dataBackend(backend) { - } + PlacementFactory(StorageManagerIF* backend) : + dataBackend(backend) { + } - /*** - * Generates an object of type T in the backend storage. - * - * @warning Do not use with any Type that allocates memory internally! - * - * @tparam T Type of Object - * @param args Constructor Arguments to be passed - * @return A pointer to the new object or a nullptr in case of failure - */ - template - T* generate(Args&&... args) { - store_address_t tempId; - uint8_t* pData = nullptr; - ReturnValue_t result = dataBackend->getFreeElement(&tempId, sizeof(T), - &pData); - if (result != HasReturnvaluesIF::RETURN_OK) { - return nullptr; - } - T* temp = new (pData) T(std::forward(args)...); - return temp; - } - /*** - * Function to destroy the object allocated with generate and free space in backend. - * This must be called by the user. - * - * @param thisElement Element to be destroyed - * @return RETURN_OK if the element was destroyed, different errors on failure - */ - template - ReturnValue_t destroy(T* thisElement) { - if (thisElement == nullptr){ - return HasReturnvaluesIF::RETURN_FAILED; - } - //Need to call destructor first, in case something was allocated by the object (shouldn't do that, however). - thisElement->~T(); - uint8_t* pointer = (uint8_t*) (thisElement); - return dataBackend->deleteData(pointer, sizeof(T)); - } + /*** + * Generates an object of type T in the backend storage. + * + * @warning Do not use with any Type that allocates memory internally! + * + * @tparam T Type of Object + * @param args Constructor Arguments to be passed + * @return A pointer to the new object or a nullptr in case of failure + */ + template + T* generate(Args&&... args) { + store_address_t tempId; + uint8_t* pData = nullptr; + ReturnValue_t result = dataBackend->getFreeElement(&tempId, sizeof(T), + &pData); + if (result != HasReturnvaluesIF::RETURN_OK) { + return nullptr; + } + T* temp = new (pData) T(std::forward(args)...); + return temp; + } + /*** + * Function to destroy the object allocated with generate and free space in backend. + * This must be called by the user. + * + * @param thisElement Element to be destroyed + * @return RETURN_OK if the element was destroyed, different errors on failure + */ + template + ReturnValue_t destroy(T* thisElement) { + if (thisElement == nullptr){ + return HasReturnvaluesIF::RETURN_FAILED; + } + //Need to call destructor first, in case something was allocated by the object (shouldn't do that, however). + thisElement->~T(); + uint8_t* pointer = (uint8_t*) (thisElement); + return dataBackend->deleteData(pointer, sizeof(T)); + } private: - StorageManagerIF* dataBackend; + StorageManagerIF* dataBackend; }; #endif /* FRAMEWORK_CONTAINER_PLACEMENTFACTORY_H_ */ diff --git a/container/RingBufferBase.h b/container/RingBufferBase.h index 886b9fab9..9277c50bf 100644 --- a/container/RingBufferBase.h +++ b/container/RingBufferBase.h @@ -7,107 +7,107 @@ template class RingBufferBase { public: - RingBufferBase(size_t startAddress, const size_t size, bool overwriteOld) : - start(startAddress), write(startAddress), size(size), - overwriteOld(overwriteOld) { - for (uint8_t count = 0; count < N_READ_PTRS; count++) { - read[count] = startAddress; - } - } + RingBufferBase(size_t startAddress, const size_t size, bool overwriteOld) : + start(startAddress), write(startAddress), size(size), + overwriteOld(overwriteOld) { + for (uint8_t count = 0; count < N_READ_PTRS; count++) { + read[count] = startAddress; + } + } - virtual ~RingBufferBase() {} + virtual ~RingBufferBase() {} - bool isFull(uint8_t n = 0) { - return (availableWriteSpace(n) == 0); - } - bool isEmpty(uint8_t n = 0) { - return (getAvailableReadData(n) == 0); - } + bool isFull(uint8_t n = 0) { + return (availableWriteSpace(n) == 0); + } + bool isEmpty(uint8_t n = 0) { + return (getAvailableReadData(n) == 0); + } - size_t getAvailableReadData(uint8_t n = 0) const { - return ((write + size) - read[n]) % size; - } - size_t availableWriteSpace(uint8_t n = 0) const { - //One less to avoid ambiguous full/empty problem. - return (((read[n] + size) - write - 1) % size); - } + size_t getAvailableReadData(uint8_t n = 0) const { + return ((write + size) - read[n]) % size; + } + size_t availableWriteSpace(uint8_t n = 0) const { + //One less to avoid ambiguous full/empty problem. + return (((read[n] + size) - write - 1) % size); + } - bool overwritesOld() const { - return overwriteOld; - } + bool overwritesOld() const { + return overwriteOld; + } - size_t getMaxSize() const { - return size - 1; - } + size_t getMaxSize() const { + return size - 1; + } - void clear() { - write = start; - for (uint8_t count = 0; count < N_READ_PTRS; count++) { - read[count] = start; - } - } + void clear() { + write = start; + for (uint8_t count = 0; count < N_READ_PTRS; count++) { + read[count] = start; + } + } - size_t writeTillWrap() { - return (start + size) - write; - } + size_t writeTillWrap() { + return (start + size) - write; + } - size_t readTillWrap(uint8_t n = 0) { - return (start + size) - read[n]; - } + size_t readTillWrap(uint8_t n = 0) { + return (start + size) - read[n]; + } - size_t getStart() const { - return start; - } + size_t getStart() const { + return start; + } protected: - const size_t start; - size_t write; - size_t read[N_READ_PTRS]; - const size_t size; - const bool overwriteOld; + const size_t start; + size_t write; + size_t read[N_READ_PTRS]; + const size_t size; + const bool overwriteOld; - void incrementWrite(uint32_t amount) { - write = ((write + amount - start) % size) + start; - } - void incrementRead(uint32_t amount, uint8_t n = 0) { - read[n] = ((read[n] + amount - start) % size) + start; - } + void incrementWrite(uint32_t amount) { + write = ((write + amount - start) % size) + start; + } + void incrementRead(uint32_t amount, uint8_t n = 0) { + read[n] = ((read[n] + amount - start) % size) + start; + } - ReturnValue_t readData(uint32_t amount, uint8_t n = 0) { - if (getAvailableReadData(n) >= amount) { - incrementRead(amount, n); - return HasReturnvaluesIF::RETURN_OK; - } else { - return HasReturnvaluesIF::RETURN_FAILED; - } - } + ReturnValue_t readData(uint32_t amount, uint8_t n = 0) { + if (getAvailableReadData(n) >= amount) { + incrementRead(amount, n); + return HasReturnvaluesIF::RETURN_OK; + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } + } - ReturnValue_t writeData(uint32_t amount) { - if (availableWriteSpace() >= amount or overwriteOld) { - incrementWrite(amount); - return HasReturnvaluesIF::RETURN_OK; - } else { - return HasReturnvaluesIF::RETURN_FAILED; - } - } + ReturnValue_t writeData(uint32_t amount) { + if (availableWriteSpace() >= amount or overwriteOld) { + incrementWrite(amount); + return HasReturnvaluesIF::RETURN_OK; + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } + } - size_t getRead(uint8_t n = 0) const { - return read[n]; - } + size_t getRead(uint8_t n = 0) const { + return read[n]; + } - void setRead(uint32_t read, uint8_t n = 0) { - if (read >= start && read < (start+size)) { - this->read[n] = read; - } - } + void setRead(uint32_t read, uint8_t n = 0) { + if (read >= start && read < (start+size)) { + this->read[n] = read; + } + } - uint32_t getWrite() const { - return write; - } + uint32_t getWrite() const { + return write; + } - void setWrite(uint32_t write) { - this->write = write; - } + void setWrite(uint32_t write) { + this->write = write; + } }; #endif /* FSFW_CONTAINER_RINGBUFFERBASE_H_ */ diff --git a/container/SharedRingBuffer.cpp b/container/SharedRingBuffer.cpp index 769ce0000..1681325d0 100644 --- a/container/SharedRingBuffer.cpp +++ b/container/SharedRingBuffer.cpp @@ -3,23 +3,23 @@ #include "../ipc/MutexHelper.h" SharedRingBuffer::SharedRingBuffer(object_id_t objectId, const size_t size, - bool overwriteOld, size_t maxExcessBytes): - SystemObject(objectId), SimpleRingBuffer(size, overwriteOld, - maxExcessBytes) { - mutex = MutexFactory::instance()->createMutex(); + bool overwriteOld, size_t maxExcessBytes): + SystemObject(objectId), SimpleRingBuffer(size, overwriteOld, + maxExcessBytes) { + mutex = MutexFactory::instance()->createMutex(); } SharedRingBuffer::SharedRingBuffer(object_id_t objectId, uint8_t *buffer, - const size_t size, bool overwriteOld, size_t maxExcessBytes): - SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld, - maxExcessBytes) { - mutex = MutexFactory::instance()->createMutex(); + const size_t size, bool overwriteOld, size_t maxExcessBytes): + SystemObject(objectId), SimpleRingBuffer(buffer, size, overwriteOld, + maxExcessBytes) { + mutex = MutexFactory::instance()->createMutex(); } void SharedRingBuffer::setToUseReceiveSizeFIFO(size_t fifoDepth) { - this->fifoDepth = fifoDepth; + this->fifoDepth = fifoDepth; } ReturnValue_t SharedRingBuffer::lockRingBufferMutex( @@ -38,20 +38,20 @@ MutexIF* SharedRingBuffer::getMutexHandle() const { } ReturnValue_t SharedRingBuffer::initialize() { - if(fifoDepth > 0) { - receiveSizesFIFO = new DynamicFIFO(fifoDepth); - } - return SystemObject::initialize(); + if(fifoDepth > 0) { + receiveSizesFIFO = new DynamicFIFO(fifoDepth); + } + return SystemObject::initialize(); } DynamicFIFO* SharedRingBuffer::getReceiveSizesFIFO() { - if(receiveSizesFIFO == nullptr) { - // Configuration error. + if(receiveSizesFIFO == nullptr) { + // Configuration error. #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer" - << " was not configured to have sizes FIFO, returning nullptr!" - << std::endl; + sif::warning << "SharedRingBuffer::getReceiveSizesFIFO: Ring buffer" + << " was not configured to have sizes FIFO, returning nullptr!" + << std::endl; #endif - } - return receiveSizesFIFO; + } + return receiveSizesFIFO; } diff --git a/container/SharedRingBuffer.h b/container/SharedRingBuffer.h index 64d7ee291..43ab6e8fe 100644 --- a/container/SharedRingBuffer.h +++ b/container/SharedRingBuffer.h @@ -15,76 +15,76 @@ * and unlock operations. */ class SharedRingBuffer: public SystemObject, - public SimpleRingBuffer { + public SimpleRingBuffer { public: - /** - * This constructor allocates a new internal buffer with the supplied size. - * @param size - * @param overwriteOld - * If the ring buffer is overflowing at a write operartion, the oldest data - * will be overwritten. - */ - SharedRingBuffer(object_id_t objectId, const size_t size, - bool overwriteOld, size_t maxExcessBytes); + /** + * This constructor allocates a new internal buffer with the supplied size. + * @param size + * @param overwriteOld + * If the ring buffer is overflowing at a write operartion, the oldest data + * will be overwritten. + */ + SharedRingBuffer(object_id_t objectId, const size_t size, + bool overwriteOld, size_t maxExcessBytes); - /** - * @brief This function can be used to add an optional FIFO to the class - * @details - * This FIFO will be allocated in the initialize function (and will - * have a fixed maximum size after that). It can be used to store - * values like packet sizes, for example for a shared ring buffer - * used by producer/consumer tasks. - */ - void setToUseReceiveSizeFIFO(size_t fifoDepth); + /** + * @brief This function can be used to add an optional FIFO to the class + * @details + * This FIFO will be allocated in the initialize function (and will + * have a fixed maximum size after that). It can be used to store + * values like packet sizes, for example for a shared ring buffer + * used by producer/consumer tasks. + */ + void setToUseReceiveSizeFIFO(size_t fifoDepth); - /** - * This constructor takes an external buffer with the specified size. - * @param buffer - * @param size - * @param overwriteOld - * If the ring buffer is overflowing at a write operartion, the oldest data - * will be overwritten. - */ - SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const size_t size, - bool overwriteOld, size_t maxExcessBytes); + /** + * This constructor takes an external buffer with the specified size. + * @param buffer + * @param size + * @param overwriteOld + * If the ring buffer is overflowing at a write operartion, the oldest data + * will be overwritten. + */ + SharedRingBuffer(object_id_t objectId, uint8_t* buffer, const size_t size, + bool overwriteOld, size_t maxExcessBytes); - /** - * Unless a read-only constant value is read, all operations on the - * shared ring buffer should be protected by calling this function. - * @param timeoutType - * @param timeout - * @return - */ - virtual ReturnValue_t lockRingBufferMutex(MutexIF::TimeoutType timeoutType, - dur_millis_t timeout); - /** - * Any locked mutex also has to be unlocked, otherwise, access to the - * shared ring buffer will be blocked. - * @return - */ - virtual ReturnValue_t unlockRingBufferMutex(); + /** + * Unless a read-only constant value is read, all operations on the + * shared ring buffer should be protected by calling this function. + * @param timeoutType + * @param timeout + * @return + */ + virtual ReturnValue_t lockRingBufferMutex(MutexIF::TimeoutType timeoutType, + dur_millis_t timeout); + /** + * Any locked mutex also has to be unlocked, otherwise, access to the + * shared ring buffer will be blocked. + * @return + */ + virtual ReturnValue_t unlockRingBufferMutex(); - /** - * The mutex handle can be accessed directly, for example to perform - * the lock with the #MutexHelper for a RAII compliant lock operation. - * @return - */ - MutexIF* getMutexHandle() const; + /** + * The mutex handle can be accessed directly, for example to perform + * the lock with the #MutexHelper for a RAII compliant lock operation. + * @return + */ + MutexIF* getMutexHandle() const; - ReturnValue_t initialize() override; + ReturnValue_t initialize() override; - /** - * If the shared ring buffer was configured to have a sizes FIFO, a handle - * to that FIFO can be retrieved with this function. - * Do not forget to protect access with a lock if required! - * @return - */ - DynamicFIFO* getReceiveSizesFIFO(); + /** + * If the shared ring buffer was configured to have a sizes FIFO, a handle + * to that FIFO can be retrieved with this function. + * Do not forget to protect access with a lock if required! + * @return + */ + DynamicFIFO* getReceiveSizesFIFO(); private: - MutexIF* mutex = nullptr; + MutexIF* mutex = nullptr; - size_t fifoDepth = 0; - DynamicFIFO* receiveSizesFIFO = nullptr; + size_t fifoDepth = 0; + DynamicFIFO* receiveSizesFIFO = nullptr; }; diff --git a/container/SimpleRingBuffer.cpp b/container/SimpleRingBuffer.cpp index 88c9290ef..8544acbf3 100644 --- a/container/SimpleRingBuffer.cpp +++ b/container/SimpleRingBuffer.cpp @@ -2,31 +2,31 @@ #include SimpleRingBuffer::SimpleRingBuffer(const size_t size, bool overwriteOld, - size_t maxExcessBytes) : - RingBufferBase<>(0, size, overwriteOld), - maxExcessBytes(maxExcessBytes) { - if(maxExcessBytes > size) { - this->maxExcessBytes = size; - } - else { - this->maxExcessBytes = maxExcessBytes; - } - buffer = new uint8_t[size + maxExcessBytes]; + size_t maxExcessBytes) : + RingBufferBase<>(0, size, overwriteOld), + maxExcessBytes(maxExcessBytes) { + if(maxExcessBytes > size) { + this->maxExcessBytes = size; + } + else { + this->maxExcessBytes = maxExcessBytes; + } + buffer = new uint8_t[size + maxExcessBytes]; } SimpleRingBuffer::SimpleRingBuffer(uint8_t *buffer, const size_t size, - bool overwriteOld, size_t maxExcessBytes): + bool overwriteOld, size_t maxExcessBytes): RingBufferBase<>(0, size, overwriteOld), buffer(buffer) { - if(maxExcessBytes > size) { - this->maxExcessBytes = size; - } - else { - this->maxExcessBytes = maxExcessBytes; - } + if(maxExcessBytes > size) { + this->maxExcessBytes = size; + } + else { + this->maxExcessBytes = maxExcessBytes; + } } SimpleRingBuffer::~SimpleRingBuffer() { - delete[] buffer; + delete[] buffer; } ReturnValue_t SimpleRingBuffer::getFreeElement(uint8_t **writePointer, @@ -48,58 +48,58 @@ ReturnValue_t SimpleRingBuffer::getFreeElement(uint8_t **writePointer, } void SimpleRingBuffer::confirmBytesWritten(size_t amount) { - if(getExcessBytes() > 0) { - moveExcessBytesToStart(); - } - incrementWrite(amount); + if(getExcessBytes() > 0) { + moveExcessBytesToStart(); + } + incrementWrite(amount); } ReturnValue_t SimpleRingBuffer::writeData(const uint8_t* data, - size_t amount) { - if (availableWriteSpace() >= amount or overwriteOld) { - size_t amountTillWrap = writeTillWrap(); - if (amountTillWrap >= amount) { - // remaining size in buffer is sufficient to fit full amount. - memcpy(&buffer[write], data, amount); - } - else { - memcpy(&buffer[write], data, amountTillWrap); - memcpy(buffer, data + amountTillWrap, amount - amountTillWrap); - } - incrementWrite(amount); - return HasReturnvaluesIF::RETURN_OK; - } else { - return HasReturnvaluesIF::RETURN_FAILED; - } + size_t amount) { + if (availableWriteSpace() >= amount or overwriteOld) { + size_t amountTillWrap = writeTillWrap(); + if (amountTillWrap >= amount) { + // remaining size in buffer is sufficient to fit full amount. + memcpy(&buffer[write], data, amount); + } + else { + memcpy(&buffer[write], data, amountTillWrap); + memcpy(buffer, data + amountTillWrap, amount - amountTillWrap); + } + incrementWrite(amount); + return HasReturnvaluesIF::RETURN_OK; + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } } ReturnValue_t SimpleRingBuffer::readData(uint8_t* data, size_t amount, - bool incrementReadPtr, bool readRemaining, size_t* trueAmount) { - size_t availableData = getAvailableReadData(READ_PTR); - size_t amountTillWrap = readTillWrap(READ_PTR); - if (availableData < amount) { - if (readRemaining) { - // more data available than amount specified. - amount = availableData; - } else { - return HasReturnvaluesIF::RETURN_FAILED; - } - } - if (trueAmount != nullptr) { - *trueAmount = amount; - } - if (amountTillWrap >= amount) { - memcpy(data, &buffer[read[READ_PTR]], amount); - } else { - memcpy(data, &buffer[read[READ_PTR]], amountTillWrap); - memcpy(data + amountTillWrap, buffer, amount - amountTillWrap); - } + bool incrementReadPtr, bool readRemaining, size_t* trueAmount) { + size_t availableData = getAvailableReadData(READ_PTR); + size_t amountTillWrap = readTillWrap(READ_PTR); + if (availableData < amount) { + if (readRemaining) { + // more data available than amount specified. + amount = availableData; + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + if (trueAmount != nullptr) { + *trueAmount = amount; + } + if (amountTillWrap >= amount) { + memcpy(data, &buffer[read[READ_PTR]], amount); + } else { + memcpy(data, &buffer[read[READ_PTR]], amountTillWrap); + memcpy(data + amountTillWrap, buffer, amount - amountTillWrap); + } - if(incrementReadPtr) { - deleteData(amount, readRemaining); - } - return HasReturnvaluesIF::RETURN_OK; + if(incrementReadPtr) { + deleteData(amount, readRemaining); + } + return HasReturnvaluesIF::RETURN_OK; } size_t SimpleRingBuffer::getExcessBytes() const { @@ -114,18 +114,18 @@ void SimpleRingBuffer::moveExcessBytesToStart() { } ReturnValue_t SimpleRingBuffer::deleteData(size_t amount, - bool deleteRemaining, size_t* trueAmount) { - size_t availableData = getAvailableReadData(READ_PTR); - if (availableData < amount) { - if (deleteRemaining) { - amount = availableData; - } else { - return HasReturnvaluesIF::RETURN_FAILED; - } - } - if (trueAmount != nullptr) { - *trueAmount = amount; - } - incrementRead(amount, READ_PTR); - return HasReturnvaluesIF::RETURN_OK; + bool deleteRemaining, size_t* trueAmount) { + size_t availableData = getAvailableReadData(READ_PTR); + if (availableData < amount) { + if (deleteRemaining) { + amount = availableData; + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + if (trueAmount != nullptr) { + *trueAmount = amount; + } + incrementRead(amount, READ_PTR); + return HasReturnvaluesIF::RETURN_OK; } diff --git a/container/SimpleRingBuffer.h b/container/SimpleRingBuffer.h index 37ad5679f..6f31c5fba 100644 --- a/container/SimpleRingBuffer.h +++ b/container/SimpleRingBuffer.h @@ -5,7 +5,7 @@ #include /** - * @brief Circular buffer implementation, useful for buffering + * @brief Circular buffer implementation, useful for buffering * into data streams. * @details * Note that the deleteData() has to be called to increment the read pointer. @@ -25,104 +25,104 @@ public: * with getFreeElement. * */ - SimpleRingBuffer(const size_t size, bool overwriteOld, - size_t maxExcessBytes = 0); - /** - * This constructor takes an external buffer with the specified size. - * @param buffer - * @param size - * @param overwriteOld - * If the ring buffer is overflowing at a write operartion, the oldest data + SimpleRingBuffer(const size_t size, bool overwriteOld, + size_t maxExcessBytes = 0); + /** + * This constructor takes an external buffer with the specified size. + * @param buffer + * @param size + * @param overwriteOld + * If the ring buffer is overflowing at a write operartion, the oldest data * will be overwritten. - * @param maxExcessBytes - * If the buffer can accomodate additional bytes for contigous write - * operations with getFreeElement, this is the maximum allowed additional - * size - */ - SimpleRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld, - size_t maxExcessBytes = 0); + * @param maxExcessBytes + * If the buffer can accomodate additional bytes for contigous write + * operations with getFreeElement, this is the maximum allowed additional + * size + */ + SimpleRingBuffer(uint8_t* buffer, const size_t size, bool overwriteOld, + size_t maxExcessBytes = 0); - virtual ~SimpleRingBuffer(); + virtual ~SimpleRingBuffer(); - /** - * Write to circular buffer and increment write pointer by amount. - * @param data - * @param amount - * @return -@c RETURN_OK if write operation was successfull - * -@c RETURN_FAILED if - */ - ReturnValue_t writeData(const uint8_t* data, size_t amount); + /** + * Write to circular buffer and increment write pointer by amount. + * @param data + * @param amount + * @return -@c RETURN_OK if write operation was successfull + * -@c RETURN_FAILED if + */ + ReturnValue_t writeData(const uint8_t* data, size_t amount); - /** - * Returns a pointer to a free element. If the remaining buffer is - * not large enough, the data will be written past the actual size - * and the amount of excess bytes will be cached. This function - * does not increment the write pointer! - * @param writePointer Pointer to a pointer which can be used to write - * contiguous blocks into the ring buffer - * @param amount - * @return - */ - ReturnValue_t getFreeElement(uint8_t** writePointer, size_t amount); + /** + * Returns a pointer to a free element. If the remaining buffer is + * not large enough, the data will be written past the actual size + * and the amount of excess bytes will be cached. This function + * does not increment the write pointer! + * @param writePointer Pointer to a pointer which can be used to write + * contiguous blocks into the ring buffer + * @param amount + * @return + */ + ReturnValue_t getFreeElement(uint8_t** writePointer, size_t amount); - /** - * This increments the write pointer and also copies the excess bytes - * to the beginning. It should be called if the write operation - * conducted after calling getFreeElement() was performed. - * @return - */ - void confirmBytesWritten(size_t amount); + /** + * This increments the write pointer and also copies the excess bytes + * to the beginning. It should be called if the write operation + * conducted after calling getFreeElement() was performed. + * @return + */ + void confirmBytesWritten(size_t amount); - virtual size_t getExcessBytes() const; - /** - * Helper functions which moves any excess bytes to the start - * of the ring buffer. - * @return - */ - virtual void moveExcessBytesToStart(); + virtual size_t getExcessBytes() const; + /** + * Helper functions which moves any excess bytes to the start + * of the ring buffer. + * @return + */ + virtual void moveExcessBytesToStart(); - /** - * Read from circular buffer at read pointer. - * @param data - * @param amount - * @param incrementReadPtr - * If this is set to true, the read pointer will be incremented. - * If readRemaining is set to true, the read pointer will be incremented - * accordingly. - * @param readRemaining - * If this is set to true, the data will be read even if the amount - * specified exceeds the read data available. - * @param trueAmount [out] - * If readRemaining was set to true, the true amount read will be assigned - * to the passed value. - * @return - * - @c RETURN_OK if data was read successfully - * - @c RETURN_FAILED if not enough data was available and readRemaining - * was set to false. - */ - ReturnValue_t readData(uint8_t* data, size_t amount, - bool incrementReadPtr = false, bool readRemaining = false, - size_t* trueAmount = nullptr); + /** + * Read from circular buffer at read pointer. + * @param data + * @param amount + * @param incrementReadPtr + * If this is set to true, the read pointer will be incremented. + * If readRemaining is set to true, the read pointer will be incremented + * accordingly. + * @param readRemaining + * If this is set to true, the data will be read even if the amount + * specified exceeds the read data available. + * @param trueAmount [out] + * If readRemaining was set to true, the true amount read will be assigned + * to the passed value. + * @return + * - @c RETURN_OK if data was read successfully + * - @c RETURN_FAILED if not enough data was available and readRemaining + * was set to false. + */ + ReturnValue_t readData(uint8_t* data, size_t amount, + bool incrementReadPtr = false, bool readRemaining = false, + size_t* trueAmount = nullptr); - /** - * Delete data by incrementing read pointer. - * @param amount - * @param deleteRemaining - * If the amount specified is larger than the remaing size to read and this - * is set to true, the remaining amount will be deleted as well - * @param trueAmount [out] - * If deleteRemaining was set to true, the amount deleted will be assigned - * to the passed value. - * @return - */ - ReturnValue_t deleteData(size_t amount, bool deleteRemaining = false, - size_t* trueAmount = nullptr); + /** + * Delete data by incrementing read pointer. + * @param amount + * @param deleteRemaining + * If the amount specified is larger than the remaing size to read and this + * is set to true, the remaining amount will be deleted as well + * @param trueAmount [out] + * If deleteRemaining was set to true, the amount deleted will be assigned + * to the passed value. + * @return + */ + ReturnValue_t deleteData(size_t amount, bool deleteRemaining = false, + size_t* trueAmount = nullptr); private: - static const uint8_t READ_PTR = 0; - uint8_t* buffer = nullptr; - size_t maxExcessBytes; - size_t excessBytes = 0; + static const uint8_t READ_PTR = 0; + uint8_t* buffer = nullptr; + size_t maxExcessBytes; + size_t excessBytes = 0; }; #endif /* FSFW_CONTAINER_SIMPLERINGBUFFER_H_ */ diff --git a/container/SinglyLinkedList.h b/container/SinglyLinkedList.h index eb6ae276a..02d590c5c 100644 --- a/container/SinglyLinkedList.h +++ b/container/SinglyLinkedList.h @@ -5,71 +5,71 @@ #include /** - * @brief Linked list data structure, - * each entry has a pointer to the next entry (singly) + * @brief Linked list data structure, + * each entry has a pointer to the next entry (singly) * @ingroup container */ template class LinkedElement { public: - T *value; - class Iterator { - public: - LinkedElement *value = nullptr; - Iterator() {} + T *value; + class Iterator { + public: + LinkedElement *value = nullptr; + Iterator() {} - Iterator(LinkedElement *element) : - value(element) { - } + Iterator(LinkedElement *element) : + value(element) { + } - Iterator& operator++() { - value = value->getNext(); - return *this; - } + Iterator& operator++() { + value = value->getNext(); + return *this; + } - Iterator operator++(int) { - Iterator tmp(*this); - operator++(); - return tmp; - } + Iterator operator++(int) { + Iterator tmp(*this); + operator++(); + return tmp; + } - bool operator==(Iterator other) { - return value == other.value; - } + bool operator==(Iterator other) { + return value == other.value; + } - bool operator!=(Iterator other) { - return !(*this == other); - } - T *operator->() { - return value->value; - } - }; + bool operator!=(Iterator other) { + return !(*this == other); + } + T *operator->() { + return value->value; + } + }; - LinkedElement(T* setElement, LinkedElement* setNext = nullptr): - value(setElement), next(setNext) {} + LinkedElement(T* setElement, LinkedElement* setNext = nullptr): + value(setElement), next(setNext) {} - virtual ~LinkedElement(){} + virtual ~LinkedElement(){} - virtual LinkedElement* getNext() const { - return next; - } + virtual LinkedElement* getNext() const { + return next; + } - virtual void setNext(LinkedElement* next) { - this->next = next; - } + virtual void setNext(LinkedElement* next) { + this->next = next; + } - virtual void setEnd() { - this->next = nullptr; - } + virtual void setEnd() { + this->next = nullptr; + } - LinkedElement* begin() { - return this; - } - LinkedElement* end() { - return nullptr; - } + LinkedElement* begin() { + return this; + } + LinkedElement* end() { + return nullptr; + } private: - LinkedElement *next; + LinkedElement *next; }; template @@ -77,52 +77,52 @@ class SinglyLinkedList { public: using ElementIterator = typename LinkedElement::Iterator; - SinglyLinkedList() {} + SinglyLinkedList() {} - SinglyLinkedList(ElementIterator start) : - start(start.value) {} + SinglyLinkedList(ElementIterator start) : + start(start.value) {} - SinglyLinkedList(LinkedElement* startElement) : - start(startElement) {} + SinglyLinkedList(LinkedElement* startElement) : + start(startElement) {} - ElementIterator begin() const { - return ElementIterator::Iterator(start); - } + ElementIterator begin() const { + return ElementIterator::Iterator(start); + } - /** Returns iterator to nulltr */ - ElementIterator end() const { - return ElementIterator::Iterator(); - } + /** Returns iterator to nulltr */ + ElementIterator end() const { + return ElementIterator::Iterator(); + } - /** - * Returns last element in singly linked list. - * @return - */ - ElementIterator back() const { - LinkedElement *element = start; - while (element->getNext() != nullptr) { - element = element->getNext(); - } - return ElementIterator::Iterator(element); - } + /** + * Returns last element in singly linked list. + * @return + */ + ElementIterator back() const { + LinkedElement *element = start; + while (element->getNext() != nullptr) { + element = element->getNext(); + } + return ElementIterator::Iterator(element); + } - size_t getSize() const { - size_t size = 0; - LinkedElement *element = start; - while (element != nullptr) { - size++; - element = element->getNext(); - } - return size; - } - void setStart(LinkedElement* firstElement) { - start = firstElement; - } + size_t getSize() const { + size_t size = 0; + LinkedElement *element = start; + while (element != nullptr) { + size++; + element = element->getNext(); + } + return size; + } + void setStart(LinkedElement* firstElement) { + start = firstElement; + } - void setNext(LinkedElement* currentElement, - LinkedElement* nextElement) { - currentElement->setNext(nextElement); - } + void setNext(LinkedElement* currentElement, + LinkedElement* nextElement) { + currentElement->setNext(nextElement); + } void setLast(LinkedElement* lastElement) { lastElement->setEnd(); @@ -148,7 +148,7 @@ public: } protected: - LinkedElement *start = nullptr; + LinkedElement *start = nullptr; }; #endif /* SINGLYLINKEDLIST_H_ */ -- 2.34.1 From 6127bb5ea40cd9ef61cfaab39d97213b0c6f1aea Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 28 Jan 2021 11:47:28 +0100 Subject: [PATCH 03/14] tab replacements --- controller/CMakeLists.txt | 4 +- controller/ControllerBase.cpp | 152 +++++++++++++++++----------------- controller/ControllerBase.h | 90 ++++++++++---------- 3 files changed, 123 insertions(+), 123 deletions(-) diff --git a/controller/CMakeLists.txt b/controller/CMakeLists.txt index 6f6607388..b7624d989 100644 --- a/controller/CMakeLists.txt +++ b/controller/CMakeLists.txt @@ -1,4 +1,4 @@ target_sources(${LIB_FSFW_NAME} - PRIVATE - ControllerBase.cpp + PRIVATE + ControllerBase.cpp ) \ No newline at end of file diff --git a/controller/ControllerBase.cpp b/controller/ControllerBase.cpp index 2a4024680..89f0ff681 100644 --- a/controller/ControllerBase.cpp +++ b/controller/ControllerBase.cpp @@ -5,128 +5,128 @@ #include "../action/HasActionsIF.h" ControllerBase::ControllerBase(object_id_t setObjectId, object_id_t parentId, - size_t commandQueueDepth) : - SystemObject(setObjectId), parentId(parentId), mode(MODE_OFF), - submode(SUBMODE_NONE), modeHelper(this), - healthHelper(this, setObjectId) { - commandQueue = QueueFactory::instance()->createMessageQueue( - commandQueueDepth); + size_t commandQueueDepth) : + SystemObject(setObjectId), parentId(parentId), mode(MODE_OFF), + submode(SUBMODE_NONE), modeHelper(this), + healthHelper(this, setObjectId) { + commandQueue = QueueFactory::instance()->createMessageQueue( + commandQueueDepth); } ControllerBase::~ControllerBase() { - QueueFactory::instance()->deleteMessageQueue(commandQueue); + QueueFactory::instance()->deleteMessageQueue(commandQueue); } ReturnValue_t ControllerBase::initialize() { - ReturnValue_t result = SystemObject::initialize(); - if (result != RETURN_OK) { - return result; - } + ReturnValue_t result = SystemObject::initialize(); + if (result != RETURN_OK) { + return result; + } - MessageQueueId_t parentQueue = 0; - if (parentId != objects::NO_OBJECT) { - SubsystemBase *parent = objectManager->get(parentId); - if (parent == nullptr) { - return RETURN_FAILED; - } - parentQueue = parent->getCommandQueue(); + MessageQueueId_t parentQueue = 0; + if (parentId != objects::NO_OBJECT) { + SubsystemBase *parent = objectManager->get(parentId); + if (parent == nullptr) { + return RETURN_FAILED; + } + parentQueue = parent->getCommandQueue(); - parent->registerChild(getObjectId()); - } + parent->registerChild(getObjectId()); + } - result = healthHelper.initialize(parentQueue); - if (result != RETURN_OK) { - return result; - } + result = healthHelper.initialize(parentQueue); + if (result != RETURN_OK) { + return result; + } - result = modeHelper.initialize(parentQueue); - if (result != RETURN_OK) { - return result; - } + result = modeHelper.initialize(parentQueue); + if (result != RETURN_OK) { + return result; + } - return RETURN_OK; + return RETURN_OK; } MessageQueueId_t ControllerBase::getCommandQueue() const { - return commandQueue->getId(); + return commandQueue->getId(); } void ControllerBase::handleQueue() { - CommandMessage command; - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - for (result = commandQueue->receiveMessage(&command); - result == RETURN_OK; - result = commandQueue->receiveMessage(&command)) { + CommandMessage command; + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + for (result = commandQueue->receiveMessage(&command); + result == RETURN_OK; + result = commandQueue->receiveMessage(&command)) { - result = modeHelper.handleModeCommand(&command); - if (result == RETURN_OK) { - continue; - } + result = modeHelper.handleModeCommand(&command); + if (result == RETURN_OK) { + continue; + } - result = healthHelper.handleHealthCommand(&command); - if (result == RETURN_OK) { - continue; - } - result = handleCommandMessage(&command); - if (result == RETURN_OK) { - continue; - } - command.setToUnknownCommand(); - commandQueue->reply(&command); - } + result = healthHelper.handleHealthCommand(&command); + if (result == RETURN_OK) { + continue; + } + result = handleCommandMessage(&command); + if (result == RETURN_OK) { + continue; + } + command.setToUnknownCommand(); + commandQueue->reply(&command); + } } void ControllerBase::startTransition(Mode_t mode, Submode_t submode) { - changeHK(this->mode, this->submode, false); - triggerEvent(CHANGING_MODE, mode, submode); - this->mode = mode; - this->submode = submode; - modeHelper.modeChanged(mode, submode); - modeChanged(mode, submode); - announceMode(false); - changeHK(this->mode, this->submode, true); + changeHK(this->mode, this->submode, false); + triggerEvent(CHANGING_MODE, mode, submode); + this->mode = mode; + this->submode = submode; + modeHelper.modeChanged(mode, submode); + modeChanged(mode, submode); + announceMode(false); + changeHK(this->mode, this->submode, true); } void ControllerBase::getMode(Mode_t* mode, Submode_t* submode) { - *mode = this->mode; - *submode = this->submode; + *mode = this->mode; + *submode = this->submode; } void ControllerBase::setToExternalControl() { - healthHelper.setHealth(EXTERNAL_CONTROL); + healthHelper.setHealth(EXTERNAL_CONTROL); } void ControllerBase::announceMode(bool recursive) { - triggerEvent(MODE_INFO, mode, submode); + triggerEvent(MODE_INFO, mode, submode); } ReturnValue_t ControllerBase::performOperation(uint8_t opCode) { - handleQueue(); - performControlOperation(); - return RETURN_OK; + handleQueue(); + performControlOperation(); + return RETURN_OK; } void ControllerBase::modeChanged(Mode_t mode, Submode_t submode) { - return; + return; } ReturnValue_t ControllerBase::setHealth(HealthState health) { - switch (health) { - case HEALTHY: - case EXTERNAL_CONTROL: - healthHelper.setHealth(health); - return RETURN_OK; - default: - return INVALID_HEALTH_STATE; - } + switch (health) { + case HEALTHY: + case EXTERNAL_CONTROL: + healthHelper.setHealth(health); + return RETURN_OK; + default: + return INVALID_HEALTH_STATE; + } } HasHealthIF::HealthState ControllerBase::getHealth() { - return healthHelper.getHealth(); + return healthHelper.getHealth(); } void ControllerBase::setTaskIF(PeriodicTaskIF* task_){ - executingTask = task_; + executingTask = task_; } void ControllerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) { diff --git a/controller/ControllerBase.h b/controller/ControllerBase.h index 6e83fe80b..f583342fe 100644 --- a/controller/ControllerBase.h +++ b/controller/ControllerBase.h @@ -17,39 +17,39 @@ * a mode and a health state. This avoids boilerplate code. */ class ControllerBase: public HasModesIF, - public HasHealthIF, - public ExecutableObjectIF, - public SystemObject, - public HasReturnvaluesIF { + public HasHealthIF, + public ExecutableObjectIF, + public SystemObject, + public HasReturnvaluesIF { public: - static const Mode_t MODE_NORMAL = 2; + static const Mode_t MODE_NORMAL = 2; - ControllerBase(object_id_t setObjectId, object_id_t parentId, - size_t commandQueueDepth = 3); - virtual ~ControllerBase(); + ControllerBase(object_id_t setObjectId, object_id_t parentId, + size_t commandQueueDepth = 3); + virtual ~ControllerBase(); - /** SystemObject override */ - virtual ReturnValue_t initialize() override; + /** SystemObject override */ + virtual ReturnValue_t initialize() override; - virtual MessageQueueId_t getCommandQueue() const override; + virtual MessageQueueId_t getCommandQueue() const override; - /** HasHealthIF overrides */ - virtual ReturnValue_t setHealth(HealthState health) override; - virtual HasHealthIF::HealthState getHealth() override; + /** HasHealthIF overrides */ + virtual ReturnValue_t setHealth(HealthState health) override; + virtual HasHealthIF::HealthState getHealth() override; - /** ExecutableObjectIF overrides */ - virtual ReturnValue_t performOperation(uint8_t opCode) override; - virtual void setTaskIF(PeriodicTaskIF* task) override; - virtual ReturnValue_t initializeAfterTaskCreation() override; + /** ExecutableObjectIF overrides */ + virtual ReturnValue_t performOperation(uint8_t opCode) override; + virtual void setTaskIF(PeriodicTaskIF* task) override; + virtual ReturnValue_t initializeAfterTaskCreation() override; protected: - /** - * Implemented by child class. Handle command messages which are not - * mode or health messages. - * @param message - * @return - */ + /** + * Implemented by child class. Handle command messages which are not + * mode or health messages. + * @param message + * @return + */ virtual ReturnValue_t handleCommandMessage(CommandMessage *message) = 0; /** @@ -60,35 +60,35 @@ protected: virtual ReturnValue_t checkModeCommand(Mode_t mode, Submode_t submode, uint32_t *msToReachTheMode) = 0; - const object_id_t parentId; + const object_id_t parentId; - Mode_t mode; + Mode_t mode; - Submode_t submode; + Submode_t submode; - MessageQueueIF* commandQueue = nullptr; + MessageQueueIF* commandQueue = nullptr; - ModeHelper modeHelper; + ModeHelper modeHelper; - HealthHelper healthHelper; + HealthHelper healthHelper; - /** - * Pointer to the task which executes this component, - * is invalid before setTaskIF was called. - */ - PeriodicTaskIF* executingTask = nullptr; + /** + * Pointer to the task which executes this component, + * is invalid before setTaskIF was called. + */ + PeriodicTaskIF* executingTask = nullptr; - /** Handle mode and health messages */ - virtual void handleQueue(); + /** Handle mode and health messages */ + virtual void handleQueue(); - /** Mode helpers */ - virtual void modeChanged(Mode_t mode, Submode_t submode); - virtual void startTransition(Mode_t mode, Submode_t submode); - virtual void getMode(Mode_t *mode, Submode_t *submode); - virtual void setToExternalControl(); - virtual void announceMode(bool recursive); - /** HK helpers */ - virtual void changeHK(Mode_t mode, Submode_t submode, bool enable); + /** Mode helpers */ + virtual void modeChanged(Mode_t mode, Submode_t submode); + virtual void startTransition(Mode_t mode, Submode_t submode); + virtual void getMode(Mode_t *mode, Submode_t *submode); + virtual void setToExternalControl(); + virtual void announceMode(bool recursive); + /** HK helpers */ + virtual void changeHK(Mode_t mode, Submode_t submode, bool enable); }; #endif /* FSFW_CONTROLLER_CONTROLLERBASE_H_ */ -- 2.34.1 From 6b4bed8ca93614021da471437e8350cb2170369a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jan 2021 00:12:40 +0100 Subject: [PATCH 04/14] imrpoved windows includes --- osal/Endiness.h | 3 ++- osal/host/Clock.cpp | 2 +- osal/host/PeriodicTask.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/osal/Endiness.h b/osal/Endiness.h index 9d3fdef0f..281b715b9 100644 --- a/osal/Endiness.h +++ b/osal/Endiness.h @@ -25,7 +25,8 @@ #else #ifdef WIN32 -#include +#include +#include #if REG_DWORD == REG_DWORD_LITTLE_ENDIAN #define BYTE_ORDER_SYSTEM LITTLE_ENDIAN #else diff --git a/osal/host/Clock.cpp b/osal/host/Clock.cpp index 0b3063490..771474c7c 100644 --- a/osal/host/Clock.cpp +++ b/osal/host/Clock.cpp @@ -3,7 +3,7 @@ #include #if defined(WIN32) -#include +#include #elif defined(LINUX) #include #endif diff --git a/osal/host/PeriodicTask.cpp b/osal/host/PeriodicTask.cpp index 1f4275464..7663d522d 100644 --- a/osal/host/PeriodicTask.cpp +++ b/osal/host/PeriodicTask.cpp @@ -9,7 +9,7 @@ #include #if defined(WIN32) -#include +#include #elif defined(LINUX) #include #endif -- 2.34.1 From bc722b5583b3a0b9b2ec517d1289081344927088 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jan 2021 02:35:08 +0100 Subject: [PATCH 05/14] clock and dhb update --- devicehandlers/DeviceHandlerBase.cpp | 16 ++++----- osal/host/Clock.cpp | 52 +++++++++++++--------------- 2 files changed, 32 insertions(+), 36 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index ed5c1fa75..b0fdb310d 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -1286,18 +1286,17 @@ ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId, } void DeviceHandlerBase::buildInternalCommand(void) { -//Neither Raw nor Direct could build a command + /* Neither raw nor direct could build a command */ ReturnValue_t result = NOTHING_TO_SEND; DeviceCommandId_t deviceCommandId = NO_COMMAND_ID; if (mode == MODE_NORMAL) { result = buildNormalDeviceCommand(&deviceCommandId); if (result == BUSY) { - // so we can track misconfigurations - printWarningOrError(sif::OutputTypes::OUT_WARNING, - "buildInternalCommand", - HasReturnvaluesIF::RETURN_FAILED, - "Busy."); - result = NOTHING_TO_SEND; //no need to report this + /* So we can track misconfigurations */ + printWarningOrError(sif::OutputTypes::OUT_WARNING, "buildInternalCommand", + HasReturnvaluesIF::RETURN_FAILED, "Busy."); + /* No need to report this */ + result = NOTHING_TO_SEND; } } else if (mode == MODE_RAW) { @@ -1319,7 +1318,8 @@ void DeviceHandlerBase::buildInternalCommand(void) { deviceCommandId); if (iter == deviceCommandMap.end()) { result = COMMAND_NOT_SUPPORTED; - } else if (iter->second.isExecuting) { + } + else if (iter->second.isExecuting) { #if FSFW_DISABLE_PRINTOUT == 0 char output[36]; sprintf(output, "Command 0x%08x is executing", diff --git a/osal/host/Clock.cpp b/osal/host/Clock.cpp index 771474c7c..f0543c790 100644 --- a/osal/host/Clock.cpp +++ b/osal/host/Clock.cpp @@ -15,35 +15,34 @@ using SystemClock = std::chrono::system_clock; uint32_t Clock::getTicksPerSecond(void){ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "Clock::getTicksPerSecond: not implemented yet" << std::endl; + sif::warning << "Clock::getTicksPerSecond: Not implemented for host OSAL" << std::endl; +#else + sif::printWarning("Clock::getTicksPerSecond: Not implemented for host OSAL\n"); #endif - return 0; - //return CLOCKS_PER_SEC; - //uint32_t ticks = sysconf(_SC_CLK_TCK); - //return ticks; + /* To avoid division by zero */ + return 1; } ReturnValue_t Clock::setClock(const TimeOfDay_t* time) { - // do some magic with chrono + /* I don't know why someone would need to set a clock which is probably perfectly fine on a + host system with internet access so this is not implemented for now. */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "Clock::setClock: not implemented yet" << std::endl; + sif::warning << "Clock::setClock: Not implemented for host OSAL" << std::endl; +#else + sif::printWarning("Clock::setClock: Not implemented for host OSAL\n"); #endif return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t Clock::setClock(const timeval* time) { - // do some magic with chrono -#if defined(WIN32) - return HasReturnvaluesIF::RETURN_OK; -#elif defined(LINUX) - return HasReturnvaluesIF::RETURN_OK; -#else - -#endif + /* I don't know why someone would need to set a clock which is probably perfectly fine on a + host system with internet access so this is not implemented for now. */ #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "Clock::getUptime: Not implemented for found OS" << std::endl; + sif::warning << "Clock::setClock: Not implemented for host OSAL" << std::endl; +#else + sif::printWarning("Clock::setClock: Not implemented for host OSAL\n"); #endif - return HasReturnvaluesIF::RETURN_FAILED; + return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t Clock::getClock_timeval(timeval* time) { @@ -76,10 +75,11 @@ ReturnValue_t Clock::getClock_timeval(timeval* time) { } ReturnValue_t Clock::getClock_usecs(uint64_t* time) { - // do some magic with chrono -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "Clock::gerClock_usecs: not implemented yet" << std::endl; -#endif + if(time == nullptr) { + return HasReturnvaluesIF::RETURN_FAILED; + } + using namespace std::chrono; + *time = duration_cast(system_clock::now().time_since_epoch()).count(); return HasReturnvaluesIF::RETURN_OK; } @@ -121,9 +121,9 @@ ReturnValue_t Clock::getUptime(uint32_t* uptimeMs) { ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { - // do some magic with chrono (C++20!) - // Right now, the library doesn't have the new features yet. - // so we work around that for now. + /* Do some magic with chrono (C++20!) */ + /* Right now, the library doesn't have the new features to get the required values yet. + so we work around that for now. */ auto now = SystemClock::now(); auto seconds = std::chrono::time_point_cast(now); auto fraction = now - seconds; @@ -138,10 +138,6 @@ ReturnValue_t Clock::getDateAndTime(TimeOfDay_t* time) { time->second = timeInfo->tm_sec; auto usecond = std::chrono::duration_cast(fraction); time->usecond = usecond.count(); - -#if FSFW_CPP_OSTREAM_ENABLED == 1 - //sif::warning << "Clock::getDateAndTime: not implemented yet" << std::endl; -#endif return HasReturnvaluesIF::RETURN_OK; } -- 2.34.1 From 484f9b6b37c531e8a64a9767d9324f42d57475af Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jan 2021 17:16:34 +0100 Subject: [PATCH 06/14] some tweaks --- pus/Service17Test.cpp | 2 +- tmtcservices/TmTcBridge.cpp | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/pus/Service17Test.cpp b/pus/Service17Test.cpp index 2ef44490d..85a32e1e5 100644 --- a/pus/Service17Test.cpp +++ b/pus/Service17Test.cpp @@ -15,7 +15,7 @@ Service17Test::~Service17Test() { } ReturnValue_t Service17Test::handleRequest(uint8_t subservice) { - switch(subservice){ + switch(subservice) { case Subservice::CONNECTION_TEST: { TmPacketStored connectionPacket(apid, serviceId, Subservice::CONNECTION_TEST_REPORT, packetSubCounter++); diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 2513071a5..12d163d16 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -1,7 +1,7 @@ #include "TmTcBridge.h" #include "../ipc/QueueFactory.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "../serviceinterface/ServiceInterface.h" #include "../globalfunctions/arrayprinter.h" TmTcBridge::TmTcBridge(object_id_t objectId, object_id_t tcDestination, @@ -109,9 +109,8 @@ ReturnValue_t TmTcBridge::handleTm() { ReturnValue_t result = handleTmQueue(); if(result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmTcBridge::handleTm: Error handling TM queue with " - << "error code 0x" << std::hex << result << std::dec - << "!" << std::endl; + sif::error << "TmTcBridge::handleTm: Error handling TM queue with error code 0x" << + std::hex << result << std::dec << "!" << std::endl; #endif status = result; } @@ -121,8 +120,7 @@ ReturnValue_t TmTcBridge::handleTm() { result = handleStoredTm(); if(result != RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "TmTcBridge::handleTm: Error handling stored TMs!" - << std::endl; + sif::error << "TmTcBridge::handleTm: Error handling stored TMs!" << std::endl; #endif status = result; } @@ -140,9 +138,15 @@ ReturnValue_t TmTcBridge::handleTmQueue() { result == HasReturnvaluesIF::RETURN_OK; result = tmTcReceptionQueue->receiveMessage(&message)) { + +#if FSFW_VERBOSE_LEVEL >= 3 #if FSFW_CPP_OSTREAM_ENABLED == 1 - //sif::info << (int) packetSentCounter << std::endl; + sif::info << "Sent packet counter: " << static_cast(packetSentCounter) << std::endl; +#else + sif::printInfo("Sent packet counter: %d\n", packetSentCounter); #endif +#endif /* FSFW_VERBOSE_LEVEL >= 3 */ + if(communicationLinkUp == false or packetSentCounter >= sentPacketsPerCycle) { storeDownlinkData(&message); -- 2.34.1 From e65990feffc379a0b7e466a7674b6c44cb476c87 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jan 2021 22:28:38 +0100 Subject: [PATCH 07/14] getParameters: uint16_t -> uint8_t for unique identfiier --- parameters/HasParametersIF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/parameters/HasParametersIF.h b/parameters/HasParametersIF.h index 19c12d81f..4bdd2e1b2 100644 --- a/parameters/HasParametersIF.h +++ b/parameters/HasParametersIF.h @@ -75,7 +75,7 @@ public: * @return */ virtual ReturnValue_t getParameter(uint8_t domainId, - uint16_t uniqueIdentifier, ParameterWrapper *parameterWrapper, + uint8_t uniqueIdentifier, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex) = 0; }; -- 2.34.1 From 7f0db5b47cf9ff4dd78fbb267855cb112ab106c5 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 29 Jan 2021 22:45:53 +0100 Subject: [PATCH 08/14] type and name change for HasParametersIF --- devicehandlers/DeviceHandlerBase.cpp | 6 +++--- devicehandlers/DeviceHandlerBase.h | 2 +- devicehandlers/DeviceHandlerFailureIsolation.cpp | 12 ++++++------ devicehandlers/DeviceHandlerFailureIsolation.h | 6 +++--- fdir/FaultCounter.cpp | 4 ++-- fdir/FaultCounter.h | 2 +- monitoring/LimitMonitor.h | 10 +++++----- monitoring/MonitorReporter.h | 8 ++++---- monitoring/TriplexMonitor.h | 8 ++++---- parameters/HasParametersIF.h | 11 +++++------ power/Fuse.cpp | 6 +++--- power/Fuse.h | 6 +++--- power/PowerComponent.cpp | 8 ++++---- power/PowerComponent.h | 6 +++--- power/PowerSensor.cpp | 6 +++--- power/PowerSensor.h | 2 +- thermal/Heater.cpp | 6 +++--- thermal/Heater.h | 4 ++-- thermal/TemperatureSensor.h | 6 +++--- thermal/ThermalComponent.cpp | 6 +++--- thermal/ThermalComponent.h | 2 +- thermal/ThermalComponentCore.cpp | 6 +++--- thermal/ThermalComponentCore.h | 2 +- 23 files changed, 67 insertions(+), 68 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index b0fdb310d..897d0595b 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -1380,10 +1380,10 @@ void DeviceHandlerBase::doOffActivity() { } ReturnValue_t DeviceHandlerBase::getParameter(uint8_t domainId, - uint16_t parameterId, ParameterWrapper* parameterWrapper, + uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { - ReturnValue_t result = fdirInstance->getParameter(domainId, parameterId, - parameterWrapper, newValues, startAtIndex); + ReturnValue_t result = fdirInstance->getParameter(domainId, uniqueId, parameterWrapper, + newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; } diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 92dc9201a..e75d2729d 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -216,7 +216,7 @@ public: virtual void getMode(Mode_t *mode, Submode_t *submode); HealthState getHealth(); ReturnValue_t setHealth(HealthState health); - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex) override; diff --git a/devicehandlers/DeviceHandlerFailureIsolation.cpp b/devicehandlers/DeviceHandlerFailureIsolation.cpp index 5f7ab89f6..ba118090b 100644 --- a/devicehandlers/DeviceHandlerFailureIsolation.cpp +++ b/devicehandlers/DeviceHandlerFailureIsolation.cpp @@ -209,20 +209,20 @@ void DeviceHandlerFailureIsolation::startRecovery(Event reason) { } ReturnValue_t DeviceHandlerFailureIsolation::getParameter(uint8_t domainId, - uint16_t parameterId, ParameterWrapper* parameterWrapper, + uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { - ReturnValue_t result = strangeReplyCount.getParameter(domainId, parameterId, + ReturnValue_t result = strangeReplyCount.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; } - result = missedReplyCount.getParameter(domainId, parameterId, - parameterWrapper, newValues, startAtIndex); + result = missedReplyCount.getParameter(domainId, uniqueId, parameterWrapper, newValues, + startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; } - result = recoveryCounter.getParameter(domainId, parameterId, - parameterWrapper, newValues, startAtIndex); + result = recoveryCounter.getParameter(domainId, uniqueId, parameterWrapper, newValues, + startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; } diff --git a/devicehandlers/DeviceHandlerFailureIsolation.h b/devicehandlers/DeviceHandlerFailureIsolation.h index 8a3fd9dd9..016b18b3a 100644 --- a/devicehandlers/DeviceHandlerFailureIsolation.h +++ b/devicehandlers/DeviceHandlerFailureIsolation.h @@ -17,9 +17,9 @@ public: ReturnValue_t initialize(); void triggerEvent(Event event, uint32_t parameter1 = 0, uint32_t parameter2 = 0);bool isFdirActionInProgress(); - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper *parameterWrapper, - const ParameterWrapper *newValues, uint16_t startAtIndex); + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex); protected: FaultCounter strangeReplyCount; diff --git a/fdir/FaultCounter.cpp b/fdir/FaultCounter.cpp index 6519a3a88..53c1dd7de 100644 --- a/fdir/FaultCounter.cpp +++ b/fdir/FaultCounter.cpp @@ -58,14 +58,14 @@ FaultCounter::FaultCounter() : parameterDomain(0), timer(), faultCount(0), failureThreshold(0) { } -ReturnValue_t FaultCounter::getParameter(uint8_t domainId, uint16_t parameterId, +ReturnValue_t FaultCounter::getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { if (domainId != parameterDomain) { return INVALID_DOMAIN_ID; } - switch (parameterId) { + switch (uniqueId) { case 0: parameterWrapper->set(failureThreshold); break; diff --git a/fdir/FaultCounter.h b/fdir/FaultCounter.h index dc929debd..e0670c4b3 100644 --- a/fdir/FaultCounter.h +++ b/fdir/FaultCounter.h @@ -23,7 +23,7 @@ public: void setFailureThreshold(uint32_t failureThreshold); void setFaultDecrementTimeMs(uint32_t timeMs); - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex); diff --git a/monitoring/LimitMonitor.h b/monitoring/LimitMonitor.h index c4448ceda..cd8b8d130 100644 --- a/monitoring/LimitMonitor.h +++ b/monitoring/LimitMonitor.h @@ -37,16 +37,16 @@ public: } } - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper *parameterWrapper, - const ParameterWrapper *newValues, uint16_t startAtIndex) { + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex) { ReturnValue_t result = this->MonitorBase::getParameter(domainId, - parameterId, parameterWrapper, newValues, startAtIndex); + uniqueId, parameterWrapper, newValues, startAtIndex); //We'll reuse the DOMAIN_ID of MonitorReporter, as we know the parameterIds used there. if (result != this->INVALID_IDENTIFIER_ID) { return result; } - switch (parameterId) { + switch (uniqueId) { case 10: parameterWrapper->set(this->lowerLimit); break; diff --git a/monitoring/MonitorReporter.h b/monitoring/MonitorReporter.h index 7ce110e57..d155594d6 100644 --- a/monitoring/MonitorReporter.h +++ b/monitoring/MonitorReporter.h @@ -51,13 +51,13 @@ public: return state; } - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper *parameterWrapper, - const ParameterWrapper *newValues, uint16_t startAtIndex) { + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex) { if (domainId != monitorId) { return INVALID_DOMAIN_ID; } - switch (parameterId) { + switch (uniqueId) { case 0: parameterWrapper->set(this->confirmationLimit); break; diff --git a/monitoring/TriplexMonitor.h b/monitoring/TriplexMonitor.h index c4b3c5375..d9ee83053 100644 --- a/monitoring/TriplexMonitor.h +++ b/monitoring/TriplexMonitor.h @@ -71,13 +71,13 @@ public: return HasReturnvaluesIF::RETURN_OK; } - ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper *parameterWrapper, - const ParameterWrapper *newValues, uint16_t startAtIndex) { + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex) { if (domainId != this->domainId) { return INVALID_DOMAIN_ID; } - switch (parameterId) { + switch (uniqueId) { case 0: parameterWrapper->set(limit); break; diff --git a/parameters/HasParametersIF.h b/parameters/HasParametersIF.h index 4bdd2e1b2..84790be66 100644 --- a/parameters/HasParametersIF.h +++ b/parameters/HasParametersIF.h @@ -52,9 +52,8 @@ public: return id; } - static uint32_t getFullParameterId(uint8_t domainId, - uint8_t uniqueIdentifier, uint16_t linearIndex) { - return (domainId << 24) + (uniqueIdentifier << 16) + linearIndex; + static uint32_t getFullParameterId(uint8_t domainId, uint8_t uniqueId, uint16_t linearIndex) { + return (domainId << 24) + (uniqueId << 16) + linearIndex; } virtual ~HasParametersIF() {} @@ -74,9 +73,9 @@ public: * matrix indexes. * @return */ - virtual ReturnValue_t getParameter(uint8_t domainId, - uint8_t uniqueIdentifier, ParameterWrapper *parameterWrapper, - const ParameterWrapper *newValues, uint16_t startAtIndex) = 0; + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueIdentifier, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex) = 0; }; #endif /* FSFW_PARAMETERS_HASPARAMETERSIF_H_ */ diff --git a/power/Fuse.cpp b/power/Fuse.cpp index b6e0a7f16..91da5388c 100644 --- a/power/Fuse.cpp +++ b/power/Fuse.cpp @@ -210,15 +210,15 @@ void Fuse::setDataPoolEntriesInvalid() { set.commit(); } -ReturnValue_t Fuse::getParameter(uint8_t domainId, uint16_t parameterId, +ReturnValue_t Fuse::getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { - ReturnValue_t result = currentLimit.getParameter(domainId, parameterId, + ReturnValue_t result = currentLimit.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; } - result = powerMonitor.getParameter(domainId, parameterId, parameterWrapper, + result = powerMonitor.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); return result; } diff --git a/power/Fuse.h b/power/Fuse.h index b892611bc..1dc387212 100644 --- a/power/Fuse.h +++ b/power/Fuse.h @@ -62,9 +62,9 @@ public: ReturnValue_t setHealth(HealthState health); HasHealthIF::HealthState getHealth(); - ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper *parameterWrapper, - const ParameterWrapper *newValues, uint16_t startAtIndex); + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex); private: uint8_t oldFuseState; diff --git a/power/PowerComponent.cpp b/power/PowerComponent.cpp index c31b9a85e..04f8658ea 100644 --- a/power/PowerComponent.cpp +++ b/power/PowerComponent.cpp @@ -61,13 +61,13 @@ ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, size_t* size, return SerializeAdapter::deSerialize(&max, buffer, size, streamEndianness); } -ReturnValue_t PowerComponent::getParameter(uint8_t domainId, - uint16_t parameterId, ParameterWrapper* parameterWrapper, - const ParameterWrapper* newValues, uint16_t startAtIndex) { +ReturnValue_t PowerComponent::getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, + uint16_t startAtIndex) { if (domainId != moduleId) { return INVALID_DOMAIN_ID; } - switch (parameterId) { + switch (uniqueId) { case 0: parameterWrapper->set<>(min); break; diff --git a/power/PowerComponent.h b/power/PowerComponent.h index c1add3b91..659b68530 100644 --- a/power/PowerComponent.h +++ b/power/PowerComponent.h @@ -31,9 +31,9 @@ public: ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, Endianness streamEndianness) override; - ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper *parameterWrapper, - const ParameterWrapper *newValues, uint16_t startAtIndex); + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, + uint16_t startAtIndex); private: const object_id_t deviceObjectId = objects::NO_OBJECT; const uint8_t switchId1; diff --git a/power/PowerSensor.cpp b/power/PowerSensor.cpp index fb181d9f9..40d7afc61 100644 --- a/power/PowerSensor.cpp +++ b/power/PowerSensor.cpp @@ -119,15 +119,15 @@ HasHealthIF::HealthState PowerSensor::getHealth() { return healthHelper.getHealth(); } -ReturnValue_t PowerSensor::getParameter(uint8_t domainId, uint16_t parameterId, +ReturnValue_t PowerSensor::getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { - ReturnValue_t result = currentLimit.getParameter(domainId, parameterId, + ReturnValue_t result = currentLimit.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; } - result = voltageLimit.getParameter(domainId, parameterId, parameterWrapper, + result = voltageLimit.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); return result; } diff --git a/power/PowerSensor.h b/power/PowerSensor.h index a0ccb1ca7..5a21ab104 100644 --- a/power/PowerSensor.h +++ b/power/PowerSensor.h @@ -48,7 +48,7 @@ public: float getPower(); ReturnValue_t setHealth(HealthState health); HasHealthIF::HealthState getHealth(); - ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex); private: diff --git a/thermal/Heater.cpp b/thermal/Heater.cpp index ce965d5ea..782ce2963 100644 --- a/thermal/Heater.cpp +++ b/thermal/Heater.cpp @@ -290,13 +290,13 @@ void Heater::handleQueue() { } } -ReturnValue_t Heater::getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, +ReturnValue_t Heater::getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { if (domainId != DOMAIN_ID_BASE) { return INVALID_DOMAIN_ID; } - switch (parameterId) { + switch (uniqueId) { case 0: parameterWrapper->set(heaterOnCountdown.timeout); break; diff --git a/thermal/Heater.h b/thermal/Heater.h index b034dfee5..f83957a2e 100644 --- a/thermal/Heater.h +++ b/thermal/Heater.h @@ -34,8 +34,8 @@ public: MessageQueueId_t getCommandQueue() const; - ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, - ParameterWrapper *parameterWrapper, + ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, + ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex); protected: diff --git a/thermal/TemperatureSensor.h b/thermal/TemperatureSensor.h index f41b3761b..2b1fb1f07 100644 --- a/thermal/TemperatureSensor.h +++ b/thermal/TemperatureSensor.h @@ -183,10 +183,10 @@ public: static const uint8_t DOMAIN_ID_SENSOR = 1; - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex) { - ReturnValue_t result = sensorMonitor.getParameter(domainId, parameterId, + ReturnValue_t result = sensorMonitor.getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; @@ -194,7 +194,7 @@ public: if (domainId != this->DOMAIN_ID_BASE) { return INVALID_DOMAIN_ID; } - switch (parameterId) { + switch (uniqueId) { case ADDRESS_A: parameterWrapper->set(parameters.a); break; diff --git a/thermal/ThermalComponent.cpp b/thermal/ThermalComponent.cpp index 084201dd4..d42c34b33 100644 --- a/thermal/ThermalComponent.cpp +++ b/thermal/ThermalComponent.cpp @@ -148,14 +148,14 @@ ThermalComponentIF::State ThermalComponent::getIgnoredState(int8_t state) { } ReturnValue_t ThermalComponent::getParameter(uint8_t domainId, - uint16_t parameterId, ParameterWrapper* parameterWrapper, + uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { - ReturnValue_t result = ThermalComponentCore::getParameter(domainId, parameterId, + ReturnValue_t result = ThermalComponentCore::getParameter(domainId, uniqueId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_IDENTIFIER_ID) { return result; } - switch (parameterId) { + switch (uniqueId) { case 12: parameterWrapper->set(nopParameters.lowerNopLimit); break; diff --git a/thermal/ThermalComponent.h b/thermal/ThermalComponent.h index 0785a9141..3b6dd9cdd 100644 --- a/thermal/ThermalComponent.h +++ b/thermal/ThermalComponent.h @@ -58,7 +58,7 @@ public: virtual ReturnValue_t setLimits( const uint8_t* data, size_t size); - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex); diff --git a/thermal/ThermalComponentCore.cpp b/thermal/ThermalComponentCore.cpp index ba8750532..7df04b047 100644 --- a/thermal/ThermalComponentCore.cpp +++ b/thermal/ThermalComponentCore.cpp @@ -247,17 +247,17 @@ ThermalComponentCore::Parameters ThermalComponentCore::getParameters() { } ReturnValue_t ThermalComponentCore::getParameter(uint8_t domainId, - uint16_t parameterId, ParameterWrapper* parameterWrapper, + uint8_t uniqueId, ParameterWrapper* parameterWrapper, const ParameterWrapper* newValues, uint16_t startAtIndex) { ReturnValue_t result = temperatureMonitor.getParameter(domainId, - parameterId, parameterWrapper, newValues, startAtIndex); + uniqueId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; } if (domainId != this->domainId) { return INVALID_DOMAIN_ID; } - switch (parameterId) { + switch (uniqueId) { case 0: parameterWrapper->set(parameters.heaterOn); break; diff --git a/thermal/ThermalComponentCore.h b/thermal/ThermalComponentCore.h index da9424e68..a1fa594a5 100644 --- a/thermal/ThermalComponentCore.h +++ b/thermal/ThermalComponentCore.h @@ -68,7 +68,7 @@ public: virtual void setOutputInvalid(); - virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, + virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex); -- 2.34.1 From cf945d4d34fc7cd99c17138d788ef1dc153e5b30 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 30 Jan 2021 20:29:23 +0100 Subject: [PATCH 09/14] added srv20 written by J. Gerhards --- objectmanager/frameworkObjects.h | 1 + pus/CMakeLists.txt | 22 ++-- pus/Service20ParameterManagement.cpp | 181 ++++++++++++++++++++++++++ pus/Service20ParameterManagement.h | 58 +++++++++ pus/servicepackets/Service20Packets.h | 91 +++++++++++++ 5 files changed, 342 insertions(+), 11 deletions(-) create mode 100644 pus/Service20ParameterManagement.cpp create mode 100644 pus/Service20ParameterManagement.h create mode 100644 pus/servicepackets/Service20Packets.h diff --git a/objectmanager/frameworkObjects.h b/objectmanager/frameworkObjects.h index a138b07ea..2174f829a 100644 --- a/objectmanager/frameworkObjects.h +++ b/objectmanager/frameworkObjects.h @@ -14,6 +14,7 @@ enum framework_objects: object_id_t { PUS_SERVICE_8_FUNCTION_MGMT = 0x53000008, PUS_SERVICE_9_TIME_MGMT = 0x53000009, PUS_SERVICE_17_TEST = 0x53000017, + PUS_SERVICE_20_PARAMETERS = 0x53000020, PUS_SERVICE_200_MODE_MGMT = 0x53000200, //Generic IDs for IPC, modes, health, events diff --git a/pus/CMakeLists.txt b/pus/CMakeLists.txt index c0e004481..8b55adf03 100644 --- a/pus/CMakeLists.txt +++ b/pus/CMakeLists.txt @@ -1,12 +1,12 @@ -target_sources(${LIB_FSFW_NAME} - PRIVATE - CService200ModeCommanding.cpp - CService201HealthCommanding.cpp - Service17Test.cpp - Service1TelecommandVerification.cpp - Service2DeviceAccess.cpp - Service3Housekeeping.cpp - Service5EventReporting.cpp - Service8FunctionManagement.cpp - Service9TimeManagement.cpp +target_sources(${LIB_FSFW_NAME} PRIVATE + Service1TelecommandVerification.cpp + Service2DeviceAccess.cpp + Service3Housekeeping.cpp + Service5EventReporting.cpp + Service8FunctionManagement.cpp + Service9TimeManagement.cpp + Service17Test.cpp + Service20ParameterManagement.cpp + CService200ModeCommanding.cpp + CService201HealthCommanding.cpp ) \ No newline at end of file diff --git a/pus/Service20ParameterManagement.cpp b/pus/Service20ParameterManagement.cpp new file mode 100644 index 000000000..3b04bd4e0 --- /dev/null +++ b/pus/Service20ParameterManagement.cpp @@ -0,0 +1,181 @@ +#include "Service20ParameterManagement.h" +#include "servicepackets/Service20Packets.h" + +#include +#include +#include +#include +#include + + +Service20ParameterManagement::Service20ParameterManagement(object_id_t objectId, uint16_t apid, + uint8_t serviceId, uint8_t numberOfParallelCommands, uint16_t commandTimeoutSeconds) : + CommandingServiceBase(objectId, apid, serviceId, + numberOfParallelCommands,commandTimeoutSeconds) {} + +Service20ParameterManagement::~Service20ParameterManagement() {} + + +ReturnValue_t Service20ParameterManagement::isValidSubservice( + uint8_t subservice) { + switch(static_cast(subservice)) { + case Subservice::PARAMETER_LOAD: + case Subservice::PARAMETER_DUMP: + return HasReturnvaluesIF::RETURN_OK; + default: +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "Invalid Subservice for Service 20" << std::endl; +#else + sif::printError("Invalid Subservice for Service 20\n"); +#endif + return AcceptsTelecommandsIF::INVALID_SUBSERVICE; + } +} + + +ReturnValue_t Service20ParameterManagement::getMessageQueueAndObject( + uint8_t subservice, const uint8_t* tcData, size_t tcDataLen, + MessageQueueId_t* id, object_id_t* objectId) { + ReturnValue_t result = checkAndAcquireTargetID(objectId,tcData,tcDataLen); + if(result != RETURN_OK) { + return result; + } + return checkInterfaceAndAcquireMessageQueue(id,objectId); +} + + +ReturnValue_t Service20ParameterManagement::checkAndAcquireTargetID( + object_id_t* objectIdToSet, const uint8_t* tcData, size_t tcDataLen) { + if(SerializeAdapter::deSerialize(objectIdToSet, &tcData, &tcDataLen, + SerializeIF::Endianness::BIG) != HasReturnvaluesIF::RETURN_OK) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "Service20ParameterManagement::checkAndAcquireTargetID: " + << "Invalid data." << std::endl; +#else + sif::printError("Service20ParameterManagement::" + "checkAndAcquireTargetID: Invalid data.\n"); +#endif + return CommandingServiceBase::INVALID_TC; + } + return HasReturnvaluesIF::RETURN_OK; +} + + +ReturnValue_t Service20ParameterManagement::checkInterfaceAndAcquireMessageQueue( + MessageQueueId_t* messageQueueToSet, object_id_t* objectId) { + // check ReceivesParameterMessagesIF property of target + ReceivesParameterMessagesIF* possibleTarget = + objectManager->get(*objectId); + if(possibleTarget == nullptr) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::error << "Service20ParameterManagement::checkInterfaceAndAcquire" + <<"MessageQueue: Can't access object" << std::endl; + sif::error << "Object ID: " << std::hex << objectId << std::dec + << std::endl; + sif::error << "Make sure it implements ReceivesParameterMessagesIF!" + << std::endl; +#else + sif::printError("Service20ParameterManagement::checkInterfaceAndAcquire" + "MessageQueue: Can't access object\n"); + sif::printError("Object ID: 0x%08x\n", objectId); + sif::printError("Make sure it implements " + "ReceivesParameterMessagesIF!\n"); +#endif + + return CommandingServiceBase::INVALID_OBJECT; + } + *messageQueueToSet = possibleTarget->getCommandQueue(); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Service20ParameterManagement::prepareCommand( + CommandMessage* message, uint8_t subservice, const uint8_t* tcData, + size_t tcDataLen, uint32_t* state, object_id_t objectId) { + switch(static_cast(subservice)){ + case Subservice::PARAMETER_DUMP: { + return prepareDumpCommand(message, tcData, tcDataLen); + } + break; + case Subservice::PARAMETER_LOAD: { + return prepareLoadCommand(message, tcData, tcDataLen); + } + break; + default: + return HasReturnvaluesIF::RETURN_FAILED; + } +} + +ReturnValue_t Service20ParameterManagement::prepareDumpCommand( + CommandMessage* message, const uint8_t* tcData, size_t tcDataLen) { + //the first part is the objectId, but we have extracted that earlier + //and only need the parameterId + tcData += sizeof(object_id_t); + tcDataLen -= sizeof(object_id_t); + ParameterId_t parameterId; + if(SerializeAdapter::deSerialize(¶meterId, &tcData, &tcDataLen, + SerializeIF::Endianness::BIG) != HasReturnvaluesIF::RETURN_OK) { + return CommandingServiceBase::INVALID_TC; + } + //Autodeserialize should have decremented size to 0 by this point + if(tcDataLen != 0) { + return CommandingServiceBase::INVALID_TC; + } + + ParameterMessage::setParameterDumpCommand(message, parameterId); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Service20ParameterManagement::prepareLoadCommand( + CommandMessage* message, const uint8_t* tcData, size_t tcDataLen) { + if(tcDataLen < sizeof(object_id_t) + sizeof(ParameterId_t) + + sizeof(uint32_t)) { + return CommandingServiceBase::INVALID_TC; + } + + uint8_t* storePointer = nullptr; + store_address_t storeAddress; + size_t parameterDataLen = tcDataLen - sizeof(object_id_t) - + sizeof(ParameterId_t) - sizeof(uint32_t); + ReturnValue_t result = IPCStore->getFreeElement(&storeAddress, + parameterDataLen, &storePointer); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + ParameterLoadCommand command(storePointer, parameterDataLen); + result = command.deSerialize(&tcData, &tcDataLen, + SerializeIF::Endianness::BIG); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + ParameterMessage::setParameterLoadCommand(message, + command.getParameterId(), storeAddress, command.getPtc(), + command.getPfc(), command.getRows(), command.getColumns()); + return HasReturnvaluesIF::RETURN_OK; +} + +ReturnValue_t Service20ParameterManagement::handleReply( + const CommandMessage* reply, Command_t previousCommand, uint32_t* state, + CommandMessage* optionalNextCommand, object_id_t objectId, + bool* isStep) { + Command_t replyId = reply->getCommand(); + + switch(replyId) { + case ParameterMessage::REPLY_PARAMETER_DUMP: { + ConstAccessorPair parameterData = IPCStore->getData( + ParameterMessage::getStoreId(reply)); + if(parameterData.first != HasReturnvaluesIF::RETURN_OK) { + return HasReturnvaluesIF::RETURN_FAILED; + } + ParameterId_t parameterId = ParameterMessage::getParameterId(reply); + ParameterDumpReply parameterReply(objectId, parameterId, + parameterData.second.data(), parameterData.second.size()); + sendTmPacket(static_cast( + Subservice::PARAMETER_DUMP_REPLY), ¶meterReply); + return HasReturnvaluesIF::RETURN_OK; + } + default: + return CommandingServiceBase::INVALID_REPLY; + } +} diff --git a/pus/Service20ParameterManagement.h b/pus/Service20ParameterManagement.h new file mode 100644 index 000000000..3e62bc147 --- /dev/null +++ b/pus/Service20ParameterManagement.h @@ -0,0 +1,58 @@ +#ifndef FSFW_PUS_SERVICE20PARAMETERMANAGEMENT_H_ +#define FSFW_PUS_SERVICE20PARAMETERMANAGEMENT_H_ + +#include + +/** + * @brief PUS Service 20 Parameter Service implementation + * @details + * @author J. Gerhards + * + */ +class Service20ParameterManagement : public CommandingServiceBase +{ +public: + Service20ParameterManagement(object_id_t objectId, uint16_t apid, uint8_t serviceId, + uint8_t numberOfParallelCommands = 4, uint16_t commandTimeoutSeconds = 60); + virtual ~Service20ParameterManagement(); + + static constexpr uint8_t NUM_OF_PARALLEL_COMMANDS = 4; + static constexpr uint16_t COMMAND_TIMEOUT_SECONDS = 60; +protected: + /* CommandingServiceBase (CSB) abstract functions. See CSB documentation. */ + ReturnValue_t isValidSubservice(uint8_t subservice) override; + ReturnValue_t getMessageQueueAndObject(uint8_t subservice, + const uint8_t *tcData, size_t tcDataLen, MessageQueueId_t *id, + object_id_t *objectId) override; + ReturnValue_t prepareCommand(CommandMessage* message, uint8_t subservice, + const uint8_t *tcData, size_t tcDataLen, uint32_t *state, + object_id_t objectId) override; + ReturnValue_t handleReply(const CommandMessage* reply, + Command_t previousCommand, uint32_t *state, + CommandMessage* optionalNextCommand, object_id_t objectId, + bool *isStep) override; + +private: + + ReturnValue_t checkAndAcquireTargetID(object_id_t* objectIdToSet, + const uint8_t* tcData, size_t tcDataLen); + ReturnValue_t checkInterfaceAndAcquireMessageQueue( + MessageQueueId_t* messageQueueToSet, object_id_t* objectId); + ReturnValue_t prepareDirectCommand(CommandMessage* message, + const uint8_t* tcData, size_t tcDataLen); + + ReturnValue_t prepareDumpCommand(CommandMessage* message, + const uint8_t* tcData, size_t tcDataLen); + ReturnValue_t prepareLoadCommand(CommandMessage* message, + const uint8_t* tcData, size_t tcDataLen); + + enum class Subservice { + PARAMETER_LOAD = 128, //!< [EXPORT] : Load a Parameter + PARAMETER_DUMP = 129, //!< [EXPORT] : Dump a Parameter + PARAMETER_DUMP_REPLY = 130, //!< [EXPORT] : Dump a Parameter + }; + +}; + + +#endif /* FSFW_PUS_SERVICE20PARAMETERMANAGEMENT_H_ */ diff --git a/pus/servicepackets/Service20Packets.h b/pus/servicepackets/Service20Packets.h new file mode 100644 index 000000000..cf65cdbff --- /dev/null +++ b/pus/servicepackets/Service20Packets.h @@ -0,0 +1,91 @@ +#ifndef FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ +#define FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ + +#include +#include +#include +#include + +/** + * @brief + * @details + * @author + */ +class ParameterCommand: public SerialLinkedListAdapter { //!< [EXPORT] : [SUBSERVICE] 128, 129, 130 +public: + ParameterCommand(uint8_t* storePointer, size_t parameterDataLen): + parameterBuffer(storePointer, parameterDataLen) { + setLinks(); + } + + ParameterCommand(object_id_t objectId, ParameterId_t parameterId, + const uint8_t* parameterBuffer, size_t parameterBufferSize): + objectId(objectId), parameterId(parameterId), + parameterBuffer(parameterBuffer, parameterBufferSize) { + setLinks(); + } + + ParameterId_t getParameterId() const { + return parameterId.entry; + } + + const uint8_t* getParameterBuffer() { + return parameterBuffer.entry.getConstBuffer(); + } + + size_t getParameterBufferLen() const { + return parameterBuffer.getSerializedSize(); + } + + uint8_t getPtc() const { + return ccsdsType.entry >> 8 & 0xff; + } + + uint8_t getPfc() const { + return ccsdsType.entry & 0xff; + } + + uint8_t getRows() const { + return rows.entry; + } + + uint8_t getColumns() const { + return columns.entry; + } + +private: + void setLinks() { + setStart(&objectId); + objectId.setNext(¶meterId); + parameterId.setNext(&ccsdsType); + ccsdsType.setNext(&rows); + rows.setNext(&columns); + columns.setNext(¶meterBuffer); + } + + SerializeElement objectId = 0; + SerializeElement parameterId = 0; + //! [EXPORT] : [COMMENT] Type consisting of one byte PTC and one byte PFC. + SerializeElement ccsdsType = 0; + SerializeElement columns = 0; + SerializeElement rows = 0; + SerializeElement> parameterBuffer; +}; + +class ParameterLoadCommand: public ParameterCommand { +public: + ParameterLoadCommand(uint8_t* parameterPacket, size_t parameterDataLen): + ParameterCommand(parameterPacket, parameterDataLen) { + } +}; + +class ParameterDumpReply: public ParameterCommand { +public: + ParameterDumpReply(object_id_t objectId, ParameterId_t parameterId, + const uint8_t* parameterBuffer, size_t parameterBufferSize): + ParameterCommand(objectId, parameterId, parameterBuffer, + parameterBufferSize) { + } +}; + +#endif /* FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ */ -- 2.34.1 From 503de9ba898e2070d1d29a3334ed61623d428c55 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 31 Jan 2021 00:27:47 +0100 Subject: [PATCH 10/14] IMPORTant bugfix --- parameters/ParameterMessage.cpp | 2 +- pus/Service20ParameterManagement.cpp | 15 ++++++--------- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/parameters/ParameterMessage.cpp b/parameters/ParameterMessage.cpp index af1f9ce83..88a45c808 100644 --- a/parameters/ParameterMessage.cpp +++ b/parameters/ParameterMessage.cpp @@ -38,7 +38,7 @@ void ParameterMessage::setParameterLoadCommand(CommandMessage* message, store_address_t ParameterMessage::getParameterLoadCommand( const CommandMessage *message, ParameterId_t* parameterId, uint8_t *ptc, uint8_t *pfc, uint8_t *rows, uint8_t *columns) { - *parameterId = message->getParameter2(); + *parameterId = message->getParameter(); uint32_t packedParamSettings = message->getParameter3(); *ptc = packedParamSettings >> 24 & 0xff; *pfc = packedParamSettings >> 16 & 0xff; diff --git a/pus/Service20ParameterManagement.cpp b/pus/Service20ParameterManagement.cpp index 3b04bd4e0..302b69b72 100644 --- a/pus/Service20ParameterManagement.cpp +++ b/pus/Service20ParameterManagement.cpp @@ -70,10 +70,8 @@ ReturnValue_t Service20ParameterManagement::checkInterfaceAndAcquireMessageQueue #if FSFW_CPP_OSTREAM_ENABLED == 1 sif::error << "Service20ParameterManagement::checkInterfaceAndAcquire" <<"MessageQueue: Can't access object" << std::endl; - sif::error << "Object ID: " << std::hex << objectId << std::dec - << std::endl; - sif::error << "Make sure it implements ReceivesParameterMessagesIF!" - << std::endl; + sif::error << "Object ID: " << std::hex << objectId << std::dec << std::endl; + sif::error << "Make sure it implements ReceivesParameterMessagesIF!" << std::endl; #else sif::printError("Service20ParameterManagement::checkInterfaceAndAcquire" "MessageQueue: Can't access object\n"); @@ -134,8 +132,8 @@ ReturnValue_t Service20ParameterManagement::prepareLoadCommand( uint8_t* storePointer = nullptr; store_address_t storeAddress; - size_t parameterDataLen = tcDataLen - sizeof(object_id_t) - - sizeof(ParameterId_t) - sizeof(uint32_t); + size_t parameterDataLen = tcDataLen - sizeof(object_id_t) - sizeof(ParameterId_t) - + sizeof(uint32_t); ReturnValue_t result = IPCStore->getFreeElement(&storeAddress, parameterDataLen, &storePointer); if(result != HasReturnvaluesIF::RETURN_OK) { @@ -149,9 +147,8 @@ ReturnValue_t Service20ParameterManagement::prepareLoadCommand( return result; } - ParameterMessage::setParameterLoadCommand(message, - command.getParameterId(), storeAddress, command.getPtc(), - command.getPfc(), command.getRows(), command.getColumns()); + ParameterMessage::setParameterLoadCommand(message, command.getParameterId(), storeAddress, + command.getPtc(), command.getPfc(), command.getRows(), command.getColumns()); return HasReturnvaluesIF::RETURN_OK; } -- 2.34.1 From f067695353b77ccde7e33f17f0687df6838ce519 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 31 Jan 2021 17:40:20 +0100 Subject: [PATCH 11/14] printout, doc, bugfixes.. --- parameters/ParameterWrapper.cpp | 36 ++++++++++++++++++++++++---- parameters/ParameterWrapper.h | 36 +++++++++++++++++++++++----- pus/Service20ParameterManagement.cpp | 13 +++++++--- pus/Service20ParameterManagement.h | 2 ++ 4 files changed, 74 insertions(+), 13 deletions(-) diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index d9f1ef685..124f2eda6 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -1,4 +1,6 @@ #include "ParameterWrapper.h" +#include +#include ParameterWrapper::ParameterWrapper() : pointsToStream(false), type(Type::UNKNOWN_TYPE) { @@ -75,7 +77,7 @@ ReturnValue_t ParameterWrapper::serialize(uint8_t **buffer, size_t *size, result = serializeData(buffer, size, maxSize, streamEndianness); break; default: - result = UNKNOW_DATATYPE; + result = UNKNOWN_DATATYPE; break; } return result; @@ -220,22 +222,48 @@ ReturnValue_t ParameterWrapper::set(const uint8_t *stream, size_t streamSize, ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from, uint16_t startWritingAtIndex) { - // TODO: Optional diagnostic output (which can be disabled in FSFWConfig) - // to determined faulty implementations and configuration errors quickly. if (data == nullptr) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "ParameterWrapper::copyFrom: Called on read-only variable!" << std::endl; +#else + sif::printWarning("ParameterWrapper::copyFrom: Called on read-only variable!\n"); +#endif +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ return READONLY; } if (from->readonlyData == nullptr) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "ParameterWrapper::copyFrom: Source not set!" << std::endl; +#else + sif::printWarning("ParameterWrapper::copyFrom: Source not set!\n"); +#endif +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ return SOURCE_NOT_SET; } if (type != from->type) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "ParameterWrapper::copyFrom: Datatype missmatch!" << std::endl; +#else + sif::printWarning("ParameterWrapper::copyFrom: Datatype missmatch!\n"); +#endif +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ return DATATYPE_MISSMATCH; } // The smallest allowed value for rows and columns is one. if(rows == 0 or columns == 0) { +#if FSFW_VERBOSE_LEVEL >= 1 +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "ParameterWrapper::copyFrom: Columns or rows zero!" << std::endl; +#else + sif::printWarning("ParameterWrapper::copyFrom: Columns or rows zero!\n"); +#endif +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ return COLUMN_OR_ROWS_ZERO; } @@ -289,7 +317,7 @@ ReturnValue_t ParameterWrapper::copyFrom(const ParameterWrapper *from, from->readonlyData, from->rows, from->columns); break; default: - result = UNKNOW_DATATYPE; + result = UNKNOWN_DATATYPE; break; } } diff --git a/parameters/ParameterWrapper.h b/parameters/ParameterWrapper.h index 168a535f2..b0ca210d0 100644 --- a/parameters/ParameterWrapper.h +++ b/parameters/ParameterWrapper.h @@ -8,14 +8,23 @@ #include /** - * @brief + * @brief This wrapper encapsulates the access to parameters provided by HasParametersIF. * @details + * This wrapper is used by the ParameterHelper to interface with the on-board parameters + * exposed by the software via the HasParametersIF. A handle of this wrapper is passed + * to the user which then can be used to set or dump the parameters. + * + * The wrapper provides a set of setter functions. The user should call those setter functions, + * supplying an address to the local parameters. The user can also deserialize or + * serialize the parameter data. Please note that this will also serialize and deserialize + * the parameter information field (4 bytes) containing the ECSS PTC, PFC and rows and columns + * number. */ class ParameterWrapper: public SerializeIF { friend class DataPoolParameterWrapper; public: static const uint8_t INTERFACE_ID = CLASS_ID::PARAMETER_WRAPPER; - static const ReturnValue_t UNKNOW_DATATYPE = MAKE_RETURN_CODE(0x01); + static const ReturnValue_t UNKNOWN_DATATYPE = MAKE_RETURN_CODE(0x01); static const ReturnValue_t DATATYPE_MISSMATCH = MAKE_RETURN_CODE(0x02); static const ReturnValue_t READONLY = MAKE_RETURN_CODE(0x03); static const ReturnValue_t TOO_BIG = MAKE_RETURN_CODE(0x04); @@ -26,8 +35,7 @@ public: ParameterWrapper(); ParameterWrapper(Type type, uint8_t rows, uint8_t columns, void *data); - ParameterWrapper(Type type, uint8_t rows, uint8_t columns, - const void *data); + ParameterWrapper(Type type, uint8_t rows, uint8_t columns, const void *data); virtual ~ParameterWrapper(); virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, @@ -77,11 +85,23 @@ public: this->pointsToStream = false; } + /** + * Setter function for scalar non-const entries + * @tparam T + * @param member + */ template void set(T& member) { this->set(&member, 1, 1); } + /** + * Setter function for scalar const entries. + * TODO: This is confusing, it should not be called set. Maybe we should call all functions + * assign instead? + * @tparam T + * @param readonlyMember + */ template void set(const T& readonlyMember) { this->set(&readonlyMember, 1, 1); @@ -89,12 +109,16 @@ public: template void setVector(T& member) { - this->set(member, sizeof(member)/sizeof(member[0]), 1); + /* For a vector entry, the number of rows will be one + (left to right, top to bottom indexing) */ + this->set(member, 1, sizeof(member) / sizeof(member[0])); } template void setVector(const T& member) { - this->set(member, 1, sizeof(member)/sizeof(member[0])); + /* For a vector entry, the number of rows will be one + (left to right, top to bottom indexing) */ + this->set(member, 1, sizeof(member) / sizeof(member[0])); } template void setMatrix(T& member) { diff --git a/pus/Service20ParameterManagement.cpp b/pus/Service20ParameterManagement.cpp index 302b69b72..2d69f77a9 100644 --- a/pus/Service20ParameterManagement.cpp +++ b/pus/Service20ParameterManagement.cpp @@ -105,8 +105,8 @@ ReturnValue_t Service20ParameterManagement::prepareCommand( ReturnValue_t Service20ParameterManagement::prepareDumpCommand( CommandMessage* message, const uint8_t* tcData, size_t tcDataLen) { - //the first part is the objectId, but we have extracted that earlier - //and only need the parameterId + /* the first part is the objectId, but we have extracted that earlier + and only need the parameterId */ tcData += sizeof(object_id_t); tcDataLen -= sizeof(object_id_t); ParameterId_t parameterId; @@ -114,7 +114,7 @@ ReturnValue_t Service20ParameterManagement::prepareDumpCommand( SerializeIF::Endianness::BIG) != HasReturnvaluesIF::RETURN_OK) { return CommandingServiceBase::INVALID_TC; } - //Autodeserialize should have decremented size to 0 by this point + /* The length should have been decremented to 0 by this point */ if(tcDataLen != 0) { return CommandingServiceBase::INVALID_TC; } @@ -140,6 +140,13 @@ ReturnValue_t Service20ParameterManagement::prepareLoadCommand( return result; } + /* Following format is expected: The first 4 bytes in the TC data are the 4 byte + parameter ID (ParameterId_t). The second 4 bytes are the parameter information field, + containing the following 1 byte fields: + 1. ECSS PTC field + 2. ECSS PFC field + 3. Number of rows + 4. Number of columns */ ParameterLoadCommand command(storePointer, parameterDataLen); result = command.deSerialize(&tcData, &tcDataLen, SerializeIF::Endianness::BIG); diff --git a/pus/Service20ParameterManagement.h b/pus/Service20ParameterManagement.h index 3e62bc147..488edfb5c 100644 --- a/pus/Service20ParameterManagement.h +++ b/pus/Service20ParameterManagement.h @@ -6,6 +6,8 @@ /** * @brief PUS Service 20 Parameter Service implementation * @details + * This service handles PUS service requests related to parameter management and forwards + * them to the internal software bus. * @author J. Gerhards * */ -- 2.34.1 From 8b90360b453aa0e7791654b64890eb78d262a09a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 31 Jan 2021 18:27:21 +0100 Subject: [PATCH 12/14] changed order --- pus/servicepackets/Service20Packets.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pus/servicepackets/Service20Packets.h b/pus/servicepackets/Service20Packets.h index cf65cdbff..4a7c24f0c 100644 --- a/pus/servicepackets/Service20Packets.h +++ b/pus/servicepackets/Service20Packets.h @@ -67,8 +67,8 @@ private: SerializeElement parameterId = 0; //! [EXPORT] : [COMMENT] Type consisting of one byte PTC and one byte PFC. SerializeElement ccsdsType = 0; - SerializeElement columns = 0; SerializeElement rows = 0; + SerializeElement columns = 0; SerializeElement> parameterBuffer; }; -- 2.34.1 From 4522668066c7b402a7fcd1e76923b6c322647f3d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 31 Jan 2021 19:13:40 +0100 Subject: [PATCH 13/14] some form stuff --- pus/servicepackets/Service20Packets.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/pus/servicepackets/Service20Packets.h b/pus/servicepackets/Service20Packets.h index 4a7c24f0c..d108dba44 100644 --- a/pus/servicepackets/Service20Packets.h +++ b/pus/servicepackets/Service20Packets.h @@ -75,17 +75,14 @@ private: class ParameterLoadCommand: public ParameterCommand { public: ParameterLoadCommand(uint8_t* parameterPacket, size_t parameterDataLen): - ParameterCommand(parameterPacket, parameterDataLen) { - } + ParameterCommand(parameterPacket, parameterDataLen) {} }; class ParameterDumpReply: public ParameterCommand { public: ParameterDumpReply(object_id_t objectId, ParameterId_t parameterId, const uint8_t* parameterBuffer, size_t parameterBufferSize): - ParameterCommand(objectId, parameterId, parameterBuffer, - parameterBufferSize) { - } + ParameterCommand(objectId, parameterId, parameterBuffer, parameterBufferSize) {} }; #endif /* FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ */ -- 2.34.1 From 5ac3762dc51752ba4538817d8ddd87dc50766ec7 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 31 Jan 2021 20:53:25 +0100 Subject: [PATCH 14/14] srv20 improvements and bugfixes --- parameters/ParameterHelper.cpp | 2 +- parameters/ParameterWrapper.cpp | 8 ++-- pus/Service20ParameterManagement.cpp | 1 + pus/servicepackets/Service20Packets.h | 62 +++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 9 deletions(-) diff --git a/parameters/ParameterHelper.cpp b/parameters/ParameterHelper.cpp index 4ad5cdf25..24d0b2b1f 100644 --- a/parameters/ParameterHelper.cpp +++ b/parameters/ParameterHelper.cpp @@ -90,7 +90,7 @@ ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id, const ParameterWrapper* description) { size_t serializedSize = description->getSerializedSize(); - uint8_t *storeElement; + uint8_t *storeElement = nullptr; store_address_t address; ReturnValue_t result = storage->getFreeElement(&address, serializedSize, diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index 124f2eda6..660d7db71 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -7,13 +7,13 @@ ParameterWrapper::ParameterWrapper() : } ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns, - void *data) : + void *data): pointsToStream(false), type(type), rows(rows), columns(columns), data(data), readonlyData(data) { } ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns, - const void *data) : + const void *data): pointsToStream(false), type(type), rows(rows), columns(columns), data(nullptr), readonlyData(data) { } @@ -42,8 +42,8 @@ ReturnValue_t ParameterWrapper::serialize(uint8_t **buffer, size_t *size, return result; } - //serialize uses readonlyData, as it is always valid - if (readonlyData == NULL) { + /* serialize uses readonlyData, as it is always valid */ + if (readonlyData == nullptr) { return NOT_SET; } switch (type) { diff --git a/pus/Service20ParameterManagement.cpp b/pus/Service20ParameterManagement.cpp index 2d69f77a9..bc3a9119b 100644 --- a/pus/Service20ParameterManagement.cpp +++ b/pus/Service20ParameterManagement.cpp @@ -172,6 +172,7 @@ ReturnValue_t Service20ParameterManagement::handleReply( if(parameterData.first != HasReturnvaluesIF::RETURN_OK) { return HasReturnvaluesIF::RETURN_FAILED; } + ParameterId_t parameterId = ParameterMessage::getParameterId(reply); ParameterDumpReply parameterReply(objectId, parameterId, parameterData.second.data(), parameterData.second.size()); diff --git a/pus/servicepackets/Service20Packets.h b/pus/servicepackets/Service20Packets.h index d108dba44..33bd153dd 100644 --- a/pus/servicepackets/Service20Packets.h +++ b/pus/servicepackets/Service20Packets.h @@ -1,28 +1,57 @@ #ifndef FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ #define FSFW_PUS_SERVICEPACKETS_SERVICE20PACKETS_H_ +#include #include #include #include #include +#include /** - * @brief + * @brief This class encapsulates the packets sent to the PUS service 20 or sent by the + * PUS service 20 * @details + * This command can be used to handle both load and dump commands as well. * @author */ class ParameterCommand: public SerialLinkedListAdapter { //!< [EXPORT] : [SUBSERVICE] 128, 129, 130 public: + + /** + * This constructor is used for load replies. The data is expected in the correct formast + * in the store pointer. + * @param storePointer + * @param parameterDataLen + */ ParameterCommand(uint8_t* storePointer, size_t parameterDataLen): parameterBuffer(storePointer, parameterDataLen) { - setLinks(); +#if FSFW_VERBOSE_LEVEL >= 1 + if(parameterDataLen < sizeof(object_id_t) + sizeof(ParameterId_t) + 4) { +#if FSFW_CPP_OSTREAM_ENABLED == 1 + sif::warning << "ParameterCommand: Parameter data length is less than 12!" + << std::endl; +#else + sif::printWarning("ParameterCommand: Parameter data length is less than 12!\n"); +#endif + } +#endif /* FSFW_VERBOSE_LEVEL >= 1 */ + setLoadLinks(); } + /** + * This constructor is used for dump replies. It is assumed the 4 byte parameter + * information field is located inside the parameter buffer. + * @param objectId + * @param parameterId + * @param parameterBuffer + * @param parameterBufferSize + */ ParameterCommand(object_id_t objectId, ParameterId_t parameterId, const uint8_t* parameterBuffer, size_t parameterBufferSize): objectId(objectId), parameterId(parameterId), parameterBuffer(parameterBuffer, parameterBufferSize) { - setLinks(); + setDumpReplyLinks(); } ParameterId_t getParameterId() const { @@ -37,6 +66,18 @@ public: return parameterBuffer.getSerializedSize(); } + uint8_t getDomainId() const { + return (parameterId.entry >> 24) & 0xff; + } + + uint8_t getUniqueId() const { + return (parameterId.entry >> 16) & 0xff; + } + + uint16_t getLinearIndex() const { + return parameterId.entry & 0xffff; + } + uint8_t getPtc() const { return ccsdsType.entry >> 8 & 0xff; } @@ -54,7 +95,7 @@ public: } private: - void setLinks() { + void setLoadLinks() { setStart(&objectId); objectId.setNext(¶meterId); parameterId.setNext(&ccsdsType); @@ -63,6 +104,19 @@ private: columns.setNext(¶meterBuffer); } + void setDumpReplyLinks() { + /* For a dump reply, the parameter information is contained in the parameter buffer + with the actual parameters */ + setStart(&objectId); + objectId.setNext(¶meterId); + parameterId.setNext(¶meterBuffer); + } + + void setDumpRequestLinks() { + setStart(&objectId); + objectId.setNext(¶meterId); + } + SerializeElement objectId = 0; SerializeElement parameterId = 0; //! [EXPORT] : [COMMENT] Type consisting of one byte PTC and one byte PFC. -- 2.34.1