00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 __facility__ = "Online"
00011 __abstract__ = "Wrapper class for LCAT based telecommands"
00012 __author__ = "Selim Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__ = "2005/07/23 00:08:27"
00014 __updated__ = "$Date: 2006/03/07 23:59:37 $"
00015 __version__ = "$Revision: 1.20 $"
00016 __release__ = "$Name: HEAD $"
00017 __credits__ = "SLAC"
00018
00019 import LICOS.copyright_SLAC
00020
00021 import logging as log
00022 from binascii import hexlify
00023
00024
00025 import LCAT_cmd_db
00026
00027 from LICOS.lib.cmdTlmDb.cmdTlmDb import CmdDb
00028 from LICOS.lib.cmdTlmDb.TelemetryEvent import TelemetryEvent
00029 from LICOS.lib.cmdTlmDb.LMC import LMC
00030 from LICOS.lib.cmdTlmDb.LHK import LHK
00031 from LICOS.lib.cmdTlmDb.MEM import MEM
00032 from LICOS.lib.cmdTlmDb.PBC import PBC
00033 from LICOS.lib.cmdTlmDb.FILE import FILE
00034 from LICOS.lib.cmdTlmDb.LFS import LFS
00035 from LICOS.lib.cmdTlmDb.LSM import LSM
00036 from LICOS.lib.cmdTlmDb.LTC import LTC
00037 from LICOS.lib.cmdTlmDb.LCM import LCM
00038 from LICOS.lib.cmdTlmDb.LIM import LIM
00039 from LICOS.lib.cmdTlmDb.LCI import LCI
00040 from LICOS.lib.cmdTlmDb.LPA import LPA
00041 from LICOS.lib.cmdTlmDb.DDT import DDT
00042
00043 class LCATcmdDb(CmdDb):
00044 """!\brief Database wrapper class for LCAT based telecommands
00045
00046 This class contains all telecommands based on the generated LCAT_cmd_db
00047 database. The telecommands are grouped by packages. A sample usage of
00048 queuing the telecommands to the VSC is shown below:
00049
00050 \code
00051 from LICOS.lib.cmdTlmDb.LCATcmdDb import LCATcmdDb
00052 .
00053 .
00054 lcat = LCATcmdDb(self.vsc)
00055 mem = lcat.MEM
00056 packet = mem.LMEMDUMPMEM(LMEMLATUNIT=1, LMEMTRANID=2, LMEMPAD=3,
00057 LMEMADDRESSHI=4, LMEMADDRESSLO=5, LMEMSIZEHI=6, LMEMSIZELO=7)
00058
00059 \endcode
00060 """
00061
00062 def __init__(self, vsc):
00063 """!\brief LCATcmdDb constructor.
00064
00065 \param vsc VPI_Proxy object.
00066 """
00067 CmdDb.__init__(self, vsc)
00068 self.__dbModule = LCAT_cmd_db
00069 self.__cmdDict = self.__dbModule.CmdDict()
00070 self.LMC = LMC(self)
00071 self.LHK = LHK(self)
00072 self.MEM = MEM(self)
00073 self.PBC = PBC(self)
00074 self.FILE = FILE(self)
00075 self.LFS = LFS(self)
00076 self.LSM = LSM(self)
00077 self.LTC = LTC(self)
00078 self.LCM = LCM(self)
00079 self.LIM = LIM(self)
00080 self.LCI = LCI(self)
00081 self.LPA = LPA(self)
00082 self.DDT = DDT(self)
00083
00084 self.__cmdConfirmTelem = TelemetryEvent(vsc.getDiagHandler(),
00085 [self.getVsc().getTlmDb().getApidFromName('CmdConfirm')],
00086 self.__confirmation
00087 )
00088 self.__confPacket = None
00089 self.__confCallback = self.confirmation
00090
00091 def getCmdDict(self):
00092 """!\brief Return the command dictionary.
00093
00094 \return Command dictionary
00095 """
00096 return self.__cmdDict
00097
00098 def getDbModule(self):
00099 """!\brief Return the generated database module.
00100
00101 \return Database module
00102 """
00103 return self.__dbModule
00104
00105 def setCmdConfirmCallback(self, callback):
00106 """!\brief Set the user script callback for the command confirmation telemetry.
00107
00108 \param callback Callback method
00109 """
00110 self.__confCallback = callback
00111
00112 def getCmdConfirmCallback(self):
00113 """!\brief Get the current command confirmation callback.
00114
00115 \return Command confirmation callback.
00116 """
00117 return self.__confCallback
00118
00119 def confirmation(self, telemetry):
00120 """!\brief Default callback for command confirmation telemetry
00121
00122 \param Raw telemetry packet
00123 """
00124 confPacket = self.getVsc().getTlmDb().decodeTelemetry(telemetry, dump=True)
00125
00126
00127
00128
00129 for i in range(0x22, telemetry.sizeofPayload(), 2):
00130 log.debug(" %15s 0x%02x: 0x%s " %\
00131 ( "ITC_PAYLOAD", i - 0x1a, hexlify(telemetry.payload()[i:i+2])) )
00132
00133 log.info(self.getVsc().getTlmDb().msgByValue(confPacket.get_payload("ITC_EXESTATUS")))
00134
00135 def quietConfirmation(self, telemetry):
00136 """!\brief quiet callback for command confirmation telemetry
00137
00138 \param Raw telemetry packet
00139 """
00140 pass
00141
00142 def getConfirmationPacket(self):
00143 """!\brief Retrieve the last command confirmation packet received.
00144
00145 """
00146 return self.__confPacket
00147
00148 def getConfirmationMsg(self):
00149 """!\brief Retrieve the status inside the last command confirmation packet received.
00150
00151 """
00152 if self.__confPacket is not None:
00153 return self.__confPacket.get_payload('ITC_EXESTATUS')
00154 else:
00155 return 0xffffffff
00156
00157
00158 def __confirmation(self, telemetry):
00159 """!\brief Callback for the command confirmation telemetry.
00160
00161 \param Raw telemetry packet
00162 """
00163 if self.__confCallback is not None:
00164 self.__confCallback(telemetry)
00165 self.__confPacket = self.getVsc().getTlmDb().decodeTelemetry(telemetry, dump=False)
00166
00167 def waitForConfirmation(self, timeout=10, quiet=False):
00168 """!\brief Wait for the command confirmation packet.
00169
00170 \param timeout Amount of time to wait for the command
00171 confirmation packet
00172
00173 \return True if a command confirmation packet is received.
00174 False if no command confirmation packet is received before
00175 the timeout.
00176 """
00177 cmdConfirmTelemReceived = self.__cmdConfirmTelem.wait(timeout, quiet)
00178 if not cmdConfirmTelemReceived:
00179 if not quiet:
00180 log.warn("Timeout waiting for command confirmation")
00181 self.__confPacket = None
00182 return cmdConfirmTelemReceived
00183
00184 def waitForSuccessfulConfirmation(self, timeout=10, quiet=False):
00185 """!\brief Wait for successful command confirmation telemetry.
00186
00187 \param timeout Number of seconds to wait for the confirmation.
00188
00189 \return True if command confirmation was successful, False otherwise.
00190 """
00191 result = True
00192 if self.waitForConfirmation(timeout, quiet):
00193 if not self.getVsc().getTlmDb().msgIsSuccess(self.__confPacket.get_payload("ITC_EXESTATUS")):
00194 result = False
00195 else:
00196 result = False
00197 return result
00198
00199 def enableCmdConfirmTelem(self):
00200 self.__cmdConfirmTelem.enable()
00201
00202 def disableCmdConfirmTelem(self):
00203 self.__cmdConfirmTelem.disable()
00204
00205 def isCmdConfirmTelemEnabled(self):
00206 return self.__cmdConfirmTelem.isEnabled()