Cleaned up code
Removed lots of duplicated code, merged classes, etc.
This commit is contained in:
@@ -75,9 +75,7 @@ import ch.psi.fda.core.scripting.JythonParameterMapping;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingChannel;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingGlobalVariable;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingID;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessStringSensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessSensor;
|
||||
import ch.psi.fda.core.sensors.MillisecondTimestampSensor;
|
||||
import ch.psi.fda.core.sensors.OTFNamedChannelSensor;
|
||||
import ch.psi.fda.core.sensors.OTFReadbackSensor;
|
||||
@@ -722,7 +720,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = lp.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(lp.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if(p instanceof FunctionPositioner){
|
||||
@@ -755,7 +753,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = lp.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(lp.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(lp.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (p instanceof ArrayPositioner){
|
||||
@@ -788,7 +786,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = ap.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(ap.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(ap.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (p instanceof RegionPositioner){
|
||||
@@ -875,7 +873,7 @@ public class Acquisition {
|
||||
if(name==null){
|
||||
name = rp.getName();
|
||||
}
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor(rp.getId(), createChannel(Double.class, name));
|
||||
ChannelAccessSensor<Double> sensor = new ChannelAccessSensor<Double>(rp.getId(), createChannel(Double.class, name));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if(p instanceof PseudoPositioner){
|
||||
@@ -970,10 +968,10 @@ public class Acquisition {
|
||||
// Add sensor
|
||||
Sensor sensor;
|
||||
if(sd.getType().equals("String")){
|
||||
sensor = new ChannelAccessStringSensor(sd.getId(), createChannel(String.class,sd.getName()));
|
||||
sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(String.class,sd.getName()));
|
||||
}
|
||||
else{
|
||||
sensor = new ChannelAccessDoubleSensor(sd.getId(), createChannel(Double.class,sd.getName()));
|
||||
sensor = new ChannelAccessSensor<>(sd.getId(), createChannel(Double.class,sd.getName()));
|
||||
}
|
||||
|
||||
aLoop.getSensors().add(sensor);
|
||||
@@ -985,7 +983,7 @@ public class Acquisition {
|
||||
aLoop.getPreSensorActions().addAll(mapActions(ad.getPreAction()));
|
||||
|
||||
// Ad sensor
|
||||
ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor(ad.getId(), createChannel(double[].class, ad.getName(), ad.getArraySize()));
|
||||
Sensor sensor = new ChannelAccessSensor<>(ad.getId(), createChannel(double[].class, ad.getName(), ad.getArraySize()));
|
||||
aLoop.getSensors().add(sensor);
|
||||
}
|
||||
else if (detector instanceof DetectorOfDetectors){
|
||||
|
||||
@@ -41,7 +41,6 @@ import ch.psi.fda.core.messages.Message;
|
||||
*/
|
||||
public class Collector implements Runnable{
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(Collector.class.getName());
|
||||
|
||||
/**
|
||||
@@ -56,17 +55,11 @@ public class Collector implements Runnable{
|
||||
*/
|
||||
private EventBus bus;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Collector(EventBus b){
|
||||
queues = new ArrayList<DataQueue>();
|
||||
this.bus = b;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
@@ -78,9 +71,6 @@ public class Collector implements Runnable{
|
||||
// Readout aborted through interrupt
|
||||
}
|
||||
}
|
||||
else{
|
||||
// No queue registered for reading
|
||||
}
|
||||
|
||||
bus.post(new EndOfStreamMessage());
|
||||
|
||||
@@ -126,9 +116,6 @@ public class Collector implements Runnable{
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the queues
|
||||
*/
|
||||
public List<DataQueue> getQueues() {
|
||||
return queues;
|
||||
}
|
||||
|
||||
@@ -41,13 +41,4 @@ public interface Guard {
|
||||
* @return Returns true if the guard condition was not constrainted since the last init call. False otherwise.
|
||||
*/
|
||||
public boolean check();
|
||||
|
||||
/**
|
||||
* Destroy guard.
|
||||
* Can be used for the cleanup of used resources of the guard (e.g. to close connections, ...) if
|
||||
* this cannot be done automatically by the GarbageCollector.
|
||||
*
|
||||
* After calling this method the guard must not be used any more!
|
||||
*/
|
||||
public void destroy();
|
||||
}
|
||||
|
||||
@@ -38,13 +38,4 @@ public interface Sensor {
|
||||
* @return id of sensor
|
||||
*/
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* Destroy sensor.
|
||||
* Can be used for the cleanup of used resources of the sensor (e.g. to close connections, ...) if
|
||||
* this cannot be done automatically by the GarbageCollector.
|
||||
*
|
||||
* After calling this method the sensor must not be used any more!
|
||||
*/
|
||||
public void destroy();
|
||||
}
|
||||
|
||||
@@ -44,19 +44,14 @@ public class ChannelAccessGuard implements Guard {
|
||||
* Flag to indicate whether a guard condition failed since the last init call
|
||||
* true: all conditions met, false: at least one condition failed
|
||||
*/
|
||||
private boolean check = true;
|
||||
private volatile boolean check = true;
|
||||
|
||||
private final List<ChannelAccessGuardCondition<?>> conditions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param conditions
|
||||
*/
|
||||
public ChannelAccessGuard(List<ChannelAccessGuardCondition<?>> conditions){
|
||||
|
||||
this.conditions = conditions;
|
||||
|
||||
// Create channel that contribute to the status of the guard
|
||||
for(final ChannelAccessGuardCondition<?> condition: conditions){
|
||||
condition.getChannel().addPropertyChangeListener(new PropertyChangeListener() {
|
||||
@Override
|
||||
@@ -95,9 +90,4 @@ public class ChannelAccessGuard implements Guard {
|
||||
public boolean check() {
|
||||
return check;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -452,16 +452,6 @@ public class ActorSensorLoop implements ActionLoop {
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
for(Sensor s: sensors){
|
||||
logger.finest("Destroy sensor");
|
||||
s.destroy();
|
||||
}
|
||||
|
||||
if(guard != null){
|
||||
logger.finest("Destroy guard");
|
||||
guard.destroy();
|
||||
}
|
||||
|
||||
// Recursively call cleanup() method of all registered action loops
|
||||
for(ActionLoop actionLoop: actionLoops){
|
||||
logger.finest("Destroy action loop");
|
||||
@@ -469,18 +459,11 @@ public class ActorSensorLoop implements ActionLoop {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#getPreActions()
|
||||
*/
|
||||
@Override
|
||||
public List<Action> getPreActions() {
|
||||
return preActions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#getPostActions()
|
||||
*/
|
||||
@Override
|
||||
public List<Action> getPostActions() {
|
||||
return postActions;
|
||||
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Scalar sensor that reads a double form a Channel Access channel
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessDoubleArraySensor implements Sensor {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleArraySensor.class.getName());
|
||||
|
||||
private final Channel<double[]> channel;
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* @param id Global id of the sensor
|
||||
* @param channel
|
||||
*/
|
||||
public ChannelAccessDoubleArraySensor(String id, Channel<double[]> channel){
|
||||
this.channel = channel;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
logger.finest("Read sensor "+channel.getName());
|
||||
|
||||
double[] v;
|
||||
try {
|
||||
v = channel.getValue();
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
// Only fail during data acquisition if fail on error sensor flag is on true. Otherwise
|
||||
// return null
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
v = null;
|
||||
}
|
||||
return(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
+8
-23
@@ -29,39 +29,32 @@ import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Scalar sensor that reads a double form a Channel Access channel
|
||||
* @author ebner
|
||||
*
|
||||
* Channel Access sensor capable of reading a channel access channel
|
||||
*/
|
||||
public class ChannelAccessDoubleSensor implements Sensor {
|
||||
public class ChannelAccessSensor<T> implements Sensor {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleSensor.class.getName());
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessSensor.class.getName());
|
||||
|
||||
private Channel<Double> channel;
|
||||
private Channel<T> channel;
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Global id of the sensor
|
||||
* @param channel
|
||||
*/
|
||||
public ChannelAccessDoubleSensor(String id, Channel<Double> channel){
|
||||
this.channel = channel;
|
||||
public ChannelAccessSensor(String id, Channel<T> channel){
|
||||
this.id = id;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
logger.finest("Read sensor "+channel.getName());
|
||||
|
||||
Double v;
|
||||
T v;
|
||||
try {
|
||||
v = channel.getValue();
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
v = Double.NaN;
|
||||
v = null;
|
||||
}
|
||||
return(v);
|
||||
}
|
||||
@@ -70,12 +63,4 @@ public class ChannelAccessDoubleSensor implements Sensor {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
public Channel<Double> getChannel(){
|
||||
return channel;
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Scalar sensor that reads a double form a Channel Access channel
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessStringSensor implements Sensor {
|
||||
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessStringSensor.class.getName());
|
||||
|
||||
private Channel<String> channel;
|
||||
private final String id; // Global id of the sensor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Global id of the sensor
|
||||
* @param channelName Name of the Channel Access channel of this sensor
|
||||
*/
|
||||
public ChannelAccessStringSensor(String id, Channel<String> channel){
|
||||
this.id = id;
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
logger.finest("Read sensor "+channel.getName());
|
||||
|
||||
String v;
|
||||
try {
|
||||
v = channel.getValue();
|
||||
} catch (TimeoutException | ChannelException | ExecutionException e) {
|
||||
if(EngineConfiguration.getInstance().isFailOnSensorError()){
|
||||
throw new RuntimeException("Unable to get value from channel [name:"+channel.getName()+"]",e);
|
||||
}
|
||||
v = null;
|
||||
}
|
||||
return(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
|
||||
/**
|
||||
* Complex sensor that complements an other sensor with pre and post actions.
|
||||
* Before reading out the complemented sensor the pre actions are executed. After the
|
||||
* readout the post actions.
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ComplexSensor implements Sensor {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ComplexSensor.class.getName());
|
||||
|
||||
/**
|
||||
* Id of the sensor
|
||||
*/
|
||||
private String id;
|
||||
|
||||
/**
|
||||
* Sensor to complement
|
||||
*/
|
||||
private final Sensor sensor;
|
||||
|
||||
/**
|
||||
* Actions that are executed directly before the first step of this actor
|
||||
*/
|
||||
private final List<Action> preActions;
|
||||
|
||||
/**
|
||||
* Actions that are executed directly after the last step of this actor
|
||||
*/
|
||||
private final List<Action> postActions;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ComplexSensor(String id, Sensor sensor){
|
||||
this.id = id;
|
||||
|
||||
this.sensor = sensor;
|
||||
this.preActions = new ArrayList<Action>();
|
||||
this.postActions = new ArrayList<Action>();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#read()
|
||||
*/
|
||||
@Override
|
||||
public Object read() throws InterruptedException {
|
||||
// Execute pre actions
|
||||
logger.finest("Execute pre actions");
|
||||
for(Action action: preActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
// Readout sensor
|
||||
Object value = sensor.read();
|
||||
|
||||
// Execute post actions
|
||||
logger.finest("Execute post actions");
|
||||
for(Action action: postActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy preActions
|
||||
for(Action a: preActions){
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
sensor.destroy();
|
||||
|
||||
// Destroy postActions
|
||||
for(Action a: postActions){
|
||||
a.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the preActions
|
||||
*/
|
||||
public List<Action> getPreActions() {
|
||||
return preActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the postActions
|
||||
*/
|
||||
public List<Action> getPostActions() {
|
||||
return postActions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -23,47 +23,24 @@ import ch.psi.fda.core.Sensor;
|
||||
|
||||
/**
|
||||
* Get the current time in milliseconds
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class MillisecondTimestampSensor implements Sensor {
|
||||
|
||||
/**
|
||||
* Global id of the sensor
|
||||
*/
|
||||
private final String id;
|
||||
private final String id; // Global id of the sensor
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Global id of the sensor
|
||||
*/
|
||||
public MillisecondTimestampSensor(String id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#read()
|
||||
*/
|
||||
@Override
|
||||
public Object read() {
|
||||
// Return current time in milliseconds
|
||||
return new Double(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,9 +49,6 @@ public class OTFNamedChannelSensor implements Sensor {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#read()
|
||||
*/
|
||||
@Override
|
||||
public Object read() {
|
||||
// Always return 0 if read() method is called.
|
||||
@@ -65,20 +62,8 @@ public class OTFNamedChannelSensor implements Sensor {
|
||||
return name;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -29,42 +29,20 @@ import ch.psi.fda.core.Sensor;
|
||||
*/
|
||||
public class OTFReadbackSensor implements Sensor {
|
||||
|
||||
/**
|
||||
* Global id of the sensor
|
||||
*/
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id Global id of the sensor
|
||||
*/
|
||||
public OTFReadbackSensor(String id){
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#read()
|
||||
*/
|
||||
@Override
|
||||
public Object read() {
|
||||
// Always return 0 if read() method is called.
|
||||
return 0d;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -24,7 +24,6 @@ import ch.psi.fda.core.Sensor;
|
||||
/**
|
||||
* Sensor to read out a scaler channel. This sensor can only be used within the
|
||||
* OTFLoop. If it is used in other loops, the read value will always be 0.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class OTFScalerChannelSensor implements Sensor {
|
||||
@@ -49,12 +48,8 @@ public class OTFScalerChannelSensor implements Sensor {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#read()
|
||||
*/
|
||||
@Override
|
||||
public Object read() {
|
||||
// Always return 0 if read() method is called.
|
||||
return 0d;
|
||||
}
|
||||
|
||||
@@ -65,20 +60,8 @@ public class OTFScalerChannelSensor implements Sensor {
|
||||
return index;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -40,8 +40,6 @@ import ch.psi.fda.model.v1.Configuration;
|
||||
|
||||
/**
|
||||
* Manage the serialization and deserialization of the FDA data model
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ModelManager {
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ import ch.psi.fda.model.v1.Recipient;
|
||||
|
||||
/**
|
||||
* Agent to send out notifications to specified recipients.
|
||||
* @author ebner
|
||||
*/
|
||||
public class NotificationAgent {
|
||||
|
||||
@@ -54,7 +53,6 @@ public class NotificationAgent {
|
||||
fromAddress = from;
|
||||
|
||||
properties = new Properties();
|
||||
// Setup mail server
|
||||
properties.put("mail.smtp.host", host);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.junit.Test;
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.Guard;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.fda.core.actions.Delay;
|
||||
import ch.psi.fda.core.actors.ChannelAccessLinearActuator;
|
||||
import ch.psi.fda.core.guard.ChannelAccessGuard;
|
||||
@@ -45,9 +46,7 @@ import ch.psi.fda.core.loops.ActorSensorLoop;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessStringSensor;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessSensor;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
@@ -79,10 +78,10 @@ public class ActorSensorLoopTest {
|
||||
loopOne = new ActorSensorLoop();
|
||||
|
||||
ChannelAccessLinearActuator<Integer> a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, 10, 0.1, timeout); // Positioner
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); // Positioner Readback
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); // Scalar Detector
|
||||
ChannelAccessStringSensor s1string = new ChannelAccessStringSensor("id3", cservice.createChannel(new ChannelDescriptor<>(String.class, boChannel+".NAME"))); // Scalar String Detector
|
||||
ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class, wfChannel,false, 10)));
|
||||
Sensor s = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel))); // Positioner Readback
|
||||
Sensor s1 = new ChannelAccessSensor<>("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel))); // Scalar Detector
|
||||
Sensor s1string = new ChannelAccessSensor<>("id3", cservice.createChannel(new ChannelDescriptor<>(String.class, boChannel+".NAME"))); // Scalar String Detector
|
||||
Sensor s2 = new ChannelAccessSensor<>("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class, wfChannel,false, 10)));
|
||||
|
||||
loopOne.getActors().add(a);
|
||||
loopOne.getSensors().add(s);
|
||||
@@ -144,8 +143,8 @@ public class ActorSensorLoopTest {
|
||||
ActorSensorLoop loop = new ActorSensorLoop();
|
||||
|
||||
int numberOfSensors = 2;
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel)));
|
||||
ChannelAccessDoubleSensor s2 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
Sensor s1 = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel)));
|
||||
Sensor s2 = new ChannelAccessSensor<>("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
loop.getSensors().add(s1);
|
||||
loop.getSensors().add(s2);
|
||||
|
||||
@@ -183,9 +182,9 @@ public class ActorSensorLoopTest {
|
||||
|
||||
ChannelAccessLinearActuator<Integer> a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, 1.5, 0.1,timeout); // Positioner
|
||||
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel)));
|
||||
ChannelAccessDoubleArraySensor s2 = new ChannelAccessDoubleArraySensor("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class,wfChannel, false,10)));
|
||||
Sensor s = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
Sensor s1 = new ChannelAccessSensor<>("id1", cservice.createChannel(new ChannelDescriptor<>(Double.class, boChannel)));
|
||||
Sensor s2 = new ChannelAccessSensor<>("id2", cservice.createChannel(new ChannelDescriptor<>(double[].class,wfChannel, false,10)));
|
||||
|
||||
loop.getActors().add(a);
|
||||
loop.getPostActorActions().add(new Delay(500));
|
||||
@@ -270,7 +269,7 @@ public class ActorSensorLoopTest {
|
||||
|
||||
ChannelAccessLinearActuator<Integer> a = new ChannelAccessLinearActuator<>(cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)), null, 1,0, 0, (steps*0.1), 0.1, timeout); // Positioner
|
||||
|
||||
ChannelAccessDoubleSensor s = new ChannelAccessDoubleSensor("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
Sensor s = new ChannelAccessSensor<>("id0", cservice.createChannel(new ChannelDescriptor<>(Double.class, aoChannel)));
|
||||
|
||||
loop.getActors().add(a);
|
||||
loop.getActors().add(new Actor() {
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for the ScalarDoubleSensorChannelAccess class.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessDoubleSensorTest {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleSensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.ANALOG_OUT;
|
||||
private ChannelService cservice;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
Channel<Double> channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
ChannelAccessDoubleSensor sensor = new ChannelAccessDoubleSensor("id0", channel);
|
||||
|
||||
// Prepare sensor channel
|
||||
Double setValue = 0.1d;
|
||||
channel.setValue(setValue);
|
||||
|
||||
// Get sensor readout value
|
||||
Double value = (Double) sensor.read();
|
||||
logger.finest("Sensor value: "+value);
|
||||
if(!value.equals(setValue)){
|
||||
fail("Sensor readout value does not match actual value");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+46
-9
@@ -20,19 +20,18 @@
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleArraySensor;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
@@ -44,12 +43,10 @@ import ch.psi.jcae.impl.DefaultChannelService;
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessDoubleArraySensorTest {
|
||||
public class ChannelAccessSensorTest {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessDoubleArraySensorTest.class.getName());
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessSensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.DOUBLE_WAVEFORM;
|
||||
private static final int numberOfPoints = 10;
|
||||
private ChannelService cservice;
|
||||
|
||||
@Before
|
||||
@@ -63,9 +60,49 @@ public class ChannelAccessDoubleArraySensorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
public void testReadDouble() throws InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
final String channelName = TestChannels.ANALOG_OUT;
|
||||
|
||||
Channel<Double> channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
Sensor sensor = new ChannelAccessSensor<>("id0", channel);
|
||||
|
||||
// Prepare sensor channel
|
||||
Double setValue = 0.1d;
|
||||
channel.setValue(setValue);
|
||||
|
||||
// Get sensor readout value
|
||||
Double value = (Double) sensor.read();
|
||||
logger.finest("Sensor value: "+value);
|
||||
if(!value.equals(setValue)){
|
||||
fail("Sensor readout value does not match actual value");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReadString() throws CAException, InterruptedException, ChannelException, TimeoutException {
|
||||
final String channelName = TestChannels.ANALOG_OUT+".NAME";
|
||||
final String actualValue = TestChannels.ANALOG_OUT;
|
||||
|
||||
Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, channelName));
|
||||
Sensor sensor = new ChannelAccessSensor<>("id0", channel);
|
||||
|
||||
// Get sensor readout value
|
||||
String value = (String) sensor.read();
|
||||
logger.info("Sensor value: "+value);
|
||||
if(!value.equals(actualValue)){
|
||||
fail("Sensor readout "+value+" value does not match actual value "+actualValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReadDoubleArray() throws CAException, InterruptedException, ChannelException, TimeoutException, ExecutionException {
|
||||
|
||||
final String channelName = TestChannels.DOUBLE_WAVEFORM;
|
||||
final int numberOfPoints = 10;
|
||||
|
||||
Channel<double[]> channel = cservice.createChannel(new ChannelDescriptor<>(double[].class, channelName, false, numberOfPoints));
|
||||
ChannelAccessDoubleArraySensor sensor = new ChannelAccessDoubleArraySensor("id0", channel);
|
||||
Sensor sensor = new ChannelAccessSensor<>("id0", channel);
|
||||
|
||||
// Prepare sensor channel
|
||||
double[] setValue = new double[] { 0.1,0.2,0.3,4,5,6,77,88,99,10.2};
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for the ScalarDoubleSensorChannelAccess class.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessStringSensorTest {
|
||||
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessStringSensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.ANALOG_OUT+".NAME";
|
||||
private static final String actualValue = TestChannels.ANALOG_OUT;
|
||||
|
||||
private ChannelService cservice;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRead() throws CAException, InterruptedException, ChannelException, TimeoutException {
|
||||
Channel<String> channel = cservice.createChannel(new ChannelDescriptor<>(String.class, channelName));
|
||||
ChannelAccessStringSensor sensor = new ChannelAccessStringSensor("id0", channel);
|
||||
|
||||
// Get sensor readout value
|
||||
String value = (String) sensor.read();
|
||||
logger.info("Sensor value: "+value);
|
||||
if(!value.equals(actualValue)){
|
||||
fail("Sensor readout "+value+" value does not match actual value "+actualValue);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,135 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2010 Paul Scherrer Institute. All rights reserved.
|
||||
*
|
||||
* This code is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful,
|
||||
* but without any warranty; without even the implied warranty of
|
||||
* merchantability or fitness for a particular purpose. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with this code. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package ch.psi.fda.core.sensors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import gov.aps.jca.CAException;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import ch.psi.fda.TestChannels;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.sensors.ChannelAccessDoubleSensor;
|
||||
import ch.psi.fda.core.sensors.ComplexSensor;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
/**
|
||||
* Test class for the ScalarDoubleSensorChannelAccess class.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ComplexSensorTest {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ComplexSensorTest.class.getName());
|
||||
|
||||
private static final String channelName = TestChannels.ANALOG_OUT;
|
||||
private ChannelService cservice;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
cservice = new DefaultChannelService();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
cservice.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link ch.psi.fda.core.sensors.ChannelAccessDoubleSensor#read()}.
|
||||
* @throws CAException
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException
|
||||
*/
|
||||
@Test
|
||||
public void testRead() throws CAException, InterruptedException, ExecutionException, ChannelException, TimeoutException {
|
||||
|
||||
final HashMap<String, Long> timestamps = new HashMap<String,Long>();
|
||||
Channel<Double> channel = cservice.createChannel(new ChannelDescriptor<>(Double.class, channelName));
|
||||
ChannelAccessDoubleSensor s1 = new ChannelAccessDoubleSensor("id0", channel);
|
||||
ComplexSensor sensor = new ComplexSensor("id2", s1);
|
||||
|
||||
// Add pre action
|
||||
sensor.getPreActions().add(new Action() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
logger.info("PreAction");
|
||||
timestamps.put("pre", System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort() {
|
||||
}
|
||||
});
|
||||
|
||||
// Add post action
|
||||
sensor.getPostActions().add(new Action() {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
logger.info("PostAction");
|
||||
timestamps.put("post", System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void abort() {
|
||||
}
|
||||
});
|
||||
|
||||
// Prepare sensor channel
|
||||
Double setValue = 0.1d;
|
||||
channel.setValue(setValue);
|
||||
|
||||
// Get sensor readout value
|
||||
Double value = (Double) sensor.read();
|
||||
|
||||
logger.finest("Sensor value: "+value);
|
||||
if(!value.equals(setValue)){
|
||||
fail("Sensor readout value does not match actual value");
|
||||
}
|
||||
|
||||
if(timestamps.get("post")<timestamps.get("pre")){
|
||||
fail("Post got executed before pre");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user