00001 #!/usr/local/bin/python 00002 # 00003 # Copyright 2004 00004 # by 00005 # The Board of Trustees of the 00006 # Leland Stanford Junior University. 00007 # All rights reserved. 00008 # 00009 00010 00011 __facility__ = "Online" 00012 __abstract__ = "PDU switch test" 00013 __author__ = "Patrick Young <plsyoung@SLAC.Stanford.edu> SLAC - GLAST LAT Electronics" 00014 __date__ = "16/09/2004" 00015 __version__ = "$Revision: 2.2 $" 00016 __credits__ = "SLAC" 00017 00018 from LATTE.client.gOptions import Options 00019 from LATTE.client.gCmdCli import CmdCli 00020 from LATTE.database.gLAT import GLAT 00021 from LATTE.database.gPlumber import Plumber 00022 00023 from ELX.Common.instruments.ElxSwitch import ElxSwitch 00024 from ELX.Common.instruments.ElxPowerSupply import ElxPowerSupply 00025 from ELX.Common.instruments.ElxFunctionGenerator import ElxFunctionGenerator 00026 00027 import time 00028 import traceback 00029 00030 class PduSwitch: 00031 def __init__(self, lat): 00032 self.lat = lat 00033 self.switch = ElxSwitch('37', 'COM2', [100,200]) 00034 self.black0 = ElxPowerSupply('1697', 'COM1', 5) 00035 if not self.switch.allOpen(): 00036 raise RuntimeError, 'allOpen failed' 00037 if not self.black0.setVoltage(28.): 00038 raise RuntimeError, 'setVoltage failed' 00039 if not self.black0.switchOn(): 00040 raise RuntimeError, 'switchOn failed' 00041 00042 def configureTestHardware(self, pdu, gasu): 00043 status = self.__setRelays(pdu, gasu) 00044 if not status: 00045 message = 'Problem setting relays pdu %d, gasu side %d, please resolve' \ 00046 %(pdu, gasu) 00047 raise RuntimeError, message 00048 self.__plumb(self.lat, pdu, gasu) 00049 00050 def __setRelays(self, pdu=0, gasu=0): 00051 feed = 0 00052 success = self.switch.allOpen() 00053 #time.sleep(1) 00054 pattern0 = 2*pdu + feed + 1 00055 pattern1 = 2*gasu + pdu + 1 00056 success &= self.switch.setValue(100, pattern0) 00057 #time.sleep(1) 00058 success &= self.switch.setValue(200, pattern1) 00059 #time.sleep(1) 00060 return success 00061 00062 def __plumb(self, lat, pdu=0, gasu=0): 00063 onPdu = lat.downPDU(pdu) 00064 offPdu = lat.downPDU(pdu^1) 00065 lcb = lat.downLCB() 00066 offPdu.setFlag('CmdrspFabric','Off') 00067 onPdu.setFlag('CmdrspFabric','On') 00068 lcb.setFlag('UseRedundant',gasu) 00069 plumber = Plumber(lat, None) 00070 plumber.initialize(3, ocsverbose=True, force=True) 00071 00072 00073 if __name__ == '__main__': 00074 options = Options(['server', 'schema']) 00075 00076 try: 00077 options.parse() 00078 except Exception, msg: 00079 options.usage(str(msg)) 00080 raise RuntimeError 00081 00082 cmd = CmdCli() 00083 cmd.connect(options.server) 00084 cmd.setDebug(1) 00085 00086 lat = GLAT(cmd) 00087 lat.readSchema(options.schema) 00088 00089 pduswitch = PduSwitch(lat) 00090 00091 i = 0 00092 while True: 00093 print 'set configuration %d' %(i%4) 00094 pduswitch.configureTestHardware(i%2, (i>>1) & 0x1) 00095 print 'test %d completed, iteration %d. %s' %(i%4, i, time.ctime()) 00096 i += 2