Fix package names and imports

This commit is contained in:
Alexander Nozik 2021-06-20 17:05:07 +03:00
parent a093f1921e
commit a510a8aedf
45 changed files with 161 additions and 170 deletions

View File

@ -36,7 +36,7 @@ Generally, a Device has Properties that can be read and written. Also, some Acti
can optionally be applied on a device (may or may not affect properties).
- `base` - contains baseline `Device` implementation
[`DeviceBase`](dataforge-device-core/src/commonMain/kotlin/hep/dataforge/control/base/DeviceBase.kt)
[`DeviceBase`](controls-core/src/commonMain/kotlin/ru/mipt/npm/controls/base/DeviceBase.kt)
and property implementation, including property asynchronous flows.
- `controllers` - implements Message Controller that can be attached to the event bus, Message

View File

@ -1,11 +1,11 @@
package space.kscience.dataforge.control.api
package ru.mipt.npm.controls.api
import io.ktor.utils.io.core.Closeable
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.cancel
import kotlinx.coroutines.flow.SharedFlow
import ru.mipt.npm.controls.api.Device.Companion.DEVICE_TARGET
import space.kscience.dataforge.context.ContextAware
import space.kscience.dataforge.control.api.Device.Companion.DEVICE_TARGET
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.misc.Type

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.api
package ru.mipt.npm.controls.api
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.names.*
@ -38,9 +38,7 @@ public interface DeviceHub : Provider {
}
}
public companion object {
}
public companion object
}
public operator fun DeviceHub.get(nameToken: NameToken): Device =

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.messages
package ru.mipt.npm.controls.api
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.api
package ru.mipt.npm.controls.api
import io.ktor.utils.io.core.Closeable
import kotlinx.coroutines.CoroutineScope

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.api
package ru.mipt.npm.controls.api
import space.kscience.dataforge.meta.Scheme
import space.kscience.dataforge.meta.string

View File

