WIP Datapool
This commit is contained in:
parent
531d8c45e8
commit
33a2fb48e5
@ -13,6 +13,8 @@
|
||||
#include "../introspection/Enum.h"
|
||||
#endif
|
||||
|
||||
//TODO ActionId_t
|
||||
|
||||
class Action: public SerializeIF {
|
||||
public:
|
||||
#ifdef FSFW_INTROSPECTION
|
||||
|
120
src/fsfw/datapool/DataSetEntry.h
Normal file
120
src/fsfw/datapool/DataSetEntry.h
Normal file
@ -0,0 +1,120 @@
|
||||
#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,10 @@
|
||||
#include "DatapoolHelper.h"
|
||||
|
||||
#include "Dataset.h"
|
||||
|
||||
DatapoolHelper::DatapoolHelper() {}
|
||||
|
||||
DatapoolHelper::~DatapoolHelper() {}
|
||||
|
||||
const Dataset* DatapoolHelper::getDataSet(uint8_t id) {
|
||||
const Dataset* DatapoolHelper::getDataSet(DataSetId_t id) {
|
||||
auto iter = dataSets.find(id);
|
||||
if (iter == dataSets.end()) {
|
||||
return nullptr;
|
||||
@ -16,5 +14,5 @@ const Dataset* DatapoolHelper::getDataSet(uint8_t id) {
|
||||
|
||||
void DatapoolHelper::registerSet(Dataset* set) {
|
||||
auto id = set->getId();
|
||||
dataSets.insert(std::pair<uint8_t, Dataset*>(id, set));
|
||||
dataSets.emplace(id, set);
|
||||
}
|
@ -1,24 +1,23 @@
|
||||
#pragma once
|
||||
|
||||
#include "Dataset.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include <map>
|
||||
|
||||
class Dataset;
|
||||
|
||||
class DatapoolHelper {
|
||||
public:
|
||||
DatapoolHelper();
|
||||
~DatapoolHelper();
|
||||
|
||||
const Dataset* getDataSet(uint8_t id);
|
||||
const Dataset* getDataSet(DataSetId_t id);
|
||||
|
||||
const std::map<uint8_t, Dataset*>* getDatasets() const {
|
||||
const std::map<DataSetId_t, Dataset*>* getDatasets() const {
|
||||
return &dataSets;
|
||||
}
|
||||
|
||||
void registerSet(Dataset* set);
|
||||
|
||||
private:
|
||||
std::map<uint8_t, Dataset*> dataSets;
|
||||
std::map<DataSetId_t, Dataset*> dataSets;
|
||||
};
|
||||
|
@ -11,6 +11,9 @@
|
||||
#include "DatasetEntryIF.h"
|
||||
#include "HasDatapoolIF.h"
|
||||
|
||||
|
||||
using DataSetId_t = uint32_t;
|
||||
|
||||
/**
|
||||
* This class has a dual use
|
||||
*
|
||||
@ -44,8 +47,8 @@ class Dataset {
|
||||
Dataset(uint32_t owner_id);
|
||||
void setEnum(EnumIF* theEnum);
|
||||
#else
|
||||
Dataset(HasDatapoolIF* owner, uint8_t id, bool allowUserCommit);
|
||||
Dataset(uint32_t owner_id, uint8_t id);
|
||||
Dataset(HasDatapoolIF* owner, uint32_t id, bool allowUserCommit);
|
||||
Dataset(uint32_t owner_id, uint32_t id);
|
||||
#endif
|
||||
public:
|
||||
~Dataset();
|
||||
@ -156,9 +159,6 @@ class Dataset {
|
||||
const char* getDescription() const;
|
||||
#endif
|
||||
|
||||
/**
|
||||
* returns whether the set is the actual owned set (entries should allocate actual variables)
|
||||
*/
|
||||
bool registerEntry(DatasetEntryIF*);
|
||||
|
||||
protected:
|
||||
|
@ -9,10 +9,7 @@ class DatasetEntryIF {
|
||||
friend class Dataset;
|
||||
|
||||
public:
|
||||
/**
|
||||
* @brief This is an empty virtual destructor,
|
||||
* as it is required for C++ interfaces.
|
||||
*/
|
||||
|
||||
virtual ~DatasetEntryIF() {}
|
||||
/**
|
||||
* @brief This method allows to set the valid information of the pool entry.
|
||||
@ -24,7 +21,7 @@ class DatasetEntryIF {
|
||||
virtual bool getValid() = 0;
|
||||
|
||||
|
||||
#ifdef FSFW_INTROSPECTION
|
||||
#ifdef FSFW_INTROSPECTION
|
||||
|
||||
virtual const char *getName() = 0;
|
||||
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include "DataSet.h"
|
||||
|
||||
//TODO use object_id_t
|
||||
|
||||
template <typename HkIDs>
|
||||
class TemplateSet : public Dataset {
|
||||
public:
|
||||
@ -14,10 +16,10 @@ class TemplateSet : public Dataset {
|
||||
TemplateSet(uint32_t owner_id, HkIDs id) : Dataset(owner_id) { setEnum(&id); }
|
||||
#else
|
||||
TemplateSet(HasDatapoolIF* owner, HkIDs id, bool allowUserCommit)
|
||||
: Dataset(owner, (uint8_t)id, allowUserCommit) {
|
||||
: Dataset(owner, static_cast<DataSetId_t>(id), allowUserCommit) {
|
||||
owner->getDatapoolHelper()->registerSet(this);
|
||||
}
|
||||
TemplateSet(uint32_t owner_id, HkIDs id) : Dataset(owner_id, (uint8_t)id) {}
|
||||
TemplateSet(uint32_t owner_id, HkIDs id) : Dataset(owner_id, static_cast<DataSetId_t>(id) {}
|
||||
#endif
|
||||
virtual ~TemplateSet() = default;
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user