consistency changes

This commit is contained in:
Robin Müller 2021-01-13 12:41:24 +01:00
parent fdef8bc22b
commit a4e0f15dac
17 changed files with 1099 additions and 1094 deletions

View File

@ -9,16 +9,16 @@ class MutexIF;
*/ */
class AccessPoolManagerIF { class AccessPoolManagerIF {
public: public:
virtual ~AccessPoolManagerIF() {}; virtual ~AccessPoolManagerIF() {};
virtual MutexIF* getLocalPoolMutex() = 0; virtual MutexIF* getLocalPoolMutex() = 0;
/** /**
* Can be used to get a handle to the local data pool manager. * Can be used to get a handle to the local data pool manager.
* This function is protected because it should only be used by the * This function is protected because it should only be used by the
* class imlementing the interface. * class imlementing the interface.
*/ */
virtual LocalDataPoolManager* getHkManagerHandle() = 0; virtual LocalDataPoolManager* getHkManagerHandle() = 0;
protected: protected:

View File

@ -30,32 +30,32 @@ class LocalDataPoolManager;
* *
*/ */
class HasLocalDataPoolIF { class HasLocalDataPoolIF {
friend class HasLocalDpIFManagerAttorney; friend class HasLocalDpIFManagerAttorney;
friend class HasLocalDpIFUserAttorney; friend class HasLocalDpIFUserAttorney;
public: public:
virtual~ HasLocalDataPoolIF() {}; virtual~ HasLocalDataPoolIF() {};
static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID; static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID;
virtual object_id_t getObjectId() const = 0; virtual object_id_t getObjectId() const = 0;
/** Command queue for housekeeping messages. */ /** Command queue for housekeeping messages. */
virtual MessageQueueId_t getCommandQueue() const = 0; virtual MessageQueueId_t getCommandQueue() const = 0;
/** /**
* Is used by pool owner to initialize the pool map once * Is used by pool owner to initialize the pool map once
* The manager instance shall also be passed to this function. * The manager instance shall also be passed to this function.
* It can be used to subscribe for periodic packets for for updates. * It can be used to subscribe for periodic packets for for updates.
*/ */
virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap, virtual ReturnValue_t initializeLocalDataPool(localpool::DataPool& localDataPoolMap,
LocalDataPoolManager& poolManager) = 0; LocalDataPoolManager& poolManager) = 0;
/** /**
* Returns the minimum sampling frequency in milliseconds, which will * Returns the minimum sampling frequency in milliseconds, which will
* usually be the period the pool owner performs its periodic operation. * usually be the period the pool owner performs its periodic operation.
* @return * @return
*/ */
virtual uint32_t getPeriodicOperationFrequency() const = 0; virtual uint32_t getPeriodicOperationFrequency() const = 0;
/** /**
* @brief This function will be called by the manager if an update * @brief This function will be called by the manager if an update
@ -67,7 +67,7 @@ public:
* the IPC store with this store ID. * the IPC store with this store ID.
*/ */
virtual void handleChangedDataset(sid_t sid, virtual void handleChangedDataset(sid_t sid,
store_address_t storeId = storeId::INVALID_STORE_ADDRESS) { store_address_t storeId = storeId::INVALID_STORE_ADDRESS) {
return; return;
} }
@ -85,68 +85,68 @@ public:
return; return;
} }
/** /**
* These function can be implemented by pool owner, if they are required * These function can be implemented by pool owner, if they are required
* and used by the housekeeping message interface. * and used by the housekeeping message interface.
* */ * */
virtual ReturnValue_t addDataSet(sid_t sid) { virtual ReturnValue_t addDataSet(sid_t sid) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
}; };
virtual ReturnValue_t removeDataSet(sid_t sid) { virtual ReturnValue_t removeDataSet(sid_t sid) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
}; };
virtual ReturnValue_t changeCollectionInterval(sid_t sid, float newIntervalSeconds) { virtual ReturnValue_t changeCollectionInterval(sid_t sid, float newIntervalSeconds) {
return HasReturnvaluesIF::RETURN_FAILED; return HasReturnvaluesIF::RETURN_FAILED;
}; };
/** /**
* This function can be used by data pool consumers to retrieve a handle * This function can be used by data pool consumers to retrieve a handle
* which allows subscriptions to dataset and variable updates in form of messages. * which allows subscriptions to dataset and variable updates in form of messages.
* The consumers can then read the most recent variable value by calling read with * The consumers can then read the most recent variable value by calling read with
* an own pool variable or set instance or using the deserialized snapshot data. * an own pool variable or set instance or using the deserialized snapshot data.
* @return * @return
*/ */
virtual ProvidesDataPoolSubscriptionIF* getSubscriptionInterface() = 0; virtual ProvidesDataPoolSubscriptionIF* getSubscriptionInterface() = 0;
protected: protected:
/** /**
* Accessor handle required for internal handling. Not intended for users and therefore * Accessor handle required for internal handling. Not intended for users and therefore
* declared protected. Users should instead use pool variables, sets or the subscription * declared protected. Users should instead use pool variables, sets or the subscription
* interface to access pool entries. * interface to access pool entries.
* @return * @return
*/ */
virtual AccessPoolManagerIF* getAccessorHandle() = 0; virtual AccessPoolManagerIF* getAccessorHandle() = 0;
/** /**
* This function is used by the pool manager to get a valid dataset * This function is used by the pool manager to get a valid dataset
* from a SID. This function is protected to prevent users from * from a SID. This function is protected to prevent users from
* using raw data set pointers which could not be thread-safe. Users * using raw data set pointers which could not be thread-safe. Users
* should use the #ProvidesDataPoolSubscriptionIF. * should use the #ProvidesDataPoolSubscriptionIF.
* @param sid Corresponding structure ID * @param sid Corresponding structure ID
* @return * @return
*/ */
virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) = 0; virtual LocalPoolDataSetBase* getDataSetHandle(sid_t sid) = 0;
/** /**
* Similar to the function above, but used to get a local pool variable * Similar to the function above, but used to get a local pool variable
* handle. This is only needed for update notifications, so it is not * handle. This is only needed for update notifications, so it is not
* defined as abstract. This function is protected to prevent users from * defined as abstract. This function is protected to prevent users from
* using raw pool variable pointers which could not be thread-safe. * using raw pool variable pointers which could not be thread-safe.
* Users should use the #ProvidesDataPoolSubscriptionIF. * Users should use the #ProvidesDataPoolSubscriptionIF.
* @param localPoolId * @param localPoolId
* @return * @return
*/ */
virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) { virtual LocalPoolObjectBase* getPoolObjectHandle(lp_id_t localPoolId) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden" sif::warning << "HasLocalDataPoolIF::getPoolObjectHandle: Not overriden"
<< ". Returning nullptr!" << std::endl; << ". Returning nullptr!" << std::endl;
#else #else
sif::printWarning("HasLocalDataPoolIF::getPoolObjectHandle: " sif::printWarning("HasLocalDataPoolIF::getPoolObjectHandle: "
"Not overriden. Returning nullptr!\n"); "Not overriden. Returning nullptr!\n");
#endif #endif
return nullptr; return nullptr;
} }
}; };
#endif /* FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ */ #endif /* FSFW_DATAPOOLLOCAL_HASLOCALDATAPOOLIF_H_ */

View File

@ -9,13 +9,13 @@ LocalDataSet::LocalDataSet(HasLocalDataPoolIF *hkOwner, uint32_t setId,
const size_t maxNumberOfVariables): const size_t maxNumberOfVariables):
LocalPoolDataSetBase(hkOwner, setId, nullptr, maxNumberOfVariables), LocalPoolDataSetBase(hkOwner, setId, nullptr, maxNumberOfVariables),
poolVarList(maxNumberOfVariables) { poolVarList(maxNumberOfVariables) {
this->setContainer(poolVarList.data()); this->setContainer(poolVarList.data());
} }
LocalDataSet::LocalDataSet(sid_t sid, const size_t maxNumberOfVariables): LocalDataSet::LocalDataSet(sid_t sid, const size_t maxNumberOfVariables):
LocalPoolDataSetBase(sid, nullptr, maxNumberOfVariables), LocalPoolDataSetBase(sid, nullptr, maxNumberOfVariables),
poolVarList(maxNumberOfVariables) { poolVarList(maxNumberOfVariables) {
this->setContainer(poolVarList.data()); this->setContainer(poolVarList.data());
} }
LocalDataSet::~LocalDataSet() {} LocalDataSet::~LocalDataSet() {}

View File

