diff --git a/build.gradle b/build.gradle index 78048f6b..02d5ace7 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,5 @@ buildscript { - ext.kotlin_version = "1.3.10" + ext.kotlin_version = "1.3.50" repositories { jcenter() } @@ -10,14 +10,14 @@ buildscript { } } -//plugins{ -// id 'org.openjfx.javafxplugin' version '0.0.7' apply false -//} +plugins{ + id 'org.openjfx.javafxplugin' version '0.0.8' apply false +} allprojects { apply plugin: 'idea' apply plugin: 'java' - apply plugin: "kotlin" + apply plugin: "org.jetbrains.kotlin.jvm" group = 'inr.numass' version = '1.0.0' @@ -38,8 +38,6 @@ allprojects { testImplementation group: 'junit', name: 'junit', version: '4.+' } - - compileKotlin { kotlinOptions { jvmTarget = "1.8" diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index b80bcedc..cc4fdc29 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 33e4396b..6ce793f2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,5 @@ -#Fri Jun 16 20:54:50 MSK 2017 -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-3.5.0-bin.zip +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-6.0-bin.zip +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 4453ccea..2fe81a7d 100644 --- a/gradlew +++ b/gradlew @@ -1,5 +1,21 @@ #!/usr/bin/env sh +# +# Copyright 2015 the original author or authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + ############################################################################## ## ## Gradle start up script for UN*X @@ -28,16 +44,16 @@ APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" -warn ( ) { +warn () { echo "$*" } -die ( ) { +die () { echo echo "$*" echo @@ -109,8 +125,8 @@ if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi -# For Cygwin, switch paths to Windows format before running java -if $cygwin ; then +# For Cygwin or MSYS, switch paths to Windows format before running java +if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` @@ -138,35 +154,30 @@ if $cygwin ; then else eval `echo args$i`="\"$arg\"" fi - i=$((i+1)) + i=`expr $i + 1` done case $i in - (0) set -- ;; - (1) set -- "$args0" ;; - (2) set -- "$args0" "$args1" ;; - (3) set -- "$args0" "$args1" "$args2" ;; - (4) set -- "$args0" "$args1" "$args2" "$args3" ;; - (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; - (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; - (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; - (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; - (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; + 0) set -- ;; + 1) set -- "$args0" ;; + 2) set -- "$args0" "$args1" ;; + 3) set -- "$args0" "$args1" "$args2" ;; + 4) set -- "$args0" "$args1" "$args2" "$args3" ;; + 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; + 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; + 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; + 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; + 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Escape application args -save ( ) { +save () { for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done echo " " } -APP_ARGS=$(save "$@") +APP_ARGS=`save "$@"` # Collect all arguments for the java command, following the shell quoting and substitution rules eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" -# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong -if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then - cd "$(dirname "$0")" -fi - exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat index e95643d6..24467a14 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -1,3 +1,19 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @@ -14,7 +30,7 @@ set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome diff --git a/numass-control/build.gradle b/numass-control/build.gradle index cbf2f947..5cd7e551 100644 --- a/numass-control/build.gradle +++ b/numass-control/build.gradle @@ -1,6 +1,12 @@ allprojects { apply plugin: "kotlin" +// apply plugin: 'org.openjfx.javafxplugin' +// +// javafx { +// modules = [ 'javafx.controls' ] +// } + compileKotlin { kotlinOptions { jvmTarget = "1.8" diff --git a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt index 6e583d13..fa98ae75 100644 --- a/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt +++ b/numass-control/src/main/kotlin/inr/numass/control/DeviceDisplayFX.kt @@ -122,6 +122,7 @@ abstract class DeviceDisplayFX : Component(), Connection { * Default display shows only board pane and nothing else */ class DefaultDisplay : DeviceDisplayFX() { + override fun buildView(device: Device): UIComponent? = null } diff --git a/numass-control/vac/build.gradle b/numass-control/vac/build.gradle index dbb783d8..18a78bf2 100644 --- a/numass-control/vac/build.gradle +++ b/numass-control/vac/build.gradle @@ -1,6 +1,6 @@ apply plugin: 'application' -version = "0.5.0" +version = "0.6.0" if (!hasProperty('mainClass')) { ext.mainClass = 'inr.numass.control.readvac.ReadVac' diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt index ffebdf2a..21bc6279 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/MKSBaratronDevice.kt @@ -27,10 +27,7 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor(context, meta var channel by valueState("channel").intDelegate - override val type: String - get() { - return meta.getString("type", "numass.vac.baratron") - } + override val type: String get() = meta.getString("type", "numass.vac.baratron") override fun buildConnection(meta: Meta): GenericPortController { val port: Port = PortFactory.build(meta) diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ReadVac.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ReadVac.kt index b9b46ad4..5d2af146 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ReadVac.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ReadVac.kt @@ -22,7 +22,11 @@ class ReadVac : NumassControlApplication() { } override fun getDeviceMeta(config: Meta): Meta { - return MetaUtils.findNode(config,"device"){it.getString("name") == "numass.vac"}.orElseThrow{RuntimeException("Vacuum measurement configuration not found")} + return MetaUtils.findNode(config, "device") { + it.getString("type") == "numass:vac" + }.orElseThrow { + RuntimeException("Vacuum measurement configuration not found") + } } } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ThyroContVacDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ThyroContVacDevice.kt new file mode 100644 index 00000000..0520a271 --- /dev/null +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/ThyroContVacDevice.kt @@ -0,0 +1,66 @@ +package inr.numass.control.readvac + +import hep.dataforge.context.Context +import hep.dataforge.control.devices.PortSensor +import hep.dataforge.control.ports.GenericPortController +import hep.dataforge.control.ports.Port +import hep.dataforge.control.ports.PortFactory +import hep.dataforge.meta.Meta +import inr.numass.control.DeviceView + +//@ValueDef(key = "address") +@DeviceView(VacDisplay::class) +//@StateDef(value = ValueDef(key = "address", type = [ValueType.STRING], def = "001")) +class ThyroContVacDevice(context: Context, meta: Meta) : PortSensor(context, meta) { + //val address by valueState("address").stringDelegate + val address = "001" + + override val type: String get() = meta.getString("type", "numass.vac.thyrocont") + + override fun buildConnection(meta: Meta): GenericPortController { + val port: Port = PortFactory.build(meta) + logger.info("Connecting to port {}", port.name) + return GenericPortController(context, port) { it.endsWith("\r") } + } + + private fun String.checksum(): Char = (sumBy { it.toInt() } % 64 + 64).toChar() + + private fun wrap(str: String): String = buildString { + append(str) + append(str.checksum()) + append('\r') + } + + override fun startMeasurement(oldMeta: Meta?, newMeta: Meta) { + measurement { + val request = wrap("0010MV00") + val answer = sendAndWait(request) + if (answer.isEmpty()) { + updateState(CONNECTED_STATE, false) + notifyError("No connection") + } else { + updateState(CONNECTED_STATE, true) + } + try { + + val address = answer.substring(0..2) + //if wrong answer + if (address != this.address) { + logger.warn("Expected response for address ${this.address}, bur received for $address") + notifyError("Wrong response address") + return@measurement + } + val dataSize = answer.substring(6..7).toInt() + val data = answer.substring(8, 8 + dataSize).toDouble() + if (data <= 0) { + notifyError("Non positive") + } else { + notifyResult(data) + } + } catch (ex: Exception) { + logger.error("Parsing error", ex) + notifyError("Parse error") + } + } + } +} \ No newline at end of file diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt index 2918729a..6d3acd5f 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacCollectorDevice.kt @@ -47,17 +47,18 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection() { private val sensorConnection = object : MeasurementListener, Connection { override fun onMeasurementResult(measurement: Measurement<*>, result: Any, time: Instant?) { if (result is Double) { - table.put(measurement.device.name, result); + table[measurement.device.name] = result; } } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt index dc6ce782..0ab26a7c 100644 --- a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/VacDeviceFactory.kt @@ -19,6 +19,7 @@ class VacDeviceFactory : DeviceFactory { "CM32" -> CM32Device(context, sensorConfig) "meradat" -> MeradatVacDevice(context, sensorConfig) "baratron" -> MKSBaratronDevice(context, sensorConfig) + "ThyroCont" -> ThyroContVacDevice(context,sensorConfig) // VIRTUAL_SENSOR_TYPE -> VirtualDevice.randomDoubleSensor(context, sensorConfig) else -> throw RuntimeException("Unknown vacuum sensor type") } diff --git a/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/test.kt b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/test.kt new file mode 100644 index 00000000..26f3ff9d --- /dev/null +++ b/numass-control/vac/src/main/kotlin/inr/numass/control/readvac/test.kt @@ -0,0 +1,20 @@ +package inr.numass.control.readvac + +import hep.dataforge.context.Global +import hep.dataforge.meta.buildMeta +import kotlinx.coroutines.delay + +suspend fun main() { + val meta = buildMeta { + "name" to "PSP" + "port" to "tcp::192.168.111.32:4001" + "sensorType" to "ThyroCont" + } + val device = ThyroContVacDevice(Global, meta) + device.measure() + device.connected.set(true) + delay(400) + println(device.result) + device.connected.set(false) + +} \ No newline at end of file diff --git a/numass-control/vac/src/main/resources/config/devices.xml b/numass-control/vac/src/main/resources/config/devices.xml index 60afc049..4f2405d3 100644 --- a/numass-control/vac/src/main/resources/config/devices.xml +++ b/numass-control/vac/src/main/resources/config/devices.xml @@ -8,5 +8,6 @@ + diff --git a/numass-main/build.gradle b/numass-main/build.gradle index 0430e9b9..8bebe9dd 100644 --- a/numass-main/build.gradle +++ b/numass-main/build.gradle @@ -7,8 +7,8 @@ apply plugin: 'kotlin' //apply plugin: 'org.openjfx.javafxplugin' // -//javafx{ -// modules = [ 'javafx.controls'] +//javafx { +// modules = [ 'javafx.controls' ] //} //if (!hasProperty('mainClass')) { diff --git a/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt b/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt index 3d0a5750..6c7c3c45 100644 --- a/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt +++ b/numass-main/src/main/kotlin/inr/numass/actions/TransformDataAction.kt @@ -11,15 +11,13 @@ import hep.dataforge.isAnonymous import hep.dataforge.meta.Laminate import hep.dataforge.meta.Meta import hep.dataforge.meta.MetaUtils -import hep.dataforge.tables.ColumnFormat -import hep.dataforge.tables.ColumnTable -import hep.dataforge.tables.ListColumn -import hep.dataforge.tables.Table +import hep.dataforge.tables.* import hep.dataforge.values.ValueType.NUMBER import hep.dataforge.values.ValueType.STRING import hep.dataforge.values.Values import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_RATE_ERROR_KEY import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_RATE_KEY +import inr.numass.data.analyzers.NumassAnalyzer.Companion.TIME_KEY import inr.numass.pointExpression import java.util.* import kotlin.math.pow @@ -121,6 +119,8 @@ object TransformDataAction : OneToOneAction("numass.transform", Ta //replacing cr column val res = table.addColumn(ListColumn.build(table.getColumn(COUNT_RATE_KEY).format, cr.stream())) .addColumn(ListColumn.build(table.getColumn(COUNT_RATE_ERROR_KEY).format, crErr.stream())) + .sort(TIME_KEY) + context.output[this@TransformDataAction.name, name].render(res, meta) return res @@ -213,9 +213,7 @@ object TransformDataAction : OneToOneAction("numass.transform", Ta } } // -// override fun corrErr(point: Values): Double { -// return super.corrErr(point) -// } +// override fun corrErr(point: Values): Double = 0.0 // // override fun hasError(): Boolean = yErr.isNullOrEmpty() } diff --git a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt index bfc6275a..9a5e0ebe 100644 --- a/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt +++ b/numass-main/src/main/kotlin/inr/numass/tasks/NumassTasks.kt @@ -18,14 +18,16 @@ import hep.dataforge.stat.models.XYModel import hep.dataforge.tables.* import hep.dataforge.useMeta import hep.dataforge.useValue -import hep.dataforge.values.* +import hep.dataforge.values.ValueType +import hep.dataforge.values.Values +import hep.dataforge.values.asValue +import hep.dataforge.values.edit import hep.dataforge.workspace.tasks.task import inr.numass.NumassUtils import inr.numass.actions.MergeDataAction import inr.numass.actions.MergeDataAction.MERGE_NAME import inr.numass.actions.TransformDataAction import inr.numass.addSetMarkers -import inr.numass.data.analyzers.NumassAnalyzer import inr.numass.data.analyzers.NumassAnalyzer.Companion.CHANNEL_KEY import inr.numass.data.analyzers.NumassAnalyzer.Companion.COUNT_KEY import inr.numass.data.analyzers.SmartAnalyzer @@ -230,21 +232,24 @@ val filterTask = task("filter") { } else { dependsOn(analyzeTask, meta) } + configure(meta.getMetaOrEmpty("filter")) } pipe { data -> - if (!meta.hasMeta("filter")) return@pipe data + if(meta.isEmpty) return@pipe data - if (meta.hasValue("from") || meta.hasValue("to")) { + val result = if (meta.hasValue("from") || meta.hasValue("to")) { val uLo = meta.getDouble("from", 0.0) val uHi = meta.getDouble("to", java.lang.Double.POSITIVE_INFINITY) - this.log.report("Filtering finished") Tables.filter(data, NumassPoint.HV_KEY, uLo, uHi) } else if (meta.hasValue("condition")) { Tables.filter(data, Predicate { ExpressionUtils.condition(meta.getString("condition"), it.unbox()) }) } else { throw RuntimeException("No filtering condition specified") } + + context.output.render(result, name = this.name, stage = "numass.filter") + return@pipe result } } diff --git a/numass-viewer/build.gradle b/numass-viewer/build.gradle index 3a4c54b1..2608af67 100644 --- a/numass-viewer/build.gradle +++ b/numass-viewer/build.gradle @@ -5,6 +5,11 @@ repositories { mavenCentral() } +//apply plugin: 'org.openjfx.javafxplugin' +// +//javafx { +// modules = [ 'javafx.controls' ] +//} if (!hasProperty('mainClass')) { ext.mainClass = 'inr.numass.viewer.Viewer'//"inr.numass.viewer.test.TestApp"