fsfw/src/fsfw/subsystem/modes/ModeDefinitions.h

128 lines
4.1 KiB
C
Raw Normal View History

2020-12-14 11:34:54 +01:00
#ifndef FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_
#define FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_
2023-03-07 13:55:40 +01:00
#include "fsfw/modes/HasModesIF.h"
#include "fsfw/objectmanager/SystemObjectIF.h"
#include "fsfw/serialize/SerialLinkedListAdapter.h"
#include "fsfw/serialize/SerializeIF.h"
2022-02-02 10:29:30 +01:00
2023-03-07 13:55:40 +01:00
namespace mode {
enum SpecialSubmodeFlags : uint8_t { INHERIT = 1 << 0, ALLOWED_MASK = 1 << 1 };
}
2022-02-02 10:29:30 +01:00
2023-03-07 13:55:40 +01:00
class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
public LinkedElement<ModeListEntry> {
public:
2023-03-07 17:15:34 +01:00
static constexpr uint8_t ALL_SUBMODES_ALLOWED_MASK = 0xff;
ModeListEntry() : SerialLinkedListAdapter(), LinkedElement<ModeListEntry>(this) { setLinks(); }
2023-03-07 13:55:40 +01:00
SerializeElement<uint32_t> value1 = 0;
SerializeElement<uint32_t> value2 = 0;
SerializeElement<uint8_t> value3 = 0;
SerializeElement<uint8_t> value4 = 0;
SerializeElement<uint8_t> value5 = 0;
2023-03-07 13:55:40 +01:00
ModeListEntry(const ModeListEntry& other)
: SerialLinkedListAdapter(), LinkedElement<ModeListEntry>(this) {
value1.entry = other.value1.entry;
value2.entry = other.value2.entry;
value3.entry = other.value3.entry;
value4.entry = other.value4.entry;
value5.entry = other.value5.entry;
setLinks();
}
ModeListEntry& operator=(const ModeListEntry& other) {
this->value1.entry = other.value1.entry;
this->value2.entry = other.value2.entry;
this->value3.entry = other.value3.entry;
this->value4.entry = other.value4.entry;
this->value5.entry = other.value5.entry;
return *this;
}
2023-03-07 13:55:40 +01:00
void setLinks() {
setStart(&value1);
value1.setNext(&value2);
value2.setNext(&value3);
value3.setNext(&value4);
value4.setNext(&value5);
2022-02-02 10:29:30 +01:00
}
// for Sequences
2023-03-07 13:55:40 +01:00
Mode_t getTableId() const { return value1.entry; }
2022-02-02 10:29:30 +01:00
2023-03-07 13:55:40 +01:00
void setTableId(Mode_t tableId) { this->value1.entry = tableId; }
2022-02-02 10:29:30 +01:00
2023-03-07 13:55:40 +01:00
uint8_t getWaitSeconds() const { return value2.entry; }
2022-02-02 10:29:30 +01:00
2023-03-07 13:55:40 +01:00
void setWaitSeconds(uint8_t waitSeconds) { this->value2.entry = waitSeconds; }
2022-02-02 10:29:30 +01:00
2023-03-07 13:55:40 +01:00
bool checkSuccess() const { return value3.entry == 1; }
2022-02-02 10:29:30 +01:00
2023-03-07 13:55:40 +01:00
void setCheckSuccess(bool checkSuccess) { this->value3.entry = checkSuccess; }
2022-02-02 10:29:30 +01:00
// for Tables
2023-03-07 13:55:40 +01:00
object_id_t getObject() const { return value1.entry; }
2020-12-14 11:34:54 +01:00
2023-03-07 13:55:40 +01:00
void setObject(object_id_t object) { this->value1.entry = object; }
2023-03-07 13:55:40 +01:00
Mode_t getMode() const { return value2.entry; }
2023-03-07 13:55:40 +01:00
void setMode(Mode_t mode) { this->value2.entry = mode; }
2023-03-07 13:55:40 +01:00
Submode_t getSubmode() const { return value3.entry; }
2023-03-07 13:55:40 +01:00
void setSubmode(Submode_t submode) { this->value3.entry = submode; }
2023-03-07 13:55:40 +01:00
bool inheritSubmode() const {
return (value4.entry & mode::SpecialSubmodeFlags::INHERIT) ==
mode::SpecialSubmodeFlags::INHERIT;
}
bool submodesAllowed(uint8_t* mask) const {
bool submodesAllowed = (value4.entry & mode::SpecialSubmodeFlags::ALLOWED_MASK) ==
mode::SpecialSubmodeFlags::ALLOWED_MASK;
if (submodesAllowed and mask != nullptr) {
*mask = value5.entry;
2022-02-02 10:29:30 +01:00
}
2023-03-07 13:55:40 +01:00
return submodesAllowed;
2022-02-02 10:29:30 +01:00
}
2023-03-07 13:55:40 +01:00
/**
* Enable the inheritance of submodes. This is relevant for both the execution
* of mode tables and for mode checking.
*/
void enableInheritSubmode() { value4.entry |= mode::SpecialSubmodeFlags::INHERIT; }
/**
* Disable the inheritance of submodes. This is relevant for both the execution
* of mode tables and for mode checking.
*/
void disableInheritSubmode() { value4.entry &= ~mode::SpecialSubmodeFlags::INHERIT; }
/**
* Specialization of @enableSubmodeAllowed which allows all submodes.
*/
2023-03-07 17:15:34 +01:00
void allowAllSubmodes() { enableSubmodeAllowed(ALL_SUBMODES_ALLOWED_MASK); }
2023-03-07 13:55:40 +01:00
/**
2023-03-07 17:15:34 +01:00
* Enable an allowed submode mask for mode checks. Any submode which contains bits
* outside of the mask will be declined.
*
* For example, for a mask of 0b11, only the modes 0b00, 0b01 and 0b11 will be accepted.
2023-03-07 13:55:40 +01:00
*/
void enableSubmodeAllowed(uint8_t mask) {
value4.entry |= mode::SpecialSubmodeFlags::ALLOWED_MASK;
value5.entry = mask;
2023-03-07 13:55:40 +01:00
}
/**
* Enforce the equality of submodes for mode checks. This is the default.
*/
void disableSubmodeAllowed() {
value4.entry &= ~mode::SpecialSubmodeFlags::ALLOWED_MASK;
value5.entry = 0;
2022-02-02 10:29:30 +01:00
}
};
2020-12-14 11:34:54 +01:00
#endif /* FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_ */