Compare commits

...

32 Commits

Author SHA1 Message Date
c42da5df86 fixed DHB unittest for new Actions 2022-09-14 17:04:17 +02:00
6c711415c1 bug found by unittest 2022-09-14 16:34:09 +02:00
253aa30263 fixing merge 2022-09-14 16:31:24 +02:00
eae7bfc935 Merge branch 'mohr/merge-upstream' into mohr/introspection 2022-09-14 16:23:23 +02:00
383bafe344 Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr/introspection 2022-09-08 11:42:27 +02:00
1c527c4946 copy paste fail #2 2022-09-08 11:41:32 +02:00
0e6e124eab small fixes 2022-09-07 10:54:49 +02:00
c7e6f01f9b Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr/introspection 2022-08-26 15:52:14 +02:00
4c0f67adf5 missing implementation in subsystembase 2022-08-26 15:03:17 +02:00
450ad1dad4 ControllerBase Modes 2022-08-26 12:07:59 +02:00
1dfb3323f7 default getModehelper for ControllerBase 2022-08-26 11:53:46 +02:00
f5adcd0625 default getModehelper for subsystembase 2022-08-26 10:57:05 +02:00
bc593c938d some more mode introspection 2022-08-26 10:31:45 +02:00
8353964635 Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr/introspection 2022-08-25 22:41:25 +02:00
3f8f17a66e copy paste fail 2022-08-25 22:39:21 +02:00
3260a03544 forgot include 2022-08-25 22:37:41 +02:00
3ffdc0d31f Mode introspection 2022-08-25 22:33:33 +02:00
d367baa42c stupid idea 2022-08-24 18:47:25 +02:00
d634bdb775 Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr/introspection 2022-08-24 17:49:29 +02:00
59f8dd1322 preparing DHB::buildCommandFromCommand for retirement 2022-08-24 17:49:16 +02:00
61b4e68f3d parameter tuning 2022-08-24 17:19:45 +02:00
e34664d265 Adding error message to a coding error 2022-08-19 13:47:13 +02:00
20eb232bf5 added access to objectlist and a produce function to ObjectManager 2022-08-19 12:23:14 +02:00
31f59f915c Merge commit 'd9759581' into mohr/introspection 2022-08-18 12:20:20 +02:00
cfdbe0f6cb Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr/introspection 2022-07-28 16:32:24 +02:00
dd281f8a67 Controller base missing a function 2022-07-28 16:32:12 +02:00
f9e9ff320f Small fixes 2022-07-28 14:55:43 +02:00
f56646d2c3 changed action handling slightly 2022-07-20 16:59:42 +02:00
b08d127e11 Merge remote-tracking branch 'sidestream/mohr_introspection' into mohr_other_introspection 2022-07-14 15:59:22 +02:00
ef18377cef new Actions 2022-06-29 23:36:45 +02:00
0c057c66b1 added introspection 2022-06-28 18:56:52 +02:00
34c50ce3e2 ignore .vscode 2022-06-28 17:44:53 +02:00
43 changed files with 1022 additions and 103 deletions

3
.gitignore vendored
View File

@ -10,5 +10,8 @@
.settings
.metadata
# VSCode
.vscode
/build*
/cmake-build*

View File

@ -15,6 +15,7 @@ add_subdirectory(globalfunctions)
add_subdirectory(health)
add_subdirectory(housekeeping)
add_subdirectory(internalerror)
add_subdirectory(introspection)
add_subdirectory(ipc)
add_subdirectory(memory)
add_subdirectory(modes)

View File

@ -0,0 +1,62 @@
#include "Action.h"
#include <fsfw/serialize/SerializeAdapter.h>
#undef Action
#ifdef FSFW_INTROSPECTION
Action::Action() {}
void Action::setEnum(EnumIF *theEnum) {
id = theEnum->getValue();
name = theEnum->getDescription();
}
const char *Action::getName() { return name; }
#else
Action::Action(ActionId_t id) : id(id) {}
#endif
ActionId_t Action::getId() { return id; }
void Action::registerParameter(ParameterIF *parameter) { parameterList.push_back(parameter); }
std::vector<ParameterIF *> const *Action::getParameters() const { return &parameterList; }
size_t Action::getSerializedSize() const {
size_t size = SerializeAdapter::getSerializedSize(&id);
for (auto parameter : *getParameters()) {
size += parameter->getSerializedSize();
}
return size;
}
ReturnValue_t Action::serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const {
ReturnValue_t result = SerializeAdapter::serialize(&id, buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
for (auto parameter : *getParameters()) {
result = parameter->serialize(buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
}
return result;
}
ReturnValue_t Action::deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) {
ReturnValue_t result = returnvalue::OK;/* TODO not needed as must have been read before to find this action = SerializeAdapter::deSerialize(&id, buffer, size, streamEndianness);
if (result != HasReturnvaluesIF::RETURN_OK) {
return result;
}*/
for (auto parameter : *getParameters()) {
result = parameter->deSerialize(buffer, size, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
}
return result;
}

50
src/fsfw/action/Action.h Normal file
View File

@ -0,0 +1,50 @@
#pragma once
#include <stdint.h>
#include <vector>
#include <fsfw/serialize/SerializeIF.h>
#include "ActionMessage.h"
#include "ParameterIF.h"
#ifdef FSFW_INTROSPECTION
#include "../introspection/Enum.h"
#endif
class Action: public SerializeIF {
public:
#ifdef FSFW_INTROSPECTION
Action();
void setEnum(EnumIF* id);
const char *getName();
#else
Action(ActionId_t id);
#endif
ActionId_t getId();
MessageQueueId_t commandedBy;
[[nodiscard]] virtual ReturnValue_t handle() = 0;
void registerParameter(ParameterIF *parameter);
std::vector<ParameterIF *> const *getParameters() const;
ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
Endianness streamEndianness) const override;
size_t getSerializedSize() const override;
ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
Endianness streamEndianness) override;
private:
ActionId_t id;
#ifdef FSFW_INTROSPECTION
const char *name;
#endif
std::vector<ParameterIF *> parameterList;
};

View File

