Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr/introspection

This commit is contained in:
Ulrich Mohr 2022-08-25 22:41:25 +02:00
commit 8353964635
6 changed files with 78 additions and 4 deletions

View File

@ -342,7 +342,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
*/ */
virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand, virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData, const uint8_t *commandData,
size_t commandDataLen) {exit(0);} size_t commandDataLen) {return HasReturnvaluesIF::RETURN_FAILED;}
/* Reply handling */ /* Reply handling */
/** /**

View File

@ -1,10 +1,11 @@
#pragma once #pragma once
#include <cstdint>
#include <cstddef> #include <cstddef>
#include <cstdint>
class EnumIF { class EnumIF {
public: public:
virtual ~EnumIF() {}
virtual int64_t getValue() const = 0; virtual int64_t getValue() const = 0;
virtual bool isValid() const = 0; virtual bool isValid() const = 0;
virtual size_t getSize() const = 0; virtual size_t getSize() const = 0;

View File

@ -6,6 +6,7 @@
#include "../events/Event.h" #include "../events/Event.h"
#include "../returnvalues/HasReturnvaluesIF.h" #include "../returnvalues/HasReturnvaluesIF.h"
#include "ModeHelper.h" #include "ModeHelper.h"
#include "ModeDefinitionHelper.h"
#include "ModeMessage.h" #include "ModeMessage.h"
class HasModesIF { class HasModesIF {
@ -49,6 +50,7 @@ class HasModesIF {
virtual ~HasModesIF() {} virtual ~HasModesIF() {}
virtual MessageQueueId_t getCommandQueue() const = 0; virtual MessageQueueId_t getCommandQueue() const = 0;
virtual ModeDefinitionHelper getModeDefinitionHelper()= 0;
virtual void getMode(Mode_t *mode, Submode_t *submode) = 0; virtual void getMode(Mode_t *mode, Submode_t *submode) = 0;
protected: protected:

View File

@ -0,0 +1,33 @@
#pragma once
#include <fsfw/introspection/EnumIF.h>
class ModeDefinitionHelper {
public:
#ifdef FSFW_INTROSPECTION
ModeDefinitionHelper(EnumIF *mode, EnumIF *submode) : mode(mode), submode(submode) {}
#else
ModeDefinitionHelper(void *mode, void *submode) {};
#endif
template <typename Mode, typename Submode>
static ModeDefinitionHelper create() {
#ifdef FSFW_INTROSPECTION
EnumIF *mode = new Mode();
EnumIF *submode = new Submode();
return ModeDefinitionHelper(mode, submode);
#else
return ModeDefinitionHelper(nullptr, nullptr);
#endif
}
void free() {
#ifdef FSFW_INTROSPECTION
delete mode;
delete submode;
#endif
}
#ifdef FSFW_INTROSPECTION
EnumIF *mode;
EnumIF *submode;
#endif
};

View File

@ -106,3 +106,33 @@ bool ModeHelper::isTimedOut() { return countdown.hasTimedOut(); }
bool ModeHelper::isForced() { return forced; } bool ModeHelper::isForced() { return forced; }
void ModeHelper::setForced(bool forced) { this->forced = forced; } void ModeHelper::setForced(bool forced) { this->forced = forced; }
#ifdef FSFW_INTROSPECTION
std::vector<std::pair<Mode_t, const char *>> ModeHelper::getModes() const {
std::vector<std::pair<Mode_t, const char *>> modeVector;
auto modeDefinitionHelper = owner->getModeDefinitionHelper();
EnumIF *mode = modeDefinitionHelper.mode;
for (size_t i = 0; i < mode->getSize(); i++) {
modeVector.push_back(
std::pair<Mode_t, const char *>(mode->getElements()[i], mode->getDescriptions()[i]));
}
modeDefinitionHelper.free();
return modeVector;
}
std::vector<std::pair<Submode_t, const char *>> ModeHelper::getSubmodes(Mode_t mode) const {
auto modeDefinitionHelper = owner->getModeDefinitionHelper();
EnumIF *submode = modeDefinitionHelper.submode;
std::vector<std::pair<Submode_t, const char *>> submodeVector;
for (size_t i = 0; i < submode->getSize(); i++) {
uint32_t ignored;
if (owner->checkModeCommand(mode, submode->getElements()[i], &ignored) ==
HasReturnvaluesIF::RETURN_OK) {
submodeVector.push_back(std::pair<Submode_t, const char *>(submode->getElements()[i],
submode->getDescriptions()[i]));
}
}
modeDefinitionHelper.free();
return submodeVector;
}
#endif

View File

@ -1,6 +1,8 @@
#ifndef FSFW_MODES_MODEHELPER_H_ #ifndef FSFW_MODES_MODEHELPER_H_
#define FSFW_MODES_MODEHELPER_H_ #define FSFW_MODES_MODEHELPER_H_
#include <vector>
#include "ModeMessage.h" #include "ModeMessage.h"
#include "fsfw/ipc/MessageQueueIF.h" #include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/returnvalues/HasReturnvaluesIF.h" #include "fsfw/returnvalues/HasReturnvaluesIF.h"
@ -39,6 +41,12 @@ class ModeHelper {
void setForced(bool forced); void setForced(bool forced);
#ifdef FSFW_INTROSPECTION
std::vector<std::pair<Mode_t, const char *>> getModes() const;
std::vector<std::pair<Submode_t, const char *>> getSubmodes(Mode_t mode) const;
#endif
protected: protected:
HasModesIF *owner; HasModesIF *owner;
MessageQueueId_t parentQueueId = MessageQueueIF::NO_QUEUE; MessageQueueId_t parentQueueId = MessageQueueIF::NO_QUEUE;