Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr/introspection
This commit is contained in:
commit
8353964635
@ -342,7 +342,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
|
||||
*/
|
||||
virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||
const uint8_t *commandData,
|
||||
size_t commandDataLen) {exit(0);}
|
||||
size_t commandDataLen) {return HasReturnvaluesIF::RETURN_FAILED;}
|
||||
|
||||
/* Reply handling */
|
||||
/**
|
||||
|
@ -1,10 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
class EnumIF {
|
||||
public:
|
||||
virtual ~EnumIF() {}
|
||||
virtual int64_t getValue() const = 0;
|
||||
virtual bool isValid() const = 0;
|
||||
virtual size_t getSize() const = 0;
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "../events/Event.h"
|
||||
#include "../returnvalues/HasReturnvaluesIF.h"
|
||||
#include "ModeHelper.h"
|
||||
#include "ModeDefinitionHelper.h"
|
||||
#include "ModeMessage.h"
|
||||
|
||||
class HasModesIF {
|
||||
@ -49,6 +50,7 @@ class HasModesIF {
|
||||
|
||||
virtual ~HasModesIF() {}
|
||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||
virtual ModeDefinitionHelper getModeDefinitionHelper()= 0;
|
||||
virtual void getMode(Mode_t *mode, Submode_t *submode) = 0;
|
||||
|
||||
protected:
|
||||
|
33
src/fsfw/modes/ModeDefinitionHelper.h
Normal file
33
src/fsfw/modes/ModeDefinitionHelper.h
Normal 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
|
||||
};
|
@ -4,7 +4,7 @@
|
||||
#include "fsfw/modes/HasModesIF.h"
|
||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||
|
||||
ModeHelper::ModeHelper(HasModesIF* owner)
|
||||
ModeHelper::ModeHelper(HasModesIF *owner)
|
||||
: commandedMode(HasModesIF::MODE_OFF),
|
||||
commandedSubmode(HasModesIF::SUBMODE_NONE),
|
||||
owner(owner),
|
||||
@ -12,7 +12,7 @@ ModeHelper::ModeHelper(HasModesIF* owner)
|
||||
|
||||
ModeHelper::~ModeHelper() {}
|
||||
|
||||
ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* command) {
|
||||
ReturnValue_t ModeHelper::handleModeCommand(CommandMessage *command) {
|
||||
CommandMessage reply;
|
||||
Mode_t mode;
|
||||
Submode_t submode;
|
||||
@ -106,3 +106,33 @@ bool ModeHelper::isTimedOut() { return countdown.hasTimedOut(); }
|
||||
bool ModeHelper::isForced() { return 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
|
@ -1,6 +1,8 @@
|
||||
#ifndef FSFW_MODES_MODEHELPER_H_
|
||||
#define FSFW_MODES_MODEHELPER_H_
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "ModeMessage.h"
|
||||
#include "fsfw/ipc/MessageQueueIF.h"
|
||||
#include "fsfw/returnvalues/HasReturnvaluesIF.h"
|
||||
@ -39,6 +41,12 @@ class ModeHelper {
|
||||
|
||||
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:
|
||||
HasModesIF *owner;
|
||||
MessageQueueId_t parentQueueId = MessageQueueIF::NO_QUEUE;
|
||||
|
Loading…
Reference in New Issue
Block a user