JDK update new vacuum controller

This commit is contained in:
Alexander Nozik 2019-11-18 17:04:27 +03:00
parent e549bad998
commit aa25ca5674
2 changed files with 12 additions and 16 deletions

View File

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

View File

@ -5,13 +5,13 @@
*/ */
package inr.numass.control.readvac package inr.numass.control.readvac
import hep.dataforge.connections.Connection
import hep.dataforge.control.connections.Roles import hep.dataforge.control.connections.Roles
import hep.dataforge.control.devices.Device
import hep.dataforge.control.devices.DeviceListener
import hep.dataforge.control.devices.Sensor import hep.dataforge.control.devices.Sensor
import hep.dataforge.control.measurements.Measurement
import hep.dataforge.control.measurements.MeasurementListener
import hep.dataforge.fx.bindWindow import hep.dataforge.fx.bindWindow
import hep.dataforge.fx.fragments.LogFragment import hep.dataforge.fx.fragments.LogFragment
import hep.dataforge.meta.Meta
import hep.dataforge.plots.PlotGroup import hep.dataforge.plots.PlotGroup
import hep.dataforge.plots.data.TimePlot import hep.dataforge.plots.data.TimePlot
import hep.dataforge.values.Value import hep.dataforge.values.Value
@ -24,7 +24,6 @@ import javafx.geometry.Orientation
import javafx.scene.control.ScrollPane import javafx.scene.control.ScrollPane
import javafx.scene.layout.Priority import javafx.scene.layout.Priority
import tornadofx.* import tornadofx.*
import java.time.Instant
/** /**
* A view controller for Vac collector * A view controller for Vac collector
@ -35,15 +34,12 @@ class VacCollectorDisplay : DeviceDisplayFX<VacCollectorDevice>() {
private val table = FXCollections.observableHashMap<String, Double>() private val table = FXCollections.observableHashMap<String, Double>()
private val sensorConnection = object : MeasurementListener, Connection { private val sensorConnection = object : DeviceListener {
override fun onMeasurementResult(measurement: Measurement<*>, result: Any, time: Instant?) {
if (result is Double) {
table[measurement.device.name] = result;
}
}
override fun onMeasurementFailed(measurement: Measurement<*>?, exception: Throwable?) {
override fun notifyStateChanged(device: Device, name: String, state: Any) {
if (name == Sensor.MEASUREMENT_RESULT_STATE) {
table[device.name] = (state as Meta).getDouble(Sensor.RESULT_VALUE)
}
} }
} }
@ -58,7 +54,7 @@ class VacCollectorDisplay : DeviceDisplayFX<VacCollectorDevice>() {
device.sensors.forEach { sensor -> device.sensors.forEach { sensor ->
val view = VacDisplay() val view = VacDisplay()
sensor.connect(view, Roles.VIEW_ROLE, Roles.DEVICE_LISTENER_ROLE) sensor.connect(view, Roles.VIEW_ROLE, Roles.DEVICE_LISTENER_ROLE)
sensor.connect(sensorConnection, Roles.MEASUREMENT_LISTENER_ROLE); sensor.connect(sensorConnection, Roles.DEVICE_LISTENER_ROLE)
viewList.add(view) viewList.add(view)
} }
} }