Compare commits
145 Commits
2.x.experi
...
econtainer
| Author | SHA1 | Date | |
|---|---|---|---|
| f2e3bf23e8 | |||
| f39822ec74 | |||
| 5038912472 | |||
| 8ab87b8332 | |||
| 8f698e82ba | |||
| 58e92684ad | |||
| 5a6396cfb7 | |||
| 57ecb121b2 | |||
| 3ce7282214 | |||
| 16d18288b6 | |||
| 76ce595f87 | |||
| 486d11db2b | |||
| fa2416492e | |||
| db097eba8f | |||
| 838f6fd385 | |||
| 1c9eca2a1c | |||
| f30aa6495f | |||
| a15356190d | |||
| 88f4dd2b19 | |||
| 9f4c6c0356 | |||
| 84fb119932 | |||
| 311eae3cbc | |||
| 9529d7f088 | |||
| e597b5cd12 | |||
| 8ab6f7965b | |||
| 4bb984cc1c | |||
| b64f31e778 | |||
| 43a8347924 | |||
| f520ff4337 | |||
| 5995b2ed5c | |||
| e20cab4874 | |||
| 576d7eb048 | |||
| 21f86d7d69 | |||
| aa1681aaf3 | |||
| da182adcd2 | |||
| 8d1bd4e816 | |||
| 07d6b47885 | |||
| 87781b8f06 | |||
| 28bd7c40d8 | |||
| dcd394b586 | |||
| 76c40ccf28 | |||
| 8522d46813 | |||
| 1077ec8ab3 | |||
| da0e0eab79 | |||
| ac54407e34 | |||
| b0d4ef9d8b | |||
| f8ee1bd666 | |||
| 8d37cdbeca | |||
| fbe03b7ade | |||
| d866fa0eda | |||
| 2b0877c65d | |||
| d7f1b15927 | |||
| 35a4949907 | |||
| 30355deacc | |||
| eb0aa9a1b6 | |||
| b447ec12d7 | |||
| ae78b8c7a7 | |||
| c9ff7ccf2c | |||
| c01995675e | |||
| e4885d11e1 | |||
| 407aff2e24 | |||
| 9d6ae89f13 | |||
| fafea6dc69 | |||
| 3e841c7596 | |||
| 542379545b | |||
| 4d0f329e72 | |||
| 488fa5c908 | |||
| d550e59254 | |||
| 685ac0cd2d | |||
| 9476f9b57c | |||
| 8888172ede | |||
| e324987c8e | |||
| 76e9ea1bed | |||
| 244001fd99 | |||
| 55faaa2aa3 | |||
| ab0d1654c1 | |||
| 726cf9c0ff | |||
| 03c7d84b05 | |||
| 54fb16a0e9 | |||
| f96b85f6d0 | |||
| 696893ba16 | |||
| d84ce43676 | |||
| e625185b6d | |||
| a40573d320 | |||
| 70089581c4 | |||
| 08cbd0bad0 | |||
| f4d5102ea3 | |||
| e483f90837 | |||
| 795b269bd0 | |||
| 3cb7458e64 | |||
| 51d7b36219 | |||
| 67e7f9a6c8 | |||
| 491812ddeb | |||
| 40cc7f6a31 | |||
| 9386f42d06 | |||
| 855535134e | |||
| e2921ff1f4 | |||
| 36cd4335ab | |||
| d92534ec37 | |||
| ca871ad478 | |||
| b65764ac57 | |||
| 63e681c3bb | |||
| 48cda75405 | |||
| 4b615d29a6 | |||
| d8f1e2d8f1 | |||
| 768ea9f254 | |||
| 2cba6e7991 | |||
| cb6ec74859 | |||
| 36f717c8bf | |||
| 716eeba98b | |||
| c1c8170f36 | |||
| c8031db1fd | |||
| a2d9216e84 | |||
| 57eca36d27 | |||
| 809caa3ed1 | |||
| 3532f95acb | |||
| 5d2c2b94d6 | |||
| 2520573d12 | |||
| 97ab9fa5b2 | |||
| debc54a28a | |||
| 55ed5ac764 | |||
| 84c86b8d9f | |||
| b38654056b | |||
| 5660fafe25 | |||
| bf3535a9b5 | |||
| b9c15b0fc8 | |||
| 83dd7654ed | |||
| e723f66df3 | |||
| 1574dcc7bb | |||
| 1de3b6c14e | |||
| 2a6018c4f5 | |||
| c3238e4d22 | |||
| 4045873135 | |||
| 3e38e4002d | |||
| 0958b76bb0 | |||
| eaffe7ff91 | |||
| 70cb7a8939 | |||
| 0b9ee77f76 | |||
| 81af4449dc | |||
| 858d8dbd45 | |||
| 879ec1d657 | |||
| 3025f597c0 | |||
| 73107a4799 | |||
| a5da9a2527 | |||
| 21d935e35e |
@@ -6,7 +6,6 @@
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="src" path="target/generated-sources/xjc"/>
|
||||
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
|
||||
3
ch.psi.fda/.settings/org.eclipse.core.resources.prefs
Normal file
@@ -0,0 +1,3 @@
|
||||
eclipse.preferences.version=1
|
||||
encoding//src/main/java=UTF-8
|
||||
encoding//src/test/java=UTF-8
|
||||
107
ch.psi.fda/Readme.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# Overview
|
||||
This package holds the core functionality of FDA.
|
||||
|
||||
# Usage
|
||||
use -Djava.util.logging.config.file=logging.properties` to configure logging
|
||||
|
||||
## Server
|
||||
|
||||
The FDA server is started as follows:
|
||||
|
||||
```
|
||||
./bin/server -h
|
||||
usage: fda
|
||||
-h Help
|
||||
-p <arg> Server port (default: 8080)
|
||||
-s <arg> Server address (default: localhost)
|
||||
```
|
||||
|
||||
Start new scan:
|
||||
|
||||
```
|
||||
curl -X PUT -d @scan1d.xml -H 'Content-Type:application/xml' http://localhost:8080/fda/scan
|
||||
```
|
||||
|
||||
## Viewer
|
||||
|
||||
```
|
||||
./bin/viewer -h
|
||||
usage: viewer
|
||||
-h Help
|
||||
-p <arg> Server port (default: 10000)
|
||||
-s <arg> Server address (default: localhost)
|
||||
```
|
||||
|
||||
|
||||
# Development
|
||||
When checking out the project from the repository there is the `target/generated-sources/xjc` folder missing.
|
||||
After checking out the project execute `mvn compile` to create the folder and the required classes.
|
||||
|
||||
To build project use `mvn clean install`.
|
||||
|
||||
To upload the latest version to the central artifact repository use `mvn clean deploy`.
|
||||
Create Zip file via `mvn clean compile assembly:assembly`
|
||||
|
||||
To use the FDA libary in an other project (like the GUI project) use:
|
||||
|
||||
```
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>fda</artifactId>
|
||||
<version>x.x.x</version>
|
||||
</dependency>
|
||||
```
|
||||
|
||||
## REST
|
||||
FDA offers a rest service to execute scans. There are 3 distinct service for fda scan, fdaq and cdump.
|
||||
|
||||
### FDA Service
|
||||
|
||||
Submit scan
|
||||
|
||||
```
|
||||
PUT fda/{trackingId}
|
||||
Content-Type: application/xml
|
||||
<configuration>
|
||||
...
|
||||
</configuration>
|
||||
|
||||
204 - Success
|
||||
|
||||
```
|
||||
|
||||
Stop/cancel scan
|
||||
|
||||
```
|
||||
DELETE fda/{trackingId}
|
||||
|
||||
204 - Success
|
||||
```
|
||||
|
||||
Stop all scans
|
||||
|
||||
```
|
||||
DELETE fda
|
||||
|
||||
204 - Success
|
||||
```
|
||||
|
||||
Check if scan is running
|
||||
|
||||
```
|
||||
GET fda/{trackingId}/running
|
||||
|
||||
200 - true/false
|
||||
```
|
||||
|
||||
Wait for scan done (blocks until scan is done)
|
||||
|
||||
```
|
||||
GET fda/{trackingId}/done
|
||||
|
||||
204 - Success
|
||||
```
|
||||
|
||||
# Notes
|
||||
## Upgrade FDA 1.x to 2.x
|
||||
In existing fda.properties file the following property need to be added: `ch.psi.fda.aq.data.dir=../data`
|
||||
2
ch.psi.fda/ReleaseNotes.md
Normal file
@@ -0,0 +1,2 @@
|
||||
# 3.0.0
|
||||
* Update the fda.properties file and replace ch.psi.fda.aq.data.baseDirectory with ch.psi.fda.aq.data.dir.
|
||||
@@ -3,107 +3,100 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>fda</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.4.3</version>
|
||||
|
||||
<dependencies>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>ch.psi.fda.core</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- These 3 libraries are just needed for testing -->
|
||||
<dependency>
|
||||
<groupId>ch.psi.fda</groupId>
|
||||
<artifactId>ch.psi.fda.xscan</artifactId>
|
||||
<version>2.3.2</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>ch.psi.fda.cdump</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>ch.psi.fda.fdaq</artifactId>
|
||||
<version>2.3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>jcae</artifactId>
|
||||
<version>2.1.11</version>
|
||||
<version>2.4.1</version>
|
||||
</dependency>
|
||||
<!-- Plotting library -->
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.psi</groupId>
|
||||
<artifactId>plot</artifactId>
|
||||
<version>1.1.30</version>
|
||||
</dependency>
|
||||
<!-- Java SMB/CIFS library -->
|
||||
<dependency>
|
||||
<groupId>jcifs</groupId>
|
||||
<artifactId>jcifs</artifactId>
|
||||
<version>1.3.17</version>
|
||||
<version>1.1.31</version>
|
||||
</dependency>
|
||||
|
||||
<!-- JAXB implementation -->
|
||||
<!-- <dependency> <groupId>com.sun.xml.bind</groupId> <artifactId>jaxb-impl</artifactId>
|
||||
<version>2.2.1</version> </dependency> <dependency> <groupId>com.sun.xml.bind</groupId>
|
||||
<artifactId>jaxb-xjc</artifactId> <version>2.2.1</version> </dependency> -->
|
||||
<!-- Jython Library -->
|
||||
<dependency>
|
||||
<groupId>org.python</groupId>
|
||||
<artifactId>jython</artifactId>
|
||||
<!-- <artifactId>jython-standalone</artifactId> -->
|
||||
<version>2.5.3</version>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>3.0</version>
|
||||
</dependency>
|
||||
<!-- CLI Libraries -->
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-grizzly2-http</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-sse</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.jeromq</groupId>
|
||||
<artifactId>jeromq</artifactId>
|
||||
<version>0.2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>cli</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Library to Read Matlab Files -->
|
||||
<dependency>
|
||||
<groupId>com.jmatio</groupId>
|
||||
<artifactId>jmatio</artifactId>
|
||||
<version>0.2u2psi1</version>
|
||||
</dependency>
|
||||
<!-- Mail Libraries -->
|
||||
<dependency>
|
||||
<groupId>javax.mail</groupId>
|
||||
<artifactId>mail</artifactId>
|
||||
<version>1.4.1</version>
|
||||
</dependency>
|
||||
<!-- Library for reading/writing XDR Format (MDA) -->
|
||||
<dependency>
|
||||
<groupId>org.freehep</groupId>
|
||||
<artifactId>freehep-xdr</artifactId>
|
||||
<version>2.0.4</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.inject</groupId>
|
||||
<artifactId>guice</artifactId>
|
||||
<version>3.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
<version>14.0.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<scope>test</scope>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.11</version>
|
||||
<version>4.8.2</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<!-- For Testing NG functionality purposes -->
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.containers</groupId>
|
||||
<artifactId>jersey-container-grizzly2-http</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-sse</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.media</groupId>
|
||||
<artifactId>jersey-media-json-jackson</artifactId>
|
||||
<version>2.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>commons-cli</groupId>
|
||||
<artifactId>commons-cli</artifactId>
|
||||
<version>1.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
@@ -112,15 +105,17 @@
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<encoding>UTF-8</encoding>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Generate Javadoc Jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-javadoc-plugin</artifactId>
|
||||
<version>2.8</version>
|
||||
<configuration>
|
||||
<additionalparam>-Xdoclint:none</additionalparam> <!-- Disable Java8 strict Javadoc checking -->
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-javadocs</id>
|
||||
@@ -130,11 +125,9 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Generate Source Jar -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
<version>2.1.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>attach-sources</id>
|
||||
@@ -144,101 +137,19 @@
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- Schema generation -->
|
||||
<plugin>
|
||||
<groupId>org.jvnet.jaxb2.maven2</groupId>
|
||||
<artifactId>maven-jaxb2-plugin</artifactId>
|
||||
<version>0.8.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<generatePackage>ch.psi.fda.model.v1</generatePackage>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<!-- Schema Documentation Generation -->
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>xml-maven-plugin</artifactId>
|
||||
<version>1.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>transform</phase>
|
||||
<goals>
|
||||
<goal>transform</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<transformationSets>
|
||||
<transformationSet>
|
||||
<!-- <outputDir>target</outputDir> -->
|
||||
<dir>src/main/resources</dir>
|
||||
<stylesheet>src/main/documentation/xs3p.xsl</stylesheet>
|
||||
<fileMappers>
|
||||
<fileMapper
|
||||
implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
|
||||
<pattern>\.xsd$</pattern>
|
||||
<replacement>.html</replacement>
|
||||
</fileMapper>
|
||||
</fileMappers>
|
||||
</transformationSet>
|
||||
</transformationSets>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
<pluginManagement>
|
||||
<plugins>
|
||||
<!--This plugin's configuration is used to store Eclipse m2e settings
|
||||
only. It has no influence on the Maven build itself. -->
|
||||
<plugin>
|
||||
<groupId>org.eclipse.m2e</groupId>
|
||||
<artifactId>lifecycle-mapping</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<configuration>
|
||||
<lifecycleMappingMetadata>
|
||||
<pluginExecutions>
|
||||
<pluginExecution>
|
||||
<pluginExecutionFilter>
|
||||
<groupId>
|
||||
org.jvnet.jaxb2.maven2
|
||||
</groupId>
|
||||
<artifactId>
|
||||
maven-jaxb2-plugin
|
||||
</artifactId>
|
||||
<versionRange>
|
||||
[0.8.0,)
|
||||
</versionRange>
|
||||
<goals>
|
||||
<goal>generate</goal>
|
||||
</goals>
|
||||
</pluginExecutionFilter>
|
||||
<action>
|
||||
<ignore></ignore>
|
||||
</action>
|
||||
</pluginExecution>
|
||||
</pluginExecutions>
|
||||
</lifecycleMappingMetadata>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</pluginManagement>
|
||||
</build>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>i.snapshots</id>
|
||||
<name>Artifactory Snapshots</name>
|
||||
<url>http://yoke/artifactory/libs-snapshots-local</url>
|
||||
<url>http://yoke.psi.ch:8081/artifactory/libs-snapshots-local</url>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>i.releases</id>
|
||||
<name>Atrifactory Releases</name>
|
||||
<url>http://yoke/artifactory/libs-releases-local</url>
|
||||
<url>http://yoke.psi.ch:8081/artifactory/libs-releases-local</url>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
</project>
|
||||
54
ch.psi.fda/src/main/assembly/assembly.xml
Normal file
@@ -0,0 +1,54 @@
|
||||
<assembly xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
|
||||
|
||||
|
||||
<id>bin</id>
|
||||
<!-- Generates a zip package containing the needed files -->
|
||||
<formats>
|
||||
<format>zip</format>
|
||||
</formats>
|
||||
|
||||
<!-- Adds dependencies to zip package under lib directory -->
|
||||
<dependencySets>
|
||||
<dependencySet>
|
||||
<outputDirectory>lib</outputDirectory>
|
||||
<unpack>false</unpack>
|
||||
</dependencySet>
|
||||
</dependencySets>
|
||||
|
||||
<fileSets>
|
||||
<!-- Adds startup scripts to the root directory of zip package -->
|
||||
<fileSet>
|
||||
<fileMode>0755</fileMode>
|
||||
<directory>src/main/assembly/bin</directory>
|
||||
<outputDirectory>bin</outputDirectory>
|
||||
<includes>
|
||||
<include>*</include>
|
||||
</includes>
|
||||
</fileSet>
|
||||
<!-- <fileSet>
|
||||
<directory>src/main/assembly/www</directory>
|
||||
<outputDirectory>www</outputDirectory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet> -->
|
||||
<!-- <fileSet>
|
||||
<fileMode>0755</fileMode>
|
||||
<directory>src/main/assembly/var</directory>
|
||||
<outputDirectory>var</outputDirectory>
|
||||
<includes>
|
||||
<include>**/*</include>
|
||||
</includes>
|
||||
</fileSet> -->
|
||||
<!-- adds jar package to the root directory of zip package -->
|
||||
<!-- <fileSet>
|
||||
<directory>target</directory>
|
||||
<outputDirectory></outputDirectory>
|
||||
<includes>
|
||||
<include>*.jar</include>
|
||||
</includes>
|
||||
</fileSet> -->
|
||||
</fileSets>
|
||||
</assembly>
|
||||
40
ch.psi.fda/src/main/assembly/bin/convert
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENTDIR=`pwd`
|
||||
|
||||
# Resolve symlinks
|
||||
BASEDIR=$0
|
||||
while [ -h "$BASEDIR" ]; do
|
||||
ls=`ls -ld "$BASEDIR"`
|
||||
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
|
||||
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
|
||||
BASEDIR="$link"
|
||||
else
|
||||
BASEDIR="`dirname "$BASEDIR"`/$link"
|
||||
fi
|
||||
done
|
||||
BASEDIR=`dirname "$BASEDIR"`
|
||||
|
||||
SCRIPTNAME=`basename ${0}`
|
||||
|
||||
APPLICATION_HOME=$BASEDIR/../..
|
||||
|
||||
LIB_DIR=`find $BASEDIR/../lib -name "*.jar"`
|
||||
LIB_DIR=`echo $LIB_DIR | sed -e 's/ /:/g'`
|
||||
|
||||
CLASSPATH=${APPLICATION_HOME}/config/:$LIB_DIR
|
||||
|
||||
ARGUMENTS=
|
||||
VM_ARGUMENTS=
|
||||
for i in $@
|
||||
do
|
||||
if [ `expr $i : '-D.*'` != '0' ] ;then
|
||||
# Extract VM options
|
||||
VM_ARGUMENTS="$VM_ARGUMENTS $i"
|
||||
else
|
||||
ARGUMENTS="$ARGUMENTS $i"
|
||||
fi
|
||||
done
|
||||
|
||||
# Execute java
|
||||
java -Xmx1024m -XX:MaxPermSize=128m -cp $CLASSPATH -Djava.util.logging.config.file=${APPLICATION_HOME}/config/logging.properties $VM_ARGUMENTS ch.psi.fda.ui.ConversionMain $ARGUMENTS
|
||||
40
ch.psi.fda/src/main/assembly/bin/scan
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENTDIR=`pwd`
|
||||
|
||||
# Resolve symlinks
|
||||
BASEDIR=$0
|
||||
while [ -h "$BASEDIR" ]; do
|
||||
ls=`ls -ld "$BASEDIR"`
|
||||
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
|
||||
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
|
||||
BASEDIR="$link"
|
||||
else
|
||||
BASEDIR="`dirname "$BASEDIR"`/$link"
|
||||
fi
|
||||
done
|
||||
BASEDIR=`dirname "$BASEDIR"`
|
||||
|
||||
SCRIPTNAME=`basename ${0}`
|
||||
|
||||
APPLICATION_HOME=$BASEDIR/../..
|
||||
|
||||
LIB_DIR=`find $BASEDIR/../lib -name "*.jar"`
|
||||
LIB_DIR=`echo $LIB_DIR | sed -e 's/ /:/g'`
|
||||
|
||||
CLASSPATH=${APPLICATION_HOME}/config/:$LIB_DIR
|
||||
|
||||
ARGUMENTS=
|
||||
VM_ARGUMENTS=
|
||||
for i in $@
|
||||
do
|
||||
if [ `expr $i : '-D.*'` != '0' ] ;then
|
||||
# Extract VM options
|
||||
VM_ARGUMENTS="$VM_ARGUMENTS $i"
|
||||
else
|
||||
ARGUMENTS="$ARGUMENTS $i"
|
||||
fi
|
||||
done
|
||||
|
||||
# Execute java
|
||||
java -Xmx1024m -XX:MaxPermSize=128m -Dch.psi.fda.home=${APPLICATION_HOME} -Djava.util.logging.config.file=${APPLICATION_HOME}/config/logging.properties $VM_ARGUMENTS -cp $CLASSPATH ch.psi.fda.ui.RemoteAcquisitionMain $ARGUMENTS
|
||||
40
ch.psi.fda/src/main/assembly/bin/scan_local
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENTDIR=`pwd`
|
||||
|
||||
# Resolve symlinks
|
||||
BASEDIR=$0
|
||||
while [ -h "$BASEDIR" ]; do
|
||||
ls=`ls -ld "$BASEDIR"`
|
||||
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
|
||||
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
|
||||
BASEDIR="$link"
|
||||
else
|
||||
BASEDIR="`dirname "$BASEDIR"`/$link"
|
||||
fi
|
||||
done
|
||||
BASEDIR=`dirname "$BASEDIR"`
|
||||
|
||||
SCRIPTNAME=`basename ${0}`
|
||||
|
||||
APPLICATION_HOME=$BASEDIR/../..
|
||||
|
||||
LIB_DIR=`find $BASEDIR/../lib -name "*.jar"`
|
||||
LIB_DIR=`echo $LIB_DIR | sed -e 's/ /:/g'`
|
||||
|
||||
CLASSPATH=${APPLICATION_HOME}/config/:$LIB_DIR
|
||||
|
||||
ARGUMENTS=
|
||||
VM_ARGUMENTS=
|
||||
for i in $@
|
||||
do
|
||||
if [ `expr $i : '-D.*'` != '0' ] ;then
|
||||
# Extract VM options
|
||||
VM_ARGUMENTS="$VM_ARGUMENTS $i"
|
||||
else
|
||||
ARGUMENTS="$ARGUMENTS $i"
|
||||
fi
|
||||
done
|
||||
|
||||
# Execute java
|
||||
java -Xmx1024m -XX:MaxPermSize=128m -Dch.psi.fda.home=${APPLICATION_HOME} -Djava.util.logging.config.file=${APPLICATION_HOME}/config/logging.properties $VM_ARGUMENTS -cp $CLASSPATH ch.psi.fda.ui.AcquisitionMain $ARGUMENTS
|
||||
42
ch.psi.fda/src/main/assembly/bin/server
Normal file
@@ -0,0 +1,42 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENTDIR=`pwd`
|
||||
|
||||
# Resolve symlinks
|
||||
BASEDIR=$0
|
||||
while [ -h "$BASEDIR" ]; do
|
||||
ls=`ls -ld "$BASEDIR"`
|
||||
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
|
||||
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
|
||||
BASEDIR="$link"
|
||||
else
|
||||
BASEDIR="`dirname "$BASEDIR"`/$link"
|
||||
fi
|
||||
done
|
||||
BASEDIR=`dirname "$BASEDIR"`
|
||||
|
||||
SCRIPTNAME=`basename ${0}`
|
||||
|
||||
APPLICATION_HOME=$BASEDIR/../..
|
||||
|
||||
LIB_DIR=`find $BASEDIR/../lib -name "*.jar"`
|
||||
LIB_DIR=`echo $LIB_DIR | sed -e 's/ /:/g'`
|
||||
|
||||
CLASSPATH=${APPLICATION_HOME}/config/:$LIB_DIR
|
||||
|
||||
ARGUMENTS=
|
||||
VM_ARGUMENTS=
|
||||
for i in $@
|
||||
do
|
||||
if [ `expr $i : '-D.*'` != '0' ] ;then
|
||||
# Extract VM options
|
||||
VM_ARGUMENTS="$VM_ARGUMENTS $i"
|
||||
else
|
||||
ARGUMENTS="$ARGUMENTS $i"
|
||||
fi
|
||||
done
|
||||
|
||||
|
||||
#HUB_BASE=$BASEDIR/../
|
||||
#export HUB_BASE
|
||||
java $VM_ARGUMENTS -cp $CLASSPATH -Dch.psi.fda.home=${APPLICATION_HOME} -Djava.util.logging.config.file=${APPLICATION_HOME}/config/logging.properties ch.psi.fda.rest.FdaServer $ARGUMENTS
|
||||
40
ch.psi.fda/src/main/assembly/bin/viewer
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENTDIR=`pwd`
|
||||
|
||||
# Resolve symlinks
|
||||
BASEDIR=$0
|
||||
while [ -h "$BASEDIR" ]; do
|
||||
ls=`ls -ld "$BASEDIR"`
|
||||
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
|
||||
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
|
||||
BASEDIR="$link"
|
||||
else
|
||||
BASEDIR="`dirname "$BASEDIR"`/$link"
|
||||
fi
|
||||
done
|
||||
BASEDIR=`dirname "$BASEDIR"`
|
||||
|
||||
SCRIPTNAME=`basename ${0}`
|
||||
|
||||
APPLICATION_HOME=$BASEDIR/../..
|
||||
|
||||
LIB_DIR=`find $BASEDIR/../lib -name "*.jar"`
|
||||
LIB_DIR=`echo $LIB_DIR | sed -e 's/ /:/g'`
|
||||
|
||||
CLASSPATH=${APPLICATION_HOME}/config/:$LIB_DIR
|
||||
|
||||
ARGUMENTS=
|
||||
VM_ARGUMENTS=
|
||||
for i in $@
|
||||
do
|
||||
if [ `expr $i : '-D.*'` != '0' ] ;then
|
||||
# Extract VM options
|
||||
VM_ARGUMENTS="$VM_ARGUMENTS $i"
|
||||
else
|
||||
ARGUMENTS="$ARGUMENTS $i"
|
||||
fi
|
||||
done
|
||||
|
||||
# Execute java
|
||||
java -Xmx1024m -XX:MaxPermSize=128m -cp $CLASSPATH -Djava.util.logging.config.file=${APPLICATION_HOME}/config/logging.properties $VM_ARGUMENTS ch.psi.fda.ui.VisualizationZMQMain $ARGUMENTS
|
||||
40
ch.psi.fda/src/main/assembly/bin/visualize
Normal file
@@ -0,0 +1,40 @@
|
||||
#!/bin/bash
|
||||
|
||||
CURRENTDIR=`pwd`
|
||||
|
||||
# Resolve symlinks
|
||||
BASEDIR=$0
|
||||
while [ -h "$BASEDIR" ]; do
|
||||
ls=`ls -ld "$BASEDIR"`
|
||||
link=`expr "$ls" : '^.*-> \(.*\)$' 2>/dev/null`
|
||||
if expr "$link" : '^/' 2> /dev/null >/dev/null; then
|
||||
BASEDIR="$link"
|
||||
else
|
||||
BASEDIR="`dirname "$BASEDIR"`/$link"
|
||||
fi
|
||||
done
|
||||
BASEDIR=`dirname "$BASEDIR"`
|
||||
|
||||
SCRIPTNAME=`basename ${0}`
|
||||
|
||||
APPLICATION_HOME=$BASEDIR/../..
|
||||
|
||||
LIB_DIR=`find $BASEDIR/../lib -name "*.jar"`
|
||||
LIB_DIR=`echo $LIB_DIR | sed -e 's/ /:/g'`
|
||||
|
||||
CLASSPATH=${APPLICATION_HOME}/config/:$LIB_DIR
|
||||
|
||||
ARGUMENTS=
|
||||
VM_ARGUMENTS=
|
||||
for i in $@
|
||||
do
|
||||
if [ `expr $i : '-D.*'` != '0' ] ;then
|
||||
# Extract VM options
|
||||
VM_ARGUMENTS="$VM_ARGUMENTS $i"
|
||||
else
|
||||
ARGUMENTS="$ARGUMENTS $i"
|
||||
fi
|
||||
done
|
||||
|
||||
# Execute java
|
||||
java -Xmx1024m -XX:MaxPermSize=128m -cp $CLASSPATH -Djava.util.logging.config.file=${APPLICATION_HOME}/config/logging.properties $VM_ARGUMENTS ch.psi.fda.ui.VisualizationMain $ARGUMENTS
|
||||
|
After Width: | Height: | Size: 1.2 KiB |
|
After Width: | Height: | Size: 1.4 KiB |
|
After Width: | Height: | Size: 730 B |
|
After Width: | Height: | Size: 854 B |
|
After Width: | Height: | Size: 730 B |
BIN
ch.psi.fda/src/main/assembly/www/apple-touch-icon.png
Normal file
|
After Width: | Height: | Size: 730 B |
1109
ch.psi.fda/src/main/assembly/www/css/bootstrap-responsive.css
vendored
Normal file
9
ch.psi.fda/src/main/assembly/www/css/bootstrap-responsive.min.css
vendored
Normal file
6158
ch.psi.fda/src/main/assembly/www/css/bootstrap.css
vendored
Normal file
9
ch.psi.fda/src/main/assembly/www/css/bootstrap.min.css
vendored
Normal file
22
ch.psi.fda/src/main/assembly/www/css/main.css
Normal file
@@ -0,0 +1,22 @@
|
||||
|
||||
|
||||
/* ==========================================================================
|
||||
Author's custom styles
|
||||
========================================================================== */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
BIN
ch.psi.fda/src/main/assembly/www/favicon.ico
Normal file
|
After Width: | Height: | Size: 766 B |
|
After Width: | Height: | Size: 8.6 KiB |
BIN
ch.psi.fda/src/main/assembly/www/img/glyphicons-halflings.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
222
ch.psi.fda/src/main/assembly/www/index.html
Normal file
@@ -0,0 +1,222 @@
|
||||
<!DOCTYPE html>
|
||||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
|
||||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
|
||||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
|
||||
<!--[if gt IE 8]><!-->
|
||||
<html class="no-js">
|
||||
<!--<![endif]-->
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
|
||||
<title></title>
|
||||
<meta name="description" content="">
|
||||
<meta name="viewport" content="width=device-width">
|
||||
|
||||
<link rel="stylesheet" href="css/bootstrap.min.css">
|
||||
<style>
|
||||
body {
|
||||
padding-top: 60px;
|
||||
padding-bottom: 40px;
|
||||
}
|
||||
</style>
|
||||
<link rel="stylesheet" href="css/bootstrap-responsive.min.css">
|
||||
<link rel="stylesheet" href="css/main.css">
|
||||
|
||||
<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>
|
||||
<script src="js/jquery-2.0.0.min.js"></script>
|
||||
<script type='text/javascript'>
|
||||
var base = '../hub';
|
||||
var stream;
|
||||
|
||||
function getVersion() {
|
||||
$.get(base+'/version', function(data) {
|
||||
$('#version').empty();
|
||||
$('#version').append(data)
|
||||
});
|
||||
}
|
||||
|
||||
function getBeamlines() {
|
||||
$.get(base, function(data) {
|
||||
/* update beamlines selection */
|
||||
|
||||
$('#selectionBeamline').empty();
|
||||
for (var i in data){
|
||||
beamline = data[i];
|
||||
$('#selectionBeamline').append('<option value="'+beamline+'">'+beamline+'</option>')
|
||||
}
|
||||
/* $('#selectionBeamline')[0].selectedIndex=0; */
|
||||
connectStream(data[0]);
|
||||
});
|
||||
}
|
||||
|
||||
function updateKeys(beamline, keys){
|
||||
keytag = $('#beamlineKeys');
|
||||
keytag.empty();
|
||||
table='<table class="table table-hover"><thead><tr><td>Key</td><td>Value</td></tr></thead><tbody>';
|
||||
|
||||
for(k in keys){
|
||||
table=table+'<tr><td>'+k+'</td><td>'+
|
||||
'<div class="input-append">'+
|
||||
'<input type="text" value="'+keys[k]+'" onchange="setKey(\''+beamline+'\',\''+k+'\',$(this).val())">'+
|
||||
//'<button class="btn" type="button" onclick="setKey(\''+beamline+'\',\''+k+'\',$(this).prev().val())">Update</button>'+
|
||||
'<button class="btn" type="button" onclick="deleteKey(\''+beamline+'\',\''+k+'\')">Delete</button>'+
|
||||
'</div>'+
|
||||
'</td></tr>';
|
||||
}
|
||||
|
||||
table = table+'<tr>'+
|
||||
'<td><input id="keyToAdd" type="text" placeholder="Key"></td>'+
|
||||
'<td><div class="input-append">'+
|
||||
'<input id="valueToAdd"type="text" placeholder="Value">'+
|
||||
'<button class="btn" type="button" onclick="setKey(\''+beamline+'\',$(\'#keyToAdd\').val(),$(\'#valueToAdd\').val())">Add</button>'+
|
||||
'</div></td>'+
|
||||
'</tr>';
|
||||
|
||||
table = table+'</table></tbody>';
|
||||
keytag.append(table);
|
||||
}
|
||||
|
||||
function connectStream(beamline) {
|
||||
closeStream();
|
||||
stream = new EventSource(base + '/' + beamline + '/stream');
|
||||
stream.onmessage = function(event) {
|
||||
keys=JSON.parse(event.data)
|
||||
updateKeys(beamline, keys);
|
||||
|
||||
};
|
||||
getKeys(beamline);
|
||||
}
|
||||
|
||||
function closeStream() {
|
||||
try {
|
||||
stream.close();
|
||||
} catch (e) {
|
||||
}
|
||||
}
|
||||
|
||||
function getKeys(beamline){
|
||||
$.get(base+'/'+beamline+'/keys', function(data) {
|
||||
updateKeys(beamline, data );
|
||||
});
|
||||
}
|
||||
|
||||
function setKey(beamline, key, value){
|
||||
$.ajax({
|
||||
url: base+'/'+beamline+'/keys/'+key,
|
||||
type: 'PUT',
|
||||
data: value,
|
||||
success: function(result) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function deleteKey(beamline, key){
|
||||
$.ajax({
|
||||
url: base+'/'+beamline+'/keys/'+key,
|
||||
type: 'DELETE',
|
||||
success: function(result) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function addBeamline(beamline){
|
||||
getKeys(beamline); /*create beamline*/
|
||||
getBeamlines();
|
||||
}
|
||||
|
||||
function deleteBeamline(beamline){
|
||||
$.ajax({
|
||||
url: base+'/'+beamline,
|
||||
type: 'DELETE',
|
||||
success: function(result) {
|
||||
getBeamlines(); /* Update beamline list */
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<!-- <script>
|
||||
var source = new EventSource('../server-sent-events/');
|
||||
source.onmessage = function(e) {
|
||||
$('#messagefield') = e.data;
|
||||
};
|
||||
</script> -->
|
||||
|
||||
<!--[if lt IE 7]>
|
||||
<p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
|
||||
<![endif]-->
|
||||
|
||||
<!-- This code is taken from http://twitter.github.com/bootstrap/examples/hero.html -->
|
||||
|
||||
<div class="navbar navbar-inverse navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
<a class="btn btn-navbar" data-toggle="collapse"
|
||||
data-target=".nav-collapse"> <span class="icon-bar"></span> <span
|
||||
class="icon-bar"></span> <span class="icon-bar"></span>
|
||||
</a> <a class="brand" href="#">hub</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="container">
|
||||
|
||||
<!-- Main hero unit for a primary marketing message or call to action -->
|
||||
<!-- <div class="hero-unit">
|
||||
<p>This is the central Hub administration page ...</p>
|
||||
</div> -->
|
||||
|
||||
<!-- Example row of columns -->
|
||||
<div class="row">
|
||||
<div class="span5">
|
||||
<h2>Key Group</h2>
|
||||
<div>
|
||||
<select id="selectionBeamline">
|
||||
<!-- <option value="sydney">Sydney</option> -->
|
||||
</select>
|
||||
</div>
|
||||
<div id="beamlineKeys"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="span5">
|
||||
<h2>Key Group Management</h2>
|
||||
<div class="input-append">
|
||||
<input class="span2" id="appendedInputButton" placeholder="Key Group" type="text">
|
||||
<button id="addBeamlineBtn" class="btn" type="button" onclick="addBeamline($(this).prev().val());$(this).prev().val('')">Add</button>
|
||||
<button id="addBeamlineBtn" class="btn" type="button" onclick="deleteBeamline($(this).prev().prev().val());$(this).prev().prev().val('')">Delete</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr>
|
||||
|
||||
<footer>
|
||||
<p>Hub - Version <span id='version'></span> - © Paul Scherrer Institute 2013</p>
|
||||
</footer>
|
||||
|
||||
</div>
|
||||
<!-- /container -->
|
||||
|
||||
<script>
|
||||
/* update beamlines */
|
||||
getVersion();
|
||||
getBeamlines();
|
||||
$('#selectionBeamline').change(function(){connectStream($('#selectionBeamline').val())});
|
||||
</script>
|
||||
|
||||
|
||||
<script>
|
||||
window.jQuery
|
||||
|| document
|
||||
.write('<script src="js/vendor/jquery-1.9.1.min.js"><\/script>')
|
||||
</script>
|
||||
|
||||
<script src="js/vendor/bootstrap.min.js"></script>
|
||||
|
||||
<script src="js/main.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
6
ch.psi.fda/src/main/assembly/www/js/jquery-2.0.0.min.js
vendored
Normal file
1
ch.psi.fda/src/main/assembly/www/js/main.js
Normal file
@@ -0,0 +1 @@
|
||||
|
||||
2268
ch.psi.fda/src/main/assembly/www/js/vendor/bootstrap.js
vendored
Normal file
6
ch.psi.fda/src/main/assembly/www/js/vendor/bootstrap.min.js
vendored
Normal file
5
ch.psi.fda/src/main/assembly/www/js/vendor/jquery-1.9.1.min.js
vendored
Normal file
11
ch.psi.fda/src/main/assembly/www/js/vendor/modernizr-2.6.2-respond-1.1.0.min.js
vendored
Normal file
@@ -1,299 +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.aq;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Properties;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import ch.psi.fda.install.ApplicationConfigurator;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class AcquisitionEngineConfiguration {
|
||||
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AcquisitionEngineConfiguration.class.getName());
|
||||
private static final AcquisitionEngineConfiguration instance = new AcquisitionEngineConfiguration();
|
||||
|
||||
private String otfChannelPrefix;
|
||||
private String otfNfsServer;
|
||||
private String otfNfsShare;
|
||||
private String otfSmbShare;
|
||||
private String otfScalerPrefix;
|
||||
private boolean otfUseCrlogic;
|
||||
private String otfCrlogicPrefix;
|
||||
private boolean otfCrlogicKeepTmpFiles;
|
||||
|
||||
/**
|
||||
* Base directory for data. The directory may contain date macros. The string may contain any @see java.text.SimpleDateFormat
|
||||
* patterns within ${ } brackets. The macros are resolved with the actual time while the get method
|
||||
* of this property is called.
|
||||
*/
|
||||
private String dataBaseDirectory = System.getProperty("user.home");
|
||||
/**
|
||||
* Prefix of the data file. The prefix may contain date macros. The string may contain any @see java.text.SimpleDateFormat
|
||||
* patterns within ${ } brackets. The macros are resolved with the actual time while the get method
|
||||
* of this property is called.
|
||||
*/
|
||||
private String dataFilePrefix = "";
|
||||
|
||||
/**
|
||||
* Maximum time for a actor move
|
||||
*/
|
||||
private Long actorMoveTimeout = 600000l; // 10 Minutes maximum move time
|
||||
|
||||
private String smptServer;
|
||||
|
||||
/**
|
||||
* Default Constructor
|
||||
* The constructor will read the configuration from the /fda.properties file (resource) located in the classpath.
|
||||
*/
|
||||
private AcquisitionEngineConfiguration(){
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get instance of this configuration
|
||||
* @return configuration
|
||||
*/
|
||||
public static AcquisitionEngineConfiguration getInstance(){
|
||||
return(instance);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load configuration from properties file
|
||||
*/
|
||||
private void loadConfiguration() {
|
||||
String config = System.getProperty(ApplicationConfigurator.FDA_CONFIG_FILE_ARGUMENT);
|
||||
|
||||
Properties properties = new Properties();
|
||||
|
||||
if(config != null){
|
||||
try {
|
||||
properties.load(new FileReader(config));
|
||||
} catch (FileNotFoundException e) {
|
||||
throw new RuntimeException("Configuration file "+config+" not found", e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Cannot read configuration file "+config, e);
|
||||
}
|
||||
}
|
||||
else{
|
||||
logger.warning("No configfile specified !");
|
||||
}
|
||||
|
||||
// The defaults are set here
|
||||
otfChannelPrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.channelPrefix", "");
|
||||
otfScalerPrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.scalerPrefix", "");
|
||||
otfNfsServer = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.nfsServer", "");
|
||||
otfNfsShare = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.nfsShare", "");
|
||||
otfSmbShare = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.smbShare", "");
|
||||
otfUseCrlogic = new Boolean(properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.useCrlogic", "false"));
|
||||
otfCrlogicPrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.crlogicPrefix", "");
|
||||
otfCrlogicKeepTmpFiles = new Boolean(properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".otf.crlogicKeepTmpFiles", "false"));
|
||||
|
||||
// Workaround
|
||||
// dataBaseDirectory = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".data.baseDirectory", ".");
|
||||
if(System.getProperty(ApplicationConfigurator.FDA_HOME_ARGUMENT)!=null){
|
||||
dataBaseDirectory = System.getProperty(ApplicationConfigurator.FDA_HOME_ARGUMENT)+"/data";
|
||||
}
|
||||
else{
|
||||
dataBaseDirectory = "./data";
|
||||
}
|
||||
|
||||
dataFilePrefix = properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".data.filePrefix","");
|
||||
|
||||
actorMoveTimeout = new Long(properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".actorMoveTimeout","600000"));
|
||||
|
||||
smptServer= properties.getProperty(AcquisitionEngineConfiguration.class.getPackage().getName()+".notification.host","mail.psi.ch");
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reload this configuration from the corresponding properties file
|
||||
* @throws IOException
|
||||
*/
|
||||
public void reloadConfiguration() throws IOException{
|
||||
loadConfiguration();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the otfChannelPrefix
|
||||
*/
|
||||
public String getOtfChannelPrefix() {
|
||||
return otfChannelPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the otfScalerPrefix
|
||||
*/
|
||||
public String getOtfScalerPrefix() {
|
||||
return otfScalerPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the otfNfsServer
|
||||
*/
|
||||
public String getOtfNfsServer() {
|
||||
return otfNfsServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the otfNfsShare
|
||||
*/
|
||||
public String getOtfNfsShare() {
|
||||
return otfNfsShare;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the otfSmbShare
|
||||
*/
|
||||
public String getOtfSmbShare() {
|
||||
return otfSmbShare;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the otfUseCrlogic
|
||||
*/
|
||||
public boolean isOtfUseCrlogic() {
|
||||
return otfUseCrlogic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataBaseDirectory
|
||||
*/
|
||||
public String getDataBaseDirectory() {
|
||||
return dataBaseDirectory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataFilePrefix
|
||||
*/
|
||||
public String getDataFilePrefix() {
|
||||
return dataFilePrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the smptServer
|
||||
*/
|
||||
public String getSmptServer() {
|
||||
return smptServer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the otfCrlogicPrefix
|
||||
*/
|
||||
public String getOtfCrlogicPrefix() {
|
||||
return otfCrlogicPrefix;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the otfCrlogicKeepTmpFiles
|
||||
*/
|
||||
public boolean isOtfCrlogicKeepTmpFiles() {
|
||||
return otfCrlogicKeepTmpFiles;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actorMoveTimeout
|
||||
*/
|
||||
public Long getActorMoveTimeout() {
|
||||
return actorMoveTimeout;
|
||||
}
|
||||
|
||||
public String replaceMacros(String string, Date date, String name){
|
||||
String newString = string;
|
||||
|
||||
// Replace scan name macros
|
||||
newString = newString.replaceAll("\\$\\{name\\}", name);
|
||||
|
||||
|
||||
// Replace date macros
|
||||
Pattern pattern = Pattern.compile("\\$\\{[a-z,A-Z,-,_,:]*\\}");
|
||||
Matcher matcher = pattern.matcher(newString);
|
||||
while(matcher.find()){
|
||||
String datePattern = matcher.group();
|
||||
datePattern = datePattern.replaceAll("\\$\\{", "");
|
||||
datePattern = datePattern.replaceAll("\\}", "");
|
||||
SimpleDateFormat datef = new SimpleDateFormat(datePattern);
|
||||
newString = matcher.replaceFirst(datef.format(date));
|
||||
matcher = pattern.matcher(newString);
|
||||
}
|
||||
return newString;
|
||||
}
|
||||
|
||||
public void setOtfChannelPrefix(String otfChannelPrefix) {
|
||||
this.otfChannelPrefix = otfChannelPrefix;
|
||||
}
|
||||
|
||||
public void setOtfNfsServer(String otfNfsServer) {
|
||||
this.otfNfsServer = otfNfsServer;
|
||||
}
|
||||
|
||||
public void setOtfNfsShare(String otfNfsShare) {
|
||||
this.otfNfsShare = otfNfsShare;
|
||||
}
|
||||
|
||||
public void setOtfSmbShare(String otfSmbShare) {
|
||||
this.otfSmbShare = otfSmbShare;
|
||||
}
|
||||
|
||||
public void setOtfScalerPrefix(String otfScalerPrefix) {
|
||||
this.otfScalerPrefix = otfScalerPrefix;
|
||||
}
|
||||
|
||||
public void setOtfUseCrlogic(boolean otfUseCrlogic) {
|
||||
this.otfUseCrlogic = otfUseCrlogic;
|
||||
}
|
||||
|
||||
public void setOtfCrlogicPrefix(String otfCrlogicPrefix) {
|
||||
this.otfCrlogicPrefix = otfCrlogicPrefix;
|
||||
}
|
||||
|
||||
public void setOtfCrlogicKeepTmpFiles(boolean otfCrlogicKeepTmpFiles) {
|
||||
this.otfCrlogicKeepTmpFiles = otfCrlogicKeepTmpFiles;
|
||||
}
|
||||
|
||||
public void setDataBaseDirectory(String dataBaseDirectory) {
|
||||
this.dataBaseDirectory = dataBaseDirectory;
|
||||
}
|
||||
|
||||
public void setDataFilePrefix(String dataFilePrefix) {
|
||||
this.dataFilePrefix = dataFilePrefix;
|
||||
}
|
||||
|
||||
public void setActorMoveTimeout(Long actorMoveTimeout) {
|
||||
this.actorMoveTimeout = actorMoveTimeout;
|
||||
}
|
||||
|
||||
public void setSmptServer(String smptServer) {
|
||||
this.smptServer = smptServer;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,154 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import ch.psi.fda.aq.ng.rdescriptors.ProbeDescriptor;
|
||||
import ch.psi.fda.aq.ng.rdescriptors.ShellDescriptor;
|
||||
import ch.psi.fda.aq.ng.resources.ChannelProbeResource;
|
||||
import ch.psi.fda.aq.ng.resources.ShellResource;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class AcquisitionEngineNG {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(AcquisitionEngineNG.class.getName());
|
||||
|
||||
private ChannelService cservice;
|
||||
private BlockingQueue<Message> outQueue;
|
||||
|
||||
public AcquisitionEngineNG(ChannelService cservice) {
|
||||
this.cservice = cservice;
|
||||
this.outQueue = new LinkedBlockingQueue<Message>(1000); // Create bounded queue to prevent running out of memory ...
|
||||
|
||||
// Workaround for Jython memory leak
|
||||
// http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/
|
||||
System.setProperty("python.options.internalTablesImpl", "weak");
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the specified script/logic while using the specified resources and paramters
|
||||
* @param resourceDescriptors
|
||||
* @param script
|
||||
* @param parameter
|
||||
*/
|
||||
public void execute(Map<String, ?> resourceDescriptors, String script, List<String> parameter){
|
||||
|
||||
// TODO Remove debugging messages
|
||||
// For debugging purpose only
|
||||
logger.info("Resources to create: "+resourceDescriptors);
|
||||
logger.info("Script to execute: "+script);
|
||||
|
||||
try {
|
||||
ScriptEngine engine = new ScriptEngineManager().getEngineByName("python");
|
||||
|
||||
// Set logger
|
||||
engine.put("logger", logger);
|
||||
|
||||
// Set parameters
|
||||
engine.put("parameter", parameter);
|
||||
|
||||
// Create/retrieve and set resources
|
||||
Map<String,?> resources = createResources(resourceDescriptors);
|
||||
engine.put("resources", resources);
|
||||
for(String k: resources.keySet()){ // For convenience make resources also available as variable named by the resource id
|
||||
engine.put(k, resources.get(k));
|
||||
}
|
||||
|
||||
// Execute script
|
||||
engine.eval(script);
|
||||
|
||||
|
||||
} catch (ScriptException e) {
|
||||
logger.info(e.getMessage());
|
||||
throw new RuntimeException("Action failed while executing the Jython script",e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create resources based on the passed rDescriptors
|
||||
* Supported descriptor types are:
|
||||
* ChannelDescriptor, ShellDescriptor, ProbeDescriptor
|
||||
*
|
||||
* @param resourceDescriptors
|
||||
* @return
|
||||
*/
|
||||
private Map<String,?> createResources(Map<String, ?> resourceDescriptors){
|
||||
Map<String,Object> resources = new HashMap<>();
|
||||
for(String k: resourceDescriptors.keySet()){
|
||||
if(resourceDescriptors.get(k) instanceof ChannelDescriptor){
|
||||
ChannelDescriptor<?> descriptor = (ChannelDescriptor<?>)resourceDescriptors.get(k);
|
||||
try {
|
||||
resources.put(k, cservice.createChannel(descriptor));
|
||||
// engine.put(k, cservice.createChannel(descriptor));
|
||||
} catch (ChannelException | InterruptedException | TimeoutException e) {
|
||||
throw new RuntimeException("Unable to create resource for channel: "+descriptor.getName(),e);
|
||||
}
|
||||
}
|
||||
else if(resourceDescriptors.get(k) instanceof ShellDescriptor){
|
||||
resources.put(k, new ShellResource());
|
||||
// engine.put(k, new ShellResource());
|
||||
}
|
||||
else if(resourceDescriptors.get(k) instanceof ProbeDescriptor){
|
||||
ProbeDescriptor descriptor = (ProbeDescriptor) resourceDescriptors.get(k);
|
||||
List<Channel<?>> channels = new ArrayList<>();
|
||||
|
||||
for(ChannelDescriptor<?> s: descriptor.getSensors()){
|
||||
try {
|
||||
channels.add(cservice.createChannel(s));
|
||||
|
||||
} catch (ChannelException | InterruptedException | TimeoutException e) {
|
||||
throw new RuntimeException("Unable to create resource for channel: "+s.getName(),e);
|
||||
}
|
||||
}
|
||||
// TODO Remove workaround ...
|
||||
resources.put(k, new ChannelProbeResource(channels, outQueue)); // Configure the probe to use the acquisitions out queue for writing data into
|
||||
// engine.put(k, new ChannelProbeResource(channels, outQueue));
|
||||
}
|
||||
else{
|
||||
throw new RuntimeException("Resource type not supported: "+resourceDescriptors.get(k).getClass().getName());
|
||||
}
|
||||
}
|
||||
return resources;
|
||||
}
|
||||
|
||||
public BlockingQueue<Message> getOutQueue(){
|
||||
return outQueue;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,173 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
import javax.ws.rs.NotFoundException;
|
||||
import javax.ws.rs.POST;
|
||||
import javax.ws.rs.PUT;
|
||||
import javax.ws.rs.Path;
|
||||
import javax.ws.rs.PathParam;
|
||||
import javax.ws.rs.Produces;
|
||||
import javax.ws.rs.core.MediaType;
|
||||
|
||||
import ch.psi.fda.aq.ng.rdescriptors.ShellDescriptor;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
@Path("/")
|
||||
public class AcquisitionEngineNGResource {
|
||||
|
||||
@Inject
|
||||
private AcquisitionEngineNG engine;
|
||||
|
||||
@Inject
|
||||
private LManager lmanager;
|
||||
|
||||
// @PUT
|
||||
// @Path("logic")
|
||||
// public void execute(String logic){
|
||||
// Map<String, ?> map = new HashMap<>();
|
||||
// engine.execute(map, logic);
|
||||
// }
|
||||
|
||||
@GET
|
||||
@Path("logic")
|
||||
@Produces(MediaType.APPLICATION_JSON)
|
||||
public Set<String> getLogics(){
|
||||
return lmanager.getLogics();
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("logic/{id}")
|
||||
public void setLogic(@PathParam("id") String id, String logic){
|
||||
lmanager.addLogic(id, logic);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("logic/{id}")
|
||||
public String getLogic(@PathParam("id") String id){
|
||||
String logic = lmanager.getLogic(id);
|
||||
if(logic==null){
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return logic;
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("logic/{id}")
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public void executeLogic(@PathParam("id") String id, EDescriptor edescriptor){
|
||||
|
||||
// Before executing the logic first merge the default descriptors and provided descriptors
|
||||
// Where the provided descriptors take precedence over the default onces.
|
||||
Map<String, RDescriptor> rdesc = new HashMap<>();
|
||||
rdesc.putAll(lmanager.getResources(id));
|
||||
if (edescriptor.getResources() != null) {
|
||||
rdesc.putAll(edescriptor.getResources());
|
||||
}
|
||||
|
||||
Map<String, ?> map = createResourceDescriptors(rdesc);
|
||||
|
||||
List<String> parameters = new ArrayList<>();
|
||||
if(edescriptor.getParameter()!=null){
|
||||
parameters = edescriptor.getParameter();
|
||||
}
|
||||
|
||||
engine.execute(map, lmanager.getLogic(id), parameters);
|
||||
}
|
||||
|
||||
@PUT
|
||||
@Path("logic/{id}/resources")
|
||||
public void setLogicResources(@PathParam("id") String id, Map<String, RDescriptor> rprofile){
|
||||
lmanager.addResources(id, rprofile);
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("logic/{id}/resources")
|
||||
public Map<String, RDescriptor> getLogicResources(@PathParam("id") String id){
|
||||
Map<String, RDescriptor> rprofile = lmanager.getResources(id);
|
||||
if(rprofile==null){
|
||||
throw new NotFoundException();
|
||||
}
|
||||
return rprofile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create internal resource descriptors based on the rdescriptors passed to the method.
|
||||
*
|
||||
* Currently following rdescriptor types are supported:
|
||||
* - channel
|
||||
* - shell
|
||||
*
|
||||
* @param descriptor
|
||||
* @return
|
||||
*/
|
||||
private Map<String, ?> createResourceDescriptors(Map<String, RDescriptor> resourceDescriptors) {
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
for (String k : resourceDescriptors.keySet()) {
|
||||
RDescriptor r = resourceDescriptors.get(k);
|
||||
if (r.getType().equals("channel")) {
|
||||
Class<?> c;
|
||||
switch (r.getParameter().get("type").toLowerCase()) {
|
||||
case "double":
|
||||
c = Double.class;
|
||||
break;
|
||||
case "integer":
|
||||
c = Integer.class;
|
||||
break;
|
||||
case "boolean":
|
||||
c = Boolean.class;
|
||||
break;
|
||||
case "String":
|
||||
c = String.class;
|
||||
break;
|
||||
default:
|
||||
c = String.class;
|
||||
}
|
||||
;
|
||||
String name = r.getParameter().get("name");
|
||||
boolean monitored = false;
|
||||
if(r.getParameter().get("monitor")!=null){
|
||||
monitored = new Boolean(r.getParameter().get("monitor"));
|
||||
}
|
||||
|
||||
// Create channel descriptor
|
||||
ChannelDescriptor<?> cd = new ChannelDescriptor<>(c, name, monitored);
|
||||
map.put(k, cd);
|
||||
}
|
||||
else if (r.getType().equals("shell")) {
|
||||
map.put(k, new ShellDescriptor());
|
||||
}
|
||||
}
|
||||
return map;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.codehaus.jackson.map.annotate.JsonSerialize;
|
||||
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
|
||||
|
||||
/**
|
||||
* Execution descriptor - Describes resources and parameters used to execute a logic
|
||||
*/
|
||||
@XmlRootElement
|
||||
@JsonSerialize(include = Inclusion.NON_NULL) // Do not serialize NULL values
|
||||
public class EDescriptor {
|
||||
|
||||
private Map<String, RDescriptor> resources;
|
||||
private List<String> parameter;
|
||||
|
||||
public Map<String, RDescriptor> getResources() {
|
||||
return resources;
|
||||
}
|
||||
public void setResources(Map<String, RDescriptor> resources) {
|
||||
this.resources = resources;
|
||||
}
|
||||
public List<String> getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
public void setParameter(List<String> parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Logic Manager
|
||||
* Basically a map holding id->logic pairs
|
||||
*
|
||||
* also holds default resource profiles for logics (rprofiles)
|
||||
*/
|
||||
public class LManager {
|
||||
private final Map<String, String> logics = new HashMap<>();
|
||||
|
||||
/** Default resourses assigned to a logic */
|
||||
private final Map<String, Map<String, RDescriptor>> resources = new HashMap<>();
|
||||
|
||||
public void addLogic(String id, String logic){
|
||||
logics.put(id, logic);
|
||||
resources.put(id, new HashMap<String,RDescriptor>()); // No default resources attached to logic
|
||||
}
|
||||
|
||||
public void addResources(String id, Map<String, RDescriptor> lresources){
|
||||
resources.put(id, lresources);
|
||||
}
|
||||
|
||||
public String getLogic(String id){
|
||||
return logics.get(id);
|
||||
}
|
||||
|
||||
public Set<String> getLogics(){
|
||||
return logics.keySet();
|
||||
}
|
||||
|
||||
public Map<String, RDescriptor> getResources(String id){
|
||||
return resources.get(id);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,119 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng;
|
||||
|
||||
import java.net.InetAddress;
|
||||
import java.net.URI;
|
||||
import java.net.UnknownHostException;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
import javax.ws.rs.core.UriBuilderException;
|
||||
|
||||
import org.apache.commons.cli.CommandLine;
|
||||
import org.apache.commons.cli.GnuParser;
|
||||
import org.apache.commons.cli.HelpFormatter;
|
||||
import org.apache.commons.cli.Options;
|
||||
import org.apache.commons.cli.ParseException;
|
||||
import org.glassfish.grizzly.http.server.HttpServer;
|
||||
import org.glassfish.grizzly.http.server.StaticHttpHandler;
|
||||
import org.glassfish.jersey.grizzly2.httpserver.GrizzlyHttpServerFactory;
|
||||
import org.glassfish.jersey.jackson.JacksonFeature;
|
||||
import org.glassfish.jersey.media.sse.SseFeature;
|
||||
import org.glassfish.jersey.server.ResourceConfig;
|
||||
|
||||
import sun.misc.Signal;
|
||||
import sun.misc.SignalHandler;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
@SuppressWarnings("restriction")
|
||||
public class NGServer {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(NGServer.class.getName());
|
||||
|
||||
/**
|
||||
* @param args
|
||||
* @throws ParseException
|
||||
* @throws UnknownHostException
|
||||
* @throws UriBuilderException
|
||||
* @throws IllegalArgumentException
|
||||
*/
|
||||
public static void main(String[] args) throws ParseException, IllegalArgumentException, UriBuilderException, UnknownHostException {
|
||||
// Option handling
|
||||
int port = 8080;
|
||||
|
||||
Options options = new Options();
|
||||
options.addOption("h", false, "Help");
|
||||
options.addOption("p", true, "Server port (default: " + port + ")");
|
||||
|
||||
GnuParser parser = new GnuParser();
|
||||
CommandLine line = parser.parse(options, args);
|
||||
|
||||
if (line.hasOption("p")) {
|
||||
port = Integer.parseInt(line.getOptionValue("p"));
|
||||
}
|
||||
if (line.hasOption("h")) {
|
||||
HelpFormatter f = new HelpFormatter();
|
||||
f.printHelp("dae", options); // definition dae - http://www.urbandictionary.com/define.php?term=dae
|
||||
return;
|
||||
}
|
||||
|
||||
URI baseUri = UriBuilder.fromUri("http://" + InetAddress.getLocalHost().getHostName() + "/").port(port).build();
|
||||
|
||||
// final ResourceConfig resourceConfig = new
|
||||
// ResourceConfig(ServerSentEventsResource.class, SseFeature.class);
|
||||
ResourceConfig resourceConfig = new ResourceConfig(SseFeature.class, JacksonFeature.class);
|
||||
resourceConfig.packages(AcquisitionEngineNGResource.class.getPackage().getName());
|
||||
resourceConfig.register(new ResourceBinder());
|
||||
HttpServer server = GrizzlyHttpServerFactory.createHttpServer(baseUri, resourceConfig);
|
||||
|
||||
// Static content
|
||||
String home = System.getenv("DAE_BASE");
|
||||
if (home == null) {
|
||||
home = "src/main/assembly";
|
||||
}
|
||||
home = home + "/www";
|
||||
server.getServerConfiguration().addHttpHandler(new StaticHttpHandler(home), "/static");
|
||||
|
||||
logger.info("dae started");
|
||||
logger.info(String.format("Management interface available at %sstatic/", baseUri));
|
||||
logger.info("Use ctrl+c to stop ...");
|
||||
|
||||
// Signal handling
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
Signal.handle(new Signal("INT"), new SignalHandler() {
|
||||
public void handle(Signal sig) {
|
||||
latch.countDown();
|
||||
}
|
||||
});
|
||||
|
||||
// Wait for termination, i.e. wait for ctrl+c
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
|
||||
server.stop();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,58 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import org.codehaus.jackson.map.annotate.JsonSerialize;
|
||||
import org.codehaus.jackson.map.annotate.JsonSerialize.Inclusion;
|
||||
|
||||
/**
|
||||
* Resource descriptor - Used to identify and/or create resource on server
|
||||
*/
|
||||
@XmlRootElement
|
||||
@JsonSerialize(include = Inclusion.NON_NULL) // Do not serialize NULL values
|
||||
public class RDescriptor {
|
||||
|
||||
private String ref;
|
||||
private String type;
|
||||
private Map<String,String> parameter;
|
||||
|
||||
public String getRef() {
|
||||
return ref;
|
||||
}
|
||||
public void setRef(String ref) {
|
||||
this.ref = ref;
|
||||
}
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
public Map<String, String> getParameter() {
|
||||
return parameter;
|
||||
}
|
||||
public void setParameter(Map<String, String> parameter) {
|
||||
this.parameter = parameter;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
package ch.psi.fda.aq.ng;
|
||||
|
||||
import org.glassfish.hk2.utilities.binding.AbstractBinder;
|
||||
//import org.glassfish.jersey.media.sse.SseBroadcaster;
|
||||
|
||||
//import ch.psi.da.hub.model.Keystore;
|
||||
import ch.psi.jcae.impl.DefaultChannelService;
|
||||
|
||||
public class ResourceBinder extends AbstractBinder {
|
||||
|
||||
@Override
|
||||
protected void configure() {
|
||||
// request scope binding
|
||||
// bind(MyInjectablePerRequest.class).to(MyInjectablePerRequest.class).in(RequestScope.class);
|
||||
// singleton binding
|
||||
// bind(MyInjectableSingleton.class).in(Singleton.class);
|
||||
// singleton instance binding
|
||||
|
||||
// KeystoreSerializer serializer = new KeystoreSerializer();
|
||||
// Keystore keystore = serializer.deserialize();
|
||||
|
||||
// bind(new SseBroadcaster()).to(SseBroadcaster.class);
|
||||
// bind(serializer).to(KeystoreSerializer.class);
|
||||
// bind(new KeystoreBroadcaster()).to(KeystoreBroadcaster.class);
|
||||
// bind(keystore).to(Keystore.class);
|
||||
|
||||
bind(new AcquisitionEngineNG(new DefaultChannelService())).to(AcquisitionEngineNG.class);
|
||||
bind(new LManager()).to(LManager.class);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,405 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.aq.ng.rdescriptors.ProbeDescriptor;
|
||||
import ch.psi.fda.aq.ng.rdescriptors.ShellDescriptor;
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.model.v1.Action;
|
||||
import ch.psi.fda.model.v1.ArrayPositioner;
|
||||
import ch.psi.fda.model.v1.ChannelAction;
|
||||
import ch.psi.fda.model.v1.Configuration;
|
||||
import ch.psi.fda.model.v1.ContinuousDimension;
|
||||
import ch.psi.fda.model.v1.Dimension;
|
||||
import ch.psi.fda.model.v1.DiscreteStepDimension;
|
||||
import ch.psi.fda.model.v1.DiscreteStepPositioner;
|
||||
import ch.psi.fda.model.v1.FunctionPositioner;
|
||||
import ch.psi.fda.model.v1.LinearPositioner;
|
||||
import ch.psi.fda.model.v1.PseudoPositioner;
|
||||
import ch.psi.fda.model.v1.RegionPositioner;
|
||||
import ch.psi.fda.model.v1.Scan;
|
||||
import ch.psi.fda.model.v1.ScriptAction;
|
||||
import ch.psi.fda.model.v1.ShellAction;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.util.ComparatorAND;
|
||||
import ch.psi.jcae.util.ComparatorOR;
|
||||
import ch.psi.jcae.util.ComparatorREGEX;
|
||||
|
||||
/**
|
||||
* Mapper to transform a FDA v1 xml into the new internal model
|
||||
*
|
||||
*/
|
||||
public class ScanMapperNG {
|
||||
|
||||
// Reserved resource id's
|
||||
private static final String PROBE_RESOURCE_ID = "probe";
|
||||
private static final String SHELL_RESOURCE_ID = "shell";
|
||||
// "logger" is also a special variable as it is bound to the logger of the application!
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ScanMapperNG.class.getName());
|
||||
|
||||
private static final String INDENT = " ";
|
||||
|
||||
private StringBuilder script = new StringBuilder();
|
||||
private Set<String> imports = new HashSet<>();
|
||||
private Map<String, Object> resourceDescriptors = new HashMap<>();
|
||||
|
||||
private ProbeDescriptor probeDescriptor = new ProbeDescriptor();
|
||||
private DataMessageMetadata dataMessageMetadata = new DataMessageMetadata();
|
||||
|
||||
|
||||
private String indentation = "";
|
||||
|
||||
public void map(Configuration configuration) {
|
||||
|
||||
// Clear object state
|
||||
script = new StringBuilder();
|
||||
imports = new HashSet<>();
|
||||
resourceDescriptors = new HashMap<>();
|
||||
probeDescriptor = new ProbeDescriptor();
|
||||
|
||||
resourceDescriptors.put(PROBE_RESOURCE_ID, probeDescriptor);
|
||||
|
||||
Scan scan = configuration.getScan();
|
||||
mapActions(scan.getPreAction());
|
||||
|
||||
// Bring the dimensions into the correct order and then map them
|
||||
// to the script
|
||||
List<Dimension> dimensions = new ArrayList<>();
|
||||
int size = scan.getDimension().size();
|
||||
for (int i = size - 1; i >= 0; i--) {
|
||||
dimensions.add(scan.getDimension().get(i));
|
||||
}
|
||||
// Continuous dimensions are always at the very end
|
||||
if (scan.getCdimension() != null) {
|
||||
dimensions.add(scan.getCdimension());
|
||||
}
|
||||
mapDimensions(dimensions, 0);
|
||||
|
||||
// map
|
||||
mapActions(scan.getPostAction());
|
||||
|
||||
// TODO CONSIDER TO PROVIDE RESOURCE MAP AND SCRIPT IN ONE OBJECT AS
|
||||
// RETURN TYPE
|
||||
// WOULD MAKE MORE SENSE
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the generated script
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public String getScript() {
|
||||
StringBuilder scriptlines = new StringBuilder();
|
||||
for (String s : imports) {
|
||||
scriptlines.append(s + "\n");
|
||||
}
|
||||
scriptlines.append(script);
|
||||
return scriptlines.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get map of required resources
|
||||
* @return
|
||||
*/
|
||||
public Map<String, Object> getResourceDescriptors(){
|
||||
return resourceDescriptors;
|
||||
}
|
||||
|
||||
/**
|
||||
* TODO need to be moved somewhere else
|
||||
* @return
|
||||
*/
|
||||
public DataMessageMetadata getDataMessageMetadata(){
|
||||
return dataMessageMetadata;
|
||||
}
|
||||
|
||||
private void mapDimensions(List<Dimension> dimensions, int index) {
|
||||
|
||||
if(dimensions.size()<1){
|
||||
logger.info("There are no dimensions to map");
|
||||
return;
|
||||
}
|
||||
|
||||
Dimension dimension = dimensions.get(index);
|
||||
if (dimension instanceof DiscreteStepDimension) {
|
||||
DiscreteStepDimension d = (DiscreteStepDimension) dimension;
|
||||
|
||||
mapActions(d.getPreAction());
|
||||
|
||||
List<String> actuators = new ArrayList<>();
|
||||
|
||||
for(DiscreteStepPositioner positioner: d.getPositioner()){
|
||||
Class<?> type = String.class;
|
||||
switch (positioner.getType()) {
|
||||
case "Integer":
|
||||
type = Integer.class;
|
||||
break;
|
||||
case "Double":
|
||||
type = Double.class;
|
||||
break;
|
||||
}
|
||||
|
||||
String var = getChannelResourceVariable(positioner.getName(), type, false);
|
||||
actuators.add(var);
|
||||
|
||||
// Readback
|
||||
if(positioner.getReadback()==null){
|
||||
probeDescriptor.getSensors().add(new ChannelDescriptor<>(type, positioner.getName(), false));
|
||||
}
|
||||
else{
|
||||
// Use readback
|
||||
probeDescriptor.getSensors().add(new ChannelDescriptor<>(type, positioner.getReadback(), false));
|
||||
}
|
||||
// System.out.println(positioner.getId());
|
||||
dataMessageMetadata.getComponents().add(new ComponentMetadata(positioner.getId(), (dimensions.size()-1-index)));
|
||||
|
||||
// TODO Done resource
|
||||
|
||||
|
||||
if(positioner instanceof LinearPositioner){
|
||||
// Calculate steps and add it to position array
|
||||
LinearPositioner lpositioner = (LinearPositioner) positioner;
|
||||
boolean first = true;
|
||||
StringBuffer b = new StringBuffer();
|
||||
b.append("[");
|
||||
for(double i=0;(lpositioner.getStart()+i*lpositioner.getStepSize())<=lpositioner.getEnd();i++){
|
||||
if(first){
|
||||
first=false;
|
||||
}
|
||||
else{
|
||||
b.append(",");
|
||||
}
|
||||
b.append(String.format("%f", (lpositioner.getStart()+i*lpositioner.getStepSize())));
|
||||
}
|
||||
b.append("]");
|
||||
script.append(indentation + var+"_positions="+b.toString()+"\n");
|
||||
}
|
||||
else if(positioner instanceof ArrayPositioner){
|
||||
ArrayPositioner apositioner = (ArrayPositioner) positioner;
|
||||
// Calculate positions
|
||||
String[] positions = apositioner.getPositions().trim().split(" +");
|
||||
boolean first = true;
|
||||
StringBuffer b = new StringBuffer();
|
||||
b.append("[");
|
||||
for(String po: positions){
|
||||
if(first){
|
||||
first=false;
|
||||
}
|
||||
else{
|
||||
b.append(",");
|
||||
}
|
||||
|
||||
b.append(getPythonValue(po, type));
|
||||
}
|
||||
b.append("]");
|
||||
script.append(indentation + var+"_positions="+b.toString()+"\n");
|
||||
}
|
||||
else if(positioner instanceof FunctionPositioner){
|
||||
// TODO take variable mappings into account !
|
||||
}
|
||||
else if(positioner instanceof PseudoPositioner){
|
||||
// TODO implement
|
||||
}
|
||||
else if(positioner instanceof RegionPositioner){
|
||||
// TODO implement
|
||||
}
|
||||
}
|
||||
|
||||
// Create dimension loop
|
||||
String v = getUniqueVariableName();
|
||||
script.append(indentation + "for "+v+"_idx ,"+v+"_pos in enumerate("+actuators.get(0)+"_positions):\n");
|
||||
indentation = indentation + INDENT;
|
||||
|
||||
// Set all actuators of this dimension
|
||||
for(String a: actuators){
|
||||
script.append(indentation + a+".setValue("+a+"_positions["+v+"_idx])\n");
|
||||
}
|
||||
|
||||
// Add all actions executed between actuator and sensors
|
||||
mapActions(d.getAction());
|
||||
|
||||
// TODO map guard and sensors
|
||||
|
||||
|
||||
// Check whether final dimension reached
|
||||
if ((index + 1) < dimensions.size()) {
|
||||
// Map next dimension
|
||||
mapDimensions(dimensions, (index + 1));
|
||||
}
|
||||
else{
|
||||
// Final dimension reached - readout probe
|
||||
script.append(indentation + PROBE_RESOURCE_ID+".read()\n");
|
||||
}
|
||||
|
||||
indentation = indentation.replaceFirst(INDENT, ""); // decrease indentation
|
||||
|
||||
|
||||
script.append(indentation + PROBE_RESOURCE_ID+".delimiter("+(dimensions.size()-1-index)+", "+(d.isDataGroup()?"True":"False")+")\n");
|
||||
// send delimiter for this dimension
|
||||
// if lowest dimension end of stream message
|
||||
// if highest dimension no delimiter
|
||||
if(index==0){
|
||||
script.append(indentation + PROBE_RESOURCE_ID+".terminateStream()\n");
|
||||
}
|
||||
|
||||
mapActions(d.getPostAction());
|
||||
} else if (dimension instanceof ContinuousDimension) {
|
||||
// ContinuousDimension d = (ContinuousDimension) dimension;
|
||||
// TODO Map continuous dimension
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void mapActions(List<Action> actions) {
|
||||
for (Action action : actions) {
|
||||
if (action instanceof ChannelAction) {
|
||||
ChannelAction ca = (ChannelAction) action;
|
||||
Class<?> type = String.class;
|
||||
long waitTimeout=1800000; // Max wait timeout is 30 minutes
|
||||
if(ca.getTimeout()!=null){
|
||||
waitTimeout = ca.getTimeout().longValue()*1000; // wait timeout is currently in seconds
|
||||
}
|
||||
ca.getTimeout();
|
||||
switch (ca.getType()) {
|
||||
case "Integer":
|
||||
type = Integer.class;
|
||||
break;
|
||||
case "Double":
|
||||
type = Double.class;
|
||||
break;
|
||||
}
|
||||
String var = getChannelResourceVariable(ca.getChannel(), type, false);
|
||||
switch (ca.getOperation()) {
|
||||
case "put":
|
||||
if(ca.getTimeout()==null){
|
||||
script.append(var+".setValue("+getPythonValue(ca.getValue(), type)+")\n");
|
||||
} else {
|
||||
imports.add("from java.util.concurrent import TimeUnit");
|
||||
script.append(var+".setValueAsync("+getPythonValue(ca.getValue(), type)+").get("+ca.getTimeout()+", TimeUnit.MILLISECONDS)\n");
|
||||
}
|
||||
break;
|
||||
case "putq":
|
||||
script.append(var+".setValueNoWait("+getPythonValue(ca.getValue(), type)+")\n");
|
||||
break;
|
||||
case "wait":
|
||||
script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+waitTimeout+")\n");
|
||||
break;
|
||||
case "waitREGEX":
|
||||
imports.add("from"+ComparatorREGEX.class.getPackage().getName()+" import "+ComparatorREGEX.class.getName());
|
||||
script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+ComparatorREGEX.class.getName()+"() "+waitTimeout+")\n");
|
||||
break;
|
||||
case "waitOR":
|
||||
imports.add("from"+ComparatorOR.class.getPackage().getName()+" import "+ComparatorOR.class.getName());
|
||||
script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+ComparatorOR.class.getName()+"() "+waitTimeout+")\n");
|
||||
break;
|
||||
case "waitAND":
|
||||
imports.add("from"+ComparatorAND.class.getPackage().getName()+" import "+ComparatorAND.class.getName());
|
||||
script.append(var+".waitForValue("+getPythonValue(ca.getValue(), type)+", "+ComparatorAND.class.getName()+"() "+waitTimeout+")\n");
|
||||
break;
|
||||
default:
|
||||
logger.warning("Operation - "+ca.getOperation()+" - is not supported");
|
||||
// TODO Eventually throw exception - have two modes one logging, one exception?
|
||||
break;
|
||||
}
|
||||
|
||||
// If delay is specified wait specified time
|
||||
if (ca.getDelay() != null) {
|
||||
imports.add("import time");
|
||||
script.append("time.sleep(" + (ca.getDelay()) + ")\n");
|
||||
}
|
||||
|
||||
} else if (action instanceof ShellAction) {
|
||||
ShellAction saction = (ShellAction) action;
|
||||
resourceDescriptors.put(SHELL_RESOURCE_ID, new ShellDescriptor());
|
||||
// TODO Need to indicate that shell resource is required
|
||||
script.append(indentation + String.format(SHELL_RESOURCE_ID+".execute('%s', %d, %s)\n", saction.getCommand(), saction.getExitValue(), saction.isCheckExitValue()?"True":"False"));
|
||||
} else if (action instanceof ScriptAction) {
|
||||
ScriptAction saction = (ScriptAction) action;
|
||||
|
||||
// TODO Need to indicate that that mapped resources are required
|
||||
// Read script line by line and prepend the current indentation
|
||||
// level
|
||||
String[] lines = saction.getScript().split(System.getProperty("line.separator"));
|
||||
for (String s : lines) {
|
||||
script.append(indentation + s+"\n");
|
||||
}
|
||||
script.append(indentation + "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get unique variable names that do not collide with others. (at least have
|
||||
* an extreme unlikeness to do so)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
private String getUniqueVariableName() {
|
||||
return "v" + UUID.randomUUID().toString().replaceAll("-", "");
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the string representation for a variable in python
|
||||
* i.e. surrounds String with '', ensures that double has a . in the value, ...
|
||||
* @param value
|
||||
* @param type
|
||||
* @return
|
||||
*/
|
||||
private String getPythonValue(String value, Class<?> type){
|
||||
if(type.equals(String.class)){
|
||||
return "'"+value+"'";
|
||||
}
|
||||
else if(type.equals(Double.class)){
|
||||
return String.format("%f", new Double(value));
|
||||
}
|
||||
else if(type.equals(Integer.class)){
|
||||
return String.format("%d", new Integer(value));
|
||||
}
|
||||
return value.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* Request resource
|
||||
*
|
||||
* @param resourceId
|
||||
* @return variable name for resource
|
||||
*
|
||||
* TODO Eventually we need to add type of resource here to be able
|
||||
* to generate the resource before the script is executed.
|
||||
*/
|
||||
private String getChannelResourceVariable(String channelName, Class<?> type, boolean monitor) {
|
||||
// Right now each a new channel object will be created for each requirested channel resource (even it is the same channel)
|
||||
// TODO Optimize the resource consumption by checking whether the resource already exists and return only one reference.
|
||||
String varname = getUniqueVariableName();
|
||||
resourceDescriptors.put(varname, new ChannelDescriptor<>(type, channelName, monitor));
|
||||
return varname;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng.rdescriptors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ProbeDescriptor {
|
||||
|
||||
private List<ChannelDescriptor<?>> sensors = new ArrayList<>();
|
||||
|
||||
public List<ChannelDescriptor<?>> getSensors(){
|
||||
return sensors;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng.rdescriptors;
|
||||
|
||||
/**
|
||||
* Resource descriptor of an operating system shell.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ShellDescriptor {
|
||||
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng.resources;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.messages.StreamDelimiterMessage;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelProbeResource {
|
||||
|
||||
private final List<Channel<?>> channels;
|
||||
private BlockingQueue<Message> queue;
|
||||
|
||||
public ChannelProbeResource(List<Channel<?>> channels, BlockingQueue<Message> queue){
|
||||
this.channels = channels;
|
||||
this.queue = queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read configured channels and send out data message
|
||||
*/
|
||||
public void read(){
|
||||
try{
|
||||
DataMessage message = new DataMessage();
|
||||
for(Channel<?> sensor: channels){
|
||||
// Readout sensor
|
||||
Object o = sensor.getValue();
|
||||
// Add sensor data item to message
|
||||
message.getData().add(o);
|
||||
}
|
||||
System.out.println("MESSAGE: "+message);
|
||||
queue.put(message);
|
||||
} catch (InterruptedException | TimeoutException | ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a stream delimiter message for the given index
|
||||
* @param index
|
||||
* @param iflag
|
||||
*/
|
||||
public void delimiter(int index, boolean iflag){
|
||||
try {
|
||||
StreamDelimiterMessage message = new StreamDelimiterMessage(index, iflag);
|
||||
System.out.println(message);
|
||||
queue.put(message);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to send delimiter message", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Send end of stream message
|
||||
*/
|
||||
public void terminateStream(){
|
||||
try {
|
||||
EndOfStreamMessage message = new EndOfStreamMessage();
|
||||
System.out.println(message);
|
||||
queue.put(message);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to send end of stream message", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,73 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2013 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.aq.ng.resources;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ShellResource {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(ShellResource.class.getName());
|
||||
|
||||
/**
|
||||
* Execute script/command in shell
|
||||
* @param script
|
||||
*/
|
||||
public void execute(String script){
|
||||
execute(script, 0, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute script/command in shell
|
||||
* @param script
|
||||
* @param returnValue
|
||||
* @param checkReturnValue
|
||||
*/
|
||||
public void execute(String script, int returnValue, boolean checkReturnValue){
|
||||
ProcessBuilder pb = new ProcessBuilder(new String[]{"/bin/bash","-c",script});
|
||||
pb.redirectErrorStream(true);
|
||||
|
||||
try {
|
||||
Process p = pb.start();
|
||||
int rvalue = p.waitFor();
|
||||
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
|
||||
String line = null;
|
||||
while((line=reader.readLine()) != null){
|
||||
logger.info(line);
|
||||
}
|
||||
|
||||
// Check return value if need to be checked
|
||||
if(checkReturnValue){
|
||||
if(rvalue != returnValue){
|
||||
throw new RuntimeException("Executing script "+script+" failed");
|
||||
}
|
||||
}
|
||||
} catch (IOException | InterruptedException e) {
|
||||
throw new RuntimeException("Unable to execute script", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,46 +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;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public interface Action {
|
||||
|
||||
/**
|
||||
* Execute logic of the action
|
||||
*/
|
||||
public void execute() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Abort the execution logic of the action
|
||||
*/
|
||||
public void abort();
|
||||
|
||||
/**
|
||||
* Destroy action.
|
||||
* Can be used for the cleanup of used resources of the action (e.g. to close connections, ...) if
|
||||
* this cannot be done automatically by the GarbageCollector.
|
||||
*
|
||||
* After calling this method the action must not be executed any more!
|
||||
*/
|
||||
public void destroy();
|
||||
}
|
||||
@@ -1,69 +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;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
|
||||
/**
|
||||
* Loop of actions to accomplish a task. Depending on the loop
|
||||
* actions may be executed in a different way.
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public interface ActionLoop extends Action {
|
||||
|
||||
/**
|
||||
* Prepare ActionLoop for execution.
|
||||
*/
|
||||
public void prepare();
|
||||
|
||||
/**
|
||||
* Cleanup resources used by this ActionLoop while it was executed.
|
||||
*/
|
||||
public void cleanup();
|
||||
|
||||
/**
|
||||
* Get the pre actions of the Loop
|
||||
* @return pre actions
|
||||
*/
|
||||
public List<Action> getPreActions();
|
||||
|
||||
/**
|
||||
* Get the post actions of the loop
|
||||
* @return post actions
|
||||
*/
|
||||
public List<Action> getPostActions();
|
||||
|
||||
/**
|
||||
* @return is a datagroup
|
||||
*/
|
||||
public boolean isDataGroup();
|
||||
|
||||
/**
|
||||
* Set whether data of the loop belongs to a own data group
|
||||
* @param dataGroup
|
||||
*/
|
||||
public void setDataGroup(boolean dataGroup);
|
||||
|
||||
public DataQueue getDataQueue();
|
||||
}
|
||||
@@ -1,64 +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;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public interface Actor {
|
||||
/**
|
||||
* Set actor value
|
||||
*/
|
||||
public void set() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Function to check whether the actor has a next set value
|
||||
* @return Returns true if there is an actor value for the next iteration.
|
||||
* False if there is no actor value (i.e. this will be the last iteration in the ActionLoop)
|
||||
*/
|
||||
public boolean hasNext();
|
||||
|
||||
/**
|
||||
* Initialize the actor to the start
|
||||
*/
|
||||
public void init();
|
||||
|
||||
/**
|
||||
* Reverse the set values of the actor
|
||||
*/
|
||||
public void reverse();
|
||||
|
||||
/**
|
||||
* Reset the actuator to its initial configuration
|
||||
*/
|
||||
public void reset();
|
||||
|
||||
|
||||
/**
|
||||
* Destroy action.
|
||||
* Can be used for the cleanup of used resources of the actor (e.g. to close connections, ...) if
|
||||
* this cannot be done automatically by the GarbageCollector.
|
||||
*
|
||||
* After calling this method the actor must not be used any more!
|
||||
*/
|
||||
public void destroy();
|
||||
}
|
||||
@@ -1,47 +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;
|
||||
|
||||
import java.util.concurrent.Callable;
|
||||
|
||||
/**
|
||||
* Callable used for parallel execution of the set method of an actor
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ActorSetCallable implements Callable<Object> {
|
||||
|
||||
// Callable actor
|
||||
private Actor actor;
|
||||
|
||||
public ActorSetCallable(Actor actor){
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.util.concurrent.Callable#call()
|
||||
*/
|
||||
@Override
|
||||
public Object call() throws Exception {
|
||||
actor.set();
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,87 +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;
|
||||
|
||||
/**
|
||||
* Singleton object for holing the core engine configuration
|
||||
*
|
||||
* @author ebner
|
||||
*/
|
||||
public class EngineConfiguration {
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the engine should fail if there is an error while reading out a sensor.
|
||||
*/
|
||||
private boolean failOnSensorError = true;
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the set value of the actor should be verified after the set operation.
|
||||
* Having this flag on true will enable detecting for example that a motor hit the end switch or
|
||||
* did not move correctly.
|
||||
*/
|
||||
private boolean checkActorSet = true;
|
||||
|
||||
/**
|
||||
* Singleton instance
|
||||
*/
|
||||
private final static EngineConfiguration instance = new EngineConfiguration();
|
||||
|
||||
|
||||
|
||||
private EngineConfiguration(){
|
||||
}
|
||||
|
||||
/**
|
||||
* Get singleton instance of this class
|
||||
* @return Engine configuration
|
||||
*/
|
||||
public static EngineConfiguration getInstance(){
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the failOnSensorError
|
||||
*/
|
||||
public boolean isFailOnSensorError() {
|
||||
return failOnSensorError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param failOnSensorError the failOnSensorError to set
|
||||
*/
|
||||
public void setFailOnSensorError(boolean failOnSensorError) {
|
||||
this.failOnSensorError = failOnSensorError;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the checkActorSet
|
||||
*/
|
||||
public boolean isCheckActorSet() {
|
||||
return checkActorSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checkActorSet the checkActorSet to set
|
||||
*/
|
||||
public void setCheckActorSet(boolean checkActorSet) {
|
||||
this.checkActorSet = checkActorSet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,53 +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;
|
||||
|
||||
/**
|
||||
* Guard to protect specific activities. A guard can be used to check for environment changes while a
|
||||
* certain activity was executed.
|
||||
*
|
||||
* Example:
|
||||
* An Guard can be used to check whether an injection happened while the the detector were read.
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public interface Guard {
|
||||
|
||||
/**
|
||||
* Initialize guard object and its internal state.
|
||||
*/
|
||||
public void init();
|
||||
|
||||
/**
|
||||
* Check the status of the 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();
|
||||
}
|
||||
@@ -1,50 +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;
|
||||
|
||||
/**
|
||||
* The sensor interface describes an entity that can be read out like a
|
||||
* simple channel or (image) detector. Depending on the sensor type the
|
||||
* returned data is of a certain type.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public interface Sensor {
|
||||
/**
|
||||
* Readout sensor.
|
||||
* @return Sensor value. The type of the returned value depends on the sensor type.
|
||||
*/
|
||||
public Object read() throws InterruptedException;
|
||||
|
||||
/**
|
||||
* Get the global id of the 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();
|
||||
}
|
||||
@@ -1,163 +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.actions;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* Perform a put on the specified Channel Access channel. The put can be done
|
||||
* synchronous or asynchronously.
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessCondition<E> implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessCondition.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final Channel<E> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final E expectedValue;
|
||||
|
||||
private Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
private volatile Thread waitT = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param channelName
|
||||
* Name of the channel to set the value
|
||||
* @param expectedValue
|
||||
* Value to wait for
|
||||
* @param timeout
|
||||
* Timeout of the condition in milliseconds (null accepted - will
|
||||
* take default wait timeout for channels
|
||||
* ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException
|
||||
* Unable to initialize channel, Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessCondition(ChannelService s, String channelName, E expectedValue, Long timeout) {
|
||||
|
||||
if (timeout != null && timeout <= 0) {
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = (Channel<E>) s.createChannel(new ChannelDescriptor<>(expectedValue.getClass(), channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:" + channelName + "]", e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:" + channelName + "]", e);
|
||||
}
|
||||
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if (timeout == null) {
|
||||
// this.timeout = channel.get.getWaitTimeout();
|
||||
this.timeout=1L;
|
||||
} else {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException
|
||||
* Channel value did not reach expected value (within the
|
||||
* specified timeout period)
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
abort = false;
|
||||
logger.finest("Checking channel " + channel.getName() + " for value " + expectedValue + " [timeout: " + timeout + "]");
|
||||
try {
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValueAsync(expectedValue).get(timeout, TimeUnit.MILLISECONDS); // Workaround use
|
||||
// 10seconds default
|
||||
// set timeout to
|
||||
// check several
|
||||
// times whether the
|
||||
// channel has
|
||||
// reached the value
|
||||
} catch (InterruptedException e) {
|
||||
if (!abort) {
|
||||
throw e;
|
||||
}
|
||||
} catch (ExecutionException | TimeoutException | ChannelException e) {
|
||||
throw new RuntimeException("Channel [name:" + channel.getName() + "] did not reach expected value " + expectedValue + " ", e);
|
||||
} finally {
|
||||
waitT = null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort = true;
|
||||
if (waitT != null) {
|
||||
waitT.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
logger.finest("Destroy action channel: " + channel.getName());
|
||||
try {
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel [" + channel.getName() + "]", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,159 +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.actions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
|
||||
* asynchronously.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessConditionAnd<E extends Integer> implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessConditionAnd.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final Channel<E> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final E expectedValue;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
private volatile Thread waitT = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param expectedValue Value to wait for
|
||||
* @param timeout Timeout of the condition in milliseconds (null accepted - will take default wait timeout for channels ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel,
|
||||
* Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessConditionAnd(ChannelService s, String channelName, E expectedValue, Long timeout){
|
||||
|
||||
if(timeout !=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = s.createChannel(new ChannelDescriptor<>( (Class<E>) expectedValue.getClass(), channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if(timeout==null){
|
||||
// this.timeout = channel.getWaitTimeout();
|
||||
this.timeout = 0L;
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Channel value did not reach expected value (within the specified timeout period)
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
abort=false;
|
||||
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
|
||||
try{
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValue(expectedValue, new Comparator<E>() {
|
||||
|
||||
@Override
|
||||
public int compare(E o1, E o2) {
|
||||
int one = o1;
|
||||
int two = o2;
|
||||
if((one & two) != 0){
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} catch(InterruptedException e){
|
||||
if(!abort){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
finally{
|
||||
waitT=null;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
if(waitT!=null){
|
||||
waitT.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,159 +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.actions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
|
||||
* asynchronously.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessConditionOr<E extends Integer> implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessConditionOr.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final Channel<E> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final E expectedValue;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
private volatile Thread waitT = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param expectedValue Value to wait for
|
||||
* @param timeout Timeout of the condition in milliseconds (null accepted - will take default wait timeout for channels ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel,
|
||||
* Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessConditionOr(ChannelService s, String channelName, E expectedValue, Long timeout){
|
||||
|
||||
if(timeout !=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = s.createChannel(new ChannelDescriptor<>( (Class<E>) expectedValue.getClass(), channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if(timeout==null){
|
||||
// this.timeout = channel.getWaitTimeout();
|
||||
this.timeout = 0L;
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Channel value did not reach expected value (within the specified timeout period)
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
abort=false;
|
||||
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
|
||||
try{
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValue(expectedValue, new Comparator<E>() {
|
||||
|
||||
@Override
|
||||
public int compare(E o1, E o2) {
|
||||
int one = o1;
|
||||
int two = o2;
|
||||
if((one | two) != 0){
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} catch(InterruptedException e){
|
||||
if(!abort){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
finally{
|
||||
waitT=null;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
if(waitT!=null){
|
||||
waitT.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,153 +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.actions;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
|
||||
* asynchronously.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessConditionRegex<E extends String> implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessConditionRegex.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final Channel<E> channel;
|
||||
/**
|
||||
* Value to wait for
|
||||
*/
|
||||
private final E expectedValue;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
private volatile boolean abort = false;
|
||||
private volatile Thread waitT = null;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param expectedValue Value to wait for
|
||||
* @param timeout Timeout of the condition in milliseconds (null accepted - will take default wait timeout for channels ch.psi.jcae.ChannelBeanFactory.waitTimeout)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel,
|
||||
* Timeout specified is not >=0
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessConditionRegex(ChannelService s, String channelName, E expectedValue, Long timeout){
|
||||
|
||||
if(timeout !=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be > 0");
|
||||
}
|
||||
|
||||
try {
|
||||
this.channel = s.createChannel(new ChannelDescriptor<>( (Class<E>) expectedValue.getClass(), channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.expectedValue = expectedValue;
|
||||
|
||||
if(timeout==null){
|
||||
// this.timeout = channel.getWaitTimeout();
|
||||
this.timeout = 0L;
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Channel value did not reach expected value (within the specified timeout period)
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
abort=false;
|
||||
logger.finest("Checking channel "+channel.getName()+" for value "+expectedValue+" [timeout: "+timeout+"]" );
|
||||
try{
|
||||
waitT = Thread.currentThread();
|
||||
channel.waitForValue(expectedValue, new Comparator<E>() {
|
||||
|
||||
@Override
|
||||
public int compare(E o1, E o2) {
|
||||
return o1.matches(o2) ? 0:1;
|
||||
}
|
||||
}, timeout); // Workaround use 10seconds default set timeout to check several times whether the channel has reached the value
|
||||
} catch (ChannelException | ExecutionException e) {
|
||||
throw new RuntimeException("Channel [name:"+channel.getName()+"] did not reach expected value "+expectedValue+" ", e);
|
||||
} catch(InterruptedException e){
|
||||
if(!abort){
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
finally{
|
||||
waitT=null;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
if(waitT!=null){
|
||||
waitT.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,146 +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.actions;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* Perform a put on the specified Channel Access channel. The put can be done synchronous or
|
||||
* asynchronously.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessPut<E> implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessPut.class.getName());
|
||||
|
||||
/**
|
||||
* Channel to set
|
||||
*/
|
||||
private final Channel<E> channel;
|
||||
/**
|
||||
* Value to set
|
||||
*/
|
||||
private final E value;
|
||||
/**
|
||||
* Put mode, true = fire and forget, false = wait for response
|
||||
*/
|
||||
private final boolean asynchronous;
|
||||
|
||||
private final Long timeout;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param value Value to set
|
||||
* @param asynchronous Flag whether to set the value synchronous (wait for response) or asynchronously (fire and forget)
|
||||
* @param timeout Timeout used for set operation (time that set need to come back)
|
||||
*
|
||||
* @throws IllegalArgumentException Unable to initialize channel
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessPut(ChannelService s, String channelName, E value, boolean asynchronous, Long timeout){
|
||||
|
||||
try {
|
||||
this.channel = s.createChannel(new ChannelDescriptor<>((Class<E>)value.getClass(), channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
this.value = value;
|
||||
this.asynchronous = asynchronous;
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Additional constructor for convenience. This constructor defaults the operation type to synchronous put.
|
||||
* @param channelName Name of the channel to set the value
|
||||
* @param value Value to set
|
||||
*
|
||||
* @throws RuntimeException Unable to initialize channel
|
||||
*/
|
||||
public ChannelAccessPut(ChannelService s, String channelName, E value){
|
||||
this(s, channelName, value, false, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Cannot set value on channel
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
logger.finest("Put to channel: "+channel.getName()+ " asynchronous: "+asynchronous);
|
||||
try{
|
||||
if(asynchronous){
|
||||
channel.setValueNoWait(value);
|
||||
}
|
||||
else{
|
||||
if(timeout==null){
|
||||
channel.setValue(value);
|
||||
}
|
||||
else{
|
||||
channel.setValueAsync(value).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
} catch (ChannelException | ExecutionException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to set channel [name:"+channel.getName()+"] to value "+value, e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
// This action cannot be aborted, therefore this method is not implemented
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy action channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,74 +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.actions;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
|
||||
/**
|
||||
* Wait a specific time until executing the next action ...
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class Delay implements Action {
|
||||
|
||||
/**
|
||||
* Time to wait
|
||||
*/
|
||||
private final long time;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param time Time to wait (in milliseconds)
|
||||
*/
|
||||
public Delay(long time){
|
||||
|
||||
// Check if delay time is positive and >0
|
||||
if(time<=0){
|
||||
throw new IllegalArgumentException("Wait time must be >0");
|
||||
}
|
||||
|
||||
this.time = time;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
Thread.sleep(time);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
// Not implemented because not needed
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,170 +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.actions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMapping;
|
||||
import ch.psi.fda.core.scripting.JythonParameterMappingChannel;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class JythonAction implements Action {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(JythonAction.class.getName());
|
||||
|
||||
/**
|
||||
* Pattern of the entry function of the jython script
|
||||
*/
|
||||
private static final String entryFunction = "process";
|
||||
private static final String entryFunctionPattern = "def "+entryFunction+"\\((.*)\\):";
|
||||
|
||||
/**
|
||||
* Script engine of the manipulator
|
||||
*/
|
||||
private ScriptEngine engine;
|
||||
|
||||
/**
|
||||
* Jython entry call
|
||||
*/
|
||||
private String jythonCall;
|
||||
|
||||
public JythonAction(ChannelService s, String script, List<JythonParameterMappingChannel> mapping){
|
||||
|
||||
// Workaround for Jython memory leak
|
||||
// http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/
|
||||
System.setProperty("python.options.internalTablesImpl","weak");
|
||||
|
||||
// Create new script engine
|
||||
this.engine = new ScriptEngineManager().getEngineByName("python");
|
||||
|
||||
// Determine script entry function and the function parameters
|
||||
Pattern pattern = Pattern.compile(entryFunctionPattern);
|
||||
Matcher matcher = pattern.matcher(script);
|
||||
String[] functionParameters = null;
|
||||
if(matcher.find() && matcher.groupCount()==1){
|
||||
logger.finest("Entry function '"+entryFunctionPattern+"' found - Identified parameters: "+matcher.group(1));
|
||||
functionParameters = matcher.group(1).split(" *, *");
|
||||
}
|
||||
else{
|
||||
throw new IllegalArgumentException("Cannot determine entry function: "+entryFunctionPattern);
|
||||
}
|
||||
|
||||
// Check whether all function parameters have a mapping
|
||||
for(int i=0;i<functionParameters.length; i++){
|
||||
String p = functionParameters[i];
|
||||
p = p.trim();
|
||||
boolean found = false;
|
||||
for(JythonParameterMapping pm: mapping){
|
||||
if(pm.getVariable().equals(p)){
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(!found){
|
||||
throw new IllegalArgumentException("No mapping compontent found for parameter "+p);
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether more mappings are specified than function parameters
|
||||
if(functionParameters.length<mapping.size()){
|
||||
throw new IllegalArgumentException("More mappings than function parameters are specified");
|
||||
}
|
||||
|
||||
// Load manipulation script
|
||||
try {
|
||||
engine.eval(script);
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException("Unable to load manipulation script", e);
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(entryFunction);
|
||||
buffer.append("(");
|
||||
for(JythonParameterMappingChannel b: mapping){
|
||||
// Create channel
|
||||
|
||||
Channel<?> cb;
|
||||
try {
|
||||
cb = s.createChannel(new ChannelDescriptor<>(b.getType(), b.getChannel(), true));
|
||||
} catch (TimeoutException | ChannelException e) {
|
||||
throw new IllegalArgumentException("Unable to establish channel: "+b.getChannel(), e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to establish channel: "+b.getChannel(), e);
|
||||
}
|
||||
|
||||
// Assign channel bean to variable
|
||||
engine.put(b.getVariable(), cb);
|
||||
|
||||
buffer.append(b.getVariable());
|
||||
buffer.append(",");
|
||||
}
|
||||
buffer.setCharAt(buffer.length()-1, ')');
|
||||
|
||||
jythonCall = buffer.toString();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() {
|
||||
try {
|
||||
engine.eval(jythonCall);
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException("Action failed while executing the Jython script",e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
// TODO need to find a way to abort script execution
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,174 +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.actions;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
|
||||
/**
|
||||
* Action that executes a specified script when it is executed.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ShellAction implements Action{
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ShellAction.class.getName());
|
||||
|
||||
private volatile Process process;
|
||||
private volatile boolean abort = false;
|
||||
private boolean checkExitValue = true;
|
||||
private int exitValue = 0;
|
||||
|
||||
/**
|
||||
* Name (full path if it is not in the system path) of the script to execute when
|
||||
* the execute() function of this action is invoked.
|
||||
*/
|
||||
private final String script;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param script Name of the script to execute when this action is invoked
|
||||
*
|
||||
* @throws IllegalArgumentException Specified script does not exist
|
||||
*/
|
||||
public ShellAction(String script){
|
||||
String[] scri = script.split("[ ,\t]");
|
||||
File s = new File(scri[0]);
|
||||
if(!s.exists()){
|
||||
throw new IllegalArgumentException("Script "+script+" does not exist.");
|
||||
}
|
||||
this.script = script;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
/**
|
||||
* @throws InterruptedException
|
||||
* @throws RuntimeException Script did not exit with 0,
|
||||
* Execution was interrupted,
|
||||
* IO problem occurred
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
try{
|
||||
abort = false;
|
||||
logger.fine("Execute script "+script);
|
||||
process = Runtime.getRuntime().exec(new String[]{"/bin/bash","-c",script});
|
||||
int exitVal = process.waitFor();
|
||||
|
||||
// Log output of the shell script if loglevel is finest
|
||||
if(logger.isLoggable(Level.FINEST)){
|
||||
logger.finest("STDOUT [BEGIN]");
|
||||
// TODO The readout of the stream should be in parallel to the processing of the script! I.e. the output appears in the log as it is generated by the script!
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
||||
String line = null;
|
||||
while((line=reader.readLine()) != null){
|
||||
logger.finest(line);
|
||||
}
|
||||
logger.finest("STDOUT [END]");
|
||||
|
||||
logger.finest("STDERR [BEGIN]");
|
||||
// TODO The readout of the stream should be in parallel to the processing of the script! I.e. the output appears in the log as it is generated by the script!
|
||||
reader = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
line = null;
|
||||
while((line=reader.readLine()) != null){
|
||||
logger.finest(line);
|
||||
}
|
||||
logger.finest("STDERR [END]");
|
||||
}
|
||||
|
||||
logger.fine("Script ["+script+"] return value: "+exitVal);
|
||||
|
||||
if(abort){
|
||||
throw new RuntimeException("Script ["+script+"] was aborted");
|
||||
}
|
||||
else{
|
||||
// Check script exit value to 0 if != 0 then throw an runtime exception
|
||||
if(checkExitValue && exitVal != exitValue){
|
||||
throw new RuntimeException("Script ["+script+"] returned with an exit value not equal to 0");
|
||||
}
|
||||
}
|
||||
process = null; // Ensure that the process is null
|
||||
}
|
||||
catch(IOException e){
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to execute script: "+script,e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort=true;
|
||||
// This action cannot be aborted, therefore this function is not implemented.
|
||||
if(process!=null){
|
||||
// Terminate process via kill
|
||||
process.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the checkExitValue
|
||||
*/
|
||||
public boolean isCheckExitValue() {
|
||||
return checkExitValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param checkExitValue the checkExitValue to set
|
||||
*/
|
||||
public void setCheckExitValue(boolean checkExitValue) {
|
||||
this.checkExitValue = checkExitValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the exitValue
|
||||
*/
|
||||
public int getExitValue() {
|
||||
return exitValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param exitValue the exitValue to set
|
||||
*/
|
||||
public void setExitValue(int exitValue) {
|
||||
this.exitValue = exitValue;
|
||||
}
|
||||
}
|
||||
@@ -1,353 +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.actors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* This actuator sets an Channel Access channel from a start to an end value by doing discrete steps.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessFunctionActuator<T> implements Actor {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessFunctionActuator.class.getName());
|
||||
|
||||
private boolean asynchronous = false;
|
||||
|
||||
/**
|
||||
* Start value of the actuator
|
||||
*/
|
||||
private double start;
|
||||
|
||||
/**
|
||||
* End value of the actuator
|
||||
*/
|
||||
private double end;
|
||||
|
||||
/**
|
||||
* Step size of the move
|
||||
*/
|
||||
private double stepSize;
|
||||
|
||||
/**
|
||||
* Move direction (start<end = 1, start>end = -1)
|
||||
*/
|
||||
private int direction;
|
||||
|
||||
/**
|
||||
* Execution count of actuator. This variable is used to minimize the floating point
|
||||
* rounding errors for calculating the next step.
|
||||
*/
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* Flag that indicates whether there is a next set value for the Actor
|
||||
*/
|
||||
private boolean next;
|
||||
|
||||
/**
|
||||
* Value to set at next @see ch.psi.fda.engine.Actor#set() call
|
||||
*/
|
||||
private double value;
|
||||
|
||||
/**
|
||||
* Level of accuracy the positioner need to have (e.g. if a positioner is set to 1 the readback set value
|
||||
* of the positioner need to have at lease 1+/-accuracy)
|
||||
* Default is stepSize/2
|
||||
*/
|
||||
private double accuracy;
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private Channel<Double> channel;
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private Channel<T> doneChannel = null;
|
||||
|
||||
private final T doneValue;
|
||||
private final long doneDelay;
|
||||
|
||||
private final double originalStart;
|
||||
private final double originalEnd;
|
||||
private final int originalDirection;
|
||||
|
||||
|
||||
/**
|
||||
* Move timeout
|
||||
*/
|
||||
private Long timeout;
|
||||
|
||||
private final Function function;
|
||||
|
||||
/**
|
||||
* Constructor - Initialize actor
|
||||
* @param channelName
|
||||
* @param start
|
||||
* @param end
|
||||
* @param stepSize
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
public ChannelAccessFunctionActuator(ChannelService s, String channelName, Function function, double start, double end, double stepSize, Long timeout){
|
||||
this(s, channelName, null, null, 0, function, start, end, stepSize, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName
|
||||
* @param doneChannelName If null actor will not wait (for this channel) to continue
|
||||
* @param doneValue
|
||||
* @param doneDelay Delay in seconds before checking the done channel
|
||||
* @param start
|
||||
* @param end
|
||||
* @param stepSize
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessFunctionActuator(ChannelService s, String channelName, String doneChannelName, T doneValue, double doneDelay, Function function, double start, double end, double stepSize, Long timeout){
|
||||
|
||||
this.doneValue = doneValue;
|
||||
this.doneDelay = (long) Math.floor((doneDelay*1000));
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
if(stepSize <= 0){
|
||||
throw new IllegalArgumentException("Step size ["+stepSize+"] must be > 0");
|
||||
}
|
||||
this.stepSize = stepSize;
|
||||
|
||||
this.accuracy = stepSize/2;
|
||||
|
||||
// Validate and save timeout parameter
|
||||
if(timeout!=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be >0 or null");
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
if(function==null){
|
||||
throw new IllegalArgumentException("Function must not be null");
|
||||
}
|
||||
this.function = function;
|
||||
|
||||
|
||||
init();
|
||||
|
||||
// Save original settings
|
||||
this.originalStart = start;
|
||||
this.originalEnd = end;
|
||||
this.originalDirection = direction;
|
||||
|
||||
|
||||
// Initialize/create Channel Access channel
|
||||
try {
|
||||
channel = s.createChannel(new ChannelDescriptor<>(Double.class, channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
if(doneChannelName != null){
|
||||
try {
|
||||
doneChannel = s.createChannel(new ChannelDescriptor<>((Class<T>)doneValue.getClass(), doneChannelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.Actor#set()
|
||||
*/
|
||||
@Override
|
||||
public void set() throws InterruptedException {
|
||||
|
||||
// Throw an IllegalStateException in the case that set is called although there is no next step.
|
||||
if(!next){
|
||||
throw new IllegalStateException("The actuator does not have any next step.");
|
||||
}
|
||||
|
||||
// Set actuator channel
|
||||
logger.finest("Set actuator channel "+channel.getName()+" to value: "+value);
|
||||
try {
|
||||
double fvalue = function.calculate(value);
|
||||
|
||||
if(!asynchronous){
|
||||
if(timeout==null){
|
||||
channel.setValue(fvalue);
|
||||
}
|
||||
else{
|
||||
channel.setValueAsync(fvalue).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
else{
|
||||
channel.setValueNoWait(fvalue);
|
||||
}
|
||||
|
||||
if(doneChannel != null){
|
||||
Thread.sleep(doneDelay);
|
||||
doneChannel.waitForValue(doneValue);
|
||||
}
|
||||
|
||||
// Check whether the set value is really on the value that was set before.
|
||||
if(EngineConfiguration.getInstance().isCheckActorSet()){
|
||||
double c = channel.getValue(true);
|
||||
double a = Math.abs( c - fvalue );
|
||||
if ( a > accuracy ){
|
||||
throw new RuntimeException("Actor could not be set to the value "+fvalue+" The readback of the set value does not match the value that was set [value: "+c+" delta: "+a+" accuracy: "+accuracy+"]");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ChannelException | ExecutionException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to move actuator [channel: "+channel.getName()+"] to value "+value,e);
|
||||
}
|
||||
|
||||
|
||||
count++;
|
||||
double nextValue = start+(count*stepSize*direction); // Done like this to keep floating point rounding errors minimal
|
||||
|
||||
if((direction==1&&nextValue<=end)||(direction==-1&nextValue>=end)){
|
||||
|
||||
// Apply function
|
||||
// nextValue = function.calculate(nextValue);
|
||||
|
||||
logger.fine("Next actor value: "+nextValue);
|
||||
value=nextValue;
|
||||
this.next = true;
|
||||
}
|
||||
else{
|
||||
// There is no next set value
|
||||
this.next = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.Actor#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
this.count = 0;
|
||||
|
||||
// Determine move direction
|
||||
this.direction = 1;
|
||||
if(start>end){
|
||||
direction=-1; // Move in negative direction
|
||||
}
|
||||
|
||||
|
||||
// Set first set value to the start value
|
||||
this.value = start;
|
||||
this.next = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reverse()
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reverse() {
|
||||
double oldStart = start;
|
||||
this.start = this.end;
|
||||
this.end = oldStart;
|
||||
|
||||
// Determine move direction
|
||||
this.direction = 1;
|
||||
if(this.start>this.end){
|
||||
direction=-1; // Move in negative direction
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
this.start = this.originalStart;
|
||||
this.end = this.originalEnd;
|
||||
this.direction = this.originalDirection;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy actor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
|
||||
// Destroy done channel if exists
|
||||
if(doneChannel != null){
|
||||
try {
|
||||
logger.finest("Destroy actor done channel: "+doneChannel.getName());
|
||||
doneChannel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the asynchronous
|
||||
*/
|
||||
public boolean isAsynchronous() {
|
||||
return asynchronous;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param asynchronous the asynchronous to set
|
||||
*/
|
||||
public void setAsynchronous(boolean asynchronous) {
|
||||
this.asynchronous = asynchronous;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,332 +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.actors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* This actuator sets an Channel Access channel from a start to an end value by doing discrete steps.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessLinearActuator<T> implements Actor {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessLinearActuator.class.getName());
|
||||
|
||||
private boolean asynchronous = false;
|
||||
|
||||
/**
|
||||
* Start value of the actuator
|
||||
*/
|
||||
private double start;
|
||||
|
||||
/**
|
||||
* End value of the actuator
|
||||
*/
|
||||
private double end;
|
||||
|
||||
/**
|
||||
* Step size of the move
|
||||
*/
|
||||
private double stepSize;
|
||||
|
||||
/**
|
||||
* Move direction (start<end = 1, start>end = -1)
|
||||
*/
|
||||
private int direction;
|
||||
|
||||
/**
|
||||
* Execution count of actuator. This variable is used to minimize the floating point
|
||||
* rounding errors for calculating the next step.
|
||||
*/
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* Flag that indicates whether there is a next set value for the Actor
|
||||
*/
|
||||
private boolean next;
|
||||
|
||||
/**
|
||||
* Value to set at next @see ch.psi.fda.engine.Actor#set() call
|
||||
*/
|
||||
private double value;
|
||||
|
||||
/**
|
||||
* Level of accuracy the positioner need to have (e.g. if a positioner is set to 1 the readback set value
|
||||
* of the positioner need to have at lease 1+/-accuracy)
|
||||
* Default is stepSize/2
|
||||
*/
|
||||
private double accuracy;
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private Channel<Double> channel;
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private Channel<T> doneChannel = null;
|
||||
|
||||
private final T doneValue;
|
||||
private final long doneDelay;
|
||||
|
||||
private final double originalStart;
|
||||
private final double originalEnd;
|
||||
private final int originalDirection;
|
||||
|
||||
|
||||
/**
|
||||
* Move timeout
|
||||
*/
|
||||
private Long timeout;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName
|
||||
* @param doneChannelName If null actor will not wait (for this channel) to continue
|
||||
* @param doneValue
|
||||
* @param doneDelay Delay in seconds before checking the done channel
|
||||
* @param start
|
||||
* @param end
|
||||
* @param stepSize
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessLinearActuator(ChannelService s, String channelName, String doneChannelName, T doneValue, double doneDelay, double start, double end, double stepSize, Long timeout){
|
||||
|
||||
this.doneValue = doneValue;
|
||||
this.doneDelay = (long) Math.floor((doneDelay*1000));
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
|
||||
if(stepSize <= 0){
|
||||
throw new IllegalArgumentException("Step size ["+stepSize+"] must be > 0");
|
||||
}
|
||||
this.stepSize = stepSize;
|
||||
|
||||
this.accuracy = stepSize/2;
|
||||
|
||||
// Validate and save timeout parameter
|
||||
if(timeout!=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be >0 or null");
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
|
||||
init();
|
||||
|
||||
// Save original settings
|
||||
this.originalStart = start;
|
||||
this.originalEnd = end;
|
||||
this.originalDirection = direction;
|
||||
|
||||
|
||||
// Initialize/create Channel Access channel
|
||||
try {
|
||||
channel = s.createChannel(new ChannelDescriptor<>(Double.class, channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
if(doneChannelName != null){
|
||||
try {
|
||||
doneChannel = s.createChannel(new ChannelDescriptor<>((Class<T>) doneValue.getClass(), doneChannelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.Actor#set()
|
||||
*/
|
||||
@Override
|
||||
public void set() throws InterruptedException {
|
||||
|
||||
// Throw an IllegalStateException in the case that set is called although there is no next step.
|
||||
if(!next){
|
||||
throw new IllegalStateException("The actuator does not have any next step.");
|
||||
}
|
||||
|
||||
// Set actuator channel
|
||||
logger.finest("Set actuator channel "+channel.getName()+" to value: "+value);
|
||||
try {
|
||||
|
||||
if(!asynchronous){
|
||||
if(timeout==null){
|
||||
channel.setValue(value);
|
||||
}
|
||||
else{
|
||||
channel.setValueAsync(value).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
else{
|
||||
channel.setValueNoWait(value);
|
||||
}
|
||||
|
||||
if(doneChannel != null){
|
||||
Thread.sleep(doneDelay);
|
||||
doneChannel.waitForValue(doneValue);
|
||||
}
|
||||
|
||||
// Check whether the set value is really on the value that was set before.
|
||||
if(EngineConfiguration.getInstance().isCheckActorSet()){
|
||||
double c = channel.getValue(true);
|
||||
double a = Math.abs( c - value );
|
||||
if ( a > accuracy ){
|
||||
throw new RuntimeException("Actor could not be set to the value "+value+" The readback of the set value does not match the value that was set [value: "+c+" delta: "+a+" accuracy: "+accuracy+"]");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ChannelException | TimeoutException | ExecutionException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Unable to move actuator [channel: "+channel.getName()+"] to value "+value,e);
|
||||
}
|
||||
|
||||
|
||||
count++;
|
||||
double nextValue = start+(count*stepSize*direction); // Done like this to keep floating point rounding errors minimal
|
||||
|
||||
if((direction==1&&nextValue<=end)||(direction==-1&nextValue>=end)){
|
||||
logger.fine("Next actor value: "+nextValue);
|
||||
value=nextValue;
|
||||
this.next = true;
|
||||
}
|
||||
else{
|
||||
// There is no next set value
|
||||
this.next = false;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.Actor#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
this.count = 0;
|
||||
|
||||
// Determine move direction
|
||||
this.direction = 1;
|
||||
if(start>end){
|
||||
direction=-1; // Move in negative direction
|
||||
}
|
||||
|
||||
|
||||
// Set first set value to the start value
|
||||
this.value = start;
|
||||
this.next = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reverse()
|
||||
*/
|
||||
@Override
|
||||
public synchronized void reverse() {
|
||||
double oldStart = start;
|
||||
this.start = this.end;
|
||||
this.end = oldStart;
|
||||
|
||||
// Determine move direction
|
||||
this.direction = 1;
|
||||
if(this.start>this.end){
|
||||
direction=-1; // Move in negative direction
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
this.start = this.originalStart;
|
||||
this.end = this.originalEnd;
|
||||
this.direction = this.originalDirection;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy actor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
|
||||
// Destroy done channel if exists
|
||||
if(doneChannel != null){
|
||||
try {
|
||||
logger.finest("Destroy actor done channel: "+doneChannel.getName());
|
||||
doneChannel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the asynchronous
|
||||
*/
|
||||
public boolean isAsynchronous() {
|
||||
return asynchronous;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param asynchronous the asynchronous to set
|
||||
*/
|
||||
public void setAsynchronous(boolean asynchronous) {
|
||||
this.asynchronous = asynchronous;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,317 +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.actors;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.EngineConfiguration;
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* This actuator sets an Channel Access channel by using the positions from the given table.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessTableActuator<T> implements Actor {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessTableActuator.class.getName());
|
||||
|
||||
private boolean asynchronous = false;
|
||||
|
||||
/**
|
||||
* Position table
|
||||
*/
|
||||
private final double[] table;
|
||||
|
||||
/**
|
||||
* Level of accuracy the positioner need to have (e.g. if a positioner is set to 1 the readback set value
|
||||
* of the positioner need to have at lease 1+/-accuracy)
|
||||
*/
|
||||
private double accuracy = 0.1;
|
||||
|
||||
/**
|
||||
* Execution count of actuator. This variable is used to minimize the floating point
|
||||
* rounding errors for calculating the next step.
|
||||
*/
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* Flag that indicates whether there is a next set value for the Actor
|
||||
*/
|
||||
private boolean next;
|
||||
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private Channel<Double> channel;
|
||||
|
||||
/**
|
||||
* Channel Access channel of the actuator
|
||||
*/
|
||||
private Channel<T> doneChannel = null;
|
||||
|
||||
private final T doneValue;
|
||||
private final long doneDelay;
|
||||
|
||||
/**
|
||||
* Flag that indicates whether the actor moves in the positive direction
|
||||
*/
|
||||
private boolean positiveDirection = true;
|
||||
private final boolean originalPositiveDirection;
|
||||
|
||||
/**
|
||||
* Maximum move time (in milliseconds)
|
||||
*/
|
||||
private Long timeout = null;
|
||||
|
||||
|
||||
/**
|
||||
* Constructor - Initialize actor
|
||||
* @param channelName Name of the channel to set
|
||||
* @param table Position table with the explicit positions for each step
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
public ChannelAccessTableActuator(ChannelService s, String channelName, double[] table, Long timeout){
|
||||
this(s, channelName, null, null, 0, table, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelName
|
||||
* @param doneChannelName
|
||||
* @param doneValue
|
||||
* @param doneDelay
|
||||
* @param table
|
||||
* @param timeout Maximum move time (in milliseconds)
|
||||
*/
|
||||
@SuppressWarnings("unchecked")
|
||||
public ChannelAccessTableActuator(ChannelService s, String channelName, String doneChannelName, T doneValue, double doneDelay, double[] table, Long timeout){
|
||||
|
||||
this.doneValue = doneValue;
|
||||
this.doneDelay = (long) Math.floor((doneDelay*1000));
|
||||
|
||||
if(table==null){
|
||||
throw new IllegalArgumentException("Null table is not accepted");
|
||||
}
|
||||
if(table.length==0){
|
||||
throw new IllegalArgumentException("Position table need to have at least one position");
|
||||
}
|
||||
|
||||
this.table = table;
|
||||
|
||||
// Validate and save timeout parameter
|
||||
if(timeout!=null && timeout<=0){
|
||||
throw new IllegalArgumentException("Timeout must be >0 or null");
|
||||
}
|
||||
else{
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
init();
|
||||
|
||||
// Save the initial direction
|
||||
this.originalPositiveDirection = positiveDirection;
|
||||
|
||||
// Initialize/create Channel Access channel
|
||||
try {
|
||||
channel = s.createChannel(new ChannelDescriptor<>(Double.class, channelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channelName+"]",e);
|
||||
}
|
||||
|
||||
if(doneChannelName != null){
|
||||
try {
|
||||
doneChannel = s.createChannel(new ChannelDescriptor<>((Class<T>)doneValue.getClass(), doneChannelName, false));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+doneChannelName+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.Actor#set()
|
||||
*/
|
||||
@Override
|
||||
public void set() throws InterruptedException {
|
||||
|
||||
// Throw an IllegalStateException in the case that set is called although there is no next step.
|
||||
if(!next){
|
||||
throw new IllegalStateException("The actuator does not have any next step.");
|
||||
}
|
||||
|
||||
// Set actuator channel
|
||||
logger.finest("Set actuator channel "+channel.getName()+" to value: "+table[count]);
|
||||
try {
|
||||
if(!asynchronous){
|
||||
if(timeout==null){
|
||||
channel.setValue(table[count]);
|
||||
}
|
||||
else{
|
||||
channel.setValueAsync(table[count]).get(timeout, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
}
|
||||
else{
|
||||
channel.setValueNoWait(table[count]);
|
||||
}
|
||||
|
||||
|
||||
if(doneChannel != null){
|
||||
Thread.sleep(doneDelay);
|
||||
doneChannel.waitForValue(doneValue);
|
||||
}
|
||||
|
||||
// Check whether the set value is really on the value that was set before.
|
||||
if(doneChannel==null && !asynchronous && EngineConfiguration.getInstance().isCheckActorSet()){
|
||||
if ( Math.abs( channel.getValue() - table[count] ) > accuracy ){
|
||||
throw new RuntimeException("Actor could not be set to the value "+table[count]+" The readback of the set value does not match the value that was set");
|
||||
}
|
||||
}
|
||||
|
||||
} catch (ChannelException | ExecutionException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new RuntimeException("Move actuator [channel: "+channel.getName()+"] to value "+table[count],e);
|
||||
}
|
||||
|
||||
if(positiveDirection){
|
||||
count++;
|
||||
if(count<table.length){
|
||||
this.next = true;
|
||||
}
|
||||
else{
|
||||
// There is no next set value
|
||||
this.next = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
count--;
|
||||
if(count>=0){
|
||||
this.next = true;
|
||||
}
|
||||
else{
|
||||
// There is no next set value
|
||||
this.next = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.Actor#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
// Set first set value to the start value
|
||||
if(positiveDirection){
|
||||
this.count = 0; // Set count to the first element
|
||||
}
|
||||
else{
|
||||
this.count = table.length-1; // Set count to the last element
|
||||
}
|
||||
|
||||
if(table.length>0){
|
||||
this.next = true;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reverse()
|
||||
*/
|
||||
@Override
|
||||
public void reverse() {
|
||||
if(positiveDirection){
|
||||
positiveDirection=false;
|
||||
}
|
||||
else{
|
||||
positiveDirection=true;
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
this.positiveDirection = this.originalPositiveDirection;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy actor channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
|
||||
// Destroy done channel if exists
|
||||
if(doneChannel != null){
|
||||
try {
|
||||
logger.finest("Destroy actor done channel: "+doneChannel.getName());
|
||||
doneChannel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the asynchronous
|
||||
*/
|
||||
public boolean isAsynchronous() {
|
||||
return asynchronous;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param asynchronous the asynchronous to set
|
||||
*/
|
||||
public void setAsynchronous(boolean asynchronous) {
|
||||
this.asynchronous = asynchronous;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,261 +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.actors;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.Actor;
|
||||
|
||||
/**
|
||||
* Complex actuator that consists of a list of other actuators. The steps of this actor are composed out of the
|
||||
* steps of the actors that this actuator consists of.
|
||||
* First all the steps of the first actor are used, after that the steps of the next actor are done.
|
||||
* Before the first step of an actor pre actions are available and after the last step of an actor a post action is available.
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ComplexActuator implements Actor {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ComplexActuator.class.getName());
|
||||
|
||||
/**
|
||||
* List of actors this actor is made of
|
||||
*/
|
||||
private final List<Actor> actors;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
* Flag that indicates whether there is a next set value for the Actor
|
||||
*/
|
||||
private boolean next;
|
||||
|
||||
/**
|
||||
* Index of the actor currently used
|
||||
*/
|
||||
private int actualActorCount;
|
||||
|
||||
/**
|
||||
* Actor currently used to perform steps
|
||||
*/
|
||||
private Actor actualActor;
|
||||
|
||||
/**
|
||||
* Flag to indicate the first set() execution of this actor.
|
||||
* This flag is used to decide whether to execute the pre actions.
|
||||
*/
|
||||
private boolean firstrun;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public ComplexActuator(){
|
||||
this.actors = new ArrayList<Actor>();
|
||||
this.preActions = new ArrayList<Action>();
|
||||
this.postActions = new ArrayList<Action>();
|
||||
|
||||
this.next = false;
|
||||
this.actualActorCount = 0;
|
||||
|
||||
this.firstrun = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#set()
|
||||
*/
|
||||
@Override
|
||||
public void set() throws InterruptedException {
|
||||
// Throw an IllegalStateException in the case that set is called although there is no next step.
|
||||
if(!next){
|
||||
throw new IllegalStateException("The actuator does not have any next step.");
|
||||
}
|
||||
|
||||
// PRE actions
|
||||
if(firstrun){
|
||||
this.firstrun = false;
|
||||
|
||||
// Execute pre actions
|
||||
logger.finest("Execute pre actions");
|
||||
for(Action action: preActions){
|
||||
action.execute();
|
||||
}
|
||||
}
|
||||
|
||||
actualActor.set(); // If the actor has no next step then something is wrong in the init/next step logic
|
||||
|
||||
// If the last point of the actual actuator is set take the next actuator in the list if there is one available
|
||||
while(!actualActor.hasNext()&&actualActorCount<actors.size()){
|
||||
actualActorCount++;
|
||||
if(actualActorCount<actors.size()){
|
||||
actualActor = actors.get(actualActorCount);
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(actualActor.hasNext()){
|
||||
this.next = true;
|
||||
}
|
||||
else{
|
||||
this.next = false;
|
||||
|
||||
// Execute post actions
|
||||
logger.finest("Execute post actions");
|
||||
for(Action action: postActions){
|
||||
action.execute();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return next;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
|
||||
// Initialize all actors this actor consist of
|
||||
for(Actor a: actors){
|
||||
a.init();
|
||||
}
|
||||
|
||||
// Set the actual actor to the first actor in the list
|
||||
actualActorCount=0;
|
||||
if(actualActorCount<actors.size()){
|
||||
actualActor = actors.get(actualActorCount);
|
||||
|
||||
// Check whether the actor has a next step, if not increase to the next one
|
||||
// This is needed because the first actor might not have any step ... (very unlikely but bad things happens some time)
|
||||
while(!actualActor.hasNext()&&actualActorCount<actors.size()){
|
||||
actualActorCount++;
|
||||
if(actualActorCount<actors.size()){
|
||||
actualActor = actors.get(actualActorCount);
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(actualActor.hasNext()){
|
||||
this.next = true;
|
||||
}
|
||||
else{
|
||||
this.next = false;
|
||||
}
|
||||
|
||||
}
|
||||
else{
|
||||
actualActor=null;
|
||||
this.next=false;
|
||||
}
|
||||
|
||||
this.firstrun = true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reverse()
|
||||
*/
|
||||
@Override
|
||||
public void reverse() {
|
||||
// Reverse all actors this actor consist of
|
||||
for(Actor a: actors){
|
||||
a.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
// Reset all actors this actor consist of
|
||||
for(Actor a: actors){
|
||||
a.reset();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of actors of this ComplexActor
|
||||
* @return the actors
|
||||
*/
|
||||
public List<Actor> getActors() {
|
||||
return actors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the preActions
|
||||
*/
|
||||
public List<Action> getPreActions() {
|
||||
return preActions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the postActions
|
||||
*/
|
||||
public List<Action> getPostActions() {
|
||||
return postActions;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy preActions
|
||||
for(Action a: preActions){
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
// Destroy actors
|
||||
for(Actor a: actors){
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
// Destroy postActions
|
||||
for(Action a: postActions){
|
||||
a.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,28 +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.actors;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public interface Function {
|
||||
public double calculate(double parameter);
|
||||
}
|
||||
@@ -1,114 +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.actors;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import ch.psi.fda.core.scripting.JythonGlobalVariable;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class JythonFunction implements Function {
|
||||
|
||||
// Get Logger
|
||||
private static final Logger logger = Logger.getLogger(JythonFunction.class.getName());
|
||||
|
||||
public static final String ENTRY_FUNCTION_NAME = "calculate";
|
||||
private static final String ENTRY_FUNCTION_PATTERN = "def "+ENTRY_FUNCTION_NAME+"\\((.*)\\):";
|
||||
|
||||
/**
|
||||
* Script engine of the manipulator
|
||||
*/
|
||||
private ScriptEngine engine;
|
||||
|
||||
private String additionalParameter = "";
|
||||
|
||||
|
||||
public JythonFunction(String script, Map<String, JythonGlobalVariable> map){
|
||||
// Create new script engine
|
||||
this.engine = new ScriptEngineManager().getEngineByName("python");
|
||||
|
||||
// Determine script entry function and the function parameters
|
||||
String[] parameter;
|
||||
Pattern pattern = Pattern.compile(ENTRY_FUNCTION_PATTERN);
|
||||
Matcher matcher = pattern.matcher(script);
|
||||
if(matcher.find() && matcher.groupCount()==1){
|
||||
if(!matcher.group(1).trim().equals("")){
|
||||
logger.finest("Entry function '"+ENTRY_FUNCTION_PATTERN+"' found - Identified parameters: "+matcher.group(1));
|
||||
parameter = matcher.group(1).split(" *, *");
|
||||
}
|
||||
else{
|
||||
parameter = new String[0];
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new IllegalArgumentException("Cannot determine entry function: "+ENTRY_FUNCTION_PATTERN);
|
||||
}
|
||||
|
||||
// Check whether all parameters are mapped
|
||||
StringBuilder b = new StringBuilder();
|
||||
for(int i=1;i<parameter.length; i++){ // Starting at 1 because first argument is implicit.
|
||||
if(!map.containsKey(parameter[i])){
|
||||
throw new IllegalArgumentException("Function parameter "+parameter[i]+" is not mapped");
|
||||
}
|
||||
b.append(",");
|
||||
b.append(parameter[i]);
|
||||
}
|
||||
additionalParameter = b.toString();
|
||||
|
||||
// Set variables in Jython engine
|
||||
for(String k: map.keySet()){
|
||||
engine.put(k, map.get(k));
|
||||
}
|
||||
|
||||
// Load manipulation script
|
||||
try {
|
||||
engine.eval(script);
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException("Unable to load manipulation script", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.actors.Function#calculate(double)
|
||||
*/
|
||||
@Override
|
||||
public double calculate(double parameter) {
|
||||
logger.fine("Function called");
|
||||
|
||||
try {
|
||||
logger.info("calculate( "+parameter+""+additionalParameter+" )");
|
||||
return ((Double) engine.eval("calculate( "+parameter+""+additionalParameter+" )"));
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException("Calculating actuator step failed while executing the Jython script",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,188 +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.actors;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
|
||||
/**
|
||||
* Special actuator for the OTFLoop. This type of actor must not be used in any other
|
||||
* type of loop than OTFLoop. If it is used it will, depending on the loop, immediately stop the loop
|
||||
* as it no single step.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class OTFActuator implements Actor {
|
||||
|
||||
/**
|
||||
* Name of the motor channel
|
||||
*/
|
||||
private final String name;
|
||||
|
||||
/**
|
||||
* Channel name of the encoder;
|
||||
*/
|
||||
private final String readback;
|
||||
|
||||
private double start;
|
||||
private double end;
|
||||
private final double stepSize;
|
||||
private final double integrationTime;
|
||||
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Additional backlash for the motor
|
||||
*/
|
||||
private final double additionalBacklash;
|
||||
|
||||
|
||||
public OTFActuator(String id, String name, String readback, double start, double end, double stepSize, double integrationTime, double additionalBacklash){
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
this.readback = readback;
|
||||
this.start = start;
|
||||
this.end = end;
|
||||
this.stepSize = stepSize;
|
||||
this.integrationTime = integrationTime;
|
||||
this.additionalBacklash = additionalBacklash;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#set()
|
||||
*/
|
||||
@Override
|
||||
public void set() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the name
|
||||
*/
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readback
|
||||
*/
|
||||
public String getReadback() {
|
||||
return readback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the start
|
||||
*/
|
||||
public double getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the end
|
||||
*/
|
||||
public double getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the stepSize
|
||||
*/
|
||||
public double getStepSize() {
|
||||
return stepSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the integrationTime
|
||||
*/
|
||||
public double getIntegrationTime() {
|
||||
return integrationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the additionalBacklash
|
||||
*/
|
||||
public double getAdditionalBacklash() {
|
||||
return additionalBacklash;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reverse()
|
||||
*/
|
||||
@Override
|
||||
public void reverse() {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @param start the start to set
|
||||
*/
|
||||
public void setStart(double start) {
|
||||
this.start = start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param end the end to set
|
||||
*/
|
||||
public void setEnd(double end) {
|
||||
this.end = end;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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.actors;
|
||||
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
|
||||
/**
|
||||
* Pseudo actor that is literally doing nothing for n times
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class PseudoActuatorSensor implements Actor, Sensor {
|
||||
|
||||
/**
|
||||
* Execution count of actuator.
|
||||
*/
|
||||
private int count;
|
||||
|
||||
/**
|
||||
* Number of counts for this actuator
|
||||
*/
|
||||
private final int counts;
|
||||
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param counts
|
||||
* @param id Id of the Actor/Sensor
|
||||
*/
|
||||
public PseudoActuatorSensor(String id, int counts){
|
||||
if(counts < 1){
|
||||
throw new IllegalArgumentException("Count ["+counts+"] must be > 0");
|
||||
}
|
||||
this.id = id;
|
||||
this.counts = counts;
|
||||
|
||||
init();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#set()
|
||||
*/
|
||||
@Override
|
||||
public void set() {
|
||||
|
||||
// Throw an IllegalStateException in the case that set is called although there is no next step.
|
||||
if(!hasNext()){
|
||||
throw new IllegalStateException("The actuator does not have any next step.");
|
||||
}
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#hasNext()
|
||||
*/
|
||||
@Override
|
||||
public boolean hasNext() {
|
||||
return (count<counts);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
count=0; // Set count back to 0
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reverse()
|
||||
*/
|
||||
@Override
|
||||
public void reverse() {
|
||||
// Not implemented
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#reset()
|
||||
*/
|
||||
@Override
|
||||
public void reset() {
|
||||
// NOt implemented
|
||||
}
|
||||
|
||||
|
||||
// Sensor implementation
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#read()
|
||||
*/
|
||||
@Override
|
||||
public Object read() {
|
||||
return new Double(count); // Return actual count
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Sensor#getId()
|
||||
*/
|
||||
@Override
|
||||
public String getId() {
|
||||
return this.id;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Actor#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Nothing to be done
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,165 +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.collector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.StreamDelimiterMessage;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
|
||||
/**
|
||||
* Collector class that is collecting and merging data from different Queues.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class Collector implements Runnable{
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(Collector.class.getName());
|
||||
|
||||
/**
|
||||
* List of queues and their metadata this collector is responsible to readout.
|
||||
* The logic is as follows:
|
||||
* Read out the last queue until the first queue in the list has the EndOfLoopMessage.
|
||||
*/
|
||||
private List<DataQueue> queues;
|
||||
|
||||
/**
|
||||
* Outgoing queue of this collector
|
||||
*/
|
||||
private BlockingQueue<Message> outQueue;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public Collector(){
|
||||
queues = new ArrayList<DataQueue>();
|
||||
outQueue = new LinkedBlockingQueue<Message>(1000); // Create bounded queue to prevent running out of memory ...
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if(queues.size()>0){
|
||||
try{
|
||||
readQueue(0, null);
|
||||
}
|
||||
catch(InterruptedException e){
|
||||
// Readout aborted through interrupt
|
||||
}
|
||||
}
|
||||
else{
|
||||
// No queue registered for reading
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
outQueue.put(new EndOfStreamMessage());
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Stop loop and exit logic instead of throwing an Exception
|
||||
throw new RuntimeException("Unable to terminate stream with and End of Stream Message",e);
|
||||
}
|
||||
|
||||
logger.info("END");
|
||||
|
||||
}
|
||||
|
||||
|
||||
private void readQueue(int index, DataMessage m) throws InterruptedException{
|
||||
|
||||
BlockingQueue<Message> q = queues.get(index).getQueue();
|
||||
|
||||
// Read Message
|
||||
Message message = q.take();
|
||||
while(message instanceof DataMessage){
|
||||
// Create new data message
|
||||
DataMessage dm = new DataMessage();
|
||||
if(m!=null){
|
||||
dm.getData().addAll(m.getData());
|
||||
}
|
||||
|
||||
dm.getData().addAll(((DataMessage)message).getData());
|
||||
|
||||
if(index<(queues.size()-1)){
|
||||
readQueue(index+1, dm);
|
||||
}
|
||||
else{
|
||||
// Write message to outgoing queue
|
||||
outQueue.put(dm);
|
||||
}
|
||||
|
||||
// Read next message
|
||||
message = q.take();
|
||||
}
|
||||
|
||||
if(message instanceof EndOfStreamMessage){
|
||||
// Translate EndOfStream to StreamDelimiter message
|
||||
StreamDelimiterMessage ddm = new StreamDelimiterMessage(queues.size()-1-index, ((EndOfStreamMessage)message).isIflag());
|
||||
// Write message to outgoing queue
|
||||
outQueue.put(ddm);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the queues
|
||||
*/
|
||||
public List<DataQueue> getQueues() {
|
||||
return queues;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the outgoing data queue.
|
||||
* Attention, only call this method after all ingoing queues were registered! Otherwise the data returned
|
||||
* by this method is not accurate.
|
||||
* @return output queue of collector
|
||||
*/
|
||||
public DataQueue getOutQueue(){
|
||||
DataMessageMetadata dataMessageMetadata = new DataMessageMetadata();
|
||||
dataMessageMetadata.getComponents();
|
||||
|
||||
// Generate new combined metadata and add dimension information to the components
|
||||
int nq = queues.size();
|
||||
for(int i=0;i<nq;i++){
|
||||
DataQueue q = queues.get(i);
|
||||
for(ComponentMetadata cm: q.getDataMessageMetadata().getComponents()){
|
||||
// The dimension number is the number of queues minus the index of the current queue minus 1 (because dimension index starts at 0)
|
||||
dataMessageMetadata.getComponents().add(new ComponentMetadata(cm.getId(), nq-i-1));
|
||||
}
|
||||
}
|
||||
|
||||
return(new DataQueue(outQueue, dataMessageMetadata));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,88 +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.collector;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
|
||||
/**
|
||||
* Serialize data received by a DataQueue
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DataDispatcher implements Runnable{
|
||||
|
||||
private DataQueue queue;
|
||||
private List<DataQueue> outQueues;
|
||||
|
||||
public DataDispatcher(DataQueue queue){
|
||||
this.queue = queue;
|
||||
this.outQueues = new ArrayList<DataQueue>();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
|
||||
// TODO Need to synchronize message metadata
|
||||
// for(DataQueue q: outQueues){
|
||||
// }
|
||||
|
||||
// Dispatch Messages
|
||||
Message message = queue.getQueue().take();
|
||||
while(!(message instanceof EndOfStreamMessage)){
|
||||
|
||||
// Clone message ...
|
||||
for(DataQueue q: outQueues){
|
||||
q.getQueue().put(message);
|
||||
}
|
||||
|
||||
// Read next message
|
||||
message = queue.getQueue().take();
|
||||
}
|
||||
|
||||
// Write end of stream message
|
||||
for(DataQueue q: outQueues){
|
||||
q.getQueue().put(message);
|
||||
}
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Stop loop and exit logic instead of throwing an Exception
|
||||
throw new RuntimeException("Data serializer was interrupted while writing data to file",e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the outQueues
|
||||
*/
|
||||
public List<DataQueue> getOutQueues() {
|
||||
return outQueues;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,118 +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.guard;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Guard;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
|
||||
/**
|
||||
* Guard checking channels to meet a certain condition
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessGuard implements Guard {
|
||||
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessGuard.class.getName());
|
||||
|
||||
/**
|
||||
* 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 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
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
if(! evt.getNewValue().equals(condition.getValue())){
|
||||
check=false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Guard#init()
|
||||
*/
|
||||
@Override
|
||||
public void init() {
|
||||
check = true;
|
||||
|
||||
// Check one time if all conditions are met
|
||||
for(ChannelAccessGuardCondition condition: conditions){
|
||||
try{
|
||||
if(! (condition.getChannel().getValue(true)).equals(condition.getValue()) ){
|
||||
check=false;
|
||||
// Early exit
|
||||
break;
|
||||
}
|
||||
}
|
||||
catch(ChannelException | TimeoutException | ExecutionException e){
|
||||
logger.log(Level.WARNING, "Unable ", e);
|
||||
check=false;
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Guard interrupted ",e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Guard#check()
|
||||
*/
|
||||
@Override
|
||||
public boolean check() {
|
||||
return check;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Guard#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy Guard Conditions
|
||||
for(ChannelAccessGuardCondition condition: conditions){
|
||||
condition.destroy();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,98 +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.guard;
|
||||
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* Channel and condition that need to be met.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ChannelAccessGuardCondition {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ChannelAccessGuardCondition.class.getName());
|
||||
|
||||
/**
|
||||
* Channel name
|
||||
*/
|
||||
private final Channel<?> channel;
|
||||
|
||||
/**
|
||||
* Value of the channel to meet condition
|
||||
*/
|
||||
private final Object value;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channel Name of the channel that contributes to a guard
|
||||
* @param value
|
||||
*/
|
||||
public ChannelAccessGuardCondition(ChannelService s, String channel, Object value){
|
||||
try {
|
||||
this.channel = s.createChannel(new ChannelDescriptor<>(value.getClass(), channel, true));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
// Convert Exception into unchecked RuntimeException
|
||||
throw new IllegalArgumentException("Unable to initialize actuator channel [name:"+channel+"]",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to initialize actuator channel [name:"+channel+"]",e);
|
||||
}
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channel
|
||||
*/
|
||||
public Channel<?> getChannel() {
|
||||
return channel;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public Object getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Destroy guard condition.
|
||||
* Can be used for the cleanup of used resources of the guard condition (e.g. to close connections, ...) if
|
||||
* this cannot be done automatically by the GarbageCollector.
|
||||
*
|
||||
* After calling this method the guard condition must not be used any more!
|
||||
*/
|
||||
public void destroy(){
|
||||
// Destroy channel
|
||||
try {
|
||||
logger.finest("Destroy guard condition channel: "+channel.getName());
|
||||
channel.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channel ["+channel.getName()+"]",e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,590 +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.loops;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Actor;
|
||||
import ch.psi.fda.core.ActorSetCallable;
|
||||
import ch.psi.fda.core.Guard;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
|
||||
/**
|
||||
* Loop of actions to accomplish a task or test.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ActorSensorLoop implements ActionLoop {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(ActorSensorLoop.class.getName());
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the data of this loop will be grouped
|
||||
* According to this flag the dataGroup flag in EndOfStream will be set.
|
||||
*/
|
||||
private boolean dataGroup = false;
|
||||
|
||||
/**
|
||||
* List of additional action loops that are executed at the end of each
|
||||
* iteration of the loop
|
||||
*/
|
||||
private List<ActionLoop> actionLoops;
|
||||
/**
|
||||
* List of actions that are executed at the beginning of the loop.
|
||||
*/
|
||||
private List<Action> preActions;
|
||||
/**
|
||||
* List of actions that are executed at the end of the loop.
|
||||
*/
|
||||
private List<Action> postActions;
|
||||
|
||||
/**
|
||||
* List of actions that are executed before the actors are set
|
||||
*/
|
||||
private List<Action> preActorActions;
|
||||
|
||||
/**
|
||||
* List of actions that are executed after all actors have been set
|
||||
*/
|
||||
private List<Action> postActorActions;
|
||||
|
||||
/**
|
||||
* List of actions that are executed before the sensors are read out
|
||||
*/
|
||||
private List<Action> preSensorActions;
|
||||
/**
|
||||
* List of actions that are executed after all sensors have been read out
|
||||
*/
|
||||
private List<Action> postSensorActions;
|
||||
|
||||
/**
|
||||
* List of actors of this loop
|
||||
*/
|
||||
private List<Actor> actors;
|
||||
|
||||
/**
|
||||
* List of sensors of this loop
|
||||
*/
|
||||
private List<Sensor> sensors;
|
||||
|
||||
/**
|
||||
* Data queue sensor data is posted to. A message consists of a list of data objects
|
||||
* that are read out of the sensors of this loop.
|
||||
*/
|
||||
private BlockingQueue<Message> dataQueue;
|
||||
|
||||
/**
|
||||
* Guard used to check whether the environment was ok while reading out the sensors
|
||||
*/
|
||||
private Guard guard = null;
|
||||
|
||||
private volatile boolean loop = false;
|
||||
private volatile boolean abort = false;
|
||||
|
||||
private final boolean zigZag;
|
||||
|
||||
private List<ActorSetCallable> pactors;
|
||||
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public ActorSensorLoop(){
|
||||
this(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create instance of the
|
||||
*/
|
||||
public ActorSensorLoop(boolean zigZag){
|
||||
this.zigZag = zigZag;
|
||||
this.actionLoops = new ArrayList<ActionLoop>();
|
||||
this.preActions = new ArrayList<Action>();
|
||||
this.postActions = new ArrayList<Action>();
|
||||
this.preActorActions = new ArrayList<Action>();
|
||||
this.postActorActions = new ArrayList<Action>();
|
||||
this.preSensorActions = new ArrayList<Action>();
|
||||
this.postSensorActions = new ArrayList<Action>();
|
||||
|
||||
this.actors = new ArrayList<Actor>();
|
||||
this.pactors = new ArrayList<ActorSetCallable>();
|
||||
this.sensors = new ArrayList<Sensor>();
|
||||
|
||||
this.dataQueue = new LinkedBlockingQueue<Message>(1000);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.ActionLoop#execute()
|
||||
*/
|
||||
/**
|
||||
* Executes the actor sensor loop. The actor sensor loop is build up as follows:
|
||||
* preActions
|
||||
* loop{
|
||||
* check actors - abort if there are no new steps
|
||||
* pre actor actions
|
||||
* set actors
|
||||
* post actor actions
|
||||
* pre sensor actions
|
||||
* read sensors
|
||||
* post sensor actions
|
||||
* execute additional registered action loops
|
||||
* }
|
||||
* postActions
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
abort = false;
|
||||
|
||||
/**
|
||||
* Thread pool for parallel execution of tasks
|
||||
*/
|
||||
ExecutorService executorService = Executors.newCachedThreadPool();
|
||||
|
||||
loop = true;
|
||||
|
||||
// Execute pre actions
|
||||
for(Action action: preActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
// Initialize actors of Loop
|
||||
for(Actor actor: actors){
|
||||
actor.init();
|
||||
}
|
||||
|
||||
// Variable to store the last guard status
|
||||
boolean guardOK=true;
|
||||
|
||||
try{
|
||||
|
||||
// Execute loop logic
|
||||
while(loop){
|
||||
|
||||
if(guardOK){
|
||||
|
||||
|
||||
// If actors are defined for the loop check whether all of them
|
||||
// have a next step defined if there is no actor defined only run this loop once
|
||||
if(actors.size()>0){
|
||||
// Check whether the actors of this loop have a next step. If not
|
||||
// abort the loop
|
||||
boolean hasNext = true;
|
||||
for(Actor actor: actors){
|
||||
if(!actor.hasNext()){
|
||||
hasNext=false;
|
||||
break; // Stop actor check loop
|
||||
}
|
||||
}
|
||||
|
||||
// If not all actors have a next step abort the loop
|
||||
if(!hasNext){
|
||||
break; // Stop action loop
|
||||
}
|
||||
}
|
||||
else{
|
||||
// No actors defined, only run loop once
|
||||
loop = false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Execute pre actor actions
|
||||
for(Action action: preActorActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
if(abort){ // End loop if abort was issued
|
||||
break;
|
||||
}
|
||||
|
||||
// Set actors
|
||||
// for(Actor actor: actors){
|
||||
// actor.set();
|
||||
// }
|
||||
// Parallel set of the actors
|
||||
try {
|
||||
for (Future<Object> f : executorService.invokeAll(pactors)) {
|
||||
f.get(); //Blocks until the async set() is finished
|
||||
}
|
||||
} catch (ExecutionException e) {
|
||||
throw new RuntimeException("Setting the actors failed",e);
|
||||
}
|
||||
|
||||
// Execute post actor actions
|
||||
for(Action action: postActorActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
if(abort){ // End loop if abort was issued
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(guard!=null){
|
||||
// Initialize guard
|
||||
guard.init();
|
||||
guardOK=guard.check();
|
||||
|
||||
// Wait until guard is ok
|
||||
while(!guardOK){
|
||||
logger.info("Waiting for guard condition(s) to be met");
|
||||
// Sleep 100 milliseconds before next check
|
||||
Thread.sleep(1000);
|
||||
|
||||
// Check whether the loop is not aborted, if it is aborted
|
||||
// break the wait loop (afterwards also the loop loop is aborted)
|
||||
if(!loop){
|
||||
break;
|
||||
}
|
||||
|
||||
guard.init();
|
||||
guardOK=guard.check();
|
||||
}
|
||||
|
||||
// If loop is aborted proceed to next iteration an abort loop
|
||||
if(!loop){
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Execute pre sensor actions
|
||||
for(Action action: preSensorActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
if(abort){ // End loop if abort was issued
|
||||
break;
|
||||
}
|
||||
|
||||
// Read sensors
|
||||
DataMessage message = new DataMessage();
|
||||
for(Sensor sensor: sensors){
|
||||
// Readout sensor
|
||||
Object o = sensor.read();
|
||||
// Add sensor data item to message
|
||||
message.getData().add(o);
|
||||
}
|
||||
|
||||
// Execute post sensor actions
|
||||
for(Action action: postSensorActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
if(abort){ // End loop if abort was issued
|
||||
break;
|
||||
}
|
||||
|
||||
// Check guard if one is registered
|
||||
if(guard!=null){
|
||||
guardOK=guard.check();
|
||||
}
|
||||
|
||||
if(guardOK){
|
||||
|
||||
// Post a message with the sensor data
|
||||
dataQueue.put(message);
|
||||
|
||||
// Loop all configured ActionLoop objects
|
||||
for(ActionLoop actionLoop: actionLoops){
|
||||
actionLoop.execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Execute post actions
|
||||
for(Action action: postActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
}
|
||||
finally{
|
||||
// Ensure that data stream is terminated ...
|
||||
|
||||
// Issue end of loop control message
|
||||
// Set iflag of the EndOfStreamMessage according to dataGroup flag of this loop
|
||||
dataQueue.put(new EndOfStreamMessage(dataGroup));
|
||||
}
|
||||
|
||||
if(zigZag){
|
||||
// Reverse actors for the next run
|
||||
for(Actor actor: actors){
|
||||
actor.reverse();
|
||||
}
|
||||
}
|
||||
|
||||
executorService.shutdownNow();
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.engine.ActionLoop#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort(){
|
||||
abort = true;
|
||||
loop = false;
|
||||
|
||||
// To abort all wait actions interrupt this thread
|
||||
for(Action a: preSensorActions){
|
||||
a.abort();
|
||||
}
|
||||
|
||||
// Recursively abort all registered action loops
|
||||
for(ActionLoop actionLoop: actionLoops){
|
||||
actionLoop.abort();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
// Put in prepare code here
|
||||
|
||||
// Create callable for all actors
|
||||
pactors.clear();
|
||||
for(final Actor a: actors){
|
||||
pactors.add(new ActorSetCallable(a));
|
||||
}
|
||||
|
||||
// Reset all actuators
|
||||
for(Actor a: actors){
|
||||
a.reset();
|
||||
}
|
||||
|
||||
// Recursively call prepare() method of all registered action loops
|
||||
for(ActionLoop actionLoop: actionLoops){
|
||||
actionLoop.prepare();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#cleanup()
|
||||
*/
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// Put in cleanup code here
|
||||
|
||||
// Recursively call cleanup() method of all registered action loops
|
||||
for(ActionLoop actionLoop: actionLoops){
|
||||
actionLoop.cleanup();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
|
||||
// Call destroy method of sub components
|
||||
for(Action a: preActions){
|
||||
logger.finest("Destroy pre-action");
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
for(Action a: postActions){
|
||||
logger.finest("Destroy post-action");
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
for(Action a: preActorActions){
|
||||
logger.finest("Destroy pre-actor action");
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
for(Action a: postActorActions){
|
||||
logger.finest("Destroy post-actor action");
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
for(Action a: preSensorActions){
|
||||
logger.finest("Destroy pre-sensor action");
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
for(Action a: postSensorActions){
|
||||
logger.finest("Destroy post-sensor action");
|
||||
a.destroy();
|
||||
}
|
||||
|
||||
for(Actor a: actors){
|
||||
logger.finest("Destroy actor");
|
||||
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");
|
||||
actionLoop.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* (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;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The structure of the data message depends on the sensors registered at this loop
|
||||
* at the time this method is called.
|
||||
* @return the data queue and the metadata of the data messages
|
||||
*/
|
||||
public DataQueue getDataQueue() {
|
||||
DataMessageMetadata m = new DataMessageMetadata();
|
||||
|
||||
// Build up data message metadata based on the sensors currently registered.
|
||||
for(Sensor s: sensors){
|
||||
m.getComponents().add(new ComponentMetadata(s.getId()));
|
||||
}
|
||||
return new DataQueue(dataQueue, m);
|
||||
}
|
||||
|
||||
// Getter functions for variable parts
|
||||
|
||||
/**
|
||||
* @return the actionLoops
|
||||
*/
|
||||
public List<ActionLoop> getActionLoops() {
|
||||
return actionLoops;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the preActorActions
|
||||
*/
|
||||
public List<Action> getPreActorActions() {
|
||||
return preActorActions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the postActorActions
|
||||
*/
|
||||
public List<Action> getPostActorActions() {
|
||||
return postActorActions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the preSensorActions
|
||||
*/
|
||||
public List<Action> getPreSensorActions() {
|
||||
return preSensorActions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the postSensorActions
|
||||
*/
|
||||
public List<Action> getPostSensorActions() {
|
||||
return postSensorActions;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the actors
|
||||
*/
|
||||
public List<Actor> getActors() {
|
||||
return actors;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the sensors
|
||||
*/
|
||||
public List<Sensor> getSensors() {
|
||||
return sensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the guard
|
||||
*/
|
||||
public Guard getGuard() {
|
||||
return guard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param guard the guard to set
|
||||
*/
|
||||
public void setGuard(Guard guard) {
|
||||
this.guard = guard;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataGroup
|
||||
*/
|
||||
public boolean isDataGroup() {
|
||||
return dataGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataGroup the dataGroup to set
|
||||
*/
|
||||
public void setDataGroup(boolean dataGroup) {
|
||||
this.dataGroup = dataGroup;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* Copyright 2012 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.loops;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
|
||||
import jcifs.smb.SmbFile;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DistributedFile {
|
||||
|
||||
private SmbFile smbfile = null;
|
||||
private File file = null;
|
||||
|
||||
public DistributedFile(SmbFile file){
|
||||
this.smbfile = file;
|
||||
}
|
||||
|
||||
public DistributedFile(File file){
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public DistributedFile(String url) throws MalformedURLException{
|
||||
if(url.startsWith("smb://")){
|
||||
smbfile = new SmbFile(url);
|
||||
}
|
||||
else {
|
||||
file = new File(url);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getCanonicalPath() throws IOException{
|
||||
if(smbfile!=null){
|
||||
return(smbfile.getCanonicalPath());
|
||||
}
|
||||
else{
|
||||
return file.getCanonicalPath();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public boolean exists() throws IOException {
|
||||
if(smbfile!=null){
|
||||
return(smbfile.exists());
|
||||
}
|
||||
else{
|
||||
return file.exists();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isDirectory() throws IOException {
|
||||
if(smbfile!=null){
|
||||
return(smbfile.isDirectory());
|
||||
}
|
||||
else{
|
||||
return file.isDirectory();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public DistributedFile[] listFiles() throws IOException {
|
||||
if(smbfile!=null){
|
||||
SmbFile[] files = smbfile.listFiles();
|
||||
DistributedFile[] dfiles = new DistributedFile[files.length];
|
||||
for(int i=0;i<files.length;i++){
|
||||
dfiles[i] = new DistributedFile(files[i]);
|
||||
}
|
||||
return(dfiles);
|
||||
}
|
||||
else{
|
||||
File[] files = file.listFiles();
|
||||
DistributedFile[] dfiles = new DistributedFile[files.length];
|
||||
for(int i=0;i<files.length;i++){
|
||||
dfiles[i] = new DistributedFile(files[i]);
|
||||
}
|
||||
return(dfiles);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public String getName() {
|
||||
if(smbfile!=null){
|
||||
return(smbfile.getName());
|
||||
}
|
||||
else{
|
||||
return file.getName();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public boolean isFile() throws IOException {
|
||||
if(smbfile!=null){
|
||||
return(smbfile.isFile());
|
||||
}
|
||||
else{
|
||||
return file.isFile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public void delete() throws IOException {
|
||||
if(smbfile!=null){
|
||||
smbfile.delete();
|
||||
}
|
||||
else{
|
||||
file.delete();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return
|
||||
*/
|
||||
public InputStreamReader getInputStream() throws IOException {
|
||||
if(smbfile!=null){
|
||||
return(new InputStreamReader(smbfile.getInputStream()));
|
||||
}
|
||||
else{
|
||||
return new FileReader(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,801 +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.loops;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
* Bean holding all OTF channels and functionality
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class OTFBean {
|
||||
|
||||
public enum Status { SETUP, INACTIVE, INITIALIZE, ACTIVE, STOP, FAULT, ERROR };
|
||||
public enum Command { NONE, START, STOP };
|
||||
|
||||
private long timeoutMotorOk = 8000;
|
||||
private long commandTimeout = 20000; // Maximum time until a command should take effect
|
||||
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:UMOT")
|
||||
private Channel<String> motor;
|
||||
|
||||
@CaChannel(type=String.class, name="${PREFIX}:MENC")
|
||||
private Channel<String> encoder;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBEG")
|
||||
private Channel<Double> begin;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBEG.DRVL")
|
||||
private Channel<Double> beginMin;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBEG.DRVH")
|
||||
private Channel<Double> beginMax;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UEND")
|
||||
private Channel<Double> end;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UEND.DRVL")
|
||||
private Channel<Double> endMin;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UEND.DRVH")
|
||||
private Channel<Double> endMax;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:USSIZ")
|
||||
private Channel<Double> stepSize;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:USSIZ.DRVL")
|
||||
private Channel<Double> stepSizeMin;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UITIM")
|
||||
private Channel<Double> integrationTime;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UITIM.DRVL")
|
||||
private Channel<Double> integrationTimeMin;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UITIM.DRVH")
|
||||
private Channel<Double> integrationTimeMax;
|
||||
|
||||
@CaChannel(type=Double.class, name="${PREFIX}:UBCL")
|
||||
private Channel<Double> userBacklash;
|
||||
|
||||
@CaChannel(type=String.class, name="${PREFIX}:NFSSE")
|
||||
private Channel<String> nfsServer;
|
||||
|
||||
@CaChannel(type=String.class, name="${PREFIX}:NFSSH")
|
||||
private Channel<String> nfsShare;
|
||||
|
||||
@CaChannel(type=String.class, name="${PREFIX}:DFNAM")
|
||||
private Channel<String> fileName;
|
||||
|
||||
@CaChannel(type=String.class, name="${PREFIX}:FFORM")
|
||||
private Channel<String> fileNameFormat;
|
||||
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:FCNT")
|
||||
private Channel<Integer> fileCount;
|
||||
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:FCNT.B")
|
||||
private Channel<Integer> resetFileCounter;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:FAPPE")
|
||||
private Channel<Boolean> appendFile;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:FUSE")
|
||||
private Channel<Boolean> fileNameGeneration;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:UZIGZ")
|
||||
private Channel<Boolean> zigZag;
|
||||
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:UCOM")
|
||||
private Channel<Integer> command;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:SCRU", monitor=true)
|
||||
private Channel<Boolean> scanRunning;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:MUENC")
|
||||
private Channel<Boolean> useEncoder;
|
||||
|
||||
@CaChannel(type=String.class, name={"${PREFIX}:CTM0","${PREFIX}:CTM1","${PREFIX}:CTM2","${PREFIX}:CTM3","${PREFIX}:CTM4","${PREFIX}:CTM5","${PREFIX}:CTM6","${PREFIX}:CTM7"})
|
||||
private List<Channel<String>> monitoredChannels;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:OTF", monitor=true)
|
||||
private Channel<Boolean> running;
|
||||
|
||||
@CaChannel(type=Integer.class, name="${PREFIX}:USTAT", monitor=true)
|
||||
private Channel<Integer> status;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:MOK", monitor=true)
|
||||
private Channel<Boolean> motorOk;
|
||||
|
||||
@CaChannel(type=Boolean.class, name="${PREFIX}:EOK", monitor=true)
|
||||
private Channel<Boolean> encoderOk;
|
||||
|
||||
@CaChannel(type=String.class, name="${PREFIX}:MSG")
|
||||
private Channel<String> message;
|
||||
|
||||
/**
|
||||
* Get the trigger name that can be used by the sscan record to trigger an OTFScan
|
||||
* @return Name of the trigger that can be used by sscan record
|
||||
*/
|
||||
public String getSScanTriggerName(){
|
||||
return(running.getName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Start OTF scan
|
||||
*/
|
||||
public void start() {
|
||||
try{
|
||||
if(getStatus().equals(Status.INACTIVE)){
|
||||
|
||||
// Send START command
|
||||
this.command.setValue(Command.START.ordinal());
|
||||
|
||||
// Wait until OtF logic is active
|
||||
this.scanRunning.waitForValue(true, commandTimeout);
|
||||
}
|
||||
else{
|
||||
throw new RuntimeException("Cannot start scan, status is not INACTIVE.\nThe current status is: "+getStatus()+" . The OTF logic need to be recovered manually [Message: "+getMessage()+"]");
|
||||
}
|
||||
}
|
||||
catch(Exception e){
|
||||
throw new RuntimeException("Unable to start OTF scan.",e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort scan
|
||||
*/
|
||||
public void abort() {
|
||||
try{
|
||||
// Send STOP command
|
||||
this.command.setValue(Command.STOP.ordinal());
|
||||
|
||||
// Do not wait for put to return
|
||||
this.running.setValueNoWait(false);
|
||||
}
|
||||
catch(Exception e){
|
||||
throw new RuntimeException("Unable to abort OTF logic" ,e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop OTF scan
|
||||
* @throws Exception
|
||||
*/
|
||||
public void stop() throws Exception{
|
||||
if(!getStatus().equals(Status.INACTIVE) || !getStatus().equals(Status.FAULT)){
|
||||
|
||||
// Send STOP command
|
||||
this.command.setValue(Command.STOP.ordinal());
|
||||
|
||||
// Wait until logic is stopped
|
||||
status.waitForValue(Status.INACTIVE.ordinal(), commandTimeout);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until scan has stopped
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void waitUntilStopped() throws InterruptedException {
|
||||
try {
|
||||
scanRunning.waitForValue(false); // Use of default wait timeout
|
||||
|
||||
// Check whether the status is INACTIVE otherwise get messge from OTF and throw an exception
|
||||
if(status.getValue() != Status.INACTIVE.ordinal()){
|
||||
throw new RuntimeException("OTFSCAN failed with message: "+message.getValue());
|
||||
}
|
||||
|
||||
} catch (ChannelException | ExecutionException | TimeoutException e) {
|
||||
throw new RuntimeException("An error occurred while waiting for the OTF logic to finish.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until scan has stopped
|
||||
* @param waitTimeout
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void waitUntilStopped(Long waitTimeout) throws InterruptedException {
|
||||
try {
|
||||
scanRunning.waitForValue(false, waitTimeout);
|
||||
|
||||
// Check whether the status is INACTIVE otherwise get messge from OTF and throw an exception
|
||||
if(status.getValue() != Status.INACTIVE.ordinal()){
|
||||
throw new RuntimeException("OTFSCAN failed with message: "+message.getValue());
|
||||
}
|
||||
|
||||
} catch (ChannelException | ExecutionException | TimeoutException e) {
|
||||
throw new RuntimeException("An error occurred while waiting for the OTF logic to finish.", e);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset OTFScan records to defaults
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void resetToDefaults() throws ChannelException , ExecutionException , TimeoutException, InterruptedException{
|
||||
setMonitoredChannels(new String[]{});
|
||||
setMotor("");
|
||||
begin.setValue(0d);
|
||||
end.setValue(0d);
|
||||
stepSize.setValue(0d);
|
||||
integrationTime.setValue(0d);
|
||||
zigZag.setValue(false);
|
||||
setAppendFile(false);
|
||||
setFileNameGeneration(true);
|
||||
setFileName("");
|
||||
setFileNameFormat("%06d.txt");
|
||||
resetFileCounter();
|
||||
|
||||
setUserBacklash(0d);
|
||||
|
||||
// setNfsServer("");
|
||||
// setNfsShare("");
|
||||
|
||||
waitUntilMotorNotOk(timeoutMotorOk);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get motor of the OTFScan axis
|
||||
* @return Name of the OTF motor
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String getMotor() throws ChannelException, InterruptedException, TimeoutException, ExecutionException {
|
||||
return(this.motor.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set motor of the OTFScan axis
|
||||
* @param motor
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setMotor(String motor) throws InterruptedException, ExecutionException, ChannelException {
|
||||
this.motor.setValue(motor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get encoder of the OTFScan axis
|
||||
* @return Name of the used encoder
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String getEncoder() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
return(this.encoder.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set encoder to use of the OTFScan axis
|
||||
* @param encoder
|
||||
* @throws ChannelException
|
||||
* @throws ExecutionException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setEncoder(String encoder) throws InterruptedException, ExecutionException, ChannelException {
|
||||
this.encoder.setValue(encoder);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get begin position of the scan
|
||||
* @return Begin position scan
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getBegin() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
return(this.begin.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set begin position of scan
|
||||
* @param begin
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws Exception
|
||||
*/
|
||||
public void setBegin(Double begin) throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
if(begin==null){
|
||||
throw new IllegalArgumentException("Begin position must not be null");
|
||||
}
|
||||
|
||||
if(begin < beginMin.getValue() || begin > beginMax.getValue()){
|
||||
throw new IllegalArgumentException("Cannot set begin value to "+begin+ ". Value is outside range [min: "+beginMin.getValue()+" max: "+beginMax.getValue()+"]");
|
||||
}
|
||||
|
||||
this.begin.setValue(begin);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum value of the begin position
|
||||
* @return Min value for begin
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getMinBegin() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
return(this.beginMin.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get maximum value of the begin position
|
||||
* @return Max value for begin
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getMaxBegin() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
return(this.beginMax.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get end position of the scan
|
||||
* @return End position scan
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getEnd() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
return(this.end.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set end positon of scan
|
||||
* @param end
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setEnd(Double end) throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
|
||||
if(end==null){
|
||||
throw new IllegalArgumentException("End position must not be null");
|
||||
}
|
||||
|
||||
if(end < endMin.getValue() || end > endMax.getValue()){
|
||||
throw new IllegalArgumentException("Cannot set end value to "+end+ ". Value is outside range [min: "+endMin.getValue()+" max: "+endMax.getValue()+"]");
|
||||
}
|
||||
|
||||
this.end.setValue(end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum value of end position
|
||||
* @return Min value for end
|
||||
* @throws ExecutionException
|
||||
* @throws ChannelException
|
||||
* @throws TimeoutException
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getMinEnd() throws InterruptedException, TimeoutException, ChannelException, ExecutionException {
|
||||
return(this.endMin.getValue());
|
||||
}
|
||||
/**
|
||||
* Get maximum value of end position
|
||||
* @return Max value for end
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getMaxEnd() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.endMax.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scan step size
|
||||
* @return Step size
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getStepSize() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.stepSize.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set step size of scan
|
||||
* @param stepSize
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setStepSize(Double stepSize) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
|
||||
if(integrationTime==null){
|
||||
throw new IllegalArgumentException("Step size must not be null");
|
||||
}
|
||||
|
||||
// Check if step size is greater than min step size
|
||||
if(stepSizeMin.getValue() != 0 && stepSize < stepSizeMin.getValue()){
|
||||
throw new IllegalArgumentException("Step size value ["+stepSize+"] is less than minimum step size ["+stepSizeMin.getValue()+"]!");
|
||||
}
|
||||
|
||||
this.stepSize.setValue(stepSize);
|
||||
|
||||
// TODO WORKAROUND - Wait to "ensure" that step size related fields are updated (i.e. min/max integration time)
|
||||
Thread.sleep(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum integration time
|
||||
* @return Min value for step size
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public double getMinStepSize() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.stepSizeMin.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get scan integration time (time that is spend in one step)
|
||||
* @return Integration time
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getIntegrationTime() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.integrationTime.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set integration time of scan
|
||||
* @param integrationTime
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setIntegrationTime(Double integrationTime) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
|
||||
if(integrationTime==null){
|
||||
throw new IllegalArgumentException("Integration time must not be null");
|
||||
}
|
||||
|
||||
// Check range (if limit is set to 0 then limit is not set)
|
||||
double min = integrationTimeMin.getValue();
|
||||
double max = integrationTimeMax.getValue();
|
||||
if(min!= 0 && max!= 0){
|
||||
if(integrationTime < min || integrationTime > max){
|
||||
throw new IllegalArgumentException("Integration time ["+integrationTime+"] is outside range [min: "+min+" max: "+max+"]");
|
||||
}
|
||||
}
|
||||
else {
|
||||
if(min!= 0 && integrationTime<min){
|
||||
throw new IllegalArgumentException("Integration time ["+integrationTime+"] is outside range [min: "+min+" max: - ]");
|
||||
}
|
||||
else if(max!= 0 && integrationTime>max){
|
||||
throw new IllegalArgumentException("Integration time ["+integrationTime+"] is outside range [min: - max: "+max+"]");
|
||||
}
|
||||
}
|
||||
|
||||
this.integrationTime.setValue(integrationTime);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get minimum integration time
|
||||
* @return Min value for integration time
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getMinIntegrationTime() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.integrationTimeMin.getValue());
|
||||
}
|
||||
/**
|
||||
* Get maximum integration time
|
||||
* @return Max value for integration time
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getMaxIntegrationTime() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.integrationTimeMax.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get additional user defined backlash
|
||||
* @return User backlash
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Double getUserBacklash() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.userBacklash.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set additional user defined backlash
|
||||
* @param userBacklash
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setUserBacklash(Double userBacklash) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
if(userBacklash==null){
|
||||
throw new IllegalArgumentException("User backlash must not be null");
|
||||
}
|
||||
|
||||
this.userBacklash.setValue(userBacklash);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current NFS server the data is written to
|
||||
* @return Name of NFS server
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String getNfsServer() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.nfsServer.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name of the NFS server the data is written to
|
||||
* @param nfsServer
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setNfsServer(String nfsServer) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.nfsServer.setValue(nfsServer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the NFS share the data is written to
|
||||
* @return Name of NFS share
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String getNfsShare() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.nfsShare.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name of the NFS share the data is written to
|
||||
* @param nfsShare
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setNfsShare(String nfsShare) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.nfsShare.setValue(nfsShare);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the name of the data file
|
||||
* @return Name of data file name
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String getFileName() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.fileName.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set name of the data file
|
||||
* @param filename
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setFileName(String filename) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.fileName.setValue(filename);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get File name formate
|
||||
* @return Get format for file name
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String getFileNameFormat() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.fileNameFormat.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set file name formate of the data file
|
||||
* @param fileNameFormat
|
||||
* @throws Exception
|
||||
*/
|
||||
public void setFileNameFormat(String fileNameFormat) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.fileNameFormat.setValue(fileNameFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get value of the IOC based file name counter
|
||||
* @return File counter
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public int getFileCounter() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.fileCount.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the IOC based file counter
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void resetFileCounter() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.resetFileCounter.setValue(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if append file option is activated
|
||||
* @return Append file flag
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public boolean isAppendFile() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.appendFile.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to append the specified file if the file exists
|
||||
* @param append
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setAppendFile(boolean append) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.appendFile.setValue(append);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if file name generation is on or off
|
||||
* @return File name generation flag
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public boolean isFileNameGeneration() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.fileNameGeneration.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Whether the file name should be generated out of the file name format and the file counter
|
||||
* @param generation
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setFileNameGeneration(boolean generation) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.fileNameGeneration.setValue(generation);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get if ZigZag scan option is on or off
|
||||
* @return ZigZag flag
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public boolean isZigZag() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.zigZag.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set ZigZag scan mode on/off
|
||||
* @param zigZag ZigZag mode on = true, ZigZag mode off = false
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setZigZag(boolean zigZag) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.zigZag.setValue(zigZag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get whether encoder is used
|
||||
*/
|
||||
public boolean isUseEncoder() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(this.useEncoder.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag to use encoder
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setUseEncoder(boolean flag) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
this.useEncoder.setValue(flag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the channels that are currently monitored by the OTFScan logic
|
||||
* @return Names of the monitored channels
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String[] getMonitoredChannels() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
String[] values = new String[this.monitoredChannels.size()];
|
||||
|
||||
for(int i=0; i<this.monitoredChannels.size();i++){
|
||||
values[i] = monitoredChannels.get(i).getValue();
|
||||
}
|
||||
|
||||
return(values);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the channels that need to be monitored.
|
||||
* Note: As OTF only supports 8 channels to be monitored, only the first 8
|
||||
* values of the passed channelNames are considered.
|
||||
* @param values Array of channel names to be monitored
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public void setMonitoredChannels(String[] values) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
|
||||
if(values.length>monitoredChannels.size()){
|
||||
throw new IllegalArgumentException("Only up to "+monitoredChannels.size()+" monitored channels are supported by OTF");
|
||||
}
|
||||
|
||||
for(int i=0; i<this.monitoredChannels.size(); i++){
|
||||
if(values != null && i<values.length){
|
||||
this.monitoredChannels.get(i).setValue(values[i]);
|
||||
}
|
||||
else{
|
||||
this.monitoredChannels.get(i).setValue("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether an scan is running
|
||||
* @return Running flag
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public boolean isRunning() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(running.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get status of the scan
|
||||
* @return Status of the scan
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public Status getStatus() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(Status.values()[this.status.getValue()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the (error) message from the OTF records
|
||||
* @return Message from OTF C logic
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public String getMessage() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(message.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the specified motor is recognized as ok (i.e. it is registered as OTFScan motor)
|
||||
* @return Flag whether motor is ok
|
||||
* @throws TimeoutException, ChannelException, ExecutionException
|
||||
*/
|
||||
public boolean isMotorOk() throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
return(motorOk.getValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the motor flag goes to ok
|
||||
* @param timeout Timout in milliseconds
|
||||
*
|
||||
* @throws TimeoutException, ChannelException, ExecutionException If motor ok flag does not switch to ok within the specified timeout
|
||||
*/
|
||||
public void waitUntilMotorOk(long timeout) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
motorOk.waitForValue(true, timeout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Wait until the motor flag goes to not ok
|
||||
* @param timeout Timout in milliseconds
|
||||
*
|
||||
* @throws TimeoutException, ChannelException, ExecutionException If motor ok flag does not switch to ok within the specified timeout
|
||||
*/
|
||||
public void waitUntilMotorNotOk(long timeout) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
motorOk.waitForValue(false, timeout);
|
||||
}
|
||||
|
||||
|
||||
public void waitUntilEncoderOk(long timeout) throws TimeoutException, ChannelException, ExecutionException, InterruptedException {
|
||||
if(!useEncoder.getValue()){
|
||||
return;
|
||||
}
|
||||
encoderOk.waitForValue(true, timeout);
|
||||
}
|
||||
}
|
||||
@@ -1,533 +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.loops;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
//import jcifs.smb.SmbException;
|
||||
//import jcifs.smb.SmbFile;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.fda.core.actors.OTFActuator;
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.sensors.MillisecondTimestampSensor;
|
||||
import ch.psi.fda.core.sensors.OTFNamedChannelSensor;
|
||||
import ch.psi.fda.core.sensors.OTFReadbackSensor;
|
||||
import ch.psi.fda.core.sensors.OTFScalerChannelSensor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* ActionLoop that is implementing the OTF Scan logic.
|
||||
* While executing the loop a full OTF scan procedure is executed.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class OTFLoop implements ActionLoop {
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(OTFLoop.class.getName());
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the data of this loop will be grouped
|
||||
* According to this flag the dataGroup flag in EndOfStream will be set.
|
||||
*/
|
||||
private boolean dataGroup = false;
|
||||
|
||||
// Constants
|
||||
/**
|
||||
* Maximum number of monitored channels
|
||||
*/
|
||||
private static final int numberOfMonitoredChannels = 8;
|
||||
/**
|
||||
* Maximum number of Scaler channels
|
||||
*/
|
||||
private static final int numberOfScalerChannels = 16;
|
||||
|
||||
/**
|
||||
* Default timeout (in milliseconds) for wait operations
|
||||
*/
|
||||
private long timeout = 8000;
|
||||
|
||||
/**
|
||||
* Name of the NFS server to place the data of the OTF logic
|
||||
*/
|
||||
private final String server;
|
||||
/**
|
||||
* Share on the NFS server to put the OTF data on to
|
||||
*/
|
||||
private final String share;
|
||||
/**
|
||||
* SMB share to access the data written by the OTF C logic
|
||||
*/
|
||||
private final String smbShare;
|
||||
|
||||
/**
|
||||
* Flag whether the actor of this loop should move in zig zag mode
|
||||
*/
|
||||
private final boolean zigZag;
|
||||
|
||||
/**
|
||||
* Bean holding all OTF channels and functionality.
|
||||
*/
|
||||
private OTFBean obean;
|
||||
|
||||
/**
|
||||
* List of actions that are executed at the beginning of the loop.
|
||||
*/
|
||||
private List<Action> preActions;
|
||||
/**
|
||||
* List of actions that are executed at the end of the loop.
|
||||
*/
|
||||
private List<Action> postActions;
|
||||
|
||||
/**
|
||||
* Special OTF Actuator
|
||||
*/
|
||||
private OTFActuator actor = null;
|
||||
|
||||
/**
|
||||
* List of sensors of this loop
|
||||
*/
|
||||
private List<Sensor> sensors;
|
||||
|
||||
|
||||
private List<Integer> dataIndexes;
|
||||
|
||||
/**
|
||||
* Execution count of this loop. This count is used to determine the
|
||||
* file name of the OTF file.
|
||||
*/
|
||||
private int executionCount;
|
||||
|
||||
/**
|
||||
* Data queue sensor data is posted to. A message consists of a list of data objects
|
||||
* that are read out of the sensors of this loop.
|
||||
*/
|
||||
private BlockingQueue<Message> dataQueue;
|
||||
|
||||
/**
|
||||
* Flag that indicates that the loop was requested to abort.
|
||||
*/
|
||||
private volatile boolean abort = false;
|
||||
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param channelPrefix Prefix of the OTF related records, e.g. MTEST-HW3-OTF
|
||||
* @param server NFS server the OTF C Logic should put its data to
|
||||
* @param share Share on NFS server to put the OTF C Logic data
|
||||
* @param smbShare SMB share to get the data written by the OTF C Logic
|
||||
* @param zigZag Operate loop in zig zag mode
|
||||
*/
|
||||
public OTFLoop(ChannelService s, String channelPrefix, String server, String share, String smbShare, boolean zigZag){
|
||||
cservice = s;
|
||||
// Initialize connection to the OTF records
|
||||
try {
|
||||
this.obean = new OTFBean();
|
||||
Map<String,String> m = new HashMap<>();
|
||||
m.put("PREFIX", channelPrefix);
|
||||
s.createAnnotatedChannels(obean, m);
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
throw new IllegalArgumentException("Unable to connect to the OTF channels",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to connect to the OTF channels",e);
|
||||
}
|
||||
|
||||
// Store loop configuration
|
||||
this.server = server;
|
||||
this.share = share;
|
||||
this.smbShare = smbShare;
|
||||
this.zigZag = zigZag;
|
||||
|
||||
// Initialize lists used by the loop
|
||||
this.preActions = new ArrayList<Action>();
|
||||
this.postActions = new ArrayList<Action>();
|
||||
this.sensors = new ArrayList<Sensor>();
|
||||
|
||||
this.dataQueue = new LinkedBlockingQueue<Message>(2000);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
|
||||
// Execute pre actions
|
||||
for(Action action: preActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
// Start scan
|
||||
obean.start();
|
||||
|
||||
// Wait for end of scan
|
||||
obean.waitUntilStopped();
|
||||
|
||||
// Read data from file
|
||||
collectData();
|
||||
|
||||
// Execute post actions
|
||||
for(Action action: postActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
|
||||
// Issue end of loop control message
|
||||
dataQueue.put(new EndOfStreamMessage(dataGroup));
|
||||
|
||||
// Increase execution count
|
||||
executionCount++;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
// Abort otf scan logic
|
||||
obean.abort();
|
||||
|
||||
abort=true;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
executionCount = 0;
|
||||
|
||||
// Set abort flag to false
|
||||
abort=false;
|
||||
|
||||
// Check whether actor is set for the loop
|
||||
if(actor == null){
|
||||
throw new IllegalStateException("No actor specified for this loop");
|
||||
}
|
||||
|
||||
// list with all monitored channels
|
||||
List<String> monitoredChannels = new ArrayList<String>();
|
||||
dataIndexes = new ArrayList<Integer>();
|
||||
int channelCount =0;
|
||||
for(Sensor s: sensors){
|
||||
if(s instanceof OTFNamedChannelSensor){
|
||||
// Monitored channel
|
||||
OTFNamedChannelSensor so = (OTFNamedChannelSensor) s;
|
||||
if(channelCount>=numberOfMonitoredChannels){
|
||||
throw new IllegalArgumentException("Only up to "+numberOfMonitoredChannels+" channels can be monitored by OTF");
|
||||
}
|
||||
|
||||
monitoredChannels.add(so.getName());
|
||||
dataIndexes.add(2+numberOfScalerChannels+channelCount);
|
||||
|
||||
|
||||
channelCount++;
|
||||
}
|
||||
else if (s instanceof OTFScalerChannelSensor){
|
||||
OTFScalerChannelSensor so = (OTFScalerChannelSensor) s;
|
||||
if(so.getIndex()>=numberOfScalerChannels){
|
||||
throw new IllegalArgumentException("Scaler index must be between 0<=index<"+numberOfScalerChannels);
|
||||
}
|
||||
dataIndexes.add(2+so.getIndex()); // scalers follow directly after the readback
|
||||
}
|
||||
else if (s instanceof MillisecondTimestampSensor){
|
||||
dataIndexes.add(2+numberOfScalerChannels+numberOfMonitoredChannels);
|
||||
}
|
||||
else if (s instanceof OTFReadbackSensor){
|
||||
dataIndexes.add(1);
|
||||
}
|
||||
else{
|
||||
throw new IllegalArgumentException("Sensor type "+s.getClass()+" is not supported by this loop");
|
||||
}
|
||||
}
|
||||
|
||||
// Set OTF parameters
|
||||
try{
|
||||
obean.resetToDefaults();
|
||||
|
||||
// Set actor properties
|
||||
obean.setMotor(actor.getName());
|
||||
obean.waitUntilMotorOk(timeout);
|
||||
|
||||
obean.setBegin(actor.getStart());
|
||||
obean.setEnd(actor.getEnd());
|
||||
obean.setStepSize(actor.getStepSize());
|
||||
obean.setIntegrationTime(actor.getIntegrationTime());
|
||||
|
||||
// Override encoder if specified
|
||||
if(actor.getReadback()!=null){
|
||||
obean.setUseEncoder(true);
|
||||
obean.setEncoder(actor.getReadback());
|
||||
obean.waitUntilEncoderOk(timeout);
|
||||
}
|
||||
|
||||
// Set user backlash
|
||||
obean.setUserBacklash(actor.getAdditionalBacklash());
|
||||
|
||||
|
||||
// NFS settings
|
||||
obean.setNfsServer(server);
|
||||
obean.setNfsShare(share);
|
||||
|
||||
obean.setFileNameGeneration(true);
|
||||
obean.setAppendFile(false);
|
||||
obean.setZigZag(zigZag); // Set ZigZag because there might be iterations
|
||||
obean.setFileNameFormat("%06d"); // Force an update of the filename/counter by setting file format twice with different values
|
||||
obean.setFileNameFormat("%06d.txt");
|
||||
|
||||
|
||||
|
||||
// Set monitored channels
|
||||
obean.setMonitoredChannels(monitoredChannels.toArray(new String[monitoredChannels.size()]));
|
||||
}
|
||||
catch(ChannelException | ExecutionException | TimeoutException e){
|
||||
throw new RuntimeException("Unable to set OTF configuration parameters",e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to set OTF configuration parameters",e);
|
||||
}
|
||||
|
||||
|
||||
// Cleanup temporary directory
|
||||
try{
|
||||
DistributedFile tmpDir = new DistributedFile(smbShare);
|
||||
if( !tmpDir.exists() || !tmpDir.isDirectory() ){
|
||||
throw new RuntimeException("Cannot access OTF temporary directory "+tmpDir.getCanonicalPath());
|
||||
}
|
||||
DistributedFile[] files = tmpDir.listFiles();
|
||||
|
||||
for(int i=0;i<files.length;i++){
|
||||
// Only delete item if it is not a directory and if it matches the given pattern.
|
||||
if(files[i].isFile() && files[i].getName().matches("[0-9]+.txt")){
|
||||
files[i].delete();
|
||||
logger.fine("Delete file: "+files[i].getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch(MalformedURLException e){
|
||||
throw new RuntimeException(e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to access share (temporary files)",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#cleanup()
|
||||
*/
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Close all connections used by the OTFBean
|
||||
try {
|
||||
cservice.destroyAnnotatedChannels(obean);
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException("Unable to destroy channels",e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (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;
|
||||
}
|
||||
|
||||
/**
|
||||
* The structure of the data message depends on the sensors registered at this loop
|
||||
* at the time this method is called.
|
||||
* @return the data queue and the metadata of the data messages
|
||||
*/
|
||||
public DataQueue getDataQueue() {
|
||||
DataMessageMetadata m = new DataMessageMetadata();
|
||||
|
||||
// Build up data message metadata based on the sensors currently registered.
|
||||
for(Sensor s: sensors){
|
||||
m.getComponents().add(new ComponentMetadata(s.getId()));
|
||||
}
|
||||
return new DataQueue(dataQueue, m);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collect data written by the OTFScan logic
|
||||
* @param dataSet
|
||||
* @param tmpFile
|
||||
*/
|
||||
private void collectData() {
|
||||
try{
|
||||
final int timestampIndex = 2+numberOfScalerChannels+numberOfMonitoredChannels;
|
||||
|
||||
DistributedFile tmpFile = new DistributedFile(smbShare +"/"+ String.format("%06d.txt", executionCount));
|
||||
logger.fine("Collect data from "+tmpFile.getCanonicalPath());
|
||||
|
||||
DistributedFile lockfile = new DistributedFile(tmpFile.getCanonicalPath() + ".lock");
|
||||
|
||||
logger.fine("Wait until file is written [lock file: "+lockfile.getCanonicalPath()+"]");
|
||||
// Wait until file is created
|
||||
while ((!tmpFile.exists()) || lockfile.exists()) {
|
||||
Thread.sleep(500);
|
||||
if(abort){
|
||||
// If abort is issued while waiting for data immediately return without
|
||||
// trying to read the data
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
logger.fine("Read file " + tmpFile.getCanonicalPath());
|
||||
InputStreamReader inreader = tmpFile.getInputStream();
|
||||
BufferedReader in = new BufferedReader(inreader);
|
||||
String line;
|
||||
boolean firstline = true;
|
||||
while (true) {
|
||||
line = in.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
} else {
|
||||
if(line.matches("^\\[.*")){
|
||||
// Skip header lines
|
||||
}
|
||||
else{
|
||||
if(firstline){
|
||||
firstline=false;
|
||||
continue;
|
||||
}
|
||||
|
||||
DataMessage message = new DataMessage();
|
||||
// Add data to dataset
|
||||
String[] tokens = line.split("\t");
|
||||
|
||||
for(Integer i: dataIndexes){
|
||||
try{
|
||||
if(i == timestampIndex) {
|
||||
// Calculate time in milliseconds
|
||||
Double seconds = new Double(tokens[i]);
|
||||
Double nanoseconds = new Double(tokens[i+1]);
|
||||
|
||||
Double v = seconds*1000+Math.floor(nanoseconds*0.000001);
|
||||
message.getData().add(v);
|
||||
}
|
||||
else {
|
||||
|
||||
message.getData().add(new Double(tokens[i]));
|
||||
}
|
||||
}
|
||||
catch(NumberFormatException e){
|
||||
logger.warning("Cannot parse component ["+tokens[i]+"] from source file - will add 0 for this component");
|
||||
message.getData().add(new Double(0));
|
||||
}
|
||||
}
|
||||
dataQueue.put(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
inreader.close();
|
||||
} catch(InterruptedException e){
|
||||
throw new RuntimeException("An interrupt occured while waiting for the file to show up",e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("An IO Exception occured while reading the OTF data file",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Getter functions for variable parts
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return the sensors
|
||||
*/
|
||||
public List<Sensor> getSensors() {
|
||||
return sensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actor
|
||||
*/
|
||||
public OTFActuator getActor() {
|
||||
return actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actor the actor to set
|
||||
*/
|
||||
public void setActor(OTFActuator actor) {
|
||||
this.actor = actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataGroup
|
||||
*/
|
||||
public boolean isDataGroup() {
|
||||
return dataGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param dataGroup the dataGroup to set
|
||||
*/
|
||||
public void setDataGroup(boolean dataGroup) {
|
||||
this.dataGroup = dataGroup;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,157 +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.loops.cr;
|
||||
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class CrlogicChannelsTemplate {
|
||||
|
||||
/**
|
||||
* Status of the OTFSCAN IOC logic
|
||||
*/
|
||||
public enum Status { SETUP, INACTIVE, INITIALIZE, ACTIVE, STOP, FAULT, ERROR };
|
||||
|
||||
/**
|
||||
* Ticks per second - IOC setting
|
||||
* ATTENTION - This field must only be set bu the IOC - ATTENTION
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}:TPS")
|
||||
private Channel<Integer> ticksPerSecond;
|
||||
|
||||
/**
|
||||
* Status of the OTFSCAN IOC logic
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:STATUS")
|
||||
private Channel<String> status;
|
||||
|
||||
/**
|
||||
* Message from the OTFSCAN IOC logic
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:MSG")
|
||||
private Channel<String> message;
|
||||
|
||||
/**
|
||||
* IOC ticks between data acquisition interrupts
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}:TBINT")
|
||||
private Channel<Integer> ticksBetweenInterrupts;
|
||||
|
||||
/**
|
||||
* Name or ip address of the NFS server to save the data to
|
||||
* (depending on the IOC setup)
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:NFSSE")
|
||||
private Channel<String> nfsServer;
|
||||
|
||||
/**
|
||||
* Name of the NFS share on the NFS server
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:NFSSH")
|
||||
private Channel<String> nfsShare;
|
||||
|
||||
/**
|
||||
* Name of the data file
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}:DFNAM")
|
||||
private Channel<String> dataFile;
|
||||
|
||||
/**
|
||||
* Flag to identify whether the data file should be appended
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}:FAPPE")
|
||||
private Channel<Boolean> appendFile;
|
||||
|
||||
|
||||
/**
|
||||
* Readout resources
|
||||
*/
|
||||
@CaChannel(type=String[].class, name ="${PREFIX}:RRES")
|
||||
private Channel<String[]> readoutResources;
|
||||
|
||||
|
||||
/**
|
||||
* @return the ticksPerSecond
|
||||
*/
|
||||
public Channel<Integer> getTicksPerSecond() {
|
||||
return ticksPerSecond;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the status
|
||||
*/
|
||||
public Channel<String> getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the message
|
||||
*/
|
||||
public Channel<String> getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the ticksBetweenInterrupts
|
||||
*/
|
||||
public Channel<Integer> getTicksBetweenInterrupts() {
|
||||
return ticksBetweenInterrupts;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nfsServer
|
||||
*/
|
||||
public Channel<String> getNfsServer() {
|
||||
return nfsServer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nfsShare
|
||||
*/
|
||||
public Channel<String> getNfsShare() {
|
||||
return nfsShare;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dataFile
|
||||
*/
|
||||
public Channel<String> getDataFile() {
|
||||
return dataFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the appendFile
|
||||
*/
|
||||
public Channel<Boolean> getAppendFile() {
|
||||
return appendFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readoutResources
|
||||
*/
|
||||
public Channel<String[]> getReadoutResources() {
|
||||
return readoutResources;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,47 +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.loops.cr;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class CrlogicDeltaDataFilter {
|
||||
|
||||
private Double lastValue = null;
|
||||
|
||||
public void reset(){
|
||||
lastValue = null;
|
||||
}
|
||||
|
||||
public Double delta(Double value){
|
||||
|
||||
Double lvalue = lastValue;
|
||||
lastValue = value;
|
||||
|
||||
if(lvalue==null){
|
||||
return Double.NaN;
|
||||
}
|
||||
else{
|
||||
// Return delta
|
||||
return(value-lvalue);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,908 +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.loops.cr;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import jcifs.smb.SmbFile;
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.fda.core.actors.OTFActuator;
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
import ch.psi.fda.core.sensors.MillisecondTimestampSensor;
|
||||
import ch.psi.fda.core.sensors.OTFNamedChannelSensor;
|
||||
import ch.psi.fda.core.sensors.OTFScalerChannelSensor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
* While using Crlogic the IOC system clock rate should/must be set to 1000 (default 60)
|
||||
*
|
||||
* sysClkRateSet 1000
|
||||
*
|
||||
*/
|
||||
public class CrlogicLoop implements ActionLoop {
|
||||
|
||||
// Get Logger
|
||||
private static final Logger logger = Logger.getLogger(CrlogicLoop.class.getName());
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the data of this loop will be grouped
|
||||
* According to this flag the dataGroup flag in EndOfStream will be set.
|
||||
*/
|
||||
private boolean dataGroup = false;
|
||||
|
||||
private boolean keepTmpFiles = false;
|
||||
|
||||
private BlockingQueue<String> readQueue = new LinkedBlockingQueue<String>();
|
||||
private volatile boolean stopReadoutThread = false;
|
||||
private Thread readoutThread;
|
||||
|
||||
// Constants
|
||||
|
||||
/**
|
||||
* Default timeout (in milliseconds) for wait operations
|
||||
*/
|
||||
private long startStopTimeout = 8000;
|
||||
|
||||
/**
|
||||
* Name of the NFS server to place the data of the OTF logic
|
||||
*/
|
||||
private final String server;
|
||||
/**
|
||||
* Share on the NFS server to put the OTF data on to
|
||||
*/
|
||||
private final String share;
|
||||
/**
|
||||
* SMB share to access the data written by the OTF C logic
|
||||
*/
|
||||
private final String smbShare;
|
||||
|
||||
/**
|
||||
* Flag whether the actor of this loop should move in zig zag mode
|
||||
*/
|
||||
private final boolean zigZag;
|
||||
|
||||
boolean useReadback;
|
||||
boolean useEncoder;
|
||||
|
||||
/**
|
||||
* List of actions that are executed at the beginning of the loop.
|
||||
*/
|
||||
private List<Action> preActions;
|
||||
/**
|
||||
* List of actions that are executed at the end of the loop.
|
||||
*/
|
||||
private List<Action> postActions;
|
||||
|
||||
/**
|
||||
* Prefix for the CRLOGIC channels
|
||||
*/
|
||||
private String prefix;
|
||||
|
||||
private CrlogicChannelsTemplate template;
|
||||
private MotorChannelsTemplate motortemplate;
|
||||
|
||||
/**
|
||||
* Semaphore to ensure that data is read in correct sequence
|
||||
*/
|
||||
private Semaphore semaphore = new Semaphore(1);
|
||||
|
||||
/**
|
||||
* Special OTF Actuator
|
||||
*/
|
||||
private OTFActuator actuator = null;
|
||||
|
||||
/**
|
||||
* List of sensors of this loop
|
||||
*/
|
||||
private List<Sensor> sensors;
|
||||
|
||||
private List<String> readoutResources;
|
||||
private Map<Integer, CrlogicDeltaDataFilter> scalerIndices;
|
||||
private CrlogicRangeDataFilter crlogicDataFilter;
|
||||
|
||||
/**
|
||||
* Data queue sensor data is posted to. A message consists of a list of data objects
|
||||
* that are read out of the sensors of this loop.
|
||||
*/
|
||||
private BlockingQueue<Message> dataQueue;
|
||||
|
||||
/**
|
||||
* Abort status
|
||||
*/
|
||||
private boolean abort = false;
|
||||
private boolean abortForce = false;
|
||||
private Thread executionThread = null;
|
||||
|
||||
private ChannelService cservice;
|
||||
public CrlogicLoop(ChannelService s, String prefix, String server, String share, String smbShare, boolean zigZag){
|
||||
cservice = s;
|
||||
this.prefix = prefix;
|
||||
this.server = server;
|
||||
this.share = share;
|
||||
this.smbShare = smbShare;
|
||||
this.zigZag = zigZag;
|
||||
|
||||
// Initialize lists used by the loop
|
||||
this.preActions = new ArrayList<Action>();
|
||||
this.postActions = new ArrayList<Action>();
|
||||
this.sensors = new ArrayList<Sensor>();
|
||||
this.readoutResources = new ArrayList<String>();
|
||||
this.scalerIndices = new HashMap<Integer, CrlogicDeltaDataFilter>();
|
||||
|
||||
this.crlogicDataFilter = new CrlogicRangeDataFilter();
|
||||
this.dataQueue = new LinkedBlockingQueue<Message>(2000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Collect data from share
|
||||
* @param tmpFileName Name of the temporary file
|
||||
* @throws InterruptedException
|
||||
* @throws IOException
|
||||
*/
|
||||
private void collectData(String tmpDir, String tmpFileName) throws InterruptedException, IOException {
|
||||
semaphore.acquire();
|
||||
if (tmpDir.startsWith("smb:")) {
|
||||
|
||||
SmbFile tmpFile = new SmbFile(tmpDir, tmpFileName);
|
||||
logger.info("Collect data from " + tmpFile.getCanonicalPath());
|
||||
|
||||
SmbFile lockfile = new SmbFile(tmpFile.getCanonicalPath() + ".lock");
|
||||
|
||||
logger.info("Wait until file is written [lock file: " + lockfile.getCanonicalPath() + "]");
|
||||
// Wait until file is created
|
||||
while ((!tmpFile.exists()) || lockfile.exists()) {
|
||||
try{
|
||||
Thread.sleep(100);
|
||||
}
|
||||
catch(InterruptedException e){
|
||||
abort=true;
|
||||
}
|
||||
if(abort){
|
||||
// If abort is issued while waiting for data immediately return without
|
||||
// trying to read the data
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
InputStreamReader inreader = new InputStreamReader(tmpFile.getInputStream());
|
||||
BufferedReader in = new BufferedReader(inreader);
|
||||
String line;
|
||||
boolean firstline = true;
|
||||
int linecount=0;
|
||||
int mcounter=0;
|
||||
|
||||
// boolean wasInRangeBefore = false;
|
||||
boolean discardAnyway = false;
|
||||
|
||||
while (true) {
|
||||
line = in.readLine();
|
||||
linecount++;
|
||||
if (line == null) {
|
||||
break;
|
||||
} else {
|
||||
// if(line.matches("^\\[.*")){
|
||||
if (line.matches("^ *#.*")) {
|
||||
// Skip header/comment lines
|
||||
// logger.info("HEADER: " + line);
|
||||
} else {
|
||||
if (firstline) {
|
||||
firstline = false;
|
||||
continue;
|
||||
}
|
||||
|
||||
// logger.info(line);
|
||||
|
||||
// Write into queue
|
||||
DataMessage message = new DataMessage();
|
||||
String[] tokens = line.split("\t");
|
||||
boolean use = true;
|
||||
|
||||
for(int i=0;i<tokens.length;i++){
|
||||
String t = tokens[i];
|
||||
Double val;
|
||||
|
||||
if(i==0){
|
||||
Double raw = new Double(t);
|
||||
|
||||
if(useEncoder){
|
||||
val = crlogicDataFilter.calculatePositionMotorUseEncoder(raw);
|
||||
}
|
||||
else if(useReadback){
|
||||
val = crlogicDataFilter.calculatePositionMotorUseReadback(raw);
|
||||
}
|
||||
else{
|
||||
val = crlogicDataFilter.calculatePositionMotor(raw);
|
||||
}
|
||||
|
||||
// Check whether data is within the configured range - otherwise drop data
|
||||
use = crlogicDataFilter.filter(val);
|
||||
// if(!use){
|
||||
// break;
|
||||
// }
|
||||
}
|
||||
else if(scalerIndices.containsKey(i)){
|
||||
CrlogicDeltaDataFilter f = scalerIndices.get(i);
|
||||
val = f.delta(new Double(t));
|
||||
}
|
||||
else{
|
||||
val = new Double(t);
|
||||
}
|
||||
|
||||
|
||||
message.getData().add(val);
|
||||
}
|
||||
|
||||
// Does not work if zigzag, ...
|
||||
// // Use this to filter out motor retry movements at the end of the scan
|
||||
// wasInRangeBefore = wasInRangeBefore | use;
|
||||
// if(!use && wasInRangeBefore){
|
||||
// discardAnyway=true;
|
||||
// // Optimization - terminate read loop once range is left
|
||||
// logger.info("Terminate read loop because point is outside range");
|
||||
// break;
|
||||
// }
|
||||
|
||||
// Filter data
|
||||
if(use && !discardAnyway){
|
||||
dataQueue.put(message);
|
||||
mcounter++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
inreader.close();
|
||||
|
||||
logger.info("Lines read: "+linecount+" Messages generated (after filtering): "+mcounter);
|
||||
|
||||
// Remove temporary file
|
||||
if(!keepTmpFiles){
|
||||
tmpFile.delete();
|
||||
}
|
||||
}
|
||||
else{
|
||||
// TODO - File in local file system
|
||||
}
|
||||
|
||||
// Issue end of loop control message
|
||||
dataQueue.put(new EndOfStreamMessage(dataGroup));
|
||||
semaphore.release();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
try{
|
||||
|
||||
double stepSize = actuator.getStepSize();
|
||||
double start = actuator.getStart();
|
||||
double end = actuator.getEnd();
|
||||
double integrationTime = actuator.getIntegrationTime();
|
||||
double ubacklash = actuator.getAdditionalBacklash();
|
||||
|
||||
// Set values for the datafilter
|
||||
crlogicDataFilter.setStart(actuator.getStart());
|
||||
crlogicDataFilter.setEnd(actuator.getEnd());
|
||||
|
||||
// Reset data filter
|
||||
for(Integer k: scalerIndices.keySet()){
|
||||
scalerIndices.get(k).reset();
|
||||
}
|
||||
|
||||
synchronized(this){
|
||||
// Set abort state to false
|
||||
abort = false;
|
||||
abortForce = false;
|
||||
|
||||
// Set execution thread to current thread
|
||||
executionThread = Thread.currentThread();
|
||||
}
|
||||
|
||||
|
||||
// TODO each actuator will result in an additional sensor (at the beginning)
|
||||
// Dependent on actuator settings (readback use encoder, ...)
|
||||
|
||||
|
||||
// TODO filename generation?
|
||||
final String tmpFileName = "tmp-"+System.currentTimeMillis()+".txt";
|
||||
|
||||
Long timeout = 600000l; // 10 minutes move timeout
|
||||
|
||||
// Check if logic is inactive, otherwise return early
|
||||
if(!template.getStatus().getValue().equals(CrlogicChannelsTemplate.Status.INACTIVE.toString())){
|
||||
logger.info("CRLOGIC is not inactive!");
|
||||
// TODO Decide what to do in this situation
|
||||
|
||||
if(template.getStatus().getValue().equals(CrlogicChannelsTemplate.Status.FAULT.toString())){
|
||||
// If in fault show message and recover
|
||||
logger.info("CRLOGIC in FAULT state");
|
||||
logger.info("Error message: "+template.getMessage().getValue());
|
||||
logger.info("Recover logic and set it to INACTIVE");
|
||||
template.getStatus().setValue(CrlogicChannelsTemplate.Status.INACTIVE.toString());
|
||||
}
|
||||
else if(template.getStatus().getValue().equals(CrlogicChannelsTemplate.Status.ACTIVE.toString())){
|
||||
template.getStatus().setValue(CrlogicChannelsTemplate.Status.STOP.toString());
|
||||
template.getStatus().waitForValue(CrlogicChannelsTemplate.Status.INACTIVE.toString(), startStopTimeout);
|
||||
}
|
||||
else{
|
||||
throw new RuntimeException("CRLOGIC is not inactive");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
logger.info("Set parameters");
|
||||
template.getNfsServer().setValue(server);
|
||||
template.getNfsShare().setValue(share);
|
||||
template.getDataFile().setValue(tmpFileName);
|
||||
|
||||
int tps = template.getTicksPerSecond().getValue();
|
||||
logger.info("Ticks per second: "+tps);
|
||||
|
||||
logger.info("Set readout resources");
|
||||
|
||||
template.getReadoutResources().setValue(readoutResources.toArray(new String[readoutResources.size()]));
|
||||
|
||||
|
||||
|
||||
// Set ticks between interrupt to integration time
|
||||
int ticks = (int)(tps*integrationTime);
|
||||
template.getTicksBetweenInterrupts().setValue(ticks);
|
||||
|
||||
// Prepare motor
|
||||
double totalTimeSeconds = Math.abs((end-start)/stepSize*integrationTime);
|
||||
int hours = (int) Math.floor(totalTimeSeconds/60/60);
|
||||
int minutes = (int) Math.floor(totalTimeSeconds/60-hours*60);
|
||||
int seconds = (int) Math.floor(totalTimeSeconds-hours*60*60-minutes*60);
|
||||
|
||||
logger.info("Estimated time: "+hours+":"+minutes+":"+seconds);
|
||||
|
||||
int direction = 1;
|
||||
if(end-start<0){
|
||||
direction = -1;
|
||||
}
|
||||
|
||||
double motorBaseSpeed = motortemplate.getBaseSpeed().getValue();
|
||||
double motorHighLimit = motortemplate.getHighLimit().getValue();
|
||||
double motorLowLimit = motortemplate.getLowLimit().getValue();
|
||||
double motorBacklash = motortemplate.getBacklashDistance().getValue();
|
||||
|
||||
boolean respectMotorMinSpeed = false; // if false set min speed to 0
|
||||
double motorMinSpeed = 0;
|
||||
if(respectMotorMinSpeed){
|
||||
motorMinSpeed = motorBaseSpeed;
|
||||
}
|
||||
|
||||
// Check user parameters
|
||||
// TODO start and end values must be between the motor high and low value - otherwise fail
|
||||
if(start>motorHighLimit || start<motorLowLimit){
|
||||
// Start value is outside motor high and/or low value
|
||||
logger.info("Start value is outside motor high and/or low value");
|
||||
throw new IllegalArgumentException("Start value is outside motor high and/or low value");
|
||||
}
|
||||
if(end>motorHighLimit || end<motorLowLimit){
|
||||
// End value is outside motor high and/or low value
|
||||
logger.info("End value is outside motor high and/or low value");
|
||||
throw new IllegalArgumentException("End value is outside motor high and/or low value");
|
||||
}
|
||||
// TODO Check minimum step size
|
||||
int minimumTicks = 10;
|
||||
double minStepSize = motorMinSpeed*(minimumTicks/tps);
|
||||
if(stepSize<minStepSize){
|
||||
// Step size is too small
|
||||
logger.info("Step size is too small");
|
||||
throw new IllegalArgumentException("Step size is too small");
|
||||
}
|
||||
// TODO Check integration time
|
||||
if(motorMinSpeed>0){
|
||||
double maxIntegrationTime = stepSize/motorMinSpeed;
|
||||
if(integrationTime>maxIntegrationTime){
|
||||
logger.info("Integration time is too big");
|
||||
// Integration time is too big
|
||||
throw new IllegalArgumentException("Integration time is too big");
|
||||
}
|
||||
}
|
||||
double motorMaxSpeed = motortemplate.getVelocity().getValue();
|
||||
double minIntegrationTime = Math.min( (stepSize/motorMaxSpeed), ((double)minimumTicks/(double)tps) );
|
||||
if(integrationTime<minIntegrationTime){
|
||||
// Integration time is too small
|
||||
logger.info("Integration time is too small [min integration time: "+minIntegrationTime+"]");
|
||||
throw new IllegalArgumentException("Integration time is too small [min integration time: "+minIntegrationTime+"]");
|
||||
}
|
||||
|
||||
|
||||
// TODO Calculate and set motor speed, backlash, etc.
|
||||
double motorSpeed = stepSize/integrationTime;
|
||||
double backlash = (0.5*motorSpeed*motortemplate.getAccelerationTime().getValue())+motorBacklash+ubacklash;
|
||||
double realEnd = end+(backlash*direction);
|
||||
double realStart = start-(backlash*direction);
|
||||
|
||||
|
||||
// Move to start
|
||||
logger.info("Move motor to start ["+realStart+"]");
|
||||
motortemplate.getSetValue().setValueAsync(realStart).get(timeout, TimeUnit.MILLISECONDS); // Will block until move is done
|
||||
|
||||
|
||||
// Set motor paramters
|
||||
// Backup settings
|
||||
logger.info("Backup motor settings");
|
||||
double backupSpeed = motortemplate.getVelocity().getValue();
|
||||
double backupBacklash = motorBacklash;
|
||||
double backupMinSpeed = motorBaseSpeed;
|
||||
|
||||
try{
|
||||
// Set motor settings
|
||||
logger.info("Update motor settings");
|
||||
// if(!respectMotorMinSpeed){
|
||||
// motortemplate.getBaseSpeed().setValue(0d);
|
||||
// }
|
||||
// Set base speed as fast as possible but not faster than the original base speed.
|
||||
double base = motorBaseSpeed;
|
||||
if(motorSpeed<base){
|
||||
base = motorSpeed;
|
||||
}
|
||||
motortemplate.getBaseSpeed().setValue(base);
|
||||
motortemplate.getVelocity().setValue(motorSpeed);
|
||||
motortemplate.getBacklashDistance().setValue(0d);
|
||||
|
||||
|
||||
// Execute pre actions
|
||||
for(Action action: preActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
|
||||
// Start crlogic logic
|
||||
logger.info("Start CRLOGIC");
|
||||
template.getStatus().setValue(CrlogicChannelsTemplate.Status.INITIALIZE.toString());
|
||||
try{
|
||||
template.getStatus().waitForValue(CrlogicChannelsTemplate.Status.ACTIVE.toString(), startStopTimeout);
|
||||
}
|
||||
catch(ChannelException e){
|
||||
logger.info( "Failed to start CRLOGIC. Logic in status: "+template.getStatus().getValue() );
|
||||
if(template.getStatus().getValue().equals(CrlogicChannelsTemplate.Status.FAULT.toString())){
|
||||
logger.info("Error message: "+template.getMessage().getValue());
|
||||
}
|
||||
// Recover to inactive
|
||||
template.getStatus().setValue(CrlogicChannelsTemplate.Status.INACTIVE.toString());
|
||||
// TODO Improve error handling
|
||||
throw new RuntimeException("Failed to start CRLOGIC. Logic in status: "+template.getStatus().getValue()+ " Error message: "+template.getMessage().getValue(), e);
|
||||
|
||||
}
|
||||
|
||||
// Move motor(s) to end / wait until motor is stopped
|
||||
logger.info("Move motor to end ["+realEnd+"]");
|
||||
try{
|
||||
motortemplate.getSetValue().setValueAsync(realEnd).get(timeout, TimeUnit.MILLISECONDS); // Will block until move is done
|
||||
}
|
||||
catch (InterruptedException e) {
|
||||
if(abort & (!abortForce)){
|
||||
// Abort motor move
|
||||
motortemplate.getCommand().setValue(MotorChannelsTemplate.Commands.Stop.ordinal());
|
||||
motortemplate.getCommand().setValue(MotorChannelsTemplate.Commands.Go.ordinal());
|
||||
}
|
||||
else{
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
logger.info("Motor reached end position");
|
||||
|
||||
// Stop crlogic logic
|
||||
logger.info("Stop CRLOGIC");
|
||||
template.getStatus().setValue(CrlogicChannelsTemplate.Status.STOP.toString());
|
||||
// Wait until stopped
|
||||
logger.info("Wait until stopped");
|
||||
try{
|
||||
template.getStatus().waitForValue(CrlogicChannelsTemplate.Status.INACTIVE.toString(), startStopTimeout);
|
||||
}
|
||||
catch(ChannelException | ExecutionException e){
|
||||
logger.info( "Failed to stop CRLOGIC. Logic in status: "+template.getStatus().getValue() );
|
||||
// TODO Improve error handling
|
||||
throw new RuntimeException("Failed to stop CRLOGIC. Logic in status: "+template.getStatus().getValue(), e);
|
||||
}
|
||||
logger.info("CRLOGIC is now stopped");
|
||||
|
||||
|
||||
// Execute post actions
|
||||
for(Action action: postActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
finally{
|
||||
logger.info("Restore motor settings");
|
||||
motortemplate.getBaseSpeed().setValue(backupMinSpeed);
|
||||
motortemplate.getVelocity().setValue(backupSpeed);
|
||||
motortemplate.getBacklashDistance().setValue(backupBacklash);
|
||||
}
|
||||
|
||||
// Request read of data file
|
||||
readQueue.put(tmpFileName);
|
||||
|
||||
// // Read data
|
||||
// Thread t = new Thread(new Runnable() {
|
||||
//
|
||||
// @Override
|
||||
// public void run() {
|
||||
// try {
|
||||
// collectData(smbShare, tmpFileName);
|
||||
// } catch (InterruptedException e) {
|
||||
// throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// t.start();
|
||||
|
||||
if(zigZag){
|
||||
// Swap start and end
|
||||
double aend = actuator.getEnd();
|
||||
actuator.setEnd(actuator.getStart());
|
||||
actuator.setStart(aend);
|
||||
}
|
||||
|
||||
synchronized(this){
|
||||
executionThread = null;
|
||||
}
|
||||
}
|
||||
catch(ChannelException | ExecutionException | TimeoutException e){
|
||||
throw new RuntimeException("Unable to execute crloop", e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
abort(false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Abort logic
|
||||
* @param force
|
||||
*/
|
||||
public synchronized void abort(boolean force){
|
||||
abort = true;
|
||||
abortForce = force;
|
||||
|
||||
// executionThread variable guarded by "this"
|
||||
if(executionThread != null){
|
||||
executionThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
stopReadoutThread = true;
|
||||
readoutThread.interrupt();
|
||||
// TODO eventually interrupt readout thread
|
||||
|
||||
try {
|
||||
|
||||
cservice.destroyAnnotatedChannels(template);
|
||||
cservice.destroyAnnotatedChannels(motortemplate);
|
||||
template = null;
|
||||
motortemplate = null;
|
||||
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("Unable to destroy CrlogicLoop", e);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
|
||||
stopReadoutThread = false;
|
||||
// Start readout Thread
|
||||
readoutThread = new Thread(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
while(!stopReadoutThread){
|
||||
String file;
|
||||
try {
|
||||
file = readQueue.take();
|
||||
} catch (InterruptedException e) {
|
||||
break;
|
||||
}
|
||||
// TODO Read file and
|
||||
try {
|
||||
collectData(smbShare, file);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("Unable to read CRLOGIC raw data file",e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
});
|
||||
readoutThread.start();
|
||||
|
||||
try{
|
||||
// Connect crlogic channels
|
||||
template = new CrlogicChannelsTemplate();
|
||||
logger.info("Connect channels");
|
||||
Map<String, String> m = new HashMap<>();
|
||||
m.put("PREFIX", prefix);
|
||||
cservice.createAnnotatedChannels(template, m);
|
||||
|
||||
// Connect motor channels
|
||||
motortemplate = new MotorChannelsTemplate();
|
||||
m = new HashMap<>();
|
||||
m.put("PREFIX", actuator.getName());
|
||||
cservice.createAnnotatedChannels(motortemplate, m);
|
||||
|
||||
useReadback = motortemplate.getUseReadback().getValue();
|
||||
useEncoder = motortemplate.getUseEncoder().getValue();
|
||||
|
||||
logger.info("Motor type: "+ MotorChannelsTemplate.Type.values()[motortemplate.getType().getValue()]);
|
||||
logger.info("Motor use readback: "+useReadback);
|
||||
logger.info("Motor use encoder: "+useEncoder);
|
||||
|
||||
// TODO build up list of readout resources (based on sensors)
|
||||
readoutResources.clear();
|
||||
// first sensor is the actuator
|
||||
|
||||
// Determine mode of motor
|
||||
if((!useReadback) && (!useEncoder)){
|
||||
// Open loop
|
||||
if(actuator.getReadback()!=null){
|
||||
throw new IllegalArgumentException("Readback not supported if motor is configured in open loop");
|
||||
}
|
||||
else{
|
||||
readoutResources.add(actuator.getName());
|
||||
}
|
||||
|
||||
}
|
||||
else if(useReadback && (!useEncoder)){
|
||||
String readback;
|
||||
// use readback link
|
||||
if(actuator.getReadback()!=null){
|
||||
// Use specified readback
|
||||
readback = (actuator.getReadback());
|
||||
}
|
||||
else{
|
||||
// Set resouce to readback link
|
||||
readback = (motortemplate.getReadbackLink().getValue());
|
||||
readback = readback.replaceAll(" +.*", ""); // remove NPP etc at the end
|
||||
}
|
||||
|
||||
readoutResources.add(readback);
|
||||
|
||||
// Fill readback encoder settings
|
||||
// Connect to encoder
|
||||
EncoderChannelsTemplate encodertemplate = new EncoderChannelsTemplate();
|
||||
m = new HashMap<>();
|
||||
m.put("PREFIX", readback);
|
||||
cservice.createAnnotatedChannels(encodertemplate, m);
|
||||
|
||||
// Read encoder settings
|
||||
if(encodertemplate.getDirection().getValue()==EncoderChannelsTemplate.Direction.Positive.ordinal()){
|
||||
crlogicDataFilter.setEncoderDirection(1);
|
||||
}
|
||||
else{
|
||||
crlogicDataFilter.setEncoderDirection(-1);
|
||||
}
|
||||
crlogicDataFilter.setEncoderOffset(encodertemplate.getOffset().getValue());
|
||||
crlogicDataFilter.setEncoderResolution(encodertemplate.getResolution().getValue());
|
||||
|
||||
// Disconnect from encoder
|
||||
cservice.destroyAnnotatedChannels(encodertemplate);
|
||||
|
||||
}
|
||||
else if (useEncoder && (!useReadback)){
|
||||
// use readback link
|
||||
if(actuator.getReadback()!=null){
|
||||
throw new IllegalArgumentException("Readback not supported if motor is configured to use encoder");
|
||||
}
|
||||
else{
|
||||
// Set resouce to readback link
|
||||
readoutResources.add(actuator.getName()+"_ENC");
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new IllegalArgumentException("Motor configuration not supportet: use readback - "+useReadback+" use encoder - "+useEncoder);
|
||||
}
|
||||
|
||||
// Fill Motor specific settings
|
||||
if(motortemplate.getDirection().getValue()==MotorChannelsTemplate.Direction.Positive.ordinal()){
|
||||
crlogicDataFilter.setMotorDirection(1);
|
||||
}
|
||||
else{
|
||||
crlogicDataFilter.setMotorDirection(-1);
|
||||
}
|
||||
crlogicDataFilter.setMotorEncoderResolution(motortemplate.getEncoderResolution().getValue());
|
||||
crlogicDataFilter.setMotorOffset(motortemplate.getOffset().getValue());
|
||||
crlogicDataFilter.setMotorReadbackResolution(motortemplate.getReadbackResolution().getValue());
|
||||
crlogicDataFilter.setMotorResolution(motortemplate.getMotorResolution().getValue());
|
||||
|
||||
// Clear all indices
|
||||
scalerIndices.clear();
|
||||
|
||||
int c = 1; // We start at 1 because the actuator right now is an implicit sensor
|
||||
for(Sensor s: sensors){
|
||||
if(s instanceof OTFNamedChannelSensor){
|
||||
// Monitored channel (MUST be configured MODULE ID'S)
|
||||
OTFNamedChannelSensor so = (OTFNamedChannelSensor) s;
|
||||
readoutResources.add(so.getName());
|
||||
}
|
||||
else if (s instanceof OTFScalerChannelSensor){
|
||||
OTFScalerChannelSensor so = (OTFScalerChannelSensor) s;
|
||||
readoutResources.add("SCALER"+so.getIndex());
|
||||
scalerIndices.put(c, new CrlogicDeltaDataFilter());
|
||||
}
|
||||
else if (s instanceof MillisecondTimestampSensor){
|
||||
readoutResources.add("TIMESTAMP");
|
||||
}
|
||||
else{
|
||||
throw new IllegalArgumentException("Sensor type "+s.getClass()+" is not supported by this loop");
|
||||
}
|
||||
c++;
|
||||
}
|
||||
|
||||
// Workaround - somehow one has to add an empty thing to the value otherwise the c logic
|
||||
// does not pick up the end
|
||||
readoutResources.add("");
|
||||
}
|
||||
catch(Exception e){
|
||||
throw new RuntimeException("Unable to prepare crloop: ",e);
|
||||
}
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#cleanup()
|
||||
*/
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (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;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#isDataGroup()
|
||||
*/
|
||||
@Override
|
||||
public boolean isDataGroup() {
|
||||
// TODO Auto-generated method stub
|
||||
return dataGroup;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#setDataGroup(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setDataGroup(boolean dataGroup) {
|
||||
this.dataGroup = dataGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the sensors
|
||||
*/
|
||||
public List<Sensor> getSensors() {
|
||||
return sensors;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the actor
|
||||
*/
|
||||
public OTFActuator getActor() {
|
||||
return actuator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param actor the actor to set
|
||||
*/
|
||||
public void setActor(OTFActuator actor) {
|
||||
this.actuator = actor;
|
||||
}
|
||||
|
||||
/**
|
||||
* The structure of the data message depends on the sensors registered at this loop
|
||||
* at the time this method is called.
|
||||
* @return the data queue and the metadata of the data messages
|
||||
*/
|
||||
public DataQueue getDataQueue() {
|
||||
DataMessageMetadata m = new DataMessageMetadata();
|
||||
|
||||
// Build up data message metadata based on the sensors currently registered.
|
||||
m.getComponents().add(new ComponentMetadata(actuator.getId()));
|
||||
for(Sensor s: sensors){
|
||||
m.getComponents().add(new ComponentMetadata(s.getId()));
|
||||
}
|
||||
return new DataQueue(dataQueue, m);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the keepTmpFiles
|
||||
*/
|
||||
public boolean isKeepTmpFiles() {
|
||||
return keepTmpFiles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param keepTmpFiles the keepTmpFiles to set
|
||||
*/
|
||||
public void setKeepTmpFiles(boolean keepTmpFiles) {
|
||||
this.keepTmpFiles = keepTmpFiles;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -1,274 +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.loops.cr;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class CrlogicRangeDataFilter {
|
||||
|
||||
private double motorResolution = 1;
|
||||
private int motorDirection = 1;
|
||||
private double motorOffset = 0;
|
||||
private double motorReadbackResolution = 1;
|
||||
private double motorEncoderResolution = 1;
|
||||
|
||||
private double encoderOffset = 0;
|
||||
private double encoderResolution = 1;
|
||||
private int encoderDirection = 1;
|
||||
|
||||
private double start = 0;
|
||||
private double end = 0;
|
||||
private boolean positive = true;
|
||||
|
||||
/**
|
||||
* Marker whether the value was equal
|
||||
*/
|
||||
private boolean wasEqualBefore = false;
|
||||
|
||||
/**
|
||||
* @return the motorResolution
|
||||
*/
|
||||
public double getMotorResolution() {
|
||||
return motorResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param motorResolution the motorResolution to set
|
||||
*/
|
||||
public void setMotorResolution(double motorResolution) {
|
||||
this.motorResolution = motorResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the motorDirection
|
||||
*/
|
||||
public int getMotorDirection() {
|
||||
return motorDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param motorDirection the motorDirection to set
|
||||
*/
|
||||
public void setMotorDirection(int motorDirection) {
|
||||
this.motorDirection = motorDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the motorOffset
|
||||
*/
|
||||
public double getMotorOffset() {
|
||||
return motorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param motorOffset the motorOffset to set
|
||||
*/
|
||||
public void setMotorOffset(double motorOffset) {
|
||||
this.motorOffset = motorOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the motorReadbackResolution
|
||||
*/
|
||||
public double getMotorReadbackResolution() {
|
||||
return motorReadbackResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param motorReadbackResolution the motorReadbackResolution to set
|
||||
*/
|
||||
public void setMotorReadbackResolution(double motorReadbackResolution) {
|
||||
this.motorReadbackResolution = motorReadbackResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the motorEncoderResolution
|
||||
*/
|
||||
public double getMotorEncoderResolution() {
|
||||
return motorEncoderResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param motorEncoderResolution the motorEncoderResolution to set
|
||||
*/
|
||||
public void setMotorEncoderResolution(double motorEncoderResolution) {
|
||||
this.motorEncoderResolution = motorEncoderResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoderOffset
|
||||
*/
|
||||
public double getEncoderOffset() {
|
||||
return encoderOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param encoderOffset the encoderOffset to set
|
||||
*/
|
||||
public void setEncoderOffset(double encoderOffset) {
|
||||
this.encoderOffset = encoderOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoderResolution
|
||||
*/
|
||||
public double getEncoderResolution() {
|
||||
return encoderResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param encoderResolution the encoderResolution to set
|
||||
*/
|
||||
public void setEncoderResolution(double encoderResolution) {
|
||||
this.encoderResolution = encoderResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoderDirection
|
||||
*/
|
||||
public int getEncoderDirection() {
|
||||
return encoderDirection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param encoderDirection the encoderDirection to set
|
||||
*/
|
||||
public void setEncoderDirection(int encoderDirection) {
|
||||
this.encoderDirection = encoderDirection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return the start
|
||||
*/
|
||||
public double getStart() {
|
||||
return start;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param start the start to set
|
||||
*/
|
||||
public void setStart(double start) {
|
||||
this.start = start;
|
||||
if(start<=end){
|
||||
positive=true;
|
||||
}
|
||||
else{
|
||||
positive=false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the end
|
||||
*/
|
||||
public double getEnd() {
|
||||
return end;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param end the end to set
|
||||
*/
|
||||
public void setEnd(double end) {
|
||||
this.end = end;
|
||||
if(end>=start){
|
||||
positive=true;
|
||||
}
|
||||
else{
|
||||
positive=false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate real position
|
||||
* @param raw
|
||||
* @return
|
||||
*/
|
||||
public double calculatePositionMotor(double raw){
|
||||
return(((raw * motorResolution * motorReadbackResolution)/motorDirection)+motorOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate real motor position using the readback link
|
||||
* @param raw
|
||||
* @return
|
||||
*/
|
||||
public double calculatePositionMotorUseReadback(double raw){
|
||||
return((((raw - encoderOffset) * encoderResolution * encoderDirection * motorReadbackResolution) / motorDirection) + motorOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate real motor position using encoder
|
||||
* @param raw
|
||||
* @return
|
||||
*/
|
||||
public double calculatePositionMotorUseEncoder(double raw){
|
||||
return(raw * motorEncoderResolution * motorReadbackResolution/motorDirection + motorOffset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter whether value is with the range
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public boolean filter(Double value){
|
||||
if(positive){
|
||||
if(start<=value && value<=end){
|
||||
|
||||
// If motor is very accurete and user backlash==null it might be that value is exactly
|
||||
// the end value. To prevent that unnecessary data is captured execute this check
|
||||
if(wasEqualBefore){
|
||||
wasEqualBefore=false; // Reset flag
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check whether was equal
|
||||
if(value==end){
|
||||
wasEqualBefore=true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(end<=value && value <=start){
|
||||
|
||||
if(wasEqualBefore){
|
||||
wasEqualBefore=false; // Reset flag
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check whether was equal
|
||||
if(value==start){
|
||||
wasEqualBefore=true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,73 +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.loops.cr;
|
||||
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class EncoderChannelsTemplate {
|
||||
|
||||
/**
|
||||
* Resolution - $(P)$(E)_SCL
|
||||
*/
|
||||
@CaChannel(type=Double.class, name="${PREFIX}_SCL")
|
||||
private Channel<Double> resolution;
|
||||
|
||||
/**
|
||||
* Offset - $(P)$(E)_OFF
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}_OFF")
|
||||
private Channel<Double> offset;
|
||||
|
||||
/**
|
||||
* Direction - $(P)$(E)_DIR
|
||||
*/
|
||||
public enum Direction {Negative, Positive};
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}_DIR")
|
||||
private Channel<Integer> direction;
|
||||
|
||||
|
||||
/**
|
||||
* @return the resolution
|
||||
*/
|
||||
public Channel<Double> getResolution() {
|
||||
return resolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the offset
|
||||
*/
|
||||
public Channel<Double> getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the direction
|
||||
*/
|
||||
public Channel<Integer> getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,652 +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.loops.cr;
|
||||
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class MotorChannelsTemplate {
|
||||
|
||||
public enum Type {SOFT_CHANNEL, MOTOR_SIMULATION, OMS_VME58, OMS_MAXv};
|
||||
|
||||
/**
|
||||
* ## Drive section ##
|
||||
* # User coordinates #
|
||||
*/
|
||||
|
||||
/**
|
||||
* .HLM High limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.HLM")
|
||||
private Channel<Double> highLimit;
|
||||
|
||||
/**
|
||||
* .LLM Low limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.LLM")
|
||||
private Channel<Double> lowLimit;
|
||||
|
||||
/**
|
||||
* .RBV Readback value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RBV", monitor=true)
|
||||
private Channel<Double> readbackValue;
|
||||
|
||||
/**
|
||||
* .VAL Set value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.VAL", monitor=true)
|
||||
private Channel<Double> setValue;
|
||||
|
||||
/**
|
||||
* .RLV Relative move value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RLV")
|
||||
private Channel<Double> relativeMoveValue;
|
||||
|
||||
/**
|
||||
* .TWV Teak value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.TWV")
|
||||
private Channel<Double> tweakValue;
|
||||
|
||||
/**
|
||||
* .TWR Tweak reverse - move left - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.TWR")
|
||||
private Channel<Integer> tweakReverse;
|
||||
|
||||
/**
|
||||
* .TWF Tweak forward - move right - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.TWF")
|
||||
private Channel<Integer> tweakForward;
|
||||
|
||||
/**
|
||||
* .JOGR Jog reverse - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.JOGR")
|
||||
private Channel<Integer> jogReverse;
|
||||
|
||||
/**
|
||||
* .JOGF Jog forward - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.JOGF")
|
||||
private Channel<Integer> jogForward;
|
||||
|
||||
/**
|
||||
* .HOMR Home reverse - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.HOMR")
|
||||
private Channel<Integer> homeReverse;
|
||||
|
||||
/**
|
||||
* .HOMF Home forward - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.HOMF")
|
||||
private Channel<Integer> homeForward;
|
||||
|
||||
/**
|
||||
* .EGU Engineering unit - String
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}.EGU")
|
||||
private Channel<String> engineeringUnit;
|
||||
|
||||
/**
|
||||
* .DTYP Type - String (e.g. "OMS MAXv") see enum Type
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.DTYP")
|
||||
private Channel<Integer> type;
|
||||
|
||||
/**
|
||||
* .DESC Description - String
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}.DESC")
|
||||
private Channel<String> description;
|
||||
|
||||
|
||||
/**
|
||||
* # Dial coordinates #
|
||||
*/
|
||||
|
||||
/**
|
||||
* .DHLM Dial high limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DHLM")
|
||||
private Channel<Double> dialHighLimit;
|
||||
|
||||
/**
|
||||
* .DLLM Dial low limit - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DLLM")
|
||||
private Channel<Double> dialLowLimit;
|
||||
|
||||
/**
|
||||
* .DRBV Dial readback value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DRBV", monitor=true)
|
||||
private Channel<Double> dialReadbackValue;
|
||||
|
||||
/**
|
||||
* .DVAL Dial set value - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DVAL", monitor=true)
|
||||
private Channel<Double> dialSetValue;
|
||||
|
||||
/**
|
||||
* .RVAL Raw value - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RVAL", monitor=true)
|
||||
private Channel<Integer> rawValue;
|
||||
|
||||
/**
|
||||
* .RRBV Raw readback value - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RRBV", monitor=true)
|
||||
private Channel<Integer> rawReadbackValue;
|
||||
|
||||
/**
|
||||
* .SPMG Stop/Pause/Move/Go - (0:"Stop", 1:"Pause", 2:"Move", 3:"Go") - 3
|
||||
*/
|
||||
public enum Commands { Stop, Pause, Move, Go };
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.SPMG")
|
||||
private Channel<Integer> command;
|
||||
|
||||
|
||||
/**
|
||||
* ## Calibration section ##
|
||||
*/
|
||||
|
||||
/**
|
||||
* .SET Set/Use Switch - (0:"Use", 1:"Set") - 0
|
||||
*/
|
||||
public enum Calibration {Use, Set};
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.SET")
|
||||
private Channel<Integer> calibration;
|
||||
|
||||
/**
|
||||
* .OFF User offset (EGU) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.OFF")
|
||||
private Channel<Double> offset;
|
||||
|
||||
/**
|
||||
* .FOFF Offset-Freeze Switch - (0:"Variable", 1:"Frozen") - 1
|
||||
*/
|
||||
public enum OffsetMode {Variable, Frozen};
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.FOFF")
|
||||
private Channel<Integer> offsetMode;
|
||||
|
||||
/**
|
||||
* .DIR User direction - (0:"Pos", 1:"Neg")
|
||||
*/
|
||||
public enum Direction {Positive, Negative};
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.DIR")
|
||||
private Channel<Integer> direction;
|
||||
|
||||
|
||||
/**
|
||||
* ## Dynamics ##
|
||||
*/
|
||||
|
||||
/**
|
||||
* .VELO Velocity (EGU/s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.VELO")
|
||||
private Channel<Double> velocity;
|
||||
|
||||
/**
|
||||
* .BVEL Backlash velocity (EGU/s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.BVEL")
|
||||
private Channel<Double> backlashVelocity;
|
||||
|
||||
/**
|
||||
* .VBAS Base speed (EGU/s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.VBAS")
|
||||
private Channel<Double> baseSpeed;
|
||||
|
||||
/**
|
||||
* .ACCL Acceleration time / seconds to velocity - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.ACCL")
|
||||
private Channel<Double> accelerationTime;
|
||||
|
||||
/**
|
||||
* .BACC Backlash acceleration time / seconds to velocity - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.BACC")
|
||||
private Channel<Double> backlashAccelerationTime;
|
||||
|
||||
/**
|
||||
* .BDST Backlash distance (EGU) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.BDST")
|
||||
private Channel<Double> backlashDistance;
|
||||
|
||||
/**
|
||||
* .FRAC Move fraction - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.FRAC")
|
||||
private Channel<Double> moveFracion;
|
||||
|
||||
|
||||
/**
|
||||
* ## Resolution ##
|
||||
*/
|
||||
|
||||
/**
|
||||
* .MRES Motor resolution - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.MRES")
|
||||
private Channel<Double> motorResolution;
|
||||
|
||||
/**
|
||||
* .ERES Encoder resolution - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.ERES")
|
||||
private Channel<Double> encoderResolution;
|
||||
|
||||
/**
|
||||
* .RRES Readback resolution - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RRES")
|
||||
private Channel<Double> readbackResolution;
|
||||
|
||||
/**
|
||||
* .RDBD Retry deadband (EGU) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.RDBD")
|
||||
private Channel<Double> retryDeadband;
|
||||
|
||||
/**
|
||||
* .RTRY Max retry count - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RTRY")
|
||||
private Channel<Integer> maxRetryCount;
|
||||
|
||||
/**
|
||||
* .RCNT Retry count - int
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.RCNT", monitor=true)
|
||||
private Channel<Integer> retryCount;
|
||||
|
||||
/**
|
||||
* .UEIP Use encoder (if present) - (0:"No", 1:"Yes")
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}.UEIP")
|
||||
private Channel<Boolean> useEncoder;
|
||||
|
||||
/**
|
||||
* .URIP Use readback link (if present) - (0:"No", 1:"Yes")
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}.URIP")
|
||||
private Channel<Boolean> useReadback;
|
||||
|
||||
/**
|
||||
* .DLY Readback delay (s) - double
|
||||
*/
|
||||
@CaChannel(type=Double.class, name ="${PREFIX}.DLY")
|
||||
private Channel<Double> readbackDelay;
|
||||
|
||||
/**
|
||||
* .RDBL Readback link - String
|
||||
*/
|
||||
@CaChannel(type=String.class, name ="${PREFIX}.RDBL")
|
||||
private Channel<String> readbackLink;
|
||||
|
||||
/**
|
||||
* .OMSL Output mode select - (0:"supervisory", 1:"closed_loop")
|
||||
*/
|
||||
public enum OutputMode {Supervisory, Closed_Loop};
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.OMSL")
|
||||
private Channel<Integer> outputMode;
|
||||
|
||||
/**
|
||||
* ## Status ##
|
||||
*/
|
||||
|
||||
/**
|
||||
* .DMOV Done move - int
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name ="${PREFIX}.DMOV", monitor=true)
|
||||
private Channel<Boolean> moveDone;
|
||||
|
||||
/**
|
||||
* @return the highLimit
|
||||
*/
|
||||
public Channel<Double> getHighLimit() {
|
||||
return highLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the lowLimit
|
||||
*/
|
||||
public Channel<Double> getLowLimit() {
|
||||
return lowLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackValue
|
||||
*/
|
||||
public Channel<Double> getReadbackValue() {
|
||||
return readbackValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the setValue
|
||||
*/
|
||||
public Channel<Double> getSetValue() {
|
||||
return setValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the relativeMoveValue
|
||||
*/
|
||||
public Channel<Double> getRelativeMoveValue() {
|
||||
return relativeMoveValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tweakValue
|
||||
*/
|
||||
public Channel<Double> getTweakValue() {
|
||||
return tweakValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tweakReverse
|
||||
*/
|
||||
public Channel<Integer> getTweakReverse() {
|
||||
return tweakReverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the tweakForward
|
||||
*/
|
||||
public Channel<Integer> getTweakForward() {
|
||||
return tweakForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jogReverse
|
||||
*/
|
||||
public Channel<Integer> getJogReverse() {
|
||||
return jogReverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the jogForward
|
||||
*/
|
||||
public Channel<Integer> getJogForward() {
|
||||
return jogForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the homeReverse
|
||||
*/
|
||||
public Channel<Integer> getHomeReverse() {
|
||||
return homeReverse;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the homeForward
|
||||
*/
|
||||
public Channel<Integer> getHomeForward() {
|
||||
return homeForward;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the engineeringUnit
|
||||
*/
|
||||
public Channel<String> getEngineeringUnit() {
|
||||
return engineeringUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type
|
||||
*/
|
||||
public Channel<Integer> getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the description
|
||||
*/
|
||||
public Channel<String> getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialHighLimit
|
||||
*/
|
||||
public Channel<Double> getDialHighLimit() {
|
||||
return dialHighLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialLowLimit
|
||||
*/
|
||||
public Channel<Double> getDialLowLimit() {
|
||||
return dialLowLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialReadbackValue
|
||||
*/
|
||||
public Channel<Double> getDialReadbackValue() {
|
||||
return dialReadbackValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dialSetValue
|
||||
*/
|
||||
public Channel<Double> getDialSetValue() {
|
||||
return dialSetValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rawValue
|
||||
*/
|
||||
public Channel<Integer> getRawValue() {
|
||||
return rawValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the rawReadbackValue
|
||||
*/
|
||||
public Channel<Integer> getRawReadbackValue() {
|
||||
return rawReadbackValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the command
|
||||
*/
|
||||
public Channel<Integer> getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the calibration
|
||||
*/
|
||||
public Channel<Integer> getCalibration() {
|
||||
return calibration;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the userOffset
|
||||
*/
|
||||
public Channel<Double> getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the offsetMode
|
||||
*/
|
||||
public Channel<Integer> getOffsetMode() {
|
||||
return offsetMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the direction
|
||||
*/
|
||||
public Channel<Integer> getDirection() {
|
||||
return direction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the velocity
|
||||
*/
|
||||
public Channel<Double> getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the backlashVelocity
|
||||
*/
|
||||
public Channel<Double> getBacklashVelocity() {
|
||||
return backlashVelocity;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the baseSpeed
|
||||
*/
|
||||
public Channel<Double> getBaseSpeed() {
|
||||
return baseSpeed;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the accelerationTime
|
||||
*/
|
||||
public Channel<Double> getAccelerationTime() {
|
||||
return accelerationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the backlashAccelerationTime
|
||||
*/
|
||||
public Channel<Double> getBacklashAccelerationTime() {
|
||||
return backlashAccelerationTime;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the backlashDistance
|
||||
*/
|
||||
public Channel<Double> getBacklashDistance() {
|
||||
return backlashDistance;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the moveFracion
|
||||
*/
|
||||
public Channel<Double> getMoveFracion() {
|
||||
return moveFracion;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the motorResolution
|
||||
*/
|
||||
public Channel<Double> getMotorResolution() {
|
||||
return motorResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the encoderResolution
|
||||
*/
|
||||
public Channel<Double> getEncoderResolution() {
|
||||
return encoderResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackResolution
|
||||
*/
|
||||
public Channel<Double> getReadbackResolution() {
|
||||
return readbackResolution;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the retryDeadband
|
||||
*/
|
||||
public Channel<Double> getRetryDeadband() {
|
||||
return retryDeadband;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the maxRetryCount
|
||||
*/
|
||||
public Channel<Integer> getMaxRetryCount() {
|
||||
return maxRetryCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the retryCount
|
||||
*/
|
||||
public Channel<Integer> getRetryCount() {
|
||||
return retryCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the useEncoder
|
||||
*/
|
||||
public Channel<Boolean> getUseEncoder() {
|
||||
return useEncoder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the useReadback
|
||||
*/
|
||||
public Channel<Boolean> getUseReadback() {
|
||||
return useReadback;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackDelay
|
||||
*/
|
||||
public Channel<Double> getReadbackDelay() {
|
||||
return readbackDelay;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the readbackLink
|
||||
*/
|
||||
public Channel<String> getReadbackLink() {
|
||||
return readbackLink;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the outputMode
|
||||
*/
|
||||
public Channel<Integer> getOutputMode() {
|
||||
return outputMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the moveDone
|
||||
*/
|
||||
public Channel<Boolean> getMoveDone() {
|
||||
return moveDone;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,268 +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.loops.cr;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.concurrent.CyclicBarrier;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.Future;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.sensors.MillisecondTimestampSensor;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ParallelCrlogic implements ActionLoop {
|
||||
|
||||
// Get Logger
|
||||
private static final Logger logger = Logger.getLogger(ParallelCrlogic.class.getName());
|
||||
|
||||
/**
|
||||
* Flag to indicate whether the data of this loop will be grouped
|
||||
* According to this flag the dataGroup flag in EndOfStream will be set.
|
||||
*/
|
||||
private boolean dataGroup = false;
|
||||
|
||||
private CrlogicLoop crlogic;
|
||||
private ScrlogicLoop scrlogic;
|
||||
|
||||
/**
|
||||
* List of actions that are executed at the beginning of the loop.
|
||||
*/
|
||||
private List<Action> preActions;
|
||||
/**
|
||||
* List of actions that are executed at the end of the loop.
|
||||
*/
|
||||
private List<Action> postActions;
|
||||
|
||||
private ParallelCrlogicStreamMerge merger;
|
||||
|
||||
|
||||
public ParallelCrlogic(CrlogicLoop crlogic, ScrlogicLoop scrlogic){
|
||||
|
||||
if(crlogic==null){
|
||||
throw new IllegalArgumentException("No Crloop specified");
|
||||
}
|
||||
if(scrlogic==null){
|
||||
throw new IllegalArgumentException("No Scrloop specified");
|
||||
}
|
||||
|
||||
this.crlogic = crlogic;
|
||||
// Add timestamp to sensor at the beginning of the sensor list as this is required for merging the data
|
||||
// Timestamp will be at the second position of a message in the queue!
|
||||
this.crlogic.getSensors().add(0, new MillisecondTimestampSensor("tmp_timestamp"));
|
||||
this.scrlogic = scrlogic;
|
||||
|
||||
// Initialize lists used by the loop
|
||||
this.preActions = new ArrayList<Action>();
|
||||
this.postActions = new ArrayList<Action>();
|
||||
|
||||
this.merger = new ParallelCrlogicStreamMerge(crlogic.getDataQueue(), scrlogic.getDataQueue());
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.logic.Logic#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.logic.Logic#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
|
||||
// Execute pre actions
|
||||
for(Action action: preActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
|
||||
ExecutorService service = Executors.newFixedThreadPool(3); // 2 for the parallel data acquisition and 1 for the merger thread
|
||||
final CyclicBarrier b = new CyclicBarrier(2);
|
||||
|
||||
List<Future<Boolean>> list = new ArrayList<Future<Boolean>>();
|
||||
|
||||
// Start a thread for each logic
|
||||
logger.info("Submit logic");
|
||||
Future<Boolean> f = service.submit(new Callable<Boolean>(){
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
|
||||
// Prepare logic
|
||||
crlogic.prepare();
|
||||
|
||||
// Ensure that really all parallel logics start in parallel
|
||||
b.await();
|
||||
|
||||
// Execute the logic of this path
|
||||
crlogic.execute();
|
||||
|
||||
// Need to stop the scrlogic logic (otherwise it would keep going to take data)
|
||||
scrlogic.abort();
|
||||
return true;
|
||||
}});
|
||||
list.add(f);
|
||||
|
||||
//Start a thread for the scrlogic
|
||||
logger.info("Submit logic");
|
||||
f = service.submit(new Callable<Boolean>(){
|
||||
@Override
|
||||
public Boolean call() throws Exception {
|
||||
|
||||
// Prepare logic
|
||||
scrlogic.prepare();
|
||||
|
||||
// Ensure that really all parallel logics start in parallel
|
||||
b.await();
|
||||
|
||||
// Execute the logic of this path
|
||||
scrlogic.execute(); // This actually just starts the collection ...
|
||||
return true;
|
||||
}});
|
||||
list.add(f);
|
||||
|
||||
|
||||
// // Start data merge thread
|
||||
// logger.info("Start data merge");
|
||||
// f = service.submit(new Callable<Boolean>(){
|
||||
// @Override
|
||||
// public Boolean call() throws Exception {
|
||||
//
|
||||
// merger.merge();
|
||||
// return true;
|
||||
// }});
|
||||
// list.add(f);
|
||||
|
||||
|
||||
for(Future<Boolean> bf: list){
|
||||
// Wait for completion of the thread
|
||||
try {
|
||||
bf.get();
|
||||
} catch (ExecutionException e) {
|
||||
logger.log(Level.WARNING, "Something went wrong while waiting for crthreads to finish");
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
merger.merge();
|
||||
|
||||
// Wait until all threads have finished
|
||||
service.shutdown();
|
||||
service.awaitTermination(1, TimeUnit.MINUTES);
|
||||
|
||||
|
||||
// Execute post actions
|
||||
for(Action action: postActions){
|
||||
action.execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
crlogic.destroy();
|
||||
scrlogic.destroy();
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#cleanup()
|
||||
*/
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* (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;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#isDataGroup()
|
||||
*/
|
||||
@Override
|
||||
public boolean isDataGroup() {
|
||||
return dataGroup;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#setDataGroup(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setDataGroup(boolean dataGroup) {
|
||||
this.dataGroup = dataGroup;
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see ch.psi.fda.core.ActionLoop#getDataQueue()
|
||||
*/
|
||||
@Override
|
||||
public DataQueue getDataQueue() {
|
||||
return(merger.getDataQueue());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,169 +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.loops.cr;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ParallelCrlogicStreamMerge {
|
||||
|
||||
private BlockingQueue<Message> dataQueue;
|
||||
|
||||
private DataQueue primaryQueue;
|
||||
private DataQueue secondaryQueue;
|
||||
|
||||
/**
|
||||
* Class to merge two data streams into one. The secondary queues data is added to the primary queues data.
|
||||
* The resulting queue therefor will hold the same amount of elements as the primary queue does.
|
||||
* The datagroup flag set in the end of stream message will be set according to the flag set in the primary queue.
|
||||
*
|
||||
* @param pqueue Primary/master queue
|
||||
* @param squeue Secondary queue
|
||||
*/
|
||||
public ParallelCrlogicStreamMerge(DataQueue pqueue, DataQueue squeue){
|
||||
this.primaryQueue = pqueue;
|
||||
this.secondaryQueue = squeue;
|
||||
|
||||
this.dataQueue = new LinkedBlockingQueue<Message>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge the streams based on the timestamp
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
public void merge() throws InterruptedException{
|
||||
|
||||
// Actual data of the secondary queue
|
||||
List<Object> currData = null;
|
||||
|
||||
// Take first element of the primary queue (wait until message is available)
|
||||
Message m = primaryQueue.getQueue().take();
|
||||
|
||||
while(! (m instanceof EndOfStreamMessage)){
|
||||
|
||||
if(m instanceof DataMessage){
|
||||
|
||||
DataMessage dm = (DataMessage) m;
|
||||
|
||||
// Get and remove merge timestamp from the data of the message
|
||||
Double timestamp = (Double) dm.getData().remove(1);
|
||||
long milliseconds = (long) (timestamp*1000);
|
||||
long nanoOffset = (long)((timestamp*1000-milliseconds)*1000000);
|
||||
|
||||
// System.out.println("timestamp: "+new Date(milliseconds)+" "+milliseconds+" ."+nanoOffset);
|
||||
|
||||
while(true){
|
||||
// Assumption: the secondary Queue holds at least the data up to the
|
||||
// timestamp of the primary queue
|
||||
Message mess = secondaryQueue.getQueue().peek();
|
||||
// Message mess = secondaryQueue.getQueue().take();
|
||||
|
||||
if(mess instanceof EndOfStreamMessage){
|
||||
break;
|
||||
}
|
||||
|
||||
if(mess == null){
|
||||
break;
|
||||
}
|
||||
|
||||
if(mess instanceof DataMessage){
|
||||
// Check whether timestamp of the next message is bigger than the timestamp of the
|
||||
// message from the primary queue - if the timestamp is bigger do not take message out of the queue
|
||||
DataMessage msCheck = (DataMessage) mess;
|
||||
|
||||
// System.out.println("Mess: "+mess);
|
||||
|
||||
long currMilliCheck = ((Double) msCheck.getData().get(0)).longValue();
|
||||
long currNanoCheck = ((Double) msCheck.getData().get(1)).longValue();
|
||||
|
||||
// Check
|
||||
if(currMilliCheck>milliseconds || (currMilliCheck==milliseconds && currNanoCheck>nanoOffset)){
|
||||
break;
|
||||
}
|
||||
|
||||
DataMessage ms = (DataMessage) secondaryQueue.getQueue().take();
|
||||
|
||||
// System.out.println("Ms: "+ms);
|
||||
|
||||
currData = ms.getData();
|
||||
// Remove timestamps
|
||||
currData.remove(0);
|
||||
currData.remove(0);
|
||||
}
|
||||
else{
|
||||
// No DataMessage
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Add data to primary data queue message and put it into the out queue
|
||||
dm.getData().addAll(currData);
|
||||
|
||||
dataQueue.add(dm);
|
||||
}
|
||||
|
||||
|
||||
m = primaryQueue.getQueue().take();
|
||||
}
|
||||
|
||||
// Add the end of stream message of the primary queue
|
||||
dataQueue.add(m);
|
||||
|
||||
// Clear all remaining messages in secondary queue
|
||||
secondaryQueue.getQueue().clear();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The structure of the data message depends on the sensors registered at this loop
|
||||
* at the time this method is called.
|
||||
* @return the data queue and the metadata of the data messages
|
||||
*/
|
||||
public DataQueue getDataQueue() {
|
||||
DataMessageMetadata m = new DataMessageMetadata();
|
||||
|
||||
DataMessageMetadata pqm = primaryQueue.getDataMessageMetadata();
|
||||
m.getComponents().add(pqm.getComponents().get(0)); // add first component (this is the actuator)
|
||||
// Skip the next component as this is the timestamp used to merge the data
|
||||
for(int i=2;i<pqm.getComponents().size();i++){
|
||||
m.getComponents().add(pqm.getComponents().get(i));
|
||||
}
|
||||
|
||||
DataMessageMetadata sqm = secondaryQueue.getDataMessageMetadata();
|
||||
// Skip first two components of the message as this is the timestamp
|
||||
for(int i=2;i<sqm.getComponents().size();i++){
|
||||
m.getComponents().add(sqm.getComponents().get(i));
|
||||
}
|
||||
|
||||
return new DataQueue(dataQueue, m);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,405 +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.loops.cr;
|
||||
|
||||
import gov.aps.jca.Monitor;
|
||||
|
||||
import java.beans.PropertyChangeEvent;
|
||||
import java.beans.PropertyChangeListener;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import ch.psi.fda.core.Action;
|
||||
import ch.psi.fda.core.ActionLoop;
|
||||
import ch.psi.fda.core.Sensor;
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
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.type.DoubleTimestamp;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
* Assumptions: - The delay between the monitor writing the value to the
|
||||
* monitor queue and the readout of all the queues is sufficient to
|
||||
* prevent the situation that some monitors of events close to each
|
||||
* other on different IOC's have not arrived yet. - The sequence of
|
||||
* monitors fired for one channel is according to the sequence of the
|
||||
* causes. No monitor package is overtaking an other package on the
|
||||
* network.
|
||||
*
|
||||
* - No monitor events are lost on the network (while using monitors you
|
||||
* cannot guarantee this)
|
||||
*
|
||||
* The data queue returned by this logic includes two items for the
|
||||
* timestamp and nanoseconds offset. These two items are the first two
|
||||
* items of a message The id's are: crTimestampMilliseconds
|
||||
* crTimestampOffsetNanoseconds
|
||||
*/
|
||||
public class ScrlogicLoop implements ActionLoop {
|
||||
|
||||
private static String ID_TIMESTAMP_MILLISECONDS = "crTimestampMilliseconds";
|
||||
private static String ID_TIMESTAMP_OFFSET_NANOSECONDS = "crTimestampOffsetNanoseconds";
|
||||
|
||||
// Get Logger
|
||||
private static final Logger logger = Logger.getLogger(ScrlogicLoop.class.getName());
|
||||
|
||||
|
||||
/**
|
||||
* Data queue sensor data is posted to. A message consists of a list of data
|
||||
* objects that are read out of the sensors of this loop.
|
||||
*/
|
||||
private final BlockingQueue<Message> dataQueue = new LinkedBlockingQueue<Message>();
|
||||
|
||||
private boolean dataGroup = false;
|
||||
private final List<Action> preActions = new ArrayList<Action>();
|
||||
private final List<Action> postActions = new ArrayList<Action>();
|
||||
|
||||
/**
|
||||
* Sensors to read out
|
||||
*/
|
||||
// private List<Sensor> sensors;
|
||||
|
||||
/**
|
||||
* List of monitors that were attached to the sensor channels (i.e
|
||||
* workaround)
|
||||
*/
|
||||
private final List<PropertyChangeListener> monitors = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* List of blocking queues that hold the data for one sensor (channel)
|
||||
*/
|
||||
private final List<BlockingQueue<TimestampedValue>> queues = new ArrayList<BlockingQueue<TimestampedValue>>();
|
||||
|
||||
private CountDownLatch latch;
|
||||
|
||||
private List<Channel<DoubleTimestamp>> sensors = new ArrayList<>();
|
||||
private List<String> sensorIds = new ArrayList<>();
|
||||
private ChannelService cservice;
|
||||
|
||||
public ScrlogicLoop(ChannelService s, List<Sensor> sensors) {
|
||||
try{
|
||||
for(Sensor ss: sensors){
|
||||
this.sensors.add(s.createChannel(new ChannelDescriptor<DoubleTimestamp>(DoubleTimestamp.class, ((ChannelAccessDoubleSensor)ss).getChannel().getName(), true)));
|
||||
sensorIds.add(ss.getId());
|
||||
}
|
||||
this.cservice = s;
|
||||
} catch (ChannelException | InterruptedException | TimeoutException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#execute()
|
||||
*/
|
||||
@Override
|
||||
public void execute() throws InterruptedException {
|
||||
|
||||
// Clear all queues
|
||||
queues.clear();
|
||||
latch = new CountDownLatch(1);
|
||||
|
||||
// Attach monitors to the channels (this is actually a workaround)
|
||||
for (Channel<DoubleTimestamp> sensor : sensors) {
|
||||
// if (sensor instanceof ChannelAccessDoubleSensor) {
|
||||
// ChannelAccessDoubleSensor s = (ChannelAccessDoubleSensor) sensor;
|
||||
// Channel<Double> b = s.getChannel();
|
||||
// Create data queue for the channel
|
||||
final BlockingQueue<TimestampedValue> q = new LinkedBlockingQueue<TimestampedValue>();
|
||||
queues.add(q);
|
||||
|
||||
PropertyChangeListener b = new PropertyChangeListener() {
|
||||
|
||||
@Override
|
||||
public void propertyChange(PropertyChangeEvent evt) {
|
||||
DoubleTimestamp value = (DoubleTimestamp) evt.getNewValue();
|
||||
q.add(new TimestampedValue(value.getValue(), value.getTimestamp().getTime(), value.getNanosecondOffset()));
|
||||
}
|
||||
};
|
||||
|
||||
sensor.addPropertyChangeListener("value", b);
|
||||
|
||||
monitors.add(b);
|
||||
// }
|
||||
}
|
||||
|
||||
logger.info("Start data acquisition");
|
||||
|
||||
latch.await();
|
||||
|
||||
// Remove monitors
|
||||
try{
|
||||
for (int i = 0; i < sensors.size(); i++) {
|
||||
Channel<DoubleTimestamp> sensor = sensors.get(i);
|
||||
sensor.removePropertyChangeListener(monitors.get(i));
|
||||
}
|
||||
}
|
||||
finally{
|
||||
// Clear all monitors in the list
|
||||
monitors.clear();
|
||||
}
|
||||
|
||||
// Merge data
|
||||
merge();
|
||||
|
||||
// Clear data queues
|
||||
for (BlockingQueue<TimestampedValue> q : queues) {
|
||||
q.clear();
|
||||
}
|
||||
queues.clear();
|
||||
|
||||
// Put end of stream to the queue
|
||||
dataQueue.add(new EndOfStreamMessage(dataGroup));
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#abort()
|
||||
*/
|
||||
@Override
|
||||
public void abort() {
|
||||
latch.countDown();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.Action#destroy()
|
||||
*/
|
||||
@Override
|
||||
public void destroy() {
|
||||
// Destroy all sensors
|
||||
for (Channel<DoubleTimestamp> s : sensors) {
|
||||
try {
|
||||
s.destroy();
|
||||
} catch (ChannelException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
sensors.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#prepare()
|
||||
*/
|
||||
@Override
|
||||
public void prepare() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#cleanup()
|
||||
*/
|
||||
@Override
|
||||
public void cleanup() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
/*
|
||||
* (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;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#isDataGroup()
|
||||
*/
|
||||
@Override
|
||||
public boolean isDataGroup() {
|
||||
return dataGroup;
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see ch.psi.fda.core.ActionLoop#setDataGroup(boolean)
|
||||
*/
|
||||
@Override
|
||||
public void setDataGroup(boolean dataGroup) {
|
||||
this.dataGroup = dataGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* The structure of the data message depends on the sensors registered at
|
||||
* this loop at the time this method is called.
|
||||
*
|
||||
* @return the data queue and the metadata of the data messages
|
||||
*/
|
||||
public DataQueue getDataQueue() {
|
||||
DataMessageMetadata m = new DataMessageMetadata();
|
||||
|
||||
// Build up data message metadata based on the channels registered.
|
||||
m.getComponents().add(new ComponentMetadata(ID_TIMESTAMP_MILLISECONDS));
|
||||
m.getComponents().add(
|
||||
new ComponentMetadata(ID_TIMESTAMP_OFFSET_NANOSECONDS));
|
||||
for (String id : sensorIds) {
|
||||
m.getComponents().add(new ComponentMetadata(id));
|
||||
}
|
||||
return new DataQueue(dataQueue, m);
|
||||
}
|
||||
|
||||
private boolean hasNext(){
|
||||
for (int i = 0; i < queues.size(); i++) {
|
||||
if(!queues.get(i).isEmpty()){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge data collected by different monitor
|
||||
*
|
||||
* @throws InterruptedException
|
||||
*/
|
||||
private void merge() throws InterruptedException {
|
||||
|
||||
// Array to hold temporary channel values
|
||||
TimestampedValue[] cvalues = new TimestampedValue[queues.size()];
|
||||
TimestampedValueComparator comparator = new TimestampedValueComparator();
|
||||
|
||||
// Oldest value written
|
||||
TimestampedValue globalOldest = null;
|
||||
List<Integer> indexes = new ArrayList<Integer>();
|
||||
|
||||
while (hasNext()) {
|
||||
|
||||
// semaphore.acquire();
|
||||
Thread.sleep(10); // Ensure that close by monitors have time to
|
||||
// catch up / also ensure context switch
|
||||
|
||||
// Oldest value of this run
|
||||
TimestampedValue oldest = null;
|
||||
// Queue index of the oldest value of this run
|
||||
indexes.clear();
|
||||
|
||||
// Find oldest element in any of the queues
|
||||
for (int i = 0; i < queues.size(); i++) {
|
||||
|
||||
BlockingQueue<TimestampedValue> q = queues.get(i);
|
||||
TimestampedValue ttcheck = q.peek();
|
||||
|
||||
if (ttcheck != null) {
|
||||
if (oldest == null) {
|
||||
// Update the oldest variable with current element
|
||||
oldest = ttcheck;
|
||||
indexes.clear();
|
||||
indexes.add(i);
|
||||
} else if (comparator.compare(ttcheck, oldest) < 0) {
|
||||
// Check whether timestamp is less (older) than the current oldest timestamp.
|
||||
oldest = ttcheck;
|
||||
indexes.clear();
|
||||
indexes.add(i);
|
||||
} else if (comparator.compare(ttcheck, oldest) == 0) {
|
||||
// SAME TIMESTAMP
|
||||
indexes.add(i);
|
||||
} else {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// logger.info("Index: "+index+" Permits: "+semaphore.availablePermits());
|
||||
// System.out.println("indexes: "+indexes.size());
|
||||
|
||||
if (indexes.size() > 0) {
|
||||
long timestamp = 0l;
|
||||
long nanoOffset = 0l;
|
||||
|
||||
for (Integer index : indexes) {
|
||||
// Get next older value
|
||||
cvalues[index] = queues.get(index).poll();
|
||||
|
||||
if (globalOldest != null) {
|
||||
if (comparator.compare(cvalues[index], globalOldest) >= 0) {
|
||||
// Update the global oldest variable
|
||||
globalOldest = cvalues[index];
|
||||
timestamp = cvalues[index].getTimestamp();
|
||||
nanoOffset = cvalues[index].getNanosecondsOffset();
|
||||
} else {
|
||||
// Monitors did not fire in sequence (an newer
|
||||
// monitor overtook an older (from an other IOC))
|
||||
logger.warning("Timestamped value out of sequence - discard value !!!!");
|
||||
// Continue with next value ...
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
globalOldest = cvalues[index];
|
||||
}
|
||||
}
|
||||
|
||||
// Assemble data message ...
|
||||
DataMessage message = new DataMessage();
|
||||
|
||||
message.getData().add(new Double(timestamp));
|
||||
message.getData().add(new Double(nanoOffset));
|
||||
|
||||
for (int y = 0; y < cvalues.length; y++) {
|
||||
if (cvalues[y] != null) {
|
||||
message.getData().add(new Double(cvalues[y].getValue()));
|
||||
} else {
|
||||
message.getData().add(Double.NaN);
|
||||
}
|
||||
}
|
||||
// System.out.println(message);
|
||||
dataQueue.add(message);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,81 +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.loops.cr;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class TimestampedValue {
|
||||
|
||||
private Double value;
|
||||
private long timestamp;
|
||||
private long nanosecondsOffset;
|
||||
|
||||
public TimestampedValue(Double value, long timestamp, long nanosecondsOffset){
|
||||
this.value = value;
|
||||
this.timestamp = timestamp;
|
||||
this.nanosecondsOffset = nanosecondsOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the value
|
||||
*/
|
||||
public Double getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value the value to set
|
||||
*/
|
||||
public void setValue(Double value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the timestamp
|
||||
*/
|
||||
public long getTimestamp() {
|
||||
return timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param timestamp the timestamp to set
|
||||
*/
|
||||
public void setTimestamp(long timestamp) {
|
||||
this.timestamp = timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the nanosecondsOffset
|
||||
*/
|
||||
public long getNanosecondsOffset() {
|
||||
return nanosecondsOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param nanosecondsOffset the nanosecondsOffset to set
|
||||
*/
|
||||
public void setNanosecondsOffset(long nanosecondsOffset) {
|
||||
this.nanosecondsOffset = nanosecondsOffset;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,45 +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.loops.cr;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class TimestampedValueComparator implements Comparator<TimestampedValue> {
|
||||
|
||||
@Override
|
||||
public int compare(TimestampedValue o1, TimestampedValue o2) {
|
||||
if (o1.getTimestamp() < o2.getTimestamp()) {
|
||||
return -1;
|
||||
} else if (o1.getTimestamp() > o2.getTimestamp()) {
|
||||
return 1;
|
||||
} else if (o1.getTimestamp() == o2.getTimestamp()) {
|
||||
if (o1.getNanosecondsOffset() < o2.getNanosecondsOffset()) {
|
||||
return -1;
|
||||
} else if (o1.getNanosecondsOffset() > o2.getNanosecondsOffset()) {
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -1,103 +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.loops.cr;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import ch.psi.jcae.Channel;
|
||||
import ch.psi.jcae.annotation.CaChannel;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class VSC16ScalerChannelsTemplate {
|
||||
|
||||
|
||||
public enum Command {Done, Count};
|
||||
/**
|
||||
* Command
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.CNT")
|
||||
private Channel<Integer> command;
|
||||
|
||||
|
||||
public enum Mode {OneShot, AutoCount};
|
||||
/**
|
||||
* Count mode
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name ="${PREFIX}.CONT")
|
||||
private Channel<Integer> mode;
|
||||
|
||||
/**
|
||||
* Channel description
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name={"${PREFIX}.NM1", "${PREFIX}.NM2", "${PREFIX}.NM3", "${PREFIX}.NM4", "${PREFIX}.NM5", "${PREFIX}.NM6", "${PREFIX}.NM7", "${PREFIX}.NM8", "${PREFIX}.NM9", "${PREFIX}.NM10", "${PREFIX}.NM11", "${PREFIX}.NM12", "${PREFIX}.NM13", "${PREFIX}.NM14", "${PREFIX}.NM15", "${PREFIX}.NM16"})
|
||||
private List<Channel<Boolean>> channelDescription;
|
||||
|
||||
/**
|
||||
* Channel gate
|
||||
*/
|
||||
@CaChannel(type=Boolean.class, name={"${PREFIX}.G1", "${PREFIX}.G2", "${PREFIX}.G3", "${PREFIX}.G4", "${PREFIX}.G5", "${PREFIX}.G6", "${PREFIX}.G7", "${PREFIX}.G8", "${PREFIX}.G9", "${PREFIX}.G10", "${PREFIX}.G11", "${PREFIX}.G12", "${PREFIX}.G13", "${PREFIX}.G14", "${PREFIX}.G15", "${PREFIX}.G16"})
|
||||
private List<Channel<Boolean>> channelGate;
|
||||
|
||||
/**
|
||||
* Channel preset count
|
||||
* If gate is on scaler will only count until this value
|
||||
*/
|
||||
@CaChannel(type=Integer.class, name={"${PREFIX}.PR1", "${PREFIX}.PR2", "${PREFIX}.PR3", "${PREFIX}.PR4", "${PREFIX}.PR5", "${PREFIX}.PR6", "${PREFIX}.PR7", "${PREFIX}.PR8", "${PREFIX}.PR9", "${PREFIX}.PR10", "${PREFIX}.PR11", "${PREFIX}.PR12", "${PREFIX}.PR13", "${PREFIX}.PR14", "${PREFIX}.PR15", "${PREFIX}.PR16"})
|
||||
private List<Channel<Integer>> channelPresetCount;
|
||||
|
||||
/**
|
||||
* @return the command
|
||||
*/
|
||||
public Channel<Integer> getCommand() {
|
||||
return command;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mode
|
||||
*/
|
||||
public Channel<Integer> getMode() {
|
||||
return mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channelDescription
|
||||
*/
|
||||
public List<Channel<Boolean>> getChannelDescription() {
|
||||
return channelDescription;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channelGate
|
||||
*/
|
||||
public List<Channel<Boolean>> getChannelGate() {
|
||||
return channelGate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the channelPresetCount
|
||||
*/
|
||||
public List<Channel<Integer>> getChannelPresetCount() {
|
||||
return channelPresetCount;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,276 +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.manipulator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeoutException;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.script.ScriptEngine;
|
||||
import javax.script.ScriptEngineManager;
|
||||
import javax.script.ScriptException;
|
||||
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
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.jcae.Channel;
|
||||
import ch.psi.jcae.ChannelDescriptor;
|
||||
import ch.psi.jcae.ChannelException;
|
||||
import ch.psi.jcae.ChannelService;
|
||||
|
||||
/**
|
||||
* Manipulation
|
||||
* @author ebner
|
||||
*/
|
||||
public class JythonManipulation implements Manipulation{
|
||||
|
||||
|
||||
// Get Logger
|
||||
private static Logger logger = Logger.getLogger(JythonManipulation.class.getName());
|
||||
|
||||
/**
|
||||
* Pattern of the entry function of the jython script
|
||||
*/
|
||||
private static final String entryFunction = "process";
|
||||
private static final String entryFunctionPattern = "def "+entryFunction+"\\((.*)\\):";
|
||||
|
||||
/**
|
||||
* Code of the manipulation. The script need to implement a function of the type:
|
||||
* <code>
|
||||
* def process():
|
||||
* # ... your code
|
||||
* return value
|
||||
* </code>
|
||||
*
|
||||
* The number of parameters of the script are not limited. So <code>process(a)</code> is valid
|
||||
* as well as <code>process(a,b,c,d,e,f)</code>.
|
||||
* However for each parameter there need to be a mapping inside the mapping list! If there is no
|
||||
* mapping inside the Manipulator evaluating this Manipulation will throw an Exception.
|
||||
*/
|
||||
private final String script;
|
||||
|
||||
/**
|
||||
* Id of the resulting component
|
||||
*/
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Mapping of components to manipulation code variables
|
||||
*/
|
||||
private final List<JythonParameterMapping> mapping;
|
||||
|
||||
private final boolean returnArray;
|
||||
|
||||
/**
|
||||
* Script engine of the manipulator
|
||||
*/
|
||||
private ScriptEngine engine;
|
||||
/**
|
||||
* Component index of the script parameter. The sequence of the indexes in this array correspond to the script
|
||||
* parameter position, i.e. the first index corresponds to the first parameter.
|
||||
*/
|
||||
private Integer[] parameterIndex;
|
||||
/**
|
||||
* Parameter array of the entry function
|
||||
*/
|
||||
private String[] parameter;
|
||||
private ChannelService cservice;
|
||||
|
||||
/**
|
||||
* Jython entry call
|
||||
*/
|
||||
private String jythonCall;
|
||||
|
||||
public JythonManipulation(ChannelService s, String id, String script, List<JythonParameterMapping> mapping){
|
||||
this(s, id, script, mapping, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param id
|
||||
* @param script
|
||||
* @param mapping
|
||||
*/
|
||||
public JythonManipulation(ChannelService s, String id, String script, List<JythonParameterMapping> mapping, boolean returnArray){
|
||||
this.id = id;
|
||||
this.script = script;
|
||||
this.mapping = mapping;
|
||||
this.returnArray = returnArray;
|
||||
this.cservice = s;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the script
|
||||
*/
|
||||
public String getScript() {
|
||||
return script;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the mapping
|
||||
*/
|
||||
public List<JythonParameterMapping> getMapping() {
|
||||
return mapping;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(DataMessageMetadata metadata){
|
||||
|
||||
// Workaround for Jython memory leak
|
||||
// http://blog.hillbrecht.de/2009/07/11/jython-memory-leakout-of-memory-problem/
|
||||
System.setProperty("python.options.internalTablesImpl","weak");
|
||||
|
||||
// Create new script engine
|
||||
this.engine = new ScriptEngineManager().getEngineByName("python");
|
||||
|
||||
// Determine script entry function and the function parameters
|
||||
Pattern pattern = Pattern.compile(entryFunctionPattern);
|
||||
Matcher matcher = pattern.matcher(this.script);
|
||||
if(matcher.find() && matcher.groupCount()==1){
|
||||
if(!matcher.group(1).trim().equals("")){
|
||||
logger.finest("Entry function '"+entryFunctionPattern+"' found - Identified parameters: "+matcher.group(1));
|
||||
parameter = matcher.group(1).split(" *, *");
|
||||
}
|
||||
else{
|
||||
parameter = new String[0];
|
||||
}
|
||||
}
|
||||
else{
|
||||
throw new IllegalArgumentException("Cannot determine entry function: "+entryFunctionPattern);
|
||||
}
|
||||
|
||||
// Load manipulation script
|
||||
try {
|
||||
engine.eval(this.script);
|
||||
} catch (ScriptException e) {
|
||||
throw new RuntimeException("Unable to load manipulation script", e);
|
||||
}
|
||||
|
||||
// Determine component index of the needed parameters
|
||||
// If the component index of the parameter cannot be determined an IllegalArgumentException is thrown
|
||||
parameterIndex = new Integer[parameter.length];
|
||||
for(int i=0;i<parameter.length; i++){
|
||||
String p = parameter[i];
|
||||
p = p.trim();
|
||||
boolean found = false;
|
||||
|
||||
for(JythonParameterMapping jpm: this.mapping){
|
||||
if(jpm.getVariable().equals(p)){
|
||||
if(jpm instanceof JythonParameterMappingID){
|
||||
JythonParameterMappingID pm = (JythonParameterMappingID)jpm;
|
||||
// Mapping for parameter found, determine index of the corresponding component
|
||||
parameterIndex[i] = metadata.getIndex(pm.getRefid());
|
||||
}
|
||||
else if (jpm instanceof JythonParameterMappingChannel){
|
||||
JythonParameterMappingChannel pm = (JythonParameterMappingChannel)jpm;
|
||||
parameterIndex[i] = null;
|
||||
|
||||
Channel<?> cb;
|
||||
try {
|
||||
cb = cservice.createChannel(new ChannelDescriptor<>(pm.getType(), pm.getChannel(), true));
|
||||
} catch (ChannelException | TimeoutException e) {
|
||||
throw new IllegalArgumentException("Unable to establish channel: "+pm.getChannel(), e);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException("Unable to establish channel: "+pm.getChannel(), e);
|
||||
}
|
||||
|
||||
engine.put(pm.getVariable(), cb);
|
||||
}
|
||||
else if (jpm instanceof JythonParameterMappingGlobalVariable){
|
||||
JythonParameterMappingGlobalVariable pm = (JythonParameterMappingGlobalVariable)jpm;
|
||||
parameterIndex[i] = null;
|
||||
|
||||
engine.put(pm.getVariable(), pm.getGlobalVariable());
|
||||
}
|
||||
found=true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// If there is no mapping nothing can be found
|
||||
// If there are mappings everything need to be found
|
||||
if(!found){
|
||||
throw new IllegalArgumentException("No mapping compontent found for parameter "+p);
|
||||
}
|
||||
}
|
||||
|
||||
StringBuffer buffer = new StringBuffer();
|
||||
buffer.append(entryFunction);
|
||||
buffer.append("(");
|
||||
|
||||
for(String p: parameter){
|
||||
buffer.append(p);
|
||||
buffer.append(",");
|
||||
}
|
||||
|
||||
buffer.setCharAt(buffer.length()-1, ')');
|
||||
|
||||
jythonCall = buffer.toString();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object execute(DataMessage message){
|
||||
|
||||
// Manipulate data
|
||||
for(int i=0;i<parameterIndex.length;i++){
|
||||
if(parameterIndex[i] != null){
|
||||
engine.put(parameter[i], message.getData().get(parameterIndex[i]));
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
if(returnArray){
|
||||
return((double[]) engine.eval(jythonCall));
|
||||
}
|
||||
else{
|
||||
// Due to the typeless nature of Python an Integer of Float/Double might be returned from the
|
||||
// Python code (e.g. depending on the factors in a calculation)
|
||||
// Always return the return value to a double. If this cannot be done return NaN
|
||||
Object r = engine.eval(jythonCall);
|
||||
if(r instanceof Double){
|
||||
return((Double) r);
|
||||
}
|
||||
else if( r instanceof Integer){
|
||||
return(((Integer)r).doubleValue());
|
||||
}
|
||||
else{
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
} catch (ScriptException e) {
|
||||
// throw new RuntimeException("Data manipulaton [id: "+id+"] failed while executing the manipulation script",e);
|
||||
logger.log(Level.WARNING, "Data manipulaton [id: "+id+"] failed while executing the manipulation script");
|
||||
return Double.NaN;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,49 +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.manipulator;
|
||||
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public interface Manipulation {
|
||||
|
||||
/**
|
||||
* Get the id of the manipulation
|
||||
* @return id of manipulation
|
||||
*/
|
||||
public String getId();
|
||||
|
||||
/**
|
||||
* Initialize the manipulation
|
||||
* @param metadata Metadata of the incomming data message
|
||||
*/
|
||||
public void initialize(DataMessageMetadata metadata);
|
||||
|
||||
/**
|
||||
* Execute the manipulation on the passed data message
|
||||
* @param message Message to manipulate
|
||||
* @return Result of the manipulation
|
||||
*/
|
||||
public Object execute(DataMessage message);
|
||||
}
|
||||
@@ -1,123 +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.manipulator;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
|
||||
import ch.psi.fda.core.messages.ComponentMetadata;
|
||||
import ch.psi.fda.core.messages.DataMessage;
|
||||
import ch.psi.fda.core.messages.DataMessageMetadata;
|
||||
import ch.psi.fda.core.messages.DataQueue;
|
||||
import ch.psi.fda.core.messages.EndOfStreamMessage;
|
||||
import ch.psi.fda.core.messages.Message;
|
||||
|
||||
/**
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class Manipulator implements Runnable{
|
||||
|
||||
/**
|
||||
* Outgoing data queue
|
||||
*/
|
||||
private final DataQueue outQueue;
|
||||
|
||||
/**
|
||||
* Incomming data queue
|
||||
*/
|
||||
private final DataQueue queue;
|
||||
|
||||
/**
|
||||
* List of manipulations
|
||||
*/
|
||||
private final List<Manipulation> manipulations;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param queue
|
||||
* @param manipulations
|
||||
*/
|
||||
// TODO need to support multiple (a list of) manipulation(s)
|
||||
public Manipulator(DataQueue queue, List<Manipulation> manipulations){
|
||||
|
||||
this.manipulations = manipulations;
|
||||
|
||||
// Create outgoing data metadata
|
||||
DataMessageMetadata dmetadata = queue.getDataMessageMetadata().clone();
|
||||
|
||||
// Initialize manipulations and create outgoing metadata
|
||||
for(Manipulation manipulation: this.manipulations){
|
||||
// Initialize manipulation
|
||||
// manipulation.initialize(queue.getDataMessageMetadata());
|
||||
manipulation.initialize(dmetadata);
|
||||
|
||||
// Add manipulation id to metadata
|
||||
dmetadata.getComponents().add(new ComponentMetadata(manipulation.getId(),0)); // Calculated component always belongs to lowes dimension
|
||||
}
|
||||
|
||||
this.queue = queue;
|
||||
this.outQueue = new DataQueue(new LinkedBlockingQueue<Message>(1000) , dmetadata ); // Create bounded queue to prevent running out of memory ...
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the outQueue
|
||||
*/
|
||||
public DataQueue getOutQueue() {
|
||||
return outQueue;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
|
||||
// Dispatch Messages
|
||||
Message message = queue.getQueue().take();
|
||||
while(!(message instanceof EndOfStreamMessage)){
|
||||
if(message instanceof DataMessage){
|
||||
DataMessage dm = (DataMessage) message;
|
||||
|
||||
for(Manipulation manipulation: manipulations){
|
||||
dm.getData().add(manipulation.execute(dm));
|
||||
}
|
||||
}
|
||||
|
||||
// Put message to outgoing queue ...
|
||||
outQueue.getQueue().put(message);
|
||||
|
||||
// Read next message
|
||||
message = queue.getQueue().take();
|
||||
}
|
||||
|
||||
// Write end of stream message
|
||||
outQueue.getQueue().put(message);
|
||||
|
||||
|
||||
} catch (InterruptedException e) {
|
||||
// TODO Stop loop and exit logic instead of throwing an Exception
|
||||
throw new RuntimeException("Data manipulator was interrupted while writing data to file",e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,82 +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.messages;
|
||||
|
||||
/**
|
||||
* Metadata of a component of a message. Each component has a global id.
|
||||
* Optionally the component can also belong to a dimension. However, depending on the
|
||||
* view the number of the dimension might vary. Therefore the dimension number
|
||||
* might change during the lifetime of a message (component).
|
||||
*
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class ComponentMetadata {
|
||||
/**
|
||||
* Global id of the component
|
||||
*/
|
||||
private final String id;
|
||||
|
||||
/**
|
||||
* Dimension of the component (optional)
|
||||
*/
|
||||
private final int dimension;
|
||||
|
||||
/**
|
||||
* Default constructor - Create component metadata
|
||||
* @param id Global id of the component
|
||||
*/
|
||||
public ComponentMetadata(String id){
|
||||
this.id = id;
|
||||
this.dimension = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor that initializes id and the dimension number
|
||||
* @param id
|
||||
* @param dimension
|
||||
*/
|
||||
public ComponentMetadata(String id, int dimension){
|
||||
this.id = id;
|
||||
this.dimension = dimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the dimension
|
||||
*/
|
||||
public int getDimension() {
|
||||
return dimension;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the id
|
||||
*/
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Component Metadata[id="+id+" dimension="+dimension+"]";
|
||||
}
|
||||
}
|
||||
@@ -1,29 +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.messages;
|
||||
|
||||
/**
|
||||
* A control message that is not holding any data but
|
||||
* control information (like end of loop, etc.)
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public abstract class ControlMessage extends Message {
|
||||
}
|
||||
@@ -1,83 +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.messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Message holding data
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DataMessage extends Message {
|
||||
|
||||
/**
|
||||
* Data payload of the message
|
||||
*/
|
||||
private List<Object> data;
|
||||
|
||||
/**
|
||||
* Constructor - Create message object with data payload
|
||||
*/
|
||||
public DataMessage(){
|
||||
this.data = new ArrayList<Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get data object of the message
|
||||
* @return Data object of the message
|
||||
*/
|
||||
public List<Object> getData(){
|
||||
return(data);
|
||||
}
|
||||
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuffer b = new StringBuffer();
|
||||
b.append("Message [ ");
|
||||
for (Object o : data) {
|
||||
if (o.getClass().isArray()) {
|
||||
// If the array object is of type double[] display its content
|
||||
if (o instanceof double[]) {
|
||||
double[] oa = (double[]) o;
|
||||
b.append("[ ");
|
||||
for (double o1 : oa) {
|
||||
b.append(o1);
|
||||
b.append(" ");
|
||||
}
|
||||
b.append("]");
|
||||
} else {
|
||||
b.append(o.toString());
|
||||
}
|
||||
} else {
|
||||
b.append(o);
|
||||
}
|
||||
|
||||
b.append(" ");
|
||||
}
|
||||
b.append("]");
|
||||
return b.toString();
|
||||
}
|
||||
}
|
||||
@@ -1,81 +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.messages;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Structure to hold the metadata of a component of a message.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DataMessageMetadata {
|
||||
|
||||
/**
|
||||
* List of the metadata of the message components
|
||||
*/
|
||||
private List<ComponentMetadata> components;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
public DataMessageMetadata(){
|
||||
components = new ArrayList<ComponentMetadata>();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the list of component metadata of a message described by this object.
|
||||
*/
|
||||
public List<ComponentMetadata> getComponents() {
|
||||
return components;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the index of the component with the specified Id
|
||||
* @param componentId Id of the component to look for
|
||||
* @return Index of the component
|
||||
* @throws IllegalArgumentException There is no component with the specified Id
|
||||
*/
|
||||
public int getIndex(String componentId) throws IllegalArgumentException {
|
||||
for(int i=0;i<components.size();i++){
|
||||
ComponentMetadata c =components.get(i);
|
||||
if(c.getId().equals(componentId)){
|
||||
return(i);
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("There is no message component with Id "+ componentId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Clone data structure
|
||||
* @return Cloned data structure
|
||||
*/
|
||||
public DataMessageMetadata clone(){
|
||||
DataMessageMetadata metadata = new DataMessageMetadata();
|
||||
|
||||
for(int i=0;i<components.size();i++){
|
||||
ComponentMetadata c =components.get(i);
|
||||
metadata.getComponents().add(new ComponentMetadata(c.getId(), c.getDimension()));
|
||||
}
|
||||
|
||||
return(metadata);
|
||||
}
|
||||
}
|
||||
@@ -1,66 +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.messages;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
|
||||
|
||||
/**
|
||||
* Container holding for holding a queue and the metadata of the
|
||||
* data messages of that queue.
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class DataQueue {
|
||||
|
||||
/**
|
||||
* Queue serving the messages
|
||||
*/
|
||||
private final BlockingQueue<Message> queue;
|
||||
/**
|
||||
* Metadata of the data messages of the queue
|
||||
*/
|
||||
private final DataMessageMetadata dataMessageMetadata;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
* @param queue Data queue
|
||||
* @param dataMessageMetadata Metadata of the data messages of the queue
|
||||
*/
|
||||
public DataQueue(BlockingQueue<Message> queue, DataMessageMetadata dataMessageMetadata){
|
||||
this.queue = queue;
|
||||
this.dataMessageMetadata = dataMessageMetadata;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the queue
|
||||
*/
|
||||
public BlockingQueue<Message> getQueue() {
|
||||
return queue;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the metadata
|
||||
*/
|
||||
public DataMessageMetadata getDataMessageMetadata() {
|
||||
return dataMessageMetadata;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +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.messages;
|
||||
|
||||
/**
|
||||
* Message that is send at the end of the action loop inside an ActionLoop implementation
|
||||
* of just to indicate that a particular stream has finished
|
||||
* @author ebner
|
||||
*
|
||||
*/
|
||||
public class EndOfStreamMessage extends ControlMessage{
|
||||
|
||||
|
||||
/**
|
||||
* Intersect flag - flag to indicate that stream should be intersected
|
||||
* after this message.
|
||||
*/
|
||||
private final boolean iflag;
|
||||
|
||||
public EndOfStreamMessage(){
|
||||
this(false);
|
||||
}
|
||||
|
||||
public EndOfStreamMessage(boolean iflag){
|
||||
this.iflag = iflag;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the iflag
|
||||
*/
|
||||
public boolean isIflag(){
|
||||
return(iflag);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#toString()
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Message[ c message: end of stream ]";
|
||||
}
|
||||
}
|
||||