better returnvalues etc.

This commit is contained in:
Robin Müller 2021-01-08 13:40:13 +01:00
parent 3b39c6b6e2
commit 5a8647d367
7 changed files with 74 additions and 43 deletions

View File

@ -1,6 +1,6 @@
#include "PoolEntry.h" #include "PoolEntry.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../serviceinterface/ServiceInterface.h"
#include "../globalfunctions/arrayprinter.h" #include "../globalfunctions/arrayprinter.h"
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
@ -62,14 +62,26 @@ bool PoolEntry<T>::getValid() {
template <typename T> template <typename T>
void PoolEntry<T>::print() { void PoolEntry<T>::print() {
const char* validString = nullptr;
if(valid) {
validString = "Valid";
}
else {
validString = "Invalid";
}
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Pool Entry Validity: " << sif::info << "PoolEntry information." << std::endl;
(this->valid? " (valid) " : " (invalid) ") << std::endl; sif::info << "PoolEntry validity: " << validString << std::endl;
#endif #else
arrayprinter::print(reinterpret_cast<uint8_t*>(address), length); fsfw::printInfo("PoolEntry information.\n");
#if FSFW_CPP_OSTREAM_ENABLED == 1 fsfw::printInfo("PoolEntry validity: %s\n", validString);
sif::debug << std::dec << std::endl;
#endif #endif
arrayprinter::print(reinterpret_cast<uint8_t*>(address), getByteSize());
}
template<typename T>
inline T* PoolEntry<T>::getDataPtr() {
return this->address;
} }
template<typename T> template<typename T>

View File

@ -80,21 +80,16 @@ public:
~PoolEntry(); ~PoolEntry();
/** /**
* @brief This is the address pointing to the allocated memory. * Return typed pointer to start of data.
* @return
*/ */
T* address; T* getDataPtr();
/**
* @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 getSize returns the array size of the entry. * @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(); uint8_t getSize();
/** /**
@ -121,8 +116,22 @@ public:
* information to the screen. It prints all array entries in a row. * information to the screen. It prints all array entries in a row.
*/ */
void print(); void print();
Type getType(); 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_ */ #endif /* FSFW_DATAPOOL_POOLENTRY_H_ */

View File

@ -213,7 +213,7 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(
LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle( LocalPoolObjectBase* poolObj = owner->getPoolObjectHandle(
receiver.dataId.localPoolId); receiver.dataId.localPoolId);
if(poolObj == nullptr) { if(poolObj == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return POOLOBJECT_NOT_FOUND;
} }
if (not poolObj->hasChanged()) { if (not poolObj->hasChanged()) {
@ -249,7 +249,7 @@ ReturnValue_t LocalDataPoolManager::handleNotificationSnapshot(
LocalPoolDataSetBase* dataSet = owner->getDataSetHandle( LocalPoolDataSetBase* dataSet = owner->getDataSetHandle(
receiver.dataId.sid); receiver.dataId.sid);
if(dataSet == nullptr) { if(dataSet == nullptr) {
return HasReturnvaluesIF::RETURN_FAILED; return DATASET_NOT_FOUND;
} }
if(not dataSet->hasChanged()) { if(not dataSet->hasChanged()) {
@ -618,7 +618,7 @@ ReturnValue_t LocalDataPoolManager::generateHousekeepingPacket(sid_t sid,
sif::warning << "HousekeepingManager::generateHousekeepingPacket:" sif::warning << "HousekeepingManager::generateHousekeepingPacket:"
<< " Set ID not found or dataset not assigned!" << std::endl; << " Set ID not found or dataset not assigned!" << std::endl;
#endif #endif
return HasReturnvaluesIF::RETURN_FAILED; return DATASET_NOT_FOUND;
} }
store_address_t storeId; store_address_t storeId;

View File

@ -56,11 +56,13 @@ class LocalDataPoolManager {
public: public:
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER; 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 WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(1);
static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(0x02); static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(2);
static constexpr ReturnValue_t PERIODIC_HELPER_INVALID = MAKE_RETURN_CODE(0x03); 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 * This constructor is used by a class which wants to implement

View File

@ -50,16 +50,16 @@ inline ReturnValue_t LocalPoolVariable<T>::readWithoutLock() {
} }
// Actually this should never happen.. // Actually this should never happen..
if(poolEntry->address == nullptr) { // if(poolEntry->address == nullptr) {
result = PoolVariableIF::INVALID_POOL_ENTRY; // result = PoolVariableIF::INVALID_POOL_ENTRY;
object_id_t ownerObjectId = hkManager->getOwner()->getObjectId(); // object_id_t ownerObjectId = hkManager->getOwner()->getObjectId();
reportReadCommitError("LocalPoolVariable", result, // reportReadCommitError("LocalPoolVariable", result,
false, ownerObjectId, localPoolId); // false, ownerObjectId, localPoolId);
return result; // return result;
} // }
this->value = *(poolEntry->address); this->value = *(poolEntry->getDataPtr());
this->valid = poolEntry->valid; this->valid = poolEntry->getValid();
return RETURN_OK; return RETURN_OK;
} }
@ -96,8 +96,8 @@ inline ReturnValue_t LocalPoolVariable<T>::commitWithoutLock() {
return result; return result;
} }
*(poolEntry->address) = this->value; *(poolEntry->getDataPtr()) = this->value;
poolEntry->valid = this->valid; poolEntry->setValid(this->valid);
return RETURN_OK; return RETURN_OK;
} }

View File

@ -49,8 +49,8 @@ inline ReturnValue_t LocalPoolVector<T, vectorSize>::readWithoutLock() {
localPoolId); localPoolId);
return result; return result;
} }
std::memcpy(this->value, poolEntry->address, poolEntry->getByteSize()); std::memcpy(this->value, poolEntry->getDataPtr(), poolEntry->getByteSize());
this->valid = poolEntry->valid; this->valid = poolEntry->getValid();
return RETURN_OK; return RETURN_OK;
} }
@ -85,8 +85,8 @@ inline ReturnValue_t LocalPoolVector<T, vectorSize>::commitWithoutLock() {
localPoolId); localPoolId);
return result; return result;
} }
std::memcpy(poolEntry->address, this->value, poolEntry->getByteSize()); std::memcpy(poolEntry->getDataPtr(), this->value, poolEntry->getByteSize());
poolEntry->valid = this->valid; poolEntry->setValid(this->valid);
return RETURN_OK; return RETURN_OK;
} }

