diff --git a/datapool/PoolRawAccessHelper.cpp b/datapool/PoolRawAccessHelper.cpp deleted file mode 100644 index 5a6827b6..00000000 --- a/datapool/PoolRawAccessHelper.cpp +++ /dev/null @@ -1,181 +0,0 @@ -#include "PoolRawAccessHelper.h" -#include "../datapoolglob/GlobalDataSet.h" -#include "../serialize/SerializeAdapter.h" -#include "../serviceinterface/ServiceInterfaceStream.h" - -#include -#include - -PoolRawAccessHelper::PoolRawAccessHelper(uint32_t * poolIdBuffer_, - uint8_t numberOfParameters_): - poolIdBuffer(reinterpret_cast(poolIdBuffer_)), - numberOfParameters(numberOfParameters_), validBufferIndex(0), - validBufferIndexBit(1) { -} - -PoolRawAccessHelper::~PoolRawAccessHelper() { -} - -ReturnValue_t PoolRawAccessHelper::serialize(uint8_t **buffer, size_t *size, - const size_t max_size, SerializeIF::Endianness streamEndianness) { - SerializationArgs serializationArgs = {buffer, size, max_size, - streamEndianness}; - ReturnValue_t result = RETURN_OK; - size_t remainingParametersSize = numberOfParameters * 4; - for(uint8_t count=0; count < numberOfParameters; count++) { - result = serializeCurrentPoolEntryIntoBuffer(serializationArgs, - &remainingParametersSize, false); - if(result != RETURN_OK) { - return result; - } - } - if(remainingParametersSize != 0) { - sif::debug << "PoolRawAccessHelper: " - "Remaining parameters size not 0 !" << std::endl; - result = RETURN_FAILED; - } - return result; -} - -ReturnValue_t PoolRawAccessHelper::serializeWithValidityMask(uint8_t ** buffer, - size_t * size, const size_t max_size, - SerializeIF::Endianness streamEndianness) { - ReturnValue_t result = RETURN_OK; - SerializationArgs argStruct = {buffer, size, max_size, streamEndianness}; - size_t remainingParametersSize = numberOfParameters * 4; - uint8_t validityMaskSize = ceil((float)numberOfParameters/8.0); - uint8_t validityMask[validityMaskSize]; - memset(validityMask,0, validityMaskSize); - for(uint8_t count = 0; count < numberOfParameters; count++) { - result = serializeCurrentPoolEntryIntoBuffer(argStruct, - &remainingParametersSize,true,validityMask); - if (result != RETURN_OK) { - return result; - } - } - if(remainingParametersSize != 0) { - sif::debug << "PoolRawAccessHelper: Remaining " - "parameters size not 0 !" << std::endl; - result = RETURN_FAILED; - } - - memcpy(*argStruct.buffer, validityMask, validityMaskSize); - *size += validityMaskSize; - validBufferIndex = 1; - validBufferIndexBit = 0; - return result; -} - -ReturnValue_t PoolRawAccessHelper::serializeCurrentPoolEntryIntoBuffer( - SerializationArgs argStruct, size_t * remainingParameters, - bool withValidMask, uint8_t * validityMask) { - uint32_t currentPoolId; - // Deserialize current pool ID from pool ID buffer - ReturnValue_t result = SerializeAdapter::deSerialize(¤tPoolId, - &poolIdBuffer,remainingParameters, SerializeIF::Endianness::MACHINE); - if(result != RETURN_OK) { - sif::debug << std::hex << "PoolRawAccessHelper: Error deSeralizing " - "pool IDs" << std::dec << std::endl; - return result; - } - result = handlePoolEntrySerialization(currentPoolId, argStruct, - withValidMask, validityMask); - return result; -} - -ReturnValue_t PoolRawAccessHelper::handlePoolEntrySerialization( - uint32_t currentPoolId,SerializationArgs argStruct, bool withValidMask, - uint8_t * validityMask) { - ReturnValue_t result = RETURN_FAILED; - uint8_t arrayPosition = 0; - uint8_t counter = 0; - bool poolEntrySerialized = false; - //debug << "Pool Raw Access Helper: Handling Pool ID: " - // << std::hex << currentPoolId << std::endl; - while(not poolEntrySerialized) { - - if(counter > GlobDataSet::DATA_SET_MAX_SIZE) { - sif::error << "PoolRawAccessHelper: Config error, " - "max. number of possible data set variables exceeded" - << std::endl; - return result; - } - counter ++; - - GlobDataSet currentDataSet; - //debug << "Current array position: " << (int)arrayPosition << std::endl; - PoolRawAccess currentPoolRawAccess(currentPoolId, arrayPosition, - ¤tDataSet, PoolVariableIF::VAR_READ); - - result = currentDataSet.read(); - if (result != RETURN_OK) { - sif::debug << std::hex << "PoolRawAccessHelper: Error reading raw " - "dataset with returncode 0x" << result << std::dec << std::endl; - return result; - } - - result = checkRemainingSize(¤tPoolRawAccess, &poolEntrySerialized, - &arrayPosition); - if(result != RETURN_OK) { - sif::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); - } - validBufferIndexBit ++; - } - - result = currentDataSet.serialize(argStruct.buffer, argStruct.size, - argStruct.max_size, argStruct.streamEndianness); - if (result != RETURN_OK) { - sif::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 += 1; - } - else { - return RETURN_FAILED; - } - return RETURN_OK; -} - -void PoolRawAccessHelper::handleMaskModification(uint8_t * validityMask) { - validityMask[validBufferIndex] = - bitSetter(validityMask[validBufferIndex], validBufferIndexBit, true); - if(validBufferIndexBit == 8) { - validBufferIndex ++; - validBufferIndexBit = 1; - } -} - -uint8_t PoolRawAccessHelper::bitSetter(uint8_t byte, uint8_t position, - bool value) { - if(position < 1 or position > 8) { - sif::debug << "Pool Raw Access: Bit setting invalid position" << std::endl; - return byte; - } - uint8_t shiftNumber = position + (6 - 2 * (position - 1)); - byte |= 1UL << shiftNumber; - return byte; -} diff --git a/datapool/PoolRawAccessHelper.h b/datapool/PoolRawAccessHelper.h deleted file mode 100644 index 6ff3e955..00000000 --- a/datapool/PoolRawAccessHelper.h +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef FSFW_DATAPOOL_POOLRAWACCESSHELPER_H_ -#define FSFW_DATAPOOL_POOLRAWACCESSHELPER_H_ - -#include "../returnvalues/HasReturnvaluesIF.h" -#include "../datapoolglob/GlobalDataSet.h" -#include "../datapoolglob/PoolRawAccess.h" - -/** - * @brief This helper function simplifies accessing data pool entries - * via PoolRawAccess - * @details Can be used for a Housekeeping Service - * 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: - /** - * 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(uint32_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, size_t * size, - const size_t max_size, SerializeIF::Endianness streamEndianness); - - /** - * 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, size_t * size, - const size_t max_size, SerializeIF::Endianness streamEndianness); - - -private: - // DataSet * dataSet; - const uint8_t * poolIdBuffer; - uint8_t numberOfParameters; - - uint8_t validBufferIndex; - uint8_t validBufferIndexBit; - - struct SerializationArgs { - uint8_t ** buffer; - size_t * size; - const size_t max_size; - SerializeIF::Endianness streamEndianness; - }; - /** - * 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( - SerializationArgs argStruct, size_t * remainingParameters, - bool withValidMask = false, uint8_t * validityMask = nullptr); - - 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); - void handleMaskModification(uint8_t * validityMask); - /** - * 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); -}; - -#endif /* FRAMEWORK_DATAPOOL_POOLRAWACCESSHELPER_H_ */