From 1f1831c4a14ddf806a6a360e1f60b1c46e90d968 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 Dec 2019 22:15:39 +0100 Subject: [PATCH] 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 24bcc1d4..5a43e43c 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 bb19a3ce..36f42f83 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); };