@ -7,7 +7,7 @@
class LocalDataSet: public LocalPoolDataSetBase { class LocalDataSet: public LocalPoolDataSetBase {
public: public:
LocalDataSet(HasLocalDataPoolIF* hkOwner, uint32_t setId, LocalDataSet(HasLocalDataPoolIF* hkOwner, uint32_t setId,
const size_t maxSize); const size_t maxSize);
LocalDataSet(sid_t sid, const size_t maxSize); LocalDataSet(sid_t sid, const size_t maxSize);
virtual~ LocalDataSet(); virtual~ LocalDataSet();

View File

@ -11,309 +11,309 @@
#include <cstring> #include <cstring>
LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, LocalPoolDataSetBase::LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
uint32_t setId, PoolVariableIF** registeredVariablesArray, uint32_t setId, PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables, bool periodicHandling): const size_t maxNumberOfVariables, bool periodicHandling):
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
// Configuration error. // Configuration error.
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " sif::error << "LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
<< "invalid!" << std::endl; << "invalid!" << std::endl;
#else #else
sif::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner " sif::printError("LocalPoolDataSetBase::LocalPoolDataSetBase: Owner "
"invalid!\n\r"); "invalid!\n\r");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
return; return;
} }
AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
if(accessor != nullptr) { if(accessor != nullptr) {
poolManager = accessor->getHkManagerHandle(); poolManager = accessor->getHkManagerHandle();
mutexIfSingleDataCreator = accessor->getLocalPoolMutex(); mutexIfSingleDataCreator = accessor->getLocalPoolMutex();
} }
this->sid.objectId = hkOwner->getObjectId(); this->sid.objectId = hkOwner->getObjectId();
this->sid.ownerSetId = setId; this->sid.ownerSetId = setId;
// Data creators get a periodic helper for periodic HK data generation. // Data creators get a periodic helper for periodic HK data generation.
if(periodicHandling) { if(periodicHandling) {
periodicHelper = new PeriodicHousekeepingHelper(this); periodicHelper = new PeriodicHousekeepingHelper(this);
} }
} }
LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid,
PoolVariableIF** registeredVariablesArray, PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables): const size_t maxNumberOfVariables):
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>( HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(
sid.objectId); sid.objectId);
if(hkOwner != nullptr) { if(hkOwner != nullptr) {
AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
if(accessor != nullptr) { if(accessor != nullptr) {
mutexIfSingleDataCreator = accessor->getLocalPoolMutex(); mutexIfSingleDataCreator = accessor->getLocalPoolMutex();
} }
} }
this->sid = sid; this->sid = sid;
} }
LocalPoolDataSetBase::LocalPoolDataSetBase( LocalPoolDataSetBase::LocalPoolDataSetBase(
PoolVariableIF **registeredVariablesArray, PoolVariableIF **registeredVariablesArray,
const size_t maxNumberOfVariables, bool protectEveryReadCommitCall): const size_t maxNumberOfVariables, bool protectEveryReadCommitCall):
PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) { PoolDataSetBase(registeredVariablesArray, maxNumberOfVariables) {
this->setReadCommitProtectionBehaviour(protectEveryReadCommitCall); this->setReadCommitProtectionBehaviour(protectEveryReadCommitCall);
} }
LocalPoolDataSetBase::~LocalPoolDataSetBase() { LocalPoolDataSetBase::~LocalPoolDataSetBase() {
if(periodicHelper != nullptr) { if(periodicHelper != nullptr) {
delete periodicHelper; delete periodicHelper;
} }
} }
ReturnValue_t LocalPoolDataSetBase::lockDataPool( ReturnValue_t LocalPoolDataSetBase::lockDataPool(
MutexIF::TimeoutType timeoutType, MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs) { uint32_t timeoutMs) {
if(mutexIfSingleDataCreator != nullptr) { if(mutexIfSingleDataCreator != nullptr) {
return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs); return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs);
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer, ReturnValue_t LocalPoolDataSetBase::serializeWithValidityBuffer(uint8_t **buffer,
size_t *size, size_t maxSize, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const { SerializeIF::Endianness streamEndianness) const {
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0); uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
uint8_t validityMask[validityMaskSize]; uint8_t validityMask[validityMaskSize];
uint8_t validBufferIndex = 0; uint8_t validBufferIndex = 0;
uint8_t validBufferIndexBit = 0; uint8_t validBufferIndexBit = 0;
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
if(registeredVariables[count]->isValid()) { if(registeredVariables[count]->isValid()) {
// set validity buffer here. // set validity buffer here.
this->bitSetter(validityMask + validBufferIndex, this->bitSetter(validityMask + validBufferIndex,
validBufferIndexBit); validBufferIndexBit);
if(validBufferIndexBit == 7) { if(validBufferIndexBit == 7) {
validBufferIndex ++; validBufferIndex ++;
validBufferIndexBit = 0; validBufferIndexBit = 0;
} }
else { else {
validBufferIndexBit ++; validBufferIndexBit ++;
} }
} }
result = registeredVariables[count]->serialize(buffer, size, maxSize, result = registeredVariables[count]->serialize(buffer, size, maxSize,
streamEndianness); streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
} }
if(*size + validityMaskSize > maxSize) { if(*size + validityMaskSize > maxSize) {
return SerializeIF::BUFFER_TOO_SHORT; return SerializeIF::BUFFER_TOO_SHORT;
} }
// copy validity buffer to end // copy validity buffer to end
std::memcpy(*buffer, validityMask, validityMaskSize); std::memcpy(*buffer, validityMask, validityMaskSize);
*size += validityMaskSize; *size += validityMaskSize;
return result; return result;
} }
ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer( ReturnValue_t LocalPoolDataSetBase::deSerializeWithValidityBuffer(
const uint8_t **buffer, size_t *size, const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) { SerializeIF::Endianness streamEndianness) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
result = registeredVariables[count]->deSerialize(buffer, size, result = registeredVariables[count]->deSerialize(buffer, size,
streamEndianness); streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
return result; return result;
} }
} }
if(*size < std::ceil(static_cast<float>(fillCount) / 8.0)) { if(*size < std::ceil(static_cast<float>(fillCount) / 8.0)) {
return SerializeIF::STREAM_TOO_SHORT; return SerializeIF::STREAM_TOO_SHORT;
} }
uint8_t validBufferIndex = 0; uint8_t validBufferIndex = 0;
uint8_t validBufferIndexBit = 0; uint8_t validBufferIndexBit = 0;
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
// set validity buffer here. // set validity buffer here.
bool nextVarValid = this->bitGetter(*buffer + bool nextVarValid = this->bitGetter(*buffer +
validBufferIndex, validBufferIndexBit); validBufferIndex, validBufferIndexBit);
registeredVariables[count]->setValid(nextVarValid); registeredVariables[count]->setValid(nextVarValid);
if(validBufferIndexBit == 7) { if(validBufferIndexBit == 7) {
validBufferIndex ++; validBufferIndex ++;
validBufferIndexBit = 0; validBufferIndexBit = 0;
} }
else { else {
validBufferIndexBit ++; validBufferIndexBit ++;
} }
} }
return result; return result;
} }
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() { ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
if(mutexIfSingleDataCreator != nullptr) { if(mutexIfSingleDataCreator != nullptr) {
return mutexIfSingleDataCreator->unlockMutex(); return mutexIfSingleDataCreator->unlockMutex();
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer, ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t** buffer,
size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness, size_t* size, size_t maxSize,SerializeIF::Endianness streamEndianness,
bool serializeFillCount) const { bool serializeFillCount) const {
// Serialize as uint8_t // Serialize as uint8_t
uint8_t fillCount = this->fillCount; uint8_t fillCount = this->fillCount;
if(serializeFillCount) { if(serializeFillCount) {
SerializeAdapter::serialize(&fillCount, buffer, size, maxSize, SerializeAdapter::serialize(&fillCount, buffer, size, maxSize,
streamEndianness); streamEndianness);
} }
for (uint16_t count = 0; count < fillCount; count++) { for (uint16_t count = 0; count < fillCount; count++) {
lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId(); lp_id_t currentPoolId = registeredVariables[count]->getDataPoolId();
auto result = SerializeAdapter::serialize(&currentPoolId, buffer, auto result = SerializeAdapter::serialize(&currentPoolId, buffer,
size, maxSize, streamEndianness); size, maxSize, streamEndianness);
if(result != HasReturnvaluesIF::RETURN_OK) { if(result != HasReturnvaluesIF::RETURN_OK) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolDataSetBase::serializeLocalPoolIds: " sif::warning << "LocalPoolDataSetBase::serializeLocalPoolIds: "
<< "Serialization error!" << std::endl; << "Serialization error!" << std::endl;
#else #else
sif::printWarning("LocalPoolDataSetBase::serializeLocalPoolIds: " sif::printWarning("LocalPoolDataSetBase::serializeLocalPoolIds: "
"Serialization error!\n\r"); "Serialization error!\n\r");
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
return result; return result;
} }
} }
return HasReturnvaluesIF::RETURN_OK; return HasReturnvaluesIF::RETURN_OK;
} }
uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize( uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize(
bool serializeFillCount) const { bool serializeFillCount) const {
if(serializeFillCount) { if(serializeFillCount) {
return fillCount * sizeof(lp_id_t) + sizeof(uint8_t); return fillCount * sizeof(lp_id_t) + sizeof(uint8_t);
} }
else { else {
return fillCount * sizeof(lp_id_t); return fillCount * sizeof(lp_id_t);
} }
} }
size_t LocalPoolDataSetBase::getSerializedSize() const { size_t LocalPoolDataSetBase::getSerializedSize() const {
if(withValidityBuffer) { if(withValidityBuffer) {
uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0); uint8_t validityMaskSize = std::ceil(static_cast<float>(fillCount)/8.0);
return validityMaskSize + PoolDataSetBase::getSerializedSize(); return validityMaskSize + PoolDataSetBase::getSerializedSize();
} }
else { else {
return PoolDataSetBase::getSerializedSize(); return PoolDataSetBase::getSerializedSize();
} }
} }
void LocalPoolDataSetBase::setValidityBufferGeneration( void LocalPoolDataSetBase::setValidityBufferGeneration(
bool withValidityBuffer) { bool withValidityBuffer) {
this->withValidityBuffer = withValidityBuffer; this->withValidityBuffer = withValidityBuffer;
} }
ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer, ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer,
size_t *size, SerializeIF::Endianness streamEndianness) { size_t *size, SerializeIF::Endianness streamEndianness) {
if(withValidityBuffer) { if(withValidityBuffer) {
return this->deSerializeWithValidityBuffer(buffer, size, return this->deSerializeWithValidityBuffer(buffer, size,
streamEndianness); streamEndianness);
} }
else { else {
return PoolDataSetBase::deSerialize(buffer, size, streamEndianness); return PoolDataSetBase::deSerialize(buffer, size, streamEndianness);
} }
} }
ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size, ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size,
size_t maxSize, SerializeIF::Endianness streamEndianness) const { size_t maxSize, SerializeIF::Endianness streamEndianness) const {
if(withValidityBuffer) { if(withValidityBuffer) {
return this->serializeWithValidityBuffer(buffer, size, return this->serializeWithValidityBuffer(buffer, size,
maxSize, streamEndianness); maxSize, streamEndianness);
} }
else { else {
return PoolDataSetBase::serialize(buffer, size, maxSize, return PoolDataSetBase::serialize(buffer, size, maxSize,
streamEndianness); streamEndianness);
} }
} }
void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const { void LocalPoolDataSetBase::bitSetter(uint8_t* byte, uint8_t position) const {
if(position > 7) { if(position > 7) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolDataSetBase::bitSetter: Invalid position!" sif::warning << "LocalPoolDataSetBase::bitSetter: Invalid position!"
<< std::endl; << std::endl;
#else #else
sif::printWarning("LocalPoolDataSetBase::bitSetter: " sif::printWarning("LocalPoolDataSetBase::bitSetter: "
"Invalid position!\n\r"); "Invalid position!\n\r");
#endif #endif
return; return;
} }
uint8_t shiftNumber = position + (7 - 2 * position); uint8_t shiftNumber = position + (7 - 2 * position);
*byte |= 1 << shiftNumber; *byte |= 1 << shiftNumber;
} }
void LocalPoolDataSetBase::setDiagnostic(bool isDiagnostics) { void LocalPoolDataSetBase::setDiagnostic(bool isDiagnostics) {
this->diagnostic = isDiagnostics; this->diagnostic = isDiagnostics;
} }
bool LocalPoolDataSetBase::isDiagnostics() const { bool LocalPoolDataSetBase::isDiagnostics() const {
return diagnostic; return diagnostic;
} }
void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) { void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) {
this->reportingEnabled = reportingEnabled; this->reportingEnabled = reportingEnabled;
} }
bool LocalPoolDataSetBase::getReportingEnabled() const { bool LocalPoolDataSetBase::getReportingEnabled() const {
return reportingEnabled; return reportingEnabled;
} }
void LocalPoolDataSetBase::initializePeriodicHelper( void LocalPoolDataSetBase::initializePeriodicHelper(
float collectionInterval, dur_millis_t minimumPeriodicInterval, float collectionInterval, dur_millis_t minimumPeriodicInterval,
bool isDiagnostics, uint8_t nonDiagIntervalFactor) { bool isDiagnostics, uint8_t nonDiagIntervalFactor) {
periodicHelper->initialize(collectionInterval, minimumPeriodicInterval, periodicHelper->initialize(collectionInterval, minimumPeriodicInterval,
isDiagnostics, nonDiagIntervalFactor); isDiagnostics, nonDiagIntervalFactor);
} }
void LocalPoolDataSetBase::setChanged(bool changed) { void LocalPoolDataSetBase::setChanged(bool changed) {
this->changed = changed; this->changed = changed;
} }
bool LocalPoolDataSetBase::hasChanged() const { bool LocalPoolDataSetBase::hasChanged() const {
return changed; return changed;
} }
sid_t LocalPoolDataSetBase::getSid() const { sid_t LocalPoolDataSetBase::getSid() const {
return sid; return sid;
} }
bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte, bool LocalPoolDataSetBase::bitGetter(const uint8_t* byte,
uint8_t position) const { uint8_t position) const {
if(position > 7) { if(position > 7) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::debug << "Pool Raw Access: Bit setting invalid position" sif::debug << "Pool Raw Access: Bit setting invalid position"
<< std::endl; << std::endl;
#endif #endif
return false; return false;
} }
uint8_t shiftNumber = position + (7 - 2 * position); uint8_t shiftNumber = position + (7 - 2 * position);
return *byte & (1 << shiftNumber); return *byte & (1 << shiftNumber);
} }
bool LocalPoolDataSetBase::isValid() const { bool LocalPoolDataSetBase::isValid() const {
return this->valid; return this->valid;
} }
void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) { void LocalPoolDataSetBase::setValidity(bool valid, bool setEntriesRecursively) {
if(setEntriesRecursively) { if(setEntriesRecursively) {
for(size_t idx = 0; idx < this->getFillCount(); idx++) { for(size_t idx = 0; idx < this->getFillCount(); idx++) {
registeredVariables[idx] -> setValid(valid); registeredVariables[idx] -> setValid(valid);
} }
} }
this->valid = valid; this->valid = valid;
} }
object_id_t LocalPoolDataSetBase::getCreatorObjectId() { object_id_t LocalPoolDataSetBase::getCreatorObjectId() {
if(poolManager != nullptr) { if(poolManager != nullptr) {
return poolManager->getCreatorObjectId(); return poolManager->getCreatorObjectId();
} }
return objects::NO_OBJECT; return objects::NO_OBJECT;
} }