@ -57,6 +57,10 @@ void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t co
void ActionHelper::setQueueToUse(MessageQueueIF* queue) { queueToUse = queue; }
MessageQueueIF const * ActionHelper::getQueue() const {
return queueToUse;
}
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
store_address_t dataAddress) {
const uint8_t* dataPtr = nullptr;
@ -66,9 +70,29 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act
CommandMessage reply;
ActionMessage::setStepReply(&reply, actionId, 0, result);
queueToUse->sendMessage(commandedBy, &reply);
ipcStore->deleteData(dataAddress);
return;
}
result = owner->executeAction(actionId, commandedBy, dataPtr, size);
auto actionIter = actionMap.find(actionId);
if (actionIter == actionMap.end()){
CommandMessage reply;
ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::INVALID_ACTION_ID);
queueToUse->sendMessage(commandedBy, &reply);
ipcStore->deleteData(dataAddress);
return;
}
Action* action = actionIter->second;
result = action->deSerialize(&dataPtr, &size, SerializeIF::Endianness::NETWORK);
if ((result != returnvalue::OK) or (size != 0)){
CommandMessage reply;
ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::INVALID_PARAMETERS);
queueToUse->sendMessage(commandedBy, &reply);
ipcStore->deleteData(dataAddress);
return;
}
//TODO call action->check()
action->commandedBy = commandedBy;
result = owner->executeAction(action);
ipcStore->deleteData(dataAddress);
if (result == HasActionsIF::EXECUTION_FINISHED) {
CommandMessage reply;
@ -163,3 +187,11 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t rep
}
return result;
}
void ActionHelper::registerAction(Action* action) {
//TODO error handling
ActionId_t id = action->getId();
actionMap.emplace(id, action);
}
std::map<ActionId_t, Action*> const* ActionHelper::getActionMap() { return &actionMap; }

View File

@ -1,9 +1,13 @@
#ifndef FSFW_ACTION_ACTIONHELPER_H_
#define FSFW_ACTION_ACTIONHELPER_H_
#include <map>
#include "Action.h"
#include "ActionMessage.h"
#include "fsfw/ipc/MessageQueueIF.h"
#include "fsfw/serialize/SerializeIF.h"
/**
* @brief Action Helper is a helper class which handles action messages
*
@ -98,6 +102,16 @@ class ActionHelper {
*/
void setQueueToUse(MessageQueueIF* queue);
/**
* Needed so templateAction can check if actionHelper was
* contructed already to aid in debuggig a nasty coding error.
*/
MessageQueueIF const * getQueue() const;
void registerAction(Action* action);
std::map<ActionId_t, Action*> const* getActionMap();
protected:
//! Increase of value of this per step
static const uint8_t STEP_OFFSET = 1;
@ -108,6 +122,8 @@ class ActionHelper {
MessageQueueIF* queueToUse;
//! Pointer to an IPC Store, initialized during construction or
StorageManagerIF* ipcStore = nullptr;
//! Map of all implemented Actions
std::map<ActionId_t, Action*> actionMap;
/**
* Internal function called by handleActionMessage

View File

@ -1,3 +1,3 @@
target_sources(
${LIB_FSFW_NAME} PRIVATE ActionHelper.cpp ActionMessage.cpp
${LIB_FSFW_NAME} PRIVATE Action.cpp ActionHelper.cpp ActionMessage.cpp
CommandActionHelper.cpp SimpleActionHelper.cpp)

View File

@ -44,8 +44,12 @@ class HasActionsIF {
/**
* Function to get the MessageQueueId_t of the implementing object
* @return MessageQueueId_t of the object
*
*/
[[nodiscard]] virtual MessageQueueId_t getCommandQueue() const = 0;
[[nodiscard]] virtual ActionHelper* getActionHelper() = 0;
/**
* Execute or initialize the execution of a certain function.
* The ActionHelpers will execute this function and behave differently
@ -55,8 +59,7 @@ class HasActionsIF {
* -@c EXECUTION_FINISHED Finish reply will be generated
* -@c Not returnvalue::OK Step failure reply will be generated
*/
virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) = 0;
virtual ReturnValue_t executeAction(Action* action) = 0;
};
#endif /* FSFW_ACTION_HASACTIONSIF_H_ */

View File

@ -0,0 +1,40 @@
#pragma once
#include "Parameter.h"
template <typename T>
class MinMaxParameter : public Parameter<T> {
#ifdef FSFW_INTROSPECTION
private:
MinMaxParameter(Action *owner, const char *name, T min, T max)
: Parameter<T>(owner, name), min(min), max(max) {}
public:
static MinMaxParameter createMinMaxParameter(Action *owner, const char *name, T min, T max) {
return MinMaxParameter(owner, name, min, max);
}
virtual double getMinFloating() override { return static_cast<double>(min); }
virtual int64_t getMinSigned() override { return static_cast<int64_t>(min); }
virtual double getMaxFloating() override { return static_cast<double>(max); }
virtual int64_t getMaxSigned() override { return static_cast<int64_t>(max); }
#else
private:
MinMaxParameter(Action *owner, T min, T max) : Parameter<T>(owner), min(min), max(max) {}
public:
static MinMaxParameter createMinMaxParameter(Action *owner, T min, T max) {
return MinMaxParameter(owner, min, max);
}
#endif
private:
T min;
T max;
};
#ifdef FSFW_INTROSPECTION
#define createMinMaxParameter(p1, p2, p3, p4) createMinMaxParameter(p1, p2, p3, p4)
#else
#define createMinMaxParameter(p1, p2, p3, p4) createMinMaxParameter(p1, p3, p4)
#endif

120
src/fsfw/action/Parameter.h Normal file
View File

