datapool updates, fixes, pool read helper
This commit is contained in:
@ -44,6 +44,9 @@ public:
|
||||
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::LOCAL_POOL_OWNER_IF;
|
||||
|
||||
static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0x00);
|
||||
static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x01);
|
||||
|
||||
static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID;
|
||||
|
||||
virtual object_id_t getObjectId() const = 0;
|
||||
|
@ -577,7 +577,7 @@ ReturnValue_t LocalDataPoolManager::printPoolEntry(
|
||||
if (poolIter == localPoolMap.end()) {
|
||||
sif::debug << "HousekeepingManager::fechPoolEntry:"
|
||||
<< " Pool entry not found." << std::endl;
|
||||
return POOL_ENTRY_NOT_FOUND;
|
||||
return HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
|
||||
}
|
||||
poolIter->second->print();
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
|
@ -55,14 +55,11 @@ class LocalDataPoolManager {
|
||||
public:
|
||||
static constexpr uint8_t INTERFACE_ID = CLASS_ID::HOUSEKEEPING_MANAGER;
|
||||
|
||||
static constexpr ReturnValue_t POOL_ENTRY_NOT_FOUND = MAKE_RETURN_CODE(0x00);
|
||||
static constexpr ReturnValue_t POOL_ENTRY_TYPE_CONFLICT = MAKE_RETURN_CODE(0x01);
|
||||
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(0x02);
|
||||
|
||||
static constexpr ReturnValue_t WRONG_HK_PACKET_TYPE = MAKE_RETURN_CODE(0x03);
|
||||
static constexpr ReturnValue_t REPORTING_STATUS_UNCHANGED = MAKE_RETURN_CODE(0x04);
|
||||
static constexpr ReturnValue_t PERIODIC_HELPER_INVALID = MAKE_RETURN_CODE(0x05);
|
||||
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);
|
||||
|
||||
/**
|
||||
* This constructor is used by a class which wants to implement
|
||||
@ -380,14 +377,14 @@ ReturnValue_t LocalDataPoolManager::fetchPoolEntry(lp_id_t localPoolId,
|
||||
if (poolIter == localPoolMap.end()) {
|
||||
sif::warning << "HousekeepingManager::fechPoolEntry: Pool entry "
|
||||
"not found." << std::endl;
|
||||
return POOL_ENTRY_NOT_FOUND;
|
||||
return HasLocalDataPoolIF::POOL_ENTRY_NOT_FOUND;
|
||||
}
|
||||
|
||||
*poolEntry = dynamic_cast< PoolEntry<T>* >(poolIter->second);
|
||||
if(*poolEntry == nullptr) {
|
||||
sif::debug << "HousekeepingManager::fetchPoolEntry:"
|
||||
" Pool entry not found." << std::endl;
|
||||
return POOL_ENTRY_TYPE_CONFLICT;
|
||||
return HasLocalDataPoolIF::POOL_ENTRY_TYPE_CONFLICT;
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
|
||||
LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||
uint32_t setId, PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables, bool noPeriodicHandling):
|
||||
const size_t maxNumberOfVariables, bool periodicHandling):
|
||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||
if(hkOwner == nullptr) {
|
||||
// Configuration error.
|
||||
@ -23,7 +23,7 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
|
||||
// Data creators get a periodic helper for periodic HK data generation.
|
||||
if(not noPeriodicHandling) {
|
||||
if(periodicHandling) {
|
||||
periodicHelper = new PeriodicHousekeepingHelper(this);
|
||||
}
|
||||
}
|
||||
@ -34,13 +34,9 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid,
|
||||
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
|
||||
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
|
||||
sid.objectId);
|
||||
if(hkOwner == nullptr) {
|
||||
// Configuration error.
|
||||
sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
|
||||
<< "invalid!" << std::endl;
|
||||
return;
|
||||
if(hkOwner != nullptr) {
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
}
|
||||
hkManager = hkOwner->getHkManagerHandle();
|
||||
this->sid = sid;
|
||||
|
||||
mutex = MutexFactory::instance()->createMutex();
|
||||
@ -50,8 +46,11 @@ LocalPoolDataSetBase::~LocalPoolDataSetBase() {
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::lockDataPool(uint32_t timeoutMs) {
|
||||
MutexIF* mutex = hkManager->getMutexHandle();
|
||||
return mutex->lockMutex(MutexIF::TimeoutType::WAITING, timeoutMs);
|
||||
if(hkManager != nullptr) {
|
||||
MutexIF* mutex = hkManager->getMutexHandle();
|
||||
return mutex->lockMutex(MutexIF::TimeoutType::WAITING, timeoutMs);
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer,
|
||||
@ -127,8 +126,11 @@ ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
|
||||
MutexIF* mutex = hkManager->getMutexHandle();
|
||||
return mutex->unlockMutex();
|
||||
if(hkManager != nullptr) {
|
||||
MutexIF* mutex = hkManager->getMutexHandle();
|
||||
return mutex->unlockMutex();
|
||||
}
|
||||
return HasReturnvaluesIF::RETURN_OK;
|
||||
}
|
||||
|
||||
ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer,
|
||||
@ -276,3 +278,9 @@ void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) {
|
||||
}
|
||||
this->valid = valid;
|
||||
}
|
||||
|
||||
void LocalPoolDataSetBase::setReadCommitProtectionBehaviour(
|
||||
bool protectEveryReadCommit, uint32_t mutexTimeout) {
|
||||
PoolDataSetBase::setReadCommitProtectionBehaviour(protectEveryReadCommit,
|
||||
mutexTimeout);
|
||||
}
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
*/
|
||||
LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
|
||||
uint32_t setId, PoolVariableIF** registeredVariablesArray,
|
||||
const size_t maxNumberOfVariables, bool noPeriodicHandling = false);
|
||||
const size_t maxNumberOfVariables, bool periodicHandling = true);
|
||||
|
||||
/**
|
||||
* @brief Constructor for users of local pool data.
|
||||
@ -77,6 +77,16 @@ public:
|
||||
*/
|
||||
~LocalPoolDataSetBase();
|
||||
|
||||
/**
|
||||
* If the data is pulled from different local data pools, every read and
|
||||
* commit call should be mutex protected for thread safety.
|
||||
* This can be specified with the second parameter.
|
||||
* @param dataCreator
|
||||
* @param protectEveryReadCommit
|
||||
*/
|
||||
void setReadCommitProtectionBehaviour(bool protectEveryReadCommit,
|
||||
uint32_t mutexTimeout = 20);
|
||||
|
||||
void setValidityBufferGeneration(bool withValidityBuffer);
|
||||
|
||||
sid_t getSid() const;
|
||||
@ -128,6 +138,7 @@ public:
|
||||
|
||||
protected:
|
||||
sid_t sid;
|
||||
uint32_t mutexTimeout = 20;
|
||||
MutexIF* mutex = nullptr;
|
||||
|
||||
bool diagnostic = false;
|
||||
@ -181,7 +192,7 @@ protected:
|
||||
*/
|
||||
ReturnValue_t unlockDataPool() override;
|
||||
|
||||
LocalDataPoolManager* hkManager;
|
||||
LocalDataPoolManager* hkManager = nullptr;
|
||||
|
||||
/**
|
||||
* Set n-th bit of a byte, with n being the position from 0
|
||||
|
@ -11,14 +11,14 @@ inline LocalPoolVariable<T>::LocalPoolVariable(HasLocalDataPoolIF* hkOwner,
|
||||
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}
|
||||
|
||||
template<typename T>
|
||||
inline LocalPoolVariable<T>::LocalPoolVariable(object_id_t poolOwner, lp_id_t poolId,
|
||||
DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
|
||||
inline LocalPoolVariable<T>::LocalPoolVariable(object_id_t poolOwner,
|
||||
lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
|
||||
LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {}
|
||||
|
||||
|
||||
template<typename T>
|
||||
inline LocalPoolVariable<T>::LocalPoolVariable(gp_id_t globalPoolId, DataSetIF *dataSet,
|
||||
pool_rwm_t setReadWriteMode):
|
||||
inline LocalPoolVariable<T>::LocalPoolVariable(gp_id_t globalPoolId,
|
||||
DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
|
||||
LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId,
|
||||
dataSet, setReadWriteMode){}
|
||||
|
||||
@ -40,11 +40,11 @@ inline ReturnValue_t LocalPoolVariable<T>::readWithoutLock() {
|
||||
|
||||
PoolEntry<T>* poolEntry = nullptr;
|
||||
ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
|
||||
if(result != RETURN_OK and poolEntry != nullptr) {
|
||||
if(result != RETURN_OK or poolEntry == nullptr) {
|
||||
sif::error << "PoolVector: Read of local pool variable of object "
|
||||
"0x" << std::hex << std::setw(8) << std::setfill('0') <<
|
||||
hkManager->getOwner() << " and lp ID 0x" << localPoolId <<
|
||||
std::dec << " failed.\n" << std::flush;
|
||||
<< std::hex << std::setw(8) << std::setfill('0')
|
||||
<< hkManager->getOwner() << " and lp ID " << localPoolId
|
||||
<< std::dec << " failed." << std::setfill(' ') << std::endl;
|
||||
return result;
|
||||
}
|
||||
this->value = *(poolEntry->address);
|
||||
@ -62,7 +62,7 @@ inline ReturnValue_t LocalPoolVariable<T>::commit(dur_millis_t lockTimeout) {
|
||||
template<typename T>
|
||||
inline ReturnValue_t LocalPoolVariable<T>::commitWithoutLock() {
|
||||
if(readWriteMode == pool_rwm_t::VAR_READ) {
|
||||
sif::debug << "LocalPoolVar: Invalid read write "
|
||||
sif::debug << "LocalPoolVariable: Invalid read write "
|
||||
"mode for commit() call." << std::endl;
|
||||
return PoolVariableIF::INVALID_READ_WRITE_MODE;
|
||||
}
|
||||
|
41
datapoollocal/PoolReadHelper.h
Normal file
41
datapoollocal/PoolReadHelper.h
Normal file
@ -0,0 +1,41 @@
|
||||
#ifndef FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_
|
||||
#define FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_
|
||||
|
||||
#include <fsfw/datapoollocal/LocalPoolDataSetBase.h>
|
||||
#include <FSFWConfig.h>
|
||||
|
||||
/**
|
||||
* @brief Helper class to read data sets or pool variables
|
||||
*/
|
||||
class PoolReadHelper {
|
||||
public:
|
||||
PoolReadHelper(ReadCommitIF* readObject, uint32_t mutexTimeout = 20):
|
||||
readObject(readObject), mutexTimeout(mutexTimeout) {
|
||||
if(readObject != nullptr) {
|
||||
readResult = readObject->read(mutexTimeout);
|
||||
#if FSFW_PRINT_VERBOSITY_LEVEL == 1
|
||||
sif::error << "PoolReadHelper: Read failed!" << std::endl;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
ReturnValue_t getReadResult() const {
|
||||
return readResult;
|
||||
}
|
||||
|
||||
~PoolReadHelper() {
|
||||
if(readObject != nullptr) {
|
||||
readObject->commit(mutexTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private:
|
||||
ReadCommitIF* readObject = nullptr;
|
||||
ReturnValue_t readResult = HasReturnvaluesIF::RETURN_OK;
|
||||
uint32_t mutexTimeout = 20;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif /* FSFW_DATAPOOLLOCAL_POOLREADHELPER_H_ */
|
Reference in New Issue
Block a user