View File

@ -41,184 +41,185 @@ class PeriodicHousekeepingHelper;
* *
* @ingroup data_pool * @ingroup data_pool
*/ */
class LocalPoolDataSetBase: public PoolDataSetBase, class LocalPoolDataSetBase:
public PoolDataSetBase,
public MarkChangedIF { public MarkChangedIF {
friend class LocalPoolDataSetAttorney; friend class LocalPoolDataSetAttorney;
friend class PeriodicHousekeepingHelper; friend class PeriodicHousekeepingHelper;
public: public:
/** /**
* @brief Constructor for the creator of local pool data. * @brief Constructor for the creator of local pool data.
* @details * @details
* This constructor also initializes the components required for * This constructor also initializes the components required for
* periodic handling. * periodic handling.
*/ */
LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner, LocalPoolDataSetBase(HasLocalDataPoolIF *hkOwner,
uint32_t setId, PoolVariableIF** registeredVariablesArray, uint32_t setId, PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables, bool periodicHandling = true); const size_t maxNumberOfVariables, bool periodicHandling = true);
/** /**
* @brief Constructor for users of the local pool data, which need * @brief Constructor for users of the local pool data, which need
* to access data created by one (!) HK manager. * to access data created by one (!) HK manager.
* @details * @details
* Unlike the first constructor, no component for periodic handling * Unlike the first constructor, no component for periodic handling
* will be initiated. * will be initiated.
* @param sid Unique identifier of dataset consisting of object ID and * @param sid Unique identifier of dataset consisting of object ID and
* set ID. * set ID.
* @param registeredVariablesArray * @param registeredVariablesArray
* @param maxNumberOfVariables * @param maxNumberOfVariables
*/ */
LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray, LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables); const size_t maxNumberOfVariables);
/** /**
* @brief Simple constructor, if the dataset is not the owner by * @brief Simple constructor, if the dataset is not the owner by
* a class with a HK manager. * a class with a HK manager.
* @details * @details
* This constructor won't create components required for periodic handling * This constructor won't create components required for periodic handling
* and it also won't try to deduce the HK manager because no SID is * and it also won't try to deduce the HK manager because no SID is
* supplied. This function should therefore be called by classes which need * supplied. This function should therefore be called by classes which need
* to access pool variables from different creators. * to access pool variables from different creators.
* *
* If the class is intended to access pool variables from different * If the class is intended to access pool variables from different
* creators, the third argument should be set to true. The mutex * creators, the third argument should be set to true. The mutex
* properties can be set with #setReadCommitProtectionBehaviour . * properties can be set with #setReadCommitProtectionBehaviour .
* @param registeredVariablesArray * @param registeredVariablesArray
* @param maxNumberOfVariables * @param maxNumberOfVariables
* @param protectEveryReadCommitCall If the pool variables are created by * @param protectEveryReadCommitCall If the pool variables are created by
* multiple creators, this flag can be set to protect all read and * multiple creators, this flag can be set to protect all read and
* commit calls separately. * commit calls separately.
*/ */
LocalPoolDataSetBase(PoolVariableIF** registeredVariablesArray, LocalPoolDataSetBase(PoolVariableIF** registeredVariablesArray,
const size_t maxNumberOfVariables, const size_t maxNumberOfVariables,
bool protectEveryReadCommitCall = true); bool protectEveryReadCommitCall = true);
/** /**
* @brief The destructor automatically manages writing the valid * @brief The destructor automatically manages writing the valid
* information of variables. * information of variables.
* @details * @details
* In case the data set was read out, but not committed(indicated by state), * In case the data set was read out, but not committed(indicated by state),
* the destructor parses all variables that are still registered to the set. * the destructor parses all variables that are still registered to the set.
* For each, the valid flag in the data pool is set to "invalid". * For each, the valid flag in the data pool is set to "invalid".
*/ */
~LocalPoolDataSetBase(); ~LocalPoolDataSetBase();
void setValidityBufferGeneration(bool withValidityBuffer); void setValidityBufferGeneration(bool withValidityBuffer);
sid_t getSid() const; sid_t getSid() const;
/** SerializeIF overrides */ /** SerializeIF overrides */
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const override; SerializeIF::Endianness streamEndianness) const override;
ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size, ReturnValue_t deSerialize(const uint8_t** buffer, size_t *size,
SerializeIF::Endianness streamEndianness) override; SerializeIF::Endianness streamEndianness) override;
size_t getSerializedSize() const override; size_t getSerializedSize() const override;
/** /**
* Special version of the serilization function which appends a * Special version of the serilization function which appends a
* validity buffer at the end. Each bit of this validity buffer * validity buffer at the end. Each bit of this validity buffer
* denotes whether the container data set entries are valid from left * denotes whether the container data set entries are valid from left
* to right, MSB first. (length = ceil(N/8), N = number of pool variables) * to right, MSB first. (length = ceil(N/8), N = number of pool variables)
* @param buffer * @param buffer
* @param size * @param size
* @param maxSize * @param maxSize
* @param bigEndian * @param bigEndian
* @param withValidityBuffer * @param withValidityBuffer
* @return * @return
*/ */
ReturnValue_t serializeWithValidityBuffer(uint8_t** buffer, ReturnValue_t serializeWithValidityBuffer(uint8_t** buffer,
size_t* size, size_t maxSize, size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const; SerializeIF::Endianness streamEndianness) const;
ReturnValue_t deSerializeWithValidityBuffer(const uint8_t** buffer, ReturnValue_t deSerializeWithValidityBuffer(const uint8_t** buffer,
size_t *size, SerializeIF::Endianness streamEndianness); size_t *size, SerializeIF::Endianness streamEndianness);
ReturnValue_t serializeLocalPoolIds(uint8_t** buffer, ReturnValue_t serializeLocalPoolIds(uint8_t** buffer,
size_t* size, size_t maxSize, size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness, SerializeIF::Endianness streamEndianness,
bool serializeFillCount = true) const; bool serializeFillCount = true) const;
uint8_t getLocalPoolIdsSerializedSize(bool serializeFillCount = true) const; uint8_t getLocalPoolIdsSerializedSize(bool serializeFillCount = true) const;
/** /**
* Set the dataset valid or invalid. These calls are mutex protected. * Set the dataset valid or invalid. These calls are mutex protected.
* @param setEntriesRecursively * @param setEntriesRecursively
* If this is true, all contained datasets will also be set recursively. * If this is true, all contained datasets will also be set recursively.
*/ */
void setValidity(bool valid, bool setEntriesRecursively); void setValidity(bool valid, bool setEntriesRecursively);
bool isValid() const override; bool isValid() const override;
/** /**
* These calls are mutex protected. * These calls are mutex protected.
* @param changed * @param changed
*/ */
void setChanged(bool changed) override; void setChanged(bool changed) override;
bool hasChanged() const override; bool hasChanged() const override;
object_id_t getCreatorObjectId(); object_id_t getCreatorObjectId();
protected: protected:
sid_t sid; sid_t sid;
//! This mutex is used if the data is created by one object only. //! This mutex is used if the data is created by one object only.
MutexIF* mutexIfSingleDataCreator = nullptr; MutexIF* mutexIfSingleDataCreator = nullptr;
bool diagnostic = false; bool diagnostic = false;
void setDiagnostic(bool diagnostics); void setDiagnostic(bool diagnostics);
bool isDiagnostics() const; bool isDiagnostics() const;
/** /**
* Used for periodic generation. * Used for periodic generation.
*/ */
bool reportingEnabled = false; bool reportingEnabled = false;
void setReportingEnabled(bool enabled); void setReportingEnabled(bool enabled);
bool getReportingEnabled() const; bool getReportingEnabled() const;
void initializePeriodicHelper(float collectionInterval, void initializePeriodicHelper(float collectionInterval,
dur_millis_t minimumPeriodicInterval, dur_millis_t minimumPeriodicInterval,
bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5); bool isDiagnostics, uint8_t nonDiagIntervalFactor = 5);
/** /**
* If the valid state of a dataset is always relevant to the whole * If the valid state of a dataset is always relevant to the whole
* data set we can use this flag. * data set we can use this flag.
*/ */
bool valid = false; bool valid = false;
/** /**
* Can be used to mark the dataset as changed, which is used * Can be used to mark the dataset as changed, which is used
* by the LocalDataPoolManager to send out update messages. * by the LocalDataPoolManager to send out update messages.
*/ */
bool changed = false; bool changed = false;
/** /**
* Specify whether the validity buffer is serialized too when serializing * Specify whether the validity buffer is serialized too when serializing
* or deserializing the packet. Each bit of the validity buffer will * or deserializing the packet. Each bit of the validity buffer will
* contain the validity state of the pool variables from left to right. * contain the validity state of the pool variables from left to right.
* The size of validity buffer thus will be ceil(N / 8) with N = number of * The size of validity buffer thus will be ceil(N / 8) with N = number of
* pool variables. * pool variables.
*/ */
bool withValidityBuffer = true; bool withValidityBuffer = true;
/** /**
* @brief This is a small helper function to facilitate locking * @brief This is a small helper function to facilitate locking
* the global data pool. * the global data pool.
* @details * @details
* It makes use of the lockDataPool method offered by the DataPool class. * It makes use of the lockDataPool method offered by the DataPool class.
*/ */
ReturnValue_t lockDataPool(MutexIF::TimeoutType timeoutType, ReturnValue_t lockDataPool(MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs) override; uint32_t timeoutMs) override;
/** /**
* @brief This is a small helper function to facilitate * @brief This is a small helper function to facilitate
* unlocking the global data pool * unlocking the global data pool
* @details * @details
* It makes use of the freeDataPoolLock method offered by the DataPool class. * It makes use of the freeDataPoolLock method offered by the DataPool class.
*/ */
ReturnValue_t unlockDataPool() override; ReturnValue_t unlockDataPool() override;
/** /**
* Set n-th bit of a byte, with n being the position from 0 * Set n-th bit of a byte, with n being the position from 0
* (most significant bit) to 7 (least significant bit) * (most significant bit) to 7 (least significant bit)
*/ */
void bitSetter(uint8_t* byte, uint8_t position) const; void bitSetter(uint8_t* byte, uint8_t position) const;
bool bitGetter(const uint8_t* byte, uint8_t position) const; bool bitGetter(const uint8_t* byte, uint8_t position) const;
PeriodicHousekeepingHelper* periodicHelper = nullptr; PeriodicHousekeepingHelper* periodicHelper = nullptr;
LocalDataPoolManager* poolManager = nullptr; LocalDataPoolManager* poolManager = nullptr;
}; };

