allow submode mask now

This commit is contained in:
Robin Müller 2023-03-07 13:55:40 +01:00
parent e9d9f44605
commit 2745b2080d
No known key found for this signature in database
GPG Key ID: 11D4952C8CCEF814
8 changed files with 147 additions and 99 deletions

View File

@ -100,9 +100,7 @@ ReturnValue_t Clock::getClock(timeval* time) {
#endif #endif
} }
ReturnValue_t Clock::getClock_timeval(timeval* time) { ReturnValue_t Clock::getClock_timeval(timeval* time) { return Clock::getClock(time); }
return Clock::getClock(time);
}
ReturnValue_t Clock::getClock_usecs(uint64_t* time) { ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
if (time == nullptr) { if (time == nullptr) {

View File

@ -53,9 +53,7 @@ ReturnValue_t Clock::getClock(timeval *time) {
return returnvalue::OK; return returnvalue::OK;
} }
ReturnValue_t Clock::getClock_timeval(timeval* time) { ReturnValue_t Clock::getClock_timeval(timeval* time) { return Clock::getClock(time); }
return Clock::getClock(time);
}
ReturnValue_t Clock::getClock_usecs(uint64_t* time) { ReturnValue_t Clock::getClock_usecs(uint64_t* time) {
timeval timeVal{}; timeval timeVal{};

View File

@ -21,8 +21,23 @@ SubsystemBase::~SubsystemBase() { QueueFactory::instance()->deleteMessageQueue(c
ReturnValue_t SubsystemBase::checkStateAgainstTable(HybridIterator<ModeListEntry> tableIter, ReturnValue_t SubsystemBase::checkStateAgainstTable(HybridIterator<ModeListEntry> tableIter,
Submode_t targetSubmode) { Submode_t targetSubmode) {
using namespace mode;
std::map<object_id_t, ChildInfo>::iterator childIter; std::map<object_id_t, ChildInfo>::iterator childIter;
auto checkSubmode = [&]() {
if (tableIter.value->inheritSubmode()) {
if (childIter->second.submode != targetSubmode) {
return returnvalue::FAILED;
}
}
uint8_t mask;
if (tableIter.value->submodesAllowed(&mask)) {
if ((childIter->second.submode | mask) != mask) {
return returnvalue::FAILED;
}
}
return returnvalue::OK;
};
for (; tableIter.value != NULL; ++tableIter) { for (; tableIter.value != NULL; ++tableIter) {
object_id_t object = tableIter.value->getObject(); object_id_t object = tableIter.value->getObject();
@ -33,14 +48,9 @@ ReturnValue_t SubsystemBase::checkStateAgainstTable(HybridIterator<ModeListEntry
if (childIter->second.mode != tableIter.value->getMode()) { if (childIter->second.mode != tableIter.value->getMode()) {
return returnvalue::FAILED; return returnvalue::FAILED;
} }
ReturnValue_t result = checkSubmode();
Submode_t submodeToCheckAgainst = tableIter.value->getSubmode(); if (result != returnvalue::OK) {
if (tableIter.value->inheritSubmode()) { return result;
submodeToCheckAgainst = targetSubmode;
}
if (childIter->second.submode != submodeToCheckAgainst) {
return returnvalue::FAILED;
} }
} }
return returnvalue::OK; return returnvalue::OK;

View File

@ -1,111 +1,102 @@
#ifndef FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_ #ifndef FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_
#define FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_ #define FSFW_SUBSYSTEM_MODES_MODEDEFINITIONS_H_
#include "../../modes/HasModesIF.h" #include "fsfw/modes/HasModesIF.h"
#include "../../objectmanager/SystemObjectIF.h" #include "fsfw/objectmanager/SystemObjectIF.h"
#include "../../serialize/SerialLinkedListAdapter.h" #include "fsfw/serialize/SerialLinkedListAdapter.h"
#include "../../serialize/SerializeIF.h" #include "fsfw/serialize/SerializeIF.h"
class ModeListEntry : public SerializeIF, public LinkedElement<ModeListEntry> { namespace mode {
enum SpecialSubmodeFlags : uint8_t { INHERIT = 1 << 0, ALLOWED_MASK = 1 << 1 };
}
class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
public LinkedElement<ModeListEntry> {
public: public:
ModeListEntry() : LinkedElement<ModeListEntry>(this) {} ModeListEntry() : LinkedElement<ModeListEntry>(this) { setLinks(); }
uint32_t value1 = 0; SerializeElement<uint32_t> value1 = 0;
uint32_t value2 = 0; SerializeElement<uint32_t> value2 = 0;
uint8_t value3 = 0; SerializeElement<uint8_t> value3 = 0;
uint8_t value4 = 0; SerializeElement<uint8_t> value4 = 0;
SerializeElement<uint8_t> value5 = 0;
virtual ReturnValue_t serialize(uint8_t** buffer, size_t* size, size_t maxSize, void setLinks() {
Endianness streamEndianness) const { setStart(&value1);
ReturnValue_t result; value1.setNext(&value2);
value2.setNext(&value3);
result = SerializeAdapter::serialize(&value1, buffer, size, maxSize, streamEndianness); value3.setNext(&value4);
value4.setNext(&value5);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&value2, buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&value3, buffer, size, maxSize, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::serialize(&value4, buffer, size, maxSize, streamEndianness);
return result;
}
virtual size_t getSerializedSize() const {
return sizeof(value1) + sizeof(value2) + sizeof(value3) + sizeof(value4);
}
virtual ReturnValue_t deSerialize(const uint8_t** buffer, size_t* size,
Endianness streamEndianness) {
ReturnValue_t result;
result = SerializeAdapter::deSerialize(&value1, buffer, size, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&value2, buffer, size, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&value3, buffer, size, streamEndianness);
if (result != returnvalue::OK) {
return result;
}
result = SerializeAdapter::deSerialize(&value4, buffer, size, streamEndianness);
return result;
} }
// for Sequences // for Sequences
Mode_t getTableId() const { return value1; } Mode_t getTableId() const { return value1.entry; }
void setTableId(Mode_t tableId) { this->value1 = tableId; } void setTableId(Mode_t tableId) { this->value1.entry = tableId; }
uint8_t getWaitSeconds() const { return value2; } uint8_t getWaitSeconds() const { return value2.entry; }
void setWaitSeconds(uint8_t waitSeconds) { this->value2 = waitSeconds; } void setWaitSeconds(uint8_t waitSeconds) { this->value2.entry = waitSeconds; }
bool checkSuccess() const { return value3 == 1; } bool checkSuccess() const { return value3.entry == 1; }
void setCheckSuccess(bool checkSuccess) { this->value3 = checkSuccess; } void setCheckSuccess(bool checkSuccess) { this->value3.entry = checkSuccess; }
// for Tables // for Tables
object_id_t getObject() const { return value1; } object_id_t getObject() const { return value1.entry; }
void setObject(object_id_t object) { this->value1 = object; } void setObject(object_id_t object) { this->value1.entry = object; }
Mode_t getMode() const { return value2; } Mode_t getMode() const { return value2.entry; }
void setMode(Mode_t mode) { this->value2 = mode; } void setMode(Mode_t mode) { this->value2.entry = mode; }
Submode_t getSubmode() const { return value3; } Submode_t getSubmode() const { return value3.entry; }
void setSubmode(Submode_t submode) { this->value3 = submode; } void setSubmode(Submode_t submode) { this->value3.entry = submode; }
bool inheritSubmode() const { return value4 == 1; } bool inheritSubmode() const {
return (value4.entry & mode::SpecialSubmodeFlags::INHERIT) ==
void setInheritSubmode(bool inherit) { mode::SpecialSubmodeFlags::INHERIT;
if (inherit) {
value4 = 1;
} else {
value4 = 0;
} }
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;
}
return submodesAllowed;
} }
bool operator==(ModeListEntry other) { /**
return ((value1 == other.value1) && (value2 == other.value2) && (value3 == other.value3)); * 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.
*/
void allowAllSubmodes() { enableSubmodeAllowed(0xff); }
/**
* Enable an allowed submode mask for mode checks.
*/
void enableSubmodeAllowed(uint8_t mask) {
value4.entry |= mode::SpecialSubmodeFlags::ALLOWED_MASK;
value5.entry = mask;
}
/**
* Enforce the equality of submodes for mode checks. This is the default.
*/
void disableSubmodeAllowed() {
value4.entry &= ~mode::SpecialSubmodeFlags::ALLOWED_MASK;
value5.entry = 0;
} }
}; };

View File

@ -13,6 +13,7 @@ add_subdirectory(util)
add_subdirectory(container) add_subdirectory(container)
add_subdirectory(osal) add_subdirectory(osal)
add_subdirectory(pus) add_subdirectory(pus)
add_subdirectory(subsystem)
add_subdirectory(serialize) add_subdirectory(serialize)
add_subdirectory(datapoollocal) add_subdirectory(datapoollocal)
add_subdirectory(storagemanager) add_subdirectory(storagemanager)

View File

@ -0,0 +1 @@
target_sources(${FSFW_TEST_TGT} PRIVATE testModeDef.cpp)

View File

@ -0,0 +1,49 @@
#include <array>
#include <catch2/catch_test_macros.hpp>
#include "fsfw/subsystem/modes/ModeDefinitions.h"
TEST_CASE("Mode Definitions", "[mode]") {
ModeListEntry entry;
SECTION("Basic") {
entry.setMode(HasModesIF::MODE_OFF);
entry.setSubmode(2);
CHECK(entry.getMode() == HasModesIF::MODE_OFF);
CHECK(entry.getSubmode() == 2);
uint8_t mask;
CHECK(entry.submodesAllowed(&mask) == false);
}
SECTION("Allowed submode mask") {
entry.allowAllSubmodes();
uint8_t mask;
CHECK(entry.submodesAllowed(&mask) == true);
CHECK(mask == 0xff);
}
SECTION("Serialization") {
std::array<uint8_t, 32> buf{};
entry.setObject(0x1f2f3f4f);
entry.setMode(HasModesIF::MODE_ON);
entry.setSubmode(2);
entry.enableInheritSubmode();
entry.enableSubmodeAllowed(0x1f);
uint8_t* serPtr = buf.data();
size_t serLen = 0;
REQUIRE(entry.serialize(&serPtr, &serLen, buf.size(), SerializeIF::Endianness::NETWORK) ==
returnvalue::OK);
CHECK(buf[0] == 0x1f);
CHECK(buf[1] == 0x2f);
CHECK(buf[2] == 0x3f);
CHECK(buf[3] == 0x4f);
CHECK(buf[4] == 0);
CHECK(buf[5] == 0);
CHECK(buf[6] == 0);
CHECK(buf[7] == HasModesIF::MODE_ON);
CHECK(buf[8] == 2);
CHECK(buf[9] == (mode::SpecialSubmodeFlags::ALLOWED_MASK | mode::SpecialSubmodeFlags::INHERIT));
CHECK(buf[10] == 0x1f);
}
}