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())
val response = sendAndWait("g" + it.intValue()).trim { it <= ' ' }
if (response.contains("=")) {
updateState(PGA, Integer.parseInt(response.substring(4)))
updateLogicalState(PGA, Integer.parseInt(response.substring(4)))
} else {
logger.error("Setting pga failed with message: " + response)
}
@ -175,7 +175,7 @@ class PKT8Device(context: Context, meta: Meta) : PortSensor<PKT8Result>(context,
}
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);
} else {
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("=")) {
updateState(SPS, Integer.parseInt(response.substring(4)))
updateLogicalState(SPS, Integer.parseInt(response.substring(4)))
} else {
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
stopListener = controller.onPhrase("[Ss]topped\\s*") {
afterPause()
updateState(Sensor.MEASURING_STATE, false)
updateLogicalState(Sensor.MEASURING_STATE, false)
}
//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 measuredCurrent = s2d(getParameter("MC"))
// updateState("current", measuredCurrent)
// updateLogicalState("current", measuredCurrent)
// val setCurrent = s2d(getParameter("PC"))
// val measuredVoltage = s2d(getParameter("MV"))
// 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) {
when (key) {
"OUT" -> updateState("output", value == "ON")
"MC" -> updateState("current", s2d(value))
"PC" -> updateState("targetCurrent", s2d(value))
"MV" -> updateState("voltage", s2d(value))
"PV" -> updateState("targetVoltage", s2d(value))
"OUT" -> updateLogicalState("output", value == "ON")
"MC" -> updateLogicalState("current", s2d(value))
"PC" -> updateLogicalState("targetCurrent", s2d(value))
"MV" -> updateLogicalState("voltage", 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)
listener?.updateTaskStateChanged(getName(), true)
setLogicalState("updating", Value.of(true))
updateLogicalState("updating", Value.of(true))
}
@Throws(PortException::class)
@ -340,7 +340,7 @@ open class LambdaMagnet(context: Context, meta: Meta, private val controller: La
listener?.monitorTaskStateChanged(getName(), false)
monitorTask = null
}
setLogicalState("output", Value.of(false))
updateLogicalState("output", Value.of(false))
}
override fun getName(): String {

View File

@ -82,8 +82,8 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
connection.weakOnError(this::notifyError)
onResponse("FilamentStatus"){
val status = it[0, 2]
updateState("filamentOn", status == "ON")
updateState("filamentStatus", status)
updateLogicalState("filamentOn", status == "ON")
updateLogicalState("filamentStatus", status)
}
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
"FilamentStatus" -> {
val status = response[0, 2]
updateState("filamentOn", status == "ON")
updateState("filamentStatus", status)
updateLogicalState("filamentOn", status == "ON")
updateLogicalState("filamentStatus", status)
}
}
if (measurementDelegate != null) {
@ -197,7 +197,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
response = commandAndWait("Select", sensorName)
if (response.isOK) {
updateState("selected", true)
updateLogicalState("selected", true)
// selected = true;
} else {
notifyError(response.errorDescription(), null)
@ -208,13 +208,13 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
if (response.isOK) {
// controlled = true;
// invalidateState("controlled");
updateState("controlled", true)
updateLogicalState("controlled", true)
} else {
notifyError(response.errorDescription(), null)
return false
}
// connected = true;
updateState(PortSensor.CONNECTED_STATE, true)
updateLogicalState(PortSensor.CONNECTED_STATE, true)
return true
} else {
connection.close()
@ -274,7 +274,7 @@ class MspDevice(context: Context, meta: Meta) : PortSensor<Values>(context, meta
private fun selectFilament(filament: Int) {
val response = commandAndWait("FilamentSelect", filament)
if (response.isOK) {
updateState("filament", response[1, 1])
updateLogicalState("filament", response[1, 1])
} else {
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()) {
this.updateMessage("No signal")
updateState(PortSensor.CONNECTED_STATE, false)
updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null
} else if (!answer.contains("PM1:mbar")) {
this.updateMessage("Wrong answer: " + answer)
updateState(PortSensor.CONNECTED_STATE, false)
updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null
} else if (answer.substring(14, 17) == "OFF") {
this.updateMessage("Off")
updateState(PortSensor.CONNECTED_STATE, true)
updateLogicalState(PortSensor.CONNECTED_STATE, true)
return null
} else {
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))
}
}

View File

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

View File

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

View File

@ -61,7 +61,7 @@ class MeradatVacDevice(context: Context, meta: Meta) : PortSensor<Double>(contex
if (answer.isEmpty()) {
this.updateMessage("No signal")
updateState(PortSensor.CONNECTED_STATE, false)
updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null
} else {
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()))
res = res.setScale(4, RoundingMode.CEILING)
this.updateMessage("OK")
updateState(PortSensor.CONNECTED_STATE, true)
updateLogicalState(PortSensor.CONNECTED_STATE, true)
return res.toDouble()
} else {
this.updateMessage("Wrong answer: " + answer)
updateState(PortSensor.CONNECTED_STATE, false)
updateLogicalState(PortSensor.CONNECTED_STATE, false)
return null
}
}

View File

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

View File

@ -30,7 +30,7 @@ class NumassFitScanSummaryTask : AbstractTask<Table>() {
val builder = DataSet.builder(Table::class.java)
val action = FitSummaryAction()
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()
}

View File

@ -43,7 +43,10 @@ val selectTask = task("select") {
configure(meta.getMetaOrEmpty("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")
}
}
}