ScienceProxy.py

Go to the documentation of this file.
00001 #!/usr/local/bin/python
00002 #
00003 #                               Copyright 2005
00004 #                                     by
00005 #                        The Board of Trustees of the
00006 #                     Leland Stanford Junior University.
00007 #                            All rights reserved.
00008 #
00009 
00010 __facility__ = "Online"
00011 __abstract__ = "Science Proxy class"
00012 __author__   = "S. Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__     = "2006/01/16"
00014 __updated__  = "$Date: 2006/04/25 17:22:01 $"
00015 __version__  = "$Revision: 1.11 $"
00016 __release__  = "$Name: HEAD $"
00017 __credits__  = "SLAC"
00018 
00019 import LICOS.copyright_SLAC
00020 
00021 import VSC
00022 import CCSDS
00023 
00024 from LICOS.util.gOptions import Options
00025 from LICOS.tools.proxy.VscProxyPorts import VscProxyPorts
00026 from LICOS.tools.proxy.VscProxyTools import getip, VscProxyLogger
00027 from LICOS.tools.proxy.VscArchivers  import VscArchiver
00028 
00029 import os
00030 import sys
00031 import time
00032 from ConfigParser import ConfigParser
00033 
00034 
00035 class VscScienceRouter(VSC.VscRouting.ScienceRouter):
00036   def __init__(self, streams):
00037     VSC.VscRouting.ScienceRouter.__init__(self)
00038     self.__packet = CCSDS.Ccsds.Science(0, 0, 0)
00039     self.__streams = streams
00040     self.__apids = {}
00041 
00042   def allocate(self):
00043     return self.__packet
00044 
00045   def catchall(self, ccsds):
00046     apid = ccsds.apid()
00047     if apid in self.__apids.keys():
00048       self.__apids[apid] += 1
00049     else:
00050       self.__apids[apid] = 1
00051     for stream in self.__streams:
00052       stream.send_nothrow(ccsds)
00053 
00054   def apids(self):
00055     return self.__apids
00056 
00057 
00058 class ScienceProxy(VSC.VscProxy.Proxy):
00059   def __init__(self, ip_vsc, config, noarchiver):
00060     ports = VscProxyPorts(config.getint('vsc', 'proxyPortBase'))
00061     VSC.VscProxy.Proxy.__init__(self, ip_vsc, ports.vsc())
00062     self.__archiver = None
00063     if noarchiver is False:
00064       archive_path = config.get('paths', 'archive_path')
00065       granularity  = config.getint('ccsds_archivers', 'granularity')
00066       self.__archiver = VscArchiver(apIdGrp = "SCI",
00067                                     path = archive_path,
00068                                     granularity = granularity)
00069     self.router = VscScienceRouter([self.__archiver])
00070     self.latScience(self.router)
00071 
00072 
00073 if __name__ == '__main__':
00074   options = Options(['vscip', 'config'], [], ['logtime', 'noarchiver'])
00075   try:
00076     options.parse()
00077   except Exception, msg:
00078     options.usage(str(msg))
00079     sys.exit()
00080   
00081   if options.logtime is not None:
00082     sys.stdout = VscProxyLogger('science proxy: ')
00083     sys.stderr = sys.stdout
00084 
00085   vscip = getip(options.vscip)
00086   config = ConfigParser()
00087   config.read(options.config)
00088   dumpInterval = config.getint('vsc', 'dumpInterval')
00089   noarchiver = (options.noarchiver is not None)
00090   proxy = ScienceProxy(vscip, config, noarchiver)
00091   apids = proxy.router.apids()
00092   while True:
00093     time.sleep(dumpInterval)
00094     npackets = 0
00095     msg = ''
00096     for (apid, counter) in apids.items():
00097       npackets += counter
00098       msg += ', 0x%x: %d' %(apid, counter)
00099     print 'received %d packets%s' %(npackets, msg)
00100     sys.stdout.flush()

Generated on Thu Apr 27 20:52:43 2006 for LICOS L02-01-00 by doxygen 1.4.6-NO