From 29c0291fa3bdefb51ef469249599380f438f65b4 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Fri, 24 Dec 2021 20:52:04 +0300 Subject: [PATCH] Add details for device description message. Update build plugin and kotlin. --- .../ru/mipt/npm/controls/api/DeviceMessage.kt | 2 ++ .../controls/controllers/deviceMessages.kt | 21 +++---------------- .../mipt/npm/controls/demo/car/VirtualCar.kt | 3 ++- .../ru/mipt/npm/controls/demo/DemoDevice.kt | 4 ++-- gradle/wrapper/gradle-wrapper.properties | 2 +- .../pimotionmaster/PiMotionMasterDevice.kt | 3 ++- settings.gradle.kts | 4 ++-- 7 files changed, 14 insertions(+), 25 deletions(-) diff --git a/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt b/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt index f919f1e..9d9bc19 100644 --- a/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt +++ b/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/api/DeviceMessage.kt @@ -113,6 +113,8 @@ public data class GetDescriptionMessage( @SerialName("description") public data class DescriptionMessage( val description: Meta, + val properties: Collection, + val actions: Collection, override val sourceDevice: Name, override val targetDevice: Name? = null, override val comment: String? = null, diff --git a/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/deviceMessages.kt b/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/deviceMessages.kt index 5158961..07fa3cb 100644 --- a/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/deviceMessages.kt +++ b/controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/controllers/deviceMessages.kt @@ -5,11 +5,7 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableSharedFlow import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach -import kotlinx.serialization.json.Json -import kotlinx.serialization.json.encodeToJsonElement import ru.mipt.npm.controls.api.* -import space.kscience.dataforge.meta.Meta -import space.kscience.dataforge.meta.toMeta import space.kscience.dataforge.names.Name import space.kscience.dataforge.names.plus @@ -48,21 +44,10 @@ public suspend fun Device.respondMessage(deviceTarget: Name, request: DeviceMess } is GetDescriptionMessage -> { - val descriptionMeta = Meta { - "properties" put { - propertyDescriptors.map { descriptor -> - descriptor.name put Json.encodeToJsonElement(descriptor).toMeta() - } - } - "actions" put { - actionDescriptors.map { descriptor -> - descriptor.name put Json.encodeToJsonElement(descriptor).toMeta() - } - } - } - DescriptionMessage( - description = descriptionMeta, + description = meta, + properties = propertyDescriptors, + actions = actionDescriptors, sourceDevice = deviceTarget, targetDevice = request.sourceDevice ) diff --git a/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCar.kt b/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCar.kt index 2cfea25..18fc440 100644 --- a/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCar.kt +++ b/demo/car/src/main/kotlin/ru/mipt/npm/controls/demo/car/VirtualCar.kt @@ -17,6 +17,7 @@ import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.transformations.MetaConverter import kotlin.math.pow import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.ExperimentalTime data class Vector2D(var x: Double = 0.0, var y: Double = 0.0) : MetaRepr { @@ -103,7 +104,7 @@ open class VirtualCar(context: Context, meta: Meta) : DeviceBySpec(I //initializing the clock timeState = Clock.System.now() //starting regular updates - doRecurring(Duration.milliseconds(100)) { + doRecurring(100.milliseconds) { update() } } diff --git a/demo/src/main/kotlin/ru/mipt/npm/controls/demo/DemoDevice.kt b/demo/src/main/kotlin/ru/mipt/npm/controls/demo/DemoDevice.kt index d4a3912..9bd45cf 100644 --- a/demo/src/main/kotlin/ru/mipt/npm/controls/demo/DemoDevice.kt +++ b/demo/src/main/kotlin/ru/mipt/npm/controls/demo/DemoDevice.kt @@ -10,7 +10,7 @@ import space.kscience.dataforge.meta.descriptors.value import space.kscience.dataforge.meta.transformations.MetaConverter import space.kscience.dataforge.values.ValueType import java.time.Instant -import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds import kotlin.time.ExperimentalTime @@ -27,7 +27,7 @@ class DemoDevice(context: Context, meta: Meta) : DeviceBySpec(DemoDe cosScale.read() timeScale.read() } - doRecurring(Duration.milliseconds(50)) { + doRecurring(50.milliseconds) { coordinates.read() } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index ffed3a2..d2880ba 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt index 2f43e62..7bdfa9f 100644 --- a/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt +++ b/motors/src/main/kotlin/ru/mipt/npm/devices/pimotionmaster/PiMotionMasterDevice.kt @@ -25,6 +25,7 @@ import space.kscience.dataforge.values.asValue import kotlin.collections.component1 import kotlin.collections.component2 import kotlin.time.Duration +import kotlin.time.Duration.Companion.milliseconds class PiMotionMasterDevice( context: Context, @@ -42,7 +43,7 @@ class PiMotionMasterDevice( } } - var timeoutValue: Duration = Duration.microseconds(200) + var timeoutValue: Duration = 200.milliseconds /** * Name-friendly accessor for axis diff --git a/settings.gradle.kts b/settings.gradle.kts index 198eaff..f67c59d 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -5,7 +5,7 @@ enableFeaturePreview("VERSION_CATALOGS") pluginManagement { - val toolsVersion = "0.10.5" + val toolsVersion = "0.10.7" repositories { maven("https://repo.kotlin.link") @@ -29,7 +29,7 @@ dependencyResolutionManagement { versionCatalogs { create("npm") { - from("ru.mipt.npm:version-catalog:0.10.5") + from("ru.mipt.npm:version-catalog:0.10.7") } } }