Automatic diff

This commit is contained in:
Alexander Nozik 2018-04-11 16:54:39 +03:00
parent 4372f46055
commit e99fe84053
4 changed files with 65 additions and 176 deletions

View File

@ -1,123 +0,0 @@
/*
* Copyright 2015 Alexander Nozik.
*
* 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
*
* http://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.
*/
package inr.numass.control.magnet.fx
import tornadofx.*
/**
*
* @author Alexander Nozik
*/
class MagnetControllerApp : App() {
//
// private lateinit var device: LambdaHub
//
// @Throws(IOException::class, ControlException::class)
// override fun start(stage: Stage) {
// Locale.setDefault(Locale.US)// чтобы отделение десятичных знаков было точкой
// val rootLogger = LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME) as ch.qos.logback.classic.Logger
//
// val logLevel = parameters.named.getOrDefault("logLevel", "INFO")
//
// rootLogger.level = Level.valueOf(logLevel)
//
// val logFile = parameters.named["logFile"]
//
// if (logFile != null) {
// val appender = FileAppender<ILoggingEvent>()
// appender.file = logFile
// appender.context = rootLogger.loggerContext
// appender.start()
// rootLogger.addAppender(appender)
// }
//
//
// val configFileName = parameters.named
// val config = MetaFileReader.instance().read(context,)
//
//// val portName = (parameters.named as java.util.Map<String, String>).getOrDefault("port", "virtual")
////
//// if (portName == "virtual") {
//// handler = VirtualLambdaPort("COM12", 1, 2, 3, 4)
//// } else {
//// handler = PortFactory.getPort(portName)
//// //TODO add meta reader here
//// }
////
//// sourceController = SafeLambdaMagnet("SOURCE", handler, 1)
//// pinchController = SafeLambdaMagnet("PINCH", handler, 2)
//// conusController = SafeLambdaMagnet("CONUS", handler, 3)
//// detectorController = SafeLambdaMagnet("DETECTOR", handler, 4)
////
//// conusController.bindTo(pinchController, 30.0)
////
//// controllers.add(sourceController)
//// sourceController.speed = 4.0
//// controllers.add(pinchController)
//// controllers.add(conusController)
//// controllers.add(detectorController)
//
//
// val showConfirmation = java.lang.Boolean.parseBoolean((parameters.named as java.util.Map<String, String>).getOrDefault("confirmOut", "false"))
//
// val vbox = VBox(5.0)
// var height = 0.0
// var width = 0.0
// for (controller in controllers) {
// val comp = MagnetControllerComponent.build(controller)
// width = Math.max(width, comp.prefWidth)
// height += comp.prefHeight + 5
// if (!showConfirmation) {
// comp.setShowConfirmation(showConfirmation)
// }
// vbox.children.add(comp)
// }
//
// val scene = Scene(vbox, width, height)
//
//
// stage.title = "Numass magnet view"
// stage.scene = scene
// stage.isResizable = false
// stage.show()
// }
//
// @Throws(Exception::class)
// override fun stop() {
// super.stop() //To change body of generated methods, choose Tools | Templates.
// for (magnet in controllers) {
// magnet.stopMonitorTask()
// magnet.stopUpdateTask()
// }
// if (handler.isOpen) {
// handler.close()
// }
// System.exit(0)
// }
//
// companion object {
//
// /**
// * @param args the command line arguments
// */
// @JvmStatic
// fun main(args: Array<String>) {
// Application.launch(*args)
// }
// }
}

View File

