Interrupt/Watchdog Window

This commit is contained in:
2024-05-15 13:46:42 +02:00
parent 0b932966c5
commit 073ad3dada
3 changed files with 24 additions and 10 deletions

View File

@ -8,7 +8,11 @@ import javafx.collections.ObservableList;
import javafx.event.ActionEvent; import javafx.event.ActionEvent;
import javafx.fxml.FXML; import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.*; import javafx.scene.control.*;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.stage.FileChooser; import javafx.stage.FileChooser;
import java.io.File; import java.io.File;
@ -81,12 +85,26 @@ public class Controller_Frontend {
private static volatile boolean isAutoRunActive = true; private static volatile boolean isAutoRunActive = true;
private static volatile boolean isSleeping = false; private static volatile boolean isSleeping = false;
public static void stopRunFromBackend(){ public static void stopRunFromBackend(String message){
isAutoRunActive = false; isAutoRunActive = false;
if (isSleeping) if (isSleeping)
isSleeping = false; isSleeping = false;
else else
DataRegister.resetPC(); DataRegister.resetPC();
Stage stoppedStage = new Stage();
stoppedStage.setTitle("Programm unterbrochen!");
VBox vbox = new VBox();
vbox.setAlignment(javafx.geometry.Pos.CENTER);
Label grundlabel = new Label("Grund: " + message);
grundlabel.setStyle("-fx-font-size: 16px; -fx-font-weight: bold;");
Label ueberlabel = new Label("Programm unterbrochen!");
vbox.getChildren().add(ueberlabel);
vbox.getChildren().add(grundlabel);
VBox.setMargin(grundlabel, new javafx.geometry.Insets(10, 10, 10, 10));
Scene scene = new Scene(vbox, 300, 90);
stoppedStage.setAlwaysOnTop(true);
stoppedStage.setScene(scene);
stoppedStage.show();
} }
public static void sleep() { public static void sleep() {
@ -116,7 +134,7 @@ public class Controller_Frontend {
e.printStackTrace(); e.printStackTrace();
} }
}); });
Thread.sleep(50); //Verzögerungszeit in Millisekunden Thread.sleep(20); //Verzögerungszeit in Millisekunden
} }
} catch (InterruptedException e) { } catch (InterruptedException e) {
e.printStackTrace(); e.printStackTrace();
@ -124,8 +142,6 @@ public class Controller_Frontend {
}); });
autoRunThread.setDaemon(true); autoRunThread.setDaemon(true);
autoRunThread.start(); autoRunThread.start();
} }
@ -152,9 +168,9 @@ public class Controller_Frontend {
String selectedRowStyle; String selectedRowStyle;
if (!isSleeping) if (!isSleeping)
selectedRowStyle = "-fx-background-color: red;"; selectedRowStyle = "-fx-background-color: red; -fx-text-fill: white;";
else else
selectedRowStyle = "-fx-background-color: teal;"; selectedRowStyle = "-fx-background-color: teal; -fx-text-fill: white;";
lstContentListView.setCellFactory(column -> new ListCell<String>() { lstContentListView.setCellFactory(column -> new ListCell<String>() {
@Override @Override
protected void updateItem(String item, boolean empty) { protected void updateItem(String item, boolean empty) {

View File

@ -12,12 +12,10 @@ public class WatchdogTimer {
public static void testAndTrigger() { public static void testAndTrigger() {
watchdogTime = getTimeFromRegister() * 1000; watchdogTime = getTimeFromRegister() * 1000;
if (enabled) { if (enabled) {
System.err.println("Remaining: " + ((watchdogTime + lastReset - 1) - Commands.getTotalExecutionTime()));
if (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset - 1)) { if (Commands.getTotalExecutionTime() >= (watchdogTime + lastReset - 1)) {
System.err.println("Watchdog Timer triggered");
DataRegister.clearBit(3, 4); DataRegister.clearBit(3, 4);
lastReset = Commands.getTotalExecutionTime(); lastReset = Commands.getTotalExecutionTime();
Controller_Frontend.stopRunFromBackend(); Controller_Frontend.stopRunFromBackend("Watchdog Timer");
} }
} }
} }

View File

@ -46,7 +46,7 @@
</HBox> </HBox>
<VBox layoutX="14.0" layoutY="727.0"> <VBox layoutX="14.0" layoutY="727.0">
<children> <children>
<Label fx:id="totalExecutionTimeLabel" text="Total Execution Time: 0µs" /> <Label fx:id="totalExecutionTimeLabel" text="Total Execution Time: 0µs"/>
<CheckBox fx:id="wdtCheck" mnemonicParsing="false" onAction="#toggleWatchdog" text="Watchdog-Timer"> <CheckBox fx:id="wdtCheck" mnemonicParsing="false" onAction="#toggleWatchdog" text="Watchdog-Timer">
<VBox.margin> <VBox.margin>
<Insets top="10.0" /> <Insets top="10.0" />