@ -1,6 +1,6 @@
package space.kscience.dataforge.control.base
package ru.mipt.npm.controls.base
import space.kscience.dataforge.control.api.ActionDescriptor
import ru.mipt.npm.controls.api.ActionDescriptor
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.meta.asMetaItem

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.base
package ru.mipt.npm.controls.base
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.MutableSharedFlow
@ -7,10 +7,10 @@ import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import ru.mipt.npm.controls.api.ActionDescriptor
import ru.mipt.npm.controls.api.Device
import ru.mipt.npm.controls.api.PropertyDescriptor
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.control.api.ActionDescriptor
import space.kscience.dataforge.control.api.Device
import space.kscience.dataforge.control.api.PropertyDescriptor
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.misc.DFExperimental
@ -56,7 +56,7 @@ public abstract class DeviceBase(override val context: Context) : Device {
override val actionDescriptors: Collection<ActionDescriptor>
get() = _actions.values.map { it.descriptor }
internal fun <P : ReadOnlyDeviceProperty> registerProperty(name: String, property: P) {
private fun <P : ReadOnlyDeviceProperty> registerProperty(name: String, property: P) {
if (_properties.contains(name)) error("Property with name $name already registered")
_properties[name] = property
}

View File

@ -1,8 +1,8 @@
package space.kscience.dataforge.control.base
package ru.mipt.npm.controls.base
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.Flow
import space.kscience.dataforge.control.api.PropertyDescriptor
import ru.mipt.npm.controls.api.PropertyDescriptor
import space.kscience.dataforge.meta.MetaItem
import kotlin.time.Duration

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.base
package ru.mipt.npm.controls.base
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map

View File

@ -1,6 +1,6 @@
package space.kscience.dataforge.control.base
package ru.mipt.npm.controls.base
import space.kscience.dataforge.control.api.ActionDescriptor
import ru.mipt.npm.controls.api.ActionDescriptor
import space.kscience.dataforge.meta.MetaBuilder
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.meta.MetaItemNode

View File

@ -1,6 +1,6 @@
package space.kscience.dataforge.control.base
package ru.mipt.npm.controls.base
import space.kscience.dataforge.control.api.PropertyDescriptor
import ru.mipt.npm.controls.api.PropertyDescriptor
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.transformations.MetaConverter
import space.kscience.dataforge.values.Null

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.base
package ru.mipt.npm.controls.base
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.meta.transformations.MetaConverter

View File

@ -1,11 +1,8 @@
package space.kscience.dataforge.control.controllers
package ru.mipt.npm.controls.controllers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import space.kscience.dataforge.control.api.Device
import space.kscience.dataforge.control.api.DeviceHub
import space.kscience.dataforge.control.api.getOrNull
import space.kscience.dataforge.control.messages.*
import ru.mipt.npm.controls.api.*
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.misc.DFExperimental

View File

@ -1,8 +1,8 @@
package space.kscience.dataforge.control.controllers
package ru.mipt.npm.controls.controllers
import ru.mipt.npm.controls.api.Device
import ru.mipt.npm.controls.api.DeviceHub
import space.kscience.dataforge.context.*
import space.kscience.dataforge.control.api.Device
import space.kscience.dataforge.control.api.DeviceHub
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.MetaBuilder
import space.kscience.dataforge.meta.get

View File

@ -1,11 +1,11 @@
package space.kscience.dataforge.control.controllers
package ru.mipt.npm.controls.controllers
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.consumeAsFlow
import space.kscience.dataforge.control.api.DeviceHub
import space.kscience.dataforge.control.api.getOrNull
import space.kscience.dataforge.control.messages.DeviceMessage
import ru.mipt.npm.controls.api.DeviceHub
import ru.mipt.npm.controls.api.DeviceMessage
import ru.mipt.npm.controls.api.getOrNull
import space.kscience.dataforge.misc.DFExperimental
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.toName
@ -14,7 +14,7 @@ import space.kscience.dataforge.names.toName
@OptIn(DFExperimental::class)
public class HubController(
public val hub: DeviceHub,
) {
) {
private val messageOutbox = Channel<DeviceMessage>(Channel.CONFLATED)

View File

@ -1,11 +1,11 @@
package space.kscience.dataforge.control.ports
package ru.mipt.npm.controls.ports
import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.receiveAsFlow
import ru.mipt.npm.controls.api.Socket
import space.kscience.dataforge.context.*
import space.kscience.dataforge.control.api.Socket
import kotlin.coroutines.CoroutineContext
public interface Port : ContextAware, Socket<ByteArray>

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.ports
package ru.mipt.npm.controls.ports
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.ports
package ru.mipt.npm.controls.ports
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.first

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.ports
package ru.mipt.npm.controls.ports
import io.ktor.utils.io.core.BytePacketBuilder
import io.ktor.utils.io.core.readBytes

View File

@ -1,7 +1,7 @@
package space.kscience.dataforge.control.controllers
package ru.mipt.npm.controls.controllers
import kotlinx.coroutines.runBlocking
import space.kscience.dataforge.control.base.*
import ru.mipt.npm.controls.base.*
import space.kscience.dataforge.meta.MetaItem
import space.kscience.dataforge.meta.transformations.MetaConverter
import kotlin.properties.ReadOnlyProperty

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.ports
package ru.mipt.npm.controls.ports
import kotlinx.coroutines.*
import space.kscience.dataforge.context.Context
@ -41,7 +41,7 @@ public class TcpPort private constructor(
*/
public val startJob: Job get() = futureChannel
private val listenerJob = this.scope.launch {
private val listenerJob = this.scope.launch(Dispatchers.IO) {
val channel = futureChannel.await()
val buffer = ByteBuffer.allocate(1024)
while (isActive) {

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.ports
package ru.mipt.npm.controls.ports
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.flow.map

View File

@ -1,17 +1,17 @@
package space.kscience.dataforge.control.client
package ru.mipt.npm.controls.client
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import ru.mipt.npm.controls.api.DeviceMessage
import ru.mipt.npm.controls.controllers.DeviceManager
import ru.mipt.npm.controls.controllers.respondMessage
import ru.mipt.npm.magix.api.MagixEndpoint
import ru.mipt.npm.magix.api.MagixMessage
import space.kscience.dataforge.context.error
import space.kscience.dataforge.context.logger
import space.kscience.dataforge.control.controllers.DeviceManager
import space.kscience.dataforge.control.controllers.respondMessage
import space.kscience.dataforge.control.messages.DeviceMessage
public const val DATAFORGE_MAGIX_FORMAT: String = "dataforge"

View File

@ -5,13 +5,12 @@ import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import kotlinx.serialization.Serializable
import ru.mipt.npm.controls.api.get
import ru.mipt.npm.controls.controllers.DeviceManager
import ru.mipt.npm.magix.api.MagixEndpoint
import ru.mipt.npm.magix.api.MagixMessage
import space.kscience.dataforge.context.error
import space.kscience.dataforge.context.logger
import space.kscience.dataforge.control.api.get
import space.kscience.dataforge.control.client.generateId
import space.kscience.dataforge.control.controllers.DeviceManager
import space.kscience.dataforge.meta.MetaItem
public const val TANGO_MAGIX_FORMAT: String = "tango"
@ -64,9 +63,8 @@ public data class TangoPayload(
public fun DeviceManager.launchTangoMagix(
endpoint: MagixEndpoint<TangoPayload>,
endpointID: String = TANGO_MAGIX_FORMAT,
): Job = context.launch {
suspend inline fun respond(request: MagixMessage<TangoPayload>, payloadBuilder: (TangoPayload) -> TangoPayload) {
): Job {
suspend fun respond(request: MagixMessage<TangoPayload>, payloadBuilder: (TangoPayload) -> TangoPayload) {
endpoint.broadcast(
request.copy(
id = generateId(request),
@ -77,55 +75,57 @@ public fun DeviceManager.launchTangoMagix(
)
}
endpoint.subscribe().onEach { request ->
try {
val device = get(request.payload.device)
when (request.payload.action) {
TangoAction.read -> {
val value = device.getProperty(request.payload.name)
respond(request) { requestPayload ->
requestPayload.copy(
value = value,
quality = TangoQuality.VALID
)
return context.launch {
endpoint.subscribe().onEach { request ->
try {
val device = get(request.payload.device)
when (request.payload.action) {
TangoAction.read -> {
val value = device.getProperty(request.payload.name)
respond(request) { requestPayload ->
requestPayload.copy(
value = value,
quality = TangoQuality.VALID
)
}
}
TangoAction.write -> {
request.payload.value?.let { value ->
device.setProperty(request.payload.name, value)
}
//wait for value to be written and return final state
val value = device.getProperty(request.payload.name)
respond(request) { requestPayload ->
requestPayload.copy(
value = value,
quality = TangoQuality.VALID
)
}
}
TangoAction.exec -> {
val result = device.execute(request.payload.name, request.payload.argin)
respond(request) { requestPayload ->
requestPayload.copy(
argout = result,
quality = TangoQuality.VALID
)
}
}
TangoAction.pipe -> TODO("Pipe not implemented")
}
TangoAction.write -> {
request.payload.value?.let { value ->
device.setProperty(request.payload.name, value)
}
//wait for value to be written and return final state
val value = device.getProperty(request.payload.name)
respond(request) { requestPayload ->
requestPayload.copy(
value = value,
quality = TangoQuality.VALID
)
}
}
TangoAction.exec -> {
val result = device.execute(request.payload.name, request.payload.argin)
respond(request) { requestPayload ->
requestPayload.copy(
argout = result,
quality = TangoQuality.VALID
)
}
}
TangoAction.pipe -> TODO("Pipe not implemented")
}
} catch (ex: Exception) {
logger.error(ex) { "Error while responding to message" }
endpoint.broadcast(
request.copy(
id = generateId(request),
parentId = request.id,
origin = endpointID,
payload = request.payload.copy(quality = TangoQuality.WARNING)
} catch (ex: Exception) {
logger.error(ex) { "Error while responding to message" }
endpoint.broadcast(
request.copy(
id = generateId(request),
parentId = request.id,
origin = endpointID,
payload = request.payload.copy(quality = TangoQuality.WARNING)
)
)
)
}
}.launchIn(this)
}
}.launchIn(this)
//TODO implement subscriptions?
// controller.messageOutput().onEach { payload ->
@ -140,4 +140,5 @@ public fun DeviceManager.launchTangoMagix(
// }.catch { error ->
// logger.error(error) { "Error while sending a message" }
// }.launchIn(this)
}
}

View File

@ -1,11 +1,11 @@
package space.kscience.dataforge.control.serial
package ru.mipt.npm.controls.serial
import jssc.SerialPort.*
import jssc.SerialPortEventListener
import ru.mipt.npm.controls.ports.AbstractPort
import ru.mipt.npm.controls.ports.Port
import ru.mipt.npm.controls.ports.PortFactory
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.control.ports.AbstractPort
import space.kscience.dataforge.control.ports.Port
import space.kscience.dataforge.control.ports.PortFactory
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.int
import space.kscience.dataforge.meta.string

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.server
package ru.mipt.npm.controls.server
import io.ktor.application.ApplicationCall
import io.ktor.http.ContentType
@ -7,8 +7,8 @@ import io.ktor.response.respondText
import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObjectBuilder
import kotlinx.serialization.json.buildJsonObject
import space.kscience.dataforge.control.messages.DeviceMessage
import space.kscience.dataforge.control.messages.toMeta
import ru.mipt.npm.controls.api.DeviceMessage
import ru.mipt.npm.controls.api.toMeta
import space.kscience.dataforge.io.*
import space.kscience.dataforge.meta.MetaSerializer

View File

@ -1,6 +1,6 @@
@file:OptIn(ExperimentalCoroutinesApi::class, KtorExperimentalAPI::class, FlowPreview::class)
package space.kscience.dataforge.control.server
package ru.mipt.npm.controls.server
import io.ktor.application.*
@ -29,12 +29,12 @@ import kotlinx.serialization.json.Json
import kotlinx.serialization.json.JsonObject
import kotlinx.serialization.json.buildJsonArray
import kotlinx.serialization.json.put
import space.kscience.dataforge.control.api.getOrNull
import space.kscience.dataforge.control.controllers.DeviceManager
import space.kscience.dataforge.control.controllers.respondMessage
import space.kscience.dataforge.control.messages.DeviceMessage
import space.kscience.dataforge.control.messages.PropertyGetMessage
import space.kscience.dataforge.control.messages.PropertySetMessage
import ru.mipt.npm.controls.api.DeviceMessage
import ru.mipt.npm.controls.api.PropertyGetMessage
import ru.mipt.npm.controls.api.PropertySetMessage
import ru.mipt.npm.controls.api.getOrNull
import ru.mipt.npm.controls.controllers.DeviceManager
import ru.mipt.npm.controls.controllers.respondMessage
import space.kscience.dataforge.meta.toJson
import space.kscience.dataforge.meta.toMeta
import space.kscience.dataforge.meta.toMetaItem
@ -42,7 +42,6 @@ import space.kscience.dataforge.meta.toMetaItem
/**
* Create and start a web server for several devices
*/
@OptIn(KtorExperimentalAPI::class)
public fun CoroutineScope.startDeviceServer(
manager: DeviceManager,
port: Int = 8111,

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.control.ports
package ru.mipt.npm.controls.ports
import io.ktor.network.selector.ActorSelectorManager
import io.ktor.network.sockets.aSocket

View File

@ -3,18 +3,18 @@ package ru.mipt.npm.controls.demo
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.asCoroutineDispatcher
import ru.mipt.npm.controls.base.*
import ru.mipt.npm.controls.controllers.double
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.context.Factory
import space.kscience.dataforge.control.base.*
import space.kscience.dataforge.control.controllers.double
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.values.asValue
import java.time.Instant
import java.util.concurrent.Executors
import kotlin.math.cos
import kotlin.math.sin
import kotlin.time.Duration
import kotlin.time.ExperimentalTime
import kotlin.time.seconds
@OptIn(ExperimentalTime::class)
class DemoDevice(context: Context) : DeviceBase(context) {
@ -57,9 +57,9 @@ class DemoDevice(context: Context) : DeviceBase(context) {
}
init {
sin.readEvery(0.2.seconds)
cos.readEvery(0.2.seconds)
coordinates.readEvery(0.3.seconds)
sin.readEvery(Duration.seconds(0.2))
cos.readEvery(Duration.seconds(0.2))
coordinates.readEvery(Duration.seconds(0.3))
}
override fun close() {

View File

@ -5,10 +5,10 @@ import kotlinx.coroutines.flow.*
import kotlinx.coroutines.launch
import kotlinx.html.div
import kotlinx.html.link
import ru.mipt.npm.controls.controllers.devices
import ru.mipt.npm.controls.server.startDeviceServer
import ru.mipt.npm.controls.server.whenStarted
import space.kscience.dataforge.context.Context
import space.kscience.dataforge.control.controllers.devices
import space.kscience.dataforge.control.server.startDeviceServer
import space.kscience.dataforge.control.server.whenStarted
import space.kscience.dataforge.meta.double
import space.kscience.dataforge.names.NameToken
import space.kscience.plotly.layout

View File

@ -2,7 +2,7 @@ package ru.mipt.npm.controls.demo
import com.github.ricky12awesome.jss.encodeToSchema
import com.github.ricky12awesome.jss.globalJson
import space.kscience.dataforge.control.messages.DeviceMessage
import ru.mipt.npm.controls.api.DeviceMessage
fun main() {
val schema = globalJson.encodeToSchema(DeviceMessage.serializer(), generateDefinitions = false)

View File

@ -3,11 +3,8 @@ package ru.mipt.npm.magix.api
import kotlinx.serialization.Serializable
import kotlinx.serialization.json.JsonElement
/**
*
* Magix message according to [magix specification](https://github.com/piazza-controls/rfc/tree/master/1)
* with a [correction](https://github.com/piazza-controls/rfc/issues/12)
*
/*
* {
* "format": "string[required]",
* "id":"string|number[optional, but desired]",
@ -19,6 +16,13 @@ import kotlinx.serialization.json.JsonElement
* "payload":"object[optional]"
* }
*/
/**
*
* Magix message according to [magix specification](https://github.com/piazza-controls/rfc/tree/master/1)
* with a [correction](https://github.com/piazza-controls/rfc/issues/12)
*
*/
@Serializable
public data class MagixMessage<T>(
val format: String,

View File

@ -1,12 +1,9 @@
package space.kscience.dataforge.magix.api
package ru.mipt.npm.magix.api
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import ru.mipt.npm.magix.api.MagixEndpoint
import ru.mipt.npm.magix.api.MagixMessage
import ru.mipt.npm.magix.api.MagixMessageFilter
/**
* Launch magix message converter service

View File

@ -6,8 +6,8 @@ import kotlinx.serialization.KSerializer
import ru.mipt.npm.magix.api.MagixEndpoint
import ru.mipt.npm.magix.api.MagixMessage
import ru.mipt.npm.magix.api.MagixMessageFilter
import space.kscience.dataforge.magix.service.RSocketMagixEndpoint
import space.kscience.dataforge.magix.service.withTcp
import ru.mipt.npm.magix.service.RSocketMagixEndpoint
import ru.mipt.npm.magix.service.withTcp
import java.util.concurrent.Flow
public class ControlsMagixClient<T>(

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.magix.server
package ru.mipt.npm.magix.server
import io.ktor.network.selector.ActorSelectorManager
import io.ktor.network.sockets.aSocket
@ -13,9 +13,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.MutableSharedFlow
import ru.mipt.npm.magix.api.MagixEndpoint.Companion.DEFAULT_MAGIX_RAW_PORT
import ru.mipt.npm.magix.api.MagixEndpoint.Companion.DEFAULT_MAGIX_WS_PORT
import ru.mipt.npm.magix.server.GenericMagixMessage
import ru.mipt.npm.magix.server.magixAcceptor
import ru.mipt.npm.magix.server.magixModule
@OptIn(KtorExperimentalAPI::class)
public fun CoroutineScope.startMagixServer(

View File

@ -29,8 +29,6 @@ import ru.mipt.npm.magix.api.MagixEndpoint.Companion.magixJson
import ru.mipt.npm.magix.api.MagixMessage
import ru.mipt.npm.magix.api.MagixMessageFilter
import ru.mipt.npm.magix.api.filter
import space.kscience.dataforge.magix.server.SseEvent
import space.kscience.dataforge.magix.server.respondSse
import java.util.*
public typealias GenericMagixMessage = MagixMessage<JsonElement>

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.magix.server
package ru.mipt.npm.magix.server
import io.ktor.application.ApplicationCall
import io.ktor.http.CacheControl

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.magix.service
package ru.mipt.npm.magix.service
import io.ktor.client.HttpClient
import io.ktor.client.features.websocket.WebSockets

View File

@ -1,4 +1,4 @@
package space.kscience.dataforge.magix.service
package ru.mipt.npm.magix.service
import io.ktor.network.selector.ActorSelectorManager
import io.ktor.network.sockets.SocketOptions

View File

@ -11,10 +11,10 @@ import javafx.scene.layout.VBox
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import ru.mipt.npm.controls.controllers.DeviceManager
import ru.mipt.npm.controls.controllers.installing
import space.kscience.dataforge.context.Global
import space.kscience.dataforge.context.fetch
import space.kscience.dataforge.control.controllers.DeviceManager
import space.kscience.dataforge.control.controllers.installing
import tornadofx.*
class PiMotionMasterApp : App(PiMotionMasterView::class)

View File

@ -3,21 +3,22 @@
package ru.mipt.npm.devices.pimotionmaster
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.transformWhile
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import ru.mipt.npm.controls.api.DeviceHub
import ru.mipt.npm.controls.api.PropertyDescriptor
import ru.mipt.npm.controls.base.*
import ru.mipt.npm.controls.controllers.DeviceFactory
import ru.mipt.npm.controls.controllers.duration
import ru.mipt.npm.controls.ports.*
import space.kscience.dataforge.context.*
import space.kscience.dataforge.control.api.DeviceHub
import space.kscience.dataforge.control.api.PropertyDescriptor
import space.kscience.dataforge.control.base.*
import space.kscience.dataforge.control.controllers.*
import space.kscience.dataforge.control.ports.*
import space.kscience.dataforge.meta.*
import space.kscience.dataforge.names.NameToken
import space.kscience.dataforge.values.asValue
import tornadofx.*
import java.util.*
import kotlin.error
import kotlin.collections.component1
import kotlin.collections.component2
import kotlin.time.Duration
class PiMotionMasterDevice(

View File

@ -5,10 +5,10 @@ import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.sync.Mutex
import kotlinx.coroutines.sync.withLock
import ru.mipt.npm.controls.api.Socket
import ru.mipt.npm.controls.ports.AbstractPort
import ru.mipt.npm.controls.ports.withDelimiter
import space.kscience.dataforge.context.*
import space.kscience.dataforge.control.api.Socket
import space.kscience.dataforge.control.ports.AbstractPort
import space.kscience.dataforge.control.ports.withDelimiter
import kotlin.math.abs
import kotlin.time.Duration
@ -167,7 +167,7 @@ class PiMotionMasterVirtualDevice(
}
override suspend fun evaluateRequest(request: ByteArray) {
assert(request.last() == '\n'.toByte())
assert(request.last() == '\n'.code.toByte())
val string = request.decodeToString().substringBefore("\n")
.dropWhile { it != '*' && it != '#' && it !in 'A'..'Z' } //filter junk symbols at the beginning of the line

View File

@ -6,11 +6,11 @@ import javafx.beans.property.ReadOnlyProperty
import kotlinx.coroutines.flow.catch
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import ru.mipt.npm.controls.api.Device
import ru.mipt.npm.controls.base.TypedDeviceProperty
import ru.mipt.npm.controls.base.TypedReadOnlyDeviceProperty
import space.kscience.dataforge.context.info
import space.kscience.dataforge.context.logger
import space.kscience.dataforge.control.api.Device
import space.kscience.dataforge.control.base.TypedDeviceProperty
import space.kscience.dataforge.control.base.TypedReadOnlyDeviceProperty
import tornadofx.*
fun <T : Any> TypedReadOnlyDeviceProperty<T>.fxProperty(ownerDevice: Device?): ReadOnlyProperty<T> =

View File

@ -5,7 +5,6 @@ import io.ktor.network.sockets.aSocket
import io.ktor.network.sockets.openReadChannel
import io.ktor.network.sockets.openWriteChannel
import io.ktor.util.InternalAPI
import io.ktor.util.KtorExperimentalAPI
import io.ktor.util.moveToByteArray
import io.ktor.utils.io.writeAvailable
import kotlinx.coroutines.*
@ -18,7 +17,7 @@ val exceptionHandler = CoroutineExceptionHandler { _, throwable ->
throwable.printStackTrace()
}
@OptIn(KtorExperimentalAPI::class, InternalAPI::class)
@OptIn(InternalAPI::class)
fun Context.launchPiDebugServer(port: Int, axes: List<String>): Job = launch(exceptionHandler) {
val virtualDevice = PiMotionMasterVirtualDevice(this@launchPiDebugServer, axes)
val server = aSocket(ActorSelectorManager(Dispatchers.IO)).tcp().bind(InetSocketAddress("localhost", port))