Feature: Allowed Submodes Mask for Mode List Entry #130
@ -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) {
|
||||||
gaisser marked this conversation as resolved
Outdated
|
|||||||
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;
|
||||||
gaisser marked this conversation as resolved
Outdated
gaisser
commented
This can be the else case of the above. Or maybe switch cases (not XX might be harder to read):
This can be the else case of the above. Or maybe switch cases (not XX might be harder to read):
``` c++
if (submodesAllowedMask) {
if ((childIter->second.submode | mask) != mask) {
return returnvalue::FAILED;
}
}else{
if (childIter->second.submode != submodeToCheckAgainst) {
return returnvalue::FAILED;
}
}
return returnvalue::OK;
```
|
|||||||
|
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;
|
||||||
|
@ -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.
|
||||||
gaisser marked this conversation as resolved
gaisser
commented
0xFF should be defined somewhere visible as a restricted mask. 0xFF should be defined somewhere visible as a restricted mask.
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
|
Loading…
Reference in New Issue
Block a user
If you have to use a lambda, which I find a nightmare to read, maybe capture &childIter explicitly.