@ -39,6 +39,7 @@ import hep.dataforge.tables.ValuesListener
import hep.dataforge.values.ValueType
import inr.numass.control.DeviceView
import inr.numass.control.NumassStorageConnection
import inr.numass.control.msp.MspDevice.Companion.SELECTED_STATE
import java.time.Duration
import java.util.*
@ -51,6 +52,7 @@ import java.util.*
)
@StateDefs(
StateDef(value = ValueDef(name = "controlled", info = "Connection with the device itself"), writable = true),
StateDef(ValueDef(name = SELECTED_STATE)),
StateDef(value = ValueDef(name = "storing", info = "Define if this device is currently writes to storage"), writable = true),
StateDef(value = ValueDef(name = "filament", info = "The number of filament in use"), writable = true),
StateDef(value = ValueDef(name = "filamentOn", info = "Mass-spectrometer filament on"), writable = true),
@ -62,18 +64,22 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
// private var measurementDelegate: Consumer<MspResponse>? = null
val selected: Boolean by valueState("selected").booleanDelegate
//val selected: Boolean by valueState("selected").booleanDelegate
var controlled = valueState(CONTROLLED_STATE) { _, value ->
control(value.booleanValue())
}
var filament by valueState("filament") { old, value ->
selectFilament(value.intValue())
if (old != value) {
selectFilament(value.intValue())
}
}.intDelegate
var filamentOn = valueState("filamentOn") { _, value ->
setFilamentOn(value.booleanValue())
var filamentOn = valueState("filamentOn") { old, value ->
if (old != value) {
setFilamentOn(value.booleanValue())
}
}
var peakJumpZero: Double by valueState("peakJump.zero").doubleDelegate
@ -124,42 +130,47 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
* @throws hep.dataforge.exceptions.ControlException
*/
private fun control(on: Boolean): Boolean {
val sensorName: String
if (on) {
//ensure device is connected
connected.set(true)
var response = commandAndWait("Sensors")
if (response.isOK) {
sensorName = response[2, 1]
} else {
notifyError(response.errorDescription, null)
return false
}
//PENDING определеить в конфиге номер прибора
synchronized(this) {
logger.info("Starting initialization sequence")
if (on != this.controlled.booleanValue) {
val sensorName: String
if (on) {
//ensure device is connected
connected.setAndWait(true)
var response = commandAndWait("Sensors")
if (response.isOK) {
sensorName = response[2, 1]
} else {
notifyError(response.errorDescription, null)
return false
}
//PENDING определеить в конфиге номер прибора
response = commandAndWait("Select", sensorName)
if (response.isOK) {
updateState("selected", true)
} else {
notifyError(response.errorDescription, null)
return false
}
response = commandAndWait("Select", sensorName)
if (response.isOK) {
updateState("selected", true)
} else {
notifyError(response.errorDescription, null)
return false
}
response = commandAndWait("Control", "inr.numass.msp", "1.1")
if (response.isOK) {
updateState("controlled", true)
response = commandAndWait("Control", "inr.numass.msp", "1.1")
if (response.isOK) {
controlled.update(true)
} else {
notifyError(response.errorDescription, null)
return false
}
// connected = true;
updateState(PortSensor.CONNECTED_STATE, true)
return true
} else {
return !commandAndWait("Release").isOK
}
} else {
notifyError(response.errorDescription, null)
return false
return on
}
// connected = true;
updateState(PortSensor.CONNECTED_STATE, true)
return true
} else {
return !commandAndWait("Release").isOK
}
}
/**
@ -201,8 +212,14 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
*/
@Throws(PortException::class)
private fun commandAndWait(commandName: String, vararg parameters: Any): MspResponse {
send(buildCommand(commandName, *parameters))
val response = connection.waitFor(TIMEOUT) { str: String -> str.trim { it <= ' ' }.startsWith(commandName) }
val command = buildCommand(commandName, *parameters)
if (debug) {
logger.info("SEND: $command")
}
val response = connection.sendAndWait(command, TIMEOUT) { str: String -> str.trim { it <= ' ' }.startsWith(commandName) }
if (debug) {
logger.info("RECEIVE:\n$response")
}
return MspResponse(response)
}
@ -280,19 +297,6 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
operator fun get(lineNo: Int, columnNo: Int): String = data[lineNo][columnNo]
}
// @Throws(MeasurementException::class)
// override fun createMeasurement(): PeakJumpMeasurement {
// val measurementMeta = meta.getMeta("peakJump")
// val s = measurementMeta.getString("type", "peakJump")
// if (s == "peakJump") {
// val measurement = PeakJumpMeasurement(measurementMeta)
// this.measurementDelegate = measurement
// return measurement
// } else {
// throw MeasurementException("Unknown measurement type")
// }
// }
override fun stopMeasurement() {
super.stopMeasurement()
execute {
@ -393,6 +397,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor(context, meta) {
companion object {
const val MSP_DEVICE_TYPE = "numass.msp"
const val CONTROLLED_STATE = "controlled"
const val SELECTED_STATE = "selected"
private val TIMEOUT = Duration.ofMillis(200)
}

View File

@ -137,7 +137,7 @@ class MspDisplay() : DeviceDisplayFX<MspDevice>(), NamedValueListener {
}
switch {
padding = Insets(5.0, 0.0, 0.0, 0.0)
disableProperty().bind(booleanStateProperty(PortSensor.CONNECTED_STATE))
disableProperty().bind(device.controlled.asBooleanProperty().not())
device.filamentOn.asBooleanProperty().bindBidirectional(selectedProperty())
}
deviceStateIndicator(this@MspDisplay, "filamentStatus", false) {

View File

@ -118,7 +118,9 @@ fun Node.deviceStateToggle(connection: DeviceDisplayFX<*>, state: String, title:
}
}
connection.valueStateProperty(state).onChange {
isSelected = it?.booleanValue() ?: false
runLater {
isSelected = it?.booleanValue() ?: false
}
}
}
deviceStateIndicator(connection, state, false)
@ -142,4 +144,9 @@ fun BorderPane.plot(plottable: Plottable, metaTransform: (KMetaBuilder.() -> Uni
frame.add(plottable)
center = PlotContainer(frame).root
return frame;
}
}
//val ValueState.property: ObjectProperty<Value>
// get() {
// ret
// }