Search in sources :

Example 1 with SensorsSimulator

use of il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator in project Smartcity-Smarthouse by TechnionYP5777.

the class VitalsApp method initSimulator.

private static SensorsSimulator initSimulator() {
    final String pulsePath = "vitals" + PathBuilder.DELIMITER + "pulse", sysBPPath = "vitals" + PathBuilder.DELIMITER + "systolicBP", diBPPath = "vitals" + PathBuilder.DELIMITER + "diastolicBP";
    SensorsSimulator s = new SensorsSimulator();
    s.addSensor(new SensorBuilder().setCommname("iVitals").setAlias("Yarden's vitals sensor").addInfoSendingPath(pulsePath, Integer.class).addStreamingRange(pulsePath, Arrays.asList(80, 100)).addInfoSendingPath(sysBPPath, Integer.class).addStreamingRange(sysBPPath, Arrays.asList(100, 130)).addInfoSendingPath(diBPPath, Integer.class).addStreamingRange(diBPPath, Arrays.asList(30, 40)).setStreamInterval(TimeUnit.SECONDS.toMillis(1)).build());
    return s;
}
Also used : SensorsSimulator(il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator) SensorBuilder(il.ac.technion.cs.smarthouse.sensors.simulator.SensorBuilder)

Example 2 with SensorsSimulator

use of il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator in project Smartcity-Smarthouse by TechnionYP5777.

the class SosAppGui method initSimulator.

private static SensorsSimulator initSimulator() {
    final String path = "sos" + PathBuilder.DELIMITER + "pressed";
    SensorsSimulator s = new SensorsSimulator();
    s.addSensor(new SensorBuilder().setCommname("iSOS").setAlias("Elia's sos sensor").addInfoSendingPath(path, Boolean.class).addStreamingRange(path, Arrays.asList(true)).setStreamInterval(TimeUnit.MINUTES.toMillis(3)).build());
    return s;
}
Also used : SensorsSimulator(il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator) SensorBuilder(il.ac.technion.cs.smarthouse.sensors.simulator.SensorBuilder)

Example 3 with SensorsSimulator

use of il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator in project Smartcity-Smarthouse by TechnionYP5777.

the class StoveModuleGui method initSimulator.

private static SensorsSimulator initSimulator() {
    final String onPath = "stove" + PathBuilder.DELIMITER + "is_on", temperPath = "stove" + PathBuilder.DELIMITER + "temperature";
    SensorsSimulator s = new SensorsSimulator();
    s.addSensor(new SensorBuilder().setCommname("iStoves").setAlias("Roy's awesome stove").addInfoSendingPath(onPath, Boolean.class).addInfoSendingPath(temperPath, Integer.class).addStreamingRange(onPath, Arrays.asList(true)).addStreamingRange(temperPath, Arrays.asList(0, 140)).setStreamInterval(1000L).build());
    return s;
}
Also used : SensorsSimulator(il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator) SensorBuilder(il.ac.technion.cs.smarthouse.sensors.simulator.SensorBuilder)

Example 4 with SensorsSimulator

use of il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator in project Smartcity-Smarthouse by TechnionYP5777.

the class Entry method main.

