Skip to content
Snippets Groups Projects
Commit a9b4699b authored by Samuel GARNIER's avatar Samuel GARNIER
Browse files

Move include LBP to properties, improve logs and status

* Log array builds up to 1024
* Last log error is displayed in status
parent c36cc3b1
Branches
Tags
No related merge requests found
......@@ -22,6 +22,7 @@ from tango import AttrQuality, DispLevel, DevState
from tango import AttrWriteType, PipeWriteType
# Additional import
#----- PROTECTED REGION ID(DG_PY_FOFBTool.additionnal_import) ENABLED START -----#
import datetime
import threading
import FofbTool
import FofbTool.Operation
......@@ -34,7 +35,12 @@ class ds_logappender(logging.StreamHandler):
self.parent = parent
logging.StreamHandler.__init__(self=self)
def emit(self, record):
self.parent._logs = [self.format(record),] + self.parent._logs[:-1]
if len(self.parent._logs) > 1023:
self.parent._logs.pop(0)
self.parent._logs.append(self.format(record))
if record.levelno > logging.WARNING:
self.parent.d_status['error'] = "Last Error: ({}) {}".format(record.asctime, record.msg)
#----- PROTECTED REGION END -----# // DG_PY_FOFBTool.additionnal_import
......@@ -85,6 +91,9 @@ class DG_PY_FOFBTool(Device):
- Type:'DevVarLongArray'
loglevel
- Type:'DevString'
includeLBP
- Do not include LBP in the com.\nThis will skip the starting of comlbp during the start command.
- Type:'DevBoolean'
"""
# PROTECTED REGION ID(DG_PY_FOFBTool.class_variable) ENABLED START #
......@@ -97,7 +106,7 @@ class DG_PY_FOFBTool(Device):
def my_status(self):
try:
return "\n\n".join([str(v) for v in self.d_status.values()])+"\n"
return "\n".join([str(v) for v in self.d_status.values()])+"\n"
except Exception:
self.debug_stream(str(self.d_status))
return "Status failure\n"
......@@ -183,16 +192,24 @@ class DG_PY_FOFBTool(Device):
mandatory=True
)
includeLBP = device_property(
dtype='DevBoolean',
mandatory=True
)
# ----------
# Attributes
# ----------
includeLBP = attribute(
dtype='DevBoolean',
access=AttrWriteType.READ_WRITE,
FofbToolVersion = attribute(
dtype='DevString',
)
FofbToolVersion = attribute(
lastSync = attribute(
dtype='DevString',
)
lastStart = attribute(
dtype='DevString',
)
......@@ -211,16 +228,19 @@ class DG_PY_FOFBTool(Device):
#----- PROTECTED REGION ID(DG_PY_FOFBTool.init_device) ENABLED START -----#
self.lock = threading.Lock()
if not self.lock.acquire(False):
self.error_stream("Device is running, skiping command")
return
self.set_state(tango.DevState.RUNNING)
self.d_status = {}
self.info_stream("FofbTool {}".format(FofbTool.__version__))
self._logs = ['',]*1024
self._logs = []
self._last_sync = ''
self._last_start = ''
logger = logging.getLogger("FofbTool")
self.loghandler = ds_logappender(self)
......@@ -228,9 +248,6 @@ class DG_PY_FOFBTool(Device):
logger.addHandler(self.loghandler)
logger.setLevel(getattr(logging, self.loglevel.upper()))
if not hasattr(self, "_include_lbp"):
self._include_lbp= False
self.set_state(tango.DevState.ON)
self.lock.release()
......@@ -260,24 +277,24 @@ class DG_PY_FOFBTool(Device):
# Attributes methods
# ------------------
def read_includeLBP(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.includeLBP_read) ENABLED START #
"""Return the includeLBP attribute."""
return self._include_lbp
# PROTECTED REGION END # // DG_PY_FOFBTool.includeLBP_read
def write_includeLBP(self, value):
# PROTECTED REGION ID(DG_PY_FOFBTool.includeLBP_write) ENABLED START #
"""Set the includeLBP attribute."""
self._include_lbp = value
# PROTECTED REGION END # // DG_PY_FOFBTool.includeLBP_write
def read_FofbToolVersion(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.FofbToolVersion_read) ENABLED START #
"""Return the FofbToolVersion attribute."""
return FofbTool.__version__
# PROTECTED REGION END # // DG_PY_FOFBTool.FofbToolVersion_read
def read_lastSync(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.lastSync_read) ENABLED START #
"""Return the lastSync attribute."""
return self._last_sync
# PROTECTED REGION END # // DG_PY_FOFBTool.lastSync_read
def read_lastStart(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.lastStart_read) ENABLED START #
"""Return the lastStart attribute."""
return self._last_start
# PROTECTED REGION END # // DG_PY_FOFBTool.lastStart_read
def read_logs(self):
# PROTECTED REGION ID(DG_PY_FOFBTool.logs_read) ENABLED START #
"""Return the logs attribute."""
......@@ -404,7 +421,7 @@ class DG_PY_FOFBTool(Device):
self.info_stream("Starting all")
self.d_status["nodes"]="FofbNode: starting"
if self._include_lbp:
if self.includeLBP:
self.debug_stream("Starting comlbp")
for cn in self.tangopath_cellnode:
FofbTool.Operation.start_comlbp(cn)
......@@ -426,6 +443,7 @@ class DG_PY_FOFBTool(Device):
T = threading.Thread(target=target,)
self._last_start = datetime.datetime.now().strftime("%y/%m/%d %H:%M")
self.set_state(tango.DevState.RUNNING)
T.start()
......@@ -462,6 +480,7 @@ class DG_PY_FOFBTool(Device):
self.lock.release()
T = threading.Thread(target=target,)
self._last_sync = datetime.datetime.now().strftime("%y/%m/%d %H:%M")
self.set_state(tango.DevState.RUNNING)
T.start()
......
<?xml version="1.0" encoding="ASCII"?>
<pogoDsl:PogoSystem xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:pogoDsl="http://www.esrf.fr/tango/pogo/PogoDsl">
<classes name="DG_PY_FOFBTool" pogoRevision="9.6">
<description description="" title="" sourcePath="/home/operateur/GrpDiagnostics/RBT/FOFB/FofbTool_dev/DG_PY_FOFBTool" language="PythonHL" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<description description="" title="" sourcePath="/home/operateur/GrpDiagnostics/RBT/FOFB/dg_py_fofbtool" language="PythonHL" filestogenerate="XMI file,Code files,Protected Regions" license="GPL" copyright="" hasMandatoryProperty="true" hasConcreteProperty="true" hasAbstractCommand="false" hasAbstractAttribute="false">
<inheritances classname="Device_Impl" sourcePath=""/>
<identification contact="at synchrotron-soleil.fr - romain.brones" author="romain.brones" emailDomain="synchrotron-soleil.fr" classFamily="SoftwareSystem" siteSpecific="Soleil" platform="Unix Like" bus="Not Applicable" manufacturer="none" reference=""/>
</description>
......@@ -65,6 +65,10 @@
<type xsi:type="pogoDsl:StringType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<deviceProperties name="includeLBP" mandatory="true" description="Do not include LBP in the com.&#xA;This will skip the starting of comlbp during the start command.">
<type xsi:type="pogoDsl:BooleanType"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</deviceProperties>
<commands name="State" description="This command gets the device state (stored in its device_state data member) and returns it to the caller." execMethod="dev_state" displayLevel="OPERATOR" polledPeriod="0">
<argin description="none">
<type xsi:type="pogoDsl:VoidType"/>
......@@ -128,15 +132,23 @@
</argout>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</commands>
<attributes name="includeLBP" attType="Scalar" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:BooleanType"/>
<attributes name="FofbToolVersion" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:StringType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="FofbToolVersion" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<attributes name="lastSync" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:StringType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
<dataReadyEvent fire="false" libCheckCriteria="true"/>
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="" label="" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="lastStart" attType="Scalar" rwType="READ" displayLevel="OPERATOR" polledPeriod="0" maxX="" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:StringType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment