diff --git a/comIF/OBSW_ComInterface.py b/comIF/OBSW_ComInterface.py index 49cab7f6cfdbe4ea75969473a83b0242857afa42..5121548fb022cb549f07f3225341b8e340a003ab 100644 --- a/comIF/OBSW_ComInterface.py +++ b/comIF/OBSW_ComInterface.py @@ -8,11 +8,11 @@ Description: Generic Communication Interface. Defines the syntax of the communic @author: R. Mueller """ from abc import abstractmethod -from typing import TypeVar, Tuple, Union, List +from typing import TypeVar, Tuple, Union, List, Deque from tm.OBSW_PusTm import pusPacketT, pusPacketInfoT ComIF_T = TypeVar('ComIF_T', bound='CommunicationInterface') -pusTupleT = Tuple[pusPacketT, pusPacketInfoT] +pusTupleQueueT = Deque[Tuple[pusPacketT, pusPacketInfoT]] packetListT = List[pusPacketT] @@ -68,7 +68,7 @@ class CommunicationInterface: pass # Receive Telemetry and store a tuple consisting of TM information and TM packet into queue - def receiveTelemetryAndStoreTuple(self, tmTupleQueue) -> Union[None, pusTupleT]: + def receiveTelemetryAndStoreTuple(self, tmTupleQueue) -> Union[None, pusTupleQueueT]: pass diff --git a/comIF/OBSW_Serial_ComIF.py b/comIF/OBSW_Serial_ComIF.py index 5241e3cc5b8b7cbb4bacf710d9695780cdb5afd4..41cd95028612aeb8c5f866f5de207f377d2b04fe 100644 --- a/comIF/OBSW_Serial_ComIF.py +++ b/comIF/OBSW_Serial_ComIF.py @@ -8,8 +8,8 @@ import time import serial import logging -from typing import Tuple, Union -from comIF.OBSW_ComInterface import CommunicationInterface, pusTupleT, packetListT +from typing import Tuple, Union, Deque +from comIF.OBSW_ComInterface import CommunicationInterface, pusTupleQueueT, packetListT from tm.OBSW_TmPacket import PUSTelemetryFactory @@ -113,13 +113,12 @@ class SerialComIF(CommunicationInterface): for packet in pusPackets: tmQueue.put(packet) - def receiveTelemetryAndStoreTuple(self, tmTupleQueue) -> Union[None, pusTupleT]: + def receiveTelemetryAndStoreTuple(self, tmTupleQueue: Deque) -> pusTupleQueueT: (packetReceived, pusPackets) = self.pollInterface() if packetReceived: for packet in pusPackets: tmInfo = packet.packTmInformation() - tmTupleQueue.put(packet, tmInfo) - return tmTupleQueue - else: - return None + tmTupleQueue.append((packet, tmInfo)) + return tmTupleQueue + diff --git a/sendreceive/OBSW_MultipleCommandsSenderReceiver.py b/sendreceive/OBSW_MultipleCommandsSenderReceiver.py index bc3ff58f61e9b872477e0f396b3a3f53ffc10050..fc3e866c21041e3ae9848fccef1acf63027cfe67 100644 --- a/sendreceive/OBSW_MultipleCommandsSenderReceiver.py +++ b/sendreceive/OBSW_MultipleCommandsSenderReceiver.py @@ -54,9 +54,9 @@ class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver): # time.sleep(0.5) try: self.sendAllQueue() - while not self.allRepliesReceived: - time.sleep(0.5) - self.tmListener.retrieveTmInfoQueue() + self.handleLastRepliesListening(self.tmTimeout/2.0) + self.tmListener.modeOpFinished.set() + self.tmInfoQueue = self.tmListener.retrieveTmInfoQueue() # self.handleTcResending() Turned off for now, not needed if self.doPrintToFile: self.tmtcPrinter.printToFile() @@ -93,10 +93,16 @@ class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver): def retrieveTmInfoQueue(self): if self.tmListener.replyEvent.is_set(): - self.tmInfoQueue = self.tmListener.tmInfoQueue + return self.tmListener.tmInfoQueue else: print("Multiple Command SenderReceiver: Configuration error, reply event not set in TM listener") + @staticmethod + def handleLastRepliesListening(waitTime: float): + elapsed_time_seconds = 0 + start_time = time.time() + while elapsed_time_seconds < waitTime: + elapsed_time_seconds = time.time() - start_time # def checkForMultipleReplies(self): # super().checkForMultipleReplies() @@ -105,29 +111,22 @@ class MultipleCommandSenderReceiver(SequentialCommandSenderReceiver): # # listen for duration timeoutInSeconds for replies # self.handleReplyListening() - def handleReplyListening(self): - tmReady = self.comInterface.dataAvailable(2.0) - if tmReady: - self.receiveTelemetryAndStoreInformation() - if self.tcQueue.empty(): - print("TC queue empty. Listening for a few more seconds ... ") - start_time = time.time() - self.handleLastRepliesListening(start_time) - self.allRepliesReceived = True - - def receiveTelemetryAndStoreInformation(self): - packetList = self.comInterface.receiveTelemetry() - for counter in range(0, len(packetList)): - tmInfo = packetList[counter].packTmInformation() - self.tmInfoQueue.append(tmInfo) - - def handleLastRepliesListening(self, start_time): - elapsed_time_seconds = 0 - while elapsed_time_seconds < self.tmTimeout/2.0: - elapsed_time_seconds = time.time() - start_time - tmReady = self.comInterface.dataAvailable(self.tmTimeout/4.0) - if tmReady: - self.receiveTelemetryAndStoreInformation() + # def handleReplyListening(self): + # tmReady = self.comInterface.dataAvailable(2.0) + # if tmReady: + # self.receiveTelemetryAndStoreInformation() + # if self.tcQueue.empty(): + # print("TC queue empty. Listening for a few more seconds ... ") + # start_time = time.time() + # self.handleLastRepliesListening(start_time) + # self.allRepliesReceived = True + + # def receiveTelemetryAndStoreInformation(self): + # packetList = self.comInterface.receiveTelemetry() + # for counter in range(0, len(packetList)): + # tmInfo = packetList[counter].packTmInformation() + # self.tmInfoQueue.append(tmInfo) + diff --git a/sendreceive/OBSW_TmListener.py b/sendreceive/OBSW_TmListener.py index 8fccb0cb0ccb3e2749652c67192e024d3ea57b77..2c8384296833e8f99bbdc990985e74019c4db314 100644 --- a/sendreceive/OBSW_TmListener.py +++ b/sendreceive/OBSW_TmListener.py @@ -90,7 +90,7 @@ class TmListener: print("TM Listener: Reply sequence received!") self.replyEvent.set() elif self.modeId == g.modeList.UnitTest: - currentPackets = self.comInterface.receiveTelemetryAndStoreTuple() + self.comInterface.receiveTelemetryAndStoreTuple(self.tmInfoQueue) def checkForOneTelemetrySequence(self) -> bool: """