Add message flow output for PidDemo

This commit is contained in:
Alexander Nozik 2024-07-25 12:28:58 +03:00
parent f0f9d0e174
commit 47327aef19
5 changed files with 21 additions and 54 deletions

View File

@ -1,45 +0,0 @@
import kotlin.io.path.readText
job("Build") {
gradlew("spc.registry.jetbrains.space/p/sci/containers/kotlin-ci:1.0.3", "build")
}
job("Publish") {
startOn {
gitPush { enabled = false }
}
container("spc.registry.jetbrains.space/p/sci/containers/kotlin-ci:1.0.3") {
env["SPACE_USER"] = "{{ project:space_user }}"
env["SPACE_TOKEN"] = "{{ project:space_token }}"
kotlinScript { api ->
val spaceUser = System.getenv("SPACE_USER")
val spaceToken = System.getenv("SPACE_TOKEN")
// write the version to the build directory
api.gradlew("version")
//read the version from build file
val version = java.nio.file.Path.of("build/project-version.txt").readText()
val revisionSuffix = if (version.endsWith("SNAPSHOT")) {
"-" + api.gitRevision().take(7)
} else {
""
}
api.space().projects.automation.deployments.start(
project = api.projectIdentifier(),
targetIdentifier = TargetIdentifier.Key("maps-kt"),
version = version+revisionSuffix,
// automatically update deployment status based on the status of a job
syncWithAutomationJob = true
)
api.gradlew(
"publishAllPublicationsToSpaceRepository",
"-Ppublishing.space.user=\"$spaceUser\"",
"-Ppublishing.space.token=\"$spaceToken\"",
)
}
}
}

View File

@ -3,6 +3,7 @@ import space.kscience.gradle.useSPCTeam
plugins { plugins {
id("space.kscience.gradle.project") id("space.kscience.gradle.project")
alias(libs.plugins.versions)
} }
allprojects { allprojects {

View File

@ -82,22 +82,24 @@ class DemoController : ContextAware {
opcUaServer.startup() opcUaServer.startup()
opcUaServer.serveDevices(deviceManager) opcUaServer.serveDevices(deviceManager)
//create a remote listener endpoint
val listenerEndpoint = MagixEndpoint.rSocketWithWebSockets("localhost") val listenerEndpoint = MagixEndpoint.rSocketWithWebSockets("localhost")
// subscribe remote endpoint
listenerEndpoint.subscribe(DeviceManager.magixFormat).onEach { (magixMessage, 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(MagixMessage.serializer(), magixMessage)}") println(">> ${json.encodeToString(MagixMessage.serializer(), magixMessage)}")
} }
}.launchIn(this) }.launchIn(this)
// send description request
listenerEndpoint.send( listenerEndpoint.send(
format = DeviceManager.magixFormat, format = DeviceManager.magixFormat,
payload = GetDescriptionMessage(), payload = GetDescriptionMessage(),
source = "listener", source = "listener",
// target = "demoDevice" // target = "demoDevice"
) )
} }
fun shutdown(): Job = context.launch { fun shutdown(): Job = context.launch {

View File

@ -19,10 +19,13 @@ import io.github.koalaplot.core.util.toString
import io.github.koalaplot.core.xygraph.XYGraph import io.github.koalaplot.core.xygraph.XYGraph
import io.github.koalaplot.core.xygraph.rememberDoubleLinearAxisModel import io.github.koalaplot.core.xygraph.rememberDoubleLinearAxisModel
import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filterIsInstance
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.flow.onEach
import kotlinx.datetime.Instant import kotlinx.datetime.Instant
import org.jetbrains.compose.splitpane.ExperimentalSplitPaneApi import org.jetbrains.compose.splitpane.ExperimentalSplitPaneApi
import org.jetbrains.compose.splitpane.HorizontalSplitPane import org.jetbrains.compose.splitpane.HorizontalSplitPane
import space.kscience.controls.api.PropertyChangedMessage
import space.kscience.controls.compose.NumberTextField import space.kscience.controls.compose.NumberTextField
import space.kscience.controls.compose.PlotNumericState import space.kscience.controls.compose.PlotNumericState
import space.kscience.controls.compose.TimeAxisModel import space.kscience.controls.compose.TimeAxisModel
@ -39,11 +42,9 @@ import space.kscience.controls.constructor.onTimer
import space.kscience.controls.constructor.units.Kilograms import space.kscience.controls.constructor.units.Kilograms
import space.kscience.controls.constructor.units.Meters import space.kscience.controls.constructor.units.Meters
import space.kscience.controls.constructor.units.NumericalValue import space.kscience.controls.constructor.units.NumericalValue
import space.kscience.controls.manager.ClockManager import space.kscience.controls.manager.*
import space.kscience.controls.manager.DeviceManager
import space.kscience.controls.manager.clock
import space.kscience.controls.manager.install
import space.kscience.dataforge.context.Context import space.kscience.dataforge.context.Context
import space.kscience.dataforge.context.request
import java.awt.Dimension import java.awt.Dimension
import kotlin.math.PI import kotlin.math.PI
import kotlin.math.sin import kotlin.math.sin
@ -165,6 +166,15 @@ fun main() = application {
//bind pid parameters //bind pid parameters
LaunchedEffect(Unit) { LaunchedEffect(Unit) {
// start listening to local device hub
context.request(DeviceManager).hubMessageFlow()
.filterIsInstance<PropertyChangedMessage>() // filter only property change messages
//.filter { it.sourceDevice == "linearDrive".asName()} //optionally filter by device name
.onEach {
println("${it.sourceDevice} >> ${it.property} changed to ${it.value}")
}.launchIn(this)
snapshotFlow { snapshotFlow {
pidParameters pidParameters
}.onEach { }.onEach {

View File

@ -31,8 +31,6 @@ plc4j = "0.12.0"
visionforge = "0.4.2" visionforge = "0.4.2"
versions = "0.51.0"
[libraries] [libraries]
dataforge-io = { module = "space.kscience:dataforge-io", version.ref = "dataforge" } dataforge-io = { module = "space.kscience:dataforge-io", version.ref = "dataforge" }
@ -89,4 +87,5 @@ koala-plots = { module = "io.github.koalaplot:koalaplot-core", version = "0.6.1"
[plugins] [plugins]
versions = { id = "com.github.ben-manes.versions", version.ref = "versions" } versions = "com.github.ben-manes.versions:0.51.0"
versions-update = "nl.littlerobots.version-catalog-update:0.8.4"