Add timestamp to all messages
This commit is contained in:
parent
553d819c54
commit
b3898d2ab3
@ -17,6 +17,7 @@ kotlin {
|
|||||||
commonMain{
|
commonMain{
|
||||||
dependencies {
|
dependencies {
|
||||||
api("space.kscience:dataforge-io:$dataforgeVersion")
|
api("space.kscience:dataforge-io:$dataforgeVersion")
|
||||||
|
api(npm.kotlinx.datetime)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package ru.mipt.npm.controls.api
|
package ru.mipt.npm.controls.api
|
||||||
|
|
||||||
|
import kotlinx.datetime.Clock
|
||||||
|
import kotlinx.datetime.Instant
|
||||||
import kotlinx.serialization.SerialName
|
import kotlinx.serialization.SerialName
|
||||||
import kotlinx.serialization.Serializable
|
import kotlinx.serialization.Serializable
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
@ -16,6 +18,7 @@ public sealed class DeviceMessage {
|
|||||||
public abstract val sourceDevice: Name?
|
public abstract val sourceDevice: Name?
|
||||||
public abstract val targetDevice: Name?
|
public abstract val targetDevice: Name?
|
||||||
public abstract val comment: String?
|
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.
|
* 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 sourceDevice: Name = Name.EMPTY,
|
||||||
override val targetDevice: Name? = null,
|
override val targetDevice: Name? = null,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice))
|
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 sourceDevice: Name? = null,
|
||||||
override val targetDevice: Name,
|
override val targetDevice: Name,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block))
|
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 sourceDevice: Name? = null,
|
||||||
override val targetDevice: Name,
|
override val targetDevice: Name,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block))
|
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 sourceDevice: Name? = null,
|
||||||
override val targetDevice: Name,
|
override val targetDevice: Name,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block))
|
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 sourceDevice: Name,
|
||||||
override val targetDevice: Name? = null,
|
override val targetDevice: Name? = null,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice))
|
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 sourceDevice: Name? = null,
|
||||||
override val targetDevice: Name,
|
override val targetDevice: Name,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block))
|
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 sourceDevice: Name,
|
||||||
override val targetDevice: Name? = null,
|
override val targetDevice: Name? = null,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice))
|
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 sourceDevice: Name,
|
||||||
override val targetDevice: Name? = null,
|
override val targetDevice: Name? = null,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice))
|
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 sourceDevice: Name? = null,
|
||||||
override val targetDevice: Name? = null,
|
override val targetDevice: Name? = null,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block))
|
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 sourceDevice: Name? = null,
|
||||||
override val targetDevice: Name? = null,
|
override val targetDevice: Name? = null,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = sourceDevice?.let(block))
|
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 sourceDevice: Name,
|
||||||
override val targetDevice: Name? = null,
|
override val targetDevice: Name? = null,
|
||||||
override val comment: String? = null,
|
override val comment: String? = null,
|
||||||
|
override val time: Instant? = Clock.System.now()
|
||||||
) : DeviceMessage(){
|
) : DeviceMessage(){
|
||||||
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice))
|
override fun changeSource(block: (Name) -> Name):DeviceMessage = copy(sourceDevice = block(sourceDevice))
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,24 @@
|
|||||||
package ru.mipt.npm.controls.opcua.server
|
package ru.mipt.npm.controls.opcua.server
|
||||||
|
|
||||||
|
import kotlinx.serialization.encodeToString
|
||||||
import kotlinx.serialization.json.Json
|
import kotlinx.serialization.json.Json
|
||||||
import org.eclipse.milo.opcua.stack.core.types.builtin.DataValue
|
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.DateTime
|
||||||
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode
|
import org.eclipse.milo.opcua.stack.core.types.builtin.StatusCode
|
||||||
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant
|
import org.eclipse.milo.opcua.stack.core.types.builtin.Variant
|
||||||
import space.kscience.dataforge.meta.Meta
|
import space.kscience.dataforge.meta.Meta
|
||||||
import space.kscience.dataforge.meta.MetaSerializer
|
|
||||||
import space.kscience.dataforge.meta.isLeaf
|
import space.kscience.dataforge.meta.isLeaf
|
||||||
import space.kscience.dataforge.values.*
|
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) {
|
val variant: Variant = if (isLeaf) {
|
||||||
when (value?.type) {
|
when (value?.type) {
|
||||||
null, ValueType.NULL -> Variant.NULL_VALUE
|
null, ValueType.NULL -> Variant.NULL_VALUE
|
||||||
@ -24,7 +32,7 @@ internal fun Meta.toOpc(statusCode: StatusCode = StatusCode.GOOD, time: DateTime
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Variant(Json.encodeToString(MetaSerializer, this))
|
Variant(Json.encodeToString(this))
|
||||||
}
|
}
|
||||||
return DataValue(variant, statusCode, time)
|
return DataValue(variant, statusCode, sourceTime,serverTime ?: DateTime(Instant.now()))
|
||||||
}
|
}
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -7,7 +7,6 @@ pluginManagement {
|
|||||||
val toolsVersion = "0.10.4"
|
val toolsVersion = "0.10.4"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenLocal()
|
|
||||||
maven("https://repo.kotlin.link")
|
maven("https://repo.kotlin.link")
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
gradlePluginPortal()
|
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(
|
include(
|
||||||
":controls-core",
|
":controls-core",
|
||||||
":controls-tcp",
|
":controls-tcp",
|
||||||
|
Loading…
Reference in New Issue
Block a user