00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 __facility__ = "Online"
00011 __abstract__ = "Minimal data taking application - VSC version"
00012 __author__ = "S. Tuvi <Stuvi@SLAC.Stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__ = "2005/07/23 00:08:27"
00014 __updated__ = "$Date: 2006/04/14 02:22:47 $"
00015 __version__ = "$Revision: 1.14 $"
00016 __release__ = "$Name: HEAD $"
00017 __credits__ = "SLAC"
00018
00019 import LICOS.copyright_SLAC
00020
00021 import logging as log
00022 import struct
00023 import time
00024 import sys
00025
00026 from LICOS.lib.LATconstants import *
00027 from LICOS.lib.cmdTlmDb.PBC import PBC
00028
00029 from LICOS.lib.scriptEngine.seAppBase import seAppBase
00030 from LICOS.lib.scriptEngine.ArgumentImpl import ArgumentImpl
00031 from LICOS.lib.cmdTlmDb.LCATcmdDb import LCATcmdDb
00032 from LICOS.lib.cmdTlmDb.LCATtlmDb import LCATtlmDb
00033 from LICOS.lib.testReport.rcTestReport import rcTestReport
00034
00035
00036 class testVscMinimal(seAppBase):
00037 """!\brief Sample script based on seAppBase that demonstrates tele-commands.
00038
00039 Demonstrates queuing memory dump commands to the VSC.
00040
00041 """
00042 def __init__(self, common):
00043 """!\brief MemDump constructor.
00044
00045 \param common ScriptEngineCommon constructor
00046 """
00047 seAppBase.__init__(self, common)
00048 log.debug("%s.__init__()" % self.getName())
00049 self.__arg = None
00050 self.__tr = rcTestReport()
00051
00052 def getName(self):
00053 """!\brief Return the name of this class.
00054
00055 \return Class name
00056 """
00057 return self.__class__.__name__
00058
00059 def setup(self):
00060 """!\brief SETUP transition method.
00061
00062 """
00063 log.debug("%s.setup()" % self.getName())
00064
00065 hwConfig = self.prefs['hwConfig']
00066 if len(hwConfig) == 0:
00067 pass
00068 else:
00069 log.debug("Setting cross strapping from --vscConfig item")
00070 siuIdPhysical = int(hwConfig['siuIdPhysical'])
00071 pduId = int(hwConfig['pduId'])
00072
00073
00074 priFeed = int(hwConfig['primaryFeed'])
00075 priGasu = int(hwConfig['primaryGasu'])
00076 firstEpuId = int(hwConfig['firstEpuId'])
00077 secondEpuId = int(hwConfig['secondEpuId'])
00078
00079
00080
00081
00082
00083 if self.rc is None:
00084 self.__arg = userArgText()
00085 else:
00086 self.rc.execGUImethod(self.createGUI)
00087
00088 def createGUI(self):
00089 """!\brief Create the argument GUI.
00090
00091 Must be passed to an execGUImethod.
00092 This is done here in a separate method so that the GUI creation
00093 and deletion is done in the GUI thread.
00094
00095 Executing self.__arg = self.rc.createGUI(userArgument, self.rc, 'test1', 1)
00096 does not work since the GUI object was being garbage collected (deleted)
00097 in the non-GUI thread.
00098 """
00099 self.__arg = userArgument(self.rc, 'test1', 1)
00100
00101 def run(self):
00102 """!\brief RUN transition method.
00103
00104 """
00105 log.debug("%s.run()" % self.getName())
00106
00107 self.startTestReport("testVscMinimal")
00108
00109 caption = "Enter number of HSK AemEnv0 diagnostic packets to be requested"
00110 if self.rc is None:
00111 hskCount = self.__arg.getValue(caption)
00112 else:
00113 hskCount = self.rc.execGUImethod(self.__arg.getValue, caption)
00114
00115 if hskCount is None:
00116 self.setCompletionStatus(self.COMPL_STATUS_ABORTED)
00117 return -1
00118
00119 lcat = LCATcmdDb(self.vsc)
00120 lcat.enableCmdConfirmTelem()
00121 lcatTlm = LCATtlmDb()
00122 mem = lcat.MEM
00123 memAddr = PBC.WATCHDOG_TIMER_ADDRESS
00124 result = mem.dumpMemory(FSW_UNIT_SIU, memAddr, size=1, tranID=0, dest=FSW_DEST_1553)
00125 secs = (struct.unpack('!I',result)[0])*PBC.WATCHDOG_TIMER_SECS_PER_CLK
00126 log.info("Watchdog timer set to %.2f seconds." % secs)
00127 lhk = lcat.LHK
00128 apid = lcatTlm.getApidFromName('AemEnv0')
00129 lhk.requestDiagHskPacket(apid, payloadMnems=[], timeout=10,
00130 count=hskCount, interval=0x64)
00131 self.setCompletionStatus(self.COMPL_STATUS_PASSED)
00132 lcat.disableCmdConfirmTelem()
00133
00134
00135 def stopRun(self):
00136 self.addAddlInputFile(sys.modules[self.__class__.__name__].__file__)
00137 self.closeTestReport()
00138
00139 def teardown(self):
00140 """!\brief TEARDOWN transition method.
00141
00142 """
00143
00144 if self.__arg is not None:
00145 self.__arg.deleteLater()
00146
00147 def startTestReport(self, title, configPrefs=None):
00148 """!\brief Add heading and summary to the test report.
00149
00150 """
00151 tr = self.__tr
00152 tr.initReport(title + ' [%s]' % self.runId)
00153 tr.addHeading(self.getName())
00154 tr.addHeading(title)
00155 tr.addHeading(time.asctime())
00156 self.addHwConfigToReport()
00157 summary = tr.addSection('Test Summary')
00158 if configPrefs is not None:
00159 cfgFile = os.path.split(self.__configFile)[1]
00160 tr.addSectionItem(summary, 'Configuration file', cfgFile, cfgFile)
00161 tr.addSectionItem(summary, 'Configuration file version', configPrefs["config"]["version"])
00162 tr.addSectionItem(summary, 'Configuration file release', configPrefs["config"]["release"])
00163 tr.addSectionItem(summary, 'Run Id', self.runId)
00164 runReportFile = '%s_rcReport.xml' % self.runId
00165 tr.addSectionItem(summary, 'Run Report', runReportFile, runReportFile)
00166 tr.addSectionItem(summary, "HTML test", tr.escape("The text that produced the following item is: <b>This text should be in bold</b>"))
00167 tr.addSectionItem(summary, "HTML test", "<b>This text should be in bold</b>")
00168
00169 def closeTestReport(self):
00170 """!\brief Close the test report and add it to exported file list.
00171
00172 """
00173 tr = self.__tr
00174 summary = tr.findSection("Test Summary")
00175 tr.addSectionItem(summary, "Completion Status", self.getCompletionStatusStr())
00176 testReportFile = os.path.join(self.prefs["reportdir"],
00177 '%s_%s.html' % (self.getName(), self.runId))
00178 self.__tr.transformToFile(LICOS_TEST_REPORT_XSL, testReportFile)
00179 self.addExportedFile(testReportFile, delete=True)
00180
00181 def addHwConfigToReport(self):
00182 hwConfig = self.prefs['hwConfig']
00183 siuIdPhysical = hwConfig['siuIdPhysical']
00184 pduId = hwConfig['pduId']
00185 siuSelect = hwConfig['siuSelect']
00186 daqSelect = hwConfig['daqSelect']
00187 priFeed = hwConfig['primaryFeed']
00188 priGasu = hwConfig['primaryGasu']
00189 firstEpuId = hwConfig['firstEpuId']
00190 secondEpuId = hwConfig['secondEpuId']
00191 hvbs = hwConfig['hvbs']
00192 tr = self.__tr
00193 hwSection = tr.addSection('Hardware Configuration')
00194 tr.addSectionItem(hwSection, "Preset Configuration", str(self.common.getLatConfigId()))
00195 tr.addSectionItem(hwSection, 'SIU Cross Strapping', siuSelect)
00196 tr.addSectionItem(hwSection, 'DAQ Cross Strapping', daqSelect)
00197 if priFeed:
00198 value = "Primary"
00199 else:
00200 value = "Redundant"
00201 tr.addSectionItem(hwSection, 'DAQ Feed', value)
00202 if siuIdPhysical:
00203 value = "Primary"
00204 else:
00205 value = "Redundant"
00206 tr.addSectionItem(hwSection, 'SIU', value)
00207 if priGasu:
00208 value = "Primary"
00209 else:
00210 value = "Redundant"
00211 tr.addSectionItem(hwSection, 'GASU', value)
00212 tr.addSectionItem(hwSection, 'EPU-A', str(firstEpuId))
00213 tr.addSectionItem(hwSection, 'EPU-B', str(secondEpuId))
00214 tr.addSectionItem(hwSection, 'ACD HVBS', str(hvbs))
00215 if pduId == 0:
00216 value = "Primary"
00217 else:
00218 value = "Redundant"
00219 tr.addSectionItem(hwSection, 'PDU', value)
00220
00221
00222
00223
00224 class userArgument(ArgumentImpl):
00225 """!\brief GUI for getting the user to input some sort of value.
00226
00227 """
00228 def __init__(self, parent = None, name = None, modal = 0, fl = 0):
00229 """!\brief userArgument constructor.
00230
00231 \param parent Parent GUI
00232 \param name GUI name
00233 \param modal Whether the dialog is modal or not
00234 \param fl GUI flags
00235 """
00236 ArgumentImpl.__init__(self, parent, name, modal, fl)
00237 self.__value = 0
00238 self.setCaption("Hello world!")
00239
00240 def OKButtonClicked(self):
00241 """!\brief Slot for the OK button.
00242
00243 """
00244 self.__value = int(self.ArgumentList.text().latin1())
00245 self.close()
00246
00247 def CancelButtonClicked(self):
00248 """!\brief Slot for the Cancel button.
00249
00250 """
00251 self.__value = None
00252 self.close()
00253
00254 def getValue(self, caption):
00255 """!\brief Bring up the GUI and return a value when OK is clicked.
00256
00257 \param caption Dialog caption
00258
00259 \return The value entered by the user
00260 """
00261 self.setCaption(caption)
00262 self.show()
00263 self.exec_loop()
00264 return self.__value
00265
00266 class userArgText(object):
00267 """!\brief Text user interface for getting the user to input some sort of value.
00268
00269 """
00270 def __init__(self):
00271 """!\brief userArgText constructor.
00272
00273 """
00274 pass
00275
00276 def getValue(self, caption):
00277 """!\brief Use console input to return a value from the user.
00278
00279 \return The value entered by the user
00280 """
00281 return int(raw_input("%s: " % (caption)))