WIP fixing angles

This commit is contained in:
Alexander Nozik 2023-06-08 10:03:41 +03:00
parent bfeeed00d5
commit 33e1aafa01
3 changed files with 11 additions and 8 deletions

View File

@ -1,18 +1,18 @@
package space.kscience.controls.misc package space.kscience.controls.misc
import kotlinx.datetime.Instant
import space.kscience.dataforge.meta.Meta import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.get import space.kscience.dataforge.meta.get
import space.kscience.dataforge.meta.long import space.kscience.dataforge.meta.long
import java.time.Instant
// TODO move to core // TODO move to core
public fun Instant.toMeta(): Meta = Meta { public fun Instant.toMeta(): Meta = Meta {
"seconds" put epochSecond "seconds" put epochSeconds
"nanos" put nano "nanos" put nanosecondsOfSecond
} }
public fun Meta.instant(): Instant = value?.long?.let { Instant.ofEpochMilli(it) } ?: Instant.ofEpochSecond( public fun Meta.instant(): Instant = value?.long?.let { Instant.fromEpochMilliseconds(it) } ?: Instant.fromEpochSeconds(
get("seconds")?.long ?: 0L, get("seconds")?.long ?: 0L,
get("nanos")?.long ?: 0L, get("nanos")?.long ?: 0L,
) )

View File

@ -142,6 +142,7 @@ public abstract class ModbusRegistryMap {
} }
public fun print(map: ModbusRegistryMap, to: Appendable = System.out) { public fun print(map: ModbusRegistryMap, to: Appendable = System.out) {
validate(map)
map.entries.entries.sortedBy { it.key.address }.forEach { (key, description) -> map.entries.entries.sortedBy { it.key.address }.forEach { (key, description) ->
val typeString = when (key) { val typeString = when (key) {
is ModbusRegistryKey.Coil -> "Coil" is ModbusRegistryKey.Coil -> "Coil"

View File

@ -1,5 +1,7 @@
package space.kscience.controls.opcua.client package space.kscience.controls.opcua.client
import kotlinx.datetime.toJavaInstant
import kotlinx.datetime.toKotlinInstant
import org.eclipse.milo.opcua.binaryschema.AbstractCodec import org.eclipse.milo.opcua.binaryschema.AbstractCodec
import org.eclipse.milo.opcua.binaryschema.parser.BsdParser import org.eclipse.milo.opcua.binaryschema.parser.BsdParser
import org.eclipse.milo.opcua.stack.core.UaSerializationException import org.eclipse.milo.opcua.stack.core.UaSerializationException
@ -66,7 +68,7 @@ internal fun opcToMeta(value: Any?): Meta = when (value) {
is Boolean -> Meta(value.asValue()) is Boolean -> Meta(value.asValue())
is String -> Meta(value.asValue()) is String -> Meta(value.asValue())
is Char -> Meta(value.toString().asValue()) is Char -> Meta(value.toString().asValue())
is DateTime -> value.javaInstant.toMeta() is DateTime -> value.javaInstant.toKotlinInstant().toMeta()
is UUID -> Meta(value.toString().asValue()) is UUID -> Meta(value.toString().asValue())
is QualifiedName -> Meta { is QualifiedName -> Meta {
"namespaceIndex" put value.namespaceIndex "namespaceIndex" put value.namespaceIndex
@ -79,9 +81,9 @@ internal fun opcToMeta(value: Any?): Meta = when (value) {
is DataValue -> Meta { is DataValue -> Meta {
"value" put opcToMeta(value.value) // need SerializationContext to do that properly "value" put opcToMeta(value.value) // need SerializationContext to do that properly
value.statusCode?.value?.let { "status" put Meta(it.asValue()) } value.statusCode?.value?.let { "status" put Meta(it.asValue()) }
value.sourceTime?.javaInstant?.let { "sourceTime" put it.toMeta() } value.sourceTime?.javaInstant?.let { "sourceTime" put it.toKotlinInstant().toMeta() }
value.sourcePicoseconds?.let { "sourcePicoseconds" put Meta(it.asValue()) } value.sourcePicoseconds?.let { "sourcePicoseconds" put Meta(it.asValue()) }
value.serverTime?.javaInstant?.let { "serverTime" put it.toMeta() } value.serverTime?.javaInstant?.let { "serverTime" put it.toKotlinInstant().toMeta() }
value.serverPicoseconds?.let { "serverPicoseconds" put Meta(it.asValue()) } value.serverPicoseconds?.let { "serverPicoseconds" put Meta(it.asValue()) }
} }
is ByteString -> Meta(value.bytesOrEmpty().asValue()) is ByteString -> Meta(value.bytesOrEmpty().asValue())
@ -145,7 +147,7 @@ internal class MetaStructureCodec(
"Float" -> member.value?.numberOrNull?.toFloat() "Float" -> member.value?.numberOrNull?.toFloat()
"Double" -> member.value?.numberOrNull?.toDouble() "Double" -> member.value?.numberOrNull?.toDouble()
"String" -> member.string "String" -> member.string
"DateTime" -> DateTime(member.instant()) "DateTime" -> DateTime(member.instant().toJavaInstant())
"Guid" -> member.string?.let { UUID.fromString(it) } "Guid" -> member.string?.let { UUID.fromString(it) }
"ByteString" -> member.value?.list?.let { list -> "ByteString" -> member.value?.list?.let { list ->
ByteString(list.map { it.number.toByte() }.toByteArray()) ByteString(list.map { it.number.toByte() }.toByteArray())