Intermediate commit for devices update

This commit is contained in:
Alexander Nozik 2017-11-14 21:14:15 +03:00
parent 1b76b42d55
commit 1f5b7ea58a
7 changed files with 35 additions and 61 deletions

View File

@ -1,5 +1,5 @@
plugins { plugins {
id "org.jetbrains.kotlin.jvm" version "1.1.51" apply false id "org.jetbrains.kotlin.jvm" version "1.1.60" apply false
} }
allprojects{ allprojects{

View File

@ -1,15 +1,3 @@
buildscript {
ext.kotlin_version = '1.1.51'
repositories {
mavenCentral()
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
allprojects{ allprojects{
apply plugin: "kotlin" apply plugin: "kotlin"

View File

@ -1,6 +1,6 @@
plugins { plugins {
id "application" id "application"
id 'com.github.johnrengelman.shadow' version '2.0.0' id 'com.github.johnrengelman.shadow' version '2.0.1'
} }
@ -38,7 +38,7 @@ shadowJar{
task debugWithDevice(dependsOn: classes, type: JavaExec) { task debugWithDevice(dependsOn: classes, type: JavaExec) {
main mainClass main mainClass
args "--config.resource=/config/server.xml" args = ["--config.resource=/config/control.xml"]
classpath = sourceSets.main.runtimeClasspath + configurations.devices classpath = sourceSets.main.runtimeClasspath + configurations.devices
description "Start application in debug mode" description "Start application in debug mode"
group "debug" group "debug"

View File

@ -23,7 +23,7 @@ task testDevice(dependsOn: classes, type: JavaExec) {
group "test" group "test"
} }
buildscript { buildscript {
ext.kotlin_version = '1.1.51' ext.kotlin_version = '1.1.60'
repositories { repositories {
mavenCentral() mavenCentral()
} }

View File

@ -154,11 +154,9 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
@Throws(ControlException::class) @Throws(ControlException::class)
override fun shutdown() { override fun shutdown() {
storageHelper!!.close() storageHelper?.close()
if (collector != null) { collector?.stop()
collector!!.stop()
collector = null collector = null
}
super.shutdown() super.shutdown()
} }
@ -299,11 +297,9 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
} }
inner class PKT8Measurement(internal val handler: PortHandler) : AbstractMeasurement<PKT8Result>(), PortHandler.PortController { inner class PKT8Measurement(private val handler: PortHandler) : AbstractMeasurement<PKT8Result>(), PortHandler.PortController {
override fun getDevice(): Device { override fun getDevice(): Device = this@PKT8Device
return this@PKT8Device
}
override fun start() { override fun start() {
if (isStarted) { if (isStarted) {
@ -327,14 +323,14 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
logger.warn("Trying to stop measurement which is already stopped") logger.warn("Trying to stop measurement which is already stopped")
} }
try { return try {
logger.info("Stopping measurement") logger.info("Stopping measurement")
val response = sendAndWait("p", TIMEOUT).trim { it <= ' ' } val response = sendAndWait("p", TIMEOUT).trim { it <= ' ' }
// Должно быть именно с большой буквы!!! // Должно быть именно с большой буквы!!!
return "Stopped" == response || "stopped" == response "Stopped" == response || "stopped" == response
} catch (ex: Exception) { } catch (ex: Exception) {
error(ex) error(ex)
return false false
} finally { } finally {
if (collector != null) { if (collector != null) {
collector!!.clear() collector!!.clear()
@ -384,8 +380,4 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
private val CHANNEL_DESIGNATIONS = arrayOf("a", "b", "c", "d", "e", "f", "g", "h") private val CHANNEL_DESIGNATIONS = arrayOf("a", "b", "c", "d", "e", "f", "g", "h")
} }
init {
setContext(context)
setMeta(meta)
}
} }

View File

@ -10,7 +10,6 @@ import hep.dataforge.meta.Meta
import hep.dataforge.plots.PlotFrame import hep.dataforge.plots.PlotFrame
import hep.dataforge.plots.PlotUtils import hep.dataforge.plots.PlotUtils
import hep.dataforge.plots.data.TimePlot import hep.dataforge.plots.data.TimePlot
import hep.dataforge.plots.data.TimePlottableGroup
import hep.dataforge.plots.jfreechart.JFreeChartFrame import hep.dataforge.plots.jfreechart.JFreeChartFrame
import inr.numass.control.DeviceDisplay import inr.numass.control.DeviceDisplay
import javafx.application.Platform import javafx.application.Platform
@ -33,9 +32,7 @@ import java.time.Instant
*/ */
class PKT8Display : DeviceDisplay<PKT8Device>(), MeasurementListener { class PKT8Display : DeviceDisplay<PKT8Device>(), MeasurementListener {
override fun buildView(device: PKT8Device): View { override fun buildView(device: PKT8Device): View = CryoView()
return CryoView()
}
internal val table = FXCollections.observableHashMap<String, PKT8Result>() internal val table = FXCollections.observableHashMap<String, PKT8Result>()
val lastUpdateProperty = SimpleObjectProperty<String>("NEVER") val lastUpdateProperty = SimpleObjectProperty<String>("NEVER")
@ -146,9 +143,9 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), MeasurementListener {
} }
} }
var rawDataButton: ToggleButton by singleAssign() private val plottables = plotFrame.plots
val plottables: TimePlottableGroup = TimePlottableGroup() var rawDataButton: ToggleButton by singleAssign()
override val root: Parent = borderpane { override val root: Parent = borderpane {
prefWidth = 800.0 prefWidth = 800.0
@ -187,16 +184,16 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), MeasurementListener {
} }
if (device.meta().hasMeta("plotConfig")) { if (device.meta().hasMeta("plotConfig")) {
plottables.configure(device.meta().getMeta("plotConfig")) plottables.configure(device.meta().getMeta("plotConfig"))
plottables.setMaxItems(1000) TimePlot.setMaxItems(plottables, 1000)
plottables.setPrefItems(400) TimePlot.setPrefItems(plottables, 400)
} }
table.addListener(MapChangeListener { change -> table.addListener(MapChangeListener { change ->
if (change.wasAdded()) { if (change.wasAdded()) {
change.valueAdded.apply { change.valueAdded.apply {
if (rawDataButton.isSelected()) { if (rawDataButton.isSelected) {
plottables.put(this.channel, this.rawValue) plottables.opt(channel).ifPresent { TimePlot.put(it, rawValue) }
} else { } else {
plottables.put(this.channel, this.temperature) plottables.opt(channel).ifPresent { TimePlot.put(it, temperature) }
} }
} }
} }
@ -204,9 +201,7 @@ class PKT8Display : DeviceDisplay<PKT8Device>(), MeasurementListener {
} }
fun clearPlot() { fun clearPlot() {
plottables.forEach { plottables.clear()
it.clear()
}
} }
} }
} }

View File

@ -31,7 +31,7 @@ annotation class DeviceView(val value: KClass<out DeviceDisplay<*>>)
* Get existing view connection or create a new one * Get existing view connection or create a new one
*/ */
fun Device.getDisplay(): DeviceDisplay<*> { fun Device.getDisplay(): DeviceDisplay<*> {
val type = DefaultDisplay::class; val type = (this::class.annotations.find { it is DeviceView } as DeviceView?)?.value ?: DefaultDisplay::class
return optConnection(Roles.VIEW_ROLE, DeviceDisplay::class.java).orElseGet { return optConnection(Roles.VIEW_ROLE, DeviceDisplay::class.java).orElseGet {
type.createInstance().also { type.createInstance().also {
connect(it, Roles.VIEW_ROLE, Roles.DEVICE_LISTENER_ROLE); connect(it, Roles.VIEW_ROLE, Roles.DEVICE_LISTENER_ROLE);
@ -57,9 +57,7 @@ abstract class DeviceDisplay<D : Device> : Component(), Connection, DeviceListen
buildView(device) buildView(device)
} }
override fun isOpen(): Boolean { override fun isOpen(): Boolean = this.deviceProperty.get() != null
return this.deviceProperty.get() != null
}
override fun open(obj: Any) { override fun open(obj: Any) {
if (!isOpen) { if (!isOpen) {
@ -121,6 +119,9 @@ abstract class DeviceDisplay<D : Device> : Component(), Connection, DeviceListen
property.addListener { observable, oldValue, newValue -> property.addListener { observable, oldValue, newValue ->
if (isOpen && oldValue != newValue) { if (isOpen && oldValue != newValue) {
runAsync { runAsync {
if(!device.isInitialized){
device.init()
}
device.setState(state, newValue).get().booleanValue(); device.setState(state, newValue).get().booleanValue();
} ui { } ui {
property.set(it) property.set(it)
@ -160,8 +161,6 @@ abstract class DeviceDisplay<D : Device> : Component(), Connection, DeviceListen
* Default display shows only board pane and nothing else * Default display shows only board pane and nothing else
*/ */
class DefaultDisplay() : DeviceDisplay<Device>() { class DefaultDisplay() : DeviceDisplay<Device>() {
override fun buildView(device: Device): UIComponent? { override fun buildView(device: Device): UIComponent? = null
return null;
}
} }