def helpCmd(self, argv): """Decoded help command""" LOG_INFO("Available commands:") LOG("") LOG("h | help ........provides this information") LOG("q | quit ........terminates the application") LOG("")
def listPacketsCmd(self, argv): """Decoded listPackets command""" self.logMethod("listPacketsCmd", "SPACE") # consistency check if len(argv) != 1: LOG_WARNING("invalid parameters passed", "SPACE") return False # dump the packet definitions try: for tmPktDef in SPACE.IF.s_definitions.getTMpktDefs(): LOG( "TM: " + tmPktDef.pktName + " (SPID = " + str(tmPktDef.pktSPID) + ") - " + tmPktDef.pktDescr, "SPACE") for tcPktDef in SPACE.IF.s_definitions.getTCpktDefs(): LOG( "TC: " + tcPktDef.pktName + " (APID = " + str(tcPktDef.pktAPID) + ", TYPE = " + str(tcPktDef.pktType) + ", STPYE = " + str(tcPktDef.pktSType) + ") - " + tcPktDef.pktDescr, "SPACE") except Exception as ex: LOG_ERROR("MIB Error: " + str(ex), "SPACE") return False return True
def notifyTCcltuResponseDataUnit(self, tcCltuRespDu): """CLTU response received""" LOG("") LOG("*** notifyTCcltuResponseDataUnit ***") LOG("tcCltuRespDu.acknowledgement = " + GRND.NCTRSDUhelpers.ackStr(tcCltuRespDu.acknowledgement)) LOG("tcCltuRespDu = " + str(tcCltuRespDu))
def notifyTCpacketResponseDataUnit(self, tcPktRespDu): """AD packet / BD segment response received""" LOG("") LOG("*** notifyTCpacketResponseDataUnit ***") LOG("tcPktRespDu.acknowledgement = " + GRND.NCTRSDUhelpers.ackStr(tcPktRespDu.acknowledgement)) LOG("tcPktRespDu = " + str(tcPktRespDu))
def notifyTCpacket(self, tcPacketDu): """TC packet received""" LOG("- notifyTCpacket") LOG(" APID = " + str(tcPacketDu.applicationProcessId)) LOG(" TYPE = " + str(tcPacketDu.serviceType)) LOG(" SUBTYPE = " + str(tcPacketDu.serviceSubType)) LOG(" SSC = " + str(tcPacketDu.sequenceControlCount))
def setPacketDataCmd(self, argv, extraData): """Decoded setPacketData command""" self.logMethod("setPacketDataCmd", "SPACE") # consistency check if len(argv) != 2 and len(argv) != 4: LOG_WARNING("invalid parameters passed for setPacketData", "SPACE") return False # extract the arguments pktMnemonic = argv[1] if len(argv) == 2: params = "" values = "" else: params = argv[2] values = argv[3] tmStruct = extraData # check the packet data tmPacketData = SUPP.IF.s_definitions.getTMpacketInjectData(pktMnemonic, params, values, tmStruct) if tmPacketData == None: LOG_WARNING("invalid data passed for setPacketData", "SPACE") return False # initialise the packet data SPACE.IF.s_configuration.tmPacketData = tmPacketData LOG("Packet = " + SPACE.IF.s_configuration.tmPacketData.pktName, "SPACE") LOG("SPID = " + str(SPACE.IF.s_configuration.tmPacketData.pktSPID), "SPACE") LOG("Parameters and values = " + str(SPACE.IF.s_configuration.tmPacketData.parameterValuesList), "SPACE") # notify the GUI self.notifyGUItask("PACKETDATA_SET") return True
def generateTMpacket(self, tmPacketData, obtUTC=None, ertUTC=None): """ generates a TM packet: implementation of SPACE.IF.OnboardComputer.generateTMpacket """ # create the TM packet spid = tmPacketData.pktSPID paramValues = tmPacketData.parameterValuesList dataField = tmPacketData.dataField segmentationFlags = tmPacketData.segmentationFlags tmPacketDu = SPACE.IF.s_tmPacketGenerator.getTMpacket( spid, paramValues, dataField, segmentationFlags, obtUTC) if tmPacketDu.dataFieldHeaderFlag: LOG( "PUS Packet:" + UTIL.DU.array2str( tmPacketDu.getBufferString()[0:min(16, len(tmPacketDu))]), "SPACE") else: LOG( "CCSDS Packet:" + UTIL.DU.array2str( tmPacketDu.getBufferString()[0:min(16, len(tmPacketDu))]), "SPACE") if tmPacketDu == None: LOG_ERROR("packet creation failed: SPID = " + str(spid), "SPACE") return False # send the TM packet return self.pushTMpacket(tmPacketDu, ertUTC)
def tcpDataCallback(self, socket, stateMask): """Callback when a TCP/IP client (e.g. TECO) has send a command""" # read the next set of byte from stdin tcpLineBuffer = self.tcpLineBuffer try: tcpLineBuffer += self.clientSocket.recv(LINEBUFFERLEN).decode( "ascii") LOG("tcpLineBuffer: " + tcpLineBuffer) except: # read failed self.disconnected() return # handle the input: extract the lines from the line buffer lines = tcpLineBuffer.split("\n") # the last line has to be handled in a special way and can not be # processed directly lastLine = lines[-1] lines = lines[:-1] if lastLine == "": # read of the data was complete (incl. "\n") pass else: # last line was cutt off and the rest should come with the next read self.tcpLineBuffer = lastLine for line in lines: # remove a terminating "\r" for clients like telnet if line[-1] == "\r": line = line[:-1] # terminate the client connection if exit has been entered (case insensitive) upperLine = line.upper() if (upperLine == "X") or (upperLine == "EXIT"): LOG("exit requested") # set the OK response back to the TECO retString = "OK 0\n" try: self.clientSocket.send(retString.encode()) except: LOG_ERROR("send of OK response failed!") # terminate the client connection self.disconnected() return # delegate the input pstatus = self.processBuffer(line) if pstatus == 0: # send the OK response back to the TECO retString = "OK 0\n" try: self.clientSocket.send(retString.encode()) except: LOG_ERROR("send of OK response failed!") else: LOG_WARNING("return status = " + str(pstatus)) # set the Error response back to the TECO: retString = "Error: execution failed (see log)!\n" try: self.clientSocket.send(retString.encode()) except: LOG_ERROR("send of Error response failed!")
def dump(self): """Dumps the status of the configuration attributes""" LOG_INFO("Monitoring an Control configuration", "CFG") LOG("Connected = " + str(self.connected), "CFG") if self.tcPacketData == None: LOG("No packet defined", "CFG") else: LOG("Packet = " + self.tcPacketData.pktName, "CFG")
def helpCmd(self, argv): """Decoded help command""" LOG_INFO("Available commands:") LOG("") LOG("h | help .......provides this information") LOG("q | quit .......terminates the application") LOG("1 | cmd_answ ...send message via EDEN (CMD,ANSW)") LOG("")
def dump(self): """Dumps the status of the server configuration attributes""" LOG_INFO("EGSE interface server configuration", "EDEN") LOG("EDEN host = " + self.edenHost, "EDEN") LOG("EDEN connected = " + str(self.connected), "EDEN") LOG("EDEN interface port = " + str(self.edenPort), "EDEN") LOG("EDEN connected 2 = " + str(self.connected2), "EDEN") LOG("EDEN interface port 2 = " + str(self.edenPort2), "EDEN")
def dump(self): """Dumps the status of the server configuration attributes""" LOG_INFO("EGSE interface server configuration", "CNC") LOG("CNC host = " + self.cncHost, "CNC") LOG("CNC connected = " + str(self.connected), "CNC") LOG("CNC interface port = " + str(self.cncPort), "CNC") LOG("CNC connected 2 = " + str(self.connected2), "CNC") LOG("CNC interface port 2 = " + str(self.cncPort2), "CNC")
def pushTCpacket(self, tcPacketDu, route): """ consumes a telecommand packet: implementation of MC.IF.TCmodel.pushTCpacket """ LOG_INFO("pushTCpacket", "TC") LOG("Route: " + route, "TC") if route == "CNC": if not EGSE.IF.s_cncClientConfiguration.connected: LOG_ERROR("route CNC is not initialized", "TC") return False CS.CNCclient.s_client.pushTCpacket(tcPacketDu) elif route == "EDEN_SPACE": if not EGSE.IF.s_edenClientConfiguration.connected: LOG_ERROR("route EDEN_SPACE is not initialized", "TC") return False CS.EDENclient.s_client.pushTcSpace(tcPacketDu) elif route == "EDEN_SCOE": if not EGSE.IF.s_edenClientConfiguration.connected: LOG_ERROR("route EDEN_SCOE is not initialized", "TC") return False CS.EDENclient.s_client.pushTcScoe(tcPacketDu) elif route == "EDEN2_SPACE": if not EGSE.IF.s_edenClientConfiguration.connected2: LOG_ERROR("route EDEN2_SPACE is not initialized", "TC") return False CS.EDENclient.s_client2.pushTcSpace(tcPacketDu) elif route == "EDEN2_SCOE": if not EGSE.IF.s_edenClientConfiguration.connected2: LOG_ERROR("route EDEN2_SCOE is not initialized", "TC") return False CS.EDENclient.s_client2.pushTcScoe(tcPacketDu) elif route == "NCTRS_PACKET": if not GRND.IF.s_clientConfiguration.nctrsTCconn: LOG_ERROR("route NCTRS is not initialized", "TC") return False return CS.FRAMEmodel.s_frameModel.sendTCpacket( tcPacketDu, CS.FRAMEmodel.SEND_AS_PACKET) elif route == "NCTRS_FRAME": if not GRND.IF.s_clientConfiguration.nctrsTCconn: LOG_ERROR("route NCTRS is not initialized", "TC") return False return CS.FRAMEmodel.s_frameModel.sendTCpacket( tcPacketDu, CS.FRAMEmodel.SEND_AS_FRAME) elif route == "NCTRS_CLTU": if not GRND.IF.s_clientConfiguration.nctrsTCconn: LOG_ERROR("route NCTRS is not initialized", "TC") return False return CS.FRAMEmodel.s_frameModel.sendTCpacket( tcPacketDu, CS.FRAMEmodel.SEND_AS_CLTU) else: LOG_ERROR("invalid route for TC packet: " + route, "TC") LOG( "use instead: CNC | EDEN_SPACE | EDEN_SCOE | EDEN2_SPACE | EDEN2_SCOE |", "TC") LOG(" NCTRS_PACKET | NCTRS_FRAME | NCTRS_CLTU", "TC") return False return True
def receiveCallback(self, socket, stateMask): """Callback when data are received""" LOG("*** TCPsendingServer.receiveCallback ***") data = self.recv(MAXBYTESREAD) if data == None: # client is automatically disconnected return LOG("data read, len(data) = " + str(len(data))) LOG("data = " + data.decode("ascii"))
def tcScoeCmd(self, argv): """Decoded (TC,SCOE) command""" global s_client if len(argv) != 1: LOG_WARNING("Invalid command argument(s)") LOG("usage: tc_scoe") LOG("or: 2") return s_client.sendTcScoe(UnitTest.testData.TC_PACKET_01)
def helpCmd(self, argv): """Decoded help command""" # overloaded from UTIL.TASK.ProcessingTask LOG_INFO("Available commands:") LOG("") LOG("h | help .....provides this information") LOG("q | quit .....terminates TEST application") LOG("c | custom ...custom command, implemented in ModeTask") LOG("")
def tcSpaceCmd(self, argv): """Decoded (TC,SPACE) command""" global s_client if len(argv) != 1: LOG_WARNING("Invalid command argument(s)") LOG("usage: tc_space") LOG("or: 1") return s_client.sendTcSpace(testData.TC_PACKET_01)
def receiveCallback(self, socket, stateMask): """Callback when a client has send data""" LOG("*** receiveCallback ***") # read the next set of byte from the data socket data = self.recv(LINEBUFFERLEN) if data == None: # client is automatically disconnected return tcpLineBuffer = self.tcpLineBuffer tcpLineBuffer += data.decode("ascii") LOG("tcpLineBuffer: " + tcpLineBuffer) # handle the input: extract the lines from the line buffer lines = tcpLineBuffer.split("\n") # the last line has to be handled in a special way and can not be # processed directly lastLine = lines[-1] lines = lines[:-1] if lastLine == "": # read of the data was complete (incl. "\n") pass else: # last line was cutt off and the rest should come with the next read self.tcpLineBuffer = lastLine for line in lines: # remove a terminating "\r" for clients like telnet if line[-1] == "\r": line = line[:-1] # terminate the client connection if exit has been entered (case insensitive) upperLine = line.upper() if (upperLine == "X") or (upperLine == "EXIT"): LOG("Exit requested") # send the OK response back to the client retString = "OK\n" self.send(retString.encode()) # terminate the client connection self.disconnectClient(); return if (upperLine == "Q") or (upperLine == "QUIT"): LOG("Quit requested") # send the OK response back to the client retString = "OK\n" self.send(retString.encode()) # terminate the client connection self.disconnectClient(); sys.exit(0) # delegate the input pstatus = self.processLine(line); if pstatus == 0: LOG("OK") # send the OK response back to the TECO retString = "OK\n"; self.send(retString.encode()) else: LOG_ERROR(str(pstatus)) # set the Error response back to the client: retString = "Error: execution failed (see log)!\n" self.send(retString.encode())
def cmdExecCmd(self, argv): """Decoded (CMD,EXEC) command""" global s_client if len(argv) != 2: LOG_WARNING("Invalid command argument(s)") LOG("usage: cmd_exec <message>") LOG("or: 3 <message>") return message = argv[1] s_client.sendCmdExec(message)
def cmdAnswCmd(self, argv): """Decoded (CMD,ANSW) command""" global s_client if len(argv) != 2: LOG_WARNING("Invalid command argument(s)") LOG("usage: cmd_answ <message>") LOG("or: 1 <message>") return message = argv[1] s_server.sendCmdAnsw(message)
def tmPktCmd(self, argv): """Decoded TM-packet command""" global s_client1 if len(argv) != 1: LOG_WARNING("Invalid command argument(s)") LOG("usage: tm_pkt") LOG("or: 1") return tmPacketDU = CCSDS.PACKET.TMpacket(testData.TM_PACKET_01) s_server2.sendTMpacket(tmPacketDU.getBufferString())
def dump(self): """Dumps the status of the configuration attributes""" LOG_INFO("Ground segment configuration", "GRND") LOG("NCTRS TM conn = " + str(self.nctrsTMconn), "GRND") LOG("NCTRS TM port = " + str(self.nctrsTMport), "GRND") LOG("NCTRS TC conn = " + str(self.nctrsTCconn), "GRND") LOG("NCTRS TC port = " + str(self.nctrsTCport), "GRND") LOG("NCTRS admin message conn = " + str(self.nctrsAdminConn), "GRND") LOG("NCTRS admin message port = " + str(self.nctrsAdminPort), "GRND") LOG("TC Ack 1 = " + ACK_STRS[self.grndAck1], "GRND") LOG("TC Ack 2 = " + ACK_STRS[self.grndAck2], "GRND") LOG("Frame Record File = " + str(self.frameRecordFile), "GRND") LOG("Frame Record Format = " + str(self.frameRecordFormat), "GRND")
def cncCommand(self, argv): """CnC command""" global s_client if len(argv) != 2: LOG_WARNING("Invalid command argument(s)") LOG("usage: cnc_command <message>") LOG("or: 1 <message>") return message = argv[1] cncTCpacketDU = EGSE.CNCPDU.CNCcommand() cncTCpacketDU.applicationProcessId = 1234 cncTCpacketDU.setCNCmessage(message) s_client.sendCNCpacket(cncTCpacketDU.getBufferString())
def receiveCallback(self, socket, stateMask): """Callback when a server has send data""" LOG("*** receiveCallback ***") # read the next set of byte from the data socket tcpLineBuffer = self.tcpLineBuffer try: tcpLineBuffer += self.dataSocket.recv(LINEBUFFERLEN); LOG("tcpLineBuffer: " + tcpLineBuffer) except Exception, ex: # read failed LOG_ERROR("Read failed: " + str(ex)) self.disconnectClient() return
def helpCmd(self, argv): """Decoded help command""" LOG("Available commands:") LOG("-------------------") LOG("") LOG("h | help .......provides this information") LOG("q | quit .......terminates the application") LOG("1 | tc_space ...send TC via EDEN (TC,SPACE)") LOG("2 | tc_scoe ....send TC via EDEN (TC,SCOE)") LOG("3 | cmd_exec ...send message via EDEN (CMD,EXEC)") LOG("")
def helpCmd(self, argv): """Decoded help command""" LOG("Available commands:") LOG("-------------------") LOG("") LOG("h | help .............provides this information") LOG("q | quit .............terminates the application") LOG("p | packetresponse ...send NCTRS TC packet response") LOG("c | clturesponse .....send NCTRS TC CLTU response") LOG("l | linkstatus .......send NCTRS TC link status") LOG("")
def processTCpacket(self, tcPacketDu): """ processes a telecommand C&C packet from the CCS implementation of SPACE.IF.ApplicationSoftware.processTCpacket """ apid = tcPacketDu.applicationProcessId LOG_INFO("EUCLIDpowerFEEsim_BS.processTCpacket(" + str(apid) + ")", "SPACE") # packet is a PUS Function Management command if tcPacketDu.serviceType == PUS.SERVICES.TC_FKT_TYPE: if tcPacketDu.serviceSubType == PUS.SERVICES.TC_FKT_PERFORM_FUNCTION: tcFunctionId = tcPacketDu.getUnsigned( self.tcFunctionIdBytePos, self.tcFunctionIdByteSize) LOG("tcFunctionId = " + str(tcFunctionId), "SPACE") if tcFunctionId == BS_Initialize: LOG_INFO("*** BS_Initialize ***", "SPACE") LOG("push HKTM", "SPACE") return self.sendBS_Monitor() elif tcFunctionId == BS_SetLocal: LOG_INFO("*** BS_SetLocal ***", "SPACE") LOG("set the SCOE into the LOCAL commanding mode", "SPACE") self.commandingMode = EPWR_CMD_LOCAL elif tcFunctionId == BS_SetRemote: LOG_INFO("*** BS_SetRemote ***", "SPACE") LOG("set the SCOE into the REMOTE commanding mode", "SPACE") self.commandingMode = EPWR_CMD_REMOTE elif tcFunctionId == BS_LockInstruments: LOG_INFO("*** BS_LockInstruments ***", "SPACE") LOG("not used for simulation", "SPACE") elif tcFunctionId == BS_UnlockInstruments: LOG_INFO("*** BS_UnlockInstruments ***", "SPACE") LOG("not used for simulation", "SPACE") elif tcFunctionId == BS_SetOnline: LOG_INFO("*** BS_SetOnline ***", "SPACE") LOG("set the SCOE into the ONLINE operation mode", "SPACE") self.operationMode = EPWR_OP_ONLINE return self.sendBS_Monitor() elif tcFunctionId == BS_SetOffline: LOG_INFO("*** BS_SetOffline ***", "SPACE") LOG("set the SCOE into the OFFLINE operation mode", "SPACE") self.operationMode = EPWR_OP_OFFLINE return self.sendBS_Monitor() elif tcFunctionId == BS_SelfTest: LOG_INFO("*** BS_SelfTest ***", "SPACE") # the SELFTEST is only allowed in OFFLINE mode if self.operationMode == EPWR_OP_ONLINE: LOG_ERROR("SELFTEST not allowed when system is ONLINE", "SPACE") return False else: # unexpected Function ID LOG_WARNING( "no simulation for Function ID " + str(tcFunctionId) + " implemented", "SPACE") return True LOG_WARNING("TC ignored by simulation", "SPACE") return True
def accepted(self, clientSocket): """Client has connected""" LOG("*** accepted ***") self.clientSocket = clientSocket self.clientSocket.send("connected\n") # prepare a timer that calls the after method one second ago UTIL.TASK.s_processingTask.createTimeHandler(1000, self.after)
def notifyTCframeCallback(self, frameDU): """notifies when the next TC frame is assembled""" # overloaded from TCencoder LOG("FrameModel.notifyTCframeCallback" + frameDU.getDumpString(), "FRAME") LOG_WARNING("frame cannot be directly sent, there is no NCTRS service", "FRAME")
def notifyError(self, errorMessage, data): """error notification""" LOG_ERROR(errorMessage) try: LOG(str(data)) except Exception, ex: LOG_WARNING("data passed to notifyError are invalid: " + str(ex))