View File

@ -1,5 +1,5 @@
#include "arrayprinter.h" #include "arrayprinter.h"
#include "../serviceinterface/ServiceInterfaceStream.h" #include "../serviceinterface/ServiceInterface.h"
#include <bitset> #include <bitset>
void arrayprinter::print(const uint8_t *data, size_t size, OutputType type, 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 << "Printing data with size " << size << ": ";
} }
sif::info << "["; sif::info << "[";
#else
fsfw::printInfo("Printing data with size %zu: [", size);
#endif #endif
if(type == OutputType::HEX) { if(type == OutputType::HEX) {
arrayprinter::printHex(data, size, maxCharPerLine); 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::dec;
sif::info << "]" << std::endl; sif::info << "]" << std::endl;
#else
// how much memory to reserve for printout?
#endif #endif
} }
@ -54,6 +58,8 @@ void arrayprinter::printDec(const uint8_t *data, size_t size,
} }
} }
sif::info << "]" << std::endl; sif::info << "]" << std::endl;
#else
// how much memory to reserve for printout?
#endif #endif
} }
@ -65,5 +71,7 @@ void arrayprinter::printBin(const uint8_t *data, size_t size) {
std::bitset<8>(data[i]) << ",\n" << std::flush; std::bitset<8>(data[i]) << ",\n" << std::flush;
} }
sif::info << "]" << std::endl; sif::info << "]" << std::endl;
#else
// how much memory to reserve for printout?
#endif #endif
} }