Fix small typo in event id generation

This commit is contained in:
Alexander Nozik 2024-05-16 21:22:34 +03:00
parent 5921978122
commit ee83f81a04
2 changed files with 34 additions and 10 deletions

View File

@ -29,7 +29,7 @@ public val DeviceManager.Companion.magixFormat: MagixFormat<DeviceMessage> get()
internal fun generateId(request: MagixMessage): String = if (request.id != null) { internal fun generateId(request: MagixMessage): String = if (request.id != null) {
"${request.id}.response" "${request.id}.response"
} else { } else {
"controls[${request.payload.hashCode().toString(16)}" "controls[${request.payload.hashCode().toUInt().toString(16)}]"
} }
/** /**
@ -43,7 +43,7 @@ public fun DeviceManager.launchMagixService(
coroutineContext: CoroutineContext = EmptyCoroutineContext, coroutineContext: CoroutineContext = EmptyCoroutineContext,
): Job = context.launch(coroutineContext) { ): Job = context.launch(coroutineContext) {
endpoint.subscribe(controlsMagixFormat, targetFilter = listOf(endpointID, null)).onEach { (request, payload) -> endpoint.subscribe(controlsMagixFormat, targetFilter = listOf(endpointID, null)).onEach { (request, payload) ->
val responsePayload = respondHubMessage(payload) val responsePayload: List<DeviceMessage> = respondHubMessage(payload)
responsePayload.forEach { responsePayload.forEach {
endpoint.send( endpoint.send(
format = controlsMagixFormat, format = controlsMagixFormat,

View File

@ -17,7 +17,6 @@ import kotlinx.coroutines.launch
import kotlinx.serialization.json.Json import kotlinx.serialization.json.Json
import org.eclipse.milo.opcua.sdk.server.OpcUaServer import org.eclipse.milo.opcua.sdk.server.OpcUaServer
import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText import org.eclipse.milo.opcua.stack.core.types.builtin.LocalizedText
import space.kscience.controls.api.DeviceMessage
import space.kscience.controls.api.GetDescriptionMessage import space.kscience.controls.api.GetDescriptionMessage
import space.kscience.controls.api.PropertyChangedMessage import space.kscience.controls.api.PropertyChangedMessage
import space.kscience.controls.client.launchMagixService import space.kscience.controls.client.launchMagixService
@ -30,6 +29,7 @@ import space.kscience.controls.opcua.server.serveDevices
import space.kscience.controls.spec.write import space.kscience.controls.spec.write
import space.kscience.dataforge.context.* import space.kscience.dataforge.context.*
import space.kscience.magix.api.MagixEndpoint import space.kscience.magix.api.MagixEndpoint
import space.kscience.magix.api.MagixMessage
import space.kscience.magix.api.send import space.kscience.magix.api.send
import space.kscience.magix.api.subscribe import space.kscience.magix.api.subscribe
import space.kscience.magix.rsocket.rSocketWithTcp import space.kscience.magix.rsocket.rSocketWithTcp
@ -40,6 +40,9 @@ import space.kscince.magix.zmq.ZmqMagixFlowPlugin
import java.awt.Desktop import java.awt.Desktop
import java.net.URI import java.net.URI
private val json = Json { prettyPrint = true }
class DemoController : ContextAware { class DemoController : ContextAware {
var device: DemoDevice? = null var device: DemoDevice? = null
@ -70,7 +73,7 @@ class DemoController : ContextAware {
) )
//Launch a device client and connect it to the server //Launch a device client and connect it to the server
val deviceEndpoint = MagixEndpoint.rSocketWithTcp("localhost") val deviceEndpoint = MagixEndpoint.rSocketWithTcp("localhost")
deviceManager.launchMagixService(deviceEndpoint) deviceManager.launchMagixService(deviceEndpoint, "demoDevice")
//connect visualization to a magix endpoint //connect visualization to a magix endpoint
val visualEndpoint = MagixEndpoint.rSocketWithWebSockets("localhost") val visualEndpoint = MagixEndpoint.rSocketWithWebSockets("localhost")
visualizer = startDemoDeviceServer(visualEndpoint) visualizer = startDemoDeviceServer(visualEndpoint)
@ -81,13 +84,19 @@ class DemoController : ContextAware {
val listenerEndpoint = MagixEndpoint.rSocketWithWebSockets("localhost") val listenerEndpoint = MagixEndpoint.rSocketWithWebSockets("localhost")
listenerEndpoint.subscribe(DeviceManager.magixFormat).onEach { (_, deviceMessage) ->
listenerEndpoint.subscribe(DeviceManager.magixFormat).onEach { (magixMessage, deviceMessage) ->
// print all messages that are not property change message // print all messages that are not property change message
if (deviceMessage !is PropertyChangedMessage) { if (deviceMessage !is PropertyChangedMessage) {
println(">> ${Json.encodeToString(DeviceMessage.serializer(), deviceMessage)}") println(">> ${json.encodeToString(MagixMessage.serializer(), magixMessage)}")
} }
}.launchIn(this) }.launchIn(this)
listenerEndpoint.send(DeviceManager.magixFormat, GetDescriptionMessage(), "listener", "controls-kt") listenerEndpoint.send(
format = DeviceManager.magixFormat,
payload = GetDescriptionMessage(),
source = "listener",
// target = "demoDevice"
)
} }
@ -114,17 +123,32 @@ fun DemoControls(controller: DemoController) {
Column { Column {
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {
Text("Time Scale", modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)) Text("Time Scale", modifier = Modifier.align(Alignment.CenterVertically).width(100.dp))
TextField(String.format("%.2f", timeScale),{}, enabled = false, modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)) TextField(
String.format("%.2f", timeScale),
{},
enabled = false,
modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)
)
Slider(timeScale, onValueChange = { timeScale = it }, steps = 20, valueRange = 1000f..5000f) Slider(timeScale, onValueChange = { timeScale = it }, steps = 20, valueRange = 1000f..5000f)
} }
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {
Text("X scale", modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)) Text("X scale", modifier = Modifier.align(Alignment.CenterVertically).width(100.dp))
TextField(String.format("%.2f", xScale),{}, enabled = false, modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)) TextField(
String.format("%.2f", xScale),
{},
enabled = false,
modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)
)
Slider(xScale, onValueChange = { xScale = it }, steps = 20, valueRange = 0.1f..2.0f) Slider(xScale, onValueChange = { xScale = it }, steps = 20, valueRange = 0.1f..2.0f)
} }
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {
Text("Y scale", modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)) Text("Y scale", modifier = Modifier.align(Alignment.CenterVertically).width(100.dp))
TextField(String.format("%.2f", yScale),{}, enabled = false, modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)) TextField(
String.format("%.2f", yScale),
{},
enabled = false,
modifier = Modifier.align(Alignment.CenterVertically).width(100.dp)
)
Slider(yScale, onValueChange = { yScale = it }, steps = 20, valueRange = 0.1f..2.0f) Slider(yScale, onValueChange = { yScale = it }, steps = 20, valueRange = 0.1f..2.0f)
} }
Row(Modifier.fillMaxWidth()) { Row(Modifier.fillMaxWidth()) {