diff --git a/OBSW_UdpClient.py b/OBSW_UdpClient.py index 4037c4466761e6c7939e0b847cab626dd97b4166..797f72e80abe46ef4a2dea1b275ff30417ab5093 100644 --- a/OBSW_UdpClient.py +++ b/OBSW_UdpClient.py @@ -98,7 +98,7 @@ def main(): else: comPort = g.comPort baudRate = 115200 - g.serialTimeout = 0.03 + g.serialTimeout = 0.05 communicationInterface = SerialComIF(tmtcPrinter, comPort, baudRate, g.serialTimeout) connectToBoard() @@ -141,9 +141,11 @@ def main(): # Prepare command for single command testing def commandPreparation(): - # Single Command Testing - command = PUSTelecommand(service=17, subservice=1, SSC=21) - command.packCommandTuple() + # Direct command which triggers an additional step reply and one completion reply + objectId = bytearray([0x44, 0x00, 0xAF, 0xFE]) + actionId = bytearray([0xBA, 0xDE, 0xAF, 0xFE]) + directCommand = objectId + actionId + command = PUSTelecommand(service=8, subservice=128, SSC=840, data=directCommand) return command.packCommandTuple() @@ -218,8 +220,11 @@ def setGlobals(args): def setUpSocket(): - g.sockReceive.bind(g.recAddress) - g.sockReceive.setblocking(False) + try: + g.sockReceive.bind(g.recAddress) + g.sockReceive.setblocking(False) + except OSError: + print("Error setting up sockets.") class GracefulKiller: diff --git a/comIF/OBSW_Serial_ComIF.py b/comIF/OBSW_Serial_ComIF.py index 722394d9ac336cbd18b688992d1bfd3cdf3b9130..7921fbe12727f497116972edaa09f62a22cde4ac 100644 --- a/comIF/OBSW_Serial_ComIF.py +++ b/comIF/OBSW_Serial_ComIF.py @@ -11,6 +11,8 @@ class SerialComIF(CommunicationInterface): super().__init__(tmtcPrinter) self.tmtcPrinter = tmtcPrinter self.serial = serial.Serial(port=comPort, baudrate=baudRate, timeout=serialTimeout) + self.data = bytearray() + self.numberOfPackets = 0 # self.serial.open() def sendTelecommand(self, tcPacket, tcPacketInfo=""): @@ -45,30 +47,41 @@ class SerialComIF(CommunicationInterface): def pollPusPackets(self): pusDataList = [] - data = self.serial.read(1024) - packetSize = (data[4] << 8 | data[5]) + 7 - readSize = len(data) - numberOfPackets = 1 + self.data = self.serial.read(1024) + packetSize = (self.data[4] << 8 | self.data[5]) + 7 + readSize = len(self.data) + self.numberOfPackets = 1 if readSize < packetSize: print("Serial Com IF: Size missmatch when polling PUS packet. Packet Size: " + str(packetSize) + ". Read Size: " + str(readSize) + ". Check timeout too") if readSize > packetSize: - endOfBuffer = readSize - 1 - endIndex = packetSize - startIndex = 0 - pusData = data[startIndex:endIndex] - pusDataList.append(pusData) - while endIndex < endOfBuffer: - startIndex = endIndex - endIndex = endIndex + 6 - nextPacketSize = (data[endIndex-1] << 8 | data[endIndex]) + 7 - endIndex = startIndex + nextPacketSize - numberOfPackets = numberOfPackets + 1 - pusData = data[startIndex:endIndex] - pusDataList.append(pusData) + self.handleMultiplePackets(packetSize, readSize, pusDataList) else: - pusDataList.append(data) - return pusDataList, numberOfPackets + pusDataList.append(self.data) + return pusDataList, self.numberOfPackets + + def handleMultiplePackets(self, packetSize, readSize, pusDataList): + endOfBuffer = readSize - 1 + endIndex = packetSize + startIndex = 0 + pusData = self.data[startIndex:endIndex] + pusDataList.append(pusData) + while endIndex < endOfBuffer: + endIndex = self.parseNextPackets(endIndex, pusDataList) + + def parseNextPackets(self, endIndex, pusDataList): + startIndex = endIndex + endIndex = endIndex + 5 + nextPacketSize = (self.data[endIndex - 1] << 8 | self.data[endIndex]) + 7 + if nextPacketSize > 1024: + print("PUS Polling: Very Large packet detected, large packet reading not implemented yet !") + print("Detected Size: " + str(nextPacketSize)) + return pusDataList, self.numberOfPackets + endIndex = startIndex + nextPacketSize + pusData = self.data[startIndex:endIndex] + pusDataList.append(pusData) + self.numberOfPackets = self.numberOfPackets + 1 + return endIndex def performListenerMode(self): print("Listening for packages ...") diff --git a/sendreceive/OBSW_CommandSenderReceiver.py b/sendreceive/OBSW_CommandSenderReceiver.py index e4da2682da9a3c1f8868ff74cee5daa5bc72a426..1e3352df52cba0afd9326a7cc32e269c72910372 100644 --- a/sendreceive/OBSW_CommandSenderReceiver.py +++ b/sendreceive/OBSW_CommandSenderReceiver.py @@ -37,6 +37,9 @@ class CommandSenderReceiver: self.doPrintToFile = doPrintToFile self.queueEntryIsTelecommand = True + self.lastTc = [] + self.lastTcInfo = [] + # checks for replies. if no reply is received, send telecommand again def checkForFirstReply(self): success = self.checkForOneTelemetrySequence() @@ -46,6 +49,7 @@ class CommandSenderReceiver: if len(self.pusPacket) == 0: print("Command Sender Receiver: No command has been sent yet") else: + print("Command Sender Receiver: Sending command again") self.comInterface.sendTelecommand(self.pusPacket, self.pusPacketInfo) # Check for special queue entries. @@ -64,6 +68,7 @@ class CommandSenderReceiver: self.tmtcPrinter.printToFile(exportName, True) else: self.queueEntryIsTelecommand = True + self.lastTc, self.lastTcInfo = (self.pusPacket, self.pusPacketInfo) def checkForTimeout(self): if self.timeoutCounter == 5: @@ -72,8 +77,8 @@ class CommandSenderReceiver: if self.start_time != 0: self.elapsed_time = time.time() - self.start_time if self.elapsed_time > self.tmTimeout * self.tcSendTimeoutFactor: - print("Command Sender Receiver: Timeout, sending Telecommand again") - self.comInterface.sendTelecommand(self.pusPacket, self.pusPacketInfo) + print("Command Sender Receiver: Timeout, sending TC again !") + self.comInterface.sendTelecommand(self.lastTc, self.lastTcInfo) self.timeoutCounter = self.timeoutCounter + 1 self.start_time = time.time() time.sleep(1) diff --git a/sendreceive/OBSW_SequentialSenderReceiver.py b/sendreceive/OBSW_SequentialSenderReceiver.py index 8e326efc064e72fa7cf7434e69e1ca6b77ae5c27..b56cf0cab552c8a33fa22b089add875a37a3bf7a 100644 --- a/sendreceive/OBSW_SequentialSenderReceiver.py +++ b/sendreceive/OBSW_SequentialSenderReceiver.py @@ -42,7 +42,8 @@ class SequentialCommandSenderReceiver(CommandSenderReceiver): while not self.tcQueue.empty(): self.performNextTcSend() if self.tcQueue.empty(): - print("TC queue empty") + print("TC Sender: TC queue empty") + self.start_time = time.time() self.checkForTimeout() if self.doPrintToFile: print("Exporting output to log file") @@ -78,6 +79,7 @@ class SequentialCommandSenderReceiver(CommandSenderReceiver): elif self.tcQueue.empty(): # Special case: Last queue entry is not a Telecommand self.allRepliesReceived = True + print("Receiver: All replies received") else: self.replyReceived = True self.performNextTcSend() @@ -96,6 +98,7 @@ class SequentialCommandSenderReceiver(CommandSenderReceiver): tmReady = self.comInterface.dataAvailable(1.0) if tmReady: self.handleTelemetrySequence() + else: self.handleFirstReplyListening() @@ -106,6 +109,7 @@ class SequentialCommandSenderReceiver(CommandSenderReceiver): # set this flag so the other thread can send the next telecommand self.replyReceived = True if self.tcQueue.empty(): + print("Receiver: All replies received") self.allRepliesReceived = True def handleFirstReplyListening(self): diff --git a/tc/OBSW_TcService3.py b/tc/OBSW_TcService3.py index 1e96a21f5239dc05e100f1d28f206afba21307b8..84109842e2ebc6a2f4e3589c30e2d900ab7d86c0 100644 --- a/tc/OBSW_TcService3.py +++ b/tc/OBSW_TcService3.py @@ -13,8 +13,9 @@ from tc.OBSW_TcPacket import PUSTelecommand def packService3TestInto(tcQueue): tcQueue.put(("print", "Testing Service 3")) # adding custom defintion to hk using test pool variables - tcQueue.put(("print", "\r\nTesting Service 3: Adding custom definition")) - sid = bytearray([0x00, 0x00, 0x42, 0x00]) + tcQueue.put(("print", "\r\nTesting Service 3: Adding custom HK definition")) + sid1 = bytearray([0x00, 0x00, 0x43, 0x00]) + sid2 = bytearray([0x00, 0x00, 0x44, 0x00]) collectionInterval = struct.pack('>f', 3) numberOfParameters = struct.pack('B', 5) p1 = bytearray([0x01, 0x01, 0x01, 0x01]) @@ -22,11 +23,13 @@ def packService3TestInto(tcQueue): p3 = bytearray([0x03, 0x03, 0x03, 0x03]) p4 = bytearray([0x04, 0x04, 0x04, 0x04]) p5 = bytearray([0x05, 0x05, 0x05, 0x05]) - hkDefinition = sid + collectionInterval + numberOfParameters + p1 + p2 + p3 + p4 + p5 - command = PUSTelecommand(service=3, subservice=1, SSC=3010, data=hkDefinition) + hkDefinition1 = sid1 + collectionInterval + numberOfParameters + p1 + p2 + p3 + p4 + p5 + hkDefinition2 = sid2 + collectionInterval + numberOfParameters + p1 + p2 + p3 + p4 + p5 + command = PUSTelecommand(service=3, subservice=1, SSC=3010, data=hkDefinition1) tcQueue.put(command.packCommandTuple()) + tcQueue.put(("print", "\r\nTesting Service 3: Adding custom diganostics definition")) # adding custom definition to diagnostics using test pool variables - command = PUSTelecommand(service=3, subservice=2, SSC=3010, data=hkDefinition) + command = PUSTelecommand(service=3, subservice=2, SSC=3020, data=hkDefinition2) tcQueue.put(command.packCommandTuple()) # enable custom hk definition # enable custom diag definition @@ -45,7 +48,13 @@ def packService3TestInto(tcQueue): # report custom hk definition # report custom diag definition # delete custom hk definition + tcQueue.put(("print", "\r\nTesting Service 3: Deleting custom HK definition")) + command = PUSTelecommand(service=3, subservice=3, SSC=3080, data=sid1) + tcQueue.put(command.packCommandTuple()) # delete custom diag definition + tcQueue.put(("print", "\r\nTesting Service 3: Deleting custom diagnostics definition")) + command = PUSTelecommand(service=3, subservice=4, SSC=3090, data=sid2) + tcQueue.put(command.packCommandTuple()) # do some basic testing on predefined structs too # e.g. add one variable, change interval, report them.... tcQueue.put(("export", "log/tmtc_log_service3.txt")) diff --git a/tc/OBSW_TcService8.py b/tc/OBSW_TcService8.py index 6768e4cda2b2b26166019536773d8105be9836fc..e8ba84ae853a25adc0782a8b84c47c3c8adeb03c 100644 --- a/tc/OBSW_TcService8.py +++ b/tc/OBSW_TcService8.py @@ -17,16 +17,21 @@ def packService8TestInto(tcQueue, calledExternally=False): if calledExternally is False: tcQueue.put(("print", "Testing Service 8")) objectId = bytearray([0x44, 0x00, 0xAF, 0xFE]) + # set mode on + tcQueue.put(("print", "\r\nTesting Service 8: Set Normal Mode")) + modeData = packModeData(objectId, 1, 0) + command = PUSTelecommand(service=200, subservice=1, SSC=800, data=modeData) + tcQueue.put(command.packCommandTuple()) # set mode normal tcQueue.put(("print", "\r\nTesting Service 8: Set Normal Mode")) modeData = packModeData(objectId, 2, 0) - command = PUSTelecommand(service=200, subservice=1, SSC=3, data=modeData) + command = PUSTelecommand(service=200, subservice=1, SSC=810, data=modeData) tcQueue.put(command.packCommandTuple()) # Direct command which triggers completion reply tcQueue.put(("print", "\r\nTesting Service 8: Trigger Completion Reply")) actionId = struct.pack(">I", 666) directCommand = objectId + actionId - command = PUSTelecommand(service=8, subservice=128, SSC=810, data=directCommand) + command = PUSTelecommand(service=8, subservice=128, SSC=820, data=directCommand) tcQueue.put(command.packCommandTuple()) # Direct command which triggers data reply tcQueue.put(("print", "\r\nTesting Service 8: Trigger Data Reply")) @@ -34,14 +39,15 @@ def packService8TestInto(tcQueue, calledExternally=False): commandParam1 = bytearray([0xBA, 0xB0]) commandParam2 = bytearray([0x00, 0x00, 0x00, 0x52, 0x4F, 0x42, 0x49, 0x4E]) directCommand = objectId + actionId + commandParam1 + commandParam2 - command = PUSTelecommand(service=8, subservice=128, SSC=820, data=directCommand) + command = PUSTelecommand(service=8, subservice=128, SSC=830, data=directCommand) tcQueue.put(command.packCommandTuple()) # Direct command which triggers an additional step reply and one completion reply tcQueue.put(("print", "\r\nTesting Service 8: Trigger Step and Completion Reply")) actionId = bytearray([0xBA, 0xDE, 0xAF, 0xFE]) directCommand = objectId + actionId - command = PUSTelecommand(service=8, subservice=128, SSC=830, data=directCommand) + command = PUSTelecommand(service=8, subservice=128, SSC=840, data=directCommand) tcQueue.put(command.packCommandTuple()) + tcQueue.put(("wait", 2)) tcQueue.put(("print", "\r")) if calledExternally is False: tcQueue.put(("export", "log/tmtc_log_service8.txt")) diff --git a/utility/OBSW_TmTcPrinter.py b/utility/OBSW_TmTcPrinter.py index a4abbc265ae9718177d234e33b53ba8dc35af3fa..f79183238d1e4425bd7e15df89c8919c0003082e 100644 --- a/utility/OBSW_TmTcPrinter.py +++ b/utility/OBSW_TmTcPrinter.py @@ -109,11 +109,14 @@ class TmtcPrinter: self.addPrintBufferToFileBuffer() def handleLongTcPrint(self, pusPacketInfo): - self.printBuffer = "Telecommand TC[" + str(pusPacketInfo["service"]) + "," + str(pusPacketInfo["subservice"]) \ - + "] with SSC " + str(pusPacketInfo["ssc"]) + " sent with data " \ - + self.returnDataString(pusPacketInfo["data"]) - print(self.printBuffer) - self.addPrintBufferToFileBuffer() + try: + self.printBuffer = "Telecommand TC[" + str(pusPacketInfo["service"]) + "," + str(pusPacketInfo["subservice"]) \ + + "] with SSC " + str(pusPacketInfo["ssc"]) + " sent with data " \ + + self.returnDataString(pusPacketInfo["data"]) + print(self.printBuffer) + self.addPrintBufferToFileBuffer() + except TypeError: + print("TMTC Printer: Type Error !") def printData(self, byteArray): string = self.returnDataString(byteArray)