Laufzeit und Watchdog und Timer

This commit is contained in:
2024-06-02 15:16:01 +02:00
parent 45f9878047
commit c49a073cfd
7 changed files with 209 additions and 15 deletions

View File

@ -11,8 +11,6 @@ import javafx.fxml.FXML;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.paint.RadialGradient;
import javafx.scene.shape.Circle;
import javafx.stage.FileChooser;
@ -27,9 +25,12 @@ import javafx.scene.control.Label;
import javafx.scene.control.TableView;
import javafx.stage.Stage;
import javafx.util.Callback;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
public class Controller_Frontend {
@ -37,6 +38,14 @@ public class Controller_Frontend {
private int [][] read;
private int [] ind;
private double executionTimeMultiplier = 1;
@FXML
private ComboBox<String> executionTimeComboBox;
@FXML
@ -78,6 +87,8 @@ public class Controller_Frontend {
@FXML
private CheckBox wdtCheck;
private static volatile boolean isAutoRunActive = false;
private static volatile boolean isSleeping = false;
@ -117,6 +128,9 @@ public class Controller_Frontend {
}
@FXML
private void autoRunGUI(ActionEvent event) {
if (!isAutoRunActive) {
@ -141,9 +155,37 @@ public class Controller_Frontend {
});
autoRunThread.setDaemon(true);
autoRunThread.start();
}
private void updateExecutionTimeMultiplier() {
String selectedOption = executionTimeComboBox.getValue();
switch (selectedOption) {
case "8 MHZ":
executionTimeMultiplier = 0.5;
break;
case "4 MHZ":
executionTimeMultiplier = 1;
break;
case "1 MHZ":
executionTimeMultiplier = 4;
break;
case "500 HZ":
executionTimeMultiplier = 8;
break;
case "100 HZ":
executionTimeMultiplier = 40;
break;
case "32 HZ":
executionTimeMultiplier = 125;
break;
}
}
@FXML
private void stepintoButton(ActionEvent event) throws IOException {
if (lstContentListView.getItems().isEmpty()) {
@ -158,6 +200,14 @@ public class Controller_Frontend {
else
currentIndex = ind[DataRegister.getPC()]-1;
// Überprüfen, ob ein Breakpoint gesetzt ist testte
if (breakpoints.contains(currentIndex)) {
stopAutoRun(null);
System.out.println("Breakpoint erreicht bei Zeile: " + currentIndex);
return;
}
// Scrollen zur ausgewählten Zeile
lstContentListView.scrollTo(currentIndex -2);
@ -173,7 +223,8 @@ public class Controller_Frontend {
markSelectedRow(currentIndex, selectedRowStyle);
// Befehle ausführen
if (!isSleeping) {
Commands.decode(prog[DataRegister.getPC()]);
DataRegister.increasePC();
@ -187,10 +238,13 @@ public class Controller_Frontend {
Stage stage = (Stage) stepintoButton.getScene().getWindow();
CreateWindow.refreshTable(stage);
IOPorts.refreshUI(getTRISbuttons(), getPORTbuttons());
totalExecutionTimeLabel.setText("Total Execution Time: " + Commands.getTotalExecutionTime() + "µs");
long totalExecutionTime = Commands.getTotalExecutionTime();
double adjustedTotalExecutionTime = totalExecutionTime * executionTimeMultiplier;
totalExecutionTimeLabel.setText("Total Execution Time: " + adjustedTotalExecutionTime + "µs");
}
private void markSelectedRow(int currentIndex, String selectedRowStyle){
private void markSelectedRow(int currentIndex, String selectedRowStyle) {
lstContentListView.setCellFactory(column -> new ListCell<String>() {
@Override
protected void updateItem(String item, boolean empty) {
@ -205,6 +259,10 @@ public class Controller_Frontend {
});
}
//////////////testeteet
private Set<Integer> breakpoints = new HashSet<>();
@FXML
protected void selectFileLST(ActionEvent event) throws IOException {
@ -234,9 +292,68 @@ public class Controller_Frontend {
System.out.println(Arrays.toString(Arrays.stream(prog).toArray()));
displayLSTFileContent(selectedFile);
markSelectedRow(0, "-fx-background-color: red; -fx-text-fill: white;");
initializeBreakpoints();
}
}
private void initializeBreakpoints() {
lstContentListView.setCellFactory(createBreakpointCell());
}
private boolean checkBreakpoint(int pc) {
// Hier wird überprüft, ob ein Breakpoint am angegebenen Programmzähler gesetzt ist
return breakpoints.contains(pc);
}
private Callback<ListView<String>, ListCell<String>> createBreakpointCell() {
return listView -> new ListCell<String>() {
private final CheckBox breakpointCheckBox = new CheckBox();
{
breakpointCheckBox.setOnAction(event -> {
int index = getIndex();
if (breakpointCheckBox.isSelected()) {
breakpoints.add(index);
} else {
breakpoints.remove(index);
}
});
}
@Override
protected void updateItem(String item, boolean empty) {
super.updateItem(item, empty);
if (empty || item == null) {
setGraphic(null);
} else {
setText(item);
setGraphic(breakpointCheckBox);
breakpointCheckBox.setSelected(breakpoints.contains(getIndex()));
}
}
};
}
@FXML
protected void loadLSTFileContent(String fileContent) {
ObservableList<String> items = FXCollections.observableArrayList(fileContent.split("\n"));
lstContentListView.setItems(items);
}
private File chooseLSTFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setTitle("Open LST File");
@ -340,6 +457,7 @@ public class Controller_Frontend {
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allTRISButtons[i]);
ToggleButtonGroupExt.get().addAlwaysOneSelectedSupport(allPORTButtons[i]);
}
ledCheckA.setSelected(false);
ledCheckB.setSelected(false);
setTRISbuttons(allTRISButtons);
@ -350,6 +468,13 @@ public class Controller_Frontend {
autoRunGUI.setOnAction(this::autoRunGUI);
stopButton.setOnAction(this::stopAutoRun);
executionTimeComboBox.setItems(FXCollections.observableArrayList("8 MHZ", "4 MHZ", "1 MHZ", "500 HZ", "100 HZ", "32 HZ"));
executionTimeComboBox.setValue("4 MHZ");
executionTimeComboBox.setOnAction(event -> updateExecutionTimeMultiplier());
lstContentListView.setCellFactory(createBreakpointCell());
}