From 5a8647d36701b9eda4d6b6a29f2d83dd9b5eeeab Mon Sep 17 00:00:00 2001 From: Robin Mueller Date: Fri, 8 Jan 2021 13:40:13 +0100 Subject: [PATCH] better returnvalues etc. --- datapool/PoolEntry.cpp | 26 +++++++++++++------ datapool/PoolEntry.h | 35 ++++++++++++++++---------- datapoollocal/LocalDataPoolManager.cpp | 6 ++--- datapoollocal/LocalDataPoolManager.h | 10 +++++--- datapoollocal/LocalPoolVariable.tpp | 22 ++++++++-------- datapoollocal/LocalPoolVector.tpp | 8 +++--- globalfunctions/arrayprinter.cpp | 10 +++++++- 7 files changed, 74 insertions(+), 43 deletions(-) diff --git a/datapool/PoolEntry.cpp b/datapool/PoolEntry.cpp index d21cf2ec..1e99a28c 100644 --- a/datapool/PoolEntry.cpp +++ b/datapool/PoolEntry.cpp @@ -1,6 +1,6 @@ #include "PoolEntry.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "../serviceinterface/ServiceInterface.h" #include "../globalfunctions/arrayprinter.h" #include #include @@ -62,14 +62,26 @@ bool PoolEntry::getValid() { template void PoolEntry::print() { + const char* validString = nullptr; + if(valid) { + validString = "Valid"; + } + else { + validString = "Invalid"; + } #if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << "Pool Entry Validity: " << - (this->valid? " (valid) " : " (invalid) ") << std::endl; -#endif - arrayprinter::print(reinterpret_cast(address), length); -#if FSFW_CPP_OSTREAM_ENABLED == 1 - sif::debug << std::dec << std::endl; + sif::info << "PoolEntry information." << std::endl; + sif::info << "PoolEntry validity: " << validString << std::endl; +#else + fsfw::printInfo("PoolEntry information.\n"); + fsfw::printInfo("PoolEntry validity: %s\n", validString); #endif + arrayprinter::print(reinterpret_cast(address), getByteSize()); +} + +template +inline T* PoolEntry::getDataPtr() { + return this->address; } template diff --git a/datapool/PoolEntry.h b/datapool/PoolEntry.h index aecfce94..30940320 100644 --- a/datapool/PoolEntry.h +++ b/datapool/PoolEntry.h @@ -80,21 +80,16 @@ public: ~PoolEntry(); /** - * @brief This is the address pointing to the allocated memory. + * Return typed pointer to start of data. + * @return */ - T* address; - /** - * @brief This attribute stores the length information. - */ - uint8_t length; - /** - * @brief Here, the validity information for a variable is stored. - * Every entry (single variable or vector) has one valid flag. - */ - uint8_t valid; + T* getDataPtr(); + /** * @brief getSize returns the array size of the entry. - * @details A single parameter has size 1. + * @details + * For non-array pool entries return type size, for vector entries + * return type size times the number of entries. */ uint8_t getSize(); /** @@ -121,8 +116,22 @@ public: * information to the screen. It prints all array entries in a row. */ void print(); - Type getType(); + +private: + /** + * @brief This attribute stores the length information. + */ + uint8_t length; + /** + * @brief Here, the validity information for a variable is stored. + * Every entry (single variable or vector) has one valid flag. + */ + uint8_t valid; + /** + * @brief This is the address pointing to the allocated memory. + */ + T* address; }; #endif /* FSFW_DATAPOOL_POOLENTRY_H_ */ diff --git a/datapoollocal/LocalDataPoolManager.cpp b/datapoollocal/LocalDataPoolManager.cpp index 24516aad..db5cd5dd 100644 --- a/datapoollocal/LocalDataPoolManager.cpp +++ b/datapoollocal/LocalDataPoolManager.cpp @@ -213,7 +213,7 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( receiver.dataId.localPoolId); if(poolObj == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return POOLOBJECT_NOT_FOUND; } if (not poolObj->hasChanged()) { @@ -249,7 +249,7 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot( LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( receiver.dataId.sid); if(dataSet == nullptr) { - return HasReturnvaluesIF::RETURN_FAILED; + return DATASET_NOT_FOUND; } if(not dataSet->hasChanged()) { @@ -618,7 +618,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid, sif::warning << "HousekeepingManager::generateHousekeepingPacket:" << " Set ID not found or dataset not assigned!" << std::endl; #endif - return HasReturnvaluesIF::RETURN_FAILED; + return DATASET_NOT_FOUND; } store_address_t storeId; diff --git a/datapoollocal/LocalDataPoolManager.h b/datapoollocal/LocalDataPoolManager.h index 7fa480cb..098158da 100644 --- a/datapoollocal/LocalDataPoolManager.h +++ b/datapoollocal/LocalDataPoolManager.h @@ -56,11 +56,13 @@ class LocalDataPoolManager { public: static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER; - static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0x0); + static constexpr ReturnValue_t QUEUE_OR_DESTINATION_NOT_SET = MAKE_RETURN_CODE(0); - static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(0x01); - static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(0x02); - static constexpr ReturnValue_t PERIODIC_HELPER_INVALID = MAKE_RETURN_CODE(0x03); + static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(1); + static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(2); + static constexpr ReturnValue_t PERIODIC_HELPER_INVALID = MAKE_RETURN_CODE(3); + static constexpr ReturnValue_t POOLOBJECT_NOT_FOUND = MAKE_RETURN_CODE(4); + static constexpr ReturnValue_t DATASET_NOT_FOUND = MAKE_RETURN_CODE(5); /** * This constructor is used by a class which wants to implement diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index d9d45d38..ef94b620 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -50,16 +50,16 @@ inline ReturnValue_t LocalPoolVariable::readWithoutLock() { } // Actually this should never happen.. - if(poolEntry->address == nullptr) { - result = PoolVariableIF::INVALID_POOL_ENTRY; - object_id_t ownerObjectId = hkManager->getOwner()->getObjectId(); - reportReadCommitError("LocalPoolVariable", result, - false, ownerObjectId, localPoolId); - return result; - } +// if(poolEntry->address == nullptr) { +// result = PoolVariableIF::INVALID_POOL_ENTRY; +// object_id_t ownerObjectId = hkManager->getOwner()->getObjectId(); +// reportReadCommitError("LocalPoolVariable", result, +// false, ownerObjectId, localPoolId); +// return result; +// } - this->value = *(poolEntry->address); - this->valid = poolEntry->valid; + this->value = *(poolEntry->getDataPtr()); + this->valid = poolEntry->getValid(); return RETURN_OK; } @@ -96,8 +96,8 @@ inline ReturnValue_t LocalPoolVariable::commitWithoutLock() { return result; } - *(poolEntry->address) = this->value; - poolEntry->valid = this->valid; + *(poolEntry->getDataPtr()) = this->value; + poolEntry->setValid(this->valid); return RETURN_OK; } diff --git a/datapoollocal/LocalPoolVector.tpp b/datapoollocal/LocalPoolVector.tpp index 94f3916e..a0e32f62 100644 --- a/datapoollocal/LocalPoolVector.tpp +++ b/datapoollocal/LocalPoolVector.tpp @@ -49,8 +49,8 @@ inline ReturnValue_t LocalPoolVector::readWithoutLock() { localPoolId); return result; } - std::memcpy(this->value, poolEntry->address, poolEntry->getByteSize()); - this->valid = poolEntry->valid; + std::memcpy(this->value, poolEntry->getDataPtr(), poolEntry->getByteSize()); + this->valid = poolEntry->getValid(); return RETURN_OK; } @@ -85,8 +85,8 @@ inline ReturnValue_t LocalPoolVector::commitWithoutLock() { localPoolId); return result; } - std::memcpy(poolEntry->address, this->value, poolEntry->getByteSize()); - poolEntry->valid = this->valid; + std::memcpy(poolEntry->getDataPtr(), this->value, poolEntry->getByteSize()); + poolEntry->setValid(this->valid); return RETURN_OK; } diff --git a/globalfunctions/arrayprinter.cpp b/globalfunctions/arrayprinter.cpp index c273b250..ebf21bb8 100644 --- a/globalfunctions/arrayprinter.cpp +++ b/globalfunctions/arrayprinter.cpp @@ -1,5 +1,5 @@ #include "arrayprinter.h" -#include "../serviceinterface/ServiceInterfaceStream.h" +#include "../serviceinterface/ServiceInterface.h" #include void arrayprinter::print(const uint8_t *data, size_t size, OutputType type, @@ -9,6 +9,8 @@ void arrayprinter::print(const uint8_t *data, size_t size, OutputType type, sif::info << "Printing data with size " << size << ": "; } sif::info << "["; +#else + fsfw::printInfo("Printing data with size %zu: [", size); #endif if(type == OutputType::HEX) { arrayprinter::printHex(data, size, maxCharPerLine); @@ -37,6 +39,8 @@ void arrayprinter::printHex(const uint8_t *data, size_t size, } sif::info << std::dec; sif::info << "]" << std::endl; +#else + // how much memory to reserve for printout? #endif } @@ -54,6 +58,8 @@ void arrayprinter::printDec(const uint8_t *data, size_t size, } } sif::info << "]" << std::endl; +#else + // how much memory to reserve for printout? #endif } @@ -65,5 +71,7 @@ void arrayprinter::printBin(const uint8_t *data, size_t size) { std::bitset<8>(data[i]) << ",\n" << std::flush; } sif::info << "]" << std::endl; +#else + // how much memory to reserve for printout? #endif }