Refactoring in core. Added delegates for values and states
This commit is contained in:
parent
ae17288664
commit
2d8ed4da69
@ -8,6 +8,7 @@ import hep.dataforge.control.devices.StateDef
|
|||||||
import hep.dataforge.control.ports.Port
|
import hep.dataforge.control.ports.Port
|
||||||
import hep.dataforge.control.ports.PortFactory
|
import hep.dataforge.control.ports.PortFactory
|
||||||
import hep.dataforge.description.ValueDef
|
import hep.dataforge.description.ValueDef
|
||||||
|
import hep.dataforge.kodex.useEachMeta
|
||||||
import hep.dataforge.meta.Meta
|
import hep.dataforge.meta.Meta
|
||||||
import hep.dataforge.names.Name
|
import hep.dataforge.names.Name
|
||||||
import hep.dataforge.values.ValueType
|
import hep.dataforge.values.ValueType
|
||||||
@ -50,11 +51,8 @@ class LambdaHub(context: Context, meta: Meta) : DeviceHub, AbstractDevice(contex
|
|||||||
port.close()
|
port.close()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun optDevice(name: Name): Optional<Device> {
|
override fun optDevice(name: Name): Optional<Device> =
|
||||||
return magnets.stream().filter { it.name == name.toUnescaped() }.map { it as Device }.findFirst()
|
magnets.stream().filter { it.name == name.toUnescaped() }.map { it as Device }.findFirst()
|
||||||
}
|
|
||||||
|
|
||||||
override fun deviceNames(): Stream<Name> {
|
override fun getDeviceNames(): Stream<Name> = magnets.stream().map { Name.ofSingle(it.name) }
|
||||||
return magnets.stream().map { Name.ofSingle(it.name) }
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -26,70 +26,4 @@ class LambdaPortController(context: Context, port: Port) : GenericPortController
|
|||||||
return action(this)
|
return action(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// override fun getContext(): Context = _context
|
|
||||||
//
|
|
||||||
// private var address: Int = -1;
|
|
||||||
//
|
|
||||||
// private val channel = ConflatedChannel<String>();
|
|
||||||
//
|
|
||||||
// private val listeners = ReferenceRegistry<LambdaPortListener>()
|
|
||||||
//
|
|
||||||
// fun open() {
|
|
||||||
// try {
|
|
||||||
// port.holdBy(this)
|
|
||||||
// if (!port.isOpen) {
|
|
||||||
// port.open()
|
|
||||||
// }
|
|
||||||
// } catch (e: PortException) {
|
|
||||||
// throw RuntimeException("Can't hold the port $port LAMBDA port controller", e)
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// private suspend fun setAddress(address: Int, timeout: Duration) {
|
|
||||||
// synchronized(this) {
|
|
||||||
// port.send(this, "ADR $address\r")
|
|
||||||
// val res = channel.receive()
|
|
||||||
// if (res == "OK") {
|
|
||||||
// this.address = address
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private suspend fun sendMessage(message: String): String {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// suspend fun fireSequence(address: Int, timeout: Duration, vararg messages: String) {
|
|
||||||
// setAddress(address, timeout);
|
|
||||||
// for (message in messages) {
|
|
||||||
// sendMessage(message);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun close() {
|
|
||||||
// port.releaseBy(this)
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun acceptPhrase(message: String) {
|
|
||||||
// async {
|
|
||||||
// channel.send(message);
|
|
||||||
// }
|
|
||||||
// listeners.forEach {
|
|
||||||
// if (it.address == address) {
|
|
||||||
// context.parallelExecutor().submit { it.action(message) }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// override fun acceptError(errorMessage: String?, error: Throwable?) {
|
|
||||||
// listeners.forEach {
|
|
||||||
// if (it.address == address) {
|
|
||||||
// context.parallelExecutor().submit { it.onError(errorMessage, error) }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// class LambdaPortListener(val address: Int, val action: (String) -> Unit, val onError: (String?, Throwable?) -> Unit = { _, _ -> })
|
|
||||||
}
|
}
|
@ -58,7 +58,7 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection<S
|
|||||||
override fun optDevice(name: Name): Optional<Device> =
|
override fun optDevice(name: Name): Optional<Device> =
|
||||||
Optional.ofNullable(sensors.find { it.name == name.toUnescaped() })
|
Optional.ofNullable(sensors.find { it.name == name.toUnescaped() })
|
||||||
|
|
||||||
override fun deviceNames(): Stream<Name> = sensors.stream().map { Name.ofSingle(it.name) }
|
override fun getDeviceNames(): Stream<Name> = sensors.stream().map { Name.ofSingle(it.name) }
|
||||||
|
|
||||||
|
|
||||||
override fun init() {
|
override fun init() {
|
||||||
@ -141,7 +141,7 @@ class VacCollectorDevice(context: Context, meta: Meta, val sensors: Collection<S
|
|||||||
private fun terminator(): Values {
|
private fun terminator(): Values {
|
||||||
val p = ValueMap.Builder()
|
val p = ValueMap.Builder()
|
||||||
p.putValue("timestamp", DateTimeUtils.now())
|
p.putValue("timestamp", DateTimeUtils.now())
|
||||||
deviceNames().forEach { n -> p.putValue(n.toUnescaped(), null) }
|
getDeviceNames().forEach { n -> p.putValue(n.toUnescaped(), null) }
|
||||||
return p.build()
|
return p.build()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ val deviceInterceptor = InterceptorFactory { context, meta ->
|
|||||||
get("listDevices") {
|
get("listDevices") {
|
||||||
call.json {
|
call.json {
|
||||||
val devices = jsonArray();
|
val devices = jsonArray();
|
||||||
for (name in deviceManager.deviceNames()) {
|
for (name in deviceManager.getDeviceNames()) {
|
||||||
val device = deviceManager.optDevice(name).get();
|
val device = deviceManager.optDevice(name).get();
|
||||||
devices.add(jsonObject {
|
devices.add(jsonObject {
|
||||||
add("name", name.toUnescaped())
|
add("name", name.toUnescaped())
|
||||||
|
Loading…
Reference in New Issue
Block a user