Fixed Coal lazy execution (workaround for couroutine bug)

This commit is contained in:
Alexander Nozik 2017-12-08 11:26:02 +03:00
parent 2556cf36f8
commit 35fa048010
10 changed files with 38 additions and 35 deletions

View File

@ -130,7 +130,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
logger.info("Setting dynamic range to " + it.intValue()) logger.info("Setting dynamic range to " + it.intValue())
val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' } val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' }
if (response.contains("=")) { if (response.contains("=")) {
updateState(PGA, Integer.parseInt(response.substring(4))) updateLogicalState(PGA, Integer.parseInt(response.substring(4)))
} else { } else {
logger.error("Setting pga failed with message: " + response) logger.error("Setting pga failed with message: " + response)
} }
@ -175,7 +175,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
} }
if (response.contains("=")) { if (response.contains("=")) {
updateState(ABUF, Integer.parseInt(response.substring(14))) updateLogicalState(ABUF, Integer.parseInt(response.substring(14)))
// getLogger().info("successfully set buffer size to {}", this.abuf); // getLogger().info("successfully set buffer size to {}", this.abuf);
} else { } else {
logger.error("Setting averaging buffer failed with message: " + response) logger.error("Setting averaging buffer failed with message: " + response)
@ -242,7 +242,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
} }
if (response.contains("=")) { if (response.contains("=")) {
updateState(SPS, Integer.parseInt(response.substring(4))) updateLogicalState(SPS, Integer.parseInt(response.substring(4)))
} else { } else {
logger.error("Setting sps failed with message: " + response) logger.error("Setting sps failed with message: " + response)
} }
@ -303,7 +303,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
//add weak stop listener //add weak stop listener
stopListener = controller.onPhrase("[Ss]topped\\s*") { stopListener = controller.onPhrase("[Ss]topped\\s*") {
afterPause() afterPause()
updateState(Sensor.MEASURING_STATE, false) updateLogicalState(Sensor.MEASURING_STATE, false)
} }
//add weak measurement listener //add weak measurement listener

View File

