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__ = "Response class" 00013 __author__ = "Amedeo Perazzo <perazzo@slac.stanford.edu> SLAC - GLAST I&T/Online" 00014 __date__ = ("$Date: 2005/07/11 17:08:14 $").split(' ')[1] 00015 __version__ = "$Revision: 2.6 $" 00016 __release__ = "$Name: R04-12-00 $" 00017 __credits__ = "SLAC" 00018 00019 import LATTE.copyright_SLAC 00020 import struct 00021 import gException 00022 00023 class Response: 00024 def __init__(self, command, result): 00025 self.__timestamp = 0x0L 00026 self.__status = 0 00027 self.__payloads = [] 00028 self.__formats = command.payloadfmts() 00029 00030 fmt = '!IQI' 00031 for payloadfmt in self.__formats: 00032 fmt += payloadfmt 00033 if len(result) != struct.calcsize(fmt): 00034 print "*** gResponse: received %d bytes but expected %d bytes" \ 00035 %(len(result), struct.calcsize(fmt)) 00036 self.__status = gException.LATInterfaceStatus.status('OCS_BDRESP') 00037 else: 00038 rsp = struct.unpack(fmt, result) 00039 self.__timestamp = rsp[1] 00040 self.__status = rsp[2] 00041 self.__payloads = rsp[3:] 00042 00043 def timestamp(self): 00044 return self.__timestamp 00045 00046 def status(self): 00047 return self.__status & 0x7fffffff 00048 00049 def rvalue(self): 00050 return self.__status 00051 00052 def value(self): 00053 return self.__payloads[0] 00054 00055 def payloads(self): 00056 return self.__payloads