From 743d8abeaffe55cefbddbd2b264be4adcac4d19c Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 17 Oct 2019 00:23:46 +0200 Subject: [PATCH 0001/1774] first attempt to document and explain serialization tools for application developers --- serialize/SerialLinkedListAdapter.h | 16 +++++++++++++++- serialize/SerializeAdapter.h | 14 +++++++++++++- serialize/SerializeIF.h | 2 +- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index 29952c4a3..44d9e15bc 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -13,7 +13,21 @@ #include //This is where we need the SerializeAdapter! -/** + /** + * An alternative to the AutoSerializeAdapter functions to implement the conversion + * of object data to data streams or vice-versa, using linked lists. + * + * All object members with a datatype are declared as SerializeElement inside the class. + * + * Buffers with a size header inside that class can be declared with + * SerialFixedArrayListAdapter. + * typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows + * and MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. + * The sequence of objects is defined in the constructor by using the setStart and setNext functions. + * + * The serialization and deserialization process is done by instantiating the class and + * calling the serialize or deserialize function. + * * \ingroup serialize */ template diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index fd9e1b6af..67c37493a 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -7,7 +7,19 @@ #include #include -/** + /** + * This adapter provides an interface to use the SerializeIF functions + * with arbitrary template objects to facilitate and simplify the serialization of classes + * with different multiple different data types into buffers vice-versa. + * + * Examples: + * A report class is converted into a TM buffer. The report class implements a serialize functions and calls + * the AutoSerializeAdapter::serialize function repeatedly on all object data fields. + * The getSerializedSize function is implemented by calling the + * AutoSerializeAdapter::getSerializedSize function repeatedly on all data fields. + * + * The AutoSerializeAdapter functions can also be used as an alternative to memcpy + * to retrieve data out of a buffer directly into a class variable with data type T while being able to specify endianness. * \ingroup serialize */ template diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index 701fbf563..50555d379 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -9,7 +9,7 @@ */ /** - * Translation of objects into data streams. + * An interface for alle classes which require translation of objects data into data streams and vice-versa. * \ingroup serialize */ class SerializeIF { From 5e3b7c36257314bab40b36c78c13c0525b08eb86 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 18 Oct 2019 13:37:09 +0200 Subject: [PATCH 0002/1774] explanation of cookie purpose added, device handler base indentation --- devicehandlers/Cookie.h | 3 +++ devicehandlers/DeviceHandlerBase.cpp | 27 +++++++++++++-------------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/devicehandlers/Cookie.h b/devicehandlers/Cookie.h index 495c8c403..618c901ff 100644 --- a/devicehandlers/Cookie.h +++ b/devicehandlers/Cookie.h @@ -1,6 +1,9 @@ #ifndef COOKIE_H_ #define COOKIE_H_ +/** + * This datatype is used to identify different connection over a single interface (like RMAP or I2C) + */ class Cookie{ public: virtual ~Cookie(){} diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index ae9199f2c..750d4d4ad 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -21,20 +21,19 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t ioBoardAddress, uint8_t setDeviceSwitch, object_id_t deviceCommunication, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : - SystemObject(setObjectId), rawPacket(0), rawPacketLen(0), mode( - MODE_OFF), submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen( - maxDeviceReplyLen), wiretappingMode(OFF), defaultRawReceiver(0), storedRawData( - StorageManagerIF::INVALID_ADDRESS), requestedRawTraffic(0), powerSwitcher( - NULL), IPCStore(NULL), deviceCommunicationId(deviceCommunication), communicationInterface( - NULL), cookie( - NULL), commandQueue(NULL), deviceThermalStatePoolId(thermalStatePoolId), deviceThermalRequestPoolId( - thermalRequestPoolId), healthHelper(this, setObjectId), modeHelper( - this), parameterHelper(this), childTransitionFailure(RETURN_OK), ignoreMissedRepliesCount( - 0), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed( - fdirInstance == NULL), switchOffWasReported(false),executingTask(NULL), actionHelper(this, NULL), cookieInfo(), ioBoardAddress( - ioBoardAddress), timeoutStart(0), childTransitionDelay(5000), transitionSourceMode( - _MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), deviceSwitch( - setDeviceSwitch) { + SystemObject(setObjectId), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), + submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen(maxDeviceReplyLen), + wiretappingMode(OFF), defaultRawReceiver(0), storedRawData(StorageManagerIF::INVALID_ADDRESS), + requestedRawTraffic(0), powerSwitcher(NULL), IPCStore(NULL), + deviceCommunicationId(deviceCommunication), communicationInterface(NULL), + cookie(NULL), commandQueue(NULL), deviceThermalStatePoolId(thermalStatePoolId), + deviceThermalRequestPoolId(thermalRequestPoolId), healthHelper(this, setObjectId), + modeHelper(this), parameterHelper(this), childTransitionFailure(RETURN_OK), + ignoreMissedRepliesCount(0), fdirInstance(fdirInstance), hkSwitcher(this), + defaultFDIRUsed(fdirInstance == NULL), switchOffWasReported(false), + executingTask(NULL), actionHelper(this, NULL), cookieInfo(), ioBoardAddress(ioBoardAddress), + timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), + transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); cookieInfo.state = COOKIE_UNUSED; From 907664cea9958f1259ed19560839c26533481cf7 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 21 Oct 2019 11:38:13 +0200 Subject: [PATCH 0003/1774] added do performOperation where the comIF functions are called, some comments added in DeviceHandlerIF --- devicehandlers/DeviceHandlerBase.h | 18 +++++++++++------- devicehandlers/DeviceHandlerIF.h | 7 ++++++- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 756ad530d..70fefe8aa 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -33,6 +33,7 @@ class StorageManagerIF; * Contains all devices and the DeviceHandlerBase class. */ +// Robin: We're not really using RMAP, right? Maybe we should adapt class description for that? /** * \brief This is the abstract base class for device handlers. * @@ -81,7 +82,7 @@ public: /** - * This function is a core component and is called periodically. + * This function is the device handler base core component and is called periodically. * General sequence: * If the State is SEND_WRITE: * 1. Set the cookie state to COOKIE_UNUSED and read the command queue @@ -95,13 +96,16 @@ public: * 7. If the device mode is MODE_OFF, return RETURN_OK. Otherwise, perform the Action property * and performs depending on value specified * by input value counter. The child class tells base class what to do by setting this value. - * - SEND_WRITE: Send data or commands to device by calling doSendWrite() - * Calls abstract funtions buildNomalDeviceCommand() - * or buildTransitionDeviceCommand() - * - GET_WRITE: Get ackknowledgement for sending by calling doGetWrite(). + * - SEND_WRITE: Send data or commands to device by calling doSendWrite() which calls + * sendMessage function of #communicationInterface + * and calls buildInternalCommand if the cookie state is COOKIE_UNUSED + * - GET_WRITE: Get ackknowledgement for sending by calling doGetWrite() which calls + * getSendSuccess of #communicationInterface. * Calls abstract functions scanForReply() and interpretDeviceReply(). - * - SEND_READ: Request reading data from device by calling doSendRead() - * - GET_READ: Access requested reading data by calling doGetRead() + * - SEND_READ: Request reading data from device by calling doSendRead() which calls + * requestReceiveMessage of #communcationInterface + * - GET_READ: Access requested reading data by calling doGetRead() which calls + * readReceivedMessage of #communicationInterface * @param counter Specifies which Action to perform * @return RETURN_OK for successful execution */ diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index fe0ee8e8b..8fdd04fe9 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -23,6 +23,11 @@ public: * @details The mode of the device handler must not be confused with the mode the device is in. * The mode of the device itself is transparent to the user but related to the mode of the handler. */ + // Robin: The first two modes (MODE_ON, MODE_OFF) are specified in hasModesIF. + // We could mention in a comment where those modes are located. + // The comments for _MODE_TO_ON have been taken from the comments in DeviceHandlerBase.cpp file. + // Is the same explanation valid for _MODE_TO_RAW and MODE_TO_NORMAL? + // MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted // MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on. static const Mode_t MODE_NORMAL = 2; //!< The device is powered on and the device handler periodically sends commands. The commands to be sent are selected by the handler according to the submode. @@ -30,7 +35,7 @@ public: static const Mode_t MODE_ERROR_ON = 4; //!4< The device is shut down but the switch could not be turned off, so the device still is powered. In this mode, only a mode change to @c MODE_OFF can be commanded, which tries to switch off the device again. static const Mode_t _MODE_START_UP = TRANSITION_MODE_CHILD_ACTION_MASK | 5; //!< This is a transitional state which can not be commanded. The device handler performs all commands to get the device in a state ready to perform commands. When this is completed, the mode changes to @c MODE_ON. static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6; //!< This is a transitional state which can not be commanded. The device handler performs all actions and commands to get the device shut down. When the device is off, the mode changes to @c MODE_OFF. - static const Mode_t _MODE_TO_ON = TRANSITION_MODE_CHILD_ACTION_MASK | HasModesIF::MODE_ON; + static const Mode_t _MODE_TO_ON = TRANSITION_MODE_CHILD_ACTION_MASK | HasModesIF::MODE_ON; //!< It is possible to set the mode to _MODE_TO_ON to use the to on transition if available. static const Mode_t _MODE_TO_RAW = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_RAW; static const Mode_t _MODE_TO_NORMAL = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_NORMAL; static const Mode_t _MODE_POWER_DOWN = TRANSITION_MODE_BASE_ACTION_MASK | 1; //!< This is a transitional state which can not be commanded. The device is shut down and ready to be switched off. After the command to set the switch off has been sent, the mode changes to @c MODE_WAIT_OFF From cbc8012198da6e94870f2b5fe63b799587092bc8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 22 Oct 2019 00:06:11 +0200 Subject: [PATCH 0004/1774] ioBoardAddress protected instead of private to allow custom initialize --- devicehandlers/DeviceHandlerBase.cpp | 4 ++-- devicehandlers/DeviceHandlerBase.h | 14 ++++++++++---- devicehandlers/DeviceHandlerIF.h | 6 ++---- health/HealthHelper.h | 2 +- osal/FreeRTOS/FixedTimeslotTask.cpp | 3 +-- 5 files changed, 16 insertions(+), 13 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 750d4d4ad..bc87422d8 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -21,7 +21,7 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t ioBoardAddress, uint8_t setDeviceSwitch, object_id_t deviceCommunication, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : - SystemObject(setObjectId), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), + SystemObject(setObjectId),ioBoardAddress(ioBoardAddress), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen(maxDeviceReplyLen), wiretappingMode(OFF), defaultRawReceiver(0), storedRawData(StorageManagerIF::INVALID_ADDRESS), requestedRawTraffic(0), powerSwitcher(NULL), IPCStore(NULL), @@ -31,7 +31,7 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t ioBoardAddress, modeHelper(this), parameterHelper(this), childTransitionFailure(RETURN_OK), ignoreMissedRepliesCount(0), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed(fdirInstance == NULL), switchOffWasReported(false), - executingTask(NULL), actionHelper(this, NULL), cookieInfo(), ioBoardAddress(ioBoardAddress), + executingTask(NULL), actionHelper(this, NULL), cookieInfo(), timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 70fefe8aa..45a87a8aa 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -141,6 +141,11 @@ public: */ virtual void setTaskIF(PeriodicTaskIF* task_); protected: + /** + * cached from ctor for initialize() + */ + const uint32_t ioBoardAddress; + /** * The Returnvalues id of this class, required by HasReturnvaluesIF */ @@ -163,6 +168,8 @@ protected: static const DeviceCommandId_t NO_COMMAND_ID = -2; static const MessageQueueId_t NO_COMMANDER = 0; + + /** * Pointer to the raw packet that will be sent. */ @@ -833,6 +840,9 @@ protected: DeviceCommandMap deviceCommandMap; ActionHelper actionHelper; + + + private: /** @@ -865,10 +875,6 @@ private: */ CookieInfo cookieInfo; - /** - * cached from ctor for initialize() - */ - const uint32_t ioBoardAddress; /** * Used for timing out mode transitions. diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index 8fdd04fe9..bfa7c7b24 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -22,11 +22,9 @@ public: * * @details The mode of the device handler must not be confused with the mode the device is in. * The mode of the device itself is transparent to the user but related to the mode of the handler. + * MODE_ON and MODE_OFF are included in hasModesIF.h */ - // Robin: The first two modes (MODE_ON, MODE_OFF) are specified in hasModesIF. - // We could mention in a comment where those modes are located. - // The comments for _MODE_TO_ON have been taken from the comments in DeviceHandlerBase.cpp file. - // Is the same explanation valid for _MODE_TO_RAW and MODE_TO_NORMAL? + // MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted // MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on. diff --git a/health/HealthHelper.h b/health/HealthHelper.h index a1ca2c525..24fd0d14a 100644 --- a/health/HealthHelper.h +++ b/health/HealthHelper.h @@ -27,8 +27,8 @@ public: /** * ctor * + * @param owner * @param objectId the object Id to use when communication with the HealthTable - * @param useAsFrom id to use as from id when sending replies, can be set to 0 */ HealthHelper(HasHealthIF* owner, object_id_t objectId); diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 00fd73d35..5bf09f136 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -19,8 +19,7 @@ FixedTimeslotTask::~FixedTimeslotTask() { void FixedTimeslotTask::taskEntryPoint(void* argument) { //The argument is re-interpreted as FixedTimeslotTask. The Task object is global, so it is found from any place. - FixedTimeslotTask *originalTask( - reinterpret_cast(argument)); + FixedTimeslotTask *originalTask(reinterpret_cast(argument)); // Task should not start until explicitly requested // in FreeRTOS, tasks start as soon as they are created if the scheduler is running // but not if the scheduler is not running. From 4db655e4898de934f6388365ec036d9d6e6b1bbe Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 22 Oct 2019 14:01:17 +0200 Subject: [PATCH 0005/1774] task priority order comment --- osal/FreeRTOS/TaskFactory.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/osal/FreeRTOS/TaskFactory.cpp b/osal/FreeRTOS/TaskFactory.cpp index 7b2f70a3a..753da60f7 100644 --- a/osal/FreeRTOS/TaskFactory.cpp +++ b/osal/FreeRTOS/TaskFactory.cpp @@ -15,6 +15,7 @@ TaskFactory* TaskFactory::instance() { } /*** * Keep in Mind that you need to call before this vTaskStartScheduler()! + * High taskPriority_ number means high priority. */ PeriodicTaskIF* TaskFactory::createPeriodicTask(TaskName name_, TaskPriority taskPriority_, TaskStackSize stackSize_, From c6e34cada64f59757e420347dec8373401d73c7a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 22 Oct 2019 17:15:29 +0200 Subject: [PATCH 0006/1774] documentation for DHB init function, ioBoard addres has default value 0 now, order in ctor changed (not used in source) --- devicehandlers/ChildHandlerBase.cpp | 4 ++-- devicehandlers/DeviceHandlerBase.cpp | 9 ++++----- devicehandlers/DeviceHandlerBase.h | 21 ++++++++++++++++++--- 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/devicehandlers/ChildHandlerBase.cpp b/devicehandlers/ChildHandlerBase.cpp index 50a5c07e5..fb9238f7e 100644 --- a/devicehandlers/ChildHandlerBase.cpp +++ b/devicehandlers/ChildHandlerBase.cpp @@ -7,8 +7,8 @@ ChildHandlerBase::ChildHandlerBase(uint32_t ioBoardAddress, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t parent, FailureIsolationBase* customFdir, uint32_t cmdQueueSize) : - DeviceHandlerBase(ioBoardAddress, setObjectId, maxDeviceReplyLen, - setDeviceSwitch, deviceCommunication, thermalStatePoolId, + DeviceHandlerBase(setObjectId, maxDeviceReplyLen, + setDeviceSwitch, deviceCommunication,ioBoardAddress, thermalStatePoolId, thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir), cmdQueueSize), parentId( parent), childHandlerFdir(setObjectId) { } diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index bc87422d8..d0f9d8b24 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -16,11 +16,10 @@ object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; -DeviceHandlerBase::DeviceHandlerBase(uint32_t ioBoardAddress, - object_id_t setObjectId, uint32_t maxDeviceReplyLen, - uint8_t setDeviceSwitch, object_id_t deviceCommunication, - uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, - FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : +DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, + uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, + object_id_t deviceCommunication, uint32_t ioBoardAddress, uint32_t thermalStatePoolId, + uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : SystemObject(setObjectId),ioBoardAddress(ioBoardAddress), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen(maxDeviceReplyLen), wiretappingMode(OFF), defaultRawReceiver(0), storedRawData(StorageManagerIF::INVALID_ADDRESS), diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 45a87a8aa..2278e1f5d 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -71,10 +71,10 @@ public: * @param maxDeviceReplyLen the length the RMAP getRead call will be sent with * @param setDeviceSwitch the switch the device is connected to, for devices using two switches, overwrite getSwitches() */ - DeviceHandlerBase(uint32_t ioBoardAddress, object_id_t setObjectId, + DeviceHandlerBase(object_id_t setObjectId, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, - object_id_t deviceCommunication, uint32_t thermalStatePoolId = - PoolVariableIF::NO_PARAMETER, + object_id_t deviceCommunication,uint32_t ioBoardAddress = 0, + uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, FailureIsolationBase* fdirInstance = NULL, uint32_t cmdQueueSize = 20); @@ -111,6 +111,21 @@ public: */ virtual ReturnValue_t performOperation(uint8_t counter); + /** + * Prerequisites to call initialize function without custom implementation: + * 1. The three static framework IDs are set to respective objects in the Factory function + * - First ID: Power Switcher ID. Example: PCDU Handler Object + * - Second ID: Raw Data Receiver. Example: PUS Service 2 Object + * - Third ID: Default FDIR parent ID. Example: ? + * 2. Communication Interface Object for respective device. + * Example: UART Communication Interface which calls respective UART drivers + * 3. Health table class has been instantiated in Factory + * 4. deviceThermalRequestPoolId and deviceThermalStatePoolId are set to the respective data pool entries. + * This is only required if thermal checking is needed. Otherwise, set both variables to + * PoolVariableIF::NO_PARAMETER + * + * @return + */ virtual ReturnValue_t initialize(); /** From 07950b0c2bb9c3822729a225302cb685cb62ea7a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 23 Oct 2019 00:31:45 +0200 Subject: [PATCH 0007/1774] documentation for object manager IF get function --- fdir/FailureIsolationBase.cpp | 7 ++++--- objectmanager/ObjectManagerIF.h | 7 +++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/fdir/FailureIsolationBase.cpp b/fdir/FailureIsolationBase.cpp index 4b7caac53..c65640c27 100644 --- a/fdir/FailureIsolationBase.cpp +++ b/fdir/FailureIsolationBase.cpp @@ -5,9 +5,10 @@ #include #include -FailureIsolationBase::FailureIsolationBase(object_id_t owner, object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) : - eventQueue(NULL), ownerId( - owner), owner(NULL), faultTreeParent(parent), parameterDomainBase(parameterDomainBase) { +FailureIsolationBase::FailureIsolationBase(object_id_t owner, + object_id_t parent, uint8_t messageDepth, uint8_t parameterDomainBase) : + eventQueue(NULL), ownerId(owner), owner(NULL), + faultTreeParent(parent), parameterDomainBase(parameterDomainBase) { eventQueue = QueueFactory::instance()->createMessageQueue(messageDepth, EventMessage::EVENT_MESSAGE_SIZE); } diff --git a/objectmanager/ObjectManagerIF.h b/objectmanager/ObjectManagerIF.h index aca24a24a..9f58f600c 100644 --- a/objectmanager/ObjectManagerIF.h +++ b/objectmanager/ObjectManagerIF.h @@ -78,6 +78,13 @@ public: virtual void printList() = 0; }; +/** + * Used to retrieve Target Interface Pointers of objects. + * The object has to implement the SystemObject or SystemObjectIF at the very least, + * otherwise NULL will be returned. + * @param id + * @return NULL or pointer to target interface specified by template object + */ template T* ObjectManagerIF::get( object_id_t id ) { SystemObjectIF* temp = this->getSystemObject(id); From 1631e739b8c0b3b7ab0af314309da898df7e2eae Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 23 Oct 2019 12:03:32 +0200 Subject: [PATCH 0008/1774] at91sam9g20 uses custom stdio.c, unsigned long cast in sprintf does not seem to work, casting (unsigned int) does, timestamp now visible in debug output --- serviceinterface/ServiceInterfaceBuffer.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/serviceinterface/ServiceInterfaceBuffer.cpp b/serviceinterface/ServiceInterfaceBuffer.cpp index 58065994a..d5ce60568 100644 --- a/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/serviceinterface/ServiceInterfaceBuffer.cpp @@ -5,6 +5,8 @@ // to be implemented by bsp extern "C" void printChar(const char*); + + int ServiceInterfaceBuffer::overflow(int c) { // Handle output putChars(pbase(), pptr()); @@ -19,16 +21,18 @@ int ServiceInterfaceBuffer::overflow(int c) { return 0; } +// custom stdio.c library for at91sam9g20 chip which does not support unsigned long +// So I cast (unsigned int) on loggerTimes int ServiceInterfaceBuffer::sync(void) { if (this->isActive) { Clock::TimeOfDay_t loggerTime; Clock::getDateAndTime(&loggerTime); char preamble[96] = { 0 }; - sprintf(preamble, "%s: | %lu:%02lu:%02lu.%03lu | ", - this->log_message.c_str(), (unsigned long) loggerTime.hour, - (unsigned long) loggerTime.minute, - (unsigned long) loggerTime.second, - (unsigned long) loggerTime.usecond /1000); + sprintf(preamble, "%s: | %u:%02u:%02u.%03u | ", + this->log_message.c_str(), (unsigned int) loggerTime.hour, + (unsigned int) loggerTime.minute, + (unsigned int) loggerTime.second, + (unsigned int) loggerTime.usecond /1000); // Write log_message and time this->putChars(preamble, preamble + sizeof(preamble)); // Handle output From 8f1517d276aac56dc260b8ea4609204ab8e1036a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 25 Oct 2019 21:12:11 +0200 Subject: [PATCH 0009/1774] additional comments on endianness (I hope this is correct) --- devicehandlers/DeviceHandlerBase.cpp | 2 -- serialize/SerializeAdapter.h | 7 +++++++ serialize/SerializeIF.h | 7 +++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index d0f9d8b24..4eb9f5049 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -53,7 +53,6 @@ DeviceHandlerBase::~DeviceHandlerBase() { ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { this->pstStep = counter; - if (counter == 0) { cookieInfo.state = COOKIE_UNUSED; readCommandQueue(); @@ -670,7 +669,6 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len, } CommandMessage message; - DeviceHandlerMessage::setDeviceHandlerRawReplyMessage(&message, getObjectId(), address, isCommand); diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 67c37493a..6e2f3e5fb 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -20,6 +20,13 @@ * * The AutoSerializeAdapter functions can also be used as an alternative to memcpy * to retrieve data out of a buffer directly into a class variable with data type T while being able to specify endianness. + * + * In the SOURCE mission , the target architecture is little endian, + * so any buffers must be deSerialized with bool bigEndian = false if + * the parameters are used in the FSFW. + * When serializing for downlink, the packets are generally serialized into big endian for the network when using a TC/UDP client + * like seen in TmPacketStored.cpp for example. + * * \ingroup serialize */ template diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index 50555d379..14f6995e5 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -10,6 +10,13 @@ /** * An interface for alle classes which require translation of objects data into data streams and vice-versa. + * + * In the SOURCE mission , the target architecture is little endian, + * so any buffers must be deSerialized with bool bigEndian = false if + * the parameters are used in the FSFW. + * When serializing for downlink, the packets are generally serialized into big endian for the network when using a TC/UDP client + * like seen in TmPacketStored.cpp for example. + * * \ingroup serialize */ class SerializeIF { From 64f84d9d9ffbf2d4b357ac72ad24956b8540db07 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 27 Oct 2019 03:21:38 +0100 Subject: [PATCH 0010/1774] doc for dhb, serializeIF and SerializeAdapter --- devicehandlers/DeviceCommunicationIF.h | 2 +- devicehandlers/DeviceHandlerBase.cpp | 11 ++++++---- devicehandlers/DeviceHandlerBase.h | 11 ++++++---- serialize/SerializeAdapter.h | 28 ++++++++++++++++++++++---- serialize/SerializeIF.h | 14 +++++++++---- tmtcservices/PusServiceBase.h | 4 ++-- 6 files changed, 51 insertions(+), 19 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index e0aca5731..88f0d1240 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -40,7 +40,7 @@ public: virtual void close(Cookie *cookie) = 0; //SHOULDDO can data be const? - virtual ReturnValue_t sendMessage(Cookie *cookie, uint8_t *data, + virtual ReturnValue_t sendMessage(Cookie *cookie,const uint8_t *data, uint32_t len) = 0; virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0; diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 4eb9f5049..2f16f8462 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -11,6 +11,7 @@ #include #include #include +#include object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; @@ -452,7 +453,7 @@ void DeviceHandlerBase::doGetWrite() { if (wiretappingMode == RAW) { replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true); } - //We need to distinguish here, because a raw command never expects a reply. (Could be done in eRIRM, but then child implementations need to be careful. + // We need to distinguish here, because a raw command never expects a reply. (Could be done in eRIRM, but then child implementations need to be careful. result = enableReplyInReplyMap(cookieInfo.pendingCommand); } else { //always generate a failure event, so that FDIR knows what's up @@ -473,9 +474,9 @@ void DeviceHandlerBase::doSendRead() { cookieInfo.state = COOKIE_READ_SENT; } else { triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result); - //We can't inform anyone, because we don't know which command was sent last. - //So, we need to wait for a timeout. - //but I think we can allow to ignore one missedReply. + // We can't inform anyone, because we don't know which command was sent last. + // So, we need to wait for a timeout. + // but I think we can allow to ignore one missedReply. ignoreMissedRepliesCount++; cookieInfo.state = COOKIE_UNUSED; } @@ -1266,3 +1267,5 @@ void DeviceHandlerBase::changeHK(Mode_t mode, Submode_t submode, bool enable) { void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){ executingTask = task_; } + + diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 2278e1f5d..6abfb675c 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -167,7 +167,7 @@ protected: static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE; static const ReturnValue_t INVALID_CHANNEL = MAKE_RETURN_CODE(4); - static const ReturnValue_t APERIODIC_REPLY = MAKE_RETURN_CODE(5); + static const ReturnValue_t APERIODIC_REPLY = MAKE_RETURN_CODE(5); //!< This is used to specify for replies from a device which are not replies to requests static const ReturnValue_t IGNORE_REPLY_DATA = MAKE_RETURN_CODE(6); // static const ReturnValue_t ONE_SWITCH = MAKE_RETURN_CODE(8); // static const ReturnValue_t TWO_SWITCHES = MAKE_RETURN_CODE(9); @@ -626,9 +626,9 @@ protected: * @param[out] foundLen length of the packet found * @return * - @c RETURN_OK a valid packet was found at @c start, @c foundLen is valid - * - @c NO_VALID_REPLY no reply could be found starting at @c start, implies @c foundLen is not valid, base class will call scanForReply() again with ++start - * - @c INVALID_REPLY a packet was found but it is invalid, eg checksum error, implies @c foundLen is valid, can be used to skip some bytes - * - @c TOO_SHORT @c len is too short for any valid packet + * - @c RETURN_FAILED no reply could be found starting at @c start, implies @c foundLen is not valid, base class will call scanForReply() again with ++start + * - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid, eg checksum error, implies @c foundLen is valid, can be used to skip some bytes + * - @c DeviceHandlerIF::LENGTH_MISSMATCH @c len is invalid * - @c APERIODIC_REPLY if a valid reply is received that has not been requested by a command, but should be handled anyway (@see also fillCommandAndCookieMap() ) */ virtual ReturnValue_t scanForReply(const uint8_t *start, uint32_t len, @@ -954,6 +954,7 @@ private: * * This is called at the beginning of each cycle. It checks whether a reply has timed out (that means a reply was expected * but not received). + * In case the reply is periodic, the counter is simply set back to a specified value. */ void decrementDeviceReplyMap(void); @@ -1053,6 +1054,8 @@ private: ReturnValue_t switchCookieChannel(object_id_t newChannelId); ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message); + + }; #endif /* DEVICEHANDLERBASE_H_ */ diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 6e2f3e5fb..04216c897 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -20,11 +20,31 @@ * * The AutoSerializeAdapter functions can also be used as an alternative to memcpy * to retrieve data out of a buffer directly into a class variable with data type T while being able to specify endianness. + * The boolean bigEndian specifies the endiness of the data to serialize or deSerialize. * - * In the SOURCE mission , the target architecture is little endian, - * so any buffers must be deSerialized with bool bigEndian = false if - * the parameters are used in the FSFW. - * When serializing for downlink, the packets are generally serialized into big endian for the network when using a TC/UDP client + * If the target architecture is little endian (ARM), any data types created might + * have the wrong endiness if they are to be used for the FSFW. + * there are three ways to retrieve data out of a buffer to be used in the FSFW to use regular aligned (big endian) data. + * This can also be applied to uint32_t and uint64_t: + * + * 1. Use the AutoSerializeAdapter::deSerialize function with bool bigEndian = true: + * + * uint16_t data; + * int32_t dataLen = sizeof(data); + * ReturnValue_t result = AutoSerializeAdapter::deSerialize(&data,&buffer,&dataLen,true); + * + * 2. Perform a bitshift operation: + * + * uint16_t data; + * data = buffer[targetByte1] >> 8 | buffer[targetByte2]; + * + * 3. Memcpy can be used when data is little-endian. Otherwise, endian-swapper has to be used. + * + * uint16_t data; + * memcpy(&data,buffer + positionOfTargetByte1,sizeof(data)); + * data = EndianSwapper::swap(data); + * + * When serializing for downlink, the packets are generally serialized assuming big endian data format * like seen in TmPacketStored.cpp for example. * * \ingroup serialize diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index 14f6995e5..d86349ab5 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -11,10 +11,16 @@ /** * An interface for alle classes which require translation of objects data into data streams and vice-versa. * - * In the SOURCE mission , the target architecture is little endian, - * so any buffers must be deSerialized with bool bigEndian = false if - * the parameters are used in the FSFW. - * When serializing for downlink, the packets are generally serialized into big endian for the network when using a TC/UDP client + * If the target architecture is little endian (ARM), any data types created might + * have the wrong endiness if they are to be used for the FSFW. + * there are three ways to retrieve data out of a buffer to be used in the FSFW to use regular aligned (big endian) data. + * This can also be applied to uint32_t and uint64_t: + * + * 1. Use the @c AutoSerializeAdapter::deSerialize function with @c bigEndian = true + * 2. Perform a bitshift operation + * 3. @c memcpy can be used when data is little-endian. Otherwise, @c EndianSwapper has to be used. + * + * When serializing for downlink, the packets are generally serialized assuming big endian data format * like seen in TmPacketStored.cpp for example. * * \ingroup serialize diff --git a/tmtcservices/PusServiceBase.h b/tmtcservices/PusServiceBase.h index 782d375ff..4fe13ca91 100644 --- a/tmtcservices/PusServiceBase.h +++ b/tmtcservices/PusServiceBase.h @@ -68,8 +68,8 @@ public: * It checks for new requests, and, if found, calls handleRequest, sends completion verification messages and deletes * the TC requests afterwards. * performService is always executed afterwards. - * @return - \c RETURN_OK if the periodic performService was successful. - * - \c RETURN_FAILED else. + * @return \c RETURN_OK if the periodic performService was successful. + * \c RETURN_FAILED else. */ ReturnValue_t performOperation(uint8_t opCode); virtual uint16_t getIdentifier(); From d79f072851264ec3f9e369f2b2ccbfa7fddd3145 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 27 Oct 2019 13:38:08 +0100 Subject: [PATCH 0011/1774] Additional documentation for DHB and CSB --- devicehandlers/DeviceHandlerBase.h | 19 ++++++---- tmtcservices/CommandingServiceBase.h | 54 +++++++++++++++++++++++++--- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 6abfb675c..be488d354 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -33,24 +33,29 @@ class StorageManagerIF; * Contains all devices and the DeviceHandlerBase class. */ -// Robin: We're not really using RMAP, right? Maybe we should adapt class description for that? + /** * \brief This is the abstract base class for device handlers. * * Documentation: Dissertation Baetz p.138,139, p.141-149 - * SpaceWire Remote Memory Access Protocol (RMAP) * - * It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink, the RMAP communication and the - * communication with commanding objects. + * It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink, communication with + * physical devices, using the @link DeviceCommunicationIF, and communication with commanding objects. + * + * NOTE: RMAP is a legacy standard which is used for FLP. + * RMAP communication is not mandatory for projects implementing the FSFW. + * However, the communication principles are similar to RMAP as there are two write and two send calls involved. + * * It inherits SystemObject and thus can be created by the ObjectManagerIF. * * This class uses the opcode of ExecutableObjectIF to perform a step-wise execution. - * For each step an RMAP action is selected and executed. If data has been received (eg in case of an RMAP Read), the data will be interpreted. - * The action for each step can be defined by the child class but as most device handlers share a 4-call (Read-getRead-write-getWrite) structure, - * a default implementation is provided. + * For each step an RMAP action is selected and executed. If data has been received (GET_READ), the data will be interpreted. + * The action for each step can be defined by the child class but as most device handlers share a 4-call + * (sendRead-getRead-sendWrite-getWrite) structure, a default implementation is provided. * * Device handler instances should extend this class and implement the abstract functions. * Components and drivers can send so called cookies which are used for communication + * and contain information about the communcation (e.g. slave address for I2C or RMAP structs). * * \ingroup devices */ diff --git a/tmtcservices/CommandingServiceBase.h b/tmtcservices/CommandingServiceBase.h index ee59ffe44..f662072fd 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/tmtcservices/CommandingServiceBase.h @@ -180,20 +180,65 @@ protected: */ void sendTmPacket(uint8_t subservice, SerializeIF* content, SerializeIF* header = NULL); + + /** + * Check the target subservice + * @param subservice + * @return + */ virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0; + /** + * Once a TC Request is valid, the existence of the destination and its target interface is checked and retrieved. + * The target message queue ID can then be acquired by using the target interface. + * @param subservice + * @param tcData Application Data of TC Packet + * @param tcDataLen + * @param id MessageQueue ID is stored here + * @param objectId + * @return - @c RETURN_OK on success + * - @c RETURN_FAILED + * - @c CSB or implementation specific return codes + */ + virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice, + const uint8_t *tcData, uint32_t tcDataLen, MessageQueueId_t *id, + object_id_t *objectId) = 0; + + /** + * After the Message Queue and Object ID are determined, + * the command is prepared by using an implementation specific CommandMessage type which is sent to + * the target device. It contains all necessary information for the device to + * execute telecommands. + * @param message + * @param subservice + * @param tcData + * @param tcDataLen + * @param state + * @param objectId + * @return + */ virtual ReturnValue_t prepareCommand(CommandMessage *message, uint8_t subservice, const uint8_t *tcData, uint32_t tcDataLen, uint32_t *state, object_id_t objectId) = 0; + /** + * This function is responsible for the communication between the Command Service Base + * and the respective PUS Commanding Service once the execution has started. + * The PUS Commanding Service receives replies from the target device and forwards them by calling this function. + * There are different translations of these replies to specify how the Command Service proceeds. + * @param reply Command Message which determines how CommandServiceBase proceeds + * @param previousCommand + * @param state + * @param optionalNextCommand + * @param objectId + * @param isStep Flag value to mark steps of command execution + * @return + */ virtual ReturnValue_t handleReply(const CommandMessage *reply, Command_t previousCommand, uint32_t *state, CommandMessage *optionalNextCommand, object_id_t objectId, bool *isStep) = 0; - virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice, - const uint8_t *tcData, uint32_t tcDataLen, MessageQueueId_t *id, - object_id_t *objectId) = 0; virtual void handleUnrequestedReply(CommandMessage *reply); @@ -209,7 +254,8 @@ private: * It handles replies generated by the devices and relayed by the specific service implementation. * This means that it determines further course of action depending on the return values specified * in the service implementation. - * This includes the generation of TC verification messages: + * This includes the generation of TC verification messages. Note that + * the static framework object ID @c VerificationReporter::messageReceiver needs to be set. * - TM[1,5] Step Successs * - TM[1,6] Step Failure * - TM[1,7] Completion Success From b51536c772c9d058b7c7a4449f8cf8ca107773ec Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 28 Oct 2019 12:48:41 +0100 Subject: [PATCH 0012/1774] CSB doc correction --- fdir/FailureIsolationBase.h | 4 ++++ tmtcservices/CommandingServiceBase.h | 8 +++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/fdir/FailureIsolationBase.h b/fdir/FailureIsolationBase.h index cd582e399..894f63562 100644 --- a/fdir/FailureIsolationBase.h +++ b/fdir/FailureIsolationBase.h @@ -21,6 +21,10 @@ public: uint8_t messageDepth = 10, uint8_t parameterDomainBase = 0xF0); virtual ~FailureIsolationBase(); virtual ReturnValue_t initialize(); + + /** + * This is called by the DHB in performOperation() + */ void checkForFailures(); MessageQueueId_t getEventReceptionQueue(); virtual void triggerEvent(Event event, uint32_t parameter1 = 0, diff --git a/tmtcservices/CommandingServiceBase.h b/tmtcservices/CommandingServiceBase.h index f662072fd..8ce25f007 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/tmtcservices/CommandingServiceBase.h @@ -64,7 +64,7 @@ public: virtual ~CommandingServiceBase(); /*** - * This is the periodic called function + * This is the periodically called function. * Handle request queue for external commands. * Handle command Queue for internal commands. * @param opCode is unused here at the moment @@ -226,13 +226,15 @@ protected: * and the respective PUS Commanding Service once the execution has started. * The PUS Commanding Service receives replies from the target device and forwards them by calling this function. * There are different translations of these replies to specify how the Command Service proceeds. - * @param reply Command Message which determines how CommandServiceBase proceeds + * @param reply Command Message which contains information about the command * @param previousCommand * @param state * @param optionalNextCommand * @param objectId * @param isStep Flag value to mark steps of command execution - * @return + * @return - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to generate TC verification success + * - @c INVALID_REPLY can handle unrequested replies + * - Anything else triggers a TC verification failure */ virtual ReturnValue_t handleReply(const CommandMessage *reply, Command_t previousCommand, uint32_t *state, From 1ee445ce245b0383a3d770b44f971693ff37542f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 29 Oct 2019 11:17:07 +0100 Subject: [PATCH 0013/1774] fifo typo --- container/FIFO.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container/FIFO.h b/container/FIFO.h index 670a50d74..134da9b80 100644 --- a/container/FIFO.h +++ b/container/FIFO.h @@ -21,7 +21,7 @@ public: readIndex(0), writeIndex(0), currentSize(0) { } - bool emtpy() { + bool empty() { return (currentSize == 0); } @@ -45,7 +45,7 @@ public: } ReturnValue_t retrieve(T *value) { - if (emtpy()) { + if (empty()) { return EMPTY; } else { *value = data[readIndex]; From e8a16ac59cf87d27d1e79a6571a6ee11f0edc3c2 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 29 Oct 2019 18:21:01 +0100 Subject: [PATCH 0014/1774] dummy com if sendMessage data const --- devicehandlers/DeviceCommunicationIF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index e0aca5731..88f0d1240 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -40,7 +40,7 @@ public: virtual void close(Cookie *cookie) = 0; //SHOULDDO can data be const? - virtual ReturnValue_t sendMessage(Cookie *cookie, uint8_t *data, + virtual ReturnValue_t sendMessage(Cookie *cookie,const uint8_t *data, uint32_t len) = 0; virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0; From 3887cb8ca14f4a12a2fd446e1779b66c76096962 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 29 Oct 2019 18:22:34 +0100 Subject: [PATCH 0015/1774] removed wrong include in dhb --- devicehandlers/DeviceHandlerBase.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 2f16f8462..1bb411b7d 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -11,7 +11,6 @@ #include #include #include -#include object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; From 16af33a7bb52e3d9363e1e6f61e16a67783f74df Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 29 Oct 2019 19:31:18 +0100 Subject: [PATCH 0016/1774] doc for fifo, device com if.. --- container/FIFO.h | 4 +-- container/SimpleRingBuffer.h | 28 +++++++++++++++++++++ devicehandlers/DeviceCommunicationIF.h | 35 +++++++++++++++++++++++++- serialize/SerializeAdapter.h | 2 ++ 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/container/FIFO.h b/container/FIFO.h index 670a50d74..134da9b80 100644 --- a/container/FIFO.h +++ b/container/FIFO.h @@ -21,7 +21,7 @@ public: readIndex(0), writeIndex(0), currentSize(0) { } - bool emtpy() { + bool empty() { return (currentSize == 0); } @@ -45,7 +45,7 @@ public: } ReturnValue_t retrieve(T *value) { - if (emtpy()) { + if (empty()) { return EMPTY; } else { *value = data[readIndex]; diff --git a/container/SimpleRingBuffer.h b/container/SimpleRingBuffer.h index 6d7d67e1d..45cb09277 100644 --- a/container/SimpleRingBuffer.h +++ b/container/SimpleRingBuffer.h @@ -4,12 +4,40 @@ #include #include +/** + * Circular buffer implementation, useful for buffering into data streams. + * Note that the deleteData() has to be called to increment the read pointer + */ class SimpleRingBuffer: public RingBufferBase<> { public: SimpleRingBuffer(uint32_t size, bool overwriteOld); virtual ~SimpleRingBuffer(); + + /** + * Write to circular buffer and increment write pointer by amount + * @param data + * @param amount + * @return + */ ReturnValue_t writeData(const uint8_t* data, uint32_t amount); + + /** + * Read from circular buffer at read pointer + * @param data + * @param amount + * @param readRemaining + * @param trueAmount + * @return + */ ReturnValue_t readData(uint8_t* data, uint32_t amount, bool readRemaining = false, uint32_t* trueAmount = NULL); + + /** + * Delete data starting by incrementing read pointer + * @param amount + * @param deleteRemaining + * @param trueAmount + * @return + */ ReturnValue_t deleteData(uint32_t amount, bool deleteRemaining = false, uint32_t* trueAmount = NULL); private: // static const uint8_t TEMP_READ_PTR = 1; diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 88f0d1240..59420861e 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -4,6 +4,22 @@ #include #include +/** + * Documentation: Dissertation Baetz p.138 + * + * This is an interface to decouple device communication from + * the device handler to allow reuse of these components. + * It works with the assumption that received data + * is polled by a component. There are four generic steps of device communication: + * + * 1. Send data to a device + * 2. Get acknowledgement for sending + * 3. Request reading data from a device + * 4. Read received data + * + * To identify different connection over a single interface can return so-called cookies to components. + * + */ class DeviceCommunicationIF: public HasReturnvaluesIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF; @@ -39,7 +55,15 @@ public: virtual void close(Cookie *cookie) = 0; - //SHOULDDO can data be const? + /** + * Called by DHB in the SEND_WRITE doSendWrite(). + * This function is used to send data to the physical device + * by implementing and calling related drivers or wrapper functions. + * @param cookie + * @param data + * @param len + * @return + */ virtual ReturnValue_t sendMessage(Cookie *cookie,const uint8_t *data, uint32_t len) = 0; @@ -47,6 +71,15 @@ public: virtual ReturnValue_t requestReceiveMessage(Cookie *cookie) = 0; + /** + * Called by DHB in the GET_WIRTE doGetRead(). + * This function is used to receive data from the physical device + * by implementing and calling related drivers or wrapper functions. + * @param cookie + * @param data + * @param len + * @return + */ virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, uint32_t *size) = 0; diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 04216c897..a0aab9e98 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -28,6 +28,8 @@ * This can also be applied to uint32_t and uint64_t: * * 1. Use the AutoSerializeAdapter::deSerialize function with bool bigEndian = true: + * The pointer *buffer will be incremented automatically by the typeSize of data, + * so this function can be called on &buffer without adjusting pointer position * * uint16_t data; * int32_t dataLen = sizeof(data); From 46986f69e4a17923717464c120f4d227df561618 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 2 Nov 2019 23:30:12 +0100 Subject: [PATCH 0017/1774] serialize tools more documentation --- serialize/SerialBufferAdapter.cpp | 8 ++++---- serialize/SerialBufferAdapter.h | 8 ++++++++ serialize/SerialFixedArrayListAdapter.h | 11 +++++++++++ serialize/SerialLinkedListAdapter.h | 10 +++++++++- serialize/SerializeIF.h | 6 +++--- 5 files changed, 35 insertions(+), 8 deletions(-) diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 3ed083bf5..c5fcfb57e 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -5,15 +5,15 @@ template SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, - T bufferLength, bool serializeLenght) : - serializeLength(serializeLenght), constBuffer(buffer), buffer(NULL), bufferLength( + T bufferLength, bool serializeLength) : + serializeLength(serializeLength), constBuffer(buffer), buffer(NULL), bufferLength( bufferLength) { } template SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, T bufferLength, - bool serializeLenght) : - serializeLength(serializeLenght), constBuffer(NULL), buffer(buffer), bufferLength( + bool serializeLength) : + serializeLength(serializeLength), constBuffer(NULL), buffer(buffer), bufferLength( bufferLength) { } diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 7cd75d556..7d192bb45 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -5,6 +5,14 @@ #include /** + * This adapter provides an interface for SerializeIF to serialize or deserialize + * buffers with no length header but a known size. + * + * Additionally, the buffer length can be serialized too and will be put in front of the serialized buffer. + * + * Can be used with SerialLinkedListAdapter by declaring a SerializeElement with + * SerialElement> serialBufferElement + * * \ingroup serialize */ template diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 16919b623..821e87104 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -5,6 +5,17 @@ #include /** + * This adapter provides an interface for SerializeIF to serialize and deserialize + * buffers with a header containing the buffer length. + * + * Can be used by SerialLinkedListAdapter. + * + * Buffers with a size header inside that class can be declared with + * SerialFixedArrayListAdapter. + * typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows + * and MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. + * The sequence of objects is defined in the constructor by using the setStart and setNext functions. + * * \ingroup serialize */ template diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index 44d9e15bc..08d385eec 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -17,12 +17,20 @@ * An alternative to the AutoSerializeAdapter functions to implement the conversion * of object data to data streams or vice-versa, using linked lists. * - * All object members with a datatype are declared as SerializeElement inside the class. + * All object members with a datatype are declared as SerializeElement inside the class + * implementing this adapter. * * Buffers with a size header inside that class can be declared with * SerialFixedArrayListAdapter. * typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows * and MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. + * Please note that a direct link from a linked element to a SerialFixedArrayListAdapter element is not possible and a + * helper needs to be used by calling .setNext(&linkHelper) + * and initialising the link helper as linkHelper(&SerialFixedArrayListAdapterElement). + * + * For buffers with no size header, declare + * SerializeElement> and initialise the buffer adapter in the constructor. + * * The sequence of objects is defined in the constructor by using the setStart and setNext functions. * * The serialization and deserialization process is done by instantiating the class and diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index d86349ab5..cada1e72a 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -11,14 +11,14 @@ /** * An interface for alle classes which require translation of objects data into data streams and vice-versa. * - * If the target architecture is little endian (ARM), any data types created might + * If the target architecture is little endian (e.g. ARM), any data types created might * have the wrong endiness if they are to be used for the FSFW. - * there are three ways to retrieve data out of a buffer to be used in the FSFW to use regular aligned (big endian) data. + * There are three ways to retrieve data out of a buffer to be used in the FSFW to use regular aligned (big endian) data. * This can also be applied to uint32_t and uint64_t: * * 1. Use the @c AutoSerializeAdapter::deSerialize function with @c bigEndian = true * 2. Perform a bitshift operation - * 3. @c memcpy can be used when data is little-endian. Otherwise, @c EndianSwapper has to be used. + * 3. @c memcpy can be used when data is in little-endian format. Otherwise, @c EndianSwapper has to be used in conjuction. * * When serializing for downlink, the packets are generally serialized assuming big endian data format * like seen in TmPacketStored.cpp for example. From 8eb1a5b13e2fccf21176aed9a6a27287196fd236 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 Nov 2019 00:47:46 +0100 Subject: [PATCH 0018/1774] proposal 1: expectedReplies parameter is set in insertInCommandAndReplyMap, default value stays one. overriding enableReplyInReplyMap is not necessary anymore.second proposal: the commander id is supplied in the interpretDeviceReply function, so we don't have to look for it in the DeviceCommandMap. was it removed at some point because it is listed in the documentation? --- action/ActionHelper.h | 2 +- devicehandlers/DeviceHandlerBase.cpp | 32 +++++++++++++++++--------- devicehandlers/DeviceHandlerBase.h | 16 ++++++++----- modes/ModeHelper.h | 13 ++++++++++- tmtcservices/CommandingServiceBase.cpp | 11 ++++----- 5 files changed, 49 insertions(+), 25 deletions(-) diff --git a/action/ActionHelper.h b/action/ActionHelper.h index 6ba6dd89b..a72e3654a 100644 --- a/action/ActionHelper.h +++ b/action/ActionHelper.h @@ -74,7 +74,7 @@ public: protected: static const uint8_t STEP_OFFSET = 1;//!< Increase of value of this per step HasActionsIF* owner;//!< Pointer to the owner - MessageQueueIF* queueToUse;//!< Queue to be used as response sender, has to be set with + MessageQueueIF* queueToUse;//!< Queue to be used as response sender, has to be set with @c setQueueToUse StorageManagerIF* ipcStore;//!< Pointer to an IPC Store, initialized during construction or initialize(MessageQueueIF* queueToUse_) or with setQueueToUse(MessageQueueIF *queue) /** *Internal function called by handleActionMessage(CommandMessage* command) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 1bb411b7d..c92cac332 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -255,9 +255,9 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode, ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap( DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, - uint8_t periodic, bool hasDifferentReplyId, DeviceCommandId_t replyId) { -//No need to check, as we may try to insert multiple times. - insertInCommandMap(deviceCommand); + uint8_t periodic, uint8_t expectedReplies, bool hasDifferentReplyId, DeviceCommandId_t replyId) { + //No need to check, as we may try to insert multiple times. + insertInCommandMap(deviceCommand,expectedReplies); if (hasDifferentReplyId) { return insertInReplyMap(replyId, maxDelayCycles, periodic); } else { @@ -283,9 +283,9 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, } ReturnValue_t DeviceHandlerBase::insertInCommandMap( - DeviceCommandId_t deviceCommand) { + DeviceCommandId_t deviceCommand, uint8_t expectedReplies) { DeviceCommandInfo info; - info.expectedReplies = 0; + info.expectedReplies = expectedReplies; info.isExecuting = false; info.sendReplyTo = NO_COMMANDER; std::pair::iterator, bool> returnValue; @@ -712,6 +712,7 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData, DeviceCommandId_t foundId, uint32_t foundLen) { ReturnValue_t result; DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId); + MessageQueueId_t commander; if (iter == deviceReplyMap.end()) { replyRawReplyIfnotWiretapped(receivedData, foundLen); @@ -728,7 +729,17 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData, } else { info->delayCycles = 0; } - result = interpretDeviceReply(foundId, receivedData); + + DeviceCommandMap::iterator commandIter = deviceCommandMap.find(foundId); + // could be a reply only packet + if(commandIter == deviceCommandMap.end()) { + commander = 0; + } + else { + commander = commandIter->second.sendReplyTo; + } + + result = interpretDeviceReply(foundId, receivedData,commander); if (result != RETURN_OK) { //Report failed interpretation to FDIR. replyRawReplyIfnotWiretapped(receivedData, foundLen); @@ -798,7 +809,7 @@ void DeviceHandlerBase::modeChanged(void) { } ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( - DeviceCommandMap::iterator command, uint8_t expectedReplies, + DeviceCommandMap::iterator command,/* uint8_t expectedReplies, */ bool useAlternativeId, DeviceCommandId_t alternativeReply) { DeviceReplyMap::iterator iter; if (useAlternativeId) { @@ -810,7 +821,7 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( DeviceReplyInfo *info = &(iter->second); info->delayCycles = info->maxDelayCycles; info->command = command; - command->second.expectedReplies = expectedReplies; + // command->second.expectedReplies = expectedReplies; return RETURN_OK; } else { return NO_REPLY_EXPECTED; @@ -1108,8 +1119,7 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data, // hiding of sender needed so the service will handle it as unexpected Data, no matter what state //(progress or completed) it is in - actionHelper.reportData(defaultRawReceiver, replyId, &wrapper, - true); + actionHelper.reportData(defaultRawReceiver, replyId, &wrapper); } } else { //unrequested/aperiodic replies @@ -1122,7 +1132,7 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data, true); } } -//Try to cast to DataSet and commit data. + //Try to cast to DataSet and commit data. if (!neverInDataPool) { DataSet* dataSet = dynamic_cast(data); if (dataSet != NULL) { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index be488d354..89f965036 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -576,8 +576,9 @@ protected: * Default is aperiodic (0) * @return RETURN_OK when the command was successfully inserted, COMMAND_MAP_ERROR else. */ + // Proposal: Set expected replies for a command in insertInCommandAndReplyMap so we don't have to overwrite enableReplyInReplyMap ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, - uint16_t maxDelayCycles, uint8_t periodic = 0, + uint16_t maxDelayCycles, uint8_t periodic = 0, uint8_t expectedReplies = 1, bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0); /** * This is a helper method to insert replies in the reply map. @@ -594,7 +595,7 @@ protected: * @param deviceCommand The command to add * @return RETURN_OK if the command was successfully inserted, RETURN_FAILED else. */ - ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand); + ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand, uint8_t expectedReplies = 1); /** * This is a helper method to facilitate updating entries in the reply map. * @param deviceCommand Identifier of the reply to update. @@ -644,18 +645,19 @@ protected: * * This is called after scanForReply() found a valid packet, it can be assumed that the length and structure is valid. * This routine extracts the data from the packet into a DataSet and then calls handleDeviceTM(), which either sends - * a TM packet or stores the data in the DataPool depending on whether the it was an external command. + * a TM packet or stores the data in the DataPool depending on whether it was an external command. * No packet length is given, as it should be defined implicitly by the id. * * @param id the id found by scanForReply() * @param packet - * @param commander the one who initiated the command, is 0 if not external commanded + * @param commander the one who initiated the command, is 0 if not external commanded. + * UPDATE: This parameter does not exist anymore. Why? * @return * - @c RETURN_OK when the reply was interpreted. * - @c RETURN_FAILED when the reply could not be interpreted, eg. logical errors or range violations occurred */ virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet) = 0; + const uint8_t *packet, MessageQueueId_t commander = 0) = 0; /** * Construct a command reply containing a raw reply. @@ -723,13 +725,15 @@ protected: * - If the command was not found in the reply map, NO_REPLY_EXPECTED MUST be returned. * - A failure code may be returned if something went fundamentally wrong. * + * * @param deviceCommand * @return - RETURN_OK if a reply was activated. * - NO_REPLY_EXPECTED if there was no reply found. This is not an error case as many commands * do not expect a reply. */ + // Proposal: Set expected replies in insertInCommandAndReplyMap so we don't have to overwrite that function anymore. virtual ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator cmd, - uint8_t expectedReplies = 1, bool useAlternateId = false, + /* uint8_t expectedReplies = 0 */ bool useAlternateId = false, DeviceCommandId_t alternateReplyID = 0); /** diff --git a/modes/ModeHelper.h b/modes/ModeHelper.h index 87f6d4112..b23eb69e5 100644 --- a/modes/ModeHelper.h +++ b/modes/ModeHelper.h @@ -16,11 +16,17 @@ public: ModeHelper(HasModesIF *owner); virtual ~ModeHelper(); + /** + * This is used by DHB to handle all mode messages issued by a service + * @param message + * @return + */ ReturnValue_t handleModeCommand(CommandMessage *message); /** * - * @param parentQueue the Queue id of the parent object. Set to 0 if no parent present + * @param parentQueue the Queue id of the parent object (assembly or subsystem object). + * Set to 0 if no parent present */ void setParentQueue(MessageQueueId_t parentQueueId); @@ -28,6 +34,11 @@ public: ReturnValue_t initialize(void); //void is there to stop eclipse CODAN from falsely reporting an error + /** + * Used to notify + * @param mode + * @param submode + */ void modeChanged(Mode_t mode, Submode_t submode); void startTimer(uint32_t timeoutMs); diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index d70b90428..ec65492de 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -11,12 +11,11 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, uint16_t commandTimeout_seconds, object_id_t setPacketSource, object_id_t setPacketDestination, size_t queueDepth) : - SystemObject(setObjectId), apid(apid), service(service), timeout_seconds( - commandTimeout_seconds), tmPacketCounter(0), IPCStore(NULL), TCStore( - NULL), commandQueue(NULL), requestQueue(NULL), commandMap( - numberOfParallelCommands), failureParameter1(0), failureParameter2( - 0), packetSource(setPacketSource), packetDestination( - setPacketDestination),executingTask(NULL) { + SystemObject(setObjectId), apid(apid), service(service), + timeout_seconds(commandTimeout_seconds), tmPacketCounter(0), IPCStore(NULL), + TCStore(NULL), commandQueue(NULL), requestQueue(NULL), commandMap(numberOfParallelCommands), + failureParameter1(0), failureParameter2(0), packetSource(setPacketSource), + packetDestination(setPacketDestination),executingTask(NULL) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); } From 12f51575eb42bffc9e2cf5a72a5678975f87db34 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 Nov 2019 00:53:05 +0100 Subject: [PATCH 0019/1774] removed a flag by accident, fixed now --- devicehandlers/DeviceHandlerBase.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index c92cac332..3018a076f 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -1119,7 +1119,7 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data, // hiding of sender needed so the service will handle it as unexpected Data, no matter what state //(progress or completed) it is in - actionHelper.reportData(defaultRawReceiver, replyId, &wrapper); + actionHelper.reportData(defaultRawReceiver, replyId, &wrapper, true); } } else { //unrequested/aperiodic replies From cb919ada2a99b818624d05a4e4fdfeb85e9b8174 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 4 Nov 2019 01:55:40 +0100 Subject: [PATCH 0020/1774] assuming that a default value of 0 for expectedReplies is needed, I introduced a new variable into DeviceCommandInfo, which stores another number of replies expected. this value is assigned in enableReplyInReplyMap. That way, the initial value of 0 remains the same (if it was needed), and is only set to another desired value if a write was sent --- devicehandlers/DeviceHandlerBase.cpp | 5 +++-- devicehandlers/DeviceHandlerBase.h | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 3018a076f..491d792b5 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -285,7 +285,8 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, ReturnValue_t DeviceHandlerBase::insertInCommandMap( DeviceCommandId_t deviceCommand, uint8_t expectedReplies) { DeviceCommandInfo info; - info.expectedReplies = expectedReplies; + info.expectedReplies = 0; + info.expectedRepliesWhenEnablingReplyMap = expectedReplies; info.isExecuting = false; info.sendReplyTo = NO_COMMANDER; std::pair::iterator, bool> returnValue; @@ -821,7 +822,7 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( DeviceReplyInfo *info = &(iter->second); info->delayCycles = info->maxDelayCycles; info->command = command; - // command->second.expectedReplies = expectedReplies; + command->second.expectedReplies = command->second.expectedRepliesWhenEnablingReplyMap; return RETURN_OK; } else { return NO_REPLY_EXPECTED; diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 89f965036..ad4a22035 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -704,7 +704,8 @@ protected: struct DeviceCommandInfo { bool isExecuting; //!< Indicates if the command is already executing. - uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. + uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0. + uint8_t expectedRepliesWhenEnablingReplyMap; //!< Constant value which specifies expected replies when enabling reply map. Inititated in insertInCommandAndReplyMap() MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander. }; @@ -732,8 +733,12 @@ protected: * do not expect a reply. */ // Proposal: Set expected replies in insertInCommandAndReplyMap so we don't have to overwrite that function anymore. + // Replies are only checked when a write was issued and the default value here was one, so + // it should be possible to set this in the DeviceCommandMap with default value one. + // UPDATE: The default value of 0 when inserting into command and reply map is retained now by introducing a new + // variable in the DeviceCommandInfo which specifies expected replies if this function is called. virtual ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator cmd, - /* uint8_t expectedReplies = 0 */ bool useAlternateId = false, + /* uint8_t expectedReplies = 1, */ bool useAlternateId = false, DeviceCommandId_t alternateReplyID = 0); /** From e7f7625adf27263aec16580fa70ca137e412aef6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 4 Nov 2019 11:06:59 +0100 Subject: [PATCH 0021/1774] removed wrong include --- devicehandlers/DeviceHandlerBase.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 2f16f8462..1bb411b7d 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -11,7 +11,6 @@ #include #include #include -#include object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; From b594bc2a9719b6ffb99cb3fdaf4813c688576158 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Nov 2019 19:25:00 +0100 Subject: [PATCH 0022/1774] removed obsolete comment --- action/ActionHelper.h | 2 +- devicehandlers/DeviceHandlerBase.cpp | 28 ++++++++------------------ devicehandlers/DeviceHandlerBase.h | 19 +++++------------ modes/ModeHelper.h | 13 +----------- tmtcservices/CommandingServiceBase.cpp | 11 +++++----- 5 files changed, 21 insertions(+), 52 deletions(-) diff --git a/action/ActionHelper.h b/action/ActionHelper.h index a72e3654a..6ba6dd89b 100644 --- a/action/ActionHelper.h +++ b/action/ActionHelper.h @@ -74,7 +74,7 @@ public: protected: static const uint8_t STEP_OFFSET = 1;//!< Increase of value of this per step HasActionsIF* owner;//!< Pointer to the owner - MessageQueueIF* queueToUse;//!< Queue to be used as response sender, has to be set with @c setQueueToUse + MessageQueueIF* queueToUse;//!< Queue to be used as response sender, has to be set with StorageManagerIF* ipcStore;//!< Pointer to an IPC Store, initialized during construction or initialize(MessageQueueIF* queueToUse_) or with setQueueToUse(MessageQueueIF *queue) /** *Internal function called by handleActionMessage(CommandMessage* command) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 491d792b5..6150954d9 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -255,9 +255,9 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode, ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap( DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, - uint8_t periodic, uint8_t expectedReplies, bool hasDifferentReplyId, DeviceCommandId_t replyId) { - //No need to check, as we may try to insert multiple times. - insertInCommandMap(deviceCommand,expectedReplies); + uint8_t periodic, bool hasDifferentReplyId, DeviceCommandId_t replyId) { +//No need to check, as we may try to insert multiple times. + insertInCommandMap(deviceCommand); if (hasDifferentReplyId) { return insertInReplyMap(replyId, maxDelayCycles, periodic); } else { @@ -283,10 +283,9 @@ ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, } ReturnValue_t DeviceHandlerBase::insertInCommandMap( - DeviceCommandId_t deviceCommand, uint8_t expectedReplies) { + DeviceCommandId_t deviceCommand) { DeviceCommandInfo info; info.expectedReplies = 0; - info.expectedRepliesWhenEnablingReplyMap = expectedReplies; info.isExecuting = false; info.sendReplyTo = NO_COMMANDER; std::pair::iterator, bool> returnValue; @@ -713,7 +712,6 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData, DeviceCommandId_t foundId, uint32_t foundLen) { ReturnValue_t result; DeviceReplyMap::iterator iter = deviceReplyMap.find(foundId); - MessageQueueId_t commander; if (iter == deviceReplyMap.end()) { replyRawReplyIfnotWiretapped(receivedData, foundLen); @@ -730,17 +728,7 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData, } else { info->delayCycles = 0; } - - DeviceCommandMap::iterator commandIter = deviceCommandMap.find(foundId); - // could be a reply only packet - if(commandIter == deviceCommandMap.end()) { - commander = 0; - } - else { - commander = commandIter->second.sendReplyTo; - } - - result = interpretDeviceReply(foundId, receivedData,commander); + result = interpretDeviceReply(foundId, receivedData); if (result != RETURN_OK) { //Report failed interpretation to FDIR. replyRawReplyIfnotWiretapped(receivedData, foundLen); @@ -810,7 +798,7 @@ void DeviceHandlerBase::modeChanged(void) { } ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( - DeviceCommandMap::iterator command,/* uint8_t expectedReplies, */ + DeviceCommandMap::iterator command, uint8_t expectedReplies, bool useAlternativeId, DeviceCommandId_t alternativeReply) { DeviceReplyMap::iterator iter; if (useAlternativeId) { @@ -822,7 +810,7 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( DeviceReplyInfo *info = &(iter->second); info->delayCycles = info->maxDelayCycles; info->command = command; - command->second.expectedReplies = command->second.expectedRepliesWhenEnablingReplyMap; + command->second.expectedReplies = expectedReplies; return RETURN_OK; } else { return NO_REPLY_EXPECTED; @@ -1133,7 +1121,7 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data, true); } } - //Try to cast to DataSet and commit data. +//Try to cast to DataSet and commit data. if (!neverInDataPool) { DataSet* dataSet = dynamic_cast(data); if (dataSet != NULL) { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index ad4a22035..040c21903 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -576,9 +576,8 @@ protected: * Default is aperiodic (0) * @return RETURN_OK when the command was successfully inserted, COMMAND_MAP_ERROR else. */ - // Proposal: Set expected replies for a command in insertInCommandAndReplyMap so we don't have to overwrite enableReplyInReplyMap ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, - uint16_t maxDelayCycles, uint8_t periodic = 0, uint8_t expectedReplies = 1, + uint16_t maxDelayCycles, uint8_t periodic = 0, bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0); /** * This is a helper method to insert replies in the reply map. @@ -595,7 +594,7 @@ protected: * @param deviceCommand The command to add * @return RETURN_OK if the command was successfully inserted, RETURN_FAILED else. */ - ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand, uint8_t expectedReplies = 1); + ReturnValue_t insertInCommandMap(DeviceCommandId_t deviceCommand); /** * This is a helper method to facilitate updating entries in the reply map. * @param deviceCommand Identifier of the reply to update. @@ -645,19 +644,17 @@ protected: * * This is called after scanForReply() found a valid packet, it can be assumed that the length and structure is valid. * This routine extracts the data from the packet into a DataSet and then calls handleDeviceTM(), which either sends - * a TM packet or stores the data in the DataPool depending on whether it was an external command. + * a TM packet or stores the data in the DataPool depending on whether the it was an external command. * No packet length is given, as it should be defined implicitly by the id. * * @param id the id found by scanForReply() * @param packet - * @param commander the one who initiated the command, is 0 if not external commanded. - * UPDATE: This parameter does not exist anymore. Why? * @return * - @c RETURN_OK when the reply was interpreted. * - @c RETURN_FAILED when the reply could not be interpreted, eg. logical errors or range violations occurred */ virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet, MessageQueueId_t commander = 0) = 0; + const uint8_t *packet) = 0; /** * Construct a command reply containing a raw reply. @@ -726,19 +723,13 @@ protected: * - If the command was not found in the reply map, NO_REPLY_EXPECTED MUST be returned. * - A failure code may be returned if something went fundamentally wrong. * - * * @param deviceCommand * @return - RETURN_OK if a reply was activated. * - NO_REPLY_EXPECTED if there was no reply found. This is not an error case as many commands * do not expect a reply. */ - // Proposal: Set expected replies in insertInCommandAndReplyMap so we don't have to overwrite that function anymore. - // Replies are only checked when a write was issued and the default value here was one, so - // it should be possible to set this in the DeviceCommandMap with default value one. - // UPDATE: The default value of 0 when inserting into command and reply map is retained now by introducing a new - // variable in the DeviceCommandInfo which specifies expected replies if this function is called. virtual ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator cmd, - /* uint8_t expectedReplies = 1, */ bool useAlternateId = false, + uint8_t expectedReplies = 1, bool useAlternateId = false, DeviceCommandId_t alternateReplyID = 0); /** diff --git a/modes/ModeHelper.h b/modes/ModeHelper.h index b23eb69e5..87f6d4112 100644 --- a/modes/ModeHelper.h +++ b/modes/ModeHelper.h @@ -16,17 +16,11 @@ public: ModeHelper(HasModesIF *owner); virtual ~ModeHelper(); - /** - * This is used by DHB to handle all mode messages issued by a service - * @param message - * @return - */ ReturnValue_t handleModeCommand(CommandMessage *message); /** * - * @param parentQueue the Queue id of the parent object (assembly or subsystem object). - * Set to 0 if no parent present + * @param parentQueue the Queue id of the parent object. Set to 0 if no parent present */ void setParentQueue(MessageQueueId_t parentQueueId); @@ -34,11 +28,6 @@ public: ReturnValue_t initialize(void); //void is there to stop eclipse CODAN from falsely reporting an error - /** - * Used to notify - * @param mode - * @param submode - */ void modeChanged(Mode_t mode, Submode_t submode); void startTimer(uint32_t timeoutMs); diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index ec65492de..d70b90428 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -11,11 +11,12 @@ CommandingServiceBase::CommandingServiceBase(object_id_t setObjectId, uint16_t apid, uint8_t service, uint8_t numberOfParallelCommands, uint16_t commandTimeout_seconds, object_id_t setPacketSource, object_id_t setPacketDestination, size_t queueDepth) : - SystemObject(setObjectId), apid(apid), service(service), - timeout_seconds(commandTimeout_seconds), tmPacketCounter(0), IPCStore(NULL), - TCStore(NULL), commandQueue(NULL), requestQueue(NULL), commandMap(numberOfParallelCommands), - failureParameter1(0), failureParameter2(0), packetSource(setPacketSource), - packetDestination(setPacketDestination),executingTask(NULL) { + SystemObject(setObjectId), apid(apid), service(service), timeout_seconds( + commandTimeout_seconds), tmPacketCounter(0), IPCStore(NULL), TCStore( + NULL), commandQueue(NULL), requestQueue(NULL), commandMap( + numberOfParallelCommands), failureParameter1(0), failureParameter2( + 0), packetSource(setPacketSource), packetDestination( + setPacketDestination),executingTask(NULL) { commandQueue = QueueFactory::instance()->createMessageQueue(queueDepth); requestQueue = QueueFactory::instance()->createMessageQueue(queueDepth); } From bf7bc342ff2bb816d910bd2c142661fecd25c867 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 5 Nov 2019 19:30:02 +0100 Subject: [PATCH 0023/1774] Revert "documentation for DHB init function, ioBoard addres has default value 0 now, order in ctor changed (not used in source)" This reverts commit c6e34cada64f59757e420347dec8373401d73c7a. --- devicehandlers/ChildHandlerBase.cpp | 4 ++-- devicehandlers/DeviceHandlerBase.cpp | 9 +++++---- devicehandlers/DeviceHandlerBase.h | 21 +++------------------ 3 files changed, 10 insertions(+), 24 deletions(-) diff --git a/devicehandlers/ChildHandlerBase.cpp b/devicehandlers/ChildHandlerBase.cpp index fb9238f7e..50a5c07e5 100644 --- a/devicehandlers/ChildHandlerBase.cpp +++ b/devicehandlers/ChildHandlerBase.cpp @@ -7,8 +7,8 @@ ChildHandlerBase::ChildHandlerBase(uint32_t ioBoardAddress, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t parent, FailureIsolationBase* customFdir, uint32_t cmdQueueSize) : - DeviceHandlerBase(setObjectId, maxDeviceReplyLen, - setDeviceSwitch, deviceCommunication,ioBoardAddress, thermalStatePoolId, + DeviceHandlerBase(ioBoardAddress, setObjectId, maxDeviceReplyLen, + setDeviceSwitch, deviceCommunication, thermalStatePoolId, thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir), cmdQueueSize), parentId( parent), childHandlerFdir(setObjectId) { } diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 6150954d9..def9a7245 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -16,10 +16,11 @@ object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; -DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, - uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, - object_id_t deviceCommunication, uint32_t ioBoardAddress, uint32_t thermalStatePoolId, - uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : +DeviceHandlerBase::DeviceHandlerBase(uint32_t ioBoardAddress, + object_id_t setObjectId, uint32_t maxDeviceReplyLen, + uint8_t setDeviceSwitch, object_id_t deviceCommunication, + uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, + FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : SystemObject(setObjectId),ioBoardAddress(ioBoardAddress), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen(maxDeviceReplyLen), wiretappingMode(OFF), defaultRawReceiver(0), storedRawData(StorageManagerIF::INVALID_ADDRESS), diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 040c21903..03e35727e 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -76,10 +76,10 @@ public: * @param maxDeviceReplyLen the length the RMAP getRead call will be sent with * @param setDeviceSwitch the switch the device is connected to, for devices using two switches, overwrite getSwitches() */ - DeviceHandlerBase(object_id_t setObjectId, + DeviceHandlerBase(uint32_t ioBoardAddress, object_id_t setObjectId, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, - object_id_t deviceCommunication,uint32_t ioBoardAddress = 0, - uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, + object_id_t deviceCommunication, uint32_t thermalStatePoolId = + PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, FailureIsolationBase* fdirInstance = NULL, uint32_t cmdQueueSize = 20); @@ -116,21 +116,6 @@ public: */ virtual ReturnValue_t performOperation(uint8_t counter); - /** - * Prerequisites to call initialize function without custom implementation: - * 1. The three static framework IDs are set to respective objects in the Factory function - * - First ID: Power Switcher ID. Example: PCDU Handler Object - * - Second ID: Raw Data Receiver. Example: PUS Service 2 Object - * - Third ID: Default FDIR parent ID. Example: ? - * 2. Communication Interface Object for respective device. - * Example: UART Communication Interface which calls respective UART drivers - * 3. Health table class has been instantiated in Factory - * 4. deviceThermalRequestPoolId and deviceThermalStatePoolId are set to the respective data pool entries. - * This is only required if thermal checking is needed. Otherwise, set both variables to - * PoolVariableIF::NO_PARAMETER - * - * @return - */ virtual ReturnValue_t initialize(); /** From 801bd4d7ebce3ce32eab46e561dec5bc95401c4a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 9 Nov 2019 13:07:26 +0100 Subject: [PATCH 0024/1774] debug interface for dhb created. This is useful to track states or values in child handler. some documentation added. New doxygen group for interfaced added. --- action/HasActionsIF.h | 6 +++++- devicehandlers/DeviceHandlerBase.cpp | 8 ++++++-- devicehandlers/DeviceHandlerBase.h | 12 ++++++++++++ events/EventManager.cpp | 7 ++++--- modes/ModeHelper.cpp | 2 +- power/PowerSwitchIF.h | 9 +++++++-- 6 files changed, 35 insertions(+), 9 deletions(-) diff --git a/action/HasActionsIF.h b/action/HasActionsIF.h index f30fcb45e..4d66ad1f6 100644 --- a/action/HasActionsIF.h +++ b/action/HasActionsIF.h @@ -7,8 +7,10 @@ #include #include /** - * \brief Interface for component which uses actions + * @brief + * Interface for component which uses actions * + * @details * This interface is used to execute actions in the component. Actions, in the sense of this interface, are activities with a well-defined beginning and * end in time. They may adjust sub-states of components, but are not supposed to change * the main mode of operation, which is handled with the HasModesIF described below. @@ -23,6 +25,8 @@ * parameters and immediately start execution of the action. It is, however, not required to * immediately finish execution. Instead, this may be deferred to a later point in time, at * which the component needs to inform the caller about finished or failed execution. + * + * \ingroup interfaces */ class HasActionsIF { public: diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index def9a7245..35a987f33 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -834,8 +834,9 @@ ReturnValue_t DeviceHandlerBase::getStateOfSwitches(void) { ReturnValue_t result = getSwitches(&switches, &numberOfSwitches); if ((result == RETURN_OK) && (numberOfSwitches != 0)) { while (numberOfSwitches > 0) { - if (powerSwitcher->getSwitchState(switches[numberOfSwitches - 1]) - == PowerSwitchIF::SWITCH_OFF) { + if (powerSwitcher-> getSwitchState(switches[numberOfSwitches - 1]) + == PowerSwitchIF::SWITCH_OFF) + { return PowerSwitchIF::SWITCH_OFF; } numberOfSwitches--; @@ -1267,4 +1268,7 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){ executingTask = task_; } +void DeviceHandlerBase::debugInterface(uint8_t positionTracker) { +} + diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 03e35727e..4938e0196 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -553,6 +553,18 @@ protected: */ virtual void fillCommandAndReplyMap() = 0; + + /** + * @brief Can be implemented by child handler to + * perform debugging + * @details Example: Calling this in performOperation + * to track values like mode. An optional position tracker can be supplied + * to provide the child handler a way to know where the debugInterface was called + * + * Please delete all debugInterface calls in DHB after debugging is finished ! + */ + virtual void debugInterface(uint8_t positionTracker = 0); + /** * This is a helper method to facilitate inserting entries in the command map. * @param deviceCommand Identifier of the command to add. diff --git a/events/EventManager.cpp b/events/EventManager.cpp index 01334bac9..46c537520 100644 --- a/events/EventManager.cpp +++ b/events/EventManager.cpp @@ -137,9 +137,10 @@ void EventManager::printEvent(EventMessage* message) { error << "0x" << std::hex << message->getReporter() << std::dec; } error << " reported " << translateEvents(message->getEvent()) << " (" - << std::dec << message->getEventId() << std::hex << ") P1: 0x" - << message->getParameter1() << " P2: 0x" - << message->getParameter2() << std::dec << std::endl; + << std::dec << message->getEventId() << ") " << std::endl; + + error << std::hex << "P1 Hex: 0x" << message->getParameter1() << ", P1 Dec: " << std::dec << message->getParameter1() << std::endl; + error << std::hex << "P2 Hex: 0x" << message->getParameter2() << ", P2 Dec: " << std::dec << message->getParameter2() << std::endl; break; } diff --git a/modes/ModeHelper.cpp b/modes/ModeHelper.cpp index 7b98bdc64..d9266c354 100644 --- a/modes/ModeHelper.cpp +++ b/modes/ModeHelper.cpp @@ -1,6 +1,7 @@ #include #include #include +#include ModeHelper::ModeHelper(HasModesIF *owner) : theOneWhoCommandedAMode(0), commandedMode(HasModesIF::MODE_OFF), commandedSubmode( @@ -42,7 +43,6 @@ ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* message) { } countdown.setTimeout(timeout); - owner->startTransition(mode, submode); } break; diff --git a/power/PowerSwitchIF.h b/power/PowerSwitchIF.h index 1c4c06f7f..f25589c4d 100644 --- a/power/PowerSwitchIF.h +++ b/power/PowerSwitchIF.h @@ -11,8 +11,13 @@ #include #include /** - * This interface defines a connection to a device that is capable of turning on and off - * switches of devices identified by a switch ID. + * + * @brief This interface defines a connection to a device that is capable of turning on and off + * switches of devices identified by a switch ID. + * @details The virtual functions of this interface do not allow to make any assignments + * because they can be called asynchronosuly (const ending). + * + * @ingroup interfaces */ class PowerSwitchIF : public HasReturnvaluesIF { public: From ee765eafc766d9a4a1053d3d685d7d63e6f9f95f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 9 Nov 2019 13:17:54 +0100 Subject: [PATCH 0025/1774] ioBoardAddress renamed to logicalAddress --- devicehandlers/DeviceHandlerBase.cpp | 8 ++++---- devicehandlers/DeviceHandlerBase.h | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 35a987f33..fd8d61410 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -16,12 +16,12 @@ object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; -DeviceHandlerBase::DeviceHandlerBase(uint32_t ioBoardAddress, +DeviceHandlerBase::DeviceHandlerBase(uint32_t logicalAddress_, object_id_t setObjectId, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, object_id_t deviceCommunication, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : - SystemObject(setObjectId),ioBoardAddress(ioBoardAddress), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), + SystemObject(setObjectId),logicalAddress(logicalAddress_), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen(maxDeviceReplyLen), wiretappingMode(OFF), defaultRawReceiver(0), storedRawData(StorageManagerIF::INVALID_ADDRESS), requestedRawTraffic(0), powerSwitcher(NULL), IPCStore(NULL), @@ -589,7 +589,7 @@ ReturnValue_t DeviceHandlerBase::initialize() { return RETURN_FAILED; } - result = communicationInterface->open(&cookie, ioBoardAddress, + result = communicationInterface->open(&cookie, logicalAddress, maxDeviceReplyLen); if (result != RETURN_OK) { return result; @@ -750,7 +750,7 @@ ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) { DeviceCommunicationIF>(newChannelId); if (newCommunication != NULL) { - ReturnValue_t result = newCommunication->reOpen(cookie, ioBoardAddress, + ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress, maxDeviceReplyLen); if (result != RETURN_OK) { return result; diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 4938e0196..8f7f065a4 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -76,7 +76,7 @@ public: * @param maxDeviceReplyLen the length the RMAP getRead call will be sent with * @param setDeviceSwitch the switch the device is connected to, for devices using two switches, overwrite getSwitches() */ - DeviceHandlerBase(uint32_t ioBoardAddress, object_id_t setObjectId, + DeviceHandlerBase(uint32_t logicalAddress, object_id_t setObjectId, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, object_id_t deviceCommunication, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, @@ -149,7 +149,7 @@ protected: /** * cached from ctor for initialize() */ - const uint32_t ioBoardAddress; + const uint32_t logicalAddress; /** * The Returnvalues id of this class, required by HasReturnvaluesIF From 537e2ceb18ddd360176fddec37331bb952f8c674 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 9 Nov 2019 13:29:12 +0100 Subject: [PATCH 0026/1774] Getter method for logicalAddress --- devicehandlers/DeviceHandlerBase.cpp | 9 ++++++--- devicehandlers/DeviceHandlerBase.h | 17 +++++++++++------ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index fd8d61410..09c27c87d 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -21,7 +21,7 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t logicalAddress_, uint8_t setDeviceSwitch, object_id_t deviceCommunication, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : - SystemObject(setObjectId),logicalAddress(logicalAddress_), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), + SystemObject(setObjectId), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen(maxDeviceReplyLen), wiretappingMode(OFF), defaultRawReceiver(0), storedRawData(StorageManagerIF::INVALID_ADDRESS), requestedRawTraffic(0), powerSwitcher(NULL), IPCStore(NULL), @@ -31,7 +31,7 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t logicalAddress_, modeHelper(this), parameterHelper(this), childTransitionFailure(RETURN_OK), ignoreMissedRepliesCount(0), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed(fdirInstance == NULL), switchOffWasReported(false), - executingTask(NULL), actionHelper(this, NULL), cookieInfo(), + executingTask(NULL), actionHelper(this, NULL), cookieInfo(), logicalAddress(logicalAddress_), timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, @@ -1018,6 +1018,7 @@ void DeviceHandlerBase::replyRawReplyIfnotWiretapped(const uint8_t* data, } } + ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage( CommandMessage * message) { ReturnValue_t result; @@ -1271,4 +1272,6 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){ void DeviceHandlerBase::debugInterface(uint8_t positionTracker) { } - +uint32_t DeviceHandlerBase::getLogicalAddress() { + return logicalAddress; +} diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 8f7f065a4..4c83b230d 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -146,11 +146,6 @@ public: */ virtual void setTaskIF(PeriodicTaskIF* task_); protected: - /** - * cached from ctor for initialize() - */ - const uint32_t logicalAddress; - /** * The Returnvalues id of this class, required by HasReturnvaluesIF */ @@ -763,6 +758,11 @@ protected: */ virtual bool dontCheckQueue(); + /** + * Used to retrieve logical address + * @return + */ + virtual uint32_t getLogicalAddress(); Mode_t getBaseMode(Mode_t transitionMode); bool isAwaitingReply(); @@ -775,7 +775,6 @@ protected: virtual void startTransition(Mode_t mode, Submode_t submode); virtual void setToExternalControl(); virtual void announceMode(bool recursive); - virtual ReturnValue_t letChildHandleMessage(CommandMessage *message); /** @@ -862,6 +861,8 @@ protected: private: + + /** * State a cookie is in. * @@ -892,6 +893,10 @@ private: */ CookieInfo cookieInfo; + /** + * cached from ctor for initialize() + */ + const uint32_t logicalAddress; /** * Used for timing out mode transitions. From b8af3b5e3df66e67c8fa7e0e99b6d5b2554deef4 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 9 Nov 2019 18:15:45 +0100 Subject: [PATCH 0027/1774] debugInterface extended --- devicehandlers/DeviceHandlerBase.cpp | 14 +++++++------- devicehandlers/DeviceHandlerBase.h | 9 +++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 09c27c87d..92232e3d4 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -33,14 +33,15 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t logicalAddress_, defaultFDIRUsed(fdirInstance == NULL), switchOffWasReported(false), executingTask(NULL), actionHelper(this, NULL), cookieInfo(), logicalAddress(logicalAddress_), timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), - transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { - commandQueue = QueueFactory::instance()->createMessageQueue(cmdQueueSize, - CommandMessage::MAX_MESSAGE_SIZE); + transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) +{ + commandQueue = QueueFactory::instance()-> + createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); cookieInfo.state = COOKIE_UNUSED; insertInCommandMap(RAW_COMMAND_ID); if (this->fdirInstance == NULL) { - this->fdirInstance = new DeviceHandlerFailureIsolation(setObjectId, - defaultFDIRParentId); + this->fdirInstance = + new DeviceHandlerFailureIsolation(setObjectId, defaultFDIRParentId); } } @@ -468,7 +469,6 @@ void DeviceHandlerBase::doGetWrite() { void DeviceHandlerBase::doSendRead() { ReturnValue_t result; - result = communicationInterface->requestReceiveMessage(cookie); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; @@ -1269,7 +1269,7 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){ executingTask = task_; } -void DeviceHandlerBase::debugInterface(uint8_t positionTracker) { +void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t objectId, uint32_t parameter) { } uint32_t DeviceHandlerBase::getLogicalAddress() { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 4c83b230d..c50823d92 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -553,12 +553,13 @@ protected: * @brief Can be implemented by child handler to * perform debugging * @details Example: Calling this in performOperation - * to track values like mode. An optional position tracker can be supplied - * to provide the child handler a way to know where the debugInterface was called - * + * to track values like mode. + * @param positionTracker Provide the child handler a way to know where the debugInterface was called + * @param objectId Provide the child handler object Id to specify actions for spefic devices + * @param parameter Supply a parameter of interest * Please delete all debugInterface calls in DHB after debugging is finished ! */ - virtual void debugInterface(uint8_t positionTracker = 0); + virtual void debugInterface(uint8_t positionTracker = 0, object_id_t objectId = 0, uint32_t parameter = 0); /** * This is a helper method to facilitate inserting entries in the command map. From 2b44e1c9c4aa5e516114a6adb922e860c5044417 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 10 Nov 2019 13:08:02 +0100 Subject: [PATCH 0028/1774] CCSDS sscanf function adapted for atmel stdio.c (see comments) --- timemanager/CCSDSTime.cpp | 43 +++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index 320327161..2eb6c4b54 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -154,32 +154,41 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* if (length < 19) { return RETURN_FAILED; } - uint16_t year; - uint8_t month; - uint16_t day; - uint8_t hour; - uint8_t minute; - float second; -//try Code A (yyyy-mm-dd) - int count = sscanf((char *) from, "%4hi-%2hhi-%2hiT%2hhi:%2hhi:%fZ", &year, - &month, &day, &hour, &minute, &second); - if (count == 6) { + // In the size optimized nano library used by ATMEL, floating point conversion + // is not allowed. There is a linker flag to allow it apparently, but I + // could not manage to make it run (removing -specs=nano.specs in linker flags works though, + // but we propably should include this). Using floats with sscanf is also expensive. + // Furthermore, the stdio.c library by ATMEL can't resolve the %hhi specifiers + // Therefore, I adapted this function. + int year; + int month; + int day; + int hour; + int minute; + int second; + int usecond; + // try Code A (yyyy-mm-dd) + //int count = sscanf((char *) from, "%4hi-%2hi-%2hiT%2hi:%2hi:%fZ", &year, + // &month, &day, &hour, &minute, &second); + int count = sscanf((char *) from, "%4d-%2d-%2dT%2d:%2d:%2d.%dZ", &year, + &month, &day, &hour, &minute, &second, &usecond); + if (count == 7) { to->year = year; to->month = month; to->day = day; to->hour = hour; to->minute = minute; to->second = second; - to->usecond = (second - floor(second)) * 1000000; + to->usecond = usecond;//(second - floor(second)) * 1000000; return RETURN_OK; } - //try Code B (yyyy-ddd) - count = sscanf((char *) from, "%4hi-%3hiT%2hhi:%2hhi:%fZ", &year, &day, - &hour, &minute, &second); - if (count == 5) { + // try Code B (yyyy-ddd) + count = sscanf((char *) from, "%4i-%3iT%2i:%2i:%2i.%iZ", &year, &day, + &hour, &minute, &second, &usecond); + if (count == 6) { uint8_t tempDay; - ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year, &month, + ReturnValue_t result = CCSDSTime::convertDaysOfYear((uint16_t)day,(uint16_t) year,(uint8_t *) &month, &tempDay); if (result != RETURN_OK) { return RETURN_FAILED; @@ -190,7 +199,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* to->hour = hour; to->minute = minute; to->second = second; - to->usecond = (second - floor(second)) * 1000000; + to->usecond = usecond; return RETURN_OK; } From 2f14fd5d4d67d2b8223b115d2c5d421cccecffb5 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 11 Nov 2019 22:45:53 +0100 Subject: [PATCH 0029/1774] Cant reach mode reason getter function added --- modes/ModeMessage.cpp | 4 ++++ modes/ModeMessage.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/modes/ModeMessage.cpp b/modes/ModeMessage.cpp index 62fea7e43..1d3baad54 100644 --- a/modes/ModeMessage.cpp +++ b/modes/ModeMessage.cpp @@ -16,6 +16,10 @@ ReturnValue_t ModeMessage::setModeMessage(CommandMessage* message, Command_t com return HasReturnvaluesIF::RETURN_OK; } +ReturnValue_t ModeMessage::getCantReachModeReason(const CommandMessage* message) { + return message->getParameter(); +} + void ModeMessage::clear(CommandMessage* message) { message->setCommand(CommandMessage::CMD_NONE); } diff --git a/modes/ModeMessage.h b/modes/ModeMessage.h index fad347264..0a72aee04 100644 --- a/modes/ModeMessage.h +++ b/modes/ModeMessage.h @@ -24,6 +24,7 @@ public: static const Command_t REPLY_MODE_INFO = MAKE_COMMAND_ID(0x03); //!> Unrequested info about the current mode (used for composites to inform their container of a changed mode) static const Command_t REPLY_CANT_REACH_MODE = MAKE_COMMAND_ID(0x04); //!> Reply in case a mode command can't be executed. Par1: returnCode, Par2: 0 //SHOULDDO is there a way we can transmit a returnvalue when responding that the mode is wrong, so we can give a nice failure code when commanded by PUS? + // shouldn't that possible with parameter 2 when submode only takes 1 byte? static const Command_t REPLY_WRONG_MODE_REPLY = MAKE_COMMAND_ID(0x05);//!> Reply to a CMD_MODE_COMMAND, indicating that a mode was commanded and a transition started but was aborted; the parameters contain the mode that was reached static const Command_t CMD_MODE_READ = MAKE_COMMAND_ID(0x06);//!> Command to read the current mode and reply with a REPLY_MODE_REPLY static const Command_t CMD_MODE_ANNOUNCE = MAKE_COMMAND_ID(0x07);//!> Command to trigger an ModeInfo Event. This command does NOT have a reply. @@ -34,6 +35,7 @@ public: static ReturnValue_t setModeMessage(CommandMessage* message, Command_t command, Mode_t mode, Submode_t submode); static void cantReachMode(CommandMessage* message, ReturnValue_t reason); + static ReturnValue_t getCantReachModeReason(const CommandMessage* message); static void clear(CommandMessage* message); }; From 2039aa56658923cb4127fddb409c251fdb8d55af Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 25 Nov 2019 00:14:39 +0100 Subject: [PATCH 0030/1774] Service Interface Stream buffer size higher to print long buffers (like nav data) --- serviceinterface/ServiceInterfaceBuffer.h | 2 +- tmtcservices/PusServiceBase.cpp | 10 +++++----- tmtcservices/PusServiceBase.h | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/serviceinterface/ServiceInterfaceBuffer.h b/serviceinterface/ServiceInterfaceBuffer.h index b42c8a197..9a5f4ef8e 100644 --- a/serviceinterface/ServiceInterfaceBuffer.h +++ b/serviceinterface/ServiceInterfaceBuffer.h @@ -30,7 +30,7 @@ private: typedef std::char_traits Traits; // Work in buffer mode. It is also possible to work without buffer. - static size_t const BUF_SIZE = 128; + static size_t const BUF_SIZE = 255; char buf[BUF_SIZE]; // In this function, the characters are parsed. diff --git a/tmtcservices/PusServiceBase.cpp b/tmtcservices/PusServiceBase.cpp index c8f6accf8..6e1053252 100644 --- a/tmtcservices/PusServiceBase.cpp +++ b/tmtcservices/PusServiceBase.cpp @@ -23,14 +23,14 @@ ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { TmTcMessage message; for (uint8_t count = 0; count < PUS_SERVICE_MAX_RECEPTION; count++) { ReturnValue_t status = this->requestQueue->receiveMessage(&message); - // debug << "PusServiceBase::performOperation: Receiving from MQ ID: " << std::hex << this->requestQueue.getId() << std::dec << " returned: " << status << std::endl; + // debug << "PusServiceBase::performOperation: Receiving from MQ ID: " << std::hex << this->requestQueue.getId() + // << std::dec << " returned: " << status << std::endl; if (status == RETURN_OK) { this->currentPacket.setStoreAddress(message.getStorageId()); -// info << "Service " << (uint16_t) this->serviceId << ": new packet!" -// << std::endl; + // info << "Service " << (uint16_t) this->serviceId << ": new packet!" << std::endl; ReturnValue_t return_code = this->handleRequest(); - // debug << "Service " << (uint16_t)this->serviceId << ": handleRequest returned: " << (int)return_code << std::endl; + // debug << "Service " << (uint16_t)this->serviceId << ": handleRequest returned: " << (int)return_code << std::endl; if (return_code == RETURN_OK) { this->verifyReporter.sendSuccessReport( TC_VERIFY::COMPLETION_SUCCESS, &this->currentPacket); @@ -44,7 +44,7 @@ ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { errorParameter2 = 0; } else if (status == MessageQueueIF::EMPTY) { status = RETURN_OK; - // debug << "PusService " << (uint16_t)this->serviceId << ": no new packet." << std::endl; + // debug << "PusService " << (uint16_t)this->serviceId << ": no new packet." << std::endl; break; } else { diff --git a/tmtcservices/PusServiceBase.h b/tmtcservices/PusServiceBase.h index 4fe13ca91..2b5e8b67c 100644 --- a/tmtcservices/PusServiceBase.h +++ b/tmtcservices/PusServiceBase.h @@ -52,7 +52,7 @@ public: * Success or Failure Reports are generated automatically after execution of this method. * If a Telecommand can not be executed within one call cycle, this Base class is not the right parent. * The child class may add additional error information in #errorParameters which are attached to the generated - * verification message. + * verification message. Subservice checking should be implemented in this method. * @return The returned status_code is directly taken as main error code in the Verification Report. * On success, RETURN_OK shall be returned. */ From 10c24e39a31293ba54ee8bfdbb2f3835b91dad9e Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 29 Nov 2019 19:56:05 +0100 Subject: [PATCH 0031/1774] new returnvalue for scanForReply to ignore full packet --- devicehandlers/DeviceCommunicationIF.h | 6 ++++-- devicehandlers/DeviceHandlerBase.cpp | 2 ++ devicehandlers/DeviceHandlerBase.h | 14 +++++++++----- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 59420861e..10ad27760 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -62,7 +62,8 @@ public: * @param cookie * @param data * @param len - * @return + * @return @c RETURN_OK for successfull send + * Everything else triggers sending failed event with returnvalue as parameter 1 */ virtual ReturnValue_t sendMessage(Cookie *cookie,const uint8_t *data, uint32_t len) = 0; @@ -78,7 +79,8 @@ public: * @param cookie * @param data * @param len - * @return + * @return @c RETURN_OK for successfull receive + * Everything else triggers receiving failed with returnvalue as parameter 1 */ virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, uint32_t *size) = 0; diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 92232e3d4..0b35effd5 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -537,6 +537,8 @@ void DeviceHandlerBase::doGetRead() { break; case IGNORE_REPLY_DATA: break; + case IGNORE_FULL_PACKET: + return; default: //We need to wait for timeout.. don't know what command failed and who sent it. replyRawReplyIfnotWiretapped(receivedData, foundLen); diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index c50823d92..b5ffa2eec 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -153,7 +153,8 @@ protected: static const ReturnValue_t INVALID_CHANNEL = MAKE_RETURN_CODE(4); static const ReturnValue_t APERIODIC_REPLY = MAKE_RETURN_CODE(5); //!< This is used to specify for replies from a device which are not replies to requests - static const ReturnValue_t IGNORE_REPLY_DATA = MAKE_RETURN_CODE(6); + static const ReturnValue_t IGNORE_REPLY_DATA = MAKE_RETURN_CODE(6); //!< Ignore parts of the received packet + static const ReturnValue_t IGNORE_FULL_PACKET = MAKE_RETURN_CODE(7); //!< Ignore full received packet // static const ReturnValue_t ONE_SWITCH = MAKE_RETURN_CODE(8); // static const ReturnValue_t TWO_SWITCHES = MAKE_RETURN_CODE(9); static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(10); @@ -607,6 +608,7 @@ protected: * @return The current delay count. If the command does not exist (should never happen) it returns 0. */ uint8_t getReplyDelayCycles(DeviceCommandId_t deviceCommand); + /** * Scans a buffer for a valid reply. * @@ -618,15 +620,17 @@ protected: * Errors should be reported directly, the base class does NOT report any errors based on the return * value of this function. * - * @param start start of data - * @param len length of data - * @param[out] foundId the id of the packet starting at @c start - * @param[out] foundLen length of the packet found + * @param start start of remaining buffer to be scanned + * @param len length of remaining buffer to be scanned + * @param[out] foundId the id of the data found in the buffer. + * @param[out] foundLen length of the data found. Is to be set in function, buffer is scanned at previous position + foundLen. * @return * - @c RETURN_OK a valid packet was found at @c start, @c foundLen is valid * - @c RETURN_FAILED no reply could be found starting at @c start, implies @c foundLen is not valid, base class will call scanForReply() again with ++start * - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid, eg checksum error, implies @c foundLen is valid, can be used to skip some bytes * - @c DeviceHandlerIF::LENGTH_MISSMATCH @c len is invalid + * - @c DeviceHandlerIF::IGNORE_REPLY_DATA Ignore this specific part of the packet + * - @c DeviceHandlerIF::IGNORE_FULL_PACKET Ignore the packet * - @c APERIODIC_REPLY if a valid reply is received that has not been requested by a command, but should be handled anyway (@see also fillCommandAndCookieMap() ) */ virtual ReturnValue_t scanForReply(const uint8_t *start, uint32_t len, From 37a70df24496dd0924969c4f52c960ed80d5a1d1 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 1 Dec 2019 17:48:05 +0100 Subject: [PATCH 0032/1774] SerialBufferAdapter can process uint32_t * buffers now --- datapool/DataPool.h | 2 +- internalError/InternalErrorReporter.cpp | 7 +++--- serialize/SerialBufferAdapter.cpp | 13 ++++++++-- serialize/SerialBufferAdapter.h | 33 ++++++++++++++++++++++--- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/datapool/DataPool.h b/datapool/DataPool.h index 6e38dc1b9..a9af8af0b 100644 --- a/datapool/DataPool.h +++ b/datapool/DataPool.h @@ -29,7 +29,7 @@ * \brief This class represents the OBSW global data-pool. * * \details All variables are registered and space is allocated in an initialization - * function, which is passed do the constructor. + * function, which is passed to the constructor. * Space for the variables is allocated on the heap (with a new call). * The data is found by a data pool id, which uniquely represents a variable. * Data pool variables should be used with a blackboard logic in mind, diff --git a/internalError/InternalErrorReporter.cpp b/internalError/InternalErrorReporter.cpp index 9a8ede002..81c4a0e58 100644 --- a/internalError/InternalErrorReporter.cpp +++ b/internalError/InternalErrorReporter.cpp @@ -8,10 +8,9 @@ InternalErrorReporter::InternalErrorReporter(object_id_t setObjectId, uint32_t queuePoolId, uint32_t tmPoolId, uint32_t storePoolId) : - SystemObject(setObjectId), mutex(NULL), queuePoolId(queuePoolId), tmPoolId( - tmPoolId), storePoolId( - storePoolId), queueHits(0), tmHits(0), storeHits( - 0) { + SystemObject(setObjectId), mutex(NULL), queuePoolId(queuePoolId), + tmPoolId(tmPoolId),storePoolId(storePoolId), queueHits(0), tmHits(0), + storeHits(0) { mutex = MutexFactory::instance()->createMutex(); } diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index c5fcfb57e..9a8e6f069 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -1,8 +1,6 @@ #include #include - - template SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, T bufferLength, bool serializeLength) : @@ -17,6 +15,13 @@ SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, T bufferLength, bufferLength) { } +template +SerialBufferAdapter::SerialBufferAdapter(uint32_t* buffer, + T bufferLength, bool serializeLength) : + serializeLength(serializeLength), constBuffer(NULL), buffer(reinterpret_cast(buffer)), + bufferLength(bufferLength*4) { +} + template SerialBufferAdapter::~SerialBufferAdapter() { } @@ -86,6 +91,10 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, } } +template +uint8_t * SerialBufferAdapter::getBuffer() { + return buffer; +} //forward Template declaration for linker template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 7d192bb45..7496c1376 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -11,16 +11,39 @@ * Additionally, the buffer length can be serialized too and will be put in front of the serialized buffer. * * Can be used with SerialLinkedListAdapter by declaring a SerializeElement with - * SerialElement> serialBufferElement + * SerialElement> serialBufferElement * * \ingroup serialize */ template class SerialBufferAdapter: public SerializeIF { public: - SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLenght = false); - SerialBufferAdapter(uint8_t* buffer, T bufferLength, - bool serializeLenght = false); + /** + * Constructor for constant uint8_t buffer. Length field can be serialized optionally. + * Type of length can be supplied as template type. + * @param buffer + * @param bufferLength + * @param serializeLength + */ + SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLength = false); + + /** + * Constructoor for non-constant uint8_t buffer. Length field can be serialized optionally. + * Type of length can be supplied as template type. + * @param buffer + * @param bufferLength + * @param serializeLength + */ + SerialBufferAdapter(uint8_t* buffer, T bufferLength, bool serializeLength = false); + + /** + * Constructoor for non-constant uint32_t buffer. Length field can be serialized optionally. + * Type of length can be supplied as template type. + * @param buffer + * @param bufferLength + * @param serializeLength + */ + SerialBufferAdapter(uint32_t* buffer,T bufferLength, bool serializeLength = false); virtual ~SerialBufferAdapter(); @@ -31,6 +54,8 @@ public: virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); + + uint8_t * getBuffer(); private: bool serializeLength; const uint8_t *constBuffer; From 9c3a9323b7ee50685fd23b57c9d1b39445c43a18 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 3 Dec 2019 19:30:37 +0100 Subject: [PATCH 0033/1774] some doc change proposals while writing hk service. Added Type.h in PoolRawAccess.h, compiler error when not doing that --- datapool/PoolRawAccess.h | 6 +-- datapool/PoolVariable.h | 3 +- devicehandlers/DeviceHandlerBase.h | 63 ++++++++++++++-------------- objectmanager/ObjectManagerIF.h | 6 +-- tmtcservices/AcceptsTelecommandsIF.h | 2 +- 5 files changed, 38 insertions(+), 42 deletions(-) diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 3e2bd7ae3..9a3000c0e 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -3,6 +3,7 @@ #include #include +#include /** * This class allows accessing Data Pool variables as raw bytes. @@ -79,9 +80,8 @@ public: ~PoolRawAccess(); /** * \brief This operation returns a pointer to the entry fetched. - * \details This means, it does not return a pointer to byte "index", but to the start byte of - * array entry "index". Example: If the original data pool array consists of an double - * array of size four, getEntry(1) returns &(this->value[8]). + * \details Return pointer to the buffer containing the raw data + * Size and number of data can be retrieved by other means. */ uint8_t* getEntry(); /** diff --git a/datapool/PoolVariable.h b/datapool/PoolVariable.h index 25345c0ac..2c48ca3e1 100644 --- a/datapool/PoolVariable.h +++ b/datapool/PoolVariable.h @@ -112,8 +112,7 @@ public: * corresponds to. * \param dataSet The data set in which the variable shall register itself. If NULL, * the variable is not registered. - * \param setWritable If this flag is set to true, changes in the value attribute can be - * written back to the data pool, otherwise not. + * \param setReadWriteMode */ PoolVariable(uint32_t set_id, DataSetIF* dataSet, ReadWriteMode_t setReadWriteMode) : diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index b5ffa2eec..d489ada1c 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -35,14 +35,14 @@ class StorageManagerIF; /** - * \brief This is the abstract base class for device handlers. - * + * @brief This is the abstract base class for device handlers. + * @details * Documentation: Dissertation Baetz p.138,139, p.141-149 * * It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink, communication with * physical devices, using the @link DeviceCommunicationIF, and communication with commanding objects. * - * NOTE: RMAP is a legacy standard which is used for FLP. + * NOTE: RMAP is a standard which is used for FLP. * RMAP communication is not mandatory for projects implementing the FSFW. * However, the communication principles are similar to RMAP as there are two write and two send calls involved. * @@ -57,7 +57,7 @@ class StorageManagerIF; * Components and drivers can send so called cookies which are used for communication * and contain information about the communcation (e.g. slave address for I2C or RMAP structs). * - * \ingroup devices + * @ingroup devices */ class DeviceHandlerBase: public DeviceHandlerIF, public HasReturnvaluesIF, @@ -87,33 +87,34 @@ public: /** - * This function is the device handler base core component and is called periodically. - * General sequence: - * If the State is SEND_WRITE: - * 1. Set the cookie state to COOKIE_UNUSED and read the command queue - * 2. Handles Device State Modes by calling doStateMachine(). - * This function calls callChildStatemachine() which calls the abstract functions - * doStartUp() and doShutDown() - * 3. Check switch states by calling checkSwitchStates() - * 4. Decrements counter for timeout of replies by calling decrementDeviceReplyMap() - * 5. Performs FDIR check for failures - * 6. Calls hkSwitcher.performOperation() - * 7. If the device mode is MODE_OFF, return RETURN_OK. Otherwise, perform the Action property - * and performs depending on value specified - * by input value counter. The child class tells base class what to do by setting this value. - * - SEND_WRITE: Send data or commands to device by calling doSendWrite() which calls - * sendMessage function of #communicationInterface - * and calls buildInternalCommand if the cookie state is COOKIE_UNUSED - * - GET_WRITE: Get ackknowledgement for sending by calling doGetWrite() which calls - * getSendSuccess of #communicationInterface. - * Calls abstract functions scanForReply() and interpretDeviceReply(). - * - SEND_READ: Request reading data from device by calling doSendRead() which calls - * requestReceiveMessage of #communcationInterface - * - GET_READ: Access requested reading data by calling doGetRead() which calls - * readReceivedMessage of #communicationInterface - * @param counter Specifies which Action to perform - * @return RETURN_OK for successful execution - */ + * @brief This function is the device handler base core component and is called periodically. + * @details + * General sequence, showing where abstract virtual functions are called: + * If the State is SEND_WRITE: + * 1. Set the cookie state to COOKIE_UNUSED and read the command queue + * 2. Handles Device State Modes by calling doStateMachine(). + * This function calls callChildStatemachine() which calls the abstract functions + * doStartUp() and doShutDown() + * 3. Check switch states by calling checkSwitchStates() + * 4. Decrements counter for timeout of replies by calling decrementDeviceReplyMap() + * 5. Performs FDIR check for failures + * 6. Calls hkSwitcher.performOperation() + * 7. If the device mode is MODE_OFF, return RETURN_OK. Otherwise, perform the Action property + * and performs depending on value specified + * by input value counter. The child class tells base class what to do by setting this value. + * - SEND_WRITE: Send data or commands to device by calling doSendWrite() which calls + * sendMessage function of #communicationInterface + * and calls buildInternalCommand if the cookie state is COOKIE_UNUSED + * - GET_WRITE: Get ackknowledgement for sending by calling doGetWrite() which calls + * getSendSuccess of #communicationInterface. + * Calls abstract functions scanForReply() and interpretDeviceReply(). + * - SEND_READ: Request reading data from device by calling doSendRead() which calls + * requestReceiveMessage of #communcationInterface + * - GET_READ: Access requested reading data by calling doGetRead() which calls + * readReceivedMessage of #communicationInterface + * @param counter Specifies which Action to perform + * @return RETURN_OK for successful execution + */ virtual ReturnValue_t performOperation(uint8_t counter); virtual ReturnValue_t initialize(); diff --git a/objectmanager/ObjectManagerIF.h b/objectmanager/ObjectManagerIF.h index 9f58f600c..5fbce2824 100644 --- a/objectmanager/ObjectManagerIF.h +++ b/objectmanager/ObjectManagerIF.h @@ -79,11 +79,7 @@ public: }; /** - * Used to retrieve Target Interface Pointers of objects. - * The object has to implement the SystemObject or SystemObjectIF at the very least, - * otherwise NULL will be returned. - * @param id - * @return NULL or pointer to target interface specified by template object + * @brief Documentation can be found in the class method declration. */ template T* ObjectManagerIF::get( object_id_t id ) { diff --git a/tmtcservices/AcceptsTelecommandsIF.h b/tmtcservices/AcceptsTelecommandsIF.h index 03a57aaeb..0952d3a60 100644 --- a/tmtcservices/AcceptsTelecommandsIF.h +++ b/tmtcservices/AcceptsTelecommandsIF.h @@ -12,7 +12,7 @@ class AcceptsTelecommandsIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::ACCEPTS_TELECOMMANDS_IF; - static const ReturnValue_t ACTIVITY_STARTED = MAKE_RETURN_CODE(1); + static const ReturnValue_t ACTIVITY_STARTED = MAKE_RETURN_CODE(1); // is this used anywhere or can it be removed? static const ReturnValue_t INVALID_SUBSERVICE = MAKE_RETURN_CODE(2); static const ReturnValue_t ILLEGAL_APPLICATION_DATA = MAKE_RETURN_CODE(3); static const ReturnValue_t SEND_TM_FAILED = MAKE_RETURN_CODE(4); From 950a48078c6464decada0262f5590c75c5d35a6f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 5 Dec 2019 12:21:06 +0100 Subject: [PATCH 0034/1774] some documentation, question about HasParametersIF, variable in ParameterHelper intialized (compiler warning) --- devicehandlers/DeviceCommunicationIF.h | 6 ++--- devicehandlers/DeviceHandlerBase.h | 36 ++++++++++++-------------- parameters/HasParametersIF.h | 1 + parameters/ParameterHelper.cpp | 2 +- 4 files changed, 21 insertions(+), 24 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 10ad27760..ca0e9fe27 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -5,10 +5,10 @@ #include /** - * Documentation: Dissertation Baetz p.138 - * - * This is an interface to decouple device communication from + * @brief This is an interface to decouple device communication from * the device handler to allow reuse of these components. + * @details + * Documentation: Dissertation Baetz p.138 * It works with the assumption that received data * is polled by a component. There are four generic steps of device communication: * diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index d489ada1c..e7ac3aa63 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -331,9 +331,10 @@ protected: uint32_t parameter = 0); /** - * - - * @param parameter2 additional parameter + * Send reply to a command, differentiate between raw command + * and normal command. + * @param status + * @param parameter */ void replyToCommand(ReturnValue_t status, uint32_t parameter = 0); @@ -532,10 +533,9 @@ protected: size_t commandDataLen) = 0; /** - * fill the #deviceCommandMap - * - * called by the initialize() of the base class - * + * @brief fill the #deviceCommandMap + * called by the initialize() of the base class + * @details * This is used to let the base class know which replies are expected. * There are different scenarios regarding this: * - "Normal" commands. These are commands, that trigger a direct reply from the device. In this case, the id of the command should be added to the command map @@ -556,9 +556,9 @@ protected: * perform debugging * @details Example: Calling this in performOperation * to track values like mode. - * @param positionTracker Provide the child handler a way to know where the debugInterface was called - * @param objectId Provide the child handler object Id to specify actions for spefic devices - * @param parameter Supply a parameter of interest + * @param positionTracker Provide the child handler a way to know where the debugInterface was called + * @param objectId Provide the child handler object Id to specify actions for spefic devices + * @param parameter Supply a parameter of interest * Please delete all debugInterface calls in DHB after debugging is finished ! */ virtual void debugInterface(uint8_t positionTracker = 0, object_id_t objectId = 0, uint32_t parameter = 0); @@ -766,7 +766,7 @@ protected: /** * Used to retrieve logical address - * @return + * @return logicalAddress */ virtual uint32_t getLogicalAddress(); Mode_t getBaseMode(Mode_t transitionMode); @@ -863,12 +863,8 @@ protected: ActionHelper actionHelper; - - private: - - /** * State a cookie is in. * @@ -957,11 +953,6 @@ private: void buildRawDeviceCommand(CommandMessage* message); void buildInternalCommand(void); -// /** -// * Send a reply with the current mode and submode. -// */ -// void announceMode(void); - /** * Decrement the counter for the timout of replies. * @@ -1066,6 +1057,11 @@ private: */ ReturnValue_t switchCookieChannel(object_id_t newChannelId); + /** + * Handle device handler messages (e.g. commands sent by PUS Service 2) + * @param message + * @return + */ ReturnValue_t handleDeviceHandlerMessage(CommandMessage *message); diff --git a/parameters/HasParametersIF.h b/parameters/HasParametersIF.h index fbb694454..cd053feeb 100644 --- a/parameters/HasParametersIF.h +++ b/parameters/HasParametersIF.h @@ -46,6 +46,7 @@ public: * @param startAtIndex * @return */ + // shouldnt startAtIndex be uint8? virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex) = 0; diff --git a/parameters/ParameterHelper.cpp b/parameters/ParameterHelper.cpp index 75b71a7e9..6ebc9e629 100644 --- a/parameters/ParameterHelper.cpp +++ b/parameters/ParameterHelper.cpp @@ -3,7 +3,7 @@ #include ParameterHelper::ParameterHelper(ReceivesParameterMessagesIF* owner) : - owner(owner), storage(NULL) { + owner(owner), ownerQueueId(0), storage(NULL){ } From d99ed4715017fddab2c1f80610c9c72d3b428315 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 8 Dec 2019 19:04:53 +0100 Subject: [PATCH 0035/1774] fixed map bugfix (fist instead of first), new access functions for fixed maP (first(), second()), some documentation, raw pool access read() call public because call is necessary before using public serialize function. maybe integrate read() call into serialize function? --- container/FixedMap.h | 13 +++++++++++-- datapool/PoolRawAccess.h | 22 ++++++++++++---------- parameters/HasParametersIF.h | 1 - serialize/SerialArrayListAdapter.h | 1 + serialize/SerialFixedArrayListAdapter.h | 2 ++ storagemanager/LocalPool.h | 25 +++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 13 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 0b84bf4ea..4e1dc6291 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -6,7 +6,9 @@ #include /** - * \ingroup container + * @brief Implementation of a fixed map using an array list + * @details Initialize with desired fixed size + * @ingroup container */ template class FixedMap: public SerializeIF { @@ -56,6 +58,13 @@ public: return &ArrayList, uint32_t>::Iterator::value->second; } + key_t first() { + return ArrayList, uint32_t>::Iterator::value->first; + } + + T second() { + return ArrayList, uint32_t>::Iterator::value->second; + } }; Iterator begin() const { @@ -87,7 +96,7 @@ public: } ReturnValue_t insert(std::pair pair) { - return insert(pair.fist, pair.second); + return insert(pair.first, pair.second); } ReturnValue_t exists(key_t key) const { diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 9a3000c0e..8b81894a4 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -31,7 +31,7 @@ private: */ Type type; /** - * \brief This value contains the size of the data pool entry in bytes. + * \brief This value contains the size of the data pool entry type in bytes. */ uint8_t typeSize; /** @@ -48,15 +48,7 @@ private: ReadWriteMode_t readWriteMode; static const uint8_t RAW_MAX_SIZE = sizeof(double); protected: - /** - * \brief This is a call to read the value from the global data pool. - * \details When executed, this operation tries to fetch the pool entry with matching - * data pool id from the global data pool and copies the value and the valid - * information to its local attributes. In case of a failure (wrong type or - * pool id not found), the variable is set to zero and invalid. - * The operation does NOT provide any mutual exclusive protection by itself. - */ - ReturnValue_t read(); + /** * \brief The commit call writes back the variable's value to the data pool. * \details It checks type and size, as well as if the variable is writable. If so, @@ -66,6 +58,7 @@ protected: */ ReturnValue_t commit(); public: + static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS; static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01); static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02); @@ -78,6 +71,15 @@ public: * discarded and not written back to the data pool. */ ~PoolRawAccess(); + /** + * \brief This is a call to read the value from the global data pool. + * \details When executed, this operation tries to fetch the pool entry with matching + * data pool id from the global data pool and copies the value and the valid + * information to its local attributes. In case of a failure (wrong type or + * pool id not found), the variable is set to zero and invalid. + * The operation does NOT provide any mutual exclusive protection by itself. + */ + ReturnValue_t read(); /** * \brief This operation returns a pointer to the entry fetched. * \details Return pointer to the buffer containing the raw data diff --git a/parameters/HasParametersIF.h b/parameters/HasParametersIF.h index cd053feeb..fbb694454 100644 --- a/parameters/HasParametersIF.h +++ b/parameters/HasParametersIF.h @@ -46,7 +46,6 @@ public: * @param startAtIndex * @return */ - // shouldnt startAtIndex be uint8? virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex) = 0; diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 5ffbc3757..7e2e527bc 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -27,6 +27,7 @@ public: static ReturnValue_t serialize(const ArrayList* list, uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) { + // Serialize length field first ReturnValue_t result = SerializeAdapter::serialize(&list->size, buffer, size, max_size, bigEndian); count_t i = 0; diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 821e87104..18093e451 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -24,10 +24,12 @@ public: template SerialFixedArrayListAdapter(Args... args) : FixedArrayList(std::forward(args)...) { } + ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const { return SerialArrayListAdapter::serialize(this, buffer, size, max_size, bigEndian); } + uint32_t getSerializedSize() const { return SerialArrayListAdapter::getSerializedSize(this); } diff --git a/storagemanager/LocalPool.h b/storagemanager/LocalPool.h index 08cb017fc..425ba005e 100644 --- a/storagemanager/LocalPool.h +++ b/storagemanager/LocalPool.h @@ -159,6 +159,15 @@ public: * @brief In the LocalPool's destructor all allocated memory is freed. */ virtual ~LocalPool(void); + + /** + * Add data to local data pool, performs range check + * @param storageId [out] Store ID in which the data will be stored + * @param data + * @param size + * @param ignoreFault + * @return @c RETURN_OK if write was successful + */ ReturnValue_t addData(store_address_t* storageId, const uint8_t * data, uint32_t size, bool ignoreFault = false); @@ -171,8 +180,24 @@ public: */ ReturnValue_t getFreeElement(store_address_t* storageId, const uint32_t size, uint8_t** p_data, bool ignoreFault = false); + + /** + * Retrieve data from local pool + * @param packet_id + * @param packet_ptr + * @param size [out] Size of retrieved data + * @return @c RETURN_OK if data retrieval was successfull + */ ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr, uint32_t* size); + + /** + * Modify data by supplying a previously obtaind packet pointer + * @param packet_id Store ID of data to modify + * @param packet_ptr + * @param size [out] size of changed data + * @return + */ ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr, uint32_t* size); virtual ReturnValue_t deleteData(store_address_t); From 3159ccbc4017f7a9662b82054ac3adbce3aa6261 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 8 Dec 2019 22:26:42 +0100 Subject: [PATCH 0036/1774] fixed map and local pool doc --- container/FixedMap.h | 11 +++++++++-- storagemanager/LocalPool.h | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 4e1dc6291..5e8ca9c35 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -6,8 +6,10 @@ #include /** - * @brief Implementation of a fixed map using an array list - * @details Initialize with desired fixed size + * @brief Map implementation for maps with a pre-defined size. + * @details Can be initialized with desired maximum size. + * Iterator is used to access pair and + * iterate through map entries. * @ingroup container */ template @@ -54,19 +56,24 @@ public: return ArrayList, uint32_t>::Iterator::value->second; } + // -> operator overloaded, can be used to access value T *operator->() { return &ArrayList, uint32_t>::Iterator::value->second; } + // Can be used to access the key of the iterator key_t first() { return ArrayList, uint32_t>::Iterator::value->first; } + // Alternative to access value, similar to std::map implementation T second() { return ArrayList, uint32_t>::Iterator::value->second; } }; + + Iterator begin() const { return Iterator(&theMap[0]); } diff --git a/storagemanager/LocalPool.h b/storagemanager/LocalPool.h index 425ba005e..57c80c2e7 100644 --- a/storagemanager/LocalPool.h +++ b/storagemanager/LocalPool.h @@ -149,6 +149,8 @@ public: * The position of these values correspond to those in * element_sizes. * @param registered Register the pool in object manager or not. Default is false (local pool). + * @param spillsToHigherPools + * A variable to determine whether higher n pools are used if the store is full. */ LocalPool(object_id_t setObjectId, const uint16_t element_sizes[NUMBER_OF_POOLS], From 8168885dd905992920029c38444b9abf27541d52 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 8 Dec 2019 22:57:03 +0100 Subject: [PATCH 0037/1774] Serialization documentation update --- serialize/EndianSwapper.h | 4 ++ serialize/SerialFixedArrayListAdapter.h | 14 +++---- serialize/SerialLinkedListAdapter.h | 56 ++++++++++++++++--------- serialize/SerializeAdapter.h | 12 +++--- serialize/SerializeElement.h | 10 ++++- serialize/SerializeIF.h | 13 +++--- 6 files changed, 70 insertions(+), 39 deletions(-) diff --git a/serialize/EndianSwapper.h b/serialize/EndianSwapper.h index 6ff544447..dfd93484e 100644 --- a/serialize/EndianSwapper.h +++ b/serialize/EndianSwapper.h @@ -5,6 +5,10 @@ #include #include +/** + * @brief Can be used to swap endianness of data + * into big endian + */ class EndianSwapper { private: EndianSwapper() { diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 18093e451..593a0ec1d 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -5,18 +5,18 @@ #include /** - * This adapter provides an interface for SerializeIF to serialize and deserialize - * buffers with a header containing the buffer length. - * - * Can be used by SerialLinkedListAdapter. - * + * @brief This adapter provides an interface for SerializeIF to serialize and deserialize + * buffers with a header containing the buffer length. + * @details + * Can be used by SerialLinkedListAdapter by using this type in + * SerializeElement<> * Buffers with a size header inside that class can be declared with - * SerialFixedArrayListAdapter. + * SerialFixedArrayListAdapter. * typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows * and MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. * The sequence of objects is defined in the constructor by using the setStart and setNext functions. * - * \ingroup serialize + * @ingroup serialize */ template class SerialFixedArrayListAdapter : public FixedArrayList, public SerializeIF { diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index 08d385eec..c135a2d38 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -14,29 +14,30 @@ //This is where we need the SerializeAdapter! /** - * An alternative to the AutoSerializeAdapter functions to implement the conversion - * of object data to data streams or vice-versa, using linked lists. + * @brief Implement the conversion of object data to data streams + * or vice-versa, using linked lists. + * @details + * An alternative to the AutoSerializeAdapter functions + * - All object members with a datatype are declared as SerializeElement + * inside the class implementing this adapter. + * - The element type can also be a SerialBufferAdapter to de-/serialize buffers, + * with a known size, where the size can also be serialized + * - The element type can also be a SerialFixedArrayListAdapter to de-/serialize buffers + * with a size header, which is scanned automatically * - * All object members with a datatype are declared as SerializeElement inside the class - * implementing this adapter. + * The sequence of objects is defined in the constructor by using + * the setStart and setNext functions. * - * Buffers with a size header inside that class can be declared with - * SerialFixedArrayListAdapter. - * typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows - * and MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. - * Please note that a direct link from a linked element to a SerialFixedArrayListAdapter element is not possible and a - * helper needs to be used by calling .setNext(&linkHelper) - * and initialising the link helper as linkHelper(&SerialFixedArrayListAdapterElement). + * - The serialization process is done by instantiating the class and + * calling the serialize after all SerializeElement entries have been set by + * using a constructor or setter functions. An additional size variable can be supplied + * which is calculated/incremented automatically + * - The deserialization process is done by instantiating the class and supplying + * a buffer with the data which is converted into an object. The size of + * data to serialize can be supplied and is decremented in the function * - * For buffers with no size header, declare - * SerializeElement> and initialise the buffer adapter in the constructor. * - * The sequence of objects is defined in the constructor by using the setStart and setNext functions. - * - * The serialization and deserialization process is done by instantiating the class and - * calling the serialize or deserialize function. - * - * \ingroup serialize + * @ingroup serialize */ template class SerialLinkedListAdapter: public SinglyLinkedList, public SerializeIF { @@ -53,6 +54,16 @@ public: SinglyLinkedList(), printCount(printCount) { } + /** + * Serialize object implementing this adapter into the supplied buffer + * and calculate the serialized size + * @param buffer [out] Object is serialized into this buffer. Note that the buffer pointer + * *buffer is incremented automatically inside the respective serialize functions + * @param size [out] Calculated serialized size. Don't forget to set to 0. + * @param max_size + * @param bigEndian Specify endianness + * @return + */ virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const { if (printCount) { @@ -95,6 +106,13 @@ public: return size; } + /** + * Deserialize supplied buffer with supplied size into object implementing this adapter + * @param buffer + * @param size Decremented in respective deSerialize functions automatically + * @param bigEndian Specify endianness + * @return + */ virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) { return deSerialize(SinglyLinkedList::start, buffer, size, bigEndian); diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index a0aab9e98..385f40d33 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -8,10 +8,10 @@ #include /** - * This adapter provides an interface to use the SerializeIF functions - * with arbitrary template objects to facilitate and simplify the serialization of classes - * with different multiple different data types into buffers vice-versa. - * + * @brief This adapter provides an interface to use the SerializeIF functions + * with arbitrary template objects to facilitate and simplify the serialization of classes + * with different multiple different data types into buffers vice-versa. + * @details * Examples: * A report class is converted into a TM buffer. The report class implements a serialize functions and calls * the AutoSerializeAdapter::serialize function repeatedly on all object data fields. @@ -49,7 +49,7 @@ * When serializing for downlink, the packets are generally serialized assuming big endian data format * like seen in TmPacketStored.cpp for example. * - * \ingroup serialize + * @ingroup serialize */ template class SerializeAdapter_ { @@ -141,7 +141,7 @@ public: } }; - +// No type specification necessary here. class AutoSerializeAdapter { public: template diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index db7db20a9..4f5a22b6e 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -6,7 +6,15 @@ #include /** - * \ingroup serialize + * @brief This class is used to mark datatypes for serialization with the + * SerialLinkedListAdapter + * @details + * Used by declaring any arbitrary datatype with SerializeElement myVariable, + * inside a SerialLinkedListAdapter implementation and setting the sequence + * of objects with setNext() and setStart(). + * Serilization and Deserialization is then performed automatically in + * specified sequence order. + * @ingroup serialize */ template class SerializeElement : public SerializeIF, public LinkedElement { diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index cada1e72a..fb750a083 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -4,17 +4,18 @@ #include /** - * \defgroup serialize Serialization + * @defgroup serialize Serialization * Contains serialisation services. */ /** - * An interface for alle classes which require translation of objects data into data streams and vice-versa. - * + * @brief An interface for alle classes which require + * translation of objects data into data streams and vice-versa. + * @details * If the target architecture is little endian (e.g. ARM), any data types created might * have the wrong endiness if they are to be used for the FSFW. - * There are three ways to retrieve data out of a buffer to be used in the FSFW to use regular aligned (big endian) data. - * This can also be applied to uint32_t and uint64_t: + * There are three ways to retrieve data out of a buffer to be used in the FSFW to use + * regular aligned (big endian) data. This can also be applied to uint32_t and uint64_t: * * 1. Use the @c AutoSerializeAdapter::deSerialize function with @c bigEndian = true * 2. Perform a bitshift operation @@ -23,7 +24,7 @@ * When serializing for downlink, the packets are generally serialized assuming big endian data format * like seen in TmPacketStored.cpp for example. * - * \ingroup serialize + * @ingroup serialize */ class SerializeIF { public: From e765f8c99bbe6827b44a8ea21a9808ca51471cf1 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 9 Dec 2019 12:27:14 +0100 Subject: [PATCH 0038/1774] pool raw access modified so vectors are properly serialized now Endian swapper can swap the entries of a uint16,uint32 buffers now. Some documentation for functions added. setter function for serial buffer adapter written but does not appear to compile, commented out --- datapool/PoolRawAccess.cpp | 20 +++++++++++++------- datapool/PoolRawAccess.h | 18 ++++++++++++++---- serialize/EndianSwapper.h | 21 +++++++++++++++++++++ serialize/SerialBufferAdapter.cpp | 5 +++++ serialize/SerialBufferAdapter.h | 1 + serialize/SerializeAdapter.h | 8 ++++++++ 6 files changed, 62 insertions(+), 11 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 555896bb2..6e9b3d08f 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -31,7 +31,10 @@ ReturnValue_t PoolRawAccess::read() { sizeTillEnd = read_out->getByteSize() - arrayPosition; uint8_t* ptr = &((uint8_t*) read_out->getRawData())[arrayPosition]; - memcpy(value, ptr, typeSize); + for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { + memcpy(value + typeSize * arrayCount, ptr + typeSize * arrayCount, typeSize); + } + return HasReturnvaluesIF::RETURN_OK; } else { //Error value type too large. @@ -152,17 +155,20 @@ ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, #ifndef BYTE_ORDER_SYSTEM #error BYTE_ORDER_SYSTEM not defined #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - for (uint8_t count = 0; count < typeSize; count++) { - (*buffer)[count] = value[typeSize - count - 1]; + for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { + for (uint8_t count = 0; count < typeSize; count++) { + (*buffer)[typeSize * (arrayCount + 1) - count - 1] = + value[typeSize * arrayCount + count]; + } } #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN - memcpy(*buffer, value, typeSize); + memcpy(*buffer, value, typeSize * arraySize); #endif } else { - memcpy(*buffer, value, typeSize); + memcpy(*buffer, value, typeSize * arraySize); } - *size += typeSize; - (*buffer) += typeSize; + *size += typeSize * arraySize; + (*buffer) += typeSize * arraySize; return HasReturnvaluesIF::RETURN_OK; } else { return SerializeIF::BUFFER_TOO_SHORT; diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 8b81894a4..2a634fa85 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -48,7 +48,6 @@ private: ReadWriteMode_t readWriteMode; static const uint8_t RAW_MAX_SIZE = sizeof(double); protected: - /** * \brief The commit call writes back the variable's value to the data pool. * \details It checks type and size, as well as if the variable is writable. If so, @@ -80,6 +79,20 @@ public: * The operation does NOT provide any mutual exclusive protection by itself. */ ReturnValue_t read(); + + /** + * @brief Serialize raw pool entry into provided buffer directly + * @details Should be called after read() call. Endianness can be specified too + * @param buffer Provided buffer. Raw pool data will be copied here + * @param size [out] Increment provided size value by serialized size + * @param max_size Maximum allowed serialization size + * @param bigEndian Specify endianess + * @return - @c RETURN_OK if serialization was successfull + * - @c SerializeIF::BUFFER_TOO_SHORT if range check failed + */ + ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, + const uint32_t max_size, bool bigEndian) const; + /** * \brief This operation returns a pointer to the entry fetched. * \details Return pointer to the buffer containing the raw data @@ -142,9 +155,6 @@ public: */ uint16_t getSizeTillEnd() const; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; - uint32_t getSerializedSize() const; ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, diff --git a/serialize/EndianSwapper.h b/serialize/EndianSwapper.h index dfd93484e..db170c0b2 100644 --- a/serialize/EndianSwapper.h +++ b/serialize/EndianSwapper.h @@ -44,6 +44,27 @@ public: #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN memcpy(out, in, size); return; +#endif + } + + template + static void swap(T * out, const T * in, uint32_t size) { +#ifndef BYTE_ORDER_SYSTEM +#error BYTE_ORDER_SYSTEM not defined +#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + const uint8_t * in_buffer = reinterpret_cast(in); + uint8_t * out_buffer = reinterpret_cast(out); + for (uint8_t count = 0; count < size; count++) { + for(uint8_t i = 0; i < sizeof(T);i++) { + out_buffer[sizeof(T)* (count + 1) - i - 1] = in_buffer[count * sizeof(T) + i]; + } + + } + + return; +#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN + memcpy(out, in, size*sizeof(T)); + return; #endif } }; diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 9a8e6f069..d7ab0d880 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -96,6 +96,11 @@ uint8_t * SerialBufferAdapter::getBuffer() { return buffer; } +//template +//void SerialBufferAdapter::setBuffer(uint8_t * buffer_) { +// buffer = buffer_; +//} + //forward Template declaration for linker template class SerialBufferAdapter; template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 7496c1376..0438f8841 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -56,6 +56,7 @@ public: bool bigEndian); uint8_t * getBuffer(); + //void setBuffer(uint8_t * buffer_); private: bool serializeLength; const uint8_t *constBuffer; diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 385f40d33..933d933de 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -76,6 +76,14 @@ public: } } + /** + * Deserialize buffer into object + * @param object [out] Object to be deserialized with buffer data + * @param buffer buffer containing the data + * @param size int32_t type to allow value to be values smaller than 0, needed for range/size checking + * @param bigEndian Specify endianness + * @return + */ ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size, bool bigEndian) { T tmp; From 356d1d35dc97232e92778a4d0602947db812dc59 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 10 Dec 2019 13:29:16 +0100 Subject: [PATCH 0039/1774] experimenting with recursive constructor to enable automatic vector registering --- datapool/PoolRawAccess.cpp | 46 +++++++++++++++++++++++++++----------- datapool/PoolRawAccess.h | 44 +++++++++++++++++++++++++----------- 2 files changed, 64 insertions(+), 26 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 6e9b3d08f..41efdd7a1 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -5,13 +5,27 @@ #include PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, - DataSetIF* data_set, ReadWriteMode_t setReadWriteMode) : + DataSetIF* data_set, ReadWriteMode_t setReadWriteMode, + bool registerVectors) : dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false), type(Type::UNKNOWN_TYPE), typeSize( 0), arraySize(0), sizeTillEnd(0), readWriteMode(setReadWriteMode) { memset(value, 0, sizeof(value)); if (data_set != NULL) { data_set->registerVariable(this); } + if(registerVectors == true) { + this->read(); + if(arraySize > 1) { + for(uint16_t vectorCount = typeSize;vectorCount < arraySize;vectorCount += typeSize) + { + PoolRawAccess * newPoolRawAccess = + new PoolRawAccess(set_id, setArrayEntry + typeSize, + data_set,setReadWriteMode,true); + if(newPoolRawAccess) {}; + } + } + } + } PoolRawAccess::~PoolRawAccess() { @@ -31,9 +45,10 @@ ReturnValue_t PoolRawAccess::read() { sizeTillEnd = read_out->getByteSize() - arrayPosition; uint8_t* ptr = &((uint8_t*) read_out->getRawData())[arrayPosition]; - for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { - memcpy(value + typeSize * arrayCount, ptr + typeSize * arrayCount, typeSize); - } + memcpy(value, ptr, typeSize); + //for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { + // memcpy(value + typeSize * arrayCount, ptr + typeSize * arrayCount, typeSize); + //} return HasReturnvaluesIF::RETURN_OK; } else { @@ -155,20 +170,25 @@ ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, #ifndef BYTE_ORDER_SYSTEM #error BYTE_ORDER_SYSTEM not defined #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { - for (uint8_t count = 0; count < typeSize; count++) { - (*buffer)[typeSize * (arrayCount + 1) - count - 1] = - value[typeSize * arrayCount + count]; - } + for (uint8_t count = 0; count < typeSize; count++) { + (*buffer)[count] = value[typeSize - count - 1]; } + //for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { + // for (uint8_t count = 0; count < typeSize; count++) { + // (*buffer)[typeSize * (arrayCount + 1) - count - 1] = + // value[typeSize * arrayCount + count]; + // } + //} #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN - memcpy(*buffer, value, typeSize * arraySize); + memcpy(*buffer, value, typeSize); + //memcpy(*buffer, value, typeSize * arraySize); #endif } else { - memcpy(*buffer, value, typeSize * arraySize); + memcpy(*buffer, value, typeSize); + //memcpy(*buffer, value, typeSize * arraySize); } - *size += typeSize * arraySize; - (*buffer) += typeSize * arraySize; + *size += typeSize;// * arraySize; + (*buffer) += typeSize;// * arraySize; return HasReturnvaluesIF::RETURN_OK; } else { return SerializeIF::BUFFER_TOO_SHORT; diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 2a634fa85..e85bef247 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -6,10 +6,14 @@ #include /** - * This class allows accessing Data Pool variables as raw bytes. + * @brief This class allows accessing Data Pool variables as raw bytes. + * @details * This is necessary to have an access method for HK data, as the PID's alone do not - * provide a type information. - * \ingroup data_pool + * provide a type information. Please note that the the raw pool access read() and commit() + * calls are not thread-safe and therefore private. + * Please supply a data set and use the data set read(), commit() calls for thread-safe + * data pool access. + * @ingroup data_pool */ class PoolRawAccess: public PoolVariableIF { private: @@ -48,6 +52,18 @@ private: ReadWriteMode_t readWriteMode; static const uint8_t RAW_MAX_SIZE = sizeof(double); protected: + /** + * \brief This is a call to read the value from the global data pool. + * \details When executed, this operation tries to fetch the pool entry with matching + * data pool id from the global data pool and copies the value and the valid + * information to its local attributes. In case of a failure (wrong type or + * pool id not found), the variable is set to zero and invalid. + * The operation does NOT provide any mutual exclusive protection by itself ! + * If reading from the data pool without information about the type is desired, + * initialize the raw pool access by supplying a data set and using the data set + * read function, which calls this read function. + */ + ReturnValue_t read(); /** * \brief The commit call writes back the variable's value to the data pool. * \details It checks type and size, as well as if the variable is writable. If so, @@ -62,23 +78,25 @@ public: static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01); static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02); uint8_t value[RAW_MAX_SIZE]; + //uint8_t value[RAW_MAX_SIZE*3]; + + /** + * This constructor is used to access a data pool entry with a + * given ID if the target type is not known. A DataSet object is supplied + * and the data pool entry with the given ID is registered to that data set + * @param data_pool_id Target data pool entry ID + * @param arrayEntry + * @param data_set Dataset to register data pool entry to + * @param setReadWriteMode + */ PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry, DataSetIF* data_set, ReadWriteMode_t setReadWriteMode = - PoolVariableIF::VAR_READ); + PoolVariableIF::VAR_READ,bool registerVectors = false); /** * \brief The classes destructor is empty. If commit() was not called, the local value is * discarded and not written back to the data pool. */ ~PoolRawAccess(); - /** - * \brief This is a call to read the value from the global data pool. - * \details When executed, this operation tries to fetch the pool entry with matching - * data pool id from the global data pool and copies the value and the valid - * information to its local attributes. In case of a failure (wrong type or - * pool id not found), the variable is set to zero and invalid. - * The operation does NOT provide any mutual exclusive protection by itself. - */ - ReturnValue_t read(); /** * @brief Serialize raw pool entry into provided buffer directly From f33949ba4b2e7ef3784d712af06e94a04c45ebac Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 10 Dec 2019 14:54:17 +0100 Subject: [PATCH 0040/1774] doc adapted, merging --- datapool/PoolRawAccess.h | 1 - 1 file changed, 1 deletion(-) diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 2a634fa85..3b9144a20 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -82,7 +82,6 @@ public: /** * @brief Serialize raw pool entry into provided buffer directly - * @details Should be called after read() call. Endianness can be specified too * @param buffer Provided buffer. Raw pool data will be copied here * @param size [out] Increment provided size value by serialized size * @param max_size Maximum allowed serialization size From f7d8f0c1617295aae5ed652ee99566f98d84111c Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 10 Dec 2019 23:26:48 +0100 Subject: [PATCH 0041/1774] Reverted changed pool raw access commit --- datapool/PoolRawAccess.cpp | 31 ++++++++----------------------- datapool/PoolRawAccess.h | 9 +++++++-- 2 files changed, 15 insertions(+), 25 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 41efdd7a1..0c31565ac 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -15,17 +15,14 @@ PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, } if(registerVectors == true) { this->read(); - if(arraySize > 1) { - for(uint16_t vectorCount = typeSize;vectorCount < arraySize;vectorCount += typeSize) - { - PoolRawAccess * newPoolRawAccess = - new PoolRawAccess(set_id, setArrayEntry + typeSize, - data_set,setReadWriteMode,true); - if(newPoolRawAccess) {}; - } + if(arrayEntry < arraySize - 1) { + uint8_t nextArrayEntry = arrayEntry + 1; + PoolRawAccess * newPoolRawAccess = + new PoolRawAccess(set_id, nextArrayEntry, + data_set,setReadWriteMode,true); + if(newPoolRawAccess) {}; } } - } PoolRawAccess::~PoolRawAccess() { @@ -46,10 +43,6 @@ ReturnValue_t PoolRawAccess::read() { uint8_t* ptr = &((uint8_t*) read_out->getRawData())[arrayPosition]; memcpy(value, ptr, typeSize); - //for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { - // memcpy(value + typeSize * arrayCount, ptr + typeSize * arrayCount, typeSize); - //} - return HasReturnvaluesIF::RETURN_OK; } else { //Error value type too large. @@ -173,22 +166,14 @@ ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, for (uint8_t count = 0; count < typeSize; count++) { (*buffer)[count] = value[typeSize - count - 1]; } - //for(uint8_t arrayCount = 0; arrayCount < arraySize; arrayCount++) { - // for (uint8_t count = 0; count < typeSize; count++) { - // (*buffer)[typeSize * (arrayCount + 1) - count - 1] = - // value[typeSize * arrayCount + count]; - // } - //} #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN memcpy(*buffer, value, typeSize); - //memcpy(*buffer, value, typeSize * arraySize); #endif } else { memcpy(*buffer, value, typeSize); - //memcpy(*buffer, value, typeSize * arraySize); } - *size += typeSize;// * arraySize; - (*buffer) += typeSize;// * arraySize; + *size += typeSize; + (*buffer) += typeSize; return HasReturnvaluesIF::RETURN_OK; } else { return SerializeIF::BUFFER_TOO_SHORT; diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index cdead93a8..9bf09d0a7 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -78,16 +78,21 @@ public: static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01); static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02); uint8_t value[RAW_MAX_SIZE]; - //uint8_t value[RAW_MAX_SIZE*3]; /** * This constructor is used to access a data pool entry with a * given ID if the target type is not known. A DataSet object is supplied - * and the data pool entry with the given ID is registered to that data set + * and the data pool entry with the given ID is registered to that data set. + * Please note that a pool raw access buffer only has a buffer + * with a size of double. As such, for vector entries which have * @param data_pool_id Target data pool entry ID * @param arrayEntry * @param data_set Dataset to register data pool entry to * @param setReadWriteMode + * @param registerVectors If set to true, the constructor checks if + * there are multiple vector entries to registers + * and registers all of them recursively into the data_set + * */ PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry, DataSetIF* data_set, ReadWriteMode_t setReadWriteMode = From 138cac98d100affabc0916e27f8189c42af3f3b9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 11 Dec 2019 01:57:36 +0100 Subject: [PATCH 0042/1774] experimenting with recursive constructor and dataset call --- datapool/PoolRawAccess.cpp | 9 +++++---- datapool/PoolRawAccess.h | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 0c31565ac..6be4b7838 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "DataSet.h" PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, DataSetIF* data_set, ReadWriteMode_t setReadWriteMode, @@ -15,12 +16,12 @@ PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, } if(registerVectors == true) { this->read(); +// DataSet * myDataSetTest = (DataSet *) data_set; +// myDataSetTest->read(); if(arrayEntry < arraySize - 1) { uint8_t nextArrayEntry = arrayEntry + 1; - PoolRawAccess * newPoolRawAccess = - new PoolRawAccess(set_id, nextArrayEntry, - data_set,setReadWriteMode,true); - if(newPoolRawAccess) {}; + nextPoolRawAccess = new PoolRawAccess(set_id, nextArrayEntry, + data_set,setReadWriteMode,true); } } } diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 9bf09d0a7..ac7d6702f 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -50,6 +50,7 @@ private: * \brief The information whether the class is read-write or read-only is stored here. */ ReadWriteMode_t readWriteMode; + PoolRawAccess * nextPoolRawAccess; static const uint8_t RAW_MAX_SIZE = sizeof(double); protected: /** From 29a15e8154d5de81d5dff878f6e54f413f5fe12d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 11 Dec 2019 13:03:51 +0100 Subject: [PATCH 0043/1774] commented out functions which will propably not be needed and removed --- datapool/PoolRawAccess.cpp | 22 +++++++++++----------- datapool/PoolRawAccess.h | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 6be4b7838..c99d80691 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -3,7 +3,9 @@ #include #include #include -#include "DataSet.h" + +//PoolRawAccess::PoolRawAccess() { +//} PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, DataSetIF* data_set, ReadWriteMode_t setReadWriteMode, @@ -14,16 +16,14 @@ PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, if (data_set != NULL) { data_set->registerVariable(this); } - if(registerVectors == true) { - this->read(); -// DataSet * myDataSetTest = (DataSet *) data_set; -// myDataSetTest->read(); - if(arrayEntry < arraySize - 1) { - uint8_t nextArrayEntry = arrayEntry + 1; - nextPoolRawAccess = new PoolRawAccess(set_id, nextArrayEntry, - data_set,setReadWriteMode,true); - } - } +// if(registerVectors == true) { +// this->read(); +// if(arrayEntry < arraySize - 1) { +// uint8_t nextArrayEntry = arrayEntry + 1; +// nextPoolRawAccess = new PoolRawAccess(set_id, nextArrayEntry, +// data_set,setReadWriteMode,true); +// } +// } } PoolRawAccess::~PoolRawAccess() { diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index ac7d6702f..7207518cc 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -50,7 +50,7 @@ private: * \brief The information whether the class is read-write or read-only is stored here. */ ReadWriteMode_t readWriteMode; - PoolRawAccess * nextPoolRawAccess; + //PoolRawAccess * nextPoolRawAccess; static const uint8_t RAW_MAX_SIZE = sizeof(double); protected: /** @@ -79,7 +79,7 @@ public: static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01); static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02); uint8_t value[RAW_MAX_SIZE]; - + //PoolRawAccess(); /** * This constructor is used to access a data pool entry with a * given ID if the target type is not known. A DataSet object is supplied From 9382eb03e6cfb0985d78587df3f4696e52ead038 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 11 Dec 2019 22:50:08 +0100 Subject: [PATCH 0044/1774] function to serialize pool ID buffers into dataset created --- datapool/DataSet.cpp | 6 ++++++ datapool/DataSet.h | 11 +++++++++++ datapool/PoolRawAccess.h | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/datapool/DataSet.cpp b/datapool/DataSet.cpp index b4725c735..55d8d6700 100644 --- a/datapool/DataSet.cpp +++ b/datapool/DataSet.cpp @@ -148,3 +148,9 @@ ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, int32_t* size, } return result; } + +ReturnValue_t DataSet::serializeRawFromIdBuffer(uint8_t ** buffer, uint32_t * size, + const uint32_t max_size, bool bigEndian, uint32_t * poolIdBuffer, + uint32_t poolIdSize) { + return RETURN_OK; +} diff --git a/datapool/DataSet.h b/datapool/DataSet.h index 982be6928..deee8ca66 100644 --- a/datapool/DataSet.h +++ b/datapool/DataSet.h @@ -146,6 +146,14 @@ public: */ void setValid(uint8_t valid); + /** + * Serialize all registered pool variables into the provided buffer + * @param buffer + * @param size Is incremented by serialized size + * @param max_size + * @param bigEndian + * @return + */ ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const; @@ -154,6 +162,9 @@ public: ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); + ReturnValue_t serializeRawFromIdBuffer(uint8_t ** buffer, uint32_t * size, + const uint32_t max_size, bool bigEndian, uint32_t * poolIdBuffer, + uint32_t poolIdSize); }; #endif /* DATASET_H_ */ diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 7207518cc..3735868f7 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -10,7 +10,7 @@ * @details * This is necessary to have an access method for HK data, as the PID's alone do not * provide a type information. Please note that the the raw pool access read() and commit() - * calls are not thread-safe and therefore private. + * calls are not thread-safe. * Please supply a data set and use the data set read(), commit() calls for thread-safe * data pool access. * @ingroup data_pool From 625f3dc79c33794c041bf91af87bd0a2d271e67b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 11 Dec 2019 23:15:34 +0100 Subject: [PATCH 0045/1774] local pool modify data doc modifided --- storagemanager/LocalPool.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/storagemanager/LocalPool.h b/storagemanager/LocalPool.h index 57c80c2e7..80e6a4956 100644 --- a/storagemanager/LocalPool.h +++ b/storagemanager/LocalPool.h @@ -194,10 +194,11 @@ public: uint32_t* size); /** - * Modify data by supplying a previously obtaind packet pointer + * Modify data by supplying a packet pointer and using that packet pointer + * to access and modify the pool entry (via *pointer call) * @param packet_id Store ID of data to modify - * @param packet_ptr - * @param size [out] size of changed data + * @param packet_ptr [out] pointer to the pool entry to modify + * @param size [out] size of pool entry * @return */ ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr, From fa6cbe7e0c8862f903e7c78bdf938c8caff93863 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 11 Dec 2019 23:18:28 +0100 Subject: [PATCH 0046/1774] pool raw access changed reverted --- datapool/PoolRawAccess.cpp | 11 ----------- datapool/PoolRawAccess.h | 1 - 2 files changed, 12 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index c99d80691..7cc618528 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -4,9 +4,6 @@ #include #include -//PoolRawAccess::PoolRawAccess() { -//} - PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, DataSetIF* data_set, ReadWriteMode_t setReadWriteMode, bool registerVectors) : @@ -16,14 +13,6 @@ PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, if (data_set != NULL) { data_set->registerVariable(this); } -// if(registerVectors == true) { -// this->read(); -// if(arrayEntry < arraySize - 1) { -// uint8_t nextArrayEntry = arrayEntry + 1; -// nextPoolRawAccess = new PoolRawAccess(set_id, nextArrayEntry, -// data_set,setReadWriteMode,true); -// } -// } } PoolRawAccess::~PoolRawAccess() { diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 3735868f7..603bae239 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -50,7 +50,6 @@ private: * \brief The information whether the class is read-write or read-only is stored here. */ ReadWriteMode_t readWriteMode; - //PoolRawAccess * nextPoolRawAccess; static const uint8_t RAW_MAX_SIZE = sizeof(double); protected: /** From d17146d847610b403118c7992908a94deb361e1c Mon Sep 17 00:00:00 2001 From: Maximilian Luz Date: Thu, 19 Dec 2019 16:09:50 +0100 Subject: [PATCH 0047/1774] Check object existence before adding it to the PST Currently, adding new objects/components to the FixedSlotSequence PST is not being checked, meaning that it is possible to add NULL objects here without any warning. This causes NULL-pointer errors when non-existent components are added, which can be hard to debug. To solve this, add a check for the object existence before adding it to PST and emit an error message. Signed-off-by: Maximilian Luz --- osal/FreeRTOS/FixedTimeslotTask.cpp | 5 +++++ osal/linux/FixedTimeslotTask.cpp | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 5bf09f136..4a30774aa 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -57,6 +57,11 @@ ReturnValue_t FixedTimeslotTask::startTask() { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { + if (!objectManager->get(componentId)) { + error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + pst.addSlot(componentId, slotTimeMs, executionStep, this); return HasReturnvaluesIF::RETURN_OK; } diff --git a/osal/linux/FixedTimeslotTask.cpp b/osal/linux/FixedTimeslotTask.cpp index 99cbf8185..21040e6ef 100644 --- a/osal/linux/FixedTimeslotTask.cpp +++ b/osal/linux/FixedTimeslotTask.cpp @@ -40,6 +40,11 @@ uint32_t FixedTimeslotTask::getPeriodMs() const { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { + if (!objectManager->get(componentId)) { + error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl; + return HasReturnvaluesIF::RETURN_FAILED; + } + pst.addSlot(componentId, slotTimeMs, executionStep, this); return HasReturnvaluesIF::RETURN_OK; } From 89f490ac36dd3178616cbdfa712adea389ab15ec Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 20 Dec 2019 23:09:35 +0100 Subject: [PATCH 0048/1774] assembly constructor formatting --- devicehandlers/AssemblyBase.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/devicehandlers/AssemblyBase.cpp b/devicehandlers/AssemblyBase.cpp index c250cf735..bd85d1de5 100644 --- a/devicehandlers/AssemblyBase.cpp +++ b/devicehandlers/AssemblyBase.cpp @@ -2,10 +2,10 @@ AssemblyBase::AssemblyBase(object_id_t objectId, object_id_t parentId, uint16_t commandQueueDepth) : - SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth), internalState( - STATE_NONE), recoveryState(RECOVERY_IDLE), recoveringDevice( - childrenMap.end()), targetMode(MODE_OFF), targetSubmode( - SUBMODE_NONE) { + SubsystemBase(objectId, parentId, MODE_OFF, commandQueueDepth), + internalState(STATE_NONE), recoveryState(RECOVERY_IDLE), + recoveringDevice(childrenMap.end()), targetMode(MODE_OFF), + targetSubmode(SUBMODE_NONE) { recoveryOffTimer.setTimeout(POWER_OFF_TIME_MS); } From f6b9b232877d29d6a68640967f131d6091c7f2de Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 Dec 2019 01:41:04 +0100 Subject: [PATCH 0049/1774] pool raw access init --- datapool/PoolRawAccessHelper.cpp | 68 ++++++++++++++++++++++++++++++ datapool/PoolRawAccessHelper.h | 71 ++++++++++++++++++++++++++++++++ 2 files changed, 139 insertions(+) create mode 100644 datapool/PoolRawAccessHelper.cpp create mode 100644 datapool/PoolRawAccessHelper.h diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp new file mode 100644 index 000000000..24bcc1d49 --- /dev/null +++ b/datapool/PoolRawAccessHelper.cpp @@ -0,0 +1,68 @@ +/** + * @file PoolRawAccessHelper.cpp + * + * @date 22.12.2019 + */ + +#include + +PoolRawAccessHelper::PoolRawAccessHelper(DataSet *dataSet_, + const uint8_t * poolIdBuffer_, uint8_t numberOfParameters_): + dataSet(dataSet_), poolIdBuffer(poolIdBuffer_), + numberOfParameters(numberOfParameters_){ +} + +PoolRawAccessHelper::~PoolRawAccessHelper() { +} + +ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size, + const uint32_t max_size, bool bigEndian) { + const uint8_t ** pPoolIdBuffer = &poolIdBuffer; + int32_t remainingParametersSize = numberOfParameters * 4; + for(uint8_t count=0; count < numberOfParameters; count++) { + serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer, + &remainingParametersSize,size,max_size, bigEndian, false); + } + return RETURN_OK; +} + +ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer, + uint32_t *size, const uint32_t max_size, bool bigEndian) { + return RETURN_OK; +} + +void PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer, + uint8_t ** buffer, int32_t * remainingParameters, uint32_t * hkDataSize, + const uint32_t max_size, bool bigEndian, bool withValidMask) { + uint32_t currentPoolId; + // Deserialize current pool ID from pool ID buffer + ReturnValue_t result = AutoSerializeAdapter::deSerialize(¤tPoolId, + pPoolIdBuffer,remainingParameters,true); + if(result != RETURN_OK) { + debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl; + return; + } + PoolRawAccess currentPoolRawAccess(currentPoolId,0,dataSet,PoolVariableIF::VAR_READ); + result = dataSet->read(); + + if (result != RETURN_OK) { + debug << std::hex << "Pool Raw Access Helper: Error read raw dataset" << std::dec << std::endl; + return; + } + result = dataSet->serialize(buffer, hkDataSize, + max_size, bigEndian); + if (result != RETURN_OK) { + debug << "Service 3: Error serializing pool data into send buffer" << std::endl; + return; + } +} + +uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position, bool value) { + if(position < 1 or position > 8) { + debug << "Pool Raw Access: Bit setting invalid position" << std::endl; + return byte; + } + uint8_t shiftNumber = position + (6 - 2 * (position - 1)); + byte = (byte | value) << shiftNumber; + return byte; +} diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h new file mode 100644 index 000000000..bb19a3cec --- /dev/null +++ b/datapool/PoolRawAccessHelper.h @@ -0,0 +1,71 @@ +/** + * @file PoolRawAccessHelper.h + * + * @date 22.12.2019 + */ + +#ifndef FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_ +#define FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_ + +#include +#include + +/** + * @brief This helper function simplifies accessing data pool entries + * via PoolRawAccess + * @details Can be used for a Housekeeping Service + * like PUS Service 3 if the type of the datapool entries is unknown. + * The provided dataset is serialized into a provided buffer automatically. + */ +class PoolRawAccessHelper: public HasReturnvaluesIF { +public: + /** + * Call this constructor if a dataset needs to be serialized via + * Pool Raw Access + * @param dataSet_ This dataset will be used to perform thread-safe reading + * @param poolIdBuffer_ A buffer of uint32_t pool IDs + * @param numberOfParameters_ The number of parameters / pool IDs + */ + PoolRawAccessHelper(DataSet * dataSet_, const uint8_t * poolIdBuffer_, + uint8_t numberOfParameters_); + virtual ~PoolRawAccessHelper(); + + /** + * Serialize the datapool entries derived from the pool ID buffer + * directly into a provided buffer + * @param [out] buffer + * @param [out] size Size of the serialized buffer + * @param max_size + * @param bigEndian + * @return @c RETURN_OK On success + * @c RETURN_FAILED on failure + */ + ReturnValue_t serialize(uint8_t ** buffer, uint32_t * size, + const uint32_t max_size, bool bigEndian); + + /** + * Serializes data pool entries into provided buffer with the validity mask buffer + * at the end of the buffer. Every bit of the validity mask denotes + * the validity of a corresponding data pool entry from left to right. + * @param [out] buffer + * @param [out] size Size of the serialized buffer plus size + * of the validity mask + * @return @c RETURN_OK On success + * @c RETURN_FAILED on failure + */ + ReturnValue_t serializeWithValidityMask(uint8_t ** buffer, uint32_t * size, + const uint32_t max_size, bool bigEndian); + + +private: + DataSet * dataSet; + const uint8_t * poolIdBuffer; + uint8_t numberOfParameters; + + void serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer,uint8_t ** buffer, + int32_t * remainingParameters, uint32_t * hkDataSize,const uint32_t max_size, + bool bigEndian, bool withValidMask); + uint8_t bitSetter(uint8_t byte, uint8_t position, bool value); +}; + +#endif /* FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_ */ From 1f1831c4a14ddf806a6a360e1f60b1c46e90d968 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 Dec 2019 22:15:39 +0100 Subject: [PATCH 0050/1774] pool raw access init --- datapool/PoolRawAccessHelper.cpp | 53 ++++++++++++++++++++++++++------ datapool/PoolRawAccessHelper.h | 33 +++++++++++++++++--- 2 files changed, 73 insertions(+), 13 deletions(-) diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index 24bcc1d49..5a43e43c7 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -2,6 +2,7 @@ * @file PoolRawAccessHelper.cpp * * @date 22.12.2019 + * @author R. Mueller */ #include @@ -9,7 +10,7 @@ PoolRawAccessHelper::PoolRawAccessHelper(DataSet *dataSet_, const uint8_t * poolIdBuffer_, uint8_t numberOfParameters_): dataSet(dataSet_), poolIdBuffer(poolIdBuffer_), - numberOfParameters(numberOfParameters_){ + numberOfParameters(numberOfParameters_), validBufferIndex(0), validBufferIndexBit(1){ } PoolRawAccessHelper::~PoolRawAccessHelper() { @@ -17,44 +18,78 @@ PoolRawAccessHelper::~PoolRawAccessHelper() { ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size, const uint32_t max_size, bool bigEndian) { + ReturnValue_t result; const uint8_t ** pPoolIdBuffer = &poolIdBuffer; int32_t remainingParametersSize = numberOfParameters * 4; for(uint8_t count=0; count < numberOfParameters; count++) { - serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer, + result = serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer, &remainingParametersSize,size,max_size, bigEndian, false); + if(result != RETURN_OK) { + return result; + } } return RETURN_OK; } ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer, uint32_t *size, const uint32_t max_size, bool bigEndian) { + ReturnValue_t result; + const uint8_t ** pPoolIdBuffer = &poolIdBuffer; + int32_t remainingParametersSize = numberOfParameters * 4; + uint8_t validityMaskSize = numberOfParameters/8; + uint8_t validityMask[validityMaskSize]; + memset(validityMask,0, validityMaskSize); + for(uint8_t count=0; count < numberOfParameters; count++) { + result = serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer, + &remainingParametersSize,size,max_size, bigEndian,true,validityMask); + if (result != RETURN_OK) { + return result; + } + } + memcpy(*buffer + *size, validityMask, validityMaskSize); + *size += validityMaskSize; + validBufferIndex = 1; + validBufferIndexBit = 0; return RETURN_OK; } -void PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer, +ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer, uint8_t ** buffer, int32_t * remainingParameters, uint32_t * hkDataSize, - const uint32_t max_size, bool bigEndian, bool withValidMask) { + const uint32_t max_size, bool bigEndian, bool withValidMask, uint8_t * validityMask) { uint32_t currentPoolId; // Deserialize current pool ID from pool ID buffer ReturnValue_t result = AutoSerializeAdapter::deSerialize(¤tPoolId, pPoolIdBuffer,remainingParameters,true); if(result != RETURN_OK) { debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl; - return; + return result; } PoolRawAccess currentPoolRawAccess(currentPoolId,0,dataSet,PoolVariableIF::VAR_READ); - result = dataSet->read(); + // set valid mask bit if necessary + if(withValidMask) { + if(currentPoolRawAccess.isValid()) { + validityMask[validBufferIndex] = + bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true); + validBufferIndexBit ++; + if(validBufferIndexBit == 8) { + validBufferIndex ++; + validBufferIndexBit = 1; + } + } + } + + result = dataSet->read(); if (result != RETURN_OK) { debug << std::hex << "Pool Raw Access Helper: Error read raw dataset" << std::dec << std::endl; - return; + return result; } result = dataSet->serialize(buffer, hkDataSize, max_size, bigEndian); if (result != RETURN_OK) { - debug << "Service 3: Error serializing pool data into send buffer" << std::endl; - return; + debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl; } + return result; } uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position, bool value) { diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index bb19a3cec..36f42f83d 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -14,8 +14,10 @@ * @brief This helper function simplifies accessing data pool entries * via PoolRawAccess * @details Can be used for a Housekeeping Service - * like PUS Service 3 if the type of the datapool entries is unknown. - * The provided dataset is serialized into a provided buffer automatically. + * like ECSS PUS Service 3 if the type of the datapool entries is unknown. + * The provided dataset can be serialized into a provided buffer automatically by + * providing a buffer of pool IDs + * @ingroup data_pool */ class PoolRawAccessHelper: public HasReturnvaluesIF { public: @@ -62,9 +64,32 @@ private: const uint8_t * poolIdBuffer; uint8_t numberOfParameters; - void serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer,uint8_t ** buffer, + uint8_t validBufferIndex; + uint8_t validBufferIndexBit; + + /** + * Helper function to serialize single pool entries + * @param pPoolIdBuffer + * @param buffer + * @param remainingParameters + * @param hkDataSize + * @param max_size + * @param bigEndian + * @param withValidMask Can be set optionally to set a provided validity mask + * @param validityMask Can be supplied and will be set if @c withValidMask is set to true + * @return + */ + ReturnValue_t serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer,uint8_t ** buffer, int32_t * remainingParameters, uint32_t * hkDataSize,const uint32_t max_size, - bool bigEndian, bool withValidMask); + bool bigEndian, bool withValidMask = false, uint8_t * validityMask = NULL); + + /** + * Sets specific bit of a byte + * @param byte + * @param position Position of byte to set from 1 to 8 + * @param value Binary value to set + * @return + */ uint8_t bitSetter(uint8_t byte, uint8_t position, bool value); }; From e24f9b89e4c1965387de84520c80d2439337a9e3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 16:44:50 +0100 Subject: [PATCH 0051/1774] Pool Raw Access Helper tested, appesrs to work. SerializeAdapter doc changes, tm packet stored debug output if not enough storage available --- datapool/PoolRawAccessHelper.cpp | 42 +++++++++++++++++++------------ datapool/PoolRawAccessHelper.h | 7 +++--- osal/FreeRTOS/MessageQueue.cpp | 21 ++++++++-------- serialize/SerializeAdapter.h | 24 ++++++++++-------- tmtcpacket/pus/TmPacketStored.cpp | 1 + 5 files changed, 55 insertions(+), 40 deletions(-) diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index 5a43e43c7..bacf8ea51 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -6,10 +6,11 @@ */ #include +#include -PoolRawAccessHelper::PoolRawAccessHelper(DataSet *dataSet_, - const uint8_t * poolIdBuffer_, uint8_t numberOfParameters_): - dataSet(dataSet_), poolIdBuffer(poolIdBuffer_), +PoolRawAccessHelper::PoolRawAccessHelper(uint8_t * poolIdBuffer_, + uint8_t numberOfParameters_): + poolIdBuffer(poolIdBuffer_), numberOfParameters(numberOfParameters_), validBufferIndex(0), validBufferIndexBit(1){ } @@ -19,52 +20,61 @@ PoolRawAccessHelper::~PoolRawAccessHelper() { ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size, const uint32_t max_size, bool bigEndian) { ReturnValue_t result; - const uint8_t ** pPoolIdBuffer = &poolIdBuffer; int32_t remainingParametersSize = numberOfParameters * 4; for(uint8_t count=0; count < numberOfParameters; count++) { - result = serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer, + result = serializeCurrentPoolEntryIntoBuffer(buffer, &remainingParametersSize,size,max_size, bigEndian, false); if(result != RETURN_OK) { return result; } } - return RETURN_OK; + if(remainingParametersSize != 0) { + debug << "Pool Raw Access: Remaining parameters size not 0 !" << std::endl; + result = RETURN_FAILED; + } + return result; } ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer, uint32_t *size, const uint32_t max_size, bool bigEndian) { ReturnValue_t result; - const uint8_t ** pPoolIdBuffer = &poolIdBuffer; int32_t remainingParametersSize = numberOfParameters * 4; uint8_t validityMaskSize = numberOfParameters/8; uint8_t validityMask[validityMaskSize]; memset(validityMask,0, validityMaskSize); - for(uint8_t count=0; count < numberOfParameters; count++) { - result = serializeCurrentPoolEntryIntoBuffer(pPoolIdBuffer,buffer, + for(uint8_t count = 0; count < numberOfParameters; count++) { + result = serializeCurrentPoolEntryIntoBuffer(buffer, &remainingParametersSize,size,max_size, bigEndian,true,validityMask); if (result != RETURN_OK) { return result; } } + if(remainingParametersSize != 0) { + debug << "Pool Raw Access: Remaining parameters size not 0 !" << std::endl; + result = RETURN_FAILED; + } memcpy(*buffer + *size, validityMask, validityMaskSize); *size += validityMaskSize; validBufferIndex = 1; validBufferIndexBit = 0; - return RETURN_OK; + return result; } -ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer, - uint8_t ** buffer, int32_t * remainingParameters, uint32_t * hkDataSize, +ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer, + int32_t * remainingParameters, uint32_t * hkDataSize, const uint32_t max_size, bool bigEndian, bool withValidMask, uint8_t * validityMask) { uint32_t currentPoolId; + DataSet currentDataSet = DataSet(); // Deserialize current pool ID from pool ID buffer ReturnValue_t result = AutoSerializeAdapter::deSerialize(¤tPoolId, - pPoolIdBuffer,remainingParameters,true); + &poolIdBuffer,remainingParameters,true); if(result != RETURN_OK) { debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl; return result; } - PoolRawAccess currentPoolRawAccess(currentPoolId,0,dataSet,PoolVariableIF::VAR_READ); + + // info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; + PoolRawAccess currentPoolRawAccess(currentPoolId,0,¤tDataSet,PoolVariableIF::VAR_READ); // set valid mask bit if necessary if(withValidMask) { @@ -79,12 +89,12 @@ ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(const uin } } - result = dataSet->read(); + result = currentDataSet.read(); if (result != RETURN_OK) { debug << std::hex << "Pool Raw Access Helper: Error read raw dataset" << std::dec << std::endl; return result; } - result = dataSet->serialize(buffer, hkDataSize, + result = currentDataSet.serialize(buffer, hkDataSize, max_size, bigEndian); if (result != RETURN_OK) { debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl; diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index 36f42f83d..756ae2863 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -28,8 +28,7 @@ public: * @param poolIdBuffer_ A buffer of uint32_t pool IDs * @param numberOfParameters_ The number of parameters / pool IDs */ - PoolRawAccessHelper(DataSet * dataSet_, const uint8_t * poolIdBuffer_, - uint8_t numberOfParameters_); + PoolRawAccessHelper(uint8_t * poolIdBuffer_, uint8_t numberOfParameters_); virtual ~PoolRawAccessHelper(); /** @@ -60,7 +59,7 @@ public: private: - DataSet * dataSet; + // DataSet * dataSet; const uint8_t * poolIdBuffer; uint8_t numberOfParameters; @@ -79,7 +78,7 @@ private: * @param validityMask Can be supplied and will be set if @c withValidMask is set to true * @return */ - ReturnValue_t serializeCurrentPoolEntryIntoBuffer(const uint8_t ** pPoolIdBuffer,uint8_t ** buffer, + ReturnValue_t serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer, int32_t * remainingParameters, uint32_t * hkDataSize,const uint32_t max_size, bool bigEndian, bool withValidMask = false, uint8_t * validityMask = NULL); diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index f3aebcd1c..1f514cf38 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -89,23 +89,24 @@ MessageQueueId_t MessageQueue::getDefaultDestination() const { bool MessageQueue::isDefaultDestinationSet() const { return 0; } + ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, MessageQueueMessage *message, MessageQueueId_t sentFrom, bool ignoreFault) { message->setSender(sentFrom); - BaseType_t result = xQueueSendToBack(reinterpret_cast(sendTo),reinterpret_cast(message->getBuffer()), 0); - if (result != pdPASS) { - if (!ignoreFault) { - InternalErrorReporterIF* internalErrorReporter = objectManager->get( - objects::INTERNAL_ERROR_REPORTER); - if (internalErrorReporter != NULL) { - internalErrorReporter->queueMessageNotSent(); - } + BaseType_t result = xQueueSendToBack(reinterpret_cast(sendTo),reinterpret_cast(message->getBuffer()), 0); + if (result != pdPASS) { + if (!ignoreFault) { + InternalErrorReporterIF* internalErrorReporter = objectManager->get( + objects::INTERNAL_ERROR_REPORTER); + if (internalErrorReporter != NULL) { + internalErrorReporter->queueMessageNotSent(); } - return MessageQueueIF::FULL; } - return HasReturnvaluesIF::RETURN_OK; + return MessageQueueIF::FULL; + } + return HasReturnvaluesIF::RETURN_OK; } diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 933d933de..18240a95e 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -10,7 +10,7 @@ /** * @brief This adapter provides an interface to use the SerializeIF functions * with arbitrary template objects to facilitate and simplify the serialization of classes - * with different multiple different data types into buffers vice-versa. + * with different multiple different data types into buffers and vice-versa. * @details * Examples: * A report class is converted into a TM buffer. The report class implements a serialize functions and calls @@ -20,27 +20,31 @@ * * The AutoSerializeAdapter functions can also be used as an alternative to memcpy * to retrieve data out of a buffer directly into a class variable with data type T while being able to specify endianness. - * The boolean bigEndian specifies the endiness of the data to serialize or deSerialize. + * The boolean bigEndian specifies whether an endian swap is performed on the data before + * serialization or deserialization. * * If the target architecture is little endian (ARM), any data types created might * have the wrong endiness if they are to be used for the FSFW. - * there are three ways to retrieve data out of a buffer to be used in the FSFW to use regular aligned (big endian) data. + * There are three ways to retrieve data out of a buffer to be used in the FSFW + * to use regular aligned (big endian) data. * This can also be applied to uint32_t and uint64_t: * - * 1. Use the AutoSerializeAdapter::deSerialize function with bool bigEndian = true: - * The pointer *buffer will be incremented automatically by the typeSize of data, - * so this function can be called on &buffer without adjusting pointer position + * 1. Use the AutoSerializeAdapter::deSerialize function + * The pointer *buffer will be incremented automatically by the typeSize of the object, + * so this function can be called on &buffer repeatedly without adjusting pointer position. + * Set bigEndian parameter to true to perform endian swapping. * * uint16_t data; * int32_t dataLen = sizeof(data); * ReturnValue_t result = AutoSerializeAdapter::deSerialize(&data,&buffer,&dataLen,true); * - * 2. Perform a bitshift operation: + * 2. Perform a bitshift operation. Perform endian swapping if necessary: * * uint16_t data; - * data = buffer[targetByte1] >> 8 | buffer[targetByte2]; + * data = buffer[targetByte1] << 8 | buffer[targetByte2]; + * data = EndianSwapper::swap(data); * - * 3. Memcpy can be used when data is little-endian. Otherwise, endian-swapper has to be used. + * 3. Memcpy can be used when data is little-endian. Perform endian-swapping if necessary. * * uint16_t data; * memcpy(&data,buffer + positionOfTargetByte1,sizeof(data)); @@ -79,7 +83,7 @@ public: /** * Deserialize buffer into object * @param object [out] Object to be deserialized with buffer data - * @param buffer buffer containing the data + * @param buffer buffer containing the data. Non-Const pointer to non-const pointer to const buffer. * @param size int32_t type to allow value to be values smaller than 0, needed for range/size checking * @param bigEndian Specify endianness * @return diff --git a/tmtcpacket/pus/TmPacketStored.cpp b/tmtcpacket/pus/TmPacketStored.cpp index f2c1eb28a..b1c1ec624 100644 --- a/tmtcpacket/pus/TmPacketStored.cpp +++ b/tmtcpacket/pus/TmPacketStored.cpp @@ -22,6 +22,7 @@ TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service, (TmPacketBase::TM_PACKET_MIN_SIZE + size + headerSize), &pData); if (returnValue != store->RETURN_OK) { + debug << "TM Packet Stored: Issue getting free storage" << std::endl; checkAndReportLostTm(); return; } From 29b4480fc4f6d752e1236e6b9172dc622ea640ba Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 18:55:31 +0100 Subject: [PATCH 0052/1774] include adapted --- osal/FreeRTOS/QueueFactory.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osal/FreeRTOS/QueueFactory.cpp b/osal/FreeRTOS/QueueFactory.cpp index 5c7087dee..eaf245d37 100644 --- a/osal/FreeRTOS/QueueFactory.cpp +++ b/osal/FreeRTOS/QueueFactory.cpp @@ -1,6 +1,6 @@ #include -#include "../FreeRTOS/MessageQueue.h" +#include QueueFactory* QueueFactory::factoryInstance = NULL; From 0066a6b78819777a62f8f1b0ec8512f56b4a49d4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 19:47:46 +0100 Subject: [PATCH 0053/1774] Generic TMTC Bridge added --- tmtcservices/TmTcBridge.cpp | 173 ++++++++++++++++++++++++++++++++++++ tmtcservices/TmTcBridge.h | 121 +++++++++++++++++++++++++ 2 files changed, 294 insertions(+) create mode 100644 tmtcservices/TmTcBridge.cpp create mode 100644 tmtcservices/TmTcBridge.h diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp new file mode 100644 index 000000000..e79283173 --- /dev/null +++ b/tmtcservices/TmTcBridge.cpp @@ -0,0 +1,173 @@ +/** + * @file TmTcBridge.cpp + * + * @date 26.12.2019 + */ + +#include + +#include +#include +#include + +TmTcBridge::TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_): + SystemObject(objectId_),tcStore(NULL), tmStore(NULL), + ccsdsPacketDistributor(ccsdsPacketDistributor_), communicationLinkUp(false), + tmStored(false) { + TmTcReceptionQueue = QueueFactory::instance()-> + createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH); + +} + +TmTcBridge::~TmTcBridge() { +} + +ReturnValue_t TmTcBridge::initialize() { + tcStore = objectManager->get(objects::TC_STORE); + if (tcStore == NULL) { + return RETURN_FAILED; + } + tmStore = objectManager->get(objects::TM_STORE); + if (tmStore == NULL) { + return RETURN_FAILED; + } + AcceptsTelecommandsIF* tcDistributor = + objectManager->get(ccsdsPacketDistributor); + if (tcDistributor == NULL) { + return RETURN_FAILED; + } + TmTcReceptionQueue->setDefaultDestination(tcDistributor->getRequestQueue()); + return RETURN_OK; +} + +ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) { + ReturnValue_t result; + result = handleTc(); + if(result != RETURN_OK) { + error << "TMTC Bridge: Error handling TCs" << std::endl; + } + result = handleTm(); + if (result != RETURN_OK) { + error << "TMTC Bridge: Error handling TMs" << std::endl; + } + return result; +} + +ReturnValue_t TmTcBridge::handleTc() { + ReturnValue_t result = receiveTc(); + return result; +} + +ReturnValue_t TmTcBridge::handleTm() { + ReturnValue_t result = readTmQueue(); + if(result != RETURN_OK) { + error << "TMTC Bridge: Reading TM Queue failed" << std::endl; + return RETURN_FAILED; + } + + if(tmStored && communicationLinkUp) { + result = sendStoredTm(); + } + return result; + +} + +ReturnValue_t TmTcBridge::readTmQueue() { + TmTcMessage message; + const uint8_t* data = NULL; + uint32_t size = 0; + for (ReturnValue_t result = TmTcReceptionQueue->receiveMessage(&message); + result == RETURN_OK; result = TmTcReceptionQueue->receiveMessage(&message)) + { + if(not communicationLinkUp) { + result = storeDownlinkData(&message); + return result; + } + + result = tmStore->getData(message.getStorageId(), &data, &size); + if (result != HasReturnvaluesIF::RETURN_OK) { + continue; + } + + result = sendTm(data, size); + if (result != RETURN_OK) { + error << "UDP Server: Could not send TM packet"<< std::endl; + tmStore->deleteData(message.getStorageId()); + return result; + + } + tmStore->deleteData(message.getStorageId()); + } + return RETURN_OK; +} + +ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) { + info << "UDP Server: Client address not bound yet. Packet can not be sent. " + "Saving packet to be sent later " << std::endl; + store_address_t storeId; + + if(fifo.full()) { + info << "UDP Server: TM downlink store is full. Overwriting old data" << std::endl; + fifo.retrieve(&storeId); + } + storeId = message->getStorageId(); + fifo.insert(storeId); + //storageIdBufferCounter ++; + tmStored = true; + return RETURN_OK; +} + +ReturnValue_t TmTcBridge::sendStoredTm() { + uint8_t counter = 0; + ReturnValue_t result = RETURN_OK; + while(!fifo.empty() && counter < MAX_STORED_DATA_SENT_PER_CYCLE) { + info << "UDP Server: Sending stored TM data. There are " + << (int) fifo.size() << " left to send" << std::endl; + store_address_t storeId; + const uint8_t* data = NULL; + uint32_t size = 0; + fifo.retrieve(&storeId); + result = tmStore->getData(storeId, &data, &size); + sendTm(data,size); + if(result != RETURN_OK) { + error << "UDP Server: Could not send stored downlink data" << std::endl; + result = RETURN_FAILED; + } + counter ++; + + if(fifo.empty()) { + tmStored = false; + } + tmStore->deleteData(storeId); + } + return result; +} + +void TmTcBridge::registerCommConnect() { + info << "TMTC Bridge: Registered Comm Link Connect" << std::endl; + if(not communicationLinkUp) { + communicationLinkUp = true; + } +} + +void TmTcBridge::registerCommDisconnect() { + info << "TMTC Bridge: Registered Comm Link Disconnect" << std::endl; + if(communicationLinkUp) { + communicationLinkUp = false; + } +} + +MessageQueueId_t TmTcBridge::getReportReceptionQueue(uint8_t virtualChannel) { + return TmTcReceptionQueue->getId(); +} + +void TmTcBridge::printData(uint8_t * data, uint32_t dataLen) { + info << "TMTC Bridge: Printing data: ["; + for(uint32_t i=0;i +#include +#include +#include +#include + +#include +#include + +class TmTcBridge : public AcceptsTelemetryIF, + public ExecutableObjectIF, + public HasReturnvaluesIF, + public SystemObject { +public: + TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_); + virtual ~TmTcBridge(); + + /** + * Initializes basic FSFW components for TMTC Bridge + * @return + */ + virtual ReturnValue_t initialize(); + + /** + * @brief The performOperation method is executed in a task. + * @details There are no restrictions for calls within this method, so any + * other member of the class can be used. + * @return Currently, the return value is ignored. + */ + virtual ReturnValue_t performOperation(uint8_t operationCode = 0); + + /** + * Return TMTC Reception Queue + * @param virtualChannel + * @return + */ + virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0); + +protected: + MessageQueueIF* TmTcReceptionQueue; //!< Used to send and receive TMTC messages. TmTcMessage is used to transport messages between tasks. + StorageManagerIF* tcStore; + StorageManagerIF* tmStore; + object_id_t ccsdsPacketDistributor; + bool communicationLinkUp; //!< Used to specify whether communication link is up + bool tmStored; + + /** + * Handle TC reception. Default implementation provided + * @return + */ + virtual ReturnValue_t handleTc(); + + /** + * Implemented by child class. Perform receiving of Telecommand + * @return + */ + virtual ReturnValue_t receiveTc() = 0; + + /** + * Handle Telemetry. Default implementation provided. + * Calls sendTm() + * @return + */ + virtual ReturnValue_t handleTm(); + + /** + * Read the TM Queue and send TM if necessary. Default implementation provided + * @return + */ + virtual ReturnValue_t readTmQueue(); + + /** + * Implemented by child class. Perform sending of Telemetry + * @param data + * @param dataLen + * @return + */ + virtual ReturnValue_t sendTm(const uint8_t * data, uint32_t dataLen) = 0; + + /** + * Store data to be sent later if communication link is not up. + * @param message + * @return + */ + ReturnValue_t storeDownlinkData(TmTcMessage * message); + + /** + * Send stored data if communication link is active + * @return + */ + ReturnValue_t sendStoredTm(); + + /** + * Print data as hexidecimal array + * @param data + * @param dataLen + */ + void printData(uint8_t * data, uint32_t dataLen); + + void registerCommConnect(); + void registerCommDisconnect(); + +private: + static const uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20; + static const uint8_t MAX_STORED_DATA_SENT_PER_CYCLE = 10; + static const uint8_t MAX_DOWNLINK_PACKETS_STORED = 20; + + FIFO fifo; +}; + + +#endif /* FRAMEWORK_TMTCSERVICES_TMTCBRIDGE_H_ */ From 8397f5b2b1961bc875282829fa687adb6cdb6d97 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 20:17:21 +0100 Subject: [PATCH 0054/1774] tmtc bridge bugfix --- tmtcservices/TmTcBridge.cpp | 5 +++-- tmtcservices/TmTcBridge.h | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index e79283173..9e863ffd0 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -2,6 +2,7 @@ * @file TmTcBridge.cpp * * @date 26.12.2019 + * @author R. Mueller */ #include @@ -144,8 +145,8 @@ ReturnValue_t TmTcBridge::sendStoredTm() { } void TmTcBridge::registerCommConnect() { - info << "TMTC Bridge: Registered Comm Link Connect" << std::endl; - if(not communicationLinkUp) { + if(!communicationLinkUp) { + info << "TMTC Bridge: Registered Comm Link Connect" << std::endl; communicationLinkUp = true; } } diff --git a/tmtcservices/TmTcBridge.h b/tmtcservices/TmTcBridge.h index ad09bf7ce..0f045e474 100644 --- a/tmtcservices/TmTcBridge.h +++ b/tmtcservices/TmTcBridge.h @@ -25,7 +25,7 @@ public: virtual ~TmTcBridge(); /** - * Initializes basic FSFW components for TMTC Bridge + * Initializes basic FSFW components for the TMTC Bridge * @return */ virtual ReturnValue_t initialize(); From 19e257a90aa57622732177166a9b1ff547da9456 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 20:35:11 +0100 Subject: [PATCH 0055/1774] tmtc bridge debug output corrected --- tmtcservices/TmTcBridge.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 9e863ffd0..6415cb358 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -103,12 +103,13 @@ ReturnValue_t TmTcBridge::readTmQueue() { } ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) { - info << "UDP Server: Client address not bound yet. Packet can not be sent. " - "Saving packet to be sent later " << std::endl; + info << "TMTC Bridge: Comm Link down. " + "Saving packet ID to be sent later " << std::endl; store_address_t storeId; if(fifo.full()) { - info << "UDP Server: TM downlink store is full. Overwriting old data" << std::endl; + info << "TMTC Bridge: TM downlink max. number of stored packet IDs reached." + " Overwriting old data" << std::endl; fifo.retrieve(&storeId); } storeId = message->getStorageId(); From 33a7c033a27dd741ebbec31f5d517b6acabd342a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 20:38:15 +0100 Subject: [PATCH 0056/1774] doc extended, instructions for sendTm and receiveTc --- tmtcservices/TmTcBridge.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tmtcservices/TmTcBridge.h b/tmtcservices/TmTcBridge.h index 0f045e474..216dae8ba 100644 --- a/tmtcservices/TmTcBridge.h +++ b/tmtcservices/TmTcBridge.h @@ -60,7 +60,8 @@ protected: virtual ReturnValue_t handleTc(); /** - * Implemented by child class. Perform receiving of Telecommand + * Implemented by child class. Perform receiving of Telecommand, for example by implementing + * specific drivers or wrappers, e.g. UART Communication or lwIP stack * @return */ virtual ReturnValue_t receiveTc() = 0; @@ -79,7 +80,8 @@ protected: virtual ReturnValue_t readTmQueue(); /** - * Implemented by child class. Perform sending of Telemetry + * Implemented by child class. Perform sending of Telemetry by implementing + * communication drivers or wrappers, e.g. UART communication or lwIP stack. * @param data * @param dataLen * @return From a38a2f4b3a4e07b77e4989300871c91705496718 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 22:07:17 +0100 Subject: [PATCH 0057/1774] tmtc bridge bugfix: tm data deleted when overwriting old data --- tmtcservices/TmTcBridge.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 6415cb358..860589c5a 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -111,6 +111,7 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) { info << "TMTC Bridge: TM downlink max. number of stored packet IDs reached." " Overwriting old data" << std::endl; fifo.retrieve(&storeId); + tmStore->deleteData(storeId); } storeId = message->getStorageId(); fifo.insert(storeId); From 79e7fee8072abbf40d65d2114157f35d856bbb5d Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 26 Dec 2019 22:15:19 +0100 Subject: [PATCH 0058/1774] comment deleted --- tmtcservices/TmTcBridge.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 860589c5a..6af6d5248 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -115,7 +115,6 @@ ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) { } storeId = message->getStorageId(); fifo.insert(storeId); - //storageIdBufferCounter ++; tmStored = true; return RETURN_OK; } From 666341d03ddbe1394e452b0f15af2a4457a0f148 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 27 Dec 2019 22:43:09 +0100 Subject: [PATCH 0059/1774] new bool datatype for possible pool entries --- datapool/DataPool.cpp | 1 + datapool/PoolEntry.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/datapool/DataPool.cpp b/datapool/DataPool.cpp index 89543d776..1d3af7423 100644 --- a/datapool/DataPool.cpp +++ b/datapool/DataPool.cpp @@ -79,6 +79,7 @@ void DataPool::print() { } } +template PoolEntry* DataPool::getData( uint32_t data_pool_id, uint8_t size ); template PoolEntry* DataPool::getData( uint32_t data_pool_id, uint8_t size ); template PoolEntry* DataPool::getData( uint32_t data_pool_id, uint8_t size ); template PoolEntry* DataPool::getData( uint32_t data_pool_id, uint8_t size ); diff --git a/datapool/PoolEntry.cpp b/datapool/PoolEntry.cpp index c303e56b8..f2968c329 100644 --- a/datapool/PoolEntry.cpp +++ b/datapool/PoolEntry.cpp @@ -56,6 +56,7 @@ Type PoolEntry::getType() { return PodTypeConversion::type; } +template class PoolEntry; template class PoolEntry; template class PoolEntry; template class PoolEntry; From 2425685e446ec9a0dae320ea6f0cf0ca95e0cd33 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 29 Dec 2019 01:59:02 +0100 Subject: [PATCH 0060/1774] Pool Raw Access Helper serialization of vectors implemented --- datapool/PoolRawAccessHelper.cpp | 91 ++++++++++++++++--------- datapool/PoolRawAccessHelper.h | 15 +++- serialize/SerialFixedArrayListAdapter.h | 2 +- 3 files changed, 71 insertions(+), 37 deletions(-) diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index bacf8ea51..b17666712 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -19,11 +19,12 @@ PoolRawAccessHelper::~PoolRawAccessHelper() { ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size, const uint32_t max_size, bool bigEndian) { + SerializationArgs serializationArgs = {buffer, size, max_size, bigEndian}; ReturnValue_t result; int32_t remainingParametersSize = numberOfParameters * 4; for(uint8_t count=0; count < numberOfParameters; count++) { - result = serializeCurrentPoolEntryIntoBuffer(buffer, - &remainingParametersSize,size,max_size, bigEndian, false); + result = serializeCurrentPoolEntryIntoBuffer(serializationArgs, + &remainingParametersSize, false); if(result != RETURN_OK) { return result; } @@ -35,16 +36,17 @@ ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size, return result; } -ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer, - uint32_t *size, const uint32_t max_size, bool bigEndian) { +ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, uint32_t * size, + const uint32_t max_size, bool bigEndian) { ReturnValue_t result; + SerializationArgs argStruct = {buffer, size, max_size, bigEndian}; int32_t remainingParametersSize = numberOfParameters * 4; uint8_t validityMaskSize = numberOfParameters/8; uint8_t validityMask[validityMaskSize]; memset(validityMask,0, validityMaskSize); for(uint8_t count = 0; count < numberOfParameters; count++) { - result = serializeCurrentPoolEntryIntoBuffer(buffer, - &remainingParametersSize,size,max_size, bigEndian,true,validityMask); + result = serializeCurrentPoolEntryIntoBuffer(argStruct, + &remainingParametersSize,true,validityMask); if (result != RETURN_OK) { return result; } @@ -60,11 +62,9 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t **buffer, return result; } -ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer, - int32_t * remainingParameters, uint32_t * hkDataSize, - const uint32_t max_size, bool bigEndian, bool withValidMask, uint8_t * validityMask) { +ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct, + int32_t * remainingParameters, bool withValidMask, uint8_t * validityMask) { uint32_t currentPoolId; - DataSet currentDataSet = DataSet(); // Deserialize current pool ID from pool ID buffer ReturnValue_t result = AutoSerializeAdapter::deSerialize(¤tPoolId, &poolIdBuffer,remainingParameters,true); @@ -72,36 +72,61 @@ ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(uint8_t * debug << std::hex << "Pool Raw Access Helper: Error deSeralizing pool IDs" << std::dec << std::endl; return result; } + result = handlePoolEntrySerialization(currentPoolId, argStruct, withValidMask, validityMask); + return result; +} - // info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; - PoolRawAccess currentPoolRawAccess(currentPoolId,0,¤tDataSet,PoolVariableIF::VAR_READ); - - // set valid mask bit if necessary - if(withValidMask) { - if(currentPoolRawAccess.isValid()) { - validityMask[validBufferIndex] = - bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true); - validBufferIndexBit ++; - if(validBufferIndexBit == 8) { - validBufferIndex ++; - validBufferIndexBit = 1; +ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct, + bool withValidMask, uint8_t * validityMask) { + ReturnValue_t result; + uint8_t arrayPosition = 0; + bool poolEntrySerialized = false; + info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; + while(not poolEntrySerialized) { + DataSet currentDataSet = DataSet(); + PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,¤tDataSet,PoolVariableIF::VAR_READ); + result = currentDataSet.read(); + if (result != RETURN_OK) { + debug << std::hex << "Pool Raw Access Helper: Error reading raw dataset" << std::dec << std::endl; + return result; + } + uint8_t remainingSize = currentPoolRawAccess.getSizeTillEnd() - currentPoolRawAccess.getSizeOfType(); + if(remainingSize == 0) { + poolEntrySerialized = true; + } + else if(remainingSize > 0) { + arrayPosition += currentPoolRawAccess.getSizeOfType() / 8; + } + else { + error << "Pool Raw Access Helper: Configuration Error. Size till end smaller than 0" << std::endl; + return result; + } + // set valid mask bit if necessary + if(withValidMask) { + if(currentPoolRawAccess.isValid()) { + handleMaskModification(validityMask); } } - } - - result = currentDataSet.read(); - if (result != RETURN_OK) { - debug << std::hex << "Pool Raw Access Helper: Error read raw dataset" << std::dec << std::endl; - return result; - } - result = currentDataSet.serialize(buffer, hkDataSize, - max_size, bigEndian); - if (result != RETURN_OK) { - debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl; + result = currentDataSet.serialize(argStruct.buffer, argStruct.size, + argStruct.max_size, argStruct.bigEndian); + if (result != RETURN_OK) { + debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl; + return result; + } } return result; } +void PoolRawAccessHelper::handleMaskModification(uint8_t * validityMask) { + validityMask[validBufferIndex] = + bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true); + validBufferIndexBit ++; + if(validBufferIndexBit == 8) { + validBufferIndex ++; + validBufferIndexBit = 1; + } +} + uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position, bool value) { if(position < 1 or position > 8) { debug << "Pool Raw Access: Bit setting invalid position" << std::endl; diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index 756ae2863..25d8b1635 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -66,6 +66,12 @@ private: uint8_t validBufferIndex; uint8_t validBufferIndexBit; + struct SerializationArgs { + uint8_t ** buffer; + uint32_t * size; + const uint32_t max_size; + bool bigEndian; + }; /** * Helper function to serialize single pool entries * @param pPoolIdBuffer @@ -78,10 +84,13 @@ private: * @param validityMask Can be supplied and will be set if @c withValidMask is set to true * @return */ - ReturnValue_t serializeCurrentPoolEntryIntoBuffer(uint8_t ** buffer, - int32_t * remainingParameters, uint32_t * hkDataSize,const uint32_t max_size, - bool bigEndian, bool withValidMask = false, uint8_t * validityMask = NULL); + ReturnValue_t serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct, + int32_t * remainingParameters, bool withValidMask = false, uint8_t * validityMask = NULL); + ReturnValue_t handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct, + bool withValidMask = false, uint8_t * validityMask = NULL); + + void handleMaskModification(uint8_t * validityMask); /** * Sets specific bit of a byte * @param byte diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 593a0ec1d..c8424f05d 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -9,7 +9,7 @@ * buffers with a header containing the buffer length. * @details * Can be used by SerialLinkedListAdapter by using this type in - * SerializeElement<> + * SerializeElement<>. * Buffers with a size header inside that class can be declared with * SerialFixedArrayListAdapter. * typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows From a762c159fe334f1e1be6f448dd9ed6ea2519246b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 30 Dec 2019 01:13:33 +0100 Subject: [PATCH 0061/1774] pool raw access helper info output commented out --- datapool/PoolRawAccessHelper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index b17666712..fae45b535 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -81,7 +81,7 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t current ReturnValue_t result; uint8_t arrayPosition = 0; bool poolEntrySerialized = false; - info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; + //info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; while(not poolEntrySerialized) { DataSet currentDataSet = DataSet(); PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,¤tDataSet,PoolVariableIF::VAR_READ); From c73cb90c3645f50794cd2919ef73fc755cc93948 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 1 Jan 2020 16:54:05 +0100 Subject: [PATCH 0062/1774] receiveTc function adapted --- tmtcservices/TmTcBridge.cpp | 4 ++-- tmtcservices/TmTcBridge.h | 6 +++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 6af6d5248..ddd63d477 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -14,7 +14,7 @@ TmTcBridge::TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_): SystemObject(objectId_),tcStore(NULL), tmStore(NULL), ccsdsPacketDistributor(ccsdsPacketDistributor_), communicationLinkUp(false), - tmStored(false) { + tmStored(false), size(0) { TmTcReceptionQueue = QueueFactory::instance()-> createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH); @@ -55,7 +55,7 @@ ReturnValue_t TmTcBridge::performOperation(uint8_t operationCode) { } ReturnValue_t TmTcBridge::handleTc() { - ReturnValue_t result = receiveTc(); + ReturnValue_t result = receiveTc(&recvBuffer, &size); return result; } diff --git a/tmtcservices/TmTcBridge.h b/tmtcservices/TmTcBridge.h index 216dae8ba..8edf3f376 100644 --- a/tmtcservices/TmTcBridge.h +++ b/tmtcservices/TmTcBridge.h @@ -62,9 +62,11 @@ protected: /** * Implemented by child class. Perform receiving of Telecommand, for example by implementing * specific drivers or wrappers, e.g. UART Communication or lwIP stack + * @param recvBuffer [out] Received data + * @param size [out] Size of received data * @return */ - virtual ReturnValue_t receiveTc() = 0; + virtual ReturnValue_t receiveTc(uint8_t ** recvBuffer, uint32_t * size) = 0; /** * Handle Telemetry. Default implementation provided. @@ -117,6 +119,8 @@ private: static const uint8_t MAX_DOWNLINK_PACKETS_STORED = 20; FIFO fifo; + uint8_t * recvBuffer; + uint32_t size; }; From 831a01e79ef7d5c5fd6885486f9a9fc7333d504e Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 1 Jan 2020 17:31:17 +0100 Subject: [PATCH 0063/1774] recvBuffer and recvSize initialized --- tmtcservices/TmTcBridge.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index ddd63d477..7cc97d0d0 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -14,7 +14,7 @@ TmTcBridge::TmTcBridge(object_id_t objectId_, object_id_t ccsdsPacketDistributor_): SystemObject(objectId_),tcStore(NULL), tmStore(NULL), ccsdsPacketDistributor(ccsdsPacketDistributor_), communicationLinkUp(false), - tmStored(false), size(0) { + tmStored(false),recvBuffer(NULL), size(0) { TmTcReceptionQueue = QueueFactory::instance()-> createMessageQueue(TMTC_RECEPTION_QUEUE_DEPTH); From e2f07cbcd1436176c45ad8c846657436b0aed832 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 2 Jan 2020 14:01:21 +0100 Subject: [PATCH 0064/1774] connect and disconnect functions public --- tmtcservices/TmTcBridge.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/tmtcservices/TmTcBridge.h b/tmtcservices/TmTcBridge.h index 8edf3f376..7870e79b7 100644 --- a/tmtcservices/TmTcBridge.h +++ b/tmtcservices/TmTcBridge.h @@ -45,6 +45,8 @@ public: */ virtual MessageQueueId_t getReportReceptionQueue(uint8_t virtualChannel = 0); + void registerCommConnect(); + void registerCommDisconnect(); protected: MessageQueueIF* TmTcReceptionQueue; //!< Used to send and receive TMTC messages. TmTcMessage is used to transport messages between tasks. StorageManagerIF* tcStore; @@ -110,9 +112,6 @@ protected: */ void printData(uint8_t * data, uint32_t dataLen); - void registerCommConnect(); - void registerCommDisconnect(); - private: static const uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20; static const uint8_t MAX_STORED_DATA_SENT_PER_CYCLE = 10; From f6e88e83db014f529151126d7ba5fe681604981c Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 2 Jan 2020 21:12:21 +0100 Subject: [PATCH 0065/1774] debug output change --- tmtcservices/TmTcBridge.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 7cc97d0d0..e402d79eb 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -80,7 +80,7 @@ ReturnValue_t TmTcBridge::readTmQueue() { for (ReturnValue_t result = TmTcReceptionQueue->receiveMessage(&message); result == RETURN_OK; result = TmTcReceptionQueue->receiveMessage(&message)) { - if(not communicationLinkUp) { + if(communicationLinkUp == false) { result = storeDownlinkData(&message); return result; } @@ -92,7 +92,7 @@ ReturnValue_t TmTcBridge::readTmQueue() { result = sendTm(data, size); if (result != RETURN_OK) { - error << "UDP Server: Could not send TM packet"<< std::endl; + error << "TMTC Bridge: Could not send TM packet"<< std::endl; tmStore->deleteData(message.getStorageId()); return result; From a7450144de20cb086ba5a9602bd5a7ad44fb83af Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 3 Jan 2020 15:39:32 +0100 Subject: [PATCH 0066/1774] doxygen group definitions moved to framework --- devicehandlers/DeviceCommunicationIF.h | 4 ++++ subsystem/SubsystemBase.h | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index ca0e9fe27..06c228f72 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -3,6 +3,10 @@ #include #include +/** + * @defgroup interfaces Interfaces + * @brief Communication interfaces for flight software objects + */ /** * @brief This is an interface to decouple device communication from diff --git a/subsystem/SubsystemBase.h b/subsystem/SubsystemBase.h index 3294c46d7..1a050a9aa 100644 --- a/subsystem/SubsystemBase.h +++ b/subsystem/SubsystemBase.h @@ -12,6 +12,10 @@ #include #include +/** + * @defgroup subsystems Subsystem Objects + * Contains all Subsystem and Assemblies + */ class SubsystemBase: public SystemObject, public HasModesIF, public HasHealthIF, From 827f185e20788b0b72eaf4cd5d322e78fb7cadd6 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 4 Jan 2020 16:37:08 +0100 Subject: [PATCH 0067/1774] Some bugfixes(?) for PusServiceBase. Getter Function for Serial Buffer Adapter. --- container/FixedMap.h | 8 ++++---- container/FixedOrderedMultimap.h | 2 +- returnvalues/FwClassIds.h | 1 + serialize/SerialBufferAdapter.cpp | 8 ++++---- serialize/SerialBufferAdapter.h | 2 +- tmtcservices/PusServiceBase.h | 18 +++++++++++++----- 6 files changed, 24 insertions(+), 15 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 5e8ca9c35..d664a0861 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -16,8 +16,8 @@ template class FixedMap: public SerializeIF { 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_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); //!< P1: SID for HK packets + static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x02); //!< P1: SID for HK packets static const ReturnValue_t KEY_DOES_NOT_EXIST = MAKE_RETURN_CODE(0x03); private: @@ -88,10 +88,10 @@ public: ReturnValue_t insert(key_t key, T value, Iterator *storedValue = NULL) { if (exists(key) == HasReturnvaluesIF::RETURN_OK) { - return KEY_ALREADY_EXISTS; + return FixedMap::KEY_ALREADY_EXISTS; } if (_size == theMap.maxSize()) { - return MAP_FULL; + return FixedMap::MAP_FULL; } theMap[_size].first = key; theMap[_size].second = value; diff --git a/container/FixedOrderedMultimap.h b/container/FixedOrderedMultimap.h index 21629664b..3dd20a749 100644 --- a/container/FixedOrderedMultimap.h +++ b/container/FixedOrderedMultimap.h @@ -10,7 +10,7 @@ template> class FixedOrderedMultimap { public: - static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; + static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MULTIMAP; 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); diff --git a/returnvalues/FwClassIds.h b/returnvalues/FwClassIds.h index d21861c08..beef04754 100644 --- a/returnvalues/FwClassIds.h +++ b/returnvalues/FwClassIds.h @@ -24,6 +24,7 @@ enum { MEMORY_HELPER, //MH SERIALIZE_IF, //SE FIXED_MAP, //FM + FIXED_MULTIMAP, //FMM HAS_HEALTH_IF, //HHI FIFO_CLASS, //FF MESSAGE_PROXY, //MQP diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index d7ab0d880..a365cc993 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -96,10 +96,10 @@ uint8_t * SerialBufferAdapter::getBuffer() { return buffer; } -//template -//void SerialBufferAdapter::setBuffer(uint8_t * buffer_) { -// buffer = buffer_; -//} +template +void SerialBufferAdapter::setBuffer(uint8_t * buffer_) { + buffer = buffer_; +} //forward Template declaration for linker template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 0438f8841..cee2cb263 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -56,7 +56,7 @@ public: bool bigEndian); uint8_t * getBuffer(); - //void setBuffer(uint8_t * buffer_); + void setBuffer(uint8_t * buffer_); private: bool serializeLength; const uint8_t *constBuffer; diff --git a/tmtcservices/PusServiceBase.h b/tmtcservices/PusServiceBase.h index 2b5e8b67c..6c8c5f617 100644 --- a/tmtcservices/PusServiceBase.h +++ b/tmtcservices/PusServiceBase.h @@ -46,13 +46,20 @@ public: */ virtual ~PusServiceBase(); /** - * The handleRequest method shall handle any kind of Telecommand Request immediately. + * @brief The handleRequest method shall handle any kind of Telecommand Request immediately. + * @details * Implemetations can take the Telecommand in currentPacket and perform any kind of operation. * They may send additional "Start Success (1,3)" messages with the verifyReporter, but Completion * Success or Failure Reports are generated automatically after execution of this method. - * If a Telecommand can not be executed within one call cycle, this Base class is not the right parent. - * The child class may add additional error information in #errorParameters which are attached to the generated - * verification message. Subservice checking should be implemented in this method. + * + * If a Telecommand can not be executed within one call cycle, + * this Base class is not the right parent. + * + * The child class may add additional error information by setting #errorParameters which are + * attached to the generated verification message. + * + * Subservice checking should be implemented in this method. + * * @return The returned status_code is directly taken as main error code in the Verification Report. * On success, RETURN_OK shall be returned. */ @@ -91,7 +98,8 @@ protected: /** * One of two error parameters for additional error information. */ - uint8_t errorParameter2; + // shouldn't this be uint32_t ? The PUS Verification Message structure param2 has the size 4 + uint32_t errorParameter2; /** * This is a complete instance of the Telecommand reception queue of the class. * It is initialized on construction of the class. From 2ec486a8806f9c0bdf287ef81b04c6b494c592ef Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 5 Jan 2020 18:20:57 +0100 Subject: [PATCH 0068/1774] max number of stored packets lowered --- tmtcservices/TmTcBridge.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tmtcservices/TmTcBridge.h b/tmtcservices/TmTcBridge.h index 7870e79b7..8e4124e08 100644 --- a/tmtcservices/TmTcBridge.h +++ b/tmtcservices/TmTcBridge.h @@ -115,7 +115,7 @@ protected: private: static const uint8_t TMTC_RECEPTION_QUEUE_DEPTH = 20; static const uint8_t MAX_STORED_DATA_SENT_PER_CYCLE = 10; - static const uint8_t MAX_DOWNLINK_PACKETS_STORED = 20; + static const uint8_t MAX_DOWNLINK_PACKETS_STORED = 15; FIFO fifo; uint8_t * recvBuffer; From 59b25bee863987dd8a38517f95ac3dc2b780be1a Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 9 Jan 2020 19:04:33 +0100 Subject: [PATCH 0069/1774] pool raw helper input buffer type changed to uint32_t --- datapool/PoolRawAccessHelper.cpp | 4 ++-- datapool/PoolRawAccessHelper.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index fae45b535..e1ae56bf1 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -8,9 +8,9 @@ #include #include -PoolRawAccessHelper::PoolRawAccessHelper(uint8_t * poolIdBuffer_, +PoolRawAccessHelper::PoolRawAccessHelper(uint32_t * poolIdBuffer_, uint8_t numberOfParameters_): - poolIdBuffer(poolIdBuffer_), + poolIdBuffer(reinterpret_cast(poolIdBuffer_)), numberOfParameters(numberOfParameters_), validBufferIndex(0), validBufferIndexBit(1){ } diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index 25d8b1635..e9e9c8ec5 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -28,7 +28,7 @@ public: * @param poolIdBuffer_ A buffer of uint32_t pool IDs * @param numberOfParameters_ The number of parameters / pool IDs */ - PoolRawAccessHelper(uint8_t * poolIdBuffer_, uint8_t numberOfParameters_); + PoolRawAccessHelper(uint32_t * poolIdBuffer_, uint8_t numberOfParameters_); virtual ~PoolRawAccessHelper(); /** From 0ce67de8c8eb8f4eb532e4445e3a1e3765ff07f2 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 10 Jan 2020 00:57:09 +0100 Subject: [PATCH 0070/1774] Changes to pool access classes 1. PoolRawAccessHelper is more robust now and has better error handling 2. PoolRawAccess: Removed an unneeded constructor value, moved serialize further to the top. Added new returnvalues and more precise error handling for read() call 3. DataSet: Made MAX Number of data pool entries public so it can be used by pool raw access error handling --- datapool/DataSet.h | 71 +++++++------- datapool/PoolRawAccess.cpp | 72 +++++++++------ datapool/PoolRawAccess.h | 153 ++++++++++++++++--------------- datapool/PoolRawAccessHelper.cpp | 51 ++++++++--- datapool/PoolRawAccessHelper.h | 2 + 5 files changed, 199 insertions(+), 150 deletions(-) diff --git a/datapool/DataSet.h b/datapool/DataSet.h index deee8ca66..e8e1a5972 100644 --- a/datapool/DataSet.h +++ b/datapool/DataSet.h @@ -37,44 +37,11 @@ * \ingroup data_pool */ class DataSet: public DataSetIF, public HasReturnvaluesIF, public SerializeIF { -private: + +public: //SHOULDDO we could use a linked list of datapool variables static const uint8_t DATA_SET_MAX_SIZE = 63; //!< This definition sets the maximum number of variables to register in one DataSet. - /** - * \brief This array represents all pool variables registered in this set. - * \details It has a maximum size of DATA_SET_MAX_SIZE. - */ - PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE]; - /** - * \brief The fill_count attribute ensures that the variables register in the correct array - * position and that the maximum number of variables is not exceeded. - */ - uint16_t fill_count; - /** - * States of the seet. - */ - enum States { - DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED - DATA_SET_WAS_READ //!< DATA_SET_WAS_READ - }; - /** - * \brief state manages the internal state of the data set, which is important e.g. for the - * behavior on destruction. - */ - States state; - /** - * \brief This is a small helper function to facilitate locking the global data pool. - * \details It makes use of the lockDataPool method offered by the DataPool class. - */ - uint8_t lockDataPool(); - /** - * \brief This is a small helper function to facilitate unlocking the global data pool. - * \details It makes use of the freeDataPoolLock method offered by the DataPool class. - */ - uint8_t freeDataPoolLock(); - -public: static const uint8_t INTERFACE_ID = CLASS_ID::DATA_SET_CLASS; static const ReturnValue_t INVALID_PARAMETER_DEFINITION = MAKE_RETURN_CODE( 0x01 ); @@ -165,6 +132,40 @@ public: ReturnValue_t serializeRawFromIdBuffer(uint8_t ** buffer, uint32_t * size, const uint32_t max_size, bool bigEndian, uint32_t * poolIdBuffer, uint32_t poolIdSize); +private: + /** + * \brief This array represents all pool variables registered in this set. + * \details It has a maximum size of DATA_SET_MAX_SIZE. + */ + PoolVariableIF* registeredVariables[DATA_SET_MAX_SIZE]; + /** + * \brief The fill_count attribute ensures that the variables register in the correct array + * position and that the maximum number of variables is not exceeded. + */ + uint16_t fill_count; + /** + * States of the seet. + */ + enum States { + DATA_SET_UNINITIALISED, //!< DATA_SET_UNINITIALISED + DATA_SET_WAS_READ //!< DATA_SET_WAS_READ + }; + /** + * \brief state manages the internal state of the data set, which is important e.g. for the + * behavior on destruction. + */ + States state; + /** + * \brief This is a small helper function to facilitate locking the global data pool. + * \details It makes use of the lockDataPool method offered by the DataPool class. + */ + uint8_t lockDataPool(); + /** + * \brief This is a small helper function to facilitate unlocking the global data pool. + * \details It makes use of the freeDataPoolLock method offered by the DataPool class. + */ + uint8_t freeDataPoolLock(); + }; #endif /* DATASET_H_ */ diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 7cc618528..c4e327b19 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -5,8 +5,7 @@ #include PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, - DataSetIF* data_set, ReadWriteMode_t setReadWriteMode, - bool registerVectors) : + DataSetIF* data_set, ReadWriteMode_t setReadWriteMode) : dataPoolId(set_id), arrayEntry(setArrayEntry), valid(false), type(Type::UNKNOWN_TYPE), typeSize( 0), arraySize(0), sizeTillEnd(0), readWriteMode(setReadWriteMode) { memset(value, 0, sizeof(value)); @@ -20,6 +19,7 @@ PoolRawAccess::~PoolRawAccess() { } ReturnValue_t PoolRawAccess::read() { + ReturnValue_t result = RETURN_FAILED; PoolEntryIF* read_out = ::dataPool.getRawData(dataPoolId); if (read_out != NULL) { valid = read_out->getValid(); @@ -35,21 +35,30 @@ ReturnValue_t PoolRawAccess::read() { memcpy(value, ptr, typeSize); return HasReturnvaluesIF::RETURN_OK; } else { - //Error value type too large. + result = READ_TYPE_TOO_LARGE; } } else { - //Error index requested too large + result = READ_INDEX_TOO_LARGE; } } else { - //Error entry does not exist. + result = READ_ENTRY_NON_EXISTENT; } error << "PoolRawAccess: read of DP Variable 0x" << std::hex << dataPoolId - << std::dec << " failed." << std::endl; + << std::dec << " failed, "; + if(result == READ_TYPE_TOO_LARGE) { + error << "type too large." << std::endl; + } + else if(result == READ_INDEX_TOO_LARGE) { + error << "index too large." << std::endl; + } + else { + error << "entry does not exist." << std::endl; + } valid = INVALID; typeSize = 0; sizeTillEnd = 0; memset(value, 0, sizeof(value)); - return HasReturnvaluesIF::RETURN_FAILED; + return result; } ReturnValue_t PoolRawAccess::commit() { @@ -90,6 +99,32 @@ ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer, return HasReturnvaluesIF::RETURN_OK; } + +ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, + const uint32_t max_size, bool bigEndian) const { + if (typeSize + *size <= max_size) { + if (bigEndian) { +#ifndef BYTE_ORDER_SYSTEM +#error BYTE_ORDER_SYSTEM not defined +#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + for (uint8_t count = 0; count < typeSize; count++) { + (*buffer)[count] = value[typeSize - count - 1]; + } +#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN + memcpy(*buffer, value, typeSize); +#endif + } else { + memcpy(*buffer, value, typeSize); + } + *size += typeSize; + (*buffer) += typeSize; + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::BUFFER_TOO_SHORT; + } +} + + Type PoolRawAccess::getType() { return type; } @@ -146,29 +181,6 @@ uint16_t PoolRawAccess::getSizeTillEnd() const { return sizeTillEnd; } -ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - if (typeSize + *size <= max_size) { - if (bigEndian) { -#ifndef BYTE_ORDER_SYSTEM -#error BYTE_ORDER_SYSTEM not defined -#elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - for (uint8_t count = 0; count < typeSize; count++) { - (*buffer)[count] = value[typeSize - count - 1]; - } -#elif BYTE_ORDER_SYSTEM == BIG_ENDIAN - memcpy(*buffer, value, typeSize); -#endif - } else { - memcpy(*buffer, value, typeSize); - } - *size += typeSize; - (*buffer) += typeSize; - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::BUFFER_TOO_SHORT; - } -} uint32_t PoolRawAccess::getSerializedSize() const { return typeSize; diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 603bae239..432d9ad95 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -15,70 +15,17 @@ * data pool access. * @ingroup data_pool */ -class PoolRawAccess: public PoolVariableIF { -private: - /** - * \brief To access the correct data pool entry on read and commit calls, the data pool id - * is stored. - */ - uint32_t dataPoolId; - /** - * \brief The array entry that is fetched from the data pool. - */ - uint8_t arrayEntry; - /** - * \brief The valid information as it was stored in the data pool is copied to this attribute. - */ - uint8_t valid; - /** - * \brief This value contains the type of the data pool entry. - */ - Type type; - /** - * \brief This value contains the size of the data pool entry type in bytes. - */ - uint8_t typeSize; - /** - * The size of the DP array (single values return 1) - */ - uint8_t arraySize; - /** - * The size (in bytes) from the selected entry till the end of this DataPool variable. - */ - uint16_t sizeTillEnd; - /** - * \brief The information whether the class is read-write or read-only is stored here. - */ - ReadWriteMode_t readWriteMode; - static const uint8_t RAW_MAX_SIZE = sizeof(double); -protected: - /** - * \brief This is a call to read the value from the global data pool. - * \details When executed, this operation tries to fetch the pool entry with matching - * data pool id from the global data pool and copies the value and the valid - * information to its local attributes. In case of a failure (wrong type or - * pool id not found), the variable is set to zero and invalid. - * The operation does NOT provide any mutual exclusive protection by itself ! - * If reading from the data pool without information about the type is desired, - * initialize the raw pool access by supplying a data set and using the data set - * read function, which calls this read function. - */ - ReturnValue_t read(); - /** - * \brief The commit call writes back the variable's value to the data pool. - * \details It checks type and size, as well as if the variable is writable. If so, - * the value is copied and the valid flag is automatically set to "valid". - * The operation does NOT provide any mutual exclusive protection by itself. - * - */ - ReturnValue_t commit(); +class PoolRawAccess: public PoolVariableIF, HasReturnvaluesIF { public: - static const uint8_t INTERFACE_ID = CLASS_ID::POOL_RAW_ACCESS_CLASS; static const ReturnValue_t INCORRECT_SIZE = MAKE_RETURN_CODE(0x01); static const ReturnValue_t DATA_POOL_ACCESS_FAILED = MAKE_RETURN_CODE(0x02); + static const ReturnValue_t READ_TYPE_TOO_LARGE = MAKE_RETURN_CODE(0x03); + static const ReturnValue_t READ_INDEX_TOO_LARGE = MAKE_RETURN_CODE(0x04); + static const ReturnValue_t READ_ENTRY_NON_EXISTENT = MAKE_RETURN_CODE(0x05); + static const uint8_t RAW_MAX_SIZE = sizeof(double); uint8_t value[RAW_MAX_SIZE]; - //PoolRawAccess(); + /** * This constructor is used to access a data pool entry with a * given ID if the target type is not known. A DataSet object is supplied @@ -96,25 +43,13 @@ public: */ PoolRawAccess(uint32_t data_pool_id, uint8_t arrayEntry, DataSetIF* data_set, ReadWriteMode_t setReadWriteMode = - PoolVariableIF::VAR_READ,bool registerVectors = false); + PoolVariableIF::VAR_READ); /** * \brief The classes destructor is empty. If commit() was not called, the local value is * discarded and not written back to the data pool. */ ~PoolRawAccess(); - /** - * @brief Serialize raw pool entry into provided buffer directly - * @param buffer Provided buffer. Raw pool data will be copied here - * @param size [out] Increment provided size value by serialized size - * @param max_size Maximum allowed serialization size - * @param bigEndian Specify endianess - * @return - @c RETURN_OK if serialization was successfull - * - @c SerializeIF::BUFFER_TOO_SHORT if range check failed - */ - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; - /** * \brief This operation returns a pointer to the entry fetched. * \details Return pointer to the buffer containing the raw data @@ -136,6 +71,19 @@ public: */ ReturnValue_t getEntryEndianSafe(uint8_t* buffer, uint32_t* size, uint32_t max_size); + + /** + * @brief Serialize raw pool entry into provided buffer directly + * @param buffer Provided buffer. Raw pool data will be copied here + * @param size [out] Increment provided size value by serialized size + * @param max_size Maximum allowed serialization size + * @param bigEndian Specify endianess + * @return - @c RETURN_OK if serialization was successfull + * - @c SerializeIF::BUFFER_TOO_SHORT if range check failed + */ + ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, + const uint32_t max_size, bool bigEndian) const; + /** * With this method, the content can be set from a big endian buffer safely. * @param buffer Pointer to the data to set @@ -181,6 +129,67 @@ public: ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); + +protected: + /** + * \brief This is a call to read the value from the global data pool. + * \details When executed, this operation tries to fetch the pool entry with matching + * data pool id from the global data pool and copies the value and the valid + * information to its local attributes. In case of a failure (wrong type or + * pool id not found), the variable is set to zero and invalid. + * The operation does NOT provide any mutual exclusive protection by itself ! + * If reading from the data pool without information about the type is desired, + * initialize the raw pool access by supplying a data set and using the data set + * read function, which calls this read function. + * @return -@c RETURN_OK Read successfull + * -@c READ_TYPE_TOO_LARGE + * -@c READ_INDEX_TOO_LARGE + * -@c READ_ENTRY_NON_EXISTENT + */ + ReturnValue_t read(); + /** + * \brief The commit call writes back the variable's value to the data pool. + * \details It checks type and size, as well as if the variable is writable. If so, + * the value is copied and the valid flag is automatically set to "valid". + * The operation does NOT provide any mutual exclusive protection by itself. + * + */ + ReturnValue_t commit(); + +private: + /** + * \brief To access the correct data pool entry on read and commit calls, the data pool id + * is stored. + */ + uint32_t dataPoolId; + /** + * \brief The array entry that is fetched from the data pool. + */ + uint8_t arrayEntry; + /** + * \brief The valid information as it was stored in the data pool is copied to this attribute. + */ + uint8_t valid; + /** + * \brief This value contains the type of the data pool entry. + */ + Type type; + /** + * \brief This value contains the size of the data pool entry type in bytes. + */ + uint8_t typeSize; + /** + * The size of the DP array (single values return 1) + */ + uint8_t arraySize; + /** + * The size (in bytes) from the selected entry till the end of this DataPool variable. + */ + uint16_t sizeTillEnd; + /** + * \brief The information whether the class is read-write or read-only is stored here. + */ + ReadWriteMode_t readWriteMode; }; #endif /* POOLRAWACCESS_H_ */ diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index e1ae56bf1..8c7502700 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -78,45 +78,70 @@ ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(Serializa ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct, bool withValidMask, uint8_t * validityMask) { - ReturnValue_t result; + ReturnValue_t result = RETURN_FAILED; uint8_t arrayPosition = 0; + uint8_t counter = 0; bool poolEntrySerialized = false; - //info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; + info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; while(not poolEntrySerialized) { + + if(counter > DataSet::DATA_SET_MAX_SIZE) { + error << "Pool Raw Access Helper: Config error, max. number of possible data set variables exceeded" << std::endl; + return result; + } + counter ++; + DataSet currentDataSet = DataSet(); PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,¤tDataSet,PoolVariableIF::VAR_READ); + result = currentDataSet.read(); if (result != RETURN_OK) { - debug << std::hex << "Pool Raw Access Helper: Error reading raw dataset" << std::dec << std::endl; + debug << std::hex << "Pool Raw Access Helper: Error reading raw dataset with returncode " + << result << std::dec << std::endl; return result; } - uint8_t remainingSize = currentPoolRawAccess.getSizeTillEnd() - currentPoolRawAccess.getSizeOfType(); - if(remainingSize == 0) { - poolEntrySerialized = true; - } - else if(remainingSize > 0) { - arrayPosition += currentPoolRawAccess.getSizeOfType() / 8; - } - else { - error << "Pool Raw Access Helper: Configuration Error. Size till end smaller than 0" << std::endl; + + result = checkRemainingSize(¤tPoolRawAccess, &poolEntrySerialized, &arrayPosition); + if(result != RETURN_OK) { + error << "Pool Raw Access Helper: Configuration Error at pool ID " << std::hex << currentPoolId + << ". Size till end smaller than 0" << std::dec << std::endl; return result; } + // set valid mask bit if necessary if(withValidMask) { if(currentPoolRawAccess.isValid()) { handleMaskModification(validityMask); } } + result = currentDataSet.serialize(argStruct.buffer, argStruct.size, argStruct.max_size, argStruct.bigEndian); if (result != RETURN_OK) { - debug << "Pool Raw Access Helper: Error serializing pool data into send buffer" << std::endl; + debug << "Pool Raw Access Helper: Error serializing pool data with ID 0x" << std::hex << + currentPoolId << " into send buffer with return code " << result << std::dec << std::endl; return result; } + } return result; } +ReturnValue_t PoolRawAccessHelper::checkRemainingSize(PoolRawAccess * currentPoolRawAccess, + bool * isSerialized, uint8_t * arrayPosition) { + int8_t remainingSize = currentPoolRawAccess->getSizeTillEnd() - currentPoolRawAccess->getSizeOfType(); + if(remainingSize == 0) { + *isSerialized = true; + } + else if(remainingSize > 0) { + *arrayPosition += currentPoolRawAccess->getSizeOfType(); + } + else { + return RETURN_FAILED; + } + return RETURN_OK; +} + void PoolRawAccessHelper::handleMaskModification(uint8_t * validityMask) { validityMask[validBufferIndex] = bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true); diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index e9e9c8ec5..72f2324c6 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -90,6 +90,8 @@ private: ReturnValue_t handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct, bool withValidMask = false, uint8_t * validityMask = NULL); + ReturnValue_t checkRemainingSize(PoolRawAccess * currentPoolRawAccess, + bool * isSerialized, uint8_t * arrayPosition); void handleMaskModification(uint8_t * validityMask); /** * Sets specific bit of a byte From a8247eb2f0406ea78259f9a5c3f70f7b02cef15a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 12 Jan 2020 14:18:12 +0100 Subject: [PATCH 0071/1774] Some more debugging output switched on --- container/SimpleRingBuffer.h | 5 +++-- storagemanager/LocalPool.h | 4 ++-- tcdistribution/PUSDistributor.cpp | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/container/SimpleRingBuffer.h b/container/SimpleRingBuffer.h index 45cb09277..4552a1c0a 100644 --- a/container/SimpleRingBuffer.h +++ b/container/SimpleRingBuffer.h @@ -5,8 +5,9 @@ #include /** - * Circular buffer implementation, useful for buffering into data streams. - * Note that the deleteData() has to be called to increment the read pointer + * @brief Circular buffer implementation, useful for buffering into data streams. + * @details Note that the deleteData() has to be called to increment the read pointer + * @ingroup containers */ class SimpleRingBuffer: public RingBufferBase<> { public: diff --git a/storagemanager/LocalPool.h b/storagemanager/LocalPool.h index 80e6a4956..f8b2b7302 100644 --- a/storagemanager/LocalPool.h +++ b/storagemanager/LocalPool.h @@ -294,8 +294,8 @@ inline ReturnValue_t LocalPool::reserveSpace( if (!ignoreFault) { internalErrorReporter->storeFull(); } -// error << "LocalPool( " << std::hex << getObjectId() << std::dec -// << " )::reserveSpace: Packet store is full." << std::endl; + error << "LocalPool( " << std::hex << getObjectId() << std::dec + << " )::reserveSpace: Packet store is full." << std::endl; } return status; } diff --git a/tcdistribution/PUSDistributor.cpp b/tcdistribution/PUSDistributor.cpp index a209620f9..0f1aa7f03 100644 --- a/tcdistribution/PUSDistributor.cpp +++ b/tcdistribution/PUSDistributor.cpp @@ -31,7 +31,7 @@ iterator_t PUSDistributor::selectDestination() { } if (tcStatus != RETURN_OK) { - debug << "PUSDistributor::handlePacket: error with " << (int) tcStatus + debug << "PUSDistributor::handlePacket: error with 0x" << std::hex << (int) tcStatus << std::endl; return this->queueMap.end(); } else { From d2325e60b69650b5dde10f28dc88a929decf6527 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 12 Jan 2020 15:51:59 +0100 Subject: [PATCH 0072/1774] Import bugfix in MessageQueue.cpp lastPartner is only assigned if receiveMessage is successful --- osal/FreeRTOS/MessageQueue.cpp | 4 +++- tcdistribution/PUSDistributor.cpp | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 1f514cf38..887df3926 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -38,7 +38,9 @@ ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) { ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message, MessageQueueId_t* receivedFrom) { ReturnValue_t status = this->receiveMessage(message); - *receivedFrom = this->lastPartner; + if(status == HasReturnvaluesIF::RETURN_OK) { + *receivedFrom = this->lastPartner; + } return status; } diff --git a/tcdistribution/PUSDistributor.cpp b/tcdistribution/PUSDistributor.cpp index 0f1aa7f03..7b413eab7 100644 --- a/tcdistribution/PUSDistributor.cpp +++ b/tcdistribution/PUSDistributor.cpp @@ -48,6 +48,7 @@ ReturnValue_t PUSDistributor::registerService(AcceptsTelecommandsIF* service) { ReturnValue_t returnValue = RETURN_OK; bool errorCode = true; uint16_t serviceId = service->getIdentifier(); + //info << "Service ID: " << (int)serviceId << std::endl; MessageQueueId_t queue = service->getRequestQueue(); errorCode = this->queueMap.insert( std::pair(serviceId, queue)).second; From 1369e792b4c1f3327923c1e7418641c687bb512e Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 13 Jan 2020 00:14:14 +0100 Subject: [PATCH 0073/1774] CommandingServiceBase documentation --- tmtcservices/CommandingServiceBase.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tmtcservices/CommandingServiceBase.h b/tmtcservices/CommandingServiceBase.h index 8ce25f007..279f9ab43 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/tmtcservices/CommandingServiceBase.h @@ -195,7 +195,7 @@ protected: * @param tcData Application Data of TC Packet * @param tcDataLen * @param id MessageQueue ID is stored here - * @param objectId + * @param objectId Object ID is extracted and stored here * @return - @c RETURN_OK on success * - @c RETURN_FAILED * - @c CSB or implementation specific return codes @@ -206,15 +206,15 @@ protected: /** * After the Message Queue and Object ID are determined, - * the command is prepared by using an implementation specific CommandMessage type which is sent to - * the target device. It contains all necessary information for the device to - * execute telecommands. + * the command is prepared by using an implementation specific CommandMessage type + * which is sent to the target object. + * It contains all necessary information for the device to execute telecommands. * @param message * @param subservice * @param tcData * @param tcDataLen * @param state - * @param objectId + * @param objectId Target object ID * @return */ virtual ReturnValue_t prepareCommand(CommandMessage *message, @@ -226,11 +226,11 @@ protected: * and the respective PUS Commanding Service once the execution has started. * The PUS Commanding Service receives replies from the target device and forwards them by calling this function. * There are different translations of these replies to specify how the Command Service proceeds. - * @param reply Command Message which contains information about the command - * @param previousCommand + * @param reply[out] Command Message which contains information about the command + * @param previousCommand [out] * @param state * @param optionalNextCommand - * @param objectId + * @param objectId Source object ID * @param isStep Flag value to mark steps of command execution * @return - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to generate TC verification success * - @c INVALID_REPLY can handle unrequested replies From 01551b8fa5bf642bac0ec124eef94f192087188a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 13 Jan 2020 01:21:53 +0100 Subject: [PATCH 0074/1774] Getter function in SerialBufferAdapter For const uint8_t * --- serialize/SerialBufferAdapter.cpp | 27 ++++++++++++++++++++++----- serialize/SerialBufferAdapter.h | 10 +++++++++- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index a365cc993..a045d37ab 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -1,24 +1,27 @@ #include #include +#include template SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, T bufferLength, bool serializeLength) : - serializeLength(serializeLength), constBuffer(buffer), buffer(NULL), bufferLength( - bufferLength) { + currentBufferType(bufferType::CONST), serializeLength(serializeLength), + constBuffer(buffer), buffer(NULL), bufferLength(bufferLength) { + } template SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, T bufferLength, bool serializeLength) : - serializeLength(serializeLength), constBuffer(NULL), buffer(buffer), bufferLength( - bufferLength) { + currentBufferType(bufferType::NORMAL),serializeLength(serializeLength), constBuffer(NULL), buffer(buffer), + bufferLength(bufferLength) { } template SerialBufferAdapter::SerialBufferAdapter(uint32_t* buffer, T bufferLength, bool serializeLength) : - serializeLength(serializeLength), constBuffer(NULL), buffer(reinterpret_cast(buffer)), + currentBufferType(bufferType::NORMAL),serializeLength(serializeLength), + constBuffer(NULL), buffer(reinterpret_cast(buffer)), bufferLength(bufferLength*4) { } @@ -93,14 +96,28 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, template uint8_t * SerialBufferAdapter::getBuffer() { + if(currentBufferType != NORMAL) { + warning << "Wrong access function for stored type ! Use getConstBuffer()" << std::endl; + return 0; + } return buffer; } +template +const uint8_t * SerialBufferAdapter::getConstBuffer() { + if(currentBufferType != CONST) { + warning << "Wrong access function for stored type ! Use getBuffer()" << std::endl; + return 0; + } + return constBuffer; +} + template void SerialBufferAdapter::setBuffer(uint8_t * buffer_) { buffer = buffer_; } + //forward Template declaration for linker template class SerialBufferAdapter; template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index cee2cb263..6623beb3b 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -28,7 +28,7 @@ public: SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLength = false); /** - * Constructoor for non-constant uint8_t buffer. Length field can be serialized optionally. + * Constructor for non-constant uint8_t buffer. Length field can be serialized optionally. * Type of length can be supplied as template type. * @param buffer * @param bufferLength @@ -56,8 +56,16 @@ public: bool bigEndian); uint8_t * getBuffer(); + const uint8_t * getConstBuffer(); void setBuffer(uint8_t * buffer_); private: + + enum bufferType { + NORMAL, + CONST + }; + bufferType currentBufferType; + bool serializeLength; const uint8_t *constBuffer; uint8_t *buffer; From c7479523363c83db5e1c3c9a207a5eeee5cf5a65 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 14 Jan 2020 00:49:09 +0100 Subject: [PATCH 0075/1774] fixed map full() function added. Pool raw access debugging --- container/FixedMap.h | 9 +++++++++ datapool/PoolRawAccess.cpp | 1 + datapool/PoolRawAccessHelper.cpp | 5 +++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index d664a0861..55a435338 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -164,6 +164,15 @@ public: return theMap.maxSize(); } + bool full() { + if(_size == theMap.maxSize()) { + return true; + } + else { + return false; + } + } + virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&this->_size, diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index c4e327b19..66ba6218b 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -38,6 +38,7 @@ ReturnValue_t PoolRawAccess::read() { result = READ_TYPE_TOO_LARGE; } } else { + info << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl; result = READ_INDEX_TOO_LARGE; } } else { diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index 8c7502700..de6e4802f 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -92,11 +92,12 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t current counter ++; DataSet currentDataSet = DataSet(); + info << "Current array position: " << (int)arrayPosition << std::endl; PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,¤tDataSet,PoolVariableIF::VAR_READ); result = currentDataSet.read(); if (result != RETURN_OK) { - debug << std::hex << "Pool Raw Access Helper: Error reading raw dataset with returncode " + debug << std::hex << "Pool Raw Access Helper: Error reading raw dataset with returncode 0x" << result << std::dec << std::endl; return result; } @@ -134,7 +135,7 @@ ReturnValue_t PoolRawAccessHelper::checkRemainingSize(PoolRawAccess * currentPoo *isSerialized = true; } else if(remainingSize > 0) { - *arrayPosition += currentPoolRawAccess->getSizeOfType(); + *arrayPosition += 1; } else { return RETURN_FAILED; From b0d88129db48db94d4d8ed4526408c62c962e2f0 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 14 Jan 2020 01:39:47 +0100 Subject: [PATCH 0076/1774] Pool Raw Access Helper bugfix debug output commented --- datapool/PoolRawAccessHelper.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index de6e4802f..646ffbb1a 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -82,7 +82,7 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t current uint8_t arrayPosition = 0; uint8_t counter = 0; bool poolEntrySerialized = false; - info << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; + //debug << "Pool Raw Access Helper: Handling Pool ID: " << std::hex << currentPoolId << std::endl; while(not poolEntrySerialized) { if(counter > DataSet::DATA_SET_MAX_SIZE) { @@ -92,7 +92,7 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t current counter ++; DataSet currentDataSet = DataSet(); - info << "Current array position: " << (int)arrayPosition << std::endl; + //debug << "Current array position: " << (int)arrayPosition << std::endl; PoolRawAccess currentPoolRawAccess(currentPoolId,arrayPosition,¤tDataSet,PoolVariableIF::VAR_READ); result = currentDataSet.read(); From f16cce8be11be06f704fd0f141cb28dea233d802 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 15 Jan 2020 13:32:21 +0100 Subject: [PATCH 0077/1774] Basic doc for thermal modules started --- thermal/ThermalComponent.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/thermal/ThermalComponent.h b/thermal/ThermalComponent.h index 932438684..7482bd9b8 100644 --- a/thermal/ThermalComponent.h +++ b/thermal/ThermalComponent.h @@ -14,6 +14,9 @@ public: float hysteresis; float heaterSwitchoff; }; + + // TODO: Documentaiton ,what is NOP? + // propably Non-operational? struct NopParameters { float lowerNopLimit; float upperNopLimit; From 9aa57f29b81d066429f77cd163043f661062d7ed Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 15 Jan 2020 13:52:18 +0100 Subject: [PATCH 0078/1774] basic documentation thermal --- thermal/AbstractTemperatureSensor.h | 9 +++++++++ thermal/CoreComponent.h | 1 + thermal/TemperatureSensor.h | 8 ++++++++ thermal/ThermalModule.h | 3 +++ 4 files changed, 21 insertions(+) diff --git a/thermal/AbstractTemperatureSensor.h b/thermal/AbstractTemperatureSensor.h index 75437dca8..3bebbe73c 100644 --- a/thermal/AbstractTemperatureSensor.h +++ b/thermal/AbstractTemperatureSensor.h @@ -10,6 +10,15 @@ #include "ThermalModuleIF.h" #include "tcsDefinitions.h" +/** + * @defgroup thermal Thermal Components + * @brief Contains all components related to thermal tasks (sensors, heaters) + */ + +/** + * @brief Base class for Temperature Sensor, implements all important interfaces + * @ingroup thermal + */ class AbstractTemperatureSensor: public HasHealthIF, public SystemObject, public ExecutableObjectIF, diff --git a/thermal/CoreComponent.h b/thermal/CoreComponent.h index f7e7aff8d..e21ee113b 100644 --- a/thermal/CoreComponent.h +++ b/thermal/CoreComponent.h @@ -8,6 +8,7 @@ #include #include +// TODO: Documentaiton, how to use this? only use Thermal COmponent, which inherits core component? class CoreComponent: public ThermalComponentIF { public: struct Parameters { diff --git a/thermal/TemperatureSensor.h b/thermal/TemperatureSensor.h index de280d877..cbf8ea30f 100644 --- a/thermal/TemperatureSensor.h +++ b/thermal/TemperatureSensor.h @@ -5,6 +5,14 @@ #include "AbstractTemperatureSensor.h" #include +/** + * @brief This building block handles non-linear value conversion and + * range checks for analog temperature sensors. + * @details + * + * + */ + template class TemperatureSensor: public AbstractTemperatureSensor { public: diff --git a/thermal/ThermalModule.h b/thermal/ThermalModule.h index d8ac7d732..e65560cd6 100644 --- a/thermal/ThermalModule.h +++ b/thermal/ThermalModule.h @@ -11,6 +11,9 @@ #include "RedundantHeater.h" class PowerSwitchIF; +/** + * @brief Allows creation of different thermal control domains within a system. + */ class ThermalModule: public ThermalModuleIF { friend class ThermalController; public: From 1437f33027cf60c8561eb3517418df2b16194016 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 15 Jan 2020 17:30:23 +0100 Subject: [PATCH 0079/1774] Serial Fixed Array List template type clarifications --- serialize/SerialArrayListAdapter.h | 1 + serialize/SerialBufferAdapter.h | 3 ++- serialize/SerialFixedArrayListAdapter.h | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 7e2e527bc..72b8d97f6 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -12,6 +12,7 @@ #include /** + * Also serializes length field ! * \ingroup serialize */ template diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 6623beb3b..b7729e316 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -11,7 +11,8 @@ * Additionally, the buffer length can be serialized too and will be put in front of the serialized buffer. * * Can be used with SerialLinkedListAdapter by declaring a SerializeElement with - * SerialElement> serialBufferElement + * SerialElement> serialBufferElement. + * Right now, the SerialBufferAdapter must always be initialized with the buffer and size ! * * \ingroup serialize */ diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index c8424f05d..4c4ec56fd 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -8,34 +8,38 @@ * @brief This adapter provides an interface for SerializeIF to serialize and deserialize * buffers with a header containing the buffer length. * @details + * * Can be used by SerialLinkedListAdapter by using this type in * SerializeElement<>. + * * Buffers with a size header inside that class can be declared with - * SerialFixedArrayListAdapter. - * typeOfMaxData specifies the data type of the buffer header containing the buffer size that follows - * and MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. + * SerialFixedArrayListAdapter. + * LENGTH_FIELD_TYPE specifies the data type of the buffer header containing the buffer size + * (defaults to 1 byte length field) that follows and MAX_BUFFER_LENGTH specifies + * the maximum allowed value for the buffer size. + * * The sequence of objects is defined in the constructor by using the setStart and setNext functions. * * @ingroup serialize */ -template -class SerialFixedArrayListAdapter : public FixedArrayList, public SerializeIF { +template +class SerialFixedArrayListAdapter : public FixedArrayList, public SerializeIF { public: template - SerialFixedArrayListAdapter(Args... args) : FixedArrayList(std::forward(args)...) { + SerialFixedArrayListAdapter(Args... args) : FixedArrayList(std::forward(args)...) { } ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const { - return SerialArrayListAdapter::serialize(this, buffer, size, max_size, bigEndian); + return SerialArrayListAdapter::serialize(this, buffer, size, max_size, bigEndian); } uint32_t getSerializedSize() const { - return SerialArrayListAdapter::getSerializedSize(this); + return SerialArrayListAdapter::getSerializedSize(this); } ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) { - return SerialArrayListAdapter::deSerialize(this, buffer, size, bigEndian); + return SerialArrayListAdapter::deSerialize(this, buffer, size, bigEndian); } }; From 9bdbc2c380780ae7f523c4367560a13f1c64ca66 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 16 Jan 2020 18:46:29 +0100 Subject: [PATCH 0080/1774] Endian swapper changes, Serial buffer adapter New Serial Buffer Adapter with complete template class for buffer type. Endian Swapper input now standard uint8_t * pointers instead of template type. Fixed Array List new ctor, but commented out for now --- container/FixedArrayList.h | 8 ++ serialize/EndianSwapper.h | 7 +- serialize/SerialBufferAdapter2.h | 139 +++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+), 5 deletions(-) create mode 100644 serialize/SerialBufferAdapter2.h diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index eeffcc870..ef2a82f5c 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -14,6 +14,14 @@ public: ArrayList(data, MAX_SIZE) { } + //We could create a constructor to initialize the fixed array list with data and the known size field + //so it can be used for serialization too (with SerialFixedArrrayListAdapter) + //is this feasible? +// FixedArrayList(T * data_, count_t count): +// ArrayList(data, MAX_SIZE) { +// memcpy(data, data_, count); +// } + FixedArrayList(const FixedArrayList& other) : ArrayList(data, MAX_SIZE) { memcpy(this->data, other.data, sizeof(this->data)); diff --git a/serialize/EndianSwapper.h b/serialize/EndianSwapper.h index db170c0b2..6c391316a 100644 --- a/serialize/EndianSwapper.h +++ b/serialize/EndianSwapper.h @@ -48,17 +48,14 @@ public: } template - static void swap(T * out, const T * in, uint32_t size) { + static void swap(uint8_t * out, const uint8_t * in, uint32_t size) { #ifndef BYTE_ORDER_SYSTEM #error BYTE_ORDER_SYSTEM not defined #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN - const uint8_t * in_buffer = reinterpret_cast(in); - uint8_t * out_buffer = reinterpret_cast(out); for (uint8_t count = 0; count < size; count++) { for(uint8_t i = 0; i < sizeof(T);i++) { - out_buffer[sizeof(T)* (count + 1) - i - 1] = in_buffer[count * sizeof(T) + i]; + out[sizeof(T)* (count + 1) - i - 1] = in[count * sizeof(T) + i]; } - } return; diff --git a/serialize/SerialBufferAdapter2.h b/serialize/SerialBufferAdapter2.h new file mode 100644 index 000000000..a9613d940 --- /dev/null +++ b/serialize/SerialBufferAdapter2.h @@ -0,0 +1,139 @@ +#ifndef SERIALBUFFERADAPTER2_H_ +#define SERIALBUFFERADAPTER2_H_ + +#include +#include +#include + +#include + +/** + * This adapter provides an interface for SerializeIF to serialize or deserialize + * buffers with no length header but a known size. + * + * Additionally, the buffer length can be serialized too and will be put in front of the serialized buffer. + * + * Can be used with SerialLinkedListAdapter by declaring a SerializeElement with + * SerialElement> serialBufferElement. + * Right now, the SerialBufferAdapter must always be initialized with the buffer and size ! + * + * \ingroup serialize + */ +template +class SerialBufferAdapter2: public SerializeIF { +public: + /** + * Constructor for constant uint8_t buffer. Length field can be serialized optionally. + * Type of length can be supplied as template type. + * @param buffer + * @param bufferLength + * @param serializeLength + */ + SerialBufferAdapter2(BUFFER_TYPE * buffer_, count_t bufferLength_, bool serializeLength_ = false): + buffer(buffer_),bufferLength(bufferLength_), serializeLength(serializeLength_) { + determineLengthMultiplier(sizeof(count_t)); + if(std::is_const::value) { + isConst = true; + } + } + + ReturnValue_t serialize(uint8_t ** buffer, uint32_t* size, + const uint32_t max_size, bool bigEndian) const { + uint32_t serializedLength = bufferLength; + if (serializeLength) { + serializedLength += AutoSerializeAdapter::getSerializedSize( + &bufferLength); + } + if (*size + serializedLength > max_size) { + return BUFFER_TOO_SHORT; + } else { + if (serializeLength) { + AutoSerializeAdapter::serialize(&bufferLength, buffer, size, + max_size, bigEndian); + } + memcpy(*buffer, this->buffer, bufferLength); + *size += bufferLength; + (*buffer) += bufferLength; + return HasReturnvaluesIF::RETURN_OK; + } + } + + uint32_t getSerializedSize() const { + if (serializeLength) { + return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); + } else { + return bufferLength; + } + } + + ReturnValue_t deSerialize(const uint8_t** buffer, + int32_t* size, bool bigEndian) { + //TODO Ignores Endian flag! + //UPDATE: Endian swapper introduced. Must be tested.. + if (buffer != NULL) { + if(serializeLength){ + count_t serializedSize = AutoSerializeAdapter::getSerializedSize( + &bufferLength); + if((*size - bufferLength - serializedSize) >= 0){ + *buffer += serializedSize; + *size -= serializedSize; + }else{ + return STREAM_TOO_SHORT; + } + } + //No Else If, go on with buffer + if (*size - bufferLength >= 0) { + uint8_t tmp [bufferLength]; + uint8_t * pTmp = tmp; + if (bigEndian) { + EndianSwapper::swap(pTmp,*buffer, bufferLength); + } else { + pTmp = const_cast(*buffer); + } + *size -= bufferLength; + memcpy(const_cast(reinterpret_cast(this->buffer)), pTmp, bufferLength); + (*buffer) += bufferLength; + return HasReturnvaluesIF::RETURN_OK; + } else { + return STREAM_TOO_SHORT; + } + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } + } + + + uint8_t * getBuffer() { + return reinterpret_cast(buffer); + } + + void setBuffer(BUFFER_TYPE * buffer_, count_t bufferLength_, bool serializeLength_ = false) { + buffer = buffer_; + bufferLength = bufferLength_; + serializeLength = serializeLength_; + determineLengthMultiplier(sizeof(count_t)); + } +private: + BUFFER_TYPE * buffer; + count_t bufferLength; + bool serializeLength; + + bool isConst = false; + + void determineLengthMultiplier(uint8_t typeSize) { + switch(typeSize) { + case(2): + bufferLength *= 2; break; + case(4): + bufferLength *= 4; break; + case(8): + bufferLength *= 8; break; + default: + warning << "Invalid type size, assuming regular uint8_t." << std::endl; + } + } +}; + + + +#endif /* SERIALBUFFERADAPTER2_H_ */ From 1d1bb88a6f173ba3426a176fb6609e27740928cd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 16 Jan 2020 19:07:53 +0100 Subject: [PATCH 0081/1774] Merge request check --- container/FixedMap.h | 4 +- datapool/DataSet.cpp | 6 -- datapool/DataSet.h | 3 - datapool/PoolRawAccess.cpp | 2 +- devicehandlers/DeviceHandlerBase.h | 2 - devicehandlers/DeviceHandlerIF.h | 133 ++++++++++++------------ objectmanager/ObjectManagerIF.h | 5 +- serialize/SerialBufferAdapter.cpp | 2 +- serialize/SerialFixedArrayListAdapter.h | 17 ++- serialize/SerialLinkedListAdapter.h | 7 +- 10 files changed, 83 insertions(+), 98 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 55a435338..39e9106d1 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -16,8 +16,8 @@ template class FixedMap: public SerializeIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::FIXED_MAP; - static const ReturnValue_t KEY_ALREADY_EXISTS = MAKE_RETURN_CODE(0x01); //!< P1: SID for HK packets - static const ReturnValue_t MAP_FULL = MAKE_RETURN_CODE(0x02); //!< P1: SID for HK packets + 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: diff --git a/datapool/DataSet.cpp b/datapool/DataSet.cpp index 55d8d6700..b4725c735 100644 --- a/datapool/DataSet.cpp +++ b/datapool/DataSet.cpp @@ -148,9 +148,3 @@ ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, int32_t* size, } return result; } - -ReturnValue_t DataSet::serializeRawFromIdBuffer(uint8_t ** buffer, uint32_t * size, - const uint32_t max_size, bool bigEndian, uint32_t * poolIdBuffer, - uint32_t poolIdSize) { - return RETURN_OK; -} diff --git a/datapool/DataSet.h b/datapool/DataSet.h index e8e1a5972..8e0132239 100644 --- a/datapool/DataSet.h +++ b/datapool/DataSet.h @@ -129,9 +129,6 @@ public: ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); - ReturnValue_t serializeRawFromIdBuffer(uint8_t ** buffer, uint32_t * size, - const uint32_t max_size, bool bigEndian, uint32_t * poolIdBuffer, - uint32_t poolIdSize); private: /** * \brief This array represents all pool variables registered in this set. diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 66ba6218b..4eeba4f58 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -38,7 +38,7 @@ ReturnValue_t PoolRawAccess::read() { result = READ_TYPE_TOO_LARGE; } } else { - info << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl; + //debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl; result = READ_INDEX_TOO_LARGE; } } else { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index e7ac3aa63..95e972b65 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -170,8 +170,6 @@ protected: static const DeviceCommandId_t NO_COMMAND_ID = -2; static const MessageQueueId_t NO_COMMANDER = 0; - - /** * Pointer to the raw packet that will be sent. */ diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index bfa7c7b24..ed0260d60 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -25,80 +25,79 @@ public: * MODE_ON and MODE_OFF are included in hasModesIF.h */ + // MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted + // MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on. + static const Mode_t MODE_NORMAL = 2; //!< The device is powered on and the device handler periodically sends commands. The commands to be sent are selected by the handler according to the submode. + static const Mode_t MODE_RAW = 3; //!< The device is powered on and ready to perform operations. In this mode, raw commands can be sent. The device handler will send all replies received from the command back to the commanding object. + static const Mode_t MODE_ERROR_ON = 4; //!4< The device is shut down but the switch could not be turned off, so the device still is powered. In this mode, only a mode change to @c MODE_OFF can be commanded, which tries to switch off the device again. + static const Mode_t _MODE_START_UP = TRANSITION_MODE_CHILD_ACTION_MASK | 5; //!< This is a transitional state which can not be commanded. The device handler performs all commands to get the device in a state ready to perform commands. When this is completed, the mode changes to @c MODE_ON. + static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6; //!< This is a transitional state which can not be commanded. The device handler performs all actions and commands to get the device shut down. When the device is off, the mode changes to @c MODE_OFF. + static const Mode_t _MODE_TO_ON = TRANSITION_MODE_CHILD_ACTION_MASK | HasModesIF::MODE_ON; //!< It is possible to set the mode to _MODE_TO_ON to use the to on transition if available. + static const Mode_t _MODE_TO_RAW = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_RAW; + static const Mode_t _MODE_TO_NORMAL = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_NORMAL; + static const Mode_t _MODE_POWER_DOWN = TRANSITION_MODE_BASE_ACTION_MASK | 1; //!< This is a transitional state which can not be commanded. The device is shut down and ready to be switched off. After the command to set the switch off has been sent, the mode changes to @c MODE_WAIT_OFF + static const Mode_t _MODE_POWER_ON = TRANSITION_MODE_BASE_ACTION_MASK | 2; //!< This is a transitional state which can not be commanded. The device will be switched on in this state. After the command to set the switch on has been sent, the mode changes to @c MODE_WAIT_ON + static const Mode_t _MODE_WAIT_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 3; //!< This is a transitional state which can not be commanded. The switch has been commanded off and the handler waits for it to be off. When the switch is off, the mode changes to @c MODE_OFF. + static const Mode_t _MODE_WAIT_ON = TRANSITION_MODE_BASE_ACTION_MASK | 4; //!< This is a transitional state which can not be commanded. The switch has been commanded on and the handler waits for it to be on. When the switch is on, the mode changes to @c MODE_TO_ON. + static const Mode_t _MODE_SWITCH_IS_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 5; //!< This is a transitional state which can not be commanded. The switch has been commanded off and is off now. This state is only to do an RMAP cycle once more where the doSendRead() function will set the mode to MODE_OFF. The reason to do this is to get rid of stuck packets in the IO Board -// MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted -// MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on. - static const Mode_t MODE_NORMAL = 2; //!< The device is powered on and the device handler periodically sends commands. The commands to be sent are selected by the handler according to the submode. - static const Mode_t MODE_RAW = 3; //!< The device is powered on and ready to perform operations. In this mode, raw commands can be sent. The device handler will send all replies received from the command back to the commanding object. - static const Mode_t MODE_ERROR_ON = 4; //!4< The device is shut down but the switch could not be turned off, so the device still is powered. In this mode, only a mode change to @c MODE_OFF can be commanded, which tries to switch off the device again. - static const Mode_t _MODE_START_UP = TRANSITION_MODE_CHILD_ACTION_MASK | 5; //!< This is a transitional state which can not be commanded. The device handler performs all commands to get the device in a state ready to perform commands. When this is completed, the mode changes to @c MODE_ON. - static const Mode_t _MODE_SHUT_DOWN = TRANSITION_MODE_CHILD_ACTION_MASK | 6; //!< This is a transitional state which can not be commanded. The device handler performs all actions and commands to get the device shut down. When the device is off, the mode changes to @c MODE_OFF. - static const Mode_t _MODE_TO_ON = TRANSITION_MODE_CHILD_ACTION_MASK | HasModesIF::MODE_ON; //!< It is possible to set the mode to _MODE_TO_ON to use the to on transition if available. - static const Mode_t _MODE_TO_RAW = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_RAW; - static const Mode_t _MODE_TO_NORMAL = TRANSITION_MODE_CHILD_ACTION_MASK | MODE_NORMAL; - static const Mode_t _MODE_POWER_DOWN = TRANSITION_MODE_BASE_ACTION_MASK | 1; //!< This is a transitional state which can not be commanded. The device is shut down and ready to be switched off. After the command to set the switch off has been sent, the mode changes to @c MODE_WAIT_OFF - static const Mode_t _MODE_POWER_ON = TRANSITION_MODE_BASE_ACTION_MASK | 2; //!< This is a transitional state which can not be commanded. The device will be switched on in this state. After the command to set the switch on has been sent, the mode changes to @c MODE_WAIT_ON - static const Mode_t _MODE_WAIT_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 3; //!< This is a transitional state which can not be commanded. The switch has been commanded off and the handler waits for it to be off. When the switch is off, the mode changes to @c MODE_OFF. - static const Mode_t _MODE_WAIT_ON = TRANSITION_MODE_BASE_ACTION_MASK | 4; //!< This is a transitional state which can not be commanded. The switch has been commanded on and the handler waits for it to be on. When the switch is on, the mode changes to @c MODE_TO_ON. - static const Mode_t _MODE_SWITCH_IS_OFF = TRANSITION_MODE_BASE_ACTION_MASK | 5; //!< This is a transitional state which can not be commanded. The switch has been commanded off and is off now. This state is only to do an RMAP cycle once more where the doSendRead() function will set the mode to MODE_OFF. The reason to do this is to get rid of stuck packets in the IO Board + static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CDH; + static const Event DEVICE_BUILDING_COMMAND_FAILED = MAKE_EVENT(0, SEVERITY::LOW); + static const Event DEVICE_SENDING_COMMAND_FAILED = MAKE_EVENT(1, SEVERITY::LOW); + static const Event DEVICE_REQUESTING_REPLY_FAILED = MAKE_EVENT(2, SEVERITY::LOW); + static const Event DEVICE_READING_REPLY_FAILED = MAKE_EVENT(3, SEVERITY::LOW); + static const Event DEVICE_INTERPRETING_REPLY_FAILED = MAKE_EVENT(4, SEVERITY::LOW); + static const Event DEVICE_MISSED_REPLY = MAKE_EVENT(5, SEVERITY::LOW); + static const Event DEVICE_UNKNOWN_REPLY = MAKE_EVENT(6, SEVERITY::LOW); + static const Event DEVICE_UNREQUESTED_REPLY = MAKE_EVENT(7, SEVERITY::LOW); + static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, SEVERITY::LOW); //!< Indicates a SW bug in child class. + static const Event MONITORING_LIMIT_EXCEEDED = MAKE_EVENT(9, SEVERITY::LOW); + static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, SEVERITY::HIGH); - static const uint8_t SUBSYSTEM_ID = SUBSYSTEM_ID::CDH; - static const Event DEVICE_BUILDING_COMMAND_FAILED = MAKE_EVENT(0, SEVERITY::LOW); - static const Event DEVICE_SENDING_COMMAND_FAILED = MAKE_EVENT(1, SEVERITY::LOW); - static const Event DEVICE_REQUESTING_REPLY_FAILED = MAKE_EVENT(2, SEVERITY::LOW); - static const Event DEVICE_READING_REPLY_FAILED = MAKE_EVENT(3, SEVERITY::LOW); - static const Event DEVICE_INTERPRETING_REPLY_FAILED = MAKE_EVENT(4, SEVERITY::LOW); - static const Event DEVICE_MISSED_REPLY = MAKE_EVENT(5, SEVERITY::LOW); - static const Event DEVICE_UNKNOWN_REPLY = MAKE_EVENT(6, SEVERITY::LOW); - static const Event DEVICE_UNREQUESTED_REPLY = MAKE_EVENT(7, SEVERITY::LOW); - static const Event INVALID_DEVICE_COMMAND = MAKE_EVENT(8, SEVERITY::LOW); //!< Indicates a SW bug in child class. - static const Event MONITORING_LIMIT_EXCEEDED = MAKE_EVENT(9, SEVERITY::LOW); - static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, SEVERITY::HIGH); + static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF; + static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); + static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); + static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); + static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3); + static const ReturnValue_t CANT_SWITCH_IOBOARD = MAKE_RETURN_CODE(0xA4); + static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5); + static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6); + static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7); + static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command. + static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9); + static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA); - static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF; - static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); - static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); - static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); - static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3); - static const ReturnValue_t CANT_SWITCH_IOBOARD = MAKE_RETURN_CODE(0xA4); - static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5); - static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6); - static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7); - static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command. - static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9); - static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA); - - //standard codes used in scan for reply + //standard codes used in scan for reply // static const ReturnValue_t TOO_SHORT = MAKE_RETURN_CODE(0xB1); - static const ReturnValue_t CHECKSUM_ERROR = MAKE_RETURN_CODE(0xB2); - static const ReturnValue_t LENGTH_MISSMATCH = MAKE_RETURN_CODE(0xB3); - static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(0xB4); - static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0xB5); + static const ReturnValue_t CHECKSUM_ERROR = MAKE_RETURN_CODE(0xB2); + static const ReturnValue_t LENGTH_MISSMATCH = MAKE_RETURN_CODE(0xB3); + static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(0xB4); + static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0xB5); - //standard codes used in interpret device reply - static const ReturnValue_t DEVICE_DID_NOT_EXECUTE = MAKE_RETURN_CODE(0xC1); //the device reported, that it did not execute the command - static const ReturnValue_t DEVICE_REPORTED_ERROR = MAKE_RETURN_CODE(0xC2); - static const ReturnValue_t UNKNOW_DEVICE_REPLY = MAKE_RETURN_CODE(0xC3); //the deviceCommandId reported by scanforReply is unknown - static const ReturnValue_t DEVICE_REPLY_INVALID = MAKE_RETURN_CODE(0xC4); //syntax etc is correct but still not ok, eg parameters where none are expected + //standard codes used in interpret device reply + static const ReturnValue_t DEVICE_DID_NOT_EXECUTE = MAKE_RETURN_CODE(0xC1); //the device reported, that it did not execute the command + static const ReturnValue_t DEVICE_REPORTED_ERROR = MAKE_RETURN_CODE(0xC2); + static const ReturnValue_t UNKNOW_DEVICE_REPLY = MAKE_RETURN_CODE(0xC3); //the deviceCommandId reported by scanforReply is unknown + static const ReturnValue_t DEVICE_REPLY_INVALID = MAKE_RETURN_CODE(0xC4); //syntax etc is correct but still not ok, eg parameters where none are expected - //Standard codes used in buildCommandFromCommand - static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE( - 0xD0); - static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = - MAKE_RETURN_CODE(0xD1); + //Standard codes used in buildCommandFromCommand + static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE( + 0xD0); + static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = + MAKE_RETURN_CODE(0xD1); - /** - * RMAP Action that will be executed. - * - * This is used by the child class to tell the base class what to do. - */ - enum RmapAction_t { - SEND_WRITE,//!< RMAP send write - GET_WRITE, //!< RMAP get write - SEND_READ, //!< RMAP send read - GET_READ, //!< RMAP get read - NOTHING //!< Do nothing. - }; + /** + * RMAP Action that will be executed. + * + * This is used by the child class to tell the base class what to do. + */ + enum RmapAction_t { + SEND_WRITE,//!< RMAP send write + GET_WRITE, //!< RMAP get write + SEND_READ, //!< RMAP send read + GET_READ, //!< RMAP get read + NOTHING //!< Do nothing. + }; /** * Default Destructor */ diff --git a/objectmanager/ObjectManagerIF.h b/objectmanager/ObjectManagerIF.h index 5fbce2824..1d7674c64 100644 --- a/objectmanager/ObjectManagerIF.h +++ b/objectmanager/ObjectManagerIF.h @@ -78,9 +78,8 @@ public: virtual void printList() = 0; }; -/** - * @brief Documentation can be found in the class method declration. - */ + +/*Documentation can be found in the class method declaration above.*/ template T* ObjectManagerIF::get( object_id_t id ) { SystemObjectIF* temp = this->getSystemObject(id); diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index a045d37ab..895e9461d 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -1,6 +1,6 @@ #include -#include #include +#include template SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 4c4ec56fd..e6db56e1b 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -9,17 +9,16 @@ * buffers with a header containing the buffer length. * @details * - * Can be used by SerialLinkedListAdapter by using this type in - * SerializeElement<>. - * - * Buffers with a size header inside that class can be declared with - * SerialFixedArrayListAdapter. - * LENGTH_FIELD_TYPE specifies the data type of the buffer header containing the buffer size - * (defaults to 1 byte length field) that follows and MAX_BUFFER_LENGTH specifies - * the maximum allowed value for the buffer size. - * + * Can be used by SerialLinkedListAdapter by declaring + * as a linked element with SerializeElement>. * The sequence of objects is defined in the constructor by using the setStart and setNext functions. * + * 1. Buffers with a size header inside that class can be declared with + * SerialFixedArrayListAdapter. + * 2. MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. + * 3. LENGTH_FIELD_TYPE specifies the data type of the buffer header containing the buffer size + * (defaults to 1 byte length field) that follows + * * @ingroup serialize */ template diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index c135a2d38..ef1fa2007 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -19,7 +19,7 @@ * @details * An alternative to the AutoSerializeAdapter functions * - All object members with a datatype are declared as SerializeElement - * inside the class implementing this adapter. + * members inside the class implementing this adapter. * - The element type can also be a SerialBufferAdapter to de-/serialize buffers, * with a known size, where the size can also be serialized * - The element type can also be a SerialFixedArrayListAdapter to de-/serialize buffers @@ -29,14 +29,13 @@ * the setStart and setNext functions. * * - The serialization process is done by instantiating the class and - * calling the serialize after all SerializeElement entries have been set by - * using a constructor or setter functions. An additional size variable can be supplied + * calling serializ after all SerializeElement entries have been set by + * using the constructor or setter functions. An additional size variable can be supplied * which is calculated/incremented automatically * - The deserialization process is done by instantiating the class and supplying * a buffer with the data which is converted into an object. The size of * data to serialize can be supplied and is decremented in the function * - * * @ingroup serialize */ template From 1f4391f56e5f95a44529bf89661c69c821fbb5c4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 17 Jan 2020 21:11:39 +0100 Subject: [PATCH 0082/1774] Endian Swapper buffer swapper changes reverted --- serialize/EndianSwapper.h | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/serialize/EndianSwapper.h b/serialize/EndianSwapper.h index 6c391316a..25fb681e9 100644 --- a/serialize/EndianSwapper.h +++ b/serialize/EndianSwapper.h @@ -47,17 +47,25 @@ public: #endif } + /** + * Swap endianness of buffer entries + * Template argument specifies buffer type + * @param out + * @param in + * @param size + */ template - static void swap(uint8_t * out, const uint8_t * in, uint32_t size) { + static void swap(T * out, const T * in, uint32_t size) { #ifndef BYTE_ORDER_SYSTEM #error BYTE_ORDER_SYSTEM not defined #elif BYTE_ORDER_SYSTEM == LITTLE_ENDIAN + const uint8_t * in_buffer = reinterpret_cast(in); + uint8_t * out_buffer = reinterpret_cast(out); for (uint8_t count = 0; count < size; count++) { for(uint8_t i = 0; i < sizeof(T);i++) { - out[sizeof(T)* (count + 1) - i - 1] = in[count * sizeof(T) + i]; + out_buffer[sizeof(T)* (count + 1) - i - 1] = in_buffer[count * sizeof(T) + i]; } } - return; #elif BYTE_ORDER_SYSTEM == BIG_ENDIAN memcpy(out, in, size*sizeof(T)); From c9e4c73bd251b15c05c7d3140413ca39a2617919 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 18 Jan 2020 15:03:22 +0100 Subject: [PATCH 0083/1774] Local pool public members/functions moved to top --- container/FixedArrayList.h | 9 +- serialize/SerialBufferAdapter.cpp | 8 +- serialize/SerialBufferAdapter.h | 2 +- serialize/SerialBufferAdapter2.h | 57 +++++----- storagemanager/LocalPool.h | 179 +++++++++++++++--------------- 5 files changed, 135 insertions(+), 120 deletions(-) diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index ef2a82f5c..b9394cfec 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -17,10 +17,11 @@ public: //We could create a constructor to initialize the fixed array list with data and the known size field //so it can be used for serialization too (with SerialFixedArrrayListAdapter) //is this feasible? -// FixedArrayList(T * data_, count_t count): -// ArrayList(data, MAX_SIZE) { -// memcpy(data, data_, count); -// } + FixedArrayList(T * data_, count_t count): + ArrayList(data, MAX_SIZE) { + memcpy(this->data, data_, count); + this->size = count; + } FixedArrayList(const FixedArrayList& other) : ArrayList(data, MAX_SIZE) { diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 895e9461d..ab9dae073 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -71,6 +71,11 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, //TODO Ignores Endian flag! if (buffer != NULL) { if(serializeLength){ + // Suggestion (would require removing rest of the block inside this if clause !): + //ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian); + //if (result != HasReturnvaluesIF::RETURN_OK) { + // return result; + //} T serializedSize = AutoSerializeAdapter::getSerializedSize( &bufferLength); if((*size - bufferLength - serializedSize) >= 0){ @@ -113,8 +118,9 @@ const uint8_t * SerialBufferAdapter::getConstBuffer() { } template -void SerialBufferAdapter::setBuffer(uint8_t * buffer_) { +void SerialBufferAdapter::setBuffer(uint8_t * buffer_, T bufferLength_) { buffer = buffer_; + bufferLength = bufferLength_; } diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index b7729e316..53c5dc72f 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -58,7 +58,7 @@ public: uint8_t * getBuffer(); const uint8_t * getConstBuffer(); - void setBuffer(uint8_t * buffer_); + void setBuffer(uint8_t * buffer_, T bufferLength_); private: enum bufferType { diff --git a/serialize/SerialBufferAdapter2.h b/serialize/SerialBufferAdapter2.h index a9613d940..59c79dc2e 100644 --- a/serialize/SerialBufferAdapter2.h +++ b/serialize/SerialBufferAdapter2.h @@ -29,12 +29,18 @@ public: * @param bufferLength * @param serializeLength */ - SerialBufferAdapter2(BUFFER_TYPE * buffer_, count_t bufferLength_, bool serializeLength_ = false): - buffer(buffer_),bufferLength(bufferLength_), serializeLength(serializeLength_) { - determineLengthMultiplier(sizeof(count_t)); - if(std::is_const::value) { - isConst = true; - } + SerialBufferAdapter2(void * buffer_, count_t bufferLength_, bool serializeLength_ = false): + bufferLength(bufferLength_), serializeLength(serializeLength_) { + determineLengthInBytes(sizeof(BUFFER_TYPE)); + buffer = reinterpret_cast(buffer_); + constBuffer = NULL; + } + + SerialBufferAdapter2(const void * buffer_, count_t bufferLength_, bool serializeLength_ = false): + bufferLength(bufferLength_), serializeLength(serializeLength_) { + determineLengthInBytes(sizeof(BUFFER_TYPE)); + constBuffer = reinterpret_cast(buffer_); + buffer = NULL; } ReturnValue_t serialize(uint8_t ** buffer, uint32_t* size, @@ -69,9 +75,13 @@ public: ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) { //TODO Ignores Endian flag! - //UPDATE: Endian swapper introduced. Must be tested.. if (buffer != NULL) { if(serializeLength){ + // Suggestion (would require removing rest of the block inside this if clause !): + //ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian); + //if (result != HasReturnvaluesIF::RETURN_OK) { + // return result; + //} count_t serializedSize = AutoSerializeAdapter::getSerializedSize( &bufferLength); if((*size - bufferLength - serializedSize) >= 0){ @@ -83,15 +93,8 @@ public: } //No Else If, go on with buffer if (*size - bufferLength >= 0) { - uint8_t tmp [bufferLength]; - uint8_t * pTmp = tmp; - if (bigEndian) { - EndianSwapper::swap(pTmp,*buffer, bufferLength); - } else { - pTmp = const_cast(*buffer); - } *size -= bufferLength; - memcpy(const_cast(reinterpret_cast(this->buffer)), pTmp, bufferLength); + memcpy(this->buffer, *buffer, bufferLength); (*buffer) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } else { @@ -103,24 +106,30 @@ public: } - uint8_t * getBuffer() { - return reinterpret_cast(buffer); + BUFFER_TYPE * getBuffer() { + return reinterpret_cast(buffer); } - void setBuffer(BUFFER_TYPE * buffer_, count_t bufferLength_, bool serializeLength_ = false) { + void setBuffer(void * buffer_, count_t bufferLength_, bool serializeLength_ = false) { buffer = buffer_; bufferLength = bufferLength_; serializeLength = serializeLength_; - determineLengthMultiplier(sizeof(count_t)); + determineLengthInBytes(sizeof(BUFFER_TYPE)); + } + + void setConstBuffer(const void * buffer_, count_t bufferLength_, bool serializeLength_ = false) { + constBuffer = buffer_; + bufferLength = bufferLength_; + serializeLength = serializeLength_; + determineLengthInBytes(sizeof(BUFFER_TYPE)); } private: - BUFFER_TYPE * buffer; + uint8_t * buffer; + const uint8_t * constBuffer; count_t bufferLength; bool serializeLength; - bool isConst = false; - - void determineLengthMultiplier(uint8_t typeSize) { + void determineLengthInBytes(uint8_t typeSize) { switch(typeSize) { case(2): bufferLength *= 2; break; @@ -134,6 +143,4 @@ private: } }; - - #endif /* SERIALBUFFERADAPTER2_H_ */ diff --git a/storagemanager/LocalPool.h b/storagemanager/LocalPool.h index f8b2b7302..f6d5ba8ac 100644 --- a/storagemanager/LocalPool.h +++ b/storagemanager/LocalPool.h @@ -39,7 +39,95 @@ public: * @brief This definition generally sets the number of different sized pools. * @details This must be less than the maximum number of pools (currently 0xff). */ -// static const uint32_t NUMBER_OF_POOLS; + // static const uint32_t NUMBER_OF_POOLS; + /** + * @brief This is the default constructor for a pool manager instance. + * @details By passing two arrays of size NUMBER_OF_POOLS, the constructor + * allocates memory (with \c new) for store and size_list. These + * regions are all set to zero on start up. + * @param setObjectId The object identifier to be set. This allows for + * multiple instances of LocalPool in the system. + * @param element_sizes An array of size NUMBER_OF_POOLS in which the size + * of a single element in each pool is determined. + * The sizes must be provided in ascending order. + * + * @param n_elements An array of size NUMBER_OF_POOLS in which the + * number of elements for each pool is determined. + * The position of these values correspond to those in + * element_sizes. + * @param registered Register the pool in object manager or not. Default is false (local pool). + * @param spillsToHigherPools + * A variable to determine whether higher n pools are used if the store is full. + */ + LocalPool(object_id_t setObjectId, + const uint16_t element_sizes[NUMBER_OF_POOLS], + const uint16_t n_elements[NUMBER_OF_POOLS], + bool registered = false, + bool spillsToHigherPools = false); + /** + * @brief In the LocalPool's destructor all allocated memory is freed. + */ + virtual ~LocalPool(void); + + /** + * Add data to local data pool, performs range check + * @param storageId [out] Store ID in which the data will be stored + * @param data + * @param size + * @param ignoreFault + * @return @c RETURN_OK if write was successful + */ + ReturnValue_t addData(store_address_t* storageId, const uint8_t * data, + uint32_t size, bool ignoreFault = false); + + /** + * With this helper method, a free element of \c size is reserved. + * @param storageId [out] storeID of the free element + * @param size The minimum packet size that shall be reserved. + * @param p_data [out] pointer to the pointer of free element + * @param ignoreFault + * @return Returns the storage identifier within the storage or + * StorageManagerIF::INVALID_ADDRESS (in raw). + */ + ReturnValue_t getFreeElement(store_address_t* storageId, + const uint32_t size, uint8_t** p_data, bool ignoreFault = false); + + /** + * Retrieve data from local pool + * @param packet_id + * @param packet_ptr + * @param size [out] Size of retrieved data + * @return @c RETURN_OK if data retrieval was successfull + */ + ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr, + uint32_t* size); + + /** + * Modify data by supplying a packet pointer and using that packet pointer + * to access and modify the pool entry (via *pointer call) + * @param packet_id Store ID of data to modify + * @param packet_ptr [out] pointer to the pool entry to modify + * @param size [out] size of pool entry + * @return + */ + ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr, + uint32_t* size); + virtual ReturnValue_t deleteData(store_address_t); + virtual ReturnValue_t deleteData(uint8_t* ptr, uint32_t size, + store_address_t* storeId = NULL); + void clearStore(); + ReturnValue_t initialize(); +protected: + /** + * With this helper method, a free element of \c size is reserved. + * @param size The minimum packet size that shall be reserved. + * @param[out] address Storage ID of the reserved data. + * @return - #RETURN_OK on success, + * - the return codes of #getPoolIndex or #findEmpty otherwise. + */ + virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault); + + InternalErrorReporterIF *internalErrorReporter; private: /** * Indicates that this element is free. @@ -121,93 +209,6 @@ private: * - #DATA_STORAGE_FULL if the store is full */ ReturnValue_t findEmpty(uint16_t pool_index, uint16_t* element); -protected: - /** - * With this helper method, a free element of \c size is reserved. - * @param size The minimum packet size that shall be reserved. - * @param[out] address Storage ID of the reserved data. - * @return - #RETURN_OK on success, - * - the return codes of #getPoolIndex or #findEmpty otherwise. - */ - virtual ReturnValue_t reserveSpace(const uint32_t size, store_address_t* address, bool ignoreFault); - - InternalErrorReporterIF *internalErrorReporter; -public: - /** - * @brief This is the default constructor for a pool manager instance. - * @details By passing two arrays of size NUMBER_OF_POOLS, the constructor - * allocates memory (with \c new) for store and size_list. These - * regions are all set to zero on start up. - * @param setObjectId The object identifier to be set. This allows for - * multiple instances of LocalPool in the system. - * @param element_sizes An array of size NUMBER_OF_POOLS in which the size - * of a single element in each pool is determined. - * The sizes must be provided in ascending order. - * - * @param n_elements An array of size NUMBER_OF_POOLS in which the - * number of elements for each pool is determined. - * The position of these values correspond to those in - * element_sizes. - * @param registered Register the pool in object manager or not. Default is false (local pool). - * @param spillsToHigherPools - * A variable to determine whether higher n pools are used if the store is full. - */ - LocalPool(object_id_t setObjectId, - const uint16_t element_sizes[NUMBER_OF_POOLS], - const uint16_t n_elements[NUMBER_OF_POOLS], - bool registered = false, - bool spillsToHigherPools = false); - /** - * @brief In the LocalPool's destructor all allocated memory is freed. - */ - virtual ~LocalPool(void); - - /** - * Add data to local data pool, performs range check - * @param storageId [out] Store ID in which the data will be stored - * @param data - * @param size - * @param ignoreFault - * @return @c RETURN_OK if write was successful - */ - ReturnValue_t addData(store_address_t* storageId, const uint8_t * data, - uint32_t size, bool ignoreFault = false); - - /** - * With this helper method, a free element of \c size is reserved. - * - * @param size The minimum packet size that shall be reserved. - * @return Returns the storage identifier within the storage or - * StorageManagerIF::INVALID_ADDRESS (in raw). - */ - ReturnValue_t getFreeElement(store_address_t* storageId, - const uint32_t size, uint8_t** p_data, bool ignoreFault = false); - - /** - * Retrieve data from local pool - * @param packet_id - * @param packet_ptr - * @param size [out] Size of retrieved data - * @return @c RETURN_OK if data retrieval was successfull - */ - ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr, - uint32_t* size); - - /** - * Modify data by supplying a packet pointer and using that packet pointer - * to access and modify the pool entry (via *pointer call) - * @param packet_id Store ID of data to modify - * @param packet_ptr [out] pointer to the pool entry to modify - * @param size [out] size of pool entry - * @return - */ - ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr, - uint32_t* size); - virtual ReturnValue_t deleteData(store_address_t); - virtual ReturnValue_t deleteData(uint8_t* ptr, uint32_t size, - store_address_t* storeId = NULL); - void clearStore(); - ReturnValue_t initialize(); }; template @@ -304,7 +305,7 @@ template inline LocalPool::LocalPool(object_id_t setObjectId, const uint16_t element_sizes[NUMBER_OF_POOLS], const uint16_t n_elements[NUMBER_OF_POOLS], bool registered, bool spillsToHigherPools) : - SystemObject(setObjectId, registered), spillsToHigherPools(spillsToHigherPools), internalErrorReporter(NULL) { + SystemObject(setObjectId, registered), internalErrorReporter(NULL), spillsToHigherPools(spillsToHigherPools){ for (uint16_t n = 0; n < NUMBER_OF_POOLS; n++) { this->element_sizes[n] = element_sizes[n]; this->n_elements[n] = n_elements[n]; From 6fe0f45c278e51b4a54a7f3a105edcafaad9f89a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 18 Jan 2020 16:48:33 +0100 Subject: [PATCH 0084/1774] SerialBufferAdapter new setBuffer function Serial Fixed Array List Adapter documentation adapted SinglyLinkedList setEnd() function added --- container/SinglyLinkedList.h | 5 +++++ serialize/SerialBufferAdapter.cpp | 5 +++++ serialize/SerialBufferAdapter.h | 1 + serialize/SerialFixedArrayListAdapter.h | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/container/SinglyLinkedList.h b/container/SinglyLinkedList.h index 0a2e0531d..5c9de6cfe 100644 --- a/container/SinglyLinkedList.h +++ b/container/SinglyLinkedList.h @@ -58,6 +58,11 @@ public: virtual void setNext(LinkedElement* next) { this->next = next; } + + void setEnd() { + this->next = NULL; + } + LinkedElement* begin() { return this; } diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index ab9dae073..6ac2894fe 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -123,6 +123,11 @@ void SerialBufferAdapter::setBuffer(uint8_t * buffer_, T bufferLength_) { bufferLength = bufferLength_; } +template +void SerialBufferAdapter::setBuffer(uint32_t * buffer_, T bufferLength_) { + buffer = reinterpret_cast(buffer_); + bufferLength = 4 * bufferLength_; +} //forward Template declaration for linker template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 53c5dc72f..600bd692a 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -59,6 +59,7 @@ public: uint8_t * getBuffer(); const uint8_t * getConstBuffer(); void setBuffer(uint8_t * buffer_, T bufferLength_); + void setBuffer(uint32_t * buffer_, T bufferLength_); private: enum bufferType { diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index e6db56e1b..18a970b80 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -15,7 +15,7 @@ * * 1. Buffers with a size header inside that class can be declared with * SerialFixedArrayListAdapter. - * 2. MAX_BUFFER_LENGTH specifies the maximum allowed value for the buffer size. + * 2. MAX_BUFFER_LENGTH specifies the maximum allowed number of elements in FixedArrayList * 3. LENGTH_FIELD_TYPE specifies the data type of the buffer header containing the buffer size * (defaults to 1 byte length field) that follows * From 5cb591a063cb9df22954a26e490806b5648d4061 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 18 Jan 2020 18:01:37 +0100 Subject: [PATCH 0085/1774] Array List swapper for SerialFixedArrayList --- serialize/SerialArrayListAdapter.h | 16 ++++++++++++++++ serialize/SerialFixedArrayListAdapter.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 72b8d97f6..21cbbc4d6 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -78,6 +78,22 @@ public: } return result; } + + /** + * Swap the endianness of the Array list (not the length field !) + * Useful if the case the buffer type is large than uint8_t and the endianness + * is inconsistent with other SerializeElements. + * @param list + */ + static void swapArrayListEndianness(ArrayList* list) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + count_t i = 0; + while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) { + T newEntry = EndianSwapper::swap(list->entries[i]); + list->entries[i] = newEntry; + ++i; + } + } private: ArrayList *adaptee; }; diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 18a970b80..9613f6c13 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -40,6 +40,10 @@ public: bool bigEndian) { return SerialArrayListAdapter::deSerialize(this, buffer, size, bigEndian); } + + void swapArrayListEndianness() { + SerialArrayListAdapter::swapArrayListEndianness(this); + } }; From 424c82ce165e1da122729ce058be19a32ade7dfa Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 18 Jan 2020 23:07:43 +0100 Subject: [PATCH 0086/1774] Extracted one logic block To increase readability --- datapool/PoolRawAccess.cpp | 47 ++++++++++++++++++++------------------ datapool/PoolRawAccess.h | 1 + 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 4eeba4f58..899eedd69 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -14,33 +14,13 @@ PoolRawAccess::PoolRawAccess(uint32_t set_id, uint8_t setArrayEntry, } } -PoolRawAccess::~PoolRawAccess() { - -} +PoolRawAccess::~PoolRawAccess() {} ReturnValue_t PoolRawAccess::read() { ReturnValue_t result = RETURN_FAILED; PoolEntryIF* read_out = ::dataPool.getRawData(dataPoolId); if (read_out != NULL) { - valid = read_out->getValid(); - if (read_out->getSize() > arrayEntry) { - arraySize = read_out->getSize(); - typeSize = read_out->getByteSize() / read_out->getSize(); - type = read_out->getType(); - if (typeSize <= sizeof(value)) { - uint16_t arrayPosition = arrayEntry * typeSize; - sizeTillEnd = read_out->getByteSize() - arrayPosition; - uint8_t* ptr = - &((uint8_t*) read_out->getRawData())[arrayPosition]; - memcpy(value, ptr, typeSize); - return HasReturnvaluesIF::RETURN_OK; - } else { - result = READ_TYPE_TOO_LARGE; - } - } else { - //debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl; - result = READ_INDEX_TOO_LARGE; - } + result = handleReadOut(read_out); } else { result = READ_ENTRY_NON_EXISTENT; } @@ -62,6 +42,29 @@ ReturnValue_t PoolRawAccess::read() { return result; } +ReturnValue_t PoolRawAccess::handleReadOut(PoolEntryIF* read_out) { + ReturnValue_t result = RETURN_FAILED; + valid = read_out->getValid(); + if (read_out->getSize() > arrayEntry) { + arraySize = read_out->getSize(); + typeSize = read_out->getByteSize() / read_out->getSize(); + type = read_out->getType(); + if (typeSize <= sizeof(value)) { + uint16_t arrayPosition = arrayEntry * typeSize; + sizeTillEnd = read_out->getByteSize() - arrayPosition; + uint8_t* ptr = &((uint8_t*) read_out->getRawData())[arrayPosition]; + memcpy(value, ptr, typeSize); + return RETURN_OK; + } else { + result = READ_TYPE_TOO_LARGE; + } + } else { + //debug << "PoolRawAccess: Size: " << (int)read_out->getSize() << std::endl; + result = READ_INDEX_TOO_LARGE; + } + return result; +} + ReturnValue_t PoolRawAccess::commit() { PoolEntryIF* write_back = ::dataPool.getRawData(dataPoolId); if ((write_back != NULL) && (readWriteMode != VAR_READ)) { diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 432d9ad95..5fb482f09 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -156,6 +156,7 @@ protected: */ ReturnValue_t commit(); + ReturnValue_t handleReadOut(PoolEntryIF* read_out); private: /** * \brief To access the correct data pool entry on read and commit calls, the data pool id From dba26baee6b4df5c0379f6886c7eaf12a387683d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 20 Jan 2020 23:00:23 +0100 Subject: [PATCH 0087/1774] Restructured header file Abstract functions are closer to the top because they must be implemented and documentation should be near the top. Important virtual functions moved up too. Additional documentation added --- devicehandlers/DeviceHandlerBase.cpp | 167 +++++------ devicehandlers/DeviceHandlerBase.h | 425 ++++++++++++++------------- 2 files changed, 306 insertions(+), 286 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 0b35effd5..c4f7465d9 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -90,6 +90,85 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { return RETURN_OK; } +ReturnValue_t DeviceHandlerBase::initialize() { + ReturnValue_t result = SystemObject::initialize(); + if (result != RETURN_OK) { + return result; + } + + communicationInterface = objectManager->get( + deviceCommunicationId); + if (communicationInterface == NULL) { + return RETURN_FAILED; + } + + result = communicationInterface->open(&cookie, logicalAddress, + maxDeviceReplyLen); + if (result != RETURN_OK) { + return result; + } + + IPCStore = objectManager->get(objects::IPC_STORE); + if (IPCStore == NULL) { + return RETURN_FAILED; + } + + AcceptsDeviceResponsesIF *rawReceiver = objectManager->get< + AcceptsDeviceResponsesIF>(rawDataReceiverId); + + if (rawReceiver == NULL) { + return RETURN_FAILED; + } + + defaultRawReceiver = rawReceiver->getDeviceQueue(); + + powerSwitcher = objectManager->get(powerSwitcherId); + if (powerSwitcher == NULL) { + return RETURN_FAILED; + } + + result = healthHelper.initialize(); + if (result != RETURN_OK) { + return result; + } + + result = modeHelper.initialize(); + if (result != RETURN_OK) { + return result; + } + result = actionHelper.initialize(commandQueue); + if (result != RETURN_OK) { + return result; + } + result = fdirInstance->initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + result = parameterHelper.initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + result = hkSwitcher.initialize(); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + + fillCommandAndReplyMap(); + + //Set temperature target state to NON_OP. + DataSet mySet; + PoolVariable thermalRequest(deviceThermalRequestPoolId, &mySet, + PoolVariableIF::VAR_WRITE); + mySet.read(); + thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL; + mySet.commit(PoolVariableIF::VALID); + + return RETURN_OK; + +} + void DeviceHandlerBase::decrementDeviceReplyMap() { for (std::map::iterator iter = deviceReplyMap.begin(); iter != deviceReplyMap.end(); iter++) { @@ -454,7 +533,8 @@ void DeviceHandlerBase::doGetWrite() { if (wiretappingMode == RAW) { replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true); } - // We need to distinguish here, because a raw command never expects a reply. (Could be done in eRIRM, but then child implementations need to be careful. + //We need to distinguish here, because a raw command never expects a reply. + //(Could be done in eRIRM, but then child implementations need to be careful. result = enableReplyInReplyMap(cookieInfo.pendingCommand); } else { //always generate a failure event, so that FDIR knows what's up @@ -474,9 +554,9 @@ void DeviceHandlerBase::doSendRead() { cookieInfo.state = COOKIE_READ_SENT; } else { triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result); - // We can't inform anyone, because we don't know which command was sent last. - // So, we need to wait for a timeout. - // but I think we can allow to ignore one missedReply. + //We can't inform anyone, because we don't know which command was sent last. + //So, we need to wait for a timeout. + //but I think we can allow to ignore one missedReply. ignoreMissedRepliesCount++; cookieInfo.state = COOKIE_UNUSED; } @@ -579,84 +659,6 @@ ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress, } -ReturnValue_t DeviceHandlerBase::initialize() { - ReturnValue_t result = SystemObject::initialize(); - if (result != RETURN_OK) { - return result; - } - - communicationInterface = objectManager->get( - deviceCommunicationId); - if (communicationInterface == NULL) { - return RETURN_FAILED; - } - - result = communicationInterface->open(&cookie, logicalAddress, - maxDeviceReplyLen); - if (result != RETURN_OK) { - return result; - } - - IPCStore = objectManager->get(objects::IPC_STORE); - if (IPCStore == NULL) { - return RETURN_FAILED; - } - - AcceptsDeviceResponsesIF *rawReceiver = objectManager->get< - AcceptsDeviceResponsesIF>(rawDataReceiverId); - - if (rawReceiver == NULL) { - return RETURN_FAILED; - } - - defaultRawReceiver = rawReceiver->getDeviceQueue(); - - powerSwitcher = objectManager->get(powerSwitcherId); - if (powerSwitcher == NULL) { - return RETURN_FAILED; - } - - result = healthHelper.initialize(); - if (result != RETURN_OK) { - return result; - } - - result = modeHelper.initialize(); - if (result != RETURN_OK) { - return result; - } - result = actionHelper.initialize(commandQueue); - if (result != RETURN_OK) { - return result; - } - result = fdirInstance->initialize(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - - result = parameterHelper.initialize(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - - result = hkSwitcher.initialize(); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - - fillCommandAndReplyMap(); - - //Set temperature target state to NON_OP. - DataSet mySet; - PoolVariable thermalRequest(deviceThermalRequestPoolId, &mySet, - PoolVariableIF::VAR_WRITE); - mySet.read(); - thermalRequest = ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL; - mySet.commit(PoolVariableIF::VALID); - - return RETURN_OK; - -} void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len, MessageQueueId_t sendTo, bool isCommand) { @@ -1020,7 +1022,6 @@ void DeviceHandlerBase::replyRawReplyIfnotWiretapped(const uint8_t* data, } } - ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage( CommandMessage * message) { ReturnValue_t result; diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 95e972b65..7503faf9f 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -33,7 +33,6 @@ class StorageManagerIF; * Contains all devices and the DeviceHandlerBase class. */ - /** * @brief This is the abstract base class for device handlers. * @details @@ -56,6 +55,17 @@ class StorageManagerIF; * Device handler instances should extend this class and implement the abstract functions. * Components and drivers can send so called cookies which are used for communication * and contain information about the communcation (e.g. slave address for I2C or RMAP structs). + * The following abstract methods must be implemented by a device handler: + * 1. doStartUp() + * 2. doShutDown() + * 3. buildTransitionDeviceCommand() + * 4. buildNormalDeviceCommand() + * 5. buildCommandFromCommand() + * 6. fillCommandAndReplyMap() + * 7. scanForReply() + * 8. interpretDeviceReply() + * Other important virtual methods with a default implementation + * are the getTransitionDelay() function and the getSwitches() function * * @ingroup devices */ @@ -75,17 +85,19 @@ public: * @param setObjectId the ObjectId to pass to the SystemObject() Constructor * @param maxDeviceReplyLen the length the RMAP getRead call will be sent with * @param setDeviceSwitch the switch the device is connected to, for devices using two switches, overwrite getSwitches() + * @param deviceCommuncation Communcation Interface object which is used to implement communication functions + * @param thermalStatePoolId + * @param thermalRequestPoolId + * @param fdirInstance + * @param cmdQueueSize */ DeviceHandlerBase(uint32_t logicalAddress, object_id_t setObjectId, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, - object_id_t deviceCommunication, uint32_t thermalStatePoolId = - PoolVariableIF::NO_PARAMETER, + object_id_t deviceCommunication, + uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, FailureIsolationBase* fdirInstance = NULL, uint32_t cmdQueueSize = 20); - virtual MessageQueueId_t getCommandQueue(void) const; - - /** * @brief This function is the device handler base core component and is called periodically. * @details @@ -117,17 +129,214 @@ public: */ virtual ReturnValue_t performOperation(uint8_t counter); + /** + * @brief Initializes the device handler + * @details + * Initialize Device Handler as system object and + * initializes all important helper classes. + * Calls fillCommandAndReplyMap(). + * @return + */ virtual ReturnValue_t initialize(); - /** - * - * @param parentQueueId - */ - virtual void setParentQueue(MessageQueueId_t parentQueueId); /** * Destructor. */ virtual ~DeviceHandlerBase(); +protected: + /** + * This is used to let the child class handle the transition from mode @c _MODE_START_UP to @c MODE_ON + * + * It is only called when the device handler is in mode @c _MODE_START_UP. That means, the device switch(es) are already set to on. + * Device handler commands are read and can be handled by the child class. If the child class handles a command, it should also send + * an reply accordingly. + * If an Command is not handled (ie #DeviceHandlerCommand is not @c CMD_NONE, the base class handles rejecting the command and sends a reply. + * The replies for mode transitions are handled by the base class. + * + * If the device is started and ready for operation, the mode should be set to MODE_ON. It is possible to set the mode to _MODE_TO_ON to + * use the to on transition if available. + * If the power-up fails, the mode should be set to _MODE_POWER_DOWN which will lead to the device being powered off. + * If the device does not change the mode, the mode will be changed to _MODE_POWER_DOWN, after the timeout (from getTransitionDelay()) has passed. + * + * #transitionFailure can be set to a failure code indicating the reason for a failed transition + */ + virtual void doStartUp() = 0; + + /** + * This is used to let the child class handle the transition from mode @c _MODE_SHUT_DOWN to @c _MODE_POWER_DOWN + * + * It is only called when the device handler is in mode @c _MODE_SHUT_DOWN. + * Device handler commands are read and can be handled by the child class. If the child class handles a command, it should also send + * an reply accordingly. + * If an Command is not handled (ie #DeviceHandlerCommand is not @c CMD_NONE, the base class handles rejecting the command and sends a reply. + * The replies for mode transitions are handled by the base class. + * + * If the device ready to be switched off, the mode should be set to _MODE_POWER_DOWN. + * If the device should not be switched off, the mode can be changed to _MODE_TO_ON (or MODE_ON if no transition is needed). + * If the device does not change the mode, the mode will be changed to _MODE_POWER_DOWN, when the timeout (from getTransitionDelay()) has passed. + * + * #transitionFailure can be set to a failure code indicating the reason for a failed transition + */ + virtual void doShutDown() = 0; + + /** + * Build the device command to send for normal mode. + * + * This is only called in @c MODE_NORMAL. If multiple submodes for @c MODE_NORMAL are supported, + * different commands can built returned depending on the submode. + * + * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. + * + * @param[out] id the device command id that has been built + * @return + * - @c RETURN_OK when a command is to be sent + * - not @c RETURN_OK when no command is to be sent + */ + virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) = 0; + + /** + * Build the device command to send for a transitional mode. + * + * This is only called in @c _MODE_TO_NORMAL, @c _MODE_TO_ON, @c _MODE_TO_RAW, + * @c _MODE_START_UP and @c _MODE_TO_POWER_DOWN. So it is used by doStartUp() and doShutDown() as well as doTransition() + * + * A good idea is to implement a flag indicating a command has to be built and a variable containing the command number to be built + * and filling them in doStartUp(), doShutDown() and doTransition() so no modes have to be checked here. + * + * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. + * + * @param[out] id the device command id built + * @return + * - @c RETURN_OK when a command is to be sent + * - not @c RETURN_OK when no command is to be sent + */ + virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) = 0; + + /** + * Build a device command packet from data supplied by a direct command. + * + * #rawPacket and #rawPacketLen should be set by this method to the packet to be sent. + * + * @param deviceCommand the command to build, already checked against deviceCommandMap + * @param commandData pointer to the data from the direct command + * @param commandDataLen length of commandData + * @return + * - @c RETURN_OK when #rawPacket is valid + * - @c RETURN_FAILED when #rawPacket is invalid and no data should be sent + */ + virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, + const uint8_t * commandData, size_t commandDataLen) = 0; + + /** + * @brief fill the #deviceCommandMap + * called by the initialize() of the base class + * @details + * This is used to let the base class know which replies are expected. + * There are different scenarios regarding this: + * - "Normal" commands. These are commands, that trigger a direct reply from the device. In this case, the id of the command should be added to the command map + * with a commandData_t where maxDelayCycles is set to the maximum expected number of PST cycles the reply will take. Then, scanForReply returns the id of the command and the base class can handle time-out and missing replies. + * - Periodic, unrequested replies. These are replies that, once enabled, are sent by the device on its own in a defined interval. In this case, the id of the reply or a placeholder id should be added to the deviceCommandMap + * with a commandData_t where maxDelayCycles is set to the maximum expected number of PST cycles between two replies (also a tolerance should be added, as an FDIR message will be generated if it is missed). + * As soon as the replies are enabled, DeviceCommandInfo.periodic must be set to 1, DeviceCommandInfo.delayCycles to DeviceCommandInfo.MaxDelayCycles. From then on, the base class handles the reception. + * Then, scanForReply returns the id of the reply or the placeholder id and the base class will take care of checking that all replies are received and the interval is correct. + * When the replies are disabled, DeviceCommandInfo.periodic must be set to 0, DeviceCommandInfo.delayCycles to 0; + * - Aperiodic, unrequested replies. These are replies that are sent by the device without any preceding command and not in a defined interval. These are not entered in the deviceCommandMap but handled by returning @c APERIODIC_REPLY in scanForReply(). + * + */ + virtual void fillCommandAndReplyMap() = 0; + + /** + * @brief Scans a buffer for a valid reply. + * @details + * This is used by the base class to check the data received for valid packets. + * It only checks if a valid packet starts at @c start. + * It also only checks the structural validy of the packet, eg checksums lengths and protocol data. + * No information check is done, e.g. range checks etc. + * + * Errors should be reported directly, the base class does NOT report any errors based on the return + * value of this function. + * + * @param start start of remaining buffer to be scanned + * @param len length of remaining buffer to be scanned + * @param[out] foundId the id of the data found in the buffer. + * @param[out] foundLen length of the data found. Is to be set in function, buffer is scanned at previous position + foundLen. + * @return + * - @c RETURN_OK a valid packet was found at @c start, @c foundLen is valid + * - @c RETURN_FAILED no reply could be found starting at @c start, implies @c foundLen is not valid, base class will call scanForReply() again with ++start + * - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid, eg checksum error, implies @c foundLen is valid, can be used to skip some bytes + * - @c DeviceHandlerIF::LENGTH_MISSMATCH @c len is invalid + * - @c DeviceHandlerIF::IGNORE_REPLY_DATA Ignore this specific part of the packet + * - @c DeviceHandlerIF::IGNORE_FULL_PACKET Ignore the packet + * - @c APERIODIC_REPLY if a valid reply is received that has not been requested by a command, but should be handled anyway (@see also fillCommandAndCookieMap() ) + */ + virtual ReturnValue_t scanForReply(const uint8_t *start, uint32_t len, + DeviceCommandId_t *foundId, uint32_t *foundLen) = 0; + + /** + * @brief Interpret a reply from the device. + * @details + * This is called after scanForReply() found a valid packet, it can be assumed that the length and structure is valid. + * This routine extracts the data from the packet into a DataSet and then calls handleDeviceTM(), which either sends + * a TM packet or stores the data in the DataPool depending on whether the it was an external command. + * No packet length is given, as it should be defined implicitly by the id. + * + * @param id the id found by scanForReply() + * @param packet + * @return + * - @c RETURN_OK when the reply was interpreted. + * - @c RETURN_FAILED when the reply could not be interpreted, eg. logical errors or range violations occurred + */ + virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, + const uint8_t *packet) = 0; + + /** + * @brief Can be implemented by child handler to + * perform debugging + * @details Example: Calling this in performOperation + * to track values like mode. + * @param positionTracker Provide the child handler a way to know where the debugInterface was called + * @param objectId Provide the child handler object Id to specify actions for spefic devices + * @param parameter Supply a parameter of interest + * Please delete all debugInterface calls in DHB after debugging is finished ! + */ + virtual void debugInterface(uint8_t positionTracker = 0, object_id_t objectId = 0, uint32_t parameter = 0); + + /** + * Get the time needed to transit from modeFrom to modeTo. + * + * Used for the following transitions: + * modeFrom -> modeTo: + * MODE_ON -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] + * MODE_NORMAL -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] + * MODE_RAW -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] + * _MODE_START_UP -> MODE_ON (do not include time to set the switches, the base class got you covered) + * + * The default implementation returns 0 ! + * @param modeFrom + * @param modeTo + * @return time in ms + */ + virtual uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo); + + /** + * Return the switches connected to the device. + * + * The default implementation returns one switch set in the ctor. + * + * @param[out] switches pointer to an array of switches + * @param[out] numberOfSwitches length of returned array + * @return + * - @c RETURN_OK if the parameters were set + * - @c RETURN_FAILED if no switches exist + */ + virtual ReturnValue_t getSwitches(const uint8_t **switches, + uint8_t *numberOfSwitches); + +public: + /** + * @param parentQueueId + */ + virtual void setParentQueue(MessageQueueId_t parentQueueId); ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size); @@ -146,6 +355,8 @@ public: * @param task_ Pointer to the taskIF of this task */ virtual void setTaskIF(PeriodicTaskIF* task_); + virtual MessageQueueId_t getCommandQueue(void) const; + protected: /** * The Returnvalues id of this class, required by HasReturnvaluesIF @@ -357,41 +568,6 @@ protected: */ void setMode(Mode_t newMode, Submode_t submode); - /** - * This is used to let the child class handle the transition from mode @c _MODE_START_UP to @c MODE_ON - * - * It is only called when the device handler is in mode @c _MODE_START_UP. That means, the device switch(es) are already set to on. - * Device handler commands are read and can be handled by the child class. If the child class handles a command, it should also send - * an reply accordingly. - * If an Command is not handled (ie #DeviceHandlerCommand is not @c CMD_NONE, the base class handles rejecting the command and sends a reply. - * The replies for mode transitions are handled by the base class. - * - * If the device is started and ready for operation, the mode should be set to MODE_ON. It is possible to set the mode to _MODE_TO_ON to - * use the to on transition if available. - * If the power-up fails, the mode should be set to _MODE_POWER_DOWN which will lead to the device being powered off. - * If the device does not change the mode, the mode will be changed to _MODE_POWER_DOWN, after the timeout (from getTransitionDelay()) has passed. - * - * #transitionFailure can be set to a failure code indicating the reason for a failed transition - */ - virtual void doStartUp() = 0; - - /** - * This is used to let the child class handle the transition from mode @c _MODE_SHUT_DOWN to @c _MODE_POWER_DOWN - * - * It is only called when the device handler is in mode @c _MODE_SHUT_DOWN. - * Device handler commands are read and can be handled by the child class. If the child class handles a command, it should also send - * an reply accordingly. - * If an Command is not handled (ie #DeviceHandlerCommand is not @c CMD_NONE, the base class handles rejecting the command and sends a reply. - * The replies for mode transitions are handled by the base class. - * - * If the device ready to be switched off, the mode should be set to _MODE_POWER_DOWN. - * If the device should not be switched off, the mode can be changed to _MODE_TO_ON (or MODE_ON if no transition is needed). - * If the device does not change the mode, the mode will be changed to _MODE_POWER_DOWN, when the timeout (from getTransitionDelay()) has passed. - * - * #transitionFailure can be set to a failure code indicating the reason for a failed transition - */ - virtual void doShutDown() = 0; - /** * Do the transition to the main modes (MODE_ON, MODE_NORMAL and MODE_RAW). * @@ -421,24 +597,6 @@ protected: */ virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom); - /** - * Get the time needed to transit from modeFrom to modeTo. - * - * Used for the following transitions: - * modeFrom -> modeTo: - * MODE_ON -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] - * MODE_NORMAL -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] - * MODE_RAW -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] - * _MODE_START_UP -> MODE_ON (do not include time to set the switches, the base class got you covered) - * - * The default implementation returns 0; - * - * @param modeFrom - * @param modeTo - * @return time in ms - */ - virtual uint32_t getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo); - /** * Is the combination of mode and submode valid? * @@ -460,40 +618,6 @@ protected: */ virtual RmapAction_t getRmapAction(); - /** - * Build the device command to send for normal mode. - * - * This is only called in @c MODE_NORMAL. If multiple submodes for @c MODE_NORMAL are supported, - * different commands can built returned depending on the submode. - * - * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. - * - * @param[out] id the device command id that has been built - * @return - * - @c RETURN_OK when a command is to be sent - * - not @c RETURN_OK when no command is to be sent - */ - virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) = 0; - - /** - * Build the device command to send for a transitional mode. - * - * This is only called in @c _MODE_TO_NORMAL, @c _MODE_TO_ON, @c _MODE_TO_RAW, - * @c _MODE_START_UP and @c _MODE_TO_POWER_DOWN. So it is used by doStartUp() and doShutDown() as well as doTransition() - * - * A good idea is to implement a flag indicating a command has to be built and a variable containing the command number to be built - * and filling them in doStartUp(), doShutDown() and doTransition() so no modes have to be checked here. - * - * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. - * - * @param[out] id the device command id built - * @return - * - @c RETURN_OK when a command is to be sent - * - not @c RETURN_OK when no command is to be sent - */ - virtual ReturnValue_t buildTransitionDeviceCommand( - DeviceCommandId_t * id) = 0; - /** * Build the device command to send for raw mode. * @@ -514,52 +638,6 @@ protected: */ virtual ReturnValue_t buildChildRawCommand(); - /** - * Build a device command packet from data supplied by a direct command. - * - * #rawPacket and #rawPacketLen should be set by this method to the packet to be sent. - * - * @param deviceCommand the command to build, already checked against deviceCommandMap - * @param commandData pointer to the data from the direct command - * @param commandDataLen length of commandData - * @return - * - @c RETURN_OK when #rawPacket is valid - * - @c RETURN_FAILED when #rawPacket is invalid and no data should be sent - */ - virtual ReturnValue_t buildCommandFromCommand( - DeviceCommandId_t deviceCommand, const uint8_t * commandData, - size_t commandDataLen) = 0; - - /** - * @brief fill the #deviceCommandMap - * called by the initialize() of the base class - * @details - * This is used to let the base class know which replies are expected. - * There are different scenarios regarding this: - * - "Normal" commands. These are commands, that trigger a direct reply from the device. In this case, the id of the command should be added to the command map - * with a commandData_t where maxDelayCycles is set to the maximum expected number of PST cycles the reply will take. Then, scanForReply returns the id of the command and the base class can handle time-out and missing replies. - * - Periodic, unrequested replies. These are replies that, once enabled, are sent by the device on its own in a defined interval. In this case, the id of the reply or a placeholder id should be added to the deviceCommandMap - * with a commandData_t where maxDelayCycles is set to the maximum expected number of PST cycles between two replies (also a tolerance should be added, as an FDIR message will be generated if it is missed). - * As soon as the replies are enabled, DeviceCommandInfo.periodic must be set to 1, DeviceCommandInfo.delayCycles to DeviceCommandInfo.MaxDelayCycles. From then on, the base class handles the reception. - * Then, scanForReply returns the id of the reply or the placeholder id and the base class will take care of checking that all replies are received and the interval is correct. - * When the replies are disabled, DeviceCommandInfo.periodic must be set to 0, DeviceCommandInfo.delayCycles to 0; - * - Aperiodic, unrequested replies. These are replies that are sent by the device without any preceding command and not in a defined interval. These are not entered in the deviceCommandMap but handled by returning @c APERIODIC_REPLY in scanForReply(). - * - */ - virtual void fillCommandAndReplyMap() = 0; - - - /** - * @brief Can be implemented by child handler to - * perform debugging - * @details Example: Calling this in performOperation - * to track values like mode. - * @param positionTracker Provide the child handler a way to know where the debugInterface was called - * @param objectId Provide the child handler object Id to specify actions for spefic devices - * @param parameter Supply a parameter of interest - * Please delete all debugInterface calls in DHB after debugging is finished ! - */ - virtual void debugInterface(uint8_t positionTracker = 0, object_id_t objectId = 0, uint32_t parameter = 0); /** * This is a helper method to facilitate inserting entries in the command map. @@ -608,50 +686,6 @@ protected: */ uint8_t getReplyDelayCycles(DeviceCommandId_t deviceCommand); - /** - * Scans a buffer for a valid reply. - * - * This is used by the base class to check the data received from the RMAP stack for valid packets. - * It only checks if a valid packet starts at @c start. - * It also only checks the structural validy of the packet, eg checksums lengths and protocol data. No - * information check is done, eg range checks etc. - * - * Errors should be reported directly, the base class does NOT report any errors based on the return - * value of this function. - * - * @param start start of remaining buffer to be scanned - * @param len length of remaining buffer to be scanned - * @param[out] foundId the id of the data found in the buffer. - * @param[out] foundLen length of the data found. Is to be set in function, buffer is scanned at previous position + foundLen. - * @return - * - @c RETURN_OK a valid packet was found at @c start, @c foundLen is valid - * - @c RETURN_FAILED no reply could be found starting at @c start, implies @c foundLen is not valid, base class will call scanForReply() again with ++start - * - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid, eg checksum error, implies @c foundLen is valid, can be used to skip some bytes - * - @c DeviceHandlerIF::LENGTH_MISSMATCH @c len is invalid - * - @c DeviceHandlerIF::IGNORE_REPLY_DATA Ignore this specific part of the packet - * - @c DeviceHandlerIF::IGNORE_FULL_PACKET Ignore the packet - * - @c APERIODIC_REPLY if a valid reply is received that has not been requested by a command, but should be handled anyway (@see also fillCommandAndCookieMap() ) - */ - virtual ReturnValue_t scanForReply(const uint8_t *start, uint32_t len, - DeviceCommandId_t *foundId, uint32_t *foundLen) = 0; - - /** - * Interpret a reply from the device. - * - * This is called after scanForReply() found a valid packet, it can be assumed that the length and structure is valid. - * This routine extracts the data from the packet into a DataSet and then calls handleDeviceTM(), which either sends - * a TM packet or stores the data in the DataPool depending on whether the it was an external command. - * No packet length is given, as it should be defined implicitly by the id. - * - * @param id the id found by scanForReply() - * @param packet - * @return - * - @c RETURN_OK when the reply was interpreted. - * - @c RETURN_FAILED when the reply could not be interpreted, eg. logical errors or range violations occurred - */ - virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, - const uint8_t *packet) = 0; - /** * Construct a command reply containing a raw reply. * @@ -675,21 +709,6 @@ protected: */ void replyRawReplyIfnotWiretapped(const uint8_t *data, size_t len); - /** - * Return the switches connected to the device. - * - * The default implementation returns one switch set in the ctor. - * - * - * @param[out] switches pointer to an array of switches - * @param[out] numberOfSwitches length of returned array - * @return - * - @c RETURN_OK if the parameters were set - * - @c RETURN_FAILED if no switches exist - */ - virtual ReturnValue_t getSwitches(const uint8_t **switches, - uint8_t *numberOfSwitches); - /** * notify child about mode change */ From 3d2bdae14df5427251b59bd81dc44a82f7667a34 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 20 Jan 2020 23:29:36 +0100 Subject: [PATCH 0088/1774] CSB abstract functions moved to top So documentation of functions to implement is closer to the top --- devicehandlers/DeviceHandlerBase.h | 52 +++++++----- tmtcservices/CommandingServiceBase.h | 121 +++++++++++++-------------- 2 files changed, 92 insertions(+), 81 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 7503faf9f..f16a4ff96 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -39,18 +39,17 @@ class StorageManagerIF; * Documentation: Dissertation Baetz p.138,139, p.141-149 * * It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink, communication with - * physical devices, using the @link DeviceCommunicationIF, and communication with commanding objects. - * - * NOTE: RMAP is a standard which is used for FLP. - * RMAP communication is not mandatory for projects implementing the FSFW. - * However, the communication principles are similar to RMAP as there are two write and two send calls involved. - * + * physical devices, using the @link DeviceCommunicationIF @endlink, and communication with commanding objects. * It inherits SystemObject and thus can be created by the ObjectManagerIF. * * This class uses the opcode of ExecutableObjectIF to perform a step-wise execution. - * For each step an RMAP action is selected and executed. If data has been received (GET_READ), the data will be interpreted. + * For each step an RMAP action is selected and executed. + * If data has been received (GET_READ), the data will be interpreted. * The action for each step can be defined by the child class but as most device handlers share a 4-call * (sendRead-getRead-sendWrite-getWrite) structure, a default implementation is provided. + * NOTE: RMAP is a standard which is used for FLP. + * RMAP communication is not mandatory for projects implementing the FSFW. + * However, the communication principles are similar to RMAP as there are two write and two send calls involved. * * Device handler instances should extend this class and implement the abstract functions. * Components and drivers can send so called cookies which are used for communication @@ -64,8 +63,9 @@ class StorageManagerIF; * 6. fillCommandAndReplyMap() * 7. scanForReply() * 8. interpretDeviceReply() + * * Other important virtual methods with a default implementation - * are the getTransitionDelay() function and the getSwitches() function + * are the getTransitionDelayMs() function and the getSwitches() function. * * @ingroup devices */ @@ -233,14 +233,26 @@ protected: * @details * This is used to let the base class know which replies are expected. * There are different scenarios regarding this: - * - "Normal" commands. These are commands, that trigger a direct reply from the device. In this case, the id of the command should be added to the command map - * with a commandData_t where maxDelayCycles is set to the maximum expected number of PST cycles the reply will take. Then, scanForReply returns the id of the command and the base class can handle time-out and missing replies. - * - Periodic, unrequested replies. These are replies that, once enabled, are sent by the device on its own in a defined interval. In this case, the id of the reply or a placeholder id should be added to the deviceCommandMap - * with a commandData_t where maxDelayCycles is set to the maximum expected number of PST cycles between two replies (also a tolerance should be added, as an FDIR message will be generated if it is missed). - * As soon as the replies are enabled, DeviceCommandInfo.periodic must be set to 1, DeviceCommandInfo.delayCycles to DeviceCommandInfo.MaxDelayCycles. From then on, the base class handles the reception. - * Then, scanForReply returns the id of the reply or the placeholder id and the base class will take care of checking that all replies are received and the interval is correct. - * When the replies are disabled, DeviceCommandInfo.periodic must be set to 0, DeviceCommandInfo.delayCycles to 0; - * - Aperiodic, unrequested replies. These are replies that are sent by the device without any preceding command and not in a defined interval. These are not entered in the deviceCommandMap but handled by returning @c APERIODIC_REPLY in scanForReply(). + * - "Normal" commands. These are commands, that trigger a direct reply from the device. + * In this case, the id of the command should be added to the command map + * with a commandData_t where maxDelayCycles is set to the maximum expected + * number of PST cycles the reply will take. Then, scanForReply returns + * the id of the command and the base class can handle time-out and missing replies. + * - Periodic, unrequested replies. These are replies that, once enabled, are sent by the device + * on its own in a defined interval. In this case, the id of the reply + * or a placeholder id should be added to the deviceCommandMap with a commandData_t + * where maxDelayCycles is set to the maximum expected number of PST cycles between + * two replies (also a tolerance should be added, as an FDIR message will be generated if it is missed). + * As soon as the replies are enabled, DeviceCommandInfo.periodic must be set to 1, + * DeviceCommandInfo.delayCycles to DeviceCommandInfo.MaxDelayCycles. + * From then on, the base class handles the reception. + * Then, scanForReply returns the id of the reply or the placeholder id and the base class will + * take care of checking that all replies are received and the interval is correct. + * When the replies are disabled, DeviceCommandInfo.periodic must be set to 0, + * DeviceCommandInfo.delayCycles to 0; + * - Aperiodic, unrequested replies. These are replies that are sent + * by the device without any preceding command and not in a defined interval. + * These are not entered in the deviceCommandMap but handled by returning @c APERIODIC_REPLY in scanForReply(). * */ virtual void fillCommandAndReplyMap() = 0; @@ -306,10 +318,10 @@ protected: * * Used for the following transitions: * modeFrom -> modeTo: - * MODE_ON -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] - * MODE_NORMAL -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] - * MODE_RAW -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] - * _MODE_START_UP -> MODE_ON (do not include time to set the switches, the base class got you covered) + * - MODE_ON -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] + * - MODE_NORMAL -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] + * - MODE_RAW -> [MODE_ON, MODE_NORMAL, MODE_RAW, _MODE_POWER_DOWN] + * - _MODE_START_UP -> MODE_ON (do not include time to set the switches, the base class got you covered) * * The default implementation returns 0 ! * @param modeFrom diff --git a/tmtcservices/CommandingServiceBase.h b/tmtcservices/CommandingServiceBase.h index 279f9ab43..a62b7397d 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/tmtcservices/CommandingServiceBase.h @@ -104,6 +104,66 @@ public: }; protected: + /** + * Check the target subservice + * @param subservice + * @return + */ + virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0; + + /** + * Once a TC Request is valid, the existence of the destination and its target interface is checked and retrieved. + * The target message queue ID can then be acquired by using the target interface. + * @param subservice + * @param tcData Application Data of TC Packet + * @param tcDataLen + * @param id MessageQueue ID is stored here + * @param objectId Object ID is extracted and stored here + * @return - @c RETURN_OK on success + * - @c RETURN_FAILED + * - @c CSB or implementation specific return codes + */ + virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice, + const uint8_t *tcData, uint32_t tcDataLen, MessageQueueId_t *id, + object_id_t *objectId) = 0; + + /** + * After the Message Queue and Object ID are determined, + * the command is prepared by using an implementation specific CommandMessage type + * which is sent to the target object. + * It contains all necessary information for the device to execute telecommands. + * @param message + * @param subservice + * @param tcData + * @param tcDataLen + * @param state + * @param objectId Target object ID + * @return + */ + virtual ReturnValue_t prepareCommand(CommandMessage *message, + uint8_t subservice, const uint8_t *tcData, uint32_t tcDataLen, + uint32_t *state, object_id_t objectId) = 0; + + /** + * This function is responsible for the communication between the Command Service Base + * and the respective PUS Commanding Service once the execution has started. + * The PUS Commanding Service receives replies from the target device and forwards them by calling this function. + * There are different translations of these replies to specify how the Command Service proceeds. + * @param reply[out] Command Message which contains information about the command + * @param previousCommand [out] + * @param state + * @param optionalNextCommand + * @param objectId Source object ID + * @param isStep Flag value to mark steps of command execution + * @return - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to generate TC verification success + * - @c INVALID_REPLY can handle unrequested replies + * - Anything else triggers a TC verification failure + */ + virtual ReturnValue_t handleReply(const CommandMessage *reply, + Command_t previousCommand, uint32_t *state, + CommandMessage *optionalNextCommand, object_id_t objectId, + bool *isStep) = 0; + struct CommandInfo { struct tcInfo { uint8_t ackFlags; @@ -181,67 +241,6 @@ protected: void sendTmPacket(uint8_t subservice, SerializeIF* content, SerializeIF* header = NULL); - /** - * Check the target subservice - * @param subservice - * @return - */ - virtual ReturnValue_t isValidSubservice(uint8_t subservice) = 0; - - /** - * Once a TC Request is valid, the existence of the destination and its target interface is checked and retrieved. - * The target message queue ID can then be acquired by using the target interface. - * @param subservice - * @param tcData Application Data of TC Packet - * @param tcDataLen - * @param id MessageQueue ID is stored here - * @param objectId Object ID is extracted and stored here - * @return - @c RETURN_OK on success - * - @c RETURN_FAILED - * - @c CSB or implementation specific return codes - */ - virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice, - const uint8_t *tcData, uint32_t tcDataLen, MessageQueueId_t *id, - object_id_t *objectId) = 0; - - /** - * After the Message Queue and Object ID are determined, - * the command is prepared by using an implementation specific CommandMessage type - * which is sent to the target object. - * It contains all necessary information for the device to execute telecommands. - * @param message - * @param subservice - * @param tcData - * @param tcDataLen - * @param state - * @param objectId Target object ID - * @return - */ - virtual ReturnValue_t prepareCommand(CommandMessage *message, - uint8_t subservice, const uint8_t *tcData, uint32_t tcDataLen, - uint32_t *state, object_id_t objectId) = 0; - - /** - * This function is responsible for the communication between the Command Service Base - * and the respective PUS Commanding Service once the execution has started. - * The PUS Commanding Service receives replies from the target device and forwards them by calling this function. - * There are different translations of these replies to specify how the Command Service proceeds. - * @param reply[out] Command Message which contains information about the command - * @param previousCommand [out] - * @param state - * @param optionalNextCommand - * @param objectId Source object ID - * @param isStep Flag value to mark steps of command execution - * @return - @c RETURN_OK, @c EXECUTION_COMPLETE or @c NO_STEP_MESSAGE to generate TC verification success - * - @c INVALID_REPLY can handle unrequested replies - * - Anything else triggers a TC verification failure - */ - virtual ReturnValue_t handleReply(const CommandMessage *reply, - Command_t previousCommand, uint32_t *state, - CommandMessage *optionalNextCommand, object_id_t objectId, - bool *isStep) = 0; - - virtual void handleUnrequestedReply(CommandMessage *reply); virtual void doPeriodicOperation(); From 1977942c4b2a785e503c21f5cd5cc235ee69e9ed Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 22 Jan 2020 14:24:48 +0100 Subject: [PATCH 0089/1774] Array List Entry swapper function And respective SerialAdapter functions to use it --- container/ArrayList.h | 19 +++++++++++++++++++ container/FixedArrayList.h | 9 +++++++-- serialize/SerialArrayListAdapter.h | 15 ++------------- serialize/SerialFixedArrayListAdapter.h | 4 ++++ serialize/SerializeElement.h | 4 ++++ 5 files changed, 36 insertions(+), 15 deletions(-) diff --git a/container/ArrayList.h b/container/ArrayList.h index 9c4c4cebc..0a2c2ff7e 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -223,6 +223,25 @@ public: count_t remaining() { return (maxSize_ - size); } + + /** + * Swap the endianness of the Array list (not the length field !) + * Useful if the case the buffer type is larger than uint8_t + * @param list + */ + void swapArrayListEndianness() { + ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; + count_t i = 0; + // uint8_t buffer does not require swapping of entries. + if(sizeof(T) == 1) { + return; + } + while ((result == HasReturnvaluesIF::RETURN_OK) && (i < size)) { + T newEntry = EndianSwapper::swap(entries[i]); + entries[i] = newEntry; + ++i; + } + } private: /** * This is the copy constructor diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index b9394cfec..36d379793 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -2,8 +2,10 @@ #define FIXEDARRAYLIST_H_ #include + /** - * \ingroup container + * @brief Array List with a fixed maximum size + * @ingroup container */ template class FixedArrayList: public ArrayList { @@ -17,10 +19,13 @@ public: //We could create a constructor to initialize the fixed array list with data and the known size field //so it can be used for serialization too (with SerialFixedArrrayListAdapter) //is this feasible? - FixedArrayList(T * data_, count_t count): + FixedArrayList(T * data_, count_t count, bool swapArrayListEndianess = false): ArrayList(data, MAX_SIZE) { memcpy(this->data, data_, count); this->size = count; + if(swapArrayListEndianess) { + ArrayList::swapArrayListEndianness(); + } } FixedArrayList(const FixedArrayList& other) : diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 21cbbc4d6..3f80e97b6 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -79,20 +79,9 @@ public: return result; } - /** - * Swap the endianness of the Array list (not the length field !) - * Useful if the case the buffer type is large than uint8_t and the endianness - * is inconsistent with other SerializeElements. - * @param list - */ + static void swapArrayListEndianness(ArrayList* list) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; - count_t i = 0; - while ((result == HasReturnvaluesIF::RETURN_OK) && (i < list->size)) { - T newEntry = EndianSwapper::swap(list->entries[i]); - list->entries[i] = newEntry; - ++i; - } + list->swapArrayListEndianness(); } private: ArrayList *adaptee; diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 9613f6c13..67954d685 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -24,6 +24,10 @@ template class SerialFixedArrayListAdapter : public FixedArrayList, public SerializeIF { public: + /** + * Constructor Arguments are forwarded to FixedArrayList constructor + * @param args + */ template SerialFixedArrayListAdapter(Args... args) : FixedArrayList(std::forward(args)...) { } diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index 4f5a22b6e..cd040c0f7 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -19,6 +19,10 @@ template class SerializeElement : public SerializeIF, public LinkedElement { public: + /** + * Arguments are forwarded to the element datatype constructor + * @param args + */ template SerializeElement(Args... args) : LinkedElement(this), entry(std::forward(args)...) { From d330958abb5813261936198700a2fac535aa1884 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 22 Jan 2020 14:27:11 +0100 Subject: [PATCH 0090/1774] Array List endian swapper protected now --- container/ArrayList.h | 55 ++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 27 deletions(-) diff --git a/container/ArrayList.h b/container/ArrayList.h index 0a2c2ff7e..59e5eef4a 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -224,6 +224,34 @@ public: return (maxSize_ - size); } + +private: + /** + * This is the copy constructor + * + * It is private, as copying is too ambigous in this case. (Allocate a new backend? Use the same? + * What to do in an modifying call?) + * + * @param other + */ + ArrayList(const ArrayList& other) : + size(other.size), entries(other.entries), maxSize_(other.maxSize_), + allocated(false) {} +protected: + /** + * pointer to the array in which the entries are stored + */ + T *entries; + /** + * remembering the maximum size + */ + uint32_t maxSize_; + + /** + * true if the array was allocated and needs to be deleted in the destructor. + */ + bool allocated; + /** * Swap the endianness of the Array list (not the length field !) * Useful if the case the buffer type is larger than uint8_t @@ -242,33 +270,6 @@ public: ++i; } } -private: - /** - * This is the copy constructor - * - * It is private, as copying is too ambigous in this case. (Allocate a new backend? Use the same? - * What to do in an modifying call?) - * - * @param other - */ - ArrayList(const ArrayList& other) : - size(other.size), entries(other.entries), maxSize_(other.maxSize_), allocated( - false) { - } -protected: - /** - * pointer to the array in which the entries are stored - */ - T *entries; - /** - * remembering the maximum size - */ - uint32_t maxSize_; - - /** - * true if the array was allocated and needs to be deleted in the destructor. - */ - bool allocated; }; #endif /* ARRAYLIST_H_ */ From 6eedb3f09748ed698ece38cb9fc5be6ebe1d3c66 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 23 Jan 2020 15:45:21 +0100 Subject: [PATCH 0091/1774] New Pool List Initializer. Needs testing !!! --- datapool/PoolEntry.cpp | 11 ++++++----- datapool/PoolEntry.h | 3 ++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/datapool/PoolEntry.cpp b/datapool/PoolEntry.cpp index f2968c329..af5584d81 100644 --- a/datapool/PoolEntry.cpp +++ b/datapool/PoolEntry.cpp @@ -2,12 +2,13 @@ #include template -PoolEntry::PoolEntry( T* initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) { +PoolEntry::PoolEntry(std::initializer_list initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) { this->address = new T[this->length]; - if (initValue != NULL) { - memcpy(this->address, initValue, this->getByteSize() ); - } else { - memset(this->address, 0, this->getByteSize() ); + if(initValue.size() == 0) { + memset(this->address, 0, this->getByteSize()); + } + else { + memcpy(this->address, initValue.begin(), this->getByteSize()); } } diff --git a/datapool/PoolEntry.h b/datapool/PoolEntry.h index ce41a9917..97364bf0f 100644 --- a/datapool/PoolEntry.h +++ b/datapool/PoolEntry.h @@ -5,6 +5,7 @@ #include #include #include +#include /** * \brief This is a small helper class that defines a single data pool entry. * @@ -31,7 +32,7 @@ public: * \param set_length Defines the array length of this entry. * \param set_valid Sets the initialization flag. It is invalid (0) by default. */ - PoolEntry( T* initValue = NULL, uint8_t set_length = 1, uint8_t set_valid = 0 ); + PoolEntry( std::initializer_list initValue = {}, uint8_t set_length = 1, uint8_t set_valid = 0 ); /** * \brief The allocated memory for the variable is freed in the destructor. * \details As the data pool is global, this dtor is only called on program exit. From d9fa13b6ebd597b6c23f5768405dc757b467028e Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 26 Jan 2020 18:31:17 +0100 Subject: [PATCH 0092/1774] ADDED old pool entry constructor --- datapool/PoolEntry.cpp | 11 +++++++++++ datapool/PoolEntry.h | 1 + 2 files changed, 12 insertions(+) diff --git a/datapool/PoolEntry.cpp b/datapool/PoolEntry.cpp index af5584d81..898d226e2 100644 --- a/datapool/PoolEntry.cpp +++ b/datapool/PoolEntry.cpp @@ -12,6 +12,17 @@ PoolEntry::PoolEntry(std::initializer_list initValue, uint8_t set_length, } } +template +PoolEntry::PoolEntry( T* initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) { + this->address = new T[this->length]; + if (initValue != NULL) { + memcpy(this->address, initValue, this->getByteSize() ); + } else { + memset(this->address, 0, this->getByteSize() ); + } +} + + //As the data pool is global, this dtor is only be called on program exit. //Warning! Never copy pool entries! template diff --git a/datapool/PoolEntry.h b/datapool/PoolEntry.h index 97364bf0f..a02c6c60d 100644 --- a/datapool/PoolEntry.h +++ b/datapool/PoolEntry.h @@ -33,6 +33,7 @@ public: * \param set_valid Sets the initialization flag. It is invalid (0) by default. */ PoolEntry( std::initializer_list initValue = {}, uint8_t set_length = 1, uint8_t set_valid = 0 ); + PoolEntry( T* initValue = NULL, uint8_t set_length = 1, uint8_t set_valid = 0 ); /** * \brief The allocated memory for the variable is freed in the destructor. * \details As the data pool is global, this dtor is only called on program exit. From 85048cc9ee180ce6ba14485d18d85bf694e1e51f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 26 Jan 2020 22:13:56 +0100 Subject: [PATCH 0093/1774] Pool Raw Access change bugfix --- datapool/PoolRawAccess.cpp | 37 ++++++++++++++++++++++--------------- datapool/PoolRawAccess.h | 1 + 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 899eedd69..ff8fb9561 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -21,24 +21,13 @@ ReturnValue_t PoolRawAccess::read() { PoolEntryIF* read_out = ::dataPool.getRawData(dataPoolId); if (read_out != NULL) { result = handleReadOut(read_out); + if(result == RETURN_OK) { + return result; + } } else { result = READ_ENTRY_NON_EXISTENT; } - error << "PoolRawAccess: read of DP Variable 0x" << std::hex << dataPoolId - << std::dec << " failed, "; - if(result == READ_TYPE_TOO_LARGE) { - error << "type too large." << std::endl; - } - else if(result == READ_INDEX_TOO_LARGE) { - error << "index too large." << std::endl; - } - else { - error << "entry does not exist." << std::endl; - } - valid = INVALID; - typeSize = 0; - sizeTillEnd = 0; - memset(value, 0, sizeof(value)); + handleReadError(result); return result; } @@ -65,6 +54,24 @@ ReturnValue_t PoolRawAccess::handleReadOut(PoolEntryIF* read_out) { return result; } +void PoolRawAccess::handleReadError(ReturnValue_t result) { + error << "PoolRawAccess: read of DP Variable 0x" << std::hex << dataPoolId + << std::dec << " failed, "; + if(result == READ_TYPE_TOO_LARGE) { + error << "type too large." << std::endl; + } + else if(result == READ_INDEX_TOO_LARGE) { + error << "index too large." << std::endl; + } + else if(result == READ_ENTRY_NON_EXISTENT) { + error << "entry does not exist." << std::endl; + } + valid = INVALID; + typeSize = 0; + sizeTillEnd = 0; + memset(value, 0, sizeof(value)); +} + ReturnValue_t PoolRawAccess::commit() { PoolEntryIF* write_back = ::dataPool.getRawData(dataPoolId); if ((write_back != NULL) && (readWriteMode != VAR_READ)) { diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 5fb482f09..52ba8b210 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -157,6 +157,7 @@ protected: ReturnValue_t commit(); ReturnValue_t handleReadOut(PoolEntryIF* read_out); + void handleReadError(ReturnValue_t result); private: /** * \brief To access the correct data pool entry on read and commit calls, the data pool id From 8f17d5147e7b13179c32fa47f2c2bdc7408e4ef5 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 27 Jan 2020 00:43:01 +0100 Subject: [PATCH 0094/1774] SerialFixedArrayList constructor bugfix --- container/FixedArrayList.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/container/FixedArrayList.h b/container/FixedArrayList.h index 36d379793..12e292b4a 100644 --- a/container/FixedArrayList.h +++ b/container/FixedArrayList.h @@ -21,7 +21,7 @@ public: //is this feasible? FixedArrayList(T * data_, count_t count, bool swapArrayListEndianess = false): ArrayList(data, MAX_SIZE) { - memcpy(this->data, data_, count); + memcpy(this->data, data_, count * sizeof(T)); this->size = count; if(swapArrayListEndianess) { ArrayList::swapArrayListEndianness(); From 7dd4694d9d9e25114c6b52f7539ced43b8bdca3f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 28 Jan 2020 23:19:19 +0100 Subject: [PATCH 0095/1774] CCSDS time extra defined for avr lib --- timemanager/CCSDSTime.cpp | 47 +++++++++++++++++++++++++++++--- timemanager/ReceivesTimeInfoIF.h | 1 + 2 files changed, 44 insertions(+), 4 deletions(-) diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index 2eb6c4b54..c3a28df71 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -154,6 +154,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* if (length < 19) { return RETURN_FAILED; } +#ifdef AVR_STDIO // In the size optimized nano library used by ATMEL, floating point conversion // is not allowed. There is a linker flag to allow it apparently, but I // could not manage to make it run (removing -specs=nano.specs in linker flags works though, @@ -167,11 +168,8 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* int minute; int second; int usecond; - // try Code A (yyyy-mm-dd) - //int count = sscanf((char *) from, "%4hi-%2hi-%2hiT%2hi:%2hi:%fZ", &year, - // &month, &day, &hour, &minute, &second); int count = sscanf((char *) from, "%4d-%2d-%2dT%2d:%2d:%2d.%dZ", &year, - &month, &day, &hour, &minute, &second, &usecond); + &month, &day, &hour, &minute, &second, &usecond); if (count == 7) { to->year = year; to->month = month; @@ -202,6 +200,47 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* to->usecond = usecond; return RETURN_OK; } +#else + uint16_t year; + uint8_t month; + uint16_t day; + uint8_t hour; + uint8_t minute; + float second; + //try Code A (yyyy-mm-dd) + int count = sscanf((char *) from, "%4hi-%2hhi-%2hiT%2hhi:%2hhi:%fZ", &year, + &month, &day, &hour, &minute, &second); + if (count == 6) { + to->year = year; + to->month = month; + to->day = day; + to->hour = hour; + to->minute = minute; + to->second = second; + to->usecond = (second - floor(second)) * 1000000; + return RETURN_OK; + } + + //try Code B (yyyy-ddd) + count = sscanf((char *) from, "%4hi-%3hiT%2hhi:%2hhi:%fZ", &year, &day, + &hour, &minute, &second); + if (count == 5) { + uint8_t tempDay; + ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year, &month, + &tempDay); + if (result != RETURN_OK) { + return RETURN_FAILED; + } + to->year = year; + to->month = month; + to->day = tempDay; + to->hour = hour; + to->minute = minute; + to->second = second; + to->usecond = (second - floor(second)) * 1000000; + return RETURN_OK; + } +#endif return UNSUPPORTED_TIME_FORMAT; } diff --git a/timemanager/ReceivesTimeInfoIF.h b/timemanager/ReceivesTimeInfoIF.h index 14a750c56..f65f9dadd 100644 --- a/timemanager/ReceivesTimeInfoIF.h +++ b/timemanager/ReceivesTimeInfoIF.h @@ -7,6 +7,7 @@ #ifndef RECEIVESTIMEINFOIF_H_ #define RECEIVESTIMEINFOIF_H_ +#include /** * This is a Interface for classes that receive timing information From 09144b18c4fad1c9c92510f3c99ad377ddbbac58 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 29 Jan 2020 01:03:20 +0100 Subject: [PATCH 0096/1774] ccsds time changes changed --- timemanager/CCSDSTime.cpp | 43 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 24 deletions(-) diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index c3a28df71..a81f55967 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -1,5 +1,6 @@ #include #include +#include #include CCSDSTime::CCSDSTime() { @@ -154,39 +155,33 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* if (length < 19) { return RETURN_FAILED; } -#ifdef AVR_STDIO - // In the size optimized nano library used by ATMEL, floating point conversion - // is not allowed. There is a linker flag to allow it apparently, but I - // could not manage to make it run (removing -specs=nano.specs in linker flags works though, - // but we propably should include this). Using floats with sscanf is also expensive. - // Furthermore, the stdio.c library by ATMEL can't resolve the %hhi specifiers - // Therefore, I adapted this function. - int year; - int month; - int day; - int hour; - int minute; - int second; - int usecond; - int count = sscanf((char *) from, "%4d-%2d-%2dT%2d:%2d:%2d.%dZ", &year, - &month, &day, &hour, &minute, &second, &usecond); - if (count == 7) { +// Newlib can't parse uint8 (there is a configure option but I still need to figure out how to make it work..) +#ifdef NEWLIB_NO_C99_IO + uint16_t year; + uint16_t month; + uint16_t day; + uint16_t hour; + uint16_t minute; + float second; + int count = sscanf((char *) from, "%4" SCNu16 "-%2" SCNu16 "-%2" SCNu16 "T%2" SCNu16 ":%2" SCNu16 ":%fZ", &year, + &month, &day, &hour, &minute, &second); + if (count == 6) { to->year = year; to->month = month; to->day = day; to->hour = hour; to->minute = minute; to->second = second; - to->usecond = usecond;//(second - floor(second)) * 1000000; + to->usecond = (second - floor(second)) * 1000000; return RETURN_OK; } // try Code B (yyyy-ddd) - count = sscanf((char *) from, "%4i-%3iT%2i:%2i:%2i.%iZ", &year, &day, - &hour, &minute, &second, &usecond); - if (count == 6) { + count = sscanf((char *) from, "%4" SCNu16 "-%3" SCNu16 "T%2" SCNu16 ":%2" SCNu16 ":%fZ", &year, &day, + &hour, &minute, &second); + if (count == 5) { uint8_t tempDay; - ReturnValue_t result = CCSDSTime::convertDaysOfYear((uint16_t)day,(uint16_t) year,(uint8_t *) &month, + ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year,(uint8_t *) &month, &tempDay); if (result != RETURN_OK) { return RETURN_FAILED; @@ -197,7 +192,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* to->hour = hour; to->minute = minute; to->second = second; - to->usecond = usecond; + to->usecond = (second - floor(second)) * 1000000; return RETURN_OK; } #else @@ -208,7 +203,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* uint8_t minute; float second; //try Code A (yyyy-mm-dd) - int count = sscanf((char *) from, "%4hi-%2hhi-%2hiT%2hhi:%2hhi:%fZ", &year, + int count = sscanf((char *) from, "%4" SCNu16 "-%2" SCNu8 "-%2" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year, &month, &day, &hour, &minute, &second); if (count == 6) { to->year = year; From 5190e4c16e0f6618cd1c6b3a3b8f8ad7683172f7 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 31 Jan 2020 00:54:34 +0100 Subject: [PATCH 0097/1774] Serial Buffer dapter changes reverted CCSDS time bugfixes in separate section (for C98) Serial buffer adapter 2 bugfixes --- serialize/SerialBufferAdapter2.h | 4 +++- serviceinterface/ServiceInterfaceBuffer.cpp | 14 +++++++------- timemanager/CCSDSTime.cpp | 10 ++++++---- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/serialize/SerialBufferAdapter2.h b/serialize/SerialBufferAdapter2.h index 59c79dc2e..98e2d187d 100644 --- a/serialize/SerialBufferAdapter2.h +++ b/serialize/SerialBufferAdapter2.h @@ -131,6 +131,7 @@ private: void determineLengthInBytes(uint8_t typeSize) { switch(typeSize) { + case(1): break; case(2): bufferLength *= 2; break; case(4): @@ -138,7 +139,8 @@ private: case(8): bufferLength *= 8; break; default: - warning << "Invalid type size, assuming regular uint8_t." << std::endl; + error << "Serial Buffer Adapter 2: Invalid type size, assuming regular uint8_t." << std::endl; + error << "Detected type size: " << (int) typeSize << std::endl; } } }; diff --git a/serviceinterface/ServiceInterfaceBuffer.cpp b/serviceinterface/ServiceInterfaceBuffer.cpp index d5ce60568..6798b776d 100644 --- a/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/serviceinterface/ServiceInterfaceBuffer.cpp @@ -1,6 +1,7 @@ #include #include #include +#include // to be implemented by bsp extern "C" void printChar(const char*); @@ -21,18 +22,17 @@ int ServiceInterfaceBuffer::overflow(int c) { return 0; } -// custom stdio.c library for at91sam9g20 chip which does not support unsigned long -// So I cast (unsigned int) on loggerTimes int ServiceInterfaceBuffer::sync(void) { if (this->isActive) { Clock::TimeOfDay_t loggerTime; Clock::getDateAndTime(&loggerTime); char preamble[96] = { 0 }; - sprintf(preamble, "%s: | %u:%02u:%02u.%03u | ", - this->log_message.c_str(), (unsigned int) loggerTime.hour, - (unsigned int) loggerTime.minute, - (unsigned int) loggerTime.second, - (unsigned int) loggerTime.usecond /1000); + sprintf(preamble, "%s: | %" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%03" PRIu32 " | ", + this->log_message.c_str(), + loggerTime.hour, + loggerTime.minute, + loggerTime.second, + loggerTime.usecond /1000); // Write log_message and time this->putChars(preamble, preamble + sizeof(preamble)); // Handle output diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index a81f55967..8a123f854 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -155,8 +155,9 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* if (length < 19) { return RETURN_FAILED; } -// Newlib can't parse uint8 (there is a configure option but I still need to figure out how to make it work..) -#ifdef NEWLIB_NO_C99_IO +// Newlib nano can't parse uint8, see SCNu8 documentation and https://sourceware.org/newlib/README +// Suggestion: use uint16 all the time. This should work on all systems. +#ifdef NEWLIB_NANO_NO_C99_IO uint16_t year; uint16_t month; uint16_t day; @@ -181,8 +182,8 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* &hour, &minute, &second); if (count == 5) { uint8_t tempDay; - ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year,(uint8_t *) &month, - &tempDay); + ReturnValue_t result = CCSDSTime::convertDaysOfYear(day, year, + reinterpret_cast(&month), reinterpret_cast(&tempDay)); if (result != RETURN_OK) { return RETURN_FAILED; } @@ -195,6 +196,7 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* to->usecond = (second - floor(second)) * 1000000; return RETURN_OK; } +// Warning: Compiler/Linker fails ambiguously if library does not implement C99 I/O #else uint16_t year; uint8_t month; From b3faf1e4adee4097b9bcc15ad61c299adacc33a2 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 31 Jan 2020 23:42:11 +0100 Subject: [PATCH 0098/1774] old timestring used --- timemanager/CCSDSTime.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index 8a123f854..29aafb68d 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -205,8 +205,8 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* uint8_t minute; float second; //try Code A (yyyy-mm-dd) - int count = sscanf((char *) from, "%4" SCNu16 "-%2" SCNu8 "-%2" SCNu16 "T%2" SCNu8 ":%2" SCNu8 ":%fZ", &year, - &month, &day, &hour, &minute, &second); + int count = sscanf((char *) from, "%4hi-%2hhi-%2hiT%2hhi:%2hhi:%fZ", &year, + &month, &day, &hour, &minute, &second); if (count == 6) { to->year = year; to->month = month; From e15839b3a6cdccf3f437991262c0c2eddb6b4ba6 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 15 Feb 2020 18:26:25 +0100 Subject: [PATCH 0099/1774] Thermal: Some formatting stuff, doc to do Need to find out how to use the thermal components --- thermal/AbstractTemperatureSensor.h | 3 +- thermal/CoreComponent.h | 2 +- thermal/RedundantHeater.h | 11 +++--- thermal/TemperatureSensor.h | 56 +++++++++++++++++------------ thermal/ThermalComponent.cpp | 10 +++--- thermal/ThermalComponent.h | 25 +++++++++++-- thermal/ThermalMonitor.h | 3 ++ 7 files changed, 72 insertions(+), 38 deletions(-) diff --git a/thermal/AbstractTemperatureSensor.h b/thermal/AbstractTemperatureSensor.h index 3bebbe73c..4b8693655 100644 --- a/thermal/AbstractTemperatureSensor.h +++ b/thermal/AbstractTemperatureSensor.h @@ -16,7 +16,8 @@ */ /** - * @brief Base class for Temperature Sensor, implements all important interfaces + * @brief Base class for Temperature Sensor, implements all important interfaces. + * Please use the TemperatureSensor class to implement the actual sensors. * @ingroup thermal */ class AbstractTemperatureSensor: public HasHealthIF, diff --git a/thermal/CoreComponent.h b/thermal/CoreComponent.h index e21ee113b..da77c65b3 100644 --- a/thermal/CoreComponent.h +++ b/thermal/CoreComponent.h @@ -8,7 +8,7 @@ #include #include -// TODO: Documentaiton, how to use this? only use Thermal COmponent, which inherits core component? +// TODO: Documentaiton, how to use this? only use Thermal Component, which inherits core component? class CoreComponent: public ThermalComponentIF { public: struct Parameters { diff --git a/thermal/RedundantHeater.h b/thermal/RedundantHeater.h index 29791a9a1..55d402d75 100644 --- a/thermal/RedundantHeater.h +++ b/thermal/RedundantHeater.h @@ -10,15 +10,14 @@ public: Parameters(uint32_t objectIdHeater0, uint32_t objectIdHeater1, uint8_t switch0Heater0, uint8_t switch1Heater0, uint8_t switch0Heater1, uint8_t switch1Heater1) : - objectIdHeater0(objectIdHeater0), objectIdHeater1( - objectIdHeater1), switch0Heater0(switch0Heater0), switch1Heater0( - switch1Heater0), switch0Heater1(switch0Heater1), switch1Heater1( - switch1Heater1) { + objectIdHeater0(objectIdHeater0), objectIdHeater1(objectIdHeater1), + switch0Heater0(switch0Heater0),switch1Heater0(switch1Heater0), + switch0Heater1(switch0Heater1), switch1Heater1(switch1Heater1) { } Parameters() : - objectIdHeater0(0), objectIdHeater1(0), switch0Heater0(0), switch1Heater0( - 0), switch0Heater1(0), switch1Heater1(0) { + objectIdHeater0(0), objectIdHeater1(0), switch0Heater0(0), + switch1Heater0(0), switch0Heater1(0), switch1Heater1(0) { } uint32_t objectIdHeater0; diff --git a/thermal/TemperatureSensor.h b/thermal/TemperatureSensor.h index cbf8ea30f..2f64f7721 100644 --- a/thermal/TemperatureSensor.h +++ b/thermal/TemperatureSensor.h @@ -8,14 +8,17 @@ /** * @brief This building block handles non-linear value conversion and * range checks for analog temperature sensors. - * @details - * + * @details HOW TO USE * */ template class TemperatureSensor: public AbstractTemperatureSensor { public: + + /** + * What are a,b and c? + */ struct Parameters { float a; float b; @@ -24,11 +27,37 @@ public: T upperLimit; float gradient; }; + + /** + * How to use me. + * @param setObjectid + * @param inputTemperature + * @param poolVariable + * @param vectorIndex + * @param parameters + * @param datapoolId + * @param outputSet + * @param thermalModule + */ + TemperatureSensor(object_id_t setObjectid, + T *inputTemperature, PoolVariableIF *poolVariable, + uint8_t vectorIndex, Parameters parameters, uint32_t datapoolId, + DataSet *outputSet, ThermalModuleIF *thermalModule) : + + AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters), + inputTemperature(inputTemperature), poolVariable(poolVariable), + outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE), + sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, + DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex), + DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit,parameters.upperLimit, + TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH), + oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) { + } + struct UsedParameters { UsedParameters(Parameters parameters) : - a(parameters.a), b(parameters.b), c(parameters.c), gradient( - parameters.gradient) { - } + a(parameters.a), b(parameters.b), c(parameters.c), + gradient(parameters.gradient) {} float a; float b; float c; @@ -118,23 +147,6 @@ protected: } public: - TemperatureSensor(object_id_t setObjectid, - T *inputTemperature, PoolVariableIF *poolVariable, - uint8_t vectorIndex, Parameters parameters, uint32_t datapoolId, - DataSet *outputSet, ThermalModuleIF *thermalModule) : - AbstractTemperatureSensor(setObjectid, thermalModule), parameters( - parameters), inputTemperature(inputTemperature), poolVariable( - poolVariable), outputTemperature(datapoolId, outputSet, - PoolVariableIF::VAR_WRITE), sensorMonitor(setObjectid, - DOMAIN_ID_SENSOR, - DataPool::poolIdAndPositionToPid( - poolVariable->getDataPoolId(), vectorIndex), - DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, - parameters.upperLimit, TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH), oldTemperature( - 20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) { - - } - float getTemperature() { return outputTemperature; } diff --git a/thermal/ThermalComponent.cpp b/thermal/ThermalComponent.cpp index bf6f73986..15a2bbc9c 100644 --- a/thermal/ThermalComponent.cpp +++ b/thermal/ThermalComponent.cpp @@ -12,12 +12,10 @@ ThermalComponent::ThermalComponent(object_id_t reportingObjectId, CoreComponent(reportingObjectId, domainId, temperaturePoolId, targetStatePoolId, currentStatePoolId, requestPoolId, dataSet, sensor, firstRedundantSensor, secondRedundantSensor, - thermalModule, - { parameters.lowerOpLimit, parameters.upperOpLimit, - parameters.heaterOn, parameters.hysteresis, - parameters.heaterSwitchoff }, priority, - ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL), nopParameters( - { parameters.lowerNopLimit, parameters.upperNopLimit }) { + thermalModule,{ parameters.lowerOpLimit, parameters.upperOpLimit, + parameters.heaterOn, parameters.hysteresis, parameters.heaterSwitchoff }, + priority, ThermalComponentIF::STATE_REQUEST_NON_OPERATIONAL), + nopParameters({ parameters.lowerNopLimit, parameters.upperNopLimit }) { } ThermalComponent::~ThermalComponent() { diff --git a/thermal/ThermalComponent.h b/thermal/ThermalComponent.h index 7482bd9b8..4e32e97cd 100644 --- a/thermal/ThermalComponent.h +++ b/thermal/ThermalComponent.h @@ -3,6 +3,9 @@ #include "CoreComponent.h" +/** + * What is it. How to use + */ class ThermalComponent: public CoreComponent { public: struct Parameters { @@ -15,12 +18,30 @@ public: float heaterSwitchoff; }; - // TODO: Documentaiton ,what is NOP? - // propably Non-operational? + /** + * Non-Operational Temperatures + */ struct NopParameters { float lowerNopLimit; float upperNopLimit; }; + + /** + * How to use. + * @param reportingObjectId + * @param domainId + * @param temperaturePoolId + * @param targetStatePoolId + * @param currentStatePoolId + * @param requestPoolId + * @param dataSet + * @param sensor + * @param firstRedundantSensor + * @param secondRedundantSensor + * @param thermalModule + * @param parameters + * @param priority + */ ThermalComponent(object_id_t reportingObjectId, uint8_t domainId, uint32_t temperaturePoolId, uint32_t targetStatePoolId, uint32_t currentStatePoolId, uint32_t requestPoolId, DataSet *dataSet, AbstractTemperatureSensor *sensor, diff --git a/thermal/ThermalMonitor.h b/thermal/ThermalMonitor.h index 6aca55abc..a38889d01 100644 --- a/thermal/ThermalMonitor.h +++ b/thermal/ThermalMonitor.h @@ -4,6 +4,9 @@ #include #include +/** + * What does it do. How to use it. + */ class ThermalMonitor: public MonitorReporter { public: template From d8ed5bb1c15587ef853432a84a3c0334350f9ebd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 15 Feb 2020 18:55:22 +0100 Subject: [PATCH 0100/1774] some comments for missing doc --- tmstorage/TmStoreBackendIF.h | 19 +++++++++++++++++++ tmstorage/TmStoreFrontendIF.h | 8 ++++++++ 2 files changed, 27 insertions(+) diff --git a/tmstorage/TmStoreBackendIF.h b/tmstorage/TmStoreBackendIF.h index 162bd7665..9b913b35a 100644 --- a/tmstorage/TmStoreBackendIF.h +++ b/tmstorage/TmStoreBackendIF.h @@ -49,14 +49,33 @@ public: static const Event AUTO_CATALOGS_SENDING_FAILED = MAKE_EVENT(15, SEVERITY::INFO);//!< Info that the a auto catalog report failed virtual ~TmStoreBackendIF() {} + + /** + * What do I need to implement here ? + * @param opCode + * @return + */ virtual ReturnValue_t performOperation(uint8_t opCode) = 0; virtual ReturnValue_t initialize() = 0; + + /** + * Implement the storage of TM packets to mass memory + * @param tmPacket + * @return + */ virtual ReturnValue_t storePacket(TmPacketMinimal* tmPacket) = 0; virtual ReturnValue_t setFetchLimitTime(const timeval* loverLimit, const timeval* upperLimit) = 0; virtual ReturnValue_t setFetchLimitBlocks(uint32_t startAddress, uint32_t endAddress) = 0; virtual ReturnValue_t fetchPackets(bool fromBegin = false) = 0; virtual ReturnValue_t initializeStore(object_id_t dumpTarget) = 0; virtual ReturnValue_t dumpIndex(store_address_t* storeId) = 0; + + /** + * TODO: Adapt for file management system? + * @param startAddress + * @param endAddress + * @return + */ virtual ReturnValue_t deleteBlocks(uint32_t startAddress, uint32_t endAddress) = 0; virtual ReturnValue_t deleteTime(const timeval* timeUntil, uint32_t* deletedPackets) = 0; diff --git a/tmstorage/TmStoreFrontendIF.h b/tmstorage/TmStoreFrontendIF.h index 787c35972..7d38cfc6b 100644 --- a/tmstorage/TmStoreFrontendIF.h +++ b/tmstorage/TmStoreFrontendIF.h @@ -11,6 +11,14 @@ class TmStoreBackendIF; class TmStoreFrontendIF { public: virtual TmStoreBackendIF* getBackend() const = 0; + + /** + * What do I need to implement here? + * This is propably used by PUS Service 15 so we should propably check for messages.. + * Provide base implementation? + * @param opCode + * @return + */ virtual ReturnValue_t performOperation(uint8_t opCode) = 0; /** * Callback from the back-end to indicate a certain packet was received. From ddae9ee80f2c74383fa4efa91082c3871b60f6d3 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 16 Feb 2020 14:59:45 +0100 Subject: [PATCH 0101/1774] =?UTF-8?q?adapted=20temp=20sensor=20to=20use=20?= =?UTF-8?q?=C2=B0C=20limits,=20doc=20added?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- monitoring/LimitMonitor.h | 11 +-- thermal/TemperatureSensor.h | 152 +++++++++++++++++++++++------------- 2 files changed, 105 insertions(+), 58 deletions(-) diff --git a/monitoring/LimitMonitor.h b/monitoring/LimitMonitor.h index 45abe48bf..c24629a35 100644 --- a/monitoring/LimitMonitor.h +++ b/monitoring/LimitMonitor.h @@ -16,12 +16,13 @@ public: uint16_t confirmationLimit, T lowerLimit, T upperLimit, Event belowLowEvent = MonitoringIF::VALUE_BELOW_LOW_LIMIT, Event aboveHighEvent = MonitoringIF::VALUE_ABOVE_HIGH_LIMIT) : - MonitorBase(reporterId, monitorId, parameterId, confirmationLimit), lowerLimit( - lowerLimit), upperLimit(upperLimit), belowLowEvent( - belowLowEvent), aboveHighEvent(aboveHighEvent) { - } - virtual ~LimitMonitor() { + MonitorBase(reporterId, monitorId, parameterId, confirmationLimit), + lowerLimit(lowerLimit), upperLimit(upperLimit), belowLowEvent(belowLowEvent), + aboveHighEvent(aboveHighEvent) { } + + virtual ~LimitMonitor() {} + virtual ReturnValue_t checkSample(T sample, T* crossedLimit) { *crossedLimit = 0.0; if (sample > upperLimit) { diff --git a/thermal/TemperatureSensor.h b/thermal/TemperatureSensor.h index 2f64f7721..ca0dbce61 100644 --- a/thermal/TemperatureSensor.h +++ b/thermal/TemperatureSensor.h @@ -1,105 +1,142 @@ #ifndef TEMPERATURESENSOR_H_ #define TEMPERATURESENSOR_H_ +#include #include -#include "AbstractTemperatureSensor.h" #include /** * @brief This building block handles non-linear value conversion and * range checks for analog temperature sensors. - * @details HOW TO USE + * @details This class can be used to perform all necessary tasks for temperature sensors. + * A sensor can be instantiated by calling the constructor. + * The temperature is calculated from an input value with + * the calculateOutputTemperature() function. Range checking and + * limit monitoring is performed automatically. * + * @ingroup thermal */ template class TemperatureSensor: public AbstractTemperatureSensor { public: - /** - * What are a,b and c? + * This structure contains parameters required for range checking + * and the conversion from the input value to the output temperature. + * a, b and c can be any parameters required to calculate the output + * temperature from the input value, for example parameters for the + * Callendar-Van-Dusen equation(see datasheet of used sensor / ADC) + * + * The parameters a,b and c are used in the calculateOutputTemperature() call. + * + * The lower and upper limits can be specified in °C or in the input value + * format */ struct Parameters { float a; float b; float c; - T lowerLimit; - T upperLimit; - float gradient; + float maxGradient; }; /** - * How to use me. - * @param setObjectid - * @param inputTemperature - * @param poolVariable - * @param vectorIndex - * @param parameters - * @param datapoolId - * @param outputSet - * @param thermalModule + * Forward declaration for explicit instantiation of used parameters. */ - TemperatureSensor(object_id_t setObjectid, - T *inputTemperature, PoolVariableIF *poolVariable, - uint8_t vectorIndex, Parameters parameters, uint32_t datapoolId, - DataSet *outputSet, ThermalModuleIF *thermalModule) : - - AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters), - inputTemperature(inputTemperature), poolVariable(poolVariable), - outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE), - sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, - DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex), - DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit,parameters.upperLimit, - TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH), - oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) { - } - struct UsedParameters { UsedParameters(Parameters parameters) : a(parameters.a), b(parameters.b), c(parameters.c), - gradient(parameters.gradient) {} + gradient(parameters.maxGradient) {} float a; float b; float c; float gradient; }; - static const uint16_t ADDRESS_A = 0; - static const uint16_t ADDRESS_B = 1; - static const uint16_t ADDRESS_C = 2; - static const uint16_t ADDRESS_GRADIENT = 3; + /** + * Constructor to check against raw input values + * @param setObjectid objectId of the sensor object + * @param inputValue Input value which is converted to a temperature + * @param poolVariable Pool Variable to store the temperature value + * @param vectorIndex Vector Index for the sensor monitor + * @param parameters Calculation parameters, temperature limits, gradient limit + * @param datapoolId Datapool ID of the output temperature + * @param outputSet Output dataset for the output temperature to fetch it with read() + * @param thermalModule respective thermal module, if it has one + */ + TemperatureSensor(object_id_t setObjectid, + T *inputValue, T lowerLimit, T upperLimit, PoolVariableIF *poolVariable, + uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0}, + DataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) : + AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters), + inputValue(inputValue), poolVariable(poolVariable), + outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE), + oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) + { + sensorMonitorRaw = new LimitMonitor(setObjectid, DOMAIN_ID_SENSOR, + DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex), + DEFAULT_CONFIRMATION_COUNT, lowerLimit, upperLimit, + TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH); + delete sensorMonitor; + } + + /** + * Constructor do check against °C values + */ + TemperatureSensor(object_id_t setObjectid, + T *inputValue, float lowerLimit, float upperLimit, PoolVariableIF *poolVariable, + uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0}, + DataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) : + AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters), + inputValue(inputValue), poolVariable(poolVariable), + outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE), + oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) + { + sensorMonitor = new LimitMonitor(setObjectid, DOMAIN_ID_SENSOR, + DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex), + DEFAULT_CONFIRMATION_COUNT, lowerLimit, upperLimit, + TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH); + delete sensorMonitorRaw; + } + +protected: + /** + * This formula is used to calculate the temperature from an input value + * with an arbitrary type. + * A default implementation is provided but can be replaced depending + * on the required calculation. + * @param inputTemperature + * @return + */ + virtual float calculateOutputTemperature(T inputValue) { + return parameters.a * inputValue * inputValue + + parameters.b * inputValue + parameters.c; + } - static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1; //!< Changed due to issue with later temperature checking even tough the sensor monitor was confirming already (Was 10 before with comment = Correlates to a 10s confirmation time. Chosen rather large, should not be so bad for components and helps survive glitches.) - static const uint8_t DOMAIN_ID_SENSOR = 1; private: void setInvalid() { outputTemperature = INVALID_TEMPERATURE; outputTemperature.setValid(false); uptimeOfOldTemperature.tv_sec = INVALID_UPTIME; - sensorMonitor.setToInvalid(); + sensorMonitor->setToInvalid(); } protected: static const int32_t INVALID_UPTIME = 0; UsedParameters parameters; - T *inputTemperature; + T * inputValue; PoolVariableIF *poolVariable; PoolVariable outputTemperature; - LimitMonitor sensorMonitor; + LimitMonitor * sensorMonitorRaw; + LimitMonitor * sensorMonitor; float oldTemperature; timeval uptimeOfOldTemperature; - virtual float calculateOutputTemperature(T inputTemperature) { - return parameters.a * inputTemperature * inputTemperature - + parameters.b * inputTemperature + parameters.c; - } - void doChildOperation() { if (!poolVariable->isValid() || !healthHelper.healthTable->isHealthy(getObjectId())) { @@ -107,7 +144,7 @@ protected: return; } - outputTemperature = calculateOutputTemperature(*inputTemperature); + outputTemperature = calculateOutputTemperature(*inputValue); outputTemperature.setValid(PoolVariableIF::VALID); timeval uptime; @@ -115,7 +152,7 @@ protected: if (uptimeOfOldTemperature.tv_sec != INVALID_UPTIME) { //In theory, we could use an AbsValueMonitor to monitor the gradient. - //But this would require storing the gradient in DP and quite some overhead. + //But this would require storing the maxGradient in DP and quite some overhead. //The concept of delta limits is a bit strange anyway. float deltaTime; float deltaTemp; @@ -133,10 +170,10 @@ protected: } } - //Check is done against raw limits. SHOULDDO: Why? Using °C would be more easy to handle. - sensorMonitor.doCheck(*inputTemperature); + //Check is done against raw limits. SHOULDDO: Why? Using °C would be more easy to handle. + sensorMonitor->doCheck(outputTemperature.value); - if (sensorMonitor.isOutOfLimits()) { + if (sensorMonitor->isOutOfLimits()) { uptimeOfOldTemperature.tv_sec = INVALID_UPTIME; outputTemperature.setValid(PoolVariableIF::INVALID); outputTemperature = INVALID_TEMPERATURE; @@ -155,10 +192,19 @@ public: return outputTemperature.isValid(); } + static const uint16_t ADDRESS_A = 0; + static const uint16_t ADDRESS_B = 1; + static const uint16_t ADDRESS_C = 2; + static const uint16_t ADDRESS_GRADIENT = 3; + + static const uint16_t DEFAULT_CONFIRMATION_COUNT = 1; //!< Changed due to issue with later temperature checking even tough the sensor monitor was confirming already (Was 10 before with comment = Correlates to a 10s confirmation time. Chosen rather large, should not be so bad for components and helps survive glitches.) + + static const uint8_t DOMAIN_ID_SENSOR = 1; + virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex) { - ReturnValue_t result = sensorMonitor.getParameter(domainId, parameterId, + ReturnValue_t result = sensorMonitor->getParameter(domainId, parameterId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; @@ -186,7 +232,7 @@ public: } virtual void resetOldState() { - sensorMonitor.setToUnchecked(); + sensorMonitor->setToUnchecked(); } }; From 99b90e625d916dafe30cda283c7d75ec772376a8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 16 Feb 2020 16:14:29 +0100 Subject: [PATCH 0102/1774] refactored: limit type specified separately --- thermal/TemperatureSensor.h | 60 +++++++++++++------------------------ 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/thermal/TemperatureSensor.h b/thermal/TemperatureSensor.h index ca0dbce61..00f77b242 100644 --- a/thermal/TemperatureSensor.h +++ b/thermal/TemperatureSensor.h @@ -13,11 +13,12 @@ * The temperature is calculated from an input value with * the calculateOutputTemperature() function. Range checking and * limit monitoring is performed automatically. - * + * The inputType specifies the type of the raw input while the + * limitType specifies the type of the upper and lower limit to check against. * @ingroup thermal */ -template +template class TemperatureSensor: public AbstractTemperatureSensor { public: /** @@ -29,13 +30,15 @@ public: * * The parameters a,b and c are used in the calculateOutputTemperature() call. * - * The lower and upper limits can be specified in °C or in the input value - * format + * The lower and upper limits can be specified in any type, for example float for C° values + * or any other type for raw values. */ struct Parameters { float a; float b; float c; + limitType lowerLimit; + limitType upperLimit; float maxGradient; }; @@ -64,39 +67,19 @@ public: * @param thermalModule respective thermal module, if it has one */ TemperatureSensor(object_id_t setObjectid, - T *inputValue, T lowerLimit, T upperLimit, PoolVariableIF *poolVariable, - uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0}, + inputType *inputValue, PoolVariableIF *poolVariable, + uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0, 0, 0}, DataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) : AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters), inputValue(inputValue), poolVariable(poolVariable), outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE), - oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) - { - sensorMonitorRaw = new LimitMonitor(setObjectid, DOMAIN_ID_SENSOR, + sensorMonitor(setObjectid, DOMAIN_ID_SENSOR, DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex), - DEFAULT_CONFIRMATION_COUNT, lowerLimit, upperLimit, - TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH); - delete sensorMonitor; + DEFAULT_CONFIRMATION_COUNT, parameters.lowerLimit, parameters.upperLimit, + TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH), + oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) { } - /** - * Constructor do check against °C values - */ - TemperatureSensor(object_id_t setObjectid, - T *inputValue, float lowerLimit, float upperLimit, PoolVariableIF *poolVariable, - uint8_t vectorIndex, uint32_t datapoolId, Parameters parameters = {0, 0, 0, 0}, - DataSet *outputSet = NULL, ThermalModuleIF *thermalModule = NULL) : - AbstractTemperatureSensor(setObjectid, thermalModule), parameters(parameters), - inputValue(inputValue), poolVariable(poolVariable), - outputTemperature(datapoolId, outputSet, PoolVariableIF::VAR_WRITE), - oldTemperature(20), uptimeOfOldTemperature( { INVALID_TEMPERATURE, 0 }) - { - sensorMonitor = new LimitMonitor(setObjectid, DOMAIN_ID_SENSOR, - DataPool::poolIdAndPositionToPid(poolVariable->getDataPoolId(), vectorIndex), - DEFAULT_CONFIRMATION_COUNT, lowerLimit, upperLimit, - TEMP_SENSOR_LOW, TEMP_SENSOR_HIGH); - delete sensorMonitorRaw; - } protected: /** @@ -107,7 +90,7 @@ protected: * @param inputTemperature * @return */ - virtual float calculateOutputTemperature(T inputValue) { + virtual float calculateOutputTemperature(inputType inputValue) { return parameters.a * inputValue * inputValue + parameters.b * inputValue + parameters.c; } @@ -118,21 +101,20 @@ private: outputTemperature = INVALID_TEMPERATURE; outputTemperature.setValid(false); uptimeOfOldTemperature.tv_sec = INVALID_UPTIME; - sensorMonitor->setToInvalid(); + sensorMonitor.setToInvalid(); } protected: static const int32_t INVALID_UPTIME = 0; UsedParameters parameters; - T * inputValue; + inputType * inputValue; PoolVariableIF *poolVariable; PoolVariable outputTemperature; - LimitMonitor * sensorMonitorRaw; - LimitMonitor * sensorMonitor; + LimitMonitor sensorMonitor; float oldTemperature; timeval uptimeOfOldTemperature; @@ -171,9 +153,9 @@ protected: } //Check is done against raw limits. SHOULDDO: Why? Using °C would be more easy to handle. - sensorMonitor->doCheck(outputTemperature.value); + sensorMonitor.doCheck(outputTemperature.value); - if (sensorMonitor->isOutOfLimits()) { + if (sensorMonitor.isOutOfLimits()) { uptimeOfOldTemperature.tv_sec = INVALID_UPTIME; outputTemperature.setValid(PoolVariableIF::INVALID); outputTemperature = INVALID_TEMPERATURE; @@ -204,7 +186,7 @@ public: virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, const ParameterWrapper *newValues, uint16_t startAtIndex) { - ReturnValue_t result = sensorMonitor->getParameter(domainId, parameterId, + ReturnValue_t result = sensorMonitor.getParameter(domainId, parameterId, parameterWrapper, newValues, startAtIndex); if (result != INVALID_DOMAIN_ID) { return result; @@ -232,7 +214,7 @@ public: } virtual void resetOldState() { - sensorMonitor->setToUnchecked(); + sensorMonitor.setToUnchecked(); } }; From 1001c1d48bc7aff5a88bcd58028e6f6d58777265 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 16 Feb 2020 17:21:06 +0100 Subject: [PATCH 0103/1774] added new IF for thermal messages --- thermal/AcceptsThermalMessagesIF.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 thermal/AcceptsThermalMessagesIF.h diff --git a/thermal/AcceptsThermalMessagesIF.h b/thermal/AcceptsThermalMessagesIF.h new file mode 100644 index 000000000..e95faaaf2 --- /dev/null +++ b/thermal/AcceptsThermalMessagesIF.h @@ -0,0 +1,18 @@ +/** + * \file AcceptsThermalMessagesIF.h + * + * \date 16.02.2020 + */ + +#ifndef FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_ +#define FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_ +#include + +class AcceptsThermalMessagesIF { +public: + virtual ~AcceptsThermalMessagesIF(); + + virtual MessageQueueId_t getReceptionQueue() const = 0; +}; + +#endif /* FRAMEWORK_THERMAL_ACCEPTSTHERMALMESSAGESIF_H_ */ From 6ab07aeb1978d7a630944a698abebca1097b1d71 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 16 Feb 2020 21:04:17 +0100 Subject: [PATCH 0104/1774] valid mask bugfixes --- datapool/PoolRawAccessHelper.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index 646ffbb1a..07ea44651 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -6,6 +6,9 @@ */ #include + +#include + #include PoolRawAccessHelper::PoolRawAccessHelper(uint32_t * poolIdBuffer_, @@ -41,7 +44,7 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, ReturnValue_t result; SerializationArgs argStruct = {buffer, size, max_size, bigEndian}; int32_t remainingParametersSize = numberOfParameters * 4; - uint8_t validityMaskSize = numberOfParameters/8; + uint8_t validityMaskSize = ceil((float)numberOfParameters/8.0); uint8_t validityMask[validityMaskSize]; memset(validityMask,0, validityMaskSize); for(uint8_t count = 0; count < numberOfParameters; count++) { @@ -55,7 +58,8 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, debug << "Pool Raw Access: Remaining parameters size not 0 !" << std::endl; result = RETURN_FAILED; } - memcpy(*buffer + *size, validityMask, validityMaskSize); + + memcpy(*argStruct.buffer, validityMask, validityMaskSize); *size += validityMaskSize; validBufferIndex = 1; validBufferIndexBit = 0; @@ -114,6 +118,7 @@ ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization(uint32_t current if(currentPoolRawAccess.isValid()) { handleMaskModification(validityMask); } + validBufferIndexBit ++; } result = currentDataSet.serialize(argStruct.buffer, argStruct.size, @@ -146,7 +151,6 @@ ReturnValue_t PoolRawAccessHelper::checkRemainingSize(PoolRawAccess * currentPoo void PoolRawAccessHelper::handleMaskModification(uint8_t * validityMask) { validityMask[validBufferIndex] = bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true); - validBufferIndexBit ++; if(validBufferIndexBit == 8) { validBufferIndex ++; validBufferIndexBit = 1; @@ -159,6 +163,6 @@ uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position, bool valu return byte; } uint8_t shiftNumber = position + (6 - 2 * (position - 1)); - byte = (byte | value) << shiftNumber; + byte |= 1UL << shiftNumber; return byte; } From 54eeb71f02d1c4c4e49f25e25ed0821a7325b093 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 17 Feb 2020 21:20:51 +0100 Subject: [PATCH 0105/1774] bugfix: added implementation --- thermal/AcceptsThermalMessagesIF.h | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/thermal/AcceptsThermalMessagesIF.h b/thermal/AcceptsThermalMessagesIF.h index e95faaaf2..28c62af6a 100644 --- a/thermal/AcceptsThermalMessagesIF.h +++ b/thermal/AcceptsThermalMessagesIF.h @@ -10,7 +10,11 @@ class AcceptsThermalMessagesIF { public: - virtual ~AcceptsThermalMessagesIF(); + + /** + * @brief This is the empty virtual destructor as required for C++ interfaces. + */ + virtual ~AcceptsThermalMessagesIF() { } virtual MessageQueueId_t getReceptionQueue() const = 0; }; From 7a426acece7e6fb6135f48b62f1431c894c8e711 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 21 Feb 2020 16:08:43 +0100 Subject: [PATCH 0106/1774] therm sensor doc correction --- thermal/TemperatureSensor.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/thermal/TemperatureSensor.h b/thermal/TemperatureSensor.h index 00f77b242..b4172670e 100644 --- a/thermal/TemperatureSensor.h +++ b/thermal/TemperatureSensor.h @@ -25,8 +25,7 @@ public: * This structure contains parameters required for range checking * and the conversion from the input value to the output temperature. * a, b and c can be any parameters required to calculate the output - * temperature from the input value, for example parameters for the - * Callendar-Van-Dusen equation(see datasheet of used sensor / ADC) + * temperature from the input value, depending on the formula used. * * The parameters a,b and c are used in the calculateOutputTemperature() call. * @@ -56,7 +55,7 @@ public: }; /** - * Constructor to check against raw input values + * Instantiate Temperature Sensor Object. * @param setObjectid objectId of the sensor object * @param inputValue Input value which is converted to a temperature * @param poolVariable Pool Variable to store the temperature value From bfc7a768ce73b1db2a535d7919f24cc1b3244736 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 25 Feb 2020 12:54:28 +0100 Subject: [PATCH 0107/1774] message queue adaptions for calls from ISR functions moved to top binary sempahore file init mutex return values --- ipc/MessageQueueIF.h | 6 +- ipc/MessageQueueSenderIF.h | 4 +- osal/Endiness.h | 4 + osal/FreeRTOS/BinarySemaphore.cpp | 9 +++ osal/FreeRTOS/BinarySempahore.h | 14 ++++ osal/FreeRTOS/MessageQueue.cpp | 90 +++++++++++++++-------- osal/FreeRTOS/MessageQueue.h | 90 +++++++++++++++++------ osal/FreeRTOS/Mutex.cpp | 13 ++-- osal/FreeRTOS/Mutex.h | 6 +- serviceinterface/ServiceInterfaceBuffer.h | 2 +- 10 files changed, 171 insertions(+), 67 deletions(-) create mode 100644 osal/FreeRTOS/BinarySemaphore.cpp create mode 100644 osal/FreeRTOS/BinarySempahore.h diff --git a/ipc/MessageQueueIF.h b/ipc/MessageQueueIF.h index 18e2d99ab..ee2479bfd 100644 --- a/ipc/MessageQueueIF.h +++ b/ipc/MessageQueueIF.h @@ -3,12 +3,16 @@ // COULDDO: We could support blocking calls +/** + * @defgroup message_queue Message Queue + * @brief Message Queue related software components + */ + #include #include #include class MessageQueueIF { public: - static const MessageQueueId_t NO_QUEUE = MessageQueueSenderIF::NO_QUEUE; //!< Ugly hack. static const uint8_t INTERFACE_ID = CLASS_ID::MESSAGE_QUEUE_IF; diff --git a/ipc/MessageQueueSenderIF.h b/ipc/MessageQueueSenderIF.h index 9e7e11c03..6eb7733d1 100644 --- a/ipc/MessageQueueSenderIF.h +++ b/ipc/MessageQueueSenderIF.h @@ -26,8 +26,8 @@ public: * Must be implemented by a subclass. */ static ReturnValue_t sendMessage(MessageQueueId_t sendTo, - MessageQueueMessage* message, MessageQueueId_t sentFrom = - MessageQueueSenderIF::NO_QUEUE, bool ignoreFault=false); + MessageQueueMessage* message, MessageQueueId_t sentFrom = MessageQueueSenderIF::NO_QUEUE, + bool ignoreFault=false); private: MessageQueueSenderIF() {} }; diff --git a/osal/Endiness.h b/osal/Endiness.h index 65cc0a10f..55d0aeb33 100644 --- a/osal/Endiness.h +++ b/osal/Endiness.h @@ -1,6 +1,10 @@ #ifndef FRAMEWORK_OSAL_ENDINESS_H_ #define FRAMEWORK_OSAL_ENDINESS_H_ +/** + * @defgroup osal Operating System Abstraction Layer + * @brief Provides clean interfaces to use OS functionalities + */ /* * BSD-style endian declaration diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp new file mode 100644 index 000000000..0422f105e --- /dev/null +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -0,0 +1,9 @@ +/** + * @file BinarySemaphore.cpp + * + * @date 25.02.2020 + */ + + + + diff --git a/osal/FreeRTOS/BinarySempahore.h b/osal/FreeRTOS/BinarySempahore.h new file mode 100644 index 000000000..ab32d7b76 --- /dev/null +++ b/osal/FreeRTOS/BinarySempahore.h @@ -0,0 +1,14 @@ +/** + * @file BinarySempahore.h + * + * @date 25.02.2020 + */ + +#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ +#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ + + + + + +#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */ diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 887df3926..883cf2614 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -1,11 +1,13 @@ #include "MessageQueue.h" +#include "task.h" #include // TODO I guess we should have a way of checking if we are in an ISR and then use the "fromISR" versions of all calls - +// As a first step towards this, introduces system context variable which needs to be switched manually +// Haven't found function to find system context. MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) : -defaultDestination(0),lastPartner(0) { +defaultDestination(0),lastPartner(0), callContext(SystemContext::task_context) { handle = xQueueCreate(message_depth, max_message_size); if (handle == NULL) { error << "MessageQueue creation failed" << std::endl; @@ -18,6 +20,10 @@ MessageQueue::~MessageQueue() { } } +void MessageQueue::switchSystemContext(SystemContext callContext) { + this->callContext = callContext; +} + ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, MessageQueueMessage* message, bool ignoreFault) { return sendMessageFrom(sendTo, message, this->getId(), ignoreFault); @@ -27,6 +33,11 @@ ReturnValue_t MessageQueue::sendToDefault(MessageQueueMessage* message) { return sendToDefaultFrom(message, this->getId()); } +ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessage* message, + MessageQueueId_t sentFrom, bool ignoreFault) { + return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault); +} + ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) { if (this->lastPartner != 0) { return sendMessageFrom(this->lastPartner, message, this->getId()); @@ -35,6 +46,52 @@ ReturnValue_t MessageQueue::reply(MessageQueueMessage* message) { } } +ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, + MessageQueueMessage* message, MessageQueueId_t sentFrom, + bool ignoreFault) { + return sendMessageFromMessageQueue(sendTo,message,sentFrom,ignoreFault, callContext); +} + +ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, + MessageQueueMessage *message, MessageQueueId_t sentFrom, + bool ignoreFault, SystemContext callContext) { + message->setSender(sentFrom); + BaseType_t result; + if(callContext == SystemContext::task_context) { + result = xQueueSendToBack(reinterpret_cast(sendTo), + reinterpret_cast(message->getBuffer()), 0); + } + else { + BaseType_t xHigherPriorityTaskWoken = pdFALSE; + result = xQueueSendFromISR(reinterpret_cast(sendTo), + reinterpret_cast(message->getBuffer()), &xHigherPriorityTaskWoken); + if(xHigherPriorityTaskWoken == pdTRUE) { + requestContextSwitch(callContext); + } + } + return handleSendResult(result, ignoreFault); +} + +void MessageQueue::requestContextSwitch(SystemContext callContext) { + if(callContext == SystemContext::isr_context) { + portYIELD_FROM_ISR(); + } +} + +ReturnValue_t MessageQueue::handleSendResult(BaseType_t result, bool ignoreFault) { + if (result != pdPASS) { + if (!ignoreFault) { + InternalErrorReporterIF* internalErrorReporter = objectManager->get( + objects::INTERNAL_ERROR_REPORTER); + if (internalErrorReporter != NULL) { + internalErrorReporter->queueMessageNotSent(); + } + } + return MessageQueueIF::FULL; + } + return HasReturnvaluesIF::RETURN_OK; +} + ReturnValue_t MessageQueue::receiveMessage(MessageQueueMessage* message, MessageQueueId_t* receivedFrom) { ReturnValue_t status = this->receiveMessage(message); @@ -73,17 +130,6 @@ void MessageQueue::setDefaultDestination(MessageQueueId_t defaultDestination) { this->defaultDestination = defaultDestination; } -ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, - MessageQueueMessage* message, MessageQueueId_t sentFrom, - bool ignoreFault) { - return sendMessageFromMessageQueue(sendTo,message,sentFrom,ignoreFault); -} - -ReturnValue_t MessageQueue::sendToDefaultFrom(MessageQueueMessage* message, - MessageQueueId_t sentFrom, bool ignoreFault) { - return sendMessageFrom(defaultDestination,message,sentFrom,ignoreFault); -} - MessageQueueId_t MessageQueue::getDefaultDestination() const { return defaultDestination; } @@ -92,23 +138,5 @@ bool MessageQueue::isDefaultDestinationSet() const { return 0; } -ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, - MessageQueueMessage *message, MessageQueueId_t sentFrom, - bool ignoreFault) { - message->setSender(sentFrom); - BaseType_t result = xQueueSendToBack(reinterpret_cast(sendTo),reinterpret_cast(message->getBuffer()), 0); - if (result != pdPASS) { - if (!ignoreFault) { - InternalErrorReporterIF* internalErrorReporter = objectManager->get( - objects::INTERNAL_ERROR_REPORTER); - if (internalErrorReporter != NULL) { - internalErrorReporter->queueMessageNotSent(); - } - } - return MessageQueueIF::FULL; - } - return HasReturnvaluesIF::RETURN_OK; - -} diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index 32f41b44d..9e2d7790e 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -6,7 +6,8 @@ #include #include -#include +#include "queue.h" +#include "portmacro.h" //TODO this class assumes that MessageQueueId_t is the same size as void* (the FreeRTOS handle type), compiler will catch this but it might be nice to have something checking or even an always working solution // https://scaryreasoner.wordpress.com/2009/02/28/checking-sizeof-at-compile-time/ @@ -21,11 +22,17 @@ * methods to send a message to a user-defined or a default destination. In addition * it also provides a reply method to answer to the queue it received its last message * from. + * * The MessageQueue should be used as "post box" for a single owning object. So all * message queue communication is "n-to-one". * For creating the queue, as well as sending and receiving messages, the class makes * use of the operating system calls provided. - * \ingroup message_queue + * + * Please keep in mind that FreeRTOS offers + * different calls for message queue operations if called from an ISR. + * For now, the system context needs to be switched manually. + * @ingroup osal + * @ingroup message_queue */ class MessageQueue : public MessageQueueIF { friend class MessageQueueSenderIF; @@ -43,11 +50,30 @@ public: * This should be left default. */ MessageQueue( size_t message_depth = 3, size_t max_message_size = MessageQueueMessage::MAX_MESSAGE_SIZE ); + /** * @brief The destructor deletes the formerly created message queue. * @details This is accomplished by using the delete call provided by the operating system. */ virtual ~MessageQueue(); + + /*! + * Used by calling function to tell the callbacks if they are being called from + * within an ISR or from a regular task. This is required because FreeRTOS + * has different functions for handling semaphores from within an ISR and task. + */ + typedef enum _SystemContext { + task_context = 0x00,//!< task_context + isr_context = 0xFF //!< isr_context + } SystemContext; + + /** + * This function is used to specify whether a message queue operation is called + * from within an ISR or a task. FreeRTOS offers different functions for this task. + * @param callContext + */ + void switchSystemContext(SystemContext callContext); + /** * @brief This operation sends a message to the given destination. * @details It directly uses the sendMessage call of the MessageQueueSender parent, but passes its @@ -74,6 +100,29 @@ public: */ ReturnValue_t reply( MessageQueueMessage* message ); + /** + * \brief With the sendMessage call, a queue message is sent to a receiving queue. + * \details This method takes the message provided, adds the sentFrom information and passes + * it on to the destination provided with an operating system call. The OS's return + * value is returned. + * \param sendTo This parameter specifies the message queue id to send the message to. + * \param message This is a pointer to a previously created message, which is sent. + * \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. + * This variable is set to zero by default. + * \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. + */ + virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessage* message, + MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ); + + /** + * \brief The sendToDefault method sends a queue message to the default destination. + * \details In all other aspects, it works identical to the sendMessage method. + * \param message This is a pointer to a previously created message, which is sent. + * \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. + * This variable is set to zero by default. + */ + virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ); + /** * @brief This function reads available messages from the message queue and returns the sender. * @details It works identically to the other receiveMessage call, but in addition returns the @@ -107,26 +156,7 @@ public: * @brief This method returns the message queue id of this class's message queue. */ MessageQueueId_t getId() const; - /** - * \brief With the sendMessage call, a queue message is sent to a receiving queue. - * \details This method takes the message provided, adds the sentFrom information and passes - * it on to the destination provided with an operating system call. The OS's return - * value is returned. - * \param sendTo This parameter specifies the message queue id to send the message to. - * \param message This is a pointer to a previously created message, which is sent. - * \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. - * This variable is set to zero by default. - * \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. - */ - virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ); - /** - * \brief The sendToDefault method sends a queue message to the default destination. - * \details In all other aspects, it works identical to the sendMessage method. - * \param message This is a pointer to a previously created message, which is sent. - * \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. - * This variable is set to zero by default. - */ - virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, bool ignoreFault = false ); + /** * \brief This method is a simple setter for the default destination. */ @@ -148,12 +178,26 @@ protected: * \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. * This variable is set to zero by default. * \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. + * \param context */ - static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo,MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE,bool ignoreFault=false); + static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, + MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, + bool ignoreFault=false, SystemContext callContex = SystemContext::task_context); + + static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); + + /** + * In this function, a function dependant on the portmacro.h header function calls + * to request a context switch can be specified. + * This can be used if sending to the queue from an ISR caused a task to unblock + * and a context switch is required. + */ + static void requestContextSwitch(SystemContext callContext); private: QueueHandle_t handle; MessageQueueId_t defaultDestination; MessageQueueId_t lastPartner; + SystemContext callContext; //!< Stores the current system context }; #endif /* MESSAGEQUEUE_H_ */ diff --git a/osal/FreeRTOS/Mutex.cpp b/osal/FreeRTOS/Mutex.cpp index 7c5110915..456506ea4 100644 --- a/osal/FreeRTOS/Mutex.cpp +++ b/osal/FreeRTOS/Mutex.cpp @@ -6,7 +6,9 @@ const uint32_t MutexIF::NO_TIMEOUT = 0; Mutex::Mutex() { handle = xSemaphoreCreateMutex(); - //TODO print error + if(handle == NULL) { + error << "Mutex creation failure" << std::endl; + } } Mutex::~Mutex() { @@ -18,8 +20,7 @@ Mutex::~Mutex() { ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { if (handle == 0) { - //TODO Does not exist - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::MUTEX_NOT_FOUND; } TickType_t timeout = portMAX_DELAY; if (timeoutMs != NO_TIMEOUT) { @@ -30,8 +31,7 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { if (returncode == pdPASS) { return HasReturnvaluesIF::RETURN_OK; } else { - //TODO could not be acquired/timeout - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::MUTEX_TIMEOUT; } } @@ -44,7 +44,6 @@ ReturnValue_t Mutex::unlockMutex() { if (returncode == pdPASS) { return HasReturnvaluesIF::RETURN_OK; } else { - //TODO is not owner - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::CURR_THREAD_DOES_NOT_OWN_MUTEX; } } diff --git a/osal/FreeRTOS/Mutex.h b/osal/FreeRTOS/Mutex.h index 91f295853..471b1113e 100644 --- a/osal/FreeRTOS/Mutex.h +++ b/osal/FreeRTOS/Mutex.h @@ -7,8 +7,10 @@ #include #include "semphr.h" - - +/** + * + * @ingroup osal + */ class Mutex : public MutexIF { public: Mutex(); diff --git a/serviceinterface/ServiceInterfaceBuffer.h b/serviceinterface/ServiceInterfaceBuffer.h index 9a5f4ef8e..b42c8a197 100644 --- a/serviceinterface/ServiceInterfaceBuffer.h +++ b/serviceinterface/ServiceInterfaceBuffer.h @@ -30,7 +30,7 @@ private: typedef std::char_traits Traits; // Work in buffer mode. It is also possible to work without buffer. - static size_t const BUF_SIZE = 255; + static size_t const BUF_SIZE = 128; char buf[BUF_SIZE]; // In this function, the characters are parsed. From 083cc7c50ac017a12061e66d6d937a82b2908c92 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 25 Feb 2020 17:04:21 +0100 Subject: [PATCH 0108/1774] sempahore wrapper extended --- ipc/MutexIF.h | 7 +++ osal/FreeRTOS/BinarySemaphore.cpp | 86 ++++++++++++++++++++++++++++ osal/FreeRTOS/BinarySemaphore.h | 94 +++++++++++++++++++++++++++++++ osal/FreeRTOS/BinarySempahore.h | 14 ----- osal/FreeRTOS/MessageQueue.cpp | 13 +++-- osal/FreeRTOS/MessageQueue.h | 1 + osal/FreeRTOS/Mutex.cpp | 3 +- osal/FreeRTOS/Mutex.h | 10 +++- returnvalues/FwClassIds.h | 1 + 9 files changed, 204 insertions(+), 25 deletions(-) create mode 100644 osal/FreeRTOS/BinarySemaphore.h delete mode 100644 osal/FreeRTOS/BinarySempahore.h diff --git a/ipc/MutexIF.h b/ipc/MutexIF.h index 35786d6a3..a4aff1cd8 100644 --- a/ipc/MutexIF.h +++ b/ipc/MutexIF.h @@ -3,6 +3,13 @@ #include +/** + * @brief Common interface for OS Mutex objects which provide MUTual EXclusion. + * + * @details https://en.wikipedia.org/wiki/Lock_(computer_science) + * @ingroup osal + * @ingroup interface + */ class MutexIF { public: static const uint32_t NO_TIMEOUT; //!< Needs to be defined in implementation. diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 0422f105e..dd73c5b0f 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -3,7 +3,93 @@ * * @date 25.02.2020 */ +#include +#include +#include "portmacro.h" +#include "task.h" +BinarySemaphore::BinarySemaphore() { + vSemaphoreCreateBinary(handle); + if(handle == NULL) { + error << "Binary semaphore creation failure" << std::endl; + } +} +BinarySemaphore::~BinarySemaphore() { + vSemaphoreDelete(handle); +} +ReturnValue_t BinarySemaphore::takeBinarySemaphore(uint32_t timeoutMs) { + if(handle == NULL) { + return HasReturnvaluesIF::RETURN_FAILED; + } + TickType_t timeout = portMAX_DELAY; + if(timeoutMs != 0) { + timeout = pdMS_TO_TICKS(timeoutMs); + } + BaseType_t returncode = xSemaphoreTake(handle, timeout); + if (returncode == pdPASS) { + return HasReturnvaluesIF::RETURN_OK; + } else { + return SEMAPHORE_NOT_FOUND; + } +} + +ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks) { + if(handle == NULL) { + return SEMAPHORE_NOT_FOUND; + } + + BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks); + if (returncode == pdPASS) { + return HasReturnvaluesIF::RETURN_OK; + } else { + return SEMAPHORE_TIMEOUT; + } +} + +ReturnValue_t BinarySemaphore::giveBinarySemaphore() { + if (handle == NULL) { + return HasReturnvaluesIF::RETURN_FAILED; + } + BaseType_t returncode = xSemaphoreGive(handle); + if (returncode == pdPASS) { + return HasReturnvaluesIF::RETURN_OK; + } else { + return SEMAPHORE_NOT_OWNED; + } +} + +SemaphoreHandle_t BinarySemaphore::getSemaphore() { + return handle; +} + +ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore) { + if (semaphore == NULL) { + return HasReturnvaluesIF::RETURN_FAILED; + } + BaseType_t returncode = xSemaphoreGive(semaphore); + if (returncode == pdPASS) { + return HasReturnvaluesIF::RETURN_OK; + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } +} + +ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, + BaseType_t * higherPriorityTaskWoken) { + if (semaphore == NULL) { + return HasReturnvaluesIF::RETURN_FAILED; + } + BaseType_t returncode = xSemaphoreGiveFromISR(semaphore, higherPriorityTaskWoken); + if (returncode == pdPASS) { + if(*higherPriorityTaskWoken == pdPASS) { + // Request context switch + portYIELD_FROM_ISR(); + } + return HasReturnvaluesIF::RETURN_OK; + } else { + return HasReturnvaluesIF::RETURN_FAILED; + } +} diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h new file mode 100644 index 000000000..afc01adfe --- /dev/null +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -0,0 +1,94 @@ +/** + * @file BinarySempahore.h + * + * @date 25.02.2020 + */ +#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ +#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ + +#include +#include +#include "semphr.h" + +/** + * @brief OS Tool to achieve synchronization of between tasks or between task and ISR + * @details + * Documentation: https://www.freertos.org/Embedded-RTOS-Binary-Semaphores.html + * @ingroup osal + */ +class BinarySemaphore: public HasReturnvaluesIF { +public: + static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF; + + /** Semaphore object not found */ + static const ReturnValue_t SEMAPHORE_NOT_FOUND = MAKE_RETURN_CODE(1); + /** Semaphore timeout */ + static const ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(2); + /** The current semaphore can not be given, because it is not owned */ + static const ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(3); + + /** + * Create a binary semaphore + */ + BinarySemaphore(); + + /** + * Delete the binary semaphore to prevent a memory leak + */ + ~BinarySemaphore(); + + /** + * Take the binary semaphore. + * If the semaphore has already been taken, the task will be blocked for a maximum + * of #timeoutMs or until the semaphore is given back, + * for example by an ISR or another task. + * @param timeoutMs + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ + ReturnValue_t takeBinarySemaphore(uint32_t timeoutMs); + + /** + * Same as lockBinarySemaphore() with timeout in FreeRTOS ticks. + * @param timeoutTicks + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ + ReturnValue_t takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks); + + /** + * Give back the binary semaphore + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ + ReturnValue_t giveBinarySemaphore(); + + /** + * Get Handle to the semaphore. + * @return + */ + SemaphoreHandle_t getSemaphore(); +private: + SemaphoreHandle_t handle; +}; + +/** + * Wrapper function to give back semaphore from handle + * @param semaphore + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ +ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore); + +/** + * Wrapper function to give back semaphore from handle when called from an ISR + * @param semaphore + * @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority + * was unblocked + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ +ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, + BaseType_t * higherPriorityTaskWoken); + +#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */ diff --git a/osal/FreeRTOS/BinarySempahore.h b/osal/FreeRTOS/BinarySempahore.h deleted file mode 100644 index ab32d7b76..000000000 --- a/osal/FreeRTOS/BinarySempahore.h +++ /dev/null @@ -1,14 +0,0 @@ -/** - * @file BinarySempahore.h - * - * @date 25.02.2020 - */ - -#ifndef FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ -#define FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ - - - - - -#endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */ diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 883cf2614..fdca80c7c 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -1,5 +1,4 @@ #include "MessageQueue.h" -#include "task.h" #include @@ -24,6 +23,12 @@ void MessageQueue::switchSystemContext(SystemContext callContext) { this->callContext = callContext; } +void MessageQueue::requestContextSwitch(SystemContext callContext) { + if(callContext == SystemContext::isr_context) { + portYIELD_FROM_ISR(); + } +} + ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, MessageQueueMessage* message, bool ignoreFault) { return sendMessageFrom(sendTo, message, this->getId(), ignoreFault); @@ -72,11 +77,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, return handleSendResult(result, ignoreFault); } -void MessageQueue::requestContextSwitch(SystemContext callContext) { - if(callContext == SystemContext::isr_context) { - portYIELD_FROM_ISR(); - } -} + ReturnValue_t MessageQueue::handleSendResult(BaseType_t result, bool ignoreFault) { if (result != pdPASS) { diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index 9e2d7790e..cdb2a7983 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -8,6 +8,7 @@ #include #include "queue.h" #include "portmacro.h" +#include "task.h" //TODO this class assumes that MessageQueueId_t is the same size as void* (the FreeRTOS handle type), compiler will catch this but it might be nice to have something checking or even an always working solution // https://scaryreasoner.wordpress.com/2009/02/28/checking-sizeof-at-compile-time/ diff --git a/osal/FreeRTOS/Mutex.cpp b/osal/FreeRTOS/Mutex.cpp index 456506ea4..616ef7b85 100644 --- a/osal/FreeRTOS/Mutex.cpp +++ b/osal/FreeRTOS/Mutex.cpp @@ -37,8 +37,7 @@ ReturnValue_t Mutex::lockMutex(uint32_t timeoutMs) { ReturnValue_t Mutex::unlockMutex() { if (handle == 0) { - //TODO Does not exist - return HasReturnvaluesIF::RETURN_FAILED; + return MutexIF::MUTEX_NOT_FOUND; } BaseType_t returncode = xSemaphoreGive(handle); if (returncode == pdPASS) { diff --git a/osal/FreeRTOS/Mutex.h b/osal/FreeRTOS/Mutex.h index 471b1113e..2703df4eb 100644 --- a/osal/FreeRTOS/Mutex.h +++ b/osal/FreeRTOS/Mutex.h @@ -1,5 +1,5 @@ -#ifndef OS_RTEMS_MUTEX_H_ -#define OS_RTEMS_MUTEX_H_ +#ifndef FRAMEWORK_FREERTOS_MUTEX_H_ +#define FRAMEWORK_FREERTOS_MUTEX_H_ #include @@ -8,7 +8,11 @@ #include "semphr.h" /** + * @brief OS component to implement MUTual EXclusion * + * @details + * Mutexes are binary semaphores which include a priority inheritance mechanism. + * Documentation: https://www.freertos.org/Real-time-embedded-RTOS-mutexes.html * @ingroup osal */ class Mutex : public MutexIF { @@ -21,4 +25,4 @@ private: SemaphoreHandle_t handle; }; -#endif /* OS_RTEMS_MUTEX_H_ */ +#endif /* FRAMEWORK_FREERTOS_MUTEX_H_ */ diff --git a/returnvalues/FwClassIds.h b/returnvalues/FwClassIds.h index beef04754..120d8b8c9 100644 --- a/returnvalues/FwClassIds.h +++ b/returnvalues/FwClassIds.h @@ -60,6 +60,7 @@ enum { SGP4PROPAGATOR_CLASS, //SGP4 53 MUTEX_IF, //MUX 54 MESSAGE_QUEUE_IF,//MQI 55 + SEMAPHORE_IF, //SPH 56 FW_CLASS_ID_COUNT //is actually count + 1 ! }; From abccd81fdfddb1fc065af32bf6c603c4c3722430 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 26 Feb 2020 16:55:35 +0100 Subject: [PATCH 0109/1774] new file for freeRTOS task management functions --- osal/FreeRTOS/FixedTimeslotTask.cpp | 1 - osal/FreeRTOS/FixedTimeslotTask.h | 1 + osal/FreeRTOS/MessageQueue.cpp | 6 ----- osal/FreeRTOS/MessageQueue.h | 22 +++--------------- osal/FreeRTOS/PeriodicTask.h | 6 ++--- osal/FreeRTOS/TaskManagement.cpp | 24 ++++++++++++++++++++ osal/FreeRTOS/TaskManagement.h | 35 +++++++++++++++++++++++++++++ 7 files changed, 66 insertions(+), 29 deletions(-) create mode 100644 osal/FreeRTOS/TaskManagement.cpp create mode 100644 osal/FreeRTOS/TaskManagement.h diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 413d7596b..a2c2e5c68 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -114,4 +114,3 @@ ReturnValue_t FixedTimeslotTask::sleepFor(uint32_t ms) { vTaskDelay(pdMS_TO_TICKS(ms)); return HasReturnvaluesIF::RETURN_OK; } - diff --git a/osal/FreeRTOS/FixedTimeslotTask.h b/osal/FreeRTOS/FixedTimeslotTask.h index bed130511..1ab8724f6 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.h +++ b/osal/FreeRTOS/FixedTimeslotTask.h @@ -51,6 +51,7 @@ public: ReturnValue_t checkSequence() const; ReturnValue_t sleepFor(uint32_t ms); + protected: bool started; TaskHandle_t handle; diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index fdca80c7c..92c691ea7 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -23,12 +23,6 @@ void MessageQueue::switchSystemContext(SystemContext callContext) { this->callContext = callContext; } -void MessageQueue::requestContextSwitch(SystemContext callContext) { - if(callContext == SystemContext::isr_context) { - portYIELD_FROM_ISR(); - } -} - ReturnValue_t MessageQueue::sendMessage(MessageQueueId_t sendTo, MessageQueueMessage* message, bool ignoreFault) { return sendMessageFrom(sendTo, message, this->getId(), ignoreFault); diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index cdb2a7983..9406fdefe 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -4,11 +4,11 @@ #include #include #include +#include #include #include "queue.h" -#include "portmacro.h" -#include "task.h" + //TODO this class assumes that MessageQueueId_t is the same size as void* (the FreeRTOS handle type), compiler will catch this but it might be nice to have something checking or even an always working solution // https://scaryreasoner.wordpress.com/2009/02/28/checking-sizeof-at-compile-time/ @@ -58,16 +58,6 @@ public: */ virtual ~MessageQueue(); - /*! - * Used by calling function to tell the callbacks if they are being called from - * within an ISR or from a regular task. This is required because FreeRTOS - * has different functions for handling semaphores from within an ISR and task. - */ - typedef enum _SystemContext { - task_context = 0x00,//!< task_context - isr_context = 0xFF //!< isr_context - } SystemContext; - /** * This function is used to specify whether a message queue operation is called * from within an ISR or a task. FreeRTOS offers different functions for this task. @@ -187,13 +177,7 @@ protected: static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); - /** - * In this function, a function dependant on the portmacro.h header function calls - * to request a context switch can be specified. - * This can be used if sending to the queue from an ISR caused a task to unblock - * and a context switch is required. - */ - static void requestContextSwitch(SystemContext callContext); + private: QueueHandle_t handle; MessageQueueId_t defaultDestination; diff --git a/osal/FreeRTOS/PeriodicTask.h b/osal/FreeRTOS/PeriodicTask.h index e7ba8dd26..4cbffd5a2 100644 --- a/osal/FreeRTOS/PeriodicTask.h +++ b/osal/FreeRTOS/PeriodicTask.h @@ -1,5 +1,5 @@ -#ifndef MULTIOBJECTTASK_H_ -#define MULTIOBJECTTASK_H_ +#ifndef PERIODICTASK_H_ +#define PERIODICTASK_H_ #include #include @@ -107,4 +107,4 @@ protected: void taskFunctionality(void); }; -#endif /* MULTIOBJECTTASK_H_ */ +#endif /* PERIODICTASK_H_ */ diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp new file mode 100644 index 000000000..e97817691 --- /dev/null +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -0,0 +1,24 @@ +/** + * @file TaskManagement.cpp + * + * @date 26.02.2020 + * + */ +#include +#include +#include "portmacro.h" +#include "task.h" + +void requestContextSwitchFromTask() { + vTaskDelay(0); +} + +void requestContextSwitch(SystemContext callContext) { + if(callContext == SystemContext::isr_context) { + // This function depends on the partmacro.h definition for the specific device + portYIELD_FROM_ISR(); + } else { + requestContextSwitchFromTask(); + } +} + diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h new file mode 100644 index 000000000..74e2316fc --- /dev/null +++ b/osal/FreeRTOS/TaskManagement.h @@ -0,0 +1,35 @@ +/** + * @file TaskManagement.h + * + * @date 26.02.2020 + */ + +#ifndef FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ +#define FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ + +/*! + * Used by functions to tell if they are being called from + * within an ISR or from a regular task. This is required because FreeRTOS + * has different functions for handling semaphores and messages from within an ISR and task. + */ +typedef enum _SystemContext { + task_context = 0x00,//!< task_context + isr_context = 0xFF //!< isr_context +} SystemContext; + +/** + * In this function, a function dependant on the portmacro.h header function calls + * to request a context switch can be specified. + * This can be used if sending to the queue from an ISR caused a task to unblock + * and a context switch is required. + */ +void requestContextSwitch(SystemContext callContext); + +/** + * If task preemption in FreeRTOS is disabled, a context switch + * can be requested manually by calling this function. + */ +void requestContextSwitch(void); + + +#endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */ From c93ee5c6cdc0098dbcf41ff3fe4c5511534e6c69 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Thu, 27 Feb 2020 19:00:51 +0100 Subject: [PATCH 0110/1774] message queue IF return values --- devicehandlers/DeviceCommunicationIF.h | 16 ++++++++-- ipc/CommandMessage.h | 3 ++ ipc/MessageQueueIF.h | 43 ++++++++++++++++---------- osal/FreeRTOS/MutexFactory.cpp | 3 +- 4 files changed, 43 insertions(+), 22 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 06c228f72..546081ba5 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -36,9 +36,7 @@ public: static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x06); static const ReturnValue_t CANT_CHANGE_REPLY_LEN = MAKE_RETURN_CODE(0x07); - virtual ~DeviceCommunicationIF() { - - } + virtual ~DeviceCommunicationIF() {} virtual ReturnValue_t open(Cookie **cookie, uint32_t address, uint32_t maxReplyLen) = 0; @@ -93,8 +91,20 @@ public: virtual uint32_t getAddress(Cookie *cookie) = 0; + /** + * Can be used by DeviceHandlerBase getParameter() call to set DeviceComIF parameters + * @param cookie + * @param parameter + * @return + */ virtual ReturnValue_t setParameter(Cookie *cookie, uint32_t parameter) = 0; + /** + * Can be used by DeviceHandlerBase getParameter() call to set DeviceComIF parameters + * @param cookie + * @param parameter + * @return + */ virtual uint32_t getParameter(Cookie *cookie) = 0; }; diff --git a/ipc/CommandMessage.h b/ipc/CommandMessage.h index 2d966063a..21c393e59 100644 --- a/ipc/CommandMessage.h +++ b/ipc/CommandMessage.h @@ -17,6 +17,9 @@ #define MAKE_COMMAND_ID( number ) ((MESSAGE_ID << 8) + (number)) typedef ReturnValue_t Command_t; +/** + * @brief Used to pass command messages between tasks + */ class CommandMessage : public MessageQueueMessage { public: static const uint8_t INTERFACE_ID = CLASS_ID::COMMAND_MESSAGE; diff --git a/ipc/MessageQueueIF.h b/ipc/MessageQueueIF.h index ee2479bfd..47da694cd 100644 --- a/ipc/MessageQueueIF.h +++ b/ipc/MessageQueueIF.h @@ -58,6 +58,8 @@ public: * lastPartner attribute. Else, the lastPartner information remains untouched, the * message's content is cleared and the function returns immediately. * @param message A pointer to a message in which the received data is stored. + * @return -@c RETURN_OK on success + * -@c MessageQueueIF::EMPTY if queue is empty */ virtual ReturnValue_t receiveMessage(MessageQueueMessage* message) = 0; /** @@ -76,33 +78,38 @@ public: virtual MessageQueueId_t getId() const = 0; /** - * \brief With the sendMessage call, a queue message is sent to a receiving queue. - * \details This method takes the message provided, adds the sentFrom information and passes + * @brief With the sendMessage call, a queue message is sent to a receiving queue. + * @details This method takes the message provided, adds the sentFrom information and passes * it on to the destination provided with an operating system call. The OS's return * value is returned. - * \param sendTo This parameter specifies the message queue id to send the message to. - * \param message This is a pointer to a previously created message, which is sent. - * \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. + * @param sendTo This parameter specifies the message queue id to send the message to. + * @param message This is a pointer to a previously created message, which is sent. + * @param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. * This variable is set to zero by default. - * \param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full (if implemented). + * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full (if implemented). + * @return -@c RETURN_OK on success + * -@c MessageQueueIF::FULL if queue is full */ virtual ReturnValue_t sendMessageFrom( MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0; + /** - * @brief This operation sends a message to the given destination. - * @details It directly uses the sendMessage call of the MessageQueueSender parent, but passes its - * queue id as "sentFrom" parameter. - * @param sendTo This parameter specifies the message queue id of the destination message queue. - * @param message A pointer to a previously created message, which is sent. - * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. - */ + * @brief This operation sends a message to the given destination. + * @details It directly uses the sendMessage call of the MessageQueueSender parent, but passes its + * queue id as "sentFrom" parameter. + * @param sendTo This parameter specifies the message queue id of the destination message queue. + * @param message A pointer to a previously created message, which is sent. + * @param ignoreFault If set to true, the internal software fault counter is not incremented if queue is full. + */ virtual ReturnValue_t sendMessage( MessageQueueId_t sendTo, MessageQueueMessage* message, bool ignoreFault = false ) = 0; /** - * \brief The sendToDefaultFrom method sends a queue message to the default destination. - * \details In all other aspects, it works identical to the sendMessage method. - * \param message This is a pointer to a previously created message, which is sent. - * \param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. + * @brief The sendToDefaultFrom method sends a queue message to the default destination. + * @details In all other aspects, it works identical to the sendMessage method. + * @param message This is a pointer to a previously created message, which is sent. + * @param sentFrom The sentFrom information can be set to inject the sender's queue id into the message. * This variable is set to zero by default. + * @return -@c RETURN_OK on success + * -@c MessageQueueIF::FULL if queue is full */ virtual ReturnValue_t sendToDefaultFrom( MessageQueueMessage* message, MessageQueueId_t sentFrom, bool ignoreFault = false ) = 0; /** @@ -110,6 +117,8 @@ public: * @details As in the sendMessage method, this function uses the sendToDefault call of the * Implementation class and adds its queue id as "sentFrom" information. * @param message A pointer to a previously created message, which is sent. + * @return -@c RETURN_OK on success + * -@c MessageQueueIF::FULL if queue is full */ virtual ReturnValue_t sendToDefault( MessageQueueMessage* message ) = 0; /** diff --git a/osal/FreeRTOS/MutexFactory.cpp b/osal/FreeRTOS/MutexFactory.cpp index cadb54fbd..b3e3f02c9 100644 --- a/osal/FreeRTOS/MutexFactory.cpp +++ b/osal/FreeRTOS/MutexFactory.cpp @@ -1,6 +1,5 @@ #include - -#include "../FreeRTOS/Mutex.h" +#include //TODO: Different variant than the lazy loading in QueueFactory. What's better and why? -> one is on heap the other on bss/data //MutexFactory* MutexFactory::factoryInstance = new MutexFactory(); From fa38a3760448e28109b6a73bb46e3ee50bb583a8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 28 Feb 2020 22:55:25 +0100 Subject: [PATCH 0111/1774] all context switches calls to TaskManagement.h now --- osal/FreeRTOS/BinarySemaphore.cpp | 8 ++++--- osal/FreeRTOS/BinarySemaphore.h | 38 +++++++++++++++++-------------- osal/FreeRTOS/MessageQueue.cpp | 2 +- osal/FreeRTOS/MessageQueue.h | 5 ---- osal/FreeRTOS/TaskManagement.cpp | 6 +++-- osal/FreeRTOS/TaskManagement.h | 32 ++++++++++++++------------ 6 files changed, 48 insertions(+), 43 deletions(-) diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index dd73c5b0f..09e71f6d5 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -4,6 +4,8 @@ * @date 25.02.2020 */ #include +#include + #include #include "portmacro.h" #include "task.h" @@ -65,7 +67,7 @@ SemaphoreHandle_t BinarySemaphore::getSemaphore() { return handle; } -ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore) { +ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) { if (semaphore == NULL) { return HasReturnvaluesIF::RETURN_FAILED; } @@ -77,7 +79,7 @@ ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore) { } } -ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, +ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) { if (semaphore == NULL) { return HasReturnvaluesIF::RETURN_FAILED; @@ -86,7 +88,7 @@ ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, if (returncode == pdPASS) { if(*higherPriorityTaskWoken == pdPASS) { // Request context switch - portYIELD_FROM_ISR(); + TaskManagement::requestContextSwitch(SystemContext::isr_context); } return HasReturnvaluesIF::RETURN_OK; } else { diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h index afc01adfe..7ead0d2fe 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -68,27 +68,31 @@ public: * @return */ SemaphoreHandle_t getSemaphore(); + + /** + * Wrapper function to give back semaphore from handle + * @param semaphore + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ + static ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore); + + /** + * Wrapper function to give back semaphore from handle when called from an ISR + * @param semaphore + * @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority + * was unblocked + * @return -@c RETURN_OK on success + * -@c RETURN_FAILED on failure + */ + static ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, + BaseType_t * higherPriorityTaskWoken); private: SemaphoreHandle_t handle; }; -/** - * Wrapper function to give back semaphore from handle - * @param semaphore - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure - */ -ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore); -/** - * Wrapper function to give back semaphore from handle when called from an ISR - * @param semaphore - * @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority - * was unblocked - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure - */ -ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, - BaseType_t * higherPriorityTaskWoken); + + #endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */ diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index 92c691ea7..f23d9d9d1 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -65,7 +65,7 @@ ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, result = xQueueSendFromISR(reinterpret_cast(sendTo), reinterpret_cast(message->getBuffer()), &xHigherPriorityTaskWoken); if(xHigherPriorityTaskWoken == pdTRUE) { - requestContextSwitch(callContext); + TaskManagement::requestContextSwitch(callContext); } } return handleSendResult(result, ignoreFault); diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index 9406fdefe..d8e149611 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -58,11 +58,6 @@ public: */ virtual ~MessageQueue(); - /** - * This function is used to specify whether a message queue operation is called - * from within an ISR or a task. FreeRTOS offers different functions for this task. - * @param callContext - */ void switchSystemContext(SystemContext callContext); /** diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp index e97817691..573a7d7d9 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -9,11 +9,11 @@ #include "portmacro.h" #include "task.h" -void requestContextSwitchFromTask() { +void TaskManagement::requestContextSwitchFromTask() { vTaskDelay(0); } -void requestContextSwitch(SystemContext callContext) { +void TaskManagement::requestContextSwitch(SystemContext callContext = SystemContext::task_context) { if(callContext == SystemContext::isr_context) { // This function depends on the partmacro.h definition for the specific device portYIELD_FROM_ISR(); @@ -22,3 +22,5 @@ void requestContextSwitch(SystemContext callContext) { } } + + diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h index 74e2316fc..381e06f9a 100644 --- a/osal/FreeRTOS/TaskManagement.h +++ b/osal/FreeRTOS/TaskManagement.h @@ -12,24 +12,26 @@ * within an ISR or from a regular task. This is required because FreeRTOS * has different functions for handling semaphores and messages from within an ISR and task. */ -typedef enum _SystemContext { +enum SystemContext { task_context = 0x00,//!< task_context isr_context = 0xFF //!< isr_context -} SystemContext; +}; -/** - * In this function, a function dependant on the portmacro.h header function calls - * to request a context switch can be specified. - * This can be used if sending to the queue from an ISR caused a task to unblock - * and a context switch is required. - */ -void requestContextSwitch(SystemContext callContext); - -/** - * If task preemption in FreeRTOS is disabled, a context switch - * can be requested manually by calling this function. - */ -void requestContextSwitch(void); +class TaskManagement { +public: + /** + * In this function, a function dependant on the portmacro.h header function calls + * to request a context switch can be specified. + * This can be used if sending to the queue from an ISR caused a task to unblock + * and a context switch is required. + */ + static void requestContextSwitch(SystemContext callContext); + /** + * If task preemption in FreeRTOS is disabled, a context switch + * can be requested manually by calling this function. + */ + static void requestContextSwitchFromTask(void); +}; #endif /* FRAMEWORK_OSAL_FREERTOS_TASKMANAGEMENT_H_ */ From 6d6c78b255407dc08979dbfbf927b9e4dd54db44 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sat, 29 Feb 2020 01:21:36 +0100 Subject: [PATCH 0112/1774] task management doc --- osal/FreeRTOS/TaskManagement.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp index e97817691..f94c0fde6 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -9,6 +9,12 @@ #include "portmacro.h" #include "task.h" +/** + * TODO: This stuff is hardware and architecture and mission dependant... + * Some FreeRTOS implementations might be able to determine their own task context for example. + * If not ISRs are used, or task preemption is enabled, some of this stuff might + * not be necessary anyway. Maybe there is a better solution? + */ void requestContextSwitchFromTask() { vTaskDelay(0); } From d0e8eb386ce45b3aa99f8d1413b2c05b1db079d7 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 2 Mar 2020 01:00:17 +0100 Subject: [PATCH 0113/1774] renamed system context to call context to avoid conflicts with ISIS library, I don't want to fiddle with it if we don't have source code --- devicehandlers/CommunicationMessage.cpp | 9 +++ devicehandlers/CommunicationMessage.h | 82 +++++++++++++++++++++++++ osal/FreeRTOS/BinarySemaphore.cpp | 2 +- osal/FreeRTOS/MessageQueue.cpp | 8 +-- osal/FreeRTOS/MessageQueue.h | 6 +- osal/FreeRTOS/TaskManagement.cpp | 4 +- osal/FreeRTOS/TaskManagement.h | 9 +-- 7 files changed, 106 insertions(+), 14 deletions(-) create mode 100644 devicehandlers/CommunicationMessage.cpp create mode 100644 devicehandlers/CommunicationMessage.h diff --git a/devicehandlers/CommunicationMessage.cpp b/devicehandlers/CommunicationMessage.cpp new file mode 100644 index 000000000..6dddc5be5 --- /dev/null +++ b/devicehandlers/CommunicationMessage.cpp @@ -0,0 +1,9 @@ +/** + * @file CommunicationMessage.cpp + * + * @date 28.02.2020 + */ + + + + diff --git a/devicehandlers/CommunicationMessage.h b/devicehandlers/CommunicationMessage.h new file mode 100644 index 000000000..70c1052aa --- /dev/null +++ b/devicehandlers/CommunicationMessage.h @@ -0,0 +1,82 @@ +/** + * @file CommunicationMessage.h + * + * @date 28.02.2020 + */ + +#ifndef FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ +#define FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ +#include +#include + +/** + * @brief Used to pass communication information between tasks + * + * @details + * Can be used to pass information like data pointers and + * data sizes between communication tasks + * like the Device Handler Comm Interfaces and Polling Tasks. + * + * Can also be used to exchange actual data if its not too large + * (e.g. Sensor values). + * + */ +class CommunicationMessage: public MessageQueueMessage { +public: + enum communicationStatus { + SEND_DATA, + PROCESS_DATA, + FAULTY, + }; + + //Add other messageIDs here if necessary. + static const uint8_t COMMUNICATION_MESSAGE_SIZE = HEADER_SIZE + 4 * sizeof(uint32_t); + + CommunicationMessage(); + + /** + * Send requests with pointer to the data to be sent and send data length + * @param address Target Address + * @param sendData + * @param length + */ + void setSendRequest(uint32_t address, const uint8_t * sendData, uint32_t length); + + /** + * Data message with data stored in IPC store + * @param address + * @param length + * @param storeId + */ + void setDataMessage(uint32_t address, uint32_t length, store_address_t * storeId); + + /** + * Data message with data stored in actual message. + * 4 byte datafield is intialized with 0. + * Set data with specific setter functions. + */ + void setDataMessage(uint32_t address, uint32_t length); + +private: + void setCommunicationStatus(communicationStatus status); + void setAddress(uint32_t address); + void setSendData(const uint8_t * sendData); + void setDataLen(uint32_t length); + + /** For low size data, maximum of 4 bytes can be sent */ + void setDataByte1(uint8_t byte1); + void setDataByte2(uint8_t byte2); + void setDataByte3(uint8_t byte3); + void setDataByte4(uint8_t byte4); + + void setDataUINT16_1(uint16_t data1); + void setDataUINT16_2(uint16_t data2); + + void setData(uint32_t data); + + virtual ~CommunicationMessage(); +}; + + + +#endif /* FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ */ diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 09e71f6d5..c3d573870 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -88,7 +88,7 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema if (returncode == pdPASS) { if(*higherPriorityTaskWoken == pdPASS) { // Request context switch - TaskManagement::requestContextSwitch(SystemContext::isr_context); + TaskManagement::requestContextSwitch(CallContext::isr); } return HasReturnvaluesIF::RETURN_OK; } else { diff --git a/osal/FreeRTOS/MessageQueue.cpp b/osal/FreeRTOS/MessageQueue.cpp index f23d9d9d1..cc38e77d3 100644 --- a/osal/FreeRTOS/MessageQueue.cpp +++ b/osal/FreeRTOS/MessageQueue.cpp @@ -6,7 +6,7 @@ // As a first step towards this, introduces system context variable which needs to be switched manually // Haven't found function to find system context. MessageQueue::MessageQueue(size_t message_depth, size_t max_message_size) : -defaultDestination(0),lastPartner(0), callContext(SystemContext::task_context) { +defaultDestination(0),lastPartner(0), callContext(CallContext::task) { handle = xQueueCreate(message_depth, max_message_size); if (handle == NULL) { error << "MessageQueue creation failed" << std::endl; @@ -19,7 +19,7 @@ MessageQueue::~MessageQueue() { } } -void MessageQueue::switchSystemContext(SystemContext callContext) { +void MessageQueue::switchSystemContext(CallContext callContext) { this->callContext = callContext; } @@ -53,10 +53,10 @@ ReturnValue_t MessageQueue::sendMessageFrom(MessageQueueId_t sendTo, ReturnValue_t MessageQueue::sendMessageFromMessageQueue(MessageQueueId_t sendTo, MessageQueueMessage *message, MessageQueueId_t sentFrom, - bool ignoreFault, SystemContext callContext) { + bool ignoreFault, CallContext callContext) { message->setSender(sentFrom); BaseType_t result; - if(callContext == SystemContext::task_context) { + if(callContext == CallContext::task) { result = xQueueSendToBack(reinterpret_cast(sendTo), reinterpret_cast(message->getBuffer()), 0); } diff --git a/osal/FreeRTOS/MessageQueue.h b/osal/FreeRTOS/MessageQueue.h index d8e149611..8edfed10c 100644 --- a/osal/FreeRTOS/MessageQueue.h +++ b/osal/FreeRTOS/MessageQueue.h @@ -58,7 +58,7 @@ public: */ virtual ~MessageQueue(); - void switchSystemContext(SystemContext callContext); + void switchSystemContext(CallContext callContext); /** * @brief This operation sends a message to the given destination. @@ -168,7 +168,7 @@ protected: */ static ReturnValue_t sendMessageFromMessageQueue(MessageQueueId_t sendTo, MessageQueueMessage* message, MessageQueueId_t sentFrom = NO_QUEUE, - bool ignoreFault=false, SystemContext callContex = SystemContext::task_context); + bool ignoreFault=false, CallContext callContex = CallContext::task); static ReturnValue_t handleSendResult(BaseType_t result, bool ignoreFault); @@ -177,7 +177,7 @@ private: QueueHandle_t handle; MessageQueueId_t defaultDestination; MessageQueueId_t lastPartner; - SystemContext callContext; //!< Stores the current system context + CallContext callContext; //!< Stores the current system context }; #endif /* MESSAGEQUEUE_H_ */ diff --git a/osal/FreeRTOS/TaskManagement.cpp b/osal/FreeRTOS/TaskManagement.cpp index 573a7d7d9..40a0f3955 100644 --- a/osal/FreeRTOS/TaskManagement.cpp +++ b/osal/FreeRTOS/TaskManagement.cpp @@ -13,8 +13,8 @@ void TaskManagement::requestContextSwitchFromTask() { vTaskDelay(0); } -void TaskManagement::requestContextSwitch(SystemContext callContext = SystemContext::task_context) { - if(callContext == SystemContext::isr_context) { +void TaskManagement::requestContextSwitch(CallContext callContext = CallContext::task) { + if(callContext == CallContext::isr) { // This function depends on the partmacro.h definition for the specific device portYIELD_FROM_ISR(); } else { diff --git a/osal/FreeRTOS/TaskManagement.h b/osal/FreeRTOS/TaskManagement.h index 381e06f9a..fd2bfc0b1 100644 --- a/osal/FreeRTOS/TaskManagement.h +++ b/osal/FreeRTOS/TaskManagement.h @@ -12,9 +12,10 @@ * within an ISR or from a regular task. This is required because FreeRTOS * has different functions for handling semaphores and messages from within an ISR and task. */ -enum SystemContext { - task_context = 0x00,//!< task_context - isr_context = 0xFF //!< isr_context + +enum CallContext { + task = 0x00,//!< task_context + isr = 0xFF //!< isr_context }; class TaskManagement { @@ -25,7 +26,7 @@ public: * This can be used if sending to the queue from an ISR caused a task to unblock * and a context switch is required. */ - static void requestContextSwitch(SystemContext callContext); + static void requestContextSwitch(CallContext callContext); /** * If task preemption in FreeRTOS is disabled, a context switch From dd4a5a45e3a25ce5bbbedfdd37a407273b62ac54 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 3 Mar 2020 21:20:08 +0100 Subject: [PATCH 0114/1774] communication message extended --- devicehandlers/CommunicationMessage.cpp | 95 +++++++++++++++++++++ devicehandlers/CommunicationMessage.h | 105 +++++++++++++++++++----- devicehandlers/DeviceCommunicationIF.h | 3 +- devicehandlers/FixedSequenceSlot.h | 2 +- 4 files changed, 183 insertions(+), 22 deletions(-) diff --git a/devicehandlers/CommunicationMessage.cpp b/devicehandlers/CommunicationMessage.cpp index 6dddc5be5..8f9d1eb6c 100644 --- a/devicehandlers/CommunicationMessage.cpp +++ b/devicehandlers/CommunicationMessage.cpp @@ -4,6 +4,101 @@ * @date 28.02.2020 */ +#include +#include + +CommunicationMessage::CommunicationMessage(): uninitialized(true) { +} + +void CommunicationMessage::setSendRequestFromPointer(uint32_t address, + uint32_t dataLen, const uint8_t * data) { + setMessageType(SEND_DATA_FROM_POINTER); + setAddress(address); + setDataLen(dataLen); + setDataPointer(data); +} + +void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_address_t storeId) { + setMessageType(SEND_DATA_FROM_IPC_STORE); + setAddress(address); + setStoreId(storeId); +} + +void CommunicationMessage::setSendRequestRaw(uint32_t address) { +} + +void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) { + setMessageType(REPLY_DATA_IPC_STORE); + setAddress(address); + setStoreId(storeId); +} +void CommunicationMessage::setDataReplyFromPointer(uint32_t address, + uint32_t dataLen, uint8_t *data) { +} + +void CommunicationMessage::setDataReplyRaw(uint32_t address, + uint32_t length, uint16_t receiveBufferPosition) { + setMessageType(REPLY_DATA_RAW); + setAddress(address); + setDataLen(length); + if(receiveBufferPosition != 0) { + setReceiveBufferPosition(receiveBufferPosition); + } +} + + + +void CommunicationMessage::setMessageType(messageType status) { + uint8_t status_uint8 = status; + memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8)); +} + +void CommunicationMessage::setAddress(uint32_t address) { + memcpy(getData(),&address,sizeof(address)); +} + +void CommunicationMessage::setReceiveBufferPosition(uint16_t bufferPosition) { + memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t), + &bufferPosition, sizeof(bufferPosition)); +} + +void CommunicationMessage::setDataPointer(const uint8_t *sendData) { + memcpy(getData() + 3 * sizeof(uint32_t), &sendData, sizeof(uint32_t)); +} + +void CommunicationMessage::setStoreId(store_address_t storeId) { + memcpy(getData() + 2 * sizeof(uint32_t), &storeId, sizeof(store_address_t)); +} + +void CommunicationMessage::setDataLen(uint32_t length) { + memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length)); +} + +void CommunicationMessage::setDataByte1(uint8_t byte1) { +} + +void CommunicationMessage::setDataByte2(uint8_t byte2) { +} + +void CommunicationMessage::setDataByte3(uint8_t byte3) { +} + +void CommunicationMessage::setDataByte4(uint8_t byte4) { +} + +void CommunicationMessage::setDataUINT16_1(uint16_t data1) { +} + +void CommunicationMessage::setDataUINT16_2(uint16_t data2) { +} + +void CommunicationMessage::setData(uint32_t data) { +} + +CommunicationMessage::~CommunicationMessage() { +} + + diff --git a/devicehandlers/CommunicationMessage.h b/devicehandlers/CommunicationMessage.h index 70c1052aa..fe744fd65 100644 --- a/devicehandlers/CommunicationMessage.h +++ b/devicehandlers/CommunicationMessage.h @@ -6,6 +6,8 @@ #ifndef FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ #define FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ +#include + #include #include @@ -23,9 +25,13 @@ */ class CommunicationMessage: public MessageQueueMessage { public: - enum communicationStatus { - SEND_DATA, - PROCESS_DATA, + enum messageType { + SEND_DATA_FROM_POINTER, + SEND_DATA_FROM_IPC_STORE, + SEND_DATA_RAW, + REPLY_DATA_FROM_POINTER, + REPLY_DATA_IPC_STORE, + REPLY_DATA_RAW, FAULTY, }; @@ -36,34 +42,60 @@ public: /** * Send requests with pointer to the data to be sent and send data length - * @param address Target Address - * @param sendData - * @param length + * @param address Target Address, first four bytes + * @param dataLen Length of data to send, next four bytes + * @param data Pointer to data to send + * */ - void setSendRequest(uint32_t address, const uint8_t * sendData, uint32_t length); + void setSendRequestFromPointer(uint32_t address, uint32_t dataLen, const uint8_t * data); + + /** + * Send requests with a store ID, using the IPC store + * @param address Target Address, first four bytes + * @param storeId Store ID in the IPC store + * + */ + void setSendRequestFromIpcStore(uint32_t address, store_address_t storeId); + + /** + * Send requests with data length and data in message (max. 4 bytes) + * @param address Target Address, first four bytes + * @param dataLen Length of data to send, next four bytes + * @param data Pointer to data to send + * + */ + void setSendRequestRaw(uint32_t address); /** * Data message with data stored in IPC store - * @param address + * @param address Target Address, first four bytes * @param length * @param storeId */ - void setDataMessage(uint32_t address, uint32_t length, store_address_t * storeId); + void setDataReplyFromIpcStore(uint32_t address, store_address_t storeId); + + /** + * Data reply with data stored in buffer, passing the pointer to + * the buffer and the data size + * @param address Target Address, first four bytes + * @param dataLen Length of data to send, next four bytes + * @param data Pointer to the data + */ + void setDataReplyFromPointer(uint32_t address, uint32_t dataLen, uint8_t * data); /** * Data message with data stored in actual message. * 4 byte datafield is intialized with 0. - * Set data with specific setter functions. + * Set data with specific setter functions below. + * Can also be used to supply information at which position the raw data should be stored + * in a receive buffer. */ - void setDataMessage(uint32_t address, uint32_t length); + void setDataReplyRaw(uint32_t address, uint32_t length, uint16_t receiveBufferPosition = 0); -private: - void setCommunicationStatus(communicationStatus status); - void setAddress(uint32_t address); - void setSendData(const uint8_t * sendData); - void setDataLen(uint32_t length); - - /** For low size data, maximum of 4 bytes can be sent */ + /* + * The following functions can be used to + * set the data field (4 bytes possible); + */ void setDataByte1(uint8_t byte1); void setDataByte2(uint8_t byte2); void setDataByte3(uint8_t byte3); @@ -74,9 +106,42 @@ private: void setData(uint32_t data); +private: + /** + * Message Type is stored as the fifth byte of the message data + * @param status + */ + void setMessageType(messageType status); + + /** + * First four bytes of message data + * @param address + */ + void setAddress(uint32_t address); + + /** + * Stored in Bytes 13-16 of message data + * @param length + */ + void setDataLen(uint32_t length); + + /** + * Stored in last four bytes (Bytes 17-20) of message data + * @param sendData + */ + void setDataPointer(const uint8_t * sendData); + + /** + * Buffer Position is stored as the seventh and eigth byte of + * the message, so the receive buffer can't be larger than sizeof(uint16_t) for now + * @param bufferPosition + */ + void setReceiveBufferPosition(uint16_t bufferPosition); + void setStoreId(store_address_t storeId); + virtual ~CommunicationMessage(); + + bool uninitialized; }; - - #endif /* FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ */ diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 546081ba5..e03db26be 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -22,7 +22,8 @@ * 4. Read received data * * To identify different connection over a single interface can return so-called cookies to components. - * + * The CommunicationMessage message type can be used to extend the functionality of the + * ComIF if a separate polling task is required. */ class DeviceCommunicationIF: public HasReturnvaluesIF { public: diff --git a/devicehandlers/FixedSequenceSlot.h b/devicehandlers/FixedSequenceSlot.h index 5aff0f4f3..0ed285b38 100644 --- a/devicehandlers/FixedSequenceSlot.h +++ b/devicehandlers/FixedSequenceSlot.h @@ -31,7 +31,7 @@ public: * \brief This attribute defines when a device handler object is executed. * * \details The pollingTime attribute identifies the time the handler is executed in ms. It must be - * smaller than the period length of the polling sequence, what is ensured by automated calculation + * smaller than the period length of the polling sequence, which is ensured by automated calculation * from a database. */ uint32_t pollingTimeMs; From fb6172fdc51a6e76513437ec74ed733da3847e1f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 4 Mar 2020 00:37:58 +0100 Subject: [PATCH 0115/1774] communication message continued. Some fixed timeslot task improvements --- devicehandlers/CommunicationMessage.cpp | 40 +++++++++++++++------- devicehandlers/CommunicationMessage.h | 44 +++++++++++++++---------- devicehandlers/DeviceHandlerBase.h | 7 +++- devicehandlers/FixedSlotSequence.h | 2 +- osal/FreeRTOS/FixedTimeslotTask.cpp | 4 +++ 5 files changed, 65 insertions(+), 32 deletions(-) diff --git a/devicehandlers/CommunicationMessage.cpp b/devicehandlers/CommunicationMessage.cpp index 8f9d1eb6c..5c0424879 100644 --- a/devicehandlers/CommunicationMessage.cpp +++ b/devicehandlers/CommunicationMessage.cpp @@ -10,6 +10,8 @@ CommunicationMessage::CommunicationMessage(): uninitialized(true) { } +CommunicationMessage::~CommunicationMessage() {} + void CommunicationMessage::setSendRequestFromPointer(uint32_t address, uint32_t dataLen, const uint8_t * data) { setMessageType(SEND_DATA_FROM_POINTER); @@ -24,7 +26,10 @@ void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_ad setStoreId(storeId); } -void CommunicationMessage::setSendRequestRaw(uint32_t address) { +void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length) { + setMessageType(SEND_DATA_RAW); + setAddress(address); + setDataLen(length); } void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) { @@ -34,6 +39,10 @@ void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_addr } void CommunicationMessage::setDataReplyFromPointer(uint32_t address, uint32_t dataLen, uint8_t *data) { + setMessageType(REPLY_DATA_FROM_POINTER); + setAddress(address); + setDataLen(dataLen); + setDataPointer(data); } void CommunicationMessage::setDataReplyRaw(uint32_t address, @@ -46,8 +55,6 @@ void CommunicationMessage::setDataReplyRaw(uint32_t address, } } - - void CommunicationMessage::setMessageType(messageType status) { uint8_t status_uint8 = status; memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8)); @@ -62,8 +69,8 @@ void CommunicationMessage::setReceiveBufferPosition(uint16_t bufferPosition) { &bufferPosition, sizeof(bufferPosition)); } -void CommunicationMessage::setDataPointer(const uint8_t *sendData) { - memcpy(getData() + 3 * sizeof(uint32_t), &sendData, sizeof(uint32_t)); +void CommunicationMessage::setDataPointer(const void * data) { + memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(uint32_t)); } void CommunicationMessage::setStoreId(store_address_t storeId) { @@ -74,31 +81,40 @@ void CommunicationMessage::setDataLen(uint32_t length) { memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length)); } +void CommunicationMessage::setData(uint32_t data) { + memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(data)); +} + void CommunicationMessage::setDataByte1(uint8_t byte1) { + memcpy(getData() + 3 * sizeof(uint32_t), &byte1, sizeof(byte1)); } void CommunicationMessage::setDataByte2(uint8_t byte2) { + memcpy(getData() + 3 * sizeof(uint32_t) + sizeof(uint8_t), &byte2, sizeof(byte2)); } void CommunicationMessage::setDataByte3(uint8_t byte3) { + memcpy(getData() + 3 * sizeof(uint32_t) + 2* sizeof(uint8_t), &byte3, sizeof(byte3)); } void CommunicationMessage::setDataByte4(uint8_t byte4) { + memcpy(getData() + 3 * sizeof(uint32_t) + 3* sizeof(uint8_t), &byte4, sizeof(byte4)); } void CommunicationMessage::setDataUINT16_1(uint16_t data1) { + memcpy(getData() + 3 * sizeof(uint32_t), &data1, sizeof(data1)); } void CommunicationMessage::setDataUINT16_2(uint16_t data2) { + memcpy(getData() + 3 * sizeof(uint32_t) + sizeof(uint16_t), &data2, sizeof(data2)); } -void CommunicationMessage::setData(uint32_t data) { +CommunicationMessage::messageType CommunicationMessage::getMessageType() { + messageType messageType; + memcpy(&messageType, getData() + sizeof(uint32_t),sizeof(uint8_t)); + return messageType; } -CommunicationMessage::~CommunicationMessage() { +void CommunicationMessage::clearCommunicationMessage() { + messageType messageType = getMessageType(); } - - - - - diff --git a/devicehandlers/CommunicationMessage.h b/devicehandlers/CommunicationMessage.h index fe744fd65..805dd9a88 100644 --- a/devicehandlers/CommunicationMessage.h +++ b/devicehandlers/CommunicationMessage.h @@ -39,6 +39,7 @@ public: static const uint8_t COMMUNICATION_MESSAGE_SIZE = HEADER_SIZE + 4 * sizeof(uint32_t); CommunicationMessage(); + virtual ~CommunicationMessage(); /** * Send requests with pointer to the data to be sent and send data length @@ -64,7 +65,7 @@ public: * @param data Pointer to data to send * */ - void setSendRequestRaw(uint32_t address); + void setSendRequestRaw(uint32_t address, uint32_t length); /** * Data message with data stored in IPC store @@ -92,6 +93,22 @@ public: */ void setDataReplyRaw(uint32_t address, uint32_t length, uint16_t receiveBufferPosition = 0); + /** + * First four bytes of message data + * @param address + */ + void setAddress(uint32_t address); + + /** + * Message Type is stored as the fifth byte of the message data + * @param status + */ + void setMessageType(messageType status); + messageType getMessageType(); + + void setMessageId(uint8_t messageId); + messageType getMessageId(); + /* * The following functions can be used to * set the data field (4 bytes possible); @@ -106,19 +123,6 @@ public: void setData(uint32_t data); -private: - /** - * Message Type is stored as the fifth byte of the message data - * @param status - */ - void setMessageType(messageType status); - - /** - * First four bytes of message data - * @param address - */ - void setAddress(uint32_t address); - /** * Stored in Bytes 13-16 of message data * @param length @@ -129,19 +133,23 @@ private: * Stored in last four bytes (Bytes 17-20) of message data * @param sendData */ - void setDataPointer(const uint8_t * sendData); + void setDataPointer(const void * data); /** * Buffer Position is stored as the seventh and eigth byte of - * the message, so the receive buffer can't be larger than sizeof(uint16_t) for now + * the message, so the receive buffer can't be larger than sizeof(uint16_t) for now. * @param bufferPosition */ void setReceiveBufferPosition(uint16_t bufferPosition); void setStoreId(store_address_t storeId); - virtual ~CommunicationMessage(); + /** + * Clear the message + */ + void clearCommunicationMessage(); +private: - bool uninitialized; + bool uninitialized; //!< Could be used to warn if data has not been set. }; #endif /* FRAMEWORK_DEVICEHANDLERS_COMMUNICATIONMESSAGE_H_ */ diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index f16a4ff96..98808d87e 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -33,6 +33,11 @@ class StorageManagerIF; * Contains all devices and the DeviceHandlerBase class. */ +/** + * Physical address type + */ +typedef uint32_t address_t; + /** * @brief This is the abstract base class for device handlers. * @details @@ -91,7 +96,7 @@ public: * @param fdirInstance * @param cmdQueueSize */ - DeviceHandlerBase(uint32_t logicalAddress, object_id_t setObjectId, + DeviceHandlerBase(address_t logicalAddress, object_id_t setObjectId, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, object_id_t deviceCommunication, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, diff --git a/devicehandlers/FixedSlotSequence.h b/devicehandlers/FixedSlotSequence.h index f8fd9a36f..d72de9131 100644 --- a/devicehandlers/FixedSlotSequence.h +++ b/devicehandlers/FixedSlotSequence.h @@ -104,7 +104,7 @@ protected: * \brief This list contains all OPUSPollingSlot objects, defining order and execution time of the * device handler objects. * - * \details The slot list is a std:list object that contains all created OPUSPollingSlot instances. + * @details The slot list is a std:list object that contains all created PollingSlot instances. * They are NOT ordered automatically, so by adding entries, the correct order needs to be ensured. * By iterating through this list the polling sequence is executed. Two entries with identical * polling times are executed immediately one after another. diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index a2c2e5c68..604a10b86 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -58,6 +58,10 @@ ReturnValue_t FixedTimeslotTask::startTask() { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { if (objectManager->get(componentId) != NULL) { + if(slotTimeMs == 0) { + // FreeRTOS throws errors for zero values + slotTimeMs = 1; + } pst.addSlot(componentId, slotTimeMs, executionStep, this); return HasReturnvaluesIF::RETURN_OK; } From 43ac0ec04bbaffc1f7a23b478fd747396a3a4ad4 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 4 Mar 2020 23:07:54 +0100 Subject: [PATCH 0116/1774] Communication Message continued --- devicehandlers/CommunicationMessage.cpp | 129 +++++++++++++++++++----- devicehandlers/CommunicationMessage.h | 76 +++++++++----- devicehandlers/DeviceCommunicationIF.h | 7 +- 3 files changed, 160 insertions(+), 52 deletions(-) diff --git a/devicehandlers/CommunicationMessage.cpp b/devicehandlers/CommunicationMessage.cpp index 5c0424879..028e8a2e1 100644 --- a/devicehandlers/CommunicationMessage.cpp +++ b/devicehandlers/CommunicationMessage.cpp @@ -5,6 +5,7 @@ */ #include +#include #include CommunicationMessage::CommunicationMessage(): uninitialized(true) { @@ -23,19 +24,23 @@ void CommunicationMessage::setSendRequestFromPointer(uint32_t address, void CommunicationMessage::setSendRequestFromIpcStore(uint32_t address, store_address_t storeId) { setMessageType(SEND_DATA_FROM_IPC_STORE); setAddress(address); - setStoreId(storeId); + setStoreId(storeId.raw); } -void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length) { +void CommunicationMessage::setSendRequestRaw(uint32_t address, uint32_t length, + uint16_t sendBufferPosition) { setMessageType(SEND_DATA_RAW); setAddress(address); setDataLen(length); + if(sendBufferPosition != 0) { + setBufferPosition(sendBufferPosition); + } } void CommunicationMessage::setDataReplyFromIpcStore(uint32_t address, store_address_t storeId) { setMessageType(REPLY_DATA_IPC_STORE); setAddress(address); - setStoreId(storeId); + setStoreId(storeId.raw); } void CommunicationMessage::setDataReplyFromPointer(uint32_t address, uint32_t dataLen, uint8_t *data) { @@ -51,7 +56,7 @@ void CommunicationMessage::setDataReplyRaw(uint32_t address, setAddress(address); setDataLen(length); if(receiveBufferPosition != 0) { - setReceiveBufferPosition(receiveBufferPosition); + setBufferPosition(receiveBufferPosition); } } @@ -60,61 +65,137 @@ void CommunicationMessage::setMessageType(messageType status) { memcpy(getData() + sizeof(uint32_t), &status_uint8, sizeof(status_uint8)); } -void CommunicationMessage::setAddress(uint32_t address) { +void CommunicationMessage::setAddress(address_t address) { memcpy(getData(),&address,sizeof(address)); } -void CommunicationMessage::setReceiveBufferPosition(uint16_t bufferPosition) { - memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t), +address_t CommunicationMessage::getAddress() const { + address_t address; + memcpy(&address,getData(),sizeof(address)); + return address; +} + +void CommunicationMessage::setBufferPosition(uint16_t bufferPosition) { + memcpy(getData() + sizeof(uint32_t) + sizeof(uint16_t), &bufferPosition, sizeof(bufferPosition)); } +uint16_t CommunicationMessage::getBufferPosition() const { + uint16_t bufferPosition; + memcpy(&bufferPosition, + getData() + sizeof(uint32_t) + sizeof(uint16_t), sizeof(bufferPosition)); + return bufferPosition; +} + void CommunicationMessage::setDataPointer(const void * data) { memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(uint32_t)); } void CommunicationMessage::setStoreId(store_address_t storeId) { - memcpy(getData() + 2 * sizeof(uint32_t), &storeId, sizeof(store_address_t)); + memcpy(getData() + 2 * sizeof(uint32_t), &storeId.raw, sizeof(uint32_t)); +} + +store_address_t CommunicationMessage::getStoreId() const{ + store_address_t temp; + memcpy(&temp.raw,getData() + 2 * sizeof(uint32_t), sizeof(uint32_t)); + return temp; } void CommunicationMessage::setDataLen(uint32_t length) { memcpy(getData() + 2 * sizeof(uint32_t), &length, sizeof(length)); } -void CommunicationMessage::setData(uint32_t data) { +uint32_t CommunicationMessage::getDataLen() const { + uint32_t len; + memcpy(&len, getData() + 2 * sizeof(uint32_t), sizeof(len)); + return len; +} + +void CommunicationMessage::setUint32Data(uint32_t data) { memcpy(getData() + 3 * sizeof(uint32_t), &data, sizeof(data)); } -void CommunicationMessage::setDataByte1(uint8_t byte1) { - memcpy(getData() + 3 * sizeof(uint32_t), &byte1, sizeof(byte1)); +uint32_t CommunicationMessage::getUint32Data() const{ + uint32_t data; + memcpy(&data,getData() + 3 * sizeof(uint32_t), sizeof(data)); + return data; } -void CommunicationMessage::setDataByte2(uint8_t byte2) { - memcpy(getData() + 3 * sizeof(uint32_t) + sizeof(uint8_t), &byte2, sizeof(byte2)); +void CommunicationMessage::setDataByte(uint8_t byte, uint8_t position) { + if(0 <= position && position <= 3) { + memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), &byte, sizeof(byte)); + } + else { + error << "Comm Message: Invalid byte position" << std::endl; + } } -void CommunicationMessage::setDataByte3(uint8_t byte3) { - memcpy(getData() + 3 * sizeof(uint32_t) + 2* sizeof(uint8_t), &byte3, sizeof(byte3)); +uint8_t CommunicationMessage::getDataByte(uint8_t position) const { + if(0 <= position && position <= 3) { + uint8_t byte; + memcpy(&byte, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint8_t), sizeof(byte)); + return byte; + } + else { + return 0; + error << "Comm Message: Invalid byte position" << std::endl; + } } -void CommunicationMessage::setDataByte4(uint8_t byte4) { - memcpy(getData() + 3 * sizeof(uint32_t) + 3* sizeof(uint8_t), &byte4, sizeof(byte4)); +void CommunicationMessage::setDataUint16(uint16_t data, uint8_t position) { + if(position == 0 || position == 1) { + memcpy(getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), &data, sizeof(data)); + } + else { + error << "Comm Message: Invalid byte position" << std::endl; + } + } -void CommunicationMessage::setDataUINT16_1(uint16_t data1) { - memcpy(getData() + 3 * sizeof(uint32_t), &data1, sizeof(data1)); +uint16_t CommunicationMessage::getDataUint16(uint8_t position) const{ + if(position == 0 || position == 1) { + uint16_t data; + memcpy(&data, getData() + 3 * sizeof(uint32_t) + position * sizeof(uint16_t), sizeof(data)); + return data; + } + else { + return 0; + error << "Comm Message: Invalid byte position" << std::endl; + } } -void CommunicationMessage::setDataUINT16_2(uint16_t data2) { - memcpy(getData() + 3 * sizeof(uint32_t) + sizeof(uint16_t), &data2, sizeof(data2)); -} - -CommunicationMessage::messageType CommunicationMessage::getMessageType() { +CommunicationMessage::messageType CommunicationMessage::getMessageType() const{ messageType messageType; memcpy(&messageType, getData() + sizeof(uint32_t),sizeof(uint8_t)); return messageType; } +void CommunicationMessage::setMessageId(uint8_t messageId) { + memcpy(getData() + sizeof(uint32_t) + sizeof(uint8_t), &messageId, sizeof(messageId)); +} + +uint8_t CommunicationMessage::getMessageId() const { + uint8_t messageId; + memcpy(&messageId, getData() + sizeof(uint32_t) + sizeof(uint8_t), sizeof(messageId)); + return messageId; +} + void CommunicationMessage::clearCommunicationMessage() { messageType messageType = getMessageType(); + switch(messageType) { + case(messageType::REPLY_DATA_IPC_STORE): + case(messageType::SEND_DATA_FROM_IPC_STORE): { + store_address_t storeId = getStoreId(); + StorageManagerIF *ipcStore = objectManager-> + get(objects::IPC_STORE); + if (ipcStore != NULL) { + ipcStore->deleteData(storeId); + } + } + /* NO BREAK falls through*/ + default: + memset(getData(),0,4*sizeof(uint32_t)); + break; + } } + diff --git a/devicehandlers/CommunicationMessage.h b/devicehandlers/CommunicationMessage.h index 805dd9a88..a92c4b5cf 100644 --- a/devicehandlers/CommunicationMessage.h +++ b/devicehandlers/CommunicationMessage.h @@ -10,6 +10,7 @@ #include #include +#include /** * @brief Used to pass communication information between tasks @@ -26,6 +27,7 @@ class CommunicationMessage: public MessageQueueMessage { public: enum messageType { + NONE, SEND_DATA_FROM_POINTER, SEND_DATA_FROM_IPC_STORE, SEND_DATA_RAW, @@ -41,6 +43,24 @@ public: CommunicationMessage(); virtual ~CommunicationMessage(); + /** + * Message Type is stored as the fifth byte of the message data + * @param status + */ + void setMessageType(messageType status); + messageType getMessageType() const; + + /** + * This is a unique ID which can be used to handle different kinds of messages. + * For example, the same interface (e.g. SPI) could be used to exchange raw data + * (e.g. sensor values) and data stored in the IPC store. + * The ID can be used to distinguish the messages in child implementations. + * The message ID is stored as the sixth byte of the message data. + * @param messageId + */ + void setMessageId(uint8_t messageId); + uint8_t getMessageId() const; + /** * Send requests with pointer to the data to be sent and send data length * @param address Target Address, first four bytes @@ -65,7 +85,8 @@ public: * @param data Pointer to data to send * */ - void setSendRequestRaw(uint32_t address, uint32_t length); + void setSendRequestRaw(uint32_t address, uint32_t length, + uint16_t sendBufferPosition = 0); /** * Data message with data stored in IPC store @@ -97,31 +118,27 @@ public: * First four bytes of message data * @param address */ - void setAddress(uint32_t address); + void setAddress(address_t address); + + address_t getAddress() const; + /** + * Set byte as position of 4 byte data field + * @param byte + * @param position Position, 0 to 3 possible + */ + void setDataByte(uint8_t byte, uint8_t position); + uint8_t getDataByte(uint8_t position) const; /** - * Message Type is stored as the fifth byte of the message data - * @param status + * Set 2 byte value at position 1 or 2 of data field + * @param data + * @param position 0 or 1 possible */ - void setMessageType(messageType status); - messageType getMessageType(); + void setDataUint16(uint16_t data, uint8_t position); + uint16_t getDataUint16(uint8_t position) const; - void setMessageId(uint8_t messageId); - messageType getMessageId(); - - /* - * The following functions can be used to - * set the data field (4 bytes possible); - */ - void setDataByte1(uint8_t byte1); - void setDataByte2(uint8_t byte2); - void setDataByte3(uint8_t byte3); - void setDataByte4(uint8_t byte4); - - void setDataUINT16_1(uint16_t data1); - void setDataUINT16_2(uint16_t data2); - - void setData(uint32_t data); + void setUint32Data(uint32_t data); + uint32_t getUint32Data() const; /** * Stored in Bytes 13-16 of message data @@ -129,6 +146,8 @@ public: */ void setDataLen(uint32_t length); + uint32_t getDataLen() const; + /** * Stored in last four bytes (Bytes 17-20) of message data * @param sendData @@ -136,19 +155,22 @@ public: void setDataPointer(const void * data); /** - * Buffer Position is stored as the seventh and eigth byte of + * In case the send request data or reply data is to be stored in a buffer, + * a buffer Position can be stored here as the seventh and eigth byte of * the message, so the receive buffer can't be larger than sizeof(uint16_t) for now. - * @param bufferPosition + * @param bufferPosition In case the data is stored in a buffer, the position can be supplied here */ - void setReceiveBufferPosition(uint16_t bufferPosition); + void setBufferPosition(uint16_t bufferPosition); + uint16_t getBufferPosition() const; void setStoreId(store_address_t storeId); + store_address_t getStoreId() const; /** - * Clear the message + * Clear the message. Deletes IPC Store data + * and sets all data to 0. Also sets message type to NONE */ void clearCommunicationMessage(); private: - bool uninitialized; //!< Could be used to warn if data has not been set. }; diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index e03db26be..999045105 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -73,10 +73,15 @@ public: virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0; + /** + * Called by DHB in the SEND_WRITE doSendRead(). + * @param cookie + * @return + */ virtual ReturnValue_t requestReceiveMessage(Cookie *cookie) = 0; /** - * Called by DHB in the GET_WIRTE doGetRead(). + * Called by DHB in the GET_WRITE doGetRead(). * This function is used to receive data from the physical device * by implementing and calling related drivers or wrapper functions. * @param cookie From 22e4dabd1bf778c1a4c32aa76d8bf72b99936576 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 6 Mar 2020 15:39:42 +0100 Subject: [PATCH 0117/1774] BinSemaphore reset function added --- osal/FreeRTOS/BinarySemaphore.cpp | 5 +++++ osal/FreeRTOS/BinarySemaphore.h | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index c3d573870..d429f1a07 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -79,6 +79,11 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) } } +void BinarySemaphore::resetSemaphore() { + vSemaphoreDelete(handle); + vSemaphoreCreateBinary(handle); +} + ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) { if (semaphore == NULL) { diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h index 7ead0d2fe..a809f0bb1 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -69,6 +69,11 @@ public: */ SemaphoreHandle_t getSemaphore(); + /** + * Reset the semaphore. + */ + void resetSemaphore(); + /** * Wrapper function to give back semaphore from handle * @param semaphore From 68cda479d699ef0f5c73b9ee95c352e178171896 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 6 Mar 2020 18:48:48 +0100 Subject: [PATCH 0118/1774] DHB: performOperation Hook + polling counter polling counter to specify how often communication opertions are performed, however this still needs to be changed.. --- container/FixedMap.h | 2 +- container/group.h | 8 +++----- devicehandlers/DeviceHandlerBase.cpp | 20 +++++++++++++++++--- devicehandlers/DeviceHandlerBase.h | 25 +++++++++++++++++++++++-- 4 files changed, 44 insertions(+), 11 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 39e9106d1..f5ee42445 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -9,7 +9,7 @@ * @brief Map implementation for maps with a pre-defined size. * @details Can be initialized with desired maximum size. * Iterator is used to access pair and - * iterate through map entries. + * iterate through map entries. Complexity O(n). * @ingroup container */ template diff --git a/container/group.h b/container/group.h index 5a39d34ec..9c70d5236 100644 --- a/container/group.h +++ b/container/group.h @@ -4,11 +4,9 @@ /** * @defgroup container Container * - * General Purpose Container to store various elements. - * - * Also contains Adapter classes to print elements to a - * bytestream and to read them from a bytestream, as well - * as an Adapter to swap the endianness. + * General Purpose Containers to store various elements. + * As opposed to the STL library implementation, these implementations + * don't allocate memory dynamically. */ diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index c4f7465d9..1252d61f5 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -32,8 +32,9 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t logicalAddress_, ignoreMissedRepliesCount(0), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed(fdirInstance == NULL), switchOffWasReported(false), executingTask(NULL), actionHelper(this, NULL), cookieInfo(), logicalAddress(logicalAddress_), - timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), - transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) + pollingFrequency(1), pollingCounter(1), timeoutStart(0), childTransitionDelay(5000), + transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), + deviceSwitch(setDeviceSwitch) { commandQueue = QueueFactory::instance()-> createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); @@ -63,10 +64,20 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { decrementDeviceReplyMap(); fdirInstance->checkForFailures(); hkSwitcher.performOperation(); + performOperationHook(); } if (mode == MODE_OFF) { return RETURN_OK; } + + if (pollingCounter != pollingFrequency) { + pollingCounter ++; + return RETURN_OK; + } + else { + pollingCounter = 1; + } + switch (getRmapAction()) { case SEND_WRITE: if ((cookieInfo.state == COOKIE_UNUSED)) { @@ -87,6 +98,7 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { default: break; } + return RETURN_OK; } @@ -166,7 +178,6 @@ ReturnValue_t DeviceHandlerBase::initialize() { mySet.commit(PoolVariableIF::VALID); return RETURN_OK; - } void DeviceHandlerBase::decrementDeviceReplyMap() { @@ -1278,3 +1289,6 @@ void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t obje uint32_t DeviceHandlerBase::getLogicalAddress() { return logicalAddress; } + +void DeviceHandlerBase::performOperationHook() { +} diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 98808d87e..130aedb96 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -18,9 +18,9 @@ #include #include #include -#include #include #include +#include namespace Factory{ void setStaticFrameworkObjectIds(); @@ -88,7 +88,7 @@ public: * The constructor passes the objectId to the SystemObject(). * * @param setObjectId the ObjectId to pass to the SystemObject() Constructor - * @param maxDeviceReplyLen the length the RMAP getRead call will be sent with + * @param maxDeviceReplyLen the largest allowed reply size * @param setDeviceSwitch the switch the device is connected to, for devices using two switches, overwrite getSwitches() * @param deviceCommuncation Communcation Interface object which is used to implement communication functions * @param thermalStatePoolId @@ -349,6 +349,12 @@ protected: virtual ReturnValue_t getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches); + /** + * Can be used to perform device specific periodic operations. + * This is called on the SEND_READ step of the performOperation() call + */ + virtual void performOperationHook(); + public: /** * @param parentQueueId @@ -934,6 +940,19 @@ private: */ const uint32_t logicalAddress; + /** + * Polling Frequency which specifies how often the communication functions + * and functionalities are called. + * + * This is not a time value. The time value depends on the + * respective period time of the polling sequence table. + * The actual time frequency can be calculated by multiplying that period + * with the polling frequency value. Defaults to 1 (communication operations called + * in each performOperation()). + */ + uint32_t pollingFrequency; + uint32_t pollingCounter; + /** * Used for timing out mode transitions. * @@ -981,6 +1000,8 @@ private: * - checks whether commanded mode transitions are required and calls handleCommandedModeTransition() * - does the necessary action for the current mode or calls doChildStateMachine in modes @c MODE_TO_ON and @c MODE_TO_OFF * - actions that happen in transitions (eg setting a timeout) are handled in setMode() + * - Maybe export this into own class to increase modularity of software + * and reduce the massive class size ? */ void doStateMachine(void); From 6579200f5551f93349ce018127b249ab7cdb3739 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 6 Mar 2020 19:01:31 +0100 Subject: [PATCH 0119/1774] removed counter, will be implemented in childclass --- devicehandlers/DeviceHandlerBase.cpp | 13 ++----------- devicehandlers/DeviceHandlerBase.h | 15 ++------------- 2 files changed, 4 insertions(+), 24 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 1252d61f5..e7b4c6844 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -32,9 +32,8 @@ DeviceHandlerBase::DeviceHandlerBase(uint32_t logicalAddress_, ignoreMissedRepliesCount(0), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed(fdirInstance == NULL), switchOffWasReported(false), executingTask(NULL), actionHelper(this, NULL), cookieInfo(), logicalAddress(logicalAddress_), - pollingFrequency(1), pollingCounter(1), timeoutStart(0), childTransitionDelay(5000), - transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), - deviceSwitch(setDeviceSwitch) + timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), + transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { commandQueue = QueueFactory::instance()-> createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); @@ -70,14 +69,6 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { return RETURN_OK; } - if (pollingCounter != pollingFrequency) { - pollingCounter ++; - return RETURN_OK; - } - else { - pollingCounter = 1; - } - switch (getRmapAction()) { case SEND_WRITE: if ((cookieInfo.state == COOKIE_UNUSED)) { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 130aedb96..7586cc0f4 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -668,6 +668,8 @@ protected: * @param maxDelayCycles The maximum number of delay cycles the command waits until it times out. * @param periodic Indicates if the command is periodic (i.e. it is sent by the device repeatedly without request) or not. * Default is aperiodic (0) + * @param hasDifferentReplyId + * @param replyId * @return RETURN_OK when the command was successfully inserted, COMMAND_MAP_ERROR else. */ ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, @@ -940,19 +942,6 @@ private: */ const uint32_t logicalAddress; - /** - * Polling Frequency which specifies how often the communication functions - * and functionalities are called. - * - * This is not a time value. The time value depends on the - * respective period time of the polling sequence table. - * The actual time frequency can be calculated by multiplying that period - * with the polling frequency value. Defaults to 1 (communication operations called - * in each performOperation()). - */ - uint32_t pollingFrequency; - uint32_t pollingCounter; - /** * Used for timing out mode transitions. * From b5fe1fa530ed9fd91b5936b0cb617a9774861a6a Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 9 Mar 2020 22:15:52 +0100 Subject: [PATCH 0120/1774] dhb virtual function moved to top --- devicehandlers/DeviceHandlerBase.h | 18 +++++++++--------- devicehandlers/DeviceHandlerIF.h | 8 ++++---- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 7586cc0f4..53eaa7dd0 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -306,6 +306,14 @@ protected: virtual ReturnValue_t interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) = 0; + /** + * set all datapool variables that are update periodically in normal mode invalid + * + * Child classes should provide an implementation which sets all those variables invalid + * which are set periodically during any normal mode. + */ + virtual void setNormalDatapoolEntriesInvalid() = 0; + /** * @brief Can be implemented by child handler to * perform debugging @@ -666,7 +674,7 @@ protected: * This is a helper method to facilitate inserting entries in the command map. * @param deviceCommand Identifier of the command to add. * @param maxDelayCycles The maximum number of delay cycles the command waits until it times out. - * @param periodic Indicates if the command is periodic (i.e. it is sent by the device repeatedly without request) or not. + * @param periodic Indicates if the reply is periodic (i.e. it is sent by the device repeatedly without request) or not. * Default is aperiodic (0) * @param hasDifferentReplyId * @param replyId @@ -782,14 +790,6 @@ protected: */ ReturnValue_t getStateOfSwitches(void); - /** - * set all datapool variables that are update periodically in normal mode invalid - * - * Child classes should provide an implementation which sets all those variables invalid - * which are set periodically during any normal mode. - */ - virtual void setNormalDatapoolEntriesInvalid() = 0; - /** * build a list of sids and pass it to the #hkSwitcher */ diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index ed0260d60..cce403493 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -67,20 +67,20 @@ public: static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9); static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA); - //standard codes used in scan for reply - // static const ReturnValue_t TOO_SHORT = MAKE_RETURN_CODE(0xB1); + // Standard codes used in scan for reply + //static const ReturnValue_t TOO_SHORT = MAKE_RETURN_CODE(0xB1); static const ReturnValue_t CHECKSUM_ERROR = MAKE_RETURN_CODE(0xB2); static const ReturnValue_t LENGTH_MISSMATCH = MAKE_RETURN_CODE(0xB3); static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(0xB4); static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0xB5); - //standard codes used in interpret device reply + // Standard codes used in interpret device reply static const ReturnValue_t DEVICE_DID_NOT_EXECUTE = MAKE_RETURN_CODE(0xC1); //the device reported, that it did not execute the command static const ReturnValue_t DEVICE_REPORTED_ERROR = MAKE_RETURN_CODE(0xC2); static const ReturnValue_t UNKNOW_DEVICE_REPLY = MAKE_RETURN_CODE(0xC3); //the deviceCommandId reported by scanforReply is unknown static const ReturnValue_t DEVICE_REPLY_INVALID = MAKE_RETURN_CODE(0xC4); //syntax etc is correct but still not ok, eg parameters where none are expected - //Standard codes used in buildCommandFromCommand + // Standard codes used in buildCommandFromCommand static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE( 0xD0); static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = From a3903f80fb915a046eb69e1492254ef4e69b5987 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 19 Mar 2020 00:49:47 +0100 Subject: [PATCH 0121/1774] typedef address_t moved to deviceComIF --- devicehandlers/Cookie.h | 8 ++++- devicehandlers/DeviceCommunicationIF.h | 41 +++++++++++++++++++------- devicehandlers/DeviceHandlerBase.h | 24 +++++++-------- rmap/RmapDeviceCommunicationIF.h | 6 ++-- 4 files changed, 52 insertions(+), 27 deletions(-) diff --git a/devicehandlers/Cookie.h b/devicehandlers/Cookie.h index 618c901ff..ec22ec3a5 100644 --- a/devicehandlers/Cookie.h +++ b/devicehandlers/Cookie.h @@ -2,7 +2,13 @@ #define COOKIE_H_ /** - * This datatype is used to identify different connection over a single interface (like RMAP or I2C) + * @brief This datatype is used to identify different connection over a single interface + * (like RMAP or I2C) + * @details + * To use this class, implement a communication specific child cookie. This cookie + * can be used in the device communication interface by performing + * a C++ dynamic cast. The cookie can be used to store all kinds of information + * about the communication between read and send calls. */ class Cookie{ public: diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 999045105..9b0e0a3a9 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -8,6 +8,11 @@ * @brief Communication interfaces for flight software objects */ +/** + * Physical address type + */ +typedef uint32_t address_t; + /** * @brief This is an interface to decouple device communication from * the device handler to allow reuse of these components. @@ -39,23 +44,36 @@ public: virtual ~DeviceCommunicationIF() {} - virtual ReturnValue_t open(Cookie **cookie, uint32_t address, + /** + * Open a connection. Define a communication specific cookie which can + * be used to store information about the communication. + * + * @param cookie [in/out] This data class stores information about the communication. + * @param address Logical device address + * @param maxReplyLen Maximum length of expected reply + * @return + */ + virtual ReturnValue_t open(Cookie **cookie, address_t address, uint32_t maxReplyLen) = 0; /** * Use an existing cookie to open a connection to a new DeviceCommunication. * The previous connection must not be closed. - * If the returnvalue is not RETURN_OK, the cookie is unchanged and - * can be used with the previous connection. * * @param cookie * @param address * @param maxReplyLen - * @return + * @return -@c RETURN_OK New communication set up successfully + * - Everything else: Cookie is unchanged and can be used with + * previous connection */ - virtual ReturnValue_t reOpen(Cookie *cookie, uint32_t address, + virtual ReturnValue_t reOpen(Cookie *cookie, address_t address, uint32_t maxReplyLen) = 0; + /** + * Closing call of connection. Don't forget to free memory of cookie. + * @param cookie + */ virtual void close(Cookie *cookie) = 0; /** @@ -65,16 +83,18 @@ public: * @param cookie * @param data * @param len - * @return @c RETURN_OK for successfull send - * Everything else triggers sending failed event with returnvalue as parameter 1 + * @return -@c RETURN_OK for successfull send + * -Everything else triggers sending failed event with + * returnvalue as parameter 1 */ - virtual ReturnValue_t sendMessage(Cookie *cookie,const uint8_t *data, + virtual ReturnValue_t sendMessage(Cookie *cookie, const uint8_t *data, uint32_t len) = 0; virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0; /** * Called by DHB in the SEND_WRITE doSendRead(). + * Instructs the Communication Interface to prepare * @param cookie * @return */ @@ -93,9 +113,9 @@ public: virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, uint32_t *size) = 0; - virtual ReturnValue_t setAddress(Cookie *cookie, uint32_t address) = 0; + virtual ReturnValue_t setAddress(Cookie *cookie, address_t address) = 0; - virtual uint32_t getAddress(Cookie *cookie) = 0; + virtual address_t getAddress(Cookie *cookie) = 0; /** * Can be used by DeviceHandlerBase getParameter() call to set DeviceComIF parameters @@ -112,7 +132,6 @@ public: * @return */ virtual uint32_t getParameter(Cookie *cookie) = 0; - }; #endif /* DEVICECOMMUNICATIONIF_H_ */ diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 53eaa7dd0..60e8888e2 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -33,28 +33,25 @@ class StorageManagerIF; * Contains all devices and the DeviceHandlerBase class. */ -/** - * Physical address type - */ -typedef uint32_t address_t; - /** * @brief This is the abstract base class for device handlers. * @details * Documentation: Dissertation Baetz p.138,139, p.141-149 * - * It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink, communication with - * physical devices, using the @link DeviceCommunicationIF @endlink, and communication with commanding objects. + * It features handling of @link DeviceHandlerIF::Mode_t Modes @endlink, + * communication with physical devices, using the @link DeviceCommunicationIF @endlink, + * and communication with commanding objects. * It inherits SystemObject and thus can be created by the ObjectManagerIF. * * This class uses the opcode of ExecutableObjectIF to perform a step-wise execution. * For each step an RMAP action is selected and executed. * If data has been received (GET_READ), the data will be interpreted. - * The action for each step can be defined by the child class but as most device handlers share a 4-call - * (sendRead-getRead-sendWrite-getWrite) structure, a default implementation is provided. - * NOTE: RMAP is a standard which is used for FLP. + * The action for each step can be defined by the child class but as most + * device handlers share a 4-call (sendRead-getRead-sendWrite-getWrite) structure, + * a default implementation is provided. NOTE: RMAP is a standard which is used for FLP. * RMAP communication is not mandatory for projects implementing the FSFW. - * However, the communication principles are similar to RMAP as there are two write and two send calls involved. + * However, the communication principles are similar to RMAP as there are + * two write and two send calls involved. * * Device handler instances should extend this class and implement the abstract functions. * Components and drivers can send so called cookies which are used for communication @@ -495,7 +492,8 @@ protected: DeviceCommunicationIF *communicationInterface; /** - * Cookie used for communication + * Cookie used for communication. This is passed to the communication + * interface. */ Cookie *cookie; @@ -910,7 +908,7 @@ private: /** * State a cookie is in. * - * Used to keep track of the state of the RMAP communication. + * Used to keep track of the state of the communication. */ enum CookieState_t { COOKIE_UNUSED, //!< The Cookie is unused diff --git a/rmap/RmapDeviceCommunicationIF.h b/rmap/RmapDeviceCommunicationIF.h index 12ae67e4a..45963d860 100644 --- a/rmap/RmapDeviceCommunicationIF.h +++ b/rmap/RmapDeviceCommunicationIF.h @@ -4,7 +4,8 @@ #include /** - * @brief This class is a implementation of a DeviceCommunicationIF for RMAP calls. It expects RMAPCookies or a derived class of RMAPCookies + * @brief This class is a implementation of a DeviceCommunicationIF for RMAP calls. + * It expects RMAPCookies or a derived class of RMAPCookies * * @details The open, close and reOpen calls are mission specific * The open call might return any child of RMAPCookies @@ -44,7 +45,8 @@ public: /** - * Closing call of connection and memory free of cookie. Mission dependent call + * Closing call of connection and free memory of cookie. + * Mission dependent call * @param cookie */ virtual void close(Cookie *cookie) = 0; From b7e3449b04c48ff65e6e21767667c328938701dd Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 19 Mar 2020 12:38:11 +0100 Subject: [PATCH 0122/1774] some more doc for containers --- container/ArrayList.h | 7 ++- container/FIFO.h | 5 ++ container/HybridIterator.h | 2 +- container/IndexedRingMemoryArray.h | 87 ++++++++++++++++++------------ container/SinglyLinkedList.h | 4 +- 5 files changed, 66 insertions(+), 39 deletions(-) diff --git a/container/ArrayList.h b/container/ArrayList.h index 59e5eef4a..57b2f94df 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -6,10 +6,9 @@ #include /** - * A List that stores its values in an array. - * - * The backend is an array that can be allocated by the class itself or supplied via ctor. - * + * @brief A List that stores its values in an array. + * @details The backend is an array that can be allocated + * by the class itself or supplied via ctor. * * @ingroup container */ diff --git a/container/FIFO.h b/container/FIFO.h index 134da9b80..00f56993a 100644 --- a/container/FIFO.h +++ b/container/FIFO.h @@ -3,6 +3,11 @@ #include +/** + * @brief Simple First-In-First-Out data structure + * @tparam T Entry Type + * @tparam capacity Maximum capacity + */ template class FIFO { private: diff --git a/container/HybridIterator.h b/container/HybridIterator.h index b34fdfd01..1c56aa13b 100644 --- a/container/HybridIterator.h +++ b/container/HybridIterator.h @@ -67,7 +67,7 @@ public: } bool operator==(HybridIterator other) { - return value == other->value; + return value == other.value; } bool operator!=(HybridIterator other) { diff --git a/container/IndexedRingMemoryArray.h b/container/IndexedRingMemoryArray.h index eacfe3e5d..4ab174f4b 100644 --- a/container/IndexedRingMemoryArray.h +++ b/container/IndexedRingMemoryArray.h @@ -8,20 +8,27 @@ #include #include +/** + * Index is the Type used for the list of indices. + * + * @tparam T Type which destribes the index. Needs to be a child of SerializeIF + * to be able to make it persistent + */ 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"); + static_assert(std::is_base_of::value, + "Wrong Type for Index, Type must implement SerializeIF"); public: 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){ + void setBlockStartAddress(uint32_t newAddress) { this->blockStartAddress = newAddress; } @@ -33,7 +40,7 @@ public: return &indexType; } - T* modifyIndexType(){ + T* modifyIndexType() { return &indexType; } /** @@ -128,26 +135,35 @@ private: }; - +/** + * @brief Indexed Ring Memory Array is a class for a ring memory with indices. + * @details + * 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 + * @tparam T + */ 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 + * */ 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 Size needeed for the index itself uint32_t serializedSize = 0; - if(additionalInfo!=NULL){ + if(additionalInfo!=NULL) { serializedSize += additionalInfo->getSerializedSize(); } + //Size of current iterator type Index tempIndex; serializedSize += tempIndex.getSerializedSize(); @@ -162,6 +178,7 @@ public: error << "IndexedRingMemory: Store is too small for index" << std::endl; } uint32_t useableSize = totalSize - serializedSize; + //Update the totalSize for calculations totalSize = useableSize; @@ -178,12 +195,10 @@ public: this->allocated = true; //Check trueNumberOfBlocks - if(trueNumberOfBlocks<1){ + 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) { @@ -193,7 +208,6 @@ public: address += bytesPerBlock; } - //Initialize iterators currentWriteBlock = this->begin(); currentReadBlock = this->begin(); @@ -232,10 +246,10 @@ public: (*typeResetFnc)(it->modifyIndexType()); } - /* + /** * Reading + * @param it */ - void setCurrentReadBlock(typename IndexedRingMemoryArray::Iterator it){ currentReadBlock = it; currentReadBlockSizeCached = it->getSize(); @@ -248,6 +262,7 @@ public: lastBlockToRead = currentWriteBlock; lastBlockToReadSize = currentWriteBlock->getSize(); } + /** * Sets the last block to read to this iterator. * Can be used to dump until block x @@ -292,33 +307,39 @@ public: 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 + * 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){ + if(currentReadBlock == lastBlockToRead) { //The current read block is the last to read - if((currentReadSize+readSize) return true currentReadSize += readSize; return true; - }else{ + } + else { //Reached end of read -> return false currentReadSize = lastBlockToReadSize; return false; } - }else{ + } + 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 @@ -421,13 +442,13 @@ public: 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 @@ -436,7 +457,10 @@ public: bool hasCurrentWriteBlockEnoughSpace(uint32_t sizeToWrite){ typename IndexedRingMemoryArray::Iterator next = getNextWrite(); uint32_t addressOfNextBlock = next->getBlockStartAddress(); - uint32_t availableSize = ((addressOfNextBlock+totalSize) - (getAddressOfCurrentWriteBlock()+getSizeOfCurrentWriteBlock()))%totalSize; + uint32_t availableSize = + ( ( addressOfNextBlock + totalSize ) - + (getAddressOfCurrentWriteBlock() + getSizeOfCurrentWriteBlock())) + % totalSize; return (sizeToWrite < availableSize); } @@ -694,7 +718,4 @@ private: }; - - - #endif /* FRAMEWORK_CONTAINER_INDEXEDRINGMEMORY_H_ */ diff --git a/container/SinglyLinkedList.h b/container/SinglyLinkedList.h index 5c9de6cfe..b926bd007 100644 --- a/container/SinglyLinkedList.h +++ b/container/SinglyLinkedList.h @@ -4,7 +4,9 @@ #include #include /** - * \ingroup container + * @brief Linked list data structure, + * each entry has a pointer to the next entry (singly) + * @ingroup container */ template class LinkedElement { From 52c05e2f3da8043336f77deba36e1fefa53e61fd Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 19 Mar 2020 12:44:24 +0100 Subject: [PATCH 0123/1774] minor formatting for pull request --- container/ArrayList.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/container/ArrayList.h b/container/ArrayList.h index 57b2f94df..f978c984d 100644 --- a/container/ArrayList.h +++ b/container/ArrayList.h @@ -223,7 +223,6 @@ public: return (maxSize_ - size); } - private: /** * This is the copy constructor @@ -236,6 +235,7 @@ private: ArrayList(const ArrayList& other) : size(other.size), entries(other.entries), maxSize_(other.maxSize_), allocated(false) {} + protected: /** * pointer to the array in which the entries are stored @@ -269,6 +269,6 @@ protected: ++i; } } - }; + #endif /* ARRAYLIST_H_ */ From af6d18d60b323ea2759e1ca5af5980bd25673015 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 20 Mar 2020 22:47:07 +0100 Subject: [PATCH 0124/1774] added additional parameter form open/reopen call --- devicehandlers/DeviceCommunicationIF.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 9b0e0a3a9..4f98dd6d6 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -54,7 +54,7 @@ public: * @return */ virtual ReturnValue_t open(Cookie **cookie, address_t address, - uint32_t maxReplyLen) = 0; + uint32_t maxReplyLen, uint32_t comParameter = 0) = 0; /** * Use an existing cookie to open a connection to a new DeviceCommunication. @@ -68,7 +68,7 @@ public: * previous connection */ virtual ReturnValue_t reOpen(Cookie *cookie, address_t address, - uint32_t maxReplyLen) = 0; + uint32_t maxReplyLen, uint32_t comParameter = 0) = 0; /** * Closing call of connection. Don't forget to free memory of cookie. From c50d9d90d61a727ddc90e64d75ee98a4d3679bd0 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 23 Mar 2020 13:14:23 +0100 Subject: [PATCH 0125/1774] replaced std::variant by two uint32 parameters --- devicehandlers/DeviceCommunicationIF.h | 18 ++++---- devicehandlers/DeviceHandlerBase.cpp | 6 +-- devicehandlers/DeviceHandlerBase.h | 61 ++++++++++++++++---------- devicehandlers/DeviceHandlerIF.h | 32 +++++++++++++- 4 files changed, 82 insertions(+), 35 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 4f98dd6d6..1e307b6c0 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -2,17 +2,13 @@ #define DEVICECOMMUNICATIONIF_H_ #include +#include #include /** * @defgroup interfaces Interfaces * @brief Communication interfaces for flight software objects */ -/** - * Physical address type - */ -typedef uint32_t address_t; - /** * @brief This is an interface to decouple device communication from * the device handler to allow reuse of these components. @@ -47,14 +43,20 @@ public: /** * Open a connection. Define a communication specific cookie which can * be used to store information about the communication. + * The two optional parameter provide additional flexibility to + * set up the communication interface as desired. If there are a lot of + * variables to set, a store ID to the parameters stored in the IPC store + * can also be passed. * - * @param cookie [in/out] This data class stores information about the communication. + * @param cookie [out] This data class stores information about the communication. * @param address Logical device address * @param maxReplyLen Maximum length of expected reply + * @param comParameter1 Arbitrary parameter which can be used to set up the cookie or comIF. + * @param comParameter2 Arbitrary parameter which can be used to set up the cookie or comIF. * @return */ virtual ReturnValue_t open(Cookie **cookie, address_t address, - uint32_t maxReplyLen, uint32_t comParameter = 0) = 0; + uint32_t maxReplyLen, uint32_t comParameter1, uint32_t comParameter2) = 0; /** * Use an existing cookie to open a connection to a new DeviceCommunication. @@ -68,7 +70,7 @@ public: * previous connection */ virtual ReturnValue_t reOpen(Cookie *cookie, address_t address, - uint32_t maxReplyLen, uint32_t comParameter = 0) = 0; + uint32_t maxReplyLen, uint32_t comParameter1, uint32_t comParameter2) = 0; /** * Closing call of connection. Don't forget to free memory of cookie. diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index e7b4c6844..ca883e837 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -106,7 +106,7 @@ ReturnValue_t DeviceHandlerBase::initialize() { } result = communicationInterface->open(&cookie, logicalAddress, - maxDeviceReplyLen); + maxDeviceReplyLen, comParameter1, comParameter2); if (result != RETURN_OK) { return result; } @@ -691,7 +691,7 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len, //Default child implementations -DeviceHandlerBase::RmapAction_t DeviceHandlerBase::getRmapAction() { +DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getRmapAction() { switch (pstStep) { case 0: return SEND_WRITE; @@ -757,7 +757,7 @@ ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) { if (newCommunication != NULL) { ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress, - maxDeviceReplyLen); + maxDeviceReplyLen, comParameter1, comParameter2); if (result != RETURN_OK) { return result; } diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 60e8888e2..868412edf 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -418,6 +418,22 @@ protected: */ uint32_t rawPacketLen; +// /** +// * This union (or std::variant) type can be used to set comParameters which +// * are passed in the open() and reOpen() calls to the communication +// * interface +// * TODO: I don't know if we should use C++17 features but if we do we propably +// * should also write a function to get either a storeId handle +// * or an array handle so these values can be set conveniently. +// * The good think is that if there are many parameters, they can +// * be stored in the IPC pool. But maybe two uint32_t parameters are enough. +// * Simple = Good. It is downwards compatible and one can still store +// * 4 bytes of parameters AND a store ID. +// */ +// comParameters_t comParameters; + uint32_t comParameter1 = 0; + uint32_t comParameter2 = 0; + /** * The mode the device handler is currently in. * @@ -548,6 +564,28 @@ protected: static object_id_t rawDataReceiverId; //!< Object which receives RAW data by default. static object_id_t defaultFDIRParentId; //!< Object which may be the root cause of an identified fault. + + /** + * Set the device handler mode + * + * Sets #timeoutStart with every call. + * + * Sets #transitionTargetMode if necessary so transitional states can be entered from everywhere without breaking the state machine + * (which relies on a correct #transitionTargetMode). + * + * The submode is left unchanged. + * + * + * @param newMode + */ + void setMode(Mode_t newMode); + + /** + * @overload + * @param submode + */ + void setMode(Mode_t newMode, Submode_t submode); + /** * Helper function to report a missed reply * @@ -576,27 +614,6 @@ protected: */ void replyToCommand(ReturnValue_t status, uint32_t parameter = 0); - /** - * Set the device handler mode - * - * Sets #timeoutStart with every call. - * - * Sets #transitionTargetMode if necessary so transitional states can be entered from everywhere without breaking the state machine - * (which relies on a correct #transitionTargetMode). - * - * The submode is left unchanged. - * - * - * @param newMode - */ - void setMode(Mode_t newMode); - - /** - * @overload - * @param submode - */ - void setMode(Mode_t newMode, Submode_t submode); - /** * Do the transition to the main modes (MODE_ON, MODE_NORMAL and MODE_RAW). * @@ -645,7 +662,7 @@ protected: * * @return The Rmap action to execute in this step */ - virtual RmapAction_t getRmapAction(); + virtual CommunicationAction_t getRmapAction(); /** * Build the device command to send for raw mode. diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index cce403493..c453e7e87 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -7,6 +7,33 @@ #include #include +#if __cplusplus >= 201703L +#include +#include +#endif + +/** + * Physical address type + */ +typedef uint32_t address_t; + +///** +// * This type safe union cold be used if C++17 or newer is used to transfer +// * comIF settings to the communication interface object. +// */ +// +//#if __cplusplus >= 201703L +//using comParameterArray_t = std::array; +//using comParameters_t = std::variant; +//#else +//using comParameters_t = union comParameters { +// comParameters() = default; +// comParameters(uint32_t initValue): storeIdRaw(initValue) {} +// uint32_t storeIdRaw; +// uint8_t comParameter[4]; +// }; +//#endif + /** * This is the Interface used to communicate with a device handler. * @@ -87,17 +114,18 @@ public: MAKE_RETURN_CODE(0xD1); /** - * RMAP Action that will be executed. + * Communication action that will be executed. * * This is used by the child class to tell the base class what to do. */ - enum RmapAction_t { + enum CommunicationAction_t: uint8_t { SEND_WRITE,//!< RMAP send write GET_WRITE, //!< RMAP get write SEND_READ, //!< RMAP send read GET_READ, //!< RMAP get read NOTHING //!< Do nothing. }; + /** * Default Destructor */ From d3e2652078913332c407845920b14cd0c5e459a6 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 23 Mar 2020 17:58:23 +0100 Subject: [PATCH 0126/1774] replaced DHB sizes by size_t, rework Cookie now passed to DHB, rework in progress --- action/ActionHelper.cpp | 2 +- action/CommandActionHelper.cpp | 2 +- action/SimpleActionHelper.cpp | 2 +- datapool/DataPoolAdmin.cpp | 2 +- devicehandlers/ChildHandlerBase.cpp | 15 ++-- devicehandlers/ChildHandlerBase.h | 12 +-- devicehandlers/Cookie.cpp | 24 ++++++ devicehandlers/Cookie.h | 21 ++++- devicehandlers/DeviceCommunicationIF.h | 103 +++++++----------------- devicehandlers/DeviceHandlerBase.cpp | 92 +++++++++++---------- devicehandlers/DeviceHandlerBase.h | 56 +++++++------ devicehandlers/DeviceHandlerMessage.cpp | 4 +- devicehandlers/DeviceHandlerMessage.h | 2 +- memory/MemoryHelper.cpp | 2 +- osal/FreeRTOS/BinarySemaphore.cpp | 4 +- parameters/ParameterHelper.cpp | 2 +- storagemanager/LocalPool.h | 8 +- storagemanager/StorageManagerIF.h | 4 +- subsystem/Subsystem.cpp | 4 +- tcdistribution/CCSDSDistributor.cpp | 2 +- tmtcpacket/pus/TcPacketStored.cpp | 4 +- tmtcpacket/pus/TmPacketStored.cpp | 2 +- tmtcservices/TmTcBridge.cpp | 4 +- 23 files changed, 186 insertions(+), 187 deletions(-) create mode 100644 devicehandlers/Cookie.cpp diff --git a/action/ActionHelper.cpp b/action/ActionHelper.cpp index 9c1475f12..18e46fba9 100644 --- a/action/ActionHelper.cpp +++ b/action/ActionHelper.cpp @@ -49,7 +49,7 @@ void ActionHelper::setQueueToUse(MessageQueueIF* queue) { void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId, store_address_t dataAddress) { const uint8_t* dataPtr = NULL; - uint32_t size = 0; + size_t size = 0; ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size); if (result != HasReturnvaluesIF::RETURN_OK) { CommandMessage reply; diff --git a/action/CommandActionHelper.cpp b/action/CommandActionHelper.cpp index 05eb93461..ceb97d3b9 100644 --- a/action/CommandActionHelper.cpp +++ b/action/CommandActionHelper.cpp @@ -113,7 +113,7 @@ uint8_t CommandActionHelper::getCommandCount() const { void CommandActionHelper::extractDataForOwner(ActionId_t actionId, store_address_t storeId) { const uint8_t * data = NULL; - uint32_t size = 0; + size_t size = 0; ReturnValue_t result = ipcStore->getData(storeId, &data, &size); if (result != HasReturnvaluesIF::RETURN_OK) { return; diff --git a/action/SimpleActionHelper.cpp b/action/SimpleActionHelper.cpp index 6de372fbf..6861fc28c 100644 --- a/action/SimpleActionHelper.cpp +++ b/action/SimpleActionHelper.cpp @@ -44,7 +44,7 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy, queueToUse->sendMessage(commandedBy, &reply); } const uint8_t* dataPtr = NULL; - uint32_t size = 0; + size_t size = 0; ReturnValue_t result = ipcStore->getData(dataAddress, &dataPtr, &size); if (result != HasReturnvaluesIF::RETURN_OK) { ActionMessage::setStepReply(&reply, actionId, 0, result); diff --git a/datapool/DataPoolAdmin.cpp b/datapool/DataPoolAdmin.cpp index fe6b92152..99d2b51b2 100644 --- a/datapool/DataPoolAdmin.cpp +++ b/datapool/DataPoolAdmin.cpp @@ -215,7 +215,7 @@ ReturnValue_t DataPoolAdmin::handleParameterCommand(CommandMessage* command) { ParameterMessage::getParameterId(command)); const uint8_t *storedStream; - uint32_t storedStreamSize; + size_t storedStreamSize; result = storage->getData(ParameterMessage::getStoreId(command), &storedStream, &storedStreamSize); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/devicehandlers/ChildHandlerBase.cpp b/devicehandlers/ChildHandlerBase.cpp index 50a5c07e5..a0630fc64 100644 --- a/devicehandlers/ChildHandlerBase.cpp +++ b/devicehandlers/ChildHandlerBase.cpp @@ -2,15 +2,16 @@ #include #include -ChildHandlerBase::ChildHandlerBase(uint32_t ioBoardAddress, - object_id_t setObjectId, object_id_t deviceCommunication, +ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, address_t logicalAddress, + object_id_t deviceCommunication, Cookie * cookie, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, - uint32_t parent, FailureIsolationBase* customFdir, uint32_t cmdQueueSize) : - DeviceHandlerBase(ioBoardAddress, setObjectId, maxDeviceReplyLen, - setDeviceSwitch, deviceCommunication, thermalStatePoolId, - thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir), cmdQueueSize), parentId( - parent), childHandlerFdir(setObjectId) { + uint32_t parent, FailureIsolationBase* customFdir, size_t cmdQueueSize) : + DeviceHandlerBase(setObjectId, logicalAddress, deviceCommunication, cookie, + maxDeviceReplyLen, setDeviceSwitch, thermalStatePoolId, + thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir), + cmdQueueSize), + parentId(parent), childHandlerFdir(setObjectId) { } ChildHandlerBase::~ChildHandlerBase() { diff --git a/devicehandlers/ChildHandlerBase.h b/devicehandlers/ChildHandlerBase.h index 3879f66fe..4e9eee493 100644 --- a/devicehandlers/ChildHandlerBase.h +++ b/devicehandlers/ChildHandlerBase.h @@ -6,12 +6,12 @@ class ChildHandlerBase: public DeviceHandlerBase { public: - ChildHandlerBase(uint32_t ioBoardAddress, object_id_t setObjectId, - object_id_t deviceCommunication, uint32_t maxDeviceReplyLen, - uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, - uint32_t thermalRequestPoolId, uint32_t parent, - FailureIsolationBase* customFdir = NULL, - uint32_t cmdQueueSize = 20); + ChildHandlerBase(object_id_t setObjectId, uint32_t logicalAddress, + object_id_t deviceCommunication, Cookie * cookie, + uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, + uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, + uint32_t parent, FailureIsolationBase* customFdir = nullptr, + size_t cmdQueueSize = 20); virtual ~ChildHandlerBase(); virtual ReturnValue_t initialize(); diff --git a/devicehandlers/Cookie.cpp b/devicehandlers/Cookie.cpp new file mode 100644 index 000000000..f0748b5d5 --- /dev/null +++ b/devicehandlers/Cookie.cpp @@ -0,0 +1,24 @@ +/** + * @file Cookie.cpp + * + * @date 23.03.2020 + */ +#include + +//Cookie::Cookie(address_t logicalAddress_, size_t maxReplyLen_): +// logicalAddress(logicalAddress_), maxReplyLen(maxReplyLen_){} + +Cookie::Cookie(address_t logicalAddress_): logicalAddress(logicalAddress_) { +} + +void Cookie::setMaxReplyLen(size_t maxReplyLen_) { + maxReplyLen = maxReplyLen_; +} + +address_t Cookie::getAddress() const { + return logicalAddress; +} + +size_t Cookie::getMaxReplyLen() const { + return maxReplyLen; +} diff --git a/devicehandlers/Cookie.h b/devicehandlers/Cookie.h index ec22ec3a5..60f20ff19 100644 --- a/devicehandlers/Cookie.h +++ b/devicehandlers/Cookie.h @@ -1,5 +1,6 @@ #ifndef COOKIE_H_ #define COOKIE_H_ +#include /** * @brief This datatype is used to identify different connection over a single interface @@ -7,13 +8,27 @@ * @details * To use this class, implement a communication specific child cookie. This cookie * can be used in the device communication interface by performing - * a C++ dynamic cast. The cookie can be used to store all kinds of information - * about the communication between read and send calls. + * a C++ dynamic cast and passing it to a child device handler, which stores + * it and passes the Cookie to the communication interface where it can be used + * by again performing a dynamic cast. + * The cookie can be used to store all kinds of information + * about the communication, like slave addresses, communication status, + * communication parameters etc. + * @ingroup comm */ class Cookie{ public: + Cookie() = default; + Cookie(address_t logicalAddress_); virtual ~Cookie(){} + + void setMaxReplyLen(size_t maxReplyLen_); + + address_t getAddress() const; + size_t getMaxReplyLen() const; +private: + address_t logicalAddress = 0; + size_t maxReplyLen = 0; }; - #endif /* COOKIE_H_ */ diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 1e307b6c0..43aa7965b 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -6,7 +6,12 @@ #include /** * @defgroup interfaces Interfaces - * @brief Communication interfaces for flight software objects + * @brief Interfaces for flight software objects + */ + +/** + * @defgroup communication comm + * @brief Communication software components. */ /** @@ -22,9 +27,12 @@ * 3. Request reading data from a device * 4. Read received data * - * To identify different connection over a single interface can return so-called cookies to components. + * To identify different connection over a single interface can return + * so-called cookies to components. * The CommunicationMessage message type can be used to extend the functionality of the * ComIF if a separate polling task is required. + * @ingroup interfaces + * @ingroup comm */ class DeviceCommunicationIF: public HasReturnvaluesIF { public: @@ -32,52 +40,12 @@ public: static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x01); static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x02); - static const ReturnValue_t INVALID_ADDRESS = MAKE_RETURN_CODE(0x03); - static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x04); - static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x05); - static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x06); - static const ReturnValue_t CANT_CHANGE_REPLY_LEN = MAKE_RETURN_CODE(0x07); + static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x03); + static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x04); + static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x05); virtual ~DeviceCommunicationIF() {} - /** - * Open a connection. Define a communication specific cookie which can - * be used to store information about the communication. - * The two optional parameter provide additional flexibility to - * set up the communication interface as desired. If there are a lot of - * variables to set, a store ID to the parameters stored in the IPC store - * can also be passed. - * - * @param cookie [out] This data class stores information about the communication. - * @param address Logical device address - * @param maxReplyLen Maximum length of expected reply - * @param comParameter1 Arbitrary parameter which can be used to set up the cookie or comIF. - * @param comParameter2 Arbitrary parameter which can be used to set up the cookie or comIF. - * @return - */ - virtual ReturnValue_t open(Cookie **cookie, address_t address, - uint32_t maxReplyLen, uint32_t comParameter1, uint32_t comParameter2) = 0; - - /** - * Use an existing cookie to open a connection to a new DeviceCommunication. - * The previous connection must not be closed. - * - * @param cookie - * @param address - * @param maxReplyLen - * @return -@c RETURN_OK New communication set up successfully - * - Everything else: Cookie is unchanged and can be used with - * previous connection - */ - virtual ReturnValue_t reOpen(Cookie *cookie, address_t address, - uint32_t maxReplyLen, uint32_t comParameter1, uint32_t comParameter2) = 0; - - /** - * Closing call of connection. Don't forget to free memory of cookie. - * @param cookie - */ - virtual void close(Cookie *cookie) = 0; - /** * Called by DHB in the SEND_WRITE doSendWrite(). * This function is used to send data to the physical device @@ -86,21 +54,29 @@ public: * @param data * @param len * @return -@c RETURN_OK for successfull send - * -Everything else triggers sending failed event with - * returnvalue as parameter 1 + * - Everything else triggers sending failed event with + * returnvalue as parameter 1 */ - virtual ReturnValue_t sendMessage(Cookie *cookie, const uint8_t *data, - uint32_t len) = 0; + virtual ReturnValue_t sendMessage(Cookie *cookie, const uint8_t * sendData, + size_t sendLen) = 0; + /** + * Called by DHB in the GET_WRITE doGetWrite(). + * Get send confirmation that the data in sendMessage() was sent successfully. + * @param cookie + * @return -@c RETURN_OK if data was sent successfull + * - Everything else triggers sending failed event with + * returnvalue as parameter 1 + */ virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0; /** * Called by DHB in the SEND_WRITE doSendRead(). - * Instructs the Communication Interface to prepare + * Request a reply. * @param cookie * @return */ - virtual ReturnValue_t requestReceiveMessage(Cookie *cookie) = 0; + virtual ReturnValue_t requestReceiveMessage(Cookie *cookie, size_t requestLen) = 0; /** * Called by DHB in the GET_WRITE doGetRead(). @@ -110,30 +86,11 @@ public: * @param data * @param len * @return @c RETURN_OK for successfull receive - * Everything else triggers receiving failed with returnvalue as parameter 1 + * - Everything else triggers receiving failed with + * returnvalue as parameter 1 */ virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, - uint32_t *size) = 0; - - virtual ReturnValue_t setAddress(Cookie *cookie, address_t address) = 0; - - virtual address_t getAddress(Cookie *cookie) = 0; - - /** - * Can be used by DeviceHandlerBase getParameter() call to set DeviceComIF parameters - * @param cookie - * @param parameter - * @return - */ - virtual ReturnValue_t setParameter(Cookie *cookie, uint32_t parameter) = 0; - - /** - * Can be used by DeviceHandlerBase getParameter() call to set DeviceComIF parameters - * @param cookie - * @param parameter - * @return - */ - virtual uint32_t getParameter(Cookie *cookie) = 0; + size_t *size) = 0; }; #endif /* DEVICECOMMUNICATIONIF_H_ */ diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index ca883e837..5834db2f5 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -16,37 +16,34 @@ object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; -DeviceHandlerBase::DeviceHandlerBase(uint32_t logicalAddress_, - object_id_t setObjectId, uint32_t maxDeviceReplyLen, - uint8_t setDeviceSwitch, object_id_t deviceCommunication, - uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, - FailureIsolationBase* fdirInstance, uint32_t cmdQueueSize) : - SystemObject(setObjectId), rawPacket(0), rawPacketLen(0), mode(MODE_OFF), - submode(SUBMODE_NONE), pstStep(0), maxDeviceReplyLen(maxDeviceReplyLen), - wiretappingMode(OFF), defaultRawReceiver(0), storedRawData(StorageManagerIF::INVALID_ADDRESS), - requestedRawTraffic(0), powerSwitcher(NULL), IPCStore(NULL), - deviceCommunicationId(deviceCommunication), communicationInterface(NULL), - cookie(NULL), commandQueue(NULL), deviceThermalStatePoolId(thermalStatePoolId), - deviceThermalRequestPoolId(thermalRequestPoolId), healthHelper(this, setObjectId), - modeHelper(this), parameterHelper(this), childTransitionFailure(RETURN_OK), - ignoreMissedRepliesCount(0), fdirInstance(fdirInstance), hkSwitcher(this), - defaultFDIRUsed(fdirInstance == NULL), switchOffWasReported(false), - executingTask(NULL), actionHelper(this, NULL), cookieInfo(), logicalAddress(logicalAddress_), - timeoutStart(0), childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), - transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) +DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, + object_id_t deviceCommunication, Cookie * cookie_, size_t maxReplyLen, + uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, + FailureIsolationBase* fdirInstance, size_t cmdQueueSize) : + SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE), + wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS), + deviceCommunicationId(deviceCommunication), cookie(cookie_), + deviceThermalStatePoolId(thermalStatePoolId), deviceThermalRequestPoolId(thermalRequestPoolId), + healthHelper(this, setObjectId), modeHelper(this), parameterHelper(this), + fdirInstance(fdirInstance), hkSwitcher(this), + defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false), + executingTask(nullptr), actionHelper(this, nullptr), cookieInfo(), + logicalAddress(logicalAddress_), childTransitionDelay(5000), + transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), + deviceSwitch(setDeviceSwitch) { + this->cookie->setMaxReplyLen(maxReplyLen); commandQueue = QueueFactory::instance()-> createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); cookieInfo.state = COOKIE_UNUSED; insertInCommandMap(RAW_COMMAND_ID); - if (this->fdirInstance == NULL) { + if (this->fdirInstance == nullptr) { this->fdirInstance = new DeviceHandlerFailureIsolation(setObjectId, defaultFDIRParentId); } } DeviceHandlerBase::~DeviceHandlerBase() { - communicationInterface->close(cookie); if (defaultFDIRUsed) { delete fdirInstance; } @@ -105,11 +102,11 @@ ReturnValue_t DeviceHandlerBase::initialize() { return RETURN_FAILED; } - result = communicationInterface->open(&cookie, logicalAddress, - maxDeviceReplyLen, comParameter1, comParameter2); - if (result != RETURN_OK) { - return result; - } +// result = communicationInterface->open(&cookie, logicalAddress, +// maxDeviceReplyLen, comParameter1, comParameter2); +// if (result != RETURN_OK) { +// return result; +// } IPCStore = objectManager->get(objects::IPC_STORE); if (IPCStore == NULL) { @@ -551,7 +548,7 @@ void DeviceHandlerBase::doGetWrite() { void DeviceHandlerBase::doSendRead() { ReturnValue_t result; - result = communicationInterface->requestReceiveMessage(cookie); + result = communicationInterface->requestReceiveMessage(cookie, requestLen); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; } else { @@ -565,10 +562,10 @@ void DeviceHandlerBase::doSendRead() { } void DeviceHandlerBase::doGetRead() { - uint32_t receivedDataLen; + size_t receivedDataLen; uint8_t *receivedData; DeviceCommandId_t foundId = 0xFFFFFFFF; - uint32_t foundLen = 0; + size_t foundLen = 0; ReturnValue_t result; if (cookieInfo.state != COOKIE_READ_SENT) { @@ -639,8 +636,8 @@ void DeviceHandlerBase::doGetRead() { } ReturnValue_t DeviceHandlerBase::getStorageData(store_address_t storageAddress, - uint8_t * *data, uint32_t * len) { - uint32_t lenTmp; + uint8_t ** data, size_t * len) { + size_t lenTmp; if (IPCStore == NULL) { *data = NULL; @@ -751,20 +748,20 @@ void DeviceHandlerBase::handleReply(const uint8_t* receivedData, } } -ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) { - DeviceCommunicationIF *newCommunication = objectManager->get< - DeviceCommunicationIF>(newChannelId); - - if (newCommunication != NULL) { - ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress, - maxDeviceReplyLen, comParameter1, comParameter2); - if (result != RETURN_OK) { - return result; - } - return RETURN_OK; - } - return RETURN_FAILED; -} +//ReturnValue_t DeviceHandlerBase::switchCookieChannel(object_id_t newChannelId) { +// DeviceCommunicationIF *newCommunication = objectManager->get< +// DeviceCommunicationIF>(newChannelId); +// +// if (newCommunication != NULL) { +// ReturnValue_t result = newCommunication->reOpen(cookie, logicalAddress, +// maxDeviceReplyLen, comParameter1, comParameter2); +// if (result != RETURN_OK) { +// return result; +// } +// return RETURN_OK; +// } +// return RETURN_FAILED; +//} void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) { storedRawData = DeviceHandlerMessage::getStoreAddress(commandMessage); @@ -1048,12 +1045,13 @@ ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage( } replyReturnvalueToCommand(RETURN_OK); return RETURN_OK; - case DeviceHandlerMessage::CMD_SWITCH_IOBOARD: + case DeviceHandlerMessage::CMD_SWITCH_ADDRESS: if (mode != MODE_OFF) { replyReturnvalueToCommand(WRONG_MODE_FOR_COMMAND); } else { - result = switchCookieChannel( - DeviceHandlerMessage::getIoBoardObjectId(message)); + // rework in progress + //result = switchCookieChannel( + // DeviceHandlerMessage::getIoBoardObjectId(message)); if (result == RETURN_OK) { replyReturnvalueToCommand(RETURN_OK); } else { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 868412edf..e9288921d 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -29,7 +29,7 @@ void setStaticFrameworkObjectIds(); class StorageManagerIF; /** - * \defgroup devices Devices + * @defgroup devices Devices * Contains all devices and the DeviceHandlerBase class. */ @@ -93,12 +93,11 @@ public: * @param fdirInstance * @param cmdQueueSize */ - DeviceHandlerBase(address_t logicalAddress, object_id_t setObjectId, - uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, - object_id_t deviceCommunication, - uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, + DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, + object_id_t deviceCommunication, Cookie* cookie_, size_t maxReplyLen, + uint8_t setDeviceSwitch, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, - FailureIsolationBase* fdirInstance = NULL, uint32_t cmdQueueSize = 20); + FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20); /** * @brief This function is the device handler base core component and is called periodically. @@ -283,8 +282,8 @@ protected: * - @c DeviceHandlerIF::IGNORE_FULL_PACKET Ignore the packet * - @c APERIODIC_REPLY if a valid reply is received that has not been requested by a command, but should be handled anyway (@see also fillCommandAndCookieMap() ) */ - virtual ReturnValue_t scanForReply(const uint8_t *start, uint32_t len, - DeviceCommandId_t *foundId, uint32_t *foundLen) = 0; + virtual ReturnValue_t scanForReply(const uint8_t *start, size_t len, + DeviceCommandId_t *foundId, size_t *foundLen) = 0; /** * @brief Interpret a reply from the device. @@ -412,11 +411,16 @@ protected: /** * Pointer to the raw packet that will be sent. */ - uint8_t *rawPacket; + uint8_t *rawPacket = nullptr; /** * Size of the #rawPacket. */ - uint32_t rawPacketLen; + size_t rawPacketLen = 0; + + /** + * Size of data to request. + */ + size_t requestLen = 0; // /** // * This union (or std::variant) type can be used to set comParameters which @@ -431,8 +435,8 @@ protected: // * 4 bytes of parameters AND a store ID. // */ // comParameters_t comParameters; - uint32_t comParameter1 = 0; - uint32_t comParameter2 = 0; + // uint32_t comParameter1 = 0; + // uint32_t comParameter2 = 0; /** * The mode the device handler is currently in. @@ -451,12 +455,12 @@ protected: /** * This is the counter value from performOperation(). */ - uint8_t pstStep; + uint8_t pstStep = 0; /** * This will be used in the RMAP getRead command as expected length, is set by the constructor, can be modiefied at will. */ - const uint32_t maxDeviceReplyLen; + const uint32_t maxDeviceReplyLen = 0; /** * wiretapping flag: @@ -474,7 +478,7 @@ protected: * Statically initialized in initialize() to a configurable object. Used when there is no method * of finding a recipient, ie raw mode and reporting erreonous replies */ - MessageQueueId_t defaultRawReceiver; + MessageQueueId_t defaultRawReceiver = 0; store_address_t storedRawData; @@ -483,19 +487,19 @@ protected: * * if #isWiretappingActive all raw communication from and to the device will be sent to this queue */ - MessageQueueId_t requestedRawTraffic; + MessageQueueId_t requestedRawTraffic = 0; /** * the object used to set power switches */ - PowerSwitchIF *powerSwitcher; + PowerSwitchIF *powerSwitcher = nullptr; /** * Pointer to the IPCStore. * * This caches the pointer received from the objectManager in the constructor. */ - StorageManagerIF *IPCStore; + StorageManagerIF *IPCStore = nullptr; /** * cached for init @@ -505,7 +509,7 @@ protected: /** * Communication object used for device communication */ - DeviceCommunicationIF *communicationInterface; + DeviceCommunicationIF *communicationInterface = nullptr; /** * Cookie used for communication. This is passed to the communication @@ -516,7 +520,7 @@ protected: /** * The MessageQueue used to receive device handler commands and to send replies. */ - MessageQueueIF* commandQueue; + MessageQueueIF* commandQueue = nullptr; /** * this is the datapool variable with the thermal state of the device @@ -545,9 +549,9 @@ protected: * Optional Error code * Can be set in doStartUp(), doShutDown() and doTransition() to signal cause for Transition failure. */ - ReturnValue_t childTransitionFailure; + ReturnValue_t childTransitionFailure = RETURN_OK; - uint32_t ignoreMissedRepliesCount; //!< Counts if communication channel lost a reply, so some missed replys can be ignored. + uint32_t ignoreMissedRepliesCount = 0; //!< Counts if communication channel lost a reply, so some missed replys can be ignored. FailureIsolationBase* fdirInstance; //!< Pointer to the used FDIR instance. If not provided by child, default class is instantiated. @@ -962,7 +966,7 @@ private: * * Set when setMode() is called. */ - uint32_t timeoutStart; + uint32_t timeoutStart = 0; /** * Delay for the current mode transition, used for time out @@ -1084,8 +1088,8 @@ private: * - @c RETURN_FAILED IPCStore is NULL * - the return value from the IPCStore if it was not @c RETURN_OK */ - ReturnValue_t getStorageData(store_address_t storageAddress, uint8_t **data, - uint32_t *len); + ReturnValue_t getStorageData(store_address_t storageAddress, + uint8_t ** data, size_t * len); /** * set all switches returned by getSwitches() @@ -1114,7 +1118,7 @@ private: * - @c RETURN_FAILED when cookies could not be changed, eg because the newChannel is not enabled * - @c returnvalues of RMAPChannelIF::isActive() */ - ReturnValue_t switchCookieChannel(object_id_t newChannelId); + //ReturnValue_t switchCookieChannel(object_id_t newChannelId); /** * Handle device handler messages (e.g. commands sent by PUS Service 2) diff --git a/devicehandlers/DeviceHandlerMessage.cpp b/devicehandlers/DeviceHandlerMessage.cpp index 58a6d3126..97abcac52 100644 --- a/devicehandlers/DeviceHandlerMessage.cpp +++ b/devicehandlers/DeviceHandlerMessage.cpp @@ -47,7 +47,7 @@ void DeviceHandlerMessage::setDeviceHandlerWiretappingMessage( void DeviceHandlerMessage::setDeviceHandlerSwitchIoBoardMessage( CommandMessage* message, uint32_t ioBoardIdentifier) { - message->setCommand(CMD_SWITCH_IOBOARD); + message->setCommand(CMD_SWITCH_ADDRESS); message->setParameter(ioBoardIdentifier); } @@ -90,7 +90,7 @@ void DeviceHandlerMessage::clear(CommandMessage* message) { } } /* NO BREAK falls through*/ - case CMD_SWITCH_IOBOARD: + case CMD_SWITCH_ADDRESS: case CMD_WIRETAPPING: message->setCommand(CommandMessage::CMD_NONE); message->setParameter(0); diff --git a/devicehandlers/DeviceHandlerMessage.h b/devicehandlers/DeviceHandlerMessage.h index fad0f1b1c..c91bb0a4c 100644 --- a/devicehandlers/DeviceHandlerMessage.h +++ b/devicehandlers/DeviceHandlerMessage.h @@ -28,7 +28,7 @@ public: static const uint8_t MESSAGE_ID = MESSAGE_TYPE::DEVICE_HANDLER_COMMAND; static const Command_t CMD_RAW = MAKE_COMMAND_ID( 1 ); //!< Sends a raw command, setParameter is a ::store_id_t containing the raw packet to send // static const Command_t CMD_DIRECT = MAKE_COMMAND_ID( 2 ); //!< Sends a direct command, setParameter is a ::DeviceCommandId_t, setParameter2 is a ::store_id_t containing the data needed for the command - static const Command_t CMD_SWITCH_IOBOARD = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier + static const Command_t CMD_SWITCH_ADDRESS = MAKE_COMMAND_ID( 3 ); //!< Requests a IO-Board switch, setParameter() is the IO-Board identifier static const Command_t CMD_WIRETAPPING = MAKE_COMMAND_ID( 4 ); //!< (De)Activates the monitoring of all raw traffic in DeviceHandlers, setParameter is 0 to deactivate, 1 to activate /*static const Command_t REPLY_SWITCHED_IOBOARD = MAKE_COMMAND_ID(1 );//!< Reply to a @c CMD_SWITCH_IOBOARD, indicates switch was successful, getParameter() contains the board switched to (0: nominal, 1: redundant) diff --git a/memory/MemoryHelper.cpp b/memory/MemoryHelper.cpp index 4905875e7..9bebb597a 100644 --- a/memory/MemoryHelper.cpp +++ b/memory/MemoryHelper.cpp @@ -152,7 +152,7 @@ void MemoryHelper::handleMemoryLoad(CommandMessage* message) { ipcAddress = MemoryMessage::getStoreID(message); const uint8_t* p_data = NULL; uint8_t* dataPointer = NULL; - uint32_t size = 0; + size_t size = 0; ReturnValue_t returnCode = ipcStore->getData(ipcAddress, &p_data, &size); if (returnCode == RETURN_OK) { returnCode = workOnThis->handleMemoryLoad(address, p_data, size, diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index d429f1a07..4ec61ff7a 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -11,7 +11,7 @@ #include "task.h" BinarySemaphore::BinarySemaphore() { - vSemaphoreCreateBinary(handle); + xSemaphoreCreateBinary(handle); // @suppress("Function cannot be resolved") if(handle == NULL) { error << "Binary semaphore creation failure" << std::endl; } @@ -81,7 +81,7 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) void BinarySemaphore::resetSemaphore() { vSemaphoreDelete(handle); - vSemaphoreCreateBinary(handle); + xSemaphoreCreateBinary(handle); } ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, diff --git a/parameters/ParameterHelper.cpp b/parameters/ParameterHelper.cpp index 6ebc9e629..e260465ae 100644 --- a/parameters/ParameterHelper.cpp +++ b/parameters/ParameterHelper.cpp @@ -37,7 +37,7 @@ ReturnValue_t ParameterHelper::handleParameterMessage(CommandMessage *message) { ParameterMessage::getParameterId(message)); const uint8_t *storedStream; - uint32_t storedStreamSize; + size_t storedStreamSize; result = storage->getData( ParameterMessage::getStoreId(message), &storedStream, &storedStreamSize); diff --git a/storagemanager/LocalPool.h b/storagemanager/LocalPool.h index f6d5ba8ac..c2fab82b6 100644 --- a/storagemanager/LocalPool.h +++ b/storagemanager/LocalPool.h @@ -100,7 +100,7 @@ public: * @return @c RETURN_OK if data retrieval was successfull */ ReturnValue_t getData(store_address_t packet_id, const uint8_t** packet_ptr, - uint32_t* size); + size_t * size); /** * Modify data by supplying a packet pointer and using that packet pointer @@ -111,7 +111,7 @@ public: * @return */ ReturnValue_t modifyData(store_address_t packet_id, uint8_t** packet_ptr, - uint32_t* size); + size_t * size); virtual ReturnValue_t deleteData(store_address_t); virtual ReturnValue_t deleteData(uint8_t* ptr, uint32_t size, store_address_t* storeId = NULL); @@ -348,7 +348,7 @@ inline ReturnValue_t LocalPool::getFreeElement( template inline ReturnValue_t LocalPool::getData( - store_address_t packet_id, const uint8_t** packet_ptr, uint32_t* size) { + store_address_t packet_id, const uint8_t** packet_ptr, size_t * size) { uint8_t* tempData = NULL; ReturnValue_t status = modifyData(packet_id, &tempData, size); *packet_ptr = tempData; @@ -357,7 +357,7 @@ inline ReturnValue_t LocalPool::getData( template inline ReturnValue_t LocalPool::modifyData(store_address_t packet_id, - uint8_t** packet_ptr, uint32_t* size) { + uint8_t** packet_ptr, size_t * size) { ReturnValue_t status = RETURN_FAILED; if (packet_id.pool_index >= NUMBER_OF_POOLS) { return ILLEGAL_STORAGE_ID; diff --git a/storagemanager/StorageManagerIF.h b/storagemanager/StorageManagerIF.h index 575e9caa4..e8d8b413a 100644 --- a/storagemanager/StorageManagerIF.h +++ b/storagemanager/StorageManagerIF.h @@ -125,12 +125,12 @@ public: * (e.g. an illegal packet_id was passed). */ virtual ReturnValue_t getData(store_address_t packet_id, - const uint8_t** packet_ptr, uint32_t* size) = 0; + const uint8_t** packet_ptr, size_t * size) = 0; /** * Same as above, but not const and therefore modifiable. */ virtual ReturnValue_t modifyData(store_address_t packet_id, - uint8_t** packet_ptr, uint32_t* size) = 0; + uint8_t** packet_ptr, size_t * size) = 0; /** * This method reserves an element of \c size. * diff --git a/subsystem/Subsystem.cpp b/subsystem/Subsystem.cpp index e1ec544b0..2d7d9c443 100644 --- a/subsystem/Subsystem.cpp +++ b/subsystem/Subsystem.cpp @@ -162,7 +162,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) { case ModeSequenceMessage::ADD_SEQUENCE: { FixedArrayList sequence; const uint8_t *pointer; - uint32_t sizeRead; + size_t sizeRead; result = IPCStore->getData( ModeSequenceMessage::getStoreAddress(message), &pointer, &sizeRead); @@ -188,7 +188,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) { case ModeSequenceMessage::ADD_TABLE: { FixedArrayList table; const uint8_t *pointer; - uint32_t sizeRead; + size_t sizeRead; result = IPCStore->getData( ModeSequenceMessage::getStoreAddress(message), &pointer, &sizeRead); diff --git a/tcdistribution/CCSDSDistributor.cpp b/tcdistribution/CCSDSDistributor.cpp index ecd7702e6..878b8f7d5 100644 --- a/tcdistribution/CCSDSDistributor.cpp +++ b/tcdistribution/CCSDSDistributor.cpp @@ -13,7 +13,7 @@ CCSDSDistributor::~CCSDSDistributor() { iterator_t CCSDSDistributor::selectDestination() { // debug << "CCSDSDistributor::selectDestination received: " << this->currentMessage.getStorageId().pool_index << ", " << this->currentMessage.getStorageId().packet_index << std::endl; const uint8_t* p_packet = NULL; - uint32_t size = 0; + size_t size = 0; //TODO check returncode? this->tcStore->getData( this->currentMessage.getStorageId(), &p_packet, &size ); SpacePacketBase current_packet( p_packet ); diff --git a/tmtcpacket/pus/TcPacketStored.cpp b/tmtcpacket/pus/TcPacketStored.cpp index 1f31a7638..4bfd0e37e 100644 --- a/tmtcpacket/pus/TcPacketStored.cpp +++ b/tmtcpacket/pus/TcPacketStored.cpp @@ -59,7 +59,7 @@ bool TcPacketStored::checkAndSetStore() { void TcPacketStored::setStoreAddress(store_address_t setAddress) { this->storeAddress = setAddress; const uint8_t* temp_data = NULL; - uint32_t temp_size; + size_t temp_size; ReturnValue_t status = StorageManagerIF::RETURN_FAILED; if (this->checkAndSetStore()) { status = this->store->getData(this->storeAddress, &temp_data, @@ -79,7 +79,7 @@ store_address_t TcPacketStored::getStoreAddress() { bool TcPacketStored::isSizeCorrect() { const uint8_t* temp_data = NULL; - uint32_t temp_size; + size_t temp_size; ReturnValue_t status = this->store->getData(this->storeAddress, &temp_data, &temp_size); if (status == StorageManagerIF::RETURN_OK) { diff --git a/tmtcpacket/pus/TmPacketStored.cpp b/tmtcpacket/pus/TmPacketStored.cpp index b1c1ec624..bb9326418 100644 --- a/tmtcpacket/pus/TmPacketStored.cpp +++ b/tmtcpacket/pus/TmPacketStored.cpp @@ -82,7 +82,7 @@ void TmPacketStored::deletePacket() { void TmPacketStored::setStoreAddress(store_address_t setAddress) { storeAddress = setAddress; const uint8_t* temp_data = NULL; - uint32_t temp_size; + size_t temp_size; if (!checkAndSetStore()) { return; } diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index e402d79eb..6b563f983 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -76,7 +76,7 @@ ReturnValue_t TmTcBridge::handleTm() { ReturnValue_t TmTcBridge::readTmQueue() { TmTcMessage message; const uint8_t* data = NULL; - uint32_t size = 0; + size_t size = 0; for (ReturnValue_t result = TmTcReceptionQueue->receiveMessage(&message); result == RETURN_OK; result = TmTcReceptionQueue->receiveMessage(&message)) { @@ -127,7 +127,7 @@ ReturnValue_t TmTcBridge::sendStoredTm() { << (int) fifo.size() << " left to send" << std::endl; store_address_t storeId; const uint8_t* data = NULL; - uint32_t size = 0; + size_t size = 0; fifo.retrieve(&storeId); result = tmStore->getData(storeId, &data, &size); sendTm(data,size); From fa058ee6025cfe03e0a60f62ebb744d80b676637 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 23 Mar 2020 18:05:39 +0100 Subject: [PATCH 0127/1774] renamed rmap to com (more generic) --- devicehandlers/DeviceHandlerBase.cpp | 2 +- devicehandlers/DeviceHandlerBase.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 5834db2f5..4c2ae5684 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -688,7 +688,7 @@ void DeviceHandlerBase::replyRawData(const uint8_t *data, size_t len, //Default child implementations -DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getRmapAction() { +DeviceHandlerBase::CommunicationAction_t DeviceHandlerBase::getComAction() { switch (pstStep) { case 0: return SEND_WRITE; diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index e9288921d..3e5881150 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -666,7 +666,7 @@ protected: * * @return The Rmap action to execute in this step */ - virtual CommunicationAction_t getRmapAction(); + virtual CommunicationAction_t getComAction(); /** * Build the device command to send for raw mode. From f7bd661e6923713740c77e91c2602caa74e6abe5 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 23 Mar 2020 18:08:24 +0100 Subject: [PATCH 0128/1774] small fixes --- devicehandlers/DeviceHandlerBase.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 4c2ae5684..4b88355ac 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -66,7 +66,7 @@ ReturnValue_t DeviceHandlerBase::performOperation(uint8_t counter) { return RETURN_OK; } - switch (getRmapAction()) { + switch (getComAction()) { case SEND_WRITE: if ((cookieInfo.state == COOKIE_UNUSED)) { buildInternalCommand(); @@ -1050,6 +1050,7 @@ ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage( replyReturnvalueToCommand(WRONG_MODE_FOR_COMMAND); } else { // rework in progress + result = RETURN_OK; //result = switchCookieChannel( // DeviceHandlerMessage::getIoBoardObjectId(message)); if (result == RETURN_OK) { From b6bf9d71477b3695b1a3dfe7253137c5936c7ebc Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 23 Mar 2020 19:09:42 +0100 Subject: [PATCH 0129/1774] to avoid dynamic casting, introuced CookieIF --- devicehandlers/AcceptsDeviceResponsesIF.h | 5 ++-- devicehandlers/ChildHandlerBase.cpp | 6 ++--- devicehandlers/ChildHandlerBase.h | 5 ++-- devicehandlers/Cookie.cpp | 8 ++++--- devicehandlers/Cookie.h | 28 +++++++++++++---------- devicehandlers/CookieIF.h | 25 ++++++++++++++++++++ devicehandlers/DeviceCommunicationIF.h | 8 +++---- devicehandlers/DeviceHandlerBase.cpp | 26 ++++++++++----------- devicehandlers/DeviceHandlerBase.h | 27 +++++----------------- rmap/RMAPCookie.cpp | 8 +++---- rmap/RMAPCookie.h | 4 ++-- 11 files changed, 82 insertions(+), 68 deletions(-) create mode 100644 devicehandlers/CookieIF.h diff --git a/devicehandlers/AcceptsDeviceResponsesIF.h b/devicehandlers/AcceptsDeviceResponsesIF.h index 0eedae889..c811158f6 100644 --- a/devicehandlers/AcceptsDeviceResponsesIF.h +++ b/devicehandlers/AcceptsDeviceResponsesIF.h @@ -15,9 +15,8 @@ public: /** * Default empty virtual destructor. */ - virtual ~AcceptsDeviceResponsesIF() { -} -virtual MessageQueueId_t getDeviceQueue() = 0; + virtual ~AcceptsDeviceResponsesIF() {} + virtual MessageQueueId_t getDeviceQueue() = 0; }; #endif /* ACCEPTSDEVICERESPONSESIF_H_ */ diff --git a/devicehandlers/ChildHandlerBase.cpp b/devicehandlers/ChildHandlerBase.cpp index a0630fc64..ac0b24384 100644 --- a/devicehandlers/ChildHandlerBase.cpp +++ b/devicehandlers/ChildHandlerBase.cpp @@ -2,12 +2,12 @@ #include #include -ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, address_t logicalAddress, - object_id_t deviceCommunication, Cookie * cookie, +ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, + object_id_t deviceCommunication, CookieIF * cookie, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t parent, FailureIsolationBase* customFdir, size_t cmdQueueSize) : - DeviceHandlerBase(setObjectId, logicalAddress, deviceCommunication, cookie, + DeviceHandlerBase(setObjectId, deviceCommunication, cookie, maxDeviceReplyLen, setDeviceSwitch, thermalStatePoolId, thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir), cmdQueueSize), diff --git a/devicehandlers/ChildHandlerBase.h b/devicehandlers/ChildHandlerBase.h index 4e9eee493..493b22ee2 100644 --- a/devicehandlers/ChildHandlerBase.h +++ b/devicehandlers/ChildHandlerBase.h @@ -6,9 +6,8 @@ class ChildHandlerBase: public DeviceHandlerBase { public: - ChildHandlerBase(object_id_t setObjectId, uint32_t logicalAddress, - object_id_t deviceCommunication, Cookie * cookie, - uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, + ChildHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, + CookieIF * cookie, uint32_t maxDeviceReplyLen, uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t parent, FailureIsolationBase* customFdir = nullptr, size_t cmdQueueSize = 20); diff --git a/devicehandlers/Cookie.cpp b/devicehandlers/Cookie.cpp index f0748b5d5..05b9425ca 100644 --- a/devicehandlers/Cookie.cpp +++ b/devicehandlers/Cookie.cpp @@ -5,12 +5,12 @@ */ #include -//Cookie::Cookie(address_t logicalAddress_, size_t maxReplyLen_): -// logicalAddress(logicalAddress_), maxReplyLen(maxReplyLen_){} - Cookie::Cookie(address_t logicalAddress_): logicalAddress(logicalAddress_) { } +void Cookie::setAddress(address_t logicalAddress_) { + logicalAddress = logicalAddress_; +} void Cookie::setMaxReplyLen(size_t maxReplyLen_) { maxReplyLen = maxReplyLen_; } @@ -22,3 +22,5 @@ address_t Cookie::getAddress() const { size_t Cookie::getMaxReplyLen() const { return maxReplyLen; } + + diff --git a/devicehandlers/Cookie.h b/devicehandlers/Cookie.h index 60f20ff19..d76facc0d 100644 --- a/devicehandlers/Cookie.h +++ b/devicehandlers/Cookie.h @@ -1,31 +1,35 @@ #ifndef COOKIE_H_ #define COOKIE_H_ -#include +#include /** * @brief This datatype is used to identify different connection over a single interface * (like RMAP or I2C) * @details - * To use this class, implement a communication specific child cookie. This cookie - * can be used in the device communication interface by performing - * a C++ dynamic cast and passing it to a child device handler, which stores - * it and passes the Cookie to the communication interface where it can be used - * by again performing a dynamic cast. + * To use this class, implement a communication specific child cookie which + * inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling + * CookieIF* childCookie = new ChildCookie(...).´ + * + * This cookie is then passed to the child device handlers, which stores the + * pointer and passes it to the communication interface functions. + * * The cookie can be used to store all kinds of information * about the communication, like slave addresses, communication status, * communication parameters etc. + * * @ingroup comm */ -class Cookie{ +class Cookie: public CookieIF { public: - Cookie() = default; + Cookie(); Cookie(address_t logicalAddress_); - virtual ~Cookie(){} + virtual ~Cookie() {}; - void setMaxReplyLen(size_t maxReplyLen_); + virtual void setAddress(address_t logicalAddres_); + virtual void setMaxReplyLen(size_t maxReplyLen_); - address_t getAddress() const; - size_t getMaxReplyLen() const; + virtual address_t getAddress() const; + virtual size_t getMaxReplyLen() const; private: address_t logicalAddress = 0; size_t maxReplyLen = 0; diff --git a/devicehandlers/CookieIF.h b/devicehandlers/CookieIF.h new file mode 100644 index 000000000..3e08709bd --- /dev/null +++ b/devicehandlers/CookieIF.h @@ -0,0 +1,25 @@ +/** + * @file CookieIF.h + * + * @date 23 Mar 2020 + */ + +#ifndef FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ +#define FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ +#include + +class CookieIF { +public: + /** + * Default empty virtual destructor. + */ + virtual ~CookieIF() {}; + + virtual void setAddress(address_t logicalAddress_) = 0; + virtual address_t getAddress() const = 0; + + virtual void setMaxReplyLen(size_t maxReplyLen_) = 0; + virtual size_t getMaxReplyLen() const = 0; +}; + +#endif /* FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ */ diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 43aa7965b..6f2715041 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -57,7 +57,7 @@ public: * - Everything else triggers sending failed event with * returnvalue as parameter 1 */ - virtual ReturnValue_t sendMessage(Cookie *cookie, const uint8_t * sendData, + virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData, size_t sendLen) = 0; /** @@ -68,7 +68,7 @@ public: * - Everything else triggers sending failed event with * returnvalue as parameter 1 */ - virtual ReturnValue_t getSendSuccess(Cookie *cookie) = 0; + virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0; /** * Called by DHB in the SEND_WRITE doSendRead(). @@ -76,7 +76,7 @@ public: * @param cookie * @return */ - virtual ReturnValue_t requestReceiveMessage(Cookie *cookie, size_t requestLen) = 0; + virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0; /** * Called by DHB in the GET_WRITE doGetRead(). @@ -89,7 +89,7 @@ public: * - Everything else triggers receiving failed with * returnvalue as parameter 1 */ - virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, + virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) = 0; }; diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 4b88355ac..33e441460 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -16,23 +16,22 @@ object_id_t DeviceHandlerBase::powerSwitcherId = 0; object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; -DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, - object_id_t deviceCommunication, Cookie * cookie_, size_t maxReplyLen, - uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, +DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, + CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch, + uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, size_t cmdQueueSize) : SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE), wiretappingMode(OFF), storedRawData(StorageManagerIF::INVALID_ADDRESS), - deviceCommunicationId(deviceCommunication), cookie(cookie_), + deviceCommunicationId(deviceCommunication), comCookie(comCookie_), deviceThermalStatePoolId(thermalStatePoolId), deviceThermalRequestPoolId(thermalRequestPoolId), healthHelper(this, setObjectId), modeHelper(this), parameterHelper(this), fdirInstance(fdirInstance), hkSwitcher(this), defaultFDIRUsed(fdirInstance == nullptr), switchOffWasReported(false), executingTask(nullptr), actionHelper(this, nullptr), cookieInfo(), - logicalAddress(logicalAddress_), childTransitionDelay(5000), - transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), - deviceSwitch(setDeviceSwitch) + childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), + transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { - this->cookie->setMaxReplyLen(maxReplyLen); + this->comCookie->setMaxReplyLen(maxReplyLen); commandQueue = QueueFactory::instance()-> createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); cookieInfo.state = COOKIE_UNUSED; @@ -44,6 +43,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, address_t logicalA } DeviceHandlerBase::~DeviceHandlerBase() { + delete comCookie; if (defaultFDIRUsed) { delete fdirInstance; } @@ -506,7 +506,7 @@ void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter, void DeviceHandlerBase::doSendWrite() { if (cookieInfo.state == COOKIE_WRITE_READY) { - ReturnValue_t result = communicationInterface->sendMessage(cookie, + ReturnValue_t result = communicationInterface->sendMessage(comCookie, rawPacket, rawPacketLen); if (result == RETURN_OK) { @@ -527,7 +527,7 @@ void DeviceHandlerBase::doGetWrite() { return; } cookieInfo.state = COOKIE_UNUSED; - ReturnValue_t result = communicationInterface->getSendSuccess(cookie); + ReturnValue_t result = communicationInterface->getSendSuccess(comCookie); if (result == RETURN_OK) { if (wiretappingMode == RAW) { replyRawData(rawPacket, rawPacketLen, requestedRawTraffic, true); @@ -548,7 +548,7 @@ void DeviceHandlerBase::doGetWrite() { void DeviceHandlerBase::doSendRead() { ReturnValue_t result; - result = communicationInterface->requestReceiveMessage(cookie, requestLen); + result = communicationInterface->requestReceiveMessage(comCookie, requestLen); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; } else { @@ -575,7 +575,7 @@ void DeviceHandlerBase::doGetRead() { cookieInfo.state = COOKIE_UNUSED; - result = communicationInterface->readReceivedMessage(cookie, &receivedData, + result = communicationInterface->readReceivedMessage(comCookie, &receivedData, &receivedDataLen); if (result != RETURN_OK) { @@ -1277,7 +1277,7 @@ void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t obje } uint32_t DeviceHandlerBase::getLogicalAddress() { - return logicalAddress; + return this->comCookie->getAddress(); } void DeviceHandlerBase::performOperationHook() { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 3e5881150..05be2d458 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -93,9 +94,9 @@ public: * @param fdirInstance * @param cmdQueueSize */ - DeviceHandlerBase(object_id_t setObjectId, address_t logicalAddress_, - object_id_t deviceCommunication, Cookie* cookie_, size_t maxReplyLen, - uint8_t setDeviceSwitch, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, + DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, + CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch, + uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20); @@ -422,22 +423,6 @@ protected: */ size_t requestLen = 0; -// /** -// * This union (or std::variant) type can be used to set comParameters which -// * are passed in the open() and reOpen() calls to the communication -// * interface -// * TODO: I don't know if we should use C++17 features but if we do we propably -// * should also write a function to get either a storeId handle -// * or an array handle so these values can be set conveniently. -// * The good think is that if there are many parameters, they can -// * be stored in the IPC pool. But maybe two uint32_t parameters are enough. -// * Simple = Good. It is downwards compatible and one can still store -// * 4 bytes of parameters AND a store ID. -// */ -// comParameters_t comParameters; - // uint32_t comParameter1 = 0; - // uint32_t comParameter2 = 0; - /** * The mode the device handler is currently in. * @@ -515,7 +500,7 @@ protected: * Cookie used for communication. This is passed to the communication * interface. */ - Cookie *cookie; + CookieIF *comCookie; /** * The MessageQueue used to receive device handler commands and to send replies. @@ -959,7 +944,7 @@ private: /** * cached from ctor for initialize() */ - const uint32_t logicalAddress; + //const uint32_t logicalAddress = 0; /** * Used for timing out mode transitions. diff --git a/rmap/RMAPCookie.cpp b/rmap/RMAPCookie.cpp index 5bf2ba9f5..84e407ba2 100644 --- a/rmap/RMAPCookie.cpp +++ b/rmap/RMAPCookie.cpp @@ -93,10 +93,10 @@ RMAPCookie::~RMAPCookie() { } -uint32_t RMAPCookie::getMaxReplyLen() const { - return maxReplyLen; -} - +//uint32_t RMAPCookie::getMaxReplyLen() const { +// return maxReplyLen; +//} +// void RMAPCookie::setMaxReplyLen(uint32_t maxReplyLen) { this->maxReplyLen = maxReplyLen; } diff --git a/rmap/RMAPCookie.h b/rmap/RMAPCookie.h index c091ba182..cf033bae8 100644 --- a/rmap/RMAPCookie.h +++ b/rmap/RMAPCookie.h @@ -6,7 +6,7 @@ class RMAPChannelIF; -class RMAPCookie : public Cookie{ +class RMAPCookie : public Cookie { public: //To Uli: Sorry, I need an empty ctor to initialize an array of cookies. RMAPCookie(); @@ -28,7 +28,7 @@ public: void setCommandMask(uint8_t commandMask); uint8_t getCommandMask(); - uint32_t getMaxReplyLen() const; + //size_t getMaxReplyLen() const; void setMaxReplyLen(uint32_t maxReplyLen); uint16_t getTransactionIdentifier() const; From f7b7e10d05224dcd6ab5e2c0c4e778ce5585c544 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 23 Mar 2020 19:14:36 +0100 Subject: [PATCH 0130/1774] date format changed --- devicehandlers/CookieIF.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devicehandlers/CookieIF.h b/devicehandlers/CookieIF.h index 3e08709bd..d8781cd73 100644 --- a/devicehandlers/CookieIF.h +++ b/devicehandlers/CookieIF.h @@ -1,7 +1,7 @@ /** * @file CookieIF.h * - * @date 23 Mar 2020 + * @date 23.03.2020 */ #ifndef FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ From 7e8d92f956220734c4d65dc026550595cfbf577f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 24 Mar 2020 00:22:17 +0100 Subject: [PATCH 0131/1774] replaced std::list by std::set for fixedSlotSequen --- devicehandlers/DeviceHandlerBase.h | 8 ++- devicehandlers/DeviceHandlerIF.h | 22 -------- devicehandlers/FixedSequenceSlot.h | 19 ++++--- devicehandlers/FixedSlotSequence.cpp | 84 ++++++++++++++-------------- devicehandlers/FixedSlotSequence.h | 48 ++++++++++------ osal/FreeRTOS/FixedTimeslotTask.cpp | 4 +- tasks/FixedTimeslotTaskIF.h | 4 +- 7 files changed, 95 insertions(+), 94 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 05be2d458..3bfb07aec 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -69,6 +69,12 @@ class StorageManagerIF; * * Other important virtual methods with a default implementation * are the getTransitionDelayMs() function and the getSwitches() function. + * Please ensure that getSwitches() returns DeviceHandlerIF::NO_SWITCHES if + * power switches are not implemented yet. Otherwise, the device handler will + * not transition to MODE_ON, even if setMode(MODE_ON) is called. + * If a transition to MODE_ON is desired without commanding, override the + * intialize() function and call setMode(_MODE_START_UP) before calling + * DeviceHandlerBase::initialize(). * * @ingroup devices */ @@ -349,7 +355,7 @@ protected: * @param[out] numberOfSwitches length of returned array * @return * - @c RETURN_OK if the parameters were set - * - @c RETURN_FAILED if no switches exist + * - @c NO_SWITCH or any other returnvalue if no switches exist */ virtual ReturnValue_t getSwitches(const uint8_t **switches, uint8_t *numberOfSwitches); diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index c453e7e87..f0f7adfdc 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -7,33 +7,11 @@ #include #include -#if __cplusplus >= 201703L -#include -#include -#endif - /** * Physical address type */ typedef uint32_t address_t; -///** -// * This type safe union cold be used if C++17 or newer is used to transfer -// * comIF settings to the communication interface object. -// */ -// -//#if __cplusplus >= 201703L -//using comParameterArray_t = std::array; -//using comParameters_t = std::variant; -//#else -//using comParameters_t = union comParameters { -// comParameters() = default; -// comParameters(uint32_t initValue): storeIdRaw(initValue) {} -// uint32_t storeIdRaw; -// uint8_t comParameter[4]; -// }; -//#endif - /** * This is the Interface used to communicate with a device handler. * diff --git a/devicehandlers/FixedSequenceSlot.h b/devicehandlers/FixedSequenceSlot.h index 0ed285b38..b3bac08f9 100644 --- a/devicehandlers/FixedSequenceSlot.h +++ b/devicehandlers/FixedSequenceSlot.h @@ -19,29 +19,34 @@ class PeriodicTaskIF; */ class FixedSequenceSlot { public: - FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs, int8_t setSequenceId, PeriodicTaskIF* executingTask ); + FixedSequenceSlot( object_id_t handlerId, uint32_t setTimeMs, + int8_t setSequenceId, PeriodicTaskIF* executingTask ); virtual ~FixedSequenceSlot(); /** - * \brief \c handler identifies which device handler object is executed in this slot. + * @brief Handler identifies which device handler object is executed in this slot. */ ExecutableObjectIF* handler; /** - * \brief This attribute defines when a device handler object is executed. + * @brief This attribute defines when a device handler object is executed. * - * \details The pollingTime attribute identifies the time the handler is executed in ms. It must be - * smaller than the period length of the polling sequence, which is ensured by automated calculation - * from a database. + * @details The pollingTime attribute identifies the time the handler is executed in ms. + * It must be smaller than the period length of the polling sequence. */ uint32_t pollingTimeMs; /** * \brief This value defines the type of device communication. * - * \details The state of this value decides what communication routine is called in the PST executable or the device handler object. + * \details The state of this value decides what communication routine is + * called in the PST executable or the device handler object. */ uint8_t opcode; + + bool operator <(const FixedSequenceSlot & fixedSequenceSlot) const { + return pollingTimeMs < fixedSequenceSlot.pollingTimeMs; + } }; diff --git a/devicehandlers/FixedSlotSequence.cpp b/devicehandlers/FixedSlotSequence.cpp index a65dd929e..f01b13992 100644 --- a/devicehandlers/FixedSlotSequence.cpp +++ b/devicehandlers/FixedSlotSequence.cpp @@ -2,22 +2,23 @@ #include FixedSlotSequence::FixedSlotSequence(uint32_t setLengthMs) : - lengthMs(setLengthMs) { + slotLengthMs(setLengthMs) { current = slotList.begin(); } FixedSlotSequence::~FixedSlotSequence() { - std::list::iterator slotIt; - //Iterate through slotList and delete all entries. - slotIt = this->slotList.begin(); - while (slotIt != this->slotList.end()) { - delete (*slotIt); - slotIt++; - } + // This should call the destructor on each list entry. + slotList.clear(); +// SlotListIter slotListIter = this->slotList.begin(); +// //Iterate through slotList and delete all entries. +// while (slotListIter != this->slotList.end()) { +// delete (*slotIt); +// slotIt++; +// } } void FixedSlotSequence::executeAndAdvance() { - (*this->current)->handler->performOperation((*this->current)->opcode); + current->handler->performOperation(current->opcode); // if (returnValue != RETURN_OK) { // this->sendErrorMessage( returnValue ); // } @@ -31,53 +32,50 @@ void FixedSlotSequence::executeAndAdvance() { uint32_t FixedSlotSequence::getIntervalToNextSlotMs() { uint32_t oldTime; - std::list::iterator it; - it = current; + SlotListIter slotListIter = current; // Get the pollingTimeMs of the current slot object. - oldTime = (*it)->pollingTimeMs; + oldTime = slotListIter->pollingTimeMs; // Advance to the next object. - it++; + slotListIter++; // Find the next interval which is not 0. - while (it != slotList.end()) { - if (oldTime != (*it)->pollingTimeMs) { - return (*it)->pollingTimeMs - oldTime; + while (slotListIter != slotList.end()) { + if (oldTime != slotListIter->pollingTimeMs) { + return slotListIter->pollingTimeMs - oldTime; } else { - it++; + slotListIter++; } } // If the list end is reached (this is definitely an interval != 0), // the interval is calculated by subtracting the remaining time of the PST // and adding the start time of the first handler in the list. - it = slotList.begin(); - return lengthMs - oldTime + (*it)->pollingTimeMs; + slotListIter = slotList.begin(); + return slotLengthMs - oldTime + slotListIter->pollingTimeMs; } uint32_t FixedSlotSequence::getIntervalToPreviousSlotMs() { uint32_t currentTime; - std::list::iterator it; - it = current; + SlotListIter slotListIter = current; // Get the pollingTimeMs of the current slot object. - currentTime = (*it)->pollingTimeMs; + currentTime = slotListIter->pollingTimeMs; //if it is the first slot, calculate difference to last slot - if (it == slotList.begin()){ - return lengthMs - (*(--slotList.end()))->pollingTimeMs + currentTime; + if (slotListIter == slotList.begin()){ + return slotLengthMs - (--slotList.end())->pollingTimeMs + currentTime; } // get previous slot - it--; + slotListIter--; - return currentTime - (*it)->pollingTimeMs; + return currentTime - slotListIter->pollingTimeMs; } bool FixedSlotSequence::slotFollowsImmediately() { - uint32_t currentTime = (*current)->pollingTimeMs; - std::list::iterator it; - it = this->current; + uint32_t currentTime = current->pollingTimeMs; + SlotListIter fixedSequenceIter = this->current; // Get the pollingTimeMs of the current slot object. - if (it == slotList.begin()) + if (fixedSequenceIter == slotList.begin()) return false; - it--; - if ((*it)->pollingTimeMs == currentTime) { + fixedSequenceIter--; + if (fixedSequenceIter->pollingTimeMs == currentTime) { return true; } else { return false; @@ -85,29 +83,30 @@ bool FixedSlotSequence::slotFollowsImmediately() { } uint32_t FixedSlotSequence::getLengthMs() const { - return this->lengthMs; + return this->slotLengthMs; } ReturnValue_t FixedSlotSequence::checkSequence() const { - //Iterate through slotList and check successful creation. Checks if timing is ok (must be ascending) and if all handlers were found. + // Iterate through slotList and check successful creation. + // Checks if timing is ok (must be ascending) and if all handlers were found. auto slotIt = slotList.begin(); uint32_t count = 0; uint32_t time = 0; while (slotIt != slotList.end()) { - if ((*slotIt)->handler == NULL) { + if (slotIt->handler == NULL) { error << "FixedSlotSequene::initialize: ObjectId does not exist!" << std::endl; count++; - } else if ((*slotIt)->pollingTimeMs < time) { + } else if (slotIt->pollingTimeMs < time) { error << "FixedSlotSequence::initialize: Time: " - << (*slotIt)->pollingTimeMs + << slotIt->pollingTimeMs << " is smaller than previous with " << time << std::endl; count++; } else { - //All ok, print slot. -// (*slotIt)->print(); + // All ok, print slot. + // (*slotIt)->print(); } - time = (*slotIt)->pollingTimeMs; + time = slotIt->pollingTimeMs; slotIt++; } if (count > 0) { @@ -118,8 +117,7 @@ ReturnValue_t FixedSlotSequence::checkSequence() const { void FixedSlotSequence::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep, PeriodicTaskIF* executingTask) { - this->slotList.push_back( - new FixedSequenceSlot(componentId, slotTimeMs, executionStep, - executingTask)); + this->slotList.insert(FixedSequenceSlot(componentId, slotTimeMs, executionStep, + executingTask)); this->current = slotList.begin(); } diff --git a/devicehandlers/FixedSlotSequence.h b/devicehandlers/FixedSlotSequence.h index d72de9131..974dbb2bd 100644 --- a/devicehandlers/FixedSlotSequence.h +++ b/devicehandlers/FixedSlotSequence.h @@ -4,11 +4,15 @@ #include #include #include +#include + +using SlotList = std::set; +using SlotListIter = std::set::iterator; /** - * \brief This class is the representation of a Polling Sequence Table in software. + * @brief This class is the representation of a Polling Sequence Table in software. * - * \details The FixedSlotSequence object maintains the dynamic execution of device handler objects. + * @details The FixedSlotSequence object maintains the dynamic execution of device handler objects. * The main idea is to create a list of device handlers, to announce all handlers to the * polling sequence and to maintain a list of polling slot objects. This slot list represents the * Polling Sequence Table in software. Each polling slot contains information to indicate when and @@ -19,29 +23,37 @@ class FixedSlotSequence { public: + /** - * \brief The constructor of the FixedSlotSequence object. + * @brief The constructor of the FixedSlotSequence object. * - * \details The constructor takes two arguments, the period length and the init function. + * @details The constructor takes two arguments, the period length and the init function. * - * \param setLength The period length, expressed in ms. + * @param setLength The period length, expressed in ms. */ FixedSlotSequence(uint32_t setLengthMs); /** - * \brief The destructor of the FixedSlotSequence object. + * @brief The destructor of the FixedSlotSequence object. * - * \details The destructor frees all allocated memory by iterating through the slotList + * @details The destructor frees all allocated memory by iterating through the slotList * and deleting all allocated resources. */ virtual ~FixedSlotSequence(); /** - * \brief This is a method to add an PollingSlot object to slotList. + * @brief This is a method to add an PollingSlot object to slotList. * - * \details Here, a polling slot object is added to the slot list. It is appended + * @details Here, a polling slot object is added to the slot list. It is appended * to the end of the list. The list is currently NOT reordered. * Afterwards, the iterator current is set to the beginning of the list. + * @param Object ID of the object to add + * @param setTime Value between (0 to 1) * slotLengthMs, when a FixedTimeslotTask + * will be called inside the slot period. + * @param setSequenceId ID which can be used to distinguish + * different task operations + * @param + * @param */ void addSlot(object_id_t handlerId, uint32_t setTime, int8_t setSequenceId, PeriodicTaskIF* executingTask); @@ -75,12 +87,12 @@ public: uint32_t getIntervalToPreviousSlotMs(); /** - * \brief This method returns the length of this FixedSlotSequence instance. + * @brief This method returns the length of this FixedSlotSequence instance. */ uint32_t getLengthMs() const; /** - * \brief The method to execute the device handler entered in the current OPUSPollingSlot object. + * \brief The method to execute the device handler entered in the current PollingSlot object. * * \details Within this method the device handler object to be executed is chosen by looking up the * handler address of the current slot in the handlerMap. Either the device handler's @@ -91,17 +103,17 @@ public: void executeAndAdvance(); /** - * \brief An iterator that indicates the current polling slot to execute. + * @brief An iterator that indicates the current polling slot to execute. * - * \details This is an iterator for slotList and always points to the polling slot which is executed next. + * @details This is an iterator for slotList and always points to the polling slot which is executed next. */ - std::list::iterator current; + SlotListIter current; - ReturnValue_t checkSequence() const; + virtual ReturnValue_t checkSequence() const; protected: /** - * \brief This list contains all OPUSPollingSlot objects, defining order and execution time of the + * @brief This list contains all PollingSlot objects, defining order and execution time of the * device handler objects. * * @details The slot list is a std:list object that contains all created PollingSlot instances. @@ -109,9 +121,9 @@ protected: * By iterating through this list the polling sequence is executed. Two entries with identical * polling times are executed immediately one after another. */ - std::list slotList; + SlotList slotList; - uint32_t lengthMs; + uint32_t slotLengthMs; }; #endif /* FIXEDSLOTSEQUENCE_H_ */ diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 604a10b86..71e166a52 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -80,10 +80,10 @@ ReturnValue_t FixedTimeslotTask::checkSequence() const { void FixedTimeslotTask::taskFunctionality() { // A local iterator for the Polling Sequence Table is created to find the start time for the first entry. - std::list::iterator it = pst.current; + SlotListIter slotListIter = pst.current; //The start time for the first entry is read. - uint32_t intervalMs = (*it)->pollingTimeMs; + uint32_t intervalMs = slotListIter->pollingTimeMs; TickType_t interval = pdMS_TO_TICKS(intervalMs); TickType_t xLastWakeTime; diff --git a/tasks/FixedTimeslotTaskIF.h b/tasks/FixedTimeslotTaskIF.h index 3a3582fbc..d29801841 100644 --- a/tasks/FixedTimeslotTaskIF.h +++ b/tasks/FixedTimeslotTaskIF.h @@ -5,11 +5,13 @@ #include /** - * Following the same principle as the base class IF. This is the interface for a Fixed timeslot task + * @brief Following the same principle as the base class IF. + * This is the interface for a Fixed timeslot task */ class FixedTimeslotTaskIF : public PeriodicTaskIF { public: virtual ~FixedTimeslotTaskIF() {} + virtual ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) = 0; virtual ReturnValue_t checkSequence() const = 0; }; From ea49d88c4be5929208192fd86d9f2ccf99889cb8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 24 Mar 2020 14:21:57 +0100 Subject: [PATCH 0132/1774] moved all return values to DH IF --- action/HasActionsIF.h | 7 +-- datapool/DataPoolAdmin.cpp | 2 +- datapool/DataPoolAdmin.h | 4 +- devicehandlers/DeviceHandlerBase.cpp | 22 ++++++--- devicehandlers/DeviceHandlerBase.h | 49 ++++++++++--------- devicehandlers/DeviceHandlerIF.h | 73 ++++++++++++++++------------ returnvalues/HasReturnvaluesIF.h | 8 +-- 7 files changed, 92 insertions(+), 73 deletions(-) diff --git a/action/HasActionsIF.h b/action/HasActionsIF.h index 4d66ad1f6..12ecb89a8 100644 --- a/action/HasActionsIF.h +++ b/action/HasActionsIF.h @@ -44,10 +44,11 @@ public: /** * Execute or initialize the execution of a certain function. * Returning #EXECUTION_FINISHED or a failure code, nothing else needs to be done. - * When needing more steps, return RETURN_OK and issue steps and completion manually. One "step failed" or completion report must - * be issued! + * When needing more steps, return RETURN_OK and issue steps and completion manually. + * One "step failed" or completion report must be issued! */ - virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size) = 0; + virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy, + const uint8_t* data, size_t size) = 0; }; diff --git a/datapool/DataPoolAdmin.cpp b/datapool/DataPoolAdmin.cpp index 99d2b51b2..e66a44e96 100644 --- a/datapool/DataPoolAdmin.cpp +++ b/datapool/DataPoolAdmin.cpp @@ -26,7 +26,7 @@ MessageQueueId_t DataPoolAdmin::getCommandQueue() const { } ReturnValue_t DataPoolAdmin::executeAction(ActionId_t actionId, - MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size) { + MessageQueueId_t commandedBy, const uint8_t* data, size_t size) { if (actionId != SET_VALIDITY) { return INVALID_ACTION_ID; } diff --git a/datapool/DataPoolAdmin.h b/datapool/DataPoolAdmin.h index 448d78fbc..dffcd4625 100644 --- a/datapool/DataPoolAdmin.h +++ b/datapool/DataPoolAdmin.h @@ -33,8 +33,8 @@ public: ReturnValue_t handleMemoryDump(uint32_t address, uint32_t size, uint8_t** dataPointer, uint8_t* copyHere); - ReturnValue_t executeAction(ActionId_t actionId, - MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size); + virtual ReturnValue_t executeAction(ActionId_t actionId, + MessageQueueId_t commandedBy, const uint8_t* data, size_t size); //not implemented as ParameterHelper is no used ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 33e441460..ebb361d97 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -811,9 +811,9 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( iter = deviceReplyMap.find(command->first); } if (iter != deviceReplyMap.end()) { - DeviceReplyInfo *info = &(iter->second); - info->delayCycles = info->maxDelayCycles; - info->command = command; + DeviceReplyInfo & info = iter->second; + info.delayCycles = info.maxDelayCycles; + info.command = command; command->second.expectedReplies = expectedReplies; return RETURN_OK; } else { @@ -1056,7 +1056,7 @@ ReturnValue_t DeviceHandlerBase::handleDeviceHandlerMessage( if (result == RETURN_OK) { replyReturnvalueToCommand(RETURN_OK); } else { - replyReturnvalueToCommand(CANT_SWITCH_IOBOARD); + replyReturnvalueToCommand(CANT_SWITCH_ADDRESS); } } return RETURN_OK; @@ -1138,11 +1138,15 @@ void DeviceHandlerBase::handleDeviceTM(SerializeIF* data, } ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId, - MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size) { + MessageQueueId_t commandedBy, const uint8_t* data, size_t size) { ReturnValue_t result = acceptExternalDeviceCommands(); if (result != HasReturnvaluesIF::RETURN_OK) { return result; } + if(size == 0) { + return NO_COMMAND_DATA; + } + DeviceCommandMap::iterator iter = deviceCommandMap.find(actionId); if (iter == deviceCommandMap.end()) { result = COMMAND_NOT_SUPPORTED; @@ -1161,7 +1165,7 @@ 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) { @@ -1179,12 +1183,13 @@ void DeviceHandlerBase::buildInternalCommand(void) { } else { return; } + if (result == NOTHING_TO_SEND) { return; } if (result == RETURN_OK) { - DeviceCommandMap::iterator iter = deviceCommandMap.find( - deviceCommandId); + DeviceCommandMap::iterator iter = + deviceCommandMap.find(deviceCommandId); if (iter == deviceCommandMap.end()) { result = COMMAND_NOT_SUPPORTED; } else if (iter->second.isExecuting) { @@ -1199,6 +1204,7 @@ void DeviceHandlerBase::buildInternalCommand(void) { cookieInfo.state = COOKIE_WRITE_READY; } } + if (result != RETURN_OK) { triggerEvent(DEVICE_BUILDING_COMMAND_FAILED, result, deviceCommandId); } diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 3bfb07aec..5faaa8e01 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -197,8 +197,9 @@ protected: * * @param[out] id the device command id that has been built * @return - * - @c RETURN_OK when a command is to be sent - * - not @c RETURN_OK when no command is to be sent + * - @c RETURN_OK to send command after setting #rawPacket and #rawPacketLen. + * - @c NOTHING_TO_SEND when no command is to be sent. + * - Anything else triggers an even with the returnvalue as a parameter. */ virtual ReturnValue_t buildNormalDeviceCommand(DeviceCommandId_t * id) = 0; @@ -216,21 +217,25 @@ protected: * @param[out] id the device command id built * @return * - @c RETURN_OK when a command is to be sent - * - not @c RETURN_OK when no command is to be sent + * - @c NOTHING_TO_SEND when no command is to be sent + * - Anything else triggers an even with the returnvalue as a parameter */ virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t * id) = 0; /** - * Build a device command packet from data supplied by a direct command. + * @brief Build a device command packet from data supplied by a direct command. * + * @details * #rawPacket and #rawPacketLen should be set by this method to the packet to be sent. + * The existence of the command in the command map and the command size check + * against 0 are done by the base class. * * @param deviceCommand the command to build, already checked against deviceCommandMap * @param commandData pointer to the data from the direct command * @param commandDataLen length of commandData * @return - * - @c RETURN_OK when #rawPacket is valid - * - @c RETURN_FAILED when #rawPacket is invalid and no data should be sent + * - @c RETURN_OK to send command after #rawPacket and #rawPacketLen have been set. + * - Anything else triggers an event with the returnvalue as a parameter */ virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, const uint8_t * commandData, size_t commandDataLen) = 0; @@ -366,14 +371,29 @@ protected: */ virtual void performOperationHook(); + /** + * The Returnvalues id of this class, required by HasReturnvaluesIF + */ + static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE; + public: /** * @param parentQueueId */ virtual void setParentQueue(MessageQueueId_t parentQueueId); + /** + * This function call handles the execution of external commands as required + * by the HasActionIF. + * @param actionId + * @param commandedBy + * @param data + * @param size + * @return + */ ReturnValue_t executeAction(ActionId_t actionId, - MessageQueueId_t commandedBy, const uint8_t* data, uint32_t size); + MessageQueueId_t commandedBy, const uint8_t* data, size_t size); + Mode_t getTransitionSourceMode() const; Submode_t getTransitionSourceSubMode() const; virtual void getMode(Mode_t *mode, Submode_t *submode); @@ -392,21 +412,6 @@ public: virtual MessageQueueId_t getCommandQueue(void) const; protected: - /** - * The Returnvalues id of this class, required by HasReturnvaluesIF - */ - static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_BASE; - - static const ReturnValue_t INVALID_CHANNEL = MAKE_RETURN_CODE(4); - static const ReturnValue_t APERIODIC_REPLY = MAKE_RETURN_CODE(5); //!< This is used to specify for replies from a device which are not replies to requests - static const ReturnValue_t IGNORE_REPLY_DATA = MAKE_RETURN_CODE(6); //!< Ignore parts of the received packet - static const ReturnValue_t IGNORE_FULL_PACKET = MAKE_RETURN_CODE(7); //!< Ignore full received packet -// static const ReturnValue_t ONE_SWITCH = MAKE_RETURN_CODE(8); -// static const ReturnValue_t TWO_SWITCHES = MAKE_RETURN_CODE(9); - static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(10); - static const ReturnValue_t COMMAND_MAP_ERROR = MAKE_RETURN_CODE(11); - static const ReturnValue_t NOTHING_TO_SEND = MAKE_RETURN_CODE(12); - //Mode handling error Codes static const ReturnValue_t CHILD_TIMEOUT = MAKE_RETURN_CODE(0xE1); static const ReturnValue_t SWITCH_FAILED = MAKE_RETURN_CODE(0xE2); diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index f0f7adfdc..5ea527e95 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -8,12 +8,13 @@ #include /** - * Physical address type + * @brief Physical address type */ typedef uint32_t address_t; /** - * This is the Interface used to communicate with a device handler. + * @brief This is the Interface used to communicate with a device handler. + * @details Includes all expected return values, events and modes. * */ class DeviceHandlerIF { @@ -30,8 +31,8 @@ public: * MODE_ON and MODE_OFF are included in hasModesIF.h */ - // MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted - // MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on. + // MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no commands are sent by the device handler itself, but direct commands van be commanded and will be interpreted + // MODE_OFF = 1, //!< The device is powered off. The only command accepted in this mode is a mode change to on. static const Mode_t MODE_NORMAL = 2; //!< The device is powered on and the device handler periodically sends commands. The commands to be sent are selected by the handler according to the submode. static const Mode_t MODE_RAW = 3; //!< The device is powered on and ready to perform operations. In this mode, raw commands can be sent. The device handler will send all replies received from the command back to the commanding object. static const Mode_t MODE_ERROR_ON = 4; //!4< The device is shut down but the switch could not be turned off, so the device still is powered. In this mode, only a mode change to @c MODE_OFF can be commanded, which tries to switch off the device again. @@ -60,36 +61,48 @@ public: static const Event MONITORING_AMBIGUOUS = MAKE_EVENT(10, SEVERITY::HIGH); static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_HANDLER_IF; - static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA0); - static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA1); - static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA2); - static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA3); - static const ReturnValue_t CANT_SWITCH_IOBOARD = MAKE_RETURN_CODE(0xA4); - static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA5); - static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA6); - static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xA7); - static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA8); //!< Used to indicate that this is a command-only command. - static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xA9); - static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAA); - // Standard codes used in scan for reply - //static const ReturnValue_t TOO_SHORT = MAKE_RETURN_CODE(0xB1); - static const ReturnValue_t CHECKSUM_ERROR = MAKE_RETURN_CODE(0xB2); - static const ReturnValue_t LENGTH_MISSMATCH = MAKE_RETURN_CODE(0xB3); - static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(0xB4); - static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0xB5); + // Standard codes used when building commands. + static const ReturnValue_t NOTHING_TO_SEND = MAKE_RETURN_CODE(0xA0); //!< Return this if no command sending in required + // Mostly used for internal handling. + static const ReturnValue_t NO_COMMAND_DATA = MAKE_RETURN_CODE(0xA2); //!< If the command size is 0. Checked in DHB + static const ReturnValue_t NO_REPLY_EXPECTED = MAKE_RETURN_CODE(0xA3); //!< Used to indicate that this is a command-only command. + static const ReturnValue_t COMMAND_NOT_SUPPORTED = MAKE_RETURN_CODE(0xA4); //!< Command ID not in commandMap. Checked in DHB + static const ReturnValue_t COMMAND_ALREADY_SENT = MAKE_RETURN_CODE(0xA5); //!< Command was already executed. Checked in DHB + static const ReturnValue_t COMMAND_WAS_NOT_SENT = MAKE_RETURN_CODE(0xA6); + static const ReturnValue_t CANT_SWITCH_ADDRESS = MAKE_RETURN_CODE(0xA7); + static const ReturnValue_t WRONG_MODE_FOR_COMMAND = MAKE_RETURN_CODE(0xA8); + static const ReturnValue_t TIMEOUT = MAKE_RETURN_CODE(0xA9); + static const ReturnValue_t BUSY = MAKE_RETURN_CODE(0xAA); + static const ReturnValue_t NON_OP_TEMPERATURE = MAKE_RETURN_CODE(0xAB); + static const ReturnValue_t COMMAND_NOT_IMPLEMENTED = MAKE_RETURN_CODE(0xAC); - // Standard codes used in interpret device reply + // Standard codes used in scanForReply + static const ReturnValue_t APERIODIC_REPLY = MAKE_RETURN_CODE(0xB1); //!< This is used to specify for replies from a device which are not replies to requests + static const ReturnValue_t LENGTH_MISSMATCH = MAKE_RETURN_CODE(0xB2); + static const ReturnValue_t IGNORE_REPLY_DATA = MAKE_RETURN_CODE(0xB3); //!< Ignore parts of the received packet + static const ReturnValue_t IGNORE_FULL_PACKET = MAKE_RETURN_CODE(0xB4); //!< Ignore full received packet + static const ReturnValue_t CHECKSUM_ERROR = MAKE_RETURN_CODE(0xB5); + static const ReturnValue_t INVALID_DATA = MAKE_RETURN_CODE(0xB6); + static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0xB7); + + // Standard codes used in interpretDeviceReply static const ReturnValue_t DEVICE_DID_NOT_EXECUTE = MAKE_RETURN_CODE(0xC1); //the device reported, that it did not execute the command static const ReturnValue_t DEVICE_REPORTED_ERROR = MAKE_RETURN_CODE(0xC2); static const ReturnValue_t UNKNOW_DEVICE_REPLY = MAKE_RETURN_CODE(0xC3); //the deviceCommandId reported by scanforReply is unknown static const ReturnValue_t DEVICE_REPLY_INVALID = MAKE_RETURN_CODE(0xC4); //syntax etc is correct but still not ok, eg parameters where none are expected // Standard codes used in buildCommandFromCommand - static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE( - 0xD0); - static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = - MAKE_RETURN_CODE(0xD1); + static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE(0xD0); + static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = MAKE_RETURN_CODE(0xD1); + + // Standard codes used in getSwitches + static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(0xE1); //!< Return in getSwitches() to specify there are no switches + + // static const ReturnValue_t ONE_SWITCH = MAKE_RETURN_CODE(8); + // static const ReturnValue_t TWO_SWITCHES = MAKE_RETURN_CODE(9); + // where is this used? + // static const ReturnValue_t COMMAND_MAP_ERROR = MAKE_RETURN_CODE(11); /** * Communication action that will be executed. @@ -97,10 +110,10 @@ public: * This is used by the child class to tell the base class what to do. */ enum CommunicationAction_t: uint8_t { - SEND_WRITE,//!< RMAP send write - GET_WRITE, //!< RMAP get write - SEND_READ, //!< RMAP send read - GET_READ, //!< RMAP get read + SEND_WRITE,//!< Send write + GET_WRITE, //!< Get write + SEND_READ, //!< Send read + GET_READ, //!< Get read NOTHING //!< Do nothing. }; diff --git a/returnvalues/HasReturnvaluesIF.h b/returnvalues/HasReturnvaluesIF.h index 5adbca3fc..b8b72a9fc 100644 --- a/returnvalues/HasReturnvaluesIF.h +++ b/returnvalues/HasReturnvaluesIF.h @@ -9,19 +9,13 @@ typedef uint16_t ReturnValue_t; - - - - class HasReturnvaluesIF { public: static const ReturnValue_t RETURN_OK = 0; - static const ReturnValue_t RETURN_FAILED = 1; + static const ReturnValue_t RETURN_FAILED = 0xFFFF; virtual ~HasReturnvaluesIF() { } }; - - #endif /* HASRETURNVALUESIF_H_ */ From b2b6b8ee23bc1ed05a4b1e1fc583a9c3f1f71cef Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 24 Mar 2020 15:33:18 +0100 Subject: [PATCH 0133/1774] added initializeInterface for comIF/cookie --- devicehandlers/DeviceCommunicationIF.h | 12 ++++++++++++ devicehandlers/DeviceHandlerBase.cpp | 9 ++++----- devicehandlers/DeviceHandlerBase.h | 2 +- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 6f2715041..931fc8b5e 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -46,6 +46,18 @@ public: virtual ~DeviceCommunicationIF() {} + /** + * @brief Device specific initialization, using the cookie. + * @details + * The cookie is already prepared in the factory. If the communication + * interface needs to be set up in some way and requires cookie information, + * this can be performed in this function, which is called on device handler + * initialization. + * @param cookie + * @return + */ + virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0; + /** * Called by DHB in the SEND_WRITE doSendWrite(). * This function is used to send data to the physical device diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index ebb361d97..ad699508f 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -102,11 +102,10 @@ ReturnValue_t DeviceHandlerBase::initialize() { return RETURN_FAILED; } -// result = communicationInterface->open(&cookie, logicalAddress, -// maxDeviceReplyLen, comParameter1, comParameter2); -// if (result != RETURN_OK) { -// return result; -// } + result = communicationInterface->initializeInterface(comCookie); + if (result != RETURN_OK) { + return result; + } IPCStore = objectManager->get(objects::IPC_STORE); if (IPCStore == NULL) { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 5faaa8e01..dcca2cc4b 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -464,7 +464,7 @@ protected: * indicates either that all raw messages to and from the device should be sent to #theOneWhoWantsToReadRawTraffic * or that all device TM should be downlinked to #theOneWhoWantsToReadRawTraffic */ - enum WiretappingMode { + enum WiretappingMode: uint8_t { OFF = 0, RAW = 1, TM = 2 } wiretappingMode; From 163779622fd9b7d367a0fe05d236928e2727d06e Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 25 Mar 2020 02:08:35 +0100 Subject: [PATCH 0134/1774] DHB: replyLen in replyMap now --- devicehandlers/DeviceHandlerBase.cpp | 38 +++++++------ devicehandlers/DeviceHandlerBase.h | 83 +++++++++++++++------------- 2 files changed, 67 insertions(+), 54 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index ad699508f..068a62de6 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -332,37 +332,35 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode, } } -ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap( - DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, - uint8_t periodic, bool hasDifferentReplyId, DeviceCommandId_t replyId) { -//No need to check, as we may try to insert multiple times. +ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, + uint16_t maxDelayCycles, size_t replyLen, uint8_t periodic, + bool hasDifferentReplyId, DeviceCommandId_t replyId) { + //No need to check, as we may try to insert multiple times. insertInCommandMap(deviceCommand); if (hasDifferentReplyId) { - return insertInReplyMap(replyId, maxDelayCycles, periodic); + return insertInReplyMap(replyId, maxDelayCycles, replyLen, periodic); } else { - return insertInReplyMap(deviceCommand, maxDelayCycles, periodic); + return insertInReplyMap(deviceCommand, maxDelayCycles, replyLen, periodic); } } ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId, - uint16_t maxDelayCycles, uint8_t periodic) { + uint16_t maxDelayCycles, size_t replyLen, uint8_t periodic) { DeviceReplyInfo info; info.maxDelayCycles = maxDelayCycles; info.periodic = periodic; info.delayCycles = 0; + info.replyLen = replyLen; info.command = deviceCommandMap.end(); - std::pair::iterator, bool> returnValue; - returnValue = deviceReplyMap.insert( - std::pair(replyId, info)); - if (returnValue.second) { + std::pair result = deviceReplyMap.emplace(replyId, info); + if (result.second) { return RETURN_OK; } else { return RETURN_FAILED; } } -ReturnValue_t DeviceHandlerBase::insertInCommandMap( - DeviceCommandId_t deviceCommand) { +ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceCommand) { DeviceCommandInfo info; info.expectedReplies = 0; info.isExecuting = false; @@ -378,9 +376,8 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap( } } -ReturnValue_t DeviceHandlerBase::updateReplyMapEntry( - DeviceCommandId_t deviceReply, uint16_t delayCycles, - uint16_t maxDelayCycles, uint8_t periodic) { +ReturnValue_t DeviceHandlerBase::updateReplyMapEntry(DeviceCommandId_t deviceReply, + uint16_t delayCycles, uint16_t maxDelayCycles, uint8_t periodic) { std::map::iterator iter = deviceReplyMap.find(deviceReply); if (iter == deviceReplyMap.end()) { @@ -547,6 +544,15 @@ void DeviceHandlerBase::doGetWrite() { void DeviceHandlerBase::doSendRead() { ReturnValue_t result; + + DeviceReplyIter iter = deviceReplyMap.find(cookieInfo.pendingCommand->first); + if(iter != deviceReplyMap.end()) { + requestLen = iter->second.replyLen; + } + else { + requestLen = 0; + } + result = communicationInterface->requestReceiveMessage(comCookie, requestLen); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index dcca2cc4b..b4882b9d1 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -275,26 +275,33 @@ protected: * @details * This is used by the base class to check the data received for valid packets. * It only checks if a valid packet starts at @c start. - * It also only checks the structural validy of the packet, eg checksums lengths and protocol data. + * It also only checks the structural validy of the packet, + * e.g. checksums lengths and protocol data. * No information check is done, e.g. range checks etc. * - * Errors should be reported directly, the base class does NOT report any errors based on the return - * value of this function. + * Errors should be reported directly, the base class does NOT report + * any errors based on the returnvalue of this function. * * @param start start of remaining buffer to be scanned * @param len length of remaining buffer to be scanned * @param[out] foundId the id of the data found in the buffer. - * @param[out] foundLen length of the data found. Is to be set in function, buffer is scanned at previous position + foundLen. + * @param[out] foundLen length of the data found. Is to be set in function, + * buffer is scanned at previous position + foundLen. * @return * - @c RETURN_OK a valid packet was found at @c start, @c foundLen is valid - * - @c RETURN_FAILED no reply could be found starting at @c start, implies @c foundLen is not valid, base class will call scanForReply() again with ++start - * - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid, eg checksum error, implies @c foundLen is valid, can be used to skip some bytes + * - @c RETURN_FAILED no reply could be found starting at @c start, + * implies @c foundLen is not valid, + * base class will call scanForReply() again with ++start + * - @c DeviceHandlerIF::INVALID_DATA a packet was found but it is invalid, + * e.g. checksum error, implies @c foundLen is valid, can be used to skip some bytes * - @c DeviceHandlerIF::LENGTH_MISSMATCH @c len is invalid * - @c DeviceHandlerIF::IGNORE_REPLY_DATA Ignore this specific part of the packet * - @c DeviceHandlerIF::IGNORE_FULL_PACKET Ignore the packet - * - @c APERIODIC_REPLY if a valid reply is received that has not been requested by a command, but should be handled anyway (@see also fillCommandAndCookieMap() ) + * - @c APERIODIC_REPLY if a valid reply is received that has not been + * requested by a command, but should be handled anyway + * (@see also fillCommandAndCookieMap() ) */ - virtual ReturnValue_t scanForReply(const uint8_t *start, size_t len, + virtual ReturnValue_t scanForReply(const uint8_t *start, size_t remainingSize, DeviceCommandId_t *foundId, size_t *foundLen) = 0; /** @@ -513,6 +520,30 @@ protected: */ CookieIF *comCookie; + struct DeviceCommandInfo { + bool isExecuting; //!< Indicates if the command is already executing. + uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0. + uint8_t expectedRepliesWhenEnablingReplyMap; //!< Constant value which specifies expected replies when enabling reply map. Inititated in insertInCommandAndReplyMap() + MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander. + }; + typedef std::map DeviceCommandMap; + + /** + * @brief Information about expected replies + * + * This is used to keep track of pending replies + */ + struct DeviceReplyInfo { + uint16_t maxDelayCycles; //!< The maximum number of cycles the handler should wait for a reply to this command. + uint16_t delayCycles; //!< The currently remaining cycles the handler should wait for a reply, 0 means there is no reply expected + size_t replyLen = 0; //!< Expected size of the reply. + uint8_t periodic; //!< if this is !=0, the delayCycles will not be reset to 0 but to maxDelayCycles + DeviceCommandMap::iterator command; //!< The command that expects this reply. + }; + + typedef std::map DeviceReplyMap; + typedef DeviceReplyMap::iterator DeviceReplyIter; + /** * The MessageQueue used to receive device handler commands and to send replies. */ @@ -696,7 +727,7 @@ protected: * @return RETURN_OK when the command was successfully inserted, COMMAND_MAP_ERROR else. */ ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, - uint16_t maxDelayCycles, uint8_t periodic = 0, + uint16_t maxDelayCycles, size_t replyLen = 0, uint8_t periodic = 0, bool hasDifferentReplyId = false, DeviceCommandId_t replyId = 0); /** * This is a helper method to insert replies in the reply map. @@ -707,7 +738,7 @@ protected: * @return RETURN_OK when the command was successfully inserted, COMMAND_MAP_ERROR else. */ ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand, - uint16_t maxDelayCycles, uint8_t periodic = 0); + uint16_t maxDelayCycles, size_t replyLen = 0, uint8_t periodic = 0); /** * A simple command to add a command to the commandList. * @param deviceCommand The command to add @@ -762,14 +793,6 @@ protected: */ virtual void modeChanged(void); - struct DeviceCommandInfo { - bool isExecuting; //!< Indicates if the command is already executing. - uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0. - uint8_t expectedRepliesWhenEnablingReplyMap; //!< Constant value which specifies expected replies when enabling reply map. Inititated in insertInCommandAndReplyMap() - MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander. - }; - - typedef std::map DeviceCommandMap; /** * Enable the reply checking for a command * @@ -780,16 +803,16 @@ protected: * When found, copies maxDelayCycles to delayCycles in the reply information and sets the command to * expect one reply. * - * Can be overwritten by the child, if a command activates multiple replies or replyId differs from - * commandId. + * Can be overwritten by the child, if a command activates multiple replies + * or replyId differs from commandId. * Notes for child implementations: * - If the command was not found in the reply map, NO_REPLY_EXPECTED MUST be returned. * - A failure code may be returned if something went fundamentally wrong. * * @param deviceCommand * @return - RETURN_OK if a reply was activated. - * - NO_REPLY_EXPECTED if there was no reply found. This is not an error case as many commands - * do not expect a reply. + * - NO_REPLY_EXPECTED if there was no reply found. This is not an + * error case as many commands do not expect a reply. */ virtual ReturnValue_t enableReplyInReplyMap(DeviceCommandMap::iterator cmd, uint8_t expectedReplies = 1, bool useAlternateId = false, @@ -884,22 +907,6 @@ protected: bool commandIsExecuting(DeviceCommandId_t commandId); - /** - * Information about expected replies - * - * This is used to keep track of pending replies - */ - struct DeviceReplyInfo { - uint16_t maxDelayCycles; //!< The maximum number of cycles the handler should wait for a reply to this command. - uint16_t delayCycles; //!< The currently remaining cycles the handler should wait for a reply, 0 means there is no reply expected - uint8_t periodic; //!< if this is !=0, the delayCycles will not be reset to 0 but to maxDelayCycles - DeviceCommandMap::iterator command; //!< The command that expects this reply. - }; - - /** - * Definition for the important reply Map. - */ - typedef std::map DeviceReplyMap; /** * This map is used to check and track correct reception of all replies. * From 093fef5d6f2aea6589abe45077037057bfb879ba Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 26 Mar 2020 15:20:17 +0100 Subject: [PATCH 0135/1774] moved address_t typedef to cookieImoved address_t typedef to cookieIFF --- devicehandlers/CookieIF.h | 5 ++ devicehandlers/DeviceHandlerBase.cpp | 23 ++++---- devicehandlers/DeviceHandlerBase.h | 87 ++++++++++++++-------------- devicehandlers/DeviceHandlerIF.h | 7 +-- 4 files changed, 64 insertions(+), 58 deletions(-) diff --git a/devicehandlers/CookieIF.h b/devicehandlers/CookieIF.h index d8781cd73..fc89c1af8 100644 --- a/devicehandlers/CookieIF.h +++ b/devicehandlers/CookieIF.h @@ -8,6 +8,11 @@ #define FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ #include +/** + * @brief Physical address type + */ +typedef uint32_t address_t; + class CookieIF { public: /** diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 068a62de6..b1af2689c 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -365,11 +365,8 @@ ReturnValue_t DeviceHandlerBase::insertInCommandMap(DeviceCommandId_t deviceComm info.expectedReplies = 0; info.isExecuting = false; info.sendReplyTo = NO_COMMANDER; - std::pair::iterator, bool> returnValue; - returnValue = deviceCommandMap.insert( - std::pair(deviceCommand, - info)); - if (returnValue.second) { + std::pair result = deviceCommandMap.emplace(deviceCommand,info); + if (result.second) { return RETURN_OK; } else { return RETURN_FAILED; @@ -489,7 +486,7 @@ void DeviceHandlerBase::replyToReply(DeviceReplyMap::iterator iter, return; } //Check if more replies are expected. If so, do nothing. - DeviceCommandInfo* info = &(iter->second.command->second); + DeviceCommandInfo * info = &(iter->second.command->second); if (--info->expectedReplies == 0) { //Check if it was transition or internal command. Don't send any replies in that case. if (info->sendReplyTo != NO_COMMANDER) { @@ -550,13 +547,17 @@ void DeviceHandlerBase::doSendRead() { requestLen = iter->second.replyLen; } else { - requestLen = 0; + requestLen = comCookie->getMaxReplyLen(); } result = communicationInterface->requestReceiveMessage(comCookie, requestLen); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; - } else { + } + else if(result == NO_READ_REQUEST) { + return; + } + else { triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result); //We can't inform anyone, because we don't know which command was sent last. //So, we need to wait for a timeout. @@ -816,9 +817,9 @@ ReturnValue_t DeviceHandlerBase::enableReplyInReplyMap( iter = deviceReplyMap.find(command->first); } if (iter != deviceReplyMap.end()) { - DeviceReplyInfo & info = iter->second; - info.delayCycles = info.maxDelayCycles; - info.command = command; + DeviceReplyInfo * info = &(iter->second); + info->delayCycles = info->maxDelayCycles; + info->command = command; command->second.expectedReplies = expectedReplies; return RETURN_OK; } else { diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index b4882b9d1..129fb288b 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -194,6 +194,9 @@ protected: * different commands can built returned depending on the submode. * * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. + * If variable command frequence is required, a counter can be used and + * the frequency in the reply map has to be set manually + * by calling updateReplyMap(). * * @param[out] id the device command id that has been built * @return @@ -527,6 +530,7 @@ protected: MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander. }; typedef std::map DeviceCommandMap; + typedef DeviceCommandMap::iterator DeviceCommandIter; /** * @brief Information about expected replies @@ -674,48 +678,6 @@ protected: */ virtual void doTransition(Mode_t modeFrom, Submode_t subModeFrom); - /** - * Is the combination of mode and submode valid? - * - * @param mode - * @param submode - * @return - * - @c RETURN_OK if valid - * - @c RETURN_FAILED if invalid - */ - virtual ReturnValue_t isModeCombinationValid(Mode_t mode, - Submode_t submode); - - /** - * Get the Rmap action for the current step. - * - * The step number can be read from #pstStep. - * - * @return The Rmap action to execute in this step - */ - virtual CommunicationAction_t getComAction(); - - /** - * Build the device command to send for raw mode. - * - * This is only called in @c MODE_RAW. It is for the rare case that in raw mode packets - * are to be sent by the handler itself. It is NOT needed for the raw commanding service. - * Its only current use is in the STR handler which gets its raw packets from a different - * source. - * Also it can be used for transitional commands, to get the device ready for @c MODE_RAW - * - * As it is almost never used, there is a default implementation returning @c NOTHING_TO_SEND. - * - * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. - * - * @param[out] id the device command id built - * @return - * - @c RETURN_OK when a command is to be sent - * - not @c NOTHING_TO_SEND when no command is to be sent - */ - virtual ReturnValue_t buildChildRawCommand(); - - /** * This is a helper method to facilitate inserting entries in the command map. * @param deviceCommand Identifier of the command to add. @@ -765,6 +727,47 @@ protected: */ uint8_t getReplyDelayCycles(DeviceCommandId_t deviceCommand); + /** + * Is the combination of mode and submode valid? + * + * @param mode + * @param submode + * @return + * - @c RETURN_OK if valid + * - @c RETURN_FAILED if invalid + */ + virtual ReturnValue_t isModeCombinationValid(Mode_t mode, + Submode_t submode); + + /** + * Get the Rmap action for the current step. + * + * The step number can be read from #pstStep. + * + * @return The Rmap action to execute in this step + */ + virtual CommunicationAction_t getComAction(); + + /** + * Build the device command to send for raw mode. + * + * This is only called in @c MODE_RAW. It is for the rare case that in raw mode packets + * are to be sent by the handler itself. It is NOT needed for the raw commanding service. + * Its only current use is in the STR handler which gets its raw packets from a different + * source. + * Also it can be used for transitional commands, to get the device ready for @c MODE_RAW + * + * As it is almost never used, there is a default implementation returning @c NOTHING_TO_SEND. + * + * #rawPacket and #rawPacketLen must be set by this method to the packet to be sent. + * + * @param[out] id the device command id built + * @return + * - @c RETURN_OK when a command is to be sent + * - not @c NOTHING_TO_SEND when no command is to be sent + */ + virtual ReturnValue_t buildChildRawCommand(); + /** * Construct a command reply containing a raw reply. * diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index 5ea527e95..c6baf7af0 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -7,11 +7,6 @@ #include #include -/** - * @brief Physical address type - */ -typedef uint32_t address_t; - /** * @brief This is the Interface used to communicate with a device handler. * @details Includes all expected return values, events and modes. @@ -95,6 +90,8 @@ public: // Standard codes used in buildCommandFromCommand static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE(0xD0); static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = MAKE_RETURN_CODE(0xD1); + // Standard codes used in buildNomalDeviceCommand + static const ReturnValue_t NO_READ_REQUEST = MAKE_RETURN_CODE(0xD2); // Standard codes used in getSwitches static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(0xE1); //!< Return in getSwitches() to specify there are no switches From e252a5b795147d11371514b9defad39d91a596ed Mon Sep 17 00:00:00 2001 From: "jakob.meier" Date: Thu, 26 Mar 2020 19:20:16 +0100 Subject: [PATCH 0136/1774] file system support --- memory/FileSystemMessage.cpp | 28 ++++++++++++++++++++++++++++ memory/FileSystemMessage.h | 30 ++++++++++++++++++++++++++++++ memory/HasFileSystemIF.h | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 94 insertions(+) create mode 100644 memory/FileSystemMessage.cpp create mode 100644 memory/FileSystemMessage.h create mode 100644 memory/HasFileSystemIF.h diff --git a/memory/FileSystemMessage.cpp b/memory/FileSystemMessage.cpp new file mode 100644 index 000000000..efbc80097 --- /dev/null +++ b/memory/FileSystemMessage.cpp @@ -0,0 +1,28 @@ +/* + * FileSystemMessage.cpp + * + * Created on: 19.01.2020 + * Author: Jakob Meier + */ + +#include "FileSystemMessage.h" +#include + +ReturnValue_t FileSystemMessage::setWriteToFileCommand(CommandMessage* message, + MessageQueueId_t replyQueueId, store_address_t storageID) { + message->setCommand(WRITE_TO_FILE); + message->setParameter(replyQueueId); + message->setParameter2(storageID.raw); + return HasReturnvaluesIF::RETURN_OK; +} + +store_address_t FileSystemMessage::getStoreID(const CommandMessage* message) { + store_address_t temp; + temp.raw = message->getParameter2(); + return temp; +} + +MessageQueueId_t FileSystemMessage::getReplyQueueId(const CommandMessage* message){ + return message->getParameter(); +} + diff --git a/memory/FileSystemMessage.h b/memory/FileSystemMessage.h new file mode 100644 index 000000000..b6fd7309e --- /dev/null +++ b/memory/FileSystemMessage.h @@ -0,0 +1,30 @@ +/* + * FileSystemMessage.h + * + * Created on: 19.01.2020 + * Author: Jakob Meier + */ + +#ifndef FRAMEWORK_MEMORY_FILESYSTEMMESSAGE_H_ +#define FRAMEWORK_MEMORY_FILESYSTEMMESSAGE_H_ + +#include +#include +#include + +class FileSystemMessage { +private: + FileSystemMessage(); //A private ctor inhibits instantiation +public: + static const uint8_t MESSAGE_ID = MESSAGE_TYPE::FILE_SYSTEM_MESSAGE; + static const Command_t CREATE_FILE = MAKE_COMMAND_ID( 0x01 ); + static const Command_t DELETE_FILE = MAKE_COMMAND_ID( 0x02 ); + static const Command_t WRITE_TO_FILE = MAKE_COMMAND_ID( 0x80 ); + + static ReturnValue_t setWriteToFileCommand(CommandMessage* message, MessageQueueId_t replyToQueue, store_address_t storageID ); + static store_address_t getStoreID( const CommandMessage* message ); + static MessageQueueId_t getReplyQueueId(const CommandMessage* message); + +}; + +#endif /* FRAMEWORK_MEMORY_FILESYSTEMMESSAGE_H_ */ diff --git a/memory/HasFileSystemIF.h b/memory/HasFileSystemIF.h new file mode 100644 index 000000000..8b66f88b7 --- /dev/null +++ b/memory/HasFileSystemIF.h @@ -0,0 +1,36 @@ +/* + * HasFileSystemIF.h + * + * Created on: 19.01.2020 + * Author: Jakob Meier + */ + +#ifndef FRAMEWORK_MEMORY_HASFILESYSTEMIF_H_ +#define FRAMEWORK_MEMORY_HASFILESYSTEMIF_H_ + +#include + +class HasFileSystemIF { +public: + + virtual ~HasFileSystemIF() {} + /** + * Function to get the MessageQueueId_t of the implementing object + * @return MessageQueueId_t of the object + */ + virtual MessageQueueId_t getCommandQueue() const = 0; + /** + * Function to write to a file + * @param dirname Directory of the file + * @param filename The filename of the file + * @param data The data to write to the file + * @param size The size of the data to write + * @param packetNumber Counts the number of packets. For large files the write procedure must be split in multiple calls to writeToFile + */ + virtual ReturnValue_t writeToFile(const char* dirname, char* filename, const uint8_t* data, uint32_t size, uint16_t packetNumber) = 0; + virtual ReturnValue_t createFile(const char* dirname, const char* filename, const uint8_t* data, uint32_t size) = 0; + virtual ReturnValue_t deleteFile(const char* dirname, const char* filename) = 0; +}; + + +#endif /* FRAMEWORK_MEMORY_HASFILESYSTEMIF_H_ */ From 0e56a094d305a35b80bdb20cc0c3cdcd533bd888 Mon Sep 17 00:00:00 2001 From: "jakob.meier" Date: Thu, 26 Mar 2020 19:43:38 +0100 Subject: [PATCH 0137/1774] merged FwMessageTypes --- ipc/FwMessageTypes.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ipc/FwMessageTypes.h b/ipc/FwMessageTypes.h index ec1c9aa28..07e3d2458 100644 --- a/ipc/FwMessageTypes.h +++ b/ipc/FwMessageTypes.h @@ -14,7 +14,8 @@ enum FW_MESSAGE_TYPE { MONITORING, MEMORY, PARAMETER, - FW_MESSAGES_COUNT + FW_MESSAGES_COUNT, + FILE_SYSTEM_MESSAGE }; } From 5d071a1cf1e4160386566cd1bcd1eeb70e65e5f7 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 26 Mar 2020 19:53:05 +0100 Subject: [PATCH 0138/1774] new device comIF return value in DHB request receive message --- devicehandlers/DeviceCommunicationIF.h | 32 +++++++++++++++----------- devicehandlers/DeviceHandlerBase.cpp | 6 ++--- devicehandlers/DeviceHandlerIF.h | 2 -- osal/FreeRTOS/BinarySemaphore.cpp | 20 ++++++++-------- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 931fc8b5e..ddd27d10c 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -38,11 +38,16 @@ class DeviceCommunicationIF: public HasReturnvaluesIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF; - static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x01); - static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x02); - static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x03); - static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x04); - static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x05); + //!< This is used if no read request is to be made by the device handler. + static const ReturnValue_t NO_READ_REQUEST = MAKE_RETURN_CODE(0x01); + //! General protocol error. Define more concrete errors in child handler + static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02); + //! If cookie is a null pointer + static const ReturnValue_t NULLPOINTER = MAKE_RETURN_CODE(0x03); + static const ReturnValue_t INVALID_COOKIE_TYPE = MAKE_RETURN_CODE(0x04); + // is this needed if there is no open/close call? + static const ReturnValue_t NOT_ACTIVE = MAKE_RETURN_CODE(0x05); + static const ReturnValue_t TOO_MUCH_DATA = MAKE_RETURN_CODE(0x06); virtual ~DeviceCommunicationIF() {} @@ -54,7 +59,8 @@ public: * this can be performed in this function, which is called on device handler * initialization. * @param cookie - * @return + * @return -@c RETURN_OK if initialization was successfull + * - Everything else triggers failure event with returnvalue as parameter 1 */ virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0; @@ -66,8 +72,7 @@ public: * @param data * @param len * @return -@c RETURN_OK for successfull send - * - Everything else triggers sending failed event with - * returnvalue as parameter 1 + * - Everything else triggers failure event with returnvalue as parameter 1 */ virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData, size_t sendLen) = 0; @@ -77,8 +82,7 @@ public: * Get send confirmation that the data in sendMessage() was sent successfully. * @param cookie * @return -@c RETURN_OK if data was sent successfull - * - Everything else triggers sending failed event with - * returnvalue as parameter 1 + * - Everything else triggers falure event with returnvalue as parameter 1 */ virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0; @@ -86,7 +90,10 @@ public: * Called by DHB in the SEND_WRITE doSendRead(). * Request a reply. * @param cookie - * @return + * @return -@c RETURN_OK to confirm the request for data has been sent. + * -@c NO_READ_REQUEST if no request shall be made. readReceivedMessage() + * will not be called in the respective communication cycle. + * - Everything else triggers failure event with returnvalue as parameter 1 */ virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0; @@ -98,8 +105,7 @@ public: * @param data * @param len * @return @c RETURN_OK for successfull receive - * - Everything else triggers receiving failed with - * returnvalue as parameter 1 + * - Everything else triggers failure event with returnvalue as parameter 1 */ virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) = 0; diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index b1af2689c..8187ffdef 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -554,7 +554,7 @@ void DeviceHandlerBase::doSendRead() { if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; } - else if(result == NO_READ_REQUEST) { + else if(result == DeviceCommunicationIF::NO_READ_REQUEST) { return; } else { @@ -777,8 +777,8 @@ void DeviceHandlerBase::buildRawDeviceCommand(CommandMessage* commandMessage) { replyReturnvalueToCommand(result, RAW_COMMAND_ID); storedRawData.raw = StorageManagerIF::INVALID_ADDRESS; } else { - cookieInfo.pendingCommand = deviceCommandMap.find( - (DeviceCommandId_t) RAW_COMMAND_ID); + cookieInfo.pendingCommand = deviceCommandMap. + find((DeviceCommandId_t) RAW_COMMAND_ID); cookieInfo.pendingCommand->second.isExecuting = true; cookieInfo.state = COOKIE_WRITE_READY; } diff --git a/devicehandlers/DeviceHandlerIF.h b/devicehandlers/DeviceHandlerIF.h index c6baf7af0..34aa41144 100644 --- a/devicehandlers/DeviceHandlerIF.h +++ b/devicehandlers/DeviceHandlerIF.h @@ -90,8 +90,6 @@ public: // Standard codes used in buildCommandFromCommand static const ReturnValue_t INVALID_COMMAND_PARAMETER = MAKE_RETURN_CODE(0xD0); static const ReturnValue_t INVALID_NUMBER_OR_LENGTH_OF_PARAMETERS = MAKE_RETURN_CODE(0xD1); - // Standard codes used in buildNomalDeviceCommand - static const ReturnValue_t NO_READ_REQUEST = MAKE_RETURN_CODE(0xD2); // Standard codes used in getSwitches static const ReturnValue_t NO_SWITCH = MAKE_RETURN_CODE(0xE1); //!< Return in getSwitches() to specify there are no switches diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 4ec61ff7a..631e4742d 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -11,8 +11,8 @@ #include "task.h" BinarySemaphore::BinarySemaphore() { - xSemaphoreCreateBinary(handle); // @suppress("Function cannot be resolved") - if(handle == NULL) { + xSemaphoreCreateBinary(handle); + if(handle == nullptr) { error << "Binary semaphore creation failure" << std::endl; } } @@ -22,7 +22,7 @@ BinarySemaphore::~BinarySemaphore() { } ReturnValue_t BinarySemaphore::takeBinarySemaphore(uint32_t timeoutMs) { - if(handle == NULL) { + if(handle == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } TickType_t timeout = portMAX_DELAY; @@ -39,7 +39,7 @@ ReturnValue_t BinarySemaphore::takeBinarySemaphore(uint32_t timeoutMs) { } ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks) { - if(handle == NULL) { + if(handle == nullptr) { return SEMAPHORE_NOT_FOUND; } @@ -52,7 +52,7 @@ ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(TickType_t timeout } ReturnValue_t BinarySemaphore::giveBinarySemaphore() { - if (handle == NULL) { + if (handle == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } BaseType_t returncode = xSemaphoreGive(handle); @@ -68,7 +68,7 @@ SemaphoreHandle_t BinarySemaphore::getSemaphore() { } ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) { - if (semaphore == NULL) { + if (semaphore == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } BaseType_t returncode = xSemaphoreGive(semaphore); @@ -80,13 +80,15 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) } void BinarySemaphore::resetSemaphore() { - vSemaphoreDelete(handle); - xSemaphoreCreateBinary(handle); + if(handle != nullptr) { + vSemaphoreDelete(handle); + xSemaphoreCreateBinary(handle); + } } ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) { - if (semaphore == NULL) { + if (semaphore == nullptr) { return HasReturnvaluesIF::RETURN_FAILED; } BaseType_t returncode = xSemaphoreGiveFromISR(semaphore, higherPriorityTaskWoken); From 93678adc5a8570f444e82259c991f8b5e378cae8 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 28 Mar 2020 00:09:15 +0100 Subject: [PATCH 0139/1774] replace std::set by std::multiset so there can be multiple entries with same pollignTime --- devicehandlers/FixedSlotSequence.cpp | 5 ++++- devicehandlers/FixedSlotSequence.h | 17 ++++++++++------- tasks/FixedTimeslotTaskIF.h | 3 ++- 3 files changed, 16 insertions(+), 9 deletions(-) diff --git a/devicehandlers/FixedSlotSequence.cpp b/devicehandlers/FixedSlotSequence.cpp index f01b13992..23bb0e78a 100644 --- a/devicehandlers/FixedSlotSequence.cpp +++ b/devicehandlers/FixedSlotSequence.cpp @@ -104,11 +104,14 @@ ReturnValue_t FixedSlotSequence::checkSequence() const { count++; } else { // All ok, print slot. - // (*slotIt)->print(); + //info << "Current slot polling time: " << std::endl; + //info << std::dec << slotIt->pollingTimeMs << std::endl; } time = slotIt->pollingTimeMs; slotIt++; } + //info << "Number of elements in slot list: " + // << slotList.size() << std::endl; if (count > 0) { return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/devicehandlers/FixedSlotSequence.h b/devicehandlers/FixedSlotSequence.h index 974dbb2bd..813d2fce2 100644 --- a/devicehandlers/FixedSlotSequence.h +++ b/devicehandlers/FixedSlotSequence.h @@ -6,8 +6,8 @@ #include #include -using SlotList = std::set; -using SlotListIter = std::set::iterator; +using SlotList = std::multiset; +using SlotListIter = std::multiset::iterator; /** * @brief This class is the representation of a Polling Sequence Table in software. @@ -69,11 +69,14 @@ public: /** * \brief This method returns the time until the next software component is invoked. * - * \details This method is vitally important for the operation of the PST. By fetching the polling time - * of the current slot and that of the next one (or the first one, if the list end is reached) - * it calculates and returns the interval in milliseconds within which the handler execution - * shall take place. If the next slot has the same time as the current one, it is ignored until - * a slot with different time or the end of the PST is found. + * \details + * This method is vitally important for the operation of the PST. + * By fetching the polling time of the current slot and that of the + * next one (or the first one, if the list end is reached) + * it calculates and returns the interval in milliseconds within + * which the handler execution shall take place. + * If the next slot has the same time as the current one, it is ignored + * until a slot with different time or the end of the PST is found. */ uint32_t getIntervalToNextSlotMs(); diff --git a/tasks/FixedTimeslotTaskIF.h b/tasks/FixedTimeslotTaskIF.h index d29801841..7edd67519 100644 --- a/tasks/FixedTimeslotTaskIF.h +++ b/tasks/FixedTimeslotTaskIF.h @@ -12,7 +12,8 @@ class FixedTimeslotTaskIF : public PeriodicTaskIF { public: virtual ~FixedTimeslotTaskIF() {} - virtual ReturnValue_t addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) = 0; + virtual ReturnValue_t addSlot(object_id_t componentId, + uint32_t slotTimeMs, int8_t executionStep) = 0; virtual ReturnValue_t checkSequence() const = 0; }; From 5218a0d84f987272ac2281c6a09ac4ef431dceb6 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sat, 28 Mar 2020 19:42:24 +0100 Subject: [PATCH 0140/1774] doc fix --- devicehandlers/DeviceCommunicationIF.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index ddd27d10c..68db82e60 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -10,7 +10,7 @@ */ /** - * @defgroup communication comm + * @defgroup comm Communication * @brief Communication software components. */ @@ -18,7 +18,7 @@ * @brief This is an interface to decouple device communication from * the device handler to allow reuse of these components. * @details - * Documentation: Dissertation Baetz p.138 + * Documentation: Dissertation Baetz p.138. * It works with the assumption that received data * is polled by a component. There are four generic steps of device communication: * From 996dbc9e4b952fa208b1e4b12d1ee291701ddf57 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 1 Apr 2020 12:41:54 +0200 Subject: [PATCH 0141/1774] DHB/Cookie refactoring --- devicehandlers/ChildHandlerBase.cpp | 2 +- devicehandlers/Cookie.cpp | 26 ------- devicehandlers/Cookie.h | 38 --------- devicehandlers/CookieIF.h | 63 ++++++++------- devicehandlers/DeviceCommunicationIF.h | 11 ++- devicehandlers/DeviceHandlerBase.cpp | 31 ++++---- devicehandlers/DeviceHandlerBase.h | 23 +----- rmap/RMAP.cpp | 6 +- rmap/RMAP.h | 6 +- rmap/RMAPChannelIF.h | 5 +- rmap/RMAPCookie.cpp | 10 +-- rmap/RMAPCookie.h | 9 ++- rmap/RmapDeviceCommunicationIF.cpp | 22 +++--- rmap/RmapDeviceCommunicationIF.h | 103 +++++++++++++------------ 14 files changed, 142 insertions(+), 213 deletions(-) delete mode 100644 devicehandlers/Cookie.cpp delete mode 100644 devicehandlers/Cookie.h diff --git a/devicehandlers/ChildHandlerBase.cpp b/devicehandlers/ChildHandlerBase.cpp index ac0b24384..c34846769 100644 --- a/devicehandlers/ChildHandlerBase.cpp +++ b/devicehandlers/ChildHandlerBase.cpp @@ -8,7 +8,7 @@ ChildHandlerBase::ChildHandlerBase(object_id_t setObjectId, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, uint32_t parent, FailureIsolationBase* customFdir, size_t cmdQueueSize) : DeviceHandlerBase(setObjectId, deviceCommunication, cookie, - maxDeviceReplyLen, setDeviceSwitch, thermalStatePoolId, + setDeviceSwitch, thermalStatePoolId, thermalRequestPoolId, (customFdir == NULL? &childHandlerFdir : customFdir), cmdQueueSize), parentId(parent), childHandlerFdir(setObjectId) { diff --git a/devicehandlers/Cookie.cpp b/devicehandlers/Cookie.cpp deleted file mode 100644 index 05b9425ca..000000000 --- a/devicehandlers/Cookie.cpp +++ /dev/null @@ -1,26 +0,0 @@ -/** - * @file Cookie.cpp - * - * @date 23.03.2020 - */ -#include - -Cookie::Cookie(address_t logicalAddress_): logicalAddress(logicalAddress_) { -} - -void Cookie::setAddress(address_t logicalAddress_) { - logicalAddress = logicalAddress_; -} -void Cookie::setMaxReplyLen(size_t maxReplyLen_) { - maxReplyLen = maxReplyLen_; -} - -address_t Cookie::getAddress() const { - return logicalAddress; -} - -size_t Cookie::getMaxReplyLen() const { - return maxReplyLen; -} - - diff --git a/devicehandlers/Cookie.h b/devicehandlers/Cookie.h deleted file mode 100644 index d76facc0d..000000000 --- a/devicehandlers/Cookie.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef COOKIE_H_ -#define COOKIE_H_ -#include - -/** - * @brief This datatype is used to identify different connection over a single interface - * (like RMAP or I2C) - * @details - * To use this class, implement a communication specific child cookie which - * inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling - * CookieIF* childCookie = new ChildCookie(...).´ - * - * This cookie is then passed to the child device handlers, which stores the - * pointer and passes it to the communication interface functions. - * - * The cookie can be used to store all kinds of information - * about the communication, like slave addresses, communication status, - * communication parameters etc. - * - * @ingroup comm - */ -class Cookie: public CookieIF { -public: - Cookie(); - Cookie(address_t logicalAddress_); - virtual ~Cookie() {}; - - virtual void setAddress(address_t logicalAddres_); - virtual void setMaxReplyLen(size_t maxReplyLen_); - - virtual address_t getAddress() const; - virtual size_t getMaxReplyLen() const; -private: - address_t logicalAddress = 0; - size_t maxReplyLen = 0; -}; - -#endif /* COOKIE_H_ */ diff --git a/devicehandlers/CookieIF.h b/devicehandlers/CookieIF.h index fc89c1af8..55fdb44b1 100644 --- a/devicehandlers/CookieIF.h +++ b/devicehandlers/CookieIF.h @@ -1,30 +1,33 @@ -/** - * @file CookieIF.h - * - * @date 23.03.2020 - */ - -#ifndef FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ -#define FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ -#include - -/** - * @brief Physical address type - */ -typedef uint32_t address_t; - -class CookieIF { -public: - /** - * Default empty virtual destructor. - */ - virtual ~CookieIF() {}; - - virtual void setAddress(address_t logicalAddress_) = 0; - virtual address_t getAddress() const = 0; - - virtual void setMaxReplyLen(size_t maxReplyLen_) = 0; - virtual size_t getMaxReplyLen() const = 0; -}; - -#endif /* FRAMEWORK_DEVICEHANDLERS_COOKIEIF_H_ */ +#ifndef COOKIE_H_ +#define COOKIE_H_ +#include +#include + +/** + * @brief Physical address type + */ +typedef uint32_t address_t; + +/** + * @brief This datatype is used to identify different connection over a single interface + * (like RMAP or I2C) + * @details + * To use this class, implement a communication specific child cookie which + * inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling + * CookieIF* childCookie = new ChildCookie(...). + * + * This cookie is then passed to the child device handlers, which stores the + * pointer and passes it to the communication interface functions. + * + * The cookie can be used to store all kinds of information + * about the communication, like slave addresses, communication status, + * communication parameters etc. + * + * @ingroup comm + */ +class CookieIF { +public: + virtual ~CookieIF() {}; +}; + +#endif /* COOKIE_H_ */ diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 68db82e60..657f7232a 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -1,7 +1,7 @@ #ifndef DEVICECOMMUNICATIONIF_H_ #define DEVICECOMMUNICATIONIF_H_ -#include +#include #include #include /** @@ -88,11 +88,14 @@ public: /** * Called by DHB in the SEND_WRITE doSendRead(). - * Request a reply. + * It is assumed that it is always possible to request a reply + * from a device. If a requestLen of 0 is supplied, no reply was enabled + * and communication specific action should be taken (e.g. read nothing + * or read everything). + * * @param cookie + * @param requestLen Size of data to read * @return -@c RETURN_OK to confirm the request for data has been sent. - * -@c NO_READ_REQUEST if no request shall be made. readReceivedMessage() - * will not be called in the respective communication cycle. * - Everything else triggers failure event with returnvalue as parameter 1 */ virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0; diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 8187ffdef..9691ac2f0 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -17,7 +17,7 @@ object_id_t DeviceHandlerBase::rawDataReceiverId = 0; object_id_t DeviceHandlerBase::defaultFDIRParentId = 0; DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, - CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch, + CookieIF * comCookie_, uint8_t setDeviceSwitch, uint32_t thermalStatePoolId, uint32_t thermalRequestPoolId, FailureIsolationBase* fdirInstance, size_t cmdQueueSize) : SystemObject(setObjectId), mode(MODE_OFF), submode(SUBMODE_NONE), @@ -31,7 +31,6 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t device childTransitionDelay(5000), transitionSourceMode(_MODE_POWER_DOWN), transitionSourceSubMode(SUBMODE_NONE), deviceSwitch(setDeviceSwitch) { - this->comCookie->setMaxReplyLen(maxReplyLen); commandQueue = QueueFactory::instance()-> createMessageQueue(cmdQueueSize, CommandMessage::MAX_MESSAGE_SIZE); cookieInfo.state = COOKIE_UNUSED; @@ -540,23 +539,27 @@ void DeviceHandlerBase::doGetWrite() { } void DeviceHandlerBase::doSendRead() { - ReturnValue_t result; - - DeviceReplyIter iter = deviceReplyMap.find(cookieInfo.pendingCommand->first); - if(iter != deviceReplyMap.end()) { - requestLen = iter->second.replyLen; - } - else { - requestLen = comCookie->getMaxReplyLen(); + ReturnValue_t result = RETURN_FAILED; + size_t requestLen = 0; + // If the device handler can only request replies after a command + // has been sent, there should be only one reply enabled and the + // correct reply length will be mapped. + for(DeviceReplyIter iter = deviceReplyMap.begin(); + iter != deviceReplyMap.end();iter++) + { + if(iter->second.delayCycles != 0) { + requestLen = iter->second.replyLen; + break; + } } result = communicationInterface->requestReceiveMessage(comCookie, requestLen); if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; } - else if(result == DeviceCommunicationIF::NO_READ_REQUEST) { +/* else if(result == DeviceCommunicationIF::NO_READ_REQUEST) { return; - } + }*/ else { triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result); //We can't inform anyone, because we don't know which command was sent last. @@ -1288,9 +1291,5 @@ void DeviceHandlerBase::setTaskIF(PeriodicTaskIF* task_){ void DeviceHandlerBase::debugInterface(uint8_t positionTracker, object_id_t objectId, uint32_t parameter) { } -uint32_t DeviceHandlerBase::getLogicalAddress() { - return this->comCookie->getAddress(); -} - void DeviceHandlerBase::performOperationHook() { } diff --git a/devicehandlers/DeviceHandlerBase.h b/devicehandlers/DeviceHandlerBase.h index 129fb288b..c162210c9 100644 --- a/devicehandlers/DeviceHandlerBase.h +++ b/devicehandlers/DeviceHandlerBase.h @@ -101,7 +101,7 @@ public: * @param cmdQueueSize */ DeviceHandlerBase(object_id_t setObjectId, object_id_t deviceCommunication, - CookieIF * comCookie_, size_t maxReplyLen, uint8_t setDeviceSwitch, + CookieIF * comCookie_, uint8_t setDeviceSwitch, uint32_t thermalStatePoolId = PoolVariableIF::NO_PARAMETER, uint32_t thermalRequestPoolId = PoolVariableIF::NO_PARAMETER, FailureIsolationBase* fdirInstance = nullptr, size_t cmdQueueSize = 20); @@ -439,11 +439,6 @@ protected: */ size_t rawPacketLen = 0; - /** - * Size of data to request. - */ - size_t requestLen = 0; - /** * The mode the device handler is currently in. * @@ -463,11 +458,6 @@ protected: */ uint8_t pstStep = 0; - /** - * This will be used in the RMAP getRead command as expected length, is set by the constructor, can be modiefied at will. - */ - const uint32_t maxDeviceReplyLen = 0; - /** * wiretapping flag: * @@ -526,7 +516,6 @@ protected: struct DeviceCommandInfo { bool isExecuting; //!< Indicates if the command is already executing. uint8_t expectedReplies; //!< Dynamic value to indicate how many replies are expected. Inititated with 0. - uint8_t expectedRepliesWhenEnablingReplyMap; //!< Constant value which specifies expected replies when enabling reply map. Inititated in insertInCommandAndReplyMap() MessageQueueId_t sendReplyTo; //!< if this is != NO_COMMANDER, DHB was commanded externally and shall report everything to commander. }; typedef std::map DeviceCommandMap; @@ -847,11 +836,6 @@ protected: */ virtual bool dontCheckQueue(); - /** - * Used to retrieve logical address - * @return logicalAddress - */ - virtual uint32_t getLogicalAddress(); Mode_t getBaseMode(Mode_t transitionMode); bool isAwaitingReply(); @@ -962,11 +946,6 @@ private: */ CookieInfo cookieInfo; - /** - * cached from ctor for initialize() - */ - //const uint32_t logicalAddress = 0; - /** * Used for timing out mode transitions. * diff --git a/rmap/RMAP.cpp b/rmap/RMAP.cpp index 4c95f6c9e..927fe746f 100644 --- a/rmap/RMAP.cpp +++ b/rmap/RMAP.cpp @@ -12,8 +12,8 @@ RMAP::RMAP(){ } -ReturnValue_t RMAP::sendWriteCommand(RMAPCookie *cookie, uint8_t* buffer, - uint32_t length) { +ReturnValue_t RMAP::sendWriteCommand(RMAPCookie *cookie, const uint8_t* buffer, + size_t length) { uint8_t instruction; if ((buffer == NULL) && (length != 0)) { @@ -61,7 +61,7 @@ ReturnValue_t RMAP::sendReadCommand(RMAPCookie *cookie, uint32_t expLength) { } ReturnValue_t RMAP::getReadReply(RMAPCookie *cookie, uint8_t **buffer, - uint32_t *size) { + size_t *size) { if (cookie->getChannel() == NULL) { return COMMAND_NO_CHANNEL; } diff --git a/rmap/RMAP.h b/rmap/RMAP.h index 195574f85..91aa123e2 100644 --- a/rmap/RMAP.h +++ b/rmap/RMAP.h @@ -153,8 +153,8 @@ public: * - @c COMMAND_NULLPOINTER datalen was != 0 but data was == NULL in write command * - return codes of RMAPChannelIF::sendCommand() */ - static ReturnValue_t sendWriteCommand(RMAPCookie *cookie, uint8_t* buffer, - uint32_t length); + static ReturnValue_t sendWriteCommand(RMAPCookie *cookie, const uint8_t* buffer, + size_t length); /** * get the reply to a write command @@ -204,7 +204,7 @@ public: * - return codes of RMAPChannelIF::getReply() */ static ReturnValue_t getReadReply(RMAPCookie *cookie, uint8_t **buffer, - uint32_t *size); + size_t *size); /** * @see sendReadCommand() diff --git a/rmap/RMAPChannelIF.h b/rmap/RMAPChannelIF.h index 6549c8ef9..34623bb35 100644 --- a/rmap/RMAPChannelIF.h +++ b/rmap/RMAPChannelIF.h @@ -3,6 +3,7 @@ #include #include +#include class RMAPChannelIF { public: @@ -73,7 +74,7 @@ public: * - @c NOT_SUPPORTED if you dont feel like implementing something... */ virtual ReturnValue_t sendCommand(RMAPCookie *cookie, uint8_t instruction, - uint8_t *data, uint32_t datalen)=0; + const uint8_t *data, size_t datalen)=0; /** * get the reply to an rmap command @@ -92,7 +93,7 @@ public: * - all RMAP standard replies */ virtual ReturnValue_t getReply(RMAPCookie *cookie, uint8_t **databuffer, - uint32_t *len)=0; + size_t *len)=0; /** * diff --git a/rmap/RMAPCookie.cpp b/rmap/RMAPCookie.cpp index 84e407ba2..223b5165d 100644 --- a/rmap/RMAPCookie.cpp +++ b/rmap/RMAPCookie.cpp @@ -93,11 +93,11 @@ RMAPCookie::~RMAPCookie() { } -//uint32_t RMAPCookie::getMaxReplyLen() const { -// return maxReplyLen; -//} -// -void RMAPCookie::setMaxReplyLen(uint32_t maxReplyLen) { +size_t RMAPCookie::getMaxReplyLen() const { + return maxReplyLen; +} + +void RMAPCookie::setMaxReplyLen(size_t maxReplyLen) { this->maxReplyLen = maxReplyLen; } diff --git a/rmap/RMAPCookie.h b/rmap/RMAPCookie.h index cf033bae8..99ebd6a20 100644 --- a/rmap/RMAPCookie.h +++ b/rmap/RMAPCookie.h @@ -1,12 +1,13 @@ #ifndef RMAPCOOKIE_H_ #define RMAPCOOKIE_H_ -#include +#include #include +#include class RMAPChannelIF; -class RMAPCookie : public Cookie { +class RMAPCookie : public CookieIF { public: //To Uli: Sorry, I need an empty ctor to initialize an array of cookies. RMAPCookie(); @@ -28,8 +29,8 @@ public: void setCommandMask(uint8_t commandMask); uint8_t getCommandMask(); - //size_t getMaxReplyLen() const; - void setMaxReplyLen(uint32_t maxReplyLen); + size_t getMaxReplyLen() const; + void setMaxReplyLen(size_t maxReplyLen); uint16_t getTransactionIdentifier() const; void setTransactionIdentifier(uint16_t id_); diff --git a/rmap/RmapDeviceCommunicationIF.cpp b/rmap/RmapDeviceCommunicationIF.cpp index 4958b3ed7..6dc91339f 100644 --- a/rmap/RmapDeviceCommunicationIF.cpp +++ b/rmap/RmapDeviceCommunicationIF.cpp @@ -5,43 +5,43 @@ RmapDeviceCommunicationIF::~RmapDeviceCommunicationIF() { } -ReturnValue_t RmapDeviceCommunicationIF::sendMessage(Cookie* cookie, - uint8_t* data, uint32_t len) { - return RMAP::sendWriteCommand((RMAPCookie *) cookie, data, len); +ReturnValue_t RmapDeviceCommunicationIF::sendMessage(CookieIF *cookie, + const uint8_t * sendData, size_t sendLen) { + return RMAP::sendWriteCommand((RMAPCookie *) cookie, sendData, sendLen); } -ReturnValue_t RmapDeviceCommunicationIF::getSendSuccess(Cookie* cookie) { +ReturnValue_t RmapDeviceCommunicationIF::getSendSuccess(CookieIF* cookie) { return RMAP::getWriteReply((RMAPCookie *) cookie); } ReturnValue_t RmapDeviceCommunicationIF::requestReceiveMessage( - Cookie* cookie) { + CookieIF *cookie, size_t requestLen) { return RMAP::sendReadCommand((RMAPCookie *) cookie, ((RMAPCookie *) cookie)->getMaxReplyLen()); } -ReturnValue_t RmapDeviceCommunicationIF::readReceivedMessage(Cookie* cookie, - uint8_t** buffer, uint32_t* size) { +ReturnValue_t RmapDeviceCommunicationIF::readReceivedMessage(CookieIF* cookie, + uint8_t** buffer, size_t * size) { return RMAP::getReadReply((RMAPCookie *) cookie, buffer, size); } -ReturnValue_t RmapDeviceCommunicationIF::setAddress(Cookie* cookie, +ReturnValue_t RmapDeviceCommunicationIF::setAddress(CookieIF* cookie, uint32_t address) { ((RMAPCookie *) cookie)->setAddress(address); return HasReturnvaluesIF::RETURN_OK; } -uint32_t RmapDeviceCommunicationIF::getAddress(Cookie* cookie) { +uint32_t RmapDeviceCommunicationIF::getAddress(CookieIF* cookie) { return ((RMAPCookie *) cookie)->getAddress(); } -ReturnValue_t RmapDeviceCommunicationIF::setParameter(Cookie* cookie, +ReturnValue_t RmapDeviceCommunicationIF::setParameter(CookieIF* cookie, uint32_t parameter) { //TODO Empty? return HasReturnvaluesIF::RETURN_FAILED; } -uint32_t RmapDeviceCommunicationIF::getParameter(Cookie* cookie) { +uint32_t RmapDeviceCommunicationIF::getParameter(CookieIF* cookie) { return 0; } diff --git a/rmap/RmapDeviceCommunicationIF.h b/rmap/RmapDeviceCommunicationIF.h index 45963d860..12bac57ae 100644 --- a/rmap/RmapDeviceCommunicationIF.h +++ b/rmap/RmapDeviceCommunicationIF.h @@ -17,66 +17,73 @@ class RmapDeviceCommunicationIF: public DeviceCommunicationIF { public: virtual ~RmapDeviceCommunicationIF(); - /** - * This method is mission specific as the open call will return a mission specific cookie - * - * @param cookie A cookie, can be mission specific subclass of RMAP Cookie - * @param address The address of the RMAP Cookie - * @param maxReplyLen Maximum length of expected reply - * @return + * @brief Device specific initialization, using the cookie. + * @details + * The cookie is already prepared in the factory. If the communication + * interface needs to be set up in some way and requires cookie information, + * this can be performed in this function, which is called on device handler + * initialization. + * @param cookie + * @return -@c RETURN_OK if initialization was successfull + * - Everything else triggers failure event with returnvalue as parameter 1 */ - virtual ReturnValue_t open(Cookie **cookie, uint32_t address, - uint32_t maxReplyLen) = 0; + virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0; /** - * Use an existing cookie to open a connection to a new DeviceCommunication. - * The previous connection must not be closed. - * If the returnvalue is not RETURN_OK, the cookie is unchanged and - * can be used with the previous connection. + * Called by DHB in the SEND_WRITE doSendWrite(). + * This function is used to send data to the physical device + * by implementing and calling related drivers or wrapper functions. + * @param cookie + * @param data + * @param len + * @return -@c RETURN_OK for successfull send + * - Everything else triggers failure event with returnvalue as parameter 1 + */ + virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData, + size_t sendLen); + + /** + * Called by DHB in the GET_WRITE doGetWrite(). + * Get send confirmation that the data in sendMessage() was sent successfully. + * @param cookie + * @return -@c RETURN_OK if data was sent successfull + * - Everything else triggers falure event with returnvalue as parameter 1 + */ + virtual ReturnValue_t getSendSuccess(CookieIF *cookie); + + /** + * Called by DHB in the SEND_WRITE doSendRead(). + * It is assumed that it is always possible to request a reply + * from a device. * * @param cookie - * @param address - * @param maxReplyLen - * @return + * @return -@c RETURN_OK to confirm the request for data has been sent. + * -@c NO_READ_REQUEST if no request shall be made. readReceivedMessage() + * will not be called in the respective communication cycle. + * - Everything else triggers failure event with returnvalue as parameter 1 */ - virtual ReturnValue_t reOpen(Cookie *cookie, uint32_t address, - uint32_t maxReplyLen) = 0; - + virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen); /** - * Closing call of connection and free memory of cookie. - * Mission dependent call + * Called by DHB in the GET_WRITE doGetRead(). + * This function is used to receive data from the physical device + * by implementing and calling related drivers or wrapper functions. * @param cookie + * @param data + * @param len + * @return @c RETURN_OK for successfull receive + * - Everything else triggers failure event with returnvalue as parameter 1 */ - virtual void close(Cookie *cookie) = 0; + virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, + size_t *size); - //SHOULDDO can data be const? - /** - * - * - * @param cookie Expects an RMAPCookie or derived from RMAPCookie Class - * @param data Data to be send - * @param len Length of the data to be send - * @return - Return codes of RMAP::sendWriteCommand() - */ - virtual ReturnValue_t sendMessage(Cookie *cookie, uint8_t *data, - uint32_t len); - - virtual ReturnValue_t getSendSuccess(Cookie *cookie); - - virtual ReturnValue_t requestReceiveMessage(Cookie *cookie); - - virtual ReturnValue_t readReceivedMessage(Cookie *cookie, uint8_t **buffer, - uint32_t *size); - - virtual ReturnValue_t setAddress(Cookie *cookie, uint32_t address); - - virtual uint32_t getAddress(Cookie *cookie); - - virtual ReturnValue_t setParameter(Cookie *cookie, uint32_t parameter); - - virtual uint32_t getParameter(Cookie *cookie); + ReturnValue_t setAddress(CookieIF* cookie, + uint32_t address); + uint32_t getAddress(CookieIF* cookie); + ReturnValue_t setParameter(CookieIF* cookie, + uint32_t parameter); + uint32_t getParameter(CookieIF* cookie); }; #endif /* MISSION_RMAP_RMAPDEVICECOMMUNICATIONINTERFACE_H_ */ From 8f39820ace6ecd146b5ac8e0ce10797c79159801 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 1 Apr 2020 17:05:55 +0200 Subject: [PATCH 0142/1774] doc formatting --- devicehandlers/CookieIF.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devicehandlers/CookieIF.h b/devicehandlers/CookieIF.h index 55fdb44b1..ca171ff40 100644 --- a/devicehandlers/CookieIF.h +++ b/devicehandlers/CookieIF.h @@ -9,8 +9,8 @@ typedef uint32_t address_t; /** - * @brief This datatype is used to identify different connection over a single interface - * (like RMAP or I2C) + * @brief This datatype is used to identify different connection over a + * single interface (like RMAP or I2C) * @details * To use this class, implement a communication specific child cookie which * inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling From 335df7787ab118078b1a22a26cdd1259d46240ed Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 1 Apr 2020 17:15:27 +0200 Subject: [PATCH 0143/1774] testing timeslot task 0 --- osal/FreeRTOS/FixedTimeslotTask.cpp | 4 ---- 1 file changed, 4 deletions(-) diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 71e166a52..c33c4ef04 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -58,10 +58,6 @@ ReturnValue_t FixedTimeslotTask::startTask() { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { if (objectManager->get(componentId) != NULL) { - if(slotTimeMs == 0) { - // FreeRTOS throws errors for zero values - slotTimeMs = 1; - } pst.addSlot(componentId, slotTimeMs, executionStep, this); return HasReturnvaluesIF::RETURN_OK; } From bd468a1b7498d217ca681e25c1932a39639f155f Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 1 Apr 2020 17:19:03 +0200 Subject: [PATCH 0144/1774] timeslot time 0 definitely leads to error --- osal/FreeRTOS/FixedTimeslotTask.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index c33c4ef04..7bfee7e6d 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -58,6 +58,11 @@ ReturnValue_t FixedTimeslotTask::startTask() { ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, uint32_t slotTimeMs, int8_t executionStep) { if (objectManager->get(componentId) != NULL) { + if(slotTimeMs == 0) { + // TODO: FreeRTOS throws errors for zero values. + // maybe there is a better solution than this. + slotTimeMs = 1; + } pst.addSlot(componentId, slotTimeMs, executionStep, this); return HasReturnvaluesIF::RETURN_OK; } From 80b1d28bc84ed4d9e86791b6e1c3e74abae3a4d4 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 00:23:29 +0200 Subject: [PATCH 0145/1774] new dvice com IF return value --- devicehandlers/DeviceCommunicationIF.h | 33 ++++++++++++++++---------- devicehandlers/DeviceHandlerBase.cpp | 5 +--- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 657f7232a..39cfadd75 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -29,8 +29,8 @@ * * To identify different connection over a single interface can return * so-called cookies to components. - * The CommunicationMessage message type can be used to extend the functionality of the - * ComIF if a separate polling task is required. + * The CommunicationMessage message type can be used to extend the + * functionality of the ComIF if a separate polling task is required. * @ingroup interfaces * @ingroup comm */ @@ -38,8 +38,9 @@ class DeviceCommunicationIF: public HasReturnvaluesIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::DEVICE_COMMUNICATION_IF; - //!< This is used if no read request is to be made by the device handler. - static const ReturnValue_t NO_READ_REQUEST = MAKE_RETURN_CODE(0x01); + //! This is returned in readReceivedMessage() if no reply was reived. + static const ReturnValue_t NO_REPLY_RECEIVED = MAKE_RETURN_CODE(0x01); + //! General protocol error. Define more concrete errors in child handler static const ReturnValue_t PROTOCOL_ERROR = MAKE_RETURN_CODE(0x02); //! If cookie is a null pointer @@ -60,7 +61,8 @@ public: * initialization. * @param cookie * @return -@c RETURN_OK if initialization was successfull - * - Everything else triggers failure event with returnvalue as parameter 1 + * - Everything else triggers failure event with + * returnvalue as parameter 1 */ virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0; @@ -72,7 +74,8 @@ public: * @param data * @param len * @return -@c RETURN_OK for successfull send - * - Everything else triggers failure event with returnvalue as parameter 1 + * - Everything else triggers failure event with + * returnvalue as parameter 1 */ virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData, size_t sendLen) = 0; @@ -82,7 +85,8 @@ public: * Get send confirmation that the data in sendMessage() was sent successfully. * @param cookie * @return -@c RETURN_OK if data was sent successfull - * - Everything else triggers falure event with returnvalue as parameter 1 + * - Everything else triggers falure event with + * returnvalue as parameter 1 */ virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0; @@ -96,7 +100,8 @@ public: * @param cookie * @param requestLen Size of data to read * @return -@c RETURN_OK to confirm the request for data has been sent. - * - Everything else triggers failure event with returnvalue as parameter 1 + * - Everything else triggers failure event with + * returnvalue as parameter 1 */ virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0; @@ -105,10 +110,14 @@ public: * This function is used to receive data from the physical device * by implementing and calling related drivers or wrapper functions. * @param cookie - * @param data - * @param len - * @return @c RETURN_OK for successfull receive - * - Everything else triggers failure event with returnvalue as parameter 1 + * @param buffer [out] Set reply here (by using *buffer = ...) + * @param size [out] size pointer to set (by using *size = ...). + * Set to 0 if no reply was received + * @return -@c RETURN_OK for successfull receive + * -@c NO_REPLY_RECEIVED if not reply was received. Setting size to + * 0 has the same effect + * - Everything else triggers failure event with + * returnvalue as parameter 1 */ virtual ReturnValue_t readReceivedMessage(CookieIF *cookie, uint8_t **buffer, size_t *size) = 0; diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 9691ac2f0..9f23dd7f5 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -557,9 +557,6 @@ void DeviceHandlerBase::doSendRead() { if (result == RETURN_OK) { cookieInfo.state = COOKIE_READ_SENT; } -/* else if(result == DeviceCommunicationIF::NO_READ_REQUEST) { - return; - }*/ else { triggerEvent(DEVICE_REQUESTING_REPLY_FAILED, result); //We can't inform anyone, because we don't know which command was sent last. @@ -594,7 +591,7 @@ void DeviceHandlerBase::doGetRead() { return; } - if (receivedDataLen == 0) + if (receivedDataLen == 0 or result == DeviceCommunicationIF::NO_REPLY_RECEIVED) return; if (wiretappingMode == RAW) { From 4a35035b2890f3491d096afb22ad3421bc4d1e60 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 15:30:31 +0200 Subject: [PATCH 0146/1774] serial buffer adapted improvements --- serialize/SerialBufferAdapter.cpp | 127 ++++++++++++++---------------- serialize/SerialBufferAdapter.h | 34 +++----- 2 files changed, 68 insertions(+), 93 deletions(-) diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 6ac2894fe..978d8029a 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -2,83 +2,79 @@ #include #include -template -SerialBufferAdapter::SerialBufferAdapter(const uint8_t* buffer, - T bufferLength, bool serializeLength) : - currentBufferType(bufferType::CONST), serializeLength(serializeLength), - constBuffer(buffer), buffer(NULL), bufferLength(bufferLength) { +template +SerialBufferAdapter::SerialBufferAdapter(const void* buffer, + count_t bufferLength, bool serializeLength) : + m_serialize_length(serializeLength), + m_const_buffer(static_cast(buffer)), m_buffer(nullptr), + m_buffer_length(bufferLength) { } -template -SerialBufferAdapter::SerialBufferAdapter(uint8_t* buffer, T bufferLength, +template +SerialBufferAdapter::SerialBufferAdapter(void* buffer, count_t bufferLength, bool serializeLength) : - currentBufferType(bufferType::NORMAL),serializeLength(serializeLength), constBuffer(NULL), buffer(buffer), - bufferLength(bufferLength) { + m_serialize_length(serializeLength), m_buffer_length(bufferLength) { + uint8_t * member_buffer = static_cast(buffer); + m_buffer = member_buffer; + m_const_buffer = member_buffer; } -template -SerialBufferAdapter::SerialBufferAdapter(uint32_t* buffer, - T bufferLength, bool serializeLength) : - currentBufferType(bufferType::NORMAL),serializeLength(serializeLength), - constBuffer(NULL), buffer(reinterpret_cast(buffer)), - bufferLength(bufferLength*4) { + +template +SerialBufferAdapter::~SerialBufferAdapter() { } -template -SerialBufferAdapter::~SerialBufferAdapter() { -} - -template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, uint32_t* size, +template +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, uint32_t* size, const uint32_t max_size, bool bigEndian) const { - uint32_t serializedLength = bufferLength; - if (serializeLength) { + uint32_t serializedLength = m_buffer_length; + if (m_serialize_length) { serializedLength += AutoSerializeAdapter::getSerializedSize( - &bufferLength); + &m_buffer_length); } if (*size + serializedLength > max_size) { return BUFFER_TOO_SHORT; } else { - if (serializeLength) { - AutoSerializeAdapter::serialize(&bufferLength, buffer, size, + if (m_serialize_length) { + AutoSerializeAdapter::serialize(&m_buffer_length, buffer, size, max_size, bigEndian); } - if (this->constBuffer != NULL) { - memcpy(*buffer, this->constBuffer, bufferLength); - } else if (this->buffer != NULL) { - memcpy(*buffer, this->buffer, bufferLength); + if (this->m_const_buffer != nullptr) { + memcpy(*buffer, m_const_buffer, m_buffer_length); + } else if (this->m_buffer != nullptr) { + memcpy(*buffer, m_buffer, m_buffer_length); } else { return HasReturnvaluesIF::RETURN_FAILED; } - *size += bufferLength; - (*buffer) += bufferLength; + *size += m_buffer_length; + (*buffer) += m_buffer_length; return HasReturnvaluesIF::RETURN_OK; } } -template -uint32_t SerialBufferAdapter::getSerializedSize() const { - if (serializeLength) { - return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); +template +uint32_t SerialBufferAdapter::getSerializedSize() const { + if (m_serialize_length) { + return m_buffer_length + AutoSerializeAdapter::getSerializedSize(&m_buffer_length); } else { - return bufferLength; + return m_buffer_length; } } -template -ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, +template +ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) { //TODO Ignores Endian flag! if (buffer != NULL) { - if(serializeLength){ + if(m_serialize_length){ // Suggestion (would require removing rest of the block inside this if clause !): //ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian); //if (result != HasReturnvaluesIF::RETURN_OK) { // return result; //} - T serializedSize = AutoSerializeAdapter::getSerializedSize( - &bufferLength); - if((*size - bufferLength - serializedSize) >= 0){ + count_t serializedSize = AutoSerializeAdapter::getSerializedSize( + &m_buffer_length); + if((*size - m_buffer_length - serializedSize) >= 0){ *buffer += serializedSize; *size -= serializedSize; }else{ @@ -86,10 +82,10 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, } } //No Else If, go on with buffer - if (*size - bufferLength >= 0) { - *size -= bufferLength; - memcpy(this->buffer, *buffer, bufferLength); - (*buffer) += bufferLength; + if (*size - m_buffer_length >= 0) { + *size -= m_buffer_length; + memcpy(m_buffer, *buffer, m_buffer_length); + (*buffer) += m_buffer_length; return HasReturnvaluesIF::RETURN_OK; } else { return STREAM_TOO_SHORT; @@ -99,35 +95,30 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, } } -template -uint8_t * SerialBufferAdapter::getBuffer() { - if(currentBufferType != NORMAL) { - warning << "Wrong access function for stored type ! Use getConstBuffer()" << std::endl; - return 0; +template +uint8_t * SerialBufferAdapter::getBuffer() { + if(m_buffer == nullptr) { + error << "Wrong access function for stored type ! Use getConstBuffer()" << std::endl; + return nullptr; } - return buffer; + return m_buffer; } -template -const uint8_t * SerialBufferAdapter::getConstBuffer() { - if(currentBufferType != CONST) { - warning << "Wrong access function for stored type ! Use getBuffer()" << std::endl; - return 0; +template +const uint8_t * SerialBufferAdapter::getConstBuffer() { + if(m_const_buffer == nullptr) { + error << "Wrong access function for stored type ! Use getBuffer()" << std::endl; + return nullptr; } - return constBuffer; + return m_const_buffer; } -template -void SerialBufferAdapter::setBuffer(uint8_t * buffer_, T bufferLength_) { - buffer = buffer_; - bufferLength = bufferLength_; +template +void SerialBufferAdapter::setBuffer(void * buffer, count_t buffer_length) { + m_buffer = static_cast(buffer); + m_buffer_length = buffer_length; } -template -void SerialBufferAdapter::setBuffer(uint32_t * buffer_, T bufferLength_) { - buffer = reinterpret_cast(buffer_); - bufferLength = 4 * bufferLength_; -} //forward Template declaration for linker template class SerialBufferAdapter; diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 600bd692a..4ee4ca0b8 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -16,9 +16,10 @@ * * \ingroup serialize */ -template +template class SerialBufferAdapter: public SerializeIF { public: + /** * Constructor for constant uint8_t buffer. Length field can be serialized optionally. * Type of length can be supplied as template type. @@ -26,7 +27,7 @@ public: * @param bufferLength * @param serializeLength */ - SerialBufferAdapter(const uint8_t * buffer, T bufferLength, bool serializeLength = false); + SerialBufferAdapter(const void* buffer, count_t bufferLength, bool serializeLength = false); /** * Constructor for non-constant uint8_t buffer. Length field can be serialized optionally. @@ -35,16 +36,7 @@ public: * @param bufferLength * @param serializeLength */ - SerialBufferAdapter(uint8_t* buffer, T bufferLength, bool serializeLength = false); - - /** - * Constructoor for non-constant uint32_t buffer. Length field can be serialized optionally. - * Type of length can be supplied as template type. - * @param buffer - * @param bufferLength - * @param serializeLength - */ - SerialBufferAdapter(uint32_t* buffer,T bufferLength, bool serializeLength = false); + SerialBufferAdapter(void* buffer, count_t bufferLength, bool serializeLength = false); virtual ~SerialBufferAdapter(); @@ -58,20 +50,12 @@ public: uint8_t * getBuffer(); const uint8_t * getConstBuffer(); - void setBuffer(uint8_t * buffer_, T bufferLength_); - void setBuffer(uint32_t * buffer_, T bufferLength_); + void setBuffer(void* buffer_, count_t bufferLength_); private: - - enum bufferType { - NORMAL, - CONST - }; - bufferType currentBufferType; - - bool serializeLength; - const uint8_t *constBuffer; - uint8_t *buffer; - T bufferLength; + bool m_serialize_length = false; + const uint8_t *m_const_buffer = nullptr; + uint8_t *m_buffer = nullptr; + count_t m_buffer_length = 0; }; From a65a19f583b4f71b4c13e3d553fc6e990fd49ba9 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 15:33:24 +0200 Subject: [PATCH 0147/1774] deletd serial buffer adapter2 --- serialize/SerialBufferAdapter.cpp | 4 +- serialize/SerialBufferAdapter2.h | 148 ------------------------------ 2 files changed, 2 insertions(+), 150 deletions(-) delete mode 100644 serialize/SerialBufferAdapter2.h diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 978d8029a..859e7edfc 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -40,9 +40,9 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, uint32_t AutoSerializeAdapter::serialize(&m_buffer_length, buffer, size, max_size, bigEndian); } - if (this->m_const_buffer != nullptr) { + if (m_const_buffer != nullptr) { memcpy(*buffer, m_const_buffer, m_buffer_length); - } else if (this->m_buffer != nullptr) { + } else if (m_buffer != nullptr) { memcpy(*buffer, m_buffer, m_buffer_length); } else { return HasReturnvaluesIF::RETURN_FAILED; diff --git a/serialize/SerialBufferAdapter2.h b/serialize/SerialBufferAdapter2.h deleted file mode 100644 index 98e2d187d..000000000 --- a/serialize/SerialBufferAdapter2.h +++ /dev/null @@ -1,148 +0,0 @@ -#ifndef SERIALBUFFERADAPTER2_H_ -#define SERIALBUFFERADAPTER2_H_ - -#include -#include -#include - -#include - -/** - * This adapter provides an interface for SerializeIF to serialize or deserialize - * buffers with no length header but a known size. - * - * Additionally, the buffer length can be serialized too and will be put in front of the serialized buffer. - * - * Can be used with SerialLinkedListAdapter by declaring a SerializeElement with - * SerialElement> serialBufferElement. - * Right now, the SerialBufferAdapter must always be initialized with the buffer and size ! - * - * \ingroup serialize - */ -template -class SerialBufferAdapter2: public SerializeIF { -public: - /** - * Constructor for constant uint8_t buffer. Length field can be serialized optionally. - * Type of length can be supplied as template type. - * @param buffer - * @param bufferLength - * @param serializeLength - */ - SerialBufferAdapter2(void * buffer_, count_t bufferLength_, bool serializeLength_ = false): - bufferLength(bufferLength_), serializeLength(serializeLength_) { - determineLengthInBytes(sizeof(BUFFER_TYPE)); - buffer = reinterpret_cast(buffer_); - constBuffer = NULL; - } - - SerialBufferAdapter2(const void * buffer_, count_t bufferLength_, bool serializeLength_ = false): - bufferLength(bufferLength_), serializeLength(serializeLength_) { - determineLengthInBytes(sizeof(BUFFER_TYPE)); - constBuffer = reinterpret_cast(buffer_); - buffer = NULL; - } - - ReturnValue_t serialize(uint8_t ** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - uint32_t serializedLength = bufferLength; - if (serializeLength) { - serializedLength += AutoSerializeAdapter::getSerializedSize( - &bufferLength); - } - if (*size + serializedLength > max_size) { - return BUFFER_TOO_SHORT; - } else { - if (serializeLength) { - AutoSerializeAdapter::serialize(&bufferLength, buffer, size, - max_size, bigEndian); - } - memcpy(*buffer, this->buffer, bufferLength); - *size += bufferLength; - (*buffer) += bufferLength; - return HasReturnvaluesIF::RETURN_OK; - } - } - - uint32_t getSerializedSize() const { - if (serializeLength) { - return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); - } else { - return bufferLength; - } - } - - ReturnValue_t deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { - //TODO Ignores Endian flag! - if (buffer != NULL) { - if(serializeLength){ - // Suggestion (would require removing rest of the block inside this if clause !): - //ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian); - //if (result != HasReturnvaluesIF::RETURN_OK) { - // return result; - //} - count_t serializedSize = AutoSerializeAdapter::getSerializedSize( - &bufferLength); - if((*size - bufferLength - serializedSize) >= 0){ - *buffer += serializedSize; - *size -= serializedSize; - }else{ - return STREAM_TOO_SHORT; - } - } - //No Else If, go on with buffer - if (*size - bufferLength >= 0) { - *size -= bufferLength; - memcpy(this->buffer, *buffer, bufferLength); - (*buffer) += bufferLength; - return HasReturnvaluesIF::RETURN_OK; - } else { - return STREAM_TOO_SHORT; - } - } else { - return HasReturnvaluesIF::RETURN_FAILED; - } - } - - - BUFFER_TYPE * getBuffer() { - return reinterpret_cast(buffer); - } - - void setBuffer(void * buffer_, count_t bufferLength_, bool serializeLength_ = false) { - buffer = buffer_; - bufferLength = bufferLength_; - serializeLength = serializeLength_; - determineLengthInBytes(sizeof(BUFFER_TYPE)); - } - - void setConstBuffer(const void * buffer_, count_t bufferLength_, bool serializeLength_ = false) { - constBuffer = buffer_; - bufferLength = bufferLength_; - serializeLength = serializeLength_; - determineLengthInBytes(sizeof(BUFFER_TYPE)); - } -private: - uint8_t * buffer; - const uint8_t * constBuffer; - count_t bufferLength; - bool serializeLength; - - void determineLengthInBytes(uint8_t typeSize) { - switch(typeSize) { - case(1): break; - case(2): - bufferLength *= 2; break; - case(4): - bufferLength *= 4; break; - case(8): - bufferLength *= 8; break; - default: - error << "Serial Buffer Adapter 2: Invalid type size, assuming regular uint8_t." << std::endl; - error << "Detected type size: " << (int) typeSize << std::endl; - } - } -}; - -#endif /* SERIALBUFFERADAPTER2_H_ */ From 06ae64d59c7de1bfaa63c63249cc56c53c47d829 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 15:46:10 +0200 Subject: [PATCH 0148/1774] CSB: replaced some uint32 with size_t --- tmtcservices/CommandingServiceBase.cpp | 6 +++--- tmtcservices/CommandingServiceBase.h | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index d70b90428..8d207d9c2 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -219,8 +219,8 @@ void CommandingServiceBase::handleRequestQueue() { void CommandingServiceBase::sendTmPacket(uint8_t subservice, - const uint8_t* data, uint32_t dataLen, const uint8_t* headerData, - uint32_t headerSize) { + const uint8_t* data, size_t dataLen, const uint8_t* headerData, + size_t headerSize) { TmPacketStored tmPacketStored(this->apid, this->service, subservice, this->tmPacketCounter, data, dataLen, headerData, headerSize); ReturnValue_t result = tmPacketStored.sendPacket( @@ -232,7 +232,7 @@ void CommandingServiceBase::sendTmPacket(uint8_t subservice, void CommandingServiceBase::sendTmPacket(uint8_t subservice, - object_id_t objectId, const uint8_t *data, uint32_t dataLen) { + object_id_t objectId, const uint8_t *data, size_t dataLen) { uint8_t buffer[sizeof(object_id_t)]; uint8_t* pBuffer = buffer; uint32_t size = 0; diff --git a/tmtcservices/CommandingServiceBase.h b/tmtcservices/CommandingServiceBase.h index a62b7397d..56e9b87de 100644 --- a/tmtcservices/CommandingServiceBase.h +++ b/tmtcservices/CommandingServiceBase.h @@ -124,7 +124,7 @@ protected: * - @c CSB or implementation specific return codes */ virtual ReturnValue_t getMessageQueueAndObject(uint8_t subservice, - const uint8_t *tcData, uint32_t tcDataLen, MessageQueueId_t *id, + const uint8_t *tcData, size_t tcDataLen, MessageQueueId_t *id, object_id_t *objectId) = 0; /** @@ -141,7 +141,7 @@ protected: * @return */ virtual ReturnValue_t prepareCommand(CommandMessage *message, - uint8_t subservice, const uint8_t *tcData, uint32_t tcDataLen, + uint8_t subservice, const uint8_t *tcData, size_t tcDataLen, uint32_t *state, object_id_t objectId) = 0; /** @@ -219,8 +219,8 @@ protected: * @param headerData HeaderData will be placed before data * @param headerSize Size of HeaderData */ - void sendTmPacket(uint8_t subservice, const uint8_t *data, uint32_t dataLen, - const uint8_t* headerData = NULL, uint32_t headerSize = 0); + void sendTmPacket(uint8_t subservice, const uint8_t *data, size_t dataLen, + const uint8_t* headerData = nullptr,size_t headerSize = 0); /** * To send TM packets of objects that still need to be serialized and consist of an object ID with appended data @@ -230,7 +230,7 @@ protected: * @param dataLen Length of Data */ void sendTmPacket(uint8_t subservice, object_id_t objectId, - const uint8_t *data, uint32_t dataLen); + const uint8_t *data, size_t dataLen); /** * To send packets has data which is in form of a SerializeIF or Adapters implementing it @@ -239,7 +239,7 @@ protected: * @param header Serialize IF header which will be placed before content */ void sendTmPacket(uint8_t subservice, SerializeIF* content, - SerializeIF* header = NULL); + SerializeIF* header = nullptr); virtual void handleUnrequestedReply(CommandMessage *reply); From 7079c9c56dc03bc1eb89311b831ff9f622257f81 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 17:58:39 +0200 Subject: [PATCH 0149/1774] replaced serializeIF serialize sizes with size_t --- action/ActionHelper.cpp | 5 +++-- action/CommandActionHelper.cpp | 2 +- container/FixedMap.h | 4 ++-- datapool/DataPoolAdmin.cpp | 2 +- datapool/DataPoolParameterWrapper.cpp | 2 +- datapool/DataPoolParameterWrapper.h | 4 ++-- datapool/DataSet.cpp | 4 ++-- datapool/DataSet.h | 4 ++-- datapool/PIDReader.h | 4 ++-- datapool/PoolRawAccess.cpp | 4 ++-- datapool/PoolRawAccess.h | 4 ++-- datapool/PoolRawAccessHelper.cpp | 11 ++++++----- datapool/PoolRawAccessHelper.h | 10 +++++----- datapool/PoolVariable.h | 4 ++-- datapool/PoolVector.h | 4 ++-- devicehandlers/DeviceTmReportingWrapper.cpp | 2 +- devicehandlers/DeviceTmReportingWrapper.h | 4 ++-- events/eventmatching/EventRangeMatcherBase.h | 4 ++-- globalfunctions/Type.cpp | 4 ++-- globalfunctions/Type.h | 4 ++-- globalfunctions/matching/MatchTree.h | 4 ++-- globalfunctions/matching/RangeMatcher.h | 4 ++-- health/HealthTable.cpp | 2 +- monitoring/LimitViolationReporter.cpp | 2 +- parameters/ParameterHelper.cpp | 2 +- parameters/ParameterWrapper.cpp | 8 ++++---- parameters/ParameterWrapper.h | 8 ++++---- power/Fuse.cpp | 4 ++-- power/Fuse.h | 4 ++-- power/PowerComponent.cpp | 4 ++-- power/PowerComponent.h | 4 ++-- serialize/SerialArrayListAdapter.h | 9 +++++---- serialize/SerialBufferAdapter.cpp | 4 ++-- serialize/SerialBufferAdapter.h | 4 ++-- serialize/SerialFixedArrayListAdapter.h | 4 ++-- serialize/SerialLinkedListAdapter.h | 6 +++--- serialize/SerializeAdapter.h | 14 +++++++------- serialize/SerializeElement.h | 6 ++++-- serialize/SerializeIF.h | 5 +++-- subsystem/Subsystem.cpp | 2 +- subsystem/modes/ModeDefinitions.h | 4 ++-- tmstorage/TmStorePackets.h | 8 ++++---- tmtcpacket/packetmatcher/ApidMatcher.h | 7 ++++--- tmtcpacket/packetmatcher/ServiceMatcher.h | 7 ++++--- tmtcpacket/packetmatcher/SubserviceMatcher.h | 7 ++++--- tmtcpacket/pus/TmPacketStored.cpp | 2 +- tmtcservices/CommandingServiceBase.cpp | 2 +- tmtcservices/PusVerificationReport.h | 4 ++-- 48 files changed, 118 insertions(+), 109 deletions(-) diff --git a/action/ActionHelper.cpp b/action/ActionHelper.cpp index 18e46fba9..96a4824c1 100644 --- a/action/ActionHelper.cpp +++ b/action/ActionHelper.cpp @@ -67,7 +67,8 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act } } -ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t replyId, SerializeIF* data, bool hideSender) { +ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, + ActionId_t replyId, SerializeIF* data, bool hideSender) { CommandMessage reply; store_address_t storeAddress; uint8_t *dataPtr; @@ -76,7 +77,7 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t rep //No error, there's simply nothing to report. return HasReturnvaluesIF::RETURN_OK; } - uint32_t size = 0; + size_t size = 0; ReturnValue_t result = ipcStore->getFreeElement(&storeAddress, maxSize, &dataPtr); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/action/CommandActionHelper.cpp b/action/CommandActionHelper.cpp index ceb97d3b9..e670121f4 100644 --- a/action/CommandActionHelper.cpp +++ b/action/CommandActionHelper.cpp @@ -26,7 +26,7 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - uint32_t size = 0; + size_t size = 0; result = data->serialize(&storePointer, &size, maxSize, true); if (result != HasReturnvaluesIF::RETURN_OK) { return result; diff --git a/container/FixedMap.h b/container/FixedMap.h index f5ee42445..314fb45a4 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -173,8 +173,8 @@ public: } } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&this->_size, buffer, size, max_size, bigEndian); uint32_t i = 0; diff --git a/datapool/DataPoolAdmin.cpp b/datapool/DataPoolAdmin.cpp index e66a44e96..250137265 100644 --- a/datapool/DataPoolAdmin.cpp +++ b/datapool/DataPoolAdmin.cpp @@ -272,7 +272,7 @@ ReturnValue_t DataPoolAdmin::sendParameter(MessageQueueId_t to, uint32_t id, return result; } - uint32_t storeElementSize = 0; + size_t storeElementSize = 0; result = wrapper->serialize(&storeElement, &storeElementSize, serializedSize, true); diff --git a/datapool/DataPoolParameterWrapper.cpp b/datapool/DataPoolParameterWrapper.cpp index 0ff2121d6..88ac51a6a 100644 --- a/datapool/DataPoolParameterWrapper.cpp +++ b/datapool/DataPoolParameterWrapper.cpp @@ -36,7 +36,7 @@ ReturnValue_t DataPoolParameterWrapper::set(uint8_t domainId, } ReturnValue_t DataPoolParameterWrapper::serialize(uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) const { + size_t* size, const size_t max_size, bool bigEndian) const { ReturnValue_t result; result = SerializeAdapter::serialize(&type, buffer, size, max_size, diff --git a/datapool/DataPoolParameterWrapper.h b/datapool/DataPoolParameterWrapper.h index faadf6599..32ba65098 100644 --- a/datapool/DataPoolParameterWrapper.h +++ b/datapool/DataPoolParameterWrapper.h @@ -11,8 +11,8 @@ public: ReturnValue_t set(uint8_t domainId, uint16_t parameterId); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; virtual uint32_t getSerializedSize() const; diff --git a/datapool/DataSet.cpp b/datapool/DataSet.cpp index b4725c735..ccd9fd3cb 100644 --- a/datapool/DataSet.cpp +++ b/datapool/DataSet.cpp @@ -106,8 +106,8 @@ uint8_t DataSet::lockDataPool() { return ::dataPool.lockDataPool(); } -ReturnValue_t DataSet::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t DataSet::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = RETURN_FAILED; for (uint16_t count = 0; count < fill_count; count++) { result = registeredVariables[count]->serialize(buffer, size, max_size, diff --git a/datapool/DataSet.h b/datapool/DataSet.h index 8e0132239..0732feb30 100644 --- a/datapool/DataSet.h +++ b/datapool/DataSet.h @@ -121,8 +121,8 @@ public: * @param bigEndian * @return */ - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; uint32_t getSerializedSize() const; diff --git a/datapool/PIDReader.h b/datapool/PIDReader.h index 299cc2fe6..68e70e869 100644 --- a/datapool/PIDReader.h +++ b/datapool/PIDReader.h @@ -126,8 +126,8 @@ public: return *this; } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return SerializeAdapter::serialize(&value, buffer, size, max_size, bigEndian); } diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index ff8fb9561..63dc5b49e 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -111,8 +111,8 @@ ReturnValue_t PoolRawAccess::getEntryEndianSafe(uint8_t* buffer, } -ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t PoolRawAccess::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { if (typeSize + *size <= max_size) { if (bigEndian) { #ifndef BYTE_ORDER_SYSTEM diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 52ba8b210..1599a40e1 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -81,8 +81,8 @@ public: * @return - @c RETURN_OK if serialization was successfull * - @c SerializeIF::BUFFER_TOO_SHORT if range check failed */ - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; /** * With this method, the content can be set from a big endian buffer safely. diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index 07ea44651..7ea3576f1 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -14,14 +14,15 @@ PoolRawAccessHelper::PoolRawAccessHelper(uint32_t * poolIdBuffer_, uint8_t numberOfParameters_): poolIdBuffer(reinterpret_cast(poolIdBuffer_)), - numberOfParameters(numberOfParameters_), validBufferIndex(0), validBufferIndexBit(1){ + numberOfParameters(numberOfParameters_), validBufferIndex(0), + validBufferIndexBit(1) { } PoolRawAccessHelper::~PoolRawAccessHelper() { } -ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size, - const uint32_t max_size, bool bigEndian) { +ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, size_t *size, + const size_t max_size, bool bigEndian) { SerializationArgs serializationArgs = {buffer, size, max_size, bigEndian}; ReturnValue_t result; int32_t remainingParametersSize = numberOfParameters * 4; @@ -39,8 +40,8 @@ ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, uint32_t *size, return result; } -ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, uint32_t * size, - const uint32_t max_size, bool bigEndian) { +ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, + size_t * size, const size_t max_size, bool bigEndian) { ReturnValue_t result; SerializationArgs argStruct = {buffer, size, max_size, bigEndian}; int32_t remainingParametersSize = numberOfParameters * 4; diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index 72f2324c6..4a4a1fabf 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -41,8 +41,8 @@ public: * @return @c RETURN_OK On success * @c RETURN_FAILED on failure */ - ReturnValue_t serialize(uint8_t ** buffer, uint32_t * size, - const uint32_t max_size, bool bigEndian); + ReturnValue_t serialize(uint8_t ** buffer, size_t * size, + const size_t max_size, bool bigEndian); /** * Serializes data pool entries into provided buffer with the validity mask buffer @@ -54,8 +54,8 @@ public: * @return @c RETURN_OK On success * @c RETURN_FAILED on failure */ - ReturnValue_t serializeWithValidityMask(uint8_t ** buffer, uint32_t * size, - const uint32_t max_size, bool bigEndian); + ReturnValue_t serializeWithValidityMask(uint8_t ** buffer, size_t * size, + const size_t max_size, bool bigEndian); private: @@ -68,7 +68,7 @@ private: struct SerializationArgs { uint8_t ** buffer; - uint32_t * size; + size_t * size; const uint32_t max_size; bool bigEndian; }; diff --git a/datapool/PoolVariable.h b/datapool/PoolVariable.h index 2c48ca3e1..76418ab82 100644 --- a/datapool/PoolVariable.h +++ b/datapool/PoolVariable.h @@ -193,8 +193,8 @@ public: return *this; } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return SerializeAdapter::serialize(&value, buffer, size, max_size, bigEndian); } diff --git a/datapool/PoolVector.h b/datapool/PoolVector.h index d3617d17a..154cb18aa 100644 --- a/datapool/PoolVector.h +++ b/datapool/PoolVector.h @@ -197,8 +197,8 @@ public: return *this; } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { uint16_t i; ReturnValue_t result; for (i = 0; i < vector_size; i++) { diff --git a/devicehandlers/DeviceTmReportingWrapper.cpp b/devicehandlers/DeviceTmReportingWrapper.cpp index 2c9e820fe..2be37dd4e 100644 --- a/devicehandlers/DeviceTmReportingWrapper.cpp +++ b/devicehandlers/DeviceTmReportingWrapper.cpp @@ -12,7 +12,7 @@ DeviceTmReportingWrapper::~DeviceTmReportingWrapper() { } ReturnValue_t DeviceTmReportingWrapper::serialize(uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) const { + size_t* size, const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&objectId, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/devicehandlers/DeviceTmReportingWrapper.h b/devicehandlers/DeviceTmReportingWrapper.h index 1cd9470d8..ecdeca495 100644 --- a/devicehandlers/DeviceTmReportingWrapper.h +++ b/devicehandlers/DeviceTmReportingWrapper.h @@ -11,8 +11,8 @@ public: SerializeIF *data); virtual ~DeviceTmReportingWrapper(); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; virtual uint32_t getSerializedSize() const; diff --git a/events/eventmatching/EventRangeMatcherBase.h b/events/eventmatching/EventRangeMatcherBase.h index 921a5d6a1..3906b6278 100644 --- a/events/eventmatching/EventRangeMatcherBase.h +++ b/events/eventmatching/EventRangeMatcherBase.h @@ -11,8 +11,8 @@ class EventRangeMatcherBase: public SerializeableMatcherIF { public: EventRangeMatcherBase(T from, T till, bool inverted) : rangeMatcher(from, till, inverted) { } virtual ~EventRangeMatcherBase() { } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return rangeMatcher.serialize(buffer, size, max_size, bigEndian); } uint32_t getSerializedSize() const { diff --git a/globalfunctions/Type.cpp b/globalfunctions/Type.cpp index 814d26f4e..e9bbab52d 100644 --- a/globalfunctions/Type.cpp +++ b/globalfunctions/Type.cpp @@ -59,8 +59,8 @@ uint8_t Type::getSize() const { } } -ReturnValue_t Type::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t Type::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { uint8_t ptc; uint8_t pfc; ReturnValue_t result = getPtcPfc(&ptc, &pfc); diff --git a/globalfunctions/Type.h b/globalfunctions/Type.h index 88df07b6f..8d595dafb 100644 --- a/globalfunctions/Type.h +++ b/globalfunctions/Type.h @@ -39,8 +39,8 @@ public: static ActualType_t getActualType(uint8_t ptc, uint8_t pfc); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; virtual uint32_t getSerializedSize() const; diff --git a/globalfunctions/matching/MatchTree.h b/globalfunctions/matching/MatchTree.h index 398cf3f0b..ccf464f09 100644 --- a/globalfunctions/matching/MatchTree.h +++ b/globalfunctions/matching/MatchTree.h @@ -45,8 +45,8 @@ public: return matchSubtree(iter, number); } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { iterator iter = this->begin(); uint8_t count = this->countRight(iter); ReturnValue_t result = SerializeAdapter::serialize(&count, diff --git a/globalfunctions/matching/RangeMatcher.h b/globalfunctions/matching/RangeMatcher.h index 10e07173b..8e0ae850f 100644 --- a/globalfunctions/matching/RangeMatcher.h +++ b/globalfunctions/matching/RangeMatcher.h @@ -27,8 +27,8 @@ public: } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&lowerBound, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { return result; diff --git a/health/HealthTable.cpp b/health/HealthTable.cpp index a575b2828..94b7cf0bf 100644 --- a/health/HealthTable.cpp +++ b/health/HealthTable.cpp @@ -65,7 +65,7 @@ bool HealthTable::hasHealth(object_id_t object) { void HealthTable::printAll(uint8_t* pointer, uint32_t maxSize) { mutex->lockMutex(MutexIF::NO_TIMEOUT); - uint32_t size = 0; + size_t size = 0; uint16_t count = healthMap.size(); ReturnValue_t result = SerializeAdapter::serialize(&count, &pointer, &size, maxSize, true); diff --git a/monitoring/LimitViolationReporter.cpp b/monitoring/LimitViolationReporter.cpp index 760e8b93d..77c3dad13 100644 --- a/monitoring/LimitViolationReporter.cpp +++ b/monitoring/LimitViolationReporter.cpp @@ -26,7 +26,7 @@ ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - uint32_t size = 0; + size_t size = 0; result = data->serialize(&dataTarget, &size, maxSize, true); if (result != HasReturnvaluesIF::RETURN_OK) { return result; diff --git a/parameters/ParameterHelper.cpp b/parameters/ParameterHelper.cpp index e260465ae..4ba2a1d99 100644 --- a/parameters/ParameterHelper.cpp +++ b/parameters/ParameterHelper.cpp @@ -94,7 +94,7 @@ ReturnValue_t ParameterHelper::sendParameter(MessageQueueId_t to, uint32_t id, return result; } - uint32_t storeElementSize = 0; + size_t storeElementSize = 0; result = description->serialize(&storeElement, &storeElementSize, serializedSize, true); diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index 8f661bb32..501c7c4d9 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -20,8 +20,8 @@ ParameterWrapper::ParameterWrapper(Type type, uint8_t rows, uint8_t columns, ParameterWrapper::~ParameterWrapper() { } -ReturnValue_t ParameterWrapper::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t ParameterWrapper::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result; result = SerializeAdapter::serialize(&type, buffer, size, max_size, @@ -88,8 +88,8 @@ uint32_t ParameterWrapper::getSerializedSize() const { } template -ReturnValue_t ParameterWrapper::serializeData(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t ParameterWrapper::serializeData(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { const T *element = (const T*) readonlyData; ReturnValue_t result; uint16_t dataSize = columns * rows; diff --git a/parameters/ParameterWrapper.h b/parameters/ParameterWrapper.h index f61786b8a..a78e586d9 100644 --- a/parameters/ParameterWrapper.h +++ b/parameters/ParameterWrapper.h @@ -25,8 +25,8 @@ public: const void *data); virtual ~ParameterWrapper(); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; virtual uint32_t getSerializedSize() const; @@ -128,8 +128,8 @@ private: const void *readonlyData; template - ReturnValue_t serializeData(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serializeData(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; template ReturnValue_t deSerializeData(uint8_t startingRow, uint8_t startingColumn, diff --git a/power/Fuse.cpp b/power/Fuse.cpp index dd5d3e3f4..93e982902 100644 --- a/power/Fuse.cpp +++ b/power/Fuse.cpp @@ -86,8 +86,8 @@ ReturnValue_t Fuse::check() { return result; } -ReturnValue_t Fuse::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t Fuse::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = RETURN_FAILED; for (DeviceList::const_iterator iter = devices.begin(); iter != devices.end(); iter++) { diff --git a/power/Fuse.h b/power/Fuse.h index 6da241788..a9542167c 100644 --- a/power/Fuse.h +++ b/power/Fuse.h @@ -49,8 +49,8 @@ public: uint8_t getFuseId() const; ReturnValue_t initialize(); DeviceList devices; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; uint32_t getSerializedSize() const; ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/power/PowerComponent.cpp b/power/PowerComponent.cpp index 6a87d88b8..83ed0e68e 100644 --- a/power/PowerComponent.cpp +++ b/power/PowerComponent.cpp @@ -17,8 +17,8 @@ PowerComponent::PowerComponent(object_id_t setId, uint8_t moduleId, float min, f twoSwitches), min(min), max(max), moduleId(moduleId) { } -ReturnValue_t PowerComponent::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&min, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/power/PowerComponent.h b/power/PowerComponent.h index a82fe1d7f..de08e5ec1 100644 --- a/power/PowerComponent.h +++ b/power/PowerComponent.h @@ -19,8 +19,8 @@ public: float getMin(); float getMax(); - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; uint32_t getSerializedSize() const; diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 3f80e97b6..0bc0a97b5 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -21,13 +21,14 @@ public: SerialArrayListAdapter(ArrayList *adaptee) : adaptee(adaptee) { } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return serialize(adaptee, buffer, size, max_size, bigEndian); } - static ReturnValue_t serialize(const ArrayList* list, uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) { + static ReturnValue_t serialize(const ArrayList* list, + uint8_t** buffer, size_t* size, const size_t max_size, + bool bigEndian) { // Serialize length field first ReturnValue_t result = SerializeAdapter::serialize(&list->size, buffer, size, max_size, bigEndian); diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 859e7edfc..a125ef44c 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -26,8 +26,8 @@ SerialBufferAdapter::~SerialBufferAdapter() { } template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { uint32_t serializedLength = m_buffer_length; if (m_serialize_length) { serializedLength += AutoSerializeAdapter::getSerializedSize( diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 4ee4ca0b8..f8ff122e7 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -40,8 +40,8 @@ public: virtual ~SerialBufferAdapter(); - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const; virtual uint32_t getSerializedSize() const; diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 67954d685..e10322f9c 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -32,8 +32,8 @@ public: SerialFixedArrayListAdapter(Args... args) : FixedArrayList(std::forward(args)...) { } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return SerialArrayListAdapter::serialize(this, buffer, size, max_size, bigEndian); } diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index ef1fa2007..196432af5 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -63,8 +63,8 @@ public: * @param bigEndian Specify endianness * @return */ - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { if (printCount) { count_t mySize = SinglyLinkedList::getSize(); ReturnValue_t result = SerializeAdapter::serialize(&mySize, @@ -78,7 +78,7 @@ public: } static ReturnValue_t serialize(const LinkedElement* element, - uint8_t** buffer, uint32_t* size, const uint32_t max_size, + uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) { diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 18240a95e..7654eb0d9 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -59,8 +59,8 @@ template class SerializeAdapter_ { public: static ReturnValue_t serialize(const T* object, uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) { - uint32_t ignoredSize = 0; + size_t* size, const size_t max_size, bool bigEndian) { + size_t ignoredSize = 0; if (size == NULL) { size = &ignoredSize; } @@ -115,9 +115,9 @@ public: template class SerializeAdapter_ { public: - ReturnValue_t serialize(const T* object, uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - uint32_t ignoredSize = 0; + ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + size_t ignoredSize = 0; if (size == NULL) { size = &ignoredSize; } @@ -137,7 +137,7 @@ template class SerializeAdapter { public: static ReturnValue_t serialize(const T* object, uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) { + size_t* size, const size_t max_size, bool bigEndian) { SerializeAdapter_::Is> adapter; return adapter.serialize(object, buffer, size, max_size, bigEndian); } @@ -158,7 +158,7 @@ class AutoSerializeAdapter { public: template static ReturnValue_t serialize(const T* object, uint8_t** buffer, - uint32_t* size, const uint32_t max_size, bool bigEndian) { + size_t* size, const size_t max_size, bool bigEndian) { SerializeAdapter_::Is> adapter; return adapter.serialize(object, buffer, size, max_size, bigEndian); } diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index cd040c0f7..81f557a5b 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -29,9 +29,11 @@ public: } SerializeElement() : LinkedElement(this) { } + T entry; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { return SerializeAdapter::serialize(&entry, buffer, size, max_size, bigEndian); } diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index fb750a083..d9d361c10 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -2,6 +2,7 @@ #define SERIALIZEIF_H_ #include +#include /** * @defgroup serialize Serialization @@ -36,8 +37,8 @@ public: virtual ~SerializeIF() { } - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const = 0; + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const = 0; virtual uint32_t getSerializedSize() const = 0; diff --git a/subsystem/Subsystem.cpp b/subsystem/Subsystem.cpp index 2d7d9c443..8b7f3851a 100644 --- a/subsystem/Subsystem.cpp +++ b/subsystem/Subsystem.cpp @@ -607,7 +607,7 @@ void Subsystem::sendSerializablesAsCommandMessage(Command_t command, } uint8_t *storeBuffer; store_address_t address; - uint32_t size = 0; + size_t size = 0; result = IPCStore->getFreeElement(&address, maxSize, &storeBuffer); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/subsystem/modes/ModeDefinitions.h b/subsystem/modes/ModeDefinitions.h index 8e7531f3d..8a88eb92e 100644 --- a/subsystem/modes/ModeDefinitions.h +++ b/subsystem/modes/ModeDefinitions.h @@ -18,8 +18,8 @@ public: uint8_t value3; uint8_t value4; - virtual ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result; diff --git a/tmstorage/TmStorePackets.h b/tmstorage/TmStorePackets.h index 6eea6f586..b31b37cb1 100644 --- a/tmstorage/TmStorePackets.h +++ b/tmstorage/TmStorePackets.h @@ -32,8 +32,8 @@ public: } uint16_t apid; uint16_t ssc; - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = SerializeAdapter::serialize(&apid, buffer, size, max_size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { @@ -218,8 +218,8 @@ public: } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { ReturnValue_t result = AutoSerializeAdapter::serialize(&apid,buffer,size,max_size,bigEndian); if(result!=HasReturnvaluesIF::RETURN_OK){ return result; diff --git a/tmtcpacket/packetmatcher/ApidMatcher.h b/tmtcpacket/packetmatcher/ApidMatcher.h index 1f1949682..0140340bd 100644 --- a/tmtcpacket/packetmatcher/ApidMatcher.h +++ b/tmtcpacket/packetmatcher/ApidMatcher.h @@ -22,9 +22,10 @@ public: return false; } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerializeAdapter::serialize(&apid, buffer, size, max_size, bigEndian); + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + return SerializeAdapter::serialize(&apid, buffer, + size, max_size, bigEndian); } uint32_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&apid); diff --git a/tmtcpacket/packetmatcher/ServiceMatcher.h b/tmtcpacket/packetmatcher/ServiceMatcher.h index 1a6781b40..be2dd2f56 100644 --- a/tmtcpacket/packetmatcher/ServiceMatcher.h +++ b/tmtcpacket/packetmatcher/ServiceMatcher.h @@ -22,9 +22,10 @@ public: return false; } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerializeAdapter::serialize(&service, buffer, size, max_size, bigEndian); + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + return SerializeAdapter::serialize(&service, buffer, + size, max_size, bigEndian); } uint32_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&service); diff --git a/tmtcpacket/packetmatcher/SubserviceMatcher.h b/tmtcpacket/packetmatcher/SubserviceMatcher.h index 1b589b201..de62e1835 100644 --- a/tmtcpacket/packetmatcher/SubserviceMatcher.h +++ b/tmtcpacket/packetmatcher/SubserviceMatcher.h @@ -20,9 +20,10 @@ public: return false; } } - ReturnValue_t serialize(uint8_t** buffer, uint32_t* size, - const uint32_t max_size, bool bigEndian) const { - return SerializeAdapter::serialize(&subService, buffer, size, max_size, bigEndian); + ReturnValue_t serialize(uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + return SerializeAdapter::serialize(&subService, buffer, size, + max_size, bigEndian); } uint32_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&subService); diff --git a/tmtcpacket/pus/TmPacketStored.cpp b/tmtcpacket/pus/TmPacketStored.cpp index bb9326418..c66e33245 100644 --- a/tmtcpacket/pus/TmPacketStored.cpp +++ b/tmtcpacket/pus/TmPacketStored.cpp @@ -58,7 +58,7 @@ TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service, setData(p_data); initializeTmPacket(apid, service, subservice, packetSubcounter); uint8_t* putDataHere = getSourceData(); - uint32_t size = 0; + size_t size = 0; if (header != NULL) { header->serialize(&putDataHere, &size, sourceDataSize, true); } diff --git a/tmtcservices/CommandingServiceBase.cpp b/tmtcservices/CommandingServiceBase.cpp index 8d207d9c2..5b3977567 100644 --- a/tmtcservices/CommandingServiceBase.cpp +++ b/tmtcservices/CommandingServiceBase.cpp @@ -235,7 +235,7 @@ void CommandingServiceBase::sendTmPacket(uint8_t subservice, object_id_t objectId, const uint8_t *data, size_t dataLen) { uint8_t buffer[sizeof(object_id_t)]; uint8_t* pBuffer = buffer; - uint32_t size = 0; + size_t size = 0; SerializeAdapter::serialize(&objectId, &pBuffer, &size, sizeof(object_id_t), true); TmPacketStored tmPacketStored(this->apid, this->service, subservice, diff --git a/tmtcservices/PusVerificationReport.h b/tmtcservices/PusVerificationReport.h index 7a173be9f..f8913627f 100644 --- a/tmtcservices/PusVerificationReport.h +++ b/tmtcservices/PusVerificationReport.h @@ -49,7 +49,7 @@ class PusSuccessReport { private: static const uint16_t MAX_SIZE = 7; uint8_t reportBuffer[MAX_SIZE]; - uint32_t reportSize; + size_t reportSize; uint8_t * pBuffer; public: PusSuccessReport(uint16_t setPacketId, uint16_t setSequenceControl, @@ -63,7 +63,7 @@ class PusFailureReport { private: static const uint16_t MAX_SIZE = 16; uint8_t reportBuffer[MAX_SIZE]; - uint32_t reportSize; + size_t reportSize; uint8_t * pBuffer; public: PusFailureReport(uint16_t setPacketId, uint16_t setSequenceControl, From 87852e5f2a3983e21c99a18f8503a511a158cecd Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 21:54:11 +0200 Subject: [PATCH 0150/1774] replaced getSerializedSize returnvalue with size_t --- action/ActionHelper.cpp | 2 +- action/CommandActionHelper.cpp | 2 +- container/FixedMap.h | 2 +- container/IndexedRingMemoryArray.h | 6 +++--- datapool/DataPoolParameterWrapper.cpp | 2 +- datapool/DataPoolParameterWrapper.h | 2 +- datapool/DataSet.cpp | 4 ++-- datapool/DataSet.h | 2 +- datapool/PIDReader.h | 2 +- datapool/PoolRawAccess.cpp | 2 +- datapool/PoolRawAccess.h | 2 +- datapool/PoolVariable.h | 2 +- datapool/PoolVector.h | 2 +- devicehandlers/DeviceTmReportingWrapper.cpp | 2 +- devicehandlers/DeviceTmReportingWrapper.h | 2 +- events/eventmatching/EventRangeMatcherBase.h | 2 +- globalfunctions/Type.cpp | 2 +- globalfunctions/Type.h | 2 +- globalfunctions/matching/MatchTree.h | 2 +- globalfunctions/matching/RangeMatcher.h | 2 +- monitoring/LimitViolationReporter.cpp | 2 +- parameters/ParameterWrapper.cpp | 2 +- parameters/ParameterWrapper.h | 2 +- power/Fuse.cpp | 2 +- power/PowerComponent.cpp | 2 +- power/PowerComponent.h | 2 +- serialize/SerialArrayListAdapter.h | 2 +- serialize/SerialBufferAdapter.cpp | 2 +- serialize/SerialBufferAdapter.h | 2 +- serialize/SerialFixedArrayListAdapter.h | 2 +- serialize/SerialLinkedListAdapter.h | 2 +- serialize/SerializeElement.h | 2 +- serialize/SerializeIF.h | 2 +- subsystem/Subsystem.cpp | 2 +- subsystem/modes/ModeDefinitions.h | 2 +- tmstorage/TmStorePackets.h | 4 ++-- tmtcpacket/packetmatcher/ApidMatcher.h | 2 +- tmtcpacket/packetmatcher/ServiceMatcher.h | 2 +- tmtcpacket/packetmatcher/SubserviceMatcher.h | 2 +- tmtcpacket/pus/TmPacketStored.cpp | 2 +- 40 files changed, 44 insertions(+), 44 deletions(-) diff --git a/action/ActionHelper.cpp b/action/ActionHelper.cpp index 96a4824c1..ef9f06a9e 100644 --- a/action/ActionHelper.cpp +++ b/action/ActionHelper.cpp @@ -72,7 +72,7 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, CommandMessage reply; store_address_t storeAddress; uint8_t *dataPtr; - uint32_t maxSize = data->getSerializedSize(); + size_t maxSize = data->getSerializedSize(); if (maxSize == 0) { //No error, there's simply nothing to report. return HasReturnvaluesIF::RETURN_OK; diff --git a/action/CommandActionHelper.cpp b/action/CommandActionHelper.cpp index e670121f4..772954014 100644 --- a/action/CommandActionHelper.cpp +++ b/action/CommandActionHelper.cpp @@ -20,7 +20,7 @@ ReturnValue_t CommandActionHelper::commandAction(object_id_t commandTo, } store_address_t storeId; uint8_t* storePointer; - uint32_t maxSize = data->getSerializedSize(); + size_t maxSize = data->getSerializedSize(); ReturnValue_t result = ipcStore->getFreeElement(&storeId, maxSize, &storePointer); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/container/FixedMap.h b/container/FixedMap.h index 314fb45a4..23a79aefc 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -188,7 +188,7 @@ public: return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { uint32_t printSize = sizeof(_size); uint32_t i = 0; diff --git a/container/IndexedRingMemoryArray.h b/container/IndexedRingMemoryArray.h index 4ab174f4b..8682780ad 100644 --- a/container/IndexedRingMemoryArray.h +++ b/container/IndexedRingMemoryArray.h @@ -159,7 +159,7 @@ public: uint32_t maxNrOfIndices = floor(static_cast(size)/static_cast(bytesPerBlock)); //Calculate the Size needeed for the index itself - uint32_t serializedSize = 0; + size_t serializedSize = 0; if(additionalInfo!=NULL) { serializedSize += additionalInfo->getSerializedSize(); } @@ -548,9 +548,9 @@ public: * Get the serialized Size of the index * @return The serialized size of the index */ - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { - uint32_t size = 0; + size_t size = 0; if(additionalInfo!=NULL){ size += additionalInfo->getSerializedSize(); } diff --git a/datapool/DataPoolParameterWrapper.cpp b/datapool/DataPoolParameterWrapper.cpp index 88ac51a6a..aa194b61c 100644 --- a/datapool/DataPoolParameterWrapper.cpp +++ b/datapool/DataPoolParameterWrapper.cpp @@ -69,7 +69,7 @@ ReturnValue_t DataPoolParameterWrapper::serialize(uint8_t** buffer, } //same as ParameterWrapper -uint32_t DataPoolParameterWrapper::getSerializedSize() const { +size_t DataPoolParameterWrapper::getSerializedSize() const { uint32_t serializedSize = 0; serializedSize += type.getSerializedSize(); serializedSize += sizeof(rows); diff --git a/datapool/DataPoolParameterWrapper.h b/datapool/DataPoolParameterWrapper.h index 32ba65098..c9631b9c4 100644 --- a/datapool/DataPoolParameterWrapper.h +++ b/datapool/DataPoolParameterWrapper.h @@ -14,7 +14,7 @@ public: virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/datapool/DataSet.cpp b/datapool/DataSet.cpp index ccd9fd3cb..90baf063a 100644 --- a/datapool/DataSet.cpp +++ b/datapool/DataSet.cpp @@ -119,8 +119,8 @@ ReturnValue_t DataSet::serialize(uint8_t** buffer, size_t* size, return result; } -uint32_t DataSet::getSerializedSize() const { - uint32_t size = 0; +size_t DataSet::getSerializedSize() const { + size_t size = 0; for (uint16_t count = 0; count < fill_count; count++) { size += registeredVariables[count]->getSerializedSize(); } diff --git a/datapool/DataSet.h b/datapool/DataSet.h index 0732feb30..9bcdb8920 100644 --- a/datapool/DataSet.h +++ b/datapool/DataSet.h @@ -124,7 +124,7 @@ public: ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; - uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/datapool/PIDReader.h b/datapool/PIDReader.h index 68e70e869..d6b10b653 100644 --- a/datapool/PIDReader.h +++ b/datapool/PIDReader.h @@ -132,7 +132,7 @@ public: bigEndian); } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&value); } diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 63dc5b49e..16d6562e5 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -193,7 +193,7 @@ uint16_t PoolRawAccess::getSizeTillEnd() const { } -uint32_t PoolRawAccess::getSerializedSize() const { +size_t PoolRawAccess::getSerializedSize() const { return typeSize; } diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 1599a40e1..73a609ff0 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -125,7 +125,7 @@ public: */ uint16_t getSizeTillEnd() const; - uint32_t getSerializedSize() const; + size_t getSerializedSize() const; ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/datapool/PoolVariable.h b/datapool/PoolVariable.h index 76418ab82..351ffec3a 100644 --- a/datapool/PoolVariable.h +++ b/datapool/PoolVariable.h @@ -199,7 +199,7 @@ public: bigEndian); } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&value); } diff --git a/datapool/PoolVector.h b/datapool/PoolVector.h index 154cb18aa..a21f31d2d 100644 --- a/datapool/PoolVector.h +++ b/datapool/PoolVector.h @@ -211,7 +211,7 @@ public: return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return vector_size * SerializeAdapter::getSerializedSize(value); } diff --git a/devicehandlers/DeviceTmReportingWrapper.cpp b/devicehandlers/DeviceTmReportingWrapper.cpp index 2be37dd4e..344a1dc12 100644 --- a/devicehandlers/DeviceTmReportingWrapper.cpp +++ b/devicehandlers/DeviceTmReportingWrapper.cpp @@ -26,7 +26,7 @@ ReturnValue_t DeviceTmReportingWrapper::serialize(uint8_t** buffer, return data->serialize(buffer, size, max_size, bigEndian); } -uint32_t DeviceTmReportingWrapper::getSerializedSize() const { +size_t DeviceTmReportingWrapper::getSerializedSize() const { return sizeof(objectId) + sizeof(ActionId_t) + data->getSerializedSize(); } diff --git a/devicehandlers/DeviceTmReportingWrapper.h b/devicehandlers/DeviceTmReportingWrapper.h index ecdeca495..1582ff484 100644 --- a/devicehandlers/DeviceTmReportingWrapper.h +++ b/devicehandlers/DeviceTmReportingWrapper.h @@ -14,7 +14,7 @@ public: virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/events/eventmatching/EventRangeMatcherBase.h b/events/eventmatching/EventRangeMatcherBase.h index 3906b6278..0f096b9c8 100644 --- a/events/eventmatching/EventRangeMatcherBase.h +++ b/events/eventmatching/EventRangeMatcherBase.h @@ -15,7 +15,7 @@ public: const size_t max_size, bool bigEndian) const { return rangeMatcher.serialize(buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return rangeMatcher.getSerializedSize(); } ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, diff --git a/globalfunctions/Type.cpp b/globalfunctions/Type.cpp index e9bbab52d..0d6d7c1d8 100644 --- a/globalfunctions/Type.cpp +++ b/globalfunctions/Type.cpp @@ -81,7 +81,7 @@ ReturnValue_t Type::serialize(uint8_t** buffer, size_t* size, } -uint32_t Type::getSerializedSize() const { +size_t Type::getSerializedSize() const { uint8_t dontcare = 0; return 2 * SerializeAdapter::getSerializedSize(&dontcare); } diff --git a/globalfunctions/Type.h b/globalfunctions/Type.h index 8d595dafb..e6413d2d5 100644 --- a/globalfunctions/Type.h +++ b/globalfunctions/Type.h @@ -42,7 +42,7 @@ public: virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/globalfunctions/matching/MatchTree.h b/globalfunctions/matching/MatchTree.h index ccf464f09..3b8e1942f 100644 --- a/globalfunctions/matching/MatchTree.h +++ b/globalfunctions/matching/MatchTree.h @@ -86,7 +86,7 @@ public: return result; } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { //Analogous to serialize! uint32_t size = 1; //One for count iterator iter = this->begin(); diff --git a/globalfunctions/matching/RangeMatcher.h b/globalfunctions/matching/RangeMatcher.h index 8e0ae850f..c93e79197 100644 --- a/globalfunctions/matching/RangeMatcher.h +++ b/globalfunctions/matching/RangeMatcher.h @@ -40,7 +40,7 @@ public: return SerializeAdapter::serialize(&inverted, buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return sizeof(lowerBound) + sizeof(upperBound) + sizeof(bool); } diff --git a/monitoring/LimitViolationReporter.cpp b/monitoring/LimitViolationReporter.cpp index 77c3dad13..234a0bffb 100644 --- a/monitoring/LimitViolationReporter.cpp +++ b/monitoring/LimitViolationReporter.cpp @@ -17,7 +17,7 @@ ReturnValue_t LimitViolationReporter::sendLimitViolationReport(const SerializeIF } store_address_t storeId; uint8_t* dataTarget = NULL; - uint32_t maxSize = data->getSerializedSize(); + size_t maxSize = data->getSerializedSize(); if (maxSize > MonitoringIF::VIOLATION_REPORT_MAX_SIZE) { return MonitoringIF::INVALID_SIZE; } diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index 501c7c4d9..f359a7450 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -77,7 +77,7 @@ ReturnValue_t ParameterWrapper::serialize(uint8_t** buffer, size_t* size, return result; } -uint32_t ParameterWrapper::getSerializedSize() const { +size_t ParameterWrapper::getSerializedSize() const { uint32_t serializedSize = 0; serializedSize += type.getSerializedSize(); serializedSize += sizeof(rows); diff --git a/parameters/ParameterWrapper.h b/parameters/ParameterWrapper.h index a78e586d9..6681f7c43 100644 --- a/parameters/ParameterWrapper.h +++ b/parameters/ParameterWrapper.h @@ -28,7 +28,7 @@ public: virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/power/Fuse.cpp b/power/Fuse.cpp index 93e982902..04adac804 100644 --- a/power/Fuse.cpp +++ b/power/Fuse.cpp @@ -100,7 +100,7 @@ ReturnValue_t Fuse::serialize(uint8_t** buffer, size_t* size, } uint32_t Fuse::getSerializedSize() const { - uint32_t size = 0; + size_t size = 0; for (DeviceList::const_iterator iter = devices.begin(); iter != devices.end(); iter++) { size += (*iter)->getSerializedSize(); diff --git a/power/PowerComponent.cpp b/power/PowerComponent.cpp index 83ed0e68e..b7158e624 100644 --- a/power/PowerComponent.cpp +++ b/power/PowerComponent.cpp @@ -28,7 +28,7 @@ ReturnValue_t PowerComponent::serialize(uint8_t** buffer, size_t* size, bigEndian); } -uint32_t PowerComponent::getSerializedSize() const { +size_t PowerComponent::getSerializedSize() const { return sizeof(min) + sizeof(max); } diff --git a/power/PowerComponent.h b/power/PowerComponent.h index de08e5ec1..973416672 100644 --- a/power/PowerComponent.h +++ b/power/PowerComponent.h @@ -22,7 +22,7 @@ public: ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; - uint32_t getSerializedSize() const; + size_t getSerializedSize() const; ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 0bc0a97b5..5274c4889 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -41,7 +41,7 @@ public: return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return getSerializedSize(adaptee); } diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index a125ef44c..83fda418b 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -54,7 +54,7 @@ ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* } template -uint32_t SerialBufferAdapter::getSerializedSize() const { +size_t SerialBufferAdapter::getSerializedSize() const { if (m_serialize_length) { return m_buffer_length + AutoSerializeAdapter::getSerializedSize(&m_buffer_length); } else { diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index f8ff122e7..0c3d4dd69 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -43,7 +43,7 @@ public: virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; - virtual uint32_t getSerializedSize() const; + virtual size_t getSerializedSize() const; virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian); diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index e10322f9c..573d33147 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -37,7 +37,7 @@ public: return SerialArrayListAdapter::serialize(this, buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerialArrayListAdapter::getSerializedSize(this); } ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index 196432af5..0865faa5e 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -88,7 +88,7 @@ public: } return result; } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { if (printCount) { return SerialLinkedListAdapter::getSerializedSize() + sizeof(count_t); diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index 81f557a5b..fe9d5d713 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -37,7 +37,7 @@ public: return SerializeAdapter::serialize(&entry, buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&entry); } diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index d9d361c10..a9f40a080 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -40,7 +40,7 @@ public: virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const = 0; - virtual uint32_t getSerializedSize() const = 0; + virtual size_t getSerializedSize() const = 0; virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, bool bigEndian) = 0; diff --git a/subsystem/Subsystem.cpp b/subsystem/Subsystem.cpp index 8b7f3851a..1c4bee335 100644 --- a/subsystem/Subsystem.cpp +++ b/subsystem/Subsystem.cpp @@ -601,7 +601,7 @@ void Subsystem::transitionFailed(ReturnValue_t failureCode, void Subsystem::sendSerializablesAsCommandMessage(Command_t command, SerializeIF** elements, uint8_t count) { ReturnValue_t result; - uint32_t maxSize = 0; + size_t maxSize = 0; for (uint8_t i = 0; i < count; i++) { maxSize += elements[i]->getSerializedSize(); } diff --git a/subsystem/modes/ModeDefinitions.h b/subsystem/modes/ModeDefinitions.h index 8a88eb92e..406f95835 100644 --- a/subsystem/modes/ModeDefinitions.h +++ b/subsystem/modes/ModeDefinitions.h @@ -49,7 +49,7 @@ public: } - virtual uint32_t getSerializedSize() const { + virtual size_t getSerializedSize() const { return sizeof(value1) + sizeof(value2) + sizeof(value3) + sizeof(value4); } diff --git a/tmstorage/TmStorePackets.h b/tmstorage/TmStorePackets.h index b31b37cb1..b6c63b917 100644 --- a/tmstorage/TmStorePackets.h +++ b/tmstorage/TmStorePackets.h @@ -44,7 +44,7 @@ public: } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return sizeof(apid) + sizeof(ssc); } @@ -244,7 +244,7 @@ public: return adapter.serialize(buffer,size,max_size,bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { uint32_t size = 0; size += AutoSerializeAdapter::getSerializedSize(&apid); size += AutoSerializeAdapter::getSerializedSize(&sourceSequenceCount); diff --git a/tmtcpacket/packetmatcher/ApidMatcher.h b/tmtcpacket/packetmatcher/ApidMatcher.h index 0140340bd..37b91bd30 100644 --- a/tmtcpacket/packetmatcher/ApidMatcher.h +++ b/tmtcpacket/packetmatcher/ApidMatcher.h @@ -27,7 +27,7 @@ public: return SerializeAdapter::serialize(&apid, buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&apid); } ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, diff --git a/tmtcpacket/packetmatcher/ServiceMatcher.h b/tmtcpacket/packetmatcher/ServiceMatcher.h index be2dd2f56..31502053b 100644 --- a/tmtcpacket/packetmatcher/ServiceMatcher.h +++ b/tmtcpacket/packetmatcher/ServiceMatcher.h @@ -27,7 +27,7 @@ public: return SerializeAdapter::serialize(&service, buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&service); } ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, diff --git a/tmtcpacket/packetmatcher/SubserviceMatcher.h b/tmtcpacket/packetmatcher/SubserviceMatcher.h index de62e1835..8b872876a 100644 --- a/tmtcpacket/packetmatcher/SubserviceMatcher.h +++ b/tmtcpacket/packetmatcher/SubserviceMatcher.h @@ -25,7 +25,7 @@ public: return SerializeAdapter::serialize(&subService, buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize() const { + size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&subService); } ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, diff --git a/tmtcpacket/pus/TmPacketStored.cpp b/tmtcpacket/pus/TmPacketStored.cpp index c66e33245..b60f6c7e0 100644 --- a/tmtcpacket/pus/TmPacketStored.cpp +++ b/tmtcpacket/pus/TmPacketStored.cpp @@ -42,7 +42,7 @@ TmPacketStored::TmPacketStored(uint16_t apid, uint8_t service, if (!checkAndSetStore()) { return; } - uint32_t sourceDataSize = 0; + size_t sourceDataSize = 0; if (content != NULL) { sourceDataSize += content->getSerializedSize(); } From 42838272a522b76c9e055f93bdf7af6d00b84b01 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 22:42:48 +0200 Subject: [PATCH 0151/1774] replaced int32_t size by ssize_t (type trait trick) --- container/FixedMap.h | 2 +- datapool/DataPoolParameterWrapper.cpp | 2 +- datapool/DataPoolParameterWrapper.h | 2 +- datapool/DataSet.cpp | 2 +- datapool/DataSet.h | 2 +- datapool/PIDReader.h | 2 +- datapool/PoolRawAccess.cpp | 2 +- datapool/PoolRawAccess.h | 2 +- datapool/PoolRawAccessHelper.cpp | 6 +++--- datapool/PoolRawAccessHelper.h | 8 +++++--- datapool/PoolVariable.h | 2 +- datapool/PoolVector.h | 2 +- devicehandlers/DeviceTmReportingWrapper.cpp | 2 +- devicehandlers/DeviceTmReportingWrapper.h | 2 +- events/eventmatching/EventRangeMatcherBase.h | 2 +- globalfunctions/Type.cpp | 3 +-- globalfunctions/Type.h | 2 +- globalfunctions/matching/MatchTree.h | 2 +- globalfunctions/matching/RangeMatcher.h | 2 +- parameters/ParameterWrapper.cpp | 10 +++++----- parameters/ParameterWrapper.h | 8 ++++---- power/Fuse.cpp | 2 +- power/Fuse.h | 4 ++-- power/PowerComponent.cpp | 4 ++-- power/PowerComponent.h | 2 +- serialize/SerialArrayListAdapter.h | 6 +++--- serialize/SerialBufferAdapter.cpp | 2 +- serialize/SerialBufferAdapter.h | 2 +- serialize/SerialFixedArrayListAdapter.h | 5 +++-- serialize/SerialLinkedListAdapter.h | 4 ++-- serialize/SerializeAdapter.h | 8 ++++---- serialize/SerializeElement.h | 3 ++- serialize/SerializeIF.h | 4 +++- subsystem/Subsystem.cpp | 4 ++-- subsystem/modes/ModeDefinitions.h | 2 +- thermal/ThermalComponent.cpp | 4 ++-- thermal/ThermalComponent.h | 2 +- tmstorage/TmStorePackets.h | 4 ++-- tmtcpacket/packetmatcher/ApidMatcher.h | 2 +- tmtcpacket/packetmatcher/ServiceMatcher.h | 2 +- tmtcpacket/packetmatcher/SubserviceMatcher.h | 2 +- 41 files changed, 70 insertions(+), 65 deletions(-) diff --git a/container/FixedMap.h b/container/FixedMap.h index 23a79aefc..7f3d28f7d 100644 --- a/container/FixedMap.h +++ b/container/FixedMap.h @@ -201,7 +201,7 @@ public: return printSize; } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&this->_size, buffer, size, bigEndian); diff --git a/datapool/DataPoolParameterWrapper.cpp b/datapool/DataPoolParameterWrapper.cpp index aa194b61c..7139a0d89 100644 --- a/datapool/DataPoolParameterWrapper.cpp +++ b/datapool/DataPoolParameterWrapper.cpp @@ -80,7 +80,7 @@ size_t DataPoolParameterWrapper::getSerializedSize() const { } ReturnValue_t DataPoolParameterWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + ssize_t* size, bool bigEndian) { return HasReturnvaluesIF::RETURN_FAILED; } diff --git a/datapool/DataPoolParameterWrapper.h b/datapool/DataPoolParameterWrapper.h index c9631b9c4..45d3de537 100644 --- a/datapool/DataPoolParameterWrapper.h +++ b/datapool/DataPoolParameterWrapper.h @@ -16,7 +16,7 @@ public: virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); ReturnValue_t copyFrom(const ParameterWrapper *from, diff --git a/datapool/DataSet.cpp b/datapool/DataSet.cpp index 90baf063a..eabb4b8c1 100644 --- a/datapool/DataSet.cpp +++ b/datapool/DataSet.cpp @@ -136,7 +136,7 @@ void DataSet::setValid(uint8_t valid) { } } -ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t DataSet::deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = RETURN_FAILED; for (uint16_t count = 0; count < fill_count; count++) { diff --git a/datapool/DataSet.h b/datapool/DataSet.h index 9bcdb8920..888d45e65 100644 --- a/datapool/DataSet.h +++ b/datapool/DataSet.h @@ -126,7 +126,7 @@ public: virtual size_t getSerializedSize() const; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); private: diff --git a/datapool/PIDReader.h b/datapool/PIDReader.h index d6b10b653..26a9e2a80 100644 --- a/datapool/PIDReader.h +++ b/datapool/PIDReader.h @@ -136,7 +136,7 @@ public: return SerializeAdapter::getSerializedSize(&value); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&value, buffer, size, bigEndian); } diff --git a/datapool/PoolRawAccess.cpp b/datapool/PoolRawAccess.cpp index 16d6562e5..b5f94c8c5 100644 --- a/datapool/PoolRawAccess.cpp +++ b/datapool/PoolRawAccess.cpp @@ -197,7 +197,7 @@ size_t PoolRawAccess::getSerializedSize() const { return typeSize; } -ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t PoolRawAccess::deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { *size -= typeSize; if (*size >= 0) { diff --git a/datapool/PoolRawAccess.h b/datapool/PoolRawAccess.h index 73a609ff0..955c640ba 100644 --- a/datapool/PoolRawAccess.h +++ b/datapool/PoolRawAccess.h @@ -127,7 +127,7 @@ public: size_t getSerializedSize() const; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); protected: diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp index 7ea3576f1..cac6e5064 100644 --- a/datapool/PoolRawAccessHelper.cpp +++ b/datapool/PoolRawAccessHelper.cpp @@ -25,7 +25,7 @@ ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, size_t *size, const size_t max_size, bool bigEndian) { SerializationArgs serializationArgs = {buffer, size, max_size, bigEndian}; ReturnValue_t result; - int32_t remainingParametersSize = numberOfParameters * 4; + ssize_t remainingParametersSize = numberOfParameters * 4; for(uint8_t count=0; count < numberOfParameters; count++) { result = serializeCurrentPoolEntryIntoBuffer(serializationArgs, &remainingParametersSize, false); @@ -44,7 +44,7 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, size_t * size, const size_t max_size, bool bigEndian) { ReturnValue_t result; SerializationArgs argStruct = {buffer, size, max_size, bigEndian}; - int32_t remainingParametersSize = numberOfParameters * 4; + ssize_t remainingParametersSize = numberOfParameters * 4; uint8_t validityMaskSize = ceil((float)numberOfParameters/8.0); uint8_t validityMask[validityMaskSize]; memset(validityMask,0, validityMaskSize); @@ -68,7 +68,7 @@ ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, } ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct, - int32_t * remainingParameters, bool withValidMask, uint8_t * validityMask) { + ssize_t * remainingParameters, bool withValidMask, uint8_t * validityMask) { uint32_t currentPoolId; // Deserialize current pool ID from pool ID buffer ReturnValue_t result = AutoSerializeAdapter::deSerialize(¤tPoolId, diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index 4a4a1fabf..89974ea4f 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -85,10 +85,12 @@ private: * @return */ ReturnValue_t serializeCurrentPoolEntryIntoBuffer(SerializationArgs argStruct, - int32_t * remainingParameters, bool withValidMask = false, uint8_t * validityMask = NULL); + ssize_t * remainingParameters, bool withValidMask = false, + uint8_t * validityMask = nullptr); - ReturnValue_t handlePoolEntrySerialization(uint32_t currentPoolId,SerializationArgs argStruct, - bool withValidMask = false, uint8_t * validityMask = NULL); + ReturnValue_t handlePoolEntrySerialization(uint32_t currentPoolId, + SerializationArgs argStruct, bool withValidMask = false, + uint8_t * validityMask = nullptr); ReturnValue_t checkRemainingSize(PoolRawAccess * currentPoolRawAccess, bool * isSerialized, uint8_t * arrayPosition); diff --git a/datapool/PoolVariable.h b/datapool/PoolVariable.h index 351ffec3a..d32cdf22a 100644 --- a/datapool/PoolVariable.h +++ b/datapool/PoolVariable.h @@ -203,7 +203,7 @@ public: return SerializeAdapter::getSerializedSize(&value); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&value, buffer, size, bigEndian); } diff --git a/datapool/PoolVector.h b/datapool/PoolVector.h index a21f31d2d..3e82a721a 100644 --- a/datapool/PoolVector.h +++ b/datapool/PoolVector.h @@ -215,7 +215,7 @@ public: return vector_size * SerializeAdapter::getSerializedSize(value); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { uint16_t i; ReturnValue_t result; diff --git a/devicehandlers/DeviceTmReportingWrapper.cpp b/devicehandlers/DeviceTmReportingWrapper.cpp index 344a1dc12..4987c7fb5 100644 --- a/devicehandlers/DeviceTmReportingWrapper.cpp +++ b/devicehandlers/DeviceTmReportingWrapper.cpp @@ -31,7 +31,7 @@ size_t DeviceTmReportingWrapper::getSerializedSize() const { } ReturnValue_t DeviceTmReportingWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + ssize_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&objectId, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/devicehandlers/DeviceTmReportingWrapper.h b/devicehandlers/DeviceTmReportingWrapper.h index 1582ff484..fce748147 100644 --- a/devicehandlers/DeviceTmReportingWrapper.h +++ b/devicehandlers/DeviceTmReportingWrapper.h @@ -16,7 +16,7 @@ public: virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); private: object_id_t objectId; diff --git a/events/eventmatching/EventRangeMatcherBase.h b/events/eventmatching/EventRangeMatcherBase.h index 0f096b9c8..8dea3e101 100644 --- a/events/eventmatching/EventRangeMatcherBase.h +++ b/events/eventmatching/EventRangeMatcherBase.h @@ -18,7 +18,7 @@ public: size_t getSerializedSize() const { return rangeMatcher.getSerializedSize(); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return rangeMatcher.deSerialize(buffer, size, bigEndian); } diff --git a/globalfunctions/Type.cpp b/globalfunctions/Type.cpp index 0d6d7c1d8..ea2ad896f 100644 --- a/globalfunctions/Type.cpp +++ b/globalfunctions/Type.cpp @@ -1,4 +1,3 @@ -#include #include #include @@ -86,7 +85,7 @@ size_t Type::getSerializedSize() const { return 2 * SerializeAdapter::getSerializedSize(&dontcare); } -ReturnValue_t Type::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t Type::deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { uint8_t ptc; uint8_t pfc; diff --git a/globalfunctions/Type.h b/globalfunctions/Type.h index e6413d2d5..244091f71 100644 --- a/globalfunctions/Type.h +++ b/globalfunctions/Type.h @@ -44,7 +44,7 @@ public: virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); private: diff --git a/globalfunctions/matching/MatchTree.h b/globalfunctions/matching/MatchTree.h index 3b8e1942f..498fe8603 100644 --- a/globalfunctions/matching/MatchTree.h +++ b/globalfunctions/matching/MatchTree.h @@ -115,7 +115,7 @@ public: return size; } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return HasReturnvaluesIF::RETURN_OK; } diff --git a/globalfunctions/matching/RangeMatcher.h b/globalfunctions/matching/RangeMatcher.h index c93e79197..c09802554 100644 --- a/globalfunctions/matching/RangeMatcher.h +++ b/globalfunctions/matching/RangeMatcher.h @@ -44,7 +44,7 @@ public: return sizeof(lowerBound) + sizeof(upperBound) + sizeof(bool); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&lowerBound, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/parameters/ParameterWrapper.cpp b/parameters/ParameterWrapper.cpp index f359a7450..1420c0761 100644 --- a/parameters/ParameterWrapper.cpp +++ b/parameters/ParameterWrapper.cpp @@ -112,7 +112,7 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow, //treat from as a continuous Stream as we copy all of it const uint8_t *fromAsStream = (const uint8_t *) from; - int32_t streamSize = fromRows * fromColumns * sizeof(T); + ssize_t streamSize = fromRows * fromColumns * sizeof(T); ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; @@ -137,12 +137,12 @@ ReturnValue_t ParameterWrapper::deSerializeData(uint8_t startingRow, } ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + ssize_t* size, bool bigEndian) { return deSerialize(buffer, size, bigEndian, 0); } ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian, uint16_t startWritingAtIndex) { + ssize_t* size, bool bigEndian, uint16_t startWritingAtIndex) { ParameterWrapper streamDescription; ReturnValue_t result = streamDescription.set(*buffer, *size, buffer, size); @@ -153,8 +153,8 @@ ReturnValue_t ParameterWrapper::deSerialize(const uint8_t** buffer, return copyFrom(&streamDescription, startWritingAtIndex); } -ReturnValue_t ParameterWrapper::set(const uint8_t* stream, int32_t streamSize, - const uint8_t **remainingStream, int32_t *remainingSize) { +ReturnValue_t ParameterWrapper::set(const uint8_t* stream, ssize_t streamSize, + const uint8_t **remainingStream, ssize_t *remainingSize) { ReturnValue_t result = SerializeAdapter::deSerialize(&type, &stream, &streamSize, true); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/parameters/ParameterWrapper.h b/parameters/ParameterWrapper.h index 6681f7c43..6f8f6fc97 100644 --- a/parameters/ParameterWrapper.h +++ b/parameters/ParameterWrapper.h @@ -30,10 +30,10 @@ public: virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian, uint16_t startWritingAtIndex = 0); template @@ -111,8 +111,8 @@ public: void setMatrix(const T& member) { this->set(member[0], sizeof(member)/sizeof(member[0]), sizeof(member[0])/sizeof(member[0][0])); } - ReturnValue_t set(const uint8_t *stream, int32_t streamSize, - const uint8_t **remainingStream = NULL, int32_t *remainingSize = + ReturnValue_t set(const uint8_t *stream, ssize_t streamSize, + const uint8_t **remainingStream = NULL, ssize_t *remainingSize = NULL); ReturnValue_t copyFrom(const ParameterWrapper *from, diff --git a/power/Fuse.cpp b/power/Fuse.cpp index 04adac804..6a4e6caf6 100644 --- a/power/Fuse.cpp +++ b/power/Fuse.cpp @@ -108,7 +108,7 @@ uint32_t Fuse::getSerializedSize() const { return size; } -ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, int32_t* size, +ReturnValue_t Fuse::deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = RETURN_FAILED; for (DeviceList::iterator iter = devices.begin(); iter != devices.end(); diff --git a/power/Fuse.h b/power/Fuse.h index a9542167c..b3c9547ac 100644 --- a/power/Fuse.h +++ b/power/Fuse.h @@ -52,8 +52,8 @@ public: ReturnValue_t serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const; uint32_t getSerializedSize() const; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, - bool bigEndian); + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, + bool bigEndian); void setAllMonitorsToUnchecked(); ReturnValue_t performOperation(uint8_t opCode); MessageQueueId_t getCommandQueue() const; diff --git a/power/PowerComponent.cpp b/power/PowerComponent.cpp index b7158e624..77e60d0e1 100644 --- a/power/PowerComponent.cpp +++ b/power/PowerComponent.cpp @@ -56,8 +56,8 @@ float PowerComponent::getMax() { return max; } -ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, int32_t* size, -bool bigEndian) { +ReturnValue_t PowerComponent::deSerialize(const uint8_t** buffer, ssize_t* size, + bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&min, buffer, size, bigEndian); if (result != HasReturnvaluesIF::RETURN_OK) { diff --git a/power/PowerComponent.h b/power/PowerComponent.h index 973416672..1410e69d3 100644 --- a/power/PowerComponent.h +++ b/power/PowerComponent.h @@ -24,7 +24,7 @@ public: size_t getSerializedSize() const; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, diff --git a/serialize/SerialArrayListAdapter.h b/serialize/SerialArrayListAdapter.h index 5274c4889..21a669c2d 100644 --- a/serialize/SerialArrayListAdapter.h +++ b/serialize/SerialArrayListAdapter.h @@ -56,13 +56,13 @@ public: return printSize; } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return deSerialize(adaptee, buffer, size, bigEndian); } - static ReturnValue_t deSerialize(ArrayList* list, const uint8_t** buffer, int32_t* size, - bool bigEndian) { + static ReturnValue_t deSerialize(ArrayList* list, + const uint8_t** buffer, ssize_t* size, bool bigEndian) { count_t tempSize = 0; ReturnValue_t result = SerializeAdapter::deSerialize(&tempSize, buffer, size, bigEndian); diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 83fda418b..618e8a152 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -63,7 +63,7 @@ size_t SerialBufferAdapter::getSerializedSize() const { } template ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, - int32_t* size, bool bigEndian) { + ssize_t* size, bool bigEndian) { //TODO Ignores Endian flag! if (buffer != NULL) { if(m_serialize_length){ diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index 0c3d4dd69..ff2083de1 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -45,7 +45,7 @@ public: virtual size_t getSerializedSize() const; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian); uint8_t * getBuffer(); diff --git a/serialize/SerialFixedArrayListAdapter.h b/serialize/SerialFixedArrayListAdapter.h index 573d33147..8bcbf09e7 100644 --- a/serialize/SerialFixedArrayListAdapter.h +++ b/serialize/SerialFixedArrayListAdapter.h @@ -40,9 +40,10 @@ public: size_t getSerializedSize() const { return SerialArrayListAdapter::getSerializedSize(this); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { - return SerialArrayListAdapter::deSerialize(this, buffer, size, bigEndian); + return SerialArrayListAdapter::deSerialize(this, + buffer, size, bigEndian); } void swapArrayListEndianness() { diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index 0865faa5e..80dbcaf1c 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -112,13 +112,13 @@ public: * @param bigEndian Specify endianness * @return */ - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return deSerialize(SinglyLinkedList::start, buffer, size, bigEndian); } static ReturnValue_t deSerialize(LinkedElement* element, - const uint8_t** buffer, int32_t* size, bool bigEndian) { + const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = HasReturnvaluesIF::RETURN_OK; while ((result == HasReturnvaluesIF::RETURN_OK) && (element != NULL)) { result = element->value->deSerialize(buffer, size, bigEndian); diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 7654eb0d9..81a3730f8 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -88,7 +88,7 @@ public: * @param bigEndian Specify endianness * @return */ - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(T* object, const uint8_t** buffer, ssize_t* size, bool bigEndian) { T tmp; *size -= sizeof(T); @@ -127,7 +127,7 @@ public: return object->getSerializedSize(); } - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(T* object, const uint8_t** buffer, ssize_t* size, bool bigEndian) { return object->deSerialize(buffer, size, bigEndian); } @@ -147,7 +147,7 @@ public: } static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, - int32_t* size, bool bigEndian) { + ssize_t* size, bool bigEndian) { SerializeAdapter_::Is> adapter; return adapter.deSerialize(object, buffer, size, bigEndian); } @@ -169,7 +169,7 @@ public: } template static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, - int32_t* size, bool bigEndian) { + ssize_t* size, bool bigEndian) { SerializeAdapter_::Is> adapter; return adapter.deSerialize(object, buffer, size, bigEndian); } diff --git a/serialize/SerializeElement.h b/serialize/SerializeElement.h index fe9d5d713..e2da5c141 100644 --- a/serialize/SerializeElement.h +++ b/serialize/SerializeElement.h @@ -41,10 +41,11 @@ public: return SerializeAdapter::getSerializedSize(&entry); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&entry, buffer, size, bigEndian); } + operator T() { return entry; } diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index a9f40a080..d547daac7 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -3,7 +3,9 @@ #include #include +#include +typedef std::make_signed::type ssize_t; /** * @defgroup serialize Serialization * Contains serialisation services. @@ -42,7 +44,7 @@ public: virtual size_t getSerializedSize() const = 0; - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) = 0; }; diff --git a/subsystem/Subsystem.cpp b/subsystem/Subsystem.cpp index 1c4bee335..e4a682bae 100644 --- a/subsystem/Subsystem.cpp +++ b/subsystem/Subsystem.cpp @@ -168,7 +168,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) { &sizeRead); if (result == RETURN_OK) { Mode_t fallbackId; - int32_t size = sizeRead; + ssize_t size = sizeRead; result = SerializeAdapter::deSerialize(&fallbackId, &pointer, &size, true); if (result == RETURN_OK) { @@ -193,7 +193,7 @@ ReturnValue_t Subsystem::handleCommandMessage(CommandMessage* message) { ModeSequenceMessage::getStoreAddress(message), &pointer, &sizeRead); if (result == RETURN_OK) { - int32_t size = sizeRead; + ssize_t size = sizeRead; result = SerialArrayListAdapter::deSerialize(&table, &pointer, &size, true); if (result == RETURN_OK) { diff --git a/subsystem/modes/ModeDefinitions.h b/subsystem/modes/ModeDefinitions.h index 406f95835..4c0c4a261 100644 --- a/subsystem/modes/ModeDefinitions.h +++ b/subsystem/modes/ModeDefinitions.h @@ -53,7 +53,7 @@ public: return sizeof(value1) + sizeof(value2) + sizeof(value3) + sizeof(value4); } - virtual ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + virtual ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result; diff --git a/thermal/ThermalComponent.cpp b/thermal/ThermalComponent.cpp index 15a2bbc9c..737ffd2ea 100644 --- a/thermal/ThermalComponent.cpp +++ b/thermal/ThermalComponent.cpp @@ -40,11 +40,11 @@ ReturnValue_t ThermalComponent::setTargetState(int8_t newState) { } } -ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, uint32_t size) { +ReturnValue_t ThermalComponent::setLimits(const uint8_t* data, ssize_t size) { if (size != 4 * sizeof(parameters.lowerOpLimit)) { return MonitoringIF::INVALID_SIZE; } - int32_t readSize = size; + ssize_t readSize = size; SerializeAdapter::deSerialize(&nopParameters.lowerNopLimit, &data, &readSize, true); SerializeAdapter::deSerialize(¶meters.lowerOpLimit, &data, diff --git a/thermal/ThermalComponent.h b/thermal/ThermalComponent.h index 4e32e97cd..37ed01c0f 100644 --- a/thermal/ThermalComponent.h +++ b/thermal/ThermalComponent.h @@ -53,7 +53,7 @@ public: ReturnValue_t setTargetState(int8_t newState); - virtual ReturnValue_t setLimits( const uint8_t* data, uint32_t size); + virtual ReturnValue_t setLimits( const uint8_t* data, ssize_t size); virtual ReturnValue_t getParameter(uint8_t domainId, uint16_t parameterId, ParameterWrapper *parameterWrapper, diff --git a/tmstorage/TmStorePackets.h b/tmstorage/TmStorePackets.h index b6c63b917..4e7bc94b4 100644 --- a/tmstorage/TmStorePackets.h +++ b/tmstorage/TmStorePackets.h @@ -48,7 +48,7 @@ public: return sizeof(apid) + sizeof(ssc); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = SerializeAdapter::deSerialize(&apid, buffer, size, bigEndian); @@ -257,7 +257,7 @@ public: }; - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { ReturnValue_t result = AutoSerializeAdapter::deSerialize(&apid, buffer, size, bigEndian); diff --git a/tmtcpacket/packetmatcher/ApidMatcher.h b/tmtcpacket/packetmatcher/ApidMatcher.h index 37b91bd30..1ee444762 100644 --- a/tmtcpacket/packetmatcher/ApidMatcher.h +++ b/tmtcpacket/packetmatcher/ApidMatcher.h @@ -30,7 +30,7 @@ public: size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&apid); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&apid, buffer, size, bigEndian); } diff --git a/tmtcpacket/packetmatcher/ServiceMatcher.h b/tmtcpacket/packetmatcher/ServiceMatcher.h index 31502053b..b69ac7a5d 100644 --- a/tmtcpacket/packetmatcher/ServiceMatcher.h +++ b/tmtcpacket/packetmatcher/ServiceMatcher.h @@ -30,7 +30,7 @@ public: size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&service); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&service, buffer, size, bigEndian); } diff --git a/tmtcpacket/packetmatcher/SubserviceMatcher.h b/tmtcpacket/packetmatcher/SubserviceMatcher.h index 8b872876a..9c93af649 100644 --- a/tmtcpacket/packetmatcher/SubserviceMatcher.h +++ b/tmtcpacket/packetmatcher/SubserviceMatcher.h @@ -28,7 +28,7 @@ public: size_t getSerializedSize() const { return SerializeAdapter::getSerializedSize(&subService); } - ReturnValue_t deSerialize(const uint8_t** buffer, int32_t* size, + ReturnValue_t deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { return SerializeAdapter::deSerialize(&subService, buffer, size, bigEndian); } From e791f44c41525bc742c9027bbeb08a530cd5a424 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Sun, 5 Apr 2020 23:03:32 +0200 Subject: [PATCH 0152/1774] copy ctor and assgnment op forbidden for serial linked lists --- returnvalues/HasReturnvaluesIF.h | 2 +- serialize/SerialLinkedListAdapter.h | 10 ++++++++++ serialize/SerializeIF.h | 3 +++ 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/returnvalues/HasReturnvaluesIF.h b/returnvalues/HasReturnvaluesIF.h index b8b72a9fc..d84fc7578 100644 --- a/returnvalues/HasReturnvaluesIF.h +++ b/returnvalues/HasReturnvaluesIF.h @@ -1,9 +1,9 @@ #ifndef HASRETURNVALUESIF_H_ #define HASRETURNVALUESIF_H_ -#include #include #include +#include #define MAKE_RETURN_CODE( number ) ((INTERFACE_ID << 8) + (number)) typedef uint16_t ReturnValue_t; diff --git a/serialize/SerialLinkedListAdapter.h b/serialize/SerialLinkedListAdapter.h index 80dbcaf1c..b5c06a166 100644 --- a/serialize/SerialLinkedListAdapter.h +++ b/serialize/SerialLinkedListAdapter.h @@ -41,6 +41,16 @@ template class SerialLinkedListAdapter: public SinglyLinkedList, public SerializeIF { public: + /** + * Copying is forbidden by deleting the copy constructor and the copy + * assignment operator because of the pointers to the linked list members. + * Unless the child class implements an own copy constructor or + * copy assignment operator, these operation will throw a compiler error. + * @param + */ + SerialLinkedListAdapter(const SerialLinkedListAdapter &) = delete; + SerialLinkedListAdapter& operator=(const SerialLinkedListAdapter&) = delete; + SerialLinkedListAdapter(typename LinkedElement::Iterator start, bool printCount = false) : SinglyLinkedList(start), printCount(printCount) { diff --git a/serialize/SerializeIF.h b/serialize/SerializeIF.h index d547daac7..da401b2f9 100644 --- a/serialize/SerializeIF.h +++ b/serialize/SerializeIF.h @@ -5,7 +5,10 @@ #include #include +#ifndef ssize_t typedef std::make_signed::type ssize_t; +#endif + /** * @defgroup serialize Serialization * Contains serialisation services. From 3654c7bf8162cd176509db6d83241f077bdfb929 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 6 Apr 2020 11:15:44 +0200 Subject: [PATCH 0153/1774] some form stuff --- datapool/PoolEntry.cpp | 6 ++++-- osal/FreeRTOS/FixedTimeslotTask.cpp | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/datapool/PoolEntry.cpp b/datapool/PoolEntry.cpp index 898d226e2..e5d4ffdef 100644 --- a/datapool/PoolEntry.cpp +++ b/datapool/PoolEntry.cpp @@ -2,7 +2,8 @@ #include template -PoolEntry::PoolEntry(std::initializer_list initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) { +PoolEntry::PoolEntry(std::initializer_list initValue, uint8_t set_length, + uint8_t set_valid ) : length(set_length), valid(set_valid) { this->address = new T[this->length]; if(initValue.size() == 0) { memset(this->address, 0, this->getByteSize()); @@ -13,7 +14,8 @@ PoolEntry::PoolEntry(std::initializer_list initValue, uint8_t set_length, } template -PoolEntry::PoolEntry( T* initValue, uint8_t set_length, uint8_t set_valid ) : length(set_length), valid(set_valid) { +PoolEntry::PoolEntry( T* initValue, uint8_t set_length, uint8_t set_valid ) : + length(set_length), valid(set_valid) { this->address = new T[this->length]; if (initValue != NULL) { memcpy(this->address, initValue, this->getByteSize() ); diff --git a/osal/FreeRTOS/FixedTimeslotTask.cpp b/osal/FreeRTOS/FixedTimeslotTask.cpp index 7bfee7e6d..b1c974202 100644 --- a/osal/FreeRTOS/FixedTimeslotTask.cpp +++ b/osal/FreeRTOS/FixedTimeslotTask.cpp @@ -67,7 +67,8 @@ ReturnValue_t FixedTimeslotTask::addSlot(object_id_t componentId, return HasReturnvaluesIF::RETURN_OK; } - error << "Component " << std::hex << componentId << " not found, not adding it to pst" << std::endl; + error << "Component " << std::hex << componentId + << " not found, not adding it to pst" << std::endl; return HasReturnvaluesIF::RETURN_FAILED; } From 78aad91aab99ff6123d8575300613dd14a79b81e Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 6 Apr 2020 12:38:39 +0200 Subject: [PATCH 0154/1774] PSB subservice passed to handleRequest --- tmtcservices/PusServiceBase.cpp | 2 +- tmtcservices/PusServiceBase.h | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/tmtcservices/PusServiceBase.cpp b/tmtcservices/PusServiceBase.cpp index 6e1053252..a0ab17681 100644 --- a/tmtcservices/PusServiceBase.cpp +++ b/tmtcservices/PusServiceBase.cpp @@ -29,7 +29,7 @@ ReturnValue_t PusServiceBase::performOperation(uint8_t opCode) { this->currentPacket.setStoreAddress(message.getStorageId()); // info << "Service " << (uint16_t) this->serviceId << ": new packet!" << std::endl; - ReturnValue_t return_code = this->handleRequest(); + ReturnValue_t return_code = this->handleRequest(currentPacket.getSubService()); // debug << "Service " << (uint16_t)this->serviceId << ": handleRequest returned: " << (int)return_code << std::endl; if (return_code == RETURN_OK) { this->verifyReporter.sendSuccessReport( diff --git a/tmtcservices/PusServiceBase.h b/tmtcservices/PusServiceBase.h index 6c8c5f617..de16ebe28 100644 --- a/tmtcservices/PusServiceBase.h +++ b/tmtcservices/PusServiceBase.h @@ -30,7 +30,10 @@ void setStaticFrameworkObjectIds(); * All PUS Services are System Objects, so an Object ID needs to be specified on construction. * \ingroup pus_services */ -class PusServiceBase : public ExecutableObjectIF, public AcceptsTelecommandsIF, public SystemObject, public HasReturnvaluesIF { +class PusServiceBase : public ExecutableObjectIF, + public AcceptsTelecommandsIF, + public SystemObject, + public HasReturnvaluesIF { friend void (Factory::setStaticFrameworkObjectIds)(); public: /** @@ -63,7 +66,7 @@ public: * @return The returned status_code is directly taken as main error code in the Verification Report. * On success, RETURN_OK shall be returned. */ - virtual ReturnValue_t handleRequest() = 0; + virtual ReturnValue_t handleRequest(uint8_t subservice) = 0; /** * In performService, implementations can handle periodic, non-TC-triggered activities. * The performService method is always called. From aaabbe8aef2a759d1928b22c6b3acfca2fd9980d Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 6 Apr 2020 13:59:57 +0200 Subject: [PATCH 0155/1774] DHB fix --- devicehandlers/DeviceHandlerBase.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/devicehandlers/DeviceHandlerBase.cpp b/devicehandlers/DeviceHandlerBase.cpp index 9f23dd7f5..5fb5a9e5f 100644 --- a/devicehandlers/DeviceHandlerBase.cpp +++ b/devicehandlers/DeviceHandlerBase.cpp @@ -1149,9 +1149,6 @@ ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId, if (result != HasReturnvaluesIF::RETURN_OK) { return result; } - if(size == 0) { - return NO_COMMAND_DATA; - } DeviceCommandMap::iterator iter = deviceCommandMap.find(actionId); if (iter == deviceCommandMap.end()) { From c88c6c2a45482d19f51ec0548ffe50e5b1203a82 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 6 Apr 2020 19:51:45 +0200 Subject: [PATCH 0156/1774] binary semaphore info printout added --- osal/FreeRTOS/BinarySemaphore.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 631e4742d..546c5a46d 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -86,6 +86,7 @@ void BinarySemaphore::resetSemaphore() { } } +// Be careful with the stack size here. This is called from an ISR! ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) { if (semaphore == nullptr) { @@ -95,6 +96,10 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema if (returncode == pdPASS) { if(*higherPriorityTaskWoken == pdPASS) { // Request context switch + // TODO: I don't know if this will ever happen but if it does, + // I want to to know in case this causes issues. If it doesn't + // we should remove this. + TRACE_INFO("Binary Semaphore: Higher priority task unblocked!"); TaskManagement::requestContextSwitch(CallContext::isr); } return HasReturnvaluesIF::RETURN_OK; From 30ed08005fd07cd894a49dee5123e028d1fbeed6 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 7 Apr 2020 22:16:43 +0200 Subject: [PATCH 0157/1774] reverted some naming changes --- datapool/DataPool.h | 3 +- serialize/SerialBufferAdapter.cpp | 56 +++++++++++++++---------------- serialize/SerialBufferAdapter.h | 6 ++-- 3 files changed, 33 insertions(+), 32 deletions(-) diff --git a/datapool/DataPool.h b/datapool/DataPool.h index a9af8af0b..857bc3b2c 100644 --- a/datapool/DataPool.h +++ b/datapool/DataPool.h @@ -42,7 +42,8 @@ private: /** * \brief This is the actual data pool itself. * \details It is represented by a map - * with the data pool id as index and a pointer to a single PoolEntry as value. + * with the data pool id as index and a pointer to a single + * PoolEntry as value. */ std::map data_pool; public: diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index 618e8a152..f97d0d588 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -5,19 +5,19 @@ template SerialBufferAdapter::SerialBufferAdapter(const void* buffer, count_t bufferLength, bool serializeLength) : - m_serialize_length(serializeLength), - m_const_buffer(static_cast(buffer)), m_buffer(nullptr), - m_buffer_length(bufferLength) { + serializeLength(serializeLength), + constBuffer(static_cast(buffer)), m_buffer(nullptr), + bufferLength(bufferLength) { } template SerialBufferAdapter::SerialBufferAdapter(void* buffer, count_t bufferLength, bool serializeLength) : - m_serialize_length(serializeLength), m_buffer_length(bufferLength) { + serializeLength(serializeLength), bufferLength(bufferLength) { uint8_t * member_buffer = static_cast(buffer); m_buffer = member_buffer; - m_const_buffer = member_buffer; + constBuffer = member_buffer; } @@ -28,37 +28,37 @@ SerialBufferAdapter::~SerialBufferAdapter() { template ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) const { - uint32_t serializedLength = m_buffer_length; - if (m_serialize_length) { + uint32_t serializedLength = bufferLength; + if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( - &m_buffer_length); + &bufferLength); } if (*size + serializedLength > max_size) { return BUFFER_TOO_SHORT; } else { - if (m_serialize_length) { - AutoSerializeAdapter::serialize(&m_buffer_length, buffer, size, + if (serializeLength) { + AutoSerializeAdapter::serialize(&bufferLength, buffer, size, max_size, bigEndian); } - if (m_const_buffer != nullptr) { - memcpy(*buffer, m_const_buffer, m_buffer_length); + if (constBuffer != nullptr) { + memcpy(*buffer, constBuffer, bufferLength); } else if (m_buffer != nullptr) { - memcpy(*buffer, m_buffer, m_buffer_length); + memcpy(*buffer, m_buffer, bufferLength); } else { return HasReturnvaluesIF::RETURN_FAILED; } - *size += m_buffer_length; - (*buffer) += m_buffer_length; + *size += bufferLength; + (*buffer) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } } template size_t SerialBufferAdapter::getSerializedSize() const { - if (m_serialize_length) { - return m_buffer_length + AutoSerializeAdapter::getSerializedSize(&m_buffer_length); + if (serializeLength) { + return bufferLength + AutoSerializeAdapter::getSerializedSize(&bufferLength); } else { - return m_buffer_length; + return bufferLength; } } template @@ -66,15 +66,15 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, ssize_t* size, bool bigEndian) { //TODO Ignores Endian flag! if (buffer != NULL) { - if(m_serialize_length){ + if(serializeLength){ // Suggestion (would require removing rest of the block inside this if clause !): //ReturnValue_t result = AutoSerializeAdapter::deSerialize(&bufferLength,buffer,size,bigEndian); //if (result != HasReturnvaluesIF::RETURN_OK) { // return result; //} count_t serializedSize = AutoSerializeAdapter::getSerializedSize( - &m_buffer_length); - if((*size - m_buffer_length - serializedSize) >= 0){ + &bufferLength); + if((*size - bufferLength - serializedSize) >= 0){ *buffer += serializedSize; *size -= serializedSize; }else{ @@ -82,10 +82,10 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, } } //No Else If, go on with buffer - if (*size - m_buffer_length >= 0) { - *size -= m_buffer_length; - memcpy(m_buffer, *buffer, m_buffer_length); - (*buffer) += m_buffer_length; + if (*size - bufferLength >= 0) { + *size -= bufferLength; + memcpy(m_buffer, *buffer, bufferLength); + (*buffer) += bufferLength; return HasReturnvaluesIF::RETURN_OK; } else { return STREAM_TOO_SHORT; @@ -106,17 +106,17 @@ uint8_t * SerialBufferAdapter::getBuffer() { template const uint8_t * SerialBufferAdapter::getConstBuffer() { - if(m_const_buffer == nullptr) { + if(constBuffer == nullptr) { error << "Wrong access function for stored type ! Use getBuffer()" << std::endl; return nullptr; } - return m_const_buffer; + return constBuffer; } template void SerialBufferAdapter::setBuffer(void * buffer, count_t buffer_length) { m_buffer = static_cast(buffer); - m_buffer_length = buffer_length; + bufferLength = buffer_length; } diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index ff2083de1..cf3ae07ed 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -52,10 +52,10 @@ public: const uint8_t * getConstBuffer(); void setBuffer(void* buffer_, count_t bufferLength_); private: - bool m_serialize_length = false; - const uint8_t *m_const_buffer = nullptr; + bool serializeLength = false; + const uint8_t *constBuffer = nullptr; uint8_t *m_buffer = nullptr; - count_t m_buffer_length = 0; + count_t bufferLength = 0; }; From e0e1e64a092b9a06570149c2c694102230af182c Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 8 Apr 2020 18:08:14 +0200 Subject: [PATCH 0158/1774] various changes, stopwatch Semaphore: Some bugfixes, some constructors added Stopwatch: First implementation, can measure in ms(double) and ms(normal) --- datalinklayer/Clcw.cpp | 3 +- datapool/PoolEntry.cpp | 3 +- health/HealthHelper.cpp | 5 +- osal/FreeRTOS/BinarySemaphore.cpp | 68 ++++++++++++++++++----- osal/FreeRTOS/BinarySemaphore.h | 51 +++++++++++++---- osal/FreeRTOS/Clock.cpp | 4 +- osal/FreeRTOS/Timekeeper.cpp | 26 +++++---- osal/FreeRTOS/Timekeeper.h | 9 ++- serviceinterface/ServiceInterfaceStream.h | 3 +- timemanager/CCSDSTime.cpp | 3 +- timemanager/Clock.h | 3 +- timemanager/Stopwatch.cpp | 62 +++++++++++++++++++++ timemanager/Stopwatch.h | 52 +++++++++++++++++ 13 files changed, 247 insertions(+), 45 deletions(-) create mode 100644 timemanager/Stopwatch.cpp create mode 100644 timemanager/Stopwatch.h diff --git a/datalinklayer/Clcw.cpp b/datalinklayer/Clcw.cpp index 448d4d7bc..0ffa7abf6 100644 --- a/datalinklayer/Clcw.cpp +++ b/datalinklayer/Clcw.cpp @@ -55,7 +55,8 @@ void Clcw::setBitLock(bool bitLock) { } void Clcw::print() { - debug << "Clcw::print: Clcw is: " << std::hex << getAsWhole() << std::dec << std::endl; + debug << "Clcw::print: Clcw is: " << std::hex << getAsWhole() + << std::dec << std::endl; } void Clcw::setWhole(uint32_t rawClcw) { diff --git a/datapool/PoolEntry.cpp b/datapool/PoolEntry.cpp index e5d4ffdef..655b467a0 100644 --- a/datapool/PoolEntry.cpp +++ b/datapool/PoolEntry.cpp @@ -60,7 +60,8 @@ uint8_t PoolEntry::getValid() { template void PoolEntry::print() { for (uint8_t size = 0; size < this->length; size++ ) { - debug << "| " << std::hex << (double)this->address[size] << (this->valid? " (valid) " : " (invalid) "); + debug << "| " << std::hex << (double)this->address[size] + << (this->valid? " (valid) " : " (invalid) "); } debug << std::dec << std::endl; } diff --git a/health/HealthHelper.cpp b/health/HealthHelper.cpp index 8fc413edd..931645d1a 100644 --- a/health/HealthHelper.cpp +++ b/health/HealthHelper.cpp @@ -89,8 +89,7 @@ void HealthHelper::handleSetHealthCommand(CommandMessage* message) { } if (MessageQueueSenderIF::sendMessage(message->getSender(), &reply, owner->getCommandQueue()) != HasReturnvaluesIF::RETURN_OK) { - debug - << "HealthHelper::handleHealthCommand: sending health reply failed." - << std::endl; + debug << "HealthHelper::handleHealthCommand: sending health " + "reply failed." << std::endl; } } diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 546c5a46d..05c97ae2e 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -21,26 +21,68 @@ BinarySemaphore::~BinarySemaphore() { vSemaphoreDelete(handle); } +// This copy ctor is important as it prevents the assignment to a ressource +// (other.handle) variable which is later deleted! +BinarySemaphore::BinarySemaphore(const BinarySemaphore& other) { + xSemaphoreCreateBinary(handle); + if(handle == nullptr) { + error << "Binary semaphore creation failure" << std::endl; + } +} + +BinarySemaphore& BinarySemaphore::operator =(const BinarySemaphore& s) { + if(this != &s) { + xSemaphoreCreateBinary(handle); + if(handle == nullptr) { + error << "Binary semaphore creation failure" << std::endl; + } + } + return *this; +} + +BinarySemaphore::BinarySemaphore(BinarySemaphore&& s) { + xSemaphoreCreateBinary(handle); + if(handle == nullptr) { + error << "Binary semaphore creation failure" << std::endl; + } +} + +BinarySemaphore& BinarySemaphore::operator =( + BinarySemaphore&& s) { + if(&s != this) { + xSemaphoreCreateBinary(handle); + if(handle == nullptr) { + error << "Binary semaphore creation failure" << std::endl; + } + } + return *this; +} + ReturnValue_t BinarySemaphore::takeBinarySemaphore(uint32_t timeoutMs) { if(handle == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return SEMAPHORE_NULLPOINTER; } - TickType_t timeout = portMAX_DELAY; - if(timeoutMs != 0) { - timeout = pdMS_TO_TICKS(timeoutMs); + TickType_t timeout = BinarySemaphore::NO_BLOCK_TICKS; + if(timeoutMs == BinarySemaphore::BLOCK_TIMEOUT) { + timeout = BinarySemaphore::BLOCK_TIMEOUT_TICKS; + } + else if(timeoutMs > BinarySemaphore::NO_BLOCK_TIMEOUT){ + timeout = pdMS_TO_TICKS(timeoutMs); } BaseType_t returncode = xSemaphoreTake(handle, timeout); if (returncode == pdPASS) { return HasReturnvaluesIF::RETURN_OK; - } else { - return SEMAPHORE_NOT_FOUND; + } + else { + return SEMAPHORE_TIMEOUT; } } -ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks) { +ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout( + TickType_t timeoutTicks) { if(handle == nullptr) { - return SEMAPHORE_NOT_FOUND; + return SEMAPHORE_NULLPOINTER; } BaseType_t returncode = xSemaphoreTake(handle, timeoutTicks); @@ -53,7 +95,7 @@ ReturnValue_t BinarySemaphore::takeBinarySemaphoreTickTimeout(TickType_t timeout ReturnValue_t BinarySemaphore::giveBinarySemaphore() { if (handle == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return SEMAPHORE_NULLPOINTER; } BaseType_t returncode = xSemaphoreGive(handle); if (returncode == pdPASS) { @@ -69,7 +111,7 @@ SemaphoreHandle_t BinarySemaphore::getSemaphore() { ReturnValue_t BinarySemaphore::giveBinarySemaphore(SemaphoreHandle_t semaphore) { if (semaphore == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return SEMAPHORE_NULLPOINTER; } BaseType_t returncode = xSemaphoreGive(semaphore); if (returncode == pdPASS) { @@ -86,11 +128,12 @@ void BinarySemaphore::resetSemaphore() { } } + // Be careful with the stack size here. This is called from an ISR! ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken) { if (semaphore == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return SEMAPHORE_NULLPOINTER; } BaseType_t returncode = xSemaphoreGiveFromISR(semaphore, higherPriorityTaskWoken); if (returncode == pdPASS) { @@ -99,11 +142,10 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema // TODO: I don't know if this will ever happen but if it does, // I want to to know in case this causes issues. If it doesn't // we should remove this. - TRACE_INFO("Binary Semaphore: Higher priority task unblocked!"); TaskManagement::requestContextSwitch(CallContext::isr); } return HasReturnvaluesIF::RETURN_OK; } else { - return HasReturnvaluesIF::RETURN_FAILED; + return SEMAPHORE_NOT_OWNED; } } diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h index a809f0bb1..541266929 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -20,22 +20,51 @@ class BinarySemaphore: public HasReturnvaluesIF { public: static const uint8_t INTERFACE_ID = CLASS_ID::SEMAPHORE_IF; - /** Semaphore object not found */ - static const ReturnValue_t SEMAPHORE_NOT_FOUND = MAKE_RETURN_CODE(1); - /** Semaphore timeout */ - static const ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(2); + //! No block time, poll the semaphore. Can also be used as tick type. + //! Can be passed as tick type and ms value. + static constexpr uint32_t NO_BLOCK_TIMEOUT = 0; + static constexpr TickType_t NO_BLOCK_TICKS = 0; + //! No block time, poll the semaphore. + //! Can be passed as tick type and ms value. + static constexpr TickType_t BLOCK_TIMEOUT_TICKS = portMAX_DELAY; + static constexpr uint32_t BLOCK_TIMEOUT = portMAX_DELAY; + + //! Semaphore timeout + static constexpr ReturnValue_t SEMAPHORE_TIMEOUT = MAKE_RETURN_CODE(1); /** The current semaphore can not be given, because it is not owned */ - static const ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(3); + static constexpr ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(2); + static constexpr ReturnValue_t SEMAPHORE_NULLPOINTER = MAKE_RETURN_CODE(3); /** * Create a binary semaphore */ BinarySemaphore(); + /** + * Copy ctor + * @param + */ + BinarySemaphore(const BinarySemaphore&); + + /** + * Copy assignment + */ + BinarySemaphore& operator=(const BinarySemaphore&); + + /** + * Move constructor + */ + BinarySemaphore (BinarySemaphore &&); + + /** + * Move assignment + */ + BinarySemaphore & operator=(BinarySemaphore &&); + /** * Delete the binary semaphore to prevent a memory leak */ - ~BinarySemaphore(); + virtual ~BinarySemaphore(); /** * Take the binary semaphore. @@ -46,7 +75,8 @@ public: * @return -@c RETURN_OK on success * -@c RETURN_FAILED on failure */ - ReturnValue_t takeBinarySemaphore(uint32_t timeoutMs); + ReturnValue_t takeBinarySemaphore(uint32_t timeoutMs = + BinarySemaphore::NO_BLOCK_TIMEOUT); /** * Same as lockBinarySemaphore() with timeout in FreeRTOS ticks. @@ -54,7 +84,8 @@ public: * @return -@c RETURN_OK on success * -@c RETURN_FAILED on failure */ - ReturnValue_t takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks); + ReturnValue_t takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks = + BinarySemaphore::NO_BLOCK_TICKS); /** * Give back the binary semaphore @@ -96,8 +127,4 @@ private: SemaphoreHandle_t handle; }; - - - - #endif /* FRAMEWORK_OSAL_FREERTOS_BINARYSEMPAHORE_H_ */ diff --git a/osal/FreeRTOS/Clock.cpp b/osal/FreeRTOS/Clock.cpp index cffc2125e..5e597f258 100644 --- a/osal/FreeRTOS/Clock.cpp +++ b/osal/FreeRTOS/Clock.cpp @@ -3,8 +3,11 @@ #include #include "Timekeeper.h" +extern "C" { #include #include +} + //TODO sanitize input? //TODO much of this code can be reused for tick-only systems @@ -56,7 +59,6 @@ ReturnValue_t Clock::getUptime(timeval* uptime) { timeval Clock::getUptime() { TickType_t ticksSinceStart = xTaskGetTickCount(); - return Timekeeper::ticksToTimeval(ticksSinceStart); } diff --git a/osal/FreeRTOS/Timekeeper.cpp b/osal/FreeRTOS/Timekeeper.cpp index 81f7f9979..949e1df3c 100644 --- a/osal/FreeRTOS/Timekeeper.cpp +++ b/osal/FreeRTOS/Timekeeper.cpp @@ -1,20 +1,24 @@ -#include "Timekeeper.h" -#include +/** + * @file Timekeeper.cpp + * @date + */ -Timekeeper::Timekeeper() : - offset( { 0, 0 }) { - // TODO Auto-generated constructor stub +#include +extern "C" { +#include } -Timekeeper * Timekeeper::myinstance = NULL; +Timekeeper * Timekeeper::myinstance = nullptr; + +Timekeeper::Timekeeper() : offset( { 0, 0 }) {} const timeval& Timekeeper::getOffset() const { return offset; } Timekeeper* Timekeeper::instance() { - if (myinstance == NULL) { + if (myinstance == nullptr) { myinstance = new Timekeeper(); } return myinstance; @@ -24,9 +28,7 @@ void Timekeeper::setOffset(const timeval& offset) { this->offset = offset; } -Timekeeper::~Timekeeper() { - // TODO Auto-generated destructor stub -} +Timekeeper::~Timekeeper() {} timeval Timekeeper::ticksToTimeval(TickType_t ticks) { timeval uptime; @@ -40,3 +42,7 @@ timeval Timekeeper::ticksToTimeval(TickType_t ticks) { return uptime; } + +TickType_t Timekeeper::getTicks() { + return xTaskGetTickCount(); +} diff --git a/osal/FreeRTOS/Timekeeper.h b/osal/FreeRTOS/Timekeeper.h index 2ba3e4a9b..05f0f7011 100644 --- a/osal/FreeRTOS/Timekeeper.h +++ b/osal/FreeRTOS/Timekeeper.h @@ -2,8 +2,10 @@ #define FRAMEWORK_OSAL_FREERTOS_TIMEKEEPER_H_ #include - +extern "C" { #include +} + /** * A Class to basically store the time difference between uptime and UTC @@ -25,6 +27,11 @@ public: virtual ~Timekeeper(); static timeval ticksToTimeval(TickType_t ticks); + /** + * Get elapsed time in system ticks. + * @return + */ + static TickType_t getTicks(); const timeval& getOffset() const; void setOffset(const timeval& offset); diff --git a/serviceinterface/ServiceInterfaceStream.h b/serviceinterface/ServiceInterfaceStream.h index 32bc263ee..44cf1168f 100644 --- a/serviceinterface/ServiceInterfaceStream.h +++ b/serviceinterface/ServiceInterfaceStream.h @@ -7,7 +7,8 @@ #include #include -//Unfortunately, there must be a forward declaration of log_fe (MUST be defined in main), to let the system know where to write to. +//Unfortunately, there must be a forward declaration of log_fe +// (MUST be defined in main), to let the system know where to write to. extern std::ostream debug; extern std::ostream info; extern std::ostream warning; diff --git a/timemanager/CCSDSTime.cpp b/timemanager/CCSDSTime.cpp index 29aafb68d..47cab911d 100644 --- a/timemanager/CCSDSTime.cpp +++ b/timemanager/CCSDSTime.cpp @@ -196,7 +196,8 @@ ReturnValue_t CCSDSTime::convertFromASCII(Clock::TimeOfDay_t* to, const uint8_t* to->usecond = (second - floor(second)) * 1000000; return RETURN_OK; } -// Warning: Compiler/Linker fails ambiguously if library does not implement C99 I/O +// Warning: Compiler/Linker fails ambiguously if library does not implement +// C99 I/O #else uint16_t year; uint8_t month; diff --git a/timemanager/Clock.h b/timemanager/Clock.h index af6572472..afa9963c5 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -7,7 +7,8 @@ #include #include - +typedef uint32_t ms_normal_t; +typedef double ms_double_t; class Clock { public: diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp new file mode 100644 index 000000000..37133def3 --- /dev/null +++ b/timemanager/Stopwatch.cpp @@ -0,0 +1,62 @@ +/** + * @file Stopwatch.cpp + * + * @date 08.04.2020 + */ + +#include +#include + +Stopwatch::Stopwatch(bool displayOnDestruction, DisplayMode displayMode): + displayOnDestruction(displayOnDestruction) { + Clock::getUptime(&startTime); + stopwatchState = StopwatchState::STARTED; +} + +void Stopwatch::start() { + startTime = Clock::getUptime(); +} + +ms_normal_t Stopwatch::stop() { + elapsedTime = Clock::getUptime() - startTime; + int32_t elapsedTimeMs = elapsedTime.tv_sec * 1000 + + elapsedTime.tv_usec/1000; + if(elapsedTimeMs < 0) { + error << "Stopwatch: Measured time negative!"; + return INVALID_TIME; + } + else { + return static_cast(elapsedTimeMs); + } +} + +ms_double_t Stopwatch::stopPrecise() { + elapsedTime = Clock::getUptime() - startTime; + return timevalOperations::toDouble(elapsedTime) * 1000.0; +} + + +void Stopwatch::display() { + if(displayMode == DisplayMode::MS_FLOAT) { + info << "Stopwatch: Operation took " << + elapsedTimeMs << " milliseconds" << std::endl; + } + else { + timeval elapsedTime = stopTime - startTime; + info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + + elapsedTime.tv_usec * 1000 << " milliseconds"; + } +} + + +Stopwatch::~Stopwatch() { + if(displayOnDestruction) { + stopInternal(); + display(); + } +} + +void Stopwatch::stopInternal() { + elapsedTime = Clock::getUptime() - startTime; + elapsedTimeMs = timevalOperations::toDouble(elapsedTime) * 1000.0; +} diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h new file mode 100644 index 000000000..6f58553f1 --- /dev/null +++ b/timemanager/Stopwatch.h @@ -0,0 +1,52 @@ +/** + * @file Stopwatch.h + * + * @date 08.04.2020 + */ + +#ifndef FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ +#define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ +#include + +class Stopwatch { + enum class DisplayMode { + MS_FLOAT, + MS + }; + + Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode = + DisplayMode::MS_FLOAT); + virtual~ Stopwatch(); + + void start(); + + ms_normal_t stop(); + ms_double_t stopPrecise(); + + void display(); +private: + static const ms_normal_t INVALID_TIME = 0xFFFFFFFF; + + timeval startTime {0, 0}; + timeval stopTime {0, 0}; + timeval elapsedTime {0, 0}; + double elapsedTimeMs = 0; + //ms_normal_t elapsedTimeMs {0}; + + bool displayOnDestruction = true; + + enum class StopwatchState { + IDLE, + STARTED, + }; + + StopwatchState stopwatchState = StopwatchState::IDLE; + DisplayMode displayMode = DisplayMode::MS_FLOAT; + + void stopInternal(); +}; + + + + +#endif /* FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ */ From 3af241b9c48f1c0f5685435f198d27e4333caa99 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 8 Apr 2020 18:27:18 +0200 Subject: [PATCH 0159/1774] stopwatch more lightweight now --- timemanager/Stopwatch.cpp | 25 ++++++++----------------- timemanager/Stopwatch.h | 27 +++++++++++++-------------- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 37133def3..fde77540b 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -10,7 +10,6 @@ Stopwatch::Stopwatch(bool displayOnDestruction, DisplayMode displayMode): displayOnDestruction(displayOnDestruction) { Clock::getUptime(&startTime); - stopwatchState = StopwatchState::STARTED; } void Stopwatch::start() { @@ -18,31 +17,22 @@ void Stopwatch::start() { } ms_normal_t Stopwatch::stop() { - elapsedTime = Clock::getUptime() - startTime; - int32_t elapsedTimeMs = elapsedTime.tv_sec * 1000 + - elapsedTime.tv_usec/1000; - if(elapsedTimeMs < 0) { - error << "Stopwatch: Measured time negative!"; - return INVALID_TIME; - } - else { - return static_cast(elapsedTimeMs); - } + stopInternal(); + return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000; } ms_double_t Stopwatch::stopPrecise() { - elapsedTime = Clock::getUptime() - startTime; - return timevalOperations::toDouble(elapsedTime) * 1000.0; + stopInternal(); + return elapsedTimeMsDouble; } void Stopwatch::display() { - if(displayMode == DisplayMode::MS_FLOAT) { + if(displayMode == DisplayMode::MS_DOUBLE) { info << "Stopwatch: Operation took " << - elapsedTimeMs << " milliseconds" << std::endl; + elapsedTimeMsDouble << " milliseconds" << std::endl; } else { - timeval elapsedTime = stopTime - startTime; info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec * 1000 << " milliseconds"; } @@ -56,7 +46,8 @@ Stopwatch::~Stopwatch() { } } + void Stopwatch::stopInternal() { elapsedTime = Clock::getUptime() - startTime; - elapsedTimeMs = timevalOperations::toDouble(elapsedTime) * 1000.0; + elapsedTimeMsDouble = timevalOperations::toDouble(elapsedTime) * 1000.0; } diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index 6f58553f1..7760fda9c 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -8,14 +8,23 @@ #define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ #include +/** + * @brief Simple Stopwatch implementation to measure elapsed time + * @details + * This class can be used to measure elapsed times. It also displays elapsed + * times automatically on destruction if not explicitely deactivated in the + * constructor. The default time format is the elapsed time in miliseconds + * as a float. + * This class caches the value + */ class Stopwatch { enum class DisplayMode { - MS_FLOAT, + MS_DOUBLE, MS }; Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode = - DisplayMode::MS_FLOAT); + DisplayMode::MS_DOUBLE); virtual~ Stopwatch(); void start(); @@ -25,23 +34,13 @@ class Stopwatch { void display(); private: - static const ms_normal_t INVALID_TIME = 0xFFFFFFFF; timeval startTime {0, 0}; - timeval stopTime {0, 0}; timeval elapsedTime {0, 0}; - double elapsedTimeMs = 0; - //ms_normal_t elapsedTimeMs {0}; + double elapsedTimeMsDouble = 0; bool displayOnDestruction = true; - - enum class StopwatchState { - IDLE, - STARTED, - }; - - StopwatchState stopwatchState = StopwatchState::IDLE; - DisplayMode displayMode = DisplayMode::MS_FLOAT; + DisplayMode displayMode = DisplayMode::MS_DOUBLE; void stopInternal(); }; From 3dbf35338561897c356a1f949ed2a74ec7e9f311 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 8 Apr 2020 18:33:38 +0200 Subject: [PATCH 0160/1774] some more refactoring for stopwatch --- timemanager/Stopwatch.cpp | 13 +++++++++++-- timemanager/Stopwatch.h | 35 +++++++++++++++++++++++++++-------- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index fde77540b..7b08c120d 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -7,8 +7,10 @@ #include #include -Stopwatch::Stopwatch(bool displayOnDestruction, DisplayMode displayMode): +Stopwatch::Stopwatch(bool displayOnDestruction, + StopwatchDisplayMode displayMode): displayOnDestruction(displayOnDestruction) { + // Measures start time on initialization. Clock::getUptime(&startTime); } @@ -28,7 +30,7 @@ ms_double_t Stopwatch::stopPrecise() { void Stopwatch::display() { - if(displayMode == DisplayMode::MS_DOUBLE) { + if(displayMode == StopwatchDisplayMode::MS_DOUBLE) { info << "Stopwatch: Operation took " << elapsedTimeMsDouble << " milliseconds" << std::endl; } @@ -46,6 +48,13 @@ Stopwatch::~Stopwatch() { } } +void Stopwatch::setDisplayMode(StopwatchDisplayMode displayMode) { + this->displayMode = displayMode; +} + +StopwatchDisplayMode Stopwatch::getDisplayMode() const { + return displayMode; +} void Stopwatch::stopInternal() { elapsedTime = Clock::getUptime() - startTime; diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index 7760fda9c..b136019fd 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -8,6 +8,11 @@ #define FRAMEWORK_TIMEMANAGER_STOPWATCH_H_ #include +enum class StopwatchDisplayMode { + MS_DOUBLE, + MS +}; + /** * @brief Simple Stopwatch implementation to measure elapsed time * @details @@ -15,24 +20,38 @@ * times automatically on destruction if not explicitely deactivated in the * constructor. The default time format is the elapsed time in miliseconds * as a float. - * This class caches the value */ class Stopwatch { - enum class DisplayMode { - MS_DOUBLE, - MS - }; - Stopwatch(bool displayOnDestruction = true, DisplayMode displayMode = - DisplayMode::MS_DOUBLE); + Stopwatch(bool displayOnDestruction = true, + StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE); virtual~ Stopwatch(); + /** + * Caches the start time + */ void start(); + /** + * Calculates the elapsed time since start and returns it + * @return elapsed time in milliseconds (rounded) + */ ms_normal_t stop(); + + /** + * Calculates the elapsed time since start and returns it + * @return elapsed time in milliseconds (doulbe precision) + */ ms_double_t stopPrecise(); + /** + * Displays the elapsed times on the osstream, depending on internal display + * mode. + */ void display(); + + StopwatchDisplayMode getDisplayMode() const; + void setDisplayMode(StopwatchDisplayMode displayMode); private: timeval startTime {0, 0}; @@ -40,7 +59,7 @@ private: double elapsedTimeMsDouble = 0; bool displayOnDestruction = true; - DisplayMode displayMode = DisplayMode::MS_DOUBLE; + StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE; void stopInternal(); }; From da9bb97b23f2519137674a8b352e7b93592f4ef4 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 8 Apr 2020 19:05:21 +0200 Subject: [PATCH 0161/1774] added precision for double output --- timemanager/Stopwatch.cpp | 12 ++++++++---- timemanager/Stopwatch.h | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 7b08c120d..1ccebc577 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -6,10 +6,11 @@ #include #include +#include Stopwatch::Stopwatch(bool displayOnDestruction, - StopwatchDisplayMode displayMode): - displayOnDestruction(displayOnDestruction) { + StopwatchDisplayMode displayMode, uint8_t precision): + displayOnDestruction(displayOnDestruction), outputPrecision(precision) { // Measures start time on initialization. Clock::getUptime(&startTime); } @@ -31,8 +32,9 @@ ms_double_t Stopwatch::stopPrecise() { void Stopwatch::display() { if(displayMode == StopwatchDisplayMode::MS_DOUBLE) { - info << "Stopwatch: Operation took " << - elapsedTimeMsDouble << " milliseconds" << std::endl; + info << "Stopwatch: Operation took " + << std::setprecision(outputPrecision) << elapsedTimeMsDouble + << " milliseconds" << std::endl; } else { info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + @@ -56,6 +58,8 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const { return displayMode; } + + void Stopwatch::stopInternal() { elapsedTime = Clock::getUptime() - startTime; elapsedTimeMsDouble = timevalOperations::toDouble(elapsedTime) * 1000.0; diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index b136019fd..1e4382724 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -22,9 +22,19 @@ enum class StopwatchDisplayMode { * as a float. */ class Stopwatch { - +public: + /** + * Default constructor. Call "Stopwatch stopwatch" without brackets if + * no parameters are required! + * @param displayOnDestruction If set to true, displays measured time on + * object destruction + * @param displayMode Display format is either MS rounded or MS as double + * format + * @param outputPrecision If using double format, specify precision here. + */ Stopwatch(bool displayOnDestruction = true, - StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE); + StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE, + uint8_t outputPrecision = 4); virtual~ Stopwatch(); /** @@ -53,12 +63,12 @@ class Stopwatch { StopwatchDisplayMode getDisplayMode() const; void setDisplayMode(StopwatchDisplayMode displayMode); private: - timeval startTime {0, 0}; timeval elapsedTime {0, 0}; - double elapsedTimeMsDouble = 0; + double elapsedTimeMsDouble {0.0}; bool displayOnDestruction = true; + uint8_t outputPrecision = 4; StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE; void stopInternal(); From 5b0f80509f7f8dec258d333c26766dfdf8336ccc Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 8 Apr 2020 19:24:24 +0200 Subject: [PATCH 0162/1774] usec replaced by seconds --- timemanager/Clock.h | 4 ++-- timemanager/Stopwatch.cpp | 27 +++++++++++---------------- timemanager/Stopwatch.h | 22 +++++++--------------- 3 files changed, 20 insertions(+), 33 deletions(-) diff --git a/timemanager/Clock.h b/timemanager/Clock.h index afa9963c5..5f18de3ee 100644 --- a/timemanager/Clock.h +++ b/timemanager/Clock.h @@ -7,8 +7,8 @@ #include #include -typedef uint32_t ms_normal_t; -typedef double ms_double_t; +typedef uint32_t millis_t; +typedef float seconds_t; class Clock { public: diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 1ccebc577..40b711d9e 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -9,8 +9,8 @@ #include Stopwatch::Stopwatch(bool displayOnDestruction, - StopwatchDisplayMode displayMode, uint8_t precision): - displayOnDestruction(displayOnDestruction), outputPrecision(precision) { + StopwatchDisplayMode displayMode): + displayOnDestruction(displayOnDestruction) { // Measures start time on initialization. Clock::getUptime(&startTime); } @@ -19,30 +19,28 @@ void Stopwatch::start() { startTime = Clock::getUptime(); } -ms_normal_t Stopwatch::stop() { +millis_t Stopwatch::stop() { stopInternal(); return elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec / 1000; } -ms_double_t Stopwatch::stopPrecise() { +seconds_t Stopwatch::stopSeconds() { stopInternal(); - return elapsedTimeMsDouble; + return timevalOperations::toDouble(elapsedTime); } - void Stopwatch::display() { - if(displayMode == StopwatchDisplayMode::MS_DOUBLE) { - info << "Stopwatch: Operation took " - << std::setprecision(outputPrecision) << elapsedTimeMsDouble - << " milliseconds" << std::endl; - } - else { + if(displayMode == StopwatchDisplayMode::MILLIS) { info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + elapsedTime.tv_usec * 1000 << " milliseconds"; } + else if(displayMode == StopwatchDisplayMode::SECONDS) { + info <<"Stopwatch: Operation took " << std::setprecision(4) + << std::fixed << timevalOperations::toDouble(elapsedTime) + << " seconds"; + } } - Stopwatch::~Stopwatch() { if(displayOnDestruction) { stopInternal(); @@ -58,9 +56,6 @@ StopwatchDisplayMode Stopwatch::getDisplayMode() const { return displayMode; } - - void Stopwatch::stopInternal() { elapsedTime = Clock::getUptime() - startTime; - elapsedTimeMsDouble = timevalOperations::toDouble(elapsedTime) * 1000.0; } diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index 1e4382724..aeb612650 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -9,8 +9,8 @@ #include enum class StopwatchDisplayMode { - MS_DOUBLE, - MS + MILLIS, + SECONDS }; /** @@ -32,9 +32,8 @@ public: * format * @param outputPrecision If using double format, specify precision here. */ - Stopwatch(bool displayOnDestruction = true, - StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE, - uint8_t outputPrecision = 4); + Stopwatch(bool displayOnDestruction = true, StopwatchDisplayMode displayMode + = StopwatchDisplayMode::MILLIS); virtual~ Stopwatch(); /** @@ -46,13 +45,8 @@ public: * Calculates the elapsed time since start and returns it * @return elapsed time in milliseconds (rounded) */ - ms_normal_t stop(); - - /** - * Calculates the elapsed time since start and returns it - * @return elapsed time in milliseconds (doulbe precision) - */ - ms_double_t stopPrecise(); + millis_t stop(); + seconds_t stopSeconds(); /** * Displays the elapsed times on the osstream, depending on internal display @@ -65,11 +59,9 @@ public: private: timeval startTime {0, 0}; timeval elapsedTime {0, 0}; - double elapsedTimeMsDouble {0.0}; bool displayOnDestruction = true; - uint8_t outputPrecision = 4; - StopwatchDisplayMode displayMode = StopwatchDisplayMode::MS_DOUBLE; + StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS; void stopInternal(); }; From 640cc1ddec6fa6e53c8dca212b06b61604e5a6da Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Wed, 8 Apr 2020 19:30:39 +0200 Subject: [PATCH 0163/1774] some more bugfixes --- timemanager/Stopwatch.cpp | 8 ++++---- timemanager/Stopwatch.h | 3 +-- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 40b711d9e..6c50f0de9 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -9,7 +9,7 @@ #include Stopwatch::Stopwatch(bool displayOnDestruction, - StopwatchDisplayMode displayMode): + StopwatchDisplayMode displayMode): displayMode(displayMode), displayOnDestruction(displayOnDestruction) { // Measures start time on initialization. Clock::getUptime(&startTime); @@ -32,12 +32,12 @@ seconds_t Stopwatch::stopSeconds() { void Stopwatch::display() { if(displayMode == StopwatchDisplayMode::MILLIS) { info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + - elapsedTime.tv_usec * 1000 << " milliseconds"; + elapsedTime.tv_usec * 1000 << " milliseconds" << std::endl; } else if(displayMode == StopwatchDisplayMode::SECONDS) { - info <<"Stopwatch: Operation took " << std::setprecision(4) + info <<"Stopwatch: Operation took " << std::setprecision(3) << std::fixed << timevalOperations::toDouble(elapsedTime) - << " seconds"; + << " seconds" << std::endl; } } diff --git a/timemanager/Stopwatch.h b/timemanager/Stopwatch.h index aeb612650..786a9d571 100644 --- a/timemanager/Stopwatch.h +++ b/timemanager/Stopwatch.h @@ -60,9 +60,8 @@ private: timeval startTime {0, 0}; timeval elapsedTime {0, 0}; - bool displayOnDestruction = true; StopwatchDisplayMode displayMode = StopwatchDisplayMode::MILLIS; - + bool displayOnDestruction = true; void stopInternal(); }; From 8a8761ea88e361ff610dd18ba22e59f3f5a9140b Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 9 Apr 2020 17:56:48 +0200 Subject: [PATCH 0164/1774] stopwatch bugfix --- devicehandlers/CookieIF.h | 5 +++-- devicehandlers/DeviceCommunicationIF.h | 24 ++++++++++++------------ osal/FreeRTOS/BinarySemaphore.h | 26 +++++++++++--------------- serialize/SerializeDoc.h | 16 ++++++++++++++++ timemanager/Stopwatch.cpp | 2 +- 5 files changed, 43 insertions(+), 30 deletions(-) create mode 100644 serialize/SerializeDoc.h diff --git a/devicehandlers/CookieIF.h b/devicehandlers/CookieIF.h index ca171ff40..6b2bb5598 100644 --- a/devicehandlers/CookieIF.h +++ b/devicehandlers/CookieIF.h @@ -13,8 +13,9 @@ typedef uint32_t address_t; * single interface (like RMAP or I2C) * @details * To use this class, implement a communication specific child cookie which - * inherits Cookie. Cookie instances are created in config/ Factory.cpp by calling - * CookieIF* childCookie = new ChildCookie(...). + * inherits Cookie. Cookie instances are created in config/Factory.cpp by + * calling @code{.cpp} CookieIF* childCookie = new ChildCookie(...) + * @endcode . * * This cookie is then passed to the child device handlers, which stores the * pointer and passes it to the communication interface functions. diff --git a/devicehandlers/DeviceCommunicationIF.h b/devicehandlers/DeviceCommunicationIF.h index 39cfadd75..bb0951164 100644 --- a/devicehandlers/DeviceCommunicationIF.h +++ b/devicehandlers/DeviceCommunicationIF.h @@ -60,9 +60,9 @@ public: * this can be performed in this function, which is called on device handler * initialization. * @param cookie - * @return -@c RETURN_OK if initialization was successfull - * - Everything else triggers failure event with - * returnvalue as parameter 1 + * @return + * - @c RETURN_OK if initialization was successfull + * - Everything else triggers failure event with returnvalue as parameter 1 */ virtual ReturnValue_t initializeInterface(CookieIF * cookie) = 0; @@ -73,9 +73,9 @@ public: * @param cookie * @param data * @param len - * @return -@c RETURN_OK for successfull send - * - Everything else triggers failure event with - * returnvalue as parameter 1 + * @return + * - @c RETURN_OK for successfull send + * - Everything else triggers failure event with returnvalue as parameter 1 */ virtual ReturnValue_t sendMessage(CookieIF *cookie, const uint8_t * sendData, size_t sendLen) = 0; @@ -84,9 +84,9 @@ public: * Called by DHB in the GET_WRITE doGetWrite(). * Get send confirmation that the data in sendMessage() was sent successfully. * @param cookie - * @return -@c RETURN_OK if data was sent successfull + * @return - @c RETURN_OK if data was sent successfull * - Everything else triggers falure event with - * returnvalue as parameter 1 + * returnvalue as parameter 1 */ virtual ReturnValue_t getSendSuccess(CookieIF *cookie) = 0; @@ -99,9 +99,9 @@ public: * * @param cookie * @param requestLen Size of data to read - * @return -@c RETURN_OK to confirm the request for data has been sent. + * @return - @c RETURN_OK to confirm the request for data has been sent. * - Everything else triggers failure event with - * returnvalue as parameter 1 + * returnvalue as parameter 1 */ virtual ReturnValue_t requestReceiveMessage(CookieIF *cookie, size_t requestLen) = 0; @@ -113,8 +113,8 @@ public: * @param buffer [out] Set reply here (by using *buffer = ...) * @param size [out] size pointer to set (by using *size = ...). * Set to 0 if no reply was received - * @return -@c RETURN_OK for successfull receive - * -@c NO_REPLY_RECEIVED if not reply was received. Setting size to + * @return - @c RETURN_OK for successfull receive + * - @c NO_REPLY_RECEIVED if not reply was received. Setting size to * 0 has the same effect * - Everything else triggers failure event with * returnvalue as parameter 1 diff --git a/osal/FreeRTOS/BinarySemaphore.h b/osal/FreeRTOS/BinarySemaphore.h index 541266929..373e26bfc 100644 --- a/osal/FreeRTOS/BinarySemaphore.h +++ b/osal/FreeRTOS/BinarySemaphore.h @@ -35,24 +35,20 @@ public: static constexpr ReturnValue_t SEMAPHORE_NOT_OWNED = MAKE_RETURN_CODE(2); static constexpr ReturnValue_t SEMAPHORE_NULLPOINTER = MAKE_RETURN_CODE(3); - /** - * Create a binary semaphore - */ BinarySemaphore(); /** - * Copy ctor - * @param + * @brief Copy ctor */ BinarySemaphore(const BinarySemaphore&); /** - * Copy assignment + * @brief Copy assignment */ BinarySemaphore& operator=(const BinarySemaphore&); /** - * Move constructor + * @brief Move constructor */ BinarySemaphore (BinarySemaphore &&); @@ -81,16 +77,16 @@ public: /** * Same as lockBinarySemaphore() with timeout in FreeRTOS ticks. * @param timeoutTicks - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure + * @return - @c RETURN_OK on success + * - @c RETURN_FAILED on failure */ ReturnValue_t takeBinarySemaphoreTickTimeout(TickType_t timeoutTicks = BinarySemaphore::NO_BLOCK_TICKS); /** * Give back the binary semaphore - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure + * @return - @c RETURN_OK on success + * - @c RETURN_FAILED on failure */ ReturnValue_t giveBinarySemaphore(); @@ -108,8 +104,8 @@ public: /** * Wrapper function to give back semaphore from handle * @param semaphore - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure + * @return - @c RETURN_OK on success + * - @c RETURN_FAILED on failure */ static ReturnValue_t giveBinarySemaphore(SemaphoreHandle_t semaphore); @@ -118,8 +114,8 @@ public: * @param semaphore * @param higherPriorityTaskWoken This will be set to pdPASS if a task with a higher priority * was unblocked - * @return -@c RETURN_OK on success - * -@c RETURN_FAILED on failure + * @return - @c RETURN_OK on success + * - @c RETURN_FAILED on failure */ static ReturnValue_t giveBinarySemaphoreFromISR(SemaphoreHandle_t semaphore, BaseType_t * higherPriorityTaskWoken); diff --git a/serialize/SerializeDoc.h b/serialize/SerializeDoc.h new file mode 100644 index 000000000..6186b77b7 --- /dev/null +++ b/serialize/SerializeDoc.h @@ -0,0 +1,16 @@ +/** + * @page serialPage Serialization Tools + * This page refers to the serialization tools included in framework/serialize. + * The serialization tools are a useful tool to convert object data into raw + * buffers and vice-versa. Here is a rough overview which tool to use for + * which purpose. + * + * @section endSwapper Endian Swapper + * This header file includes tools to do simple serial order swapping + * + * @section serialiezIF SerializeIF + * + * @section serElement SerializeElement + * + */ + diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index 6c50f0de9..a7cbfa7cc 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -31,7 +31,7 @@ seconds_t Stopwatch::stopSeconds() { void Stopwatch::display() { if(displayMode == StopwatchDisplayMode::MILLIS) { - info << "Stopwatch: Operation took " << elapsedTime.tv_sec * 1000 + + info << "Stopwatch: Operation took " << elapsedTime.tv_sec / 1000 + elapsedTime.tv_usec * 1000 << " milliseconds" << std::endl; } else if(displayMode == StopwatchDisplayMode::SECONDS) { From 841b28b65d3c46a175d283d01e92729495f218d9 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Thu, 9 Apr 2020 18:02:10 +0200 Subject: [PATCH 0165/1774] stopwatch ms now working --- timemanager/Stopwatch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/timemanager/Stopwatch.cpp b/timemanager/Stopwatch.cpp index a7cbfa7cc..3f0755fd7 100644 --- a/timemanager/Stopwatch.cpp +++ b/timemanager/Stopwatch.cpp @@ -12,7 +12,7 @@ Stopwatch::Stopwatch(bool displayOnDestruction, StopwatchDisplayMode displayMode): displayMode(displayMode), displayOnDestruction(displayOnDestruction) { // Measures start time on initialization. - Clock::getUptime(&startTime); + startTime = Clock::getUptime(); } void Stopwatch::start() { @@ -31,8 +31,8 @@ seconds_t Stopwatch::stopSeconds() { void Stopwatch::display() { if(displayMode == StopwatchDisplayMode::MILLIS) { - info << "Stopwatch: Operation took " << elapsedTime.tv_sec / 1000 + - elapsedTime.tv_usec * 1000 << " milliseconds" << std::endl; + info << "Stopwatch: Operation took " << (elapsedTime.tv_sec * 1000 + + elapsedTime.tv_usec / 1000) << " milliseconds" << std::endl; } else if(displayMode == StopwatchDisplayMode::SECONDS) { info <<"Stopwatch: Operation took " << std::setprecision(3) From 69e9710bf17013f974188ee420279107b472e822 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 10 Apr 2020 17:06:06 +0200 Subject: [PATCH 0166/1774] added intial carriage return im preamble --- osal/FreeRTOS/BinarySemaphore.cpp | 6 ++---- serviceinterface/ServiceInterfaceBuffer.cpp | 9 +++++---- serviceinterface/ServiceInterfaceBuffer.h | 10 +++++----- serviceinterface/ServiceInterfaceStream.cpp | 4 ++-- serviceinterface/ServiceInterfaceStream.h | 4 ++-- tmtcservices/TmTcBridge.cpp | 4 ++-- 6 files changed, 18 insertions(+), 19 deletions(-) diff --git a/osal/FreeRTOS/BinarySemaphore.cpp b/osal/FreeRTOS/BinarySemaphore.cpp index 05c97ae2e..e2cddacc0 100644 --- a/osal/FreeRTOS/BinarySemaphore.cpp +++ b/osal/FreeRTOS/BinarySemaphore.cpp @@ -138,10 +138,8 @@ ReturnValue_t BinarySemaphore::giveBinarySemaphoreFromISR(SemaphoreHandle_t sema BaseType_t returncode = xSemaphoreGiveFromISR(semaphore, higherPriorityTaskWoken); if (returncode == pdPASS) { if(*higherPriorityTaskWoken == pdPASS) { - // Request context switch - // TODO: I don't know if this will ever happen but if it does, - // I want to to know in case this causes issues. If it doesn't - // we should remove this. + // Request context switch because unblocking the semaphore + // caused a high priority task unblock. TaskManagement::requestContextSwitch(CallContext::isr); } return HasReturnvaluesIF::RETURN_OK; diff --git a/serviceinterface/ServiceInterfaceBuffer.cpp b/serviceinterface/ServiceInterfaceBuffer.cpp index 6798b776d..527db07b1 100644 --- a/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/serviceinterface/ServiceInterfaceBuffer.cpp @@ -27,8 +27,8 @@ int ServiceInterfaceBuffer::sync(void) { Clock::TimeOfDay_t loggerTime; Clock::getDateAndTime(&loggerTime); char preamble[96] = { 0 }; - sprintf(preamble, "%s: | %" PRIu32 ":%02" PRIu32 ":%02" PRIu32 ".%03" PRIu32 " | ", - this->log_message.c_str(), + sprintf(preamble, "\r%s: | %" PRIu32 ":%02" PRIu32 ":%02" PRIu32 + ".%03" PRIu32 " | ", this->log_message.c_str(), loggerTime.hour, loggerTime.minute, loggerTime.second, @@ -45,7 +45,8 @@ int ServiceInterfaceBuffer::sync(void) { #ifndef UT699 -ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, uint16_t port) { +ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, + uint16_t port) { this->log_message = set_message; this->isActive = true; setp( buf, buf + BUF_SIZE ); @@ -59,7 +60,7 @@ void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) { } memcpy(array, begin, length); - for( ; begin != end; begin++){ + for(; begin != end; begin++){ printChar(begin); } diff --git a/serviceinterface/ServiceInterfaceBuffer.h b/serviceinterface/ServiceInterfaceBuffer.h index b42c8a197..b4756d417 100644 --- a/serviceinterface/ServiceInterfaceBuffer.h +++ b/serviceinterface/ServiceInterfaceBuffer.h @@ -7,8 +7,8 @@ #include #ifndef UT699 -class ServiceInterfaceBuffer: public std::basic_streambuf > { +class ServiceInterfaceBuffer: + public std::basic_streambuf> { friend class ServiceInterfaceStream; public: ServiceInterfaceBuffer(std::string set_message, uint16_t port); @@ -17,11 +17,11 @@ protected: // This is called when buffer becomes full. If // buffer is not used, then this is called every // time when characters are put to stream. - virtual int overflow(int c = Traits::eof()); + int overflow(int c = Traits::eof()) override; // This function is called when stream is flushed, // for example when std::endl is put to stream. - virtual int sync(void); + int sync(void) override; private: // For additional message information @@ -30,7 +30,7 @@ private: typedef std::char_traits Traits; // Work in buffer mode. It is also possible to work without buffer. - static size_t const BUF_SIZE = 128; + static size_t const BUF_SIZE = 150; char buf[BUF_SIZE]; // In this function, the characters are parsed. diff --git a/serviceinterface/ServiceInterfaceStream.cpp b/serviceinterface/ServiceInterfaceStream.cpp index c2979f369..f52413a44 100644 --- a/serviceinterface/ServiceInterfaceStream.cpp +++ b/serviceinterface/ServiceInterfaceStream.cpp @@ -6,6 +6,6 @@ void ServiceInterfaceStream::setActive( bool myActive) { ServiceInterfaceStream::ServiceInterfaceStream(std::string set_message, uint16_t port) : - std::basic_ostream >(&buf), buf( - set_message, port) { + std::basic_ostream>(&buf), + buf(set_message, port) { } diff --git a/serviceinterface/ServiceInterfaceStream.h b/serviceinterface/ServiceInterfaceStream.h index 44cf1168f..4a5b709fb 100644 --- a/serviceinterface/ServiceInterfaceStream.h +++ b/serviceinterface/ServiceInterfaceStream.h @@ -14,7 +14,8 @@ extern std::ostream info; extern std::ostream warning; extern std::ostream error; -class ServiceInterfaceStream : public std::basic_ostream< char, std::char_traits< char > > { +class ServiceInterfaceStream : + public std::basic_ostream> { protected: ServiceInterfaceBuffer buf; public: @@ -23,5 +24,4 @@ public: }; - #endif /* FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACESTREAM_H_ */ diff --git a/tmtcservices/TmTcBridge.cpp b/tmtcservices/TmTcBridge.cpp index 6b563f983..8450494a6 100644 --- a/tmtcservices/TmTcBridge.cpp +++ b/tmtcservices/TmTcBridge.cpp @@ -104,7 +104,7 @@ ReturnValue_t TmTcBridge::readTmQueue() { ReturnValue_t TmTcBridge::storeDownlinkData(TmTcMessage *message) { info << "TMTC Bridge: Comm Link down. " - "Saving packet ID to be sent later " << std::endl; + "Saving packet ID to be sent later\r\n" << std::flush; store_address_t storeId; if(fifo.full()) { @@ -124,7 +124,7 @@ ReturnValue_t TmTcBridge::sendStoredTm() { ReturnValue_t result = RETURN_OK; while(!fifo.empty() && counter < MAX_STORED_DATA_SENT_PER_CYCLE) { info << "UDP Server: Sending stored TM data. There are " - << (int) fifo.size() << " left to send" << std::endl; + << (int) fifo.size() << " left to send\r\n" << std::flush; store_address_t storeId; const uint8_t* data = NULL; size_t size = 0; From eb2df3d88cc3bc2c70bda89208bf4e392bbef860 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Sun, 12 Apr 2020 23:06:57 +0200 Subject: [PATCH 0167/1774] Using C++ to implement preamble. adding optional flag for carriage return --- datapool/PoolRawAccessHelper.h | 2 +- osal/linux/FixedTimeslotTask.cpp | 4 ++- serviceinterface/ServiceInterfaceBuffer.cpp | 32 ++++++++++++--------- serviceinterface/ServiceInterfaceBuffer.h | 22 ++++++++++++-- serviceinterface/ServiceInterfaceStream.cpp | 4 +-- serviceinterface/ServiceInterfaceStream.h | 5 ++-- 6 files changed, 47 insertions(+), 22 deletions(-) diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h index 89974ea4f..7d9b9b487 100644 --- a/datapool/PoolRawAccessHelper.h +++ b/datapool/PoolRawAccessHelper.h @@ -69,7 +69,7 @@ private: struct SerializationArgs { uint8_t ** buffer; size_t * size; - const uint32_t max_size; + const size_t max_size; bool bigEndian; }; /** diff --git a/osal/linux/FixedTimeslotTask.cpp b/osal/linux/FixedTimeslotTask.cpp index 21040e6ef..7f117301a 100644 --- a/osal/linux/FixedTimeslotTask.cpp +++ b/osal/linux/FixedTimeslotTask.cpp @@ -9,7 +9,9 @@ uint32_t FixedTimeslotTask::deadlineMissedCount = 0; const size_t PeriodicTaskIF::MINIMUM_STACK_SIZE = PTHREAD_STACK_MIN; -FixedTimeslotTask::FixedTimeslotTask(const char* name_, int priority_, size_t stackSize_, uint32_t periodMs_):PosixThread(name_,priority_,stackSize_),pst(periodMs_),started(false) { +FixedTimeslotTask::FixedTimeslotTask(const char* name_, int priority_, + size_t stackSize_, uint32_t periodMs_): + PosixThread(name_,priority_,stackSize_),pst(periodMs_),started(false) { } FixedTimeslotTask::~FixedTimeslotTask() { diff --git a/serviceinterface/ServiceInterfaceBuffer.cpp b/serviceinterface/ServiceInterfaceBuffer.cpp index 527db07b1..a2365d000 100644 --- a/serviceinterface/ServiceInterfaceBuffer.cpp +++ b/serviceinterface/ServiceInterfaceBuffer.cpp @@ -1,13 +1,10 @@ #include #include #include -#include // to be implemented by bsp extern "C" void printChar(const char*); - - int ServiceInterfaceBuffer::overflow(int c) { // Handle output putChars(pbase(), pptr()); @@ -26,15 +23,16 @@ int ServiceInterfaceBuffer::sync(void) { if (this->isActive) { Clock::TimeOfDay_t loggerTime; Clock::getDateAndTime(&loggerTime); - char preamble[96] = { 0 }; - sprintf(preamble, "\r%s: | %" PRIu32 ":%02" PRIu32 ":%02" PRIu32 - ".%03" PRIu32 " | ", this->log_message.c_str(), - loggerTime.hour, - loggerTime.minute, - loggerTime.second, - loggerTime.usecond /1000); + std::string preamble; + if(addCrToPreamble) { + preamble += "\r"; + } + preamble += log_message + ": | " + zero_padded(loggerTime.hour, 2) + + ":" + zero_padded(loggerTime.minute, 2) + ":" + + zero_padded(loggerTime.second, 2) + "." + + zero_padded(loggerTime.usecond/1000, 3) + " | "; // Write log_message and time - this->putChars(preamble, preamble + sizeof(preamble)); + this->putChars(preamble.c_str(), preamble.c_str() + preamble.size()); // Handle output this->putChars(pbase(), pptr()); } @@ -43,10 +41,13 @@ int ServiceInterfaceBuffer::sync(void) { return 0; } + + #ifndef UT699 ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, - uint16_t port) { + uint16_t port, bool addCrToPreamble) { + this->addCrToPreamble = addCrToPreamble; this->log_message = set_message; this->isActive = true; setp( buf, buf + BUF_SIZE ); @@ -67,10 +68,15 @@ void ServiceInterfaceBuffer::putChars(char const* begin, char const* end) { } #endif +/** + * TODO: This is architecture specific. Maybe there is a better solution + * to move this into the Bsp folder.. + */ #ifdef UT699 #include -ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, uint16_t port) { +ServiceInterfaceBuffer::ServiceInterfaceBuffer(std::string set_message, + uint16_t port) { this->log_message = set_message; this->isActive = true; setp( buf, buf + BUF_SIZE ); diff --git a/serviceinterface/ServiceInterfaceBuffer.h b/serviceinterface/ServiceInterfaceBuffer.h index b4756d417..a2bc4f4b1 100644 --- a/serviceinterface/ServiceInterfaceBuffer.h +++ b/serviceinterface/ServiceInterfaceBuffer.h @@ -2,16 +2,17 @@ #define FRAMEWORK_SERVICEINTERFACE_SERVICEINTERFACEBUFFER_H_ #include -#include #include #include +#include #ifndef UT699 class ServiceInterfaceBuffer: public std::basic_streambuf> { friend class ServiceInterfaceStream; public: - ServiceInterfaceBuffer(std::string set_message, uint16_t port); + ServiceInterfaceBuffer(std::string set_message, uint16_t port, + bool addCrToPreamble); protected: bool isActive; // This is called when buffer becomes full. If @@ -28,13 +29,28 @@ private: std::string log_message; // For EOF detection typedef std::char_traits Traits; + // This is useful for some terminal programs which do not have + // implicit carriage return with newline characters. + bool addCrToPreamble; // Work in buffer mode. It is also possible to work without buffer. - static size_t const BUF_SIZE = 150; + static size_t const BUF_SIZE = 128; char buf[BUF_SIZE]; // In this function, the characters are parsed. void putChars(char const* begin, char const* end); + + template + std::string zero_padded(const T& num, uint8_t width) { + std::ostringstream string_to_pad; + string_to_pad << std::setw(width) << std::setfill('0') << num; + std::string result = string_to_pad.str(); + if (result.length() > width) + { + result.erase(0, result.length() - width); + } + return result; + } }; #endif diff --git a/serviceinterface/ServiceInterfaceStream.cpp b/serviceinterface/ServiceInterfaceStream.cpp index f52413a44..40f52f1fe 100644 --- a/serviceinterface/ServiceInterfaceStream.cpp +++ b/serviceinterface/ServiceInterfaceStream.cpp @@ -5,7 +5,7 @@ void ServiceInterfaceStream::setActive( bool myActive) { } ServiceInterfaceStream::ServiceInterfaceStream(std::string set_message, - uint16_t port) : + bool addCrToPreamble, uint16_t port) : std::basic_ostream>(&buf), - buf(set_message, port) { + buf(set_message, port, addCrToPreamble) { } diff --git a/serviceinterface/ServiceInterfaceStream.h b/serviceinterface/ServiceInterfaceStream.h index 4a5b709fb..5e223f0eb 100644 --- a/serviceinterface/ServiceInterfaceStream.h +++ b/serviceinterface/ServiceInterfaceStream.h @@ -7,7 +7,7 @@ #include #include -//Unfortunately, there must be a forward declaration of log_fe +// Unfortunately, there must be a forward declaration of log_fe // (MUST be defined in main), to let the system know where to write to. extern std::ostream debug; extern std::ostream info; @@ -19,7 +19,8 @@ class ServiceInterfaceStream : protected: ServiceInterfaceBuffer buf; public: - ServiceInterfaceStream( std::string set_message, uint16_t port = 1234 ); + ServiceInterfaceStream( std::string set_message, + bool addCrToPreamble = false, uint16_t port = 1234); void setActive( bool ); }; From a0ee010926eb3870c61c8eaa8cd39f9601b1fa86 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Mon, 13 Apr 2020 16:27:05 +0200 Subject: [PATCH 0168/1774] Added test folder. --- framework.mk | 1 + serialize/EndianSwapper.h | 4 +- serialize/SerialBufferAdapter.cpp | 17 ++- serialize/SerialBufferAdapter.h | 18 +-- serialize/SerializeAdapter.h | 37 ++--- test/UnitTestClass.cpp | 217 ++++++++++++++++++++++++++++++ test/UnitTestClass.h | 78 +++++++++++ 7 files changed, 338 insertions(+), 34 deletions(-) create mode 100644 test/UnitTestClass.cpp create mode 100644 test/UnitTestClass.h diff --git a/framework.mk b/framework.mk index a5a653641..2e7e57e93 100644 --- a/framework.mk +++ b/framework.mk @@ -54,3 +54,4 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/packetmatcher/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/pus/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcservices/*.cpp) +CXXSRC += $(wildcard $(FRAMEWORK_PATH)/test/*.cpp) diff --git a/serialize/EndianSwapper.h b/serialize/EndianSwapper.h index 25fb681e9..9f621902f 100644 --- a/serialize/EndianSwapper.h +++ b/serialize/EndianSwapper.h @@ -11,9 +11,7 @@ */ class EndianSwapper { private: - EndianSwapper() { - } - ; + EndianSwapper() {}; public: template static T swap(T in) { diff --git a/serialize/SerialBufferAdapter.cpp b/serialize/SerialBufferAdapter.cpp index f97d0d588..42ea3dada 100644 --- a/serialize/SerialBufferAdapter.cpp +++ b/serialize/SerialBufferAdapter.cpp @@ -12,8 +12,8 @@ SerialBufferAdapter::SerialBufferAdapter(const void* buffer, } template -SerialBufferAdapter::SerialBufferAdapter(void* buffer, count_t bufferLength, - bool serializeLength) : +SerialBufferAdapter::SerialBufferAdapter(void* buffer, + count_t bufferLength, bool serializeLength) : serializeLength(serializeLength), bufferLength(bufferLength) { uint8_t * member_buffer = static_cast(buffer); m_buffer = member_buffer; @@ -26,8 +26,8 @@ SerialBufferAdapter::~SerialBufferAdapter() { } template -ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, size_t* size, - const size_t max_size, bool bigEndian) const { +ReturnValue_t SerialBufferAdapter::serialize(uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) const { uint32_t serializedLength = bufferLength; if (serializeLength) { serializedLength += AutoSerializeAdapter::getSerializedSize( @@ -98,7 +98,8 @@ ReturnValue_t SerialBufferAdapter::deSerialize(const uint8_t** buffer, template uint8_t * SerialBufferAdapter::getBuffer() { if(m_buffer == nullptr) { - error << "Wrong access function for stored type ! Use getConstBuffer()" << std::endl; + error << "Wrong access function for stored type !" + " Use getConstBuffer()" << std::endl; return nullptr; } return m_buffer; @@ -107,14 +108,16 @@ uint8_t * SerialBufferAdapter::getBuffer() { template const uint8_t * SerialBufferAdapter::getConstBuffer() { if(constBuffer == nullptr) { - error << "Wrong access function for stored type ! Use getBuffer()" << std::endl; + error << "Wrong access function for stored type !" + " Use getBuffer()" << std::endl; return nullptr; } return constBuffer; } template -void SerialBufferAdapter::setBuffer(void * buffer, count_t buffer_length) { +void SerialBufferAdapter::setBuffer(void * buffer, + count_t buffer_length) { m_buffer = static_cast(buffer); bufferLength = buffer_length; } diff --git a/serialize/SerialBufferAdapter.h b/serialize/SerialBufferAdapter.h index cf3ae07ed..4a886cbaa 100644 --- a/serialize/SerialBufferAdapter.h +++ b/serialize/SerialBufferAdapter.h @@ -8,11 +8,13 @@ * This adapter provides an interface for SerializeIF to serialize or deserialize * buffers with no length header but a known size. * - * Additionally, the buffer length can be serialized too and will be put in front of the serialized buffer. + * Additionally, the buffer length can be serialized too and will be put in + * front of the serialized buffer. * * Can be used with SerialLinkedListAdapter by declaring a SerializeElement with - * SerialElement> serialBufferElement. - * Right now, the SerialBufferAdapter must always be initialized with the buffer and size ! + * SerialElement>. + * Right now, the SerialBufferAdapter must always + * be initialized with the buffer and size ! * * \ingroup serialize */ @@ -27,14 +29,16 @@ public: * @param bufferLength * @param serializeLength */ - SerialBufferAdapter(const void* buffer, count_t bufferLength, bool serializeLength = false); + SerialBufferAdapter(const void* buffer, count_t bufferLength, + bool serializeLength = false); /** - * Constructor for non-constant uint8_t buffer. Length field can be serialized optionally. + * Constructor for non-constant uint8_t buffer. + * Length field can be serialized optionally. * Type of length can be supplied as template type. * @param buffer * @param bufferLength - * @param serializeLength + * @param serializeLength Length field will be serialized with size count_t */ SerialBufferAdapter(void* buffer, count_t bufferLength, bool serializeLength = false); @@ -58,6 +62,4 @@ private: count_t bufferLength = 0; }; - - #endif /* SERIALBUFFERADAPTER_H_ */ diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index 81a3730f8..fce8651b5 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -9,18 +9,21 @@ /** * @brief This adapter provides an interface to use the SerializeIF functions - * with arbitrary template objects to facilitate and simplify the serialization of classes - * with different multiple different data types into buffers and vice-versa. + * with arbitrary template objects to facilitate and simplify the + * serialization of classes with different multiple different data types + * into buffers and vice-versa. * @details * Examples: - * A report class is converted into a TM buffer. The report class implements a serialize functions and calls - * the AutoSerializeAdapter::serialize function repeatedly on all object data fields. - * The getSerializedSize function is implemented by calling the - * AutoSerializeAdapter::getSerializedSize function repeatedly on all data fields. + * A report class is converted into a TM buffer. The report class implements a + * serialize functions and calls the AutoSerializeAdapter::serialize function + * repeatedly on all object data fields. The getSerializedSize function is + * implemented by calling the AutoSerializeAdapter::getSerializedSize function + * repeatedly on all data fields. * - * The AutoSerializeAdapter functions can also be used as an alternative to memcpy - * to retrieve data out of a buffer directly into a class variable with data type T while being able to specify endianness. - * The boolean bigEndian specifies whether an endian swap is performed on the data before + * The AutoSerializeAdapter functions can also be used as an alternative to + * memcpy to retrieve data out of a buffer directly into a class variable + * with data type T while being able to specify endianness. The boolean + * bigEndian specifies whether an endian swap is performed on the data before * serialization or deserialization. * * If the target architecture is little endian (ARM), any data types created might @@ -50,8 +53,8 @@ * memcpy(&data,buffer + positionOfTargetByte1,sizeof(data)); * data = EndianSwapper::swap(data); * - * When serializing for downlink, the packets are generally serialized assuming big endian data format - * like seen in TmPacketStored.cpp for example. + * When serializing for downlink, the packets are generally serialized assuming + * big endian data format like seen in TmPacketStored.cpp for example. * * @ingroup serialize */ @@ -83,8 +86,10 @@ public: /** * Deserialize buffer into object * @param object [out] Object to be deserialized with buffer data - * @param buffer buffer containing the data. Non-Const pointer to non-const pointer to const buffer. - * @param size int32_t type to allow value to be values smaller than 0, needed for range/size checking + * @param buffer buffer containing the data. Non-Const pointer to non-const + * pointer to const buffer. + * @param size int32_t type to allow value to be values smaller than 0, + * needed for range/size checking * @param bigEndian Specify endianness * @return */ @@ -106,7 +111,7 @@ public: } } - uint32_t getSerializedSize(const T * object) { + size_t getSerializedSize(const T * object) { return sizeof(T); } @@ -123,7 +128,7 @@ public: } return object->serialize(buffer, size, max_size, bigEndian); } - uint32_t getSerializedSize(const T* object) const { + size_t getSerializedSize(const T* object) const { return object->getSerializedSize(); } @@ -163,7 +168,7 @@ public: return adapter.serialize(object, buffer, size, max_size, bigEndian); } template - static uint32_t getSerializedSize(const T* object) { + static size_t getSerializedSize(const T* object) { SerializeAdapter_::Is> adapter; return adapter.getSerializedSize(object); } diff --git a/test/UnitTestClass.cpp b/test/UnitTestClass.cpp new file mode 100644 index 000000000..7050dece0 --- /dev/null +++ b/test/UnitTestClass.cpp @@ -0,0 +1,217 @@ +/** + * @file UnitTestClass.cpp + * + * @date 11.04.2020 + * @author R. Mueller + */ +#include +#include +#include +#include + +#include + +UnitTestClass::UnitTestClass() { +} + +UnitTestClass::~UnitTestClass() { +} + +ReturnValue_t UnitTestClass::performTests() { + ReturnValue_t result = test_serialization(); + if(result != RETURN_OK) { + return result; + } + + return RETURN_OK; +} + +ReturnValue_t UnitTestClass::test_serialization() { + // Here, we test all serialization tools. First test basic cases. + ReturnValue_t result = test_autoserialization(); + if(result != RETURN_OK) { + return result; + } + result = test_serial_buffer_adapter(); + if(result != RETURN_OK) { + return result; + } + return RETURN_OK; +} + +ReturnValue_t UnitTestClass::test_autoserialization() { + current_id = TestIds::AUTO_SERIALIZATION_SIZE; + // Unit Test getSerializedSize + if(AutoSerializeAdapter:: + getSerializedSize(&test_value_bool) != sizeof(test_value_bool) or + AutoSerializeAdapter:: + getSerializedSize(&tv_uint8) != sizeof(tv_uint8) or + AutoSerializeAdapter:: + getSerializedSize(&tv_uint16) != sizeof(tv_uint16) or + AutoSerializeAdapter:: + getSerializedSize(&tv_uint32) != sizeof(tv_uint32) or + AutoSerializeAdapter:: + getSerializedSize(&tv_uint64) != sizeof(tv_uint64) or + AutoSerializeAdapter:: + getSerializedSize(&tv_int8) != sizeof(tv_int8) or + AutoSerializeAdapter:: + getSerializedSize(&tv_double) != sizeof(tv_double) or + AutoSerializeAdapter:: + getSerializedSize(&tv_int16) != sizeof(tv_int16) or + AutoSerializeAdapter:: + getSerializedSize(&tv_int32) != sizeof(tv_int32) or + AutoSerializeAdapter:: + getSerializedSize(&tv_float) != sizeof(tv_float)) + { + return put_error(current_id); + } + + // Unit Test AutoSerializeAdapter deserialize + current_id = TestIds::AUTO_SERIALIZATION_SERIALIZE; + + size_t serialized_size = 0; + uint8_t * p_array = test_array.data(); + + AutoSerializeAdapter::serialize(&test_value_bool, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_uint8, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_uint16, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_uint32, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_int8, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_int16, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_int32, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_uint64, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_float, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_double, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_sfloat, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_sdouble, &p_array, + &serialized_size, test_array.size(), false); + // expected size is 1 + 1 + 2 + 4 + 1 + 2 + 4 + 8 + 4 + 8 + 4 + 8 + if(serialized_size != 47) { + return put_error(current_id); + } + + // Unit Test AutoSerializeAdapter serialize + current_id = TestIds::AUTO_SERIALIZATION_DESERIALIZE; + p_array = test_array.data(); + ssize_t remaining_size = serialized_size; + AutoSerializeAdapter::deSerialize(&test_value_bool, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_uint8, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_uint16, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_uint32, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_int8, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_int16, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_int32, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_uint64, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_float, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_double, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_sfloat, + const_cast(&p_array), &remaining_size, false); + AutoSerializeAdapter::deSerialize(&tv_sdouble, + const_cast(&p_array), &remaining_size, false); + + // uint16_t tv_uint16 {283}; + // uint32_t tv_uint32 {929221}; + // uint64_t tv_uint64 {2929329429}; + // int8_t tv_int8 {-16}; + // int16_t tv_int16 {-829}; + // int32_t tv_int32 {-2312}; + // float tv_float {8.2149214}; + // float tv_sfloat = {-922.2321321}; + // double tv_double {9.2132142141e8}; + // double tv_sdouble {-2.2421e19}; + if(test_value_bool != true or tv_uint8 != 5 or tv_uint16 != 283 or + tv_uint32 != 929221 or tv_uint64 != 2929329429 or tv_int8 != -16 or + tv_int16 != -829 or tv_int32 != -2312 or tv_float != 8.214921 or + tv_double != 9.2132142141e8 or tv_sfloat != -922.2321321 or + tv_sdouble != -2.2421e19) + { + return put_error(current_id); + } + return RETURN_OK; +} + +ReturnValue_t UnitTestClass::test_serial_buffer_adapter() { + current_id = TestIds::SERIALIZATION_BUFFER_ADAPTER; + + // I will skip endian swapper testing, its going to be changed anyway.. + // uint8_t tv_uint8_swapped = EndianSwapper::swap(tv_uint8); + + size_t serialized_size = 0; + test_value_bool = true; + uint8_t * p_array = test_array.data(); + std::array test_serial_buffer {5, 4, 3, 2, 1}; + SerialBufferAdapter tv_serial_buffer_adapter = + SerialBufferAdapter(test_serial_buffer.data(), + test_serial_buffer.size(), false); + tv_uint16 = 16; + + AutoSerializeAdapter::serialize(&test_value_bool, &p_array,&serialized_size, + test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_serial_buffer_adapter, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_uint16, &p_array, &serialized_size, + test_array.size(), false); + + if(serialized_size != 8 or test_array[0] != true or test_array[1] != 5 + or test_array[2] != 4 or test_array[3] != 3 or test_array[4] != 2 + or test_array[5] != 1) + { + return put_error(current_id); + } + memcpy(&tv_uint16, test_array.data() + 6, sizeof(tv_uint16)); + if(tv_uint16 != 16) { + return put_error(current_id); + } + + // Serialize with size field + SerialBufferAdapter tv_serial_buffer_adapter2 = + SerialBufferAdapter(test_serial_buffer.data(), + test_serial_buffer.size(), true); + serialized_size = 0; + p_array = test_array.data(); + AutoSerializeAdapter::serialize(&test_value_bool, &p_array,&serialized_size, + test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_serial_buffer_adapter2, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_uint16, &p_array, &serialized_size, + test_array.size(), false); + + if(serialized_size != 9 or test_array[0] != true or test_array[1] != 5 + or test_array[2] != 5 or test_array[3] != 4 or test_array[4] != 3 + or test_array[5] != 2 or test_array[6] != 1) + { + return put_error(current_id); + } + memcpy(&tv_uint16, test_array.data() + 6, sizeof(tv_uint16)); + if(tv_uint16 != 16) { + return put_error(current_id); + } + return RETURN_OK; +} + +ReturnValue_t UnitTestClass::put_error(TestIds current_id) { + error << "Unit Tester failed at test ID " + << static_cast(current_id) << "\r\n" << std::flush; + return RETURN_FAILED; +} diff --git a/test/UnitTestClass.h b/test/UnitTestClass.h new file mode 100644 index 000000000..c93ea0bc8 --- /dev/null +++ b/test/UnitTestClass.h @@ -0,0 +1,78 @@ +/** + * @file UnitTestClass.h + * + * @date 11.04.2020 + * @author R. Mueller + */ + +#ifndef FRAMEWORK_TEST_UNITTESTCLASS_H_ +#define FRAMEWORK_TEST_UNITTESTCLASS_H_ + +#include +#include +#include + +/** + * We could start doing basic forms of Unit Testing (without a framework, first) + * for framework components. This could include: + * + * 1. TMTC Services + * 2. Serialization tools + * 3. Framework internal algorithms + */ + +class UnitTestClass: public HasReturnvaluesIF { +public: + UnitTestClass(); + virtual~ UnitTestClass(); + + enum class TestIds { + AUTO_SERIALIZATION_SIZE = 0, + AUTO_SERIALIZATION_SERIALIZE = 1, + AUTO_SERIALIZATION_DESERIALIZE = 2, + SERIALIZATION_BUFFER_ADAPTER = 3, + SERIALIZATION_FIXED_ARRAY_LIST_ADAPTER = 4, + SERIALIZATION_COMBINATION = 5, + TMTC_SERVICES , + MISC + }; + + /** + * Some function which calls all other tests + * @return + */ + ReturnValue_t performTests(); + + ReturnValue_t test_serialization(); + ReturnValue_t test_autoserialization(); + ReturnValue_t test_serial_buffer_adapter(); +private: + uint32_t errorCounter = 0; + TestIds current_id = TestIds::MISC; + std::array test_array; + + using TestResultMap = std::map; + using TestBuffer = std::vector; + TestResultMap testResultMap; + + // POD test values + bool test_value_bool = true; + uint8_t tv_uint8 {5}; + uint16_t tv_uint16 {283}; + uint32_t tv_uint32 {929221}; + uint64_t tv_uint64 {2929329429}; + + int8_t tv_int8 {-16}; + int16_t tv_int16 {-829}; + int32_t tv_int32 {-2312}; + + float tv_float {8.2149214}; + float tv_sfloat = {-922.2321321}; + double tv_double {9.2132142141e8}; + double tv_sdouble {-2.2421e19}; + + ReturnValue_t put_error(TestIds currentId); +}; + + +#endif /* FRAMEWORK_TEST_UNITTESTCLASS_H_ */ From 0d016e5a2b2e5b566c7c7f2a11e64c1c93dcc4d3 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 13 Apr 2020 16:37:25 +0200 Subject: [PATCH 0169/1774] slight formatting --- osal/linux/PeriodicPosixTask.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osal/linux/PeriodicPosixTask.h b/osal/linux/PeriodicPosixTask.h index e3fa57229..43647eda1 100644 --- a/osal/linux/PeriodicPosixTask.h +++ b/osal/linux/PeriodicPosixTask.h @@ -9,7 +9,8 @@ class PeriodicPosixTask: public PosixThread, public PeriodicTaskIF { public: - PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_, uint32_t period_, void(*deadlineMissedFunc_)()); + PeriodicPosixTask(const char* name_, int priority_, size_t stackSize_, + uint32_t period_, void(*deadlineMissedFunc_)()); virtual ~PeriodicPosixTask(); /** * @brief The method to start the task. From b48a0a4a4ce5ea9b4e85b76223e357fe49ce6907 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 13 Apr 2020 22:45:23 +0200 Subject: [PATCH 0170/1774] unit test class continued. serialize adapter functions which are internal, extracted to separate class --- container/IsDerivedFrom.h | 9 ++ serialize/SerializeAdapter.h | 162 +++++++-------------------- serialize/SerializeAdapterInternal.h | 114 +++++++++++++++++++ test/UnitTestClass.cpp | 87 +++++++++++++- test/UnitTestClass.h | 18 +-- 5 files changed, 259 insertions(+), 131 deletions(-) create mode 100644 serialize/SerializeAdapterInternal.h diff --git a/container/IsDerivedFrom.h b/container/IsDerivedFrom.h index 520033dbd..8142a3781 100644 --- a/container/IsDerivedFrom.h +++ b/container/IsDerivedFrom.h @@ -1,6 +1,13 @@ #ifndef ISDERIVEDFROM_H_ #define ISDERIVEDFROM_H_ +/** + * These template type checks are based on SFINAE + * (https://en.cppreference.com/w/cpp/language/sfinae) + * + * @tparam D Derived Type + * @tparam B Base Type + */ template class IsDerivedFrom { class No { @@ -9,7 +16,9 @@ class IsDerivedFrom { No no[3]; }; + // This will be chosen if B is the base type static Yes Test(B*); // declared, but not defined + // This will be chosen for anything else static No Test(... ); // declared, but not defined public: diff --git a/serialize/SerializeAdapter.h b/serialize/SerializeAdapter.h index fce8651b5..d926bfcec 100644 --- a/serialize/SerializeAdapter.h +++ b/serialize/SerializeAdapter.h @@ -1,19 +1,18 @@ #ifndef SERIALIZEADAPTER_H_ #define SERIALIZEADAPTER_H_ -#include #include -#include #include -#include +#include +#include /** - * @brief This adapter provides an interface to use the SerializeIF functions + * @brief These adapters provides an interface to use the SerializeIF functions * with arbitrary template objects to facilitate and simplify the * serialization of classes with different multiple different data types * into buffers and vice-versa. * @details - * Examples: + * * A report class is converted into a TM buffer. The report class implements a * serialize functions and calls the AutoSerializeAdapter::serialize function * repeatedly on all object data fields. The getSerializedSize function is @@ -26,137 +25,42 @@ * bigEndian specifies whether an endian swap is performed on the data before * serialization or deserialization. * - * If the target architecture is little endian (ARM), any data types created might - * have the wrong endiness if they are to be used for the FSFW. * There are three ways to retrieve data out of a buffer to be used in the FSFW - * to use regular aligned (big endian) data. - * This can also be applied to uint32_t and uint64_t: + * to use regular aligned (big endian) data. Examples: * * 1. Use the AutoSerializeAdapter::deSerialize function - * The pointer *buffer will be incremented automatically by the typeSize of the object, - * so this function can be called on &buffer repeatedly without adjusting pointer position. - * Set bigEndian parameter to true to perform endian swapping. - * + * The pointer *buffer will be incremented automatically by the typeSize + * of the object, so this function can be called on &buffer repeatedly + * without adjusting pointer position. Set bigEndian parameter to true + * to perform endian swapping, if necessary + * @code * uint16_t data; * int32_t dataLen = sizeof(data); - * ReturnValue_t result = AutoSerializeAdapter::deSerialize(&data,&buffer,&dataLen,true); - * - * 2. Perform a bitshift operation. Perform endian swapping if necessary: + * ReturnValue_t result = + * AutoSerializeAdapter::deSerialize(&data,&buffer,&dataLen,true); + * @endcode * + * 2. Perform a bitshift operation. Watch for for endianness: + * @code * uint16_t data; * data = buffer[targetByte1] << 8 | buffer[targetByte2]; - * data = EndianSwapper::swap(data); - * - * 3. Memcpy can be used when data is little-endian. Perform endian-swapping if necessary. + * data = EndianSwapper::swap(data); //optional, or swap order above + * @endcode * + * 3. memcpy or std::copy can also be used, but watch out if system + * endianness is different from required data endianness. + * Perform endian-swapping if necessary. + * @code * uint16_t data; * memcpy(&data,buffer + positionOfTargetByte1,sizeof(data)); - * data = EndianSwapper::swap(data); + * data = EndianSwapper::swap(data); //optional + * @endcode * * When serializing for downlink, the packets are generally serialized assuming * big endian data format like seen in TmPacketStored.cpp for example. * * @ingroup serialize */ -template -class SerializeAdapter_ { -public: - static ReturnValue_t serialize(const T* object, uint8_t** buffer, - size_t* size, const size_t max_size, bool bigEndian) { - size_t ignoredSize = 0; - if (size == NULL) { - size = &ignoredSize; - } - if (sizeof(T) + *size <= max_size) { - T tmp; - if (bigEndian) { - tmp = EndianSwapper::swap(*object); - } else { - tmp = *object; - } - memcpy(*buffer, &tmp, sizeof(T)); - *size += sizeof(T); - (*buffer) += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::BUFFER_TOO_SHORT; - } - } - - /** - * Deserialize buffer into object - * @param object [out] Object to be deserialized with buffer data - * @param buffer buffer containing the data. Non-Const pointer to non-const - * pointer to const buffer. - * @param size int32_t type to allow value to be values smaller than 0, - * needed for range/size checking - * @param bigEndian Specify endianness - * @return - */ - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, ssize_t* size, - bool bigEndian) { - T tmp; - *size -= sizeof(T); - if (*size >= 0) { - memcpy(&tmp, *buffer, sizeof(T)); - if (bigEndian) { - *object = EndianSwapper::swap(tmp); - } else { - *object = tmp; - } - *buffer += sizeof(T); - return HasReturnvaluesIF::RETURN_OK; - } else { - return SerializeIF::STREAM_TOO_SHORT; - } - } - - size_t getSerializedSize(const T * object) { - return sizeof(T); - } - -}; - -template -class SerializeAdapter_ { -public: - ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size, - const size_t max_size, bool bigEndian) const { - size_t ignoredSize = 0; - if (size == NULL) { - size = &ignoredSize; - } - return object->serialize(buffer, size, max_size, bigEndian); - } - size_t getSerializedSize(const T* object) const { - return object->getSerializedSize(); - } - - ReturnValue_t deSerialize(T* object, const uint8_t** buffer, ssize_t* size, - bool bigEndian) { - return object->deSerialize(buffer, size, bigEndian); - } -}; - -template -class SerializeAdapter { -public: - static ReturnValue_t serialize(const T* object, uint8_t** buffer, - size_t* size, const size_t max_size, bool bigEndian) { - SerializeAdapter_::Is> adapter; - return adapter.serialize(object, buffer, size, max_size, bigEndian); - } - static uint32_t getSerializedSize(const T* object) { - SerializeAdapter_::Is> adapter; - return adapter.getSerializedSize(object); - } - - static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, - ssize_t* size, bool bigEndian) { - SerializeAdapter_::Is> adapter; - return adapter.deSerialize(object, buffer, size, bigEndian); - } -}; // No type specification necessary here. class AutoSerializeAdapter { @@ -180,4 +84,24 @@ public: } }; +template +class SerializeAdapter { +public: + static ReturnValue_t serialize(const T* object, uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) { + SerializeAdapter_::Is> adapter; + return adapter.serialize(object, buffer, size, max_size, bigEndian); + } + static uint32_t getSerializedSize(const T* object) { + SerializeAdapter_::Is> adapter; + return adapter.getSerializedSize(object); + } + + static ReturnValue_t deSerialize(T* object, const uint8_t** buffer, + ssize_t* size, bool bigEndian) { + SerializeAdapter_::Is> adapter; + return adapter.deSerialize(object, buffer, size, bigEndian); + } +}; + #endif /* SERIALIZEADAPTER_H_ */ diff --git a/serialize/SerializeAdapterInternal.h b/serialize/SerializeAdapterInternal.h new file mode 100644 index 000000000..46dbdf191 --- /dev/null +++ b/serialize/SerializeAdapterInternal.h @@ -0,0 +1,114 @@ +/** + * @file SerializeAdapterInternal.h + * + * @date 13.04.2020 + * @author R. Mueller + */ + +#ifndef FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ +#define FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ +#include +#include +#include + +/** + * This template specialization will be chosen for fundamental types. + * @tparam T + * @tparam + */ +template +class SerializeAdapter_ { +public: + /** + * + * @param object + * @param buffer + * @param size + * @param max_size + * @param bigEndian + * @return + */ + static ReturnValue_t serialize(const T* object, uint8_t** buffer, + size_t* size, const size_t max_size, bool bigEndian) { + size_t ignoredSize = 0; + if (size == nullptr) { + size = &ignoredSize; + } + if (sizeof(T) + *size <= max_size) { + T tmp; + if (bigEndian) { + tmp = EndianSwapper::swap(*object); + } else { + tmp = *object; + } + memcpy(*buffer, &tmp, sizeof(T)); + *size += sizeof(T); + (*buffer) += sizeof(T); + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::BUFFER_TOO_SHORT; + } + } + + /** + * Deserialize buffer into object + * @param object [out] Object to be deserialized with buffer data + * @param buffer buffer containing the data. Non-Const pointer to non-const + * pointer to const buffer. + * @param size int32_t type to allow value to be values smaller than 0, + * needed for range/size checking + * @param bigEndian Specify endianness + * @return + */ + ReturnValue_t deSerialize(T* object, const uint8_t** buffer, ssize_t* size, + bool bigEndian) { + T tmp; + *size -= sizeof(T); + if (*size >= 0) { + memcpy(&tmp, *buffer, sizeof(T)); + if (bigEndian) { + *object = EndianSwapper::swap(tmp); + } else { + *object = tmp; + } + *buffer += sizeof(T); + return HasReturnvaluesIF::RETURN_OK; + } else { + return SerializeIF::STREAM_TOO_SHORT; + } + } + + size_t getSerializedSize(const T * object) { + return sizeof(T); + } +}; + +/** + * This template specialization will be chosen for class derived from + * SerializeIF. + * @tparam T + * @tparam + */ +template +class SerializeAdapter_ { +public: + ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size, + const size_t max_size, bool bigEndian) const { + size_t ignoredSize = 0; + if (size == NULL) { + size = &ignoredSize; + } + return object->serialize(buffer, size, max_size, bigEndian); + } + + size_t getSerializedSize(const T* object) const { + return object->getSerializedSize(); + } + + ReturnValue_t deSerialize(T* object, const uint8_t** buffer, ssize_t* size, + bool bigEndian) { + return object->deSerialize(buffer, size, bigEndian); + } +}; + +#endif /* FRAMEWORK_SERIALIZE_SERIALIZEADAPTERINTERNAL_H_ */ diff --git a/test/UnitTestClass.cpp b/test/UnitTestClass.cpp index 7050dece0..ac570b21e 100644 --- a/test/UnitTestClass.cpp +++ b/test/UnitTestClass.cpp @@ -17,7 +17,7 @@ UnitTestClass::UnitTestClass() { UnitTestClass::~UnitTestClass() { } -ReturnValue_t UnitTestClass::performTests() { +ReturnValue_t UnitTestClass::perform_tests() { ReturnValue_t result = test_serialization(); if(result != RETURN_OK) { return result; @@ -28,7 +28,11 @@ ReturnValue_t UnitTestClass::performTests() { ReturnValue_t UnitTestClass::test_serialization() { // Here, we test all serialization tools. First test basic cases. - ReturnValue_t result = test_autoserialization(); + ReturnValue_t result = test_endianness_tools(); + if(result != RETURN_OK) { + return result; + } + result = test_autoserialization(); if(result != RETURN_OK) { return result; } @@ -39,6 +43,47 @@ ReturnValue_t UnitTestClass::test_serialization() { return RETURN_OK; } +ReturnValue_t UnitTestClass::test_endianness_tools() { + test_array[0] = 0; + test_array[1] = 0; + uint16_t two_byte_value = 1; + size_t size = 0; + uint8_t* p_array = test_array.data(); + AutoSerializeAdapter::serialize(&two_byte_value, &p_array, &size, 2, false); + // Little endian: Value one on first byte + if(test_array[0] != 1 and test_array[1] != 0) { + return put_error(TestIds::ENDIANNESS_TOOLS); + + } + p_array = test_array.data(); + size = 0; + AutoSerializeAdapter::serialize(&two_byte_value, &p_array, &size, 2, true); + // Big endian: Value one on second byte + if(test_array[0] != 0 and test_array[1] != 1) { + return put_error(TestIds::ENDIANNESS_TOOLS); + } + + // Endianness paameter will be changed later. +// p_array = test_array.data(); +// ssize_t ssize = size; +// // Resulting parameter should be big endian +// AutoSerializeAdapter::deSerialize(&two_byte_value, +// const_cast(&p_array), &ssize, true); +// if(two_byte_value != 1) { +// return put_error(TestIds::ENDIANNESS_TOOLS); +// } +// +// ssize = size; +// p_array = test_array.data(); +// // Resulting parameter should be little endian +// AutoSerializeAdapter::deSerialize(&two_byte_value, +// const_cast(&p_array), &ssize, false); +// if(two_byte_value != 256) { +// return put_error(TestIds::ENDIANNESS_TOOLS); +// } + return RETURN_OK; +} + ReturnValue_t UnitTestClass::test_autoserialization() { current_id = TestIds::AUTO_SERIALIZATION_SIZE; // Unit Test getSerializedSize @@ -142,15 +187,21 @@ ReturnValue_t UnitTestClass::test_autoserialization() { // double tv_sdouble {-2.2421e19}; if(test_value_bool != true or tv_uint8 != 5 or tv_uint16 != 283 or tv_uint32 != 929221 or tv_uint64 != 2929329429 or tv_int8 != -16 or - tv_int16 != -829 or tv_int32 != -2312 or tv_float != 8.214921 or - tv_double != 9.2132142141e8 or tv_sfloat != -922.2321321 or - tv_sdouble != -2.2421e19) + tv_int16 != -829 or tv_int32 != -2312) { return put_error(current_id); } + + if(abs(tv_float - 8.214921) > 0.0001 or + abs(tv_double - 9.2132142141e8) > 0.01 or + abs(tv_sfloat - (-922.2321321)) > 0.0001 or + abs(tv_sdouble - (-2.2421e19)) > 0.01) { + return put_error(current_id); + } return RETURN_OK; } +// TODO: Also test for constant buffers. ReturnValue_t UnitTestClass::test_serial_buffer_adapter() { current_id = TestIds::SERIALIZATION_BUFFER_ADAPTER; @@ -203,6 +254,31 @@ ReturnValue_t UnitTestClass::test_serial_buffer_adapter() { { return put_error(current_id); } + memcpy(&tv_uint16, test_array.data() + 7, sizeof(tv_uint16)); + if(tv_uint16 != 16) { + return put_error(current_id); + } + + // Serialize with size field + SerialBufferAdapter tv_serial_buffer_adapter3 = + SerialBufferAdapter( + const_cast(test_serial_buffer.data()), + test_serial_buffer.size(), false); + serialized_size = 0; + p_array = test_array.data(); + AutoSerializeAdapter::serialize(&test_value_bool, &p_array,&serialized_size, + test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_serial_buffer_adapter3, &p_array, + &serialized_size, test_array.size(), false); + AutoSerializeAdapter::serialize(&tv_uint16, &p_array, &serialized_size, + test_array.size(), false); + + if(serialized_size != 8 or test_array[0] != true or test_array[1] != 5 + or test_array[2] != 4 or test_array[3] != 3 or test_array[4] != 2 + or test_array[5] != 1) + { + return put_error(current_id); + } memcpy(&tv_uint16, test_array.data() + 6, sizeof(tv_uint16)); if(tv_uint16 != 16) { return put_error(current_id); @@ -215,3 +291,4 @@ ReturnValue_t UnitTestClass::put_error(TestIds current_id) { << static_cast(current_id) << "\r\n" << std::flush; return RETURN_FAILED; } + diff --git a/test/UnitTestClass.h b/test/UnitTestClass.h index c93ea0bc8..078cf3c9f 100644 --- a/test/UnitTestClass.h +++ b/test/UnitTestClass.h @@ -19,6 +19,8 @@ * 1. TMTC Services * 2. Serialization tools * 3. Framework internal algorithms + * + * TODO: Maybe use specialized framework. */ class UnitTestClass: public HasReturnvaluesIF { @@ -27,12 +29,13 @@ public: virtual~ UnitTestClass(); enum class TestIds { - AUTO_SERIALIZATION_SIZE = 0, - AUTO_SERIALIZATION_SERIALIZE = 1, - AUTO_SERIALIZATION_DESERIALIZE = 2, - SERIALIZATION_BUFFER_ADAPTER = 3, - SERIALIZATION_FIXED_ARRAY_LIST_ADAPTER = 4, - SERIALIZATION_COMBINATION = 5, + ENDIANNESS_TOOLS, + AUTO_SERIALIZATION_SIZE, + AUTO_SERIALIZATION_SERIALIZE, + AUTO_SERIALIZATION_DESERIALIZE , + SERIALIZATION_BUFFER_ADAPTER, + SERIALIZATION_FIXED_ARRAY_LIST_ADAPTER, + SERIALIZATION_COMBINATION, TMTC_SERVICES , MISC }; @@ -41,11 +44,12 @@ public: * Some function which calls all other tests * @return */ - ReturnValue_t performTests(); + ReturnValue_t perform_tests(); ReturnValue_t test_serialization(); ReturnValue_t test_autoserialization(); ReturnValue_t test_serial_buffer_adapter(); + ReturnValue_t test_endianness_tools(); private: uint32_t errorCounter = 0; TestIds current_id = TestIds::MISC; From 03b0ae7b68541f8d6268c0dcc8b763e04870d185 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 14 Apr 2020 11:16:51 +0200 Subject: [PATCH 0171/1774] unit test fixes --- test/UnitTestClass.cpp | 2 +- test/UnitTestClass.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/UnitTestClass.cpp b/test/UnitTestClass.cpp index 7050dece0..f2925a240 100644 --- a/test/UnitTestClass.cpp +++ b/test/UnitTestClass.cpp @@ -17,7 +17,7 @@ UnitTestClass::UnitTestClass() { UnitTestClass::~UnitTestClass() { } -ReturnValue_t UnitTestClass::performTests() { +ReturnValue_t UnitTestClass::perform_tests() { ReturnValue_t result = test_serialization(); if(result != RETURN_OK) { return result; diff --git a/test/UnitTestClass.h b/test/UnitTestClass.h index c93ea0bc8..f11842695 100644 --- a/test/UnitTestClass.h +++ b/test/UnitTestClass.h @@ -41,7 +41,7 @@ public: * Some function which calls all other tests * @return */ - ReturnValue_t performTests(); + ReturnValue_t perform_tests(); ReturnValue_t test_serialization(); ReturnValue_t test_autoserialization(); From c5e5de1530acb3f3212514c254dea65635ece647 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 14 Apr 2020 12:24:26 +0200 Subject: [PATCH 0172/1774] deleted example values --- test/UnitTestClass.cpp | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/test/UnitTestClass.cpp b/test/UnitTestClass.cpp index ac570b21e..89d4001d3 100644 --- a/test/UnitTestClass.cpp +++ b/test/UnitTestClass.cpp @@ -11,11 +11,9 @@ #include -UnitTestClass::UnitTestClass() { -} +UnitTestClass::UnitTestClass() {} -UnitTestClass::~UnitTestClass() { -} +UnitTestClass::~UnitTestClass() {} ReturnValue_t UnitTestClass::perform_tests() { ReturnValue_t result = test_serialization(); @@ -175,16 +173,6 @@ ReturnValue_t UnitTestClass::test_autoserialization() { AutoSerializeAdapter::deSerialize(&tv_sdouble, const_cast(&p_array), &remaining_size, false); - // uint16_t tv_uint16 {283}; - // uint32_t tv_uint32 {929221}; - // uint64_t tv_uint64 {2929329429}; - // int8_t tv_int8 {-16}; - // int16_t tv_int16 {-829}; - // int32_t tv_int32 {-2312}; - // float tv_float {8.2149214}; - // float tv_sfloat = {-922.2321321}; - // double tv_double {9.2132142141e8}; - // double tv_sdouble {-2.2421e19}; if(test_value_bool != true or tv_uint8 != 5 or tv_uint16 != 283 or tv_uint32 != 929221 or tv_uint64 != 2929329429 or tv_int8 != -16 or tv_int16 != -829 or tv_int32 != -2312) From af27a2441affb1923a4a2ff33c044ce825549094 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Tue, 14 Apr 2020 16:19:13 +0200 Subject: [PATCH 0173/1774] added catch framework for basic testing --- framework.mk | 2 +- serialize/SerializeAdapterInternal.h | 8 +- test/CatchExample.cpp | 49 + test/UnitTestClass.cpp | 11 + test/UnitTestClass.h | 1 + test/catch2/catch.hpp | 17618 +++++++++++++++++++++ test/catch2/catch_reporter_automake.hpp | 62 + test/catch2/catch_reporter_sonarqube.hpp | 181 + test/catch2/catch_reporter_tap.hpp | 253 + test/catch2/catch_reporter_teamcity.hpp | 219 + 10 files changed, 18401 insertions(+), 3 deletions(-) create mode 100644 test/CatchExample.cpp create mode 100644 test/catch2/catch.hpp create mode 100644 test/catch2/catch_reporter_automake.hpp create mode 100644 test/catch2/catch_reporter_sonarqube.hpp create mode 100644 test/catch2/catch_reporter_tap.hpp create mode 100644 test/catch2/catch_reporter_teamcity.hpp diff --git a/framework.mk b/framework.mk index 2e7e57e93..6f64b7205 100644 --- a/framework.mk +++ b/framework.mk @@ -54,4 +54,4 @@ CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/packetmatcher/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcpacket/pus/*.cpp) CXXSRC += $(wildcard $(FRAMEWORK_PATH)/tmtcservices/*.cpp) -CXXSRC += $(wildcard $(FRAMEWORK_PATH)/test/*.cpp) +CXXSRC += $(wildcard $(FRAMEWORK_PATH)/test/*.cpp) \ No newline at end of file diff --git a/serialize/SerializeAdapterInternal.h b/serialize/SerializeAdapterInternal.h index 46dbdf191..ed0f6c3b8 100644 --- a/serialize/SerializeAdapterInternal.h +++ b/serialize/SerializeAdapterInternal.h @@ -12,7 +12,8 @@ #include /** - * This template specialization will be chosen for fundamental types. + * This template specialization will be chosen for fundamental types, + * based on partial template specialization * @tparam T * @tparam */ @@ -30,6 +31,9 @@ public: */ static ReturnValue_t serialize(const T* object, uint8_t** buffer, size_t* size, const size_t max_size, bool bigEndian) { + // function eventuelly serializes structs here. + // does this work on every architecture? + //static_assert(std::is_fundamental::value); size_t ignoredSize = 0; if (size == nullptr) { size = &ignoredSize; @@ -85,7 +89,7 @@ public: /** * This template specialization will be chosen for class derived from - * SerializeIF. + * SerializeIF, based on partial template specialization. * @tparam T * @tparam */ diff --git a/test/CatchExample.cpp b/test/CatchExample.cpp new file mode 100644 index 000000000..4db6a5c2a --- /dev/null +++ b/test/CatchExample.cpp @@ -0,0 +1,49 @@ +// Catch Example. +// Does not work yet. Problems with linker without main and config folder. +// Let Catch provide main(): + +#if defined(UNIT_TEST) +#define CATCH_CONFIG_MAIN + +#include +#include +#include + +int Factorial( int number ) { + return number <= 1 ? number : Factorial( number - 1 ) * number; // fail +// return number <= 1 ? 1 : Factorial( number - 1 ) * number; // pass +} + + + +TEST_CASE( "Factorial of 0 is 1 (fail)", "[single-file]" ) { + REQUIRE( Factorial(0) == 1 ); +} + +TEST_CASE( "Factorials of 1 and higher are computed (pass)", "[single-file]" ) { + REQUIRE( Factorial(1) == 1 ); + REQUIRE( Factorial(2) == 2 ); + REQUIRE( Factorial(3) == 6 ); + REQUIRE( Factorial(10) == 3628800 ); +} + +TEST_CASE( "Custom test", "[single-file]" ) { + UnitTestClass unitTestClass; + REQUIRE( unitTestClass.test_autoserialization() == HasReturnvaluesIF::RETURN_OK ); +} + +// Compile & run: +// - g++ -std=c++11 -Wall -I$(CATCH_SINGLE_INCLUDE) -o 010-TestCase 010-TestCase.cpp && ./010-TestCase --success +// - cl -EHsc -I%CATCH_SINGLE_INCLUDE% 010-TestCase.cpp && 010-TestCase --success + +// Expected compact output (all assertions): +// +// prompt> 010-TestCase --reporter compact --success +// 010-TestCase.cpp:14: failed: Factorial(0) == 1 for: 0 == 1 +// 010-TestCase.cpp:18: passed: Factorial(1) == 1 for: 1 == 1 +// 010-TestCase.cpp:19: passed: Factorial(2) == 2 for: 2 == 2 +// 010-TestCase.cpp:20: passed: Factorial(3) == 6 for: 6 == 6 +// 010-TestCase.cpp:21: passed: Factorial(10) == 3628800 for: 3628800 (0x375f00) == 3628800 (0x375f00) +// Failed 1 test case, failed 1 assertion. + +#endif diff --git a/test/UnitTestClass.cpp b/test/UnitTestClass.cpp index 89d4001d3..d20dfb0a0 100644 --- a/test/UnitTestClass.cpp +++ b/test/UnitTestClass.cpp @@ -11,6 +11,15 @@ #include +#if defined(UNIT_TEST) +#include "catch.hpp" +#define CATCH_CONFIG_MAIN + +TEST_CASE( "Serialization Size tests", "[single-file]") { + //REQUIRE(UnitTestClass::test_serialization == RETURN_OK ); +} +#endif + UnitTestClass::UnitTestClass() {} UnitTestClass::~UnitTestClass() {} @@ -53,6 +62,7 @@ ReturnValue_t UnitTestClass::test_endianness_tools() { return put_error(TestIds::ENDIANNESS_TOOLS); } + p_array = test_array.data(); size = 0; AutoSerializeAdapter::serialize(&two_byte_value, &p_array, &size, 2, true); @@ -180,6 +190,7 @@ ReturnValue_t UnitTestClass::test_autoserialization() { return put_error(current_id); } + // These epsilon values were just guessed.. It appears to work though. if(abs(tv_float - 8.214921) > 0.0001 or abs(tv_double - 9.2132142141e8) > 0.01 or abs(tv_sfloat - (-922.2321321)) > 0.0001 or diff --git a/test/UnitTestClass.h b/test/UnitTestClass.h index 078cf3c9f..d9ba9d1c6 100644 --- a/test/UnitTestClass.h +++ b/test/UnitTestClass.h @@ -9,6 +9,7 @@ #define FRAMEWORK_TEST_UNITTESTCLASS_H_ #include + #include #include diff --git a/test/catch2/catch.hpp b/test/catch2/catch.hpp new file mode 100644 index 000000000..51618b38e --- /dev/null +++ b/test/catch2/catch.hpp @@ -0,0 +1,17618 @@ +/* + * Catch v2.11.3 + * Generated: 2020-03-19 13:44:21.042491 + * ---------------------------------------------------------- + * This file has been merged from multiple headers. Please don't edit it directly + * Copyright (c) 2020 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + */ +#ifndef TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +#define TWOBLUECUBES_SINGLE_INCLUDE_CATCH_HPP_INCLUDED +// start catch.hpp + + +#define CATCH_VERSION_MAJOR 2 +#define CATCH_VERSION_MINOR 11 +#define CATCH_VERSION_PATCH 3 + +#ifdef __clang__ +# pragma clang system_header +#elif defined __GNUC__ +# pragma GCC system_header +#endif + +// start catch_suppress_warnings.h + +#ifdef __clang__ +# ifdef __ICC // icpc defines the __clang__ macro +# pragma warning(push) +# pragma warning(disable: 161 1682) +# else // __ICC +# pragma clang diagnostic push +# pragma clang diagnostic ignored "-Wpadded" +# pragma clang diagnostic ignored "-Wswitch-enum" +# pragma clang diagnostic ignored "-Wcovered-switch-default" +# endif +#elif defined __GNUC__ + // Because REQUIREs trigger GCC's -Wparentheses, and because still + // supported version of g++ have only buggy support for _Pragmas, + // Wparentheses have to be suppressed globally. +# pragma GCC diagnostic ignored "-Wparentheses" // See #674 for details + +# pragma GCC diagnostic push +# pragma GCC diagnostic ignored "-Wunused-variable" +# pragma GCC diagnostic ignored "-Wpadded" +#endif +// end catch_suppress_warnings.h +#if defined(CATCH_CONFIG_MAIN) || defined(CATCH_CONFIG_RUNNER) +# define CATCH_IMPL +# define CATCH_CONFIG_ALL_PARTS +#endif + +// In the impl file, we want to have access to all parts of the headers +// Can also be used to sanely support PCHs +#if defined(CATCH_CONFIG_ALL_PARTS) +# define CATCH_CONFIG_EXTERNAL_INTERFACES +# if defined(CATCH_CONFIG_DISABLE_MATCHERS) +# undef CATCH_CONFIG_DISABLE_MATCHERS +# endif +# if !defined(CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER) +# define CATCH_CONFIG_ENABLE_CHRONO_STRINGMAKER +# endif +#endif + +#if !defined(CATCH_CONFIG_IMPL_ONLY) +// start catch_platform.h + +#ifdef __APPLE__ +# include +# if TARGET_OS_OSX == 1 +# define CATCH_PLATFORM_MAC +# elif TARGET_OS_IPHONE == 1 +# define CATCH_PLATFORM_IPHONE +# endif + +#elif defined(linux) || defined(__linux) || defined(__linux__) +# define CATCH_PLATFORM_LINUX + +#elif defined(WIN32) || defined(__WIN32__) || defined(_WIN32) || defined(_MSC_VER) || defined(__MINGW32__) +# define CATCH_PLATFORM_WINDOWS +#endif + +// end catch_platform.h + +#ifdef CATCH_IMPL +# ifndef CLARA_CONFIG_MAIN +# define CLARA_CONFIG_MAIN_NOT_DEFINED +# define CLARA_CONFIG_MAIN +# endif +#endif + +// start catch_user_interfaces.h + +namespace Catch { + unsigned int rngSeed(); +} + +// end catch_user_interfaces.h +// start catch_tag_alias_autoregistrar.h + +// start catch_common.h + +// start catch_compiler_capabilities.h + +// Detect a number of compiler features - by compiler +// The following features are defined: +// +// CATCH_CONFIG_COUNTER : is the __COUNTER__ macro supported? +// CATCH_CONFIG_WINDOWS_SEH : is Windows SEH supported? +// CATCH_CONFIG_POSIX_SIGNALS : are POSIX signals supported? +// CATCH_CONFIG_DISABLE_EXCEPTIONS : Are exceptions enabled? +// **************** +// Note to maintainers: if new toggles are added please document them +// in configuration.md, too +// **************** + +// In general each macro has a _NO_ form +// (e.g. CATCH_CONFIG_NO_POSIX_SIGNALS) which disables the feature. +// Many features, at point of detection, define an _INTERNAL_ macro, so they +// can be combined, en-mass, with the _NO_ forms later. + +#ifdef __cplusplus + +# if (__cplusplus >= 201402L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201402L) +# define CATCH_CPP14_OR_GREATER +# endif + +# if (__cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L) +# define CATCH_CPP17_OR_GREATER +# endif + +#endif + +#if defined(CATCH_CPP17_OR_GREATER) +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif + +// We have to avoid both ICC and Clang, because they try to mask themselves +// as gcc, and we want only GCC in this block +#if defined(__GNUC__) && !defined(__clang__) && !defined(__ICC) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "GCC diagnostic pop" ) + +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +#endif + +#if defined(__clang__) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic push" ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION _Pragma( "clang diagnostic pop" ) + +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) (void)__builtin_constant_p(__VA_ARGS__) + +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wexit-time-destructors\"" ) \ + _Pragma( "clang diagnostic ignored \"-Wglobal-constructors\"") + +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wparentheses\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-variable\"" ) + +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wgnu-zero-variadic-macro-arguments\"" ) + +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS \ + _Pragma( "clang diagnostic ignored \"-Wunused-template\"" ) + +#endif // __clang__ + +//////////////////////////////////////////////////////////////////////////////// +// Assume that non-Windows platforms support posix signals by default +#if !defined(CATCH_PLATFORM_WINDOWS) + #define CATCH_INTERNAL_CONFIG_POSIX_SIGNALS +#endif + +//////////////////////////////////////////////////////////////////////////////// +// We know some environments not to support full POSIX signals +#if defined(__CYGWIN__) || defined(__QNX__) || defined(__EMSCRIPTEN__) || defined(__DJGPP__) + #define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +#endif + +#ifdef __OS400__ +# define CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS +# define CATCH_CONFIG_COLOUR_NONE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Android somehow still does not support std::to_string +#if defined(__ANDROID__) +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING +# define CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Not all Windows environments support SEH properly +#if defined(__MINGW32__) +# define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH +#endif + +//////////////////////////////////////////////////////////////////////////////// +// PS4 +#if defined(__ORBIS__) +# define CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE +#endif + +//////////////////////////////////////////////////////////////////////////////// +// Cygwin +#ifdef __CYGWIN__ + +// Required for some versions of Cygwin to declare gettimeofday +// see: http://stackoverflow.com/questions/36901803/gettimeofday-not-declared-in-this-scope-cygwin +# define _BSD_SOURCE +// some versions of cygwin (most) do not support std::to_string. Use the libstd check. +// https://gcc.gnu.org/onlinedocs/gcc-4.8.2/libstdc++/api/a01053_source.html line 2812-2813 +# if !((__cplusplus >= 201103L) && defined(_GLIBCXX_USE_C99) \ + && !defined(_GLIBCXX_HAVE_BROKEN_VSWPRINTF)) + +# define CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING + +# endif +#endif // __CYGWIN__ + +//////////////////////////////////////////////////////////////////////////////// +// Visual C++ +#if defined(_MSC_VER) + +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION __pragma( warning(push) ) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION __pragma( warning(pop) ) + +# if _MSC_VER >= 1900 // Visual Studio 2015 or newer +# define CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +# endif + +// Universal Windows platform does not support SEH +// Or console colours (or console at all...) +# if defined(WINAPI_FAMILY) && (WINAPI_FAMILY == WINAPI_FAMILY_APP) +# define CATCH_CONFIG_COLOUR_NONE +# else +# define CATCH_INTERNAL_CONFIG_WINDOWS_SEH +# endif + +// MSVC traditional preprocessor needs some workaround for __VA_ARGS__ +// _MSVC_TRADITIONAL == 0 means new conformant preprocessor +// _MSVC_TRADITIONAL == 1 means old traditional non-conformant preprocessor +# if !defined(__clang__) // Handle Clang masquerading for msvc +# if !defined(_MSVC_TRADITIONAL) || (defined(_MSVC_TRADITIONAL) && _MSVC_TRADITIONAL) +# define CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +# endif // MSVC_TRADITIONAL +# endif // __clang__ + +#endif // _MSC_VER + +#if defined(_REENTRANT) || defined(_MSC_VER) +// Enable async processing, as -pthread is specified or no additional linking is required +# define CATCH_INTERNAL_CONFIG_USE_ASYNC +#endif // _MSC_VER + +//////////////////////////////////////////////////////////////////////////////// +// Check if we are compiled with -fno-exceptions or equivalent +#if defined(__EXCEPTIONS) || defined(__cpp_exceptions) || defined(_CPPUNWIND) +# define CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED +#endif + +//////////////////////////////////////////////////////////////////////////////// +// DJGPP +#ifdef __DJGPP__ +# define CATCH_INTERNAL_CONFIG_NO_WCHAR +#endif // __DJGPP__ + +//////////////////////////////////////////////////////////////////////////////// +// Embarcadero C++Build +#if defined(__BORLANDC__) + #define CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// Use of __COUNTER__ is suppressed during code analysis in +// CLion/AppCode 2017.2.x and former, because __COUNTER__ is not properly +// handled by it. +// Otherwise all supported compilers support COUNTER macro, +// but user still might want to turn it off +#if ( !defined(__JETBRAINS_IDE__) || __JETBRAINS_IDE__ >= 20170300L ) + #define CATCH_INTERNAL_CONFIG_COUNTER +#endif + +//////////////////////////////////////////////////////////////////////////////// + +// RTX is a special version of Windows that is real time. +// This means that it is detected as Windows, but does not provide +// the same set of capabilities as real Windows does. +#if defined(UNDER_RTSS) || defined(RTX64_BUILD) + #define CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH + #define CATCH_INTERNAL_CONFIG_NO_ASYNC + #define CATCH_CONFIG_COLOUR_NONE +#endif + +#if !defined(_GLIBCXX_USE_C99_MATH_TR1) +#define CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Various stdlib support checks that require __has_include +#if defined(__has_include) + // Check if string_view is available and usable + #if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW + #endif + + // Check if optional is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if byte is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # define CATCH_INTERNAL_CONFIG_CPP17_BYTE + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) + + // Check if variant is available and usable + # if __has_include() && defined(CATCH_CPP17_OR_GREATER) + # if defined(__clang__) && (__clang_major__ < 8) + // work around clang bug with libstdc++ https://bugs.llvm.org/show_bug.cgi?id=31852 + // fix should be in clang 8, workaround in libstdc++ 8.2 + # include + # if defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # define CATCH_CONFIG_NO_CPP17_VARIANT + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__GLIBCXX__) && defined(_GLIBCXX_RELEASE) && (_GLIBCXX_RELEASE < 9) + # else + # define CATCH_INTERNAL_CONFIG_CPP17_VARIANT + # endif // defined(__clang__) && (__clang_major__ < 8) + # endif // __has_include() && defined(CATCH_CPP17_OR_GREATER) +#endif // defined(__has_include) + +#if defined(CATCH_INTERNAL_CONFIG_COUNTER) && !defined(CATCH_CONFIG_NO_COUNTER) && !defined(CATCH_CONFIG_COUNTER) +# define CATCH_CONFIG_COUNTER +#endif +#if defined(CATCH_INTERNAL_CONFIG_WINDOWS_SEH) && !defined(CATCH_CONFIG_NO_WINDOWS_SEH) && !defined(CATCH_CONFIG_WINDOWS_SEH) && !defined(CATCH_INTERNAL_CONFIG_NO_WINDOWS_SEH) +# define CATCH_CONFIG_WINDOWS_SEH +#endif +// This is set by default, because we assume that unix compilers are posix-signal-compatible by default. +#if defined(CATCH_INTERNAL_CONFIG_POSIX_SIGNALS) && !defined(CATCH_INTERNAL_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_NO_POSIX_SIGNALS) && !defined(CATCH_CONFIG_POSIX_SIGNALS) +# define CATCH_CONFIG_POSIX_SIGNALS +#endif +// This is set by default, because we assume that compilers with no wchar_t support are just rare exceptions. +#if !defined(CATCH_INTERNAL_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_NO_WCHAR) && !defined(CATCH_CONFIG_WCHAR) +# define CATCH_CONFIG_WCHAR +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_NO_CPP11_TO_STRING) && !defined(CATCH_CONFIG_CPP11_TO_STRING) +# define CATCH_CONFIG_CPP11_TO_STRING +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_NO_CPP17_OPTIONAL) && !defined(CATCH_CONFIG_CPP17_OPTIONAL) +# define CATCH_CONFIG_CPP17_OPTIONAL +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_NO_CPP17_UNCAUGHT_EXCEPTIONS) && !defined(CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS) +# define CATCH_CONFIG_CPP17_UNCAUGHT_EXCEPTIONS +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_NO_CPP17_STRING_VIEW) && !defined(CATCH_CONFIG_CPP17_STRING_VIEW) +# define CATCH_CONFIG_CPP17_STRING_VIEW +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_VARIANT) && !defined(CATCH_CONFIG_NO_CPP17_VARIANT) && !defined(CATCH_CONFIG_CPP17_VARIANT) +# define CATCH_CONFIG_CPP17_VARIANT +#endif + +#if defined(CATCH_INTERNAL_CONFIG_CPP17_BYTE) && !defined(CATCH_CONFIG_NO_CPP17_BYTE) && !defined(CATCH_CONFIG_CPP17_BYTE) +# define CATCH_CONFIG_CPP17_BYTE +#endif + +#if defined(CATCH_CONFIG_EXPERIMENTAL_REDIRECT) +# define CATCH_INTERNAL_CONFIG_NEW_CAPTURE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_NEW_CAPTURE) && !defined(CATCH_INTERNAL_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NO_NEW_CAPTURE) && !defined(CATCH_CONFIG_NEW_CAPTURE) +# define CATCH_CONFIG_NEW_CAPTURE +#endif + +#if !defined(CATCH_INTERNAL_CONFIG_EXCEPTIONS_ENABLED) && !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +# define CATCH_CONFIG_DISABLE_EXCEPTIONS +#endif + +#if defined(CATCH_INTERNAL_CONFIG_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_NO_POLYFILL_ISNAN) && !defined(CATCH_CONFIG_POLYFILL_ISNAN) +# define CATCH_CONFIG_POLYFILL_ISNAN +#endif + +#if defined(CATCH_INTERNAL_CONFIG_USE_ASYNC) && !defined(CATCH_INTERNAL_CONFIG_NO_ASYNC) && !defined(CATCH_CONFIG_NO_USE_ASYNC) && !defined(CATCH_CONFIG_USE_ASYNC) +# define CATCH_CONFIG_USE_ASYNC +#endif + +#if defined(CATCH_INTERNAL_CONFIG_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_NO_ANDROID_LOGWRITE) && !defined(CATCH_CONFIG_ANDROID_LOGWRITE) +# define CATCH_CONFIG_ANDROID_LOGWRITE +#endif + +#if defined(CATCH_INTERNAL_CONFIG_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_NO_GLOBAL_NEXTAFTER) && !defined(CATCH_CONFIG_GLOBAL_NEXTAFTER) +# define CATCH_CONFIG_GLOBAL_NEXTAFTER +#endif + +// Even if we do not think the compiler has that warning, we still have +// to provide a macro that can be used by the code. +#if !defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_START_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION) +# define CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_WARNINGS +#endif +#if !defined(CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_ZERO_VARIADIC_WARNINGS +#endif + +// The goal of this macro is to avoid evaluation of the arguments, but +// still have the compiler warn on problems inside... +#if !defined(CATCH_INTERNAL_IGNORE_BUT_WARN) +# define CATCH_INTERNAL_IGNORE_BUT_WARN(...) +#endif + +#if defined(__APPLE__) && defined(__apple_build_version__) && (__clang_major__ < 10) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#elif defined(__clang__) && (__clang_major__ < 5) +# undef CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if !defined(CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS) +# define CATCH_INTERNAL_SUPPRESS_UNUSED_TEMPLATE_WARNINGS +#endif + +#if defined(CATCH_CONFIG_DISABLE_EXCEPTIONS) +#define CATCH_TRY if ((true)) +#define CATCH_CATCH_ALL if ((false)) +#define CATCH_CATCH_ANON(type) if ((false)) +#else +#define CATCH_TRY try +#define CATCH_CATCH_ALL catch (...) +#define CATCH_CATCH_ANON(type) catch (type) +#endif + +#if defined(CATCH_INTERNAL_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_NO_TRADITIONAL_MSVC_PREPROCESSOR) && !defined(CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR) +#define CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#endif + +// end catch_compiler_capabilities.h +#define INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) name##line +#define INTERNAL_CATCH_UNIQUE_NAME_LINE( name, line ) INTERNAL_CATCH_UNIQUE_NAME_LINE2( name, line ) +#ifdef CATCH_CONFIG_COUNTER +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __COUNTER__ ) +#else +# define INTERNAL_CATCH_UNIQUE_NAME( name ) INTERNAL_CATCH_UNIQUE_NAME_LINE( name, __LINE__ ) +#endif + +#include +#include +#include + +// We need a dummy global operator<< so we can bring it into Catch namespace later +struct Catch_global_namespace_dummy {}; +std::ostream& operator<<(std::ostream&, Catch_global_namespace_dummy); + +namespace Catch { + + struct CaseSensitive { enum Choice { + Yes, + No + }; }; + + class NonCopyable { + NonCopyable( NonCopyable const& ) = delete; + NonCopyable( NonCopyable && ) = delete; + NonCopyable& operator = ( NonCopyable const& ) = delete; + NonCopyable& operator = ( NonCopyable && ) = delete; + + protected: + NonCopyable(); + virtual ~NonCopyable(); + }; + + struct SourceLineInfo { + + SourceLineInfo() = delete; + SourceLineInfo( char const* _file, std::size_t _line ) noexcept + : file( _file ), + line( _line ) + {} + + SourceLineInfo( SourceLineInfo const& other ) = default; + SourceLineInfo& operator = ( SourceLineInfo const& ) = default; + SourceLineInfo( SourceLineInfo&& ) noexcept = default; + SourceLineInfo& operator = ( SourceLineInfo&& ) noexcept = default; + + bool empty() const noexcept { return file[0] == '\0'; } + bool operator == ( SourceLineInfo const& other ) const noexcept; + bool operator < ( SourceLineInfo const& other ) const noexcept; + + char const* file; + std::size_t line; + }; + + std::ostream& operator << ( std::ostream& os, SourceLineInfo const& info ); + + // Bring in operator<< from global namespace into Catch namespace + // This is necessary because the overload of operator<< above makes + // lookup stop at namespace Catch + using ::operator<<; + + // Use this in variadic streaming macros to allow + // >> +StreamEndStop + // as well as + // >> stuff +StreamEndStop + struct StreamEndStop { + std::string operator+() const; + }; + template + T const& operator + ( T const& value, StreamEndStop ) { + return value; + } +} + +#define CATCH_INTERNAL_LINEINFO \ + ::Catch::SourceLineInfo( __FILE__, static_cast( __LINE__ ) ) + +// end catch_common.h +namespace Catch { + + struct RegistrarForTagAliases { + RegistrarForTagAliases( char const* alias, char const* tag, SourceLineInfo const& lineInfo ); + }; + +} // end namespace Catch + +#define CATCH_REGISTER_TAG_ALIAS( alias, spec ) \ + CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \ + CATCH_INTERNAL_SUPPRESS_GLOBALS_WARNINGS \ + namespace{ Catch::RegistrarForTagAliases INTERNAL_CATCH_UNIQUE_NAME( AutoRegisterTagAlias )( alias, spec, CATCH_INTERNAL_LINEINFO ); } \ + CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION + +// end catch_tag_alias_autoregistrar.h +// start catch_test_registry.h + +// start catch_interfaces_testcase.h + +#include + +namespace Catch { + + class TestSpec; + + struct ITestInvoker { + virtual void invoke () const = 0; + virtual ~ITestInvoker(); + }; + + class TestCase; + struct IConfig; + + struct ITestCaseRegistry { + virtual ~ITestCaseRegistry(); + virtual std::vector const& getAllTests() const = 0; + virtual std::vector const& getAllTestsSorted( IConfig const& config ) const = 0; + }; + + bool isThrowSafe( TestCase const& testCase, IConfig const& config ); + bool matchTest( TestCase const& testCase, TestSpec const& testSpec, IConfig const& config ); + std::vector filterTests( std::vector const& testCases, TestSpec const& testSpec, IConfig const& config ); + std::vector const& getAllTestCasesSorted( IConfig const& config ); + +} + +// end catch_interfaces_testcase.h +// start catch_stringref.h + +#include +#include +#include +#include + +namespace Catch { + + /// A non-owning string class (similar to the forthcoming std::string_view) + /// Note that, because a StringRef may be a substring of another string, + /// it may not be null terminated. + class StringRef { + public: + using size_type = std::size_t; + using const_iterator = const char*; + + private: + static constexpr char const* const s_empty = ""; + + char const* m_start = s_empty; + size_type m_size = 0; + + public: // construction + constexpr StringRef() noexcept = default; + + StringRef( char const* rawChars ) noexcept; + + constexpr StringRef( char const* rawChars, size_type size ) noexcept + : m_start( rawChars ), + m_size( size ) + {} + + StringRef( std::string const& stdString ) noexcept + : m_start( stdString.c_str() ), + m_size( stdString.size() ) + {} + + explicit operator std::string() const { + return std::string(m_start, m_size); + } + + public: // operators + auto operator == ( StringRef const& other ) const noexcept -> bool; + auto operator != (StringRef const& other) const noexcept -> bool { + return !(*this == other); + } + + auto operator[] ( size_type index ) const noexcept -> char { + assert(index < m_size); + return m_start[index]; + } + + public: // named queries + constexpr auto empty() const noexcept -> bool { + return m_size == 0; + } + constexpr auto size() const noexcept -> size_type { + return m_size; + } + + // Returns the current start pointer. If the StringRef is not + // null-terminated, throws std::domain_exception + auto c_str() const -> char const*; + + public: // substrings and searches + // Returns a substring of [start, start + length). + // If start + length > size(), then the substring is [start, size()). + // If start > size(), then the substring is empty. + auto substr( size_type start, size_type length ) const noexcept -> StringRef; + + // Returns the current start pointer. May not be null-terminated. + auto data() const noexcept -> char const*; + + constexpr auto isNullTerminated() const noexcept -> bool { + return m_start[m_size] == '\0'; + } + + public: // iterators + constexpr const_iterator begin() const { return m_start; } + constexpr const_iterator end() const { return m_start + m_size; } + }; + + auto operator += ( std::string& lhs, StringRef const& sr ) -> std::string&; + auto operator << ( std::ostream& os, StringRef const& sr ) -> std::ostream&; + + constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef { + return StringRef( rawChars, size ); + } +} // namespace Catch + +constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef { + return Catch::StringRef( rawChars, size ); +} + +// end catch_stringref.h +// start catch_preprocessor.hpp + + +#define CATCH_RECURSION_LEVEL0(...) __VA_ARGS__ +#define CATCH_RECURSION_LEVEL1(...) CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(CATCH_RECURSION_LEVEL0(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL2(...) CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(CATCH_RECURSION_LEVEL1(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL3(...) CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(CATCH_RECURSION_LEVEL2(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL4(...) CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(CATCH_RECURSION_LEVEL3(__VA_ARGS__))) +#define CATCH_RECURSION_LEVEL5(...) CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(CATCH_RECURSION_LEVEL4(__VA_ARGS__))) + +#ifdef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_EXPAND_VARGS(...) __VA_ARGS__ +// MSVC needs more evaluations +#define CATCH_RECURSION_LEVEL6(...) CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(CATCH_RECURSION_LEVEL5(__VA_ARGS__))) +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL6(CATCH_RECURSION_LEVEL6(__VA_ARGS__)) +#else +#define CATCH_RECURSE(...) CATCH_RECURSION_LEVEL5(__VA_ARGS__) +#endif + +#define CATCH_REC_END(...) +#define CATCH_REC_OUT + +#define CATCH_EMPTY() +#define CATCH_DEFER(id) id CATCH_EMPTY() + +#define CATCH_REC_GET_END2() 0, CATCH_REC_END +#define CATCH_REC_GET_END1(...) CATCH_REC_GET_END2 +#define CATCH_REC_GET_END(...) CATCH_REC_GET_END1 +#define CATCH_REC_NEXT0(test, next, ...) next CATCH_REC_OUT +#define CATCH_REC_NEXT1(test, next) CATCH_DEFER ( CATCH_REC_NEXT0 ) ( test, next, 0) +#define CATCH_REC_NEXT(test, next) CATCH_REC_NEXT1(CATCH_REC_GET_END test, next) + +#define CATCH_REC_LIST0(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1(f, x, peek, ...) , f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0) ) ( f, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2(f, x, peek, ...) f(x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1) ) ( f, peek, __VA_ARGS__ ) + +#define CATCH_REC_LIST0_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST1_UD(f, userdata, x, peek, ...) , f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST0_UD) ) ( f, userdata, peek, __VA_ARGS__ ) +#define CATCH_REC_LIST2_UD(f, userdata, x, peek, ...) f(userdata, x) CATCH_DEFER ( CATCH_REC_NEXT(peek, CATCH_REC_LIST1_UD) ) ( f, userdata, peek, __VA_ARGS__ ) + +// Applies the function macro `f` to each of the remaining parameters, inserts commas between the results, +// and passes userdata as the first parameter to each invocation, +// e.g. CATCH_REC_LIST_UD(f, x, a, b, c) evaluates to f(x, a), f(x, b), f(x, c) +#define CATCH_REC_LIST_UD(f, userdata, ...) CATCH_RECURSE(CATCH_REC_LIST2_UD(f, userdata, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define CATCH_REC_LIST(f, ...) CATCH_RECURSE(CATCH_REC_LIST2(f, __VA_ARGS__, ()()(), ()()(), ()()(), 0)) + +#define INTERNAL_CATCH_EXPAND1(param) INTERNAL_CATCH_EXPAND2(param) +#define INTERNAL_CATCH_EXPAND2(...) INTERNAL_CATCH_NO## __VA_ARGS__ +#define INTERNAL_CATCH_DEF(...) INTERNAL_CATCH_DEF __VA_ARGS__ +#define INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE(...) INTERNAL_CATCH_STRINGIZE2(__VA_ARGS__) +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_STRINGIZE2(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) +#else +// MSVC is adding extra space and needs another indirection to expand INTERNAL_CATCH_NOINTERNAL_CATCH_DEF +#define INTERNAL_CATCH_STRINGIZE2(...) INTERNAL_CATCH_STRINGIZE3(__VA_ARGS__) +#define INTERNAL_CATCH_STRINGIZE3(...) #__VA_ARGS__ +#define INTERNAL_CATCH_STRINGIZE_WITHOUT_PARENS(param) (INTERNAL_CATCH_STRINGIZE(INTERNAL_CATCH_REMOVE_PARENS(param)) + 1) +#endif + +#define INTERNAL_CATCH_MAKE_NAMESPACE2(...) ns_##__VA_ARGS__ +#define INTERNAL_CATCH_MAKE_NAMESPACE(name) INTERNAL_CATCH_MAKE_NAMESPACE2(name) + +#define INTERNAL_CATCH_REMOVE_PARENS(...) INTERNAL_CATCH_EXPAND1(INTERNAL_CATCH_DEF __VA_ARGS__) + +#ifndef CATCH_CONFIG_TRADITIONAL_MSVC_PREPROCESSOR +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) decltype(get_wrapper()) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__)) +#else +#define INTERNAL_CATCH_MAKE_TYPE_LIST2(...) INTERNAL_CATCH_EXPAND_VARGS(decltype(get_wrapper())) +#define INTERNAL_CATCH_MAKE_TYPE_LIST(...) INTERNAL_CATCH_EXPAND_VARGS(INTERNAL_CATCH_MAKE_TYPE_LIST2(INTERNAL_CATCH_REMOVE_PARENS(__VA_ARGS__))) +#endif + +#define INTERNAL_CATCH_MAKE_TYPE_LISTS_FROM_TYPES(...)\ + CATCH_REC_LIST(INTERNAL_CATCH_MAKE_TYPE_LIST,__VA_ARGS__) + +#define INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_0) INTERNAL_CATCH_REMOVE_PARENS(_0) +#define INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_0, _1) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_1_ARG(_1) +#define INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_0, _1, _2) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_2_ARG(_1, _2) +#define INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_0, _1, _2, _3) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_3_ARG(_1, _2, _3) +#define INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_0, _1, _2, _3, _4) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_4_ARG(_1, _2, _3, _4) +#define INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_0, _1, _2, _3, _4, _5) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_5_ARG(_1, _2, _3, _4, _5) +#define INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_0, _1, _2, _3, _4, _5, _6) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_6_ARG(_1, _2, _4, _5, _6) +#define INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_0, _1, _2, _3, _4, _5, _6, _7) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_7_ARG(_1, _2, _3, _4, _5, _6, _7) +#define INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_8_ARG(_1, _2, _3, _4, _5, _6, _7, _8) +#define INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_9_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9) +#define INTERNAL_CATCH_REMOVE_PARENS_11_ARG(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10) INTERNAL_CATCH_REMOVE_PARENS(_0), INTERNAL_CATCH_REMOVE_PARENS_10_ARG(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10) + +#define INTERNAL_CATCH_VA_NARGS_IMPL(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, N, ...) N + +#define INTERNAL_CATCH_TYPE_GEN\ + template struct TypeList {};\ + template\ + constexpr auto get_wrapper() noexcept -> TypeList { return {}; }\ + template class...> struct TemplateTypeList{};\ + template class...Cs>\ + constexpr auto get_wrapper() noexcept -> TemplateTypeList { return {}; }\ + template\ + struct append;\ + template\ + struct rewrap;\ + template class, typename...>\ + struct create;\ + template class, typename>\ + struct convert;\ + \ + template \ + struct append { using type = T; };\ + template< template class L1, typename...E1, template class L2, typename...E2, typename...Rest>\ + struct append, L2, Rest...> { using type = typename append, Rest...>::type; };\ + template< template class L1, typename...E1, typename...Rest>\ + struct append, TypeList, Rest...> { using type = L1; };\ + \ + template< template class Container, template class List, typename...elems>\ + struct rewrap, List> { using type = TypeList>; };\ + template< template class Container, template class List, class...Elems, typename...Elements>\ + struct rewrap, List, Elements...> { using type = typename append>, typename rewrap, Elements...>::type>::type; };\ + \ + template