From 753d587b69717710017b1a3983625ac7360d7eb6 Mon Sep 17 00:00:00 2001 From: Ulrich Mohr Date: Tue, 18 Jul 2023 13:17:34 +0200 Subject: [PATCH] valid flags in housekeeping tm --- src/fsfw/datapool/DataSetEntry.h | 120 ------------------ src/fsfw/datapool/Dataset.h | 7 +- src/fsfw/datapool/DatasetEntry.h | 54 ++++++++ src/fsfw/datapool/DatasetEntryIF.h | 16 --- ...ekeepingEntry.h => No_HousekeepingEntry.h} | 0 src/fsfw/housekeeping/HousekeepingSet.cpp | 75 ++++++++++- src/fsfw/housekeeping/HousekeepingSet.h | 2 +- src/fsfw/introspection/EnumCommon.h | 2 +- src/fsfw/introspection/EnumIF.h | 2 +- src/fsfw/introspection/Parameter.h | 4 +- src/fsfw/introspection/ParameterIF.h | 2 +- src/fsfw/introspection/TypesHelper.h | 4 +- 12 files changed, 137 insertions(+), 151 deletions(-) delete mode 100644 src/fsfw/datapool/DataSetEntry.h create mode 100644 src/fsfw/datapool/DatasetEntry.h rename src/fsfw/datapool/{HousekeepingEntry.h => No_HousekeepingEntry.h} (100%) diff --git a/src/fsfw/datapool/DataSetEntry.h b/src/fsfw/datapool/DataSetEntry.h deleted file mode 100644 index 41ea0e950..000000000 --- a/src/fsfw/datapool/DataSetEntry.h +++ /dev/null @@ -1,120 +0,0 @@ -#pragma once - -#include - -#include "Dataset.h" -#include -#include -#include "DatasetEntryIF.h" -// TODO: ifdef introspection stuff - - - -template -class DatasetEntry : public DatasetEntryIF { - protected: -#ifdef FSFW_INTROSPECTION - DataSetEntry(Dataset *owner, const char *name) - : name(name) -#else - DataSetEntry(Dataset *owner) -#endif - { - owner->registerDataSetEntry(this); - } - - public: -#ifdef FSFW_INTROSPECTION - static DataSetEntry createDataSetEntry(Dataset *owner, const char *name) { - return DataSetEntry(owner, name); - } -#else - static DataSetEntry createDataSetEntry(Dataset *owner) { return DataSetEntry(owner); } -#endif - - bool isValid() override { - return enumHelper::value>::isValid(&value); - } - - operator T(){ - return value; - } - - DataSetEntry& operator =(const T& newValue){ - value = newValue; - return *this; - } - -#ifdef FSFW_INTROSPECTION - Types::DataSetEntryType getType() override { - return enumHelper::value>::template getType(); - } -#endif - - T value; - - ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, - Endianness streamEndianness) const override { - return SerializeAdapter::serialize(&value, buffer, size, maxSize, streamEndianness); - } - - size_t getSerializedSize() const override { return SerializeAdapter::getSerializedSize(&value); } - - ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, - Endianness streamEndianness) override { - return SerializeAdapter::deSerialize(&value, buffer, size, streamEndianness); - } - -#ifdef FSFW_INTROSPECTION - double getFloating() override { return (double)value; } - int64_t getSigned() override { return (int64_t)value; } - - bool setFloating(double value) override { - if (getType() != Types::FLOATING) { - return false; - } - this->value = T(value); - return true; - } - - bool setSigned(int64_t value) override { - if ((getType() != Types::SIGNED) && (getType() != Types::ENUM)) { - return false; - } - this->value = T(value); - return true; - } - - double getMinFloating() override { - return enumHelper::value>::template getMin(); - } - int64_t getMinSigned() override { - return enumHelper::value>::template getMin(); - } - - double getMaxFloating() override { - return enumHelper::value>::template getMax(); - } - int64_t getMaxSigned() override { - return enumHelper::value>::template getMax(); - } - - std::vector getEnumValues() override { - return enumHelper::value>::getEnumValues(&value); - } - const char *const *getEnumDescriptions() override { - return enumHelper::value>::getEnumDescriptions(&value); - } - - const char *getName() override { return name; } - - private: - const char *name; -#endif -}; - -#ifdef FSFW_INTROSPECTION -#define createDataSetEntry(p1, p2) createDataSetEntry(p1, p2) -#else -#define createDataSetEntry(p1, p2) createDataSetEntry(p1) -#endif \ No newline at end of file diff --git a/src/fsfw/datapool/Dataset.h b/src/fsfw/datapool/Dataset.h index a1093d5dd..39484311b 100644 --- a/src/fsfw/datapool/Dataset.h +++ b/src/fsfw/datapool/Dataset.h @@ -1,12 +1,12 @@ #pragma once +#include #include #include #include #include -#include - #include + #include #include "DatasetEntryIF.h" @@ -43,7 +43,7 @@ class HasDatapoolIF; * interpretDeviceReply) */ -class Dataset: public HousekeepingSet { +class Dataset : public HousekeepingSet { protected: #ifdef FSFW_INTROSPECTION Dataset(HasDatapoolIF* owner, bool allowUserCommit); @@ -158,6 +158,7 @@ class Dataset: public HousekeepingSet { bool registerEntry(DatasetEntryIF*); protected: + bool allocated; bool allowUserCommit; union { diff --git a/src/fsfw/datapool/DatasetEntry.h b/src/fsfw/datapool/DatasetEntry.h new file mode 100644 index 000000000..07d267aa3 --- /dev/null +++ b/src/fsfw/datapool/DatasetEntry.h @@ -0,0 +1,54 @@ +#pragma once + +#include +#include +#include +#include + +#include "Dataset.h" +#include "DatasetEntryIF.h" +// TODO: ifdef introspection stuff + +template +class DatasetEntry : public Parameter, public DatasetEntryIF { + protected: +#ifdef FSFW_INTROSPECTION + DatasetEntry(Dataset *owner, const char *name) + : Parameter(owner, name) +#else + DatasetEntry(Dataset *owner) + : Parameter(owner) +#endif + { + owner->registerEntry(this); + } + + public: +#ifdef FSFW_INTROSPECTION + static DatasetEntry createDatasetEntry(Dataset *owner, const char *name) { + return DatasetEntry(owner, name); + } +#else + static DatasetEntry createDatasetEntry(Dataset *owner) { return DatasetEntry(owner); } +#endif + + virtual void setValid(bool isValid) { valid = isValid; } + + virtual bool getValid() { return valid; } + + protected: + virtual void commit() {} + virtual void read() {} + virtual void connect(DatasetEntryIF *entry) {} + + virtual bool changed() { return false; } + + private: + bool valid; +}; + +#ifdef FSFW_INTROSPECTION +#define createDatasetEntry(p1, p2) createDatasetEntry(p1, p2) +#else +#define createDatasetEntry(p1, p2) createDatasetEntry(p1) +#endif \ No newline at end of file diff --git a/src/fsfw/datapool/DatasetEntryIF.h b/src/fsfw/datapool/DatasetEntryIF.h index 9835fe86c..903792378 100644 --- a/src/fsfw/datapool/DatasetEntryIF.h +++ b/src/fsfw/datapool/DatasetEntryIF.h @@ -21,22 +21,6 @@ class DatasetEntryIF { virtual bool getValid() = 0; -#ifdef FSFW_INTROSPECTION - - virtual const char *getName() = 0; - - virtual Types::ParameterType getType() = 0; - - virtual double getFloating() = 0; - virtual int64_t getSigned() = 0; - - virtual bool setFloating(double value) = 0; - virtual bool setSigned(int64_t value) = 0; - - virtual std::vector getEnumValues() = 0; - virtual const char *const * getEnumDescriptions() = 0; -#endif - protected: virtual void commit() = 0; virtual void read() = 0; diff --git a/src/fsfw/datapool/HousekeepingEntry.h b/src/fsfw/datapool/No_HousekeepingEntry.h similarity index 100% rename from src/fsfw/datapool/HousekeepingEntry.h rename to src/fsfw/datapool/No_HousekeepingEntry.h diff --git a/src/fsfw/housekeeping/HousekeepingSet.cpp b/src/fsfw/housekeeping/HousekeepingSet.cpp index cc65007fa..c54b8ab6a 100644 --- a/src/fsfw/housekeeping/HousekeepingSet.cpp +++ b/src/fsfw/housekeeping/HousekeepingSet.cpp @@ -1,5 +1,7 @@ #include "HousekeepingSet.h" +#include + #include "GeneratesHousekeepingIF.h" #ifdef FSFW_INTROSPECTION @@ -39,20 +41,56 @@ ReturnValue_t HousekeepingSet::serialize(uint8_t** buffer, size_t* size, size_t if (result != returnvalue::OK) { return result; } - for (auto parameter : *getParameters()) { + for (auto parameter : parameterList) { result = parameter->serialize(buffer, size, maxSize, streamEndianness); if (result != returnvalue::OK) { return result; } } - return result; + + // Fill valid flags + size_t index = 0; + for (auto parameter : parameterList) { + size_t byteIndex = index / 8; + size_t bitIndex = index % 8; + if (*size + byteIndex > maxSize) { // TODO audition me + return SerializeIF::STREAM_TOO_SHORT; + } + + /** + * check if the parameter is a datasetParameter which knows its validity + * If not, just set to valid + */ + DatasetEntryIF* dataSetParameter = dynamic_cast(parameter); + if (dataSetParameter != nullptr) { + if (dataSetParameter->getValid()) { + (*buffer)[byteIndex] |= (1 << bitIndex); + } else { + (*buffer)[byteIndex] &= ~(1 << bitIndex); + } + } else { + (*buffer)[byteIndex] |= (1 << bitIndex); + } + index++; + } + + *size += (parameterList.size() - 1) / 8 + 1; + if (*size > maxSize) { + // how did we end up here + return SerializeIF::STREAM_TOO_SHORT; + } + *buffer += (parameterList.size() - 1) / 8 + 1; + + return returnvalue::OK; } size_t HousekeepingSet::getSerializedSize() const { size_t size = SerializeAdapter::getSerializedSize(&id); - for (auto parameter : *getParameters()) { + for (auto parameter : parameterList) { size += parameter->getSerializedSize(); } + const size_t validBytes = (parameterList.size() - 1) / 8 + 1; + size += validBytes; return size; } @@ -72,7 +110,36 @@ ReturnValue_t HousekeepingSet::deSerialize(const uint8_t** buffer, size_t* size, return result; } } - return result; + + // read valid flags + size_t index = 0; + for (auto parameter : parameterList) { + size_t byteIndex = index / 8; + size_t bitIndex = index % 8; + if (byteIndex > *size) { // TODO audition me + return SerializeIF::BUFFER_TOO_SHORT; + } + + /** + * check if the parameter is a datasetParameter which knows its validity + * If not, just set to valid + */ + DatasetEntryIF* dataSetParameter = dynamic_cast(parameter); + if (dataSetParameter != nullptr) { + bool valid = ((*buffer)[byteIndex] & (1 << bitIndex)) != 0; + dataSetParameter->setValid(valid); + } + index++; + } + + if (*size < (parameterList.size() - 1) / 8 + 1) { + // how did we end up here + return SerializeIF::BUFFER_TOO_SHORT; + } + *size -= (parameterList.size() - 1) / 8 + 1; + *buffer += (parameterList.size() - 1) / 8 + 1; + + return returnvalue::OK; } void HousekeepingSet::registerParameter(ParameterIF* parameter) { diff --git a/src/fsfw/housekeeping/HousekeepingSet.h b/src/fsfw/housekeeping/HousekeepingSet.h index 2b6fed718..d0f781c11 100644 --- a/src/fsfw/housekeeping/HousekeepingSet.h +++ b/src/fsfw/housekeeping/HousekeepingSet.h @@ -27,7 +27,7 @@ class HousekeepingSet : public HasTmTcParametersIF, public SerializeIF { HousekeepingSetId_t getId() const { return id; } - void report(const Action* action = nullptr); + virtual void report(const Action* action = nullptr); std::vector const* getParameters() const override; diff --git a/src/fsfw/introspection/EnumCommon.h b/src/fsfw/introspection/EnumCommon.h index 7d5523b4f..ddf3c2596 100644 --- a/src/fsfw/introspection/EnumCommon.h +++ b/src/fsfw/introspection/EnumCommon.h @@ -20,7 +20,7 @@ return BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_FOR_EACH(GET_KEY, "", enum_elements)); \ } #define VALUE_CHECK(type) \ - bool isValid() const override { \ + bool isValueValid() const override { \ for (size_t i = 0; i < sizeof(elements) / sizeof(elements[0]); i++) { \ if (value == elements[i]) { \ return true; \ diff --git a/src/fsfw/introspection/EnumIF.h b/src/fsfw/introspection/EnumIF.h index 07f542581..d5badeb59 100644 --- a/src/fsfw/introspection/EnumIF.h +++ b/src/fsfw/introspection/EnumIF.h @@ -7,7 +7,7 @@ class EnumIF { public: virtual ~EnumIF() {} virtual int64_t getValue() const = 0; - virtual bool isValid() const = 0; + virtual bool isValueValid() const = 0; virtual size_t getSize() const = 0; virtual size_t getIndex(int64_t value) const = 0; virtual const int64_t *getElements() const = 0; diff --git a/src/fsfw/introspection/Parameter.h b/src/fsfw/introspection/Parameter.h index 5e5aa9c8f..5a5eb85f0 100644 --- a/src/fsfw/introspection/Parameter.h +++ b/src/fsfw/introspection/Parameter.h @@ -32,8 +32,8 @@ class Parameter : public ParameterIF { static Parameter createParameter(HasTmTcParametersIF *owner) { return Parameter(owner); } #endif - bool isValid() override { - return enumHelper::value>::isValid(&value); + bool isValueValid() override { + return enumHelper::value>::isValueValid(&value); } operator T(){ diff --git a/src/fsfw/introspection/ParameterIF.h b/src/fsfw/introspection/ParameterIF.h index 05cc5e697..902be4cb1 100644 --- a/src/fsfw/introspection/ParameterIF.h +++ b/src/fsfw/introspection/ParameterIF.h @@ -9,7 +9,7 @@ class ParameterIF : public SerializeIF { public: - virtual bool isValid() = 0; + virtual bool isValueValid() = 0; //TODO change name to resolve confusion with valid flag #ifdef FSFW_INTROSPECTION diff --git a/src/fsfw/introspection/TypesHelper.h b/src/fsfw/introspection/TypesHelper.h index d864e77a0..0ab1e3d8d 100644 --- a/src/fsfw/introspection/TypesHelper.h +++ b/src/fsfw/introspection/TypesHelper.h @@ -13,7 +13,7 @@ class enumHelper; template <> class enumHelper { public: - static bool isValid(EnumIF *anEnum) { return anEnum->isValid(); } + static bool isValueValid(EnumIF *anEnum) { return anEnum->isValueValid(); } #ifdef FSFW_INTROSPECTION template @@ -50,7 +50,7 @@ class enumHelper { template <> class enumHelper { public: - static bool isValid(void *) { return true; } + static bool isValueValid(void *) { return true; } #ifdef FSFW_INTROSPECTION template