diff --git a/ARE/components/processor.averager/src/main/java/eu/asterics/component/processor/averager/AveragerInstance.java b/ARE/components/processor.averager/src/main/java/eu/asterics/component/processor/averager/AveragerInstance.java index 180c7bfee..19d60adc9 100644 --- a/ARE/components/processor.averager/src/main/java/eu/asterics/component/processor/averager/AveragerInstance.java +++ b/ARE/components/processor.averager/src/main/java/eu/asterics/component/processor/averager/AveragerInstance.java @@ -28,12 +28,10 @@ import java.util.LinkedList; +import eu.asterics.mw.model.runtime.*; import org.apache.commons.math3.stat.StatUtils; import eu.asterics.mw.data.ConversionUtils; -import eu.asterics.mw.model.runtime.AbstractRuntimeComponentInstance; -import eu.asterics.mw.model.runtime.IRuntimeInputPort; -import eu.asterics.mw.model.runtime.IRuntimeOutputPort; import eu.asterics.mw.model.runtime.impl.DefaultRuntimeInputPort; import eu.asterics.mw.model.runtime.impl.DefaultRuntimeOutputPort; @@ -57,13 +55,15 @@ public class AveragerInstance extends AbstractRuntimeComponentInstance { private IRuntimeOutputPort opOutput = new OutputPort1(); private int propBufferSize = DEFAULT_BUFFER_SIZE; + private boolean propEnabled = true; private int propMode = 0; + private int propAutoReenableTime = 0; private final LinkedList buffer = new LinkedList(); private long lastUpdate = 0; private double accu = 0; - private double sum = 0; + private long disableTime = 0; /** * The class constructor. @@ -104,6 +104,37 @@ public IRuntimeOutputPort getOutputPort(String portID) { } } + /** + * returns an Event Listener Port. + * + * @param eventPortID + * the name of the port + * @return the EventListener port or null if not found + */ + public IRuntimeEventListenerPort getEventListenerPort(String eventPortID) { + if ("enablePlugin".equalsIgnoreCase(eventPortID)) { + return elpEnablePlugin; + } + if ("disablePlugin".equalsIgnoreCase(eventPortID)) { + return elpDisablePlugin; + } + + return null; + } + + private final IRuntimeEventListenerPort elpEnablePlugin = new IRuntimeEventListenerPort() { + public void receiveEvent(final String data) { + propEnabled = true; + } + }; + + private final IRuntimeEventListenerPort elpDisablePlugin = new IRuntimeEventListenerPort() { + public void receiveEvent(final String data) { + propEnabled = false; + disableTime = System.currentTimeMillis(); + } + }; + /** * returns the value of the given property. * @@ -113,10 +144,14 @@ public IRuntimeOutputPort getOutputPort(String portID) { */ @Override public Object getRuntimePropertyValue(String propertyName) { - if ("bufferSize".equalsIgnoreCase(propertyName)) { + if ("enabled".equalsIgnoreCase(propertyName)) { + return propEnabled; + } else if ("bufferSize".equalsIgnoreCase(propertyName)) { return propBufferSize; } else if ("mode".equalsIgnoreCase(propertyName)) { return propMode; + } else if ("autoReenableTime".equalsIgnoreCase(propertyName)) { + return propAutoReenableTime; } else { return null; } @@ -132,7 +167,11 @@ public Object getRuntimePropertyValue(String propertyName) { */ @Override public synchronized Object setRuntimePropertyValue(String propertyName, Object newValue) { - if ("bufferSize".equalsIgnoreCase(propertyName)) { + if ("enabled".equalsIgnoreCase(propertyName)) { + final Object oldValue = propEnabled; + propEnabled = Boolean.parseBoolean((String) newValue); + return oldValue; + } else if ("bufferSize".equalsIgnoreCase(propertyName)) { final Object oldValue = propBufferSize; if (newValue != null) { @@ -165,6 +204,10 @@ public synchronized Object setRuntimePropertyValue(String propertyName, Object n } } return oldValue; + } else if ("autoReenableTime".equalsIgnoreCase(propertyName)) { + final Object oldValue = propAutoReenableTime; + propAutoReenableTime = Integer.parseInt(newValue.toString()); + return oldValue; } else { return null; } @@ -177,6 +220,12 @@ public synchronized Object setRuntimePropertyValue(String propertyName, Object n * samples are summed but not divided */ private synchronized void process(final double in) { + if (!propEnabled) { + if (System.currentTimeMillis() - disableTime < propAutoReenableTime || propAutoReenableTime == 0) { + return; + } + propEnabled = true; + } if (propMode == MODE_AVERAGE) { buffer.addFirst(in); sum += in; diff --git a/ARE/components/processor.averager/src/main/resources/bundle_descriptor.xml b/ARE/components/processor.averager/src/main/resources/bundle_descriptor.xml index 4c401b25d..4bfe73328 100644 --- a/ARE/components/processor.averager/src/main/resources/bundle_descriptor.xml +++ b/ARE/components/processor.averager/src/main/resources/bundle_descriptor.xml @@ -18,7 +18,19 @@ double - + + + enables the functionality of this plugin + + + disables the functionality of this plugin + + + + + diff --git a/Documentation/ACS-Help/HTML/Plugins/processors/Averager.htm b/Documentation/ACS-Help/HTML/Plugins/processors/Averager.htm index 9d249d882..757479c53 100644 --- a/Documentation/ACS-Help/HTML/Plugins/processors/Averager.htm +++ b/Documentation/ACS-Help/HTML/Plugins/processors/Averager.htm @@ -20,8 +20,18 @@

Output Port Description

  • output [double]: This port provides the current average of the buffered inputs.
+

Event Listener Description

+
    +
  • enablePlugin: Enables the functionality of this plugin.
  • +
  • + disablePlugin: Disables the functionality of this plugin. New values aren't accumulated anymore and no output is sent to the output port. + If property autoReenableTime set, the plugin is automatically re-enabled after the time defined by this property. + Generally disabling is delayed until the buffer of values is full, preventing any startup glitches. +
  • +

Properties

    +
  • enabled [boolean]: if true (default), the plugin is enabled, if false the plugin does nothing. Generally disabling is delayed until the buffer of values is full, preventing any startup glitches.
  • mode [integer]: Denotes the operating mode of the unit, three modes are available:
      @@ -31,6 +41,7 @@

      Properties

  • bufferSize [integer]: Specifies the size of the buffer in the averaging modes or the amount of milliseconds to accumulate in the accumulator mode.
  • +
  • autoReenableTime [integer]: Time in ms, after the plugin automatically re-enables itself after being disabled. Set to zero (default) to deactivate this functionality (never auto re-enable).
diff --git a/Documentation/ACS-Help/HTML/Plugins/processors/img/Averager.jpg b/Documentation/ACS-Help/HTML/Plugins/processors/img/Averager.jpg index 3b2ac658b..67fa74a48 100644 Binary files a/Documentation/ACS-Help/HTML/Plugins/processors/img/Averager.jpg and b/Documentation/ACS-Help/HTML/Plugins/processors/img/Averager.jpg differ