From f9d91362831f6dfb9e2d227a702da655cc31d066 Mon Sep 17 00:00:00 2001
From: "Robin.Mueller" <robin.mueller.m@gmail.com>
Date: Fri, 27 Mar 2020 01:42:23 +0100
Subject: [PATCH] some bugfixes

---
 .../OBSW_TmTcClient_Service_5_Serial.xml      |  2 +-
 .../OBSW_MultipleCommandsSenderReceiver.py    | 16 ++++++-----
 sendreceive/OBSW_TmListener.py                | 27 ++++++++++++-------
 test/OBSW_UnitTest.py                         | 11 ++++----
 4 files changed, 34 insertions(+), 22 deletions(-)

diff --git a/.idea/runConfigurations/OBSW_TmTcClient_Service_5_Serial.xml b/.idea/runConfigurations/OBSW_TmTcClient_Service_5_Serial.xml
index 711bf6f..eda5cab 100644
--- a/.idea/runConfigurations/OBSW_TmTcClient_Service_5_Serial.xml
+++ b/.idea/runConfigurations/OBSW_TmTcClient_Service_5_Serial.xml
@@ -12,7 +12,7 @@
     <option name="ADD_CONTENT_ROOTS" value="true" />
     <option name="ADD_SOURCE_ROOTS" value="true" />
     <EXTENSION ID="PythonCoverageRunConfigurationExtension" runner="coverage.py" />
-    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/../../../../../../../Robin/NoSyncDokumente/sourceobsw/tmtc/OBSW_TmTcClient.py" />
+    <option name="SCRIPT_NAME" value="$PROJECT_DIR$/obsw_tmtc_client.py" />
     <option name="PARAMETERS" value="-m 3 -s 5 -c 1 -p" />
     <option name="SHOW_COMMAND_LINE" value="false" />
     <option name="EMULATE_TERMINAL" value="true" />
diff --git a/sendreceive/OBSW_MultipleCommandsSenderReceiver.py b/sendreceive/OBSW_MultipleCommandsSenderReceiver.py
index 5041320..d94544d 100644
--- a/sendreceive/OBSW_MultipleCommandsSenderReceiver.py
+++ b/sendreceive/OBSW_MultipleCommandsSenderReceiver.py
@@ -26,20 +26,23 @@ class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver):
                  tmTimeout: float, waitIntervals: list, waitTime: Union[float, list], printTm: bool,
                  tcTimeoutFactor: float, doPrintToFile: bool):
         """
-        TCs are sent in burst when applicable. Wait intervals can be specified by supplying respective arguments
+        TCs are sent in burst when applicable. Wait intervals can be specified by supplying
+        respective arguments
         :param comInterface:
         :param tmtcPrinter:
         :param tcQueue:
         :param tmTimeout:
-        :param waitIntervals: List of pause intervals. For example [1,3] means that a waitTime is applied after
+        :param waitIntervals: List of pause intervals. For example [1,3] means that a waitTime
+            is applied after
         sendinf the first and the third telecommand
         :param waitTime: List of wait times or uniform wait time as float
         :param printTm:
         :param tcTimeoutFactor:
         :param doPrintToFile:
         """
-        super().__init__(comInterface=comInterface, tmtcPrinter=tmtcPrinter, tmListener=tmListener, tmTimeout=tmTimeout,
-                         tcQueue=tcQueue, tcTimeoutFactor=tcTimeoutFactor, doPrintToFile=doPrintToFile)
+        super().__init__(comInterface=comInterface, tmtcPrinter=tmtcPrinter, tmListener=tmListener,
+                         tmTimeout=tmTimeout, tcQueue=tcQueue, tcTimeoutFactor=tcTimeoutFactor,
+                         doPrintToFile=doPrintToFile)
         self.waitIntervals = waitIntervals
         self.waitTime = waitTime
         self.printTm = printTm
@@ -79,7 +82,7 @@ class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver):
 
     def sendAndPrintTc(self):
         self._checkQueueEntry(self._tcQueue.pop())
-        if self.__queueEntryIsTelecommand:
+        if self._queueEntryIsTelecommand:
             self.tcInfoQueue.append(self.pusPacketInfo)
             self._comInterface.sendTelecommand(self.pusPacket, self.pusPacketInfo)
             self.handleWaiting()
@@ -96,7 +99,8 @@ class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver):
         if self._tmListener.replyEvent.is_set():
             return self._tmListener.tmInfoQueue
         else:
-            print("Multiple Command SenderReceiver: Configuration error, reply event not set in TM listener")
+            print("Multiple Command SenderReceiver: Configuration error,"
+                  " reply event not set in TM listener")
 
     def clearListenerTmInfoQueue(self):
         self._tmListener.tmInfoQueue.clear()
diff --git a/sendreceive/OBSW_TmListener.py b/sendreceive/OBSW_TmListener.py
index e018c8b..5e77eae 100644
--- a/sendreceive/OBSW_TmListener.py
+++ b/sendreceive/OBSW_TmListener.py
@@ -32,19 +32,24 @@ class TmListener:
         self.comInterface = comInterface
         # this will be the default mode (listener mode)
         self.modeId = g.ModeList.ListenerMode
