00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 __facility__ = "Online"
00011 __abstract__ = "Current Value Table Client"
00012 __author__ = "Jim Panetta <panetta@slac.stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__ = ("$Date: 2006/01/28 05:35:25 $").split(' ')[1]
00014 __version__ = "$Revision: 1.9 $"
00015 __release__ = "$Name: HEAD $"
00016 __credits__ = "SLAC"
00017
00018 import LICOS.copyright_SLAC
00019
00020 import LICOS.util.gOptions as gOptions
00021
00022 import threading, asyncore, socket
00023 import time
00024 import cPickle as pickle
00025
00026 from LICOS.lib.currValTable.StringTcpProtocol import Int16StringProtocol
00027 from LICOS.lib.currValTable.CurrValTable import *
00028
00029 class CurrValClient(Int16StringProtocol):
00030 def __init__(self, host, port, mnemList):
00031
00032 super(CurrValClient, self).__init__()
00033 self.__mnemList = mnemList
00034
00035
00036 self.create_socket(socket.AF_INET,socket.SOCK_STREAM)
00037
00038 self.__host = host
00039 self.__port = port
00040 self.__connect()
00041
00042 def __connect(self):
00043 self.connect( (self.__host, self.__port) )
00044
00045
00046 def handle_connect(self):
00047 pass
00048
00049 def handle_close(self):
00050
00051 self.close()
00052
00053 def stringReceived(self, line):
00054
00055 response = line[0:3]
00056 fields = line.split()
00057 if response == 'ok ':
00058 self.sendString("observer")
00059 pass
00060 elif response == 'ob ':
00061
00062 self.registerAll()
00063 pass
00064 elif response == "up ":
00065
00066
00067 self.update(decodeCurrentValue(line[3:]))
00068 else:
00069 print "bad response:", line
00070
00071 def register(self, mnem):
00072 query = "register " + mnem
00073 self.sendString(query)
00074
00075 def unregister(self, mnem):
00076 query = "unregister " + mnem
00077 self.sendString(query)
00078
00079 def registerAll(self):
00080 for mnem in self.__mnemList:
00081 self.register(mnem)
00082
00083 def update(self, cv):
00084 """!\brief update method
00085
00086 to be overridden by the sub class
00087
00088 \param mnem
00089 \param value
00090 """
00091 print "recieved update of ", cv.name, " =", cv.rawValue()
00092
00093 if __name__ == '__main__':
00094
00095 options = gOptions.Options(['cvtHost', 'cvtPort'])
00096 try:
00097 options.parse()
00098 except Exception, msg:
00099 options.usage(str(msg))
00100 exit
00101
00102 cvtHost = options.cvtHost
00103 cvtPort = int(options.cvtPort)
00104
00105
00106 mnemList = []
00107 mnemList.append("LHKT5TKRC5T0")
00108
00109
00110 cvc = CurrValClient( cvtHost, cvtPort, mnemList )
00111
00112 asyncore.loop(1)
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123