valid flags in housekeeping tm
This commit is contained in:
parent
979a7b7d75
commit
753d587b69
@ -1,120 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#include "Dataset.h"
|
|
||||||
#include <fsfw/introspection/Types.h>
|
|
||||||
#include <fsfw/introspection/TypesHelper.h>
|
|
||||||
#include "DatasetEntryIF.h"
|
|
||||||
// TODO: ifdef introspection stuff
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
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<std::is_base_of<EnumIF, T>::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<std::is_base_of<EnumIF, T>::value>::template getType<T>();
|
|
||||||
}
|
|
||||||
#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<std::is_base_of<EnumIF, T>::value>::template getMin<T>();
|
|
||||||
}
|
|
||||||
int64_t getMinSigned() override {
|
|
||||||
return enumHelper<std::is_base_of<EnumIF, T>::value>::template getMin<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
double getMaxFloating() override {
|
|
||||||
return enumHelper<std::is_base_of<EnumIF, T>::value>::template getMax<T>();
|
|
||||||
}
|
|
||||||
int64_t getMaxSigned() override {
|
|
||||||
return enumHelper<std::is_base_of<EnumIF, T>::value>::template getMax<T>();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<int64_t> getEnumValues() override {
|
|
||||||
return enumHelper<std::is_base_of<EnumIF, T>::value>::getEnumValues(&value);
|
|
||||||
}
|
|
||||||
const char *const *getEnumDescriptions() override {
|
|
||||||
return enumHelper<std::is_base_of<EnumIF, T>::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
|
|
@ -1,12 +1,12 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <fsfw/housekeeping/HousekeepingSet.h>
|
||||||
#include <fsfw/introspection/Enum.h>
|
#include <fsfw/introspection/Enum.h>
|
||||||
#include <fsfw/ipc/MutexIF.h>
|
#include <fsfw/ipc/MutexIF.h>
|
||||||
#include <fsfw/returnvalues/returnvalue.h>
|
#include <fsfw/returnvalues/returnvalue.h>
|
||||||
#include <fsfw/storagemanager/storeAddress.h>
|
#include <fsfw/storagemanager/storeAddress.h>
|
||||||
#include <fsfw/housekeeping/HousekeepingSet.h>
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "DatasetEntryIF.h"
|
#include "DatasetEntryIF.h"
|
||||||
@ -43,7 +43,7 @@ class HasDatapoolIF;
|
|||||||
* interpretDeviceReply)
|
* interpretDeviceReply)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class Dataset: public HousekeepingSet {
|
class Dataset : public HousekeepingSet {
|
||||||
protected:
|
protected:
|
||||||
#ifdef FSFW_INTROSPECTION
|
#ifdef FSFW_INTROSPECTION
|
||||||
Dataset(HasDatapoolIF* owner, bool allowUserCommit);
|
Dataset(HasDatapoolIF* owner, bool allowUserCommit);
|
||||||
@ -158,6 +158,7 @@ class Dataset: public HousekeepingSet {
|
|||||||
bool registerEntry(DatasetEntryIF*);
|
bool registerEntry(DatasetEntryIF*);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
bool allocated;
|
bool allocated;
|
||||||
bool allowUserCommit;
|
bool allowUserCommit;
|
||||||
union {
|
union {
|
||||||
|
54
src/fsfw/datapool/DatasetEntry.h
Normal file
54
src/fsfw/datapool/DatasetEntry.h
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <fsfw/introspection/Parameter.h>
|
||||||
|
#include <fsfw/introspection/Types.h>
|
||||||
|
#include <fsfw/introspection/TypesHelper.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "Dataset.h"
|
||||||
|
#include "DatasetEntryIF.h"
|
||||||
|
// TODO: ifdef introspection stuff
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
class DatasetEntry : public Parameter<T>, public DatasetEntryIF {
|
||||||
|
protected:
|
||||||
|
#ifdef FSFW_INTROSPECTION
|
||||||
|
DatasetEntry(Dataset *owner, const char *name)
|
||||||
|
: Parameter<T>(owner, name)
|
||||||
|
#else
|
||||||
|
DatasetEntry(Dataset *owner)
|
||||||
|
: Parameter<T>(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
|
@ -21,22 +21,6 @@ class DatasetEntryIF {
|
|||||||
virtual bool getValid() = 0;
|
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<int64_t> getEnumValues() = 0;
|
|
||||||
virtual const char *const * getEnumDescriptions() = 0;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void commit() = 0;
|
virtual void commit() = 0;
|
||||||
virtual void read() = 0;
|
virtual void read() = 0;
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
#include "HousekeepingSet.h"
|
#include "HousekeepingSet.h"
|
||||||
|
|
||||||
|
#include <fsfw/datapool/DatasetEntryIF.h>
|
||||||
|
|
||||||
#include "GeneratesHousekeepingIF.h"
|
#include "GeneratesHousekeepingIF.h"
|
||||||
|
|
||||||
#ifdef FSFW_INTROSPECTION
|
#ifdef FSFW_INTROSPECTION
|
||||||
@ -39,20 +41,56 @@ ReturnValue_t HousekeepingSet::serialize(uint8_t** buffer, size_t* size, size_t
|
|||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
for (auto parameter : *getParameters()) {
|
for (auto parameter : parameterList) {
|
||||||
result = parameter->serialize(buffer, size, maxSize, streamEndianness);
|
result = parameter->serialize(buffer, size, maxSize, streamEndianness);
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
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<DatasetEntryIF*>(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 HousekeepingSet::getSerializedSize() const {
|
||||||
size_t size = SerializeAdapter::getSerializedSize(&id);
|
size_t size = SerializeAdapter::getSerializedSize(&id);
|
||||||
for (auto parameter : *getParameters()) {
|
for (auto parameter : parameterList) {
|
||||||
size += parameter->getSerializedSize();
|
size += parameter->getSerializedSize();
|
||||||
}
|
}
|
||||||
|
const size_t validBytes = (parameterList.size() - 1) / 8 + 1;
|
||||||
|
size += validBytes;
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,7 +110,36 @@ ReturnValue_t HousekeepingSet::deSerialize(const uint8_t** buffer, size_t* size,
|
|||||||
return result;
|
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<DatasetEntryIF*>(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) {
|
void HousekeepingSet::registerParameter(ParameterIF* parameter) {
|
||||||
|
@ -27,7 +27,7 @@ class HousekeepingSet : public HasTmTcParametersIF, public SerializeIF {
|
|||||||
|
|
||||||
HousekeepingSetId_t getId() const { return id; }
|
HousekeepingSetId_t getId() const { return id; }
|
||||||
|
|
||||||
void report(const Action* action = nullptr);
|
virtual void report(const Action* action = nullptr);
|
||||||
|
|
||||||
std::vector<ParameterIF*> const* getParameters() const override;
|
std::vector<ParameterIF*> const* getParameters() const override;
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
return BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_FOR_EACH(GET_KEY, "", enum_elements)); \
|
return BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_FOR_EACH(GET_KEY, "", enum_elements)); \
|
||||||
}
|
}
|
||||||
#define VALUE_CHECK(type) \
|
#define VALUE_CHECK(type) \
|
||||||
bool isValid() const override { \
|
bool isValueValid() const override { \
|
||||||
for (size_t i = 0; i < sizeof(elements) / sizeof(elements[0]); i++) { \
|
for (size_t i = 0; i < sizeof(elements) / sizeof(elements[0]); i++) { \
|
||||||
if (value == elements[i]) { \
|
if (value == elements[i]) { \
|
||||||
return true; \
|
return true; \
|
||||||
|
@ -7,7 +7,7 @@ class EnumIF {
|
|||||||
public:
|
public:
|
||||||
virtual ~EnumIF() {}
|
virtual ~EnumIF() {}
|
||||||
virtual int64_t getValue() const = 0;
|
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 getSize() const = 0;
|
||||||
virtual size_t getIndex(int64_t value) const = 0;
|
virtual size_t getIndex(int64_t value) const = 0;
|
||||||
virtual const int64_t *getElements() const = 0;
|
virtual const int64_t *getElements() const = 0;
|
||||||
|
@ -32,8 +32,8 @@ class Parameter : public ParameterIF {
|
|||||||
static Parameter createParameter(HasTmTcParametersIF *owner) { return Parameter(owner); }
|
static Parameter createParameter(HasTmTcParametersIF *owner) { return Parameter(owner); }
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
bool isValid() override {
|
bool isValueValid() override {
|
||||||
return enumHelper<std::is_base_of<EnumIF, T>::value>::isValid(&value);
|
return enumHelper<std::is_base_of<EnumIF, T>::value>::isValueValid(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
operator T(){
|
operator T(){
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
|
|
||||||
class ParameterIF : public SerializeIF {
|
class ParameterIF : public SerializeIF {
|
||||||
public:
|
public:
|
||||||
virtual bool isValid() = 0;
|
virtual bool isValueValid() = 0; //TODO change name to resolve confusion with valid flag
|
||||||
#ifdef FSFW_INTROSPECTION
|
#ifdef FSFW_INTROSPECTION
|
||||||
|
|
||||||
|
|
||||||
|
@ -13,7 +13,7 @@ class enumHelper;
|
|||||||
template <>
|
template <>
|
||||||
class enumHelper<true> {
|
class enumHelper<true> {
|
||||||
public:
|
public:
|
||||||
static bool isValid(EnumIF *anEnum) { return anEnum->isValid(); }
|
static bool isValueValid(EnumIF *anEnum) { return anEnum->isValueValid(); }
|
||||||
|
|
||||||
#ifdef FSFW_INTROSPECTION
|
#ifdef FSFW_INTROSPECTION
|
||||||
template <typename T>
|
template <typename T>
|
||||||
@ -50,7 +50,7 @@ class enumHelper<true> {
|
|||||||
template <>
|
template <>
|
||||||
class enumHelper<false> {
|
class enumHelper<false> {
|
||||||
public:
|
public:
|
||||||
static bool isValid(void *) { return true; }
|
static bool isValueValid(void *) { return true; }
|
||||||
|
|
||||||
#ifdef FSFW_INTROSPECTION
|
#ifdef FSFW_INTROSPECTION
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user