From f6b9b232877d29d6a68640967f131d6091c7f2de Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Tue, 24 Dec 2019 01:41:04 +0100 Subject: [PATCH] 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 00000000..24bcc1d4 --- /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 00000000..bb19a3ce --- /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_ */