116 lines
4.1 KiB
C++
116 lines
4.1 KiB
C++
#include "fsfw/datapool/LocalPoolObjectBase.h"
|
|
|
|
#include "fsfw/housekeeping/PeriodicHkHelper.h"
|
|
#include "fsfw/objectmanager/ObjectManager.h"
|
|
|
|
using namespace dp;
|
|
PoolObjectBase::PoolObjectBase(SharedPool& sharedPool, dp::id_t poolId, DataSetIF* dataSet,
|
|
pool_rwm_t setReadWriteMode)
|
|
: localPoolId(poolId), readWriteMode(setReadWriteMode), sharedPool(&sharedPool) {
|
|
if (poolId == PoolVariableIF::NO_PARAMETER) {
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
|
<< "which is the NO_PARAMETER value!" << std::endl;
|
|
#endif
|
|
}
|
|
|
|
if (dataSet != nullptr) {
|
|
dataSet->registerVariable(this);
|
|
}
|
|
}
|
|
|
|
PoolObjectBase::PoolObjectBase(object_id_t poolOwner, id_t poolId, DataSetIF* dataSet,
|
|
pool_rwm_t setReadWriteMode)
|
|
: localPoolId(poolId), readWriteMode(setReadWriteMode) {
|
|
if (poolId == PoolVariableIF::NO_PARAMETER) {
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
|
"which is the NO_PARAMETER value!"
|
|
<< std::endl;
|
|
#else
|
|
sif::printWarning(
|
|
"LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
|
|
"which is the NO_PARAMETER value!\n");
|
|
#endif
|
|
}
|
|
auto* hkOwner = ObjectManager::instance()->get<hk::GeneratesPeriodicHkIF>(poolOwner);
|
|
if (hkOwner == nullptr) {
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
sif::error << "LocalPoolVariable: The supplied pool owner 0x" << std::hex << poolOwner
|
|
<< std::dec << " does not exist or does not implement the correct interface "
|
|
<< "HasLocalDataPoolIF" << std::endl;
|
|
#else
|
|
sif::printError(
|
|
"LocalPoolVariable: The supplied pool owner 0x%08x does not exist or does not implement "
|
|
"the correct interface HasLocalDataPoolIF\n",
|
|
poolOwner);
|
|
#endif
|
|
return;
|
|
}
|
|
sharedPool = hkOwner->getOptionalSharedPool();
|
|
if (sharedPool == nullptr) {
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
sif::error << "PoolObjectBase: HK owner 0x" << std::hex << poolOwner << std::dec
|
|
<< "does not have a shared pool " << std::endl;
|
|
#else
|
|
sif::printError("PoolObjectBase: HK owner 0x%08x does not have a shared pool\n", poolOwner);
|
|
#endif
|
|
}
|
|
|
|
if (dataSet != nullptr) {
|
|
dataSet->registerVariable(this);
|
|
}
|
|
}
|
|
|
|
pool_rwm_t PoolObjectBase ::getReadWriteMode() const { return readWriteMode; }
|
|
|
|
id_t PoolObjectBase ::getDataPoolId() const { return localPoolId; }
|
|
|
|
void PoolObjectBase::setDataPoolId(id_t poolId) { this->localPoolId = poolId; }
|
|
|
|
void PoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) {
|
|
this->readWriteMode = newReadWriteMode;
|
|
}
|
|
|
|
[[nodiscard]] bool PoolObjectBase::isValid() const { return valid; }
|
|
|
|
void PoolObjectBase::setValid(bool valid) { this->valid = valid; }
|
|
|
|
void PoolObjectBase::reportReadCommitError(const char* variableType, ReturnValue_t error, bool read,
|
|
object_id_t objectId, id_t lpId) {
|
|
#if FSFW_DISABLE_PRINTOUT == 0
|
|
const char* variablePrintout = variableType;
|
|
if (variablePrintout == nullptr) {
|
|
variablePrintout = "Unknown Type";
|
|
}
|
|
const char* type = nullptr;
|
|
if (read) {
|
|
type = "read";
|
|
} else {
|
|
type = "commit";
|
|
}
|
|
|
|
const char* errMsg = nullptr;
|
|
if (error == POOL_ENTRY_NOT_FOUND) {
|
|
errMsg = "Pool entry not found";
|
|
} else if (error == POOL_ENTRY_TYPE_CONFLICT) {
|
|
errMsg = "Pool entry type conflict";
|
|
} else if (error == PoolVariableIF::INVALID_READ_WRITE_MODE) {
|
|
errMsg = "Pool variable wrong read-write mode";
|
|
} else if (error == PoolVariableIF::INVALID_POOL_ENTRY) {
|
|
errMsg = "Pool entry invalid";
|
|
} else {
|
|
errMsg = "Unknown error code";
|
|
}
|
|
|
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
|
sif::warning << variablePrintout << ": " << type << " call | " << errMsg << " | Owner: 0x"
|
|
<< std::hex << std::setw(8) << std::setfill('0') << objectId << std::dec
|
|
<< " LPID: " << lpId << std::endl;
|
|
#else
|
|
sif::printWarning("%s: %s call | %s | Owner: 0x%08x LPID: %lu\n", variablePrintout, type, errMsg,
|
|
objectId, lpId);
|
|
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
|
|
#endif /* FSFW_DISABLE_PRINTOUT == 0 */
|
|
}
|