diff --git a/numass-control/build.gradle b/numass-control/build.gradle index f8584abf..0e32a0ff 100644 --- a/numass-control/build.gradle +++ b/numass-control/build.gradle @@ -28,9 +28,8 @@ task installAll(type: Copy) { def configRoot = new Node(null, "config"); subprojects { sub -> //add device configuration file - def cfgFile = sub.file("src/main/resources/config/devices.xml") - if (cfgFile.exists()) { - println "Found device config file ${cfgFile}" + sub.fileTree(dir: 'src/main/resources/config', includes: ['**/*.xml']).each { cfgFile -> + println "Found config file ${cfgFile}" parser.parse(cfgFile).children().each { configRoot.append(it as Node) } diff --git a/numass-control/control-room/build.gradle b/numass-control/control-room/build.gradle index aa3fd9a9..e41363e2 100644 --- a/numass-control/control-room/build.gradle +++ b/numass-control/control-room/build.gradle @@ -1,5 +1,5 @@ plugins{ - id "org.jetbrains.kotlin.jvm" version '1.1.2-2' + id "org.jetbrains.kotlin.jvm" version '1.1.2' id "application" } @@ -8,7 +8,7 @@ repositories { } if (!hasProperty('mainClass')) { - ext.mainClass = 'inr.numass.viewer.Viewer'//"inr.numass.viewer.test.TestApp" + ext.mainClass = 'inr.numass.control.ServerApp'//"inr.numass.viewer.test.TestApp" } mainClassName = mainClass @@ -22,11 +22,12 @@ compileKotlin.kotlinOptions.jvmTarget = "1.8" dependencies { compile project(':numass-core') compile project(':numass-control') + compile project(':numass-server') compile 'org.controlsfx:controlsfx:8.40.12' compile "no.tornado:tornadofx:1.7.4" - compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2-3" + compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:1.1.2" } apply plugin: 'kotlin' diff --git a/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerApp.kt b/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerApp.kt new file mode 100644 index 00000000..a920e979 --- /dev/null +++ b/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerApp.kt @@ -0,0 +1,21 @@ +package inr.numass.control + +import hep.dataforge.context.Global +import javafx.scene.Scene +import tornadofx.* + +/** + * Created by darksnake on 19-May-17. + */ +class ServerApp : App(ServerView::class) { + + override fun createPrimaryScene(view: UIComponent): Scene { + if (view is ServerView) { + view.context = Global.getContext("NUMASS-SERVER") + NumassControlUtils.getConfig(this).ifPresent { view.configure(it) } + } + return super.createPrimaryScene(view) + } + + +} \ No newline at end of file diff --git a/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerView.kt b/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerView.kt new file mode 100644 index 00000000..44bf3056 --- /dev/null +++ b/numass-control/control-room/src/main/kotlin/inr/numass/control/ServerView.kt @@ -0,0 +1,85 @@ +package inr.numass.control + +import hep.dataforge.context.Context +import hep.dataforge.exceptions.StorageException +import hep.dataforge.meta.Meta +import hep.dataforge.server.ServerManager +import hep.dataforge.storage.commons.StorageFactory +import inr.numass.client.ClientUtils +import javafx.beans.property.SimpleObjectProperty +import javafx.event.EventHandler +import javafx.scene.control.Hyperlink +import tornadofx.* + +/** + * Created by darksnake on 18-May-17. + */ +class ServerView() : View("Numass server controller") { + val contextProperty = SimpleObjectProperty() + var context by contextProperty + + val serverManagerProperty = SimpleObjectProperty() + var serverManager: ServerManager by serverManagerProperty + + + var label: Hyperlink by singleAssign(); + override val root = borderpane { + center { + hbox { + togglebutton("Server") { + isSelected = false + disableProperty().bind(serverManagerProperty.isNull) + action { + if (isSelected) { + serverManager.startServer() + label.text = serverManager.link; + } else { + serverManager.stopServer() + label.text = "" + } + } + } + label = hyperlink{ + action { + hostServices.showDocument(serverManager.link); + } + } + } + } + } + + init { + NumassControlUtils.setDFStageIcon(primaryStage) + contextProperty.addListener { _, oldValue, newValue -> + if (oldValue != newValue) { + if (newValue != null) { + serverManager = newValue.pluginManager().getOrLoad(ServerManager::class.java); + } else { + serverManagerProperty.set(null); + } + } + } + primaryStage.onCloseRequest = EventHandler { serverManager.stopServer() } + } + + fun configure(meta: Meta) { + meta.optMeta("storage").ifPresent { node -> + context.logger.info("Creating storage for server with meta {}", node) + //building storage in a separate thread + runAsync { + val numassRun = ClientUtils.getRunName(meta) + var storage = StorageFactory.buildStorage(context, node) + if (!numassRun.isEmpty()) { + try { + storage = storage.buildShelf(numassRun, Meta.empty()) + } catch (e: StorageException) { + context.logger.error("Failed to build shelf", e) + } + + } + serverManager.addStorage("numass", storage); + } + } + } + +} diff --git a/numass-control/control-room/src/main/resources/config/server.xml b/numass-control/control-room/src/main/resources/config/server.xml new file mode 100644 index 00000000..6cea22b0 --- /dev/null +++ b/numass-control/control-room/src/main/resources/config/server.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8View.java b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8View.java index 56e87f33..39082598 100644 --- a/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8View.java +++ b/numass-control/cryotemp/src/main/java/inr/numass/cryotemp/PKT8View.java @@ -50,6 +50,8 @@ public class PKT8View extends DeviceViewConnection implements Initia @FXML private ToggleButton startStopButton; @FXML + private ToggleButton storeButton; + @FXML private ToggleButton consoleButton; @FXML private ToggleButton plotButton; @@ -70,6 +72,7 @@ public class PKT8View extends DeviceViewConnection implements Initia sensorColumn.setCellValueFactory(new PropertyValueFactory<>("channel")); resColumn.setCellValueFactory(new PropertyValueFactory<>("rawString")); tempColumn.setCellValueFactory(new PropertyValueFactory<>("temperatureString")); + bindBooleanToState("storing", storeButton.selectedProperty()); } @Override diff --git a/numass-control/cryotemp/src/main/resources/config/devices.xml b/numass-control/cryotemp/src/main/resources/config-debug/devices.xml similarity index 100% rename from numass-control/cryotemp/src/main/resources/config/devices.xml rename to numass-control/cryotemp/src/main/resources/config-debug/devices.xml diff --git a/numass-control/cryotemp/src/main/resources/config/thermo-1.xml b/numass-control/cryotemp/src/main/resources/config/thermo-1.xml index 18e1dc1c..200c435b 100644 --- a/numass-control/cryotemp/src/main/resources/config/thermo-1.xml +++ b/numass-control/cryotemp/src/main/resources/config/thermo-1.xml @@ -1,6 +1,5 @@ - 192.168.111.36:4001 diff --git a/numass-control/cryotemp/src/main/resources/fxml/PKT8Indicator.fxml b/numass-control/cryotemp/src/main/resources/fxml/PKT8Indicator.fxml index a8c905a6..04c9eb7c 100644 --- a/numass-control/cryotemp/src/main/resources/fxml/PKT8Indicator.fxml +++ b/numass-control/cryotemp/src/main/resources/fxml/PKT8Indicator.fxml @@ -19,15 +19,14 @@ - - - - - - - - + + + + + + + diff --git a/numass-control/src/main/java/inr/numass/control/DeviceViewConnection.java b/numass-control/src/main/java/inr/numass/control/DeviceViewConnection.java index 13d9ba28..75cebafa 100644 --- a/numass-control/src/main/java/inr/numass/control/DeviceViewConnection.java +++ b/numass-control/src/main/java/inr/numass/control/DeviceViewConnection.java @@ -42,12 +42,12 @@ public abstract class DeviceViewConnection extends DeviceConne */ protected void bindBooleanToState(String state, BooleanProperty property) { getStateBinding(state).addListener((observable, oldValue, newValue) -> { - if (oldValue != newValue) { + if (isOpen() && oldValue != newValue) { property.setValue(newValue.booleanValue()); } }); property.addListener((observable, oldValue, newValue) -> { - if (oldValue != newValue) { + if (isOpen() && oldValue != newValue) { getDevice().setState(state, newValue); } }); diff --git a/numass-control/src/main/java/inr/numass/control/Framework.java b/numass-control/src/main/java/inr/numass/control/Framework.java deleted file mode 100644 index d96b8ea4..00000000 --- a/numass-control/src/main/java/inr/numass/control/Framework.java +++ /dev/null @@ -1,16 +0,0 @@ -package inr.numass.control; - -import hep.dataforge.control.devices.Device; -import hep.dataforge.fx.fragments.FXFragment; -import hep.dataforge.fx.fragments.LogFragment; -import hep.dataforge.utils.MetaFactory; - -/** - * Created by darksnake on 20-Oct-16. - */ -public interface Framework { - LogFragment getLogFragment(); - FXFragment getPlotFragment(); - DeviceFragment getDeviceFragment(); - MetaFactory getDeviceFactory(); -} diff --git a/numass-control/src/main/java/inr/numass/control/NumassControlApplication.java b/numass-control/src/main/java/inr/numass/control/NumassControlApplication.java index d3cd8751..b844b140 100644 --- a/numass-control/src/main/java/inr/numass/control/NumassControlApplication.java +++ b/numass-control/src/main/java/inr/numass/control/NumassControlApplication.java @@ -36,6 +36,7 @@ public abstract class NumassControlApplication extends Applica primaryStage.show(); device = setupDevice(controller); + NumassControlUtils.setDFStageIcon(primaryStage); setupStage(primaryStage, device); } diff --git a/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java b/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java index 1b742bdf..e6c220d2 100644 --- a/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java +++ b/numass-control/src/main/java/inr/numass/control/NumassControlUtils.java @@ -14,6 +14,8 @@ import hep.dataforge.storage.commons.StorageFactory; import hep.dataforge.storage.commons.StorageManager; import inr.numass.client.ClientUtils; import javafx.application.Application; +import javafx.scene.image.Image; +import javafx.stage.Stage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -98,4 +100,8 @@ public class NumassControlUtils { return ctx; } + public static void setDFStageIcon(Stage stage){ + stage.getIcons().add(new Image(NumassControlUtils.class.getResourceAsStream("/img/df.png"))); + } + } diff --git a/numass-control/src/main/resources/img/df.png b/numass-control/src/main/resources/img/df.png new file mode 100644 index 00000000..076e26a2 Binary files /dev/null and b/numass-control/src/main/resources/img/df.png differ diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java index 88446d7f..985c17ef 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/PoweredVacuumeterView.java @@ -5,8 +5,6 @@ */ package inr.numass.readvac.fx; -import hep.dataforge.values.Value; -import javafx.beans.value.ObservableValue; import javafx.fxml.FXML; import javafx.fxml.FXMLLoader; import javafx.scene.Node; @@ -41,11 +39,9 @@ public class PoweredVacuumeterView extends VacuumeterView { @Override public void initialize(URL location, ResourceBundle resources) { + super.initialize(location,resources); unitLabel.setText(getDevice().meta().getString("units", "mbar")); deviceNameLabel.setText(getDevice().getName()); - powerSwitch.selectedProperty().addListener((ObservableValue observable, Boolean oldValue, Boolean newValue) -> { - getDevice().setState("power", Value.of(newValue)); - }); + bindBooleanToState("power", powerSwitch.selectedProperty()); } - } diff --git a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java index a3d3da29..3563d6ca 100644 --- a/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java +++ b/numass-control/vac/src/main/java/inr/numass/readvac/fx/VacuumeterView.java @@ -10,7 +10,6 @@ import hep.dataforge.control.devices.Device; import hep.dataforge.control.measurements.Measurement; import hep.dataforge.control.measurements.MeasurementListener; import hep.dataforge.control.measurements.Sensor; -import hep.dataforge.values.Value; import inr.numass.control.DeviceViewConnection; import javafx.application.Platform; import javafx.beans.value.ObservableValue; @@ -98,11 +97,6 @@ public class VacuumeterView extends DeviceViewConnection> impleme }); } - @Override - public void notifyDeviceStateChanged(Device device, String name, Value state) { - - } - @Override public void onMeasurementFailed(Measurement measurement, Throwable exception) { Platform.runLater(() -> { diff --git a/numass-control/vac/src/main/resources/config/devices.xml b/numass-control/vac/src/main/resources/config/devices.xml index 15f73677..84ab5ebb 100644 --- a/numass-control/vac/src/main/resources/config/devices.xml +++ b/numass-control/vac/src/main/resources/config/devices.xml @@ -2,7 +2,7 @@ - + diff --git a/numass-server/src/main/java/inr/numass/server/TestServer.java b/numass-server/src/main/java/inr/numass/server/TestServer.java index d1316de0..ee0ad957 100644 --- a/numass-server/src/main/java/inr/numass/server/TestServer.java +++ b/numass-server/src/main/java/inr/numass/server/TestServer.java @@ -37,7 +37,7 @@ public class TestServer { NumassStorage storage = new NumassStorage(context, FileStorageFactory.buildStorageMeta(path, true, true)); serverManager.addObject("numass", storage, NumassStorageHandler::new); - serverManager.startSetver(); + serverManager.startServer(); String stopLine = "";