public static void main(final String[] args) {
    SensorsSimulator simulator = new SensorsSimulator().setGeneralStreamingInteval(TimeUnit.SECONDS.toMillis(5));
    SystemPresenterFactory factory = new SystemPresenterFactory().initMode(SystemMode.USER_MODE).enableModePopup(false).setUseCloudServer(false).enableLocalDatabase(false);
    new Reflections("il.ac.technion.cs.smarthouse.applications", new SubTypesScanner(false)).getSubTypesOf(SmarthouseApplication.class).forEach(cls -> {
        factory.addApplicationToInstall(new ApplicationPath(PathType.CLASS, cls));
        if (Simulatable.class.isAssignableFrom(cls))
            try {
                simulator.addAllSensor(((Simulatable) cls.newInstance()).getSimulatedSensors());
            } catch (InstantiationException | IllegalAccessException e) {
            // Ignoring
            }
    });
    factory.build();
    new Thread() {

        @Override
        public void interrupt() {
            simulator.stopSendingMsgsInAllSensors();
            super.interrupt();
        }

        @Override
        public void run() {
            simulator.startSendingMsgsInAllSensors();
            JavaFxHelper.startGui(new DeveloperSimulatorGui().setSimulator(simulator));
            super.run();
        }
    }.start();
}
Also used : SensorsSimulator(il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator) SystemPresenterFactory(il.ac.technion.cs.smarthouse.system_presenter.SystemPresenterFactory) Simulatable(il.ac.technion.cs.smarthouse.sensors.Simulatable) DeveloperSimulatorGui(il.ac.technion.cs.smarthouse.DeveloperSimulator.DeveloperSimulatorGui) SubTypesScanner(org.reflections.scanners.SubTypesScanner) SmarthouseApplication(il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication) ApplicationPath(il.ac.technion.cs.smarthouse.system.applications.installer.ApplicationPath) Reflections(org.reflections.Reflections)

Example 5 with SensorsSimulator

use of il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator in project Smartcity-Smarthouse by TechnionYP5777.

the class MainSensorListController method initialize.

/*
     * (non-Javadoc)
     * 
     * @see
     * il.ac.technion.cs.smarthouse.gui_controller.GuiController#initialize(java
     * .lang.Object, il.ac.technion.cs.smarthouse.gui_controller.GuiController,
     * java.net.URL, java.util.ResourceBundle)
     */
@Override
protected <T extends GuiController<SensorsSimulator>> void initialize(SensorsSimulator model1, T parent1, URL location, ResourceBundle b) {
    Consumer<GenericSensor> addConsumer = x -> {
        this.sensors.add(new Pair<String, String>(model1.getSensorId(x), x.getCommname() + "(" + x.getAlias() + ")"));
        sensors.sort(new Comparator<Pair<String, String>>() {

            @Override
            public int compare(Pair<String, String> o1, Pair<String, String> o2) {
                return o1.getValue().compareTo(o2.getValue());
            }
        });
    };
    model1.addListenerWhen(SensorsSimulator.Action.ADD, addConsumer);
    sensorTable.setItems(sensors);
    nameColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.7));
    nameColumn.setResizable(false);
    nameColumn.setCellValueFactory(cellData -> new ReadOnlyStringWrapper(cellData.getValue().getValue()));
    configColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.1));
    configColumn.setResizable(false);
    configColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    configColumn.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                final TextInputDialog dialog = new TextInputDialog();
                dialog.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("/Homeicon.png"))));
                dialog.setTitle("Sensor simulator");
                dialog.setHeaderText("Clone Sensor");
                dialog.setContentText("Please enter the cloned sensor alias:");
                final Optional<String> result = dialog.showAndWait();
                if (!result.isPresent())
                    return;
                final String name = result.get();
                MainSensorListController.this.getModel().cloneSensor($.getTableView().getItems().get($.getIndex()).getKey(), name);
            }
        });
        $.setImage(new ImageView(new Image(getClass().getResourceAsStream("/Copy.png"))));
        $.setAlignment(Pos.CENTER);
        return $;
    });
    messageColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.1));
    messageColumn.setResizable(false);
    messageColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    messageColumn.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                setSelectedSensor($.getTableView().getItems().get($.getIndex()).getKey());
                ((DeveloperSimulatorController) MainSensorListController.this.getParentController()).openMessageWindow();
            }
        });
        $.setImage(new ImageView(new Image(getClass().getResourceAsStream("/Message.png"))));
        $.setAlignment(Pos.CENTER);
        return $;
    });
    deleteColumn.prefWidthProperty().bind(sensorTable.widthProperty().multiply(0.1));
    deleteColumn.setResizable(false);
    deleteColumn.setCellValueFactory(param -> new SimpleBooleanProperty(param.getValue() != null));
    deleteColumn.setCellFactory(p -> {
        final ButtonCell $ = new ButtonCell();
        $.setAction(new EventHandler<ActionEvent>() {

            @Override
            public void handle(ActionEvent e) {
                Alert alert = new Alert(AlertType.CONFIRMATION);
                alert.setTitle("Confirmation Dialog");
                alert.setHeaderText("Are you sure?");
                alert.setContentText("The sensor will be deleted forever!");
                Optional<ButtonType> result = alert.showAndWait();
                if (result.get() != ButtonType.OK)
                    return;
                final Pair<String, String> currentSensor = $.getTableView().getItems().get($.getIndex());
                model1.removeSensor(currentSensor.getKey());
                MainSensorListController.this.sensors.remove(currentSensor);
            }
        });
        $.setImage(new ImageView(new Image(getClass().getResourceAsStream("/Delete.png"))));
        $.setAlignment(Pos.CENTER);
        return $;
    });
    addButton.setOnAction(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent e) {
            ((DeveloperSimulatorController) MainSensorListController.this.getParentController()).moveToConfiguration();
        }
    });
}
Also used : EventHandler(javafx.event.EventHandler) Button(javafx.scene.control.Button) Pos(javafx.geometry.Pos) URL(java.net.URL) GuiController(il.ac.technion.cs.smarthouse.gui_controller.GuiController) ButtonType(javafx.scene.control.ButtonType) FXCollections(javafx.collections.FXCollections) TableColumn(javafx.scene.control.TableColumn) TableCell(javafx.scene.control.TableCell) ResourceBundle(java.util.ResourceBundle) AlertType(javafx.scene.control.Alert.AlertType) TableView(javafx.scene.control.TableView) Alert(javafx.scene.control.Alert) Pair(javafx.util.Pair) SensorsSimulator(il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) Consumer(java.util.function.Consumer) FXML(javafx.fxml.FXML) ActionEvent(javafx.event.ActionEvent) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) GenericSensor(il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor) ImageView(javafx.scene.image.ImageView) TextInputDialog(javafx.scene.control.TextInputDialog) Optional(java.util.Optional) ObservableList(javafx.collections.ObservableList) Comparator(java.util.Comparator) Image(javafx.scene.image.Image) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) Optional(java.util.Optional) ReadOnlyStringWrapper(javafx.beans.property.ReadOnlyStringWrapper) ActionEvent(javafx.event.ActionEvent) Image(javafx.scene.image.Image) Comparator(java.util.Comparator) Alert(javafx.scene.control.Alert) ImageView(javafx.scene.image.ImageView) GenericSensor(il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor) Pair(javafx.util.Pair) TextInputDialog(javafx.scene.control.TextInputDialog)

