Skip to content
Snippets Groups Projects
Commit 6453ab46 authored by Pascal Verdier's avatar Pascal Verdier
Browse files

Manage disable/enable attribute

parent ed3e2b99
No related branches found
No related merge requests found
......@@ -18,6 +18,10 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<DefaultPropValue>0</DefaultPropValue>
</deviceProperties>
<deviceProperties name="DisableAttributes" description="disable attribute list">
<type xsi:type="pogoDsl:StringVectorType"/>
<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="1000" isDynamic="false">
<argin description="none">
<type xsi:type="pogoDsl:VoidType"/>
......@@ -36,7 +40,7 @@
</argout>
<status abstract="true" inherited="true" concrete="true" concreteHere="false"/>
</commands>
<attributes name="CheckedAttributes" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="1000" maxX="128" maxY="" allocReadMember="true" isDynamic="false">
<attributes name="CheckedAttributes" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="1000" maxX="256" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:StringType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
......@@ -44,7 +48,7 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Checked Attributes list" label="Checked Attributes" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="CheckedAttributeStates" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="1000" maxX="128" maxY="" allocReadMember="true" isDynamic="false">
<attributes name="CheckedAttributeStates" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="1000" maxX="256" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:StateType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
......@@ -52,7 +56,7 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Checked Attribute states list" label="Checked Attribute states" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="CheckedAttributeStatus" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="1000" maxX="128" maxY="" allocReadMember="true" isDynamic="false">
<attributes name="CheckedAttributeStatus" attType="Spectrum" rwType="READ" displayLevel="OPERATOR" polledPeriod="1000" maxX="256" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:StringType"/>
<changeEvent fire="false" libCheckCriteria="false"/>
<archiveEvent fire="false" libCheckCriteria="false"/>
......@@ -60,6 +64,14 @@
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
<properties description="Checked Attribute states list" label="Checked Attribute states" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<attributes name="CheckedAttributeDisable" attType="Spectrum" rwType="READ_WRITE" displayLevel="OPERATOR" polledPeriod="1000" maxX="256" maxY="" allocReadMember="true" isDynamic="false">
<dataType xsi:type="pogoDsl:BooleanType"/>
<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="Disable Attribute list" label="Disable Attributes" unit="" standardUnit="" displayUnit="" format="" maxValue="" minValue="" maxAlarm="" minAlarm="" maxWarning="" minWarning="" deltaTime="" deltaValue=""/>
</attributes>
<states name="ON" description="All attributes are OK">
<status abstract="false" inherited="false" concrete="true" concreteHere="true"/>
</states>
......
......@@ -51,8 +51,10 @@ public class HdbAttribute {
private String[] contexts;
private DevState state = DevState.UNKNOWN;
private String errorMessage = "";
private final Object monitor = new Object();
private boolean registered =true;
private boolean disable = false;
private final Object monitor = new Object();
private static final String ATTRIBUTE_HEADER = "tango://";
//===============================================================
/**
......@@ -67,20 +69,21 @@ public class HdbAttribute {
this.archivePeriod = archivePeriod;
this.contexts = contexts;
if (contexts==null) {
registered = false;
setState(DevState.FAULT);
setErrorMessage(fullName + " is not registered");
setErrorMessage("Is not registered");
}
else {
// If not set for HdbAttributeCheck device, get attribute property
if (archivePeriod <= 0) {
archivePeriod = readArchivePeriod();
this.archivePeriod = readArchivePeriod();
}
// Is property found ?
if (archivePeriod <= 0) {
if (this.archivePeriod <= 0) {
setState(DevState.FAULT);
setErrorMessage("No archive period set");
}
System.out.println(fullName + ": " + archivePeriod + " ms");
System.out.println(fullName + ": " + this.archivePeriod + " ms");
}
}
//===============================================================
......@@ -152,6 +155,35 @@ public class HdbAttribute {
}
//===============================================================
//===============================================================
public boolean isRegistered() {
return registered;
}
//===============================================================
//===============================================================
public void setHdbRead(boolean ok) {
if (ok) {
setErrorMessage("");
setState(DevState.ON);
} else {
// Check if already in fault to do not overwrite error message
if (errorMessage.isEmpty()) {
setErrorMessage("Data missing in HDB");
setState(DevState.FAULT);
}
}
}
//===============================================================
//===============================================================
public boolean isDisable() {
return disable;
}
//===============================================================
//===============================================================
public void setDisable(boolean disable) {
this.disable = disable;
}
//===============================================================
//===============================================================
@Override
public String toString() {
return fullName + ": " + ApiUtil.stateName(getState()) +
......
......@@ -44,6 +44,8 @@ package org.tango.hdbattributecheck;
/*----- PROTECTED REGION ID(HdbAttributeCheck.imports) ENABLED START -----*/
import fr.esrf.Tango.DevFailed;
import fr.esrf.Tango.DevState;
import fr.esrf.TangoApi.DbDatum;
import fr.esrf.TangoApi.DeviceProxy;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.ext.XLogger;
......@@ -54,6 +56,9 @@ import org.tango.server.annotation.*;
import org.tango.server.device.DeviceManager;
import org.tango.server.dynamic.DynamicManager;
import java.util.ArrayList;
import java.util.List;
// Import Tango IDL types
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.imports
......@@ -148,6 +153,25 @@ public class HdbAttributeCheck {
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.setArchivePeriod
}
/**
* Device Property DisableAttributes
* disable attribute list
*/
@DeviceProperty(name="DisableAttributes", description="disable attribute list" )
private String[] disableAttributes;
/**
* set property DisableAttributes
* @param disableAttributes see description above.
*/
public void setDisableAttributes(String[] disableAttributes) {
this.disableAttributes = disableAttributes;
/*----- PROTECTED REGION ID(HdbAttributeCheck.setDisableAttributes) ENABLED START -----*/
// Check property value here
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.setDisableAttributes
}
//========================================================
......@@ -165,15 +189,21 @@ public class HdbAttributeCheck {
/*----- PROTECTED REGION ID(HdbAttributeCheck.initDevice) ENABLED START -----*/
// ToDo initialization code here
/*
System.out.println("Attribute checked every " + hdbCheckPeriod + " ms");
checkedAttributeDisable = new boolean[attributeList.length];
int i=0;
for (String attributeName : attributeList) {
System.out.println(attributeName);
boolean found = false;
for (String disableAttribute : disableAttributes) {
if (attributeName.equals(disableAttribute)) {
found = true;
break;
}
}
checkedAttributeDisable[i++] = found;
}
*/
attributeManager = new HdbAttributeManager(attributeList, checkPeriod, archivePeriod);
setState(DevState.INIT);
attributeManager.setDisable(checkedAttributeDisable);
setState(DevState.INIT);
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.initDevice
xlogger.exit();
......@@ -250,7 +280,7 @@ public class HdbAttributeCheck {
*/
@Attribute(name="CheckedAttributes", isPolled=true, pollingPeriod=1000)
@AttributeProperties(description="Checked Attributes list", label="Checked Attributes")
private String[] checkedAttributes = new String[128];
private String[] checkedAttributes = new String[256];
/**
* Read attribute CheckedAttributes
*
......@@ -278,7 +308,7 @@ public class HdbAttributeCheck {
*/
@Attribute(name="CheckedAttributeStates", isPolled=true, pollingPeriod=1000)
@AttributeProperties(description="Checked Attribute states list", label="Checked Attribute states")
private DevState[] checkedAttributeStates = new DevState[128];
private DevState[] checkedAttributeStates = new DevState[256];
/**
* Read attribute CheckedAttributeStates
*
......@@ -306,7 +336,7 @@ public class HdbAttributeCheck {
*/
@Attribute(name="CheckedAttributeStatus", isPolled=true, pollingPeriod=1000)
@AttributeProperties(description="Checked Attribute states list", label="Checked Attribute states")
private String[] checkedAttributeStatus = new String[128];
private String[] checkedAttributeStatus = new String[256];
/**
* Read attribute CheckedAttributeStatus
*
......@@ -327,6 +357,59 @@ public class HdbAttributeCheck {
return attributeValue;
}
/**
* Attribute CheckedAttributeDisable, boolean, Spectrum, READ_WRITE
* description:
* Disable Attribute list
*/
@Attribute(name="CheckedAttributeDisable", isPolled=true, pollingPeriod=1000)
@AttributeProperties(description="Disable Attribute list", label="Disable Attributes")
private boolean[] checkedAttributeDisable = new boolean[256];
/**
* Read attribute CheckedAttributeDisable
*
* @return attribute value
* @throws DevFailed if read attribute failed.
*/
public org.tango.server.attribute.AttributeValue isCheckedAttributeDisable() throws DevFailed {
xlogger.entry();
org.tango.server.attribute.AttributeValue
attributeValue = new org.tango.server.attribute.AttributeValue();
/*----- PROTECTED REGION ID(HdbAttributeCheck.getCheckedAttributeDisable) ENABLED START -----*/
// Put read attribute code here
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.getCheckedAttributeDisable
attributeValue.setValue(checkedAttributeDisable);
xlogger.exit();
return attributeValue;
}
/**
* Write attribute CheckedAttributeDisable
* @param checkedAttributeDisable value to write
* @throws DevFailed if write attribute failed.
*/
public void setCheckedAttributeDisable(boolean[] checkedAttributeDisable) throws DevFailed {
xlogger.entry();
/*----- PROTECTED REGION ID(HdbAttributeCheck.setCheckedAttributeDisable) ENABLED START -----*/
// ToDo write in database as a memorized attribute
List<String> list = new ArrayList<>();
int i=0;
for (String attributeName : checkedAttributes) {
if (checkedAttributeDisable[i++])
list.add(attributeName);
}
DbDatum datum = new DbDatum("DisableAttributes");
datum.insert(list.toArray(new String[0]));
new DeviceProxy(deviceManager.getName()).put_property(datum);
attributeManager.setDisable(checkedAttributeDisable);
this.checkedAttributeDisable = checkedAttributeDisable;
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.setCheckedAttributeDisable
xlogger.exit();
}
//========================================================
......@@ -399,7 +482,7 @@ public class HdbAttributeCheck {
System.out.println(applicationName);
}
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.methods
/*----- PROTECTED REGION END -----*/ // HdbAttributeCheck.methods
......
......@@ -51,7 +51,8 @@ public class HdbAttributeManager extends ArrayList<HdbAttribute> {
private String status = "Not started";
private List<String> statusList = new ArrayList<>();
private List<DevState> stateList = new ArrayList<>();
private HdbSigInfo[] hdbSigInfoArray;
private HdbSigInfo[] hdbSigInfoArray;
private ComputeGlobalThread thread;
private final Object monitor = new Object();
//===============================================================
//===============================================================
......@@ -66,18 +67,20 @@ public class HdbAttributeManager extends ArrayList<HdbAttribute> {
HdbAttribute hdbAttribute = new HdbAttribute(fullName, archivePeriod, contexts);
add(hdbAttribute);
}
buildHdbSigInfoArray(attributeNames);
buildHdbSigInfoArray();
new ComputeGlobalThread(this, checkPeriod).start();
thread = new ComputeGlobalThread(this, checkPeriod);
thread.start();
}
//===============================================================
//===============================================================
private void buildHdbSigInfoArray(String[] attributeNames) throws DevFailed {
hdbSigInfoArray = new HdbSigInfo[attributeNames.length];
int i = 0;
for (String attributeName : attributeNames) {
hdbSigInfoArray[i++] = TangoUtils.getInstance().getHdbSigInfo(attributeName);
private void buildHdbSigInfoArray() throws DevFailed {
List<HdbSigInfo> sigInfoList = new ArrayList<>();
for (HdbAttribute attribute : this) {
if (attribute.isRegistered())
sigInfoList.add(TangoUtils.getInstance().getHdbSigInfo(attribute.getFullName()));
}
hdbSigInfoArray = sigInfoList.toArray(new HdbSigInfo[0]);
}
//===============================================================
//===============================================================
......@@ -107,6 +110,16 @@ public class HdbAttributeManager extends ArrayList<HdbAttribute> {
}
//===============================================================
//===============================================================
public void setDisable(boolean[] disable) {
int i=0;
for (HdbAttribute attribute : this) {
attribute.setDisable(disable[i++]);
}
// awake thread tor recompute state
thread.wakeUp();
}
//===============================================================
//===============================================================
public DevState getState() {
synchronized (monitor) {
return state;
......@@ -165,36 +178,32 @@ public class HdbAttributeManager extends ArrayList<HdbAttribute> {
// ToDo For test !!!
if (System.getenv("TEST")!=null && System.getenv("TEST").equals("true"))
checkPeriod = 15000;
// Build an array with attribute archive period
List<Integer> list = new ArrayList<>();
int maxPeriod = 0;
for (HdbAttribute attribute : manager) {
if (attribute.isRegistered()) {
int period = attribute.getArchivePeriod();
list.add(period);
if (period > maxPeriod) {
maxPeriod = period;
}
}
}
int[] periods = new int[list.size()];
for (int i=0 ; i<list.size() ; i++)
periods[i] = list.get(i);
while (true) {
try {
// Build an array with attribute archive period
// Do it each time, because it could have changed
int[] periods = new int[manager.size()];
int i=0;
int maxPeriod = 0;
for (HdbAttribute attribute : manager) {
int period = attribute.getArchivePeriod();
periods[i++] = period;
if (period>maxPeriod) {
maxPeriod = period;
}
}
// Check all attributes, and dispatch results
long start = System.currentTimeMillis() - (maxPeriod + 5000); // A little bit more
boolean[] checked = TangoUtils.getInstance().checkEventsFromHdb(hdbSigInfoArray, start, periods);
for (i=0 ; i<checked.length && i<manager.size() ; i++) {
HdbAttribute attribute = manager.get(i);
if (checked[i]) {
attribute.setErrorMessage("");
attribute.setState(DevState.ON);
}
else {
// Check if already in fault to do not overwrite error message
if (attribute.getState()==DevState.ON) {
attribute.setErrorMessage("Data missing in HDB");
attribute.setState(DevState.FAULT);
}
int i=0;
for (HdbAttribute attribute : manager) {
// Only registered are read
if (attribute.isRegistered()) {
attribute.setHdbRead(checked[i++]);
}
}
}
......@@ -211,13 +220,19 @@ public class HdbAttributeManager extends ArrayList<HdbAttribute> {
List<DevState> stateList = new ArrayList<>();
StringBuilder sb = new StringBuilder();
for (HdbAttribute attribute : manager) {
if (attribute.getState()==DevState.FAULT) {
state = DevState.FAULT;
sb.append(attribute.getFullName()).append(": ").
append(attribute.getErrorMessage()).append('\n');
if (!attribute.isDisable()) {
if (attribute.getState() == DevState.FAULT) {
state = DevState.FAULT;
sb.append(attribute.getFullName()).append(": ").
append(attribute.getErrorMessage()).append('\n');
}
statusList.add(attribute.getErrorMessage());
stateList.add(attribute.getState());
}
else {
statusList.add("[DISABLE] " + attribute.getErrorMessage());
stateList.add(attribute.getState());
}
statusList.add(attribute.getErrorMessage());
stateList.add(attribute.getState());
}
String status;
if (state==DevState.FAULT)
......@@ -225,10 +240,21 @@ public class HdbAttributeManager extends ArrayList<HdbAttribute> {
else
status = "All attributes OK";
setInformation(status, state, statusList, stateList);
TangoUtils.sleep(checkPeriod);
waitNext(checkPeriod);
}
}
//===========================================================
private synchronized void wakeUp() {
notify();
}
//===========================================================
private synchronized void waitNext(int ms) {
try {
wait(ms);
} catch (InterruptedException e) {
/* */
}
}
//===========================================================
}
//===============================================================
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment