TelemetryEvent.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__ = "Helper class for handling telemetry"
00012 __author__   = "Selim Tuvi <stuvi@slac.stanford.edu> SLAC - GLAST LAT I&T/Online"
00013 __date__     = "2005/09/13 00:08:27"
00014 __updated__  = "$Date: 2006/03/22 03:16:00 $"
00015 __version__  = "$Revision: 1.5 $"
00016 __release__  = "$Name: HEAD $"
00017 __credits__  = "SLAC"
00018 
00019 import LICOS.copyright_SLAC
00020 
00021 import logging as log
00022 import threading
00023 
00024 from LICOS.lib.cmdTlmDb.LCATtlmDb import LICOS_VscTlmPacketFactory
00025 
00026 class TelemetryEvent(object):
00027   """!\brief Helper class for handling telemetry
00028   """
00029   def __init__(self, telemHandler, apidList, callback=None):
00030     """!\brief TelemetryEvent constructor.
00031 
00032     \param Telemetry handler instance
00033     \param apidList  List of apids
00034     \param callbcak  Callback method
00035     """
00036     self.__apidList = apidList
00037     self.__telemetryReceived = threading.Event()
00038     self.__telemHandler = telemHandler
00039     self.__telemCallback = callback
00040     self.__telemetryProcessed = threading.Event()
00041     self.__telemetryProcessed.set()
00042 
00043   def __notification(self, telemetry):
00044     """!\brief Callback for the command confirmation telemetry.
00045 
00046     \param telemetry Raw telemetry packet
00047     """
00048     if self.__telemCallback is not None:
00049       self.__telemCallback(telemetry)
00050     self.__telemetryReceived.set()
00051     self.__telemetry = telemetry
00052     self.__telemetryProcessed.wait()
00053 
00054   def wait(self, timeout=10, quiet=False):
00055     """!\brief Wait for telemetry.
00056 
00057     \param timeout Wait timeout value
00058 
00059     \return False if the telemetry is not received within the given \a timeout.
00060             True  if the telemetry is received.
00061     """
00062     self.__telemetryProcessed.clear()
00063     self.__telemetryReceived.wait(timeout)
00064     if not self.__telemetryReceived.isSet():
00065       self.__telemetryProcessed.set()
00066       if not quiet:
00067         log.warn("Timeout waiting for telemetry")
00068       return False
00069     else:
00070       self.__telemetryReceived.clear()
00071       self.__telemetryProcessed.set()
00072       return True
00073 
00074   def waitForPayload(self, payloads, timeout=10, quiet=False):
00075     """!\brief Wait for telemetry and return a list of payload values.
00076 
00077     \param timeout  Wait timeout value
00078     \param payloads Payload names to query for
00079 
00080     \return A list of payload values or None if the telemetry
00081             is not received within the given \a timeout.
00082             If any of the payload names are invalid then
00083             None is returned for that payload
00084     """
00085     self.__telemetryProcessed.clear()
00086     self.__telemetryReceived.wait(timeout)
00087     if not self.__telemetryReceived.isSet():
00088       self.__telemetryProcessed.set()
00089       if not quiet:
00090         log.warn("Timeout waiting for telemetry")
00091       return None
00092     else:
00093       self.__telemetryReceived.clear()
00094       pkt = LICOS_VscTlmPacketFactory(self.__telemetry)
00095       pkt.decode_payload()
00096       values = []
00097       pktPayloads = pkt.get_payload_list()
00098       for payload in payloads:
00099         if payload in pktPayloads:
00100           value = pkt.get_payload(payload)
00101         else:
00102           value = None
00103         values.append(value)
00104       self.__telemetryProcessed.set()
00105       return values
00106 
00107   def enable(self):
00108     """!\brief Enable the callback.
00109 
00110     """
00111     self.__telemHandler.register(self.__apidList, self.__notification)
00112 
00113   def disable(self):
00114     """!\brief Disable the callback.
00115 
00116     """
00117     self.__telemHandler.unregister(self.__apidList, self.__notification)
00118 
00119   def isEnabled(self):
00120     """!\brief Find out if the telemetry event is enabled
00121 
00122     \return Boolean indicating whether telemtry event is enabled or not
00123     """
00124     return self.__telemHandler.isregistered(self.__apidList, self.__notification)

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