continue refactoring

This commit is contained in:
Robin Müller 2024-11-06 14:18:32 +01:00
parent d2bc99baf3
commit 79dca64cf3
Signed by: muellerr
GPG Key ID: A649FB78196E3849
50 changed files with 557 additions and 677 deletions

View File

@ -123,8 +123,11 @@ option(FSFW_ADD_SGP4_PROPAGATOR "Add SGP4 propagator code" OFF)
set(FSFW_TEST_TGT fsfw-tests)
set(FSFW_DUMMY_TGT fsfw-dummy)
add_library(${LIB_FSFW_NAME} src/fsfw/datapoollocal/SharedPool.h
src/fsfw/datapoollocal/SharedPool.cpp)
add_library(
${LIB_FSFW_NAME}
src/fsfw/datapoollocal/SharedPool.h src/fsfw/datapoollocal/SharedPool.cpp
src/fsfw/serialize/SerializableList.h
src/fsfw/serialize/SerializableListElement.h)
if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
set_property(TARGET ${LIB_FSFW_NAME} PROPERTY INTERPROCEDURAL_OPTIMIZATION
@ -142,7 +145,7 @@ if(FSFW_BUILD_TESTS)
configure_file(unittests/testcfg/TestsConfig.h.in tests/TestsConfig.h)
project(${FSFW_TEST_TGT} CXX C)
add_executable(${FSFW_TEST_TGT})
add_executable(${FSFW_TEST_TGT} unittests/serialize/testList.cpp)
if(IPO_SUPPORTED AND FSFW_ENABLE_IPO)
set_property(TARGET ${FSFW_TEST_TGT} PROPERTY INTERPROCEDURAL_OPTIMIZATION
TRUE)

View File

@ -30,7 +30,7 @@
* @ingroup data_pool
*/
class PoolDataSetBase : public PoolDataSetIF, public SerializeIF {
friend class LocalPoolDataSetBase;
friend class SharedDatasetBase;
public:
/**

View File

@ -5,8 +5,7 @@
#include "fsfw/datapoollocal/LocalDataSet.h"
#include "fsfw/datapoollocal/LocalPoolVariable.h"
#include "fsfw/datapoollocal/LocalPoolVector.h"
#include "fsfw/datapoollocal/SharedLocalDataSet.h"
#include "fsfw/datapoollocal/SharedLocalDataset.h"
#include "fsfw/datapoollocal/SharedPool.h"
#include "fsfw/datapoollocal/StaticLocalDataSet.h"
#endif /* FSFW_DATAPOOLLOCAL_DATAPOOLLOCAL_H_ */

View File

@ -1,7 +1,6 @@
target_sources(
${LIB_FSFW_NAME}
PRIVATE PeriodicHkGenerationHelper.cpp LocalDataSet.cpp
LocalPoolDataSetBase.cpp LocalPoolObjectBase.cpp
SharedLocalDataSet.cpp)
PRIVATE PeriodicHkGenerationHelper.cpp LocalDataSet.cpp SharedDatasetBase.cpp
LocalPoolObjectBase.cpp SharedLocalDataset.cpp)
add_subdirectory(internal)

View File

@ -1,15 +1,15 @@
#include "fsfw/datapoollocal/LocalDataSet.h"
LocalDataSet::LocalDataSet(localpool::SharedPool& sharedPool, uint32_t setId,
const size_t maxNumberOfVariables)
: LocalPoolDataSetBase(sharedPool, setId, nullptr, maxNumberOfVariables),
SharedDataSet::SharedDataSet(localpool::SharedPool& sharedPool, uint32_t setId,
const size_t maxNumberOfVariables)
: SharedDatasetBase(sharedPool, setId, nullptr, maxNumberOfVariables),
poolVarList(maxNumberOfVariables) {
this->setContainer(poolVarList.data());
}
LocalDataSet::LocalDataSet(sid_t sid, const size_t maxNumberOfVariables)
: LocalPoolDataSetBase(sid, nullptr, maxNumberOfVariables), poolVarList(maxNumberOfVariables) {
SharedDataSet::SharedDataSet(sid_t sid, const size_t maxNumberOfVariables)
: SharedDatasetBase(sid, nullptr, maxNumberOfVariables), poolVarList(maxNumberOfVariables) {
this->setContainer(poolVarList.data());
}
LocalDataSet::~LocalDataSet() {}
SharedDataSet::~SharedDataSet() {}

View File

@ -3,7 +3,7 @@
#include <vector>
#include "LocalPoolDataSetBase.h"
#include "SharedDatasetBase.h"
/**
* @brief This dataset type can be used to group related pool variables if the number of
@ -18,17 +18,17 @@
* @tparam capacity Capacity of the static dataset, which is usually known
* beforehand.
*/
class LocalDataSet : public LocalPoolDataSetBase {
class SharedDataSet : public SharedDatasetBase {
public:
LocalDataSet(localpool::SharedPool& sharedPool, uint32_t setId, size_t maxSize);
SharedDataSet(localpool::SharedPool& sharedPool, uint32_t setId, size_t maxSize);
LocalDataSet(sid_t sid, size_t maxSize);
SharedDataSet(sid_t sid, size_t maxSize);
virtual ~LocalDataSet();
~SharedDataSet() override;
//! Copying forbidden for now.
LocalDataSet(const LocalDataSet&) = delete;
LocalDataSet& operator=(const LocalDataSet&) = delete;
SharedDataSet(const SharedDataSet&) = delete;
SharedDataSet& operator=(const SharedDataSet&) = delete;
private:
std::vector<PoolVariableIF*> poolVarList;

View File

@ -1,6 +1,7 @@
#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h"
#include <cmath>
#include <set>
#include "fsfw/datapoollocal.h"
#include "fsfw/housekeeping/AcceptsHkPacketsIF.h"
@ -14,27 +15,27 @@
#include "internal/HasLocalDpIFManagerAttorney.h"
#include "internal/LocalPoolDataSetAttorney.h"
// TODO: Get rid of this. This should be a constructor argument, not something hardcoded in any way
object_id_t PeriodicHkGenerationHelper::defaultHkDestination = objects::PUS_SERVICE_3_HOUSEKEEPING;
PeriodicHkGenerationHelper::PeriodicHkGenerationHelper(PeriodicHkGenerationIF* owner,
MessageQueueIF* queueToUse) {
MessageQueueIF* queueToUse,
MessageQueueId_t hkDestQueue)
: hkDestinationId(hkDestQueue) {
if (owner == nullptr) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "LocalDataPoolManager", returnvalue::FAILED,
"Invalid supplied owner");
return;
}
this->owner = owner;
hkQueue = queueToUse;
}
ReturnValue_t PeriodicHkGenerationHelper::initialize(MessageQueueIF* queueToUse) {
if (queueToUse == nullptr) {
if (queueToUse != nullptr) {
hkQueue = queueToUse;
}
if (hkQueue == nullptr) {
// Error, all destinations invalid
printWarningOrError(sif::OutputTypes::OUT_ERROR, "initialize", QUEUE_OR_DESTINATION_INVALID);
}
hkQueue = queueToUse;
ipcStore = ObjectManager::instance()->get<StorageManagerIF>(objects::IPC_STORE);
if (ipcStore == nullptr) {
@ -44,10 +45,10 @@ ReturnValue_t PeriodicHkGenerationHelper::initialize(MessageQueueIF* queueToUse)
return returnvalue::FAILED;
}
if (defaultHkDestination != objects::NO_OBJECT) {
auto* hkPacketReceiver =
ObjectManager::instance()->get<AcceptsHkPacketsIF>(defaultHkDestination);
if (hkPacketReceiver != nullptr) {
if (hkDestinationId == MessageQueueIF::NO_QUEUE) {
if (const auto* hkPacketReceiver =
ObjectManager::instance()->get<AcceptsHkPacketsIF>(objects::PUS_SERVICE_3_HOUSEKEEPING);
hkPacketReceiver != nullptr) {
hkDestinationId = hkPacketReceiver->getHkQueue();
} else {
printWarningOrError(sif::OutputTypes::OUT_ERROR, "initialize", QUEUE_OR_DESTINATION_INVALID);
@ -55,20 +56,19 @@ ReturnValue_t PeriodicHkGenerationHelper::initialize(MessageQueueIF* queueToUse)
}
}
owner->specifyHkDatasets(setList);
owner->specifyHkDatasets(setList);
return returnvalue::OK;
}
ReturnValue_t PeriodicHkGenerationHelper::performHkOperation() {
ReturnValue_t status = returnvalue::OK;
timeval now{};
Clock::getClockMonotonic(&now);
for (auto& setSpec : setList) {
switch (setSpec.reportingType) {
case (periodicHk::ReportingType::PERIODIC): {
if (setSpec.dataType == periodicHk::DataType::LOCAL_POOL_VARIABLE) {
/* Periodic packets shall only be generated from datasets */
// Periodic packets shall only be generated from datasets
continue;
}
performPeriodicHkGeneration(setSpec, now);
@ -79,7 +79,7 @@ ReturnValue_t PeriodicHkGenerationHelper::performHkOperation() {
return returnvalue::FAILED;
}
}
return status;
return returnvalue::OK;
}
ReturnValue_t PeriodicHkGenerationHelper::handleHousekeepingMessage(CommandMessage* message) {
@ -134,9 +134,9 @@ ReturnValue_t PeriodicHkGenerationHelper::handleHousekeepingMessage(CommandMessa
return result;
}
PeriodicHkGenerationIF* PeriodicHkGenerationHelper::getOwner() { return owner; }
PeriodicHkGenerationIF* PeriodicHkGenerationHelper::getOwner() const { return owner; }
ReturnValue_t PeriodicHkGenerationHelper::generateHousekeepingPacket(sid_t sid,
ReturnValue_t PeriodicHkGenerationHelper::generateHousekeepingPacket(const sid_t sid,
MessageQueueId_t destination) {
store_address_t storeId;
auto optSetSpec = getSetSpecification(sid);
@ -303,9 +303,9 @@ ReturnValue_t PeriodicHkGenerationHelper::generateSetStructurePacket(sid_t sid)
}
ReturnValue_t PeriodicHkGenerationHelper::enablePeriodicPacket(
sid_t structureId, std::optional<dur_millis_t> frequencyMs) {
const sid_t structureId, const std::optional<dur_millis_t> frequencyMs) {
// Get and check dataset first.
auto optSetSpec = getSetSpecification(structureId);
const auto optSetSpec = getSetSpecification(structureId);
if (!optSetSpec.has_value()) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration",
DATASET_NOT_FOUND);
@ -319,9 +319,9 @@ ReturnValue_t PeriodicHkGenerationHelper::enablePeriodicPacket(
return returnvalue::OK;
}
ReturnValue_t PeriodicHkGenerationHelper::disablePeriodicPacket(sid_t structureId) {
ReturnValue_t PeriodicHkGenerationHelper::disablePeriodicPacket(const sid_t structureId) {
// Get and check dataset first.
auto optSetSpec = getSetSpecification(structureId);
const auto optSetSpec = getSetSpecification(structureId);
if (!optSetSpec.has_value()) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration",
DATASET_NOT_FOUND);
@ -388,6 +388,10 @@ void PeriodicHkGenerationHelper::printWarningOrError(sif::OutputTypes outputType
#endif /* #if FSFW_VERBOSE_LEVEL >= 1 */
}
void PeriodicHkGenerationHelper::setHkDestinationId(MessageQueueId_t hkDestId) {
void PeriodicHkGenerationHelper::setHkDestinationId(const MessageQueueId_t hkDestId) {
hkDestinationId = hkDestId;
}
}
void PeriodicHkGenerationHelper::addSetSpecification(const periodicHk::SetSpecification& setSpec) {
setList.push_back(setSpec);
}

View File

@ -12,7 +12,6 @@
#include "fsfw/housekeeping/AcceptsHkPacketsIF.h"
#include "fsfw/housekeeping/HousekeepingMessage.h"
#include "fsfw/housekeeping/HousekeepingPacketDownlink.h"
#include "fsfw/housekeeping/PeriodicHousekeepingHelper.h"
#include "fsfw/ipc/CommandMessage.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/ipc/MutexGuard.h"
@ -130,10 +129,10 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF {
* initialize() has to be called in any case before using the object!
* @param owner
* @param queueToUse
* @param appendValidityBuffer Specify whether a buffer containing the
* validity state is generated when serializing or deserializing packets.
*/
PeriodicHkGenerationHelper(PeriodicHkGenerationIF* owner, MessageQueueIF* queueToUse);
PeriodicHkGenerationHelper(PeriodicHkGenerationIF* owner, MessageQueueIF* queueToUse,
MessageQueueId_t hkDestQueue = MessageQueueIF::NO_QUEUE);
void setHkDestinationId(MessageQueueId_t hkDestId);
@ -177,8 +176,9 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF {
ReturnValue_t generateHousekeepingPacket(sid_t sid,
MessageQueueId_t destination = MessageQueueIF::NO_QUEUE);
PeriodicHkGenerationIF* getOwner();
[[nodiscard]] PeriodicHkGenerationIF* getOwner() const;
void addSetSpecification(const periodicHk::SetSpecification& setSpec);
ReturnValue_t printPoolEntry(lp_id_t localPoolId);
/* Copying forbidden */
@ -210,7 +210,8 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF {
std::optional<dur_millis_t> frequencyMs) override;
ReturnValue_t disablePeriodicPacket(sid_t structureId) override;
ReturnValue_t setCollectionInterval(sid_t structureId, dur_millis_t newCollectionIntervalMs);
ReturnValue_t setCollectionInterval(sid_t structureId,
dur_millis_t newCollectionIntervalMs) override;
protected:
std::optional<std::reference_wrapper<periodicHk::SetSpecification>> getSetSpecification(
@ -225,7 +226,6 @@ class PeriodicHkGenerationHelper : public PeriodicHkGenerationProviderIF {
PeriodicHkGenerationIF* owner = nullptr;
/** Default receiver for periodic HK packets */
static object_id_t defaultHkDestination;
MessageQueueId_t hkDestinationId = MessageQueueIF::NO_QUEUE;
/** This vector will contain the list of HK receivers. */

View File

@ -1,32 +1,24 @@
#include <cmath>
#include <cstring>
#include "fsfw/datapoollocal.h"
#include "fsfw/datapoollocal/PeriodicHkGenerationHelper.h"
#include "fsfw/globalfunctions/bitutility.h"
#include "fsfw/housekeeping/PeriodicHousekeepingHelper.h"
#include "fsfw/objectmanager/ObjectManager.h"
#include "fsfw/serialize/SerializeAdapter.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
#include "internal/HasLocalDpIFUserAttorney.h"
LocalPoolDataSetBase::LocalPoolDataSetBase(localpool::SharedPool &sharedPool, uint32_t setId,
PoolVariableIF **registeredVariablesArray,
const size_t maxNumberOfVariables)
SharedDatasetBase::SharedDatasetBase(localpool::SharedPool &sharedPool, uint32_t setId,
PoolVariableIF **registeredVariablesArray,
const size_t maxNumberOfVariables)
: base(registeredVariablesArray, maxNumberOfVariables), sharedPool(&sharedPool) {
mutexIfSingleDataCreator = sharedPool.getLocalPoolMutex();
this->sid.objectId = sharedPool.getOwnerId();
this->sid.ownerSetId = setId;
/* Data creators get a periodic helper for periodic HK data generation. */
// if (periodicHandling) {
// periodicHelper = new PeriodicHousekeepingHelper(this);
//}
}
LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, PoolVariableIF **registeredVariablesArray,
const size_t maxNumberOfVariables)
SharedDatasetBase::SharedDatasetBase(sid_t sid, PoolVariableIF **registeredVariablesArray,
const size_t maxNumberOfVariables)
: base(registeredVariablesArray, maxNumberOfVariables) {
auto *hkOwner = ObjectManager::instance()->get<PeriodicHkGenerationIF>(sid.objectId);
if (hkOwner != nullptr) {
@ -39,14 +31,14 @@ LocalPoolDataSetBase::LocalPoolDataSetBase(sid_t sid, PoolVariableIF **registere
this->sid = sid;
}
LocalPoolDataSetBase::LocalPoolDataSetBase(PoolVariableIF **registeredVariablesArray,
const size_t maxNumberOfVariables,
bool protectEveryReadCommitCall)
SharedDatasetBase::SharedDatasetBase(PoolVariableIF **registeredVariablesArray,
const size_t maxNumberOfVariables,
bool protectEveryReadCommitCall)
: base(registeredVariablesArray, maxNumberOfVariables) {
base.setReadCommitProtectionBehaviour(protectEveryReadCommitCall);
}
LocalPoolDataSetBase::~LocalPoolDataSetBase() {
SharedDatasetBase::~SharedDatasetBase() {
// In case set was read but not comitted, we commit all variables with an invalid state
if (base.state == PoolDataSetBase::States::STATE_SET_WAS_READ) {
for (uint16_t count = 0; count < base.getFillCount(); count++) {
@ -57,25 +49,25 @@ LocalPoolDataSetBase::~LocalPoolDataSetBase() {
}
}
ReturnValue_t LocalPoolDataSetBase::lockDataPool(MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs) {
ReturnValue_t SharedDatasetBase::lockDataPool(MutexIF::TimeoutType timeoutType,
uint32_t timeoutMs) {
if (mutexIfSingleDataCreator != nullptr) {
return mutexIfSingleDataCreator->lockMutex(timeoutType, timeoutMs);
}
return returnvalue::OK;
}
ReturnValue_t LocalPoolDataSetBase::unlockDataPool() {
ReturnValue_t SharedDatasetBase::unlockDataPool() {
if (mutexIfSingleDataCreator != nullptr) {
return mutexIfSingleDataCreator->unlockMutex();
}
return returnvalue::OK;
}
ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t **buffer, size_t *size,
size_t maxSize,
SerializeIF::Endianness streamEndianness,
bool serializeFillCount) const {
ReturnValue_t SharedDatasetBase::serializeLocalPoolIds(uint8_t **buffer, size_t *size,
size_t maxSize,
SerializeIF::Endianness streamEndianness,
bool serializeFillCount) const {
/* Serialize fill count as uint8_t */
uint8_t fillCount = this->getFillCount();
if (serializeFillCount) {
@ -100,7 +92,7 @@ ReturnValue_t LocalPoolDataSetBase::serializeLocalPoolIds(uint8_t **buffer, size
return returnvalue::OK;
}
uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize(bool serializeFillCount) const {
uint8_t SharedDatasetBase::getLocalPoolIdsSerializedSize(bool serializeFillCount) const {
if (serializeFillCount) {
return base.getFillCount() * sizeof(lp_id_t) + sizeof(uint8_t);
} else {
@ -108,60 +100,60 @@ uint8_t LocalPoolDataSetBase::getLocalPoolIdsSerializedSize(bool serializeFillCo
}
}
size_t LocalPoolDataSetBase::getSerializedSize() const { return base.getSerializedSize(); }
size_t SharedDatasetBase::getSerializedSize() const { return base.getSerializedSize(); }
ReturnValue_t LocalPoolDataSetBase::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) {
ReturnValue_t SharedDatasetBase::deSerialize(const uint8_t **buffer, size_t *size,
SerializeIF::Endianness streamEndianness) {
return base.deSerialize(buffer, size, streamEndianness);
}
ReturnValue_t LocalPoolDataSetBase::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
ReturnValue_t SharedDatasetBase::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
return base.serialize(buffer, size, maxSize, streamEndianness);
}
[[nodiscard]] ReturnValue_t LocalPoolDataSetBase::serialize(
[[nodiscard]] ReturnValue_t SharedDatasetBase::serialize(
uint8_t *buffer, size_t &serLen, size_t maxSize,
SerializeIF::Endianness streamEndianness) const {
return SerializeIF::serialize(buffer, serLen, maxSize, streamEndianness);
}
void LocalPoolDataSetBase::setReportingEnabled(bool reportingEnabled) {
void SharedDatasetBase::setReportingEnabled(bool reportingEnabled) {
this->reportingEnabled = reportingEnabled;
}
bool LocalPoolDataSetBase::getReportingEnabled() const { return reportingEnabled; }
bool SharedDatasetBase::getReportingEnabled() const { return reportingEnabled; }
sid_t LocalPoolDataSetBase::getSid() const { return sid; }
sid_t SharedDatasetBase::getSid() const { return sid; }
object_id_t LocalPoolDataSetBase::getCreatorObjectId() {
object_id_t SharedDatasetBase::getCreatorObjectId() {
if (sharedPool != nullptr) {
return sharedPool->getOwnerId();
}
return objects::NO_OBJECT;
}
void LocalPoolDataSetBase::setAllVariablesReadOnly() {
void SharedDatasetBase::setAllVariablesReadOnly() {
for (size_t idx = 0; idx < this->getFillCount(); idx++) {
base.registeredVariables[idx]->setReadWriteMode(pool_rwm_t::VAR_READ);
}
}
void LocalPoolDataSetBase::printSet() { return; }
void SharedDatasetBase::printSet() { return; }
ReturnValue_t LocalPoolDataSetBase::read(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
ReturnValue_t SharedDatasetBase::read(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
return base.read(timeoutType, timeoutMs);
}
ReturnValue_t LocalPoolDataSetBase::commit(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
ReturnValue_t SharedDatasetBase::commit(MutexIF::TimeoutType timeoutType, uint32_t timeoutMs) {
return base.commit(timeoutType, timeoutMs);
}
uint16_t LocalPoolDataSetBase::getFillCount() const { return base.getFillCount(); }
uint16_t SharedDatasetBase::getFillCount() const { return base.getFillCount(); }
ReturnValue_t LocalPoolDataSetBase::registerVariable(PoolVariableIF *variable) {
ReturnValue_t SharedDatasetBase::registerVariable(PoolVariableIF *variable) {
return base.registerVariable(variable);
}
void LocalPoolDataSetBase::setContainer(PoolVariableIF **variablesContainer) {
void SharedDatasetBase::setContainer(PoolVariableIF **variablesContainer) {
return base.setContainer(variablesContainer);
}
PoolVariableIF **LocalPoolDataSetBase::getContainer() const { return base.getContainer(); }
PoolVariableIF **SharedDatasetBase::getContainer() const { return base.getContainer(); }

View File

@ -41,7 +41,7 @@ class PeriodicHousekeepingHelper;
*
* @ingroup data_pool
*/
class LocalPoolDataSetBase : public SerializeIF, public PoolDataSetIF {
class SharedDatasetBase : public SerializeIF, public PoolDataSetIF {
friend class PeriodicHousekeepingHelper;
public:
@ -51,8 +51,8 @@ class LocalPoolDataSetBase : public SerializeIF, public PoolDataSetIF {
* This constructor also initializes the components required for
* periodic handling.
*/
LocalPoolDataSetBase(localpool::SharedPool& sharedPool, uint32_t setId,
PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables);
SharedDatasetBase(localpool::SharedPool& sharedPool, uint32_t setId,
PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables);
/**
* @brief Constructor for users of the local pool data, which need
@ -65,8 +65,8 @@ class LocalPoolDataSetBase : public SerializeIF, public PoolDataSetIF {
* @param registeredVariablesArray
* @param maxNumberOfVariables
*/
LocalPoolDataSetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
size_t maxNumberOfVariables);
SharedDatasetBase(sid_t sid, PoolVariableIF** registeredVariablesArray,
size_t maxNumberOfVariables);
/**
* @brief Simple constructor, if the dataset is not the owner by
@ -86,8 +86,8 @@ class LocalPoolDataSetBase : public SerializeIF, public PoolDataSetIF {
* multiple creators, this flag can be set to protect all read and
* commit calls separately.
*/
LocalPoolDataSetBase(PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables,
bool protectEveryReadCommitCall = true);
SharedDatasetBase(PoolVariableIF** registeredVariablesArray, size_t maxNumberOfVariables,
bool protectEveryReadCommitCall = true);
/**
* @brief The destructor automatically manages writing the valid
@ -97,13 +97,13 @@ class LocalPoolDataSetBase : public SerializeIF, public PoolDataSetIF {
* 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".
*/
~LocalPoolDataSetBase() override;
~SharedDatasetBase() override;
/* The copy constructor and assingment constructor are forbidden for now.
The use-cases are limited and the first step would be to implement them properly for the
base class */
LocalPoolDataSetBase(const LocalPoolDataSetBase& otherSet) = delete;
const LocalPoolDataSetBase& operator=(const LocalPoolDataSetBase& otherSet) = delete;
SharedDatasetBase(const SharedDatasetBase& otherSet) = delete;
const SharedDatasetBase& operator=(const SharedDatasetBase& otherSet) = delete;
/**
* Helper functions used to set all currently contained variables to read-only.

View File

@ -1,21 +1,23 @@
#include "fsfw/datapoollocal/SharedLocalDataSet.h"
#include "fsfw/datapoollocal/SharedLocalDataset.h"
SharedLocalDataSet::SharedLocalDataSet(object_id_t objectId, sid_t sid, const size_t maxSize)
: SystemObject(objectId), LocalPoolDataSetBase(sid, nullptr, maxSize), poolVarVector(maxSize) {
SharedLocalDataset::SharedLocalDataset(object_id_t objectId, sid_t sid, const size_t maxSize)
: SystemObject(objectId), SharedDatasetBase(sid, nullptr, maxSize), poolVarVector(maxSize) {
this->setContainer(poolVarVector.data());
datasetLock = MutexFactory::instance()->createMutex();
}
SharedLocalDataSet::SharedLocalDataSet(object_id_t objectId, localpool::SharedPool& sharedPool,
SharedLocalDataset::SharedLocalDataset(object_id_t objectId, localpool::SharedPool& sharedPool,
uint32_t setId, const size_t maxSize)
: SystemObject(objectId),
LocalPoolDataSetBase(sharedPool, setId, nullptr, maxSize),
SharedDatasetBase(sharedPool, setId, nullptr, maxSize),
poolVarVector(maxSize) {
this->setContainer(poolVarVector.data());
datasetLock = MutexFactory::instance()->createMutex();
}
ReturnValue_t SharedLocalDataSet::lockDataset(MutexIF::TimeoutType timeoutType,
SharedLocalDataset::~SharedLocalDataset() { MutexFactory::instance()->deleteMutex(datasetLock); }
ReturnValue_t SharedLocalDataset::lockDataset(MutexIF::TimeoutType timeoutType,
dur_millis_t mutexTimeout) {
if (datasetLock != nullptr) {
return datasetLock->lockMutex(timeoutType, mutexTimeout);
@ -23,9 +25,7 @@ ReturnValue_t SharedLocalDataSet::lockDataset(MutexIF::TimeoutType timeoutType,
return returnvalue::FAILED;
}
SharedLocalDataSet::~SharedLocalDataSet() { MutexFactory::instance()->deleteMutex(datasetLock); }
ReturnValue_t SharedLocalDataSet::unlockDataset() {
ReturnValue_t SharedLocalDataset::unlockDataset() {
if (datasetLock != nullptr) {
return datasetLock->unlockMutex();
}

View File

@ -5,7 +5,7 @@
#include "../datapool/SharedDataSetIF.h"
#include "../objectmanager/SystemObject.h"
#include "LocalPoolDataSetBase.h"
#include "SharedDatasetBase.h"
/**
* This local dataset variation can be used if the dataset is used concurrently across
@ -15,15 +15,13 @@
* The user is completely responsible for locking and unlocking the dataset when using the
* shared dataset.
*/
class SharedLocalDataSet : public SystemObject,
public LocalPoolDataSetBase,
public SharedDataSetIF {
class SharedLocalDataset : public SystemObject, public SharedDatasetBase, public SharedDataSetIF {
public:
SharedLocalDataSet(object_id_t objectId, localpool::SharedPool& sharedPool, uint32_t setId,
SharedLocalDataset(object_id_t objectId, localpool::SharedPool& sharedPool, uint32_t setId,
size_t maxSize);
SharedLocalDataSet(object_id_t objectId, sid_t sid, size_t maxSize);
SharedLocalDataset(object_id_t objectId, sid_t sid, size_t maxSize);
~SharedLocalDataSet() override;
~SharedLocalDataset() override;
ReturnValue_t lockDataset(MutexIF::TimeoutType timeoutType = MutexIF::TimeoutType::WAITING,
dur_millis_t mutexTimeout = 20) override;

View File

@ -1,12 +1,11 @@
#ifndef FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_
#define FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_
#pragma once
#include <array>
#include "../objectmanager/SystemObjectIF.h"
#include "LocalPoolDataSetBase.h"
#include "LocalPoolVariable.h"
#include "LocalPoolVector.h"
#include "SharedDatasetBase.h"
/**
* @brief This dataset type can be used to group related pool variables if the number of
@ -18,35 +17,32 @@
*
* It is recommended to read the documentation of the LocalPoolDataSetBase
* class for more information on how this class works and how to use it.
* @tparam capacity Capacity of the static dataset, which is usually known
* @tparam NUM_VARIABLES Capacity of the static dataset, which is usually known
* beforehand.
*/
template <uint8_t NUM_VARIABLES>
class StaticLocalDataSet : public LocalPoolDataSetBase {
class StaticSharedDataset : public SharedDatasetBase {
public:
/**
* Constructor used by data owner and creator like device handlers.
* This constructor also initialized the components required for
* periodic handling.
* @param hkOwner
* @param sharedPool Shared pool this dataset will read from or write to.
* @param setId
*/
StaticLocalDataSet(localpool::SharedPool& sharedPool, uint32_t setId)
: LocalPoolDataSetBase(sharedPool, setId, nullptr, NUM_VARIABLES) {
StaticSharedDataset(localpool::SharedPool& sharedPool, uint32_t setId)
: SharedDatasetBase(sharedPool, setId, nullptr, NUM_VARIABLES) {
this->setContainer(poolVarList.data());
}
/**
* Constructor used by data users like controllers.
* @param hkOwner
* @param setId
* @param sid
*/
StaticLocalDataSet(sid_t sid) : LocalPoolDataSetBase(sid, nullptr, NUM_VARIABLES) {
explicit StaticSharedDataset(sid_t sid) : SharedDatasetBase(sid, nullptr, NUM_VARIABLES) {
this->setContainer(poolVarList.data());
}
private:
std::array<PoolVariableIF*, NUM_VARIABLES> poolVarList = {};
};
#endif /* FSFW_DATAPOOLLOCAL_STATICLOCALDATASET_H_ */
};

View File

@ -1,6 +1,5 @@
#include "HasLocalDpIFManagerAttorney.h"
#include "fsfw/datapoollocal/LocalPoolDataSetBase.h"
#include "fsfw/datapoollocal/LocalPoolObjectBase.h"
#include "fsfw/datapoollocal/PeriodicHkGenerationIF.h"

View File

@ -1,26 +1,11 @@
#ifndef FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_
#define FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_
#pragma once
#include "fsfw/datapoollocal/LocalPoolDataSetBase.h"
#include "fsfw/datapoollocal/SharedDatasetBase.h"
class LocalPoolDataSetAttorney {
private:
// static void initializePeriodicHelper(LocalPoolDataSetBase& set, float collectionInterval,
// uint32_t minimumPeriodicIntervalMs) {
// set.initializePeriodicHelper(collectionInterval, minimumPeriodicIntervalMs);
//}
static void setReportingEnabled(LocalPoolDataSetBase& set, bool enabled) {
static void setReportingEnabled(SharedDatasetBase& set, bool enabled) {
set.setReportingEnabled(enabled);
}
static bool getReportingEnabled(LocalPoolDataSetBase& set) { return set.getReportingEnabled(); }
// static PeriodicHousekeepingHelper* getPeriodicHelper(LocalPoolDataSetBase& set) {
// return set.periodicHelper;
//}
friend class PeriodicHkGenerationHelper;
};
#endif /* FSFW_DATAPOOLLOCAL_LOCALPOOLDATASETATTORNEY_H_ */
static bool getReportingEnabled(SharedDatasetBase& set) { return set.getReportingEnabled(); }
};

View File

@ -28,7 +28,7 @@ DeviceHandlerBase::DeviceHandlerBase(object_id_t setObjectId, object_id_t device
storedRawData(StorageManagerIF::INVALID_ADDRESS),
deviceCommunicationId(deviceCommunication),
comCookie(comCookie),
sharedPool(getObjectId()),
sharedPool(DeviceHandlerBase::getObjectId()),
healthHelper(this, setObjectId),
modeHelper(this),
parameterHelper(this),
@ -413,7 +413,7 @@ ReturnValue_t DeviceHandlerBase::isModeCombinationValid(Mode_t mode, Submode_t s
}
ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, LocalPoolDataSetBase* replyDataSet,
DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles, SharedDatasetBase* replyDataSet,
size_t replyLen, bool periodic, bool hasDifferentReplyId, DeviceCommandId_t replyId,
Countdown* countdown) {
// No need to check, as we may try to insert multiple times.
@ -428,7 +428,7 @@ ReturnValue_t DeviceHandlerBase::insertInCommandAndReplyMap(
ReturnValue_t DeviceHandlerBase::insertInReplyMap(DeviceCommandId_t replyId,
uint16_t maxDelayCycles,
LocalPoolDataSetBase* dataSet, size_t replyLen,
SharedDatasetBase* dataSet, size_t replyLen,
bool periodic, Countdown* countdown) {
DeviceReplyInfo info;
info.maxDelayCycles = maxDelayCycles;
@ -529,7 +529,7 @@ ReturnValue_t DeviceHandlerBase::updatePeriodicReply(bool enable, DeviceCommandI
}
ReturnValue_t DeviceHandlerBase::setReplyDataset(DeviceCommandId_t replyId,
LocalPoolDataSetBase* dataSet) {
SharedDatasetBase* dataSet) {
auto replyIter = deviceReplyMap.find(replyId);
if (replyIter == deviceReplyMap.end()) {
return returnvalue::FAILED;
@ -1610,3 +1610,5 @@ ReturnValue_t DeviceHandlerBase::finishAction(bool success, DeviceCommandId_t ac
}
void DeviceHandlerBase::setNormalDatapoolEntriesInvalid() { return; }
PeriodicHkGenerationHelper& DeviceHandlerBase::getHkHelper() { return hkHelper; }

View File

@ -96,7 +96,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
* The constructor passes the objectId to the SystemObject().
*
* @param setObjectId the ObjectId to pass to the SystemObject() Constructor
* @param deviceCommuncation Communcation Interface object which is used
* @param deviceCommunication Communication Interface object which is used
* to implement communication functions
* @param comCookie This object will be passed to the communication inter-
* face and can contain user-defined information about the communication.
@ -109,6 +109,8 @@ class DeviceHandlerBase : public DeviceHandlerIF,
void setCustomFdir(FailureIsolationBase *fdir);
void setPowerSwitcher(PowerSwitchIF *switcher);
PeriodicHkGenerationHelper &getHkHelper();
/**
* extending the modes of DeviceHandler IF for internal state machine
*/
@ -230,7 +232,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
ReturnValue_t initializeAfterTaskCreation() override;
/** Destructor. */
virtual ~DeviceHandlerBase();
~DeviceHandlerBase() override;
/**
* Implementation of ExecutableObjectIF function
@ -238,7 +240,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
* @param task_ Pointer to the taskIF of this task
*/
virtual void setTaskIF(PeriodicTaskIF *task_) override;
virtual MessageQueueId_t getCommandQueue(void) const override;
virtual MessageQueueId_t getCommandQueue() const override;
/** Explicit interface implementation of getObjectId */
virtual object_id_t getObjectId() const override;
@ -506,7 +508,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
* - @c returnvalue::FAILED else.
*/
ReturnValue_t insertInCommandAndReplyMap(DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
LocalPoolDataSetBase *replyDataSet = nullptr,
SharedDatasetBase *replyDataSet = nullptr,
size_t replyLen = 0, bool periodic = false,
bool hasDifferentReplyId = false,
DeviceCommandId_t replyId = 0,
@ -527,7 +529,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
* - @c returnvalue::FAILED else.
*/
ReturnValue_t insertInReplyMap(DeviceCommandId_t deviceCommand, uint16_t maxDelayCycles,
LocalPoolDataSetBase *dataSet = nullptr, size_t replyLen = 0,
SharedDatasetBase *dataSet = nullptr, size_t replyLen = 0,
bool periodic = false, Countdown *countdown = nullptr);
/**
@ -580,7 +582,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
* @details
* Used by the local data pool manager.
*/
ReturnValue_t setReplyDataset(DeviceCommandId_t replyId, LocalPoolDataSetBase *dataset);
ReturnValue_t setReplyDataset(DeviceCommandId_t replyId, SharedDatasetBase *dataset);
/**
* Get the time needed to transit from modeFrom to modeTo.
@ -847,7 +849,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
//! The dataset used to access housekeeping data related to the
//! respective device reply. Will point to a dataset held by
//! the child handler (if one is specified)
LocalPoolDataSetBase *dataSet = nullptr;
SharedDatasetBase *dataSet = nullptr;
//! The command that expects this reply.
DeviceCommandMap::iterator command;
//! Instead of using delayCycles to specify the maximum time to wait for the device reply, it

View File

@ -1,17 +1,19 @@
#ifndef FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_
#define FSFW_DEVICEHANDLERS_DEVICEHANDLERTHERMALSET_H_
#include <fsfw/datapoollocal/StaticSharedDataset.h>
#include "../datapoollocal/LocalPoolVariable.h"
#include "../datapoollocal/StaticLocalDataSet.h"
#include "../datapoollocal/SharedLocalDataset.h"
#include "DeviceHandlerIF.h"
class DeviceHandlerThermalSet : public StaticLocalDataSet<2> {
class DeviceHandlerThermalSet : public StaticSharedDataset<2> {
public:
DeviceHandlerThermalSet(PeriodicHkGenerationIF* hkOwner, ThermalStateCfg cfg)
: DeviceHandlerThermalSet(hkOwner->getObjectId(), cfg) {}
DeviceHandlerThermalSet(object_id_t deviceHandler, ThermalStateCfg cfg)
: StaticLocalDataSet(sid_t(deviceHandler, cfg.thermalSetId)),
: StaticSharedDataset(sid_t(deviceHandler, cfg.thermalSetId)),
thermalStatePoolId(cfg.thermalStatePoolId),
heaterRequestPoolId(cfg.thermalRequestPoolId) {}

View File

@ -8,12 +8,12 @@ FreshDeviceHandlerBase::FreshDeviceHandlerBase(DhbConfig config)
: SystemObject(config.objectId),
actionHelper(this, nullptr),
modeHelper(this),
healthHelper(this, getObjectId()),
healthHelper(this, FreshDeviceHandlerBase::getObjectId()),
paramHelper(this),
hkHelper(this, nullptr),
fdirInstance(config.fdirInstance),
defaultFdirParent(config.defaultFdirParent) {
auto mqArgs = MqArgs(config.objectId, static_cast<void*>(this));
auto mqArgs = MqArgs(config.objectId, this);
messageQueue = QueueFactory::instance()->createMessageQueue(
config.msgQueueDepth, MessageQueueMessage::MAX_MESSAGE_SIZE, &mqArgs);
}
@ -43,7 +43,6 @@ ReturnValue_t FreshDeviceHandlerBase::performDeviceOperationPreQueueHandling(uin
void FreshDeviceHandlerBase::startTransition(Mode_t mode_, Submode_t submode_) {
triggerEvent(CHANGING_MODE, mode_, submode_);
// Complete mode transition immediately by default.
setMode(mode_, submode_);
}

View File

@ -1,2 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE HousekeepingMessage.cpp
PeriodicHousekeepingHelper.cpp)
target_sources(${LIB_FSFW_NAME} PRIVATE HousekeepingMessage.cpp)

View File

@ -1,9 +1,8 @@
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETDOWNLINK_H_
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGPACKETDOWNLINK_H_
#pragma once
#include <fsfw/serialize/SerialBufferAdapter.h>
#include "../datapoollocal/LocalPoolDataSetBase.h"
#include "../datapoollocal/SharedDatasetBase.h"
#include "../serialize/SerialLinkedListAdapter.h"
#include "../storagemanager/StorageManagerIF.h"
@ -35,6 +34,4 @@ class HousekeepingPacketDownlink : public SerialLinkedListAdapter<SerializeIF> {
SerializeElement<object_id_t> sourceId;
SerializeElement<uint32_t> setId;
SerializeElement<SerialBufferAdapter<uint32_t>> hkData;
};
#endif /* FRAMEWORK_HOUSEKEEPING_HOUSEKEEPINGPACKETDOWNLINK_H_ */
};

View File

@ -1,9 +1,6 @@
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_
#pragma once
#include "../datapoollocal/LocalPoolDataSetBase.h"
#include "../housekeeping/HousekeepingMessage.h"
#include "../serialize/SerialLinkedListAdapter.h"
#include "fsfw/serialize/SerialLinkedListAdapter.h"
class HousekeepingSetPacket : public SerialLinkedListAdapter<SerializeIF> {
public:
@ -28,6 +25,4 @@ class HousekeepingSetPacket : public SerialLinkedListAdapter<SerializeIF> {
SerializeElement<uint32_t> setId;
SerializeElement<bool> reportingEnabled;
SerializeElement<uint32_t> collectionIntervalMs;
};
#endif /* FSFW_HOUSEKEEPING_HOUSEKEEPINGSETPACKET_H_ */
};

View File

@ -1,11 +1,11 @@
#ifndef FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_
#define FSFW_HOUSEKEEPING_HOUSEKEEPINGSNAPSHOT_H_
#include "../datapoollocal/LocalPoolDataSetBase.h"
#include "../datapoollocal/LocalPoolObjectBase.h"
#include "../serialize/SerialBufferAdapter.h"
#include "../serialize/SerialLinkedListAdapter.h"
#include "../timemanager/CCSDSTime.h"
#include "fsfw/datapoollocal/SharedDatasetBase.h"
/**
* @brief This helper class will be used to serialize and deserialize update housekeeping packets
@ -20,7 +20,7 @@ class HousekeepingSnapshot : public SerializeIF {
* @param dataSetPtr Pointer to the dataset instance to serialize or deserialize the
* data into
*/
HousekeepingSnapshot(CCSDSTime::CDS_short* cdsShort, LocalPoolDataSetBase* dataSetPtr)
HousekeepingSnapshot(CCSDSTime::CDS_short* cdsShort, SerializeIF* dataSetPtr)
: timeStamp(reinterpret_cast<uint8_t*>(cdsShort)),
timeStampSize(sizeof(CCSDSTime::CDS_short)),
updateData(dataSetPtr) {};
@ -31,27 +31,7 @@ class HousekeepingSnapshot : public SerializeIF {
* @param timeStampSize Size of the timestamp
* @param dataSetPtr Pointer to the dataset instance to deserialize the data into
*/
HousekeepingSnapshot(uint8_t* timeStamp, size_t timeStampSize, LocalPoolDataSetBase* dataSetPtr)
: timeStamp(timeStamp), timeStampSize(timeStampSize), updateData(dataSetPtr) {};
/**
* Update packet constructor for pool variables.
* @param timeStamp
* @param timeStampSize
* @param dataSetPtr
*/
HousekeepingSnapshot(CCSDSTime::CDS_short* cdsShort, LocalPoolObjectBase* dataSetPtr)
: timeStamp(reinterpret_cast<uint8_t*>(cdsShort)),
timeStampSize(sizeof(CCSDSTime::CDS_short)),
updateData(dataSetPtr) {};
/**
* Update packet constructor for pool variables.
* @param timeStamp
* @param timeStampSize
* @param dataSetPtr
*/
HousekeepingSnapshot(uint8_t* timeStamp, size_t timeStampSize, LocalPoolObjectBase* dataSetPtr)
HousekeepingSnapshot(uint8_t* timeStamp, size_t timeStampSize, SerializeIF* dataSetPtr)
: timeStamp(timeStamp), timeStampSize(timeStampSize), updateData(dataSetPtr) {};
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,

View File

@ -1,39 +0,0 @@
#include "fsfw/housekeeping/PeriodicHousekeepingHelper.h"
#include <cmath>
#include "fsfw/datapoollocal/LocalPoolDataSetBase.h"
#include "fsfw/serviceinterface.h"
PeriodicHousekeepingHelper::PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner)
: owner(owner) {}
void PeriodicHousekeepingHelper::initialize(float collectionInterval,
dur_millis_t minimumPeriodicInterval) {
this->minimumPeriodicInterval = minimumPeriodicInterval;
changeCollectionInterval(collectionInterval);
}
float PeriodicHousekeepingHelper::getCollectionIntervalInSeconds() const {
return collectionInterval;
}
bool PeriodicHousekeepingHelper::checkOpNecessary() {
if (hkGenerationCd.hasTimedOut()) {
hkGenerationCd.resetTimer();
return true;
}
return false;
}
void PeriodicHousekeepingHelper::changeCollectionInterval(float newIntervalSeconds) {
uint32_t intervalMs = newIntervalSeconds * 1000;
if (newIntervalSeconds <= 0) {
intervalMs = minimumPeriodicInterval;
newIntervalSeconds = static_cast<float>(minimumPeriodicInterval) / 1000.0;
}
collectionInterval = newIntervalSeconds;
hkGenerationCd.setTimeout(intervalMs);
// We want an immediate HK packet at the start, so time out the generation CD immediately.
hkGenerationCd.timeOut();
}

View File

@ -1,29 +0,0 @@
#ifndef FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
#define FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_
#include <cstdint>
#include "fsfw/timemanager/Clock.h"
#include "fsfw/timemanager/Countdown.h"
class LocalPoolDataSetBase;
class PeriodicHousekeepingHelper {
public:
PeriodicHousekeepingHelper(LocalPoolDataSetBase* owner);
void initialize(float collectionInterval, dur_millis_t minimumPeriodicInterval);
void changeCollectionInterval(float newInterval);
float getCollectionIntervalInSeconds() const;
bool checkOpNecessary();
private:
LocalPoolDataSetBase* owner = nullptr;
Countdown hkGenerationCd;
float collectionInterval = 0.0;
dur_millis_t minimumPeriodicInterval = 0;
};
#endif /* FSFW_HOUSEKEEPING_PERIODICHOUSEKEEPINGHELPER_H_ */

View File

@ -2,18 +2,18 @@
#define FSFW_INTERNALERROR_INTERNALERRORDATASET_H_
#include <fsfw/datapoollocal/LocalPoolVariable.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/datapoollocal/StaticSharedDataset.h>
enum errorPoolIds { TM_HITS = 0, QUEUE_HITS = 1, STORE_HITS = 2, VALID = 3 };
class InternalErrorDataset : public StaticLocalDataSet<3 * sizeof(uint32_t)> {
class InternalErrorDataset : public StaticSharedDataset<4> {
public:
static constexpr uint8_t ERROR_SET_ID = 0;
InternalErrorDataset(localpool::SharedPool& sharedPool)
: StaticLocalDataSet(sharedPool, ERROR_SET_ID) {}
: StaticSharedDataset(sharedPool, ERROR_SET_ID) {}
InternalErrorDataset(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, ERROR_SET_ID)) {}
InternalErrorDataset(object_id_t objectId) : StaticSharedDataset(sid_t(objectId, ERROR_SET_ID)) {}
lp_var_t<uint32_t> tmHits = lp_var_t<uint32_t>(sid.objectId, TM_HITS, this);
lp_var_t<uint32_t> queueHits = lp_var_t<uint32_t>(sid.objectId, QUEUE_HITS, this);

View File

@ -32,17 +32,17 @@ void InternalErrorReporter::setDiagnosticPrintout(bool enable) {
}
ReturnValue_t InternalErrorReporter::initialize() {
ReturnValue_t result = hkHelper.initialize(commandQueue);
if (result != returnvalue::OK) {
return result;
}
ReturnValue_t result = hkHelper.initialize(commandQueue);
if (result != returnvalue::OK) {
return result;
}
sharedPool.addPoolEntry(errorPoolIds::STORE_HITS, &storeHitsEntry);
sharedPool.addPoolEntry(errorPoolIds::TM_HITS, &tmHitsEntry);
sharedPool.addPoolEntry(errorPoolIds::QUEUE_HITS, &queueHitsEntry);
sharedPool.addPoolEntry(errorPoolIds::VALID, &setIsValid);
internalErrorDataset.valid= false;
return SystemObject::initialize();
sharedPool.addPoolEntry(errorPoolIds::STORE_HITS, &storeHitsEntry);
sharedPool.addPoolEntry(errorPoolIds::TM_HITS, &tmHitsEntry);
sharedPool.addPoolEntry(errorPoolIds::QUEUE_HITS, &queueHitsEntry);
sharedPool.addPoolEntry(errorPoolIds::VALID, &setIsValid);
internalErrorDataset.valid = false;
return SystemObject::initialize();
}
ReturnValue_t InternalErrorReporter::performOperation(uint8_t opCode) {
@ -164,8 +164,7 @@ ReturnValue_t InternalErrorReporter::serializeHkDataset(sid_t structureId, uint8
ReturnValue_t InternalErrorReporter::specifyHkDatasets(
std::vector<periodicHk::SetSpecification> &setSpecification) {
setSpecification.emplace_back(internalErrorDataset.getSid(),
internalErrorDataset.getSerializedSize(),
generationFrequency);
internalErrorDataset.getSerializedSize(), generationFrequency);
return returnvalue::OK;
}

View File

@ -77,7 +77,7 @@ class InternalErrorReporter : public SystemObject,
uint32_t queueHits = 0;
uint32_t tmHits = 0;
uint32_t storeHits = 0;
PoolEntry<uint8_t> setIsValid = PoolEntry<uint8_t>();
PoolEntry<uint8_t> setIsValid = PoolEntry<uint8_t>();
PoolEntry<uint32_t> tmHitsEntry = PoolEntry<uint32_t>();
PoolEntry<uint32_t> storeHitsEntry = PoolEntry<uint32_t>();
PoolEntry<uint32_t> queueHitsEntry = PoolEntry<uint32_t>();

View File

@ -54,9 +54,8 @@ ReturnValue_t Clock::getClockMonotonic(timeval* time) {
// generic is kind of awkward..
return returnvalue::FAILED;
#elif defined(PLATFORM_UNIX)
timespec timeMonotonic;
int status = clock_gettime(CLOCK_MONOTONIC_RAW, &timeMonotonic);
if (status != 0) {
timespec timeMonotonic{};
if (const int status = clock_gettime(CLOCK_MONOTONIC_RAW, &timeMonotonic); status != 0) {
return returnvalue::FAILED;
}
time->tv_sec = timeMonotonic.tv_sec;

View File

@ -3,13 +3,14 @@
#include <list>
#include "../datapoollocal/StaticLocalDataSet.h"
#include "../datapoollocal/StaticSharedDataset.h"
#include "../devicehandlers/HealthDevice.h"
#include "../monitoring/AbsLimitMonitor.h"
#include "../parameters/ParameterHelper.h"
#include "../returnvalues/returnvalue.h"
#include "PowerComponentIF.h"
#include "PowerSwitchIF.h"
namespace Factory {
void setStaticFrameworkObjectIds();
}
@ -24,13 +25,13 @@ enum FusePoolId {
};
class FuseSet : public StaticLocalDataSet<6> {
class FuseSet : public StaticSharedDataset<6> {
public:
static constexpr uint8_t FUSE_SET_ID = 0;
FuseSet(localpool::SharedPool &sharedPool) : StaticLocalDataSet(sharedPool, FUSE_SET_ID) {}
FuseSet(localpool::SharedPool &sharedPool) : StaticSharedDataset(sharedPool, FUSE_SET_ID) {}
FuseSet(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, FUSE_SET_ID)) {}
FuseSet(object_id_t objectId) : StaticSharedDataset(sid_t(objectId, FUSE_SET_ID)) {}
lp_var_t<float> voltage = lp_var_t<float>(sid.objectId, FusePoolId::VOLTAGE, this);
lp_var_t<float> current = lp_var_t<float>(sid.objectId, FusePoolId::CURRENT, this);

View File

@ -1,7 +1,7 @@
#ifndef FSFW_POWER_POWERSENSOR_H_
#define FSFW_POWER_POWERSENSOR_H_
#include "fsfw/datapoollocal/StaticLocalDataSet.h"
#include "fsfw/datapoollocal/StaticSharedDataset.h"
#include "fsfw/devicehandlers/HealthDevice.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/monitoring/LimitMonitor.h"
@ -17,14 +17,15 @@ enum PowerSensorPoolId {
SET_VALID = 3
};
class PowerSensorSet : public StaticLocalDataSet<6> {
class PowerSensorSet : public StaticSharedDataset<6> {
public:
static constexpr uint8_t POWER_SENSOR_SET_ID = 0;
PowerSensorSet(localpool::SharedPool &sharedPool)
: StaticLocalDataSet(sharedPool, POWER_SENSOR_SET_ID) {}
: StaticSharedDataset(sharedPool, POWER_SENSOR_SET_ID) {}
PowerSensorSet(object_id_t objectId) : StaticLocalDataSet(sid_t(objectId, POWER_SENSOR_SET_ID)) {}
PowerSensorSet(object_id_t objectId)
: StaticSharedDataset(sid_t(objectId, POWER_SENSOR_SET_ID)) {}
lp_var_t<float> current = lp_var_t<float>(sid.objectId, PowerSensorPoolId::CURRENT, this);
lp_var_t<float> voltage = lp_var_t<float>(sid.objectId, PowerSensorPoolId::VOLTAGE, this);

View File

@ -0,0 +1,49 @@
#pragma once
#include <vector>
#include "SerializeIF.h"
namespace serialize {
class List : public SerializeIF {
public:
void addSerializable(const std::reference_wrapper<SerializeIF> serializable) {
serializables.push_back(serializable);
}
[[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
ReturnValue_t result = returnvalue::OK;
for (auto &serializable : serializables) {
result = serializable.get().serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
}
return result;
}
[[nodiscard]] size_t getSerializedSize() const override {
size_t size = 0;
for (auto &serializable : serializables) {
size += serializable.get().getSerializedSize();
}
return size;
}
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
const Endianness streamEndianness) override {
ReturnValue_t result = returnvalue::OK;
for (auto &serializable : serializables) {
result = serializable.get().deSerialize(buffer, size, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
}
return result;
}
private:
std::vector<std::reference_wrapper<SerializeIF>> serializables;
};
} // namespace serialize

View File

@ -0,0 +1,124 @@
#pragma once
#include <utility>
#include "SerializableList.h"
#include "SerializeAdapter.h"
#include "SerializeIF.h"
namespace serialize {
template <typename T>
class ListElement : public SerializeIF {
public:
template <typename... Args>
explicit ListElement(List& list, Args... args) : entry(std::forward<Args>(args)...) {
list.addSerializable(*this);
}
explicit ListElement(List& list) : entry() { list.addSerializable(*this); }
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override {
return SerializeAdapter::serialize(&entry, buffer, size, maxSize, streamEndianness);
}
[[nodiscard]] size_t getSerializedSize() const override {
return SerializeAdapter::getSerializedSize(&entry);
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override {
return SerializeAdapter::deSerialize(&entry, buffer, size, streamEndianness);
}
explicit operator T() { return entry; }
ListElement& operator=(T newValue) {
entry = newValue;
return *this;
}
T* operator->() { return &entry; }
T get() const { return entry; }
T entry{};
};
template <typename T>
using LE = ListElement<T>;
template <typename T, size_t N>
class ListArrayElement : public SerializeIF {
public:
template <typename... Args>
explicit ListArrayElement(List& list, Args... args) : entry(std::forward<Args>(args)...) {
list.addSerializable(*this);
}
explicit ListArrayElement(List& list) : entry() { list.addSerializable(*this); }
ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize,
Endianness streamEndianness) const override {
ReturnValue_t result = returnvalue::OK;
for (size_t i = 0; i < N; i++) {
result = SerializeAdapter::serialize(entry + i, buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
}
return result;
}
[[nodiscard]] size_t getSerializedSize() const override {
return SerializeAdapter::getSerializedSize(entry) * N;
}
ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) override {
ReturnValue_t result = returnvalue::OK;
for (size_t i = 0; i < N; i++) {
result = SerializeAdapter::deSerialize(entry + i, buffer, size, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
}
return result;
}
explicit operator T() { return entry; }
ListArrayElement& operator=(T newValue[N]) {
entry = newValue;
return *this;
}
// Array subscript operator for access
T& operator[](size_t index) {
// No exceptions, so user takes care of index validation..
return entry[index];
}
const T& operator[](size_t index) const { return entry[index]; }
// Conversion operator
explicit operator T*() { return entry; }
explicit operator const T*() const { return entry; }
// Iterators for range-based for loops and STL compatibility
T* begin() { return std::begin(entry); }
T* end() { return std::end(entry); }
const T* begin() const { return std::begin(entry); }
const T* end() const { return std::end(entry); }
const T* cbegin() const { return std::begin(entry); }
const T* cend() const { return std::end(entry); }
// Additional utility methods
[[nodiscard]] constexpr size_t size() const { return N; }
T entry[N];
};
template <typename T, size_t N>
using LAE = ListArrayElement<T, N>;
} // namespace serialize

View File

@ -37,7 +37,7 @@ class SerializeElement : public SerializeIF, public LinkedElement<SerializeIF> {
return SerializeAdapter::deSerialize(&entry, buffer, size, streamEndianness);
}
operator T() { return entry; }
explicit operator T() { return entry; }
SerializeElement<T> &operator=(T newValue) {
entry = newValue;

View File

@ -35,6 +35,7 @@ class SerializeIF {
MAKE_RETURN_CODE(3); // !< There are too many elements to be deserialized
virtual ~SerializeIF() = default;
/**
* @brief
* Function to serialize the object into a buffer with maxSize. Size represents the written
@ -61,13 +62,6 @@ class SerializeIF {
*/
[[nodiscard]] virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const = 0;
/**
* Forwards to regular @serialize call with big (network) endianness
*/
[[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size,
size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
* Gets the size of a object if it would be serialized in a buffer
@ -97,6 +91,15 @@ class SerializeIF {
*/
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) = 0;
/**
* Forwards to regular @serialize call with big (network) endianness
*/
[[nodiscard]] virtual ReturnValue_t serializeBe(uint8_t **buffer, size_t *size,
size_t maxSize) const {
return serialize(buffer, size, maxSize, SerializeIF::Endianness::NETWORK);
}
/**
* Forwards to regular @deSerialize call with big (network) endianness
*/

View File

@ -3,7 +3,7 @@
ThermalComponent::ThermalComponent(object_id_t reportingObjectId, uint8_t domainId,
gp_id_t temperaturePoolId, gp_id_t targetStatePoolId,
gp_id_t currentStatePoolId, gp_id_t requestPoolId,
LocalPoolDataSetBase* dataSet, AbstractTemperatureSensor* sensor,
SharedDatasetBase* dataSet, AbstractTemperatureSensor* sensor,
AbstractTemperatureSensor* firstRedundantSensor,
AbstractTemperatureSensor* secondRedundantSensor,
ThermalModuleIF* thermalModule, Parameters parameters,

View File

@ -46,7 +46,7 @@ class ThermalComponent : public ThermalComponentCore {
*/
ThermalComponent(object_id_t reportingObjectId, uint8_t domainId, gp_id_t temperaturePoolId,
gp_id_t targetStatePoolId, gp_id_t currentStatePoolId, gp_id_t requestPoolId,
LocalPoolDataSetBase *dataSet, AbstractTemperatureSensor *sensor,
SharedDatasetBase *dataSet, AbstractTemperatureSensor *sensor,
AbstractTemperatureSensor *firstRedundantSensor,
AbstractTemperatureSensor *secondRedundantSensor, ThermalModuleIF *thermalModule,
Parameters parameters, Priority priority);

View File

@ -5,7 +5,7 @@
ThermalComponentCore::ThermalComponentCore(object_id_t reportingObjectId, uint8_t domainId,
gp_id_t temperaturePoolId, gp_id_t targetStatePoolId,
gp_id_t currentStatePoolId, gp_id_t requestPoolId,
LocalPoolDataSetBase* dataSet, Parameters parameters,
SharedDatasetBase* dataSet, Parameters parameters,
StateRequest initialTargetState)
: temperature(temperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE),
targetState(targetStatePoolId, dataSet, PoolVariableIF::VAR_READ),

View File

@ -38,7 +38,7 @@ class ThermalComponentCore : public ThermalComponentIF {
ThermalComponentCore(
object_id_t reportingObjectId, uint8_t domainId, gp_id_t temperaturePoolId,
gp_id_t targetStatePoolId, gp_id_t currentStatePoolId, gp_id_t requestPoolId,
LocalPoolDataSetBase *dataSet, Parameters parameters,
SharedDatasetBase *dataSet, Parameters parameters,
StateRequest initialTargetState = ThermalComponentIF::STATE_REQUEST_OPERATIONAL);
void addSensor(AbstractTemperatureSensor *firstRedundantSensor);

View File

@ -5,7 +5,7 @@
#include "fsfw/thermal/AbstractTemperatureSensor.h"
ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, gp_id_t currentStatePoolId,
gp_id_t targetStatePoolId, LocalPoolDataSetBase* dataSet,
gp_id_t targetStatePoolId, SharedDatasetBase* dataSet,
Parameters parameters, RedundantHeater::Parameters heaterParameters)
: oldStrategy(ACTIVE_SINGLE),
parameters(parameters),
@ -15,7 +15,7 @@ ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, gp_id_t currentSta
heater = new RedundantHeater(heaterParameters);
}
ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, LocalPoolDataSetBase* dataSet)
ThermalModule::ThermalModule(gp_id_t moduleTemperaturePoolId, SharedDatasetBase* dataSet)
: oldStrategy(ACTIVE_SINGLE),
parameters({0, 0}),
moduleTemperature(moduleTemperaturePoolId, dataSet, PoolVariableIF::VAR_WRITE),

View File

@ -3,12 +3,12 @@
#include <list>
#include "../datapoollocal/LocalPoolDataSetBase.h"
#include "../datapoollocal/LocalPoolVariable.h"
#include "../devicehandlers/HealthDevice.h"
#include "../events/EventReportingProxyIF.h"
#include "RedundantHeater.h"
#include "ThermalModuleIF.h"
#include "fsfw/datapoollocal/SharedDatasetBase.h"
#include "tcsDefinitions.h"
class PowerSwitchIF;
@ -26,10 +26,10 @@ class ThermalModule : public ThermalModuleIF {
};
ThermalModule(gp_id_t moduleTemperaturePoolId, gp_id_t currentStatePoolId,
gp_id_t targetStatePoolId, LocalPoolDataSetBase *dataSet, Parameters parameters,
gp_id_t targetStatePoolId, SharedDatasetBase *dataSet, Parameters parameters,
RedundantHeater::Parameters heaterParameters);
ThermalModule(gp_id_t moduleTemperaturePoolId, LocalPoolDataSetBase *dataSet);
ThermalModule(gp_id_t moduleTemperaturePoolId, SharedDatasetBase *dataSet);
virtual ~ThermalModule();

View File

@ -1,7 +1,5 @@
#include <fsfw/datapool/PoolReadGuard.h>
// #include <fsfw/datapoollocal/HasLocalDataPoolIF.h>
#include <fsfw/datapoollocal/SharedLocalDataSet.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/datapoollocal/SharedLocalDataset.h>
#include <fsfw/globalfunctions/bitutility.h>
#include <fsfw/objectmanager/ObjectManager.h>
@ -26,7 +24,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
CHECK(localSet.getReportingEnabled() == false);
CHECK(localSet.getLocalPoolIdsSerializedSize(false) == 3 * sizeof(lp_id_t));
CHECK(localSet.getLocalPoolIdsSerializedSize(true) == 3 * sizeof(lp_id_t) + sizeof(uint8_t));
CHECK(localSet.getSid() == lpool::testSid);
CHECK(localSet.getSid() == lpool::testSid0);
CHECK(localSet.getCreatorObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
size_t maxSize = localSet.getLocalPoolIdsSerializedSize(true);
uint8_t localPoolIdBuff[maxSize];
@ -139,7 +137,7 @@ TEST_CASE("DataSetTest", "[DataSetTest]") {
SECTION("SharedDataSet") {
object_id_t sharedSetId = objects::SHARED_SET_ID;
SharedLocalDataSet sharedSet(sharedSetId, poolOwner.sharedPool, lpool::testSetId, 5);
SharedLocalDataset sharedSet(sharedSetId, poolOwner.sharedPool, lpool::testSetId0, 5);
localSet.localPoolVarUint8.setReadWriteMode(pool_rwm_t::VAR_WRITE);
localSet.localPoolUint16Vec.setReadWriteMode(pool_rwm_t::VAR_WRITE);
CHECK(sharedSet.registerVariable(&localSet.localPoolVarUint8) == returnvalue::OK);

View File

@ -1,8 +1,7 @@
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/datapoollocal/PeriodicHkGenerationHelper.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/datapoollocal/StaticSharedDataset.h>
#include <fsfw/globalfunctions/timevalOperations.h>
#include <fsfw/housekeeping/HousekeepingSnapshot.h>
#include <fsfw/ipc/CommandMessageCleaner.h>
#include <fsfw/objectmanager/ObjectManager.h>
#include <fsfw/timemanager/CCSDSTime.h>
@ -22,21 +21,14 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
const MessageQueueId_t subscriberId = 2;
auto hkReceiver = HkReceiverMock(hkDest);
auto queue = MessageQueueMock(3);
LocalPoolOwnerBase poolOwner(queue, objects::TEST_LOCAL_POOL_OWNER_BASE);
LocalPoolOwnerBase poolOwner(queue, hkDest, objects::TEST_LOCAL_POOL_OWNER_BASE);
REQUIRE(poolOwner.initialize() == returnvalue::OK);
MessageQueueMock& poolOwnerMock = poolOwner.getMockQueueHandle();
// TODO: This is ugly. This should be an arbitrary ctor argument. Fix this in the pool
// manager
poolOwnerMock.setDefaultDestination(defaultDestId);
poolOwner.setHkDestId(hkDest);
CommandMessage messageSent;
// TODO: Fix
/*
SECTION("Basic Test") {
{
// For code coverage, should not crash
@ -46,231 +38,15 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
REQUIRE(owner != nullptr);
CHECK(owner->getObjectId() == objects::TEST_LOCAL_POOL_OWNER_BASE);
// Subscribe for message generation on update.
REQUIRE(poolOwner.subscribeWrapperSetUpdate(subscriberId) == returnvalue::OK);
/// Subscribe for an update message.
poolOwner.dataset.setChanged(true);
// Now the update message should be generated.
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
// Should have been reset.
CHECK(poolOwner.dataset.hasChanged() == false);
poolOwnerMock.clearMessages(true);
// Set changed again, result should be the same.
poolOwner.dataset.setChanged(true);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent() == true);
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
poolOwnerMock.clearMessages(true);
// Now subscribe for set update HK as well.
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == returnvalue::OK);
poolOwner.dataset.setChanged(true);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent() == true);
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
// first message sent should be the update notification
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
// Clear message to avoid memory leak, our mock won't do it for us (yet)
CommandMessageCleaner::clearCommandMessage(&messageSent);
}
SECTION("SetSnapshotUpdateTest") {
// Set the variables in the set to certain values. These are checked later.
{
PoolReadGuard readHelper(&poolOwner.dataset);
REQUIRE(readHelper.getReadResult() == returnvalue::OK);
poolOwner.dataset.localPoolVarUint8.value = 5;
poolOwner.dataset.localPoolVarFloat.value = -12.242;
poolOwner.dataset.localPoolUint16Vec.value[0] = 2;
poolOwner.dataset.localPoolUint16Vec.value[1] = 32;
poolOwner.dataset.localPoolUint16Vec.value[2] = 42932;
}
// Subscribe for snapshot generation on update.
REQUIRE(poolOwner.subscribeWrapperSetUpdateSnapshot(subscriberId) == returnvalue::OK);
poolOwner.dataset.setChanged(true);
// Store current time, we are going to check the (approximate) time equality later
timeval now{};
Clock::getClock_timeval(&now);
// Trigger generation of snapshot
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
// Check that snapshot was generated
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_SET));
// Now we deserialize the snapshot into a new dataset instance
CCSDSTime::CDS_short cdsShort{};
LocalPoolTestDataSet newSet;
HousekeepingSnapshot snapshot(&cdsShort, &newSet);
store_address_t storeId;
HousekeepingMessage::getUpdateSnapshotSetCommand(&messageSent, &storeId);
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
REQUIRE(accessorPair.first == returnvalue::OK);
const uint8_t* readOnlyPtr = accessorPair.second.data();
size_t sizeToDeserialize = accessorPair.second.size();
CHECK(newSet.localPoolVarFloat.value == 0);
CHECK(newSet.localPoolVarUint8 == 0);
CHECK(newSet.localPoolUint16Vec.value[0] == 0);
CHECK(newSet.localPoolUint16Vec.value[1] == 0);
CHECK(newSet.localPoolUint16Vec.value[2] == 0);
// Fill the dataset and timestamp
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
// Now we check that the snapshot is actually correct
CHECK(newSet.localPoolVarFloat.value == Catch::Approx(-12.242));
CHECK(newSet.localPoolVarUint8 == 5);
CHECK(newSet.localPoolUint16Vec.value[0] == 2);
CHECK(newSet.localPoolUint16Vec.value[1] == 32);
CHECK(newSet.localPoolUint16Vec.value[2] == 42932);
// Now we check that both times are equal
timeval timeFromHK{};
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
CHECK(result == returnvalue::OK);
timeval difference = timeFromHK - now;
CHECK(timevalOperations::toDouble(difference) < 1.0);
}
SECTION("VariableSnapshotTest") {
// Acquire subscription interface
PeriodicHkGenerationProviderIF* subscriptionIF = poolOwner.getSubscriptionInterface();
REQUIRE(subscriptionIF != nullptr);
// Subscribe for variable snapshot
REQUIRE(poolOwner.subscribeWrapperVariableSnapshot(subscriberId, lpool::uint8VarId) ==
returnvalue::OK);
auto poolVar =
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
REQUIRE(poolVar != nullptr);
{
PoolReadGuard rg(poolVar);
CHECK(rg.getReadResult() == returnvalue::OK);
poolVar->value = 25;
}
poolVar->setChanged(true);
// Store current time, we are going to check the (approximate) time equality later
CCSDSTime::CDS_short timeCdsNow{};
timeval now{};
Clock::getClock_timeval(&now);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// Check update snapshot was sent.
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
// Should have been reset.
CHECK(poolVar->hasChanged() == false);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_SNAPSHOT_VARIABLE));
// Now we deserialize the snapshot into a new dataset instance
CCSDSTime::CDS_short cdsShort{};
lp_var_t<uint8_t> varCopy = lp_var_t<uint8_t>(lpool::uint8VarGpid);
HousekeepingSnapshot snapshot(&cdsShort, &varCopy);
store_address_t storeId;
HousekeepingMessage::getUpdateSnapshotVariableCommand(&messageSent, &storeId);
ConstAccessorPair accessorPair = tglob::getIpcStoreHandle()->getData(storeId);
REQUIRE(accessorPair.first == returnvalue::OK);
const uint8_t* readOnlyPtr = accessorPair.second.data();
size_t sizeToDeserialize = accessorPair.second.size();
CHECK(varCopy.value == 0);
// Fill the dataset and timestamp
REQUIRE(snapshot.deSerialize(&readOnlyPtr, &sizeToDeserialize,
SerializeIF::Endianness::MACHINE) == returnvalue::OK);
CHECK(varCopy.value == 25);
// Now we check that both times are equal
timeval timeFromHK{};
auto result = CCSDSTime::convertFromCDS(&timeFromHK, &cdsShort);
CHECK(result == returnvalue::OK);
timeval difference = timeFromHK - now;
CHECK(timevalOperations::toDouble(difference) < 1.0);
}
SECTION("VariableNotificationTest") {
// Acquire subscription interface
PeriodicHkGenerationProviderIF* subscriptionIF = poolOwner.getSubscriptionInterface();
REQUIRE(subscriptionIF != nullptr);
// Subscribe for variable update
REQUIRE(poolOwner.subscribeWrapperVariableUpdate(subscriberId, lpool::uint8VarId) ==
returnvalue::OK);
auto* poolVar =
dynamic_cast<lp_var_t<uint8_t>*>(poolOwner.getPoolObjectHandle(lpool::uint8VarId));
REQUIRE(poolVar != nullptr);
poolVar->setChanged(true);
REQUIRE(poolVar->hasChanged() == true);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// Check update notification was sent.
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
// Should have been reset.
CHECK(poolVar->hasChanged() == false);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
// Now subscribe for the dataset update (HK and update) again with subscription interface
REQUIRE(subscriptionIF->subscribeForSetUpdateMessage(lpool::testSetId, objects::NO_OBJECT,
subscriberId, false) == returnvalue::OK);
REQUIRE(poolOwner.subscribeWrapperSetUpdateHk(false, &hkReceiver) == returnvalue::OK);
poolOwner.dataset.setChanged(true);
poolOwnerMock.clearMessages();
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// Now two messages should be sent.
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 2);
poolOwnerMock.clearMessages(true);
poolOwner.dataset.setChanged(true);
poolOwnerMock.clearMessages(true);
poolVar->setChanged(true);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// Now three messages should be sent.
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 3);
CHECK(poolOwnerMock.numberOfSentMessagesToDest(subscriberId) == 2);
CHECK(poolOwnerMock.numberOfSentMessagesToDest(hkDest) == 1);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_VARIABLE));
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() ==
static_cast<int>(HousekeepingMessage::UPDATE_NOTIFICATION_SET));
REQUIRE(poolOwnerMock.clearLastSentMessage(subscriberId) == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == returnvalue::OK);
CHECK(messageSent.getCommand() == static_cast<int>(HousekeepingMessage::HK_REPORT));
REQUIRE(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
REQUIRE(poolOwnerMock.getNextSentMessage(subscriberId, messageSent) == MessageQueueIF::EMPTY);
REQUIRE(poolOwnerMock.getNextSentMessageToDefaultDest(messageSent) == MessageQueueIF::EMPTY);
}
SECTION("PeriodicHKAndMessaging") {
//Now we subcribe for a HK periodic generation. Even when it's difficult to simulate
//the temporal behaviour correctly the HK manager should generate a HK packet
//immediately and the periodic helper depends on HK op function calls anyway instead of
//using the clock, so we could also just call performHkOperation multiple times
// Now we subcribe for a HK periodic generation. Even when it's difficult to simulate
// the temporal behaviour correctly the HK manager should generate a HK packet
// immediately and the periodic helper depends on HK op function calls anyway instead of
// using the clock, so we could also just call performHkOperation multiple times
REQUIRE(poolOwner.subscribePeriodicHk(true) == returnvalue::OK);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
// Now HK packet should be sent as message immediately.
@ -278,43 +54,40 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
LocalPoolDataSetBase* setHandle = poolOwner.getDataSetHandle(lpool::testSid);
REQUIRE(setHandle != nullptr);
CHECK(poolOwner.hkHelper.generateHousekeepingPacket(lpool::testSid, setHandle, false) ==
returnvalue::OK);
CHECK(poolOwner.hkHelper.generateHousekeepingPacket(lpool::testSid0) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == true);
// CHECK(setHandle->getReportingEnabled() == true);
CommandMessage hkCmd;
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, false);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == false);
// CHECK(setHandle->getReportingEnabled() == false);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, true);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == true);
// CHECK(setHandle->getReportingEnabled() == true);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, false);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(setHandle->getReportingEnabled() == false);
// CHECK(setHandle->getReportingEnabled() == false);
REQUIRE(poolOwnerMock.wasMessageSent());
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4);
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid0, 0.4);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK_THAT(poolOwner.dataset.getCollectionInterval(), Catch::Matchers::WithinAbs(0.4, 0.01));
// CHECK_THAT(poolOwner.dataset.getCollectionInterval(), Catch::Matchers::WithinAbs(0.4, 0.01));
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
CHECK(poolOwnerMock.clearLastSentMessage() == returnvalue::OK);
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid);
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid0);
REQUIRE(poolOwner.hkHelper.performHkOperation() == returnvalue::OK);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
// Now HK packet should be sent as message.
@ -322,73 +95,47 @@ TEST_CASE("Local Pool Manager Tests", "[LocManTest]") {
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid);
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid0);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setUpdateNotificationSetCommand(&hkCmd, lpool::testSid);
sid_t sidToCheck;
store_address_t storeId;
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
CHECK(sidToCheck == lpool::testSid);
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid);
HousekeepingMessage::setStructureReportingCommand(&hkCmd, lpool::testSid0);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid, 0.4);
HousekeepingMessage::setCollectionIntervalModificationCommand(&hkCmd, lpool::testSid0, 0.4);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, true);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, true);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid, false);
HousekeepingMessage::setToggleReportingCommand(&hkCmd, lpool::testSid0, false);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid);
HousekeepingMessage::setOneShotReportCommand(&hkCmd, lpool::testSid0);
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
REQUIRE(poolOwnerMock.wasMessageSent());
REQUIRE(poolOwnerMock.numberOfSentMessages() == 1);
poolOwnerMock.clearMessages();
HousekeepingMessage::setUpdateNotificationVariableCommand(&hkCmd, lpool::uint8VarGpid);
gp_id_t gpidToCheck;
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
CHECK(gpidToCheck == lpool::uint8VarGpid);
HousekeepingMessage::setUpdateSnapshotSetCommand(&hkCmd, lpool::testSid,
store_address_t::invalid());
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedDataSetCallbackWasCalled(sidToCheck, storeId) == true);
CHECK(sidToCheck == lpool::testSid);
HousekeepingMessage::setUpdateSnapshotVariableCommand(&hkCmd, lpool::uint8VarGpid,
store_address_t::invalid());
CHECK(poolOwner.hkHelper.handleHousekeepingMessage(&hkCmd) == returnvalue::OK);
CHECK(poolOwner.changedVariableCallbackWasCalled(gpidToCheck, storeId) == true);
CHECK(gpidToCheck == lpool::uint8VarGpid);
poolOwner.hkHelper.printPoolEntry(lpool::uint8VarId);
// poolOwner.hkHelper.printPoolEntry(lpool::uint8VarId);
}
// we need to reset the subscription list because the pool owner
//is a global object.
// is a global object.
CHECK(poolOwner.reset() == returnvalue::OK);
poolOwnerMock.clearMessages(true);
*/
}

View File

@ -1,3 +1,6 @@
#include <mocks/HkReceiverMock.h>
#include <mocks/MessageQueueMock.h>
#include <catch2/catch_test_macros.hpp>
#include "DeviceHandlerCommander.h"
@ -11,9 +14,13 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
// Will be deleted with DHB destructor
auto* cookieIFMock = new CookieIFMock;
ComIFMock comIF(objects::COM_IF_MOCK);
MessageQueueMock mqMock(1);
HkReceiverMock hkReceiver(1);
DeviceFdirMock deviceFdirMock(objects::DEVICE_HANDLER_MOCK, objects::NO_OBJECT);
DeviceHandlerMock deviceHandlerMock(objects::DEVICE_HANDLER_MOCK, objects::COM_IF_MOCK,
cookieIFMock, &deviceFdirMock);
auto& hkHelper = deviceHandlerMock.getHkHelper();
hkHelper.setHkDestinationId(1);
ReturnValue_t result = deviceHandlerMock.initialize();
REQUIRE(result == returnvalue::OK);
DeviceHandlerCommander deviceHandlerCommander(objects::DEVICE_HANDLER_COMMANDER);

View File

@ -90,7 +90,7 @@ void DeviceHandlerMock::changeSimpleCommandReplyCountdown(uint32_t timeout) {
void DeviceHandlerMock::resetPeriodicReplyState() { periodicReplyReceived = false; }
bool DeviceHandlerMock::getPeriodicReplyReceived() { return periodicReplyReceived; }
bool DeviceHandlerMock::getPeriodicReplyReceived() const { return periodicReplyReceived; }
ReturnValue_t DeviceHandlerMock::enablePeriodicReply(DeviceCommandId_t replyId) {
return updatePeriodicReply(true, replyId);
@ -109,7 +109,8 @@ ReturnValue_t DeviceHandlerMock::initialize() {
return result;
}
ReturnValue_t DeviceHandlerMock::serializeHkDataset(sid_t structureId, uint8_t *buf, size_t maxSize) {
ReturnValue_t DeviceHandlerMock::serializeHkDataset(sid_t structureId, uint8_t *buf,
size_t maxSize) {
return returnvalue::OK;
}

View File

@ -5,19 +5,19 @@
class DeviceHandlerMock : public DeviceHandlerBase {
public:
static const DeviceCommandId_t SIMPLE_COMMAND = 1;
static const DeviceCommandId_t PERIODIC_REPLY = 2;
static constexpr DeviceCommandId_t SIMPLE_COMMAND = 1;
static constexpr DeviceCommandId_t PERIODIC_REPLY = 2;
static const uint8_t SIMPLE_COMMAND_DATA = 1;
static const uint8_t PERIODIC_REPLY_DATA = 2;
static constexpr uint8_t SIMPLE_COMMAND_DATA = 1;
static constexpr uint8_t PERIODIC_REPLY_DATA = 2;
DeviceHandlerMock(object_id_t objectId, object_id_t deviceCommunication, CookieIF *comCookie,
FailureIsolationBase *fdirInstance);
virtual ~DeviceHandlerMock();
~DeviceHandlerMock() override;
void changePeriodicReplyCountdown(uint32_t timeout);
void changeSimpleCommandReplyCountdown(uint32_t timeout);
void resetPeriodicReplyState();
bool getPeriodicReplyReceived();
bool getPeriodicReplyReceived() const;
ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId);
ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId);
@ -46,7 +46,7 @@ class DeviceHandlerMock : public DeviceHandlerBase {
Countdown simpleCommandReplyTimeout = Countdown(1000);
Countdown periodicReplyCountdown = Countdown(1000);
uint8_t commandBuffer[1];
uint8_t commandBuffer[1]{};
bool periodicReplyReceived = false;
};

View File

@ -1,11 +1,15 @@
#include "LocalPoolOwnerBase.h"
LocalPoolOwnerBase::LocalPoolOwnerBase(MessageQueueIF &queue, object_id_t objectId)
#include <fsfw/datapool/PoolReadGuard.h>
LocalPoolOwnerBase::LocalPoolOwnerBase(MessageQueueIF &queue, MessageQueueId_t hkDestId,
object_id_t objectId)
: SystemObject(objectId),
queue(queue),
sharedPool(getObjectId()),
hkHelper(this, &queue),
dataset(sharedPool, lpool::testSetId) {}
hkHelper(this, &queue, hkDestId),
sharedPool(LocalPoolOwnerBase::getObjectId()),
set1(sharedPool, lpool::testSetId1),
set2(sharedPool, lpool::testSetId2),
queue(queue) {}
LocalPoolOwnerBase::~LocalPoolOwnerBase() = default;
@ -68,15 +72,15 @@ ReturnValue_t LocalPoolOwnerBase::reset() {
// resetSubscriptionList();
ReturnValue_t status = returnvalue::OK;
{
PoolReadGuard readHelper(&dataset);
PoolReadGuard readHelper(&set1);
if (readHelper.getReadResult() != returnvalue::OK) {
status = readHelper.getReadResult();
}
dataset.localPoolVarUint8.value = 0;
dataset.localPoolVarFloat.value = 0.0;
dataset.localPoolUint16Vec.value[0] = 0;
dataset.localPoolUint16Vec.value[1] = 0;
dataset.localPoolUint16Vec.value[2] = 0;
set1.localPoolVarUint8.value = 0;
set1.localPoolVarFloat.value = 0.0;
set1.localPoolUint16Vec.value[0] = 0;
set1.localPoolUint16Vec.value[1] = 0;
set1.localPoolUint16Vec.value[2] = 0;
// dataset.setValidity(false, true);
}
@ -101,28 +105,4 @@ ReturnValue_t LocalPoolOwnerBase::reset() {
return status;
}
bool LocalPoolOwnerBase::changedDataSetCallbackWasCalled(sid_t &sid, store_address_t &storeId) {
bool condition = false;
if (not this->changedDatasetSid.notSet()) {
condition = true;
}
sid = changedDatasetSid;
storeId = storeIdForChangedSet;
this->changedDatasetSid.raw = sid_t::INVALID_SID;
this->storeIdForChangedSet = store_address_t::invalid();
return condition;
}
bool LocalPoolOwnerBase::changedVariableCallbackWasCalled(gp_id_t &gpid, store_address_t &storeId) {
bool condition = false;
if (not this->changedPoolVariableGpid.notSet()) {
condition = true;
}
gpid = changedPoolVariableGpid;
storeId = storeIdForChangedVariable;
this->changedPoolVariableGpid.raw = gp_id_t::INVALID_GPID;
this->storeIdForChangedVariable = store_address_t::invalid();
return condition;
}
void LocalPoolOwnerBase::setHkDestId(MessageQueueId_t id) { hkHelper.setHkDestinationId(id); }

View File

@ -1,12 +1,11 @@
#ifndef FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
#define FSFW_UNITTEST_TESTS_DATAPOOLLOCAL_LOCALPOOLOWNERBASE_H_
#include <fsfw/datapool/PoolReadGuard.h>
#include <fsfw/datapoollocal/LocalDataSet.h>
#include <fsfw/datapoollocal/LocalPoolVariable.h>
#include <fsfw/datapoollocal/LocalPoolVector.h>
#include <fsfw/datapoollocal/PeriodicHkGenerationHelper.h>
#include <fsfw/datapoollocal/StaticLocalDataSet.h>
#include <fsfw/datapoollocal/StaticSharedDataset.h>
#include <fsfw/ipc/QueueFactory.h>
#include <fsfw/objectmanager/SystemObject.h>
@ -21,10 +20,14 @@ static constexpr lp_id_t uint32VarId = 2;
static constexpr lp_id_t uint16Vec3Id = 3;
static constexpr lp_id_t int64Vec2Id = 4;
static constexpr uint32_t testSetId = 0;
static constexpr uint32_t testSetId0 = 0;
static constexpr uint32_t testSetId1 = 1;
static constexpr uint32_t testSetId2 = 2;
static constexpr uint8_t dataSetMaxVariables = 10;
static const sid_t testSid = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId);
static const auto testSid0 = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId0);
static const auto testSid1 = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId1);
static const auto testSid2 = sid_t(objects::TEST_LOCAL_POOL_OWNER_BASE, testSetId2);
static const gp_id_t uint8VarGpid = gp_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, uint8VarId);
static const gp_id_t floatVarGpid = gp_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, floatVarId);
@ -33,12 +36,12 @@ static const gp_id_t uint16Vec3Gpid = gp_id_t(objects::TEST_LOCAL_POOL_OWNER_BAS
static const gp_id_t uint64Vec2Id = gp_id_t(objects::TEST_LOCAL_POOL_OWNER_BASE, int64Vec2Id);
} // namespace lpool
class LocalPoolStaticTestDataSet : public StaticLocalDataSet<3> {
class LocalPoolStaticTestDataSet : public StaticSharedDataset<3> {
public:
LocalPoolStaticTestDataSet() : StaticLocalDataSet(lpool::testSid) {}
LocalPoolStaticTestDataSet() : StaticSharedDataset(lpool::testSid1) {}
LocalPoolStaticTestDataSet(localpool::SharedPool& sharedPool, uint32_t setId)
: StaticLocalDataSet(sharedPool, setId) {}
: StaticSharedDataset(sharedPool, setId) {}
lp_var_t<uint8_t> localPoolVarUint8 = lp_var_t<uint8_t>(lpool::uint8VarGpid, this);
lp_var_t<float> localPoolVarFloat = lp_var_t<float>(lpool::floatVarGpid, this);
@ -47,12 +50,12 @@ class LocalPoolStaticTestDataSet : public StaticLocalDataSet<3> {
private:
};
class LocalPoolTestDataSet : public LocalDataSet {
class LocalPoolTestDataSet : public SharedDataSet {
public:
LocalPoolTestDataSet() : LocalDataSet(lpool::testSid, lpool::dataSetMaxVariables) {}
LocalPoolTestDataSet() : SharedDataSet(lpool::testSid2, lpool::dataSetMaxVariables) {}
LocalPoolTestDataSet(localpool::SharedPool& sharedPool, uint32_t setId)
: LocalDataSet(sharedPool, setId, lpool::dataSetMaxVariables) {}
: SharedDataSet(sharedPool, setId, lpool::dataSetMaxVariables) {}
lp_var_t<uint8_t> localPoolVarUint8 = lp_var_t<uint8_t>(lpool::uint8VarGpid, this);
lp_var_t<float> localPoolVarFloat = lp_var_t<float>(lpool::floatVarGpid, this);
@ -63,7 +66,7 @@ class LocalPoolTestDataSet : public LocalDataSet {
class LocalPoolOwnerBase : public SystemObject, public PeriodicHkGenerationIF {
public:
explicit LocalPoolOwnerBase(MessageQueueIF& queue,
explicit LocalPoolOwnerBase(MessageQueueIF& queue, MessageQueueId_t hkDestId,
object_id_t objectId = objects::TEST_LOCAL_POOL_OWNER_BASE);
~LocalPoolOwnerBase() override;
@ -79,8 +82,6 @@ class LocalPoolOwnerBase : public SystemObject, public PeriodicHkGenerationIF {
void setHkDestId(MessageQueueId_t id);
// ReturnValue_t initializeHkManagerAfterTaskCreation();
/** Command queue for housekeeping messages. */
[[nodiscard]] MessageQueueId_t getCommandQueue() const override { return queue.getId(); }
@ -91,25 +92,17 @@ class LocalPoolOwnerBase : public SystemObject, public PeriodicHkGenerationIF {
}
ReturnValue_t subscribePeriodicHk(bool enableReporting) {
return hkHelper.enablePeriodicPacket(lpool::testSid, 200);
return hkHelper.enablePeriodicPacket(lpool::testSid0, 50);
}
ReturnValue_t reset();
bool changedDataSetCallbackWasCalled(sid_t& sid, store_address_t& storeId);
bool changedVariableCallbackWasCalled(gp_id_t& gpid, store_address_t& storeId);
PeriodicHkGenerationHelper hkHelper;
localpool::SharedPool sharedPool;
LocalPoolTestDataSet dataset;
LocalPoolTestDataSet set1;
LocalPoolStaticTestDataSet set2;
private:
sid_t changedDatasetSid;
store_address_t storeIdForChangedSet;
gp_id_t changedPoolVariableGpid;
store_address_t storeIdForChangedVariable;
PoolEntry<uint8_t> u8PoolEntry = PoolEntry<uint8_t>({0});
PoolEntry<float> floatPoolEntry = PoolEntry<float>({0});
PoolEntry<uint32_t> u32PoolEntry = PoolEntry<uint32_t>({0});

View File

@ -1,3 +1,4 @@
target_sources(
${FSFW_TEST_TGT} PRIVATE testSerialBufferAdapter.cpp testSerializeAdapter.cpp
testSerialLinkedPacket.cpp testSerializeIF.cpp)
${FSFW_TEST_TGT}
PRIVATE testSerialBufferAdapter.cpp testSerializeAdapter.cpp
testSerialLinkedPacket.cpp testSerializeIF.cpp testList.cpp)

View File

@ -0,0 +1,94 @@
#include <catch2/catch_test_macros.hpp>
#include "fsfw/serialize/SerializableList.h"
#include "fsfw/serialize/SerializableListElement.h"
using namespace serialize;
class ExampleSet0 : public List {
public:
LE<uint8_t> val0{*this};
LE<uint32_t> val1{*this};
LAE<uint16_t, 3> val2{*this};
};
using namespace returnvalue;
TEST_CASE("Serial List", "[serialize]") {
ExampleSet0 set0;
uint8_t buf[1024]{};
size_t serSize = 0;
size_t dummy = 0;
SECTION("serialization default") {
uint8_t* ptr = buf;
CHECK(set0.getSerializedSize() == 11);
const ReturnValue_t result =
set0.serialize(&ptr, &serSize, sizeof(buf), SerializeIF::Endianness::NETWORK);
CHECK(result == returnvalue::OK);
CHECK(ptr == buf + 11);
CHECK(buf[0] == 0);
uint32_t u32Val = 0;
CHECK(SerializeAdapter::deSerialize(&u32Val, buf + 1, &dummy,
SerializeIF::Endianness::NETWORK) == OK);
CHECK(u32Val == 0);
uint16_t u16Val = 0;
for (uint32_t i = 0; i < 3; i++) {
CHECK(SerializeAdapter::deSerialize(&u16Val, buf + 5, &dummy,
SerializeIF::Endianness::NETWORK) == OK);
CHECK(u16Val == 0);
}
}
SECTION("serialization with values") {
uint8_t* ptr = buf;
set0.val0 = 240;
set0.val1 = 0x1f1f1f1f;
set0.val2[0] = 0x1f1f;
set0.val2[1] = 0xf1f1;
set0.val2[2] = 0x4242;
const ReturnValue_t result =
set0.serialize(&ptr, &serSize, sizeof(buf), SerializeIF::Endianness::NETWORK);
CHECK(result == returnvalue::OK);
dummy = set0.getSerializedSize();
CHECK(ptr == buf + 11);
CHECK(buf[0] == 240);
const uint8_t* cPtr = buf + 1;
uint32_t u32Val = 0;
CHECK(SerializeAdapter::deSerialize(&u32Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
OK);
CHECK(u32Val == 0x1f1f1f1f);
uint16_t u16Val = 0;
CHECK(SerializeAdapter::deSerialize(&u16Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
OK);
CHECK(u16Val == 0x1f1f);
CHECK(SerializeAdapter::deSerialize(&u16Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
OK);
CHECK(u16Val == 0xf1f1);
CHECK(SerializeAdapter::deSerialize(&u16Val, &cPtr, &dummy, SerializeIF::Endianness::NETWORK) ==
OK);
CHECK(u16Val == 0x4242);
}
SECTION("deserialization with values") {
uint8_t* ptr = buf;
set0.val0 = 240;
set0.val1 = 0x1f1f1f1f;
set0.val2[0] = 0x1f1f;
set0.val2[1] = 0xf1f1;
set0.val2[2] = 0x4242;
const ReturnValue_t result =
set0.serialize(&ptr, &serSize, sizeof(buf), SerializeIF::Endianness::NETWORK);
CHECK(result == returnvalue::OK);
const uint8_t* cPtr = buf;
dummy = set0.getSerializedSize();
ExampleSet0 deserSet;
CHECK(deserSet.deSerialize(&cPtr, &dummy, SerializeIF::Endianness::NETWORK) == returnvalue::OK);
CHECK(deserSet.val0.get() == 240);
CHECK(deserSet.val1.get() == 0x1f1f1f1f);
CHECK(deserSet.val2[0] == 0x1f1f);
CHECK(deserSet.val2[1] == 0xf1f1);
CHECK(deserSet.val2[2] == 0x4242);
CHECK(dummy == 0);
}
}