@ -0,0 +1,120 @@
#pragma once
#include <stdio.h>
#include "Action.h"
#include <fsfw/introspection/Types.h>
#include <fsfw/introspection/TypesHelper.h>
#include "ParameterIF.h"
// TODO: ifdef introspection stuff
template <typename T>
class Parameter : public ParameterIF {
protected:
#ifdef FSFW_INTROSPECTION
Parameter(Action *owner, const char *name)
: name(name)
#else
Parameter(Action *owner)
#endif
{
owner->registerParameter(this);
}
public:
#ifdef FSFW_INTROSPECTION
static Parameter createParameter(Action *owner, const char *name) {
return Parameter(owner, name);
}
#else
static Parameter createParameter(Action *owner) { return Parameter(owner); }
#endif
bool isValid() override {
return enumHelper<std::is_base_of<EnumIF, T>::value>::isValid(&value);
}
operator T(){
return value;
}
Parameter& operator =(const T& newValue){
value = newValue;
return *this;
}
#ifdef FSFW_INTROSPECTION
Types::ParameterType 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 createParameter(p1, p2) createParameter(p1, p2)
#else
#define createParameter(p1, p2) createParameter(p1)
#endif

View File

@ -0,0 +1,45 @@
#pragma once
#include <fsfw/serialize/SerializeIF.h>
#include <fsfw/introspection/Types.h>
#ifdef FSFW_INTROSPECTION
#include <vector>
#endif
class ParameterIF : public SerializeIF {
public:
virtual bool isValid() = 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 double getMinFloating() = 0;
virtual int64_t getMinSigned() = 0;
virtual double getMaxFloating() = 0;
virtual int64_t getMaxSigned() = 0;
virtual std::vector<int64_t> getEnumValues() = 0;
virtual const char *const * getEnumDescriptions() = 0;
// ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize,
// Endianness streamEndianness) const override = 0;
// size_t getSerializedSize() const override = 0;
// ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size,
// Endianness streamEndianness) override = 0;
#endif
};

View File

@ -44,11 +44,27 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId
if (result != returnvalue::OK) {
ActionMessage::setStepReply(&reply, actionId, 0, result);
queueToUse->sendMessage(commandedBy, &reply);
ipcStore->deleteData(dataAddress);
return;
}
lastCommander = commandedBy;
lastAction = actionId;
result = owner->executeAction(actionId, commandedBy, dataPtr, size);
auto actionIter = actionMap.find(actionId);
if (actionIter == actionMap.end()){
CommandMessage reply;
ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::INVALID_ACTION_ID);
queueToUse->sendMessage(commandedBy, &reply);
ipcStore->deleteData(dataAddress);
return;
}
Action* action = actionIter->second;
result = action->deSerialize(&dataPtr, &size, SerializeIF::Endianness::NETWORK);
if ((result != returnvalue::OK) or (size != 0)) {
CommandMessage reply;
ActionMessage::setStepReply(&reply, actionId, 0, HasActionsIF::INVALID_PARAMETERS);
queueToUse->sendMessage(commandedBy, &reply);
ipcStore->deleteData(dataAddress);
return;
}
result = action->handle();
ipcStore->deleteData(dataAddress);
switch (result) {
case returnvalue::OK:

View File

@ -0,0 +1,29 @@
#pragma once
#include "Action.h"
#include "fsfw/serviceinterface/ServiceInterface.h"
template <class owner, class action, class ActionEnum>
class TemplateAction : public Action {
public:
#ifdef FSFW_INTROSPECTION
TemplateAction(owner *myOwner, ActionEnum id) : Action(), myOwner(myOwner) {
Action::setEnum(&id);
if (myOwner->getActionHelper() == nullptr) {
sif::error
<< "TemplateAction::TemplateAction: Action instances need to be created (ie located) after the actionHelper instance."
<< "Program will segfault now..." << std::endl;
}
myOwner->getActionHelper()->registerAction(this);
}
#else
TemplateAction(owner *myOwner, ActionEnum id) : Action((uint32_t)id), myOwner(myOwner) {
myOwner->getActionHelper()->registerAction(this);
}
#endif
ReturnValue_t handle() override { return myOwner->handleAction(dynamic_cast<action *>(this)); }
private:
owner *myOwner;
};

View File

@ -103,6 +103,10 @@ ReturnValue_t ControllerBase::performOperation(uint8_t opCode) {
void ControllerBase::modeChanged(Mode_t mode_, Submode_t submode_) {}
const ModeHelper * ControllerBase::getModeHelper() const {
return &modeHelper;
}
ReturnValue_t ControllerBase::setHealth(HealthState health) {
switch (health) {
case HEALTHY:

View File

@ -3,6 +3,7 @@
#include "fsfw/health/HasHealthIF.h"
#include "fsfw/health/HealthHelper.h"
#include "fsfw/introspection/ClasslessEnum.h"
#include "fsfw/modes/HasModesIF.h"
#include "fsfw/modes/ModeHelper.h"
#include "fsfw/objectmanager/SystemObject.h"
@ -20,7 +21,9 @@ class ControllerBase : public HasModesIF,
public ExecutableObjectIF,
public SystemObject {
public:
static const Mode_t MODE_NORMAL = 2;
FSFW_CLASSLESS_ENUM(ControllerModes, Mode_t,
((CONTROLLER_MODE_ON, MODE_ON, "On"))((CONTROLLER_MODE_OFF, MODE_OFF,
"Off"))((MODE_NORMAL, 2, "Normal")))
ControllerBase(object_id_t setObjectId, object_id_t parentId, size_t commandQueueDepth = 3);
~ControllerBase() override;
@ -39,6 +42,9 @@ class ControllerBase : public HasModesIF,
void setTaskIF(PeriodicTaskIF *task) override;
ReturnValue_t initializeAfterTaskCreation() override;
/** HasModeIF override */
const ModeHelper *getModeHelper() const override;
protected:
/**
* Implemented by child class. Handle command messages which are not

View File

@ -8,11 +8,12 @@ ExtendedControllerBase::ExtendedControllerBase(object_id_t objectId, object_id_t
ExtendedControllerBase::~ExtendedControllerBase() = default;
ReturnValue_t ExtendedControllerBase::executeAction(ActionId_t actionId,
MessageQueueId_t commandedBy,
const uint8_t *data, size_t size) {
/* Needs to be overriden and implemented by child class. */
return returnvalue::OK;
ActionHelper *ExtendedControllerBase::getActionHelper() {
return &actionHelper;
}
ReturnValue_t ExtendedControllerBase::executeAction(Action *action) {
return action->handle();
}
object_id_t ExtendedControllerBase::getObjectId() const { return SystemObject::getObjectId(); }

View File

@ -29,6 +29,10 @@ class ExtendedControllerBase : public ControllerBase,
ReturnValue_t performOperation(uint8_t opCode) override;
ReturnValue_t initializeAfterTaskCreation() override;
/* HasActionsIF overrides */
ActionHelper* getActionHelper() override;
ReturnValue_t executeAction(Action* actionId) override;
protected:
LocalDataPoolManager poolManager;
ActionHelper actionHelper;
@ -49,10 +53,6 @@ class ExtendedControllerBase : public ControllerBase,
/* Handle the four messages mentioned above */
void handleQueue() override;
/* HasActionsIF overrides */
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override;
/* HasLocalDatapoolIF overrides */
LocalDataPoolManager* getHkManagerHandle() override;
[[nodiscard]] object_id_t getObjectId() const override;

View File

@ -1324,21 +1324,21 @@ void DeviceHandlerBase::handleDeviceTm(const SerializeIF& dataSet, DeviceCommand
}
}
ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) {
ActionHelper* DeviceHandlerBase::getActionHelper() { return &actionHelper; }
ReturnValue_t DeviceHandlerBase::executeAction(Action* action) {
ReturnValue_t result = acceptExternalDeviceCommands();
if (result != returnvalue::OK) {
return result;
}
DeviceCommandMap::iterator iter = deviceCommandMap.find(actionId);
MessageQueueId_t prevRecipient = MessageQueueIF::NO_QUEUE;
DeviceCommandMap::iterator iter = deviceCommandMap.find(action->getId());
if (iter == deviceCommandMap.end()) {
result = COMMAND_NOT_SUPPORTED;
} else if (iter->second.isExecuting) {
result = COMMAND_ALREADY_SENT;
} else {
iter->second.sendReplyTo = commandedBy;
result = buildCommandFromCommand(actionId, data, size);
iter->second.sendReplyTo = action->commandedBy;
result = action->handle();
}
if (result == returnvalue::OK) {
iter->second.isExecuting = true;
@ -1602,3 +1602,10 @@ void DeviceHandlerBase::disableCommandsAndReplies() {
}
}
}
ModeHelper const* DeviceHandlerBase::getModeHelper() const { return &modeHelper; }
ModeDefinitionHelper DeviceHandlerBase::getModeDefinitionHelper() {
return ModeDefinitionHelper::create<DeviceHandlerMode, DefaultSubmode>();
}

View File

@ -204,13 +204,15 @@ class DeviceHandlerBase : public DeviceHandlerIF,
*/
virtual void setParentQueue(MessageQueueId_t parentQueueId);
/** @brief Implementation required for HasActionIF */
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t *data, size_t size) override;
/** @brief Implementations required for HasActionIF */
ActionHelper* getActionHelper() override;
ReturnValue_t executeAction(Action *action) override;
Mode_t getTransitionSourceMode() const;
Submode_t getTransitionSourceSubMode() const;
virtual void getMode(Mode_t *mode, Submode_t *submode);
void getMode(Mode_t *mode, Submode_t *submode) override;
ModeHelper const * getModeHelper() const override;
ModeDefinitionHelper getModeDefinitionHelper() override;
HealthState getHealth();
ReturnValue_t setHealth(HealthState health);
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
@ -314,6 +316,8 @@ class DeviceHandlerBase : public DeviceHandlerIF,
* - Anything else triggers an even with the returnvalue as a parameter
*/
virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) = 0;
//TODO Remove and update documentation
/**
* @brief Build a device command packet from data supplied by a direct
* command (PUS Service 8)
@ -340,7 +344,7 @@ class DeviceHandlerBase : public DeviceHandlerIF,
*/
virtual ReturnValue_t buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) = 0;
size_t commandDataLen) {return returnvalue::FAILED;}
/* Reply handling */
/**

View File

@ -4,6 +4,7 @@
#include "../action/HasActionsIF.h"
#include "../datapoollocal/localPoolDefinitions.h"
#include "../events/Event.h"
#include "../introspection/ClasslessEnum.h"
#include "../ipc/MessageQueueSenderIF.h"
#include "../modes/HasModesIF.h"
#include "DeviceHandlerMessage.h"
@ -37,23 +38,30 @@ class DeviceHandlerIF {
* The mode of the device itself is transparent to the user but related to the mode of the
* handler. MODE_ON and MODE_OFF are included in hasModesIF.h
*/
FSFW_CLASSLESS_ENUM(
DeviceHandlerMode, Mode_t,
//! The device is powered and ready to perform operations. In this mode, no
//! commands are sent by the device handler itself, but direct commands can be
//! commanded and will be executed/forwarded to the device
//! This is an alias of MODE_ON to have the FSFW_ENUM complete for introspection
((DEVICEHANDLER_MODE_ON, HasModesIF::MODE_ON, "On"))
//! The device is powered off. The only command accepted in this
//! mode is a mode change to on.
//! This is an alias of MODE_OFF to have the FSFW_ENUM complete for introspection
((DEVICEHANDLER_MODE_OFF, HasModesIF::MODE_OFF, "Off"))
//! The device is powered on and the device handler periodically sends
//! commands. The commands to be sent are selected by the handler
//! according to the submode.
((MODE_NORMAL, 2, "Normal"))
//! The device is powered on and ready to perform operations. In this mode,
//! raw commands can be sent. The device handler will send all replies
//! received from the command back to the commanding object as raw TM
((MODE_RAW, 3, "Raw"))
//! The device is shut down but the switch could not be turned off, so the
//! device still is powered. In this mode, only a mode change to @c MODE_OFF
//! can be commanded, which tries to switch off the device again.
((MODE_ERROR_ON, 4, "Error")))
// MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no
// commands are sent by the device handler itself, but direct commands van be commanded and will
// be interpreted MODE_OFF = 1, //!< The device is powered off. The only command accepted in this
// mode is a mode change to on.
//! The device is powered on and the device handler periodically sends
//! commands. The commands to be sent are selected by the handler
//! according to the submode.
static const Mode_t MODE_NORMAL = 2;
//! The device is powered on and ready to perform operations. In this mode,
//! raw commands can be sent. The device handler will send all replies
//! received from the command back to the commanding object.
static const Mode_t MODE_RAW = 3;
//! The device is shut down but the switch could not be turned off, so the
//! device still is powered. In this mode, only a mode change to @c MODE_OFF
//! can be commanded, which tries to switch off the device again.
static const Mode_t MODE_ERROR_ON = 4;
//! This is a transitional state which can not be commanded. The device
//! handler performs all commands to get the device in a state ready to
//! perform commands. When this is completed, the mode changes to @c MODE_ON.