View File

@ -1,128 +1,130 @@
#include "LocalDataPoolManager.h"
#include "LocalPoolObjectBase.h" #include "LocalPoolObjectBase.h"
#include "LocalDataPoolManager.h"
#include "internal/HasLocalDpIFUserAttorney.h" #include "internal/HasLocalDpIFUserAttorney.h"
#include "HasLocalDataPoolIF.h" #include "HasLocalDataPoolIF.h"
#include "../objectmanager/ObjectManagerIF.h" #include "../objectmanager/ObjectManagerIF.h"
LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkOwner, LocalPoolObjectBase::LocalPoolObjectBase(lp_id_t poolId, HasLocalDataPoolIF* hkOwner,
DataSetIF* dataSet, pool_rwm_t setReadWriteMode): DataSetIF* dataSet, pool_rwm_t setReadWriteMode):
localPoolId(poolId), readWriteMode(setReadWriteMode) { localPoolId(poolId), readWriteMode(setReadWriteMode) {
if(poolId == PoolVariableIF::NO_PARAMETER) { if(poolId == PoolVariableIF::NO_PARAMETER) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, " sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
<< "which is the NO_PARAMETER value!" << std::endl; << "which is the NO_PARAMETER value!" << std::endl;
#endif #endif
} }
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPoolVar<T>::LocalPoolVar: The supplied pool " sif::error << "LocalPoolVar<T>::LocalPoolVar: The supplied pool "
<< "owner is a invalid!" << std::endl; << "owner is a invalid!" << std::endl;
#endif #endif
return; return;
} }
AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
hkManager = poolManAccessor->getHkManagerHandle(); hkManager = poolManAccessor->getHkManagerHandle();
if (dataSet != nullptr) { if (dataSet != nullptr) {
dataSet->registerVariable(this); dataSet->registerVariable(this);
} }
} }
LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF *dataSet, LocalPoolObjectBase::LocalPoolObjectBase(object_id_t poolOwner, lp_id_t poolId, DataSetIF *dataSet,
pool_rwm_t setReadWriteMode): pool_rwm_t setReadWriteMode):
localPoolId(poolId), readWriteMode(setReadWriteMode) { localPoolId(poolId), readWriteMode(setReadWriteMode) {
if(poolId == PoolVariableIF::NO_PARAMETER) { if(poolId == PoolVariableIF::NO_PARAMETER) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, " sif::warning << "LocalPoolVar<T>::LocalPoolVar: 0 passed as pool ID, "
<< "which is the NO_PARAMETER value!" << std::endl; << "which is the NO_PARAMETER value!" << std::endl;
#endif #endif
} }
HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(poolOwner); HasLocalDataPoolIF* hkOwner = objectManager->get<HasLocalDataPoolIF>(poolOwner);
if(hkOwner == nullptr) { if(hkOwner == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "LocalPoolVariable: The supplied pool owner did not " sif::error << "LocalPoolVariable: The supplied pool owner did not "
<< "implement the correct interface" << "implement the correct interface"
<< " HasLocalDataPoolIF!" << std::endl; << " HasLocalDataPoolIF!" << std::endl;
#endif #endif
return; return;
} }
//hkManager = hkOwner->getHkManagerHandle();
AccessPoolManagerIF* poolManAccessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner); AccessPoolManagerIF* accessor = HasLocalDpIFUserAttorney::getAccessorHandle(hkOwner);
//hkManager = HasLocalDpIFUserAttorney::getHkManagerHandle(hkOwner); if(accessor != nullptr) {
hkManager = poolManAccessor->getHkManagerHandle(); hkManager = accessor->getHkManagerHandle();
if(dataSet != nullptr) { }
dataSet->registerVariable(this);
} if(dataSet != nullptr) {
dataSet->registerVariable(this);
}
} }
pool_rwm_t LocalPoolObjectBase::getReadWriteMode() const { pool_rwm_t LocalPoolObjectBase::getReadWriteMode() const {
return readWriteMode; return readWriteMode;
} }
bool LocalPoolObjectBase::isValid() const { bool LocalPoolObjectBase::isValid() const {
return valid; return valid;
} }
void LocalPoolObjectBase::setValid(bool valid) { void LocalPoolObjectBase::setValid(bool valid) {
this->valid = valid; this->valid = valid;
} }
lp_id_t LocalPoolObjectBase::getDataPoolId() const { lp_id_t LocalPoolObjectBase::getDataPoolId() const {
return localPoolId; return localPoolId;
} }
void LocalPoolObjectBase::setDataPoolId(lp_id_t poolId) { void LocalPoolObjectBase::setDataPoolId(lp_id_t poolId) {
this->localPoolId = poolId; this->localPoolId = poolId;
} }
void LocalPoolObjectBase::setChanged(bool changed) { void LocalPoolObjectBase::setChanged(bool changed) {
this->changed = changed; this->changed = changed;
} }
bool LocalPoolObjectBase::hasChanged() const { bool LocalPoolObjectBase::hasChanged() const {
return changed; return changed;
} }
void LocalPoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) { void LocalPoolObjectBase::setReadWriteMode(pool_rwm_t newReadWriteMode) {
this->readWriteMode = newReadWriteMode; this->readWriteMode = newReadWriteMode;
} }
void LocalPoolObjectBase::reportReadCommitError(const char* variableType, void LocalPoolObjectBase::reportReadCommitError(const char* variableType,
ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId) { ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId) {
#if FSFW_DISABLE_PRINTOUT == 0 #if FSFW_DISABLE_PRINTOUT == 0
const char* type = nullptr; const char* type = nullptr;
if(read) { if(read) {
type = "read"; type = "read";
} }
else { else {
type = "commit"; type = "commit";
} }
const char* errMsg = nullptr; const char* errMsg = nullptr;
if(error == localpool::POOL_ENTRY_NOT_FOUND) { if(error == localpool::POOL_ENTRY_NOT_FOUND) {
errMsg = "Pool entry not found"; errMsg = "Pool entry not found";
} }
else if(error == localpool::POOL_ENTRY_TYPE_CONFLICT) { else if(error == localpool::POOL_ENTRY_TYPE_CONFLICT) {
errMsg = "Pool entry type conflict"; errMsg = "Pool entry type conflict";
} }
else if(error == PoolVariableIF::INVALID_READ_WRITE_MODE) { else if(error == PoolVariableIF::INVALID_READ_WRITE_MODE) {
errMsg = "Pool variable wrong read-write mode"; errMsg = "Pool variable wrong read-write mode";
} }
else if(error == PoolVariableIF::INVALID_POOL_ENTRY) { else if(error == PoolVariableIF::INVALID_POOL_ENTRY) {
errMsg = "Pool entry invalid"; errMsg = "Pool entry invalid";
} }
else { else {
errMsg = "Unknown error code"; errMsg = "Unknown error code";
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << variableType << ": " << type << " call | " << errMsg << " | Owner: 0x" sif::warning << variableType << ": " << type << " call | " << errMsg << " | Owner: 0x"
<< std::hex << std::setw(8) << std::setfill('0') << objectId << std::dec << std::hex << std::setw(8) << std::setfill('0') << objectId << std::dec
<< " LPID: " << lpId << std::endl; << " LPID: " << lpId << std::endl;
#else #else
sif::printWarning("%s: %s call | %s | Owner: 0x%08x LPID: %lu\n", sif::printWarning("%s: %s call | %s | Owner: 0x%08x LPID: %lu\n",
variableType, type, errMsg, objectId, lpId); variableType, type, errMsg, objectId, lpId);
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
#endif /* FSFW_DISABLE_PRINTOUT == 0 */ #endif /* FSFW_DISABLE_PRINTOUT == 0 */
} }

View File

@ -1,8 +1,9 @@
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ #ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_
#define FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ #define FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_
#include <fsfw/datapoollocal/localPoolDefinitions.h>
#include "MarkChangedIF.h" #include "MarkChangedIF.h"
#include "localPoolDefinitions.h"
#include "../objectmanager/SystemObjectIF.h" #include "../objectmanager/SystemObjectIF.h"
#include "../datapool/PoolVariableIF.h" #include "../datapool/PoolVariableIF.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
@ -11,9 +12,13 @@ class LocalDataPoolManager;
class DataSetIF; class DataSetIF;
class HasLocalDataPoolIF; class HasLocalDataPoolIF;
/**
* @brief This class serves as a non-template base for pool objects like pool variables
* or pool vectors.
*/
class LocalPoolObjectBase: public PoolVariableIF, class LocalPoolObjectBase: public PoolVariableIF,
public HasReturnvaluesIF, public HasReturnvaluesIF,
public MarkChangedIF { public MarkChangedIF {
public: public:
LocalPoolObjectBase(lp_id_t poolId, LocalPoolObjectBase(lp_id_t poolId,
HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet, HasLocalDataPoolIF* hkOwner, DataSetIF* dataSet,
@ -61,10 +66,8 @@ protected:
//! @brief Pointer to the class which manages the HK pool. //! @brief Pointer to the class which manages the HK pool.
LocalDataPoolManager* hkManager = nullptr; LocalDataPoolManager* hkManager = nullptr;
void reportReadCommitError(const char* variableType, void reportReadCommitError(const char* variableType,
ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId); ReturnValue_t error, bool read, object_id_t objectId, lp_id_t lpId);
}; };
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ */ #endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLOBJECTBASE_H_ */

View File

@ -27,159 +27,159 @@
template<typename T> template<typename T>
class LocalPoolVariable: public LocalPoolObjectBase { class LocalPoolVariable: public LocalPoolObjectBase {
public: public:
//! Default ctor is forbidden. //! Default ctor is forbidden.
LocalPoolVariable() = delete; LocalPoolVariable() = delete;
/** /**
* This constructor is used by the data creators to have pool variable * This constructor is used by the data creators to have pool variable
* instances which can also be stored in datasets. * instances which can also be stored in datasets.
* *
* It does not fetch the current value from the data pool, which * It does not fetch the current value from the data pool, which
* has to be done by calling the read() operation. * has to be done by calling the read() operation.
* Datasets can be used to access multiple local pool entries in an * Datasets can be used to access multiple local pool entries in an
* efficient way. A pointer to a dataset can be passed to register * efficient way. A pointer to a dataset can be passed to register
* the pool variable in that dataset directly. * the pool variable in that dataset directly.
* @param poolId ID of the local pool entry. * @param poolId ID of the local pool entry.
* @param hkOwner Pointer of the owner. This will generally be the calling * @param hkOwner Pointer of the owner. This will generally be the calling
* class itself which passes "this". * class itself which passes "this".
* @param dataSet The data set in which the variable shall register itself. * @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered. * If nullptr, the variable is not registered.
* @param setReadWriteMode Specify the read-write mode of the pool variable. * @param setReadWriteMode Specify the read-write mode of the pool variable.
*/ */
LocalPoolVariable(HasLocalDataPoolIF* hkOwner, lp_id_t poolId, LocalPoolVariable(HasLocalDataPoolIF* hkOwner, lp_id_t poolId,
DataSetIF* dataSet = nullptr, DataSetIF* dataSet = nullptr,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
/** /**
* This constructor is used by data users like controllers to have * This constructor is used by data users like controllers to have
* access to the local pool variables of data creators by supplying * access to the local pool variables of data creators by supplying
* the respective creator object ID. * the respective creator object ID.
* *
* It does not fetch the current value from the data pool, which * It does not fetch the current value from the data pool, which
* has to be done by calling the read() operation. * has to be done by calling the read() operation.
* Datasets can be used to access multiple local pool entries in an * Datasets can be used to access multiple local pool entries in an
* efficient way. A pointer to a dataset can be passed to register * efficient way. A pointer to a dataset can be passed to register
* the pool variable in that dataset directly. * the pool variable in that dataset directly.
* @param poolId ID of the local pool entry. * @param poolId ID of the local pool entry.
* @param hkOwner object ID of the pool owner. * @param hkOwner object ID of the pool owner.
* @param dataSet The data set in which the variable shall register itself. * @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered. * If nullptr, the variable is not registered.
* @param setReadWriteMode Specify the read-write mode of the pool variable. * @param setReadWriteMode Specify the read-write mode of the pool variable.
* *
*/ */
LocalPoolVariable(object_id_t poolOwner, lp_id_t poolId, LocalPoolVariable(object_id_t poolOwner, lp_id_t poolId,
DataSetIF* dataSet = nullptr, DataSetIF* dataSet = nullptr,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
/** /**
* Variation which takes the global unique identifier of a pool variable. * Variation which takes the global unique identifier of a pool variable.
* @param globalPoolId * @param globalPoolId
* @param dataSet * @param dataSet
* @param setReadWriteMode * @param setReadWriteMode
*/ */
LocalPoolVariable(gp_id_t globalPoolId, DataSetIF* dataSet = nullptr, LocalPoolVariable(gp_id_t globalPoolId, DataSetIF* dataSet = nullptr,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
virtual~ LocalPoolVariable() {}; virtual~ LocalPoolVariable() {};
/** /**
* @brief This is the local copy of the data pool entry. * @brief This is the local copy of the data pool entry.
* @details The user can work on this attribute * @details The user can work on this attribute
* just like he would on a simple local variable. * just like he would on a simple local variable.
*/ */
T value = 0; T value = 0;
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const override; SerializeIF::Endianness streamEndianness) const override;
virtual size_t getSerializedSize() const override; virtual size_t getSerializedSize() const override;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
SerializeIF::Endianness streamEndianness) override; SerializeIF::Endianness streamEndianness) override;
/** /**
* @brief This is a call to read the array's values * @brief This is a call to read the array's values
* from the global data pool. * from the global data pool.
* @details * @details
* When executed, this operation tries to fetch the pool entry with matching * When executed, this operation tries to fetch the pool entry with matching
* data pool id from the data pool and copies all array values and the valid * data pool id from the data pool and copies all array values and the valid
* information to its local attributes. * information to its local attributes.
* In case of a failure (wrong type, size or pool id not found), the * In case of a failure (wrong type, size or pool id not found), the
* variable is set to zero and invalid. * variable is set to zero and invalid.
* The read call is protected with a lock. * The read call is protected with a lock.
* It is recommended to use DataSets to read and commit multiple variables * It is recommended to use DataSets to read and commit multiple variables
* at once to avoid the overhead of unnecessary lock und unlock operations. * at once to avoid the overhead of unnecessary lock und unlock operations.
* *
*/ */
ReturnValue_t read(MutexIF::TimeoutType timeoutType = ReturnValue_t read(MutexIF::TimeoutType timeoutType =
MutexIF::TimeoutType::WAITING, MutexIF::TimeoutType::WAITING,
uint32_t timeoutMs = 20) override; uint32_t timeoutMs = 20) override;
/** /**
* @brief The commit call copies the array values back to the data pool. * @brief The commit call copies the array values back to the data pool.
* @details * @details
* It checks type and size, as well as if the variable is writable. If so, * It checks type and size, as well as if the variable is writable. If so,
* the value is copied and the local valid flag is written back as well. * the value is copied and the local valid flag is written back as well.
* The read call is protected with a lock. * The read call is protected with a lock.
* It is recommended to use DataSets to read and commit multiple variables * It is recommended to use DataSets to read and commit multiple variables
* at once to avoid the overhead of unnecessary lock und unlock operations. * at once to avoid the overhead of unnecessary lock und unlock operations.
*/ */
ReturnValue_t commit(MutexIF::TimeoutType timeoutType = ReturnValue_t commit(MutexIF::TimeoutType timeoutType =
MutexIF::TimeoutType::WAITING, MutexIF::TimeoutType::WAITING,
uint32_t timeoutMs = 20) override; uint32_t timeoutMs = 20) override;
/** /**
* @brief This commit function can be used to set the pool variable valid * @brief This commit function can be used to set the pool variable valid
* as well. * as well.
* @param setValid * @param setValid
* @param timeoutType * @param timeoutType
* @param timeoutMs * @param timeoutMs
* @return * @return
*/ */
ReturnValue_t commit(bool setValid, MutexIF::TimeoutType timeoutType = ReturnValue_t commit(bool setValid, MutexIF::TimeoutType timeoutType =
MutexIF::TimeoutType::WAITING, MutexIF::TimeoutType::WAITING,
uint32_t timeoutMs = 20); uint32_t timeoutMs = 20);
LocalPoolVariable<T> &operator=(const T& newValue); LocalPoolVariable<T> &operator=(const T& newValue);
LocalPoolVariable<T> &operator=(const LocalPoolVariable<T>& newPoolVariable); LocalPoolVariable<T> &operator=(const LocalPoolVariable<T>& newPoolVariable);
//! Explicit type conversion operator. Allows casting the class to //! Explicit type conversion operator. Allows casting the class to
//! its template type to perform operations on value. //! its template type to perform operations on value.
explicit operator T() const; explicit operator T() const;
bool operator==(const LocalPoolVariable<T>& other) const; bool operator==(const LocalPoolVariable<T>& other) const;
bool operator==(const T& other) const; bool operator==(const T& other) const;
bool operator!=(const LocalPoolVariable<T>& other) const; bool operator!=(const LocalPoolVariable<T>& other) const;
bool operator!=(const T& other) const; bool operator!=(const T& other) const;
bool operator<(const LocalPoolVariable<T>& other) const; bool operator<(const LocalPoolVariable<T>& other) const;
bool operator<(const T& other) const; bool operator<(const T& other) const;
bool operator>(const LocalPoolVariable<T>& other) const; bool operator>(const LocalPoolVariable<T>& other) const;
bool operator>(const T& other) const; bool operator>(const T& other) const;
protected: protected:
/** /**
* @brief Like #read, but without a lock protection of the global pool. * @brief Like #read, but without a lock protection of the global pool.
* @details * @details
* The operation does NOT provide any mutual exclusive protection by itself. * The operation does NOT provide any mutual exclusive protection by itself.
* This can be used if the lock is handled externally to avoid the overhead * This can be used if the lock is handled externally to avoid the overhead
* of consecutive lock und unlock operations. * of consecutive lock und unlock operations.
* Declared protected to discourage free public usage. * Declared protected to discourage free public usage.
*/ */
ReturnValue_t readWithoutLock() override; ReturnValue_t readWithoutLock() override;
/** /**
* @brief Like #commit, but without a lock protection of the global pool. * @brief Like #commit, but without a lock protection of the global pool.
* @details * @details
* The operation does NOT provide any mutual exclusive protection by itself. * The operation does NOT provide any mutual exclusive protection by itself.
* This can be used if the lock is handled externally to avoid the overhead * This can be used if the lock is handled externally to avoid the overhead
* of consecutive lock und unlock operations. * of consecutive lock und unlock operations.
* Declared protected to discourage free public usage. * Declared protected to discourage free public usage.
*/ */
ReturnValue_t commitWithoutLock() override; ReturnValue_t commitWithoutLock() override;
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
// std::ostream is the type for object std::cout // std::ostream is the type for object std::cout
template <typename U> template <typename U>
friend std::ostream& operator<< (std::ostream &out, friend std::ostream& operator<< (std::ostream &out,
const LocalPoolVariable<U> &var); const LocalPoolVariable<U> &var);
#endif #endif
}; };

View File

@ -7,127 +7,127 @@
template<typename T> template<typename T>
inline LocalPoolVariable<T>::LocalPoolVariable(HasLocalDataPoolIF* hkOwner, inline LocalPoolVariable<T>::LocalPoolVariable(HasLocalDataPoolIF* hkOwner,
lp_id_t poolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode): lp_id_t poolId, DataSetIF* dataSet, pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {} LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}
template<typename T> template<typename T>
inline LocalPoolVariable<T>::LocalPoolVariable(object_id_t poolOwner, inline LocalPoolVariable<T>::LocalPoolVariable(object_id_t poolOwner,
lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {} LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {}
template<typename T> template<typename T>
inline LocalPoolVariable<T>::LocalPoolVariable(gp_id_t globalPoolId, inline LocalPoolVariable<T>::LocalPoolVariable(gp_id_t globalPoolId,
DataSetIF *dataSet, pool_rwm_t setReadWriteMode): DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId,
dataSet, setReadWriteMode){} dataSet, setReadWriteMode){}
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::read( inline ReturnValue_t LocalPoolVariable<T>::read(
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs);
return readWithoutLock(); return readWithoutLock();
} }
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::readWithoutLock() { inline ReturnValue_t LocalPoolVariable<T>::readWithoutLock() {
if(readWriteMode == pool_rwm_t::VAR_WRITE) { if(readWriteMode == pool_rwm_t::VAR_WRITE) {
object_id_t targetObjectId = hkManager->getCreatorObjectId(); object_id_t targetObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVector", reportReadCommitError("LocalPoolVector",
PoolVariableIF::INVALID_READ_WRITE_MODE, true, targetObjectId, PoolVariableIF::INVALID_READ_WRITE_MODE, true, targetObjectId,
localPoolId); localPoolId);
return PoolVariableIF::INVALID_READ_WRITE_MODE; return PoolVariableIF::INVALID_READ_WRITE_MODE;
} }
PoolEntry<T>* poolEntry = nullptr; PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId,
&poolEntry); &poolEntry);
//ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); //ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
if(result != RETURN_OK) { if(result != RETURN_OK) {
object_id_t ownerObjectId = hkManager->getCreatorObjectId(); object_id_t ownerObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVariable", result, reportReadCommitError("LocalPoolVariable", result,
false, ownerObjectId, localPoolId); false, ownerObjectId, localPoolId);
return result; return result;
} }
// 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->getDataPtr()); this->value = *(poolEntry->getDataPtr());
this->valid = poolEntry->getValid(); this->valid = poolEntry->getValid();
return RETURN_OK; return RETURN_OK;
} }
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::commit(bool setValid, inline ReturnValue_t LocalPoolVariable<T>::commit(bool setValid,
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
this->setValid(setValid); this->setValid(setValid);
return commit(timeoutType, timeoutMs); return commit(timeoutType, timeoutMs);
} }
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::commit( inline ReturnValue_t LocalPoolVariable<T>::commit(
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs);
return commitWithoutLock(); return commitWithoutLock();
} }
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::commitWithoutLock() { inline ReturnValue_t LocalPoolVariable<T>::commitWithoutLock() {
if(readWriteMode == pool_rwm_t::VAR_READ) { if(readWriteMode == pool_rwm_t::VAR_READ) {
object_id_t targetObjectId = hkManager->getCreatorObjectId(); object_id_t targetObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVector", reportReadCommitError("LocalPoolVector",
PoolVariableIF::INVALID_READ_WRITE_MODE, false, targetObjectId, PoolVariableIF::INVALID_READ_WRITE_MODE, false, targetObjectId,
localPoolId); localPoolId);
return PoolVariableIF::INVALID_READ_WRITE_MODE; return PoolVariableIF::INVALID_READ_WRITE_MODE;
} }
PoolEntry<T>* poolEntry = nullptr; PoolEntry<T>* poolEntry = nullptr;
//ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry); //ReturnValue_t result = hkManager->fetchPoolEntry(localPoolId, &poolEntry);
ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId,
&poolEntry); &poolEntry);
if(result != RETURN_OK) { if(result != RETURN_OK) {
object_id_t ownerObjectId = hkManager->getCreatorObjectId(); object_id_t ownerObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVariable", result, reportReadCommitError("LocalPoolVariable", result,
false, ownerObjectId, localPoolId); false, ownerObjectId, localPoolId);
return result; return result;
} }
*(poolEntry->getDataPtr()) = this->value; *(poolEntry->getDataPtr()) = this->value;
poolEntry->setValid(this->valid); poolEntry->setValid(this->valid);
return RETURN_OK; return RETURN_OK;
} }
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::serialize(uint8_t** buffer, inline ReturnValue_t LocalPoolVariable<T>::serialize(uint8_t** buffer,
size_t* size, const size_t max_size, size_t* size, const size_t max_size,
SerializeIF::Endianness streamEndianness) const { SerializeIF::Endianness streamEndianness) const {
return SerializeAdapter::serialize(&value, return SerializeAdapter::serialize(&value,
buffer, size ,max_size, streamEndianness); buffer, size ,max_size, streamEndianness);
} }
template<typename T> template<typename T>
inline size_t LocalPoolVariable<T>::getSerializedSize() const { inline size_t LocalPoolVariable<T>::getSerializedSize() const {
return SerializeAdapter::getSerializedSize(&value); return SerializeAdapter::getSerializedSize(&value);
} }
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVariable<T>::deSerialize(const uint8_t** buffer, inline ReturnValue_t LocalPoolVariable<T>::deSerialize(const uint8_t** buffer,
size_t* size, SerializeIF::Endianness streamEndianness) { size_t* size, SerializeIF::Endianness streamEndianness) {
return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness);
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
template<typename T> template<typename T>
inline std::ostream& operator<< (std::ostream &out, inline std::ostream& operator<< (std::ostream &out,
const LocalPoolVariable<T> &var) { const LocalPoolVariable<T> &var) {
out << var.value; out << var.value;
return out; return out;
} }
@ -135,68 +135,68 @@ inline std::ostream& operator<< (std::ostream &out,
template<typename T> template<typename T>
inline LocalPoolVariable<T>::operator T() const { inline LocalPoolVariable<T>::operator T() const {
return value; return value;
} }
template<typename T> template<typename T>
inline LocalPoolVariable<T> & LocalPoolVariable<T>::operator=( inline LocalPoolVariable<T> & LocalPoolVariable<T>::operator=(
const T& newValue) { const T& newValue) {
value = newValue; value = newValue;
return *this; return *this;
} }
template<typename T> template<typename T>
inline LocalPoolVariable<T>& LocalPoolVariable<T>::operator =( inline LocalPoolVariable<T>& LocalPoolVariable<T>::operator =(
const LocalPoolVariable<T>& newPoolVariable) { const LocalPoolVariable<T>& newPoolVariable) {
value = newPoolVariable.value; value = newPoolVariable.value;
return *this; return *this;
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator ==( inline bool LocalPoolVariable<T>::operator ==(
const LocalPoolVariable<T> &other) const { const LocalPoolVariable<T> &other) const {
return this->value == other.value; return this->value == other.value;
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator ==(const T &other) const { inline bool LocalPoolVariable<T>::operator ==(const T &other) const {
return this->value == other; return this->value == other;
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator !=( inline bool LocalPoolVariable<T>::operator !=(
const LocalPoolVariable<T> &other) const { const LocalPoolVariable<T> &other) const {
return not (*this == other); return not (*this == other);
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator !=(const T &other) const { inline bool LocalPoolVariable<T>::operator !=(const T &other) const {
return not (*this == other); return not (*this == other);
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator <( inline bool LocalPoolVariable<T>::operator <(
const LocalPoolVariable<T> &other) const { const LocalPoolVariable<T> &other) const {
return this->value < other.value; return this->value < other.value;
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator <(const T &other) const { inline bool LocalPoolVariable<T>::operator <(const T &other) const {
return this->value < other; return this->value < other;
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator >( inline bool LocalPoolVariable<T>::operator >(
const LocalPoolVariable<T> &other) const { const LocalPoolVariable<T> &other) const {
return not (*this < other); return not (*this < other);
} }
template<typename T> template<typename T>
inline bool LocalPoolVariable<T>::operator >(const T &other) const { inline bool LocalPoolVariable<T>::operator >(const T &other) const {
return not (*this < other); return not (*this < other);
} }
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */ #endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLVARIABLE_TPP_ */

View File

@ -35,148 +35,148 @@
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
class LocalPoolVector: public LocalPoolObjectBase { class LocalPoolVector: public LocalPoolObjectBase {
public: public:
LocalPoolVector() = delete; LocalPoolVector() = delete;
/** /**
* This constructor is used by the data creators to have pool variable * This constructor is used by the data creators to have pool variable
* instances which can also be stored in datasets. * instances which can also be stored in datasets.
* It does not fetch the current value from the data pool. This is performed * It does not fetch the current value from the data pool. This is performed
* by the read() operation (which is not thread-safe). * by the read() operation (which is not thread-safe).
* Datasets can be used to access local pool entires in a thread-safe way. * Datasets can be used to access local pool entires in a thread-safe way.
* @param poolId ID of the local pool entry. * @param poolId ID of the local pool entry.
* @param hkOwner Pointer of the owner. This will generally be the calling * @param hkOwner Pointer of the owner. This will generally be the calling
* class itself which passes "this". * class itself which passes "this".
* @param setReadWriteMode Specify the read-write mode of the pool variable. * @param setReadWriteMode Specify the read-write mode of the pool variable.
* @param dataSet The data set in which the variable shall register itself. * @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered. * If nullptr, the variable is not registered.
*/ */
LocalPoolVector(HasLocalDataPoolIF* hkOwner, lp_id_t poolId, LocalPoolVector(HasLocalDataPoolIF* hkOwner, lp_id_t poolId,
DataSetIF* dataSet = nullptr, DataSetIF* dataSet = nullptr,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
/** /**
* This constructor is used by data users like controllers to have * This constructor is used by data users like controllers to have
* access to the local pool variables of data creators by supplying * access to the local pool variables of data creators by supplying
* the respective creator object ID. * the respective creator object ID.
* It does not fetch the current value from the data pool. This is performed * It does not fetch the current value from the data pool. This is performed
* by the read() operation (which is not thread-safe). * by the read() operation (which is not thread-safe).
* Datasets can be used to access local pool entires in a thread-safe way. * Datasets can be used to access local pool entires in a thread-safe way.
* @param poolId ID of the local pool entry. * @param poolId ID of the local pool entry.
* @param hkOwner Pointer of the owner. This will generally be the calling * @param hkOwner Pointer of the owner. This will generally be the calling
* class itself which passes "this". * class itself which passes "this".
* @param setReadWriteMode Specify the read-write mode of the pool variable. * @param setReadWriteMode Specify the read-write mode of the pool variable.
* @param dataSet The data set in which the variable shall register itself. * @param dataSet The data set in which the variable shall register itself.
* If nullptr, the variable is not registered. * If nullptr, the variable is not registered.
*/ */
LocalPoolVector(object_id_t poolOwner, lp_id_t poolId, LocalPoolVector(object_id_t poolOwner, lp_id_t poolId,
DataSetIF* dataSet = nullptr, DataSetIF* dataSet = nullptr,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
/** /**
* Variation which takes the unique global identifier of a local pool * Variation which takes the unique global identifier of a local pool
* vector. * vector.
* @param globalPoolId * @param globalPoolId
* @param dataSet * @param dataSet
* @param setReadWriteMode * @param setReadWriteMode
*/ */
LocalPoolVector(gp_id_t globalPoolId, LocalPoolVector(gp_id_t globalPoolId,
DataSetIF* dataSet = nullptr, DataSetIF* dataSet = nullptr,
pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE); pool_rwm_t setReadWriteMode = pool_rwm_t::VAR_READ_WRITE);
/** /**
* @brief This is the local copy of the data pool entry. * @brief This is the local copy of the data pool entry.
* @details * @details
* The user can work on this attribute just like he would on a local * The user can work on this attribute just like he would on a local
* array of this type. * array of this type.
*/ */
T value[vectorSize]; T value[vectorSize];
/** /**
* @brief The classes destructor is empty. * @brief The classes destructor is empty.
* @details If commit() was not called, the local value is * @details If commit() was not called, the local value is
* discarded and not written back to the data pool. * discarded and not written back to the data pool.
*/ */
~LocalPoolVector() {}; ~LocalPoolVector() {};
/** /**
* @brief The operation returns the number of array entries * @brief The operation returns the number of array entries
* in this variable. * in this variable.
*/ */
uint8_t getSize() { uint8_t getSize() {
return vectorSize; return vectorSize;
} }
T& operator [](size_t i); T& operator [](size_t i);
const T &operator [](size_t i) const; const T &operator [](size_t i) const;
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size,
const size_t maxSize, const size_t maxSize,
SerializeIF::Endianness streamEndiannes) const override; SerializeIF::Endianness streamEndiannes) const override;
virtual size_t getSerializedSize() const override; virtual size_t getSerializedSize() const override;
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size, virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
SerializeIF::Endianness streamEndianness) override; SerializeIF::Endianness streamEndianness) override;
/** /**
* @brief This is a call to read the array's values * @brief This is a call to read the array's values
* from the global data pool. * from the global data pool.
* @details * @details
* When executed, this operation tries to fetch the pool entry with matching * When executed, this operation tries to fetch the pool entry with matching
* data pool id from the data pool and copies all array values and the valid * data pool id from the data pool and copies all array values and the valid
* information to its local attributes. * information to its local attributes.
* In case of a failure (wrong type, size or pool id not found), the * In case of a failure (wrong type, size or pool id not found), the
* variable is set to zero and invalid. * variable is set to zero and invalid.
* The read call is protected with a lock. * The read call is protected with a lock.
* It is recommended to use DataSets to read and commit multiple variables * It is recommended to use DataSets to read and commit multiple variables
* at once to avoid the overhead of unnecessary lock und unlock operations. * at once to avoid the overhead of unnecessary lock und unlock operations.
*/ */
ReturnValue_t read(MutexIF::TimeoutType timeoutType = ReturnValue_t read(MutexIF::TimeoutType timeoutType =
MutexIF::TimeoutType::WAITING, MutexIF::TimeoutType::WAITING,
uint32_t timeoutMs = 20) override; uint32_t timeoutMs = 20) override;
/** /**
* @brief The commit call copies the array values back to the data pool. * @brief The commit call copies the array values back to the data pool.
* @details * @details
* It checks type and size, as well as if the variable is writable. If so, * It checks type and size, as well as if the variable is writable. If so,
* the value is copied and the local valid flag is written back as well. * the value is copied and the local valid flag is written back as well.
* The read call is protected with a lock. * The read call is protected with a lock.
* It is recommended to use DataSets to read and commit multiple variables * It is recommended to use DataSets to read and commit multiple variables
* at once to avoid the overhead of unnecessary lock und unlock operations. * at once to avoid the overhead of unnecessary lock und unlock operations.
*/ */
ReturnValue_t commit(MutexIF::TimeoutType timeoutType = ReturnValue_t commit(MutexIF::TimeoutType timeoutType =
MutexIF::TimeoutType::WAITING, MutexIF::TimeoutType::WAITING,
uint32_t timeoutMs = 20) override; uint32_t timeoutMs = 20) override;
/** /**
* @brief This commit call also sets the validity of the pool entry. * @brief This commit call also sets the validity of the pool entry.
* @details * @details
*/ */
ReturnValue_t commit(bool valid, MutexIF::TimeoutType timeoutType = ReturnValue_t commit(bool valid, MutexIF::TimeoutType timeoutType =
MutexIF::TimeoutType::WAITING, MutexIF::TimeoutType::WAITING,
uint32_t timeoutMs = 20); uint32_t timeoutMs = 20);
protected: protected:
/** /**
* @brief Like #read, but without a lock protection of the global pool. * @brief Like #read, but without a lock protection of the global pool.
* @details * @details
* The operation does NOT provide any mutual exclusive protection by itself. * The operation does NOT provide any mutual exclusive protection by itself.
* This can be used if the lock is handled externally to avoid the overhead * This can be used if the lock is handled externally to avoid the overhead
* of consecutive lock und unlock operations. * of consecutive lock und unlock operations.
* Declared protected to discourage free public usage. * Declared protected to discourage free public usage.
*/ */
ReturnValue_t readWithoutLock() override; ReturnValue_t readWithoutLock() override;
/** /**
* @brief Like #commit, but without a lock protection of the global pool. * @brief Like #commit, but without a lock protection of the global pool.
* @details * @details
* The operation does NOT provide any mutual exclusive protection by itself. * The operation does NOT provide any mutual exclusive protection by itself.
* This can be used if the lock is handled externally to avoid the overhead * This can be used if the lock is handled externally to avoid the overhead
* of consecutive lock und unlock operations. * of consecutive lock und unlock operations.
* Declared protected to discourage free public usage. * Declared protected to discourage free public usage.
*/ */
ReturnValue_t commitWithoutLock() override; ReturnValue_t commitWithoutLock() override;
private: private:
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
// std::ostream is the type for object std::cout // std::ostream is the type for object std::cout
template <typename U, uint16_t otherSize> template <typename U, uint16_t otherSize>
friend std::ostream& operator<< (std::ostream &out, friend std::ostream& operator<< (std::ostream &out,
const LocalPoolVector<U, otherSize> &var); const LocalPoolVector<U, otherSize> &var);
#endif #endif
}; };

View File

@ -7,158 +7,158 @@
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline LocalPoolVector<T, vectorSize>::LocalPoolVector( inline LocalPoolVector<T, vectorSize>::LocalPoolVector(
HasLocalDataPoolIF* hkOwner, lp_id_t poolId, DataSetIF* dataSet, HasLocalDataPoolIF* hkOwner, lp_id_t poolId, DataSetIF* dataSet,
pool_rwm_t setReadWriteMode): pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {} LocalPoolObjectBase(poolId, hkOwner, dataSet, setReadWriteMode) {}
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(object_id_t poolOwner, inline LocalPoolVector<T, vectorSize>::LocalPoolVector(object_id_t poolOwner,
lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode): lp_id_t poolId, DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {} LocalPoolObjectBase(poolOwner, poolId, dataSet, setReadWriteMode) {}
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline LocalPoolVector<T, vectorSize>::LocalPoolVector(gp_id_t globalPoolId, inline LocalPoolVector<T, vectorSize>::LocalPoolVector(gp_id_t globalPoolId,
DataSetIF *dataSet, pool_rwm_t setReadWriteMode): DataSetIF *dataSet, pool_rwm_t setReadWriteMode):
LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId, LocalPoolObjectBase(globalPoolId.objectId, globalPoolId.localPoolId,
dataSet, setReadWriteMode) {} dataSet, setReadWriteMode) {}
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::read( inline ReturnValue_t LocalPoolVector<T, vectorSize>::read(
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs);
return readWithoutLock(); return readWithoutLock();
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::readWithoutLock() { inline ReturnValue_t LocalPoolVector<T, vectorSize>::readWithoutLock() {
if(readWriteMode == pool_rwm_t::VAR_WRITE) { if(readWriteMode == pool_rwm_t::VAR_WRITE) {
object_id_t targetObjectId = hkManager->getCreatorObjectId(); object_id_t targetObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVector", reportReadCommitError("LocalPoolVector",
PoolVariableIF::INVALID_READ_WRITE_MODE, true, targetObjectId, PoolVariableIF::INVALID_READ_WRITE_MODE, true, targetObjectId,
localPoolId); localPoolId);
return PoolVariableIF::INVALID_READ_WRITE_MODE; return PoolVariableIF::INVALID_READ_WRITE_MODE;
} }
PoolEntry<T>* poolEntry = nullptr; PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId,
&poolEntry); &poolEntry);
memset(this->value, 0, vectorSize * sizeof(T)); memset(this->value, 0, vectorSize * sizeof(T));
if(result != RETURN_OK) { if(result != RETURN_OK) {
object_id_t targetObjectId = hkManager->getCreatorObjectId(); object_id_t targetObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVector", result, true, targetObjectId, reportReadCommitError("LocalPoolVector", result, true, targetObjectId,
localPoolId); localPoolId);
return result; return result;
} }
std::memcpy(this->value, poolEntry->getDataPtr(), poolEntry->getByteSize()); std::memcpy(this->value, poolEntry->getDataPtr(), poolEntry->getByteSize());
this->valid = poolEntry->getValid(); this->valid = poolEntry->getValid();
return RETURN_OK; return RETURN_OK;
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit(bool valid, inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit(bool valid,
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
this->setValid(valid); this->setValid(valid);
return commit(timeoutType, timeoutMs); return commit(timeoutType, timeoutMs);
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit( inline ReturnValue_t LocalPoolVector<T, vectorSize>::commit(
MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) { MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs); MutexHelper(LocalDpManagerAttorney::getMutexHandle(*hkManager), timeoutType, timeoutMs);
return commitWithoutLock(); return commitWithoutLock();
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::commitWithoutLock() { inline ReturnValue_t LocalPoolVector<T, vectorSize>::commitWithoutLock() {
if(readWriteMode == pool_rwm_t::VAR_READ) { if(readWriteMode == pool_rwm_t::VAR_READ) {
object_id_t targetObjectId = hkManager->getCreatorObjectId(); object_id_t targetObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVector", reportReadCommitError("LocalPoolVector",
PoolVariableIF::INVALID_READ_WRITE_MODE, false, targetObjectId, PoolVariableIF::INVALID_READ_WRITE_MODE, false, targetObjectId,
localPoolId); localPoolId);
return PoolVariableIF::INVALID_READ_WRITE_MODE; return PoolVariableIF::INVALID_READ_WRITE_MODE;
} }
PoolEntry<T>* poolEntry = nullptr; PoolEntry<T>* poolEntry = nullptr;
ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId, ReturnValue_t result = LocalDpManagerAttorney::fetchPoolEntry(*hkManager, localPoolId,
&poolEntry); &poolEntry);
if(result != RETURN_OK) { if(result != RETURN_OK) {
object_id_t targetObjectId = hkManager->getCreatorObjectId(); object_id_t targetObjectId = hkManager->getCreatorObjectId();
reportReadCommitError("LocalPoolVector", result, false, targetObjectId, reportReadCommitError("LocalPoolVector", result, false, targetObjectId,
localPoolId); localPoolId);
return result; return result;
} }
std::memcpy(poolEntry->getDataPtr(), this->value, poolEntry->getByteSize()); std::memcpy(poolEntry->getDataPtr(), this->value, poolEntry->getByteSize());
poolEntry->setValid(this->valid); poolEntry->setValid(this->valid);
return RETURN_OK; return RETURN_OK;
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline T& LocalPoolVector<T, vectorSize>::operator [](size_t i) { inline T& LocalPoolVector<T, vectorSize>::operator [](size_t i) {
if(i < vectorSize) { if(i < vectorSize) {
return value[i]; return value[i];
} }
// If this happens, I have to set some value. I consider this // If this happens, I have to set some value. I consider this
// a configuration error, but I wont exit here. // a configuration error, but I wont exit here.
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolVector: Invalid index. Setting or returning" sif::warning << "LocalPoolVector: Invalid index. Setting or returning"
" last value!" << std::endl; " last value!" << std::endl;
#else #else
sif::printWarning("LocalPoolVector: Invalid index. Setting or returning" sif::printWarning("LocalPoolVector: Invalid index. Setting or returning"
" last value!\n"); " last value!\n");
#endif #endif
return value[vectorSize - 1]; return value[vectorSize - 1];
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline const T& LocalPoolVector<T, vectorSize>::operator [](size_t i) const { inline const T& LocalPoolVector<T, vectorSize>::operator [](size_t i) const {
if(i < vectorSize) { if(i < vectorSize) {
return value[i]; return value[i];
} }
// If this happens, I have to set some value. I consider this // If this happens, I have to set some value. I consider this
// a configuration error, but I wont exit here. // a configuration error, but I wont exit here.
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::warning << "LocalPoolVector: Invalid index. Setting or returning" sif::warning << "LocalPoolVector: Invalid index. Setting or returning"
" last value!" << std::endl; " last value!" << std::endl;
#else #else
sif::printWarning("LocalPoolVector: Invalid index. Setting or returning" sif::printWarning("LocalPoolVector: Invalid index. Setting or returning"
" last value!\n"); " last value!\n");
#endif #endif
return value[vectorSize - 1]; return value[vectorSize - 1];
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::serialize(uint8_t** buffer, inline ReturnValue_t LocalPoolVector<T, vectorSize>::serialize(uint8_t** buffer,
size_t* size, size_t maxSize, size_t* size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const { SerializeIF::Endianness streamEndianness) const {
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
for (uint16_t i = 0; i < vectorSize; i++) { for (uint16_t i = 0; i < vectorSize; i++) {
result = SerializeAdapter::serialize(&(value[i]), buffer, size, result = SerializeAdapter::serialize(&(value[i]), buffer, size,
maxSize, streamEndianness); maxSize, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
break; break;
} }
} }
return result; return result;
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline size_t LocalPoolVector<T, vectorSize>::getSerializedSize() const { inline size_t LocalPoolVector<T, vectorSize>::getSerializedSize() const {
return vectorSize * SerializeAdapter::getSerializedSize(value); return vectorSize * SerializeAdapter::getSerializedSize(value);
} }
template<typename T, uint16_t vectorSize> template<typename T, uint16_t vectorSize>
inline ReturnValue_t LocalPoolVector<T, vectorSize>::deSerialize( inline ReturnValue_t LocalPoolVector<T, vectorSize>::deSerialize(
const uint8_t** buffer, size_t* size, const uint8_t** buffer, size_t* size,
SerializeIF::Endianness streamEndianness) { SerializeIF::Endianness streamEndianness) {
ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED; ReturnValue_t result = HasReturnvaluesIF::RETURN_FAILED;
for (uint16_t i = 0; i < vectorSize; i++) { for (uint16_t i = 0; i < vectorSize; i++) {
result = SerializeAdapter::deSerialize(&(value[i]), buffer, size, result = SerializeAdapter::deSerialize(&(value[i]), buffer, size,
streamEndianness); streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) { if (result != HasReturnvaluesIF::RETURN_OK) {
break; break;
} }
} }
return result; return result;
} }
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1

View File

@ -10,38 +10,38 @@
*/ */
class PoolReadHelper { class PoolReadHelper {
public: public:
PoolReadHelper(ReadCommitIF* readObject, PoolReadHelper(ReadCommitIF* readObject,
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING, MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
uint32_t mutexTimeout = 20): uint32_t mutexTimeout = 20):
readObject(readObject), mutexTimeout(mutexTimeout) { readObject(readObject), mutexTimeout(mutexTimeout) {
if(readObject != nullptr) { if(readObject != nullptr) {
readResult = readObject->read(timeoutType, mutexTimeout); readResult = readObject->read(timeoutType, mutexTimeout);
#if FSFW_VERBOSE_LEVEL == 1 #if FSFW_VERBOSE_LEVEL == 1
#if FSFW_CPP_OSTREAM_ENABLED == 1 #if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "PoolReadHelper: Read failed!" << std::endl; sif::error << "PoolReadHelper: Read failed!" << std::endl;
#else #else
sif::printError("PoolReadHelper: Read failed!\n"); sif::printError("PoolReadHelper: Read failed!\n");
#endif /* FSFW_PRINT_VERBOSITY_LEVEL == 1 */ #endif /* FSFW_PRINT_VERBOSITY_LEVEL == 1 */
#endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */ #endif /* FSFW_CPP_OSTREAM_ENABLED == 1 */
} }
} }
ReturnValue_t getReadResult() const { ReturnValue_t getReadResult() const {
return readResult; return readResult;
} }
~PoolReadHelper() { ~PoolReadHelper() {
if(readObject != nullptr) { if(readObject != nullptr) {
readObject->commit(timeoutType, mutexTimeout); readObject->commit(timeoutType, mutexTimeout);
} }
} }
private: private:
ReadCommitIF* readObject = nullptr; ReadCommitIF* readObject = nullptr;
ReturnValue_t readResult = HasReturnvaluesIF::RETURN_OK; ReturnValue_t readResult = HasReturnvaluesIF::RETURN_OK;
MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING; MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING;
uint32_t mutexTimeout = 20; uint32_t mutexTimeout = 20;
}; };

View File

@ -9,75 +9,75 @@
class ProvidesDataPoolSubscriptionIF { class ProvidesDataPoolSubscriptionIF {
public: public:
virtual ~ProvidesDataPoolSubscriptionIF(){}; virtual ~ProvidesDataPoolSubscriptionIF(){};
/** /**
* @brief Subscribe for the generation of periodic packets. * @brief Subscribe for the generation of periodic packets.
* @details * @details
* This subscription mechanism will generally be used by the data creator * This subscription mechanism will generally be used by the data creator
* to generate housekeeping packets which are downlinked directly. * to generate housekeeping packets which are downlinked directly.
* @return * @return
*/ */
virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid, virtual ReturnValue_t subscribeForPeriodicPacket(sid_t sid,
bool enableReporting, bool enableReporting,
float collectionInterval, bool isDiagnostics, float collectionInterval, bool isDiagnostics,
object_id_t packetDestination) = 0; object_id_t packetDestination) = 0;
/** /**
* @brief Subscribe for the generation of packets if the dataset * @brief Subscribe for the generation of packets if the dataset
* is marked as changed. * is marked as changed.
* @details * @details
* This subscription mechanism will generally be used by the data creator. * This subscription mechanism will generally be used by the data creator.
* @param sid * @param sid
* @param isDiagnostics * @param isDiagnostics
* @param packetDestination * @param packetDestination
* @return * @return
*/ */
virtual ReturnValue_t subscribeForUpdatePackets(sid_t sid, virtual ReturnValue_t subscribeForUpdatePackets(sid_t sid,
bool reportingEnabled, bool reportingEnabled,
bool isDiagnostics, bool isDiagnostics,
object_id_t packetDestination) = 0; object_id_t packetDestination) = 0;
/** /**
* @brief Subscribe for a notification message which will be sent * @brief Subscribe for a notification message which will be sent
* if a dataset has changed. * if a dataset has changed.
* @details * @details
* This subscription mechanism will generally be used internally by * This subscription mechanism will generally be used internally by
* other software components. * other software components.
* @param setId Set ID of the set to receive update messages from. * @param setId Set ID of the set to receive update messages from.
* @param destinationObject * @param destinationObject
* @param targetQueueId * @param targetQueueId
* @param generateSnapshot If this is set to true, a copy of the current * @param generateSnapshot If this is set to true, a copy of the current
* data with a timestamp will be generated and sent via message. * data with a timestamp will be generated and sent via message.
* Otherwise, only an notification message is sent. * Otherwise, only an notification message is sent.
* @return * @return
*/ */
virtual ReturnValue_t subscribeForSetUpdateMessages(const uint32_t setId, virtual ReturnValue_t subscribeForSetUpdateMessages(const uint32_t setId,
object_id_t destinationObject, object_id_t destinationObject,
MessageQueueId_t targetQueueId, MessageQueueId_t targetQueueId,
bool generateSnapshot) = 0; bool generateSnapshot) = 0;
/** /**
* @brief Subscribe for an notification message which will be sent if a * @brief Subscribe for an notification message which will be sent if a
* pool variable has changed. * pool variable has changed.
* @details * @details
* This subscription mechanism will generally be used internally by * This subscription mechanism will generally be used internally by
* other software components. * other software components.
* @param localPoolId Pool ID of the pool variable * @param localPoolId Pool ID of the pool variable
* @param destinationObject * @param destinationObject
* @param targetQueueId * @param targetQueueId
* @param generateSnapshot If this is set to true, a copy of the current * @param generateSnapshot If this is set to true, a copy of the current
* data with a timestamp will be generated and sent via message. * data with a timestamp will be generated and sent via message.
* Otherwise, only an notification message is sent. * Otherwise, only an notification message is sent.
* @return * @return
*/ */
virtual ReturnValue_t subscribeForVariableUpdateMessages( virtual ReturnValue_t subscribeForVariableUpdateMessages(
const lp_id_t localPoolId, const lp_id_t localPoolId,
object_id_t destinationObject, object_id_t destinationObject,
MessageQueueId_t targetQueueId, MessageQueueId_t targetQueueId,
bool generateSnapshot) = 0; bool generateSnapshot) = 0;
}; };

View File

@ -13,7 +13,8 @@
* *
* TODO: override and protect read, commit and some other calls used by pool manager. * TODO: override and protect read, commit and some other calls used by pool manager.
*/ */
class SharedLocalDataSet: public SystemObject, class SharedLocalDataSet:
public SystemObject,
public LocalPoolDataSetBase, public LocalPoolDataSetBase,
public SharedDataSetIF { public SharedDataSetIF {
public: public:

View File

@ -20,26 +20,24 @@
template <uint8_t NUM_VARIABLES> template <uint8_t NUM_VARIABLES>
class StaticLocalDataSet: public LocalPoolDataSetBase { class StaticLocalDataSet: public LocalPoolDataSetBase {
public: public:
/** /**
* Constructor used by data owner and creator like device handlers. * Constructor used by data owner and creator like device handlers.
* This constructor also initialized the components required for * This constructor also initialized the components required for
* periodic handling. * periodic handling.
* @param hkOwner * @param hkOwner
* @param setId * @param setId
*/ */
StaticLocalDataSet(HasLocalDataPoolIF* hkOwner, StaticLocalDataSet(HasLocalDataPoolIF* hkOwner, uint32_t setId):
uint32_t setId): LocalPoolDataSetBase(hkOwner, setId, nullptr, LocalPoolDataSetBase(hkOwner, setId, nullptr, NUM_VARIABLES) {
NUM_VARIABLES) {
this->setContainer(poolVarList.data()); this->setContainer(poolVarList.data());
} }
/** /**
* Constructor used by data users like controllers. * Constructor used by data users like controllers.
* @param hkOwner * @param hkOwner
* @param setId * @param setId
*/ */
StaticLocalDataSet(sid_t sid): LocalPoolDataSetBase(sid, nullptr, StaticLocalDataSet(sid_t sid): LocalPoolDataSetBase(sid, nullptr, NUM_VARIABLES) {
NUM_VARIABLES) {
this->setContainer(poolVarList.data()); this->setContainer(poolVarList.data());
} }

View File

@ -40,8 +40,8 @@ union sid_t {
sid_t(): raw(INVALID_SID) {} sid_t(): raw(INVALID_SID) {}
sid_t(object_id_t objectId, uint32_t setId): sid_t(object_id_t objectId, uint32_t setId):
objectId(objectId), objectId(objectId),
ownerSetId(setId) {} ownerSetId(setId) {}
struct { struct {
object_id_t objectId ; object_id_t objectId ;
@ -75,26 +75,26 @@ union sid_t {
* and 4 byte local pool ID. * and 4 byte local pool ID.
*/ */
union gp_id_t { union gp_id_t {
static constexpr uint64_t INVALID_GPID = -1; static constexpr uint64_t INVALID_GPID = -1;
static constexpr uint32_t INVALID_OBJECT_ID = objects::NO_OBJECT; static constexpr uint32_t INVALID_OBJECT_ID = objects::NO_OBJECT;
static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID; static constexpr uint32_t INVALID_LPID = localpool::INVALID_LPID;
gp_id_t(): raw(INVALID_GPID) {} gp_id_t(): raw(INVALID_GPID) {}
gp_id_t(object_id_t objectId, lp_id_t localPoolId): gp_id_t(object_id_t objectId, lp_id_t localPoolId):
objectId(objectId), objectId(objectId),
localPoolId(localPoolId) {} localPoolId(localPoolId) {}
struct { struct {
object_id_t objectId; object_id_t objectId;
lp_id_t localPoolId; lp_id_t localPoolId;
}; };
uint64_t raw; uint64_t raw;
bool notSet() const { bool notSet() const {
return raw == INVALID_GPID; return raw == INVALID_GPID;
} }
bool operator==(const sid_t& other) const { bool operator==(const sid_t& other) const {
return raw == other.raw; return raw == other.raw;