@ -164,7 +164,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
// val out: Boolean = "ON" == talk("OUT?") // val out: Boolean = "ON" == talk("OUT?")
// //
// val measuredCurrent = s2d(getParameter("MC")) // val measuredCurrent = s2d(getParameter("MC"))
// updateState("current", measuredCurrent) // updateLogicalState("current", measuredCurrent)
// val setCurrent = s2d(getParameter("PC")) // val setCurrent = s2d(getParameter("PC"))
// val measuredVoltage = s2d(getParameter("MV")) // val measuredVoltage = s2d(getParameter("MV"))
// val setVoltage = s2d(getParameter("PV")) // val setVoltage = s2d(getParameter("PV"))
@ -217,11 +217,11 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
private fun update(key: String, value: String) { private fun update(key: String, value: String) {
when (key) { when (key) {
"OUT" -> updateState("output", value == "ON") "OUT" -> updateLogicalState("output", value == "ON")
"MC" -> updateState("current", s2d(value)) "MC" -> updateLogicalState("current", s2d(value))
"PC" -> updateState("targetCurrent", s2d(value)) "PC" -> updateLogicalState("targetCurrent", s2d(value))
"MV" -> updateState("voltage", s2d(value)) "MV" -> updateLogicalState("voltage", s2d(value))
"PV" -> updateState("targetVoltage", s2d(value)) "PV" -> updateLogicalState("targetVoltage", s2d(value))
} }
} }
@ -288,7 +288,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
updateTask = scheduler.scheduleWithFixedDelay(call, 0, delay.toLong(), TimeUnit.MILLISECONDS) updateTask = scheduler.scheduleWithFixedDelay(call, 0, delay.toLong(), TimeUnit.MILLISECONDS)
listener?.updateTaskStateChanged(getName(), true) listener?.updateTaskStateChanged(getName(), true)
setLogicalState("updating", Value.of(true)) updateLogicalState("updating", Value.of(true))
} }
@Throws(PortException::class) @Throws(PortException::class)
@ -340,7 +340,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
listener?.monitorTaskStateChanged(getName(), false) listener?.monitorTaskStateChanged(getName(), false)
monitorTask = null monitorTask = null
} }
setLogicalState("output", Value.of(false)) updateLogicalState("output", Value.of(false))
} }
override fun getName(): String { override fun getName(): String {

View File

@ -82,8 +82,8 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
connection.weakOnError(this::notifyError) connection.weakOnError(this::notifyError)
onResponse("FilamentStatus"){ onResponse("FilamentStatus"){
val status = it[0, 2] val status = it[0, 2]
updateState("filamentOn", status == "ON") updateLogicalState("filamentOn", status == "ON")
updateState("filamentStatus", status) updateLogicalState("filamentStatus", status)
} }
logger.info("Connected to MKS mass-spectrometer on {}", connection.port); logger.info("Connected to MKS mass-spectrometer on {}", connection.port);
} }
@ -111,8 +111,8 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
// all possible async messages // all possible async messages
"FilamentStatus" -> { "FilamentStatus" -> {
val status = response[0, 2] val status = response[0, 2]
updateState("filamentOn", status == "ON") updateLogicalState("filamentOn", status == "ON")
updateState("filamentStatus", status) updateLogicalState("filamentStatus", status)
} }
} }
if (measurementDelegate != null) { if (measurementDelegate != null) {
@ -197,7 +197,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
response = commandAndWait("Select", sensorName) response = commandAndWait("Select", sensorName)
if (response.isOK) { if (response.isOK) {
updateState("selected", true) updateLogicalState("selected", true)
// selected = true; // selected = true;
} else { } else {
notifyError(response.errorDescription(), null) notifyError(response.errorDescription(), null)
@ -208,13 +208,13 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
if (response.isOK) { if (response.isOK) {
// controlled = true; // controlled = true;
// invalidateState("controlled"); // invalidateState("controlled");
updateState("controlled", true) updateLogicalState("controlled", true)
} else { } else {
notifyError(response.errorDescription(), null) notifyError(response.errorDescription(), null)
return false return false
} }
// connected = true; // connected = true;
updateState(PortSensor.CONNECTED_STATE, true) updateLogicalState(PortSensor.CONNECTED_STATE, true)
return true return true
} else { } else {
connection.close() connection.close()
@ -274,7 +274,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
private fun selectFilament(filament: Int) { private fun selectFilament(filament: Int) {
val response = commandAndWait("FilamentSelect", filament) val response = commandAndWait("FilamentSelect", filament)
if (response.isOK) { if (response.isOK) {
updateState("filament", response[1, 1]) updateLogicalState("filament", response[1, 1])
} else { } else {
logger.error("Failed to set filament with error: {}", response.errorDescription()) logger.error("Failed to set filament with error: {}", response.errorDescription())
} }

View File

@ -52,19 +52,19 @@ class CM32Device(context: Context, meta: Meta) : PortSensor<Double>(context, met
if (answer.isEmpty()) { if (answer.isEmpty()) {
this.updateMessage("No signal") this.updateMessage("No signal")
updateState(PortSensor.CONNECTED_STATE, false) updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null return null
} else if (!answer.contains("PM1:mbar")) { } else if (!answer.contains("PM1:mbar")) {
this.updateMessage("Wrong answer: " + answer) this.updateMessage("Wrong answer: " + answer)
updateState(PortSensor.CONNECTED_STATE, false) updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null return null
} else if (answer.substring(14, 17) == "OFF") { } else if (answer.substring(14, 17) == "OFF") {
this.updateMessage("Off") this.updateMessage("Off")
updateState(PortSensor.CONNECTED_STATE, true) updateLogicalState(PortSensor.CONNECTED_STATE, true)
return null return null
} else { } else {
this.updateMessage("OK") this.updateMessage("OK")
updateState(PortSensor.CONNECTED_STATE, true) updateLogicalState(PortSensor.CONNECTED_STATE, true)
return java.lang.Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23)) return java.lang.Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23))
} }
} }

View File

@ -51,11 +51,11 @@ class MKSBaratronDevice(context: Context, meta: Meta) : PortSensor<Double>(conte
val answer = sendAndWait("AV" + channel + "\r") val answer = sendAndWait("AV" + channel + "\r")
if (answer == null || answer.isEmpty()) { if (answer == null || answer.isEmpty()) {
// invalidateState("connection"); // invalidateState("connection");
updateState(PortSensor.CONNECTED_STATE, false) updateLogicalState(PortSensor.CONNECTED_STATE, false)
this.updateMessage("No connection") this.updateMessage("No connection")
return null return null
} else { } else {
updateState(PortSensor.CONNECTED_STATE, true) updateLogicalState(PortSensor.CONNECTED_STATE, true)
} }
val res = java.lang.Double.parseDouble(answer) val res = java.lang.Double.parseDouble(answer)
if (res <= 0) { if (res <= 0) {

View File

@ -88,7 +88,7 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor<Double>(context, m
@Throws(ControlException::class) @Throws(ControlException::class)
override fun shutdown() { override fun shutdown() {
if (isConnected) { if (isConnected) {
setState("power",false) setState("power", false)
} }
super.shutdown() super.shutdown()
} }
@ -138,14 +138,14 @@ class MKSVacDevice(context: Context, meta: Meta) : PortSensor<Double>(context, m
val channel = meta.getInt("channel", 5) val channel = meta.getInt("channel", 5)
val answer = talk("PR$channel?") val answer = talk("PR$channel?")
if (answer == null || answer.isEmpty()) { if (answer == null || answer.isEmpty()) {
updateState(PortSensor.CONNECTED_STATE, false) updateLogicalState(PortSensor.CONNECTED_STATE, false)
this.updateMessage("No connection") this.updateMessage("No connection")
return null return null
} }
val res = parseDouble(answer) val res = parseDouble(answer)
return if (res <= 0) { return if (res <= 0) {
this.updateMessage("No power") this.updateMessage("No power")
invalidateState("power") updateLogicalState("power", false)
null null
} else { } else {
this.updateMessage("OK") this.updateMessage("OK")

View File

@ -61,7 +61,7 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor<Double>(contex
if (answer.isEmpty()) { if (answer.isEmpty()) {
this.updateMessage("No signal") this.updateMessage("No signal")
updateState(PortSensor.CONNECTED_STATE, false) updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null return null
} else { } else {
val match = response.matcher(answer) val match = response.matcher(answer)
@ -75,11 +75,11 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor<Double>(contex
var res = BigDecimal.valueOf(base * Math.pow(10.0, exp.toDouble())) var res = BigDecimal.valueOf(base * Math.pow(10.0, exp.toDouble()))
res = res.setScale(4, RoundingMode.CEILING) res = res.setScale(4, RoundingMode.CEILING)
this.updateMessage("OK") this.updateMessage("OK")
updateState(PortSensor.CONNECTED_STATE, true) updateLogicalState(PortSensor.CONNECTED_STATE, true)
return res.toDouble() return res.toDouble()
} else { } else {
this.updateMessage("Wrong answer: " + answer) this.updateMessage("Wrong answer: " + answer)
updateState(PortSensor.CONNECTED_STATE, false) updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null return null
} }
} }

View File

@ -52,7 +52,7 @@ shell.eval {
if (meta.hasValue("subtract.reference")) { if (meta.hasValue("subtract.reference")) {
String referenceVoltage = meta["subtract.reference"] String referenceVoltage = meta["subtract.reference"]
println "subtracting reference point ${referenceVoltage}" println "subtracting reference point ${referenceVoltage}"
def referencePoint = spectra.compute(referenceVoltage) def referencePoint = spectra.get(referenceVoltage)
spectraMap = spectra spectraMap = spectra
.findAll { it.name != referenceVoltage } .findAll { it.name != referenceVoltage }
.collectEntries { .collectEntries {

View File

@ -30,7 +30,7 @@ class NumassFitScanSummaryTask : AbstractTask<Table>() {
val builder = DataSet.builder(Table::class.java) val builder = DataSet.builder(Table::class.java)
val action = FitSummaryAction() val action = FitSummaryAction()
val input = data.checked(FitResult::class.java) val input = data.checked(FitResult::class.java)
input.nodeStream().filter { it -> it.dataSize(false) > 0 }.forEach { node -> builder.putData(node.name, action.run(model.context, node, model.getMeta()).data) } input.nodeStream().filter { it -> it.getSize(false) > 0 }.forEach { node -> builder.putData(node.name, action.run(model.context, node, model.getMeta()).data) }
return builder.build() return builder.build()
} }

View File

@ -43,7 +43,10 @@ val selectTask = task("select") {
configure(meta.getMetaOrEmpty("data")) configure(meta.getMetaOrEmpty("data"))
} }
transform<NumassSet, NumassSet> { data -> transform<NumassSet, NumassSet> { data ->
CustomDataFilter(meta).filter<NumassSet>(data.checked(NumassSet::class.java)) logger.info("Starting selection from data node with size ${data.size}")
CustomDataFilter(meta).filter<NumassSet>(data.checked(NumassSet::class.java)).also {
logger.info("Selected ${it.size} elements")
}
} }
} }