View File

@ -0,0 +1 @@
target_sources(${LIB_FSFW_NAME} PRIVATE ParameterTypeSelector.cpp)

View File

@ -0,0 +1,48 @@
#pragma once
#include <fsfw/returnvalues/returnvalue.h>
#include <boost/preprocessor.hpp>
// TODO ifdef EnumIF, consistent naming of functions arrays and macros (probably enum values and
// descriptions)
#include "EnumIF.h"
#include "EnumCommon.h"
#ifdef FSFW_INTROSPECTION
#define FSFW_CLASSLESS_ENUM(name, type, elements) \
enum : type { BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(CLEAN_ENUM_ITEM, "", elements)) }; \
\
class name : public EnumIF { \
public: \
enum : type { BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(CLEAN_ENUM_ITEM, "", elements)) }; \
name(type value) : value(value) {} \
name() : value(-1) {} \
name(const name &other) : value(other.value) {} \
int64_t getValue() const override { return value; } \
operator type() { return value; } \
name &operator=(name other) { \
value = other.value; \
return *this; \
} \
name &operator=(type value) { \
this->value = value; \
return *this; \
} \
CREATE_KEY_ARRAY(elements, type) \
VALUE_CHECK(type) \
GET_INDEX() \
CREATE_DESCRIPTION_ARRAY(elements) \
GET_DESCRIPTION_FUNC() \
private: \
type value; \
};
#else
#define FSFW_CLASSLESS_ENUM(name, type, elements) \
enum name : type { BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(CLEAN_ENUM_ITEM, "", elements)) };
#endif

