EIVE upstream #29

Merged
muellerr merged 693 commits from use-eive-upstream into develop 2023-06-30 15:44:39 +02:00
2 changed files with 23 additions and 24 deletions
Showing only changes of commit 070b48ada2 - Show all commits

View File

@ -24,25 +24,6 @@ ReturnValue_t SubsystemBase::checkStateAgainstTable(HybridIterator<ModeListEntry
using namespace mode; using namespace mode;
std::map<object_id_t, ChildInfo>::iterator childIter; std::map<object_id_t, ChildInfo>::iterator childIter;
auto checkSubmode = [&]() {
uint8_t mask;
bool submodesAllowedMask = tableIter.value->submodesAllowed(&mask);
uint8_t submodeToCheckAgainst = tableIter.value->getSubmode();
if (tableIter.value->inheritSubmode()) {
submodeToCheckAgainst = targetSubmode;
}
if (not submodesAllowedMask) {
if (childIter->second.submode != submodeToCheckAgainst) {
return returnvalue::FAILED;
}
}
if (submodesAllowedMask) {
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();
@ -53,9 +34,22 @@ 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();
if (result != returnvalue::OK) { // Check submodes here.
return result; uint8_t mask;
bool submodesAllowedMask = tableIter.value->submodesAllowed(&mask);
uint8_t submodeToCheckAgainst = tableIter.value->getSubmode();
if (tableIter.value->inheritSubmode()) {
submodeToCheckAgainst = targetSubmode;
}
if (submodesAllowedMask) {
if ((childIter->second.submode | mask) != mask) {
return returnvalue::FAILED;
}
} else {
if (childIter->second.submode != submodeToCheckAgainst) {
return returnvalue::FAILED;
}
} }
} }
return returnvalue::OK; return returnvalue::OK;

View File

@ -13,6 +13,8 @@ enum SpecialSubmodeFlags : uint8_t { INHERIT = 1 << 0, ALLOWED_MASK = 1 << 1 };
class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>, class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
public LinkedElement<ModeListEntry> { public LinkedElement<ModeListEntry> {
public: public:
static constexpr uint8_t ALL_SUBMODES_ALLOWED_MASK = 0xff;
ModeListEntry() : SerialLinkedListAdapter(), LinkedElement<ModeListEntry>(this) { setLinks(); } ModeListEntry() : SerialLinkedListAdapter(), LinkedElement<ModeListEntry>(this) { setLinks(); }
SerializeElement<uint32_t> value1 = 0; SerializeElement<uint32_t> value1 = 0;
@ -101,10 +103,13 @@ class ModeListEntry : public SerialLinkedListAdapter<SerializeIF>,
/** /**
* Specialization of @enableSubmodeAllowed which allows all submodes. * Specialization of @enableSubmodeAllowed which allows all submodes.
*/ */
void allowAllSubmodes() { enableSubmodeAllowed(0xff); } void allowAllSubmodes() { enableSubmodeAllowed(ALL_SUBMODES_ALLOWED_MASK); }
/** /**
* Enable an allowed submode mask for mode checks. * 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.
*/ */
void enableSubmodeAllowed(uint8_t mask) { void enableSubmodeAllowed(uint8_t mask) {
value4.entry |= mode::SpecialSubmodeFlags::ALLOWED_MASK; value4.entry |= mode::SpecialSubmodeFlags::ALLOWED_MASK;