From c3bca518e707f8dd563f39b9e873b949d58f6961 Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Wed, 13 Jan 2021 12:12:08 +0100 Subject: [PATCH] bugfixes and auto indentation --- datapoollocal/LocalPoolDataSetBase.cpp | 369 +++++++++++++------------ 1 file changed, 186 insertions(+), 183 deletions(-) diff --git a/datapoollocal/LocalPoolDataSetBase.cpp b/datapoollocal/LocalPoolDataSetBase.cpp index 5343a9c9..f3cd7106 100644 --- a/datapoollocal/LocalPoolDataSetBase.cpp +++ b/datapoollocal/LocalPoolDataSetBase.cpp @@ -11,47 +11,50 @@ #include LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, - uint32_t setId, PoolVariableIF** registeredVariablesArray, - const size_t maxNumberOfVariables, bool periodicHandling): - PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { - if(hkOwner == nullptr) { - // Configuration error. + uint32_t setId, PoolVariableIF** registeredVariablesArray, + const size_t maxNumberOfVariables, bool periodicHandling): + PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { + if(hkOwner == nullptr) { + // Configuration error. #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " - << "invalid!" << std::endl; + sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " + << "invalid!" << std::endl; #else - sif::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " - "invalid!\n\r"); + sif::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " + "invalid!\n\r"); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - return; - } - AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); + return; + } + AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); - if(poolManager != nullptr) { - poolManager = accessor->getHkManagerHandle(); - mutexIfSingleDataCreator = accessor->getLocalPoolMutex(); - } + if(accessor != nullptr) { + poolManager = accessor->getHkManagerHandle(); + mutexIfSingleDataCreator = accessor->getLocalPoolMutex(); + } - this->sid.objectId = hkOwner->getObjectId(); - this->sid.ownerSetId = setId; + this->sid.objectId = hkOwner->getObjectId(); + this->sid.ownerSetId = setId; - // Data creators get a periodic helper for periodic HK data generation. - if(periodicHandling) { - periodicHelper = new PeriodicHousekeepingHelper(this); - } + // Data creators get a periodic helper for periodic HK data generation. + if(periodicHandling) { + periodicHelper = new PeriodicHousekeepingHelper(this); + } } LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, - PoolVariableIF** registeredVariablesArray, - const size_t maxNumberOfVariables): + PoolVariableIF** registeredVariablesArray, + const size_t maxNumberOfVariables): PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { - AccessPoolManagerIF* hkOwner = objectManager->get( - sid.objectId); - if(hkOwner != nullptr) { - mutexIfSingleDataCreator = hkOwner->getLocalPoolMutex(); - } + HasLocalDataPoolIF* hkOwner = objectManager->get( + sid.objectId); + if(hkOwner != nullptr) { + AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); + if(accessor != nullptr) { + mutexIfSingleDataCreator = accessor->getLocalPoolMutex(); + } + } - this->sid = sid; + this->sid = sid; } LocalPoolDataSetBase::LocalPoolDataSetBase( @@ -72,240 +75,240 @@ ReturnValue_t LocalPoolDataSetBase::lockDataPool( MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { if(mutexIfSingleDataCreator != nullptr) { - return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs); + return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs); } return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer, - size_t *size, size_t maxSize, - SerializeIF::Endianness streamEndianness) const { - ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; - uint8_t validityMaskSize = std::ceil(static_cast(fillCount)/8.0); - uint8_t validityMask[validityMaskSize]; - uint8_t validBufferIndex = 0; - uint8_t validBufferIndexBit = 0; - for (uint16_t count = 0; count < fillCount; count++) { - if(registeredVariables[count]->isValid()) { - // set validity buffer here. - this->bitSetter(validityMask + validBufferIndex, - validBufferIndexBit); - if(validBufferIndexBit == 7) { - validBufferIndex ++; - validBufferIndexBit = 0; - } - else { - validBufferIndexBit ++; - } - } - result = registeredVariables[count]->serialize(buffer, size, maxSize, - streamEndianness); - if (result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - } + size_t *size, size_t maxSize, + SerializeIF::Endianness streamEndianness) const { + ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; + uint8_t validityMaskSize = std::ceil(static_cast(fillCount)/8.0); + uint8_t validityMask[validityMaskSize]; + uint8_t validBufferIndex = 0; + uint8_t validBufferIndexBit = 0; + for (uint16_t count = 0; count < fillCount; count++) { + if(registeredVariables[count]->isValid()) { + // set validity buffer here. + this->bitSetter(validityMask + validBufferIndex, + validBufferIndexBit); + if(validBufferIndexBit == 7) { + validBufferIndex ++; + validBufferIndexBit = 0; + } + else { + validBufferIndexBit ++; + } + } + result = registeredVariables[count]->serialize(buffer, size, maxSize, + streamEndianness); + if (result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } - if(*size + validityMaskSize > maxSize) { - return SerializeIF::BUFFER_TOO_SHORT; - } - // copy validity buffer to end - std::memcpy(*buffer, validityMask, validityMaskSize); - *size += validityMaskSize; - return result; + if(*size + validityMaskSize > maxSize) { + return SerializeIF::BUFFER_TOO_SHORT; + } + // copy validity buffer to end + std::memcpy(*buffer, validityMask, validityMaskSize); + *size += validityMaskSize; + return result; } ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer( - const uint8_t **buffer, size_t *size, - SerializeIF::Endianness streamEndianness) { - ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; - for (uint16_t count = 0; count < fillCount; count++) { - result = registeredVariables[count]->deSerialize(buffer, size, - streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK) { - return result; - } - } + const uint8_t **buffer, size_t *size, + SerializeIF::Endianness streamEndianness) { + ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; + for (uint16_t count = 0; count < fillCount; count++) { + result = registeredVariables[count]->deSerialize(buffer, size, + streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK) { + return result; + } + } - if(*size < std::ceil(static_cast(fillCount) / 8.0)) { - return SerializeIF::STREAM_TOO_SHORT; - } + if(*size < std::ceil(static_cast(fillCount) / 8.0)) { + return SerializeIF::STREAM_TOO_SHORT; + } - uint8_t validBufferIndex = 0; - uint8_t validBufferIndexBit = 0; - for (uint16_t count = 0; count < fillCount; count++) { - // set validity buffer here. - bool nextVarValid = this->bitGetter(*buffer + - validBufferIndex, validBufferIndexBit); - registeredVariables[count]->setValid(nextVarValid); + uint8_t validBufferIndex = 0; + uint8_t validBufferIndexBit = 0; + for (uint16_t count = 0; count < fillCount; count++) { + // set validity buffer here. + bool nextVarValid = this->bitGetter(*buffer + + validBufferIndex, validBufferIndexBit); + registeredVariables[count]->setValid(nextVarValid); - if(validBufferIndexBit == 7) { - validBufferIndex ++; - validBufferIndexBit = 0; - } - else { - validBufferIndexBit ++; - } - } - return result; + if(validBufferIndexBit == 7) { + validBufferIndex ++; + validBufferIndexBit = 0; + } + else { + validBufferIndexBit ++; + } + } + return result; } ReturnValue_t LocalPoolDataSetBase::unlockDataPool() { if(mutexIfSingleDataCreator != nullptr) { - return mutexIfSingleDataCreator->unlockMutex(); + return mutexIfSingleDataCreator->unlockMutex(); } return HasReturnvaluesIF::RETURN_OK; } ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer, - size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness, - bool serializeFillCount) const { - // Serialize as uint8_t - uint8_t fillCount = this->fillCount; - if(serializeFillCount) { - SerializeAdapter::serialize(&fillCount, buffer, size, maxSize, - streamEndianness); - } - for (uint16_t count = 0; count < fillCount; count++) { - lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId(); - auto result = SerializeAdapter::serialize(¤tPoolId, buffer, - size, maxSize, streamEndianness); - if(result != HasReturnvaluesIF::RETURN_OK) { + size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness, + bool serializeFillCount) const { + // Serialize as uint8_t + uint8_t fillCount = this->fillCount; + if(serializeFillCount) { + SerializeAdapter::serialize(&fillCount, buffer, size, maxSize, + streamEndianness); + } + for (uint16_t count = 0; count < fillCount; count++) { + lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId(); + auto result = SerializeAdapter::serialize(¤tPoolId, buffer, + size, maxSize, streamEndianness); + if(result != HasReturnvaluesIF::RETURN_OK) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "LocalPoolDataSetBase::serializeLocalPoolIds: " - << "Serialization error!" << std::endl; + sif::warning << "LocalPoolDataSetBase::serializeLocalPoolIds: " + << "Serialization error!" << std::endl; #else - sif::printWarning("LocalPoolDataSetBase::serializeLocalPoolIds: " - "Serialization error!\n\r"); + sif::printWarning("LocalPoolDataSetBase::serializeLocalPoolIds: " + "Serialization error!\n\r"); #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ - return result; - } - } - return HasReturnvaluesIF::RETURN_OK; + return result; + } + } + return HasReturnvaluesIF::RETURN_OK; } uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize( - bool serializeFillCount) const { - if(serializeFillCount) { - return fillCount * sizeof(lp_id_t) + sizeof(uint8_t); - } - else { - return fillCount * sizeof(lp_id_t); - } + bool serializeFillCount) const { + if(serializeFillCount) { + return fillCount * sizeof(lp_id_t) + sizeof(uint8_t); + } + else { + return fillCount * sizeof(lp_id_t); + } } size_t LocalPoolDataSetBase::getSerializedSize() const { - if(withValidityBuffer) { - uint8_t validityMaskSize = std::ceil(static_cast(fillCount)/8.0); - return validityMaskSize + PoolDataSetBase::getSerializedSize(); - } - else { - return PoolDataSetBase::getSerializedSize(); - } + if(withValidityBuffer) { + uint8_t validityMaskSize = std::ceil(static_cast(fillCount)/8.0); + return validityMaskSize + PoolDataSetBase::getSerializedSize(); + } + else { + return PoolDataSetBase::getSerializedSize(); + } } void LocalPoolDataSetBase::setValidityBufferGeneration( - bool withValidityBuffer) { - this->withValidityBuffer = withValidityBuffer; + bool withValidityBuffer) { + this->withValidityBuffer = withValidityBuffer; } ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer, - size_t *size, SerializeIF::Endianness streamEndianness) { - if(withValidityBuffer) { - return this->deSerializeWithValidityBuffer(buffer, size, - streamEndianness); - } - else { - return PoolDataSetBase::deSerialize(buffer, size, streamEndianness); - } + size_t *size, SerializeIF::Endianness streamEndianness) { + if(withValidityBuffer) { + return this->deSerializeWithValidityBuffer(buffer, size, + streamEndianness); + } + else { + return PoolDataSetBase::deSerialize(buffer, size, streamEndianness); + } } ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size, - size_t maxSize, SerializeIF::Endianness streamEndianness) const { - if(withValidityBuffer) { - return this->serializeWithValidityBuffer(buffer, size, - maxSize, streamEndianness); - } - else { - return PoolDataSetBase::serialize(buffer, size, maxSize, - streamEndianness); - } + size_t maxSize, SerializeIF::Endianness streamEndianness) const { + if(withValidityBuffer) { + return this->serializeWithValidityBuffer(buffer, size, + maxSize, streamEndianness); + } + else { + return PoolDataSetBase::serialize(buffer, size, maxSize, + streamEndianness); + } } void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const { - if(position > 7) { + if(position > 7) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::warning << "LocalPoolDataSetBase::bitSetter: Invalid position!" - << std::endl; + sif::warning << "LocalPoolDataSetBase::bitSetter: Invalid position!" + << std::endl; #else - sif::printWarning("LocalPoolDataSetBase::bitSetter: " - "Invalid position!\n\r"); + sif::printWarning("LocalPoolDataSetBase::bitSetter: " + "Invalid position!\n\r"); #endif - return; - } - uint8_t shiftNumber = position + (7 - 2 * position); - *byte |= 1 << shiftNumber; + return; + } + uint8_t shiftNumber = position + (7 - 2 * position); + *byte |= 1 << shiftNumber; } void LocalPoolDataSetBase::setDiagnostic(bool isDiagnostics) { - this->diagnostic = isDiagnostics; + this->diagnostic = isDiagnostics; } bool LocalPoolDataSetBase::isDiagnostics() const { - return diagnostic; + return diagnostic; } void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) { - this->reportingEnabled = reportingEnabled; + this->reportingEnabled = reportingEnabled; } bool LocalPoolDataSetBase::getReportingEnabled() const { - return reportingEnabled; + return reportingEnabled; } void LocalPoolDataSetBase::initializePeriodicHelper( - float collectionInterval, dur_millis_t minimumPeriodicInterval, - bool isDiagnostics, uint8_t nonDiagIntervalFactor) { - periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, - isDiagnostics, nonDiagIntervalFactor); + float collectionInterval, dur_millis_t minimumPeriodicInterval, + bool isDiagnostics, uint8_t nonDiagIntervalFactor) { + periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, + isDiagnostics, nonDiagIntervalFactor); } void LocalPoolDataSetBase::setChanged(bool changed) { - this->changed = changed; + this->changed = changed; } bool LocalPoolDataSetBase::hasChanged() const { - return changed; + return changed; } sid_t LocalPoolDataSetBase::getSid() const { - return sid; + return sid; } bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte, - uint8_t position) const { - if(position > 7) { + uint8_t position) const { + if(position > 7) { #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Pool Raw Access: Bit setting invalid position" - << std::endl; + sif::debug << "Pool Raw Access: Bit setting invalid position" + << std::endl; #endif - return false; - } - uint8_t shiftNumber = position + (7 - 2 * position); - return *byte & (1 << shiftNumber); + return false; + } + uint8_t shiftNumber = position + (7 - 2 * position); + return *byte & (1 << shiftNumber); } bool LocalPoolDataSetBase::isValid() const { - return this->valid; + return this->valid; } void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) { - if(setEntriesRecursively) { - for(size_t idx = 0; idx < this->getFillCount(); idx++) { - registeredVariables[idx] -> setValid(valid); - } - } - this->valid = valid; + if(setEntriesRecursively) { + for(size_t idx = 0; idx < this->getFillCount(); idx++) { + registeredVariables[idx] -> setValid(valid); + } + } + this->valid = valid; } object_id_t LocalPoolDataSetBase::getCreatorObjectId() {