View File

@ -0,0 +1,64 @@
#pragma once
#include <fsfw/returnvalues/returnvalue.h>
#include <fsfw/serialize/SerializeAdapter.h>
#include <boost/preprocessor.hpp>
// TODO ifdef EnumIF, consistent naming of functions arrays and macros (probably enum values and
// descriptions)
#include "EnumIF.h"
#include "EnumCommon.h"
#ifdef FSFW_INTROSPECTION
#define FSFW_ENUM(name, type, elements) \
class name : public EnumIF, public SerializeIF { \
public: \
enum : type { BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(CLEAN_ENUM_ITEM, "", elements)) }; \
name(type value) : value(value) {} \
name() : value(-1) {} \
name(const name &other) : value(other.value) {} \
int64_t getValue() const override { return value; } \
operator type() { return value; } \
name &operator=(name other) { \
value = other.value; \
return *this; \
} \
name &operator=(type value) { \
this->value = value; \
return *this; \
} \
CREATE_KEY_ARRAY(elements, type) \
VALUE_CHECK(type) \
GET_INDEX() \
CREATE_DESCRIPTION_ARRAY(elements) \
GET_DESCRIPTION_FUNC() \
virtual ReturnValue_t serialize(uint8_t **buffer, size_t *size, size_t maxSize, \
Endianness streamEndianness) const override { \
return SerializeAdapter::serialize<>(&value, buffer, size, maxSize, streamEndianness); \
} \
virtual size_t getSerializedSize() const override { \
return SerializeAdapter::getSerializedSize<>(&value); \
} \
virtual ReturnValue_t deSerialize(const uint8_t **buffer, size_t *size, \
Endianness streamEndianness) override { \
return SerializeAdapter::deSerialize<>(&value, buffer, size, streamEndianness); \
} \
\
private: \
type value; \
};
#else
#define FSFW_ENUM(name, type, elements) \
enum class name : type { \
BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(CLEAN_ENUM_ITEM, "", elements)) \
};
#endif

View File

@ -0,0 +1,62 @@
#define CLEAN_ENUM_ITEM(r, data, element) \
BOOST_PP_IF(BOOST_PP_SUB(BOOST_PP_TUPLE_SIZE(element), 2), \
(BOOST_PP_TUPLE_ELEM(0, element) = BOOST_PP_TUPLE_ELEM(1, element)), \
(BOOST_PP_TUPLE_ELEM(0, element)))
#if defined FSFW_ENUM_VALUE_CHECKS || defined FSFW_INTROSPECTION
#define GET_KEY(r, data, element) (BOOST_PP_TUPLE_ELEM(0, element))
#define GET_DESCRIPTION(r, data, element) \
BOOST_PP_IF(BOOST_PP_SUB(BOOST_PP_TUPLE_SIZE(element), 2), (BOOST_PP_TUPLE_ELEM(2, element)), \
(BOOST_PP_TUPLE_ELEM(1, element)))
#define CREATE_KEY_ARRAY(enum_elements, type) \
/*was static constexpr, but clang won't compile that*/ \
int64_t elements[BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_FOR_EACH(GET_KEY, "", enum_elements))] = { \
BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(GET_KEY, "", enum_elements))}; \
const int64_t *getElements() const override { return elements; } \
size_t getSize() const override { \
return BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_FOR_EACH(GET_KEY, "", enum_elements)); \
}
#define VALUE_CHECK(type) \
bool isValid() const override { \
for (size_t i = 0; i < sizeof(elements) / sizeof(elements[0]); i++) { \
if (value == elements[i]) { \
return true; \
} \
} \
return false; \
}
#ifdef FSFW_INTROSPECTION
#define CREATE_DESCRIPTION_ARRAY(elements) \
/*was static constexpr, but clang won't compile that*/ \
const char \
*descriptions[BOOST_PP_SEQ_SIZE(BOOST_PP_SEQ_FOR_EACH(GET_DESCRIPTION, "", elements))] = { \
BOOST_PP_SEQ_ENUM(BOOST_PP_SEQ_FOR_EACH(GET_DESCRIPTION, "", elements))}; \
const char *const *getDescriptions() const override { return descriptions; }
#define GET_INDEX() \
size_t getIndex(int64_t value) const override { \
for (size_t i = 0; i < sizeof(elements) / sizeof(elements[0]); i++) { \
if (value == elements[i]) { \
return i; \
} \
} \
return -1; \
}
#define GET_DESCRIPTION_FUNC() \
const char *getDescription() const override { \
if (getIndex(value) == static_cast<size_t>(-1)) { \
return nullptr; \
} else { \
return descriptions[getIndex(value)]; \
} \
}
#else
#define GET_INDEX()
#define CREATE_DESCRIPTION_ARRAY(elements)
#define GET_DESCRIPTION_FUNC()
#endif
#endif

View File

@ -0,0 +1,16 @@
#pragma once
#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;
virtual size_t getIndex(int64_t value) const = 0;
virtual const int64_t *getElements() const = 0;
virtual const char *const *getDescriptions() const = 0;
virtual const char *getDescription() const = 0;
};

View File

@ -0,0 +1,56 @@
#include "ParameterTypeSelector.h"
#include <stdint.h>
#include "Types.h"
#ifdef FSFW_INTROSPECTION
template <typename T>
Types::ParameterType ParameterTypeSelector::getType() {
return Types::UNSUPPORTED;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<uint8_t>() {
return Types::SIGNED;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<int8_t>() {
return Types::SIGNED;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<uint16_t>() {
return Types::SIGNED;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<int16_t>() {
return Types::SIGNED;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<uint32_t>() {
return Types::SIGNED;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<int32_t>() {
return Types::SIGNED;
}
// template <>
// Types::ParameterType ParameterTypeSelector::getType<uint64_t>() {
// return Types::UNSIGNED;
// }
template <>
Types::ParameterType ParameterTypeSelector::getType<int64_t>() {
return Types::SIGNED;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<float>() {
return Types::FLOATING;
}
template <>
Types::ParameterType ParameterTypeSelector::getType<double>() {
return Types::FLOATING;
}
#endif

View File

@ -0,0 +1,13 @@
#pragma once
#include "Types.h"
#ifdef FSFW_INTROSPECTION
class ParameterTypeSelector {
public:
template <typename T>
static Types::ParameterType getType();
};
#endif

View File

@ -0,0 +1,8 @@
#pragma once
//maybe call them MIB types as these are the ones exposed to the MIB?
// Note: some DBs (Postgress, Mongo) only support signed 64bit integers. To have a common denominator, all integers are int64_t.
// As such, ther is no unsigned Type, as there can not be a uint64_t and uint32_t completely fits into int64_t
namespace Types {
enum ParameterType { SIGNED, FLOATING, ENUM, STRING, BYTEARRAY, UNSUPPORTED };
} // namespace Types

View File

@ -0,0 +1,74 @@
#pragma once
#include <limits>
#include <vector>
#include "Enum.h"
#include "Types.h"
#include "ParameterTypeSelector.h"
template <bool>
class enumHelper;
template <>
class enumHelper<true> {
public:
static bool isValid(EnumIF *anEnum) { return anEnum->isValid(); }
#ifdef FSFW_INTROSPECTION
template <typename T>
static Types::ParameterType getType() {
return Types::ENUM;
}
template <typename T>
static T getMin() {
return 0;
}
template <typename T>
static T getMax() {
return 0;
}
static std::vector<int64_t> getEnumValues() { return std::vector<int64_t>(); }
static std::vector<int64_t> getEnumValues(EnumIF *anEnum) {
std::vector<int64_t> vector;
for (size_t i = 0; i < anEnum->getSize(); i++) {
vector.push_back(anEnum->getElements()[i]);
}
return vector;
}
static const char *const *getEnumDescriptions(EnumIF *anEnum) {
return anEnum->getDescriptions();
}
#endif
};
template <>
class enumHelper<false> {
public:
static bool isValid(void *) { return true; }
#ifdef FSFW_INTROSPECTION
template <typename T>
static Types::ParameterType getType() {
return ParameterTypeSelector::getType<T>();
}
template <typename T>
static T getMin() {
return std::numeric_limits<T>::lowest();
}
template <typename T>
static T getMax() {
return std::numeric_limits<T>::max();
}
static std::vector<int64_t> getEnumValues(void *) { return std::vector<int64_t>(); }
static const char *const *getEnumDescriptions(void *) { return nullptr; }
#endif
};

View File

@ -4,7 +4,9 @@
#include <cstdint>
#include "../events/Event.h"
#include "../introspection/ClasslessEnum.h"
#include "../returnvalues/returnvalue.h"
#include "ModeDefinitionHelper.h"
#include "ModeHelper.h"
#include "ModeMessage.h"
@ -35,7 +37,7 @@ class HasModesIF {
static const Event MODE_CMD_REJECTED = MAKE_EVENT(7, severity::LOW);
//! The device is powered and ready to perform operations. In this mode, no commands are
//! sent by the device handler itself, but direct commands van be commanded and will be
//! sent by the device handler itself, but direct commands can be commanded and will be
//! interpreted
static constexpr Mode_t MODE_ON = 1;
//! The device is powered off. The only command accepted in this mode is a mode change to on.
@ -44,11 +46,14 @@ class HasModesIF {
static constexpr Mode_t MODE_INVALID = -1;
static constexpr Mode_t MODE_UNDEFINED = -2;
//! To avoid checks against magic number "0".
static const Submode_t SUBMODE_NONE = 0;
FSFW_CLASSLESS_ENUM(DefaultSubmode, Submode_t,
((SUBMODE_NONE, 0,
"Default"))) //!< To avoid checks against magic number "0".
virtual ~HasModesIF() {}
virtual MessageQueueId_t getCommandQueue() const = 0;
virtual const ModeHelper * getModeHelper() const = 0;
virtual ModeDefinitionHelper getModeDefinitionHelper() = 0;
virtual void getMode(Mode_t *mode, Submode_t *submode) = 0;
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

@ -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

View File

@ -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/returnvalue.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;

View File

@ -78,7 +78,7 @@ SystemObjectIF* ObjectManager::getSystemObject(object_id_t id) {
}
}
void ObjectManager::initialize() {
void ObjectManager::produce() {
if (objectFactoryFunction == nullptr) {
#if FSFW_CPP_OSTREAM_ENABLED == 1
sif::error << "ObjectManager::initialize: Passed produceObjects "
@ -90,6 +90,10 @@ void ObjectManager::initialize() {
return;
}
objectFactoryFunction(factoryArgs);
}
void ObjectManager::initialize() {
produce();
ReturnValue_t result = returnvalue::FAILED;
uint32_t errorCount = 0;
for (auto const& it : objectList) {
@ -143,3 +147,7 @@ void ObjectManager::printList() {
}
#endif
}
const std::map<object_id_t, SystemObjectIF*> * ObjectManager::getObjectList(){
return &objectList;
}

View File

@ -42,7 +42,9 @@ class ObjectManager : public ObjectManagerIF {
ReturnValue_t insert(object_id_t id, SystemObjectIF* object) override;
ReturnValue_t remove(object_id_t id) override;
void initialize() override;
void produce() override;
void printList() override;
const std::map<object_id_t, SystemObjectIF*> * getObjectList() override;
protected:
SystemObjectIF* getSystemObject(object_id_t id) override;

View File

@ -1,6 +1,8 @@
#ifndef FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
#define FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
#include <map>
#include "../returnvalues/returnvalue.h"
#include "../serviceinterface/ServiceInterface.h"
#include "SystemObjectIF.h"
@ -58,12 +60,14 @@ class ObjectManagerIF {
* @li returnvalue::OK in case the object was successfully removed
*/
virtual ReturnValue_t remove(object_id_t id) = 0;
virtual void produce() = 0;
virtual void initialize() = 0;
/**
* @brief This is a debug function, that prints the current content of the
* object list.
*/
virtual void printList() = 0;
virtual const std::map<object_id_t, SystemObjectIF*>* getObjectList() = 0;
};
#endif /* OBJECTMANAGERIF_H_ */

View File

@ -327,3 +327,7 @@ ReturnValue_t SubsystemBase::setHealth(HealthState health) {
HasHealthIF::HealthState SubsystemBase::getHealth() { return healthHelper.getHealth(); }
void SubsystemBase::modeChanged() {}
const ModeHelper * SubsystemBase::getModeHelper() const {
return &modeHelper;
}

View File

@ -40,7 +40,9 @@ class SubsystemBase : public SystemObject,
uint16_t commandQueueDepth = 8);
virtual ~SubsystemBase();
virtual MessageQueueId_t getCommandQueue() const override;
MessageQueueId_t getCommandQueue() const override;
const ModeHelper * getModeHelper() const override;
/**
* Function to register the child objects.
@ -55,13 +57,13 @@ class SubsystemBase : public SystemObject,
*/
ReturnValue_t registerChild(object_id_t objectId);
virtual ReturnValue_t initialize() override;
ReturnValue_t initialize() override;
virtual ReturnValue_t performOperation(uint8_t opCode) override;
ReturnValue_t performOperation(uint8_t opCode) override;
virtual ReturnValue_t setHealth(HealthState health) override;
ReturnValue_t setHealth(HealthState health) override;
virtual HasHealthIF::HealthState getHealth() override;
HasHealthIF::HealthState getHealth() override;
protected:
struct ChildInfo {

View File

@ -9,38 +9,35 @@
#include "mocks/MessageQueueMock.h"
TEST_CASE("Action Helper", "[ActionHelper]") {
ActionHelperOwnerMockBase testDhMock;
// TODO: Setting another number here breaks the test. Find out why
MessageQueueMock testMqMock(MessageQueueIF::NO_QUEUE);
ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
ActionHelperOwnerMockBase testDhMock(&testMqMock);
CommandMessage actionMessage;
ActionId_t testActionId = 777;
ActionId_t testActionId = (ActionId_t)TestActions::TEST_ACTION;
std::array<uint8_t, 3> testParams{1, 2, 3};
store_address_t paramAddress;
StorageManagerIF* ipcStore = tglob::getIpcStoreHandle();
REQUIRE(ipcStore != nullptr);
ipcStore->addData(&paramAddress, testParams.data(), 3);
REQUIRE(actionHelper.initialize() == returnvalue::OK);
REQUIRE(testDhMock.getActionHelper()->initialize() == returnvalue::OK);
SECTION("Simple tests") {
ActionMessage::setCommand(&actionMessage, testActionId, paramAddress);
CHECK(not testDhMock.executeActionCalled);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == returnvalue::OK);
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) == returnvalue::OK);
CHECK(testDhMock.executeActionCalled);
// No message is sent if everything is alright.
CHECK(not testMqMock.wasMessageSent());
store_address_t invalidAddress;
ActionMessage::setCommand(&actionMessage, testActionId, invalidAddress);
actionHelper.handleActionMessage(&actionMessage);
testDhMock.getActionHelper()->handleActionMessage(&actionMessage);
CHECK(testMqMock.wasMessageSent());
const uint8_t* ptr = nullptr;
size_t size = 0;
REQUIRE(ipcStore->getData(paramAddress, &ptr, &size) ==
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
REQUIRE(ptr == nullptr);
REQUIRE(size == 0);
testDhMock.getBuffer(&ptr, &size);
REQUIRE(size == 3);
testDhMock.getBuffer(&ptr);
for (uint8_t i = 0; i < 3; i++) {
REQUIRE(ptr[i] == (i + 1));
}
@ -49,12 +46,12 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
SECTION("Handle failures") {
actionMessage.setCommand(1234);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) ==
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) ==
static_cast<uint32_t>(CommandMessage::UNKNOWN_COMMAND));
CHECK(not testMqMock.wasMessageSent());
uint16_t step = 5;
ReturnValue_t status = 0x1234;
actionHelper.step(step, testMqMock.getId(), testActionId, status);
testDhMock.getActionHelper()->step(step, testMqMock.getId(), testActionId, status);
step += 1;
CHECK(testMqMock.wasMessageSent());
CommandMessage testMessage;
@ -69,7 +66,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
SECTION("Handle finish") {
CHECK(not testMqMock.wasMessageSent());
ReturnValue_t status = 0x9876;
actionHelper.finish(false, testMqMock.getId(), testActionId, status);
testDhMock.getActionHelper()->finish(false, testMqMock.getId(), testActionId, status);
CHECK(testMqMock.wasMessageSent());
CommandMessage testMessage;
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
@ -84,13 +81,13 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == returnvalue::OK);
ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress);
CHECK(not testDhMock.executeActionCalled);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == returnvalue::OK);
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) == returnvalue::OK);
REQUIRE(ipcStore->getData(toLongParamAddress).first ==
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
CommandMessage testMessage;
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
REQUIRE(ActionMessage::getReturnCode(&testMessage) == 0xAFFE);
REQUIRE(ActionMessage::getReturnCode(&testMessage) == HasActionsIF::INVALID_PARAMETERS);
REQUIRE(ActionMessage::getStep(&testMessage) == 0);
REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
}
@ -98,7 +95,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
SECTION("Missing IPC Data") {
ActionMessage::setCommand(&actionMessage, testActionId, store_address_t::invalid());
CHECK(not testDhMock.executeActionCalled);
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == returnvalue::OK);
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) == returnvalue::OK);
CommandMessage testMessage;
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));

View File

@ -2,12 +2,27 @@
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
#include <fsfw/action/HasActionsIF.h>
#include <fsfw/action/Parameter.h>
#include <fsfw/action/TemplateAction.h>
#include <fsfw/introspection/Enum.h>
#include <fsfw/ipc/MessageQueueIF.h>
#include <cstring>
#include "CatchDefinitions.h"
class ActionHelperOwnerMockBase;
FSFW_ENUM(TestActions, ActionId_t, ((TEST_ACTION, "Test Action")))
class TestAction : public TemplateAction < ActionHelperOwnerMockBase, TestAction, TestActions> {
public:
TestAction(ActionHelperOwnerMockBase* owner) : TemplateAction(owner, TestActions::TEST_ACTION) {}
Parameter<uint8_t> p1 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
Parameter<uint8_t> p2 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
Parameter<uint8_t> p3 = Parameter<uint8_t>::createParameter(this, "An uint8_t");
};
class ActionHelperOwnerMockBase : public HasActionsIF {
public:
bool getCommandQueueCalled = false;
@ -16,16 +31,26 @@ class ActionHelperOwnerMockBase : public HasActionsIF {
uint8_t buffer[MAX_SIZE] = {0, 0, 0};
size_t size = 0;
ActionHelperOwnerMockBase(MessageQueueIF* useThisQueue) : actionHelper(this, useThisQueue) {}
MessageQueueId_t getCommandQueue() const override { return tconst::testQueueId; }
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
const uint8_t* data, size_t size) override {
ActionHelper* getActionHelper() override { return &actionHelper; }
ReturnValue_t executeAction(Action* action) override {
executeActionCalled = true;
if (size > MAX_SIZE) {
return 0xAFFE;
}
this->size = size;
memcpy(buffer, data, size);
return action->handle();
}
ReturnValue_t handleAction(TestAction *action){
executeActionCalled = true;
buffer[0] = action->p1;
buffer[1] = action->p2;
buffer[2] = action->p3;
return returnvalue::OK;
}
@ -36,14 +61,15 @@ class ActionHelperOwnerMockBase : public HasActionsIF {
}
}
void getBuffer(const uint8_t** ptr, size_t* size) {
if (size != nullptr) {
*size = this->size;
}
void getBuffer(const uint8_t** ptr) {
if (ptr != nullptr) {
*ptr = buffer;
}
}
private:
ActionHelper actionHelper;
TestAction testAction = TestAction(this);
};
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */

View File

@ -23,7 +23,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
SECTION("Commanding nominal") {
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
DeviceHandlerMock::SIMPLE_COMMAND);
static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND));
REQUIRE(result == returnvalue::OK);
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
@ -43,7 +43,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
// Set the timeout to 0 to immediately timeout the reply
deviceHandlerMock.changeSimpleCommandReplyCountdown(0);
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
DeviceHandlerMock::SIMPLE_COMMAND);
static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND));
REQUIRE(result == returnvalue::OK);
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
@ -60,7 +60,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
SECTION("Periodic reply nominal") {
comIF.setTestCase(ComIFMock::TestCase::PERIODIC_REPLY_NOMINAL);
deviceHandlerMock.enablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
deviceHandlerMock.enablePeriodicReply(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY));
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
@ -73,7 +73,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
comIF.setTestCase(ComIFMock::TestCase::MISSED_REPLY);
// Set the timeout to 0 to immediately timeout the reply
deviceHandlerMock.changePeriodicReplyCountdown(0);
deviceHandlerMock.enablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
deviceHandlerMock.enablePeriodicReply(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY));
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
@ -82,7 +82,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
REQUIRE(missedReplies == 1);
// Test if disabling of periodic reply
deviceHandlerMock.disablePeriodicReply(DeviceHandlerMock::PERIODIC_REPLY);
deviceHandlerMock.disablePeriodicReply(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY));
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);

View File

@ -25,17 +25,13 @@ ReturnValue_t DeviceHandlerMock::buildTransitionDeviceCommand(DeviceCommandId_t
ReturnValue_t DeviceHandlerMock::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
const uint8_t *commandData,
size_t commandDataLen) {
switch (deviceCommand) {
case SIMPLE_COMMAND: {
commandBuffer[0] = SIMPLE_COMMAND_DATA;
rawPacket = commandBuffer;
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
break;
}
default:
WARN("DeviceHandlerMock::buildCommandFromCommand: Invalid device command");
break;
}
return returnvalue::OK;
}
ReturnValue_t DeviceHandlerMock::handleAction(MockAction *action) {
commandBuffer[0] = SIMPLE_COMMAND_DATA;
rawPacket = commandBuffer;
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
return returnvalue::OK;
}
@ -43,13 +39,13 @@ ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
DeviceCommandId_t *foundId, size_t *foundLen) {
switch (*start) {
case SIMPLE_COMMAND_DATA: {
*foundId = SIMPLE_COMMAND;
*foundId = static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND);
*foundLen = sizeof(SIMPLE_COMMAND_DATA);
return returnvalue::OK;
break;
}
case PERIODIC_REPLY_DATA: {
*foundId = PERIODIC_REPLY;
*foundId = static_cast<uint32_t>(MockCommands::PERIODIC_REPLY);
*foundLen = sizeof(PERIODIC_REPLY_DATA);
return returnvalue::OK;
break;
@ -62,8 +58,8 @@ ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
switch (id) {
case SIMPLE_COMMAND:
case PERIODIC_REPLY: {
case static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND):
case static_cast<uint32_t>(MockCommands::PERIODIC_REPLY): {
periodicReplyReceived = true;
break;
}
@ -74,10 +70,10 @@ ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, cons
}
void DeviceHandlerMock::fillCommandAndReplyMap() {
insertInCommandAndReplyMap(SIMPLE_COMMAND, 0, nullptr, 0, false, false, 0,
&simpleCommandReplyTimeout);
insertInCommandAndReplyMap(PERIODIC_REPLY, 0, nullptr, 0, true, false, 0,
&periodicReplyCountdown);
insertInCommandAndReplyMap(static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND), 0, nullptr, 0,
false, false, 0, &simpleCommandReplyTimeout);
insertInCommandAndReplyMap(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY), 0, nullptr, 0,
true, false, 0, &periodicReplyCountdown);
}
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }

View File

@ -2,11 +2,22 @@
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_
#include <fsfw/devicehandlers/DeviceHandlerBase.h>
#include <fsfw/introspection/Enum.h>
#include <fsfw/action/TemplateAction.h>
FSFW_ENUM(MockCommands, ActionId_t, ((SIMPLE_COMMAND, 1, "Simple Command")) ((PERIODIC_REPLY, 2, "Periodic Reply")))
class DeviceHandlerMock;
class MockAction : public TemplateAction<DeviceHandlerMock, MockAction, MockCommands> {
public:
MockAction(DeviceHandlerMock *owner): TemplateAction(owner, MockCommands::SIMPLE_COMMAND) {
}
};
class DeviceHandlerMock : public DeviceHandlerBase {
public:
static const DeviceCommandId_t SIMPLE_COMMAND = 1;
static const DeviceCommandId_t PERIODIC_REPLY = 2;
static const uint8_t SIMPLE_COMMAND_DATA = 1;
static const uint8_t PERIODIC_REPLY_DATA = 2;
@ -21,6 +32,8 @@ class DeviceHandlerMock : public DeviceHandlerBase {
ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId);
ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId);
ReturnValue_t handleAction(MockAction * action);
protected:
void doStartUp() override;
void doShutDown() override;
@ -41,6 +54,8 @@ class DeviceHandlerMock : public DeviceHandlerBase {
uint8_t commandBuffer[1];
bool periodicReplyReceived = false;
MockAction mockAction = MockAction(this);
};
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_ */