diff --git a/controls-core/build.gradle.kts b/controls-core/build.gradle.kts index 4e9daf8..53769c9 100644 --- a/controls-core/build.gradle.kts +++ b/controls-core/build.gradle.kts @@ -17,6 +17,7 @@ kotlin { commonMain{ dependencies { api("space.kscience:dataforge-io:$dataforgeVersion") + api(npm.kotlinx.datetime) } } } 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 b85df5b..f919f1e 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 @@ -1,5 +1,7 @@ package ru.mipt.npm.controls.api +import kotlinx.datetime.Clock +import kotlinx.datetime.Instant import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable import kotlinx.serialization.json.Json @@ -16,6 +18,7 @@ public sealed class DeviceMessage { public abstract val sourceDevice: Name? public abstract val targetDevice: Name? public abstract val comment: String? + public abstract val time: Instant? /** * Update the source device name for composition. If the original name is null, resulting name is also null. @@ -52,6 +55,7 @@ public data class PropertyChangedMessage( override val sourceDevice: Name = Name.EMPTY, override val targetDevice: Name? = null, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice)) } @@ -67,6 +71,7 @@ public data class PropertySetMessage( override val sourceDevice: Name? = null, override val targetDevice: Name, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block)) } @@ -82,6 +87,7 @@ public data class PropertyGetMessage( override val sourceDevice: Name? = null, override val targetDevice: Name, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block)) } @@ -95,6 +101,7 @@ public data class GetDescriptionMessage( override val sourceDevice: Name? = null, override val targetDevice: Name, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block)) } @@ -109,6 +116,7 @@ public data class DescriptionMessage( override val sourceDevice: Name, override val targetDevice: Name? = null, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice)) } @@ -124,6 +132,7 @@ public data class ActionExecuteMessage( override val sourceDevice: Name? = null, override val targetDevice: Name, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block)) } @@ -139,6 +148,7 @@ public data class ActionResultMessage( override val sourceDevice: Name, override val targetDevice: Name? = null, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice)) } @@ -153,6 +163,7 @@ public data class BinaryNotificationMessage( override val sourceDevice: Name, override val targetDevice: Name? = null, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice)) } @@ -167,6 +178,7 @@ public data class EmptyDeviceMessage( override val sourceDevice: Name? = null, override val targetDevice: Name? = null, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block)) } @@ -182,6 +194,7 @@ public data class DeviceLogMessage( override val sourceDevice: Name? = null, override val targetDevice: Name? = null, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block)) } @@ -198,6 +211,7 @@ public data class DeviceErrorMessage( override val sourceDevice: Name, override val targetDevice: Name? = null, override val comment: String? = null, + override val time: Instant? = Clock.System.now() ) : DeviceMessage(){ override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice)) } diff --git a/controls-opcua/src/main/kotlin/ru/mipt/npm/controls/opcua/server/metaToOpc.kt b/controls-opcua/src/main/kotlin/ru/mipt/npm/controls/opcua/server/metaToOpc.kt index ff23bf6..7aab6aa 100644 --- a/controls-opcua/src/main/kotlin/ru/mipt/npm/controls/opcua/server/metaToOpc.kt +++ b/controls-opcua/src/main/kotlin/ru/mipt/npm/controls/opcua/server/metaToOpc.kt @@ -1,16 +1,24 @@ package ru.mipt.npm.controls.opcua.server +import kotlinx.serialization.encodeToString import kotlinx.serialization.json.Json import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue import org.eclipse.milo.opcua.stack.core.types.builtin.DateTime import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode import org.eclipse.milo.opcua.stack.core.types.builtin.Variant import space.kscience.dataforge.meta.Meta -import space.kscience.dataforge.meta.MetaSerializer import space.kscience.dataforge.meta.isLeaf import space.kscience.dataforge.values.* +import java.time.Instant -internal fun Meta.toOpc(statusCode: StatusCode = StatusCode.GOOD, time: DateTime? = null): DataValue { +/** + * Convert Meta to OPC data value using + */ +internal fun Meta.toOpc( + statusCode: StatusCode = StatusCode.GOOD, + sourceTime: DateTime? = null, + serverTime: DateTime? = null +): DataValue { val variant: Variant = if (isLeaf) { when (value?.type) { null, ValueType.NULL -> Variant.NULL_VALUE @@ -24,7 +32,7 @@ internal fun Meta.toOpc(statusCode: StatusCode = StatusCode.GOOD, time: DateTime } } } else { - Variant(Json.encodeToString(MetaSerializer, this)) + Variant(Json.encodeToString(this)) } - return DataValue(variant, statusCode, time) + return DataValue(variant, statusCode, sourceTime,serverTime ?: DateTime(Instant.now())) } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 69a9715..ffed3a2 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.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index ddaeba6..cf5e79e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -7,7 +7,6 @@ pluginManagement { val toolsVersion = "0.10.4" repositories { - mavenLocal() maven("https://repo.kotlin.link") mavenCentral() gradlePluginPortal() @@ -21,6 +20,19 @@ pluginManagement { } } +dependencyResolutionManagement { + repositories { + maven("https://repo.kotlin.link") + mavenCentral() + } + + versionCatalogs { + create("npm") { + from("ru.mipt.npm:version-catalog:0.10.4") + } + } +} + include( ":controls-core", ":controls-tcp",