-        self.listenerActive = threading.Event()  # TM Listener operations can be suspended by setting this flag
+        # TM Listener operations can be suspended by setting this flag
+        self.listenerActive = threading.Event()
         self.listenerActive.set()
-        # I don't think a listener is useful without the main program, so we might just declare it daemonic.
-        # UPDATE: Right now, the main program is not in a permanent loop and setting the thread daemonic will
-        # cancel the program. Solved for now by setting a permanent loop at the end of the main program
+        # I don't think a listener is useful without the main program,
+        # so we might just declare it daemonic.
+        # UPDATE: Right now, the main program is not in a permanent loop and setting the
+        # thread daemonic will cancel the program.
+        # Solved for now by setting a permanent loop at the end of the main program
         self.listenerThread = threading.Thread(target=self.performOperation, daemon=True)
         # This Event is set by sender objects to perform mode operations
         self.modeChangeEvent = threading.Event()
-        # This Event is set by sender objects if all necessary operations are done to transition back to listener mode
+        # This Event is set by sender objects if all necessary operations are done
+        # to transition back to listener mode
         self.modeOpFinished = threading.Event()
         # maybe we will just make the thread daemonic...
         # self.terminationEvent = threading.Event()
-        # This Event is set and cleared by the listener to inform the sender objects if a reply has been received
+        # This Event is set and cleared by the listener to inform the sender objects
+        # if a reply has been received
         self.replyEvent = threading.Event()
         # Will be filled for the Unit Test
         self.tmInfoQueue = deque()
@@ -63,7 +68,8 @@ class TmListener:
         self.comInterface.pollInterface()
         if self.modeChangeEvent.is_set():
             # TODO: We should put this in a timeout.. Each mode operation up until now only takes
-            #       a maximum specified time (software test 5 minutes maybe?). Otherwise, this is a permanent loop
+            #       a maximum specified time (software test 5 minutes maybe?).
+            #       Otherwise, this is a permanent loop
             self.modeChangeEvent.clear()
             while not self.modeOpFinished.is_set():
                 self.performModeOperation()
@@ -87,7 +93,8 @@ class TmListener:
                 # Set reply event, will be cleared by checkForFirstReply()
                 self.replyEvent.set()
         # Sequential Command Mode
-        elif self.modeId == g.ModeList.ServiceTestMode or self.modeId == g.ModeList.SoftwareTestMode:
+        elif self.modeId == g.ModeList.ServiceTestMode or \
+                self.modeId == g.ModeList.SoftwareTestMode:
             if self.checkForOneTelemetrySequence():
                 print("TM Listener: Reply sequence received!")
                 self.replyEvent.set()
@@ -113,8 +120,8 @@ class TmListener:
                 if tmReady:
                     self.comInterface.receiveTelemetry()
                 elapsed_time = time.time() - start_time
-            # the timeout value can be set by special TC queue entries if packet handling takes longer,
-            # but it is reset here to the global value
+            # the timeout value can be set by special TC queue entries if packet handling
+            # takes longer, but it is reset here to the global value
             if self.tmTimeout is not g.tmTimeout:
                 self.tmTimeout = g.tmTimeout
             return True
diff --git a/test/OBSW_UnitTest.py b/test/OBSW_UnitTest.py
index 6aa86e7..b3951a9 100644
--- a/test/OBSW_UnitTest.py
+++ b/test/OBSW_UnitTest.py
@@ -78,12 +78,13 @@ class TestService(unittest.TestCase):
     # This function should be called in each individual test to send the actual telecommands
     # which are stored inside testQueue
     def performTestingAndGenerateAssertionDict(self):
-        # TODO: Maybe we should instantiate this once in the main and then reuse it instead of calling the constructor
-        #       over and over again.
+        # TODO: Maybe we should instantiate this once in the main and then reuse it instead
+        #       of calling the constructor over and over again.
         UnitTester = MultipleCommandSenderReceiver(
-            comInterface=self.communicationInterface, tmtcPrinter=self.tmtcPrinter, tmListener=self.tmListener,
-            tcQueue=self.testQueue, tmTimeout=self.tmTimeout, waitIntervals=self.waitIntervals, waitTime=self.waitTime,
-            printTm=self.printTm, tcTimeoutFactor=self.tcTimeoutFactor, doPrintToFile=self.printFile)
+            comInterface=self.communicationInterface, tmtcPrinter=self.tmtcPrinter,
+            tmListener=self.tmListener, tcQueue=self.testQueue, tmTimeout=self.tmTimeout,
+            waitIntervals=self.waitIntervals, waitTime=self.waitTime, printTm=self.printTm,
+            tcTimeoutFactor=self.tcTimeoutFactor, doPrintToFile=self.printFile)
         (tcInfoQueue, tmInfoQueue) = UnitTester.sendTcQueueAndReturnInfo()
         assertionDict = self.analyseTmTcInfo(tmInfoQueue, tcInfoQueue)
         return assertionDict
-- 
GitLab