some improvements

This commit is contained in:
Robin Müller 2024-11-13 14:12:23 +01:00
parent 02bd667376
commit d251d7ed02
Signed by: muellerr
GPG Key ID: A649FB78196E3849
5 changed files with 37 additions and 13 deletions

View File

@ -1,13 +1,13 @@
#ifndef MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
#define MISSION_DEVICES_DEVICEDEFINITIONS_MGMHANDLERRM3100DEFINITIONS_H_
#include <cstdint>
#include "fsfw/datapoollocal/LocalPoolVariable.h"
#include "fsfw/datapoollocal/StaticLocalDataSet.h"
#include "fsfw/devicehandlers/DeviceHandlerIF.h"
#include "fsfw/serialize/SerialLinkedListAdapter.h"
#include <cstdint>
namespace mgmRm3100 {
/* Actually 10, we round up a little bit */

View File

@ -139,7 +139,7 @@ GeneratesPeriodicHkIF* PeriodicHelper::getOwner() const { return owner; }
ReturnValue_t PeriodicHelper::generateHousekeepingPacket(const dp::sid_t sid,
MessageQueueId_t destination) {
store_address_t storeId;
const auto optSetSpec = getSetSpecification(sid);
const auto optSetSpec = getMutSetSpecification(sid);
if (!optSetSpec.has_value()) {
return DATASET_NOT_FOUND;
}
@ -212,7 +212,7 @@ void PeriodicHelper::performPeriodicHkGeneration(SetSpecification& setSpec, time
}
ReturnValue_t PeriodicHelper::togglePeriodicGeneration(const dp::sid_t sid, const bool enable) {
const auto optSetSpec = getSetSpecification(sid);
const auto optSetSpec = getMutSetSpecification(sid);
if (!optSetSpec.has_value()) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "togglePeriodicGeneration",
DATASET_NOT_FOUND);
@ -222,7 +222,7 @@ ReturnValue_t PeriodicHelper::togglePeriodicGeneration(const dp::sid_t sid, cons
return returnvalue::OK;
}
std::optional<std::reference_wrapper<SetSpecification>> PeriodicHelper::getSetSpecification(
std::optional<std::reference_wrapper<SetSpecification>> PeriodicHelper::getMutSetSpecification(
dp::sid_t structureId) {
for (auto& receiver : setList) {
if (receiver.dataId.sid == structureId) {
@ -232,6 +232,16 @@ std::optional<std::reference_wrapper<SetSpecification>> PeriodicHelper::getSetSp
return std::nullopt;
}
std::optional<std::reference_wrapper<const SetSpecification>> PeriodicHelper::getSetSpecification(
dp::sid_t structureId) const {
for (const auto& receiver : setList) {
if (receiver.dataId.sid == structureId) {
return receiver;
}
}
return std::nullopt;
}
ReturnValue_t PeriodicHelper::setCollectionInterval(dp::sid_t sid,
dur_millis_t newCollectionIntervalMs) {
bool wasUpdated = false;
@ -250,7 +260,7 @@ ReturnValue_t PeriodicHelper::setCollectionInterval(dp::sid_t sid,
ReturnValue_t PeriodicHelper::generateSetStructurePacket(dp::structure_id_t sid) {
// Get and check dataset first.
auto optSetSpec = getSetSpecification(sid);
auto optSetSpec = getMutSetSpecification(sid);
if (!optSetSpec.has_value()) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration",
DATASET_NOT_FOUND);
@ -301,10 +311,8 @@ ReturnValue_t PeriodicHelper::generateSetStructurePacket(dp::structure_id_t sid)
ReturnValue_t PeriodicHelper::enablePeriodicPacket(const dp::structure_id_t structureId,
const std::optional<dur_millis_t> frequencyMs) {
// Get and check dataset first.
const auto optSetSpec = getSetSpecification(structureId);
const auto optSetSpec = getMutSetSpecification(structureId);
if (!optSetSpec.has_value()) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration",
DATASET_NOT_FOUND);
return DATASET_NOT_FOUND;
}
auto& setSpec = optSetSpec.value().get();
@ -317,10 +325,8 @@ ReturnValue_t PeriodicHelper::enablePeriodicPacket(const dp::structure_id_t stru
ReturnValue_t PeriodicHelper::disablePeriodicPacket(const dp::structure_id_t structureId) {
// Get and check dataset first.
const auto optSetSpec = getSetSpecification(structureId);
const auto optSetSpec = getMutSetSpecification(structureId);
if (!optSetSpec.has_value()) {
printWarningOrError(sif::OutputTypes::OUT_WARNING, "performPeriodicHkGeneration",
DATASET_NOT_FOUND);
return DATASET_NOT_FOUND;
}
auto& setSpec = optSetSpec.value().get();
@ -328,6 +334,17 @@ ReturnValue_t PeriodicHelper::disablePeriodicPacket(const dp::structure_id_t str
return returnvalue::OK;
}
ReturnValue_t PeriodicHelper::collectionEnabled(dp::sid_t structureId,
bool& collectionEnabled) const {
// Get and check dataset first.
const auto optSetSpec = getSetSpecification(structureId);
if (!optSetSpec.has_value()) {
return DATASET_NOT_FOUND;
}
auto& setSpec = optSetSpec.value().get();
collectionEnabled = setSpec.periodicCollectionEnabled;
return returnvalue::OK;
}
object_id_t PeriodicHelper::getCreatorObjectId() const { return owner->getObjectId(); }
void PeriodicHelper::printWarningOrError(sif::OutputTypes outputType, const char* functionName,

View File

@ -145,13 +145,17 @@ class PeriodicHelper : public PeriodicHelperIF {
ReturnValue_t enablePeriodicPacket(dp::sid_t structureId,
std::optional<dur_millis_t> frequencyMs) override;
ReturnValue_t disablePeriodicPacket(dp::sid_t structureId) override;
ReturnValue_t collectionEnabled(dp::sid_t structureId, bool& collectionEnabled) const override;
ReturnValue_t setCollectionInterval(dp::sid_t structureId,
dur_millis_t newCollectionIntervalMs) override;
std::optional<std::reference_wrapper<SetSpecification>> getSetSpecification(
std::optional<std::reference_wrapper<SetSpecification>> getMutSetSpecification(
dp::sid_t structureId);
std::optional<std::reference_wrapper<const SetSpecification>> getSetSpecification(
dp::sid_t structureId) const;
protected:
std::optional<dur_millis_t> getCollectionFrequency(dp::sid_t structureId);

View File

@ -18,6 +18,7 @@ class PeriodicHelperIF {
virtual ReturnValue_t enablePeriodicPacket(dp::sid_t structureId,
std::optional<dur_millis_t> frequencyMs) = 0;
virtual ReturnValue_t disablePeriodicPacket(dp::sid_t structureId) = 0;
virtual ReturnValue_t collectionEnabled(dp::sid_t structureId, bool& collectionEnabled) const = 0;
};
} // namespace hk

View File

@ -11,6 +11,8 @@ class List : public SerializeIF {
serializables.push_back(serializable);
}
size_t getNumberOfSerializables() const { return serializables.size(); }
[[nodiscard]] ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override {
ReturnValue_t result = returnvalue::OK;