From 0ce67de8c8eb8f4eb532e4445e3a1e3765ff07f2 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Fri, 10 Jan 2020 00:57:09 +0100 Subject: [PATCH 1/7] 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 2/7] 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 3/7] 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 4/7] 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 5/7] 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 6/7] 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 7/7] 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();