Compare commits
32 Commits
develop
...
mohr/intro
Author | SHA1 | Date | |
---|---|---|---|
c42da5df86 | |||
6c711415c1 | |||
253aa30263 | |||
eae7bfc935 | |||
383bafe344 | |||
1c527c4946 | |||
0e6e124eab | |||
c7e6f01f9b | |||
4c0f67adf5 | |||
450ad1dad4 | |||
1dfb3323f7 | |||
f5adcd0625 | |||
bc593c938d | |||
8353964635 | |||
3f8f17a66e | |||
3260a03544 | |||
3ffdc0d31f | |||
d367baa42c | |||
d634bdb775 | |||
59f8dd1322 | |||
61b4e68f3d | |||
e34664d265 | |||
20eb232bf5 | |||
31f59f915c | |||
cfdbe0f6cb | |||
dd281f8a67 | |||
f9e9ff320f | |||
f56646d2c3 | |||
b08d127e11 | |||
ef18377cef | |||
0c057c66b1 | |||
34c50ce3e2 |
3
.gitignore
vendored
3
.gitignore
vendored
@ -10,5 +10,8 @@
|
|||||||
.settings
|
.settings
|
||||||
.metadata
|
.metadata
|
||||||
|
|
||||||
|
# VSCode
|
||||||
|
.vscode
|
||||||
|
|
||||||
/build*
|
/build*
|
||||||
/cmake-build*
|
/cmake-build*
|
||||||
|
@ -15,6 +15,7 @@ add_subdirectory(globalfunctions)
|
|||||||
add_subdirectory(health)
|
add_subdirectory(health)
|
||||||
add_subdirectory(housekeeping)
|
add_subdirectory(housekeeping)
|
||||||
add_subdirectory(internalerror)
|
add_subdirectory(internalerror)
|
||||||
|
add_subdirectory(introspection)
|
||||||
add_subdirectory(ipc)
|
add_subdirectory(ipc)
|
||||||
add_subdirectory(memory)
|
add_subdirectory(memory)
|
||||||
add_subdirectory(modes)
|
add_subdirectory(modes)
|
||||||
|
62
src/fsfw/action/Action.cpp
Normal file
62
src/fsfw/action/Action.cpp
Normal 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 ¶meterList; }
|
||||||
|
|
||||||
|
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
50
src/fsfw/action/Action.h
Normal 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;
|
||||||
|
};
|
@ -57,6 +57,10 @@ void ActionHelper::finish(bool success, MessageQueueId_t reportTo, ActionId_t co
|
|||||||
|
|
||||||
void ActionHelper::setQueueToUse(MessageQueueIF* queue) { queueToUse = queue; }
|
void ActionHelper::setQueueToUse(MessageQueueIF* queue) { queueToUse = queue; }
|
||||||
|
|
||||||
|
MessageQueueIF const * ActionHelper::getQueue() const {
|
||||||
|
return queueToUse;
|
||||||
|
}
|
||||||
|
|
||||||
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
|
void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t actionId,
|
||||||
store_address_t dataAddress) {
|
store_address_t dataAddress) {
|
||||||
const uint8_t* dataPtr = nullptr;
|
const uint8_t* dataPtr = nullptr;
|
||||||
@ -66,9 +70,29 @@ void ActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId_t act
|
|||||||
CommandMessage reply;
|
CommandMessage reply;
|
||||||
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
||||||
queueToUse->sendMessage(commandedBy, &reply);
|
queueToUse->sendMessage(commandedBy, &reply);
|
||||||
|
ipcStore->deleteData(dataAddress);
|
||||||
return;
|
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);
|
ipcStore->deleteData(dataAddress);
|
||||||
if (result == HasActionsIF::EXECUTION_FINISHED) {
|
if (result == HasActionsIF::EXECUTION_FINISHED) {
|
||||||
CommandMessage reply;
|
CommandMessage reply;
|
||||||
@ -163,3 +187,11 @@ ReturnValue_t ActionHelper::reportData(MessageQueueId_t reportTo, ActionId_t rep
|
|||||||
}
|
}
|
||||||
return result;
|
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; }
|
@ -1,9 +1,13 @@
|
|||||||
#ifndef FSFW_ACTION_ACTIONHELPER_H_
|
#ifndef FSFW_ACTION_ACTIONHELPER_H_
|
||||||
#define FSFW_ACTION_ACTIONHELPER_H_
|
#define FSFW_ACTION_ACTIONHELPER_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
|
#include "Action.h"
|
||||||
#include "ActionMessage.h"
|
#include "ActionMessage.h"
|
||||||
#include "fsfw/ipc/MessageQueueIF.h"
|
#include "fsfw/ipc/MessageQueueIF.h"
|
||||||
#include "fsfw/serialize/SerializeIF.h"
|
#include "fsfw/serialize/SerializeIF.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Action Helper is a helper class which handles action messages
|
* @brief Action Helper is a helper class which handles action messages
|
||||||
*
|
*
|
||||||
@ -98,6 +102,16 @@ class ActionHelper {
|
|||||||
*/
|
*/
|
||||||
void setQueueToUse(MessageQueueIF* queue);
|
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:
|
protected:
|
||||||
//! Increase of value of this per step
|
//! Increase of value of this per step
|
||||||
static const uint8_t STEP_OFFSET = 1;
|
static const uint8_t STEP_OFFSET = 1;
|
||||||
@ -108,6 +122,8 @@ class ActionHelper {
|
|||||||
MessageQueueIF* queueToUse;
|
MessageQueueIF* queueToUse;
|
||||||
//! Pointer to an IPC Store, initialized during construction or
|
//! Pointer to an IPC Store, initialized during construction or
|
||||||
StorageManagerIF* ipcStore = nullptr;
|
StorageManagerIF* ipcStore = nullptr;
|
||||||
|
//! Map of all implemented Actions
|
||||||
|
std::map<ActionId_t, Action*> actionMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Internal function called by handleActionMessage
|
* Internal function called by handleActionMessage
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
target_sources(
|
target_sources(
|
||||||
${LIB_FSFW_NAME} PRIVATE ActionHelper.cpp ActionMessage.cpp
|
${LIB_FSFW_NAME} PRIVATE Action.cpp ActionHelper.cpp ActionMessage.cpp
|
||||||
CommandActionHelper.cpp SimpleActionHelper.cpp)
|
CommandActionHelper.cpp SimpleActionHelper.cpp)
|
||||||
|
@ -44,8 +44,12 @@ class HasActionsIF {
|
|||||||
/**
|
/**
|
||||||
* Function to get the MessageQueueId_t of the implementing object
|
* Function to get the MessageQueueId_t of the implementing object
|
||||||
* @return MessageQueueId_t of the object
|
* @return MessageQueueId_t of the object
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
[[nodiscard]] virtual MessageQueueId_t getCommandQueue() const = 0;
|
[[nodiscard]] virtual MessageQueueId_t getCommandQueue() const = 0;
|
||||||
|
|
||||||
|
[[nodiscard]] virtual ActionHelper* getActionHelper() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Execute or initialize the execution of a certain function.
|
* Execute or initialize the execution of a certain function.
|
||||||
* The ActionHelpers will execute this function and behave differently
|
* The ActionHelpers will execute this function and behave differently
|
||||||
@ -55,8 +59,7 @@ class HasActionsIF {
|
|||||||
* -@c EXECUTION_FINISHED Finish reply will be generated
|
* -@c EXECUTION_FINISHED Finish reply will be generated
|
||||||
* -@c Not returnvalue::OK Step failure reply will be generated
|
* -@c Not returnvalue::OK Step failure reply will be generated
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
virtual ReturnValue_t executeAction(Action* action) = 0;
|
||||||
const uint8_t* data, size_t size) = 0;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FSFW_ACTION_HASACTIONSIF_H_ */
|
#endif /* FSFW_ACTION_HASACTIONSIF_H_ */
|
||||||
|
40
src/fsfw/action/MinMaxParameter.h
Normal file
40
src/fsfw/action/MinMaxParameter.h
Normal 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
120
src/fsfw/action/Parameter.h
Normal 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
|
45
src/fsfw/action/ParameterIF.h
Normal file
45
src/fsfw/action/ParameterIF.h
Normal 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
|
||||||
|
};
|
@ -44,11 +44,27 @@ void SimpleActionHelper::prepareExecution(MessageQueueId_t commandedBy, ActionId
|
|||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
ActionMessage::setStepReply(&reply, actionId, 0, result);
|
||||||
queueToUse->sendMessage(commandedBy, &reply);
|
queueToUse->sendMessage(commandedBy, &reply);
|
||||||
|
ipcStore->deleteData(dataAddress);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
lastCommander = commandedBy;
|
auto actionIter = actionMap.find(actionId);
|
||||||
lastAction = actionId;
|
if (actionIter == actionMap.end()){
|
||||||
result = owner->executeAction(actionId, commandedBy, dataPtr, size);
|
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);
|
ipcStore->deleteData(dataAddress);
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case returnvalue::OK:
|
case returnvalue::OK:
|
||||||
|
29
src/fsfw/action/TemplateAction.h
Normal file
29
src/fsfw/action/TemplateAction.h
Normal 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;
|
||||||
|
};
|
@ -103,6 +103,10 @@ ReturnValue_t ControllerBase::performOperation(uint8_t opCode) {
|
|||||||
|
|
||||||
void ControllerBase::modeChanged(Mode_t mode_, Submode_t submode_) {}
|
void ControllerBase::modeChanged(Mode_t mode_, Submode_t submode_) {}
|
||||||
|
|
||||||
|
const ModeHelper * ControllerBase::getModeHelper() const {
|
||||||
|
return &modeHelper;
|
||||||
|
}
|
||||||
|
|
||||||
ReturnValue_t ControllerBase::setHealth(HealthState health) {
|
ReturnValue_t ControllerBase::setHealth(HealthState health) {
|
||||||
switch (health) {
|
switch (health) {
|
||||||
case HEALTHY:
|
case HEALTHY:
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
#include "fsfw/health/HasHealthIF.h"
|
#include "fsfw/health/HasHealthIF.h"
|
||||||
#include "fsfw/health/HealthHelper.h"
|
#include "fsfw/health/HealthHelper.h"
|
||||||
|
#include "fsfw/introspection/ClasslessEnum.h"
|
||||||
#include "fsfw/modes/HasModesIF.h"
|
#include "fsfw/modes/HasModesIF.h"
|
||||||
#include "fsfw/modes/ModeHelper.h"
|
#include "fsfw/modes/ModeHelper.h"
|
||||||
#include "fsfw/objectmanager/SystemObject.h"
|
#include "fsfw/objectmanager/SystemObject.h"
|
||||||
@ -20,7 +21,9 @@ class ControllerBase : public HasModesIF,
|
|||||||
public ExecutableObjectIF,
|
public ExecutableObjectIF,
|
||||||
public SystemObject {
|
public SystemObject {
|
||||||
public:
|
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(object_id_t setObjectId, object_id_t parentId, size_t commandQueueDepth = 3);
|
||||||
~ControllerBase() override;
|
~ControllerBase() override;
|
||||||
@ -39,6 +42,9 @@ class ControllerBase : public HasModesIF,
|
|||||||
void setTaskIF(PeriodicTaskIF *task) override;
|
void setTaskIF(PeriodicTaskIF *task) override;
|
||||||
ReturnValue_t initializeAfterTaskCreation() override;
|
ReturnValue_t initializeAfterTaskCreation() override;
|
||||||
|
|
||||||
|
/** HasModeIF override */
|
||||||
|
const ModeHelper *getModeHelper() const override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
/**
|
/**
|
||||||
* Implemented by child class. Handle command messages which are not
|
* Implemented by child class. Handle command messages which are not
|
||||||
|
@ -8,11 +8,12 @@ ExtendedControllerBase::ExtendedControllerBase(object_id_t objectId, object_id_t
|
|||||||
|
|
||||||
ExtendedControllerBase::~ExtendedControllerBase() = default;
|
ExtendedControllerBase::~ExtendedControllerBase() = default;
|
||||||
|
|
||||||
ReturnValue_t ExtendedControllerBase::executeAction(ActionId_t actionId,
|
ActionHelper *ExtendedControllerBase::getActionHelper() {
|
||||||
MessageQueueId_t commandedBy,
|
return &actionHelper;
|
||||||
const uint8_t *data, size_t size) {
|
}
|
||||||
/* Needs to be overriden and implemented by child class. */
|
|
||||||
return returnvalue::OK;
|
ReturnValue_t ExtendedControllerBase::executeAction(Action *action) {
|
||||||
|
return action->handle();
|
||||||
}
|
}
|
||||||
|
|
||||||
object_id_t ExtendedControllerBase::getObjectId() const { return SystemObject::getObjectId(); }
|
object_id_t ExtendedControllerBase::getObjectId() const { return SystemObject::getObjectId(); }
|
||||||
|
@ -29,6 +29,10 @@ class ExtendedControllerBase : public ControllerBase,
|
|||||||
ReturnValue_t performOperation(uint8_t opCode) override;
|
ReturnValue_t performOperation(uint8_t opCode) override;
|
||||||
ReturnValue_t initializeAfterTaskCreation() override;
|
ReturnValue_t initializeAfterTaskCreation() override;
|
||||||
|
|
||||||
|
/* HasActionsIF overrides */
|
||||||
|
ActionHelper* getActionHelper() override;
|
||||||
|
ReturnValue_t executeAction(Action* actionId) override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
LocalDataPoolManager poolManager;
|
LocalDataPoolManager poolManager;
|
||||||
ActionHelper actionHelper;
|
ActionHelper actionHelper;
|
||||||
@ -49,10 +53,6 @@ class ExtendedControllerBase : public ControllerBase,
|
|||||||
/* Handle the four messages mentioned above */
|
/* Handle the four messages mentioned above */
|
||||||
void handleQueue() override;
|
void handleQueue() override;
|
||||||
|
|
||||||
/* HasActionsIF overrides */
|
|
||||||
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
|
||||||
const uint8_t* data, size_t size) override;
|
|
||||||
|
|
||||||
/* HasLocalDatapoolIF overrides */
|
/* HasLocalDatapoolIF overrides */
|
||||||
LocalDataPoolManager* getHkManagerHandle() override;
|
LocalDataPoolManager* getHkManagerHandle() override;
|
||||||
[[nodiscard]] object_id_t getObjectId() const override;
|
[[nodiscard]] object_id_t getObjectId() const override;
|
||||||
|
@ -1324,21 +1324,21 @@ void DeviceHandlerBase::handleDeviceTm(const SerializeIF& dataSet, DeviceCommand
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnValue_t DeviceHandlerBase::executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
ActionHelper* DeviceHandlerBase::getActionHelper() { return &actionHelper; }
|
||||||
const uint8_t* data, size_t size) {
|
|
||||||
|
ReturnValue_t DeviceHandlerBase::executeAction(Action* action) {
|
||||||
ReturnValue_t result = acceptExternalDeviceCommands();
|
ReturnValue_t result = acceptExternalDeviceCommands();
|
||||||
if (result != returnvalue::OK) {
|
if (result != returnvalue::OK) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
DeviceCommandMap::iterator iter = deviceCommandMap.find(actionId);
|
DeviceCommandMap::iterator iter = deviceCommandMap.find(action->getId());
|
||||||
MessageQueueId_t prevRecipient = MessageQueueIF::NO_QUEUE;
|
|
||||||
if (iter == deviceCommandMap.end()) {
|
if (iter == deviceCommandMap.end()) {
|
||||||
result = COMMAND_NOT_SUPPORTED;
|
result = COMMAND_NOT_SUPPORTED;
|
||||||
} else if (iter->second.isExecuting) {
|
} else if (iter->second.isExecuting) {
|
||||||
result = COMMAND_ALREADY_SENT;
|
result = COMMAND_ALREADY_SENT;
|
||||||
} else {
|
} else {
|
||||||
iter->second.sendReplyTo = commandedBy;
|
iter->second.sendReplyTo = action->commandedBy;
|
||||||
result = buildCommandFromCommand(actionId, data, size);
|
result = action->handle();
|
||||||
}
|
}
|
||||||
if (result == returnvalue::OK) {
|
if (result == returnvalue::OK) {
|
||||||
iter->second.isExecuting = true;
|
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>();
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -204,13 +204,15 @@ class DeviceHandlerBase : public DeviceHandlerIF,
|
|||||||
*/
|
*/
|
||||||
virtual void setParentQueue(MessageQueueId_t parentQueueId);
|
virtual void setParentQueue(MessageQueueId_t parentQueueId);
|
||||||
|
|
||||||
/** @brief Implementation required for HasActionIF */
|
/** @brief Implementations required for HasActionIF */
|
||||||
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
ActionHelper* getActionHelper() override;
|
||||||
const uint8_t *data, size_t size) override;
|
ReturnValue_t executeAction(Action *action) override;
|
||||||
|
|
||||||
Mode_t getTransitionSourceMode() const;
|
Mode_t getTransitionSourceMode() const;
|
||||||
Submode_t getTransitionSourceSubMode() 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();
|
HealthState getHealth();
|
||||||
ReturnValue_t setHealth(HealthState health);
|
ReturnValue_t setHealth(HealthState health);
|
||||||
virtual ReturnValue_t getParameter(uint8_t domainId, uint8_t uniqueId,
|
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
|
* - Anything else triggers an even with the returnvalue as a parameter
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t buildTransitionDeviceCommand(DeviceCommandId_t *id) = 0;
|
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
|
* @brief Build a device command packet from data supplied by a direct
|
||||||
* command (PUS Service 8)
|
* command (PUS Service 8)
|
||||||
@ -340,7 +344,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) = 0;
|
size_t commandDataLen) {return returnvalue::FAILED;}
|
||||||
|
|
||||||
/* Reply handling */
|
/* Reply handling */
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include "../action/HasActionsIF.h"
|
#include "../action/HasActionsIF.h"
|
||||||
#include "../datapoollocal/localPoolDefinitions.h"
|
#include "../datapoollocal/localPoolDefinitions.h"
|
||||||
#include "../events/Event.h"
|
#include "../events/Event.h"
|
||||||
|
#include "../introspection/ClasslessEnum.h"
|
||||||
#include "../ipc/MessageQueueSenderIF.h"
|
#include "../ipc/MessageQueueSenderIF.h"
|
||||||
#include "../modes/HasModesIF.h"
|
#include "../modes/HasModesIF.h"
|
||||||
#include "DeviceHandlerMessage.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
|
* 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
|
* handler. MODE_ON and MODE_OFF are included in hasModesIF.h
|
||||||
*/
|
*/
|
||||||
|
FSFW_CLASSLESS_ENUM(
|
||||||
// MODE_ON = 0, //!< The device is powered and ready to perform operations. In this mode, no
|
DeviceHandlerMode, Mode_t,
|
||||||
// commands are sent by the device handler itself, but direct commands van be commanded and will
|
//! The device is powered and ready to perform operations. In this mode, no
|
||||||
// be interpreted MODE_OFF = 1, //!< The device is powered off. The only command accepted in this
|
//! commands are sent by the device handler itself, but direct commands can be
|
||||||
// mode is a mode change to on.
|
//! 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
|
//! The device is powered on and the device handler periodically sends
|
||||||
//! commands. The commands to be sent are selected by the handler
|
//! commands. The commands to be sent are selected by the handler
|
||||||
//! according to the submode.
|
//! according to the submode.
|
||||||
static const Mode_t MODE_NORMAL = 2;
|
((MODE_NORMAL, 2, "Normal"))
|
||||||
//! The device is powered on and ready to perform operations. In this mode,
|
//! 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
|
//! raw commands can be sent. The device handler will send all replies
|
||||||
//! received from the command back to the commanding object.
|
//! received from the command back to the commanding object as raw TM
|
||||||
static const Mode_t MODE_RAW = 3;
|
((MODE_RAW, 3, "Raw"))
|
||||||
//! The device is shut down but the switch could not be turned off, so the
|
//! 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
|
//! 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.
|
//! can be commanded, which tries to switch off the device again.
|
||||||
static const Mode_t MODE_ERROR_ON = 4;
|
((MODE_ERROR_ON, 4, "Error")))
|
||||||
|
|
||||||
//! This is a transitional state which can not be commanded. The device
|
//! 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
|
//! 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.
|
//! perform commands. When this is completed, the mode changes to @c MODE_ON.
|
||||||
|
1
src/fsfw/introspection/CMakeLists.txt
Normal file
1
src/fsfw/introspection/CMakeLists.txt
Normal file
@ -0,0 +1 @@
|
|||||||
|
target_sources(${LIB_FSFW_NAME} PRIVATE ParameterTypeSelector.cpp)
|
48
src/fsfw/introspection/ClasslessEnum.h
Normal file
48
src/fsfw/introspection/ClasslessEnum.h
Normal 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
|
64
src/fsfw/introspection/Enum.h
Normal file
64
src/fsfw/introspection/Enum.h
Normal 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
|
62
src/fsfw/introspection/EnumCommon.h
Normal file
62
src/fsfw/introspection/EnumCommon.h
Normal 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
|
16
src/fsfw/introspection/EnumIF.h
Normal file
16
src/fsfw/introspection/EnumIF.h
Normal 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;
|
||||||
|
};
|
56
src/fsfw/introspection/ParameterTypeSelector.cpp
Normal file
56
src/fsfw/introspection/ParameterTypeSelector.cpp
Normal 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
|
13
src/fsfw/introspection/ParameterTypeSelector.h
Normal file
13
src/fsfw/introspection/ParameterTypeSelector.h
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Types.h"
|
||||||
|
|
||||||
|
#ifdef FSFW_INTROSPECTION
|
||||||
|
|
||||||
|
class ParameterTypeSelector {
|
||||||
|
public:
|
||||||
|
template <typename T>
|
||||||
|
static Types::ParameterType getType();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
8
src/fsfw/introspection/Types.h
Normal file
8
src/fsfw/introspection/Types.h
Normal 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
|
74
src/fsfw/introspection/TypesHelper.h
Normal file
74
src/fsfw/introspection/TypesHelper.h
Normal 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
|
||||||
|
};
|
@ -4,7 +4,9 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
|
|
||||||
#include "../events/Event.h"
|
#include "../events/Event.h"
|
||||||
|
#include "../introspection/ClasslessEnum.h"
|
||||||
#include "../returnvalues/returnvalue.h"
|
#include "../returnvalues/returnvalue.h"
|
||||||
|
#include "ModeDefinitionHelper.h"
|
||||||
#include "ModeHelper.h"
|
#include "ModeHelper.h"
|
||||||
#include "ModeMessage.h"
|
#include "ModeMessage.h"
|
||||||
|
|
||||||
@ -35,7 +37,7 @@ class HasModesIF {
|
|||||||
static const Event MODE_CMD_REJECTED = MAKE_EVENT(7, severity::LOW);
|
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
|
//! 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
|
//! interpreted
|
||||||
static constexpr Mode_t MODE_ON = 1;
|
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.
|
//! 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_INVALID = -1;
|
||||||
static constexpr Mode_t MODE_UNDEFINED = -2;
|
static constexpr Mode_t MODE_UNDEFINED = -2;
|
||||||
|
|
||||||
//! To avoid checks against magic number "0".
|
FSFW_CLASSLESS_ENUM(DefaultSubmode, Submode_t,
|
||||||
static const Submode_t SUBMODE_NONE = 0;
|
((SUBMODE_NONE, 0,
|
||||||
|
"Default"))) //!< To avoid checks against magic number "0".
|
||||||
|
|
||||||
virtual ~HasModesIF() {}
|
virtual ~HasModesIF() {}
|
||||||
virtual MessageQueueId_t getCommandQueue() const = 0;
|
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;
|
virtual void getMode(Mode_t *mode, Submode_t *submode) = 0;
|
||||||
|
|
||||||
protected:
|
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/modes/HasModesIF.h"
|
||||||
#include "fsfw/serviceinterface/ServiceInterface.h"
|
#include "fsfw/serviceinterface/ServiceInterface.h"
|
||||||
|
|
||||||
ModeHelper::ModeHelper(HasModesIF* owner)
|
ModeHelper::ModeHelper(HasModesIF *owner)
|
||||||
: commandedMode(HasModesIF::MODE_OFF),
|
: commandedMode(HasModesIF::MODE_OFF),
|
||||||
commandedSubmode(HasModesIF::SUBMODE_NONE),
|
commandedSubmode(HasModesIF::SUBMODE_NONE),
|
||||||
owner(owner),
|
owner(owner),
|
||||||
@ -12,7 +12,7 @@ ModeHelper::ModeHelper(HasModesIF* owner)
|
|||||||
|
|
||||||
ModeHelper::~ModeHelper() {}
|
ModeHelper::~ModeHelper() {}
|
||||||
|
|
||||||
ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* command) {
|
ReturnValue_t ModeHelper::handleModeCommand(CommandMessage *command) {
|
||||||
CommandMessage reply;
|
CommandMessage reply;
|
||||||
Mode_t mode;
|
Mode_t mode;
|
||||||
Submode_t submode;
|
Submode_t submode;
|
||||||
@ -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
|
@ -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/returnvalue.h"
|
#include "fsfw/returnvalues/returnvalue.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;
|
||||||
|
@ -78,7 +78,7 @@ SystemObjectIF* ObjectManager::getSystemObject(object_id_t id) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ObjectManager::initialize() {
|
void ObjectManager::produce() {
|
||||||
if (objectFactoryFunction == nullptr) {
|
if (objectFactoryFunction == nullptr) {
|
||||||
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
#if FSFW_CPP_OSTREAM_ENABLED == 1
|
||||||
sif::error << "ObjectManager::initialize: Passed produceObjects "
|
sif::error << "ObjectManager::initialize: Passed produceObjects "
|
||||||
@ -90,6 +90,10 @@ void ObjectManager::initialize() {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
objectFactoryFunction(factoryArgs);
|
objectFactoryFunction(factoryArgs);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ObjectManager::initialize() {
|
||||||
|
produce();
|
||||||
ReturnValue_t result = returnvalue::FAILED;
|
ReturnValue_t result = returnvalue::FAILED;
|
||||||
uint32_t errorCount = 0;
|
uint32_t errorCount = 0;
|
||||||
for (auto const& it : objectList) {
|
for (auto const& it : objectList) {
|
||||||
@ -143,3 +147,7 @@ void ObjectManager::printList() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const std::map<object_id_t, SystemObjectIF*> * ObjectManager::getObjectList(){
|
||||||
|
return &objectList;
|
||||||
|
}
|
||||||
|
@ -42,7 +42,9 @@ class ObjectManager : public ObjectManagerIF {
|
|||||||
ReturnValue_t insert(object_id_t id, SystemObjectIF* object) override;
|
ReturnValue_t insert(object_id_t id, SystemObjectIF* object) override;
|
||||||
ReturnValue_t remove(object_id_t id) override;
|
ReturnValue_t remove(object_id_t id) override;
|
||||||
void initialize() override;
|
void initialize() override;
|
||||||
|
void produce() override;
|
||||||
void printList() override;
|
void printList() override;
|
||||||
|
const std::map<object_id_t, SystemObjectIF*> * getObjectList() override;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
SystemObjectIF* getSystemObject(object_id_t id) override;
|
SystemObjectIF* getSystemObject(object_id_t id) override;
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
#ifndef FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
#ifndef FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||||
#define FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
#define FSFW_OBJECTMANAGER_OBJECTMANAGERIF_H_
|
||||||
|
|
||||||
|
#include <map>
|
||||||
|
|
||||||
#include "../returnvalues/returnvalue.h"
|
#include "../returnvalues/returnvalue.h"
|
||||||
#include "../serviceinterface/ServiceInterface.h"
|
#include "../serviceinterface/ServiceInterface.h"
|
||||||
#include "SystemObjectIF.h"
|
#include "SystemObjectIF.h"
|
||||||
@ -58,12 +60,14 @@ class ObjectManagerIF {
|
|||||||
* @li returnvalue::OK in case the object was successfully removed
|
* @li returnvalue::OK in case the object was successfully removed
|
||||||
*/
|
*/
|
||||||
virtual ReturnValue_t remove(object_id_t id) = 0;
|
virtual ReturnValue_t remove(object_id_t id) = 0;
|
||||||
|
virtual void produce() = 0;
|
||||||
virtual void initialize() = 0;
|
virtual void initialize() = 0;
|
||||||
/**
|
/**
|
||||||
* @brief This is a debug function, that prints the current content of the
|
* @brief This is a debug function, that prints the current content of the
|
||||||
* object list.
|
* object list.
|
||||||
*/
|
*/
|
||||||
virtual void printList() = 0;
|
virtual void printList() = 0;
|
||||||
|
virtual const std::map<object_id_t, SystemObjectIF*>* getObjectList() = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* OBJECTMANAGERIF_H_ */
|
#endif /* OBJECTMANAGERIF_H_ */
|
||||||
|
@ -327,3 +327,7 @@ ReturnValue_t SubsystemBase::setHealth(HealthState health) {
|
|||||||
HasHealthIF::HealthState SubsystemBase::getHealth() { return healthHelper.getHealth(); }
|
HasHealthIF::HealthState SubsystemBase::getHealth() { return healthHelper.getHealth(); }
|
||||||
|
|
||||||
void SubsystemBase::modeChanged() {}
|
void SubsystemBase::modeChanged() {}
|
||||||
|
|
||||||
|
const ModeHelper * SubsystemBase::getModeHelper() const {
|
||||||
|
return &modeHelper;
|
||||||
|
}
|
@ -40,7 +40,9 @@ class SubsystemBase : public SystemObject,
|
|||||||
uint16_t commandQueueDepth = 8);
|
uint16_t commandQueueDepth = 8);
|
||||||
virtual ~SubsystemBase();
|
virtual ~SubsystemBase();
|
||||||
|
|
||||||
virtual MessageQueueId_t getCommandQueue() const override;
|
MessageQueueId_t getCommandQueue() const override;
|
||||||
|
|
||||||
|
const ModeHelper * getModeHelper() const override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to register the child objects.
|
* Function to register the child objects.
|
||||||
@ -55,13 +57,13 @@ class SubsystemBase : public SystemObject,
|
|||||||
*/
|
*/
|
||||||
ReturnValue_t registerChild(object_id_t objectId);
|
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:
|
protected:
|
||||||
struct ChildInfo {
|
struct ChildInfo {
|
||||||
|
@ -9,38 +9,35 @@
|
|||||||
#include "mocks/MessageQueueMock.h"
|
#include "mocks/MessageQueueMock.h"
|
||||||
|
|
||||||
TEST_CASE("Action Helper", "[ActionHelper]") {
|
TEST_CASE("Action Helper", "[ActionHelper]") {
|
||||||
ActionHelperOwnerMockBase testDhMock;
|
|
||||||
// TODO: Setting another number here breaks the test. Find out why
|
// TODO: Setting another number here breaks the test. Find out why
|
||||||
MessageQueueMock testMqMock(MessageQueueIF::NO_QUEUE);
|
MessageQueueMock testMqMock(MessageQueueIF::NO_QUEUE);
|
||||||
ActionHelper actionHelper = ActionHelper(&testDhMock, dynamic_cast<MessageQueueIF*>(&testMqMock));
|
ActionHelperOwnerMockBase testDhMock(&testMqMock);
|
||||||
CommandMessage actionMessage;
|
CommandMessage actionMessage;
|
||||||
ActionId_t testActionId = 777;
|
ActionId_t testActionId = (ActionId_t)TestActions::TEST_ACTION;
|
||||||
std::array<uint8_t, 3> testParams{1, 2, 3};
|
std::array<uint8_t, 3> testParams{1, 2, 3};
|
||||||
store_address_t paramAddress;
|
store_address_t paramAddress;
|
||||||
StorageManagerIF* ipcStore = tglob::getIpcStoreHandle();
|
StorageManagerIF* ipcStore = tglob::getIpcStoreHandle();
|
||||||
REQUIRE(ipcStore != nullptr);
|
REQUIRE(ipcStore != nullptr);
|
||||||
ipcStore->addData(¶mAddress, testParams.data(), 3);
|
ipcStore->addData(¶mAddress, testParams.data(), 3);
|
||||||
REQUIRE(actionHelper.initialize() == returnvalue::OK);
|
REQUIRE(testDhMock.getActionHelper()->initialize() == returnvalue::OK);
|
||||||
|
|
||||||
SECTION("Simple tests") {
|
SECTION("Simple tests") {
|
||||||
ActionMessage::setCommand(&actionMessage, testActionId, paramAddress);
|
ActionMessage::setCommand(&actionMessage, testActionId, paramAddress);
|
||||||
CHECK(not testDhMock.executeActionCalled);
|
CHECK(not testDhMock.executeActionCalled);
|
||||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == returnvalue::OK);
|
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) == returnvalue::OK);
|
||||||
CHECK(testDhMock.executeActionCalled);
|
CHECK(testDhMock.executeActionCalled);
|
||||||
// No message is sent if everything is alright.
|
// No message is sent if everything is alright.
|
||||||
CHECK(not testMqMock.wasMessageSent());
|
CHECK(not testMqMock.wasMessageSent());
|
||||||
store_address_t invalidAddress;
|
store_address_t invalidAddress;
|
||||||
ActionMessage::setCommand(&actionMessage, testActionId, invalidAddress);
|
ActionMessage::setCommand(&actionMessage, testActionId, invalidAddress);
|
||||||
actionHelper.handleActionMessage(&actionMessage);
|
testDhMock.getActionHelper()->handleActionMessage(&actionMessage);
|
||||||
CHECK(testMqMock.wasMessageSent());
|
CHECK(testMqMock.wasMessageSent());
|
||||||
const uint8_t* ptr = nullptr;
|
const uint8_t* ptr = nullptr;
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
REQUIRE(ipcStore->getData(paramAddress, &ptr, &size) ==
|
REQUIRE(ipcStore->getData(paramAddress, &ptr, &size) ==
|
||||||
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
|
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
|
||||||
REQUIRE(ptr == nullptr);
|
REQUIRE(ptr == nullptr);
|
||||||
REQUIRE(size == 0);
|
testDhMock.getBuffer(&ptr);
|
||||||
testDhMock.getBuffer(&ptr, &size);
|
|
||||||
REQUIRE(size == 3);
|
|
||||||
for (uint8_t i = 0; i < 3; i++) {
|
for (uint8_t i = 0; i < 3; i++) {
|
||||||
REQUIRE(ptr[i] == (i + 1));
|
REQUIRE(ptr[i] == (i + 1));
|
||||||
}
|
}
|
||||||
@ -49,12 +46,12 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
|||||||
|
|
||||||
SECTION("Handle failures") {
|
SECTION("Handle failures") {
|
||||||
actionMessage.setCommand(1234);
|
actionMessage.setCommand(1234);
|
||||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) ==
|
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) ==
|
||||||
static_cast<uint32_t>(CommandMessage::UNKNOWN_COMMAND));
|
static_cast<uint32_t>(CommandMessage::UNKNOWN_COMMAND));
|
||||||
CHECK(not testMqMock.wasMessageSent());
|
CHECK(not testMqMock.wasMessageSent());
|
||||||
uint16_t step = 5;
|
uint16_t step = 5;
|
||||||
ReturnValue_t status = 0x1234;
|
ReturnValue_t status = 0x1234;
|
||||||
actionHelper.step(step, testMqMock.getId(), testActionId, status);
|
testDhMock.getActionHelper()->step(step, testMqMock.getId(), testActionId, status);
|
||||||
step += 1;
|
step += 1;
|
||||||
CHECK(testMqMock.wasMessageSent());
|
CHECK(testMqMock.wasMessageSent());
|
||||||
CommandMessage testMessage;
|
CommandMessage testMessage;
|
||||||
@ -69,7 +66,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
|||||||
SECTION("Handle finish") {
|
SECTION("Handle finish") {
|
||||||
CHECK(not testMqMock.wasMessageSent());
|
CHECK(not testMqMock.wasMessageSent());
|
||||||
ReturnValue_t status = 0x9876;
|
ReturnValue_t status = 0x9876;
|
||||||
actionHelper.finish(false, testMqMock.getId(), testActionId, status);
|
testDhMock.getActionHelper()->finish(false, testMqMock.getId(), testActionId, status);
|
||||||
CHECK(testMqMock.wasMessageSent());
|
CHECK(testMqMock.wasMessageSent());
|
||||||
CommandMessage testMessage;
|
CommandMessage testMessage;
|
||||||
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
|
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
|
||||||
@ -84,13 +81,13 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
|||||||
REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == returnvalue::OK);
|
REQUIRE(ipcStore->addData(&toLongParamAddress, toLongData.data(), 5) == returnvalue::OK);
|
||||||
ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress);
|
ActionMessage::setCommand(&actionMessage, testActionId, toLongParamAddress);
|
||||||
CHECK(not testDhMock.executeActionCalled);
|
CHECK(not testDhMock.executeActionCalled);
|
||||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == returnvalue::OK);
|
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) == returnvalue::OK);
|
||||||
REQUIRE(ipcStore->getData(toLongParamAddress).first ==
|
REQUIRE(ipcStore->getData(toLongParamAddress).first ==
|
||||||
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
|
static_cast<uint32_t>(StorageManagerIF::DATA_DOES_NOT_EXIST));
|
||||||
CommandMessage testMessage;
|
CommandMessage testMessage;
|
||||||
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
|
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
|
||||||
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
|
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::getStep(&testMessage) == 0);
|
||||||
REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
|
REQUIRE(ActionMessage::getActionId(&testMessage) == testActionId);
|
||||||
}
|
}
|
||||||
@ -98,7 +95,7 @@ TEST_CASE("Action Helper", "[ActionHelper]") {
|
|||||||
SECTION("Missing IPC Data") {
|
SECTION("Missing IPC Data") {
|
||||||
ActionMessage::setCommand(&actionMessage, testActionId, store_address_t::invalid());
|
ActionMessage::setCommand(&actionMessage, testActionId, store_address_t::invalid());
|
||||||
CHECK(not testDhMock.executeActionCalled);
|
CHECK(not testDhMock.executeActionCalled);
|
||||||
REQUIRE(actionHelper.handleActionMessage(&actionMessage) == returnvalue::OK);
|
REQUIRE(testDhMock.getActionHelper()->handleActionMessage(&actionMessage) == returnvalue::OK);
|
||||||
CommandMessage testMessage;
|
CommandMessage testMessage;
|
||||||
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
|
REQUIRE(testMqMock.getNextSentMessage(testMessage) == returnvalue::OK);
|
||||||
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
|
REQUIRE(testMessage.getCommand() == static_cast<uint32_t>(ActionMessage::STEP_FAILED));
|
||||||
|
@ -2,12 +2,27 @@
|
|||||||
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
|
#define UNITTEST_HOSTED_TESTACTIONHELPER_H_
|
||||||
|
|
||||||
#include <fsfw/action/HasActionsIF.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 <fsfw/ipc/MessageQueueIF.h>
|
||||||
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
|
|
||||||
#include "CatchDefinitions.h"
|
#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 {
|
class ActionHelperOwnerMockBase : public HasActionsIF {
|
||||||
public:
|
public:
|
||||||
bool getCommandQueueCalled = false;
|
bool getCommandQueueCalled = false;
|
||||||
@ -16,16 +31,26 @@ class ActionHelperOwnerMockBase : public HasActionsIF {
|
|||||||
uint8_t buffer[MAX_SIZE] = {0, 0, 0};
|
uint8_t buffer[MAX_SIZE] = {0, 0, 0};
|
||||||
size_t size = 0;
|
size_t size = 0;
|
||||||
|
|
||||||
|
ActionHelperOwnerMockBase(MessageQueueIF* useThisQueue) : actionHelper(this, useThisQueue) {}
|
||||||
|
|
||||||
MessageQueueId_t getCommandQueue() const override { return tconst::testQueueId; }
|
MessageQueueId_t getCommandQueue() const override { return tconst::testQueueId; }
|
||||||
|
|
||||||
ReturnValue_t executeAction(ActionId_t actionId, MessageQueueId_t commandedBy,
|
ActionHelper* getActionHelper() override { return &actionHelper; }
|
||||||
const uint8_t* data, size_t size) override {
|
|
||||||
|
ReturnValue_t executeAction(Action* action) override {
|
||||||
executeActionCalled = true;
|
executeActionCalled = true;
|
||||||
if (size > MAX_SIZE) {
|
if (size > MAX_SIZE) {
|
||||||
return 0xAFFE;
|
return 0xAFFE;
|
||||||
}
|
}
|
||||||
this->size = size;
|
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;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,14 +61,15 @@ class ActionHelperOwnerMockBase : public HasActionsIF {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void getBuffer(const uint8_t** ptr, size_t* size) {
|
void getBuffer(const uint8_t** ptr) {
|
||||||
if (size != nullptr) {
|
|
||||||
*size = this->size;
|
|
||||||
}
|
|
||||||
if (ptr != nullptr) {
|
if (ptr != nullptr) {
|
||||||
*ptr = buffer;
|
*ptr = buffer;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
ActionHelper actionHelper;
|
||||||
|
TestAction testAction = TestAction(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */
|
#endif /* UNITTEST_TESTFW_NEWTESTS_TESTACTIONHELPER_H_ */
|
||||||
|
@ -23,7 +23,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
|||||||
SECTION("Commanding nominal") {
|
SECTION("Commanding nominal") {
|
||||||
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
|
comIF.setTestCase(ComIFMock::TestCase::SIMPLE_COMMAND_NOMINAL);
|
||||||
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
|
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
|
||||||
DeviceHandlerMock::SIMPLE_COMMAND);
|
static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND));
|
||||||
REQUIRE(result == returnvalue::OK);
|
REQUIRE(result == returnvalue::OK);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
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
|
// Set the timeout to 0 to immediately timeout the reply
|
||||||
deviceHandlerMock.changeSimpleCommandReplyCountdown(0);
|
deviceHandlerMock.changeSimpleCommandReplyCountdown(0);
|
||||||
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
|
result = deviceHandlerCommander.sendCommand(objects::DEVICE_HANDLER_MOCK,
|
||||||
DeviceHandlerMock::SIMPLE_COMMAND);
|
static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND));
|
||||||
REQUIRE(result == returnvalue::OK);
|
REQUIRE(result == returnvalue::OK);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::PERFORM_OPERATION);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||||
@ -60,7 +60,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
|||||||
|
|
||||||
SECTION("Periodic reply nominal") {
|
SECTION("Periodic reply nominal") {
|
||||||
comIF.setTestCase(ComIFMock::TestCase::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::PERFORM_OPERATION);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
||||||
@ -73,7 +73,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
|||||||
comIF.setTestCase(ComIFMock::TestCase::MISSED_REPLY);
|
comIF.setTestCase(ComIFMock::TestCase::MISSED_REPLY);
|
||||||
// Set the timeout to 0 to immediately timeout the reply
|
// Set the timeout to 0 to immediately timeout the reply
|
||||||
deviceHandlerMock.changePeriodicReplyCountdown(0);
|
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::PERFORM_OPERATION);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
||||||
@ -82,7 +82,7 @@ TEST_CASE("Device Handler Base", "[DeviceHandlerBase]") {
|
|||||||
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
|
uint32_t missedReplies = deviceFdirMock.getMissedReplyCount();
|
||||||
REQUIRE(missedReplies == 1);
|
REQUIRE(missedReplies == 1);
|
||||||
// Test if disabling of periodic reply
|
// 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::PERFORM_OPERATION);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::SEND_WRITE);
|
||||||
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
deviceHandlerMock.performOperation(DeviceHandlerIF::GET_WRITE);
|
||||||
|
@ -25,17 +25,13 @@ ReturnValue_t DeviceHandlerMock::buildTransitionDeviceCommand(DeviceCommandId_t
|
|||||||
ReturnValue_t DeviceHandlerMock::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
ReturnValue_t DeviceHandlerMock::buildCommandFromCommand(DeviceCommandId_t deviceCommand,
|
||||||
const uint8_t *commandData,
|
const uint8_t *commandData,
|
||||||
size_t commandDataLen) {
|
size_t commandDataLen) {
|
||||||
switch (deviceCommand) {
|
return returnvalue::OK;
|
||||||
case SIMPLE_COMMAND: {
|
}
|
||||||
|
|
||||||
|
ReturnValue_t DeviceHandlerMock::handleAction(MockAction *action) {
|
||||||
commandBuffer[0] = SIMPLE_COMMAND_DATA;
|
commandBuffer[0] = SIMPLE_COMMAND_DATA;
|
||||||
rawPacket = commandBuffer;
|
rawPacket = commandBuffer;
|
||||||
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
|
rawPacketLen = sizeof(SIMPLE_COMMAND_DATA);
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
WARN("DeviceHandlerMock::buildCommandFromCommand: Invalid device command");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -43,13 +39,13 @@ ReturnValue_t DeviceHandlerMock::scanForReply(const uint8_t *start, size_t len,
|
|||||||
DeviceCommandId_t *foundId, size_t *foundLen) {
|
DeviceCommandId_t *foundId, size_t *foundLen) {
|
||||||
switch (*start) {
|
switch (*start) {
|
||||||
case SIMPLE_COMMAND_DATA: {
|
case SIMPLE_COMMAND_DATA: {
|
||||||
*foundId = SIMPLE_COMMAND;
|
*foundId = static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND);
|
||||||
*foundLen = sizeof(SIMPLE_COMMAND_DATA);
|
*foundLen = sizeof(SIMPLE_COMMAND_DATA);
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case PERIODIC_REPLY_DATA: {
|
case PERIODIC_REPLY_DATA: {
|
||||||
*foundId = PERIODIC_REPLY;
|
*foundId = static_cast<uint32_t>(MockCommands::PERIODIC_REPLY);
|
||||||
*foundLen = sizeof(PERIODIC_REPLY_DATA);
|
*foundLen = sizeof(PERIODIC_REPLY_DATA);
|
||||||
return returnvalue::OK;
|
return returnvalue::OK;
|
||||||
break;
|
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) {
|
ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, const uint8_t *packet) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case SIMPLE_COMMAND:
|
case static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND):
|
||||||
case PERIODIC_REPLY: {
|
case static_cast<uint32_t>(MockCommands::PERIODIC_REPLY): {
|
||||||
periodicReplyReceived = true;
|
periodicReplyReceived = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -74,10 +70,10 @@ ReturnValue_t DeviceHandlerMock::interpretDeviceReply(DeviceCommandId_t id, cons
|
|||||||
}
|
}
|
||||||
|
|
||||||
void DeviceHandlerMock::fillCommandAndReplyMap() {
|
void DeviceHandlerMock::fillCommandAndReplyMap() {
|
||||||
insertInCommandAndReplyMap(SIMPLE_COMMAND, 0, nullptr, 0, false, false, 0,
|
insertInCommandAndReplyMap(static_cast<uint32_t>(MockCommands::SIMPLE_COMMAND), 0, nullptr, 0,
|
||||||
&simpleCommandReplyTimeout);
|
false, false, 0, &simpleCommandReplyTimeout);
|
||||||
insertInCommandAndReplyMap(PERIODIC_REPLY, 0, nullptr, 0, true, false, 0,
|
insertInCommandAndReplyMap(static_cast<uint32_t>(MockCommands::PERIODIC_REPLY), 0, nullptr, 0,
|
||||||
&periodicReplyCountdown);
|
true, false, 0, &periodicReplyCountdown);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
|
uint32_t DeviceHandlerMock::getTransitionDelayMs(Mode_t modeFrom, Mode_t modeTo) { return 500; }
|
||||||
|
@ -2,11 +2,22 @@
|
|||||||
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_
|
#define TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_
|
||||||
|
|
||||||
#include <fsfw/devicehandlers/DeviceHandlerBase.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 {
|
class DeviceHandlerMock : public DeviceHandlerBase {
|
||||||
public:
|
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 SIMPLE_COMMAND_DATA = 1;
|
||||||
static const uint8_t PERIODIC_REPLY_DATA = 2;
|
static const uint8_t PERIODIC_REPLY_DATA = 2;
|
||||||
@ -21,6 +32,8 @@ class DeviceHandlerMock : public DeviceHandlerBase {
|
|||||||
ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId);
|
ReturnValue_t enablePeriodicReply(DeviceCommandId_t replyId);
|
||||||
ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId);
|
ReturnValue_t disablePeriodicReply(DeviceCommandId_t replyId);
|
||||||
|
|
||||||
|
ReturnValue_t handleAction(MockAction * action);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void doStartUp() override;
|
void doStartUp() override;
|
||||||
void doShutDown() override;
|
void doShutDown() override;
|
||||||
@ -41,6 +54,8 @@ class DeviceHandlerMock : public DeviceHandlerBase {
|
|||||||
uint8_t commandBuffer[1];
|
uint8_t commandBuffer[1];
|
||||||
|
|
||||||
bool periodicReplyReceived = false;
|
bool periodicReplyReceived = false;
|
||||||
|
|
||||||
|
MockAction mockAction = MockAction(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_ */
|
#endif /* TESTS_SRC_FSFW_TESTS_UNIT_DEVICEHANDLER_DEVICEHANDLERMOCK_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user