From 0681b1895be793405efaaa41279447931233b9c3 Mon Sep 17 00:00:00 2001
From: "spahr@ksat-stuttgart.de" <spahr@ksat-stuttgart.de>
Date: Sat, 29 Mar 2025 23:28:24 +0100
Subject: [PATCH] add new MessageQueue to ModeHelper; which is equal to the
 parentQueue and can command the object without forcing the object to
 EXTERNAL_CONTROL

---
 src/fsfw/modes/ModeHelper.cpp | 12 ++++++++++--
 src/fsfw/modes/ModeHelper.h   |  6 ++++++
 2 files changed, 16 insertions(+), 2 deletions(-)

diff --git a/src/fsfw/modes/ModeHelper.cpp b/src/fsfw/modes/ModeHelper.cpp
index 8c83012f..aa1eb0cd 100644
--- a/src/fsfw/modes/ModeHelper.cpp
+++ b/src/fsfw/modes/ModeHelper.cpp
@@ -35,8 +35,12 @@ ReturnValue_t ModeHelper::handleModeCommand(CommandMessage* command) {
       commandedMode = mode;
       commandedSubmode = submode;
 
-      if ((parentQueueId != MessageQueueIF::NO_QUEUE) &&
-          (theOneWhoCommandedAMode != parentQueueId)) {
+      // if (((parentQueueId != MessageQueueIF::NO_QUEUE) &&
+      //     (theOneWhoCommandedAMode != parentQueueId))) {
+      //   owner->setToExternalControl();
+      // }
+
+      if(theOneWhoCommandedAMode != parentQueueId and theOneWhoCommandedAMode != powerswitchQueueId) {
         owner->setToExternalControl();
       }
 
@@ -106,3 +110,7 @@ bool ModeHelper::isTimedOut() { return countdown.hasTimedOut(); }
 bool ModeHelper::isForced() { return forced; }
 
 void ModeHelper::setForced(bool forced) { this->forced = forced; }
+
+void ModeHelper::setPowerswitchQueueId(MessageQueueId_t queueId) {
+  powerswitchQueueId = queueId;
+}
diff --git a/src/fsfw/modes/ModeHelper.h b/src/fsfw/modes/ModeHelper.h
index 23f78427..c5d6bce3 100644
--- a/src/fsfw/modes/ModeHelper.h
+++ b/src/fsfw/modes/ModeHelper.h
@@ -25,6 +25,11 @@ class ModeHelper {
    */
   void setParentQueue(MessageQueueId_t parentQueueId);
 
+  /**
+   * Set to MessageQueue::NO_QUEUE if no powerswitch is commanding the obejct.
+   */
+  void setPowerswitchQueueId(MessageQueueId_t queueId);
+
   ReturnValue_t initialize(MessageQueueId_t parentQueueId);
 
   ReturnValue_t initialize(void);
@@ -42,6 +47,7 @@ class ModeHelper {
  protected:
   HasModesIF *owner;
   MessageQueueId_t parentQueueId = MessageQueueIF::NO_QUEUE;
+  MessageQueueId_t powerswitchQueueId = MessageQueueIF::NO_QUEUE;
 
   Countdown countdown;