A lot of minor updates in Control
This commit is contained in:
parent
fd5b177b30
commit
b175c3af74
@ -139,7 +139,7 @@ public class MspDevice extends Sensor<Values> implements PortHandler.PortControl
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
public String getType() {
|
||||
return "MKS E-Vision";
|
||||
}
|
||||
|
||||
|
@ -47,7 +47,7 @@ public class CM32Device extends PortSensor<Double> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
public String getType() {
|
||||
return meta().getString("type", "Leibold CM32");
|
||||
}
|
||||
|
||||
@ -61,19 +61,19 @@ public class CM32Device extends PortSensor<Double> {
|
||||
String answer = sendAndWait(CM32_QUERY, timeout());
|
||||
|
||||
if (answer.isEmpty()) {
|
||||
this.progressUpdate("No signal");
|
||||
this.updateMessage("No signal");
|
||||
updateState(CONNECTED_STATE, false);
|
||||
return null;
|
||||
} else if (!answer.contains("PM1:mbar")) {
|
||||
this.progressUpdate("Wrong answer: " + answer);
|
||||
this.updateMessage("Wrong answer: " + answer);
|
||||
updateState(CONNECTED_STATE, false);
|
||||
return null;
|
||||
} else if (answer.substring(14, 17).equals("OFF")) {
|
||||
this.progressUpdate("Off");
|
||||
this.updateMessage("Off");
|
||||
updateState(CONNECTED_STATE, true);
|
||||
return null;
|
||||
} else {
|
||||
this.progressUpdate("OK");
|
||||
this.updateMessage("OK");
|
||||
updateState(CONNECTED_STATE, true);
|
||||
return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23));
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class MKSBaratronDevice extends PortSensor<Double> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
public String getType() {
|
||||
return meta().getString("type", "MKS baratron");
|
||||
}
|
||||
|
||||
@ -64,18 +64,18 @@ public class MKSBaratronDevice extends PortSensor<Double> {
|
||||
if (answer == null || answer.isEmpty()) {
|
||||
// invalidateState("connection");
|
||||
updateState(CONNECTED_STATE, false);
|
||||
this.progressUpdate("No connection");
|
||||
this.updateMessage("No connection");
|
||||
return null;
|
||||
} else {
|
||||
updateState(CONNECTED_STATE, true);
|
||||
}
|
||||
double res = Double.parseDouble(answer);
|
||||
if (res <= 0) {
|
||||
this.progressUpdate("Non positive");
|
||||
this.updateMessage("Non positive");
|
||||
// invalidateState("power");
|
||||
return null;
|
||||
} else {
|
||||
this.progressUpdate("OK");
|
||||
this.updateMessage("OK");
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ public class MKSVacDevice extends PortSensor<Double> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
public String getType() {
|
||||
return meta().getString("type", "MKS vacuumeter");
|
||||
}
|
||||
|
||||
@ -154,16 +154,16 @@ public class MKSVacDevice extends PortSensor<Double> {
|
||||
String answer = talk("PR" + getChannel() + "?");
|
||||
if (answer == null || answer.isEmpty()) {
|
||||
updateState(CONNECTED_STATE, false);
|
||||
this.progressUpdate("No connection");
|
||||
this.updateMessage("No connection");
|
||||
return null;
|
||||
}
|
||||
double res = Double.parseDouble(answer);
|
||||
if (res <= 0) {
|
||||
this.progressUpdate("No power");
|
||||
this.updateMessage("No power");
|
||||
invalidateState("power");
|
||||
return null;
|
||||
} else {
|
||||
this.progressUpdate("OK");
|
||||
this.updateMessage("OK");
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
public String getType() {
|
||||
return meta().getString("type", "Vit vacuumeter");
|
||||
}
|
||||
|
||||
@ -93,7 +93,7 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
||||
String answer = sendAndWait(query, timeout(), phrase -> phrase.startsWith(base));
|
||||
|
||||
if (answer.isEmpty()) {
|
||||
this.progressUpdate("No signal");
|
||||
this.updateMessage("No signal");
|
||||
updateState(CONNECTED_STATE, false);
|
||||
return null;
|
||||
} else {
|
||||
@ -107,11 +107,11 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
||||
}
|
||||
BigDecimal res = BigDecimal.valueOf(base * Math.pow(10, exp));
|
||||
res = res.setScale(4, RoundingMode.CEILING);
|
||||
this.progressUpdate("OK");
|
||||
this.updateMessage("OK");
|
||||
updateState(CONNECTED_STATE, true);
|
||||
return res.doubleValue();
|
||||
} else {
|
||||
this.progressUpdate("Wrong answer: " + answer);
|
||||
this.updateMessage("Wrong answer: " + answer);
|
||||
updateState(CONNECTED_STATE, false);
|
||||
return null;
|
||||
}
|
||||
|
@ -92,7 +92,7 @@ public class VacCollectorDevice extends Sensor<Values> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String type() {
|
||||
public String getType() {
|
||||
return "Numass vacuum";
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ description = 'kodex/ktor based server'
|
||||
dependencies {
|
||||
compile "hep.dataforge:kodex-server"
|
||||
compile "hep.dataforge:dataforge-storage"
|
||||
compile "hep.dataforge:dataforge-control"
|
||||
compile project(":numass-core")
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
package inr.numass.server
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.control.DeviceManager
|
||||
import hep.dataforge.providers.Path
|
||||
import hep.dataforge.server.*
|
||||
import hep.dataforge.storage.api.TableLoader
|
||||
@ -32,60 +31,99 @@ private suspend fun ApplicationCall.json(json: suspend JsonObjectBuilder.() -> U
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class StorageInterceptorBuilder : InterceptorBuilder {
|
||||
override fun build(context: Context, meta: Meta): ServerInterceptor {
|
||||
val storageManager = context.getFeature(StorageManager::class.java);
|
||||
val storage = storageManager.buildStorage(meta);
|
||||
return ServerInterceptor("storage") {
|
||||
get("listStorage") {
|
||||
val path = call.request.queryParameters["path"] ?: ""
|
||||
val shelf = storage.optShelf(path)
|
||||
if (shelf.isPresent) {
|
||||
call.json {
|
||||
val loaders = jsonArray();
|
||||
for (loader in StorageUtils.loaderStream(shelf.get())) {
|
||||
loaders.add(jsonObject {
|
||||
add("name", loader.name)
|
||||
add("path", loader.path.toString())
|
||||
add("type", loader.type)
|
||||
add("meta", loader.laminate.asJson())
|
||||
})
|
||||
}
|
||||
add("loaders", loaders)
|
||||
val storageInterceptor = InterceptorFactory { context, meta ->
|
||||
val storageManager = context.getFeature(StorageManager::class.java);
|
||||
val storage = storageManager.buildStorage(meta);
|
||||
ServerInterceptor("storage") {
|
||||
get("listStorage") {
|
||||
val path = call.request.queryParameters["path"] ?: ""
|
||||
val shelf = storage.optShelf(path)
|
||||
if (shelf.isPresent) {
|
||||
call.json {
|
||||
val loaders = jsonArray();
|
||||
for (loader in StorageUtils.loaderStream(shelf.get())) {
|
||||
loaders.add(jsonObject {
|
||||
add("name", loader.name)
|
||||
add("path", loader.path.toString())
|
||||
add("type", loader.type)
|
||||
add("meta", loader.laminate.asJson())
|
||||
})
|
||||
}
|
||||
} else {
|
||||
call.error("storage.shelfNotFound", "The shelf with path '$path' not found")
|
||||
add("loaders", loaders)
|
||||
}
|
||||
} else {
|
||||
call.error("storage.shelfNotFound", "The shelf with path '$path' not found")
|
||||
}
|
||||
get("getPlotData") {
|
||||
val path = call.request.queryParameters["path"]
|
||||
if (path == null) {
|
||||
call.error("storage.missingParameter", "Missing request parameter 'path'")
|
||||
} else {
|
||||
val loaderObject = storage.provide(Path.of(path))
|
||||
if (loaderObject.isPresent) {
|
||||
val loader = loaderObject.get();
|
||||
if (loader is TableLoader) {
|
||||
val from = Value.of(call.request.queryParameters["from"] ?: "")
|
||||
val to = Value.of(call.request.queryParameters["to"] ?: "")
|
||||
val maxItems = (call.request.queryParameters.get("maxItems") ?: "1000").toInt()
|
||||
call.json {
|
||||
add("path", loader.path.toString())
|
||||
val data = jsonArray()
|
||||
for (point in loader.index.pull(from, to, maxItems)) {
|
||||
data.add(point.asJson())
|
||||
}
|
||||
}
|
||||
get("getPlotData") {
|
||||
val path = call.request.queryParameters["path"]
|
||||
if (path == null) {
|
||||
call.error("storage.missingParameter", "Missing request parameter 'path'")
|
||||
} else {
|
||||
val loaderObject = storage.provide(Path.of(path))
|
||||
if (loaderObject.isPresent) {
|
||||
val loader = loaderObject.get();
|
||||
if (loader is TableLoader) {
|
||||
val from = Value.of(call.request.queryParameters["from"] ?: "")
|
||||
val to = Value.of(call.request.queryParameters["to"] ?: "")
|
||||
val maxItems = (call.request.queryParameters["maxItems"] ?: "1000").toInt()
|
||||
call.json {
|
||||
add("path", loader.path.toString())
|
||||
val data = jsonArray()
|
||||
for (point in loader.index.pull(from, to, maxItems)) {
|
||||
data.add(point.asJson())
|
||||
}
|
||||
} else {
|
||||
call.error("storage.incorrectLoaderType", "Loader $path is not a TableLoader")
|
||||
}
|
||||
} else {
|
||||
call.error("storage.loaderNotFound", "Can't find TableLoader with path = '$path'")
|
||||
call.error("storage.incorrectLoaderType", "Loader $path is not a TableLoader")
|
||||
}
|
||||
} else {
|
||||
call.error("storage.loaderNotFound", "Can't find TableLoader with path = '$path'")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
val controlInterceptor = InterceptorFactory { context, meta ->
|
||||
val deviceManager = context.getFeature(DeviceManager::class.java);
|
||||
ServerInterceptor("devices") {
|
||||
get("listDevices") {
|
||||
call.json {
|
||||
val devices = jsonArray();
|
||||
for (name in deviceManager.deviceNames()) {
|
||||
val device = deviceManager.optDevice(name).get();
|
||||
devices.add(jsonObject {
|
||||
add("name", name.toUnescaped())
|
||||
add("type", device.getType())
|
||||
add("meta", device.meta.asJson())
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
get("getDeviceState") {
|
||||
val deviceName = call.request.queryParameters["name"] ?: "";
|
||||
if (deviceName.isEmpty()) {
|
||||
call.error("devices.missingParameter", "Parameter 'name' is required")
|
||||
} else {
|
||||
val deviceOpt = deviceManager.optDevice(deviceName);
|
||||
if (deviceOpt.isPresent) {
|
||||
val device = deviceOpt.get();
|
||||
call.json {
|
||||
add("name", deviceName)
|
||||
add("type", device.type)
|
||||
add("meta", device.meta.asJson())
|
||||
add("state", jsonObject {
|
||||
for (state in device.listStates()) {
|
||||
add(state, device.getState(state).toString())
|
||||
}
|
||||
})
|
||||
}
|
||||
} else {
|
||||
call.error("devices.deviceNotFound", "Device with name: $deviceName not found in the system.")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,24 @@
|
||||
package inr.numass.server
|
||||
|
||||
import hep.dataforge.context.Context
|
||||
import hep.dataforge.context.Global
|
||||
import hep.dataforge.control.DeviceManager
|
||||
import hep.dataforge.meta.Meta
|
||||
import hep.dataforge.server.KodexServer
|
||||
import hep.dataforge.storage.commons.StorageManager
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
val meta = Meta.empty();
|
||||
val context = Context.build("SERVER", Global.instance(), meta)
|
||||
val server = KodexServer(context, meta)
|
||||
|
||||
context.optFeature(StorageManager::class.java).ifPresent{
|
||||
server.intercept(storageInterceptor)
|
||||
}
|
||||
|
||||
context.optFeature(DeviceManager::class.java).ifPresent{
|
||||
|
||||
}
|
||||
|
||||
server.start()
|
||||
}
|
Loading…
Reference in New Issue
Block a user