JDK update new vacuum controller

This commit is contained in:
Alexander Nozik 2019-11-18 15:56:42 +03:00
parent ee18f68928
commit e549bad998
20 changed files with 194 additions and 64 deletions

View File

@ -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"

Binary file not shown.

View File

@ -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

57
gradlew vendored
View File

@ -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" "$@"

18
gradlew.bat vendored
View File

@ -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

View File

@ -1,6 +1,12 @@
allprojects {
apply plugin: "kotlin"
// apply plugin: 'org.openjfx.javafxplugin'
//
// javafx {
// modules = [ 'javafx.controls' ]
// }
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"

View File

@ -122,6 +122,7 @@ abstract class DeviceDisplayFX<D : Device> : Component(), Connection {
* Default display shows only board pane and nothing else
*/
class DefaultDisplay : DeviceDisplayFX<Device>() {
override fun buildView(device: Device): UIComponent? = null
}

View File

@ -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'

View File

@ -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)

View File

@ -22,7 +22,11 @@ class ReadVac : NumassControlApplication<VacCollectorDevice>() {
}
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")
}
}
}

View File

@ -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")
}
}
}
}

View File

@ -47,17 +47,18 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection<S
private val helper = StorageHelper(this, this::buildLoader)
private val collector = object : DeviceListener {
private val collector = object : DeviceListener, Connection {
val averagingDuration: Duration = Duration.parse(meta.getString("averagingDuration", "PT30S"))
private val collector = RegularPointCollector(averagingDuration) {
notifyResult(it)
}
override fun notifyStateChanged(device: Device, name: String, state: Any) {
if (name == MEASUREMENT_RESULT_STATE) {
collector.put(device.name, (state as Meta).getValue("value"))
}
}
val averagingDuration: Duration = Duration.parse(meta.getString("averagingDuration", "PT30S"))
private val collector = RegularPointCollector(averagingDuration) {
notifyResult(it)
}
}
@ -72,6 +73,7 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection<S
super.init()
for (s in sensors) {
s.init()
s.connect(collector, Roles.DEVICE_LISTENER_ROLE)
}
}

View File

@ -38,7 +38,7 @@ class VacCollectorDisplay : DeviceDisplayFX<VacCollectorDevice>() {
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;
}
}

View File

@ -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")
}

View File

@ -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)
}

View File

@ -8,5 +8,6 @@
<sensor name="Px" color="black" port="tcp::192.168.111.33:4003" sensorType="meradat" address="1"/>
<sensor name="Baratron" color="cyan" port="tcp::192.168.111.33:4004" sensorType="baratron"/>
<sensor name="Collector" color="magenta" port="tcp::192.168.111.33:4003" sensorType="meradat" address="2"/>
<sensor name="PSP" port="tcp::192.168.111.32:4001" sensorType="ThyroCont" address="001"/>
</device>
</config>

View File

@ -7,8 +7,8 @@ apply plugin: 'kotlin'
//apply plugin: 'org.openjfx.javafxplugin'
//
//javafx{
// modules = [ 'javafx.controls']
//javafx {
// modules = [ 'javafx.controls' ]
//}
//if (!hasProperty('mainClass')) {

View File

@ -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<Table, Table>("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<Table, Table>("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()
}

View File

@ -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<Table, Table> { 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
}
}

View File

@ -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"