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
|
@Override
|
||||||
public String type() {
|
public String getType() {
|
||||||
return "MKS E-Vision";
|
return "MKS E-Vision";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ public class CM32Device extends PortSensor<Double> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String type() {
|
public String getType() {
|
||||||
return meta().getString("type", "Leibold CM32");
|
return meta().getString("type", "Leibold CM32");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,19 +61,19 @@ public class CM32Device extends PortSensor<Double> {
|
|||||||
String answer = sendAndWait(CM32_QUERY, timeout());
|
String answer = sendAndWait(CM32_QUERY, timeout());
|
||||||
|
|
||||||
if (answer.isEmpty()) {
|
if (answer.isEmpty()) {
|
||||||
this.progressUpdate("No signal");
|
this.updateMessage("No signal");
|
||||||
updateState(CONNECTED_STATE, false);
|
updateState(CONNECTED_STATE, false);
|
||||||
return null;
|
return null;
|
||||||
} else if (!answer.contains("PM1:mbar")) {
|
} else if (!answer.contains("PM1:mbar")) {
|
||||||
this.progressUpdate("Wrong answer: " + answer);
|
this.updateMessage("Wrong answer: " + answer);
|
||||||
updateState(CONNECTED_STATE, false);
|
updateState(CONNECTED_STATE, false);
|
||||||
return null;
|
return null;
|
||||||
} else if (answer.substring(14, 17).equals("OFF")) {
|
} else if (answer.substring(14, 17).equals("OFF")) {
|
||||||
this.progressUpdate("Off");
|
this.updateMessage("Off");
|
||||||
updateState(CONNECTED_STATE, true);
|
updateState(CONNECTED_STATE, true);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
this.progressUpdate("OK");
|
this.updateMessage("OK");
|
||||||
updateState(CONNECTED_STATE, true);
|
updateState(CONNECTED_STATE, true);
|
||||||
return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23));
|
return Double.parseDouble(answer.substring(14, 17) + answer.substring(19, 23));
|
||||||
}
|
}
|
||||||
|
@ -36,7 +36,7 @@ public class MKSBaratronDevice extends PortSensor<Double> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String type() {
|
public String getType() {
|
||||||
return meta().getString("type", "MKS baratron");
|
return meta().getString("type", "MKS baratron");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,18 +64,18 @@ public class MKSBaratronDevice extends PortSensor<Double> {
|
|||||||
if (answer == null || answer.isEmpty()) {
|
if (answer == null || answer.isEmpty()) {
|
||||||
// invalidateState("connection");
|
// invalidateState("connection");
|
||||||
updateState(CONNECTED_STATE, false);
|
updateState(CONNECTED_STATE, false);
|
||||||
this.progressUpdate("No connection");
|
this.updateMessage("No connection");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
updateState(CONNECTED_STATE, true);
|
updateState(CONNECTED_STATE, true);
|
||||||
}
|
}
|
||||||
double res = Double.parseDouble(answer);
|
double res = Double.parseDouble(answer);
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
this.progressUpdate("Non positive");
|
this.updateMessage("Non positive");
|
||||||
// invalidateState("power");
|
// invalidateState("power");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
this.progressUpdate("OK");
|
this.updateMessage("OK");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -138,7 +138,7 @@ public class MKSVacDevice extends PortSensor<Double> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String type() {
|
public String getType() {
|
||||||
return meta().getString("type", "MKS vacuumeter");
|
return meta().getString("type", "MKS vacuumeter");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,16 +154,16 @@ public class MKSVacDevice extends PortSensor<Double> {
|
|||||||
String answer = talk("PR" + getChannel() + "?");
|
String answer = talk("PR" + getChannel() + "?");
|
||||||
if (answer == null || answer.isEmpty()) {
|
if (answer == null || answer.isEmpty()) {
|
||||||
updateState(CONNECTED_STATE, false);
|
updateState(CONNECTED_STATE, false);
|
||||||
this.progressUpdate("No connection");
|
this.updateMessage("No connection");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
double res = Double.parseDouble(answer);
|
double res = Double.parseDouble(answer);
|
||||||
if (res <= 0) {
|
if (res <= 0) {
|
||||||
this.progressUpdate("No power");
|
this.updateMessage("No power");
|
||||||
invalidateState("power");
|
invalidateState("power");
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
this.progressUpdate("OK");
|
this.updateMessage("OK");
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String type() {
|
public String getType() {
|
||||||
return meta().getString("type", "Vit vacuumeter");
|
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));
|
String answer = sendAndWait(query, timeout(), phrase -> phrase.startsWith(base));
|
||||||
|
|
||||||
if (answer.isEmpty()) {
|
if (answer.isEmpty()) {
|
||||||
this.progressUpdate("No signal");
|
this.updateMessage("No signal");
|
||||||
updateState(CONNECTED_STATE, false);
|
updateState(CONNECTED_STATE, false);
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
@ -107,11 +107,11 @@ public class MeradatVacDevice extends PortSensor<Double> {
|
|||||||
}
|
}
|
||||||
BigDecimal res = BigDecimal.valueOf(base * Math.pow(10, exp));
|
BigDecimal res = BigDecimal.valueOf(base * Math.pow(10, exp));
|
||||||
res = res.setScale(4, RoundingMode.CEILING);
|
res = res.setScale(4, RoundingMode.CEILING);
|
||||||
this.progressUpdate("OK");
|
this.updateMessage("OK");
|
||||||
updateState(CONNECTED_STATE, true);
|
updateState(CONNECTED_STATE, true);
|
||||||
return res.doubleValue();
|
return res.doubleValue();
|
||||||
} else {
|
} else {
|
||||||
this.progressUpdate("Wrong answer: " + answer);
|
this.updateMessage("Wrong answer: " + answer);
|
||||||
updateState(CONNECTED_STATE, false);
|
updateState(CONNECTED_STATE, false);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -92,7 +92,7 @@ public class VacCollectorDevice extends Sensor<Values> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String type() {
|
public String getType() {
|
||||||
return "Numass vacuum";
|
return "Numass vacuum";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,7 @@ description = 'kodex/ktor based server'
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile "hep.dataforge:kodex-server"
|
compile "hep.dataforge:kodex-server"
|
||||||
compile "hep.dataforge:dataforge-storage"
|
compile "hep.dataforge:dataforge-storage"
|
||||||
|
compile "hep.dataforge:dataforge-control"
|
||||||
compile project(":numass-core")
|
compile project(":numass-core")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
package inr.numass.server
|
package inr.numass.server
|
||||||
|
|
||||||
import hep.dataforge.context.Context
|
import hep.dataforge.control.DeviceManager
|
||||||
import hep.dataforge.meta.Meta
|
|
||||||
import hep.dataforge.providers.Path
|
import hep.dataforge.providers.Path
|
||||||
import hep.dataforge.server.*
|
import hep.dataforge.server.*
|
||||||
import hep.dataforge.storage.api.TableLoader
|
import hep.dataforge.storage.api.TableLoader
|
||||||
@ -32,60 +31,99 @@ private suspend fun ApplicationCall.json(json: suspend JsonObjectBuilder.() -> U
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val storageInterceptor = InterceptorFactory { context, meta ->
|
||||||
class StorageInterceptorBuilder : InterceptorBuilder {
|
val storageManager = context.getFeature(StorageManager::class.java);
|
||||||
override fun build(context: Context, meta: Meta): ServerInterceptor {
|
val storage = storageManager.buildStorage(meta);
|
||||||
val storageManager = context.getFeature(StorageManager::class.java);
|
ServerInterceptor("storage") {
|
||||||
val storage = storageManager.buildStorage(meta);
|
get("listStorage") {
|
||||||
return ServerInterceptor("storage") {
|
val path = call.request.queryParameters["path"] ?: ""
|
||||||
get("listStorage") {
|
val shelf = storage.optShelf(path)
|
||||||
val path = call.request.queryParameters["path"] ?: ""
|
if (shelf.isPresent) {
|
||||||
val shelf = storage.optShelf(path)
|
call.json {
|
||||||
if (shelf.isPresent) {
|
val loaders = jsonArray();
|
||||||
call.json {
|
for (loader in StorageUtils.loaderStream(shelf.get())) {
|
||||||
val loaders = jsonArray();
|
loaders.add(jsonObject {
|
||||||
for (loader in StorageUtils.loaderStream(shelf.get())) {
|
add("name", loader.name)
|
||||||
loaders.add(jsonObject {
|
add("path", loader.path.toString())
|
||||||
add("name", loader.name)
|
add("type", loader.type)
|
||||||
add("path", loader.path.toString())
|
add("meta", loader.laminate.asJson())
|
||||||
add("type", loader.type)
|
})
|
||||||
add("meta", loader.laminate.asJson())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
add("loaders", loaders)
|
|
||||||
}
|
}
|
||||||
} else {
|
add("loaders", loaders)
|
||||||
call.error("storage.shelfNotFound", "The shelf with path '$path' not found")
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
call.error("storage.shelfNotFound", "The shelf with path '$path' not found")
|
||||||
}
|
}
|
||||||
get("getPlotData") {
|
}
|
||||||
val path = call.request.queryParameters["path"]
|
get("getPlotData") {
|
||||||
if (path == null) {
|
val path = call.request.queryParameters["path"]
|
||||||
call.error("storage.missingParameter", "Missing request parameter 'path'")
|
if (path == null) {
|
||||||
} else {
|
call.error("storage.missingParameter", "Missing request parameter 'path'")
|
||||||
val loaderObject = storage.provide(Path.of(path))
|
} else {
|
||||||
if (loaderObject.isPresent) {
|
val loaderObject = storage.provide(Path.of(path))
|
||||||
val loader = loaderObject.get();
|
if (loaderObject.isPresent) {
|
||||||
if (loader is TableLoader) {
|
val loader = loaderObject.get();
|
||||||
val from = Value.of(call.request.queryParameters["from"] ?: "")
|
if (loader is TableLoader) {
|
||||||
val to = Value.of(call.request.queryParameters["to"] ?: "")
|
val from = Value.of(call.request.queryParameters["from"] ?: "")
|
||||||
val maxItems = (call.request.queryParameters.get("maxItems") ?: "1000").toInt()
|
val to = Value.of(call.request.queryParameters["to"] ?: "")
|
||||||
call.json {
|
val maxItems = (call.request.queryParameters["maxItems"] ?: "1000").toInt()
|
||||||
add("path", loader.path.toString())
|
call.json {
|
||||||
val data = jsonArray()
|
add("path", loader.path.toString())
|
||||||
for (point in loader.index.pull(from, to, maxItems)) {
|
val data = jsonArray()
|
||||||
data.add(point.asJson())
|
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 {
|
} 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