Aggregations

SensorsSimulator (il.ac.technion.cs.smarthouse.sensors.simulator.SensorsSimulator)5 SensorBuilder (il.ac.technion.cs.smarthouse.sensors.simulator.SensorBuilder)3 DeveloperSimulatorGui (il.ac.technion.cs.smarthouse.DeveloperSimulator.DeveloperSimulatorGui)1 SmarthouseApplication (il.ac.technion.cs.smarthouse.developers_api.SmarthouseApplication)1 GuiController (il.ac.technion.cs.smarthouse.gui_controller.GuiController)1 Simulatable (il.ac.technion.cs.smarthouse.sensors.Simulatable)1 GenericSensor (il.ac.technion.cs.smarthouse.sensors.simulator.GenericSensor)1 ApplicationPath (il.ac.technion.cs.smarthouse.system.applications.installer.ApplicationPath)1 SystemPresenterFactory (il.ac.technion.cs.smarthouse.system_presenter.SystemPresenterFactory)1 URL (java.net.URL)1 Comparator (java.util.Comparator)1 Optional (java.util.Optional)1 ResourceBundle (java.util.ResourceBundle)1 Consumer (java.util.function.Consumer)1 ReadOnlyStringWrapper (javafx.beans.property.ReadOnlyStringWrapper)1 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)1 FXCollections (javafx.collections.FXCollections)1 ObservableList (javafx.collections.ObservableList)1 ActionEvent (javafx.event.ActionEvent)1 EventHandler (javafx.event.EventHandler)1